blob: 7fda30acdf02f59cc079006cdf34ed27d802b554 [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;
Dianne Hackborn1e725a72015-03-24 18:23:19 -070032import android.util.ArrayMap;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080033import android.util.Printer;
34import android.util.SparseArray;
Dianne Hackborn37de0982014-05-09 09:32:18 -070035import android.util.SparseIntArray;
Dianne Hackborn1ebccf52010-08-15 13:04:34 -070036import android.util.TimeUtils;
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -070037import android.view.Display;
Dianne Hackborna7c837f2014-01-15 16:20:44 -080038import com.android.internal.os.BatterySipper;
39import com.android.internal.os.BatteryStatsHelper;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080040
41/**
42 * A class providing access to battery usage statistics, including information on
43 * wakelocks, processes, packages, and services. All times are represented in microseconds
44 * except where indicated otherwise.
45 * @hide
46 */
47public abstract class BatteryStats implements Parcelable {
48
49 private static final boolean LOCAL_LOGV = false;
Dianne Hackborn91268cf2013-06-13 19:06:50 -070050
51 /** @hide */
52 public static final String SERVICE_NAME = "batterystats";
53
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080054 /**
55 * A constant indicating a partial wake lock timer.
56 */
57 public static final int WAKE_TYPE_PARTIAL = 0;
58
59 /**
60 * A constant indicating a full wake lock timer.
61 */
62 public static final int WAKE_TYPE_FULL = 1;
63
64 /**
65 * A constant indicating a window wake lock timer.
66 */
67 public static final int WAKE_TYPE_WINDOW = 2;
Adam Lesinski9425fe22015-06-19 12:02:13 -070068
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080069 /**
70 * A constant indicating a sensor timer.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080071 */
72 public static final int SENSOR = 3;
The Android Open Source Project10592532009-03-18 17:39:46 -070073
74 /**
Dianne Hackborn58e0eef2010-09-16 01:22:10 -070075 * A constant indicating a a wifi running timer
Dianne Hackborn617f8772009-03-31 15:04:46 -070076 */
Dianne Hackborn58e0eef2010-09-16 01:22:10 -070077 public static final int WIFI_RUNNING = 4;
Dianne Hackborn617f8772009-03-31 15:04:46 -070078
79 /**
The Android Open Source Project10592532009-03-18 17:39:46 -070080 * A constant indicating a full wifi lock timer
The Android Open Source Project10592532009-03-18 17:39:46 -070081 */
Dianne Hackborn617f8772009-03-31 15:04:46 -070082 public static final int FULL_WIFI_LOCK = 5;
The Android Open Source Project10592532009-03-18 17:39:46 -070083
84 /**
Nick Pelly6ccaa542012-06-15 15:22:47 -070085 * A constant indicating a wifi scan
The Android Open Source Project10592532009-03-18 17:39:46 -070086 */
Nick Pelly6ccaa542012-06-15 15:22:47 -070087 public static final int WIFI_SCAN = 6;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080088
Dianne Hackborn62793e42015-03-09 11:15:41 -070089 /**
90 * A constant indicating a wifi multicast timer
91 */
92 public static final int WIFI_MULTICAST_ENABLED = 7;
Robert Greenwalt5347bd42009-05-13 15:10:16 -070093
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080094 /**
Amith Yamasani244fa5c2009-05-22 14:36:07 -070095 * A constant indicating a video turn on timer
Amith Yamasani244fa5c2009-05-22 14:36:07 -070096 */
97 public static final int VIDEO_TURNED_ON = 8;
98
99 /**
Dianne Hackborna06de0f2012-12-11 16:34:47 -0800100 * A constant indicating a vibrator on timer
101 */
102 public static final int VIBRATOR_ON = 9;
103
104 /**
Jeff Sharkey3e013e82013-04-25 14:48:19 -0700105 * A constant indicating a foreground activity timer
106 */
107 public static final int FOREGROUND_ACTIVITY = 10;
108
109 /**
Robert Greenwalta029ea12013-09-25 16:38:12 -0700110 * A constant indicating a wifi batched scan is active
111 */
112 public static final int WIFI_BATCHED_SCAN = 11;
113
114 /**
Dianne Hackborn61659e52014-07-09 16:13:01 -0700115 * A constant indicating a process state timer
116 */
117 public static final int PROCESS_STATE = 12;
118
119 /**
Dianne Hackbornfdb19562014-07-11 16:03:36 -0700120 * A constant indicating a sync timer
121 */
122 public static final int SYNC = 13;
123
124 /**
125 * A constant indicating a job timer
126 */
127 public static final int JOB = 14;
128
129 /**
Kweku Adamsd5379872014-11-24 17:34:05 -0800130 * A constant indicating an audio turn on timer
131 */
132 public static final int AUDIO_TURNED_ON = 15;
133
134 /**
Ruben Brunk6d2c3632015-05-26 17:32:16 -0700135 * A constant indicating a flashlight turn on timer
136 */
137 public static final int FLASHLIGHT_TURNED_ON = 16;
138
139 /**
140 * A constant indicating a camera turn on timer
141 */
142 public static final int CAMERA_TURNED_ON = 17;
143
144 /**
Jeff Brown6a8bd7b2015-06-19 15:07:51 -0700145 * A constant indicating a draw wake lock timer.
Adam Lesinski9425fe22015-06-19 12:02:13 -0700146 */
Jeff Brown6a8bd7b2015-06-19 15:07:51 -0700147 public static final int WAKE_TYPE_DRAW = 18;
Adam Lesinski9425fe22015-06-19 12:02:13 -0700148
149 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800150 * Include all of the data in the stats, including previously saved data.
151 */
Dianne Hackborn6b7b4842010-06-14 17:17:44 -0700152 public static final int STATS_SINCE_CHARGED = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800153
154 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800155 * Include only the current run in the stats.
156 */
Dianne Hackborn4590e522014-03-24 13:36:46 -0700157 public static final int STATS_CURRENT = 1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800158
159 /**
160 * Include only the run since the last time the device was unplugged in the stats.
161 */
Dianne Hackborn4590e522014-03-24 13:36:46 -0700162 public static final int STATS_SINCE_UNPLUGGED = 2;
Evan Millare84de8d2009-04-02 22:16:12 -0700163
164 // NOTE: Update this list if you add/change any stats above.
165 // These characters are supposed to represent "total", "last", "current",
Dianne Hackborn3bee5af82010-07-23 00:22:04 -0700166 // and "unplugged". They were shortened for efficiency sake.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700167 private static final String[] STAT_NAMES = { "l", "c", "u" };
168
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800169 /**
Dianne Hackborn0c820db2015-04-14 17:47:34 -0700170 * Current version of checkin data format.
171 */
172 static final String CHECKIN_VERSION = "14";
173
174 /**
175 * Old version, we hit 9 and ran out of room, need to remove.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800176 */
Ashish Sharma213bb2f2014-07-07 17:14:52 -0700177 private static final int BATTERY_STATS_CHECKIN_VERSION = 9;
Dianne Hackborn0c820db2015-04-14 17:47:34 -0700178
Evan Millar22ac0432009-03-31 11:33:18 -0700179 private static final long BYTES_PER_KB = 1024;
180 private static final long BYTES_PER_MB = 1048576; // 1024^2
181 private static final long BYTES_PER_GB = 1073741824; //1024^3
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800182
Dianne Hackborncd0e3352014-08-07 17:08:09 -0700183 private static final String VERSION_DATA = "vers";
Dianne Hackborne4a59512010-12-07 11:08:07 -0800184 private static final String UID_DATA = "uid";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800185 private static final String APK_DATA = "apk";
Evan Millare84de8d2009-04-02 22:16:12 -0700186 private static final String PROCESS_DATA = "pr";
187 private static final String SENSOR_DATA = "sr";
Dianne Hackborna06de0f2012-12-11 16:34:47 -0800188 private static final String VIBRATOR_DATA = "vib";
Jeff Sharkey3e013e82013-04-25 14:48:19 -0700189 private static final String FOREGROUND_DATA = "fg";
Dianne Hackborn61659e52014-07-09 16:13:01 -0700190 private static final String STATE_TIME_DATA = "st";
Evan Millare84de8d2009-04-02 22:16:12 -0700191 private static final String WAKELOCK_DATA = "wl";
Dianne Hackbornfdb19562014-07-11 16:03:36 -0700192 private static final String SYNC_DATA = "sy";
193 private static final String JOB_DATA = "jb";
Evan Millarc64edde2009-04-18 12:26:32 -0700194 private static final String KERNEL_WAKELOCK_DATA = "kwl";
Dianne Hackborna1bd7922014-03-21 11:07:11 -0700195 private static final String WAKEUP_REASON_DATA = "wr";
Evan Millare84de8d2009-04-02 22:16:12 -0700196 private static final String NETWORK_DATA = "nt";
197 private static final String USER_ACTIVITY_DATA = "ua";
198 private static final String BATTERY_DATA = "bt";
Dianne Hackbornc1b40e32011-01-05 18:27:40 -0800199 private static final String BATTERY_DISCHARGE_DATA = "dc";
Evan Millare84de8d2009-04-02 22:16:12 -0700200 private static final String BATTERY_LEVEL_DATA = "lv";
Adam Lesinskie283d332015-04-16 12:29:25 -0700201 private static final String GLOBAL_WIFI_DATA = "gwfl";
Nick Pelly6ccaa542012-06-15 15:22:47 -0700202 private static final String WIFI_DATA = "wfl";
Adam Lesinskie283d332015-04-16 12:29:25 -0700203 private static final String GLOBAL_BLUETOOTH_DATA = "gble";
Evan Millare84de8d2009-04-02 22:16:12 -0700204 private static final String MISC_DATA = "m";
Dianne Hackborn57ed6a62013-12-09 18:15:56 -0800205 private static final String GLOBAL_NETWORK_DATA = "gn";
Dianne Hackborn099bc622014-01-22 13:39:16 -0800206 private static final String HISTORY_STRING_POOL = "hsp";
Dianne Hackborn8a0de582013-08-07 15:22:07 -0700207 private static final String HISTORY_DATA = "h";
Evan Millare84de8d2009-04-02 22:16:12 -0700208 private static final String SCREEN_BRIGHTNESS_DATA = "br";
209 private static final String SIGNAL_STRENGTH_TIME_DATA = "sgt";
Amith Yamasanif37447b2009-10-08 18:28:01 -0700210 private static final String SIGNAL_SCANNING_TIME_DATA = "sst";
Evan Millare84de8d2009-04-02 22:16:12 -0700211 private static final String SIGNAL_STRENGTH_COUNT_DATA = "sgc";
212 private static final String DATA_CONNECTION_TIME_DATA = "dct";
213 private static final String DATA_CONNECTION_COUNT_DATA = "dcc";
Dianne Hackbornca1bf212014-02-14 14:18:36 -0800214 private static final String WIFI_STATE_TIME_DATA = "wst";
215 private static final String WIFI_STATE_COUNT_DATA = "wsc";
Dianne Hackborn3251b902014-06-20 14:40:53 -0700216 private static final String WIFI_SUPPL_STATE_TIME_DATA = "wsst";
217 private static final String WIFI_SUPPL_STATE_COUNT_DATA = "wssc";
218 private static final String WIFI_SIGNAL_STRENGTH_TIME_DATA = "wsgt";
219 private static final String WIFI_SIGNAL_STRENGTH_COUNT_DATA = "wsgc";
Dianne Hackborna7c837f2014-01-15 16:20:44 -0800220 private static final String POWER_USE_SUMMARY_DATA = "pws";
221 private static final String POWER_USE_ITEM_DATA = "pwi";
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -0700222 private static final String DISCHARGE_STEP_DATA = "dsd";
223 private static final String CHARGE_STEP_DATA = "csd";
Dianne Hackbornd06dcfd2014-05-02 13:49:30 -0700224 private static final String DISCHARGE_TIME_REMAIN_DATA = "dtr";
225 private static final String CHARGE_TIME_REMAIN_DATA = "ctr";
Ruben Brunk6d2c3632015-05-26 17:32:16 -0700226 private static final String FLASHLIGHT_DATA = "fla";
227 private static final String CAMERA_DATA = "cam";
228 private static final String VIDEO_DATA = "vid";
229 private static final String AUDIO_DATA = "aud";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800230
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700231 private final StringBuilder mFormatBuilder = new StringBuilder(32);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800232 private final Formatter mFormatter = new Formatter(mFormatBuilder);
233
234 /**
Dianne Hackborn617f8772009-03-31 15:04:46 -0700235 * State for keeping track of counting information.
236 */
237 public static abstract class Counter {
238
239 /**
240 * Returns the count associated with this Counter for the
241 * selected type of statistics.
242 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700243 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT
Dianne Hackborn617f8772009-03-31 15:04:46 -0700244 */
Evan Millarc64edde2009-04-18 12:26:32 -0700245 public abstract int getCountLocked(int which);
Dianne Hackborn617f8772009-03-31 15:04:46 -0700246
247 /**
248 * Temporary for debugging.
249 */
250 public abstract void logState(Printer pw, String prefix);
251 }
252
253 /**
Dianne Hackborna1bd7922014-03-21 11:07:11 -0700254 * State for keeping track of long counting information.
255 */
256 public static abstract class LongCounter {
257
258 /**
259 * Returns the count associated with this Counter for the
260 * selected type of statistics.
261 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700262 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT
Dianne Hackborna1bd7922014-03-21 11:07:11 -0700263 */
264 public abstract long getCountLocked(int which);
265
266 /**
267 * Temporary for debugging.
268 */
269 public abstract void logState(Printer pw, String prefix);
270 }
271
272 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800273 * State for keeping track of timing information.
274 */
275 public static abstract class Timer {
276
277 /**
278 * Returns the count associated with this Timer for the
279 * selected type of statistics.
280 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700281 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800282 */
Evan Millarc64edde2009-04-18 12:26:32 -0700283 public abstract int getCountLocked(int which);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800284
285 /**
286 * Returns the total time in microseconds associated with this Timer for the
287 * selected type of statistics.
288 *
Dianne Hackborn97ae5382014-03-05 16:43:25 -0800289 * @param elapsedRealtimeUs current elapsed realtime of system in microseconds
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700290 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800291 * @return a time in microseconds
292 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -0800293 public abstract long getTotalTimeLocked(long elapsedRealtimeUs, int which);
Amith Yamasani244fa5c2009-05-22 14:36:07 -0700294
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800295 /**
Adam Lesinskie08af192015-03-25 16:42:59 -0700296 * Returns the total time in microseconds associated with this Timer since the
297 * 'mark' was last set.
298 *
299 * @param elapsedRealtimeUs current elapsed realtime of system in microseconds
300 * @return a time in microseconds
301 */
302 public abstract long getTimeSinceMarkLocked(long elapsedRealtimeUs);
303
304 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800305 * Temporary for debugging.
306 */
Dianne Hackborn627bba72009-03-24 22:32:56 -0700307 public abstract void logState(Printer pw, String prefix);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800308 }
309
310 /**
311 * The statistics associated with a particular uid.
312 */
313 public static abstract class Uid {
314
315 /**
316 * Returns a mapping containing wakelock statistics.
317 *
318 * @return a Map from Strings to Uid.Wakelock objects.
319 */
Dianne Hackborn1e725a72015-03-24 18:23:19 -0700320 public abstract ArrayMap<String, ? extends Wakelock> getWakelockStats();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800321
322 /**
Dianne Hackbornfdb19562014-07-11 16:03:36 -0700323 * Returns a mapping containing sync statistics.
324 *
325 * @return a Map from Strings to Timer objects.
326 */
Dianne Hackborn1e725a72015-03-24 18:23:19 -0700327 public abstract ArrayMap<String, ? extends Timer> getSyncStats();
Dianne Hackbornfdb19562014-07-11 16:03:36 -0700328
329 /**
330 * Returns a mapping containing scheduled job statistics.
331 *
332 * @return a Map from Strings to Timer objects.
333 */
Dianne Hackborn1e725a72015-03-24 18:23:19 -0700334 public abstract ArrayMap<String, ? extends Timer> getJobStats();
Dianne Hackbornfdb19562014-07-11 16:03:36 -0700335
336 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800337 * The statistics associated with a particular wake lock.
338 */
339 public static abstract class Wakelock {
340 public abstract Timer getWakeTime(int type);
341 }
342
343 /**
344 * Returns a mapping containing sensor statistics.
345 *
346 * @return a Map from Integer sensor ids to Uid.Sensor objects.
347 */
Dianne Hackborn61659e52014-07-09 16:13:01 -0700348 public abstract SparseArray<? extends Sensor> getSensorStats();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800349
350 /**
Dianne Hackbornb5e31652010-09-07 12:13:55 -0700351 * Returns a mapping containing active process data.
352 */
353 public abstract SparseArray<? extends Pid> getPidStats();
354
355 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800356 * Returns a mapping containing process statistics.
357 *
358 * @return a Map from Strings to Uid.Proc objects.
359 */
Dianne Hackborn1e725a72015-03-24 18:23:19 -0700360 public abstract ArrayMap<String, ? extends Proc> getProcessStats();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800361
362 /**
363 * Returns a mapping containing package statistics.
364 *
365 * @return a Map from Strings to Uid.Pkg objects.
366 */
Dianne Hackborn1e725a72015-03-24 18:23:19 -0700367 public abstract ArrayMap<String, ? extends Pkg> getPackageStats();
Adam Lesinskie08af192015-03-25 16:42:59 -0700368
369 /**
370 * Returns the time in milliseconds that this app kept the WiFi controller in the
371 * specified state <code>type</code>.
372 * @param type one of {@link #CONTROLLER_IDLE_TIME}, {@link #CONTROLLER_RX_TIME}, or
373 * {@link #CONTROLLER_TX_TIME}.
374 * @param which one of {@link #STATS_CURRENT}, {@link #STATS_SINCE_CHARGED}, or
375 * {@link #STATS_SINCE_UNPLUGGED}.
376 */
377 public abstract long getWifiControllerActivity(int type, int which);
378
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800379 /**
380 * {@hide}
381 */
382 public abstract int getUid();
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -0700383
Dianne Hackbornca1bf212014-02-14 14:18:36 -0800384 public abstract void noteWifiRunningLocked(long elapsedRealtime);
385 public abstract void noteWifiStoppedLocked(long elapsedRealtime);
386 public abstract void noteFullWifiLockAcquiredLocked(long elapsedRealtime);
387 public abstract void noteFullWifiLockReleasedLocked(long elapsedRealtime);
388 public abstract void noteWifiScanStartedLocked(long elapsedRealtime);
389 public abstract void noteWifiScanStoppedLocked(long elapsedRealtime);
390 public abstract void noteWifiBatchedScanStartedLocked(int csph, long elapsedRealtime);
391 public abstract void noteWifiBatchedScanStoppedLocked(long elapsedRealtime);
392 public abstract void noteWifiMulticastEnabledLocked(long elapsedRealtime);
393 public abstract void noteWifiMulticastDisabledLocked(long elapsedRealtime);
Dianne Hackbornca1bf212014-02-14 14:18:36 -0800394 public abstract void noteActivityResumedLocked(long elapsedRealtime);
395 public abstract void noteActivityPausedLocked(long elapsedRealtime);
Dianne Hackborn97ae5382014-03-05 16:43:25 -0800396 public abstract long getWifiRunningTime(long elapsedRealtimeUs, int which);
397 public abstract long getFullWifiLockTime(long elapsedRealtimeUs, int which);
398 public abstract long getWifiScanTime(long elapsedRealtimeUs, int which);
Dianne Hackborn62793e42015-03-09 11:15:41 -0700399 public abstract int getWifiScanCount(int which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -0800400 public abstract long getWifiBatchedScanTime(int csphBin, long elapsedRealtimeUs, int which);
Dianne Hackborn62793e42015-03-09 11:15:41 -0700401 public abstract int getWifiBatchedScanCount(int csphBin, int which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -0800402 public abstract long getWifiMulticastTime(long elapsedRealtimeUs, int which);
Ruben Brunk6d2c3632015-05-26 17:32:16 -0700403 public abstract Timer getAudioTurnedOnTimer();
404 public abstract Timer getVideoTurnedOnTimer();
405 public abstract Timer getFlashlightTurnedOnTimer();
406 public abstract Timer getCameraTurnedOnTimer();
Jeff Sharkey3e013e82013-04-25 14:48:19 -0700407 public abstract Timer getForegroundActivityTimer();
Dianne Hackborn61659e52014-07-09 16:13:01 -0700408
409 // Time this uid has any processes in foreground state.
410 public static final int PROCESS_STATE_FOREGROUND = 0;
411 // Time this uid has any process in active state (not cached).
412 public static final int PROCESS_STATE_ACTIVE = 1;
413 // Time this uid has any processes running at all.
414 public static final int PROCESS_STATE_RUNNING = 2;
415 // Total number of process states we track.
416 public static final int NUM_PROCESS_STATE = 3;
417
418 static final String[] PROCESS_STATE_NAMES = {
419 "Foreground", "Active", "Running"
420 };
421
422 public abstract long getProcessStateTime(int state, long elapsedRealtimeUs, int which);
423
Dianne Hackborna06de0f2012-12-11 16:34:47 -0800424 public abstract Timer getVibratorOnTimer();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800425
Robert Greenwalta029ea12013-09-25 16:38:12 -0700426 public static final int NUM_WIFI_BATCHED_SCAN_BINS = 5;
427
Dianne Hackborn617f8772009-03-31 15:04:46 -0700428 /**
Jeff Browndf693de2012-07-27 12:03:38 -0700429 * Note that these must match the constants in android.os.PowerManager.
430 * Also, if the user activity types change, the BatteryStatsImpl.VERSION must
431 * also be bumped.
Dianne Hackborn617f8772009-03-31 15:04:46 -0700432 */
433 static final String[] USER_ACTIVITY_TYPES = {
Jeff Browndf693de2012-07-27 12:03:38 -0700434 "other", "button", "touch"
Dianne Hackborn617f8772009-03-31 15:04:46 -0700435 };
436
Jeff Browndf693de2012-07-27 12:03:38 -0700437 public static final int NUM_USER_ACTIVITY_TYPES = 3;
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -0700438
Dianne Hackborn617f8772009-03-31 15:04:46 -0700439 public abstract void noteUserActivityLocked(int type);
440 public abstract boolean hasUserActivity();
441 public abstract int getUserActivityCount(int type, int which);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -0700442
443 public abstract boolean hasNetworkActivity();
Dianne Hackborn57ed6a62013-12-09 18:15:56 -0800444 public abstract long getNetworkActivityBytes(int type, int which);
445 public abstract long getNetworkActivityPackets(int type, int which);
Dianne Hackbornd45665b2014-02-26 12:35:32 -0800446 public abstract long getMobileRadioActiveTime(int which);
447 public abstract int getMobileRadioActiveCount(int which);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -0700448
Adam Lesinski06af1fa2015-05-05 17:35:35 -0700449 /**
450 * Get the total cpu time (in microseconds) this UID had processes executing in userspace.
451 */
452 public abstract long getUserCpuTimeUs(int which);
453
454 /**
455 * Get the total cpu time (in microseconds) this UID had processes executing kernel syscalls.
456 */
457 public abstract long getSystemCpuTimeUs(int which);
458
459 /**
460 * Returns the approximate cpu time (in milliseconds) spent at a certain CPU speed.
461 * @param speedStep the index of the CPU speed. This is not the actual speed of the CPU.
462 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
463 * @see BatteryStats#getCpuSpeedSteps()
464 */
465 public abstract long getTimeAtCpuSpeed(int step, int which);
466
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800467 public static abstract class Sensor {
Mathias Agopian7f84c062013-02-04 19:22:47 -0800468 /*
469 * FIXME: it's not correct to use this magic value because it
470 * could clash with a sensor handle (which are defined by
471 * the sensor HAL, and therefore out of our control
472 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800473 // Magic sensor number for the GPS.
474 public static final int GPS = -10000;
475
476 public abstract int getHandle();
477
478 public abstract Timer getSensorTime();
479 }
480
Dianne Hackbornb5e31652010-09-07 12:13:55 -0700481 public class Pid {
Dianne Hackborne5167ca2014-03-08 14:39:10 -0800482 public int mWakeNesting;
483 public long mWakeSumMs;
484 public long mWakeStartMs;
Dianne Hackbornb5e31652010-09-07 12:13:55 -0700485 }
486
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800487 /**
488 * The statistics associated with a particular process.
489 */
490 public static abstract class Proc {
491
Dianne Hackborn287952c2010-09-22 22:34:31 -0700492 public static class ExcessivePower {
493 public static final int TYPE_WAKE = 1;
494 public static final int TYPE_CPU = 2;
495
496 public int type;
Dianne Hackborn9adb9c32010-08-13 14:09:56 -0700497 public long overTime;
498 public long usedTime;
499 }
500
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800501 /**
Dianne Hackborn099bc622014-01-22 13:39:16 -0800502 * Returns true if this process is still active in the battery stats.
503 */
504 public abstract boolean isActive();
505
506 /**
Adam Lesinski33dac552015-03-09 15:24:48 -0700507 * Returns the total time (in milliseconds) spent executing in user code.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800508 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700509 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800510 */
511 public abstract long getUserTime(int which);
512
513 /**
Adam Lesinski33dac552015-03-09 15:24:48 -0700514 * Returns the total time (in milliseconds) spent executing in system code.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800515 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700516 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800517 */
518 public abstract long getSystemTime(int which);
519
520 /**
521 * Returns the number of times the process has been started.
522 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700523 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800524 */
525 public abstract int getStarts(int which);
Amith Yamasanieaeb6632009-06-03 15:16:10 -0700526
527 /**
Dianne Hackborn1e01d162014-12-04 17:46:42 -0800528 * Returns the number of times the process has crashed.
529 *
530 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
531 */
532 public abstract int getNumCrashes(int which);
533
534 /**
535 * Returns the number of times the process has ANRed.
536 *
537 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
538 */
539 public abstract int getNumAnrs(int which);
540
541 /**
Adam Lesinski33dac552015-03-09 15:24:48 -0700542 * Returns the cpu time (milliseconds) spent while the process was in the foreground.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700543 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
Amith Yamasanieaeb6632009-06-03 15:16:10 -0700544 * @return foreground cpu time in microseconds
545 */
546 public abstract long getForegroundTime(int which);
Amith Yamasanie43530a2009-08-21 13:11:37 -0700547
Dianne Hackborn287952c2010-09-22 22:34:31 -0700548 public abstract int countExcessivePowers();
Dianne Hackborn9adb9c32010-08-13 14:09:56 -0700549
Dianne Hackborn287952c2010-09-22 22:34:31 -0700550 public abstract ExcessivePower getExcessivePower(int i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800551 }
552
553 /**
554 * The statistics associated with a particular package.
555 */
556 public static abstract class Pkg {
557
558 /**
Dianne Hackborn1e725a72015-03-24 18:23:19 -0700559 * Returns information about all wakeup alarms that have been triggered for this
560 * package. The mapping keys are tag names for the alarms, the counter contains
561 * the number of times the alarm was triggered while on battery.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800562 */
Dianne Hackborn1e725a72015-03-24 18:23:19 -0700563 public abstract ArrayMap<String, ? extends Counter> getWakeupAlarmStats();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800564
565 /**
566 * Returns a mapping containing service statistics.
567 */
Dianne Hackborn1e725a72015-03-24 18:23:19 -0700568 public abstract ArrayMap<String, ? extends Serv> getServiceStats();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800569
570 /**
571 * The statistics associated with a particular service.
572 */
573 public abstract class Serv {
574
575 /**
576 * Returns the amount of time spent started.
577 *
578 * @param batteryUptime elapsed uptime on battery in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700579 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800580 * @return
581 */
582 public abstract long getStartTime(long batteryUptime, int which);
583
584 /**
585 * Returns the total number of times startService() has been called.
586 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700587 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800588 */
589 public abstract int getStarts(int which);
590
591 /**
592 * Returns the total number times the service has been launched.
593 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700594 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800595 */
596 public abstract int getLaunches(int which);
597 }
598 }
599 }
600
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800601 public static final class LevelStepTracker {
602 public long mLastStepTime = -1;
603 public int mNumStepDurations;
604 public final long[] mStepDurations;
605
606 public LevelStepTracker(int maxLevelSteps) {
607 mStepDurations = new long[maxLevelSteps];
608 }
609
610 public LevelStepTracker(int numSteps, long[] steps) {
611 mNumStepDurations = numSteps;
612 mStepDurations = new long[numSteps];
613 System.arraycopy(steps, 0, mStepDurations, 0, numSteps);
614 }
615
616 public long getDurationAt(int index) {
617 return mStepDurations[index] & STEP_LEVEL_TIME_MASK;
618 }
619
620 public int getLevelAt(int index) {
621 return (int)((mStepDurations[index] & STEP_LEVEL_LEVEL_MASK)
622 >> STEP_LEVEL_LEVEL_SHIFT);
623 }
624
625 public int getInitModeAt(int index) {
626 return (int)((mStepDurations[index] & STEP_LEVEL_INITIAL_MODE_MASK)
627 >> STEP_LEVEL_INITIAL_MODE_SHIFT);
628 }
629
630 public int getModModeAt(int index) {
631 return (int)((mStepDurations[index] & STEP_LEVEL_MODIFIED_MODE_MASK)
632 >> STEP_LEVEL_MODIFIED_MODE_SHIFT);
633 }
634
635 private void appendHex(long val, int topOffset, StringBuilder out) {
636 boolean hasData = false;
637 while (topOffset >= 0) {
638 int digit = (int)( (val>>topOffset) & 0xf );
639 topOffset -= 4;
640 if (!hasData && digit == 0) {
641 continue;
642 }
643 hasData = true;
644 if (digit >= 0 && digit <= 9) {
645 out.append((char)('0' + digit));
646 } else {
647 out.append((char)('a' + digit - 10));
648 }
649 }
650 }
651
652 public void encodeEntryAt(int index, StringBuilder out) {
653 long item = mStepDurations[index];
654 long duration = item & STEP_LEVEL_TIME_MASK;
655 int level = (int)((item & STEP_LEVEL_LEVEL_MASK)
656 >> STEP_LEVEL_LEVEL_SHIFT);
657 int initMode = (int)((item & STEP_LEVEL_INITIAL_MODE_MASK)
658 >> STEP_LEVEL_INITIAL_MODE_SHIFT);
659 int modMode = (int)((item & STEP_LEVEL_MODIFIED_MODE_MASK)
660 >> STEP_LEVEL_MODIFIED_MODE_SHIFT);
661 switch ((initMode&STEP_LEVEL_MODE_SCREEN_STATE) + 1) {
662 case Display.STATE_OFF: out.append('f'); break;
663 case Display.STATE_ON: out.append('o'); break;
664 case Display.STATE_DOZE: out.append('d'); break;
665 case Display.STATE_DOZE_SUSPEND: out.append('z'); break;
666 }
667 if ((initMode&STEP_LEVEL_MODE_POWER_SAVE) != 0) {
668 out.append('p');
669 }
Dianne Hackborn88e98df2015-03-23 13:29:14 -0700670 if ((initMode&STEP_LEVEL_MODE_DEVICE_IDLE) != 0) {
671 out.append('i');
672 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800673 switch ((modMode&STEP_LEVEL_MODE_SCREEN_STATE) + 1) {
674 case Display.STATE_OFF: out.append('F'); break;
675 case Display.STATE_ON: out.append('O'); break;
676 case Display.STATE_DOZE: out.append('D'); break;
677 case Display.STATE_DOZE_SUSPEND: out.append('Z'); break;
678 }
679 if ((modMode&STEP_LEVEL_MODE_POWER_SAVE) != 0) {
680 out.append('P');
681 }
Dianne Hackborn88e98df2015-03-23 13:29:14 -0700682 if ((modMode&STEP_LEVEL_MODE_DEVICE_IDLE) != 0) {
683 out.append('I');
684 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800685 out.append('-');
686 appendHex(level, 4, out);
687 out.append('-');
688 appendHex(duration, STEP_LEVEL_LEVEL_SHIFT-4, out);
689 }
690
691 public void decodeEntryAt(int index, String value) {
692 final int N = value.length();
693 int i = 0;
694 char c;
695 long out = 0;
696 while (i < N && (c=value.charAt(i)) != '-') {
697 i++;
698 switch (c) {
Dianne Hackborn8cfb58b2015-03-04 13:28:36 -0800699 case 'f': out |= (((long)Display.STATE_OFF-1)<<STEP_LEVEL_INITIAL_MODE_SHIFT);
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800700 break;
Dianne Hackborn8cfb58b2015-03-04 13:28:36 -0800701 case 'o': out |= (((long)Display.STATE_ON-1)<<STEP_LEVEL_INITIAL_MODE_SHIFT);
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800702 break;
Dianne Hackborn8cfb58b2015-03-04 13:28:36 -0800703 case 'd': out |= (((long)Display.STATE_DOZE-1)<<STEP_LEVEL_INITIAL_MODE_SHIFT);
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800704 break;
Dianne Hackborn8cfb58b2015-03-04 13:28:36 -0800705 case 'z': out |= (((long)Display.STATE_DOZE_SUSPEND-1)
706 << STEP_LEVEL_INITIAL_MODE_SHIFT);
707 break;
708 case 'p': out |= (((long)STEP_LEVEL_MODE_POWER_SAVE)
709 << STEP_LEVEL_INITIAL_MODE_SHIFT);
710 break;
Dianne Hackborn88e98df2015-03-23 13:29:14 -0700711 case 'i': out |= (((long)STEP_LEVEL_MODE_DEVICE_IDLE)
712 << STEP_LEVEL_INITIAL_MODE_SHIFT);
713 break;
Dianne Hackborn8cfb58b2015-03-04 13:28:36 -0800714 case 'F': out |= (((long)Display.STATE_OFF-1)<<STEP_LEVEL_MODIFIED_MODE_SHIFT);
715 break;
716 case 'O': out |= (((long)Display.STATE_ON-1)<<STEP_LEVEL_MODIFIED_MODE_SHIFT);
717 break;
718 case 'D': out |= (((long)Display.STATE_DOZE-1)<<STEP_LEVEL_MODIFIED_MODE_SHIFT);
719 break;
720 case 'Z': out |= (((long)Display.STATE_DOZE_SUSPEND-1)
721 << STEP_LEVEL_MODIFIED_MODE_SHIFT);
722 break;
723 case 'P': out |= (((long)STEP_LEVEL_MODE_POWER_SAVE)
724 << STEP_LEVEL_MODIFIED_MODE_SHIFT);
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800725 break;
Dianne Hackborn88e98df2015-03-23 13:29:14 -0700726 case 'I': out |= (((long)STEP_LEVEL_MODE_DEVICE_IDLE)
727 << STEP_LEVEL_MODIFIED_MODE_SHIFT);
728 break;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800729 }
730 }
731 i++;
Dianne Hackborn8cfb58b2015-03-04 13:28:36 -0800732 long level = 0;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800733 while (i < N && (c=value.charAt(i)) != '-') {
734 i++;
735 level <<= 4;
736 if (c >= '0' && c <= '9') {
737 level += c - '0';
738 } else if (c >= 'a' && c <= 'f') {
739 level += c - 'a' + 10;
740 } else if (c >= 'A' && c <= 'F') {
741 level += c - 'A' + 10;
742 }
743 }
Dianne Hackborn8cfb58b2015-03-04 13:28:36 -0800744 i++;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800745 out |= (level << STEP_LEVEL_LEVEL_SHIFT) & STEP_LEVEL_LEVEL_MASK;
746 long duration = 0;
747 while (i < N && (c=value.charAt(i)) != '-') {
748 i++;
749 duration <<= 4;
750 if (c >= '0' && c <= '9') {
751 duration += c - '0';
752 } else if (c >= 'a' && c <= 'f') {
753 duration += c - 'a' + 10;
754 } else if (c >= 'A' && c <= 'F') {
755 duration += c - 'A' + 10;
756 }
757 }
758 mStepDurations[index] = out | (duration & STEP_LEVEL_TIME_MASK);
759 }
760
761 public void init() {
762 mLastStepTime = -1;
763 mNumStepDurations = 0;
764 }
765
766 public void clearTime() {
767 mLastStepTime = -1;
768 }
769
770 public long computeTimePerLevel() {
771 final long[] steps = mStepDurations;
772 final int numSteps = mNumStepDurations;
773
774 // For now we'll do a simple average across all steps.
775 if (numSteps <= 0) {
776 return -1;
777 }
778 long total = 0;
779 for (int i=0; i<numSteps; i++) {
780 total += steps[i] & STEP_LEVEL_TIME_MASK;
781 }
782 return total / numSteps;
783 /*
784 long[] buckets = new long[numSteps];
785 int numBuckets = 0;
786 int numToAverage = 4;
787 int i = 0;
788 while (i < numSteps) {
789 long totalTime = 0;
790 int num = 0;
791 for (int j=0; j<numToAverage && (i+j)<numSteps; j++) {
792 totalTime += steps[i+j] & STEP_LEVEL_TIME_MASK;
793 num++;
794 }
795 buckets[numBuckets] = totalTime / num;
796 numBuckets++;
797 numToAverage *= 2;
798 i += num;
799 }
800 if (numBuckets < 1) {
801 return -1;
802 }
803 long averageTime = buckets[numBuckets-1];
804 for (i=numBuckets-2; i>=0; i--) {
805 averageTime = (averageTime + buckets[i]) / 2;
806 }
807 return averageTime;
808 */
809 }
810
811 public long computeTimeEstimate(long modesOfInterest, long modeValues,
812 int[] outNumOfInterest) {
813 final long[] steps = mStepDurations;
814 final int count = mNumStepDurations;
815 if (count <= 0) {
816 return -1;
817 }
818 long total = 0;
819 int numOfInterest = 0;
820 for (int i=0; i<count; i++) {
821 long initMode = (steps[i] & STEP_LEVEL_INITIAL_MODE_MASK)
822 >> STEP_LEVEL_INITIAL_MODE_SHIFT;
823 long modMode = (steps[i] & STEP_LEVEL_MODIFIED_MODE_MASK)
824 >> STEP_LEVEL_MODIFIED_MODE_SHIFT;
825 // If the modes of interest didn't change during this step period...
826 if ((modMode&modesOfInterest) == 0) {
827 // And the mode values during this period match those we are measuring...
828 if ((initMode&modesOfInterest) == modeValues) {
829 // Then this can be used to estimate the total time!
830 numOfInterest++;
831 total += steps[i] & STEP_LEVEL_TIME_MASK;
832 }
833 }
834 }
835 if (numOfInterest <= 0) {
836 return -1;
837 }
838
839 if (outNumOfInterest != null) {
840 outNumOfInterest[0] = numOfInterest;
841 }
842
843 // The estimated time is the average time we spend in each level, multipled
844 // by 100 -- the total number of battery levels
845 return (total / numOfInterest) * 100;
846 }
847
848 public void addLevelSteps(int numStepLevels, long modeBits, long elapsedRealtime) {
849 int stepCount = mNumStepDurations;
850 final long lastStepTime = mLastStepTime;
851 if (lastStepTime >= 0 && numStepLevels > 0) {
852 final long[] steps = mStepDurations;
853 long duration = elapsedRealtime - lastStepTime;
854 for (int i=0; i<numStepLevels; i++) {
855 System.arraycopy(steps, 0, steps, 1, steps.length-1);
856 long thisDuration = duration / (numStepLevels-i);
857 duration -= thisDuration;
858 if (thisDuration > STEP_LEVEL_TIME_MASK) {
859 thisDuration = STEP_LEVEL_TIME_MASK;
860 }
861 steps[0] = thisDuration | modeBits;
862 }
863 stepCount += numStepLevels;
864 if (stepCount > steps.length) {
865 stepCount = steps.length;
866 }
867 }
868 mNumStepDurations = stepCount;
869 mLastStepTime = elapsedRealtime;
870 }
871
872 public void readFromParcel(Parcel in) {
873 final int N = in.readInt();
874 mNumStepDurations = N;
875 for (int i=0; i<N; i++) {
876 mStepDurations[i] = in.readLong();
877 }
878 }
879
880 public void writeToParcel(Parcel out) {
881 final int N = mNumStepDurations;
882 out.writeInt(N);
883 for (int i=0; i<N; i++) {
884 out.writeLong(mStepDurations[i]);
885 }
886 }
887 }
888
Dianne Hackborn88e98df2015-03-23 13:29:14 -0700889 public static final class PackageChange {
890 public String mPackageName;
891 public boolean mUpdate;
892 public int mVersionCode;
893 }
894
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800895 public static final class DailyItem {
896 public long mStartTime;
897 public long mEndTime;
898 public LevelStepTracker mDischargeSteps;
899 public LevelStepTracker mChargeSteps;
Dianne Hackborn88e98df2015-03-23 13:29:14 -0700900 public ArrayList<PackageChange> mPackageChanges;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800901 }
902
903 public abstract DailyItem getDailyItemLocked(int daysAgo);
904
905 public abstract long getCurrentDailyStartTime();
906
907 public abstract long getNextMinDailyDeadline();
908
909 public abstract long getNextMaxDailyDeadline();
910
Dianne Hackborn71fc13e2014-02-03 10:50:53 -0800911 public final static class HistoryTag {
912 public String string;
913 public int uid;
914
915 public int poolIdx;
916
917 public void setTo(HistoryTag o) {
918 string = o.string;
919 uid = o.uid;
920 poolIdx = o.poolIdx;
921 }
922
923 public void setTo(String _string, int _uid) {
924 string = _string;
925 uid = _uid;
926 poolIdx = -1;
927 }
928
929 public void writeToParcel(Parcel dest, int flags) {
930 dest.writeString(string);
931 dest.writeInt(uid);
932 }
933
934 public void readFromParcel(Parcel src) {
935 string = src.readString();
936 uid = src.readInt();
937 poolIdx = -1;
938 }
939
940 @Override
941 public boolean equals(Object o) {
942 if (this == o) return true;
943 if (o == null || getClass() != o.getClass()) return false;
944
945 HistoryTag that = (HistoryTag) o;
946
947 if (uid != that.uid) return false;
948 if (!string.equals(that.string)) return false;
949
950 return true;
951 }
952
953 @Override
954 public int hashCode() {
955 int result = string.hashCode();
956 result = 31 * result + uid;
957 return result;
958 }
959 }
960
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -0800961 /**
962 * Optional detailed information that can go into a history step. This is typically
963 * generated each time the battery level changes.
964 */
965 public final static class HistoryStepDetails {
966 // Time (in 1/100 second) spent in user space and the kernel since the last step.
967 public int userTime;
968 public int systemTime;
969
970 // Top three apps using CPU in the last step, with times in 1/100 second.
971 public int appCpuUid1;
972 public int appCpuUTime1;
973 public int appCpuSTime1;
974 public int appCpuUid2;
975 public int appCpuUTime2;
976 public int appCpuSTime2;
977 public int appCpuUid3;
978 public int appCpuUTime3;
979 public int appCpuSTime3;
980
981 // Information from /proc/stat
982 public int statUserTime;
983 public int statSystemTime;
984 public int statIOWaitTime;
985 public int statIrqTime;
986 public int statSoftIrqTime;
987 public int statIdlTime;
988
989 public HistoryStepDetails() {
990 clear();
991 }
992
993 public void clear() {
994 userTime = systemTime = 0;
995 appCpuUid1 = appCpuUid2 = appCpuUid3 = -1;
996 appCpuUTime1 = appCpuSTime1 = appCpuUTime2 = appCpuSTime2
997 = appCpuUTime3 = appCpuSTime3 = 0;
998 }
999
1000 public void writeToParcel(Parcel out) {
1001 out.writeInt(userTime);
1002 out.writeInt(systemTime);
1003 out.writeInt(appCpuUid1);
1004 out.writeInt(appCpuUTime1);
1005 out.writeInt(appCpuSTime1);
1006 out.writeInt(appCpuUid2);
1007 out.writeInt(appCpuUTime2);
1008 out.writeInt(appCpuSTime2);
1009 out.writeInt(appCpuUid3);
1010 out.writeInt(appCpuUTime3);
1011 out.writeInt(appCpuSTime3);
1012 out.writeInt(statUserTime);
1013 out.writeInt(statSystemTime);
1014 out.writeInt(statIOWaitTime);
1015 out.writeInt(statIrqTime);
1016 out.writeInt(statSoftIrqTime);
1017 out.writeInt(statIdlTime);
1018 }
1019
1020 public void readFromParcel(Parcel in) {
1021 userTime = in.readInt();
1022 systemTime = in.readInt();
1023 appCpuUid1 = in.readInt();
1024 appCpuUTime1 = in.readInt();
1025 appCpuSTime1 = in.readInt();
1026 appCpuUid2 = in.readInt();
1027 appCpuUTime2 = in.readInt();
1028 appCpuSTime2 = in.readInt();
1029 appCpuUid3 = in.readInt();
1030 appCpuUTime3 = in.readInt();
1031 appCpuSTime3 = in.readInt();
1032 statUserTime = in.readInt();
1033 statSystemTime = in.readInt();
1034 statIOWaitTime = in.readInt();
1035 statIrqTime = in.readInt();
1036 statSoftIrqTime = in.readInt();
1037 statIdlTime = in.readInt();
1038 }
1039 }
1040
Dianne Hackbornce2ef762010-09-20 11:39:14 -07001041 public final static class HistoryItem implements Parcelable {
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001042 public HistoryItem next;
Dianne Hackborn9a755432014-05-15 17:05:22 -07001043
1044 // The time of this event in milliseconds, as per SystemClock.elapsedRealtime().
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001045 public long time;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001046
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001047 public static final byte CMD_UPDATE = 0; // These can be written as deltas
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001048 public static final byte CMD_NULL = -1;
1049 public static final byte CMD_START = 4;
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001050 public static final byte CMD_CURRENT_TIME = 5;
1051 public static final byte CMD_OVERFLOW = 6;
Dianne Hackborn37de0982014-05-09 09:32:18 -07001052 public static final byte CMD_RESET = 7;
Dianne Hackborn29cd7f12015-01-08 10:37:05 -08001053 public static final byte CMD_SHUTDOWN = 8;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001054
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001055 public byte cmd = CMD_NULL;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001056
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001057 /**
1058 * Return whether the command code is a delta data update.
1059 */
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001060 public boolean isDeltaData() {
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001061 return cmd == CMD_UPDATE;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001062 }
1063
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001064 public byte batteryLevel;
1065 public byte batteryStatus;
1066 public byte batteryHealth;
1067 public byte batteryPlugType;
1068
Sungmin Choic7e9e8b2013-01-16 12:57:36 +09001069 public short batteryTemperature;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001070 public char batteryVoltage;
1071
Dianne Hackborn3bee5af82010-07-23 00:22:04 -07001072 // Constants from SCREEN_BRIGHTNESS_*
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001073 public static final int STATE_BRIGHTNESS_SHIFT = 0;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001074 public static final int STATE_BRIGHTNESS_MASK = 0x7;
Dianne Hackborn3bee5af82010-07-23 00:22:04 -07001075 // Constants from SIGNAL_STRENGTH_*
Dianne Hackborn3251b902014-06-20 14:40:53 -07001076 public static final int STATE_PHONE_SIGNAL_STRENGTH_SHIFT = 3;
1077 public static final int STATE_PHONE_SIGNAL_STRENGTH_MASK = 0x7 << STATE_PHONE_SIGNAL_STRENGTH_SHIFT;
Dianne Hackborn3bee5af82010-07-23 00:22:04 -07001078 // Constants from ServiceState.STATE_*
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001079 public static final int STATE_PHONE_STATE_SHIFT = 6;
1080 public static final int STATE_PHONE_STATE_MASK = 0x7 << STATE_PHONE_STATE_SHIFT;
Dianne Hackborn3bee5af82010-07-23 00:22:04 -07001081 // Constants from DATA_CONNECTION_*
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001082 public static final int STATE_DATA_CONNECTION_SHIFT = 9;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001083 public static final int STATE_DATA_CONNECTION_MASK = 0x1f << STATE_DATA_CONNECTION_SHIFT;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001084
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001085 // These states always appear directly in the first int token
1086 // of a delta change; they should be ones that change relatively
1087 // frequently.
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001088 public static final int STATE_CPU_RUNNING_FLAG = 1<<31;
1089 public static final int STATE_WAKE_LOCK_FLAG = 1<<30;
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001090 public static final int STATE_GPS_ON_FLAG = 1<<29;
1091 public static final int STATE_WIFI_FULL_LOCK_FLAG = 1<<28;
Dianne Hackborne13c4c02014-02-11 17:18:35 -08001092 public static final int STATE_WIFI_SCAN_FLAG = 1<<27;
Dianne Hackborn0c820db2015-04-14 17:47:34 -07001093 public static final int STATE_WIFI_RADIO_ACTIVE_FLAG = 1<<26;
Dianne Hackborne13c4c02014-02-11 17:18:35 -08001094 public static final int STATE_MOBILE_RADIO_ACTIVE_FLAG = 1<<25;
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001095 // These are on the lower bits used for the command; if they change
1096 // we need to write another int of data.
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001097 public static final int STATE_SENSOR_ON_FLAG = 1<<23;
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001098 public static final int STATE_AUDIO_ON_FLAG = 1<<22;
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001099 public static final int STATE_PHONE_SCANNING_FLAG = 1<<21;
Dianne Hackborn0c820db2015-04-14 17:47:34 -07001100 public static final int STATE_SCREEN_ON_FLAG = 1<<20; // consider moving to states2
1101 public static final int STATE_BATTERY_PLUGGED_FLAG = 1<<19; // consider moving to states2
1102 // empty slot
1103 // empty slot
1104 public static final int STATE_WIFI_MULTICAST_ON_FLAG = 1<<16;
Dianne Hackborn40c87252014-03-19 16:55:40 -07001105
Dianne Hackbornf47d8f22010-10-08 10:46:55 -07001106 public static final int MOST_INTERESTING_STATES =
Dianne Hackborn0c820db2015-04-14 17:47:34 -07001107 STATE_BATTERY_PLUGGED_FLAG | STATE_SCREEN_ON_FLAG;
1108
1109 public static final int SETTLE_TO_ZERO_STATES = 0xffff0000 & ~MOST_INTERESTING_STATES;
Dianne Hackbornf47d8f22010-10-08 10:46:55 -07001110
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001111 public int states;
1112
Dianne Hackborn3251b902014-06-20 14:40:53 -07001113 // Constants from WIFI_SUPPL_STATE_*
1114 public static final int STATE2_WIFI_SUPPL_STATE_SHIFT = 0;
1115 public static final int STATE2_WIFI_SUPPL_STATE_MASK = 0xf;
1116 // Values for NUM_WIFI_SIGNAL_STRENGTH_BINS
1117 public static final int STATE2_WIFI_SIGNAL_STRENGTH_SHIFT = 4;
1118 public static final int STATE2_WIFI_SIGNAL_STRENGTH_MASK =
1119 0x7 << STATE2_WIFI_SIGNAL_STRENGTH_SHIFT;
1120
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001121 public static final int STATE2_POWER_SAVE_FLAG = 1<<31;
Dianne Hackborn3251b902014-06-20 14:40:53 -07001122 public static final int STATE2_VIDEO_ON_FLAG = 1<<30;
1123 public static final int STATE2_WIFI_RUNNING_FLAG = 1<<29;
1124 public static final int STATE2_WIFI_ON_FLAG = 1<<28;
Dianne Hackbornabc7c492014-06-30 16:57:46 -07001125 public static final int STATE2_FLASHLIGHT_FLAG = 1<<27;
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001126 public static final int STATE2_DEVICE_IDLE_FLAG = 1<<26;
Dianne Hackborn0c820db2015-04-14 17:47:34 -07001127 public static final int STATE2_CHARGING_FLAG = 1<<25;
1128 public static final int STATE2_PHONE_IN_CALL_FLAG = 1<<24;
1129 public static final int STATE2_BLUETOOTH_ON_FLAG = 1<<23;
Ruben Brunk6d2c3632015-05-26 17:32:16 -07001130 public static final int STATE2_CAMERA_FLAG = 1<<22;
Dianne Hackborn3251b902014-06-20 14:40:53 -07001131
1132 public static final int MOST_INTERESTING_STATES2 =
Dianne Hackborn0c820db2015-04-14 17:47:34 -07001133 STATE2_POWER_SAVE_FLAG | STATE2_WIFI_ON_FLAG | STATE2_DEVICE_IDLE_FLAG
1134 | STATE2_CHARGING_FLAG | STATE2_PHONE_IN_CALL_FLAG | STATE2_BLUETOOTH_ON_FLAG;
1135
1136 public static final int SETTLE_TO_ZERO_STATES2 = 0xffff0000 & ~MOST_INTERESTING_STATES2;
Dianne Hackborn3251b902014-06-20 14:40:53 -07001137
Dianne Hackborn40c87252014-03-19 16:55:40 -07001138 public int states2;
1139
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001140 // The wake lock that was acquired at this point.
1141 public HistoryTag wakelockTag;
1142
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001143 // Kernel wakeup reason at this point.
1144 public HistoryTag wakeReasonTag;
1145
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08001146 // Non-null when there is more detailed information at this step.
1147 public HistoryStepDetails stepDetails;
1148
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08001149 public static final int EVENT_FLAG_START = 0x8000;
1150 public static final int EVENT_FLAG_FINISH = 0x4000;
1151
1152 // No event in this item.
1153 public static final int EVENT_NONE = 0x0000;
1154 // Event is about a process that is running.
1155 public static final int EVENT_PROC = 0x0001;
1156 // Event is about an application package that is in the foreground.
1157 public static final int EVENT_FOREGROUND = 0x0002;
1158 // Event is about an application package that is at the top of the screen.
1159 public static final int EVENT_TOP = 0x0003;
Dianne Hackbornfdb19562014-07-11 16:03:36 -07001160 // Event is about active sync operations.
Dianne Hackborna1f1a3c2014-02-24 18:12:28 -08001161 public static final int EVENT_SYNC = 0x0004;
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07001162 // Events for all additional wake locks aquired/release within a wake block.
1163 // These are not generated by default.
1164 public static final int EVENT_WAKE_LOCK = 0x0005;
Dianne Hackbornfdb19562014-07-11 16:03:36 -07001165 // Event is about an application executing a scheduled job.
1166 public static final int EVENT_JOB = 0x0006;
1167 // Events for users running.
1168 public static final int EVENT_USER_RUNNING = 0x0007;
1169 // Events for foreground user.
1170 public static final int EVENT_USER_FOREGROUND = 0x0008;
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001171 // Event for connectivity changed.
Dianne Hackborn1e01d162014-12-04 17:46:42 -08001172 public static final int EVENT_CONNECTIVITY_CHANGED = 0x0009;
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001173 // Event for becoming active taking us out of idle mode.
Dianne Hackbornb6683c42015-06-18 17:40:33 -07001174 public static final int EVENT_ACTIVE = 0x000a;
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001175 // Event for a package being installed.
Dianne Hackbornb6683c42015-06-18 17:40:33 -07001176 public static final int EVENT_PACKAGE_INSTALLED = 0x000b;
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001177 // Event for a package being uninstalled.
Dianne Hackbornb6683c42015-06-18 17:40:33 -07001178 public static final int EVENT_PACKAGE_UNINSTALLED = 0x000c;
Dianne Hackborn1e383822015-04-10 14:02:33 -07001179 // Event for a package being uninstalled.
Dianne Hackbornb6683c42015-06-18 17:40:33 -07001180 public static final int EVENT_ALARM = 0x000d;
Dianne Hackborn0c820db2015-04-14 17:47:34 -07001181 // Record that we have decided we need to collect new stats data.
Dianne Hackbornb6683c42015-06-18 17:40:33 -07001182 public static final int EVENT_COLLECT_EXTERNAL_STATS = 0x000e;
Amith Yamasani67768492015-06-09 12:23:58 -07001183 // Event for a package becoming inactive due to being unused for a period of time.
Dianne Hackbornb6683c42015-06-18 17:40:33 -07001184 public static final int EVENT_PACKAGE_INACTIVE = 0x000f;
Amith Yamasani67768492015-06-09 12:23:58 -07001185 // Event for a package becoming active due to an interaction.
Dianne Hackbornb6683c42015-06-18 17:40:33 -07001186 public static final int EVENT_PACKAGE_ACTIVE = 0x0010;
Amith Yamasani67768492015-06-09 12:23:58 -07001187
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08001188 // Number of event types.
Dianne Hackbornb6683c42015-06-18 17:40:33 -07001189 public static final int EVENT_COUNT = 0x0011;
Dianne Hackborn37de0982014-05-09 09:32:18 -07001190 // Mask to extract out only the type part of the event.
1191 public static final int EVENT_TYPE_MASK = ~(EVENT_FLAG_START|EVENT_FLAG_FINISH);
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08001192
1193 public static final int EVENT_PROC_START = EVENT_PROC | EVENT_FLAG_START;
1194 public static final int EVENT_PROC_FINISH = EVENT_PROC | EVENT_FLAG_FINISH;
1195 public static final int EVENT_FOREGROUND_START = EVENT_FOREGROUND | EVENT_FLAG_START;
1196 public static final int EVENT_FOREGROUND_FINISH = EVENT_FOREGROUND | EVENT_FLAG_FINISH;
1197 public static final int EVENT_TOP_START = EVENT_TOP | EVENT_FLAG_START;
1198 public static final int EVENT_TOP_FINISH = EVENT_TOP | EVENT_FLAG_FINISH;
Dianne Hackborna1f1a3c2014-02-24 18:12:28 -08001199 public static final int EVENT_SYNC_START = EVENT_SYNC | EVENT_FLAG_START;
1200 public static final int EVENT_SYNC_FINISH = EVENT_SYNC | EVENT_FLAG_FINISH;
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07001201 public static final int EVENT_WAKE_LOCK_START = EVENT_WAKE_LOCK | EVENT_FLAG_START;
1202 public static final int EVENT_WAKE_LOCK_FINISH = EVENT_WAKE_LOCK | EVENT_FLAG_FINISH;
Dianne Hackbornfdb19562014-07-11 16:03:36 -07001203 public static final int EVENT_JOB_START = EVENT_JOB | EVENT_FLAG_START;
1204 public static final int EVENT_JOB_FINISH = EVENT_JOB | EVENT_FLAG_FINISH;
1205 public static final int EVENT_USER_RUNNING_START = EVENT_USER_RUNNING | EVENT_FLAG_START;
1206 public static final int EVENT_USER_RUNNING_FINISH = EVENT_USER_RUNNING | EVENT_FLAG_FINISH;
1207 public static final int EVENT_USER_FOREGROUND_START =
1208 EVENT_USER_FOREGROUND | EVENT_FLAG_START;
1209 public static final int EVENT_USER_FOREGROUND_FINISH =
1210 EVENT_USER_FOREGROUND | EVENT_FLAG_FINISH;
Dianne Hackborn1e383822015-04-10 14:02:33 -07001211 public static final int EVENT_ALARM_START = EVENT_ALARM | EVENT_FLAG_START;
1212 public static final int EVENT_ALARM_FINISH = EVENT_ALARM | EVENT_FLAG_FINISH;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001213
1214 // For CMD_EVENT.
1215 public int eventCode;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001216 public HistoryTag eventTag;
1217
Dianne Hackborn9a755432014-05-15 17:05:22 -07001218 // Only set for CMD_CURRENT_TIME or CMD_RESET, as per System.currentTimeMillis().
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001219 public long currentTime;
1220
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001221 // Meta-data when reading.
1222 public int numReadInts;
1223
1224 // Pre-allocated objects.
1225 public final HistoryTag localWakelockTag = new HistoryTag();
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001226 public final HistoryTag localWakeReasonTag = new HistoryTag();
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001227 public final HistoryTag localEventTag = new HistoryTag();
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001228
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001229 public HistoryItem() {
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001230 }
1231
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001232 public HistoryItem(long time, Parcel src) {
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001233 this.time = time;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001234 numReadInts = 2;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07001235 readFromParcel(src);
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001236 }
1237
1238 public int describeContents() {
1239 return 0;
1240 }
1241
1242 public void writeToParcel(Parcel dest, int flags) {
1243 dest.writeLong(time);
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001244 int bat = (((int)cmd)&0xff)
1245 | ((((int)batteryLevel)<<8)&0xff00)
1246 | ((((int)batteryStatus)<<16)&0xf0000)
1247 | ((((int)batteryHealth)<<20)&0xf00000)
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001248 | ((((int)batteryPlugType)<<24)&0xf000000)
1249 | (wakelockTag != null ? 0x10000000 : 0)
1250 | (wakeReasonTag != null ? 0x20000000 : 0)
1251 | (eventCode != EVENT_NONE ? 0x40000000 : 0);
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001252 dest.writeInt(bat);
1253 bat = (((int)batteryTemperature)&0xffff)
1254 | ((((int)batteryVoltage)<<16)&0xffff0000);
1255 dest.writeInt(bat);
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001256 dest.writeInt(states);
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001257 dest.writeInt(states2);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001258 if (wakelockTag != null) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001259 wakelockTag.writeToParcel(dest, flags);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001260 }
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001261 if (wakeReasonTag != null) {
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001262 wakeReasonTag.writeToParcel(dest, flags);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001263 }
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001264 if (eventCode != EVENT_NONE) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001265 dest.writeInt(eventCode);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001266 eventTag.writeToParcel(dest, flags);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001267 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07001268 if (cmd == CMD_CURRENT_TIME || cmd == CMD_RESET) {
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001269 dest.writeLong(currentTime);
1270 }
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001271 }
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07001272
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001273 public void readFromParcel(Parcel src) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001274 int start = src.dataPosition();
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07001275 int bat = src.readInt();
1276 cmd = (byte)(bat&0xff);
1277 batteryLevel = (byte)((bat>>8)&0xff);
1278 batteryStatus = (byte)((bat>>16)&0xf);
1279 batteryHealth = (byte)((bat>>20)&0xf);
1280 batteryPlugType = (byte)((bat>>24)&0xf);
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001281 int bat2 = src.readInt();
1282 batteryTemperature = (short)(bat2&0xffff);
1283 batteryVoltage = (char)((bat2>>16)&0xffff);
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07001284 states = src.readInt();
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001285 states2 = src.readInt();
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001286 if ((bat&0x10000000) != 0) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001287 wakelockTag = localWakelockTag;
1288 wakelockTag.readFromParcel(src);
1289 } else {
1290 wakelockTag = null;
1291 }
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001292 if ((bat&0x20000000) != 0) {
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001293 wakeReasonTag = localWakeReasonTag;
1294 wakeReasonTag.readFromParcel(src);
1295 } else {
1296 wakeReasonTag = null;
1297 }
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001298 if ((bat&0x40000000) != 0) {
1299 eventCode = src.readInt();
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001300 eventTag = localEventTag;
1301 eventTag.readFromParcel(src);
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001302 } else {
1303 eventCode = EVENT_NONE;
1304 eventTag = null;
1305 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07001306 if (cmd == CMD_CURRENT_TIME || cmd == CMD_RESET) {
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001307 currentTime = src.readLong();
1308 } else {
1309 currentTime = 0;
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001310 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001311 numReadInts += (src.dataPosition()-start)/4;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07001312 }
1313
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001314 public void clear() {
1315 time = 0;
1316 cmd = CMD_NULL;
1317 batteryLevel = 0;
1318 batteryStatus = 0;
1319 batteryHealth = 0;
1320 batteryPlugType = 0;
1321 batteryTemperature = 0;
1322 batteryVoltage = 0;
1323 states = 0;
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001324 states2 = 0;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001325 wakelockTag = null;
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001326 wakeReasonTag = null;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001327 eventCode = EVENT_NONE;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001328 eventTag = null;
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001329 }
1330
Dianne Hackbornce2ef762010-09-20 11:39:14 -07001331 public void setTo(HistoryItem o) {
1332 time = o.time;
1333 cmd = o.cmd;
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001334 setToCommon(o);
1335 }
1336
1337 public void setTo(long time, byte cmd, HistoryItem o) {
1338 this.time = time;
1339 this.cmd = cmd;
1340 setToCommon(o);
1341 }
1342
1343 private void setToCommon(HistoryItem o) {
Dianne Hackbornce2ef762010-09-20 11:39:14 -07001344 batteryLevel = o.batteryLevel;
1345 batteryStatus = o.batteryStatus;
1346 batteryHealth = o.batteryHealth;
1347 batteryPlugType = o.batteryPlugType;
1348 batteryTemperature = o.batteryTemperature;
1349 batteryVoltage = o.batteryVoltage;
1350 states = o.states;
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001351 states2 = o.states2;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001352 if (o.wakelockTag != null) {
1353 wakelockTag = localWakelockTag;
1354 wakelockTag.setTo(o.wakelockTag);
1355 } else {
1356 wakelockTag = null;
1357 }
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001358 if (o.wakeReasonTag != null) {
1359 wakeReasonTag = localWakeReasonTag;
1360 wakeReasonTag.setTo(o.wakeReasonTag);
1361 } else {
1362 wakeReasonTag = null;
1363 }
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001364 eventCode = o.eventCode;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001365 if (o.eventTag != null) {
1366 eventTag = localEventTag;
1367 eventTag.setTo(o.eventTag);
1368 } else {
1369 eventTag = null;
1370 }
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001371 currentTime = o.currentTime;
Dianne Hackbornce2ef762010-09-20 11:39:14 -07001372 }
1373
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001374 public boolean sameNonEvent(HistoryItem o) {
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07001375 return batteryLevel == o.batteryLevel
1376 && batteryStatus == o.batteryStatus
1377 && batteryHealth == o.batteryHealth
1378 && batteryPlugType == o.batteryPlugType
1379 && batteryTemperature == o.batteryTemperature
1380 && batteryVoltage == o.batteryVoltage
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001381 && states == o.states
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001382 && states2 == o.states2
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001383 && currentTime == o.currentTime;
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07001384 }
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001385
1386 public boolean same(HistoryItem o) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001387 if (!sameNonEvent(o) || eventCode != o.eventCode) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001388 return false;
1389 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001390 if (wakelockTag != o.wakelockTag) {
1391 if (wakelockTag == null || o.wakelockTag == null) {
1392 return false;
1393 }
1394 if (!wakelockTag.equals(o.wakelockTag)) {
1395 return false;
1396 }
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001397 }
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001398 if (wakeReasonTag != o.wakeReasonTag) {
1399 if (wakeReasonTag == null || o.wakeReasonTag == null) {
1400 return false;
1401 }
1402 if (!wakeReasonTag.equals(o.wakeReasonTag)) {
1403 return false;
1404 }
1405 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001406 if (eventTag != o.eventTag) {
1407 if (eventTag == null || o.eventTag == null) {
1408 return false;
1409 }
1410 if (!eventTag.equals(o.eventTag)) {
1411 return false;
1412 }
1413 }
1414 return true;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001415 }
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001416 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07001417
1418 public final static class HistoryEventTracker {
1419 private final HashMap<String, SparseIntArray>[] mActiveEvents
1420 = (HashMap<String, SparseIntArray>[]) new HashMap[HistoryItem.EVENT_COUNT];
1421
1422 public boolean updateState(int code, String name, int uid, int poolIdx) {
1423 if ((code&HistoryItem.EVENT_FLAG_START) != 0) {
1424 int idx = code&HistoryItem.EVENT_TYPE_MASK;
1425 HashMap<String, SparseIntArray> active = mActiveEvents[idx];
1426 if (active == null) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07001427 active = new HashMap<>();
Dianne Hackborn37de0982014-05-09 09:32:18 -07001428 mActiveEvents[idx] = active;
1429 }
1430 SparseIntArray uids = active.get(name);
1431 if (uids == null) {
1432 uids = new SparseIntArray();
1433 active.put(name, uids);
1434 }
1435 if (uids.indexOfKey(uid) >= 0) {
1436 // Already set, nothing to do!
1437 return false;
1438 }
1439 uids.put(uid, poolIdx);
1440 } else if ((code&HistoryItem.EVENT_FLAG_FINISH) != 0) {
1441 int idx = code&HistoryItem.EVENT_TYPE_MASK;
1442 HashMap<String, SparseIntArray> active = mActiveEvents[idx];
1443 if (active == null) {
1444 // not currently active, nothing to do.
1445 return false;
1446 }
1447 SparseIntArray uids = active.get(name);
1448 if (uids == null) {
1449 // not currently active, nothing to do.
1450 return false;
1451 }
1452 idx = uids.indexOfKey(uid);
1453 if (idx < 0) {
1454 // not currently active, nothing to do.
1455 return false;
1456 }
1457 uids.removeAt(idx);
1458 if (uids.size() <= 0) {
1459 active.remove(name);
1460 }
1461 }
1462 return true;
1463 }
1464
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07001465 public void removeEvents(int code) {
1466 int idx = code&HistoryItem.EVENT_TYPE_MASK;
1467 mActiveEvents[idx] = null;
1468 }
1469
Dianne Hackborn37de0982014-05-09 09:32:18 -07001470 public HashMap<String, SparseIntArray> getStateForEvent(int code) {
1471 return mActiveEvents[code];
1472 }
1473 }
1474
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001475 public static final class BitDescription {
1476 public final int mask;
1477 public final int shift;
1478 public final String name;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001479 public final String shortName;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001480 public final String[] values;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001481 public final String[] shortValues;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001482
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001483 public BitDescription(int mask, String name, String shortName) {
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001484 this.mask = mask;
1485 this.shift = -1;
1486 this.name = name;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001487 this.shortName = shortName;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001488 this.values = null;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001489 this.shortValues = null;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001490 }
1491
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001492 public BitDescription(int mask, int shift, String name, String shortName,
1493 String[] values, String[] shortValues) {
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001494 this.mask = mask;
1495 this.shift = shift;
1496 this.name = name;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001497 this.shortName = shortName;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001498 this.values = values;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001499 this.shortValues = shortValues;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001500 }
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001501 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07001502
Dianne Hackbornfc064132014-06-02 12:42:12 -07001503 /**
1504 * Don't allow any more batching in to the current history event. This
1505 * is called when printing partial histories, so to ensure that the next
1506 * history event will go in to a new batch after what was printed in the
1507 * last partial history.
1508 */
1509 public abstract void commitCurrentHistoryBatchLocked();
1510
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001511 public abstract int getHistoryTotalSize();
1512
1513 public abstract int getHistoryUsedSize();
1514
Dianne Hackbornce2ef762010-09-20 11:39:14 -07001515 public abstract boolean startIteratingHistoryLocked();
1516
Dianne Hackborn099bc622014-01-22 13:39:16 -08001517 public abstract int getHistoryStringPoolSize();
1518
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001519 public abstract int getHistoryStringPoolBytes();
1520
1521 public abstract String getHistoryTagPoolString(int index);
1522
1523 public abstract int getHistoryTagPoolUid(int index);
Dianne Hackborn099bc622014-01-22 13:39:16 -08001524
Dianne Hackbornce2ef762010-09-20 11:39:14 -07001525 public abstract boolean getNextHistoryLocked(HistoryItem out);
1526
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07001527 public abstract void finishIteratingHistoryLocked();
1528
1529 public abstract boolean startIteratingOldHistoryLocked();
1530
1531 public abstract boolean getNextOldHistoryLocked(HistoryItem out);
1532
1533 public abstract void finishIteratingOldHistoryLocked();
1534
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001535 /**
Dianne Hackbornb5e31652010-09-07 12:13:55 -07001536 * Return the base time offset for the battery history.
1537 */
1538 public abstract long getHistoryBaseTime();
1539
1540 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001541 * Returns the number of times the device has been started.
1542 */
1543 public abstract int getStartCount();
1544
1545 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07001546 * 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 -08001547 * running on battery.
1548 *
1549 * {@hide}
1550 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001551 public abstract long getScreenOnTime(long elapsedRealtimeUs, int which);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001552
Dianne Hackborn77b987f2014-02-26 16:20:52 -08001553 /**
1554 * Returns the number of times the screen was turned on.
1555 *
1556 * {@hide}
1557 */
1558 public abstract int getScreenOnCount(int which);
1559
Jeff Browne95c3cd2014-05-02 16:59:26 -07001560 public abstract long getInteractiveTime(long elapsedRealtimeUs, int which);
1561
Dianne Hackborn617f8772009-03-31 15:04:46 -07001562 public static final int SCREEN_BRIGHTNESS_DARK = 0;
1563 public static final int SCREEN_BRIGHTNESS_DIM = 1;
1564 public static final int SCREEN_BRIGHTNESS_MEDIUM = 2;
1565 public static final int SCREEN_BRIGHTNESS_LIGHT = 3;
1566 public static final int SCREEN_BRIGHTNESS_BRIGHT = 4;
1567
1568 static final String[] SCREEN_BRIGHTNESS_NAMES = {
1569 "dark", "dim", "medium", "light", "bright"
1570 };
1571
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001572 static final String[] SCREEN_BRIGHTNESS_SHORT_NAMES = {
1573 "0", "1", "2", "3", "4"
1574 };
1575
Dianne Hackborn617f8772009-03-31 15:04:46 -07001576 public static final int NUM_SCREEN_BRIGHTNESS_BINS = 5;
Dianne Hackborn3251b902014-06-20 14:40:53 -07001577
Dianne Hackborn617f8772009-03-31 15:04:46 -07001578 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07001579 * Returns the time in microseconds that the screen has been on with
Dianne Hackborn617f8772009-03-31 15:04:46 -07001580 * the given brightness
1581 *
1582 * {@hide}
1583 */
1584 public abstract long getScreenBrightnessTime(int brightnessBin,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001585 long elapsedRealtimeUs, int which);
Dianne Hackborn617f8772009-03-31 15:04:46 -07001586
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001587 /**
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001588 * Returns the time in microseconds that power save mode has been enabled while the device was
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07001589 * running on battery.
1590 *
1591 * {@hide}
1592 */
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001593 public abstract long getPowerSaveModeEnabledTime(long elapsedRealtimeUs, int which);
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07001594
1595 /**
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001596 * Returns the number of times that power save mode was enabled.
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07001597 *
1598 * {@hide}
1599 */
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001600 public abstract int getPowerSaveModeEnabledCount(int which);
1601
1602 /**
1603 * Returns the time in microseconds that device has been in idle mode while
1604 * running on battery.
1605 *
1606 * {@hide}
1607 */
1608 public abstract long getDeviceIdleModeEnabledTime(long elapsedRealtimeUs, int which);
1609
1610 /**
1611 * Returns the number of times that the devie has gone in to idle mode.
1612 *
1613 * {@hide}
1614 */
1615 public abstract int getDeviceIdleModeEnabledCount(int which);
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07001616
1617 /**
Dianne Hackborn88e98df2015-03-23 13:29:14 -07001618 * Returns the time in microseconds that device has been in idling while on
1619 * battery. This is broader than {@link #getDeviceIdleModeEnabledTime} -- it
1620 * counts all of the time that we consider the device to be idle, whether or not
1621 * it is currently in the actual device idle mode.
1622 *
1623 * {@hide}
1624 */
1625 public abstract long getDeviceIdlingTime(long elapsedRealtimeUs, int which);
1626
1627 /**
1628 * Returns the number of times that the devie has started idling.
1629 *
1630 * {@hide}
1631 */
1632 public abstract int getDeviceIdlingCount(int which);
1633
1634 /**
Dianne Hackborn1e01d162014-12-04 17:46:42 -08001635 * Returns the number of times that connectivity state changed.
1636 *
1637 * {@hide}
1638 */
1639 public abstract int getNumConnectivityChange(int which);
1640
1641 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07001642 * 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 -08001643 * running on battery.
1644 *
1645 * {@hide}
1646 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001647 public abstract long getPhoneOnTime(long elapsedRealtimeUs, int which);
Dianne Hackborn627bba72009-03-24 22:32:56 -07001648
1649 /**
Dianne Hackborn77b987f2014-02-26 16:20:52 -08001650 * Returns the number of times a phone call was activated.
1651 *
1652 * {@hide}
1653 */
1654 public abstract int getPhoneOnCount(int which);
1655
1656 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07001657 * Returns the time in microseconds that the phone has been running with
Dianne Hackborn627bba72009-03-24 22:32:56 -07001658 * the given signal strength.
1659 *
1660 * {@hide}
1661 */
1662 public abstract long getPhoneSignalStrengthTime(int strengthBin,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001663 long elapsedRealtimeUs, int which);
Dianne Hackborn627bba72009-03-24 22:32:56 -07001664
Dianne Hackborn617f8772009-03-31 15:04:46 -07001665 /**
Amith Yamasanif37447b2009-10-08 18:28:01 -07001666 * Returns the time in microseconds that the phone has been trying to
1667 * acquire a signal.
1668 *
1669 * {@hide}
1670 */
1671 public abstract long getPhoneSignalScanningTime(
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001672 long elapsedRealtimeUs, int which);
Amith Yamasanif37447b2009-10-08 18:28:01 -07001673
1674 /**
Dianne Hackborn617f8772009-03-31 15:04:46 -07001675 * Returns the number of times the phone has entered the given signal strength.
1676 *
1677 * {@hide}
1678 */
1679 public abstract int getPhoneSignalStrengthCount(int strengthBin, int which);
1680
Dianne Hackborne13c4c02014-02-11 17:18:35 -08001681 /**
1682 * Returns the time in microseconds that the mobile network has been active
1683 * (in a high power state).
1684 *
1685 * {@hide}
1686 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001687 public abstract long getMobileRadioActiveTime(long elapsedRealtimeUs, int which);
Dianne Hackborne13c4c02014-02-11 17:18:35 -08001688
Dianne Hackbornd45665b2014-02-26 12:35:32 -08001689 /**
1690 * Returns the number of times that the mobile network has transitioned to the
1691 * active state.
1692 *
1693 * {@hide}
1694 */
1695 public abstract int getMobileRadioActiveCount(int which);
1696
1697 /**
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001698 * Returns the time in microseconds that is the difference between the mobile radio
1699 * time we saw based on the elapsed timestamp when going down vs. the given time stamp
1700 * from the radio.
1701 *
1702 * {@hide}
1703 */
1704 public abstract long getMobileRadioActiveAdjustedTime(int which);
1705
1706 /**
Dianne Hackbornd45665b2014-02-26 12:35:32 -08001707 * Returns the time in microseconds that the mobile network has been active
1708 * (in a high power state) but not being able to blame on an app.
1709 *
1710 * {@hide}
1711 */
1712 public abstract long getMobileRadioActiveUnknownTime(int which);
1713
1714 /**
Dianne Hackborn77b987f2014-02-26 16:20:52 -08001715 * Return count of number of times radio was up that could not be blamed on apps.
Dianne Hackbornd45665b2014-02-26 12:35:32 -08001716 *
1717 * {@hide}
1718 */
1719 public abstract int getMobileRadioActiveUnknownCount(int which);
Dianne Hackborne13c4c02014-02-11 17:18:35 -08001720
Dianne Hackborn627bba72009-03-24 22:32:56 -07001721 public static final int DATA_CONNECTION_NONE = 0;
1722 public static final int DATA_CONNECTION_GPRS = 1;
1723 public static final int DATA_CONNECTION_EDGE = 2;
1724 public static final int DATA_CONNECTION_UMTS = 3;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001725 public static final int DATA_CONNECTION_CDMA = 4;
1726 public static final int DATA_CONNECTION_EVDO_0 = 5;
1727 public static final int DATA_CONNECTION_EVDO_A = 6;
1728 public static final int DATA_CONNECTION_1xRTT = 7;
1729 public static final int DATA_CONNECTION_HSDPA = 8;
1730 public static final int DATA_CONNECTION_HSUPA = 9;
1731 public static final int DATA_CONNECTION_HSPA = 10;
1732 public static final int DATA_CONNECTION_IDEN = 11;
1733 public static final int DATA_CONNECTION_EVDO_B = 12;
Robert Greenwalt962a9902010-11-02 11:10:25 -07001734 public static final int DATA_CONNECTION_LTE = 13;
1735 public static final int DATA_CONNECTION_EHRPD = 14;
Patrick Tjinb71703c2013-11-06 09:27:03 -08001736 public static final int DATA_CONNECTION_HSPAP = 15;
1737 public static final int DATA_CONNECTION_OTHER = 16;
Robert Greenwalt962a9902010-11-02 11:10:25 -07001738
Dianne Hackborn627bba72009-03-24 22:32:56 -07001739 static final String[] DATA_CONNECTION_NAMES = {
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001740 "none", "gprs", "edge", "umts", "cdma", "evdo_0", "evdo_A",
Robert Greenwalt962a9902010-11-02 11:10:25 -07001741 "1xrtt", "hsdpa", "hsupa", "hspa", "iden", "evdo_b", "lte",
Patrick Tjinb71703c2013-11-06 09:27:03 -08001742 "ehrpd", "hspap", "other"
Dianne Hackborn627bba72009-03-24 22:32:56 -07001743 };
1744
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001745 public static final int NUM_DATA_CONNECTION_TYPES = DATA_CONNECTION_OTHER+1;
Dianne Hackborn627bba72009-03-24 22:32:56 -07001746
1747 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07001748 * Returns the time in microseconds that the phone has been running with
Dianne Hackborn627bba72009-03-24 22:32:56 -07001749 * the given data connection.
1750 *
1751 * {@hide}
1752 */
1753 public abstract long getPhoneDataConnectionTime(int dataType,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001754 long elapsedRealtimeUs, int which);
Dianne Hackborn627bba72009-03-24 22:32:56 -07001755
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001756 /**
Dianne Hackborn617f8772009-03-31 15:04:46 -07001757 * Returns the number of times the phone has entered the given data
1758 * connection type.
1759 *
1760 * {@hide}
1761 */
1762 public abstract int getPhoneDataConnectionCount(int dataType, int which);
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001763
Dianne Hackborn3251b902014-06-20 14:40:53 -07001764 public static final int WIFI_SUPPL_STATE_INVALID = 0;
1765 public static final int WIFI_SUPPL_STATE_DISCONNECTED = 1;
1766 public static final int WIFI_SUPPL_STATE_INTERFACE_DISABLED = 2;
1767 public static final int WIFI_SUPPL_STATE_INACTIVE = 3;
1768 public static final int WIFI_SUPPL_STATE_SCANNING = 4;
1769 public static final int WIFI_SUPPL_STATE_AUTHENTICATING = 5;
1770 public static final int WIFI_SUPPL_STATE_ASSOCIATING = 6;
1771 public static final int WIFI_SUPPL_STATE_ASSOCIATED = 7;
1772 public static final int WIFI_SUPPL_STATE_FOUR_WAY_HANDSHAKE = 8;
1773 public static final int WIFI_SUPPL_STATE_GROUP_HANDSHAKE = 9;
1774 public static final int WIFI_SUPPL_STATE_COMPLETED = 10;
1775 public static final int WIFI_SUPPL_STATE_DORMANT = 11;
1776 public static final int WIFI_SUPPL_STATE_UNINITIALIZED = 12;
1777
1778 public static final int NUM_WIFI_SUPPL_STATES = WIFI_SUPPL_STATE_UNINITIALIZED+1;
1779
1780 static final String[] WIFI_SUPPL_STATE_NAMES = {
1781 "invalid", "disconn", "disabled", "inactive", "scanning",
1782 "authenticating", "associating", "associated", "4-way-handshake",
1783 "group-handshake", "completed", "dormant", "uninit"
1784 };
1785
1786 static final String[] WIFI_SUPPL_STATE_SHORT_NAMES = {
1787 "inv", "dsc", "dis", "inact", "scan",
1788 "auth", "ascing", "asced", "4-way",
1789 "group", "compl", "dorm", "uninit"
1790 };
1791
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001792 public static final BitDescription[] HISTORY_STATE_DESCRIPTIONS
1793 = new BitDescription[] {
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001794 new BitDescription(HistoryItem.STATE_CPU_RUNNING_FLAG, "running", "r"),
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001795 new BitDescription(HistoryItem.STATE_WAKE_LOCK_FLAG, "wake_lock", "w"),
1796 new BitDescription(HistoryItem.STATE_SENSOR_ON_FLAG, "sensor", "s"),
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001797 new BitDescription(HistoryItem.STATE_GPS_ON_FLAG, "gps", "g"),
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001798 new BitDescription(HistoryItem.STATE_WIFI_FULL_LOCK_FLAG, "wifi_full_lock", "Wl"),
1799 new BitDescription(HistoryItem.STATE_WIFI_SCAN_FLAG, "wifi_scan", "Ws"),
1800 new BitDescription(HistoryItem.STATE_WIFI_MULTICAST_ON_FLAG, "wifi_multicast", "Wm"),
Dianne Hackborn0c820db2015-04-14 17:47:34 -07001801 new BitDescription(HistoryItem.STATE_WIFI_RADIO_ACTIVE_FLAG, "wifi_radio", "Wr"),
Dianne Hackborne13c4c02014-02-11 17:18:35 -08001802 new BitDescription(HistoryItem.STATE_MOBILE_RADIO_ACTIVE_FLAG, "mobile_radio", "Pr"),
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001803 new BitDescription(HistoryItem.STATE_PHONE_SCANNING_FLAG, "phone_scanning", "Psc"),
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001804 new BitDescription(HistoryItem.STATE_AUDIO_ON_FLAG, "audio", "a"),
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001805 new BitDescription(HistoryItem.STATE_SCREEN_ON_FLAG, "screen", "S"),
1806 new BitDescription(HistoryItem.STATE_BATTERY_PLUGGED_FLAG, "plugged", "BP"),
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001807 new BitDescription(HistoryItem.STATE_DATA_CONNECTION_MASK,
1808 HistoryItem.STATE_DATA_CONNECTION_SHIFT, "data_conn", "Pcn",
1809 DATA_CONNECTION_NAMES, DATA_CONNECTION_NAMES),
1810 new BitDescription(HistoryItem.STATE_PHONE_STATE_MASK,
1811 HistoryItem.STATE_PHONE_STATE_SHIFT, "phone_state", "Pst",
1812 new String[] {"in", "out", "emergency", "off"},
1813 new String[] {"in", "out", "em", "off"}),
Dianne Hackborn3251b902014-06-20 14:40:53 -07001814 new BitDescription(HistoryItem.STATE_PHONE_SIGNAL_STRENGTH_MASK,
1815 HistoryItem.STATE_PHONE_SIGNAL_STRENGTH_SHIFT, "phone_signal_strength", "Pss",
1816 SignalStrength.SIGNAL_STRENGTH_NAMES,
1817 new String[] { "0", "1", "2", "3", "4" }),
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001818 new BitDescription(HistoryItem.STATE_BRIGHTNESS_MASK,
1819 HistoryItem.STATE_BRIGHTNESS_SHIFT, "brightness", "Sb",
1820 SCREEN_BRIGHTNESS_NAMES, SCREEN_BRIGHTNESS_SHORT_NAMES),
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001821 };
Dianne Hackborn617f8772009-03-31 15:04:46 -07001822
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001823 public static final BitDescription[] HISTORY_STATE2_DESCRIPTIONS
1824 = new BitDescription[] {
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001825 new BitDescription(HistoryItem.STATE2_POWER_SAVE_FLAG, "power_save", "ps"),
Dianne Hackborn3251b902014-06-20 14:40:53 -07001826 new BitDescription(HistoryItem.STATE2_VIDEO_ON_FLAG, "video", "v"),
Dianne Hackborn0c820db2015-04-14 17:47:34 -07001827 new BitDescription(HistoryItem.STATE2_WIFI_RUNNING_FLAG, "wifi_running", "Ww"),
Dianne Hackborn3251b902014-06-20 14:40:53 -07001828 new BitDescription(HistoryItem.STATE2_WIFI_ON_FLAG, "wifi", "W"),
Dianne Hackbornabc7c492014-06-30 16:57:46 -07001829 new BitDescription(HistoryItem.STATE2_FLASHLIGHT_FLAG, "flashlight", "fl"),
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001830 new BitDescription(HistoryItem.STATE2_DEVICE_IDLE_FLAG, "device_idle", "di"),
Dianne Hackborn0c820db2015-04-14 17:47:34 -07001831 new BitDescription(HistoryItem.STATE2_CHARGING_FLAG, "charging", "ch"),
1832 new BitDescription(HistoryItem.STATE2_PHONE_IN_CALL_FLAG, "phone_in_call", "Pcl"),
1833 new BitDescription(HistoryItem.STATE2_BLUETOOTH_ON_FLAG, "bluetooth", "b"),
Dianne Hackborn3251b902014-06-20 14:40:53 -07001834 new BitDescription(HistoryItem.STATE2_WIFI_SIGNAL_STRENGTH_MASK,
1835 HistoryItem.STATE2_WIFI_SIGNAL_STRENGTH_SHIFT, "wifi_signal_strength", "Wss",
1836 new String[] { "0", "1", "2", "3", "4" },
1837 new String[] { "0", "1", "2", "3", "4" }),
1838 new BitDescription(HistoryItem.STATE2_WIFI_SUPPL_STATE_MASK,
1839 HistoryItem.STATE2_WIFI_SUPPL_STATE_SHIFT, "wifi_suppl", "Wsp",
1840 WIFI_SUPPL_STATE_NAMES, WIFI_SUPPL_STATE_SHORT_NAMES),
Ruben Brunk6d2c3632015-05-26 17:32:16 -07001841 new BitDescription(HistoryItem.STATE2_CAMERA_FLAG, "camera", "ca"),
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001842 };
1843
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08001844 public static final String[] HISTORY_EVENT_NAMES = new String[] {
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001845 "null", "proc", "fg", "top", "sync", "wake_lock_in", "job", "user", "userfg", "conn",
Dianne Hackbornb6683c42015-06-18 17:40:33 -07001846 "active", "pkginst", "pkgunin", "alarm", "stats", "inactive", "active"
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08001847 };
1848
1849 public static final String[] HISTORY_EVENT_CHECKIN_NAMES = new String[] {
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001850 "Enl", "Epr", "Efg", "Etp", "Esy", "Ewl", "Ejb", "Eur", "Euf", "Ecn",
Dianne Hackbornb6683c42015-06-18 17:40:33 -07001851 "Eac", "Epi", "Epu", "Eal", "Est", "Eai", "Eaa"
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08001852 };
1853
Dianne Hackborn617f8772009-03-31 15:04:46 -07001854 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07001855 * Returns the time in microseconds that wifi has been on while the device was
The Android Open Source Project10592532009-03-18 17:39:46 -07001856 * running on battery.
1857 *
1858 * {@hide}
1859 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001860 public abstract long getWifiOnTime(long elapsedRealtimeUs, int which);
Eric Shienbroodd4c5f892009-03-24 18:13:20 -07001861
1862 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07001863 * Returns the time in microseconds that wifi has been on and the driver has
Eric Shienbroodd4c5f892009-03-24 18:13:20 -07001864 * been in the running state while the device was running on battery.
1865 *
1866 * {@hide}
1867 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001868 public abstract long getGlobalWifiRunningTime(long elapsedRealtimeUs, int which);
Eric Shienbroodd4c5f892009-03-24 18:13:20 -07001869
Dianne Hackbornca1bf212014-02-14 14:18:36 -08001870 public static final int WIFI_STATE_OFF = 0;
1871 public static final int WIFI_STATE_OFF_SCANNING = 1;
1872 public static final int WIFI_STATE_ON_NO_NETWORKS = 2;
1873 public static final int WIFI_STATE_ON_DISCONNECTED = 3;
1874 public static final int WIFI_STATE_ON_CONNECTED_STA = 4;
1875 public static final int WIFI_STATE_ON_CONNECTED_P2P = 5;
1876 public static final int WIFI_STATE_ON_CONNECTED_STA_P2P = 6;
1877 public static final int WIFI_STATE_SOFT_AP = 7;
1878
1879 static final String[] WIFI_STATE_NAMES = {
1880 "off", "scanning", "no_net", "disconn",
1881 "sta", "p2p", "sta_p2p", "soft_ap"
1882 };
1883
1884 public static final int NUM_WIFI_STATES = WIFI_STATE_SOFT_AP+1;
1885
1886 /**
1887 * Returns the time in microseconds that WiFi has been running in the given state.
1888 *
1889 * {@hide}
1890 */
1891 public abstract long getWifiStateTime(int wifiState,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001892 long elapsedRealtimeUs, int which);
Dianne Hackbornca1bf212014-02-14 14:18:36 -08001893
1894 /**
1895 * Returns the number of times that WiFi has entered the given state.
1896 *
1897 * {@hide}
1898 */
1899 public abstract int getWifiStateCount(int wifiState, int which);
1900
The Android Open Source Project10592532009-03-18 17:39:46 -07001901 /**
Dianne Hackborn3251b902014-06-20 14:40:53 -07001902 * Returns the time in microseconds that the wifi supplicant has been
1903 * in a given state.
1904 *
1905 * {@hide}
1906 */
1907 public abstract long getWifiSupplStateTime(int state, long elapsedRealtimeUs, int which);
1908
1909 /**
1910 * Returns the number of times that the wifi supplicant has transitioned
1911 * to a given state.
1912 *
1913 * {@hide}
1914 */
1915 public abstract int getWifiSupplStateCount(int state, int which);
1916
1917 public static final int NUM_WIFI_SIGNAL_STRENGTH_BINS = 5;
1918
1919 /**
1920 * Returns the time in microseconds that WIFI has been running with
1921 * the given signal strength.
1922 *
1923 * {@hide}
1924 */
1925 public abstract long getWifiSignalStrengthTime(int strengthBin,
1926 long elapsedRealtimeUs, int which);
1927
1928 /**
1929 * Returns the number of times WIFI has entered the given signal strength.
1930 *
1931 * {@hide}
1932 */
1933 public abstract int getWifiSignalStrengthCount(int strengthBin, int which);
1934
1935 /**
Dianne Hackbornabc7c492014-06-30 16:57:46 -07001936 * Returns the time in microseconds that the flashlight has been on while the device was
1937 * running on battery.
1938 *
1939 * {@hide}
1940 */
1941 public abstract long getFlashlightOnTime(long elapsedRealtimeUs, int which);
1942
1943 /**
1944 * Returns the number of times that the flashlight has been turned on while the device was
1945 * running on battery.
1946 *
1947 * {@hide}
1948 */
1949 public abstract long getFlashlightOnCount(int which);
1950
Ruben Brunk5b1308f2015-06-03 18:49:27 -07001951 /**
1952 * Returns the time in microseconds that the camera has been on while the device was
1953 * running on battery.
1954 *
1955 * {@hide}
1956 */
1957 public abstract long getCameraOnTime(long elapsedRealtimeUs, int which);
1958
1959
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001960 public static final int NETWORK_MOBILE_RX_DATA = 0;
1961 public static final int NETWORK_MOBILE_TX_DATA = 1;
1962 public static final int NETWORK_WIFI_RX_DATA = 2;
1963 public static final int NETWORK_WIFI_TX_DATA = 3;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001964 public static final int NUM_NETWORK_ACTIVITY_TYPES = NETWORK_WIFI_TX_DATA + 1;
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07001965
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001966 public abstract long getNetworkActivityBytes(int type, int which);
1967 public abstract long getNetworkActivityPackets(int type, int which);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07001968
Adam Lesinski33dac552015-03-09 15:24:48 -07001969 public static final int CONTROLLER_IDLE_TIME = 0;
1970 public static final int CONTROLLER_RX_TIME = 1;
1971 public static final int CONTROLLER_TX_TIME = 2;
Adam Lesinskie08af192015-03-25 16:42:59 -07001972 public static final int CONTROLLER_POWER_DRAIN = 3;
1973 public static final int NUM_CONTROLLER_ACTIVITY_TYPES = CONTROLLER_POWER_DRAIN + 1;
Adam Lesinski33dac552015-03-09 15:24:48 -07001974
Adam Lesinskie08af192015-03-25 16:42:59 -07001975 /**
Adam Lesinski17390762015-04-10 13:17:47 -07001976 * Returns true if the BatteryStats object has detailed bluetooth power reports.
1977 * When true, calling {@link #getBluetoothControllerActivity(int, int)} will yield the
1978 * actual power data.
1979 */
1980 public abstract boolean hasBluetoothActivityReporting();
1981
1982 /**
Adam Lesinskie08af192015-03-25 16:42:59 -07001983 * For {@link #CONTROLLER_IDLE_TIME}, {@link #CONTROLLER_RX_TIME}, and
1984 * {@link #CONTROLLER_TX_TIME}, returns the time spent (in milliseconds) in the
1985 * respective state.
1986 * For {@link #CONTROLLER_POWER_DRAIN}, returns the power used by the controller in
1987 * milli-ampere-milliseconds (mAms).
1988 */
Adam Lesinski33dac552015-03-09 15:24:48 -07001989 public abstract long getBluetoothControllerActivity(int type, int which);
Adam Lesinskie08af192015-03-25 16:42:59 -07001990
1991 /**
Adam Lesinski17390762015-04-10 13:17:47 -07001992 * Returns true if the BatteryStats object has detailed WiFi power reports.
1993 * When true, calling {@link #getWifiControllerActivity(int, int)} will yield the
1994 * actual power data.
1995 */
1996 public abstract boolean hasWifiActivityReporting();
1997
1998 /**
Adam Lesinskie08af192015-03-25 16:42:59 -07001999 * For {@link #CONTROLLER_IDLE_TIME}, {@link #CONTROLLER_RX_TIME}, and
2000 * {@link #CONTROLLER_TX_TIME}, returns the time spent (in milliseconds) in the
2001 * respective state.
2002 * For {@link #CONTROLLER_POWER_DRAIN}, returns the power used by the controller in
2003 * milli-ampere-milliseconds (mAms).
2004 */
Adam Lesinski33dac552015-03-09 15:24:48 -07002005 public abstract long getWifiControllerActivity(int type, int which);
2006
The Android Open Source Project10592532009-03-18 17:39:46 -07002007 /**
Dianne Hackborn5f4a5f92014-01-24 16:59:34 -08002008 * Return the wall clock time when battery stats data collection started.
2009 */
2010 public abstract long getStartClockTime();
2011
2012 /**
Dianne Hackborncd0e3352014-08-07 17:08:09 -07002013 * Return platform version tag that we were running in when the battery stats started.
2014 */
2015 public abstract String getStartPlatformVersion();
2016
2017 /**
2018 * Return platform version tag that we were running in when the battery stats ended.
2019 */
2020 public abstract String getEndPlatformVersion();
2021
2022 /**
2023 * Return the internal version code of the parcelled format.
2024 */
2025 public abstract int getParcelVersion();
2026
2027 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002028 * Return whether we are currently running on battery.
2029 */
2030 public abstract boolean getIsOnBattery();
2031
2032 /**
2033 * Returns a SparseArray containing the statistics for each uid.
2034 */
2035 public abstract SparseArray<? extends Uid> getUidStats();
2036
2037 /**
2038 * Returns the current battery uptime in microseconds.
2039 *
2040 * @param curTime the amount of elapsed realtime in microseconds.
2041 */
2042 public abstract long getBatteryUptime(long curTime);
2043
2044 /**
2045 * Returns the current battery realtime in microseconds.
2046 *
2047 * @param curTime the amount of elapsed realtime in microseconds.
2048 */
2049 public abstract long getBatteryRealtime(long curTime);
The Android Open Source Project10592532009-03-18 17:39:46 -07002050
2051 /**
Evan Millar633a1742009-04-02 16:36:33 -07002052 * Returns the battery percentage level at the last time the device was unplugged from power, or
2053 * the last time it booted on battery power.
The Android Open Source Project10592532009-03-18 17:39:46 -07002054 */
Evan Millar633a1742009-04-02 16:36:33 -07002055 public abstract int getDischargeStartLevel();
The Android Open Source Project10592532009-03-18 17:39:46 -07002056
2057 /**
Evan Millar633a1742009-04-02 16:36:33 -07002058 * Returns the current battery percentage level if we are in a discharge cycle, otherwise
2059 * returns the level at the last plug event.
The Android Open Source Project10592532009-03-18 17:39:46 -07002060 */
Evan Millar633a1742009-04-02 16:36:33 -07002061 public abstract int getDischargeCurrentLevel();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002062
2063 /**
Dianne Hackborn3bee5af82010-07-23 00:22:04 -07002064 * Get the amount the battery has discharged since the stats were
2065 * last reset after charging, as a lower-end approximation.
2066 */
2067 public abstract int getLowDischargeAmountSinceCharge();
2068
2069 /**
2070 * Get the amount the battery has discharged since the stats were
2071 * last reset after charging, as an upper-end approximation.
2072 */
2073 public abstract int getHighDischargeAmountSinceCharge();
2074
2075 /**
Dianne Hackborn40c87252014-03-19 16:55:40 -07002076 * Retrieve the discharge amount over the selected discharge period <var>which</var>.
2077 */
2078 public abstract int getDischargeAmount(int which);
2079
2080 /**
Dianne Hackbornc1b40e32011-01-05 18:27:40 -08002081 * Get the amount the battery has discharged while the screen was on,
2082 * since the last time power was unplugged.
2083 */
2084 public abstract int getDischargeAmountScreenOn();
2085
2086 /**
2087 * Get the amount the battery has discharged while the screen was on,
2088 * since the last time the device was charged.
2089 */
2090 public abstract int getDischargeAmountScreenOnSinceCharge();
2091
2092 /**
2093 * Get the amount the battery has discharged while the screen was off,
2094 * since the last time power was unplugged.
2095 */
2096 public abstract int getDischargeAmountScreenOff();
2097
2098 /**
2099 * Get the amount the battery has discharged while the screen was off,
2100 * since the last time the device was charged.
2101 */
2102 public abstract int getDischargeAmountScreenOffSinceCharge();
2103
2104 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002105 * Returns the total, last, or current battery uptime in microseconds.
2106 *
2107 * @param curTime the elapsed realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002108 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002109 */
2110 public abstract long computeBatteryUptime(long curTime, int which);
2111
2112 /**
2113 * Returns the total, last, or current battery realtime in microseconds.
2114 *
2115 * @param curTime the current elapsed realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002116 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002117 */
2118 public abstract long computeBatteryRealtime(long curTime, int which);
2119
2120 /**
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002121 * Returns the total, last, or current battery screen off uptime in microseconds.
2122 *
2123 * @param curTime the elapsed realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002124 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002125 */
2126 public abstract long computeBatteryScreenOffUptime(long curTime, int which);
2127
2128 /**
2129 * Returns the total, last, or current battery screen off realtime in microseconds.
2130 *
2131 * @param curTime the current elapsed realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002132 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002133 */
2134 public abstract long computeBatteryScreenOffRealtime(long curTime, int which);
2135
2136 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002137 * Returns the total, last, or current uptime in microseconds.
2138 *
2139 * @param curTime the current elapsed realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002140 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002141 */
2142 public abstract long computeUptime(long curTime, int which);
2143
2144 /**
2145 * Returns the total, last, or current realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002146 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002147 * @param curTime the current elapsed realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002148 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002149 */
2150 public abstract long computeRealtime(long curTime, int which);
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002151
2152 /**
2153 * Compute an approximation for how much run time (in microseconds) is remaining on
2154 * the battery. Returns -1 if no time can be computed: either there is not
2155 * enough current data to make a decision, or the battery is currently
2156 * charging.
2157 *
2158 * @param curTime The current elepsed realtime in microseconds.
2159 */
2160 public abstract long computeBatteryTimeRemaining(long curTime);
2161
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07002162 // The part of a step duration that is the actual time.
2163 public static final long STEP_LEVEL_TIME_MASK = 0x000000ffffffffffL;
2164
2165 // Bits in a step duration that are the new battery level we are at.
2166 public static final long STEP_LEVEL_LEVEL_MASK = 0x0000ff0000000000L;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002167 public static final int STEP_LEVEL_LEVEL_SHIFT = 40;
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07002168
2169 // Bits in a step duration that are the initial mode we were in at that step.
2170 public static final long STEP_LEVEL_INITIAL_MODE_MASK = 0x00ff000000000000L;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002171 public static final int STEP_LEVEL_INITIAL_MODE_SHIFT = 48;
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07002172
2173 // Bits in a step duration that indicate which modes changed during that step.
2174 public static final long STEP_LEVEL_MODIFIED_MODE_MASK = 0xff00000000000000L;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002175 public static final int STEP_LEVEL_MODIFIED_MODE_SHIFT = 56;
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07002176
2177 // Step duration mode: the screen is on, off, dozed, etc; value is Display.STATE_* - 1.
2178 public static final int STEP_LEVEL_MODE_SCREEN_STATE = 0x03;
2179
2180 // Step duration mode: power save is on.
2181 public static final int STEP_LEVEL_MODE_POWER_SAVE = 0x04;
2182
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002183 // Step duration mode: device is currently in idle mode.
2184 public static final int STEP_LEVEL_MODE_DEVICE_IDLE = 0x08;
2185
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002186 public static final int[] STEP_LEVEL_MODES_OF_INTEREST = new int[] {
2187 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE,
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002188 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE|STEP_LEVEL_MODE_DEVICE_IDLE,
2189 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_DEVICE_IDLE,
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002190 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE,
2191 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE,
2192 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE,
2193 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE,
2194 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE,
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002195 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE|STEP_LEVEL_MODE_DEVICE_IDLE,
2196 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_DEVICE_IDLE,
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002197 };
2198 public static final int[] STEP_LEVEL_MODE_VALUES = new int[] {
2199 (Display.STATE_OFF-1),
2200 (Display.STATE_OFF-1)|STEP_LEVEL_MODE_POWER_SAVE,
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002201 (Display.STATE_OFF-1)|STEP_LEVEL_MODE_DEVICE_IDLE,
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002202 (Display.STATE_ON-1),
2203 (Display.STATE_ON-1)|STEP_LEVEL_MODE_POWER_SAVE,
2204 (Display.STATE_DOZE-1),
2205 (Display.STATE_DOZE-1)|STEP_LEVEL_MODE_POWER_SAVE,
2206 (Display.STATE_DOZE_SUSPEND-1),
2207 (Display.STATE_DOZE_SUSPEND-1)|STEP_LEVEL_MODE_POWER_SAVE,
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002208 (Display.STATE_DOZE_SUSPEND-1)|STEP_LEVEL_MODE_DEVICE_IDLE,
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002209 };
2210 public static final String[] STEP_LEVEL_MODE_LABELS = new String[] {
2211 "screen off",
2212 "screen off power save",
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002213 "screen off device idle",
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002214 "screen on",
2215 "screen on power save",
2216 "screen doze",
2217 "screen doze power save",
2218 "screen doze-suspend",
2219 "screen doze-suspend power save",
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002220 "screen doze-suspend device idle",
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002221 };
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002222
2223 /**
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002224 * Return the array of discharge step durations.
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002225 */
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002226 public abstract LevelStepTracker getDischargeLevelStepTracker();
2227
2228 /**
2229 * Return the array of daily discharge step durations.
2230 */
2231 public abstract LevelStepTracker getDailyDischargeLevelStepTracker();
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002232
2233 /**
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002234 * Compute an approximation for how much time (in microseconds) remains until the battery
2235 * is fully charged. Returns -1 if no time can be computed: either there is not
2236 * enough current data to make a decision, or the battery is currently
2237 * discharging.
2238 *
2239 * @param curTime The current elepsed realtime in microseconds.
2240 */
2241 public abstract long computeChargeTimeRemaining(long curTime);
2242
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002243 /**
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002244 * Return the array of charge step durations.
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002245 */
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002246 public abstract LevelStepTracker getChargeLevelStepTracker();
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002247
2248 /**
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002249 * Return the array of daily charge step durations.
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002250 */
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002251 public abstract LevelStepTracker getDailyChargeLevelStepTracker();
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002252
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002253 public abstract ArrayList<PackageChange> getDailyPackageChanges();
2254
Dianne Hackbornc3940bc2014-09-05 15:50:25 -07002255 public abstract Map<String, ? extends Timer> getWakeupReasonStats();
Dianne Hackborna1bd7922014-03-21 11:07:11 -07002256
Evan Millarc64edde2009-04-18 12:26:32 -07002257 public abstract Map<String, ? extends Timer> getKernelWakelockStats();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002258
Amith Yamasanie43530a2009-08-21 13:11:37 -07002259 /** Returns the number of different speeds that the CPU can run at */
2260 public abstract int getCpuSpeedSteps();
2261
Dianne Hackborna7c837f2014-01-15 16:20:44 -08002262 public abstract void writeToParcelWithoutUids(Parcel out, int flags);
2263
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002264 private final static void formatTimeRaw(StringBuilder out, long seconds) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002265 long days = seconds / (60 * 60 * 24);
2266 if (days != 0) {
2267 out.append(days);
2268 out.append("d ");
2269 }
2270 long used = days * 60 * 60 * 24;
2271
2272 long hours = (seconds - used) / (60 * 60);
2273 if (hours != 0 || used != 0) {
2274 out.append(hours);
2275 out.append("h ");
2276 }
2277 used += hours * 60 * 60;
2278
2279 long mins = (seconds-used) / 60;
2280 if (mins != 0 || used != 0) {
2281 out.append(mins);
2282 out.append("m ");
2283 }
2284 used += mins * 60;
2285
2286 if (seconds != 0 || used != 0) {
2287 out.append(seconds-used);
2288 out.append("s ");
2289 }
2290 }
2291
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002292 public final static void formatTimeMs(StringBuilder sb, long time) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002293 long sec = time / 1000;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002294 formatTimeRaw(sb, sec);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002295 sb.append(time - (sec * 1000));
2296 sb.append("ms ");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002297 }
2298
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002299 public final static void formatTimeMsNoSpace(StringBuilder sb, long time) {
Dianne Hackbornd45665b2014-02-26 12:35:32 -08002300 long sec = time / 1000;
2301 formatTimeRaw(sb, sec);
2302 sb.append(time - (sec * 1000));
2303 sb.append("ms");
2304 }
2305
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002306 public final String formatRatioLocked(long num, long den) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002307 if (den == 0L) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002308 return "--%";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002309 }
2310 float perc = ((float)num) / ((float)den) * 100;
2311 mFormatBuilder.setLength(0);
2312 mFormatter.format("%.1f%%", perc);
2313 return mFormatBuilder.toString();
2314 }
2315
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002316 final String formatBytesLocked(long bytes) {
Evan Millar22ac0432009-03-31 11:33:18 -07002317 mFormatBuilder.setLength(0);
2318
2319 if (bytes < BYTES_PER_KB) {
2320 return bytes + "B";
2321 } else if (bytes < BYTES_PER_MB) {
2322 mFormatter.format("%.2fKB", bytes / (double) BYTES_PER_KB);
2323 return mFormatBuilder.toString();
2324 } else if (bytes < BYTES_PER_GB){
2325 mFormatter.format("%.2fMB", bytes / (double) BYTES_PER_MB);
2326 return mFormatBuilder.toString();
2327 } else {
2328 mFormatter.format("%.2fGB", bytes / (double) BYTES_PER_GB);
2329 return mFormatBuilder.toString();
2330 }
2331 }
2332
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002333 private static long computeWakeLock(Timer timer, long elapsedRealtimeUs, int which) {
Dianne Hackbornc24ab862011-10-18 15:55:03 -07002334 if (timer != null) {
2335 // Convert from microseconds to milliseconds with rounding
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002336 long totalTimeMicros = timer.getTotalTimeLocked(elapsedRealtimeUs, which);
Dianne Hackbornc24ab862011-10-18 15:55:03 -07002337 long totalTimeMillis = (totalTimeMicros + 500) / 1000;
2338 return totalTimeMillis;
2339 }
2340 return 0;
2341 }
2342
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002343 /**
2344 *
2345 * @param sb a StringBuilder object.
2346 * @param timer a Timer object contining the wakelock times.
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002347 * @param elapsedRealtimeUs the current on-battery time in microseconds.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002348 * @param name the name of the wakelock.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002349 * @param which which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002350 * @param linePrefix a String to be prepended to each line of output.
2351 * @return the line prefix
2352 */
2353 private static final String printWakeLock(StringBuilder sb, Timer timer,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002354 long elapsedRealtimeUs, String name, int which, String linePrefix) {
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002355
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002356 if (timer != null) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002357 long totalTimeMillis = computeWakeLock(timer, elapsedRealtimeUs, which);
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002358
Evan Millarc64edde2009-04-18 12:26:32 -07002359 int count = timer.getCountLocked(which);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002360 if (totalTimeMillis != 0) {
2361 sb.append(linePrefix);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002362 formatTimeMs(sb, totalTimeMillis);
Dianne Hackborn81038902012-11-26 17:04:09 -08002363 if (name != null) {
2364 sb.append(name);
2365 sb.append(' ');
2366 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002367 sb.append('(');
2368 sb.append(count);
2369 sb.append(" times)");
2370 return ", ";
2371 }
2372 }
2373 return linePrefix;
2374 }
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002375
2376 /**
2377 *
2378 * @param pw a PrintWriter object to print to.
2379 * @param sb a StringBuilder object.
2380 * @param timer a Timer object contining the wakelock times.
2381 * @param rawRealtime the current on-battery time in microseconds.
2382 * @param which which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
2383 * @param prefix a String to be prepended to each line of output.
2384 * @param type the name of the timer.
2385 */
2386 private static final boolean printTimer(PrintWriter pw, StringBuilder sb, Timer timer,
2387 long rawRealtime, int which, String prefix, String type) {
2388 if (timer != null) {
2389 // Convert from microseconds to milliseconds with rounding
2390 final long totalTime = (timer.getTotalTimeLocked(
2391 rawRealtime, which) + 500) / 1000;
2392 final int count = timer.getCountLocked(which);
2393 if (totalTime != 0) {
2394 sb.setLength(0);
2395 sb.append(prefix);
2396 sb.append(" ");
2397 sb.append(type);
2398 sb.append(": ");
2399 formatTimeMs(sb, totalTime);
2400 sb.append("realtime (");
2401 sb.append(count);
2402 sb.append(" times)");
2403 pw.println(sb.toString());
2404 return true;
2405 }
2406 }
2407 return false;
2408 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002409
2410 /**
2411 * Checkin version of wakelock printer. Prints simple comma-separated list.
2412 *
2413 * @param sb a StringBuilder object.
2414 * @param timer a Timer object contining the wakelock times.
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002415 * @param elapsedRealtimeUs the current time in microseconds.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002416 * @param name the name of the wakelock.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002417 * @param which which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002418 * @param linePrefix a String to be prepended to each line of output.
2419 * @return the line prefix
2420 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002421 private static final String printWakeLockCheckin(StringBuilder sb, Timer timer,
2422 long elapsedRealtimeUs, String name, int which, String linePrefix) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002423 long totalTimeMicros = 0;
2424 int count = 0;
2425 if (timer != null) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002426 totalTimeMicros = timer.getTotalTimeLocked(elapsedRealtimeUs, which);
Evan Millarc64edde2009-04-18 12:26:32 -07002427 count = timer.getCountLocked(which);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002428 }
2429 sb.append(linePrefix);
2430 sb.append((totalTimeMicros + 500) / 1000); // microseconds to milliseconds with rounding
2431 sb.append(',');
Evan Millarc64edde2009-04-18 12:26:32 -07002432 sb.append(name != null ? name + "," : "");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002433 sb.append(count);
2434 return ",";
2435 }
2436
2437 /**
2438 * Dump a comma-separated line of values for terse checkin mode.
2439 *
2440 * @param pw the PageWriter to dump log to
2441 * @param category category of data (e.g. "total", "last", "unplugged", "current" )
2442 * @param type type of data (e.g. "wakelock", "sensor", "process", "apk" , "process", "network")
2443 * @param args type-dependent data arguments
2444 */
2445 private static final void dumpLine(PrintWriter pw, int uid, String category, String type,
2446 Object... args ) {
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002447 pw.print(BATTERY_STATS_CHECKIN_VERSION);
2448 pw.print(',');
2449 pw.print(uid);
2450 pw.print(',');
2451 pw.print(category);
2452 pw.print(',');
Dianne Hackborn13ac0412013-06-25 19:34:49 -07002453 pw.print(type);
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002454
2455 for (Object arg : args) {
Dianne Hackborn13ac0412013-06-25 19:34:49 -07002456 pw.print(',');
2457 pw.print(arg);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002458 }
Dianne Hackborn13ac0412013-06-25 19:34:49 -07002459 pw.println();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002460 }
Dianne Hackbornd953c532014-08-16 18:17:38 -07002461
2462 /**
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002463 * Dump a given timer stat for terse checkin mode.
2464 *
2465 * @param pw the PageWriter to dump log to
2466 * @param uid the UID to log
2467 * @param category category of data (e.g. "total", "last", "unplugged", "current" )
2468 * @param type type of data (e.g. "wakelock", "sensor", "process", "apk" , "process", "network")
2469 * @param timer a {@link Timer} to dump stats for
2470 * @param rawRealtime the current elapsed realtime of the system in microseconds
2471 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT
2472 */
2473 private static final void dumpTimer(PrintWriter pw, int uid, String category, String type,
2474 Timer timer, long rawRealtime, int which) {
2475 if (timer != null) {
2476 // Convert from microseconds to milliseconds with rounding
2477 final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500)
2478 / 1000;
2479 final int count = timer.getCountLocked(which);
2480 if (totalTime != 0) {
2481 dumpLine(pw, uid, category, type, totalTime, count);
2482 }
2483 }
2484 }
2485
2486 /**
Dianne Hackbornd953c532014-08-16 18:17:38 -07002487 * Temporary for settings.
2488 */
2489 public final void dumpCheckinLocked(Context context, PrintWriter pw, int which, int reqUid) {
2490 dumpCheckinLocked(context, pw, which, reqUid, BatteryStatsHelper.checkWifiOnly(context));
2491 }
2492
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002493 /**
2494 * Checkin server version of dump to produce more compact, computer-readable log.
2495 *
2496 * NOTE: all times are expressed in 'ms'.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002497 */
Dianne Hackbornd953c532014-08-16 18:17:38 -07002498 public final void dumpCheckinLocked(Context context, PrintWriter pw, int which, int reqUid,
2499 boolean wifiOnly) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002500 final long rawUptime = SystemClock.uptimeMillis() * 1000;
2501 final long rawRealtime = SystemClock.elapsedRealtime() * 1000;
2502 final long batteryUptime = getBatteryUptime(rawUptime);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002503 final long whichBatteryUptime = computeBatteryUptime(rawUptime, which);
2504 final long whichBatteryRealtime = computeBatteryRealtime(rawRealtime, which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002505 final long whichBatteryScreenOffUptime = computeBatteryScreenOffUptime(rawUptime, which);
2506 final long whichBatteryScreenOffRealtime = computeBatteryScreenOffRealtime(rawRealtime,
2507 which);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002508 final long totalRealtime = computeRealtime(rawRealtime, which);
2509 final long totalUptime = computeUptime(rawUptime, which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002510 final long screenOnTime = getScreenOnTime(rawRealtime, which);
Jeff Browne95c3cd2014-05-02 16:59:26 -07002511 final long interactiveTime = getInteractiveTime(rawRealtime, which);
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07002512 final long powerSaveModeEnabledTime = getPowerSaveModeEnabledTime(rawRealtime, which);
2513 final long deviceIdleModeEnabledTime = getDeviceIdleModeEnabledTime(rawRealtime, which);
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002514 final long deviceIdlingTime = getDeviceIdlingTime(rawRealtime, which);
Dianne Hackborn1e01d162014-12-04 17:46:42 -08002515 final int connChanges = getNumConnectivityChange(which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002516 final long phoneOnTime = getPhoneOnTime(rawRealtime, which);
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07002517
Dianne Hackborn1e725a72015-03-24 18:23:19 -07002518 final StringBuilder sb = new StringBuilder(128);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002519
Dianne Hackborn1e725a72015-03-24 18:23:19 -07002520 final SparseArray<? extends Uid> uidStats = getUidStats();
Evan Millar22ac0432009-03-31 11:33:18 -07002521 final int NU = uidStats.size();
2522
Dianne Hackborn1e725a72015-03-24 18:23:19 -07002523 final String category = STAT_NAMES[which];
Jeff Sharkey3e013e82013-04-25 14:48:19 -07002524
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002525 // Dump "battery" stat
2526 dumpLine(pw, 0 /* uid */, category, BATTERY_DATA,
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07002527 which == STATS_SINCE_CHARGED ? getStartCount() : "N/A",
Dianne Hackborn617f8772009-03-31 15:04:46 -07002528 whichBatteryRealtime / 1000, whichBatteryUptime / 1000,
Dianne Hackborn5f4a5f92014-01-24 16:59:34 -08002529 totalRealtime / 1000, totalUptime / 1000,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002530 getStartClockTime(),
2531 whichBatteryScreenOffRealtime / 1000, whichBatteryScreenOffUptime / 1000);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002532
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002533 // Calculate wakelock times across all uids.
Evan Millar22ac0432009-03-31 11:33:18 -07002534 long fullWakeLockTimeTotal = 0;
2535 long partialWakeLockTimeTotal = 0;
2536
2537 for (int iu = 0; iu < NU; iu++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07002538 final Uid u = uidStats.valueAt(iu);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07002539
Dianne Hackborn1e725a72015-03-24 18:23:19 -07002540 final ArrayMap<String, ? extends BatteryStats.Uid.Wakelock> wakelocks
2541 = u.getWakelockStats();
2542 for (int iw=wakelocks.size()-1; iw>=0; iw--) {
2543 final Uid.Wakelock wl = wakelocks.valueAt(iw);
Evan Millar22ac0432009-03-31 11:33:18 -07002544
Dianne Hackborn1e725a72015-03-24 18:23:19 -07002545 final Timer fullWakeTimer = wl.getWakeTime(WAKE_TYPE_FULL);
2546 if (fullWakeTimer != null) {
2547 fullWakeLockTimeTotal += fullWakeTimer.getTotalTimeLocked(rawRealtime,
2548 which);
2549 }
2550
2551 final Timer partialWakeTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL);
2552 if (partialWakeTimer != null) {
2553 partialWakeLockTimeTotal += partialWakeTimer.getTotalTimeLocked(
2554 rawRealtime, which);
Evan Millar22ac0432009-03-31 11:33:18 -07002555 }
2556 }
2557 }
Adam Lesinskie283d332015-04-16 12:29:25 -07002558
2559 // Dump network stats
Dianne Hackborn1e725a72015-03-24 18:23:19 -07002560 final long mobileRxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which);
2561 final long mobileTxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which);
2562 final long wifiRxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which);
2563 final long wifiTxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which);
2564 final long mobileRxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which);
2565 final long mobileTxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which);
2566 final long wifiRxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which);
2567 final long wifiTxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002568 dumpLine(pw, 0 /* uid */, category, GLOBAL_NETWORK_DATA,
2569 mobileRxTotalBytes, mobileTxTotalBytes, wifiRxTotalBytes, wifiTxTotalBytes,
2570 mobileRxTotalPackets, mobileTxTotalPackets, wifiRxTotalPackets, wifiTxTotalPackets);
2571
Adam Lesinskie283d332015-04-16 12:29:25 -07002572 // Dump Wifi controller stats
2573 final long wifiOnTime = getWifiOnTime(rawRealtime, which);
2574 final long wifiRunningTime = getGlobalWifiRunningTime(rawRealtime, which);
2575 final long wifiIdleTimeMs = getWifiControllerActivity(CONTROLLER_IDLE_TIME, which);
2576 final long wifiRxTimeMs = getWifiControllerActivity(CONTROLLER_RX_TIME, which);
2577 final long wifiTxTimeMs = getWifiControllerActivity(CONTROLLER_TX_TIME, which);
2578 final long wifiPowerMaMs = getWifiControllerActivity(CONTROLLER_POWER_DRAIN, which);
2579 dumpLine(pw, 0 /* uid */, category, GLOBAL_WIFI_DATA,
2580 wifiOnTime / 1000, wifiRunningTime / 1000,
2581 wifiIdleTimeMs, wifiRxTimeMs, wifiTxTimeMs, wifiPowerMaMs / (1000*60*60));
2582
2583 // Dump Bluetooth controller stats
2584 final long btIdleTimeMs = getBluetoothControllerActivity(CONTROLLER_IDLE_TIME, which);
2585 final long btRxTimeMs = getBluetoothControllerActivity(CONTROLLER_RX_TIME, which);
2586 final long btTxTimeMs = getBluetoothControllerActivity(CONTROLLER_TX_TIME, which);
2587 final long btPowerMaMs = getBluetoothControllerActivity(CONTROLLER_POWER_DRAIN, which);
2588 dumpLine(pw, 0 /* uid */, category, GLOBAL_BLUETOOTH_DATA,
2589 btIdleTimeMs, btRxTimeMs, btTxTimeMs, btPowerMaMs / (1000*60*60));
2590
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002591 // Dump misc stats
2592 dumpLine(pw, 0 /* uid */, category, MISC_DATA,
Adam Lesinskie283d332015-04-16 12:29:25 -07002593 screenOnTime / 1000, phoneOnTime / 1000,
Ashish Sharma213bb2f2014-07-07 17:14:52 -07002594 fullWakeLockTimeTotal / 1000, partialWakeLockTimeTotal / 1000,
Adam Lesinskie283d332015-04-16 12:29:25 -07002595 getMobileRadioActiveTime(rawRealtime, which) / 1000,
Ashish Sharma213bb2f2014-07-07 17:14:52 -07002596 getMobileRadioActiveAdjustedTime(which) / 1000, interactiveTime / 1000,
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07002597 powerSaveModeEnabledTime / 1000, connChanges, deviceIdleModeEnabledTime / 1000,
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002598 getDeviceIdleModeEnabledCount(which), deviceIdlingTime / 1000,
2599 getDeviceIdlingCount(which));
Dianne Hackborn617f8772009-03-31 15:04:46 -07002600
2601 // Dump screen brightness stats
2602 Object[] args = new Object[NUM_SCREEN_BRIGHTNESS_BINS];
2603 for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002604 args[i] = getScreenBrightnessTime(i, rawRealtime, which) / 1000;
Dianne Hackborn617f8772009-03-31 15:04:46 -07002605 }
2606 dumpLine(pw, 0 /* uid */, category, SCREEN_BRIGHTNESS_DATA, args);
The Android Open Source Project10592532009-03-18 17:39:46 -07002607
Dianne Hackborn627bba72009-03-24 22:32:56 -07002608 // Dump signal strength stats
Wink Saville52840902011-02-18 12:40:47 -08002609 args = new Object[SignalStrength.NUM_SIGNAL_STRENGTH_BINS];
2610 for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002611 args[i] = getPhoneSignalStrengthTime(i, rawRealtime, which) / 1000;
Dianne Hackborn627bba72009-03-24 22:32:56 -07002612 }
Dianne Hackborn617f8772009-03-31 15:04:46 -07002613 dumpLine(pw, 0 /* uid */, category, SIGNAL_STRENGTH_TIME_DATA, args);
Amith Yamasanif37447b2009-10-08 18:28:01 -07002614 dumpLine(pw, 0 /* uid */, category, SIGNAL_SCANNING_TIME_DATA,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002615 getPhoneSignalScanningTime(rawRealtime, which) / 1000);
Wink Saville52840902011-02-18 12:40:47 -08002616 for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) {
Dianne Hackborn617f8772009-03-31 15:04:46 -07002617 args[i] = getPhoneSignalStrengthCount(i, which);
2618 }
2619 dumpLine(pw, 0 /* uid */, category, SIGNAL_STRENGTH_COUNT_DATA, args);
Dianne Hackborne13c4c02014-02-11 17:18:35 -08002620
Dianne Hackborn627bba72009-03-24 22:32:56 -07002621 // Dump network type stats
2622 args = new Object[NUM_DATA_CONNECTION_TYPES];
2623 for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002624 args[i] = getPhoneDataConnectionTime(i, rawRealtime, which) / 1000;
Dianne Hackborn627bba72009-03-24 22:32:56 -07002625 }
Dianne Hackborn617f8772009-03-31 15:04:46 -07002626 dumpLine(pw, 0 /* uid */, category, DATA_CONNECTION_TIME_DATA, args);
2627 for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) {
2628 args[i] = getPhoneDataConnectionCount(i, which);
2629 }
2630 dumpLine(pw, 0 /* uid */, category, DATA_CONNECTION_COUNT_DATA, args);
Dianne Hackbornca1bf212014-02-14 14:18:36 -08002631
2632 // Dump wifi state stats
2633 args = new Object[NUM_WIFI_STATES];
2634 for (int i=0; i<NUM_WIFI_STATES; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002635 args[i] = getWifiStateTime(i, rawRealtime, which) / 1000;
Dianne Hackbornca1bf212014-02-14 14:18:36 -08002636 }
2637 dumpLine(pw, 0 /* uid */, category, WIFI_STATE_TIME_DATA, args);
2638 for (int i=0; i<NUM_WIFI_STATES; i++) {
2639 args[i] = getWifiStateCount(i, which);
2640 }
2641 dumpLine(pw, 0 /* uid */, category, WIFI_STATE_COUNT_DATA, args);
2642
Dianne Hackborn3251b902014-06-20 14:40:53 -07002643 // Dump wifi suppl state stats
2644 args = new Object[NUM_WIFI_SUPPL_STATES];
2645 for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) {
2646 args[i] = getWifiSupplStateTime(i, rawRealtime, which) / 1000;
2647 }
2648 dumpLine(pw, 0 /* uid */, category, WIFI_SUPPL_STATE_TIME_DATA, args);
2649 for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) {
2650 args[i] = getWifiSupplStateCount(i, which);
2651 }
2652 dumpLine(pw, 0 /* uid */, category, WIFI_SUPPL_STATE_COUNT_DATA, args);
2653
2654 // Dump wifi signal strength stats
2655 args = new Object[NUM_WIFI_SIGNAL_STRENGTH_BINS];
2656 for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) {
2657 args[i] = getWifiSignalStrengthTime(i, rawRealtime, which) / 1000;
2658 }
2659 dumpLine(pw, 0 /* uid */, category, WIFI_SIGNAL_STRENGTH_TIME_DATA, args);
2660 for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) {
2661 args[i] = getWifiSignalStrengthCount(i, which);
2662 }
2663 dumpLine(pw, 0 /* uid */, category, WIFI_SIGNAL_STRENGTH_COUNT_DATA, args);
2664
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07002665 if (which == STATS_SINCE_UNPLUGGED) {
Dianne Hackborne13c4c02014-02-11 17:18:35 -08002666 dumpLine(pw, 0 /* uid */, category, BATTERY_LEVEL_DATA, getDischargeStartLevel(),
Evan Millar633a1742009-04-02 16:36:33 -07002667 getDischargeCurrentLevel());
The Android Open Source Project10592532009-03-18 17:39:46 -07002668 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002669
Dianne Hackbornc1b40e32011-01-05 18:27:40 -08002670 if (which == STATS_SINCE_UNPLUGGED) {
2671 dumpLine(pw, 0 /* uid */, category, BATTERY_DISCHARGE_DATA,
2672 getDischargeStartLevel()-getDischargeCurrentLevel(),
2673 getDischargeStartLevel()-getDischargeCurrentLevel(),
2674 getDischargeAmountScreenOn(), getDischargeAmountScreenOff());
2675 } else {
2676 dumpLine(pw, 0 /* uid */, category, BATTERY_DISCHARGE_DATA,
2677 getLowDischargeAmountSinceCharge(), getHighDischargeAmountSinceCharge(),
Dianne Hackborncd0e3352014-08-07 17:08:09 -07002678 getDischargeAmountScreenOnSinceCharge(),
2679 getDischargeAmountScreenOffSinceCharge());
Dianne Hackbornc1b40e32011-01-05 18:27:40 -08002680 }
2681
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08002682 if (reqUid < 0) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07002683 final Map<String, ? extends Timer> kernelWakelocks = getKernelWakelockStats();
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08002684 if (kernelWakelocks.size() > 0) {
Dianne Hackborna1bd7922014-03-21 11:07:11 -07002685 for (Map.Entry<String, ? extends Timer> ent : kernelWakelocks.entrySet()) {
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08002686 sb.setLength(0);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002687 printWakeLockCheckin(sb, ent.getValue(), rawRealtime, null, which, "");
Dianne Hackborna1bd7922014-03-21 11:07:11 -07002688 dumpLine(pw, 0 /* uid */, category, KERNEL_WAKELOCK_DATA, ent.getKey(),
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08002689 sb.toString());
2690 }
Evan Millarc64edde2009-04-18 12:26:32 -07002691 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07002692 final Map<String, ? extends Timer> wakeupReasons = getWakeupReasonStats();
Dianne Hackborna1bd7922014-03-21 11:07:11 -07002693 if (wakeupReasons.size() > 0) {
Dianne Hackbornc3940bc2014-09-05 15:50:25 -07002694 for (Map.Entry<String, ? extends Timer> ent : wakeupReasons.entrySet()) {
2695 // Not doing the regular wake lock formatting to remain compatible
2696 // with the old checkin format.
2697 long totalTimeMicros = ent.getValue().getTotalTimeLocked(rawRealtime, which);
2698 int count = ent.getValue().getCountLocked(which);
Dianne Hackborna1bd7922014-03-21 11:07:11 -07002699 dumpLine(pw, 0 /* uid */, category, WAKEUP_REASON_DATA,
Dianne Hackbornc3940bc2014-09-05 15:50:25 -07002700 "\"" + ent.getKey() + "\"", (totalTimeMicros + 500) / 1000, count);
Dianne Hackborna1bd7922014-03-21 11:07:11 -07002701 }
2702 }
Evan Millarc64edde2009-04-18 12:26:32 -07002703 }
2704
Dianne Hackborn1e725a72015-03-24 18:23:19 -07002705 final BatteryStatsHelper helper = new BatteryStatsHelper(context, false, wifiOnly);
Dianne Hackborna7c837f2014-01-15 16:20:44 -08002706 helper.create(this);
2707 helper.refreshStats(which, UserHandle.USER_ALL);
Dianne Hackborn1e725a72015-03-24 18:23:19 -07002708 final List<BatterySipper> sippers = helper.getUsageList();
Dianne Hackborna7c837f2014-01-15 16:20:44 -08002709 if (sippers != null && sippers.size() > 0) {
2710 dumpLine(pw, 0 /* uid */, category, POWER_USE_SUMMARY_DATA,
2711 BatteryStatsHelper.makemAh(helper.getPowerProfile().getBatteryCapacity()),
Dianne Hackborn099bc622014-01-22 13:39:16 -08002712 BatteryStatsHelper.makemAh(helper.getComputedPower()),
Dianne Hackborna7c837f2014-01-15 16:20:44 -08002713 BatteryStatsHelper.makemAh(helper.getMinDrainedPower()),
2714 BatteryStatsHelper.makemAh(helper.getMaxDrainedPower()));
2715 for (int i=0; i<sippers.size(); i++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07002716 final BatterySipper bs = sippers.get(i);
Dianne Hackborna7c837f2014-01-15 16:20:44 -08002717 int uid = 0;
2718 String label;
2719 switch (bs.drainType) {
2720 case IDLE:
2721 label="idle";
2722 break;
2723 case CELL:
2724 label="cell";
2725 break;
2726 case PHONE:
2727 label="phone";
2728 break;
2729 case WIFI:
2730 label="wifi";
2731 break;
2732 case BLUETOOTH:
2733 label="blue";
2734 break;
2735 case SCREEN:
2736 label="scrn";
2737 break;
Dianne Hackbornabc7c492014-06-30 16:57:46 -07002738 case FLASHLIGHT:
2739 label="flashlight";
2740 break;
Dianne Hackborna7c837f2014-01-15 16:20:44 -08002741 case APP:
2742 uid = bs.uidObj.getUid();
2743 label = "uid";
2744 break;
2745 case USER:
2746 uid = UserHandle.getUid(bs.userId, 0);
2747 label = "user";
2748 break;
2749 case UNACCOUNTED:
2750 label = "unacc";
2751 break;
2752 case OVERCOUNTED:
2753 label = "over";
2754 break;
Ruben Brunk5b1308f2015-06-03 18:49:27 -07002755 case CAMERA:
2756 label = "camera";
2757 break;
Dianne Hackborna7c837f2014-01-15 16:20:44 -08002758 default:
2759 label = "???";
2760 }
2761 dumpLine(pw, uid, category, POWER_USE_ITEM_DATA, label,
Adam Lesinskie08af192015-03-25 16:42:59 -07002762 BatteryStatsHelper.makemAh(bs.totalPowerMah));
Dianne Hackborna7c837f2014-01-15 16:20:44 -08002763 }
2764 }
2765
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002766 for (int iu = 0; iu < NU; iu++) {
2767 final int uid = uidStats.keyAt(iu);
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08002768 if (reqUid >= 0 && uid != reqUid) {
2769 continue;
2770 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07002771 final Uid u = uidStats.valueAt(iu);
Adam Lesinskie283d332015-04-16 12:29:25 -07002772
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002773 // Dump Network stats per uid, if any
Dianne Hackborn1e725a72015-03-24 18:23:19 -07002774 final long mobileBytesRx = u.getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which);
2775 final long mobileBytesTx = u.getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which);
2776 final long wifiBytesRx = u.getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which);
2777 final long wifiBytesTx = u.getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which);
2778 final long mobilePacketsRx = u.getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which);
2779 final long mobilePacketsTx = u.getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which);
2780 final long mobileActiveTime = u.getMobileRadioActiveTime(which);
2781 final int mobileActiveCount = u.getMobileRadioActiveCount(which);
2782 final long wifiPacketsRx = u.getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which);
2783 final long wifiPacketsTx = u.getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002784 if (mobileBytesRx > 0 || mobileBytesTx > 0 || wifiBytesRx > 0 || wifiBytesTx > 0
2785 || mobilePacketsRx > 0 || mobilePacketsTx > 0 || wifiPacketsRx > 0
Dianne Hackbornd45665b2014-02-26 12:35:32 -08002786 || wifiPacketsTx > 0 || mobileActiveTime > 0 || mobileActiveCount > 0) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002787 dumpLine(pw, uid, category, NETWORK_DATA, mobileBytesRx, mobileBytesTx,
2788 wifiBytesRx, wifiBytesTx,
2789 mobilePacketsRx, mobilePacketsTx,
Dianne Hackbornd45665b2014-02-26 12:35:32 -08002790 wifiPacketsRx, wifiPacketsTx,
2791 mobileActiveTime, mobileActiveCount);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07002792 }
2793
Adam Lesinskie283d332015-04-16 12:29:25 -07002794 final long fullWifiLockOnTime = u.getFullWifiLockTime(rawRealtime, which);
2795 final long wifiScanTime = u.getWifiScanTime(rawRealtime, which);
2796 final int wifiScanCount = u.getWifiScanCount(which);
2797 final long uidWifiRunningTime = u.getWifiRunningTime(rawRealtime, which);
2798 final long uidWifiIdleTimeMs = u.getWifiControllerActivity(CONTROLLER_IDLE_TIME, which);
2799 final long uidWifiRxTimeMs = u.getWifiControllerActivity(CONTROLLER_RX_TIME, which);
2800 final long uidWifiTxTimeMs = u.getWifiControllerActivity(CONTROLLER_TX_TIME, which);
Dianne Hackborn62793e42015-03-09 11:15:41 -07002801 if (fullWifiLockOnTime != 0 || wifiScanTime != 0 || wifiScanCount != 0
Adam Lesinskie283d332015-04-16 12:29:25 -07002802 || uidWifiRunningTime != 0 || uidWifiIdleTimeMs != 0 || uidWifiRxTimeMs != 0
2803 || uidWifiTxTimeMs != 0) {
Nick Pelly6ccaa542012-06-15 15:22:47 -07002804 dumpLine(pw, uid, category, WIFI_DATA,
Adam Lesinskie283d332015-04-16 12:29:25 -07002805 fullWifiLockOnTime, wifiScanTime, uidWifiRunningTime, wifiScanCount,
2806 uidWifiIdleTimeMs, uidWifiRxTimeMs, uidWifiTxTimeMs);
The Android Open Source Project10592532009-03-18 17:39:46 -07002807 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002808
Dianne Hackborn617f8772009-03-31 15:04:46 -07002809 if (u.hasUserActivity()) {
2810 args = new Object[Uid.NUM_USER_ACTIVITY_TYPES];
2811 boolean hasData = false;
2812 for (int i=0; i<Uid.NUM_USER_ACTIVITY_TYPES; i++) {
2813 int val = u.getUserActivityCount(i, which);
2814 args[i] = val;
2815 if (val != 0) hasData = true;
2816 }
2817 if (hasData) {
Ashish Sharmacba12152014-07-07 17:14:52 -07002818 dumpLine(pw, uid /* uid */, category, USER_ACTIVITY_DATA, args);
Dianne Hackborn617f8772009-03-31 15:04:46 -07002819 }
2820 }
2821
Dianne Hackborn1e725a72015-03-24 18:23:19 -07002822 final ArrayMap<String, ? extends Uid.Wakelock> wakelocks = u.getWakelockStats();
2823 for (int iw=wakelocks.size()-1; iw>=0; iw--) {
2824 final Uid.Wakelock wl = wakelocks.valueAt(iw);
2825 String linePrefix = "";
2826 sb.setLength(0);
2827 linePrefix = printWakeLockCheckin(sb, wl.getWakeTime(WAKE_TYPE_FULL),
2828 rawRealtime, "f", which, linePrefix);
2829 linePrefix = printWakeLockCheckin(sb, wl.getWakeTime(WAKE_TYPE_PARTIAL),
2830 rawRealtime, "p", which, linePrefix);
2831 linePrefix = printWakeLockCheckin(sb, wl.getWakeTime(WAKE_TYPE_WINDOW),
2832 rawRealtime, "w", which, linePrefix);
2833
2834 // Only log if we had at lease one wakelock...
2835 if (sb.length() > 0) {
2836 String name = wakelocks.keyAt(iw);
2837 if (name.indexOf(',') >= 0) {
2838 name = name.replace(',', '_');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002839 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07002840 dumpLine(pw, uid, category, WAKELOCK_DATA, name, sb.toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002841 }
2842 }
Dianne Hackborn61659e52014-07-09 16:13:01 -07002843
Dianne Hackborn1e725a72015-03-24 18:23:19 -07002844 final ArrayMap<String, ? extends Timer> syncs = u.getSyncStats();
2845 for (int isy=syncs.size()-1; isy>=0; isy--) {
2846 final Timer timer = syncs.valueAt(isy);
2847 // Convert from microseconds to milliseconds with rounding
2848 final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000;
2849 final int count = timer.getCountLocked(which);
2850 if (totalTime != 0) {
2851 dumpLine(pw, uid, category, SYNC_DATA, syncs.keyAt(isy), totalTime, count);
Dianne Hackbornfdb19562014-07-11 16:03:36 -07002852 }
2853 }
2854
Dianne Hackborn1e725a72015-03-24 18:23:19 -07002855 final ArrayMap<String, ? extends Timer> jobs = u.getJobStats();
2856 for (int ij=jobs.size()-1; ij>=0; ij--) {
2857 final Timer timer = jobs.valueAt(ij);
2858 // Convert from microseconds to milliseconds with rounding
2859 final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000;
2860 final int count = timer.getCountLocked(which);
2861 if (totalTime != 0) {
2862 dumpLine(pw, uid, category, JOB_DATA, jobs.keyAt(ij), totalTime, count);
Dianne Hackbornfdb19562014-07-11 16:03:36 -07002863 }
2864 }
2865
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002866 dumpTimer(pw, uid, category, FLASHLIGHT_DATA, u.getFlashlightTurnedOnTimer(),
2867 rawRealtime, which);
2868 dumpTimer(pw, uid, category, CAMERA_DATA, u.getCameraTurnedOnTimer(),
2869 rawRealtime, which);
2870 dumpTimer(pw, uid, category, VIDEO_DATA, u.getVideoTurnedOnTimer(),
2871 rawRealtime, which);
2872 dumpTimer(pw, uid, category, AUDIO_DATA, u.getAudioTurnedOnTimer(),
2873 rawRealtime, which);
2874
Dianne Hackborn1e725a72015-03-24 18:23:19 -07002875 final SparseArray<? extends BatteryStats.Uid.Sensor> sensors = u.getSensorStats();
2876 final int NSE = sensors.size();
Dianne Hackborn61659e52014-07-09 16:13:01 -07002877 for (int ise=0; ise<NSE; ise++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07002878 final Uid.Sensor se = sensors.valueAt(ise);
2879 final int sensorNumber = sensors.keyAt(ise);
2880 final Timer timer = se.getSensorTime();
Dianne Hackborn61659e52014-07-09 16:13:01 -07002881 if (timer != null) {
2882 // Convert from microseconds to milliseconds with rounding
Dianne Hackborn1e725a72015-03-24 18:23:19 -07002883 final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500)
2884 / 1000;
2885 final int count = timer.getCountLocked(which);
Dianne Hackborn61659e52014-07-09 16:13:01 -07002886 if (totalTime != 0) {
2887 dumpLine(pw, uid, category, SENSOR_DATA, sensorNumber, totalTime, count);
2888 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002889 }
2890 }
2891
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002892 dumpTimer(pw, uid, category, VIBRATOR_DATA, u.getVibratorOnTimer(),
2893 rawRealtime, which);
Dianne Hackborna06de0f2012-12-11 16:34:47 -08002894
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002895 dumpTimer(pw, uid, category, FOREGROUND_DATA, u.getForegroundActivityTimer(),
2896 rawRealtime, which);
Jeff Sharkey3e013e82013-04-25 14:48:19 -07002897
Dianne Hackborn1e725a72015-03-24 18:23:19 -07002898 final Object[] stateTimes = new Object[Uid.NUM_PROCESS_STATE];
Dianne Hackborn61659e52014-07-09 16:13:01 -07002899 long totalStateTime = 0;
2900 for (int ips=0; ips<Uid.NUM_PROCESS_STATE; ips++) {
2901 totalStateTime += u.getProcessStateTime(ips, rawRealtime, which);
2902 stateTimes[ips] = (totalStateTime + 500) / 1000;
2903 }
2904 if (totalStateTime > 0) {
2905 dumpLine(pw, uid, category, STATE_TIME_DATA, stateTimes);
2906 }
2907
Dianne Hackborn1e725a72015-03-24 18:23:19 -07002908 final ArrayMap<String, ? extends BatteryStats.Uid.Proc> processStats
2909 = u.getProcessStats();
2910 for (int ipr=processStats.size()-1; ipr>=0; ipr--) {
2911 final Uid.Proc ps = processStats.valueAt(ipr);
Jeff Sharkey3e013e82013-04-25 14:48:19 -07002912
Dianne Hackborn1e725a72015-03-24 18:23:19 -07002913 final long userMillis = ps.getUserTime(which);
2914 final long systemMillis = ps.getSystemTime(which);
2915 final long foregroundMillis = ps.getForegroundTime(which);
2916 final int starts = ps.getStarts(which);
2917 final int numCrashes = ps.getNumCrashes(which);
2918 final int numAnrs = ps.getNumAnrs(which);
Jeff Sharkey3e013e82013-04-25 14:48:19 -07002919
Dianne Hackborn1e725a72015-03-24 18:23:19 -07002920 if (userMillis != 0 || systemMillis != 0 || foregroundMillis != 0
2921 || starts != 0 || numAnrs != 0 || numCrashes != 0) {
2922 dumpLine(pw, uid, category, PROCESS_DATA, processStats.keyAt(ipr), userMillis,
2923 systemMillis, foregroundMillis, starts, numAnrs, numCrashes);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002924 }
2925 }
2926
Dianne Hackborn1e725a72015-03-24 18:23:19 -07002927 final ArrayMap<String, ? extends BatteryStats.Uid.Pkg> packageStats
2928 = u.getPackageStats();
2929 for (int ipkg=packageStats.size()-1; ipkg>=0; ipkg--) {
2930 final Uid.Pkg ps = packageStats.valueAt(ipkg);
2931 int wakeups = 0;
2932 final ArrayMap<String, ? extends Counter> alarms = ps.getWakeupAlarmStats();
2933 for (int iwa=alarms.size()-1; iwa>=0; iwa--) {
2934 wakeups += alarms.valueAt(iwa).getCountLocked(which);
2935 }
2936 final ArrayMap<String, ? extends Uid.Pkg.Serv> serviceStats = ps.getServiceStats();
2937 for (int isvc=serviceStats.size()-1; isvc>=0; isvc--) {
2938 final BatteryStats.Uid.Pkg.Serv ss = serviceStats.valueAt(isvc);
2939 final long startTime = ss.getStartTime(batteryUptime, which);
2940 final int starts = ss.getStarts(which);
2941 final int launches = ss.getLaunches(which);
2942 if (startTime != 0 || starts != 0 || launches != 0) {
2943 dumpLine(pw, uid, category, APK_DATA,
2944 wakeups, // wakeup alarms
2945 packageStats.keyAt(ipkg), // Apk
2946 serviceStats.keyAt(isvc), // service
2947 startTime / 1000, // time spent started, in ms
2948 starts,
2949 launches);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002950 }
2951 }
2952 }
2953 }
2954 }
2955
Dianne Hackborn81038902012-11-26 17:04:09 -08002956 static final class TimerEntry {
2957 final String mName;
2958 final int mId;
2959 final BatteryStats.Timer mTimer;
2960 final long mTime;
2961 TimerEntry(String name, int id, BatteryStats.Timer timer, long time) {
2962 mName = name;
2963 mId = id;
2964 mTimer = timer;
2965 mTime = time;
2966 }
2967 }
2968
Dianne Hackborna7c837f2014-01-15 16:20:44 -08002969 private void printmAh(PrintWriter printer, double power) {
2970 printer.print(BatteryStatsHelper.makemAh(power));
2971 }
2972
Dianne Hackbornd953c532014-08-16 18:17:38 -07002973 /**
2974 * Temporary for settings.
2975 */
2976 public final void dumpLocked(Context context, PrintWriter pw, String prefix, int which,
2977 int reqUid) {
2978 dumpLocked(context, pw, prefix, which, reqUid, BatteryStatsHelper.checkWifiOnly(context));
2979 }
2980
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002981 @SuppressWarnings("unused")
Dianne Hackborna7c837f2014-01-15 16:20:44 -08002982 public final void dumpLocked(Context context, PrintWriter pw, String prefix, final int which,
Dianne Hackbornd953c532014-08-16 18:17:38 -07002983 int reqUid, boolean wifiOnly) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002984 final long rawUptime = SystemClock.uptimeMillis() * 1000;
2985 final long rawRealtime = SystemClock.elapsedRealtime() * 1000;
2986 final long batteryUptime = getBatteryUptime(rawUptime);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002987
2988 final long whichBatteryUptime = computeBatteryUptime(rawUptime, which);
2989 final long whichBatteryRealtime = computeBatteryRealtime(rawRealtime, which);
2990 final long totalRealtime = computeRealtime(rawRealtime, which);
2991 final long totalUptime = computeUptime(rawUptime, which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002992 final long whichBatteryScreenOffUptime = computeBatteryScreenOffUptime(rawUptime, which);
2993 final long whichBatteryScreenOffRealtime = computeBatteryScreenOffRealtime(rawRealtime,
2994 which);
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002995 final long batteryTimeRemaining = computeBatteryTimeRemaining(rawRealtime);
2996 final long chargeTimeRemaining = computeChargeTimeRemaining(rawRealtime);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002997
Dianne Hackborn1e725a72015-03-24 18:23:19 -07002998 final StringBuilder sb = new StringBuilder(128);
Evan Millar22ac0432009-03-31 11:33:18 -07002999
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003000 final SparseArray<? extends Uid> uidStats = getUidStats();
Evan Millar22ac0432009-03-31 11:33:18 -07003001 final int NU = uidStats.size();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003002
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003003 sb.setLength(0);
3004 sb.append(prefix);
3005 sb.append(" Time on battery: ");
3006 formatTimeMs(sb, whichBatteryRealtime / 1000); sb.append("(");
3007 sb.append(formatRatioLocked(whichBatteryRealtime, totalRealtime));
3008 sb.append(") realtime, ");
3009 formatTimeMs(sb, whichBatteryUptime / 1000);
3010 sb.append("("); sb.append(formatRatioLocked(whichBatteryUptime, totalRealtime));
3011 sb.append(") uptime");
3012 pw.println(sb.toString());
3013 sb.setLength(0);
3014 sb.append(prefix);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003015 sb.append(" Time on battery screen off: ");
3016 formatTimeMs(sb, whichBatteryScreenOffRealtime / 1000); sb.append("(");
3017 sb.append(formatRatioLocked(whichBatteryScreenOffRealtime, totalRealtime));
3018 sb.append(") realtime, ");
3019 formatTimeMs(sb, whichBatteryScreenOffUptime / 1000);
3020 sb.append("(");
3021 sb.append(formatRatioLocked(whichBatteryScreenOffUptime, totalRealtime));
3022 sb.append(") uptime");
3023 pw.println(sb.toString());
3024 sb.setLength(0);
3025 sb.append(prefix);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003026 sb.append(" Total run time: ");
3027 formatTimeMs(sb, totalRealtime / 1000);
3028 sb.append("realtime, ");
3029 formatTimeMs(sb, totalUptime / 1000);
Dianne Hackborn77b987f2014-02-26 16:20:52 -08003030 sb.append("uptime");
Jeff Browne95c3cd2014-05-02 16:59:26 -07003031 pw.println(sb.toString());
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07003032 if (batteryTimeRemaining >= 0) {
3033 sb.setLength(0);
3034 sb.append(prefix);
3035 sb.append(" Battery time remaining: ");
3036 formatTimeMs(sb, batteryTimeRemaining / 1000);
3037 pw.println(sb.toString());
3038 }
3039 if (chargeTimeRemaining >= 0) {
3040 sb.setLength(0);
3041 sb.append(prefix);
3042 sb.append(" Charge time remaining: ");
3043 formatTimeMs(sb, chargeTimeRemaining / 1000);
3044 pw.println(sb.toString());
3045 }
Dianne Hackborn5f4a5f92014-01-24 16:59:34 -08003046 pw.print(" Start clock time: ");
3047 pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss", getStartClockTime()).toString());
3048
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003049 final long screenOnTime = getScreenOnTime(rawRealtime, which);
Jeff Browne95c3cd2014-05-02 16:59:26 -07003050 final long interactiveTime = getInteractiveTime(rawRealtime, which);
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07003051 final long powerSaveModeEnabledTime = getPowerSaveModeEnabledTime(rawRealtime, which);
3052 final long deviceIdleModeEnabledTime = getDeviceIdleModeEnabledTime(rawRealtime, which);
Dianne Hackborn88e98df2015-03-23 13:29:14 -07003053 final long deviceIdlingTime = getDeviceIdlingTime(rawRealtime, which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003054 final long phoneOnTime = getPhoneOnTime(rawRealtime, which);
3055 final long wifiRunningTime = getGlobalWifiRunningTime(rawRealtime, which);
3056 final long wifiOnTime = getWifiOnTime(rawRealtime, which);
Dianne Hackborn617f8772009-03-31 15:04:46 -07003057 sb.setLength(0);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003058 sb.append(prefix);
3059 sb.append(" Screen on: "); formatTimeMs(sb, screenOnTime / 1000);
3060 sb.append("("); sb.append(formatRatioLocked(screenOnTime, whichBatteryRealtime));
Dianne Hackborn77b987f2014-02-26 16:20:52 -08003061 sb.append(") "); sb.append(getScreenOnCount(which));
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07003062 sb.append("x, Interactive: "); formatTimeMs(sb, interactiveTime / 1000);
3063 sb.append("("); sb.append(formatRatioLocked(interactiveTime, whichBatteryRealtime));
Jeff Browne95c3cd2014-05-02 16:59:26 -07003064 sb.append(")");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003065 pw.println(sb.toString());
3066 sb.setLength(0);
3067 sb.append(prefix);
Dianne Hackborn77b987f2014-02-26 16:20:52 -08003068 sb.append(" Screen brightnesses:");
Dianne Hackborn617f8772009-03-31 15:04:46 -07003069 boolean didOne = false;
3070 for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003071 final long time = getScreenBrightnessTime(i, rawRealtime, which);
Dianne Hackborn617f8772009-03-31 15:04:46 -07003072 if (time == 0) {
3073 continue;
3074 }
Dianne Hackborn77b987f2014-02-26 16:20:52 -08003075 sb.append("\n ");
3076 sb.append(prefix);
Dianne Hackborn617f8772009-03-31 15:04:46 -07003077 didOne = true;
3078 sb.append(SCREEN_BRIGHTNESS_NAMES[i]);
3079 sb.append(" ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003080 formatTimeMs(sb, time/1000);
Dianne Hackborn617f8772009-03-31 15:04:46 -07003081 sb.append("(");
3082 sb.append(formatRatioLocked(time, screenOnTime));
3083 sb.append(")");
3084 }
Dianne Hackborn77b987f2014-02-26 16:20:52 -08003085 if (!didOne) sb.append(" (no activity)");
Dianne Hackborn617f8772009-03-31 15:04:46 -07003086 pw.println(sb.toString());
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07003087 if (powerSaveModeEnabledTime != 0) {
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07003088 sb.setLength(0);
3089 sb.append(prefix);
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07003090 sb.append(" Power save mode enabled: ");
3091 formatTimeMs(sb, powerSaveModeEnabledTime / 1000);
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07003092 sb.append("(");
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07003093 sb.append(formatRatioLocked(powerSaveModeEnabledTime, whichBatteryRealtime));
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07003094 sb.append(")");
3095 pw.println(sb.toString());
3096 }
Dianne Hackborn88e98df2015-03-23 13:29:14 -07003097 if (deviceIdlingTime != 0) {
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07003098 sb.setLength(0);
3099 sb.append(prefix);
3100 sb.append(" Device idling: ");
Dianne Hackborn88e98df2015-03-23 13:29:14 -07003101 formatTimeMs(sb, deviceIdlingTime / 1000);
3102 sb.append("(");
3103 sb.append(formatRatioLocked(deviceIdlingTime, whichBatteryRealtime));
3104 sb.append(") "); sb.append(getDeviceIdlingCount(which));
3105 sb.append("x");
3106 pw.println(sb.toString());
3107 }
3108 if (deviceIdleModeEnabledTime != 0) {
3109 sb.setLength(0);
3110 sb.append(prefix);
3111 sb.append(" Idle mode time: ");
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07003112 formatTimeMs(sb, deviceIdleModeEnabledTime / 1000);
3113 sb.append("(");
3114 sb.append(formatRatioLocked(deviceIdleModeEnabledTime, whichBatteryRealtime));
3115 sb.append(") "); sb.append(getDeviceIdleModeEnabledCount(which));
3116 sb.append("x");
3117 pw.println(sb.toString());
3118 }
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07003119 if (phoneOnTime != 0) {
3120 sb.setLength(0);
3121 sb.append(prefix);
3122 sb.append(" Active phone call: "); formatTimeMs(sb, phoneOnTime / 1000);
3123 sb.append("("); sb.append(formatRatioLocked(phoneOnTime, whichBatteryRealtime));
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07003124 sb.append(") "); sb.append(getPhoneOnCount(which)); sb.append("x");
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07003125 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003126 final int connChanges = getNumConnectivityChange(which);
Dianne Hackborn1e01d162014-12-04 17:46:42 -08003127 if (connChanges != 0) {
3128 pw.print(prefix);
3129 pw.print(" Connectivity changes: "); pw.println(connChanges);
3130 }
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07003131
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003132 // Calculate wakelock times across all uids.
Evan Millar22ac0432009-03-31 11:33:18 -07003133 long fullWakeLockTimeTotalMicros = 0;
3134 long partialWakeLockTimeTotalMicros = 0;
Dianne Hackborn81038902012-11-26 17:04:09 -08003135
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003136 final ArrayList<TimerEntry> timers = new ArrayList<>();
Dianne Hackborn81038902012-11-26 17:04:09 -08003137
Evan Millar22ac0432009-03-31 11:33:18 -07003138 for (int iu = 0; iu < NU; iu++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003139 final Uid u = uidStats.valueAt(iu);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07003140
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003141 final ArrayMap<String, ? extends BatteryStats.Uid.Wakelock> wakelocks
3142 = u.getWakelockStats();
3143 for (int iw=wakelocks.size()-1; iw>=0; iw--) {
3144 final Uid.Wakelock wl = wakelocks.valueAt(iw);
Evan Millar22ac0432009-03-31 11:33:18 -07003145
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003146 final Timer fullWakeTimer = wl.getWakeTime(WAKE_TYPE_FULL);
3147 if (fullWakeTimer != null) {
3148 fullWakeLockTimeTotalMicros += fullWakeTimer.getTotalTimeLocked(
3149 rawRealtime, which);
3150 }
3151
3152 final Timer partialWakeTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL);
3153 if (partialWakeTimer != null) {
3154 final long totalTimeMicros = partialWakeTimer.getTotalTimeLocked(
3155 rawRealtime, which);
3156 if (totalTimeMicros > 0) {
3157 if (reqUid < 0) {
3158 // Only show the ordered list of all wake
3159 // locks if the caller is not asking for data
3160 // about a specific uid.
3161 timers.add(new TimerEntry(wakelocks.keyAt(iw), u.getUid(),
3162 partialWakeTimer, totalTimeMicros));
Dianne Hackborn81038902012-11-26 17:04:09 -08003163 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003164 partialWakeLockTimeTotalMicros += totalTimeMicros;
Evan Millar22ac0432009-03-31 11:33:18 -07003165 }
3166 }
3167 }
3168 }
3169
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003170 final long mobileRxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which);
3171 final long mobileTxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which);
3172 final long wifiRxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which);
3173 final long wifiTxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which);
3174 final long mobileRxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which);
3175 final long mobileTxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which);
3176 final long wifiRxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which);
3177 final long wifiTxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003178
Dianne Hackborn77b987f2014-02-26 16:20:52 -08003179 if (fullWakeLockTimeTotalMicros != 0) {
3180 sb.setLength(0);
3181 sb.append(prefix);
3182 sb.append(" Total full wakelock time: "); formatTimeMsNoSpace(sb,
3183 (fullWakeLockTimeTotalMicros + 500) / 1000);
3184 pw.println(sb.toString());
3185 }
3186
3187 if (partialWakeLockTimeTotalMicros != 0) {
3188 sb.setLength(0);
3189 sb.append(prefix);
3190 sb.append(" Total partial wakelock time: "); formatTimeMsNoSpace(sb,
3191 (partialWakeLockTimeTotalMicros + 500) / 1000);
3192 pw.println(sb.toString());
3193 }
3194
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003195 pw.print(prefix);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003196 pw.print(" Mobile total received: "); pw.print(formatBytesLocked(mobileRxTotalBytes));
3197 pw.print(", sent: "); pw.print(formatBytesLocked(mobileTxTotalBytes));
3198 pw.print(" (packets received "); pw.print(mobileRxTotalPackets);
3199 pw.print(", sent "); pw.print(mobileTxTotalPackets); pw.println(")");
Dianne Hackborn627bba72009-03-24 22:32:56 -07003200 sb.setLength(0);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003201 sb.append(prefix);
Dianne Hackborn3251b902014-06-20 14:40:53 -07003202 sb.append(" Phone signal levels:");
Dianne Hackborn617f8772009-03-31 15:04:46 -07003203 didOne = false;
Wink Saville52840902011-02-18 12:40:47 -08003204 for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003205 final long time = getPhoneSignalStrengthTime(i, rawRealtime, which);
Dianne Hackborn627bba72009-03-24 22:32:56 -07003206 if (time == 0) {
3207 continue;
3208 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08003209 sb.append("\n ");
Dianne Hackborn77b987f2014-02-26 16:20:52 -08003210 sb.append(prefix);
Dianne Hackborn627bba72009-03-24 22:32:56 -07003211 didOne = true;
Wink Saville52840902011-02-18 12:40:47 -08003212 sb.append(SignalStrength.SIGNAL_STRENGTH_NAMES[i]);
Dianne Hackborn627bba72009-03-24 22:32:56 -07003213 sb.append(" ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003214 formatTimeMs(sb, time/1000);
Dianne Hackborn627bba72009-03-24 22:32:56 -07003215 sb.append("(");
3216 sb.append(formatRatioLocked(time, whichBatteryRealtime));
Dianne Hackborn617f8772009-03-31 15:04:46 -07003217 sb.append(") ");
3218 sb.append(getPhoneSignalStrengthCount(i, which));
3219 sb.append("x");
Dianne Hackborn627bba72009-03-24 22:32:56 -07003220 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08003221 if (!didOne) sb.append(" (no activity)");
Dianne Hackborn627bba72009-03-24 22:32:56 -07003222 pw.println(sb.toString());
Amith Yamasanif37447b2009-10-08 18:28:01 -07003223
3224 sb.setLength(0);
3225 sb.append(prefix);
3226 sb.append(" Signal scanning time: ");
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003227 formatTimeMsNoSpace(sb, getPhoneSignalScanningTime(rawRealtime, which) / 1000);
Amith Yamasanif37447b2009-10-08 18:28:01 -07003228 pw.println(sb.toString());
3229
Dianne Hackborn627bba72009-03-24 22:32:56 -07003230 sb.setLength(0);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003231 sb.append(prefix);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08003232 sb.append(" Radio types:");
Dianne Hackborn627bba72009-03-24 22:32:56 -07003233 didOne = false;
3234 for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003235 final long time = getPhoneDataConnectionTime(i, rawRealtime, which);
Dianne Hackborn627bba72009-03-24 22:32:56 -07003236 if (time == 0) {
3237 continue;
3238 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08003239 sb.append("\n ");
Dianne Hackborn77b987f2014-02-26 16:20:52 -08003240 sb.append(prefix);
Dianne Hackborn627bba72009-03-24 22:32:56 -07003241 didOne = true;
3242 sb.append(DATA_CONNECTION_NAMES[i]);
3243 sb.append(" ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003244 formatTimeMs(sb, time/1000);
Dianne Hackborn627bba72009-03-24 22:32:56 -07003245 sb.append("(");
3246 sb.append(formatRatioLocked(time, whichBatteryRealtime));
Dianne Hackborn617f8772009-03-31 15:04:46 -07003247 sb.append(") ");
3248 sb.append(getPhoneDataConnectionCount(i, which));
3249 sb.append("x");
Dianne Hackborn627bba72009-03-24 22:32:56 -07003250 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08003251 if (!didOne) sb.append(" (no activity)");
Dianne Hackborn627bba72009-03-24 22:32:56 -07003252 pw.println(sb.toString());
Amith Yamasani3f7e35c2009-07-13 16:02:45 -07003253
3254 sb.setLength(0);
3255 sb.append(prefix);
Dianne Hackborne13c4c02014-02-11 17:18:35 -08003256 sb.append(" Mobile radio active time: ");
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003257 final long mobileActiveTime = getMobileRadioActiveTime(rawRealtime, which);
Dianne Hackbornd45665b2014-02-26 12:35:32 -08003258 formatTimeMs(sb, mobileActiveTime / 1000);
3259 sb.append("("); sb.append(formatRatioLocked(mobileActiveTime, whichBatteryRealtime));
3260 sb.append(") "); sb.append(getMobileRadioActiveCount(which));
3261 sb.append("x");
Amith Yamasani3f7e35c2009-07-13 16:02:45 -07003262 pw.println(sb.toString());
3263
Dianne Hackbornd45665b2014-02-26 12:35:32 -08003264 final long mobileActiveUnknownTime = getMobileRadioActiveUnknownTime(which);
3265 if (mobileActiveUnknownTime != 0) {
3266 sb.setLength(0);
3267 sb.append(prefix);
3268 sb.append(" Mobile radio active unknown time: ");
3269 formatTimeMs(sb, mobileActiveUnknownTime / 1000);
3270 sb.append("(");
3271 sb.append(formatRatioLocked(mobileActiveUnknownTime, whichBatteryRealtime));
3272 sb.append(") "); sb.append(getMobileRadioActiveUnknownCount(which));
3273 sb.append("x");
3274 pw.println(sb.toString());
3275 }
3276
Dianne Hackborna1bd7922014-03-21 11:07:11 -07003277 final long mobileActiveAdjustedTime = getMobileRadioActiveAdjustedTime(which);
3278 if (mobileActiveAdjustedTime != 0) {
3279 sb.setLength(0);
3280 sb.append(prefix);
3281 sb.append(" Mobile radio active adjusted time: ");
3282 formatTimeMs(sb, mobileActiveAdjustedTime / 1000);
3283 sb.append("(");
3284 sb.append(formatRatioLocked(mobileActiveAdjustedTime, whichBatteryRealtime));
3285 sb.append(")");
3286 pw.println(sb.toString());
3287 }
3288
Dianne Hackborn77b987f2014-02-26 16:20:52 -08003289 pw.print(prefix);
3290 pw.print(" Wi-Fi total received: "); pw.print(formatBytesLocked(wifiRxTotalBytes));
3291 pw.print(", sent: "); pw.print(formatBytesLocked(wifiTxTotalBytes));
3292 pw.print(" (packets received "); pw.print(wifiRxTotalPackets);
3293 pw.print(", sent "); pw.print(wifiTxTotalPackets); pw.println(")");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003294 sb.setLength(0);
3295 sb.append(prefix);
3296 sb.append(" Wifi on: "); formatTimeMs(sb, wifiOnTime / 1000);
3297 sb.append("("); sb.append(formatRatioLocked(wifiOnTime, whichBatteryRealtime));
3298 sb.append("), Wifi running: "); formatTimeMs(sb, wifiRunningTime / 1000);
3299 sb.append("("); sb.append(formatRatioLocked(wifiRunningTime, whichBatteryRealtime));
Dianne Hackbornca1bf212014-02-14 14:18:36 -08003300 sb.append(")");
3301 pw.println(sb.toString());
3302
3303 sb.setLength(0);
3304 sb.append(prefix);
3305 sb.append(" Wifi states:");
3306 didOne = false;
3307 for (int i=0; i<NUM_WIFI_STATES; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003308 final long time = getWifiStateTime(i, rawRealtime, which);
Dianne Hackbornca1bf212014-02-14 14:18:36 -08003309 if (time == 0) {
3310 continue;
3311 }
3312 sb.append("\n ");
3313 didOne = true;
3314 sb.append(WIFI_STATE_NAMES[i]);
3315 sb.append(" ");
3316 formatTimeMs(sb, time/1000);
3317 sb.append("(");
3318 sb.append(formatRatioLocked(time, whichBatteryRealtime));
3319 sb.append(") ");
Dianne Hackborn3251b902014-06-20 14:40:53 -07003320 sb.append(getWifiStateCount(i, which));
3321 sb.append("x");
3322 }
3323 if (!didOne) sb.append(" (no activity)");
3324 pw.println(sb.toString());
3325
3326 sb.setLength(0);
3327 sb.append(prefix);
3328 sb.append(" Wifi supplicant states:");
3329 didOne = false;
3330 for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) {
3331 final long time = getWifiSupplStateTime(i, rawRealtime, which);
3332 if (time == 0) {
3333 continue;
3334 }
3335 sb.append("\n ");
3336 didOne = true;
3337 sb.append(WIFI_SUPPL_STATE_NAMES[i]);
3338 sb.append(" ");
3339 formatTimeMs(sb, time/1000);
3340 sb.append("(");
3341 sb.append(formatRatioLocked(time, whichBatteryRealtime));
3342 sb.append(") ");
3343 sb.append(getWifiSupplStateCount(i, which));
3344 sb.append("x");
3345 }
3346 if (!didOne) sb.append(" (no activity)");
3347 pw.println(sb.toString());
3348
3349 sb.setLength(0);
3350 sb.append(prefix);
3351 sb.append(" Wifi signal levels:");
3352 didOne = false;
3353 for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) {
3354 final long time = getWifiSignalStrengthTime(i, rawRealtime, which);
3355 if (time == 0) {
3356 continue;
3357 }
3358 sb.append("\n ");
3359 sb.append(prefix);
3360 didOne = true;
3361 sb.append("level(");
3362 sb.append(i);
3363 sb.append(") ");
3364 formatTimeMs(sb, time/1000);
3365 sb.append("(");
3366 sb.append(formatRatioLocked(time, whichBatteryRealtime));
3367 sb.append(") ");
3368 sb.append(getWifiSignalStrengthCount(i, which));
Dianne Hackbornca1bf212014-02-14 14:18:36 -08003369 sb.append("x");
3370 }
3371 if (!didOne) sb.append(" (no activity)");
3372 pw.println(sb.toString());
3373
Adam Lesinski4b6bd8d2015-03-19 14:35:45 -07003374 final long wifiIdleTimeMs = getWifiControllerActivity(CONTROLLER_IDLE_TIME, which);
3375 final long wifiRxTimeMs = getWifiControllerActivity(CONTROLLER_RX_TIME, which);
3376 final long wifiTxTimeMs = getWifiControllerActivity(CONTROLLER_TX_TIME, which);
Adam Lesinski049c88b2015-05-28 11:38:12 -07003377 final long wifiPowerDrainMaMs = getWifiControllerActivity(CONTROLLER_POWER_DRAIN, which);
Adam Lesinski33dac552015-03-09 15:24:48 -07003378 final long wifiTotalTimeMs = wifiIdleTimeMs + wifiRxTimeMs + wifiTxTimeMs;
3379
3380 sb.setLength(0);
3381 sb.append(prefix);
3382 sb.append(" WiFi Idle time: "); formatTimeMs(sb, wifiIdleTimeMs);
Adam Lesinski049c88b2015-05-28 11:38:12 -07003383 sb.append("(");
Adam Lesinski33dac552015-03-09 15:24:48 -07003384 sb.append(formatRatioLocked(wifiIdleTimeMs, wifiTotalTimeMs));
3385 sb.append(")");
3386 pw.println(sb.toString());
3387
3388 sb.setLength(0);
3389 sb.append(prefix);
3390 sb.append(" WiFi Rx time: "); formatTimeMs(sb, wifiRxTimeMs);
Adam Lesinski049c88b2015-05-28 11:38:12 -07003391 sb.append("(");
Adam Lesinski33dac552015-03-09 15:24:48 -07003392 sb.append(formatRatioLocked(wifiRxTimeMs, wifiTotalTimeMs));
3393 sb.append(")");
3394 pw.println(sb.toString());
3395
3396 sb.setLength(0);
3397 sb.append(prefix);
3398 sb.append(" WiFi Tx time: "); formatTimeMs(sb, wifiTxTimeMs);
Adam Lesinski049c88b2015-05-28 11:38:12 -07003399 sb.append("(");
Adam Lesinski33dac552015-03-09 15:24:48 -07003400 sb.append(formatRatioLocked(wifiTxTimeMs, wifiTotalTimeMs));
3401 sb.append(")");
3402 pw.println(sb.toString());
3403
Dianne Hackbornca1bf212014-02-14 14:18:36 -08003404 sb.setLength(0);
3405 sb.append(prefix);
Adam Lesinski049c88b2015-05-28 11:38:12 -07003406 sb.append(" WiFi Power drain: ").append(
3407 BatteryStatsHelper.makemAh(wifiPowerDrainMaMs / (double) (1000*60*60)));
3408 sb.append("mAh");
Adam Lesinskie08af192015-03-25 16:42:59 -07003409 pw.println(sb.toString());
3410
Adam Lesinski33dac552015-03-09 15:24:48 -07003411 final long bluetoothIdleTimeMs =
3412 getBluetoothControllerActivity(CONTROLLER_IDLE_TIME, which);
3413 final long bluetoothRxTimeMs = getBluetoothControllerActivity(CONTROLLER_RX_TIME, which);
3414 final long bluetoothTxTimeMs = getBluetoothControllerActivity(CONTROLLER_TX_TIME, which);
3415 final long bluetoothTotalTimeMs = bluetoothIdleTimeMs + bluetoothRxTimeMs +
3416 bluetoothTxTimeMs;
3417
3418 sb.setLength(0);
3419 sb.append(prefix);
3420 sb.append(" Bluetooth Idle time: "); formatTimeMs(sb, bluetoothIdleTimeMs);
Adam Lesinski049c88b2015-05-28 11:38:12 -07003421 sb.append("(");
Adam Lesinski33dac552015-03-09 15:24:48 -07003422 sb.append(formatRatioLocked(bluetoothIdleTimeMs, bluetoothTotalTimeMs));
3423 sb.append(")");
3424 pw.println(sb.toString());
3425
3426 sb.setLength(0);
3427 sb.append(prefix);
3428 sb.append(" Bluetooth Rx time: "); formatTimeMs(sb, bluetoothRxTimeMs);
Adam Lesinski049c88b2015-05-28 11:38:12 -07003429 sb.append("(");
Adam Lesinski33dac552015-03-09 15:24:48 -07003430 sb.append(formatRatioLocked(bluetoothRxTimeMs, bluetoothTotalTimeMs));
3431 sb.append(")");
3432 pw.println(sb.toString());
3433
3434 sb.setLength(0);
3435 sb.append(prefix);
3436 sb.append(" Bluetooth Tx time: "); formatTimeMs(sb, bluetoothTxTimeMs);
Adam Lesinski049c88b2015-05-28 11:38:12 -07003437 sb.append("(");
Adam Lesinski33dac552015-03-09 15:24:48 -07003438 sb.append(formatRatioLocked(bluetoothTxTimeMs, bluetoothTotalTimeMs));
3439 sb.append(")");
3440 pw.println(sb.toString());
3441
Adam Lesinskie283d332015-04-16 12:29:25 -07003442 sb.setLength(0);
3443 sb.append(prefix);
3444 sb.append(" Bluetooth Power drain: ").append(BatteryStatsHelper.makemAh(
3445 getBluetoothControllerActivity(CONTROLLER_POWER_DRAIN, which) /
3446 (double)(1000*60*60)));
Adam Lesinski049c88b2015-05-28 11:38:12 -07003447 sb.append("mAh");
Adam Lesinskie283d332015-04-16 12:29:25 -07003448 pw.println(sb.toString());
3449
Dianne Hackbornca1bf212014-02-14 14:18:36 -08003450 pw.println();
The Android Open Source Project10592532009-03-18 17:39:46 -07003451
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07003452 if (which == STATS_SINCE_UNPLUGGED) {
The Android Open Source Project10592532009-03-18 17:39:46 -07003453 if (getIsOnBattery()) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003454 pw.print(prefix); pw.println(" Device is currently unplugged");
3455 pw.print(prefix); pw.print(" Discharge cycle start level: ");
3456 pw.println(getDischargeStartLevel());
3457 pw.print(prefix); pw.print(" Discharge cycle current level: ");
3458 pw.println(getDischargeCurrentLevel());
Dianne Hackborn99d04522010-08-20 13:43:00 -07003459 } else {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003460 pw.print(prefix); pw.println(" Device is currently plugged into power");
3461 pw.print(prefix); pw.print(" Last discharge cycle start level: ");
3462 pw.println(getDischargeStartLevel());
3463 pw.print(prefix); pw.print(" Last discharge cycle end level: ");
3464 pw.println(getDischargeCurrentLevel());
The Android Open Source Project10592532009-03-18 17:39:46 -07003465 }
Dianne Hackbornc1b40e32011-01-05 18:27:40 -08003466 pw.print(prefix); pw.print(" Amount discharged while screen on: ");
3467 pw.println(getDischargeAmountScreenOn());
3468 pw.print(prefix); pw.print(" Amount discharged while screen off: ");
3469 pw.println(getDischargeAmountScreenOff());
Dianne Hackborn617f8772009-03-31 15:04:46 -07003470 pw.println(" ");
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07003471 } else {
3472 pw.print(prefix); pw.println(" Device battery use since last full charge");
3473 pw.print(prefix); pw.print(" Amount discharged (lower bound): ");
3474 pw.println(getLowDischargeAmountSinceCharge());
3475 pw.print(prefix); pw.print(" Amount discharged (upper bound): ");
3476 pw.println(getHighDischargeAmountSinceCharge());
Dianne Hackbornc1b40e32011-01-05 18:27:40 -08003477 pw.print(prefix); pw.print(" Amount discharged while screen on: ");
3478 pw.println(getDischargeAmountScreenOnSinceCharge());
3479 pw.print(prefix); pw.print(" Amount discharged while screen off: ");
3480 pw.println(getDischargeAmountScreenOffSinceCharge());
Dianne Hackborn81038902012-11-26 17:04:09 -08003481 pw.println();
The Android Open Source Project10592532009-03-18 17:39:46 -07003482 }
Dianne Hackborn81038902012-11-26 17:04:09 -08003483
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003484 final BatteryStatsHelper helper = new BatteryStatsHelper(context, false, wifiOnly);
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003485 helper.create(this);
3486 helper.refreshStats(which, UserHandle.USER_ALL);
3487 List<BatterySipper> sippers = helper.getUsageList();
3488 if (sippers != null && sippers.size() > 0) {
3489 pw.print(prefix); pw.println(" Estimated power use (mAh):");
3490 pw.print(prefix); pw.print(" Capacity: ");
3491 printmAh(pw, helper.getPowerProfile().getBatteryCapacity());
Dianne Hackborn099bc622014-01-22 13:39:16 -08003492 pw.print(", Computed drain: "); printmAh(pw, helper.getComputedPower());
Dianne Hackborn536456f2014-05-23 16:51:05 -07003493 pw.print(", actual drain: "); printmAh(pw, helper.getMinDrainedPower());
3494 if (helper.getMinDrainedPower() != helper.getMaxDrainedPower()) {
3495 pw.print("-"); printmAh(pw, helper.getMaxDrainedPower());
3496 }
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003497 pw.println();
3498 for (int i=0; i<sippers.size(); i++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003499 final BatterySipper bs = sippers.get(i);
Adam Lesinski628ef9c2015-06-10 13:08:57 -07003500 pw.print(prefix);
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003501 switch (bs.drainType) {
3502 case IDLE:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07003503 pw.print(" Idle: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003504 break;
3505 case CELL:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07003506 pw.print(" Cell standby: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003507 break;
3508 case PHONE:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07003509 pw.print(" Phone calls: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003510 break;
3511 case WIFI:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07003512 pw.print(" Wifi: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003513 break;
3514 case BLUETOOTH:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07003515 pw.print(" Bluetooth: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003516 break;
3517 case SCREEN:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07003518 pw.print(" Screen: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003519 break;
Dianne Hackbornabc7c492014-06-30 16:57:46 -07003520 case FLASHLIGHT:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07003521 pw.print(" Flashlight: ");
Dianne Hackbornabc7c492014-06-30 16:57:46 -07003522 break;
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003523 case APP:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07003524 pw.print(" Uid ");
Dianne Hackbornd45665b2014-02-26 12:35:32 -08003525 UserHandle.formatUid(pw, bs.uidObj.getUid());
Adam Lesinski628ef9c2015-06-10 13:08:57 -07003526 pw.print(": ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003527 break;
3528 case USER:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07003529 pw.print(" User "); pw.print(bs.userId);
3530 pw.print(": ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003531 break;
3532 case UNACCOUNTED:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07003533 pw.print(" Unaccounted: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003534 break;
3535 case OVERCOUNTED:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07003536 pw.print(" Over-counted: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003537 break;
Ruben Brunk5b1308f2015-06-03 18:49:27 -07003538 case CAMERA:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07003539 pw.print(" Camera: ");
3540 break;
3541 default:
3542 pw.print(" ???: ");
Ruben Brunk5b1308f2015-06-03 18:49:27 -07003543 break;
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003544 }
Adam Lesinski628ef9c2015-06-10 13:08:57 -07003545 printmAh(pw, bs.totalPowerMah);
3546
Adam Lesinski57123002015-06-12 16:12:07 -07003547 if (bs.usagePowerMah != bs.totalPowerMah) {
3548 // If the usage (generic power) isn't the whole amount, we list out
3549 // what components are involved in the calculation.
3550
Adam Lesinski628ef9c2015-06-10 13:08:57 -07003551 pw.print(" (");
Adam Lesinski57123002015-06-12 16:12:07 -07003552 if (bs.usagePowerMah != 0) {
3553 pw.print(" usage=");
3554 printmAh(pw, bs.usagePowerMah);
3555 }
Adam Lesinski628ef9c2015-06-10 13:08:57 -07003556 if (bs.cpuPowerMah != 0) {
3557 pw.print(" cpu=");
3558 printmAh(pw, bs.cpuPowerMah);
3559 }
3560 if (bs.wakeLockPowerMah != 0) {
3561 pw.print(" wake=");
3562 printmAh(pw, bs.wakeLockPowerMah);
3563 }
3564 if (bs.mobileRadioPowerMah != 0) {
3565 pw.print(" radio=");
3566 printmAh(pw, bs.mobileRadioPowerMah);
3567 }
3568 if (bs.wifiPowerMah != 0) {
3569 pw.print(" wifi=");
3570 printmAh(pw, bs.wifiPowerMah);
3571 }
3572 if (bs.gpsPowerMah != 0) {
3573 pw.print(" gps=");
3574 printmAh(pw, bs.gpsPowerMah);
3575 }
3576 if (bs.sensorPowerMah != 0) {
3577 pw.print(" sensor=");
3578 printmAh(pw, bs.sensorPowerMah);
3579 }
3580 if (bs.cameraPowerMah != 0) {
3581 pw.print(" camera=");
3582 printmAh(pw, bs.cameraPowerMah);
3583 }
3584 if (bs.flashlightPowerMah != 0) {
3585 pw.print(" flash=");
3586 printmAh(pw, bs.flashlightPowerMah);
3587 }
3588 pw.print(" )");
3589 }
3590 pw.println();
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003591 }
Dianne Hackbornc46809e2014-01-15 16:20:44 -08003592 pw.println();
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003593 }
3594
Dianne Hackbornd45665b2014-02-26 12:35:32 -08003595 sippers = helper.getMobilemsppList();
3596 if (sippers != null && sippers.size() > 0) {
3597 pw.print(prefix); pw.println(" Per-app mobile ms per packet:");
Dianne Hackborn77b987f2014-02-26 16:20:52 -08003598 long totalTime = 0;
Dianne Hackbornd45665b2014-02-26 12:35:32 -08003599 for (int i=0; i<sippers.size(); i++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003600 final BatterySipper bs = sippers.get(i);
Dianne Hackbornd45665b2014-02-26 12:35:32 -08003601 sb.setLength(0);
3602 sb.append(prefix); sb.append(" Uid ");
3603 UserHandle.formatUid(sb, bs.uidObj.getUid());
3604 sb.append(": "); sb.append(BatteryStatsHelper.makemAh(bs.mobilemspp));
3605 sb.append(" ("); sb.append(bs.mobileRxPackets+bs.mobileTxPackets);
3606 sb.append(" packets over "); formatTimeMsNoSpace(sb, bs.mobileActive);
Dianne Hackborn77b987f2014-02-26 16:20:52 -08003607 sb.append(") "); sb.append(bs.mobileActiveCount); sb.append("x");
Dianne Hackbornd45665b2014-02-26 12:35:32 -08003608 pw.println(sb.toString());
Dianne Hackborn77b987f2014-02-26 16:20:52 -08003609 totalTime += bs.mobileActive;
Dianne Hackbornd45665b2014-02-26 12:35:32 -08003610 }
Dianne Hackborn77b987f2014-02-26 16:20:52 -08003611 sb.setLength(0);
3612 sb.append(prefix);
3613 sb.append(" TOTAL TIME: ");
3614 formatTimeMs(sb, totalTime);
3615 sb.append("("); sb.append(formatRatioLocked(totalTime, whichBatteryRealtime));
3616 sb.append(")");
3617 pw.println(sb.toString());
Dianne Hackbornd45665b2014-02-26 12:35:32 -08003618 pw.println();
3619 }
3620
Dianne Hackbornc51cf032014-03-02 19:08:15 -08003621 final Comparator<TimerEntry> timerComparator = new Comparator<TimerEntry>() {
3622 @Override
3623 public int compare(TimerEntry lhs, TimerEntry rhs) {
3624 long lhsTime = lhs.mTime;
3625 long rhsTime = rhs.mTime;
3626 if (lhsTime < rhsTime) {
3627 return 1;
3628 }
3629 if (lhsTime > rhsTime) {
3630 return -1;
3631 }
3632 return 0;
3633 }
3634 };
3635
3636 if (reqUid < 0) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003637 final Map<String, ? extends BatteryStats.Timer> kernelWakelocks
3638 = getKernelWakelockStats();
Dianne Hackbornc51cf032014-03-02 19:08:15 -08003639 if (kernelWakelocks.size() > 0) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003640 final ArrayList<TimerEntry> ktimers = new ArrayList<>();
3641 for (Map.Entry<String, ? extends BatteryStats.Timer> ent
3642 : kernelWakelocks.entrySet()) {
3643 final BatteryStats.Timer timer = ent.getValue();
3644 final long totalTimeMillis = computeWakeLock(timer, rawRealtime, which);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08003645 if (totalTimeMillis > 0) {
3646 ktimers.add(new TimerEntry(ent.getKey(), 0, timer, totalTimeMillis));
3647 }
3648 }
3649 if (ktimers.size() > 0) {
3650 Collections.sort(ktimers, timerComparator);
3651 pw.print(prefix); pw.println(" All kernel wake locks:");
3652 for (int i=0; i<ktimers.size(); i++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003653 final TimerEntry timer = ktimers.get(i);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08003654 String linePrefix = ": ";
3655 sb.setLength(0);
3656 sb.append(prefix);
3657 sb.append(" Kernel Wake lock ");
3658 sb.append(timer.mName);
3659 linePrefix = printWakeLock(sb, timer.mTimer, rawRealtime, null,
3660 which, linePrefix);
3661 if (!linePrefix.equals(": ")) {
3662 sb.append(" realtime");
3663 // Only print out wake locks that were held
3664 pw.println(sb.toString());
3665 }
3666 }
3667 pw.println();
3668 }
3669 }
Dianne Hackbornc51cf032014-03-02 19:08:15 -08003670
Dianne Hackborna1bd7922014-03-21 11:07:11 -07003671 if (timers.size() > 0) {
3672 Collections.sort(timers, timerComparator);
3673 pw.print(prefix); pw.println(" All partial wake locks:");
3674 for (int i=0; i<timers.size(); i++) {
3675 TimerEntry timer = timers.get(i);
3676 sb.setLength(0);
3677 sb.append(" Wake lock ");
3678 UserHandle.formatUid(sb, timer.mId);
3679 sb.append(" ");
3680 sb.append(timer.mName);
3681 printWakeLock(sb, timer.mTimer, rawRealtime, null, which, ": ");
3682 sb.append(" realtime");
3683 pw.println(sb.toString());
3684 }
3685 timers.clear();
3686 pw.println();
Dianne Hackborn81038902012-11-26 17:04:09 -08003687 }
Dianne Hackborna1bd7922014-03-21 11:07:11 -07003688
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003689 final Map<String, ? extends Timer> wakeupReasons = getWakeupReasonStats();
Dianne Hackborna1bd7922014-03-21 11:07:11 -07003690 if (wakeupReasons.size() > 0) {
3691 pw.print(prefix); pw.println(" All wakeup reasons:");
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003692 final ArrayList<TimerEntry> reasons = new ArrayList<>();
Dianne Hackbornc3940bc2014-09-05 15:50:25 -07003693 for (Map.Entry<String, ? extends Timer> ent : wakeupReasons.entrySet()) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003694 final Timer timer = ent.getValue();
Dianne Hackbornc3940bc2014-09-05 15:50:25 -07003695 reasons.add(new TimerEntry(ent.getKey(), 0, timer,
3696 timer.getCountLocked(which)));
Dianne Hackborna1bd7922014-03-21 11:07:11 -07003697 }
3698 Collections.sort(reasons, timerComparator);
3699 for (int i=0; i<reasons.size(); i++) {
3700 TimerEntry timer = reasons.get(i);
3701 String linePrefix = ": ";
3702 sb.setLength(0);
3703 sb.append(prefix);
3704 sb.append(" Wakeup reason ");
3705 sb.append(timer.mName);
Dianne Hackbornc3940bc2014-09-05 15:50:25 -07003706 printWakeLock(sb, timer.mTimer, rawRealtime, null, which, ": ");
3707 sb.append(" realtime");
Dianne Hackborna1bd7922014-03-21 11:07:11 -07003708 pw.println(sb.toString());
3709 }
3710 pw.println();
3711 }
Dianne Hackborn81038902012-11-26 17:04:09 -08003712 }
Evan Millar22ac0432009-03-31 11:33:18 -07003713
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003714 for (int iu=0; iu<NU; iu++) {
3715 final int uid = uidStats.keyAt(iu);
Dianne Hackborne4a59512010-12-07 11:08:07 -08003716 if (reqUid >= 0 && uid != reqUid && uid != Process.SYSTEM_UID) {
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08003717 continue;
3718 }
3719
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003720 final Uid u = uidStats.valueAt(iu);
Dianne Hackborna4cc2052013-07-08 17:31:25 -07003721
3722 pw.print(prefix);
3723 pw.print(" ");
3724 UserHandle.formatUid(pw, uid);
3725 pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003726 boolean uidActivity = false;
Dianne Hackbornd45665b2014-02-26 12:35:32 -08003727
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003728 final long mobileRxBytes = u.getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which);
3729 final long mobileTxBytes = u.getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which);
3730 final long wifiRxBytes = u.getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which);
3731 final long wifiTxBytes = u.getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which);
3732 final long mobileRxPackets = u.getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which);
3733 final long mobileTxPackets = u.getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which);
3734 final long uidMobileActiveTime = u.getMobileRadioActiveTime(which);
3735 final int uidMobileActiveCount = u.getMobileRadioActiveCount(which);
3736 final long wifiRxPackets = u.getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which);
3737 final long wifiTxPackets = u.getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which);
3738 final long fullWifiLockOnTime = u.getFullWifiLockTime(rawRealtime, which);
3739 final long wifiScanTime = u.getWifiScanTime(rawRealtime, which);
3740 final int wifiScanCount = u.getWifiScanCount(which);
3741 final long uidWifiRunningTime = u.getWifiRunningTime(rawRealtime, which);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07003742
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003743 if (mobileRxBytes > 0 || mobileTxBytes > 0
3744 || mobileRxPackets > 0 || mobileTxPackets > 0) {
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07003745 pw.print(prefix); pw.print(" Mobile network: ");
3746 pw.print(formatBytesLocked(mobileRxBytes)); pw.print(" received, ");
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003747 pw.print(formatBytesLocked(mobileTxBytes));
3748 pw.print(" sent (packets "); pw.print(mobileRxPackets);
3749 pw.print(" received, "); pw.print(mobileTxPackets); pw.println(" sent)");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003750 }
Dianne Hackbornd45665b2014-02-26 12:35:32 -08003751 if (uidMobileActiveTime > 0 || uidMobileActiveCount > 0) {
3752 sb.setLength(0);
3753 sb.append(prefix); sb.append(" Mobile radio active: ");
3754 formatTimeMs(sb, uidMobileActiveTime / 1000);
3755 sb.append("(");
3756 sb.append(formatRatioLocked(uidMobileActiveTime, mobileActiveTime));
3757 sb.append(") "); sb.append(uidMobileActiveCount); sb.append("x");
3758 long packets = mobileRxPackets + mobileTxPackets;
3759 if (packets == 0) {
3760 packets = 1;
3761 }
3762 sb.append(" @ ");
3763 sb.append(BatteryStatsHelper.makemAh(uidMobileActiveTime / 1000 / (double)packets));
3764 sb.append(" mspp");
3765 pw.println(sb.toString());
3766 }
3767
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003768 if (wifiRxBytes > 0 || wifiTxBytes > 0 || wifiRxPackets > 0 || wifiTxPackets > 0) {
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07003769 pw.print(prefix); pw.print(" Wi-Fi network: ");
3770 pw.print(formatBytesLocked(wifiRxBytes)); pw.print(" received, ");
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003771 pw.print(formatBytesLocked(wifiTxBytes));
3772 pw.print(" sent (packets "); pw.print(wifiRxPackets);
3773 pw.print(" received, "); pw.print(wifiTxPackets); pw.println(" sent)");
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07003774 }
3775
Dianne Hackborn62793e42015-03-09 11:15:41 -07003776 if (fullWifiLockOnTime != 0 || wifiScanTime != 0 || wifiScanCount != 0
Dianne Hackbornd45665b2014-02-26 12:35:32 -08003777 || uidWifiRunningTime != 0) {
3778 sb.setLength(0);
3779 sb.append(prefix); sb.append(" Wifi Running: ");
3780 formatTimeMs(sb, uidWifiRunningTime / 1000);
3781 sb.append("("); sb.append(formatRatioLocked(uidWifiRunningTime,
3782 whichBatteryRealtime)); sb.append(")\n");
3783 sb.append(prefix); sb.append(" Full Wifi Lock: ");
3784 formatTimeMs(sb, fullWifiLockOnTime / 1000);
3785 sb.append("("); sb.append(formatRatioLocked(fullWifiLockOnTime,
3786 whichBatteryRealtime)); sb.append(")\n");
3787 sb.append(prefix); sb.append(" Wifi Scan: ");
3788 formatTimeMs(sb, wifiScanTime / 1000);
3789 sb.append("("); sb.append(formatRatioLocked(wifiScanTime,
Dianne Hackborn62793e42015-03-09 11:15:41 -07003790 whichBatteryRealtime)); sb.append(") ");
3791 sb.append(wifiScanCount);
3792 sb.append("x");
Dianne Hackbornd45665b2014-02-26 12:35:32 -08003793 pw.println(sb.toString());
3794 }
3795
Adam Lesinski049c88b2015-05-28 11:38:12 -07003796 final long uidWifiIdleTimeMs = u.getWifiControllerActivity(CONTROLLER_IDLE_TIME, which);
3797 final long uidWifiRxTimeMs = u.getWifiControllerActivity(CONTROLLER_RX_TIME, which);
3798 final long uidWifiTxTimeMs = u.getWifiControllerActivity(CONTROLLER_TX_TIME, which);
3799 final long uidWifiTotalTimeMs = uidWifiIdleTimeMs + uidWifiRxTimeMs + uidWifiTxTimeMs;
3800 if (uidWifiTotalTimeMs > 0) {
3801 sb.setLength(0);
3802 sb.append(prefix).append(" WiFi Idle time: ");
3803 formatTimeMs(sb, uidWifiIdleTimeMs);
3804 sb.append("(").append(formatRatioLocked(uidWifiIdleTimeMs, uidWifiTotalTimeMs))
3805 .append(")\n");
3806
3807 sb.append(prefix).append(" WiFi Rx time: "); formatTimeMs(sb, uidWifiRxTimeMs);
3808 sb.append("(").append(formatRatioLocked(uidWifiRxTimeMs, uidWifiTotalTimeMs))
3809 .append(")\n");
3810
3811 sb.append(prefix).append(" WiFi Tx time: "); formatTimeMs(sb, uidWifiTxTimeMs);
3812 sb.append("(").append(formatRatioLocked(uidWifiTxTimeMs, uidWifiTotalTimeMs))
3813 .append(")");
3814 pw.println(sb.toString());
3815 }
3816
Dianne Hackborn617f8772009-03-31 15:04:46 -07003817 if (u.hasUserActivity()) {
3818 boolean hasData = false;
Raph Levien4c7a4a72012-08-03 14:32:39 -07003819 for (int i=0; i<Uid.NUM_USER_ACTIVITY_TYPES; i++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003820 final int val = u.getUserActivityCount(i, which);
Dianne Hackborn617f8772009-03-31 15:04:46 -07003821 if (val != 0) {
3822 if (!hasData) {
3823 sb.setLength(0);
3824 sb.append(" User activity: ");
3825 hasData = true;
3826 } else {
3827 sb.append(", ");
3828 }
3829 sb.append(val);
3830 sb.append(" ");
3831 sb.append(Uid.USER_ACTIVITY_TYPES[i]);
3832 }
3833 }
3834 if (hasData) {
3835 pw.println(sb.toString());
3836 }
3837 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003838
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003839 final ArrayMap<String, ? extends BatteryStats.Uid.Wakelock> wakelocks
3840 = u.getWakelockStats();
3841 long totalFullWakelock = 0, totalPartialWakelock = 0, totalWindowWakelock = 0;
Jeff Brown6a8bd7b2015-06-19 15:07:51 -07003842 long totalDrawWakelock = 0;
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003843 int countWakelock = 0;
3844 for (int iw=wakelocks.size()-1; iw>=0; iw--) {
3845 final Uid.Wakelock wl = wakelocks.valueAt(iw);
3846 String linePrefix = ": ";
3847 sb.setLength(0);
3848 sb.append(prefix);
3849 sb.append(" Wake lock ");
3850 sb.append(wakelocks.keyAt(iw));
3851 linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_FULL), rawRealtime,
3852 "full", which, linePrefix);
3853 linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_PARTIAL), rawRealtime,
3854 "partial", which, linePrefix);
3855 linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_WINDOW), rawRealtime,
3856 "window", which, linePrefix);
Jeff Brown6a8bd7b2015-06-19 15:07:51 -07003857 linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_DRAW), rawRealtime,
3858 "draw", which, linePrefix);
Adam Lesinski9425fe22015-06-19 12:02:13 -07003859 sb.append(" realtime");
3860 pw.println(sb.toString());
3861 uidActivity = true;
3862 countWakelock++;
3863
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003864 totalFullWakelock += computeWakeLock(wl.getWakeTime(WAKE_TYPE_FULL),
3865 rawRealtime, which);
3866 totalPartialWakelock += computeWakeLock(wl.getWakeTime(WAKE_TYPE_PARTIAL),
3867 rawRealtime, which);
3868 totalWindowWakelock += computeWakeLock(wl.getWakeTime(WAKE_TYPE_WINDOW),
3869 rawRealtime, which);
Jeff Brown6a8bd7b2015-06-19 15:07:51 -07003870 totalDrawWakelock += computeWakeLock(wl.getWakeTime(WAKE_TYPE_DRAW),
Adam Lesinski9425fe22015-06-19 12:02:13 -07003871 rawRealtime, which);
Dianne Hackbornfdb19562014-07-11 16:03:36 -07003872 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003873 if (countWakelock > 1) {
3874 if (totalFullWakelock != 0 || totalPartialWakelock != 0
3875 || totalWindowWakelock != 0) {
Dianne Hackbornfdb19562014-07-11 16:03:36 -07003876 sb.setLength(0);
3877 sb.append(prefix);
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003878 sb.append(" TOTAL wake: ");
3879 boolean needComma = false;
3880 if (totalFullWakelock != 0) {
3881 needComma = true;
3882 formatTimeMs(sb, totalFullWakelock);
3883 sb.append("full");
Dianne Hackbornfdb19562014-07-11 16:03:36 -07003884 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003885 if (totalPartialWakelock != 0) {
3886 if (needComma) {
3887 sb.append(", ");
3888 }
3889 needComma = true;
3890 formatTimeMs(sb, totalPartialWakelock);
3891 sb.append("partial");
3892 }
3893 if (totalWindowWakelock != 0) {
3894 if (needComma) {
3895 sb.append(", ");
3896 }
3897 needComma = true;
3898 formatTimeMs(sb, totalWindowWakelock);
3899 sb.append("window");
3900 }
Jeff Brown6a8bd7b2015-06-19 15:07:51 -07003901 if (totalDrawWakelock != 0) {
Adam Lesinski9425fe22015-06-19 12:02:13 -07003902 if (needComma) {
3903 sb.append(",");
3904 }
3905 needComma = true;
Jeff Brown6a8bd7b2015-06-19 15:07:51 -07003906 formatTimeMs(sb, totalDrawWakelock);
3907 sb.append("draw");
Adam Lesinski9425fe22015-06-19 12:02:13 -07003908 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003909 sb.append(" realtime");
Dianne Hackbornfdb19562014-07-11 16:03:36 -07003910 pw.println(sb.toString());
Dianne Hackbornfdb19562014-07-11 16:03:36 -07003911 }
3912 }
3913
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003914 final ArrayMap<String, ? extends Timer> syncs = u.getSyncStats();
3915 for (int isy=syncs.size()-1; isy>=0; isy--) {
3916 final Timer timer = syncs.valueAt(isy);
3917 // Convert from microseconds to milliseconds with rounding
3918 final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000;
3919 final int count = timer.getCountLocked(which);
3920 sb.setLength(0);
3921 sb.append(prefix);
3922 sb.append(" Sync ");
3923 sb.append(syncs.keyAt(isy));
3924 sb.append(": ");
3925 if (totalTime != 0) {
3926 formatTimeMs(sb, totalTime);
3927 sb.append("realtime (");
3928 sb.append(count);
3929 sb.append(" times)");
3930 } else {
3931 sb.append("(not used)");
3932 }
3933 pw.println(sb.toString());
3934 uidActivity = true;
3935 }
3936
3937 final ArrayMap<String, ? extends Timer> jobs = u.getJobStats();
3938 for (int ij=jobs.size()-1; ij>=0; ij--) {
3939 final Timer timer = jobs.valueAt(ij);
3940 // Convert from microseconds to milliseconds with rounding
3941 final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000;
3942 final int count = timer.getCountLocked(which);
3943 sb.setLength(0);
3944 sb.append(prefix);
3945 sb.append(" Job ");
3946 sb.append(jobs.keyAt(ij));
3947 sb.append(": ");
3948 if (totalTime != 0) {
3949 formatTimeMs(sb, totalTime);
3950 sb.append("realtime (");
3951 sb.append(count);
3952 sb.append(" times)");
3953 } else {
3954 sb.append("(not used)");
3955 }
3956 pw.println(sb.toString());
3957 uidActivity = true;
3958 }
3959
Ruben Brunk6d2c3632015-05-26 17:32:16 -07003960 uidActivity |= printTimer(pw, sb, u.getFlashlightTurnedOnTimer(), rawRealtime, which,
3961 prefix, "Flashlight");
3962 uidActivity |= printTimer(pw, sb, u.getCameraTurnedOnTimer(), rawRealtime, which,
3963 prefix, "Camera");
3964 uidActivity |= printTimer(pw, sb, u.getVideoTurnedOnTimer(), rawRealtime, which,
3965 prefix, "Video");
3966 uidActivity |= printTimer(pw, sb, u.getAudioTurnedOnTimer(), rawRealtime, which,
3967 prefix, "Audio");
3968
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003969 final SparseArray<? extends BatteryStats.Uid.Sensor> sensors = u.getSensorStats();
3970 final int NSE = sensors.size();
Dianne Hackborn61659e52014-07-09 16:13:01 -07003971 for (int ise=0; ise<NSE; ise++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003972 final Uid.Sensor se = sensors.valueAt(ise);
3973 final int sensorNumber = sensors.keyAt(ise);
Dianne Hackborn61659e52014-07-09 16:13:01 -07003974 sb.setLength(0);
3975 sb.append(prefix);
3976 sb.append(" Sensor ");
3977 int handle = se.getHandle();
3978 if (handle == Uid.Sensor.GPS) {
3979 sb.append("GPS");
3980 } else {
3981 sb.append(handle);
3982 }
3983 sb.append(": ");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003984
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003985 final Timer timer = se.getSensorTime();
Dianne Hackborn61659e52014-07-09 16:13:01 -07003986 if (timer != null) {
3987 // Convert from microseconds to milliseconds with rounding
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003988 final long totalTime = (timer.getTotalTimeLocked(
Dianne Hackborn61659e52014-07-09 16:13:01 -07003989 rawRealtime, which) + 500) / 1000;
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003990 final int count = timer.getCountLocked(which);
Dianne Hackborn61659e52014-07-09 16:13:01 -07003991 //timer.logState();
3992 if (totalTime != 0) {
3993 formatTimeMs(sb, totalTime);
3994 sb.append("realtime (");
3995 sb.append(count);
3996 sb.append(" times)");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003997 } else {
3998 sb.append("(not used)");
3999 }
Dianne Hackborn61659e52014-07-09 16:13:01 -07004000 } else {
4001 sb.append("(not used)");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004002 }
Dianne Hackborn61659e52014-07-09 16:13:01 -07004003
4004 pw.println(sb.toString());
4005 uidActivity = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004006 }
4007
Ruben Brunk6d2c3632015-05-26 17:32:16 -07004008 uidActivity |= printTimer(pw, sb, u.getVibratorOnTimer(), rawRealtime, which, prefix,
4009 "Vibrator");
4010 uidActivity |= printTimer(pw, sb, u.getForegroundActivityTimer(), rawRealtime, which,
4011 prefix, "Foreground activities");
Jeff Sharkey3e013e82013-04-25 14:48:19 -07004012
Dianne Hackborn61659e52014-07-09 16:13:01 -07004013 long totalStateTime = 0;
4014 for (int ips=0; ips<Uid.NUM_PROCESS_STATE; ips++) {
4015 long time = u.getProcessStateTime(ips, rawRealtime, which);
4016 if (time > 0) {
4017 totalStateTime += time;
4018 sb.setLength(0);
4019 sb.append(prefix);
4020 sb.append(" ");
4021 sb.append(Uid.PROCESS_STATE_NAMES[ips]);
4022 sb.append(" for: ");
4023 formatTimeMs(sb, (totalStateTime + 500) / 1000);
4024 pw.println(sb.toString());
4025 uidActivity = true;
4026 }
4027 }
4028
Adam Lesinski06af1fa2015-05-05 17:35:35 -07004029 final long userCpuTimeUs = u.getUserCpuTimeUs(which);
4030 final long systemCpuTimeUs = u.getSystemCpuTimeUs(which);
4031 if (userCpuTimeUs > 0 || systemCpuTimeUs > 0) {
4032 sb.setLength(0);
4033 sb.append(prefix);
Adam Lesinski72478f02015-06-17 15:39:43 -07004034 sb.append(" Total cpu time: u=");
4035 formatTimeMs(sb, userCpuTimeUs / 1000);
4036 sb.append("s=");
4037 formatTimeMs(sb, systemCpuTimeUs / 1000);
Adam Lesinski06af1fa2015-05-05 17:35:35 -07004038 pw.println(sb.toString());
4039 }
4040
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004041 final ArrayMap<String, ? extends BatteryStats.Uid.Proc> processStats
4042 = u.getProcessStats();
4043 for (int ipr=processStats.size()-1; ipr>=0; ipr--) {
4044 final Uid.Proc ps = processStats.valueAt(ipr);
4045 long userTime;
4046 long systemTime;
4047 long foregroundTime;
4048 int starts;
4049 int numExcessive;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004050
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004051 userTime = ps.getUserTime(which);
4052 systemTime = ps.getSystemTime(which);
4053 foregroundTime = ps.getForegroundTime(which);
4054 starts = ps.getStarts(which);
4055 final int numCrashes = ps.getNumCrashes(which);
4056 final int numAnrs = ps.getNumAnrs(which);
4057 numExcessive = which == STATS_SINCE_CHARGED
4058 ? ps.countExcessivePowers() : 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004059
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004060 if (userTime != 0 || systemTime != 0 || foregroundTime != 0 || starts != 0
4061 || numExcessive != 0 || numCrashes != 0 || numAnrs != 0) {
4062 sb.setLength(0);
4063 sb.append(prefix); sb.append(" Proc ");
4064 sb.append(processStats.keyAt(ipr)); sb.append(":\n");
4065 sb.append(prefix); sb.append(" CPU: ");
4066 formatTimeMs(sb, userTime); sb.append("usr + ");
4067 formatTimeMs(sb, systemTime); sb.append("krn ; ");
4068 formatTimeMs(sb, foregroundTime); sb.append("fg");
4069 if (starts != 0 || numCrashes != 0 || numAnrs != 0) {
4070 sb.append("\n"); sb.append(prefix); sb.append(" ");
4071 boolean hasOne = false;
4072 if (starts != 0) {
4073 hasOne = true;
4074 sb.append(starts); sb.append(" starts");
Dianne Hackborn0d903a82010-09-07 23:51:03 -07004075 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004076 if (numCrashes != 0) {
4077 if (hasOne) {
4078 sb.append(", ");
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07004079 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004080 hasOne = true;
4081 sb.append(numCrashes); sb.append(" crashes");
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07004082 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004083 if (numAnrs != 0) {
4084 if (hasOne) {
4085 sb.append(", ");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004086 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004087 sb.append(numAnrs); sb.append(" anrs");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004088 }
4089 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004090 pw.println(sb.toString());
4091 for (int e=0; e<numExcessive; e++) {
4092 Uid.Proc.ExcessivePower ew = ps.getExcessivePower(e);
4093 if (ew != null) {
4094 pw.print(prefix); pw.print(" * Killed for ");
4095 if (ew.type == Uid.Proc.ExcessivePower.TYPE_WAKE) {
4096 pw.print("wake lock");
4097 } else if (ew.type == Uid.Proc.ExcessivePower.TYPE_CPU) {
4098 pw.print("cpu");
4099 } else {
4100 pw.print("unknown");
4101 }
4102 pw.print(" use: ");
4103 TimeUtils.formatDuration(ew.usedTime, pw);
4104 pw.print(" over ");
4105 TimeUtils.formatDuration(ew.overTime, pw);
4106 if (ew.overTime != 0) {
4107 pw.print(" (");
4108 pw.print((ew.usedTime*100)/ew.overTime);
4109 pw.println("%)");
4110 }
4111 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004112 }
4113 uidActivity = true;
4114 }
4115 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004116
4117 final ArrayMap<String, ? extends BatteryStats.Uid.Pkg> packageStats
4118 = u.getPackageStats();
4119 for (int ipkg=packageStats.size()-1; ipkg>=0; ipkg--) {
4120 pw.print(prefix); pw.print(" Apk "); pw.print(packageStats.keyAt(ipkg));
4121 pw.println(":");
4122 boolean apkActivity = false;
4123 final Uid.Pkg ps = packageStats.valueAt(ipkg);
4124 final ArrayMap<String, ? extends Counter> alarms = ps.getWakeupAlarmStats();
4125 for (int iwa=alarms.size()-1; iwa>=0; iwa--) {
4126 pw.print(prefix); pw.print(" Wakeup alarm ");
4127 pw.print(alarms.keyAt(iwa)); pw.print(": ");
4128 pw.print(alarms.valueAt(iwa).getCountLocked(which));
4129 pw.println(" times");
4130 apkActivity = true;
4131 }
4132 final ArrayMap<String, ? extends Uid.Pkg.Serv> serviceStats = ps.getServiceStats();
4133 for (int isvc=serviceStats.size()-1; isvc>=0; isvc--) {
4134 final BatteryStats.Uid.Pkg.Serv ss = serviceStats.valueAt(isvc);
4135 final long startTime = ss.getStartTime(batteryUptime, which);
4136 final int starts = ss.getStarts(which);
4137 final int launches = ss.getLaunches(which);
4138 if (startTime != 0 || starts != 0 || launches != 0) {
4139 sb.setLength(0);
4140 sb.append(prefix); sb.append(" Service ");
4141 sb.append(serviceStats.keyAt(isvc)); sb.append(":\n");
4142 sb.append(prefix); sb.append(" Created for: ");
4143 formatTimeMs(sb, startTime / 1000);
4144 sb.append("uptime\n");
4145 sb.append(prefix); sb.append(" Starts: ");
4146 sb.append(starts);
4147 sb.append(", launches: "); sb.append(launches);
4148 pw.println(sb.toString());
4149 apkActivity = true;
4150 }
4151 }
4152 if (!apkActivity) {
4153 pw.print(prefix); pw.println(" (nothing executed)");
4154 }
4155 uidActivity = true;
4156 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004157 if (!uidActivity) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004158 pw.print(prefix); pw.println(" (nothing executed)");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004159 }
4160 }
4161 }
4162
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004163 static void printBitDescriptions(PrintWriter pw, int oldval, int newval, HistoryTag wakelockTag,
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004164 BitDescription[] descriptions, boolean longNames) {
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07004165 int diff = oldval ^ newval;
4166 if (diff == 0) return;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004167 boolean didWake = false;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07004168 for (int i=0; i<descriptions.length; i++) {
4169 BitDescription bd = descriptions[i];
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004170 if ((diff&bd.mask) != 0) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004171 pw.print(longNames ? " " : ",");
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07004172 if (bd.shift < 0) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004173 pw.print((newval&bd.mask) != 0 ? "+" : "-");
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004174 pw.print(longNames ? bd.name : bd.shortName);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004175 if (bd.mask == HistoryItem.STATE_WAKE_LOCK_FLAG && wakelockTag != null) {
4176 didWake = true;
4177 pw.print("=");
4178 if (longNames) {
4179 UserHandle.formatUid(pw, wakelockTag.uid);
4180 pw.print(":\"");
4181 pw.print(wakelockTag.string);
4182 pw.print("\"");
4183 } else {
4184 pw.print(wakelockTag.poolIdx);
4185 }
4186 }
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07004187 } else {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004188 pw.print(longNames ? bd.name : bd.shortName);
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07004189 pw.print("=");
4190 int val = (newval&bd.mask)>>bd.shift;
4191 if (bd.values != null && val >= 0 && val < bd.values.length) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004192 pw.print(longNames? bd.values[val] : bd.shortValues[val]);
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07004193 } else {
4194 pw.print(val);
4195 }
4196 }
4197 }
4198 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004199 if (!didWake && wakelockTag != null) {
Ashish Sharma81850c42014-05-05 13:57:07 -07004200 pw.print(longNames ? " wake_lock=" : ",w=");
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004201 if (longNames) {
4202 UserHandle.formatUid(pw, wakelockTag.uid);
4203 pw.print(":\"");
4204 pw.print(wakelockTag.string);
4205 pw.print("\"");
4206 } else {
4207 pw.print(wakelockTag.poolIdx);
4208 }
4209 }
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07004210 }
4211
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004212 public void prepareForDumpLocked() {
4213 }
4214
4215 public static class HistoryPrinter {
4216 int oldState = 0;
Dianne Hackborna1bd7922014-03-21 11:07:11 -07004217 int oldState2 = 0;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004218 int oldLevel = -1;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004219 int oldStatus = -1;
4220 int oldHealth = -1;
4221 int oldPlug = -1;
4222 int oldTemp = -1;
4223 int oldVolt = -1;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004224 long lastTime = -1;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004225
Dianne Hackborn3251b902014-06-20 14:40:53 -07004226 void reset() {
4227 oldState = oldState2 = 0;
4228 oldLevel = -1;
4229 oldStatus = -1;
4230 oldHealth = -1;
4231 oldPlug = -1;
4232 oldTemp = -1;
4233 oldVolt = -1;
4234 }
4235
Dianne Hackborn99009ea2014-04-18 16:23:42 -07004236 public void printNextItem(PrintWriter pw, HistoryItem rec, long baseTime, boolean checkin,
Dianne Hackborna1bd7922014-03-21 11:07:11 -07004237 boolean verbose) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004238 if (!checkin) {
4239 pw.print(" ");
Dianne Hackborn99009ea2014-04-18 16:23:42 -07004240 TimeUtils.formatDuration(rec.time - baseTime, pw, TimeUtils.HUNDRED_DAY_FIELD_LEN);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004241 pw.print(" (");
4242 pw.print(rec.numReadInts);
4243 pw.print(") ");
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004244 } else {
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07004245 pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(',');
4246 pw.print(HISTORY_DATA); pw.print(',');
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004247 if (lastTime < 0) {
Dianne Hackborn99009ea2014-04-18 16:23:42 -07004248 pw.print(rec.time - baseTime);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004249 } else {
Dianne Hackborn99009ea2014-04-18 16:23:42 -07004250 pw.print(rec.time - lastTime);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004251 }
4252 lastTime = rec.time;
4253 }
4254 if (rec.cmd == HistoryItem.CMD_START) {
4255 if (checkin) {
4256 pw.print(":");
4257 }
4258 pw.println("START");
Dianne Hackborn3251b902014-06-20 14:40:53 -07004259 reset();
Dianne Hackborn37de0982014-05-09 09:32:18 -07004260 } else if (rec.cmd == HistoryItem.CMD_CURRENT_TIME
4261 || rec.cmd == HistoryItem.CMD_RESET) {
Dianne Hackborne5167ca2014-03-08 14:39:10 -08004262 if (checkin) {
4263 pw.print(":");
4264 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07004265 if (rec.cmd == HistoryItem.CMD_RESET) {
4266 pw.print("RESET:");
Dianne Hackborn3251b902014-06-20 14:40:53 -07004267 reset();
Dianne Hackborn37de0982014-05-09 09:32:18 -07004268 }
Dianne Hackborne5167ca2014-03-08 14:39:10 -08004269 pw.print("TIME:");
4270 if (checkin) {
4271 pw.println(rec.currentTime);
4272 } else {
4273 pw.print(" ");
4274 pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss",
4275 rec.currentTime).toString());
4276 }
Dianne Hackborn29cd7f12015-01-08 10:37:05 -08004277 } else if (rec.cmd == HistoryItem.CMD_SHUTDOWN) {
4278 if (checkin) {
4279 pw.print(":");
4280 }
4281 pw.println("SHUTDOWN");
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004282 } else if (rec.cmd == HistoryItem.CMD_OVERFLOW) {
4283 if (checkin) {
4284 pw.print(":");
4285 }
4286 pw.println("*OVERFLOW*");
4287 } else {
4288 if (!checkin) {
4289 if (rec.batteryLevel < 10) pw.print("00");
4290 else if (rec.batteryLevel < 100) pw.print("0");
4291 pw.print(rec.batteryLevel);
Dianne Hackborna1bd7922014-03-21 11:07:11 -07004292 if (verbose) {
4293 pw.print(" ");
4294 if (rec.states < 0) ;
4295 else if (rec.states < 0x10) pw.print("0000000");
4296 else if (rec.states < 0x100) pw.print("000000");
4297 else if (rec.states < 0x1000) pw.print("00000");
4298 else if (rec.states < 0x10000) pw.print("0000");
4299 else if (rec.states < 0x100000) pw.print("000");
4300 else if (rec.states < 0x1000000) pw.print("00");
4301 else if (rec.states < 0x10000000) pw.print("0");
4302 pw.print(Integer.toHexString(rec.states));
4303 }
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004304 } else {
4305 if (oldLevel != rec.batteryLevel) {
4306 oldLevel = rec.batteryLevel;
4307 pw.print(",Bl="); pw.print(rec.batteryLevel);
4308 }
4309 }
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004310 if (oldStatus != rec.batteryStatus) {
4311 oldStatus = rec.batteryStatus;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004312 pw.print(checkin ? ",Bs=" : " status=");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004313 switch (oldStatus) {
4314 case BatteryManager.BATTERY_STATUS_UNKNOWN:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004315 pw.print(checkin ? "?" : "unknown");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004316 break;
4317 case BatteryManager.BATTERY_STATUS_CHARGING:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004318 pw.print(checkin ? "c" : "charging");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004319 break;
4320 case BatteryManager.BATTERY_STATUS_DISCHARGING:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004321 pw.print(checkin ? "d" : "discharging");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004322 break;
4323 case BatteryManager.BATTERY_STATUS_NOT_CHARGING:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004324 pw.print(checkin ? "n" : "not-charging");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004325 break;
4326 case BatteryManager.BATTERY_STATUS_FULL:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004327 pw.print(checkin ? "f" : "full");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004328 break;
4329 default:
4330 pw.print(oldStatus);
4331 break;
4332 }
4333 }
4334 if (oldHealth != rec.batteryHealth) {
4335 oldHealth = rec.batteryHealth;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004336 pw.print(checkin ? ",Bh=" : " health=");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004337 switch (oldHealth) {
4338 case BatteryManager.BATTERY_HEALTH_UNKNOWN:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004339 pw.print(checkin ? "?" : "unknown");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004340 break;
4341 case BatteryManager.BATTERY_HEALTH_GOOD:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004342 pw.print(checkin ? "g" : "good");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004343 break;
4344 case BatteryManager.BATTERY_HEALTH_OVERHEAT:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004345 pw.print(checkin ? "h" : "overheat");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004346 break;
4347 case BatteryManager.BATTERY_HEALTH_DEAD:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004348 pw.print(checkin ? "d" : "dead");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004349 break;
4350 case BatteryManager.BATTERY_HEALTH_OVER_VOLTAGE:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004351 pw.print(checkin ? "v" : "over-voltage");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004352 break;
4353 case BatteryManager.BATTERY_HEALTH_UNSPECIFIED_FAILURE:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004354 pw.print(checkin ? "f" : "failure");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004355 break;
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08004356 case BatteryManager.BATTERY_HEALTH_COLD:
4357 pw.print(checkin ? "c" : "cold");
4358 break;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004359 default:
4360 pw.print(oldHealth);
4361 break;
4362 }
4363 }
4364 if (oldPlug != rec.batteryPlugType) {
4365 oldPlug = rec.batteryPlugType;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004366 pw.print(checkin ? ",Bp=" : " plug=");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004367 switch (oldPlug) {
4368 case 0:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004369 pw.print(checkin ? "n" : "none");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004370 break;
4371 case BatteryManager.BATTERY_PLUGGED_AC:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004372 pw.print(checkin ? "a" : "ac");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004373 break;
4374 case BatteryManager.BATTERY_PLUGGED_USB:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004375 pw.print(checkin ? "u" : "usb");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004376 break;
Brian Muramatsu37a37f42012-08-14 15:21:02 -07004377 case BatteryManager.BATTERY_PLUGGED_WIRELESS:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004378 pw.print(checkin ? "w" : "wireless");
Brian Muramatsu37a37f42012-08-14 15:21:02 -07004379 break;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004380 default:
4381 pw.print(oldPlug);
4382 break;
4383 }
4384 }
4385 if (oldTemp != rec.batteryTemperature) {
4386 oldTemp = rec.batteryTemperature;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004387 pw.print(checkin ? ",Bt=" : " temp=");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004388 pw.print(oldTemp);
4389 }
4390 if (oldVolt != rec.batteryVoltage) {
4391 oldVolt = rec.batteryVoltage;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004392 pw.print(checkin ? ",Bv=" : " volt=");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004393 pw.print(oldVolt);
4394 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004395 printBitDescriptions(pw, oldState, rec.states, rec.wakelockTag,
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004396 HISTORY_STATE_DESCRIPTIONS, !checkin);
Dianne Hackborna1bd7922014-03-21 11:07:11 -07004397 printBitDescriptions(pw, oldState2, rec.states2, null,
4398 HISTORY_STATE2_DESCRIPTIONS, !checkin);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004399 if (rec.wakeReasonTag != null) {
4400 if (checkin) {
Dianne Hackbornd06dcfd2014-05-02 13:49:30 -07004401 pw.print(",wr=");
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004402 pw.print(rec.wakeReasonTag.poolIdx);
4403 } else {
4404 pw.print(" wake_reason=");
4405 pw.print(rec.wakeReasonTag.uid);
4406 pw.print(":\"");
4407 pw.print(rec.wakeReasonTag.string);
4408 pw.print("\"");
4409 }
4410 }
Dianne Hackborn099bc622014-01-22 13:39:16 -08004411 if (rec.eventCode != HistoryItem.EVENT_NONE) {
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08004412 pw.print(checkin ? "," : " ");
4413 if ((rec.eventCode&HistoryItem.EVENT_FLAG_START) != 0) {
4414 pw.print("+");
4415 } else if ((rec.eventCode&HistoryItem.EVENT_FLAG_FINISH) != 0) {
4416 pw.print("-");
Dianne Hackborn099bc622014-01-22 13:39:16 -08004417 }
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08004418 String[] eventNames = checkin ? HISTORY_EVENT_CHECKIN_NAMES
4419 : HISTORY_EVENT_NAMES;
4420 int idx = rec.eventCode & ~(HistoryItem.EVENT_FLAG_START
4421 | HistoryItem.EVENT_FLAG_FINISH);
4422 if (idx >= 0 && idx < eventNames.length) {
4423 pw.print(eventNames[idx]);
4424 } else {
4425 pw.print(checkin ? "Ev" : "event");
4426 pw.print(idx);
4427 }
4428 pw.print("=");
Dianne Hackborn099bc622014-01-22 13:39:16 -08004429 if (checkin) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004430 pw.print(rec.eventTag.poolIdx);
Dianne Hackborn099bc622014-01-22 13:39:16 -08004431 } else {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004432 UserHandle.formatUid(pw, rec.eventTag.uid);
4433 pw.print(":\"");
4434 pw.print(rec.eventTag.string);
4435 pw.print("\"");
Dianne Hackborn099bc622014-01-22 13:39:16 -08004436 }
4437 }
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004438 pw.println();
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08004439 if (rec.stepDetails != null) {
4440 if (!checkin) {
4441 pw.print(" Details: cpu=");
4442 pw.print(rec.stepDetails.userTime);
4443 pw.print("u+");
4444 pw.print(rec.stepDetails.systemTime);
4445 pw.print("s");
4446 if (rec.stepDetails.appCpuUid1 >= 0) {
4447 pw.print(" (");
4448 printStepCpuUidDetails(pw, rec.stepDetails.appCpuUid1,
4449 rec.stepDetails.appCpuUTime1, rec.stepDetails.appCpuSTime1);
4450 if (rec.stepDetails.appCpuUid2 >= 0) {
4451 pw.print(", ");
4452 printStepCpuUidDetails(pw, rec.stepDetails.appCpuUid2,
4453 rec.stepDetails.appCpuUTime2, rec.stepDetails.appCpuSTime2);
4454 }
4455 if (rec.stepDetails.appCpuUid3 >= 0) {
4456 pw.print(", ");
4457 printStepCpuUidDetails(pw, rec.stepDetails.appCpuUid3,
4458 rec.stepDetails.appCpuUTime3, rec.stepDetails.appCpuSTime3);
4459 }
4460 pw.print(')');
4461 }
4462 pw.println();
4463 pw.print(" /proc/stat=");
4464 pw.print(rec.stepDetails.statUserTime);
4465 pw.print(" usr, ");
4466 pw.print(rec.stepDetails.statSystemTime);
4467 pw.print(" sys, ");
4468 pw.print(rec.stepDetails.statIOWaitTime);
4469 pw.print(" io, ");
4470 pw.print(rec.stepDetails.statIrqTime);
4471 pw.print(" irq, ");
4472 pw.print(rec.stepDetails.statSoftIrqTime);
4473 pw.print(" sirq, ");
4474 pw.print(rec.stepDetails.statIdlTime);
4475 pw.print(" idle");
4476 int totalRun = rec.stepDetails.statUserTime + rec.stepDetails.statSystemTime
4477 + rec.stepDetails.statIOWaitTime + rec.stepDetails.statIrqTime
4478 + rec.stepDetails.statSoftIrqTime;
4479 int total = totalRun + rec.stepDetails.statIdlTime;
4480 if (total > 0) {
4481 pw.print(" (");
4482 float perc = ((float)totalRun) / ((float)total) * 100;
4483 pw.print(String.format("%.1f%%", perc));
4484 pw.print(" of ");
4485 StringBuilder sb = new StringBuilder(64);
4486 formatTimeMsNoSpace(sb, total*10);
4487 pw.print(sb);
4488 pw.print(")");
4489 }
4490 pw.println();
4491 } else {
4492 pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(',');
4493 pw.print(HISTORY_DATA); pw.print(",0,Dcpu=");
4494 pw.print(rec.stepDetails.userTime);
4495 pw.print(":");
4496 pw.print(rec.stepDetails.systemTime);
4497 if (rec.stepDetails.appCpuUid1 >= 0) {
4498 printStepCpuUidCheckinDetails(pw, rec.stepDetails.appCpuUid1,
4499 rec.stepDetails.appCpuUTime1, rec.stepDetails.appCpuSTime1);
4500 if (rec.stepDetails.appCpuUid2 >= 0) {
4501 printStepCpuUidCheckinDetails(pw, rec.stepDetails.appCpuUid2,
4502 rec.stepDetails.appCpuUTime2, rec.stepDetails.appCpuSTime2);
4503 }
4504 if (rec.stepDetails.appCpuUid3 >= 0) {
4505 printStepCpuUidCheckinDetails(pw, rec.stepDetails.appCpuUid3,
4506 rec.stepDetails.appCpuUTime3, rec.stepDetails.appCpuSTime3);
4507 }
4508 }
4509 pw.println();
4510 pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(',');
4511 pw.print(HISTORY_DATA); pw.print(",0,Dpst=");
4512 pw.print(rec.stepDetails.statUserTime);
4513 pw.print(',');
4514 pw.print(rec.stepDetails.statSystemTime);
4515 pw.print(',');
4516 pw.print(rec.stepDetails.statIOWaitTime);
4517 pw.print(',');
4518 pw.print(rec.stepDetails.statIrqTime);
4519 pw.print(',');
4520 pw.print(rec.stepDetails.statSoftIrqTime);
4521 pw.print(',');
4522 pw.print(rec.stepDetails.statIdlTime);
4523 pw.println();
4524 }
4525 }
Dianne Hackborne5167ca2014-03-08 14:39:10 -08004526 oldState = rec.states;
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07004527 oldState2 = rec.states2;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004528 }
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004529 }
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08004530
4531 private void printStepCpuUidDetails(PrintWriter pw, int uid, int utime, int stime) {
4532 UserHandle.formatUid(pw, uid);
4533 pw.print("=");
4534 pw.print(utime);
4535 pw.print("u+");
4536 pw.print(stime);
4537 pw.print("s");
4538 }
4539
4540 private void printStepCpuUidCheckinDetails(PrintWriter pw, int uid, int utime, int stime) {
4541 pw.print('/');
4542 pw.print(uid);
4543 pw.print(":");
4544 pw.print(utime);
4545 pw.print(":");
4546 pw.print(stime);
4547 }
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004548 }
4549
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004550 private void printSizeValue(PrintWriter pw, long size) {
4551 float result = size;
4552 String suffix = "";
4553 if (result >= 10*1024) {
4554 suffix = "KB";
4555 result = result / 1024;
4556 }
4557 if (result >= 10*1024) {
4558 suffix = "MB";
4559 result = result / 1024;
4560 }
4561 if (result >= 10*1024) {
4562 suffix = "GB";
4563 result = result / 1024;
4564 }
4565 if (result >= 10*1024) {
4566 suffix = "TB";
4567 result = result / 1024;
4568 }
4569 if (result >= 10*1024) {
4570 suffix = "PB";
4571 result = result / 1024;
4572 }
4573 pw.print((int)result);
4574 pw.print(suffix);
4575 }
4576
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08004577 private static boolean dumpTimeEstimate(PrintWriter pw, String label1, String label2,
4578 String label3, long estimatedTime) {
4579 if (estimatedTime < 0) {
Dianne Hackbornad6a99b2014-11-18 10:11:10 -08004580 return false;
4581 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08004582 pw.print(label1);
4583 pw.print(label2);
4584 pw.print(label3);
Dianne Hackbornad6a99b2014-11-18 10:11:10 -08004585 StringBuilder sb = new StringBuilder(64);
4586 formatTimeMs(sb, estimatedTime);
4587 pw.print(sb);
4588 pw.println();
Dianne Hackbornad6a99b2014-11-18 10:11:10 -08004589 return true;
4590 }
4591
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08004592 private static boolean dumpDurationSteps(PrintWriter pw, String prefix, String header,
4593 LevelStepTracker steps, boolean checkin) {
4594 if (steps == null) {
4595 return false;
4596 }
4597 int count = steps.mNumStepDurations;
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07004598 if (count <= 0) {
4599 return false;
4600 }
4601 if (!checkin) {
4602 pw.println(header);
4603 }
Kweku Adams030980a2015-04-01 16:07:48 -07004604 String[] lineArgs = new String[5];
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07004605 for (int i=0; i<count; i++) {
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08004606 long duration = steps.getDurationAt(i);
4607 int level = steps.getLevelAt(i);
4608 long initMode = steps.getInitModeAt(i);
4609 long modMode = steps.getModModeAt(i);
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07004610 if (checkin) {
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07004611 lineArgs[0] = Long.toString(duration);
4612 lineArgs[1] = Integer.toString(level);
4613 if ((modMode&STEP_LEVEL_MODE_SCREEN_STATE) == 0) {
4614 switch ((int)(initMode&STEP_LEVEL_MODE_SCREEN_STATE) + 1) {
4615 case Display.STATE_OFF: lineArgs[2] = "s-"; break;
4616 case Display.STATE_ON: lineArgs[2] = "s+"; break;
4617 case Display.STATE_DOZE: lineArgs[2] = "sd"; break;
4618 case Display.STATE_DOZE_SUSPEND: lineArgs[2] = "sds"; break;
Kweku Adams030980a2015-04-01 16:07:48 -07004619 default: lineArgs[2] = "?"; break;
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07004620 }
4621 } else {
4622 lineArgs[2] = "";
4623 }
4624 if ((modMode&STEP_LEVEL_MODE_POWER_SAVE) == 0) {
4625 lineArgs[3] = (initMode&STEP_LEVEL_MODE_POWER_SAVE) != 0 ? "p+" : "p-";
4626 } else {
4627 lineArgs[3] = "";
4628 }
Dianne Hackborn88e98df2015-03-23 13:29:14 -07004629 if ((modMode&STEP_LEVEL_MODE_DEVICE_IDLE) == 0) {
Kweku Adams030980a2015-04-01 16:07:48 -07004630 lineArgs[4] = (initMode&STEP_LEVEL_MODE_DEVICE_IDLE) != 0 ? "i+" : "i-";
Dianne Hackborn88e98df2015-03-23 13:29:14 -07004631 } else {
Kweku Adams030980a2015-04-01 16:07:48 -07004632 lineArgs[4] = "";
Dianne Hackborn88e98df2015-03-23 13:29:14 -07004633 }
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07004634 dumpLine(pw, 0 /* uid */, "i" /* category */, header, (Object[])lineArgs);
4635 } else {
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08004636 pw.print(prefix);
4637 pw.print("#"); pw.print(i); pw.print(": ");
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07004638 TimeUtils.formatDuration(duration, pw);
4639 pw.print(" to "); pw.print(level);
4640 boolean haveModes = false;
4641 if ((modMode&STEP_LEVEL_MODE_SCREEN_STATE) == 0) {
4642 pw.print(" (");
4643 switch ((int)(initMode&STEP_LEVEL_MODE_SCREEN_STATE) + 1) {
4644 case Display.STATE_OFF: pw.print("screen-off"); break;
4645 case Display.STATE_ON: pw.print("screen-on"); break;
4646 case Display.STATE_DOZE: pw.print("screen-doze"); break;
4647 case Display.STATE_DOZE_SUSPEND: pw.print("screen-doze-suspend"); break;
Kweku Adams030980a2015-04-01 16:07:48 -07004648 default: pw.print("screen-?"); break;
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07004649 }
4650 haveModes = true;
4651 }
4652 if ((modMode&STEP_LEVEL_MODE_POWER_SAVE) == 0) {
4653 pw.print(haveModes ? ", " : " (");
4654 pw.print((initMode&STEP_LEVEL_MODE_POWER_SAVE) != 0
4655 ? "power-save-on" : "power-save-off");
4656 haveModes = true;
4657 }
Dianne Hackborn88e98df2015-03-23 13:29:14 -07004658 if ((modMode&STEP_LEVEL_MODE_DEVICE_IDLE) == 0) {
4659 pw.print(haveModes ? ", " : " (");
4660 pw.print((initMode&STEP_LEVEL_MODE_DEVICE_IDLE) != 0
4661 ? "device-idle-on" : "device-idle-off");
4662 haveModes = true;
4663 }
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07004664 if (haveModes) {
4665 pw.print(")");
4666 }
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07004667 pw.println();
4668 }
4669 }
4670 return true;
4671 }
4672
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004673 public static final int DUMP_CHARGED_ONLY = 1<<1;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08004674 public static final int DUMP_DAILY_ONLY = 1<<2;
4675 public static final int DUMP_HISTORY_ONLY = 1<<3;
4676 public static final int DUMP_INCLUDE_HISTORY = 1<<4;
4677 public static final int DUMP_VERBOSE = 1<<5;
4678 public static final int DUMP_DEVICE_WIFI_ONLY = 1<<6;
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004679
Dianne Hackborn37de0982014-05-09 09:32:18 -07004680 private void dumpHistoryLocked(PrintWriter pw, int flags, long histStart, boolean checkin) {
4681 final HistoryPrinter hprinter = new HistoryPrinter();
4682 final HistoryItem rec = new HistoryItem();
4683 long lastTime = -1;
4684 long baseTime = -1;
4685 boolean printed = false;
4686 HistoryEventTracker tracker = null;
4687 while (getNextHistoryLocked(rec)) {
4688 lastTime = rec.time;
4689 if (baseTime < 0) {
4690 baseTime = lastTime;
4691 }
4692 if (rec.time >= histStart) {
4693 if (histStart >= 0 && !printed) {
4694 if (rec.cmd == HistoryItem.CMD_CURRENT_TIME
Ashish Sharma60200712014-05-23 18:22:20 -07004695 || rec.cmd == HistoryItem.CMD_RESET
Dianne Hackborn29cd7f12015-01-08 10:37:05 -08004696 || rec.cmd == HistoryItem.CMD_START
4697 || rec.cmd == HistoryItem.CMD_SHUTDOWN) {
Dianne Hackborn37de0982014-05-09 09:32:18 -07004698 printed = true;
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07004699 hprinter.printNextItem(pw, rec, baseTime, checkin,
4700 (flags&DUMP_VERBOSE) != 0);
4701 rec.cmd = HistoryItem.CMD_UPDATE;
Dianne Hackborn37de0982014-05-09 09:32:18 -07004702 } else if (rec.currentTime != 0) {
4703 printed = true;
4704 byte cmd = rec.cmd;
4705 rec.cmd = HistoryItem.CMD_CURRENT_TIME;
Dianne Hackborn37de0982014-05-09 09:32:18 -07004706 hprinter.printNextItem(pw, rec, baseTime, checkin,
4707 (flags&DUMP_VERBOSE) != 0);
4708 rec.cmd = cmd;
4709 }
4710 if (tracker != null) {
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07004711 if (rec.cmd != HistoryItem.CMD_UPDATE) {
4712 hprinter.printNextItem(pw, rec, baseTime, checkin,
4713 (flags&DUMP_VERBOSE) != 0);
4714 rec.cmd = HistoryItem.CMD_UPDATE;
4715 }
4716 int oldEventCode = rec.eventCode;
4717 HistoryTag oldEventTag = rec.eventTag;
Dianne Hackborn37de0982014-05-09 09:32:18 -07004718 rec.eventTag = new HistoryTag();
4719 for (int i=0; i<HistoryItem.EVENT_COUNT; i++) {
4720 HashMap<String, SparseIntArray> active
4721 = tracker.getStateForEvent(i);
4722 if (active == null) {
4723 continue;
4724 }
4725 for (HashMap.Entry<String, SparseIntArray> ent
4726 : active.entrySet()) {
4727 SparseIntArray uids = ent.getValue();
4728 for (int j=0; j<uids.size(); j++) {
4729 rec.eventCode = i;
4730 rec.eventTag.string = ent.getKey();
4731 rec.eventTag.uid = uids.keyAt(j);
4732 rec.eventTag.poolIdx = uids.valueAt(j);
Dianne Hackborn37de0982014-05-09 09:32:18 -07004733 hprinter.printNextItem(pw, rec, baseTime, checkin,
4734 (flags&DUMP_VERBOSE) != 0);
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07004735 rec.wakeReasonTag = null;
4736 rec.wakelockTag = null;
Dianne Hackborn37de0982014-05-09 09:32:18 -07004737 }
4738 }
4739 }
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07004740 rec.eventCode = oldEventCode;
4741 rec.eventTag = oldEventTag;
Dianne Hackborn37de0982014-05-09 09:32:18 -07004742 tracker = null;
4743 }
4744 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07004745 hprinter.printNextItem(pw, rec, baseTime, checkin,
4746 (flags&DUMP_VERBOSE) != 0);
Dianne Hackborn536456f2014-05-23 16:51:05 -07004747 } else if (false && rec.eventCode != HistoryItem.EVENT_NONE) {
4748 // This is an attempt to aggregate the previous state and generate
4749 // fake events to reflect that state at the point where we start
4750 // printing real events. It doesn't really work right, so is turned off.
Dianne Hackborn37de0982014-05-09 09:32:18 -07004751 if (tracker == null) {
4752 tracker = new HistoryEventTracker();
4753 }
4754 tracker.updateState(rec.eventCode, rec.eventTag.string,
4755 rec.eventTag.uid, rec.eventTag.poolIdx);
4756 }
4757 }
4758 if (histStart >= 0) {
Dianne Hackbornfc064132014-06-02 12:42:12 -07004759 commitCurrentHistoryBatchLocked();
Dianne Hackborn37de0982014-05-09 09:32:18 -07004760 pw.print(checkin ? "NEXT: " : " NEXT: "); pw.println(lastTime+1);
4761 }
4762 }
4763
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08004764 private void dumpDailyLevelStepSummary(PrintWriter pw, String prefix, String label,
4765 LevelStepTracker steps, StringBuilder tmpSb, int[] tmpOutInt) {
4766 if (steps == null) {
4767 return;
4768 }
4769 long timeRemaining = steps.computeTimeEstimate(0, 0, tmpOutInt);
4770 if (timeRemaining >= 0) {
4771 pw.print(prefix); pw.print(label); pw.print(" total time: ");
4772 tmpSb.setLength(0);
4773 formatTimeMs(tmpSb, timeRemaining);
4774 pw.print(tmpSb);
4775 pw.print(" (from "); pw.print(tmpOutInt[0]);
4776 pw.println(" steps)");
4777 }
4778 for (int i=0; i< STEP_LEVEL_MODES_OF_INTEREST.length; i++) {
4779 long estimatedTime = steps.computeTimeEstimate(STEP_LEVEL_MODES_OF_INTEREST[i],
4780 STEP_LEVEL_MODE_VALUES[i], tmpOutInt);
4781 if (estimatedTime > 0) {
4782 pw.print(prefix); pw.print(label); pw.print(" ");
4783 pw.print(STEP_LEVEL_MODE_LABELS[i]);
4784 pw.print(" time: ");
4785 tmpSb.setLength(0);
4786 formatTimeMs(tmpSb, estimatedTime);
4787 pw.print(tmpSb);
4788 pw.print(" (from "); pw.print(tmpOutInt[0]);
4789 pw.println(" steps)");
4790 }
4791 }
4792 }
4793
Dianne Hackborn88e98df2015-03-23 13:29:14 -07004794 private void dumpDailyPackageChanges(PrintWriter pw, String prefix,
4795 ArrayList<PackageChange> changes) {
4796 if (changes == null) {
4797 return;
4798 }
4799 pw.print(prefix); pw.println("Package changes:");
4800 for (int i=0; i<changes.size(); i++) {
4801 PackageChange pc = changes.get(i);
4802 if (pc.mUpdate) {
4803 pw.print(prefix); pw.print(" Update "); pw.print(pc.mPackageName);
4804 pw.print(" vers="); pw.println(pc.mVersionCode);
4805 } else {
4806 pw.print(prefix); pw.print(" Uninstall "); pw.println(pc.mPackageName);
4807 }
4808 }
4809 }
4810
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004811 /**
4812 * Dumps a human-readable summary of the battery statistics to the given PrintWriter.
4813 *
4814 * @param pw a Printer to receive the dump output.
4815 */
4816 @SuppressWarnings("unused")
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004817 public void dumpLocked(Context context, PrintWriter pw, int flags, int reqUid, long histStart) {
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004818 prepareForDumpLocked();
4819
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08004820 final boolean filtering = (flags
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004821 & (DUMP_HISTORY_ONLY|DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) != 0;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004822
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004823 if ((flags&DUMP_HISTORY_ONLY) != 0 || !filtering) {
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004824 final long historyTotalSize = getHistoryTotalSize();
4825 final long historyUsedSize = getHistoryUsedSize();
4826 if (startIteratingHistoryLocked()) {
4827 try {
4828 pw.print("Battery History (");
4829 pw.print((100*historyUsedSize)/historyTotalSize);
4830 pw.print("% used, ");
4831 printSizeValue(pw, historyUsedSize);
4832 pw.print(" used of ");
4833 printSizeValue(pw, historyTotalSize);
4834 pw.print(", ");
4835 pw.print(getHistoryStringPoolSize());
4836 pw.print(" strings using ");
4837 printSizeValue(pw, getHistoryStringPoolBytes());
4838 pw.println("):");
Dianne Hackborn37de0982014-05-09 09:32:18 -07004839 dumpHistoryLocked(pw, flags, histStart, false);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004840 pw.println();
4841 } finally {
4842 finishIteratingHistoryLocked();
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004843 }
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004844 }
4845
4846 if (startIteratingOldHistoryLocked()) {
4847 try {
Dianne Hackborn37de0982014-05-09 09:32:18 -07004848 final HistoryItem rec = new HistoryItem();
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004849 pw.println("Old battery History:");
4850 HistoryPrinter hprinter = new HistoryPrinter();
Dianne Hackborn99009ea2014-04-18 16:23:42 -07004851 long baseTime = -1;
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004852 while (getNextOldHistoryLocked(rec)) {
Dianne Hackborn99009ea2014-04-18 16:23:42 -07004853 if (baseTime < 0) {
4854 baseTime = rec.time;
4855 }
4856 hprinter.printNextItem(pw, rec, baseTime, false, (flags&DUMP_VERBOSE) != 0);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004857 }
4858 pw.println();
4859 } finally {
4860 finishIteratingOldHistoryLocked();
4861 }
Dianne Hackborn32907cf2010-06-10 17:50:20 -07004862 }
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004863 }
4864
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004865 if (filtering && (flags&(DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) == 0) {
Dianne Hackborn099bc622014-01-22 13:39:16 -08004866 return;
4867 }
4868
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004869 if (!filtering) {
4870 SparseArray<? extends Uid> uidStats = getUidStats();
4871 final int NU = uidStats.size();
4872 boolean didPid = false;
4873 long nowRealtime = SystemClock.elapsedRealtime();
4874 for (int i=0; i<NU; i++) {
4875 Uid uid = uidStats.valueAt(i);
4876 SparseArray<? extends Uid.Pid> pids = uid.getPidStats();
4877 if (pids != null) {
4878 for (int j=0; j<pids.size(); j++) {
4879 Uid.Pid pid = pids.valueAt(j);
4880 if (!didPid) {
4881 pw.println("Per-PID Stats:");
4882 didPid = true;
4883 }
Dianne Hackborne5167ca2014-03-08 14:39:10 -08004884 long time = pid.mWakeSumMs + (pid.mWakeNesting > 0
4885 ? (nowRealtime - pid.mWakeStartMs) : 0);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004886 pw.print(" PID "); pw.print(pids.keyAt(j));
4887 pw.print(" wake time: ");
4888 TimeUtils.formatDuration(time, pw);
4889 pw.println("");
Dianne Hackbornb5e31652010-09-07 12:13:55 -07004890 }
Dianne Hackbornb5e31652010-09-07 12:13:55 -07004891 }
4892 }
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004893 if (didPid) {
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07004894 pw.println();
4895 }
Dianne Hackborncd0e3352014-08-07 17:08:09 -07004896 }
4897
4898 if (!filtering || (flags&DUMP_CHARGED_ONLY) != 0) {
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08004899 if (dumpDurationSteps(pw, " ", "Discharge step durations:",
4900 getDischargeLevelStepTracker(), false)) {
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07004901 long timeRemaining = computeBatteryTimeRemaining(SystemClock.elapsedRealtime());
4902 if (timeRemaining >= 0) {
4903 pw.print(" Estimated discharge time remaining: ");
4904 TimeUtils.formatDuration(timeRemaining / 1000, pw);
4905 pw.println();
4906 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08004907 final LevelStepTracker steps = getDischargeLevelStepTracker();
4908 for (int i=0; i< STEP_LEVEL_MODES_OF_INTEREST.length; i++) {
4909 dumpTimeEstimate(pw, " Estimated ", STEP_LEVEL_MODE_LABELS[i], " time: ",
4910 steps.computeTimeEstimate(STEP_LEVEL_MODES_OF_INTEREST[i],
4911 STEP_LEVEL_MODE_VALUES[i], null));
4912 }
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07004913 pw.println();
4914 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08004915 if (dumpDurationSteps(pw, " ", "Charge step durations:",
4916 getChargeLevelStepTracker(), false)) {
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07004917 long timeRemaining = computeChargeTimeRemaining(SystemClock.elapsedRealtime());
4918 if (timeRemaining >= 0) {
4919 pw.print(" Estimated charge time remaining: ");
4920 TimeUtils.formatDuration(timeRemaining / 1000, pw);
4921 pw.println();
4922 }
4923 pw.println();
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004924 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08004925 }
4926 if (!filtering || (flags&(DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) != 0) {
4927 pw.println("Daily stats:");
4928 pw.print(" Current start time: ");
4929 pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss",
4930 getCurrentDailyStartTime()).toString());
4931 pw.print(" Next min deadline: ");
4932 pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss",
4933 getNextMinDailyDeadline()).toString());
4934 pw.print(" Next max deadline: ");
4935 pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss",
4936 getNextMaxDailyDeadline()).toString());
4937 StringBuilder sb = new StringBuilder(64);
4938 int[] outInt = new int[1];
4939 LevelStepTracker dsteps = getDailyDischargeLevelStepTracker();
4940 LevelStepTracker csteps = getDailyChargeLevelStepTracker();
Dianne Hackborn88e98df2015-03-23 13:29:14 -07004941 ArrayList<PackageChange> pkgc = getDailyPackageChanges();
4942 if (dsteps.mNumStepDurations > 0 || csteps.mNumStepDurations > 0 || pkgc != null) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004943 if ((flags&DUMP_DAILY_ONLY) != 0 || !filtering) {
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08004944 if (dumpDurationSteps(pw, " ", " Current daily discharge step durations:",
4945 dsteps, false)) {
4946 dumpDailyLevelStepSummary(pw, " ", "Discharge", dsteps,
4947 sb, outInt);
4948 }
4949 if (dumpDurationSteps(pw, " ", " Current daily charge step durations:",
4950 csteps, false)) {
4951 dumpDailyLevelStepSummary(pw, " ", "Charge", csteps,
4952 sb, outInt);
4953 }
Dianne Hackborn88e98df2015-03-23 13:29:14 -07004954 dumpDailyPackageChanges(pw, " ", pkgc);
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08004955 } else {
4956 pw.println(" Current daily steps:");
4957 dumpDailyLevelStepSummary(pw, " ", "Discharge", dsteps,
4958 sb, outInt);
4959 dumpDailyLevelStepSummary(pw, " ", "Charge", csteps,
4960 sb, outInt);
4961 }
4962 }
4963 DailyItem dit;
4964 int curIndex = 0;
4965 while ((dit=getDailyItemLocked(curIndex)) != null) {
4966 curIndex++;
4967 if ((flags&DUMP_DAILY_ONLY) != 0) {
4968 pw.println();
4969 }
4970 pw.print(" Daily from ");
4971 pw.print(DateFormat.format("yyyy-MM-dd-HH-mm-ss", dit.mStartTime).toString());
4972 pw.print(" to ");
4973 pw.print(DateFormat.format("yyyy-MM-dd-HH-mm-ss", dit.mEndTime).toString());
4974 pw.println(":");
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004975 if ((flags&DUMP_DAILY_ONLY) != 0 || !filtering) {
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08004976 if (dumpDurationSteps(pw, " ",
4977 " Discharge step durations:", dit.mDischargeSteps, false)) {
4978 dumpDailyLevelStepSummary(pw, " ", "Discharge", dit.mDischargeSteps,
4979 sb, outInt);
4980 }
4981 if (dumpDurationSteps(pw, " ",
4982 " Charge step durations:", dit.mChargeSteps, false)) {
4983 dumpDailyLevelStepSummary(pw, " ", "Charge", dit.mChargeSteps,
4984 sb, outInt);
4985 }
Dianne Hackborn88e98df2015-03-23 13:29:14 -07004986 dumpDailyPackageChanges(pw, " ", dit.mPackageChanges);
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08004987 } else {
4988 dumpDailyLevelStepSummary(pw, " ", "Discharge", dit.mDischargeSteps,
4989 sb, outInt);
4990 dumpDailyLevelStepSummary(pw, " ", "Charge", dit.mChargeSteps,
4991 sb, outInt);
4992 }
4993 }
4994 pw.println();
4995 }
4996 if (!filtering || (flags&DUMP_CHARGED_ONLY) != 0) {
Jeff Sharkeyec43a6b2013-04-30 13:33:18 -07004997 pw.println("Statistics since last charge:");
4998 pw.println(" System starts: " + getStartCount()
4999 + ", currently on battery: " + getIsOnBattery());
Dianne Hackbornd953c532014-08-16 18:17:38 -07005000 dumpLocked(context, pw, "", STATS_SINCE_CHARGED, reqUid,
5001 (flags&DUMP_DEVICE_WIFI_ONLY) != 0);
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07005002 pw.println();
Jeff Sharkeyec43a6b2013-04-30 13:33:18 -07005003 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005004 }
5005
5006 @SuppressWarnings("unused")
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005007 public void dumpCheckinLocked(Context context, PrintWriter pw,
5008 List<ApplicationInfo> apps, int flags, long histStart) {
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005009 prepareForDumpLocked();
Dianne Hackborncd0e3352014-08-07 17:08:09 -07005010
5011 dumpLine(pw, 0 /* uid */, "i" /* category */, VERSION_DATA,
Dianne Hackborn0c820db2015-04-14 17:47:34 -07005012 CHECKIN_VERSION, getParcelVersion(), getStartPlatformVersion(),
5013 getEndPlatformVersion());
Dianne Hackborncd0e3352014-08-07 17:08:09 -07005014
Dianne Hackborn13ac0412013-06-25 19:34:49 -07005015 long now = getHistoryBaseTime() + SystemClock.elapsedRealtime();
5016
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005017 final boolean filtering = (flags &
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005018 (DUMP_HISTORY_ONLY|DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) != 0;
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005019
5020 if ((flags&DUMP_INCLUDE_HISTORY) != 0 || (flags&DUMP_HISTORY_ONLY) != 0) {
Dianne Hackborn49021f52013-09-04 18:03:40 -07005021 if (startIteratingHistoryLocked()) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005022 try {
5023 for (int i=0; i<getHistoryStringPoolSize(); i++) {
5024 pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(',');
5025 pw.print(HISTORY_STRING_POOL); pw.print(',');
5026 pw.print(i);
Dianne Hackborn99009ea2014-04-18 16:23:42 -07005027 pw.print(",");
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005028 pw.print(getHistoryTagPoolUid(i));
Dianne Hackborn99009ea2014-04-18 16:23:42 -07005029 pw.print(",\"");
5030 String str = getHistoryTagPoolString(i);
5031 str = str.replace("\\", "\\\\");
5032 str = str.replace("\"", "\\\"");
5033 pw.print(str);
5034 pw.print("\"");
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005035 pw.println();
5036 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07005037 dumpHistoryLocked(pw, flags, histStart, true);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005038 } finally {
5039 finishIteratingHistoryLocked();
Dianne Hackborn099bc622014-01-22 13:39:16 -08005040 }
Dianne Hackborn13ac0412013-06-25 19:34:49 -07005041 }
Dianne Hackborn13ac0412013-06-25 19:34:49 -07005042 }
5043
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005044 if (filtering && (flags&(DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) == 0) {
Dianne Hackborn099bc622014-01-22 13:39:16 -08005045 return;
5046 }
5047
Dianne Hackborne4a59512010-12-07 11:08:07 -08005048 if (apps != null) {
5049 SparseArray<ArrayList<String>> uids = new SparseArray<ArrayList<String>>();
5050 for (int i=0; i<apps.size(); i++) {
5051 ApplicationInfo ai = apps.get(i);
5052 ArrayList<String> pkgs = uids.get(ai.uid);
5053 if (pkgs == null) {
5054 pkgs = new ArrayList<String>();
5055 uids.put(ai.uid, pkgs);
5056 }
5057 pkgs.add(ai.packageName);
5058 }
5059 SparseArray<? extends Uid> uidStats = getUidStats();
5060 final int NU = uidStats.size();
5061 String[] lineArgs = new String[2];
5062 for (int i=0; i<NU; i++) {
5063 int uid = uidStats.keyAt(i);
5064 ArrayList<String> pkgs = uids.get(uid);
5065 if (pkgs != null) {
5066 for (int j=0; j<pkgs.size(); j++) {
5067 lineArgs[0] = Integer.toString(uid);
5068 lineArgs[1] = pkgs.get(j);
5069 dumpLine(pw, 0 /* uid */, "i" /* category */, UID_DATA,
5070 (Object[])lineArgs);
5071 }
5072 }
5073 }
5074 }
Dianne Hackborncd0e3352014-08-07 17:08:09 -07005075 if (!filtering || (flags&DUMP_CHARGED_ONLY) != 0) {
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005076 dumpDurationSteps(pw, "", DISCHARGE_STEP_DATA, getDischargeLevelStepTracker(), true);
Dianne Hackbornd06dcfd2014-05-02 13:49:30 -07005077 String[] lineArgs = new String[1];
5078 long timeRemaining = computeBatteryTimeRemaining(SystemClock.elapsedRealtime());
5079 if (timeRemaining >= 0) {
5080 lineArgs[0] = Long.toString(timeRemaining);
5081 dumpLine(pw, 0 /* uid */, "i" /* category */, DISCHARGE_TIME_REMAIN_DATA,
5082 (Object[])lineArgs);
5083 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005084 dumpDurationSteps(pw, "", CHARGE_STEP_DATA, getChargeLevelStepTracker(), true);
Dianne Hackbornd06dcfd2014-05-02 13:49:30 -07005085 timeRemaining = computeChargeTimeRemaining(SystemClock.elapsedRealtime());
5086 if (timeRemaining >= 0) {
5087 lineArgs[0] = Long.toString(timeRemaining);
5088 dumpLine(pw, 0 /* uid */, "i" /* category */, CHARGE_TIME_REMAIN_DATA,
5089 (Object[])lineArgs);
5090 }
Dianne Hackbornd953c532014-08-16 18:17:38 -07005091 dumpCheckinLocked(context, pw, STATS_SINCE_CHARGED, -1,
5092 (flags&DUMP_DEVICE_WIFI_ONLY) != 0);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005093 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005094 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005095}