Kenny Root | 15a4d2f | 2010-03-11 18:20:12 -0800 | [diff] [blame] | 1 | /* |
| 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 Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17 | package android.os; |
| 18 | |
| 19 | import java.io.PrintWriter; |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 20 | import java.util.ArrayList; |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 21 | import java.util.Collections; |
| 22 | import java.util.Comparator; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 23 | import java.util.Formatter; |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 24 | import java.util.List; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 25 | import java.util.Map; |
| 26 | |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 27 | import android.content.Context; |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 28 | import android.content.pm.ApplicationInfo; |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 29 | import android.telephony.SignalStrength; |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 30 | import android.text.format.DateFormat; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 31 | import android.util.Printer; |
| 32 | import android.util.SparseArray; |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 33 | import android.util.TimeUtils; |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 34 | import com.android.internal.os.BatterySipper; |
| 35 | import com.android.internal.os.BatteryStatsHelper; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 36 | |
| 37 | /** |
| 38 | * A class providing access to battery usage statistics, including information on |
| 39 | * wakelocks, processes, packages, and services. All times are represented in microseconds |
| 40 | * except where indicated otherwise. |
| 41 | * @hide |
| 42 | */ |
| 43 | public abstract class BatteryStats implements Parcelable { |
| 44 | |
| 45 | private static final boolean LOCAL_LOGV = false; |
Dianne Hackborn | 91268cf | 2013-06-13 19:06:50 -0700 | [diff] [blame] | 46 | |
| 47 | /** @hide */ |
| 48 | public static final String SERVICE_NAME = "batterystats"; |
| 49 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 50 | /** |
| 51 | * A constant indicating a partial wake lock timer. |
| 52 | */ |
| 53 | public static final int WAKE_TYPE_PARTIAL = 0; |
| 54 | |
| 55 | /** |
| 56 | * A constant indicating a full wake lock timer. |
| 57 | */ |
| 58 | public static final int WAKE_TYPE_FULL = 1; |
| 59 | |
| 60 | /** |
| 61 | * A constant indicating a window wake lock timer. |
| 62 | */ |
| 63 | public static final int WAKE_TYPE_WINDOW = 2; |
| 64 | |
| 65 | /** |
| 66 | * A constant indicating a sensor timer. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 67 | */ |
| 68 | public static final int SENSOR = 3; |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 69 | |
| 70 | /** |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 71 | * A constant indicating a a wifi running timer |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 72 | */ |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 73 | public static final int WIFI_RUNNING = 4; |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 74 | |
| 75 | /** |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 76 | * A constant indicating a full wifi lock timer |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 77 | */ |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 78 | public static final int FULL_WIFI_LOCK = 5; |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 79 | |
| 80 | /** |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 81 | * A constant indicating a wifi scan |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 82 | */ |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 83 | public static final int WIFI_SCAN = 6; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 84 | |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 85 | /** |
| 86 | * A constant indicating a wifi multicast timer |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 87 | */ |
| 88 | public static final int WIFI_MULTICAST_ENABLED = 7; |
| 89 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 90 | /** |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 91 | * A constant indicating an audio turn on timer |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 92 | */ |
| 93 | public static final int AUDIO_TURNED_ON = 7; |
| 94 | |
| 95 | /** |
| 96 | * A constant indicating a video turn on timer |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 97 | */ |
| 98 | public static final int VIDEO_TURNED_ON = 8; |
| 99 | |
| 100 | /** |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 101 | * A constant indicating a vibrator on timer |
| 102 | */ |
| 103 | public static final int VIBRATOR_ON = 9; |
| 104 | |
| 105 | /** |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 106 | * A constant indicating a foreground activity timer |
| 107 | */ |
| 108 | public static final int FOREGROUND_ACTIVITY = 10; |
| 109 | |
| 110 | /** |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 111 | * A constant indicating a wifi batched scan is active |
| 112 | */ |
| 113 | public static final int WIFI_BATCHED_SCAN = 11; |
| 114 | |
| 115 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 116 | * Include all of the data in the stats, including previously saved data. |
| 117 | */ |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 118 | public static final int STATS_SINCE_CHARGED = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 119 | |
| 120 | /** |
| 121 | * Include only the last run in the stats. |
| 122 | */ |
| 123 | public static final int STATS_LAST = 1; |
| 124 | |
| 125 | /** |
| 126 | * Include only the current run in the stats. |
| 127 | */ |
| 128 | public static final int STATS_CURRENT = 2; |
| 129 | |
| 130 | /** |
| 131 | * Include only the run since the last time the device was unplugged in the stats. |
| 132 | */ |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 133 | public static final int STATS_SINCE_UNPLUGGED = 3; |
Evan Millar | e84de8d | 2009-04-02 22:16:12 -0700 | [diff] [blame] | 134 | |
| 135 | // NOTE: Update this list if you add/change any stats above. |
| 136 | // These characters are supposed to represent "total", "last", "current", |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 137 | // and "unplugged". They were shortened for efficiency sake. |
Evan Millar | e84de8d | 2009-04-02 22:16:12 -0700 | [diff] [blame] | 138 | private static final String[] STAT_NAMES = { "t", "l", "c", "u" }; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 139 | |
| 140 | /** |
| 141 | * Bump the version on this if the checkin format changes. |
| 142 | */ |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 143 | private static final int BATTERY_STATS_CHECKIN_VERSION = 7; |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 144 | |
| 145 | private static final long BYTES_PER_KB = 1024; |
| 146 | private static final long BYTES_PER_MB = 1048576; // 1024^2 |
| 147 | private static final long BYTES_PER_GB = 1073741824; //1024^3 |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 148 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 149 | |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 150 | private static final String UID_DATA = "uid"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 151 | private static final String APK_DATA = "apk"; |
Evan Millar | e84de8d | 2009-04-02 22:16:12 -0700 | [diff] [blame] | 152 | private static final String PROCESS_DATA = "pr"; |
| 153 | private static final String SENSOR_DATA = "sr"; |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 154 | private static final String VIBRATOR_DATA = "vib"; |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 155 | private static final String FOREGROUND_DATA = "fg"; |
Evan Millar | e84de8d | 2009-04-02 22:16:12 -0700 | [diff] [blame] | 156 | private static final String WAKELOCK_DATA = "wl"; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 157 | private static final String KERNEL_WAKELOCK_DATA = "kwl"; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame^] | 158 | private static final String WAKEUP_REASON_DATA = "wr"; |
Evan Millar | e84de8d | 2009-04-02 22:16:12 -0700 | [diff] [blame] | 159 | private static final String NETWORK_DATA = "nt"; |
| 160 | private static final String USER_ACTIVITY_DATA = "ua"; |
| 161 | private static final String BATTERY_DATA = "bt"; |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 162 | private static final String BATTERY_DISCHARGE_DATA = "dc"; |
Evan Millar | e84de8d | 2009-04-02 22:16:12 -0700 | [diff] [blame] | 163 | private static final String BATTERY_LEVEL_DATA = "lv"; |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 164 | private static final String WIFI_DATA = "wfl"; |
Evan Millar | e84de8d | 2009-04-02 22:16:12 -0700 | [diff] [blame] | 165 | private static final String MISC_DATA = "m"; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 166 | private static final String GLOBAL_NETWORK_DATA = "gn"; |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 167 | private static final String HISTORY_STRING_POOL = "hsp"; |
Dianne Hackborn | 8a0de58 | 2013-08-07 15:22:07 -0700 | [diff] [blame] | 168 | private static final String HISTORY_DATA = "h"; |
Evan Millar | e84de8d | 2009-04-02 22:16:12 -0700 | [diff] [blame] | 169 | private static final String SCREEN_BRIGHTNESS_DATA = "br"; |
| 170 | private static final String SIGNAL_STRENGTH_TIME_DATA = "sgt"; |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 171 | private static final String SIGNAL_SCANNING_TIME_DATA = "sst"; |
Evan Millar | e84de8d | 2009-04-02 22:16:12 -0700 | [diff] [blame] | 172 | private static final String SIGNAL_STRENGTH_COUNT_DATA = "sgc"; |
| 173 | private static final String DATA_CONNECTION_TIME_DATA = "dct"; |
| 174 | private static final String DATA_CONNECTION_COUNT_DATA = "dcc"; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 175 | private static final String WIFI_STATE_TIME_DATA = "wst"; |
| 176 | private static final String WIFI_STATE_COUNT_DATA = "wsc"; |
| 177 | private static final String BLUETOOTH_STATE_TIME_DATA = "bst"; |
| 178 | private static final String BLUETOOTH_STATE_COUNT_DATA = "bsc"; |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 179 | private static final String POWER_USE_SUMMARY_DATA = "pws"; |
| 180 | private static final String POWER_USE_ITEM_DATA = "pwi"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 181 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 182 | private final StringBuilder mFormatBuilder = new StringBuilder(32); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 183 | private final Formatter mFormatter = new Formatter(mFormatBuilder); |
| 184 | |
| 185 | /** |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 186 | * State for keeping track of counting information. |
| 187 | */ |
| 188 | public static abstract class Counter { |
| 189 | |
| 190 | /** |
| 191 | * Returns the count associated with this Counter for the |
| 192 | * selected type of statistics. |
| 193 | * |
| 194 | * @param which one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT |
| 195 | */ |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 196 | public abstract int getCountLocked(int which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 197 | |
| 198 | /** |
| 199 | * Temporary for debugging. |
| 200 | */ |
| 201 | public abstract void logState(Printer pw, String prefix); |
| 202 | } |
| 203 | |
| 204 | /** |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame^] | 205 | * State for keeping track of long counting information. |
| 206 | */ |
| 207 | public static abstract class LongCounter { |
| 208 | |
| 209 | /** |
| 210 | * Returns the count associated with this Counter for the |
| 211 | * selected type of statistics. |
| 212 | * |
| 213 | * @param which one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT |
| 214 | */ |
| 215 | public abstract long getCountLocked(int which); |
| 216 | |
| 217 | /** |
| 218 | * Temporary for debugging. |
| 219 | */ |
| 220 | public abstract void logState(Printer pw, String prefix); |
| 221 | } |
| 222 | |
| 223 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 224 | * State for keeping track of timing information. |
| 225 | */ |
| 226 | public static abstract class Timer { |
| 227 | |
| 228 | /** |
| 229 | * Returns the count associated with this Timer for the |
| 230 | * selected type of statistics. |
| 231 | * |
| 232 | * @param which one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT |
| 233 | */ |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 234 | public abstract int getCountLocked(int which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 235 | |
| 236 | /** |
| 237 | * Returns the total time in microseconds associated with this Timer for the |
| 238 | * selected type of statistics. |
| 239 | * |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 240 | * @param elapsedRealtimeUs current elapsed realtime of system in microseconds |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 241 | * @param which one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT |
| 242 | * @return a time in microseconds |
| 243 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 244 | public abstract long getTotalTimeLocked(long elapsedRealtimeUs, int which); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 245 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 246 | /** |
| 247 | * Temporary for debugging. |
| 248 | */ |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 249 | public abstract void logState(Printer pw, String prefix); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 250 | } |
| 251 | |
| 252 | /** |
| 253 | * The statistics associated with a particular uid. |
| 254 | */ |
| 255 | public static abstract class Uid { |
| 256 | |
| 257 | /** |
| 258 | * Returns a mapping containing wakelock statistics. |
| 259 | * |
| 260 | * @return a Map from Strings to Uid.Wakelock objects. |
| 261 | */ |
| 262 | public abstract Map<String, ? extends Wakelock> getWakelockStats(); |
| 263 | |
| 264 | /** |
| 265 | * The statistics associated with a particular wake lock. |
| 266 | */ |
| 267 | public static abstract class Wakelock { |
| 268 | public abstract Timer getWakeTime(int type); |
| 269 | } |
| 270 | |
| 271 | /** |
| 272 | * Returns a mapping containing sensor statistics. |
| 273 | * |
| 274 | * @return a Map from Integer sensor ids to Uid.Sensor objects. |
| 275 | */ |
| 276 | public abstract Map<Integer, ? extends Sensor> getSensorStats(); |
| 277 | |
| 278 | /** |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 279 | * Returns a mapping containing active process data. |
| 280 | */ |
| 281 | public abstract SparseArray<? extends Pid> getPidStats(); |
| 282 | |
| 283 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 284 | * Returns a mapping containing process statistics. |
| 285 | * |
| 286 | * @return a Map from Strings to Uid.Proc objects. |
| 287 | */ |
| 288 | public abstract Map<String, ? extends Proc> getProcessStats(); |
| 289 | |
| 290 | /** |
| 291 | * Returns a mapping containing package statistics. |
| 292 | * |
| 293 | * @return a Map from Strings to Uid.Pkg objects. |
| 294 | */ |
| 295 | public abstract Map<String, ? extends Pkg> getPackageStats(); |
| 296 | |
| 297 | /** |
| 298 | * {@hide} |
| 299 | */ |
| 300 | public abstract int getUid(); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 301 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 302 | public abstract void noteWifiRunningLocked(long elapsedRealtime); |
| 303 | public abstract void noteWifiStoppedLocked(long elapsedRealtime); |
| 304 | public abstract void noteFullWifiLockAcquiredLocked(long elapsedRealtime); |
| 305 | public abstract void noteFullWifiLockReleasedLocked(long elapsedRealtime); |
| 306 | public abstract void noteWifiScanStartedLocked(long elapsedRealtime); |
| 307 | public abstract void noteWifiScanStoppedLocked(long elapsedRealtime); |
| 308 | public abstract void noteWifiBatchedScanStartedLocked(int csph, long elapsedRealtime); |
| 309 | public abstract void noteWifiBatchedScanStoppedLocked(long elapsedRealtime); |
| 310 | public abstract void noteWifiMulticastEnabledLocked(long elapsedRealtime); |
| 311 | public abstract void noteWifiMulticastDisabledLocked(long elapsedRealtime); |
| 312 | public abstract void noteAudioTurnedOnLocked(long elapsedRealtime); |
| 313 | public abstract void noteAudioTurnedOffLocked(long elapsedRealtime); |
| 314 | public abstract void noteVideoTurnedOnLocked(long elapsedRealtime); |
| 315 | public abstract void noteVideoTurnedOffLocked(long elapsedRealtime); |
| 316 | public abstract void noteActivityResumedLocked(long elapsedRealtime); |
| 317 | public abstract void noteActivityPausedLocked(long elapsedRealtime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 318 | public abstract long getWifiRunningTime(long elapsedRealtimeUs, int which); |
| 319 | public abstract long getFullWifiLockTime(long elapsedRealtimeUs, int which); |
| 320 | public abstract long getWifiScanTime(long elapsedRealtimeUs, int which); |
| 321 | public abstract long getWifiBatchedScanTime(int csphBin, long elapsedRealtimeUs, int which); |
| 322 | public abstract long getWifiMulticastTime(long elapsedRealtimeUs, int which); |
| 323 | public abstract long getAudioTurnedOnTime(long elapsedRealtimeUs, int which); |
| 324 | public abstract long getVideoTurnedOnTime(long elapsedRealtimeUs, int which); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 325 | public abstract Timer getForegroundActivityTimer(); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 326 | public abstract Timer getVibratorOnTimer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 327 | |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 328 | public static final int NUM_WIFI_BATCHED_SCAN_BINS = 5; |
| 329 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 330 | /** |
Jeff Brown | df693de | 2012-07-27 12:03:38 -0700 | [diff] [blame] | 331 | * Note that these must match the constants in android.os.PowerManager. |
| 332 | * Also, if the user activity types change, the BatteryStatsImpl.VERSION must |
| 333 | * also be bumped. |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 334 | */ |
| 335 | static final String[] USER_ACTIVITY_TYPES = { |
Jeff Brown | df693de | 2012-07-27 12:03:38 -0700 | [diff] [blame] | 336 | "other", "button", "touch" |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 337 | }; |
| 338 | |
Jeff Brown | df693de | 2012-07-27 12:03:38 -0700 | [diff] [blame] | 339 | public static final int NUM_USER_ACTIVITY_TYPES = 3; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 340 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 341 | public abstract void noteUserActivityLocked(int type); |
| 342 | public abstract boolean hasUserActivity(); |
| 343 | public abstract int getUserActivityCount(int type, int which); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 344 | |
| 345 | public abstract boolean hasNetworkActivity(); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 346 | public abstract long getNetworkActivityBytes(int type, int which); |
| 347 | public abstract long getNetworkActivityPackets(int type, int which); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 348 | public abstract long getMobileRadioActiveTime(int which); |
| 349 | public abstract int getMobileRadioActiveCount(int which); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 350 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 351 | public static abstract class Sensor { |
Mathias Agopian | 7f84c06 | 2013-02-04 19:22:47 -0800 | [diff] [blame] | 352 | /* |
| 353 | * FIXME: it's not correct to use this magic value because it |
| 354 | * could clash with a sensor handle (which are defined by |
| 355 | * the sensor HAL, and therefore out of our control |
| 356 | */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 357 | // Magic sensor number for the GPS. |
| 358 | public static final int GPS = -10000; |
| 359 | |
| 360 | public abstract int getHandle(); |
| 361 | |
| 362 | public abstract Timer getSensorTime(); |
| 363 | } |
| 364 | |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 365 | public class Pid { |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 366 | public int mWakeNesting; |
| 367 | public long mWakeSumMs; |
| 368 | public long mWakeStartMs; |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 369 | } |
| 370 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 371 | /** |
| 372 | * The statistics associated with a particular process. |
| 373 | */ |
| 374 | public static abstract class Proc { |
| 375 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 376 | public static class ExcessivePower { |
| 377 | public static final int TYPE_WAKE = 1; |
| 378 | public static final int TYPE_CPU = 2; |
| 379 | |
| 380 | public int type; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 381 | public long overTime; |
| 382 | public long usedTime; |
| 383 | } |
| 384 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 385 | /** |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 386 | * Returns true if this process is still active in the battery stats. |
| 387 | */ |
| 388 | public abstract boolean isActive(); |
| 389 | |
| 390 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 391 | * Returns the total time (in 1/100 sec) spent executing in user code. |
| 392 | * |
| 393 | * @param which one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT. |
| 394 | */ |
| 395 | public abstract long getUserTime(int which); |
| 396 | |
| 397 | /** |
| 398 | * Returns the total time (in 1/100 sec) spent executing in system code. |
| 399 | * |
| 400 | * @param which one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT. |
| 401 | */ |
| 402 | public abstract long getSystemTime(int which); |
| 403 | |
| 404 | /** |
| 405 | * Returns the number of times the process has been started. |
| 406 | * |
| 407 | * @param which one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT. |
| 408 | */ |
| 409 | public abstract int getStarts(int which); |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 410 | |
| 411 | /** |
| 412 | * Returns the cpu time spent in microseconds while the process was in the foreground. |
| 413 | * @param which one of STATS_TOTAL, STATS_LAST, STATS_CURRENT or STATS_UNPLUGGED |
| 414 | * @return foreground cpu time in microseconds |
| 415 | */ |
| 416 | public abstract long getForegroundTime(int which); |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 417 | |
| 418 | /** |
| 419 | * Returns the approximate cpu time spent in microseconds, at a certain CPU speed. |
| 420 | * @param speedStep the index of the CPU speed. This is not the actual speed of the |
| 421 | * CPU. |
| 422 | * @param which one of STATS_TOTAL, STATS_LAST, STATS_CURRENT or STATS_UNPLUGGED |
| 423 | * @see BatteryStats#getCpuSpeedSteps() |
| 424 | */ |
| 425 | public abstract long getTimeAtCpuSpeedStep(int speedStep, int which); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 426 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 427 | public abstract int countExcessivePowers(); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 428 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 429 | public abstract ExcessivePower getExcessivePower(int i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 430 | } |
| 431 | |
| 432 | /** |
| 433 | * The statistics associated with a particular package. |
| 434 | */ |
| 435 | public static abstract class Pkg { |
| 436 | |
| 437 | /** |
| 438 | * Returns the number of times this package has done something that could wake up the |
| 439 | * device from sleep. |
| 440 | * |
| 441 | * @param which one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT. |
| 442 | */ |
| 443 | public abstract int getWakeups(int which); |
| 444 | |
| 445 | /** |
| 446 | * Returns a mapping containing service statistics. |
| 447 | */ |
| 448 | public abstract Map<String, ? extends Serv> getServiceStats(); |
| 449 | |
| 450 | /** |
| 451 | * The statistics associated with a particular service. |
| 452 | */ |
| 453 | public abstract class Serv { |
| 454 | |
| 455 | /** |
| 456 | * Returns the amount of time spent started. |
| 457 | * |
| 458 | * @param batteryUptime elapsed uptime on battery in microseconds. |
| 459 | * @param which one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT. |
| 460 | * @return |
| 461 | */ |
| 462 | public abstract long getStartTime(long batteryUptime, int which); |
| 463 | |
| 464 | /** |
| 465 | * Returns the total number of times startService() has been called. |
| 466 | * |
| 467 | * @param which one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT. |
| 468 | */ |
| 469 | public abstract int getStarts(int which); |
| 470 | |
| 471 | /** |
| 472 | * Returns the total number times the service has been launched. |
| 473 | * |
| 474 | * @param which one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT. |
| 475 | */ |
| 476 | public abstract int getLaunches(int which); |
| 477 | } |
| 478 | } |
| 479 | } |
| 480 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 481 | public final static class HistoryTag { |
| 482 | public String string; |
| 483 | public int uid; |
| 484 | |
| 485 | public int poolIdx; |
| 486 | |
| 487 | public void setTo(HistoryTag o) { |
| 488 | string = o.string; |
| 489 | uid = o.uid; |
| 490 | poolIdx = o.poolIdx; |
| 491 | } |
| 492 | |
| 493 | public void setTo(String _string, int _uid) { |
| 494 | string = _string; |
| 495 | uid = _uid; |
| 496 | poolIdx = -1; |
| 497 | } |
| 498 | |
| 499 | public void writeToParcel(Parcel dest, int flags) { |
| 500 | dest.writeString(string); |
| 501 | dest.writeInt(uid); |
| 502 | } |
| 503 | |
| 504 | public void readFromParcel(Parcel src) { |
| 505 | string = src.readString(); |
| 506 | uid = src.readInt(); |
| 507 | poolIdx = -1; |
| 508 | } |
| 509 | |
| 510 | @Override |
| 511 | public boolean equals(Object o) { |
| 512 | if (this == o) return true; |
| 513 | if (o == null || getClass() != o.getClass()) return false; |
| 514 | |
| 515 | HistoryTag that = (HistoryTag) o; |
| 516 | |
| 517 | if (uid != that.uid) return false; |
| 518 | if (!string.equals(that.string)) return false; |
| 519 | |
| 520 | return true; |
| 521 | } |
| 522 | |
| 523 | @Override |
| 524 | public int hashCode() { |
| 525 | int result = string.hashCode(); |
| 526 | result = 31 * result + uid; |
| 527 | return result; |
| 528 | } |
| 529 | } |
| 530 | |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 531 | public final static class HistoryItem implements Parcelable { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 532 | public HistoryItem next; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 533 | |
| 534 | public long time; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 535 | |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 536 | public static final byte CMD_UPDATE = 0; // These can be written as deltas |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 537 | public static final byte CMD_NULL = -1; |
| 538 | public static final byte CMD_START = 4; |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 539 | public static final byte CMD_CURRENT_TIME = 5; |
| 540 | public static final byte CMD_OVERFLOW = 6; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 541 | |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 542 | public byte cmd = CMD_NULL; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 543 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 544 | /** |
| 545 | * Return whether the command code is a delta data update. |
| 546 | */ |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 547 | public boolean isDeltaData() { |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 548 | return cmd == CMD_UPDATE; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 549 | } |
| 550 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 551 | public byte batteryLevel; |
| 552 | public byte batteryStatus; |
| 553 | public byte batteryHealth; |
| 554 | public byte batteryPlugType; |
| 555 | |
Sungmin Choi | c7e9e8b | 2013-01-16 12:57:36 +0900 | [diff] [blame] | 556 | public short batteryTemperature; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 557 | public char batteryVoltage; |
| 558 | |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 559 | // Constants from SCREEN_BRIGHTNESS_* |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 560 | public static final int STATE_BRIGHTNESS_SHIFT = 0; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 561 | public static final int STATE_BRIGHTNESS_MASK = 0x7; |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 562 | // Constants from SIGNAL_STRENGTH_* |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 563 | public static final int STATE_SIGNAL_STRENGTH_SHIFT = 3; |
| 564 | public static final int STATE_SIGNAL_STRENGTH_MASK = 0x7 << STATE_SIGNAL_STRENGTH_SHIFT; |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 565 | // Constants from ServiceState.STATE_* |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 566 | public static final int STATE_PHONE_STATE_SHIFT = 6; |
| 567 | public static final int STATE_PHONE_STATE_MASK = 0x7 << STATE_PHONE_STATE_SHIFT; |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 568 | // Constants from DATA_CONNECTION_* |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 569 | public static final int STATE_DATA_CONNECTION_SHIFT = 9; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 570 | public static final int STATE_DATA_CONNECTION_MASK = 0x1f << STATE_DATA_CONNECTION_SHIFT; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 571 | |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 572 | // These states always appear directly in the first int token |
| 573 | // of a delta change; they should be ones that change relatively |
| 574 | // frequently. |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame^] | 575 | public static final int STATE_CPU_RUNNING_FLAG = 1<<31; |
| 576 | public static final int STATE_WAKE_LOCK_FLAG = 1<<30; |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 577 | public static final int STATE_GPS_ON_FLAG = 1<<29; |
| 578 | public static final int STATE_WIFI_FULL_LOCK_FLAG = 1<<28; |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 579 | public static final int STATE_WIFI_SCAN_FLAG = 1<<27; |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 580 | public static final int STATE_WIFI_MULTICAST_ON_FLAG = 1<<26; |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 581 | public static final int STATE_MOBILE_RADIO_ACTIVE_FLAG = 1<<25; |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 582 | public static final int STATE_WIFI_RUNNING_FLAG = 1<<24; |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 583 | // These are on the lower bits used for the command; if they change |
| 584 | // we need to write another int of data. |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame^] | 585 | public static final int STATE_SENSOR_ON_FLAG = 1<<23; |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 586 | public static final int STATE_AUDIO_ON_FLAG = 1<<22; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame^] | 587 | public static final int STATE_PHONE_SCANNING_FLAG = 1<<21; |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 588 | public static final int STATE_SCREEN_ON_FLAG = 1<<20; |
| 589 | public static final int STATE_BATTERY_PLUGGED_FLAG = 1<<19; |
| 590 | public static final int STATE_PHONE_IN_CALL_FLAG = 1<<18; |
| 591 | public static final int STATE_WIFI_ON_FLAG = 1<<17; |
| 592 | public static final int STATE_BLUETOOTH_ON_FLAG = 1<<16; |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 593 | |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 594 | public static final int MOST_INTERESTING_STATES = |
| 595 | STATE_BATTERY_PLUGGED_FLAG | STATE_SCREEN_ON_FLAG |
| 596 | | STATE_GPS_ON_FLAG | STATE_PHONE_IN_CALL_FLAG; |
| 597 | |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 598 | public int states; |
| 599 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame^] | 600 | public static final int STATE2_VIDEO_ON_FLAG = 1<<0; |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 601 | public int states2; |
| 602 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 603 | // The wake lock that was acquired at this point. |
| 604 | public HistoryTag wakelockTag; |
| 605 | |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 606 | // Kernel wakeup reason at this point. |
| 607 | public HistoryTag wakeReasonTag; |
| 608 | |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 609 | public static final int EVENT_FLAG_START = 0x8000; |
| 610 | public static final int EVENT_FLAG_FINISH = 0x4000; |
| 611 | |
| 612 | // No event in this item. |
| 613 | public static final int EVENT_NONE = 0x0000; |
| 614 | // Event is about a process that is running. |
| 615 | public static final int EVENT_PROC = 0x0001; |
| 616 | // Event is about an application package that is in the foreground. |
| 617 | public static final int EVENT_FOREGROUND = 0x0002; |
| 618 | // Event is about an application package that is at the top of the screen. |
| 619 | public static final int EVENT_TOP = 0x0003; |
Dianne Hackborn | a1f1a3c | 2014-02-24 18:12:28 -0800 | [diff] [blame] | 620 | // Event is about an application package that is at the top of the screen. |
| 621 | public static final int EVENT_SYNC = 0x0004; |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 622 | // Number of event types. |
Dianne Hackborn | a1f1a3c | 2014-02-24 18:12:28 -0800 | [diff] [blame] | 623 | public static final int EVENT_COUNT = 0x0005; |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 624 | |
| 625 | public static final int EVENT_PROC_START = EVENT_PROC | EVENT_FLAG_START; |
| 626 | public static final int EVENT_PROC_FINISH = EVENT_PROC | EVENT_FLAG_FINISH; |
| 627 | public static final int EVENT_FOREGROUND_START = EVENT_FOREGROUND | EVENT_FLAG_START; |
| 628 | public static final int EVENT_FOREGROUND_FINISH = EVENT_FOREGROUND | EVENT_FLAG_FINISH; |
| 629 | public static final int EVENT_TOP_START = EVENT_TOP | EVENT_FLAG_START; |
| 630 | public static final int EVENT_TOP_FINISH = EVENT_TOP | EVENT_FLAG_FINISH; |
Dianne Hackborn | a1f1a3c | 2014-02-24 18:12:28 -0800 | [diff] [blame] | 631 | public static final int EVENT_SYNC_START = EVENT_SYNC | EVENT_FLAG_START; |
| 632 | public static final int EVENT_SYNC_FINISH = EVENT_SYNC | EVENT_FLAG_FINISH; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 633 | |
| 634 | // For CMD_EVENT. |
| 635 | public int eventCode; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 636 | public HistoryTag eventTag; |
| 637 | |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 638 | // Only set for CMD_CURRENT_TIME. |
| 639 | public long currentTime; |
| 640 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 641 | // Meta-data when reading. |
| 642 | public int numReadInts; |
| 643 | |
| 644 | // Pre-allocated objects. |
| 645 | public final HistoryTag localWakelockTag = new HistoryTag(); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 646 | public final HistoryTag localWakeReasonTag = new HistoryTag(); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 647 | public final HistoryTag localEventTag = new HistoryTag(); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 648 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 649 | public HistoryItem() { |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 650 | } |
| 651 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 652 | public HistoryItem(long time, Parcel src) { |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 653 | this.time = time; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 654 | numReadInts = 2; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 655 | readFromParcel(src); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 656 | } |
| 657 | |
| 658 | public int describeContents() { |
| 659 | return 0; |
| 660 | } |
| 661 | |
| 662 | public void writeToParcel(Parcel dest, int flags) { |
| 663 | dest.writeLong(time); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 664 | int bat = (((int)cmd)&0xff) |
| 665 | | ((((int)batteryLevel)<<8)&0xff00) |
| 666 | | ((((int)batteryStatus)<<16)&0xf0000) |
| 667 | | ((((int)batteryHealth)<<20)&0xf00000) |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 668 | | ((((int)batteryPlugType)<<24)&0xf000000) |
| 669 | | (wakelockTag != null ? 0x10000000 : 0) |
| 670 | | (wakeReasonTag != null ? 0x20000000 : 0) |
| 671 | | (eventCode != EVENT_NONE ? 0x40000000 : 0); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 672 | dest.writeInt(bat); |
| 673 | bat = (((int)batteryTemperature)&0xffff) |
| 674 | | ((((int)batteryVoltage)<<16)&0xffff0000); |
| 675 | dest.writeInt(bat); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 676 | dest.writeInt(states); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame^] | 677 | dest.writeInt(states2); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 678 | if (wakelockTag != null) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 679 | wakelockTag.writeToParcel(dest, flags); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 680 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 681 | if (wakeReasonTag != null) { |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 682 | wakeReasonTag.writeToParcel(dest, flags); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 683 | } |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 684 | if (eventCode != EVENT_NONE) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 685 | dest.writeInt(eventCode); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 686 | eventTag.writeToParcel(dest, flags); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 687 | } |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 688 | if (cmd == CMD_CURRENT_TIME) { |
| 689 | dest.writeLong(currentTime); |
| 690 | } |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 691 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 692 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 693 | public void readFromParcel(Parcel src) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 694 | int start = src.dataPosition(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 695 | int bat = src.readInt(); |
| 696 | cmd = (byte)(bat&0xff); |
| 697 | batteryLevel = (byte)((bat>>8)&0xff); |
| 698 | batteryStatus = (byte)((bat>>16)&0xf); |
| 699 | batteryHealth = (byte)((bat>>20)&0xf); |
| 700 | batteryPlugType = (byte)((bat>>24)&0xf); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 701 | int bat2 = src.readInt(); |
| 702 | batteryTemperature = (short)(bat2&0xffff); |
| 703 | batteryVoltage = (char)((bat2>>16)&0xffff); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 704 | states = src.readInt(); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame^] | 705 | states2 = src.readInt(); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 706 | if ((bat&0x10000000) != 0) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 707 | wakelockTag = localWakelockTag; |
| 708 | wakelockTag.readFromParcel(src); |
| 709 | } else { |
| 710 | wakelockTag = null; |
| 711 | } |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 712 | if ((bat&0x20000000) != 0) { |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 713 | wakeReasonTag = localWakeReasonTag; |
| 714 | wakeReasonTag.readFromParcel(src); |
| 715 | } else { |
| 716 | wakeReasonTag = null; |
| 717 | } |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 718 | if ((bat&0x40000000) != 0) { |
| 719 | eventCode = src.readInt(); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 720 | eventTag = localEventTag; |
| 721 | eventTag.readFromParcel(src); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 722 | } else { |
| 723 | eventCode = EVENT_NONE; |
| 724 | eventTag = null; |
| 725 | } |
| 726 | if (cmd == CMD_CURRENT_TIME) { |
| 727 | currentTime = src.readLong(); |
| 728 | } else { |
| 729 | currentTime = 0; |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 730 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 731 | numReadInts += (src.dataPosition()-start)/4; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 732 | } |
| 733 | |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 734 | public void clear() { |
| 735 | time = 0; |
| 736 | cmd = CMD_NULL; |
| 737 | batteryLevel = 0; |
| 738 | batteryStatus = 0; |
| 739 | batteryHealth = 0; |
| 740 | batteryPlugType = 0; |
| 741 | batteryTemperature = 0; |
| 742 | batteryVoltage = 0; |
| 743 | states = 0; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame^] | 744 | states2 = 0; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 745 | wakelockTag = null; |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 746 | wakeReasonTag = null; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 747 | eventCode = EVENT_NONE; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 748 | eventTag = null; |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 749 | } |
| 750 | |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 751 | public void setTo(HistoryItem o) { |
| 752 | time = o.time; |
| 753 | cmd = o.cmd; |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 754 | setToCommon(o); |
| 755 | } |
| 756 | |
| 757 | public void setTo(long time, byte cmd, HistoryItem o) { |
| 758 | this.time = time; |
| 759 | this.cmd = cmd; |
| 760 | setToCommon(o); |
| 761 | } |
| 762 | |
| 763 | private void setToCommon(HistoryItem o) { |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 764 | batteryLevel = o.batteryLevel; |
| 765 | batteryStatus = o.batteryStatus; |
| 766 | batteryHealth = o.batteryHealth; |
| 767 | batteryPlugType = o.batteryPlugType; |
| 768 | batteryTemperature = o.batteryTemperature; |
| 769 | batteryVoltage = o.batteryVoltage; |
| 770 | states = o.states; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame^] | 771 | states2 = o.states2; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 772 | if (o.wakelockTag != null) { |
| 773 | wakelockTag = localWakelockTag; |
| 774 | wakelockTag.setTo(o.wakelockTag); |
| 775 | } else { |
| 776 | wakelockTag = null; |
| 777 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 778 | if (o.wakeReasonTag != null) { |
| 779 | wakeReasonTag = localWakeReasonTag; |
| 780 | wakeReasonTag.setTo(o.wakeReasonTag); |
| 781 | } else { |
| 782 | wakeReasonTag = null; |
| 783 | } |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 784 | eventCode = o.eventCode; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 785 | if (o.eventTag != null) { |
| 786 | eventTag = localEventTag; |
| 787 | eventTag.setTo(o.eventTag); |
| 788 | } else { |
| 789 | eventTag = null; |
| 790 | } |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 791 | currentTime = o.currentTime; |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 792 | } |
| 793 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 794 | public boolean sameNonEvent(HistoryItem o) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 795 | return batteryLevel == o.batteryLevel |
| 796 | && batteryStatus == o.batteryStatus |
| 797 | && batteryHealth == o.batteryHealth |
| 798 | && batteryPlugType == o.batteryPlugType |
| 799 | && batteryTemperature == o.batteryTemperature |
| 800 | && batteryVoltage == o.batteryVoltage |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 801 | && states == o.states |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame^] | 802 | && states2 == o.states2 |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 803 | && currentTime == o.currentTime; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 804 | } |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 805 | |
| 806 | public boolean same(HistoryItem o) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 807 | if (!sameNonEvent(o) || eventCode != o.eventCode) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 808 | return false; |
| 809 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 810 | if (wakelockTag != o.wakelockTag) { |
| 811 | if (wakelockTag == null || o.wakelockTag == null) { |
| 812 | return false; |
| 813 | } |
| 814 | if (!wakelockTag.equals(o.wakelockTag)) { |
| 815 | return false; |
| 816 | } |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 817 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 818 | if (wakeReasonTag != o.wakeReasonTag) { |
| 819 | if (wakeReasonTag == null || o.wakeReasonTag == null) { |
| 820 | return false; |
| 821 | } |
| 822 | if (!wakeReasonTag.equals(o.wakeReasonTag)) { |
| 823 | return false; |
| 824 | } |
| 825 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 826 | if (eventTag != o.eventTag) { |
| 827 | if (eventTag == null || o.eventTag == null) { |
| 828 | return false; |
| 829 | } |
| 830 | if (!eventTag.equals(o.eventTag)) { |
| 831 | return false; |
| 832 | } |
| 833 | } |
| 834 | return true; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 835 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 836 | } |
| 837 | |
| 838 | public static final class BitDescription { |
| 839 | public final int mask; |
| 840 | public final int shift; |
| 841 | public final String name; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 842 | public final String shortName; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 843 | public final String[] values; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 844 | public final String[] shortValues; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 845 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 846 | public BitDescription(int mask, String name, String shortName) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 847 | this.mask = mask; |
| 848 | this.shift = -1; |
| 849 | this.name = name; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 850 | this.shortName = shortName; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 851 | this.values = null; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 852 | this.shortValues = null; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 853 | } |
| 854 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 855 | public BitDescription(int mask, int shift, String name, String shortName, |
| 856 | String[] values, String[] shortValues) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 857 | this.mask = mask; |
| 858 | this.shift = shift; |
| 859 | this.name = name; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 860 | this.shortName = shortName; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 861 | this.values = values; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 862 | this.shortValues = shortValues; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 863 | } |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 864 | } |
| 865 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 866 | public abstract int getHistoryTotalSize(); |
| 867 | |
| 868 | public abstract int getHistoryUsedSize(); |
| 869 | |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 870 | public abstract boolean startIteratingHistoryLocked(); |
| 871 | |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 872 | public abstract int getHistoryStringPoolSize(); |
| 873 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 874 | public abstract int getHistoryStringPoolBytes(); |
| 875 | |
| 876 | public abstract String getHistoryTagPoolString(int index); |
| 877 | |
| 878 | public abstract int getHistoryTagPoolUid(int index); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 879 | |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 880 | public abstract boolean getNextHistoryLocked(HistoryItem out); |
| 881 | |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 882 | public abstract void finishIteratingHistoryLocked(); |
| 883 | |
| 884 | public abstract boolean startIteratingOldHistoryLocked(); |
| 885 | |
| 886 | public abstract boolean getNextOldHistoryLocked(HistoryItem out); |
| 887 | |
| 888 | public abstract void finishIteratingOldHistoryLocked(); |
| 889 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 890 | /** |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 891 | * Return the base time offset for the battery history. |
| 892 | */ |
| 893 | public abstract long getHistoryBaseTime(); |
| 894 | |
| 895 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 896 | * Returns the number of times the device has been started. |
| 897 | */ |
| 898 | public abstract int getStartCount(); |
| 899 | |
| 900 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 901 | * Returns the time in microseconds that the screen has been on while the device was |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 902 | * running on battery. |
| 903 | * |
| 904 | * {@hide} |
| 905 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 906 | public abstract long getScreenOnTime(long elapsedRealtimeUs, int which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 907 | |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 908 | /** |
| 909 | * Returns the number of times the screen was turned on. |
| 910 | * |
| 911 | * {@hide} |
| 912 | */ |
| 913 | public abstract int getScreenOnCount(int which); |
| 914 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 915 | public static final int SCREEN_BRIGHTNESS_DARK = 0; |
| 916 | public static final int SCREEN_BRIGHTNESS_DIM = 1; |
| 917 | public static final int SCREEN_BRIGHTNESS_MEDIUM = 2; |
| 918 | public static final int SCREEN_BRIGHTNESS_LIGHT = 3; |
| 919 | public static final int SCREEN_BRIGHTNESS_BRIGHT = 4; |
| 920 | |
| 921 | static final String[] SCREEN_BRIGHTNESS_NAMES = { |
| 922 | "dark", "dim", "medium", "light", "bright" |
| 923 | }; |
| 924 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 925 | static final String[] SCREEN_BRIGHTNESS_SHORT_NAMES = { |
| 926 | "0", "1", "2", "3", "4" |
| 927 | }; |
| 928 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 929 | public static final int NUM_SCREEN_BRIGHTNESS_BINS = 5; |
| 930 | |
| 931 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 932 | * Returns the time in microseconds that the screen has been on with |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 933 | * the given brightness |
| 934 | * |
| 935 | * {@hide} |
| 936 | */ |
| 937 | public abstract long getScreenBrightnessTime(int brightnessBin, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 938 | long elapsedRealtimeUs, int which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 939 | |
| 940 | public abstract int getInputEventCount(int which); |
| 941 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 942 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 943 | * Returns the time in microseconds that the phone has been on while the device was |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 944 | * running on battery. |
| 945 | * |
| 946 | * {@hide} |
| 947 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 948 | public abstract long getPhoneOnTime(long elapsedRealtimeUs, int which); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 949 | |
| 950 | /** |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 951 | * Returns the number of times a phone call was activated. |
| 952 | * |
| 953 | * {@hide} |
| 954 | */ |
| 955 | public abstract int getPhoneOnCount(int which); |
| 956 | |
| 957 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 958 | * Returns the time in microseconds that the phone has been running with |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 959 | * the given signal strength. |
| 960 | * |
| 961 | * {@hide} |
| 962 | */ |
| 963 | public abstract long getPhoneSignalStrengthTime(int strengthBin, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 964 | long elapsedRealtimeUs, int which); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 965 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 966 | /** |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 967 | * Returns the time in microseconds that the phone has been trying to |
| 968 | * acquire a signal. |
| 969 | * |
| 970 | * {@hide} |
| 971 | */ |
| 972 | public abstract long getPhoneSignalScanningTime( |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 973 | long elapsedRealtimeUs, int which); |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 974 | |
| 975 | /** |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 976 | * Returns the number of times the phone has entered the given signal strength. |
| 977 | * |
| 978 | * {@hide} |
| 979 | */ |
| 980 | public abstract int getPhoneSignalStrengthCount(int strengthBin, int which); |
| 981 | |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 982 | /** |
| 983 | * Returns the time in microseconds that the mobile network has been active |
| 984 | * (in a high power state). |
| 985 | * |
| 986 | * {@hide} |
| 987 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 988 | public abstract long getMobileRadioActiveTime(long elapsedRealtimeUs, int which); |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 989 | |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 990 | /** |
| 991 | * Returns the number of times that the mobile network has transitioned to the |
| 992 | * active state. |
| 993 | * |
| 994 | * {@hide} |
| 995 | */ |
| 996 | public abstract int getMobileRadioActiveCount(int which); |
| 997 | |
| 998 | /** |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame^] | 999 | * Returns the time in microseconds that is the difference between the mobile radio |
| 1000 | * time we saw based on the elapsed timestamp when going down vs. the given time stamp |
| 1001 | * from the radio. |
| 1002 | * |
| 1003 | * {@hide} |
| 1004 | */ |
| 1005 | public abstract long getMobileRadioActiveAdjustedTime(int which); |
| 1006 | |
| 1007 | /** |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 1008 | * Returns the time in microseconds that the mobile network has been active |
| 1009 | * (in a high power state) but not being able to blame on an app. |
| 1010 | * |
| 1011 | * {@hide} |
| 1012 | */ |
| 1013 | public abstract long getMobileRadioActiveUnknownTime(int which); |
| 1014 | |
| 1015 | /** |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 1016 | * Return count of number of times radio was up that could not be blamed on apps. |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 1017 | * |
| 1018 | * {@hide} |
| 1019 | */ |
| 1020 | public abstract int getMobileRadioActiveUnknownCount(int which); |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 1021 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 1022 | public static final int DATA_CONNECTION_NONE = 0; |
| 1023 | public static final int DATA_CONNECTION_GPRS = 1; |
| 1024 | public static final int DATA_CONNECTION_EDGE = 2; |
| 1025 | public static final int DATA_CONNECTION_UMTS = 3; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1026 | public static final int DATA_CONNECTION_CDMA = 4; |
| 1027 | public static final int DATA_CONNECTION_EVDO_0 = 5; |
| 1028 | public static final int DATA_CONNECTION_EVDO_A = 6; |
| 1029 | public static final int DATA_CONNECTION_1xRTT = 7; |
| 1030 | public static final int DATA_CONNECTION_HSDPA = 8; |
| 1031 | public static final int DATA_CONNECTION_HSUPA = 9; |
| 1032 | public static final int DATA_CONNECTION_HSPA = 10; |
| 1033 | public static final int DATA_CONNECTION_IDEN = 11; |
| 1034 | public static final int DATA_CONNECTION_EVDO_B = 12; |
Robert Greenwalt | 962a990 | 2010-11-02 11:10:25 -0700 | [diff] [blame] | 1035 | public static final int DATA_CONNECTION_LTE = 13; |
| 1036 | public static final int DATA_CONNECTION_EHRPD = 14; |
Patrick Tjin | b71703c | 2013-11-06 09:27:03 -0800 | [diff] [blame] | 1037 | public static final int DATA_CONNECTION_HSPAP = 15; |
| 1038 | public static final int DATA_CONNECTION_OTHER = 16; |
Robert Greenwalt | 962a990 | 2010-11-02 11:10:25 -0700 | [diff] [blame] | 1039 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 1040 | static final String[] DATA_CONNECTION_NAMES = { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1041 | "none", "gprs", "edge", "umts", "cdma", "evdo_0", "evdo_A", |
Robert Greenwalt | 962a990 | 2010-11-02 11:10:25 -0700 | [diff] [blame] | 1042 | "1xrtt", "hsdpa", "hsupa", "hspa", "iden", "evdo_b", "lte", |
Patrick Tjin | b71703c | 2013-11-06 09:27:03 -0800 | [diff] [blame] | 1043 | "ehrpd", "hspap", "other" |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 1044 | }; |
| 1045 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1046 | public static final int NUM_DATA_CONNECTION_TYPES = DATA_CONNECTION_OTHER+1; |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 1047 | |
| 1048 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 1049 | * Returns the time in microseconds that the phone has been running with |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 1050 | * the given data connection. |
| 1051 | * |
| 1052 | * {@hide} |
| 1053 | */ |
| 1054 | public abstract long getPhoneDataConnectionTime(int dataType, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1055 | long elapsedRealtimeUs, int which); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 1056 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1057 | /** |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1058 | * Returns the number of times the phone has entered the given data |
| 1059 | * connection type. |
| 1060 | * |
| 1061 | * {@hide} |
| 1062 | */ |
| 1063 | public abstract int getPhoneDataConnectionCount(int dataType, int which); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame^] | 1064 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1065 | public static final BitDescription[] HISTORY_STATE_DESCRIPTIONS |
| 1066 | = new BitDescription[] { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame^] | 1067 | new BitDescription(HistoryItem.STATE_CPU_RUNNING_FLAG, "running", "r"), |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 1068 | new BitDescription(HistoryItem.STATE_WAKE_LOCK_FLAG, "wake_lock", "w"), |
| 1069 | new BitDescription(HistoryItem.STATE_SENSOR_ON_FLAG, "sensor", "s"), |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1070 | new BitDescription(HistoryItem.STATE_GPS_ON_FLAG, "gps", "g"), |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1071 | new BitDescription(HistoryItem.STATE_WIFI_FULL_LOCK_FLAG, "wifi_full_lock", "Wl"), |
| 1072 | new BitDescription(HistoryItem.STATE_WIFI_SCAN_FLAG, "wifi_scan", "Ws"), |
| 1073 | new BitDescription(HistoryItem.STATE_WIFI_MULTICAST_ON_FLAG, "wifi_multicast", "Wm"), |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 1074 | new BitDescription(HistoryItem.STATE_MOBILE_RADIO_ACTIVE_FLAG, "mobile_radio", "Pr"), |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 1075 | new BitDescription(HistoryItem.STATE_WIFI_RUNNING_FLAG, "wifi_running", "Wr"), |
| 1076 | new BitDescription(HistoryItem.STATE_PHONE_SCANNING_FLAG, "phone_scanning", "Psc"), |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1077 | new BitDescription(HistoryItem.STATE_AUDIO_ON_FLAG, "audio", "a"), |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 1078 | new BitDescription(HistoryItem.STATE_SCREEN_ON_FLAG, "screen", "S"), |
| 1079 | new BitDescription(HistoryItem.STATE_BATTERY_PLUGGED_FLAG, "plugged", "BP"), |
| 1080 | new BitDescription(HistoryItem.STATE_PHONE_IN_CALL_FLAG, "phone_in_call", "Pcl"), |
| 1081 | new BitDescription(HistoryItem.STATE_WIFI_ON_FLAG, "wifi", "W"), |
| 1082 | new BitDescription(HistoryItem.STATE_BLUETOOTH_ON_FLAG, "bluetooth", "b"), |
| 1083 | new BitDescription(HistoryItem.STATE_DATA_CONNECTION_MASK, |
| 1084 | HistoryItem.STATE_DATA_CONNECTION_SHIFT, "data_conn", "Pcn", |
| 1085 | DATA_CONNECTION_NAMES, DATA_CONNECTION_NAMES), |
| 1086 | new BitDescription(HistoryItem.STATE_PHONE_STATE_MASK, |
| 1087 | HistoryItem.STATE_PHONE_STATE_SHIFT, "phone_state", "Pst", |
| 1088 | new String[] {"in", "out", "emergency", "off"}, |
| 1089 | new String[] {"in", "out", "em", "off"}), |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1090 | new BitDescription(HistoryItem.STATE_SIGNAL_STRENGTH_MASK, |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1091 | HistoryItem.STATE_SIGNAL_STRENGTH_SHIFT, "signal_strength", "Pss", |
| 1092 | SignalStrength.SIGNAL_STRENGTH_NAMES, new String[] { |
| 1093 | "0", "1", "2", "3", "4" |
| 1094 | }), |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 1095 | new BitDescription(HistoryItem.STATE_BRIGHTNESS_MASK, |
| 1096 | HistoryItem.STATE_BRIGHTNESS_SHIFT, "brightness", "Sb", |
| 1097 | SCREEN_BRIGHTNESS_NAMES, SCREEN_BRIGHTNESS_SHORT_NAMES), |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1098 | }; |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1099 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame^] | 1100 | public static final BitDescription[] HISTORY_STATE2_DESCRIPTIONS |
| 1101 | = new BitDescription[] { |
| 1102 | new BitDescription(HistoryItem.STATE2_VIDEO_ON_FLAG, "video", "v"), |
| 1103 | }; |
| 1104 | |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 1105 | public static final String[] HISTORY_EVENT_NAMES = new String[] { |
Dianne Hackborn | a1f1a3c | 2014-02-24 18:12:28 -0800 | [diff] [blame] | 1106 | "null", "proc", "fg", "top", "sync" |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 1107 | }; |
| 1108 | |
| 1109 | public static final String[] HISTORY_EVENT_CHECKIN_NAMES = new String[] { |
Dianne Hackborn | a1f1a3c | 2014-02-24 18:12:28 -0800 | [diff] [blame] | 1110 | "Enl", "Epr", "Efg", "Etp", "Esy" |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 1111 | }; |
| 1112 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1113 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 1114 | * Returns the time in microseconds that wifi has been on while the device was |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 1115 | * running on battery. |
| 1116 | * |
| 1117 | * {@hide} |
| 1118 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1119 | public abstract long getWifiOnTime(long elapsedRealtimeUs, int which); |
Eric Shienbrood | d4c5f89 | 2009-03-24 18:13:20 -0700 | [diff] [blame] | 1120 | |
| 1121 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 1122 | * Returns the time in microseconds that wifi has been on and the driver has |
Eric Shienbrood | d4c5f89 | 2009-03-24 18:13:20 -0700 | [diff] [blame] | 1123 | * been in the running state while the device was running on battery. |
| 1124 | * |
| 1125 | * {@hide} |
| 1126 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1127 | public abstract long getGlobalWifiRunningTime(long elapsedRealtimeUs, int which); |
Eric Shienbrood | d4c5f89 | 2009-03-24 18:13:20 -0700 | [diff] [blame] | 1128 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 1129 | public static final int WIFI_STATE_OFF = 0; |
| 1130 | public static final int WIFI_STATE_OFF_SCANNING = 1; |
| 1131 | public static final int WIFI_STATE_ON_NO_NETWORKS = 2; |
| 1132 | public static final int WIFI_STATE_ON_DISCONNECTED = 3; |
| 1133 | public static final int WIFI_STATE_ON_CONNECTED_STA = 4; |
| 1134 | public static final int WIFI_STATE_ON_CONNECTED_P2P = 5; |
| 1135 | public static final int WIFI_STATE_ON_CONNECTED_STA_P2P = 6; |
| 1136 | public static final int WIFI_STATE_SOFT_AP = 7; |
| 1137 | |
| 1138 | static final String[] WIFI_STATE_NAMES = { |
| 1139 | "off", "scanning", "no_net", "disconn", |
| 1140 | "sta", "p2p", "sta_p2p", "soft_ap" |
| 1141 | }; |
| 1142 | |
| 1143 | public static final int NUM_WIFI_STATES = WIFI_STATE_SOFT_AP+1; |
| 1144 | |
| 1145 | /** |
| 1146 | * Returns the time in microseconds that WiFi has been running in the given state. |
| 1147 | * |
| 1148 | * {@hide} |
| 1149 | */ |
| 1150 | public abstract long getWifiStateTime(int wifiState, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1151 | long elapsedRealtimeUs, int which); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 1152 | |
| 1153 | /** |
| 1154 | * Returns the number of times that WiFi has entered the given state. |
| 1155 | * |
| 1156 | * {@hide} |
| 1157 | */ |
| 1158 | public abstract int getWifiStateCount(int wifiState, int which); |
| 1159 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 1160 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 1161 | * Returns the time in microseconds that bluetooth has been on while the device was |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 1162 | * running on battery. |
| 1163 | * |
| 1164 | * {@hide} |
| 1165 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1166 | public abstract long getBluetoothOnTime(long elapsedRealtimeUs, int which); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 1167 | |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 1168 | public abstract int getBluetoothPingCount(); |
| 1169 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 1170 | public static final int BLUETOOTH_STATE_INACTIVE = 0; |
| 1171 | public static final int BLUETOOTH_STATE_LOW = 1; |
| 1172 | public static final int BLUETOOTH_STATE_MEDIUM = 2; |
| 1173 | public static final int BLUETOOTH_STATE_HIGH = 3; |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 1174 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 1175 | static final String[] BLUETOOTH_STATE_NAMES = { |
| 1176 | "inactive", "low", "med", "high" |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 1177 | }; |
| 1178 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 1179 | public static final int NUM_BLUETOOTH_STATES = BLUETOOTH_STATE_HIGH +1; |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 1180 | |
| 1181 | /** |
| 1182 | * Returns the time in microseconds that Bluetooth has been running in the |
| 1183 | * given active state. |
| 1184 | * |
| 1185 | * {@hide} |
| 1186 | */ |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 1187 | public abstract long getBluetoothStateTime(int bluetoothState, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1188 | long elapsedRealtimeUs, int which); |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 1189 | |
| 1190 | /** |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 1191 | * Returns the number of times that Bluetooth has entered the given active state. |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 1192 | * |
| 1193 | * {@hide} |
| 1194 | */ |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 1195 | public abstract int getBluetoothStateCount(int bluetoothState, int which); |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 1196 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1197 | public static final int NETWORK_MOBILE_RX_DATA = 0; |
| 1198 | public static final int NETWORK_MOBILE_TX_DATA = 1; |
| 1199 | public static final int NETWORK_WIFI_RX_DATA = 2; |
| 1200 | public static final int NETWORK_WIFI_TX_DATA = 3; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 1201 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1202 | public static final int NUM_NETWORK_ACTIVITY_TYPES = NETWORK_WIFI_TX_DATA + 1; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 1203 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1204 | public abstract long getNetworkActivityBytes(int type, int which); |
| 1205 | public abstract long getNetworkActivityPackets(int type, int which); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 1206 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 1207 | /** |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 1208 | * Return the wall clock time when battery stats data collection started. |
| 1209 | */ |
| 1210 | public abstract long getStartClockTime(); |
| 1211 | |
| 1212 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1213 | * Return whether we are currently running on battery. |
| 1214 | */ |
| 1215 | public abstract boolean getIsOnBattery(); |
| 1216 | |
| 1217 | /** |
| 1218 | * Returns a SparseArray containing the statistics for each uid. |
| 1219 | */ |
| 1220 | public abstract SparseArray<? extends Uid> getUidStats(); |
| 1221 | |
| 1222 | /** |
| 1223 | * Returns the current battery uptime in microseconds. |
| 1224 | * |
| 1225 | * @param curTime the amount of elapsed realtime in microseconds. |
| 1226 | */ |
| 1227 | public abstract long getBatteryUptime(long curTime); |
| 1228 | |
| 1229 | /** |
| 1230 | * Returns the current battery realtime in microseconds. |
| 1231 | * |
| 1232 | * @param curTime the amount of elapsed realtime in microseconds. |
| 1233 | */ |
| 1234 | public abstract long getBatteryRealtime(long curTime); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 1235 | |
| 1236 | /** |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 1237 | * Returns the battery percentage level at the last time the device was unplugged from power, or |
| 1238 | * the last time it booted on battery power. |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 1239 | */ |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 1240 | public abstract int getDischargeStartLevel(); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 1241 | |
| 1242 | /** |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 1243 | * Returns the current battery percentage level if we are in a discharge cycle, otherwise |
| 1244 | * returns the level at the last plug event. |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 1245 | */ |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 1246 | public abstract int getDischargeCurrentLevel(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1247 | |
| 1248 | /** |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 1249 | * Get the amount the battery has discharged since the stats were |
| 1250 | * last reset after charging, as a lower-end approximation. |
| 1251 | */ |
| 1252 | public abstract int getLowDischargeAmountSinceCharge(); |
| 1253 | |
| 1254 | /** |
| 1255 | * Get the amount the battery has discharged since the stats were |
| 1256 | * last reset after charging, as an upper-end approximation. |
| 1257 | */ |
| 1258 | public abstract int getHighDischargeAmountSinceCharge(); |
| 1259 | |
| 1260 | /** |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 1261 | * Retrieve the discharge amount over the selected discharge period <var>which</var>. |
| 1262 | */ |
| 1263 | public abstract int getDischargeAmount(int which); |
| 1264 | |
| 1265 | /** |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 1266 | * Get the amount the battery has discharged while the screen was on, |
| 1267 | * since the last time power was unplugged. |
| 1268 | */ |
| 1269 | public abstract int getDischargeAmountScreenOn(); |
| 1270 | |
| 1271 | /** |
| 1272 | * Get the amount the battery has discharged while the screen was on, |
| 1273 | * since the last time the device was charged. |
| 1274 | */ |
| 1275 | public abstract int getDischargeAmountScreenOnSinceCharge(); |
| 1276 | |
| 1277 | /** |
| 1278 | * Get the amount the battery has discharged while the screen was off, |
| 1279 | * since the last time power was unplugged. |
| 1280 | */ |
| 1281 | public abstract int getDischargeAmountScreenOff(); |
| 1282 | |
| 1283 | /** |
| 1284 | * Get the amount the battery has discharged while the screen was off, |
| 1285 | * since the last time the device was charged. |
| 1286 | */ |
| 1287 | public abstract int getDischargeAmountScreenOffSinceCharge(); |
| 1288 | |
| 1289 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1290 | * Returns the total, last, or current battery uptime in microseconds. |
| 1291 | * |
| 1292 | * @param curTime the elapsed realtime in microseconds. |
| 1293 | * @param which one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT. |
| 1294 | */ |
| 1295 | public abstract long computeBatteryUptime(long curTime, int which); |
| 1296 | |
| 1297 | /** |
| 1298 | * Returns the total, last, or current battery realtime in microseconds. |
| 1299 | * |
| 1300 | * @param curTime the current elapsed realtime in microseconds. |
| 1301 | * @param which one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT. |
| 1302 | */ |
| 1303 | public abstract long computeBatteryRealtime(long curTime, int which); |
| 1304 | |
| 1305 | /** |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1306 | * Returns the total, last, or current battery screen off uptime in microseconds. |
| 1307 | * |
| 1308 | * @param curTime the elapsed realtime in microseconds. |
| 1309 | * @param which one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT. |
| 1310 | */ |
| 1311 | public abstract long computeBatteryScreenOffUptime(long curTime, int which); |
| 1312 | |
| 1313 | /** |
| 1314 | * Returns the total, last, or current battery screen off realtime in microseconds. |
| 1315 | * |
| 1316 | * @param curTime the current elapsed realtime in microseconds. |
| 1317 | * @param which one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT. |
| 1318 | */ |
| 1319 | public abstract long computeBatteryScreenOffRealtime(long curTime, int which); |
| 1320 | |
| 1321 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1322 | * Returns the total, last, or current uptime in microseconds. |
| 1323 | * |
| 1324 | * @param curTime the current elapsed realtime in microseconds. |
| 1325 | * @param which one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT. |
| 1326 | */ |
| 1327 | public abstract long computeUptime(long curTime, int which); |
| 1328 | |
| 1329 | /** |
| 1330 | * Returns the total, last, or current realtime in microseconds. |
| 1331 | * * |
| 1332 | * @param curTime the current elapsed realtime in microseconds. |
| 1333 | * @param which one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT. |
| 1334 | */ |
| 1335 | public abstract long computeRealtime(long curTime, int which); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1336 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame^] | 1337 | public abstract Map<String, ? extends LongCounter> getWakeupReasonStats(); |
| 1338 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1339 | public abstract Map<String, ? extends Timer> getKernelWakelockStats(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1340 | |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 1341 | /** Returns the number of different speeds that the CPU can run at */ |
| 1342 | public abstract int getCpuSpeedSteps(); |
| 1343 | |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 1344 | public abstract void writeToParcelWithoutUids(Parcel out, int flags); |
| 1345 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 1346 | private final static void formatTimeRaw(StringBuilder out, long seconds) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1347 | long days = seconds / (60 * 60 * 24); |
| 1348 | if (days != 0) { |
| 1349 | out.append(days); |
| 1350 | out.append("d "); |
| 1351 | } |
| 1352 | long used = days * 60 * 60 * 24; |
| 1353 | |
| 1354 | long hours = (seconds - used) / (60 * 60); |
| 1355 | if (hours != 0 || used != 0) { |
| 1356 | out.append(hours); |
| 1357 | out.append("h "); |
| 1358 | } |
| 1359 | used += hours * 60 * 60; |
| 1360 | |
| 1361 | long mins = (seconds-used) / 60; |
| 1362 | if (mins != 0 || used != 0) { |
| 1363 | out.append(mins); |
| 1364 | out.append("m "); |
| 1365 | } |
| 1366 | used += mins * 60; |
| 1367 | |
| 1368 | if (seconds != 0 || used != 0) { |
| 1369 | out.append(seconds-used); |
| 1370 | out.append("s "); |
| 1371 | } |
| 1372 | } |
| 1373 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1374 | public final static void formatTime(StringBuilder sb, long time) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1375 | long sec = time / 100; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 1376 | formatTimeRaw(sb, sec); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1377 | sb.append((time - (sec * 100)) * 10); |
| 1378 | sb.append("ms "); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1379 | } |
| 1380 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1381 | public final static void formatTimeMs(StringBuilder sb, long time) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1382 | long sec = time / 1000; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 1383 | formatTimeRaw(sb, sec); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1384 | sb.append(time - (sec * 1000)); |
| 1385 | sb.append("ms "); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1386 | } |
| 1387 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1388 | public final static void formatTimeMsNoSpace(StringBuilder sb, long time) { |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 1389 | long sec = time / 1000; |
| 1390 | formatTimeRaw(sb, sec); |
| 1391 | sb.append(time - (sec * 1000)); |
| 1392 | sb.append("ms"); |
| 1393 | } |
| 1394 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1395 | public final String formatRatioLocked(long num, long den) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1396 | if (den == 0L) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1397 | return "--%"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1398 | } |
| 1399 | float perc = ((float)num) / ((float)den) * 100; |
| 1400 | mFormatBuilder.setLength(0); |
| 1401 | mFormatter.format("%.1f%%", perc); |
| 1402 | return mFormatBuilder.toString(); |
| 1403 | } |
| 1404 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1405 | final String formatBytesLocked(long bytes) { |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 1406 | mFormatBuilder.setLength(0); |
| 1407 | |
| 1408 | if (bytes < BYTES_PER_KB) { |
| 1409 | return bytes + "B"; |
| 1410 | } else if (bytes < BYTES_PER_MB) { |
| 1411 | mFormatter.format("%.2fKB", bytes / (double) BYTES_PER_KB); |
| 1412 | return mFormatBuilder.toString(); |
| 1413 | } else if (bytes < BYTES_PER_GB){ |
| 1414 | mFormatter.format("%.2fMB", bytes / (double) BYTES_PER_MB); |
| 1415 | return mFormatBuilder.toString(); |
| 1416 | } else { |
| 1417 | mFormatter.format("%.2fGB", bytes / (double) BYTES_PER_GB); |
| 1418 | return mFormatBuilder.toString(); |
| 1419 | } |
| 1420 | } |
| 1421 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1422 | private static long computeWakeLock(Timer timer, long elapsedRealtimeUs, int which) { |
Dianne Hackborn | c24ab86 | 2011-10-18 15:55:03 -0700 | [diff] [blame] | 1423 | if (timer != null) { |
| 1424 | // Convert from microseconds to milliseconds with rounding |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1425 | long totalTimeMicros = timer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Dianne Hackborn | c24ab86 | 2011-10-18 15:55:03 -0700 | [diff] [blame] | 1426 | long totalTimeMillis = (totalTimeMicros + 500) / 1000; |
| 1427 | return totalTimeMillis; |
| 1428 | } |
| 1429 | return 0; |
| 1430 | } |
| 1431 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1432 | /** |
| 1433 | * |
| 1434 | * @param sb a StringBuilder object. |
| 1435 | * @param timer a Timer object contining the wakelock times. |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1436 | * @param elapsedRealtimeUs the current on-battery time in microseconds. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1437 | * @param name the name of the wakelock. |
| 1438 | * @param which which one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT. |
| 1439 | * @param linePrefix a String to be prepended to each line of output. |
| 1440 | * @return the line prefix |
| 1441 | */ |
| 1442 | private static final String printWakeLock(StringBuilder sb, Timer timer, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1443 | long elapsedRealtimeUs, String name, int which, String linePrefix) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1444 | |
| 1445 | if (timer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1446 | long totalTimeMillis = computeWakeLock(timer, elapsedRealtimeUs, which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1447 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1448 | int count = timer.getCountLocked(which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1449 | if (totalTimeMillis != 0) { |
| 1450 | sb.append(linePrefix); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 1451 | formatTimeMs(sb, totalTimeMillis); |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 1452 | if (name != null) { |
| 1453 | sb.append(name); |
| 1454 | sb.append(' '); |
| 1455 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1456 | sb.append('('); |
| 1457 | sb.append(count); |
| 1458 | sb.append(" times)"); |
| 1459 | return ", "; |
| 1460 | } |
| 1461 | } |
| 1462 | return linePrefix; |
| 1463 | } |
| 1464 | |
| 1465 | /** |
| 1466 | * Checkin version of wakelock printer. Prints simple comma-separated list. |
| 1467 | * |
| 1468 | * @param sb a StringBuilder object. |
| 1469 | * @param timer a Timer object contining the wakelock times. |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1470 | * @param elapsedRealtimeUs the current time in microseconds. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1471 | * @param name the name of the wakelock. |
| 1472 | * @param which which one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT. |
| 1473 | * @param linePrefix a String to be prepended to each line of output. |
| 1474 | * @return the line prefix |
| 1475 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1476 | private static final String printWakeLockCheckin(StringBuilder sb, Timer timer, |
| 1477 | long elapsedRealtimeUs, String name, int which, String linePrefix) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1478 | long totalTimeMicros = 0; |
| 1479 | int count = 0; |
| 1480 | if (timer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1481 | totalTimeMicros = timer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1482 | count = timer.getCountLocked(which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1483 | } |
| 1484 | sb.append(linePrefix); |
| 1485 | sb.append((totalTimeMicros + 500) / 1000); // microseconds to milliseconds with rounding |
| 1486 | sb.append(','); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1487 | sb.append(name != null ? name + "," : ""); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1488 | sb.append(count); |
| 1489 | return ","; |
| 1490 | } |
| 1491 | |
| 1492 | /** |
| 1493 | * Dump a comma-separated line of values for terse checkin mode. |
| 1494 | * |
| 1495 | * @param pw the PageWriter to dump log to |
| 1496 | * @param category category of data (e.g. "total", "last", "unplugged", "current" ) |
| 1497 | * @param type type of data (e.g. "wakelock", "sensor", "process", "apk" , "process", "network") |
| 1498 | * @param args type-dependent data arguments |
| 1499 | */ |
| 1500 | private static final void dumpLine(PrintWriter pw, int uid, String category, String type, |
| 1501 | Object... args ) { |
| 1502 | pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(','); |
| 1503 | pw.print(uid); pw.print(','); |
| 1504 | pw.print(category); pw.print(','); |
Dianne Hackborn | 13ac041 | 2013-06-25 19:34:49 -0700 | [diff] [blame] | 1505 | pw.print(type); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1506 | |
| 1507 | for (Object arg : args) { |
Dianne Hackborn | 13ac041 | 2013-06-25 19:34:49 -0700 | [diff] [blame] | 1508 | pw.print(','); |
| 1509 | pw.print(arg); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1510 | } |
Dianne Hackborn | 13ac041 | 2013-06-25 19:34:49 -0700 | [diff] [blame] | 1511 | pw.println(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1512 | } |
| 1513 | |
| 1514 | /** |
| 1515 | * Checkin server version of dump to produce more compact, computer-readable log. |
| 1516 | * |
| 1517 | * NOTE: all times are expressed in 'ms'. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1518 | */ |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 1519 | public final void dumpCheckinLocked(Context context, PrintWriter pw, int which, int reqUid) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1520 | final long rawUptime = SystemClock.uptimeMillis() * 1000; |
| 1521 | final long rawRealtime = SystemClock.elapsedRealtime() * 1000; |
| 1522 | final long batteryUptime = getBatteryUptime(rawUptime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1523 | final long whichBatteryUptime = computeBatteryUptime(rawUptime, which); |
| 1524 | final long whichBatteryRealtime = computeBatteryRealtime(rawRealtime, which); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1525 | final long whichBatteryScreenOffUptime = computeBatteryScreenOffUptime(rawUptime, which); |
| 1526 | final long whichBatteryScreenOffRealtime = computeBatteryScreenOffRealtime(rawRealtime, |
| 1527 | which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1528 | final long totalRealtime = computeRealtime(rawRealtime, which); |
| 1529 | final long totalUptime = computeUptime(rawUptime, which); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1530 | final long screenOnTime = getScreenOnTime(rawRealtime, which); |
| 1531 | final long phoneOnTime = getPhoneOnTime(rawRealtime, which); |
| 1532 | final long wifiOnTime = getWifiOnTime(rawRealtime, which); |
| 1533 | final long wifiRunningTime = getGlobalWifiRunningTime(rawRealtime, which); |
| 1534 | final long bluetoothOnTime = getBluetoothOnTime(rawRealtime, which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1535 | |
| 1536 | StringBuilder sb = new StringBuilder(128); |
| 1537 | |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 1538 | SparseArray<? extends Uid> uidStats = getUidStats(); |
| 1539 | final int NU = uidStats.size(); |
| 1540 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1541 | String category = STAT_NAMES[which]; |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 1542 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1543 | // Dump "battery" stat |
| 1544 | dumpLine(pw, 0 /* uid */, category, BATTERY_DATA, |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1545 | which == STATS_SINCE_CHARGED ? getStartCount() : "N/A", |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1546 | whichBatteryRealtime / 1000, whichBatteryUptime / 1000, |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 1547 | totalRealtime / 1000, totalUptime / 1000, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1548 | getStartClockTime(), |
| 1549 | whichBatteryScreenOffRealtime / 1000, whichBatteryScreenOffUptime / 1000); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1550 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1551 | // Calculate wakelock times across all uids. |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 1552 | long fullWakeLockTimeTotal = 0; |
| 1553 | long partialWakeLockTimeTotal = 0; |
| 1554 | |
| 1555 | for (int iu = 0; iu < NU; iu++) { |
| 1556 | Uid u = uidStats.valueAt(iu); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 1557 | |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 1558 | Map<String, ? extends BatteryStats.Uid.Wakelock> wakelocks = u.getWakelockStats(); |
| 1559 | if (wakelocks.size() > 0) { |
| 1560 | for (Map.Entry<String, ? extends BatteryStats.Uid.Wakelock> ent |
| 1561 | : wakelocks.entrySet()) { |
| 1562 | Uid.Wakelock wl = ent.getValue(); |
| 1563 | |
| 1564 | Timer fullWakeTimer = wl.getWakeTime(WAKE_TYPE_FULL); |
| 1565 | if (fullWakeTimer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1566 | fullWakeLockTimeTotal += fullWakeTimer.getTotalTimeLocked(rawRealtime, |
| 1567 | which); |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 1568 | } |
| 1569 | |
| 1570 | Timer partialWakeTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL); |
| 1571 | if (partialWakeTimer != null) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1572 | partialWakeLockTimeTotal += partialWakeTimer.getTotalTimeLocked( |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1573 | rawRealtime, which); |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 1574 | } |
| 1575 | } |
| 1576 | } |
| 1577 | } |
| 1578 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1579 | long mobileRxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which); |
| 1580 | long mobileTxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which); |
| 1581 | long wifiRxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which); |
| 1582 | long wifiTxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which); |
| 1583 | long mobileRxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which); |
| 1584 | long mobileTxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which); |
| 1585 | long wifiRxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which); |
| 1586 | long wifiTxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which); |
| 1587 | |
| 1588 | // Dump network stats |
| 1589 | dumpLine(pw, 0 /* uid */, category, GLOBAL_NETWORK_DATA, |
| 1590 | mobileRxTotalBytes, mobileTxTotalBytes, wifiRxTotalBytes, wifiTxTotalBytes, |
| 1591 | mobileRxTotalPackets, mobileTxTotalPackets, wifiRxTotalPackets, wifiTxTotalPackets); |
| 1592 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1593 | // Dump misc stats |
| 1594 | dumpLine(pw, 0 /* uid */, category, MISC_DATA, |
Eric Shienbrood | d4c5f89 | 2009-03-24 18:13:20 -0700 | [diff] [blame] | 1595 | screenOnTime / 1000, phoneOnTime / 1000, wifiOnTime / 1000, |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 1596 | wifiRunningTime / 1000, bluetoothOnTime / 1000, |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1597 | mobileRxTotalBytes, mobileTxTotalBytes, wifiRxTotalBytes, wifiTxTotalBytes, |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1598 | fullWakeLockTimeTotal, partialWakeLockTimeTotal, |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame^] | 1599 | getInputEventCount(which), getMobileRadioActiveTime(rawRealtime, which), |
| 1600 | getMobileRadioActiveAdjustedTime(which)); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1601 | |
| 1602 | // Dump screen brightness stats |
| 1603 | Object[] args = new Object[NUM_SCREEN_BRIGHTNESS_BINS]; |
| 1604 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1605 | args[i] = getScreenBrightnessTime(i, rawRealtime, which) / 1000; |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1606 | } |
| 1607 | dumpLine(pw, 0 /* uid */, category, SCREEN_BRIGHTNESS_DATA, args); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 1608 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 1609 | // Dump signal strength stats |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 1610 | args = new Object[SignalStrength.NUM_SIGNAL_STRENGTH_BINS]; |
| 1611 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1612 | args[i] = getPhoneSignalStrengthTime(i, rawRealtime, which) / 1000; |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 1613 | } |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1614 | dumpLine(pw, 0 /* uid */, category, SIGNAL_STRENGTH_TIME_DATA, args); |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 1615 | dumpLine(pw, 0 /* uid */, category, SIGNAL_SCANNING_TIME_DATA, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1616 | getPhoneSignalScanningTime(rawRealtime, which) / 1000); |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 1617 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1618 | args[i] = getPhoneSignalStrengthCount(i, which); |
| 1619 | } |
| 1620 | dumpLine(pw, 0 /* uid */, category, SIGNAL_STRENGTH_COUNT_DATA, args); |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 1621 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 1622 | // Dump network type stats |
| 1623 | args = new Object[NUM_DATA_CONNECTION_TYPES]; |
| 1624 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1625 | args[i] = getPhoneDataConnectionTime(i, rawRealtime, which) / 1000; |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 1626 | } |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1627 | dumpLine(pw, 0 /* uid */, category, DATA_CONNECTION_TIME_DATA, args); |
| 1628 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
| 1629 | args[i] = getPhoneDataConnectionCount(i, which); |
| 1630 | } |
| 1631 | dumpLine(pw, 0 /* uid */, category, DATA_CONNECTION_COUNT_DATA, args); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 1632 | |
| 1633 | // Dump wifi state stats |
| 1634 | args = new Object[NUM_WIFI_STATES]; |
| 1635 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1636 | args[i] = getWifiStateTime(i, rawRealtime, which) / 1000; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 1637 | } |
| 1638 | dumpLine(pw, 0 /* uid */, category, WIFI_STATE_TIME_DATA, args); |
| 1639 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
| 1640 | args[i] = getWifiStateCount(i, which); |
| 1641 | } |
| 1642 | dumpLine(pw, 0 /* uid */, category, WIFI_STATE_COUNT_DATA, args); |
| 1643 | |
| 1644 | // Dump bluetooth state stats |
| 1645 | args = new Object[NUM_BLUETOOTH_STATES]; |
| 1646 | for (int i=0; i<NUM_BLUETOOTH_STATES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1647 | args[i] = getBluetoothStateTime(i, rawRealtime, which) / 1000; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 1648 | } |
| 1649 | dumpLine(pw, 0 /* uid */, category, BLUETOOTH_STATE_TIME_DATA, args); |
| 1650 | for (int i=0; i<NUM_BLUETOOTH_STATES; i++) { |
| 1651 | args[i] = getBluetoothStateCount(i, which); |
| 1652 | } |
| 1653 | dumpLine(pw, 0 /* uid */, category, BLUETOOTH_STATE_COUNT_DATA, args); |
| 1654 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1655 | if (which == STATS_SINCE_UNPLUGGED) { |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 1656 | dumpLine(pw, 0 /* uid */, category, BATTERY_LEVEL_DATA, getDischargeStartLevel(), |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 1657 | getDischargeCurrentLevel()); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 1658 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1659 | |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 1660 | if (which == STATS_SINCE_UNPLUGGED) { |
| 1661 | dumpLine(pw, 0 /* uid */, category, BATTERY_DISCHARGE_DATA, |
| 1662 | getDischargeStartLevel()-getDischargeCurrentLevel(), |
| 1663 | getDischargeStartLevel()-getDischargeCurrentLevel(), |
| 1664 | getDischargeAmountScreenOn(), getDischargeAmountScreenOff()); |
| 1665 | } else { |
| 1666 | dumpLine(pw, 0 /* uid */, category, BATTERY_DISCHARGE_DATA, |
| 1667 | getLowDischargeAmountSinceCharge(), getHighDischargeAmountSinceCharge(), |
| 1668 | getDischargeAmountScreenOn(), getDischargeAmountScreenOff()); |
| 1669 | } |
| 1670 | |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1671 | if (reqUid < 0) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame^] | 1672 | Map<String, ? extends Timer> kernelWakelocks = getKernelWakelockStats(); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1673 | if (kernelWakelocks.size() > 0) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame^] | 1674 | for (Map.Entry<String, ? extends Timer> ent : kernelWakelocks.entrySet()) { |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1675 | sb.setLength(0); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1676 | printWakeLockCheckin(sb, ent.getValue(), rawRealtime, null, which, ""); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame^] | 1677 | dumpLine(pw, 0 /* uid */, category, KERNEL_WAKELOCK_DATA, ent.getKey(), |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1678 | sb.toString()); |
| 1679 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1680 | } |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame^] | 1681 | Map<String, ? extends LongCounter> wakeupReasons = getWakeupReasonStats(); |
| 1682 | if (wakeupReasons.size() > 0) { |
| 1683 | for (Map.Entry<String, ? extends LongCounter> ent : wakeupReasons.entrySet()) { |
| 1684 | dumpLine(pw, 0 /* uid */, category, WAKEUP_REASON_DATA, |
| 1685 | "\"" + ent.getKey() + "\"", ent.getValue().getCountLocked(which)); |
| 1686 | } |
| 1687 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1688 | } |
| 1689 | |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 1690 | BatteryStatsHelper helper = new BatteryStatsHelper(context); |
| 1691 | helper.create(this); |
| 1692 | helper.refreshStats(which, UserHandle.USER_ALL); |
| 1693 | List<BatterySipper> sippers = helper.getUsageList(); |
| 1694 | if (sippers != null && sippers.size() > 0) { |
| 1695 | dumpLine(pw, 0 /* uid */, category, POWER_USE_SUMMARY_DATA, |
| 1696 | BatteryStatsHelper.makemAh(helper.getPowerProfile().getBatteryCapacity()), |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 1697 | BatteryStatsHelper.makemAh(helper.getComputedPower()), |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 1698 | BatteryStatsHelper.makemAh(helper.getMinDrainedPower()), |
| 1699 | BatteryStatsHelper.makemAh(helper.getMaxDrainedPower())); |
| 1700 | for (int i=0; i<sippers.size(); i++) { |
| 1701 | BatterySipper bs = sippers.get(i); |
| 1702 | int uid = 0; |
| 1703 | String label; |
| 1704 | switch (bs.drainType) { |
| 1705 | case IDLE: |
| 1706 | label="idle"; |
| 1707 | break; |
| 1708 | case CELL: |
| 1709 | label="cell"; |
| 1710 | break; |
| 1711 | case PHONE: |
| 1712 | label="phone"; |
| 1713 | break; |
| 1714 | case WIFI: |
| 1715 | label="wifi"; |
| 1716 | break; |
| 1717 | case BLUETOOTH: |
| 1718 | label="blue"; |
| 1719 | break; |
| 1720 | case SCREEN: |
| 1721 | label="scrn"; |
| 1722 | break; |
| 1723 | case APP: |
| 1724 | uid = bs.uidObj.getUid(); |
| 1725 | label = "uid"; |
| 1726 | break; |
| 1727 | case USER: |
| 1728 | uid = UserHandle.getUid(bs.userId, 0); |
| 1729 | label = "user"; |
| 1730 | break; |
| 1731 | case UNACCOUNTED: |
| 1732 | label = "unacc"; |
| 1733 | break; |
| 1734 | case OVERCOUNTED: |
| 1735 | label = "over"; |
| 1736 | break; |
| 1737 | default: |
| 1738 | label = "???"; |
| 1739 | } |
| 1740 | dumpLine(pw, uid, category, POWER_USE_ITEM_DATA, label, |
| 1741 | BatteryStatsHelper.makemAh(bs.value)); |
| 1742 | } |
| 1743 | } |
| 1744 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1745 | for (int iu = 0; iu < NU; iu++) { |
| 1746 | final int uid = uidStats.keyAt(iu); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1747 | if (reqUid >= 0 && uid != reqUid) { |
| 1748 | continue; |
| 1749 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1750 | Uid u = uidStats.valueAt(iu); |
| 1751 | // Dump Network stats per uid, if any |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1752 | long mobileBytesRx = u.getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which); |
| 1753 | long mobileBytesTx = u.getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which); |
| 1754 | long wifiBytesRx = u.getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which); |
| 1755 | long wifiBytesTx = u.getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which); |
| 1756 | long mobilePacketsRx = u.getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which); |
| 1757 | long mobilePacketsTx = u.getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 1758 | long mobileActiveTime = u.getMobileRadioActiveTime(which); |
| 1759 | int mobileActiveCount = u.getMobileRadioActiveCount(which); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1760 | long wifiPacketsRx = u.getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which); |
| 1761 | long wifiPacketsTx = u.getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1762 | long fullWifiLockOnTime = u.getFullWifiLockTime(rawRealtime, which); |
| 1763 | long wifiScanTime = u.getWifiScanTime(rawRealtime, which); |
| 1764 | long uidWifiRunningTime = u.getWifiRunningTime(rawRealtime, which); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 1765 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1766 | if (mobileBytesRx > 0 || mobileBytesTx > 0 || wifiBytesRx > 0 || wifiBytesTx > 0 |
| 1767 | || mobilePacketsRx > 0 || mobilePacketsTx > 0 || wifiPacketsRx > 0 |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 1768 | || wifiPacketsTx > 0 || mobileActiveTime > 0 || mobileActiveCount > 0) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1769 | dumpLine(pw, uid, category, NETWORK_DATA, mobileBytesRx, mobileBytesTx, |
| 1770 | wifiBytesRx, wifiBytesTx, |
| 1771 | mobilePacketsRx, mobilePacketsTx, |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 1772 | wifiPacketsRx, wifiPacketsTx, |
| 1773 | mobileActiveTime, mobileActiveCount); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 1774 | } |
| 1775 | |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 1776 | if (fullWifiLockOnTime != 0 || wifiScanTime != 0 |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 1777 | || uidWifiRunningTime != 0) { |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 1778 | dumpLine(pw, uid, category, WIFI_DATA, |
| 1779 | fullWifiLockOnTime, wifiScanTime, uidWifiRunningTime); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 1780 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1781 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1782 | if (u.hasUserActivity()) { |
| 1783 | args = new Object[Uid.NUM_USER_ACTIVITY_TYPES]; |
| 1784 | boolean hasData = false; |
| 1785 | for (int i=0; i<Uid.NUM_USER_ACTIVITY_TYPES; i++) { |
| 1786 | int val = u.getUserActivityCount(i, which); |
| 1787 | args[i] = val; |
| 1788 | if (val != 0) hasData = true; |
| 1789 | } |
| 1790 | if (hasData) { |
| 1791 | dumpLine(pw, 0 /* uid */, category, USER_ACTIVITY_DATA, args); |
| 1792 | } |
| 1793 | } |
| 1794 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1795 | Map<String, ? extends BatteryStats.Uid.Wakelock> wakelocks = u.getWakelockStats(); |
| 1796 | if (wakelocks.size() > 0) { |
| 1797 | for (Map.Entry<String, ? extends BatteryStats.Uid.Wakelock> ent |
| 1798 | : wakelocks.entrySet()) { |
| 1799 | Uid.Wakelock wl = ent.getValue(); |
| 1800 | String linePrefix = ""; |
| 1801 | sb.setLength(0); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1802 | linePrefix = printWakeLockCheckin(sb, wl.getWakeTime(WAKE_TYPE_FULL), |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1803 | rawRealtime, "f", which, linePrefix); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1804 | linePrefix = printWakeLockCheckin(sb, wl.getWakeTime(WAKE_TYPE_PARTIAL), |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1805 | rawRealtime, "p", which, linePrefix); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1806 | linePrefix = printWakeLockCheckin(sb, wl.getWakeTime(WAKE_TYPE_WINDOW), |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1807 | rawRealtime, "w", which, linePrefix); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1808 | |
| 1809 | // Only log if we had at lease one wakelock... |
| 1810 | if (sb.length() > 0) { |
Dianne Hackborn | 13ac041 | 2013-06-25 19:34:49 -0700 | [diff] [blame] | 1811 | String name = ent.getKey(); |
| 1812 | if (name.indexOf(',') >= 0) { |
| 1813 | name = name.replace(',', '_'); |
| 1814 | } |
| 1815 | dumpLine(pw, uid, category, WAKELOCK_DATA, name, sb.toString()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1816 | } |
| 1817 | } |
| 1818 | } |
| 1819 | |
| 1820 | Map<Integer, ? extends BatteryStats.Uid.Sensor> sensors = u.getSensorStats(); |
| 1821 | if (sensors.size() > 0) { |
| 1822 | for (Map.Entry<Integer, ? extends BatteryStats.Uid.Sensor> ent |
| 1823 | : sensors.entrySet()) { |
| 1824 | Uid.Sensor se = ent.getValue(); |
| 1825 | int sensorNumber = ent.getKey(); |
| 1826 | Timer timer = se.getSensorTime(); |
| 1827 | if (timer != null) { |
| 1828 | // Convert from microseconds to milliseconds with rounding |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1829 | long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1830 | int count = timer.getCountLocked(which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1831 | if (totalTime != 0) { |
| 1832 | dumpLine(pw, uid, category, SENSOR_DATA, sensorNumber, totalTime, count); |
| 1833 | } |
| 1834 | } |
| 1835 | } |
| 1836 | } |
| 1837 | |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1838 | Timer vibTimer = u.getVibratorOnTimer(); |
| 1839 | if (vibTimer != null) { |
| 1840 | // Convert from microseconds to milliseconds with rounding |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1841 | long totalTime = (vibTimer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000; |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1842 | int count = vibTimer.getCountLocked(which); |
| 1843 | if (totalTime != 0) { |
| 1844 | dumpLine(pw, uid, category, VIBRATOR_DATA, totalTime, count); |
| 1845 | } |
| 1846 | } |
| 1847 | |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 1848 | Timer fgTimer = u.getForegroundActivityTimer(); |
| 1849 | if (fgTimer != null) { |
| 1850 | // Convert from microseconds to milliseconds with rounding |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1851 | long totalTime = (fgTimer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000; |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 1852 | int count = fgTimer.getCountLocked(which); |
| 1853 | if (totalTime != 0) { |
| 1854 | dumpLine(pw, uid, category, FOREGROUND_DATA, totalTime, count); |
| 1855 | } |
| 1856 | } |
| 1857 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1858 | Map<String, ? extends BatteryStats.Uid.Proc> processStats = u.getProcessStats(); |
| 1859 | if (processStats.size() > 0) { |
| 1860 | for (Map.Entry<String, ? extends BatteryStats.Uid.Proc> ent |
| 1861 | : processStats.entrySet()) { |
| 1862 | Uid.Proc ps = ent.getValue(); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 1863 | |
| 1864 | final long userMillis = ps.getUserTime(which) * 10; |
| 1865 | final long systemMillis = ps.getSystemTime(which) * 10; |
| 1866 | final long foregroundMillis = ps.getForegroundTime(which) * 10; |
| 1867 | final long starts = ps.getStarts(which); |
| 1868 | |
| 1869 | if (userMillis != 0 || systemMillis != 0 || foregroundMillis != 0 |
| 1870 | || starts != 0) { |
| 1871 | dumpLine(pw, uid, category, PROCESS_DATA, ent.getKey(), userMillis, |
| 1872 | systemMillis, foregroundMillis, starts); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1873 | } |
| 1874 | } |
| 1875 | } |
| 1876 | |
| 1877 | Map<String, ? extends BatteryStats.Uid.Pkg> packageStats = u.getPackageStats(); |
| 1878 | if (packageStats.size() > 0) { |
| 1879 | for (Map.Entry<String, ? extends BatteryStats.Uid.Pkg> ent |
| 1880 | : packageStats.entrySet()) { |
| 1881 | |
| 1882 | Uid.Pkg ps = ent.getValue(); |
| 1883 | int wakeups = ps.getWakeups(which); |
| 1884 | Map<String, ? extends Uid.Pkg.Serv> serviceStats = ps.getServiceStats(); |
| 1885 | for (Map.Entry<String, ? extends BatteryStats.Uid.Pkg.Serv> sent |
| 1886 | : serviceStats.entrySet()) { |
| 1887 | BatteryStats.Uid.Pkg.Serv ss = sent.getValue(); |
| 1888 | long startTime = ss.getStartTime(batteryUptime, which); |
| 1889 | int starts = ss.getStarts(which); |
| 1890 | int launches = ss.getLaunches(which); |
| 1891 | if (startTime != 0 || starts != 0 || launches != 0) { |
| 1892 | dumpLine(pw, uid, category, APK_DATA, |
| 1893 | wakeups, // wakeup alarms |
| 1894 | ent.getKey(), // Apk |
| 1895 | sent.getKey(), // service |
| 1896 | startTime / 1000, // time spent started, in ms |
| 1897 | starts, |
| 1898 | launches); |
| 1899 | } |
| 1900 | } |
| 1901 | } |
| 1902 | } |
| 1903 | } |
| 1904 | } |
| 1905 | |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 1906 | static final class TimerEntry { |
| 1907 | final String mName; |
| 1908 | final int mId; |
| 1909 | final BatteryStats.Timer mTimer; |
| 1910 | final long mTime; |
| 1911 | TimerEntry(String name, int id, BatteryStats.Timer timer, long time) { |
| 1912 | mName = name; |
| 1913 | mId = id; |
| 1914 | mTimer = timer; |
| 1915 | mTime = time; |
| 1916 | } |
| 1917 | } |
| 1918 | |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 1919 | private void printmAh(PrintWriter printer, double power) { |
| 1920 | printer.print(BatteryStatsHelper.makemAh(power)); |
| 1921 | } |
| 1922 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1923 | @SuppressWarnings("unused") |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 1924 | public final void dumpLocked(Context context, PrintWriter pw, String prefix, final int which, |
| 1925 | int reqUid) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1926 | final long rawUptime = SystemClock.uptimeMillis() * 1000; |
| 1927 | final long rawRealtime = SystemClock.elapsedRealtime() * 1000; |
| 1928 | final long batteryUptime = getBatteryUptime(rawUptime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1929 | |
| 1930 | final long whichBatteryUptime = computeBatteryUptime(rawUptime, which); |
| 1931 | final long whichBatteryRealtime = computeBatteryRealtime(rawRealtime, which); |
| 1932 | final long totalRealtime = computeRealtime(rawRealtime, which); |
| 1933 | final long totalUptime = computeUptime(rawUptime, which); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1934 | final long whichBatteryScreenOffUptime = computeBatteryScreenOffUptime(rawUptime, which); |
| 1935 | final long whichBatteryScreenOffRealtime = computeBatteryScreenOffRealtime(rawRealtime, |
| 1936 | which); |
| 1937 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1938 | StringBuilder sb = new StringBuilder(128); |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 1939 | |
| 1940 | SparseArray<? extends Uid> uidStats = getUidStats(); |
| 1941 | final int NU = uidStats.size(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1942 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 1943 | sb.setLength(0); |
| 1944 | sb.append(prefix); |
| 1945 | sb.append(" Time on battery: "); |
| 1946 | formatTimeMs(sb, whichBatteryRealtime / 1000); sb.append("("); |
| 1947 | sb.append(formatRatioLocked(whichBatteryRealtime, totalRealtime)); |
| 1948 | sb.append(") realtime, "); |
| 1949 | formatTimeMs(sb, whichBatteryUptime / 1000); |
| 1950 | sb.append("("); sb.append(formatRatioLocked(whichBatteryUptime, totalRealtime)); |
| 1951 | sb.append(") uptime"); |
| 1952 | pw.println(sb.toString()); |
| 1953 | sb.setLength(0); |
| 1954 | sb.append(prefix); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1955 | sb.append(" Time on battery screen off: "); |
| 1956 | formatTimeMs(sb, whichBatteryScreenOffRealtime / 1000); sb.append("("); |
| 1957 | sb.append(formatRatioLocked(whichBatteryScreenOffRealtime, totalRealtime)); |
| 1958 | sb.append(") realtime, "); |
| 1959 | formatTimeMs(sb, whichBatteryScreenOffUptime / 1000); |
| 1960 | sb.append("("); |
| 1961 | sb.append(formatRatioLocked(whichBatteryScreenOffUptime, totalRealtime)); |
| 1962 | sb.append(") uptime"); |
| 1963 | pw.println(sb.toString()); |
| 1964 | sb.setLength(0); |
| 1965 | sb.append(prefix); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 1966 | sb.append(" Total run time: "); |
| 1967 | formatTimeMs(sb, totalRealtime / 1000); |
| 1968 | sb.append("realtime, "); |
| 1969 | formatTimeMs(sb, totalUptime / 1000); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 1970 | sb.append("uptime"); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 1971 | pw.println(sb.toString()); |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 1972 | pw.print(" Start clock time: "); |
| 1973 | pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss", getStartClockTime()).toString()); |
| 1974 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1975 | final long screenOnTime = getScreenOnTime(rawRealtime, which); |
| 1976 | final long phoneOnTime = getPhoneOnTime(rawRealtime, which); |
| 1977 | final long wifiRunningTime = getGlobalWifiRunningTime(rawRealtime, which); |
| 1978 | final long wifiOnTime = getWifiOnTime(rawRealtime, which); |
| 1979 | final long bluetoothOnTime = getBluetoothOnTime(rawRealtime, which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1980 | sb.setLength(0); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 1981 | sb.append(prefix); |
| 1982 | sb.append(" Screen on: "); formatTimeMs(sb, screenOnTime / 1000); |
| 1983 | sb.append("("); sb.append(formatRatioLocked(screenOnTime, whichBatteryRealtime)); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 1984 | sb.append(") "); sb.append(getScreenOnCount(which)); |
| 1985 | sb.append("x, Input events: "); sb.append(getInputEventCount(which)); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 1986 | pw.println(sb.toString()); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 1987 | if (phoneOnTime != 0) { |
| 1988 | sb.setLength(0); |
| 1989 | sb.append(prefix); |
| 1990 | sb.append(" Active phone call: "); formatTimeMs(sb, phoneOnTime / 1000); |
| 1991 | sb.append("("); sb.append(formatRatioLocked(phoneOnTime, whichBatteryRealtime)); |
| 1992 | sb.append(") "); sb.append(getPhoneOnCount(which)); |
| 1993 | } |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 1994 | sb.setLength(0); |
| 1995 | sb.append(prefix); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 1996 | sb.append(" Screen brightnesses:"); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1997 | boolean didOne = false; |
| 1998 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1999 | final long time = getScreenBrightnessTime(i, rawRealtime, which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2000 | if (time == 0) { |
| 2001 | continue; |
| 2002 | } |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 2003 | sb.append("\n "); |
| 2004 | sb.append(prefix); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2005 | didOne = true; |
| 2006 | sb.append(SCREEN_BRIGHTNESS_NAMES[i]); |
| 2007 | sb.append(" "); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 2008 | formatTimeMs(sb, time/1000); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2009 | sb.append("("); |
| 2010 | sb.append(formatRatioLocked(time, screenOnTime)); |
| 2011 | sb.append(")"); |
| 2012 | } |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 2013 | if (!didOne) sb.append(" (no activity)"); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2014 | pw.println(sb.toString()); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2015 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2016 | // Calculate wakelock times across all uids. |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 2017 | long fullWakeLockTimeTotalMicros = 0; |
| 2018 | long partialWakeLockTimeTotalMicros = 0; |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 2019 | |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 2020 | final ArrayList<TimerEntry> timers = new ArrayList<TimerEntry>(); |
| 2021 | |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 2022 | for (int iu = 0; iu < NU; iu++) { |
| 2023 | Uid u = uidStats.valueAt(iu); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 2024 | |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 2025 | Map<String, ? extends BatteryStats.Uid.Wakelock> wakelocks = u.getWakelockStats(); |
| 2026 | if (wakelocks.size() > 0) { |
| 2027 | for (Map.Entry<String, ? extends BatteryStats.Uid.Wakelock> ent |
| 2028 | : wakelocks.entrySet()) { |
| 2029 | Uid.Wakelock wl = ent.getValue(); |
| 2030 | |
| 2031 | Timer fullWakeTimer = wl.getWakeTime(WAKE_TYPE_FULL); |
| 2032 | if (fullWakeTimer != null) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2033 | fullWakeLockTimeTotalMicros += fullWakeTimer.getTotalTimeLocked( |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2034 | rawRealtime, which); |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 2035 | } |
| 2036 | |
| 2037 | Timer partialWakeTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL); |
| 2038 | if (partialWakeTimer != null) { |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 2039 | long totalTimeMicros = partialWakeTimer.getTotalTimeLocked( |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2040 | rawRealtime, which); |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 2041 | if (totalTimeMicros > 0) { |
| 2042 | if (reqUid < 0) { |
| 2043 | // Only show the ordered list of all wake |
| 2044 | // locks if the caller is not asking for data |
| 2045 | // about a specific uid. |
| 2046 | timers.add(new TimerEntry(ent.getKey(), u.getUid(), |
| 2047 | partialWakeTimer, totalTimeMicros)); |
| 2048 | } |
| 2049 | partialWakeLockTimeTotalMicros += totalTimeMicros; |
| 2050 | } |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 2051 | } |
| 2052 | } |
| 2053 | } |
| 2054 | } |
| 2055 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2056 | long mobileRxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which); |
| 2057 | long mobileTxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which); |
| 2058 | long wifiRxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which); |
| 2059 | long wifiTxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which); |
| 2060 | long mobileRxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which); |
| 2061 | long mobileTxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which); |
| 2062 | long wifiRxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which); |
| 2063 | long wifiTxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which); |
| 2064 | |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 2065 | if (fullWakeLockTimeTotalMicros != 0) { |
| 2066 | sb.setLength(0); |
| 2067 | sb.append(prefix); |
| 2068 | sb.append(" Total full wakelock time: "); formatTimeMsNoSpace(sb, |
| 2069 | (fullWakeLockTimeTotalMicros + 500) / 1000); |
| 2070 | pw.println(sb.toString()); |
| 2071 | } |
| 2072 | |
| 2073 | if (partialWakeLockTimeTotalMicros != 0) { |
| 2074 | sb.setLength(0); |
| 2075 | sb.append(prefix); |
| 2076 | sb.append(" Total partial wakelock time: "); formatTimeMsNoSpace(sb, |
| 2077 | (partialWakeLockTimeTotalMicros + 500) / 1000); |
| 2078 | pw.println(sb.toString()); |
| 2079 | } |
| 2080 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 2081 | pw.print(prefix); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2082 | pw.print(" Mobile total received: "); pw.print(formatBytesLocked(mobileRxTotalBytes)); |
| 2083 | pw.print(", sent: "); pw.print(formatBytesLocked(mobileTxTotalBytes)); |
| 2084 | pw.print(" (packets received "); pw.print(mobileRxTotalPackets); |
| 2085 | pw.print(", sent "); pw.print(mobileTxTotalPackets); pw.println(")"); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 2086 | sb.setLength(0); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 2087 | sb.append(prefix); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2088 | sb.append(" Signal levels:"); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2089 | didOne = false; |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 2090 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2091 | final long time = getPhoneSignalStrengthTime(i, rawRealtime, which); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 2092 | if (time == 0) { |
| 2093 | continue; |
| 2094 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2095 | sb.append("\n "); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 2096 | sb.append(prefix); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 2097 | didOne = true; |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 2098 | sb.append(SignalStrength.SIGNAL_STRENGTH_NAMES[i]); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 2099 | sb.append(" "); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 2100 | formatTimeMs(sb, time/1000); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 2101 | sb.append("("); |
| 2102 | sb.append(formatRatioLocked(time, whichBatteryRealtime)); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2103 | sb.append(") "); |
| 2104 | sb.append(getPhoneSignalStrengthCount(i, which)); |
| 2105 | sb.append("x"); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 2106 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2107 | if (!didOne) sb.append(" (no activity)"); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 2108 | pw.println(sb.toString()); |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 2109 | |
| 2110 | sb.setLength(0); |
| 2111 | sb.append(prefix); |
| 2112 | sb.append(" Signal scanning time: "); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2113 | formatTimeMsNoSpace(sb, getPhoneSignalScanningTime(rawRealtime, which) / 1000); |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 2114 | pw.println(sb.toString()); |
| 2115 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 2116 | sb.setLength(0); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 2117 | sb.append(prefix); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2118 | sb.append(" Radio types:"); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 2119 | didOne = false; |
| 2120 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2121 | final long time = getPhoneDataConnectionTime(i, rawRealtime, which); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 2122 | if (time == 0) { |
| 2123 | continue; |
| 2124 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2125 | sb.append("\n "); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 2126 | sb.append(prefix); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 2127 | didOne = true; |
| 2128 | sb.append(DATA_CONNECTION_NAMES[i]); |
| 2129 | sb.append(" "); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 2130 | formatTimeMs(sb, time/1000); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 2131 | sb.append("("); |
| 2132 | sb.append(formatRatioLocked(time, whichBatteryRealtime)); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2133 | sb.append(") "); |
| 2134 | sb.append(getPhoneDataConnectionCount(i, which)); |
| 2135 | sb.append("x"); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 2136 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2137 | if (!didOne) sb.append(" (no activity)"); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 2138 | pw.println(sb.toString()); |
Amith Yamasani | 3f7e35c | 2009-07-13 16:02:45 -0700 | [diff] [blame] | 2139 | |
| 2140 | sb.setLength(0); |
| 2141 | sb.append(prefix); |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 2142 | sb.append(" Mobile radio active time: "); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2143 | final long mobileActiveTime = getMobileRadioActiveTime(rawRealtime, which); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 2144 | formatTimeMs(sb, mobileActiveTime / 1000); |
| 2145 | sb.append("("); sb.append(formatRatioLocked(mobileActiveTime, whichBatteryRealtime)); |
| 2146 | sb.append(") "); sb.append(getMobileRadioActiveCount(which)); |
| 2147 | sb.append("x"); |
Amith Yamasani | 3f7e35c | 2009-07-13 16:02:45 -0700 | [diff] [blame] | 2148 | pw.println(sb.toString()); |
| 2149 | |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 2150 | final long mobileActiveUnknownTime = getMobileRadioActiveUnknownTime(which); |
| 2151 | if (mobileActiveUnknownTime != 0) { |
| 2152 | sb.setLength(0); |
| 2153 | sb.append(prefix); |
| 2154 | sb.append(" Mobile radio active unknown time: "); |
| 2155 | formatTimeMs(sb, mobileActiveUnknownTime / 1000); |
| 2156 | sb.append("("); |
| 2157 | sb.append(formatRatioLocked(mobileActiveUnknownTime, whichBatteryRealtime)); |
| 2158 | sb.append(") "); sb.append(getMobileRadioActiveUnknownCount(which)); |
| 2159 | sb.append("x"); |
| 2160 | pw.println(sb.toString()); |
| 2161 | } |
| 2162 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame^] | 2163 | final long mobileActiveAdjustedTime = getMobileRadioActiveAdjustedTime(which); |
| 2164 | if (mobileActiveAdjustedTime != 0) { |
| 2165 | sb.setLength(0); |
| 2166 | sb.append(prefix); |
| 2167 | sb.append(" Mobile radio active adjusted time: "); |
| 2168 | formatTimeMs(sb, mobileActiveAdjustedTime / 1000); |
| 2169 | sb.append("("); |
| 2170 | sb.append(formatRatioLocked(mobileActiveAdjustedTime, whichBatteryRealtime)); |
| 2171 | sb.append(")"); |
| 2172 | pw.println(sb.toString()); |
| 2173 | } |
| 2174 | |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 2175 | pw.print(prefix); |
| 2176 | pw.print(" Wi-Fi total received: "); pw.print(formatBytesLocked(wifiRxTotalBytes)); |
| 2177 | pw.print(", sent: "); pw.print(formatBytesLocked(wifiTxTotalBytes)); |
| 2178 | pw.print(" (packets received "); pw.print(wifiRxTotalPackets); |
| 2179 | pw.print(", sent "); pw.print(wifiTxTotalPackets); pw.println(")"); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 2180 | sb.setLength(0); |
| 2181 | sb.append(prefix); |
| 2182 | sb.append(" Wifi on: "); formatTimeMs(sb, wifiOnTime / 1000); |
| 2183 | sb.append("("); sb.append(formatRatioLocked(wifiOnTime, whichBatteryRealtime)); |
| 2184 | sb.append("), Wifi running: "); formatTimeMs(sb, wifiRunningTime / 1000); |
| 2185 | sb.append("("); sb.append(formatRatioLocked(wifiRunningTime, whichBatteryRealtime)); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 2186 | sb.append(")"); |
| 2187 | pw.println(sb.toString()); |
| 2188 | |
| 2189 | sb.setLength(0); |
| 2190 | sb.append(prefix); |
| 2191 | sb.append(" Wifi states:"); |
| 2192 | didOne = false; |
| 2193 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2194 | final long time = getWifiStateTime(i, rawRealtime, which); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 2195 | if (time == 0) { |
| 2196 | continue; |
| 2197 | } |
| 2198 | sb.append("\n "); |
| 2199 | didOne = true; |
| 2200 | sb.append(WIFI_STATE_NAMES[i]); |
| 2201 | sb.append(" "); |
| 2202 | formatTimeMs(sb, time/1000); |
| 2203 | sb.append("("); |
| 2204 | sb.append(formatRatioLocked(time, whichBatteryRealtime)); |
| 2205 | sb.append(") "); |
| 2206 | sb.append(getPhoneDataConnectionCount(i, which)); |
| 2207 | sb.append("x"); |
| 2208 | } |
| 2209 | if (!didOne) sb.append(" (no activity)"); |
| 2210 | pw.println(sb.toString()); |
| 2211 | |
| 2212 | sb.setLength(0); |
| 2213 | sb.append(prefix); |
| 2214 | sb.append(" Bluetooth on: "); formatTimeMs(sb, bluetoothOnTime / 1000); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 2215 | sb.append("("); sb.append(formatRatioLocked(bluetoothOnTime, whichBatteryRealtime)); |
| 2216 | sb.append(")"); |
| 2217 | pw.println(sb.toString()); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 2218 | |
| 2219 | sb.setLength(0); |
| 2220 | sb.append(prefix); |
| 2221 | sb.append(" Bluetooth states:"); |
| 2222 | didOne = false; |
| 2223 | for (int i=0; i<NUM_BLUETOOTH_STATES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2224 | final long time = getBluetoothStateTime(i, rawRealtime, which); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 2225 | if (time == 0) { |
| 2226 | continue; |
| 2227 | } |
| 2228 | sb.append("\n "); |
| 2229 | didOne = true; |
| 2230 | sb.append(BLUETOOTH_STATE_NAMES[i]); |
| 2231 | sb.append(" "); |
| 2232 | formatTimeMs(sb, time/1000); |
| 2233 | sb.append("("); |
| 2234 | sb.append(formatRatioLocked(time, whichBatteryRealtime)); |
| 2235 | sb.append(") "); |
| 2236 | sb.append(getPhoneDataConnectionCount(i, which)); |
| 2237 | sb.append("x"); |
| 2238 | } |
| 2239 | if (!didOne) sb.append(" (no activity)"); |
| 2240 | pw.println(sb.toString()); |
| 2241 | |
| 2242 | pw.println(); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2243 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2244 | if (which == STATS_SINCE_UNPLUGGED) { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2245 | if (getIsOnBattery()) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 2246 | pw.print(prefix); pw.println(" Device is currently unplugged"); |
| 2247 | pw.print(prefix); pw.print(" Discharge cycle start level: "); |
| 2248 | pw.println(getDischargeStartLevel()); |
| 2249 | pw.print(prefix); pw.print(" Discharge cycle current level: "); |
| 2250 | pw.println(getDischargeCurrentLevel()); |
Dianne Hackborn | 99d0452 | 2010-08-20 13:43:00 -0700 | [diff] [blame] | 2251 | } else { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 2252 | pw.print(prefix); pw.println(" Device is currently plugged into power"); |
| 2253 | pw.print(prefix); pw.print(" Last discharge cycle start level: "); |
| 2254 | pw.println(getDischargeStartLevel()); |
| 2255 | pw.print(prefix); pw.print(" Last discharge cycle end level: "); |
| 2256 | pw.println(getDischargeCurrentLevel()); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2257 | } |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 2258 | pw.print(prefix); pw.print(" Amount discharged while screen on: "); |
| 2259 | pw.println(getDischargeAmountScreenOn()); |
| 2260 | pw.print(prefix); pw.print(" Amount discharged while screen off: "); |
| 2261 | pw.println(getDischargeAmountScreenOff()); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2262 | pw.println(" "); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2263 | } else { |
| 2264 | pw.print(prefix); pw.println(" Device battery use since last full charge"); |
| 2265 | pw.print(prefix); pw.print(" Amount discharged (lower bound): "); |
| 2266 | pw.println(getLowDischargeAmountSinceCharge()); |
| 2267 | pw.print(prefix); pw.print(" Amount discharged (upper bound): "); |
| 2268 | pw.println(getHighDischargeAmountSinceCharge()); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 2269 | pw.print(prefix); pw.print(" Amount discharged while screen on: "); |
| 2270 | pw.println(getDischargeAmountScreenOnSinceCharge()); |
| 2271 | pw.print(prefix); pw.print(" Amount discharged while screen off: "); |
| 2272 | pw.println(getDischargeAmountScreenOffSinceCharge()); |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 2273 | pw.println(); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2274 | } |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 2275 | |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 2276 | BatteryStatsHelper helper = new BatteryStatsHelper(context); |
| 2277 | helper.create(this); |
| 2278 | helper.refreshStats(which, UserHandle.USER_ALL); |
| 2279 | List<BatterySipper> sippers = helper.getUsageList(); |
| 2280 | if (sippers != null && sippers.size() > 0) { |
| 2281 | pw.print(prefix); pw.println(" Estimated power use (mAh):"); |
| 2282 | pw.print(prefix); pw.print(" Capacity: "); |
| 2283 | printmAh(pw, helper.getPowerProfile().getBatteryCapacity()); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 2284 | pw.print(", Computed drain: "); printmAh(pw, helper.getComputedPower()); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 2285 | pw.print(", Min drain: "); printmAh(pw, helper.getMinDrainedPower()); |
| 2286 | pw.print(", Max drain: "); printmAh(pw, helper.getMaxDrainedPower()); |
| 2287 | pw.println(); |
| 2288 | for (int i=0; i<sippers.size(); i++) { |
| 2289 | BatterySipper bs = sippers.get(i); |
| 2290 | switch (bs.drainType) { |
| 2291 | case IDLE: |
| 2292 | pw.print(prefix); pw.print(" Idle: "); printmAh(pw, bs.value); |
| 2293 | pw.println(); |
| 2294 | break; |
| 2295 | case CELL: |
| 2296 | pw.print(prefix); pw.print(" Cell standby: "); printmAh(pw, bs.value); |
| 2297 | pw.println(); |
| 2298 | break; |
| 2299 | case PHONE: |
| 2300 | pw.print(prefix); pw.print(" Phone calls: "); printmAh(pw, bs.value); |
| 2301 | pw.println(); |
| 2302 | break; |
| 2303 | case WIFI: |
| 2304 | pw.print(prefix); pw.print(" Wifi: "); printmAh(pw, bs.value); |
| 2305 | pw.println(); |
| 2306 | break; |
| 2307 | case BLUETOOTH: |
| 2308 | pw.print(prefix); pw.print(" Bluetooth: "); printmAh(pw, bs.value); |
| 2309 | pw.println(); |
| 2310 | break; |
| 2311 | case SCREEN: |
| 2312 | pw.print(prefix); pw.print(" Screen: "); printmAh(pw, bs.value); |
| 2313 | pw.println(); |
| 2314 | break; |
| 2315 | case APP: |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 2316 | pw.print(prefix); pw.print(" Uid "); |
| 2317 | UserHandle.formatUid(pw, bs.uidObj.getUid()); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 2318 | pw.print(": "); printmAh(pw, bs.value); pw.println(); |
| 2319 | break; |
| 2320 | case USER: |
| 2321 | pw.print(prefix); pw.print(" User "); pw.print(bs.userId); |
| 2322 | pw.print(": "); printmAh(pw, bs.value); pw.println(); |
| 2323 | break; |
| 2324 | case UNACCOUNTED: |
| 2325 | pw.print(prefix); pw.print(" Unaccounted: "); printmAh(pw, bs.value); |
| 2326 | pw.println(); |
| 2327 | break; |
| 2328 | case OVERCOUNTED: |
| 2329 | pw.print(prefix); pw.print(" Over-counted: "); printmAh(pw, bs.value); |
| 2330 | pw.println(); |
| 2331 | break; |
| 2332 | } |
| 2333 | } |
Dianne Hackborn | c46809e | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 2334 | pw.println(); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 2335 | } |
| 2336 | |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 2337 | sippers = helper.getMobilemsppList(); |
| 2338 | if (sippers != null && sippers.size() > 0) { |
| 2339 | pw.print(prefix); pw.println(" Per-app mobile ms per packet:"); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 2340 | long totalTime = 0; |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 2341 | for (int i=0; i<sippers.size(); i++) { |
| 2342 | BatterySipper bs = sippers.get(i); |
| 2343 | sb.setLength(0); |
| 2344 | sb.append(prefix); sb.append(" Uid "); |
| 2345 | UserHandle.formatUid(sb, bs.uidObj.getUid()); |
| 2346 | sb.append(": "); sb.append(BatteryStatsHelper.makemAh(bs.mobilemspp)); |
| 2347 | sb.append(" ("); sb.append(bs.mobileRxPackets+bs.mobileTxPackets); |
| 2348 | sb.append(" packets over "); formatTimeMsNoSpace(sb, bs.mobileActive); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 2349 | sb.append(") "); sb.append(bs.mobileActiveCount); sb.append("x"); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 2350 | pw.println(sb.toString()); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 2351 | totalTime += bs.mobileActive; |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 2352 | } |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 2353 | sb.setLength(0); |
| 2354 | sb.append(prefix); |
| 2355 | sb.append(" TOTAL TIME: "); |
| 2356 | formatTimeMs(sb, totalTime); |
| 2357 | sb.append("("); sb.append(formatRatioLocked(totalTime, whichBatteryRealtime)); |
| 2358 | sb.append(")"); |
| 2359 | pw.println(sb.toString()); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 2360 | pw.println(); |
| 2361 | } |
| 2362 | |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 2363 | final Comparator<TimerEntry> timerComparator = new Comparator<TimerEntry>() { |
| 2364 | @Override |
| 2365 | public int compare(TimerEntry lhs, TimerEntry rhs) { |
| 2366 | long lhsTime = lhs.mTime; |
| 2367 | long rhsTime = rhs.mTime; |
| 2368 | if (lhsTime < rhsTime) { |
| 2369 | return 1; |
| 2370 | } |
| 2371 | if (lhsTime > rhsTime) { |
| 2372 | return -1; |
| 2373 | } |
| 2374 | return 0; |
| 2375 | } |
| 2376 | }; |
| 2377 | |
| 2378 | if (reqUid < 0) { |
| 2379 | Map<String, ? extends BatteryStats.Timer> kernelWakelocks = getKernelWakelockStats(); |
| 2380 | if (kernelWakelocks.size() > 0) { |
| 2381 | final ArrayList<TimerEntry> ktimers = new ArrayList<TimerEntry>(); |
| 2382 | for (Map.Entry<String, ? extends BatteryStats.Timer> ent : kernelWakelocks.entrySet()) { |
| 2383 | BatteryStats.Timer timer = ent.getValue(); |
| 2384 | long totalTimeMillis = computeWakeLock(timer, rawRealtime, which); |
| 2385 | if (totalTimeMillis > 0) { |
| 2386 | ktimers.add(new TimerEntry(ent.getKey(), 0, timer, totalTimeMillis)); |
| 2387 | } |
| 2388 | } |
| 2389 | if (ktimers.size() > 0) { |
| 2390 | Collections.sort(ktimers, timerComparator); |
| 2391 | pw.print(prefix); pw.println(" All kernel wake locks:"); |
| 2392 | for (int i=0; i<ktimers.size(); i++) { |
| 2393 | TimerEntry timer = ktimers.get(i); |
| 2394 | String linePrefix = ": "; |
| 2395 | sb.setLength(0); |
| 2396 | sb.append(prefix); |
| 2397 | sb.append(" Kernel Wake lock "); |
| 2398 | sb.append(timer.mName); |
| 2399 | linePrefix = printWakeLock(sb, timer.mTimer, rawRealtime, null, |
| 2400 | which, linePrefix); |
| 2401 | if (!linePrefix.equals(": ")) { |
| 2402 | sb.append(" realtime"); |
| 2403 | // Only print out wake locks that were held |
| 2404 | pw.println(sb.toString()); |
| 2405 | } |
| 2406 | } |
| 2407 | pw.println(); |
| 2408 | } |
| 2409 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 2410 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame^] | 2411 | if (timers.size() > 0) { |
| 2412 | Collections.sort(timers, timerComparator); |
| 2413 | pw.print(prefix); pw.println(" All partial wake locks:"); |
| 2414 | for (int i=0; i<timers.size(); i++) { |
| 2415 | TimerEntry timer = timers.get(i); |
| 2416 | sb.setLength(0); |
| 2417 | sb.append(" Wake lock "); |
| 2418 | UserHandle.formatUid(sb, timer.mId); |
| 2419 | sb.append(" "); |
| 2420 | sb.append(timer.mName); |
| 2421 | printWakeLock(sb, timer.mTimer, rawRealtime, null, which, ": "); |
| 2422 | sb.append(" realtime"); |
| 2423 | pw.println(sb.toString()); |
| 2424 | } |
| 2425 | timers.clear(); |
| 2426 | pw.println(); |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 2427 | } |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame^] | 2428 | |
| 2429 | Map<String, ? extends LongCounter> wakeupReasons = getWakeupReasonStats(); |
| 2430 | if (wakeupReasons.size() > 0) { |
| 2431 | pw.print(prefix); pw.println(" All wakeup reasons:"); |
| 2432 | final ArrayList<TimerEntry> reasons = new ArrayList<TimerEntry>(); |
| 2433 | for (Map.Entry<String, ? extends LongCounter> ent : wakeupReasons.entrySet()) { |
| 2434 | BatteryStats.LongCounter counter = ent.getValue(); |
| 2435 | reasons.add(new TimerEntry(ent.getKey(), 0, null, |
| 2436 | ent.getValue().getCountLocked(which))); |
| 2437 | } |
| 2438 | Collections.sort(reasons, timerComparator); |
| 2439 | for (int i=0; i<reasons.size(); i++) { |
| 2440 | TimerEntry timer = reasons.get(i); |
| 2441 | String linePrefix = ": "; |
| 2442 | sb.setLength(0); |
| 2443 | sb.append(prefix); |
| 2444 | sb.append(" Wakeup reason "); |
| 2445 | sb.append(timer.mName); |
| 2446 | sb.append(": "); |
| 2447 | formatTimeMs(sb, timer.mTime); |
| 2448 | sb.append("realtime"); |
| 2449 | pw.println(sb.toString()); |
| 2450 | } |
| 2451 | pw.println(); |
| 2452 | } |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 2453 | } |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 2454 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2455 | for (int iu=0; iu<NU; iu++) { |
| 2456 | final int uid = uidStats.keyAt(iu); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 2457 | if (reqUid >= 0 && uid != reqUid && uid != Process.SYSTEM_UID) { |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 2458 | continue; |
| 2459 | } |
| 2460 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2461 | Uid u = uidStats.valueAt(iu); |
Dianne Hackborn | a4cc205 | 2013-07-08 17:31:25 -0700 | [diff] [blame] | 2462 | |
| 2463 | pw.print(prefix); |
| 2464 | pw.print(" "); |
| 2465 | UserHandle.formatUid(pw, uid); |
| 2466 | pw.println(":"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2467 | boolean uidActivity = false; |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 2468 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2469 | long mobileRxBytes = u.getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which); |
| 2470 | long mobileTxBytes = u.getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which); |
| 2471 | long wifiRxBytes = u.getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which); |
| 2472 | long wifiTxBytes = u.getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which); |
| 2473 | long mobileRxPackets = u.getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which); |
| 2474 | long mobileTxPackets = u.getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 2475 | long uidMobileActiveTime = u.getMobileRadioActiveTime(which); |
| 2476 | int uidMobileActiveCount = u.getMobileRadioActiveCount(which); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2477 | long wifiRxPackets = u.getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which); |
| 2478 | long wifiTxPackets = u.getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2479 | long fullWifiLockOnTime = u.getFullWifiLockTime(rawRealtime, which); |
| 2480 | long wifiScanTime = u.getWifiScanTime(rawRealtime, which); |
| 2481 | long uidWifiRunningTime = u.getWifiRunningTime(rawRealtime, which); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 2482 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2483 | if (mobileRxBytes > 0 || mobileTxBytes > 0 |
| 2484 | || mobileRxPackets > 0 || mobileTxPackets > 0) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 2485 | pw.print(prefix); pw.print(" Mobile network: "); |
| 2486 | pw.print(formatBytesLocked(mobileRxBytes)); pw.print(" received, "); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2487 | pw.print(formatBytesLocked(mobileTxBytes)); |
| 2488 | pw.print(" sent (packets "); pw.print(mobileRxPackets); |
| 2489 | pw.print(" received, "); pw.print(mobileTxPackets); pw.println(" sent)"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2490 | } |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 2491 | if (uidMobileActiveTime > 0 || uidMobileActiveCount > 0) { |
| 2492 | sb.setLength(0); |
| 2493 | sb.append(prefix); sb.append(" Mobile radio active: "); |
| 2494 | formatTimeMs(sb, uidMobileActiveTime / 1000); |
| 2495 | sb.append("("); |
| 2496 | sb.append(formatRatioLocked(uidMobileActiveTime, mobileActiveTime)); |
| 2497 | sb.append(") "); sb.append(uidMobileActiveCount); sb.append("x"); |
| 2498 | long packets = mobileRxPackets + mobileTxPackets; |
| 2499 | if (packets == 0) { |
| 2500 | packets = 1; |
| 2501 | } |
| 2502 | sb.append(" @ "); |
| 2503 | sb.append(BatteryStatsHelper.makemAh(uidMobileActiveTime / 1000 / (double)packets)); |
| 2504 | sb.append(" mspp"); |
| 2505 | pw.println(sb.toString()); |
| 2506 | } |
| 2507 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2508 | if (wifiRxBytes > 0 || wifiTxBytes > 0 || wifiRxPackets > 0 || wifiTxPackets > 0) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 2509 | pw.print(prefix); pw.print(" Wi-Fi network: "); |
| 2510 | pw.print(formatBytesLocked(wifiRxBytes)); pw.print(" received, "); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2511 | pw.print(formatBytesLocked(wifiTxBytes)); |
| 2512 | pw.print(" sent (packets "); pw.print(wifiRxPackets); |
| 2513 | pw.print(" received, "); pw.print(wifiTxPackets); pw.println(" sent)"); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 2514 | } |
| 2515 | |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 2516 | if (fullWifiLockOnTime != 0 || wifiScanTime != 0 |
| 2517 | || uidWifiRunningTime != 0) { |
| 2518 | sb.setLength(0); |
| 2519 | sb.append(prefix); sb.append(" Wifi Running: "); |
| 2520 | formatTimeMs(sb, uidWifiRunningTime / 1000); |
| 2521 | sb.append("("); sb.append(formatRatioLocked(uidWifiRunningTime, |
| 2522 | whichBatteryRealtime)); sb.append(")\n"); |
| 2523 | sb.append(prefix); sb.append(" Full Wifi Lock: "); |
| 2524 | formatTimeMs(sb, fullWifiLockOnTime / 1000); |
| 2525 | sb.append("("); sb.append(formatRatioLocked(fullWifiLockOnTime, |
| 2526 | whichBatteryRealtime)); sb.append(")\n"); |
| 2527 | sb.append(prefix); sb.append(" Wifi Scan: "); |
| 2528 | formatTimeMs(sb, wifiScanTime / 1000); |
| 2529 | sb.append("("); sb.append(formatRatioLocked(wifiScanTime, |
| 2530 | whichBatteryRealtime)); sb.append(")"); |
| 2531 | pw.println(sb.toString()); |
| 2532 | } |
| 2533 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2534 | if (u.hasUserActivity()) { |
| 2535 | boolean hasData = false; |
Raph Levien | 4c7a4a7 | 2012-08-03 14:32:39 -0700 | [diff] [blame] | 2536 | for (int i=0; i<Uid.NUM_USER_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2537 | int val = u.getUserActivityCount(i, which); |
| 2538 | if (val != 0) { |
| 2539 | if (!hasData) { |
| 2540 | sb.setLength(0); |
| 2541 | sb.append(" User activity: "); |
| 2542 | hasData = true; |
| 2543 | } else { |
| 2544 | sb.append(", "); |
| 2545 | } |
| 2546 | sb.append(val); |
| 2547 | sb.append(" "); |
| 2548 | sb.append(Uid.USER_ACTIVITY_TYPES[i]); |
| 2549 | } |
| 2550 | } |
| 2551 | if (hasData) { |
| 2552 | pw.println(sb.toString()); |
| 2553 | } |
| 2554 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2555 | |
| 2556 | Map<String, ? extends BatteryStats.Uid.Wakelock> wakelocks = u.getWakelockStats(); |
| 2557 | if (wakelocks.size() > 0) { |
Dianne Hackborn | c24ab86 | 2011-10-18 15:55:03 -0700 | [diff] [blame] | 2558 | long totalFull = 0, totalPartial = 0, totalWindow = 0; |
| 2559 | int count = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2560 | for (Map.Entry<String, ? extends BatteryStats.Uid.Wakelock> ent |
| 2561 | : wakelocks.entrySet()) { |
| 2562 | Uid.Wakelock wl = ent.getValue(); |
| 2563 | String linePrefix = ": "; |
| 2564 | sb.setLength(0); |
| 2565 | sb.append(prefix); |
| 2566 | sb.append(" Wake lock "); |
| 2567 | sb.append(ent.getKey()); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2568 | linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_FULL), rawRealtime, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2569 | "full", which, linePrefix); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2570 | linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_PARTIAL), rawRealtime, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2571 | "partial", which, linePrefix); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2572 | linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_WINDOW), rawRealtime, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2573 | "window", which, linePrefix); |
| 2574 | if (!linePrefix.equals(": ")) { |
| 2575 | sb.append(" realtime"); |
Jason Parks | 94b916d | 2010-07-20 12:39:07 -0500 | [diff] [blame] | 2576 | // Only print out wake locks that were held |
| 2577 | pw.println(sb.toString()); |
| 2578 | uidActivity = true; |
Dianne Hackborn | c24ab86 | 2011-10-18 15:55:03 -0700 | [diff] [blame] | 2579 | count++; |
| 2580 | } |
| 2581 | totalFull += computeWakeLock(wl.getWakeTime(WAKE_TYPE_FULL), |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2582 | rawRealtime, which); |
Dianne Hackborn | c24ab86 | 2011-10-18 15:55:03 -0700 | [diff] [blame] | 2583 | totalPartial += computeWakeLock(wl.getWakeTime(WAKE_TYPE_PARTIAL), |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2584 | rawRealtime, which); |
Dianne Hackborn | c24ab86 | 2011-10-18 15:55:03 -0700 | [diff] [blame] | 2585 | totalWindow += computeWakeLock(wl.getWakeTime(WAKE_TYPE_WINDOW), |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2586 | rawRealtime, which); |
Dianne Hackborn | c24ab86 | 2011-10-18 15:55:03 -0700 | [diff] [blame] | 2587 | } |
| 2588 | if (count > 1) { |
| 2589 | if (totalFull != 0 || totalPartial != 0 || totalWindow != 0) { |
| 2590 | sb.setLength(0); |
| 2591 | sb.append(prefix); |
| 2592 | sb.append(" TOTAL wake: "); |
| 2593 | boolean needComma = false; |
| 2594 | if (totalFull != 0) { |
| 2595 | needComma = true; |
| 2596 | formatTimeMs(sb, totalFull); |
| 2597 | sb.append("full"); |
| 2598 | } |
| 2599 | if (totalPartial != 0) { |
| 2600 | if (needComma) { |
| 2601 | sb.append(", "); |
| 2602 | } |
| 2603 | needComma = true; |
| 2604 | formatTimeMs(sb, totalPartial); |
| 2605 | sb.append("partial"); |
| 2606 | } |
| 2607 | if (totalWindow != 0) { |
| 2608 | if (needComma) { |
| 2609 | sb.append(", "); |
| 2610 | } |
| 2611 | needComma = true; |
| 2612 | formatTimeMs(sb, totalWindow); |
| 2613 | sb.append("window"); |
| 2614 | } |
| 2615 | sb.append(" realtime"); |
| 2616 | pw.println(sb.toString()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2617 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2618 | } |
| 2619 | } |
| 2620 | |
| 2621 | Map<Integer, ? extends BatteryStats.Uid.Sensor> sensors = u.getSensorStats(); |
| 2622 | if (sensors.size() > 0) { |
| 2623 | for (Map.Entry<Integer, ? extends BatteryStats.Uid.Sensor> ent |
| 2624 | : sensors.entrySet()) { |
| 2625 | Uid.Sensor se = ent.getValue(); |
| 2626 | int sensorNumber = ent.getKey(); |
| 2627 | sb.setLength(0); |
| 2628 | sb.append(prefix); |
| 2629 | sb.append(" Sensor "); |
| 2630 | int handle = se.getHandle(); |
| 2631 | if (handle == Uid.Sensor.GPS) { |
| 2632 | sb.append("GPS"); |
| 2633 | } else { |
| 2634 | sb.append(handle); |
| 2635 | } |
| 2636 | sb.append(": "); |
| 2637 | |
| 2638 | Timer timer = se.getSensorTime(); |
| 2639 | if (timer != null) { |
| 2640 | // Convert from microseconds to milliseconds with rounding |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2641 | long totalTime = (timer.getTotalTimeLocked( |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2642 | rawRealtime, which) + 500) / 1000; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2643 | int count = timer.getCountLocked(which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2644 | //timer.logState(); |
| 2645 | if (totalTime != 0) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 2646 | formatTimeMs(sb, totalTime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2647 | sb.append("realtime ("); |
| 2648 | sb.append(count); |
| 2649 | sb.append(" times)"); |
| 2650 | } else { |
| 2651 | sb.append("(not used)"); |
| 2652 | } |
| 2653 | } else { |
| 2654 | sb.append("(not used)"); |
| 2655 | } |
| 2656 | |
| 2657 | pw.println(sb.toString()); |
| 2658 | uidActivity = true; |
| 2659 | } |
| 2660 | } |
| 2661 | |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 2662 | Timer vibTimer = u.getVibratorOnTimer(); |
| 2663 | if (vibTimer != null) { |
| 2664 | // Convert from microseconds to milliseconds with rounding |
| 2665 | long totalTime = (vibTimer.getTotalTimeLocked( |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2666 | rawRealtime, which) + 500) / 1000; |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 2667 | int count = vibTimer.getCountLocked(which); |
| 2668 | //timer.logState(); |
| 2669 | if (totalTime != 0) { |
| 2670 | sb.setLength(0); |
| 2671 | sb.append(prefix); |
| 2672 | sb.append(" Vibrator: "); |
| 2673 | formatTimeMs(sb, totalTime); |
| 2674 | sb.append("realtime ("); |
| 2675 | sb.append(count); |
| 2676 | sb.append(" times)"); |
| 2677 | pw.println(sb.toString()); |
| 2678 | uidActivity = true; |
| 2679 | } |
| 2680 | } |
| 2681 | |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 2682 | Timer fgTimer = u.getForegroundActivityTimer(); |
| 2683 | if (fgTimer != null) { |
| 2684 | // Convert from microseconds to milliseconds with rounding |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2685 | long totalTime = (fgTimer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000; |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 2686 | int count = fgTimer.getCountLocked(which); |
| 2687 | if (totalTime != 0) { |
| 2688 | sb.setLength(0); |
| 2689 | sb.append(prefix); |
| 2690 | sb.append(" Foreground activities: "); |
| 2691 | formatTimeMs(sb, totalTime); |
| 2692 | sb.append("realtime ("); |
| 2693 | sb.append(count); |
| 2694 | sb.append(" times)"); |
| 2695 | pw.println(sb.toString()); |
| 2696 | uidActivity = true; |
| 2697 | } |
| 2698 | } |
| 2699 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2700 | Map<String, ? extends BatteryStats.Uid.Proc> processStats = u.getProcessStats(); |
| 2701 | if (processStats.size() > 0) { |
| 2702 | for (Map.Entry<String, ? extends BatteryStats.Uid.Proc> ent |
| 2703 | : processStats.entrySet()) { |
| 2704 | Uid.Proc ps = ent.getValue(); |
| 2705 | long userTime; |
| 2706 | long systemTime; |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 2707 | long foregroundTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2708 | int starts; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2709 | int numExcessive; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2710 | |
| 2711 | userTime = ps.getUserTime(which); |
| 2712 | systemTime = ps.getSystemTime(which); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 2713 | foregroundTime = ps.getForegroundTime(which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2714 | starts = ps.getStarts(which); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2715 | numExcessive = which == STATS_SINCE_CHARGED |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 2716 | ? ps.countExcessivePowers() : 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2717 | |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 2718 | if (userTime != 0 || systemTime != 0 || foregroundTime != 0 || starts != 0 |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2719 | || numExcessive != 0) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 2720 | sb.setLength(0); |
| 2721 | sb.append(prefix); sb.append(" Proc "); |
| 2722 | sb.append(ent.getKey()); sb.append(":\n"); |
| 2723 | sb.append(prefix); sb.append(" CPU: "); |
| 2724 | formatTime(sb, userTime); sb.append("usr + "); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 2725 | formatTime(sb, systemTime); sb.append("krn ; "); |
| 2726 | formatTime(sb, foregroundTime); sb.append("fg"); |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 2727 | if (starts != 0) { |
Dianne Hackborn | b8071d79 | 2010-09-09 16:45:15 -0700 | [diff] [blame] | 2728 | sb.append("\n"); sb.append(prefix); sb.append(" "); |
| 2729 | sb.append(starts); sb.append(" proc starts"); |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 2730 | } |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 2731 | pw.println(sb.toString()); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2732 | for (int e=0; e<numExcessive; e++) { |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 2733 | Uid.Proc.ExcessivePower ew = ps.getExcessivePower(e); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2734 | if (ew != null) { |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 2735 | pw.print(prefix); pw.print(" * Killed for "); |
| 2736 | if (ew.type == Uid.Proc.ExcessivePower.TYPE_WAKE) { |
| 2737 | pw.print("wake lock"); |
| 2738 | } else if (ew.type == Uid.Proc.ExcessivePower.TYPE_CPU) { |
| 2739 | pw.print("cpu"); |
| 2740 | } else { |
| 2741 | pw.print("unknown"); |
| 2742 | } |
| 2743 | pw.print(" use: "); |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 2744 | TimeUtils.formatDuration(ew.usedTime, pw); |
| 2745 | pw.print(" over "); |
| 2746 | TimeUtils.formatDuration(ew.overTime, pw); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 2747 | if (ew.overTime != 0) { |
| 2748 | pw.print(" ("); |
| 2749 | pw.print((ew.usedTime*100)/ew.overTime); |
| 2750 | pw.println("%)"); |
| 2751 | } |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2752 | } |
| 2753 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2754 | uidActivity = true; |
| 2755 | } |
| 2756 | } |
| 2757 | } |
| 2758 | |
| 2759 | Map<String, ? extends BatteryStats.Uid.Pkg> packageStats = u.getPackageStats(); |
| 2760 | if (packageStats.size() > 0) { |
| 2761 | for (Map.Entry<String, ? extends BatteryStats.Uid.Pkg> ent |
| 2762 | : packageStats.entrySet()) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 2763 | pw.print(prefix); pw.print(" Apk "); pw.print(ent.getKey()); pw.println(":"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2764 | boolean apkActivity = false; |
| 2765 | Uid.Pkg ps = ent.getValue(); |
| 2766 | int wakeups = ps.getWakeups(which); |
| 2767 | if (wakeups != 0) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 2768 | pw.print(prefix); pw.print(" "); |
| 2769 | pw.print(wakeups); pw.println(" wakeup alarms"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2770 | apkActivity = true; |
| 2771 | } |
| 2772 | Map<String, ? extends Uid.Pkg.Serv> serviceStats = ps.getServiceStats(); |
| 2773 | if (serviceStats.size() > 0) { |
| 2774 | for (Map.Entry<String, ? extends BatteryStats.Uid.Pkg.Serv> sent |
| 2775 | : serviceStats.entrySet()) { |
| 2776 | BatteryStats.Uid.Pkg.Serv ss = sent.getValue(); |
| 2777 | long startTime = ss.getStartTime(batteryUptime, which); |
| 2778 | int starts = ss.getStarts(which); |
| 2779 | int launches = ss.getLaunches(which); |
| 2780 | if (startTime != 0 || starts != 0 || launches != 0) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 2781 | sb.setLength(0); |
| 2782 | sb.append(prefix); sb.append(" Service "); |
| 2783 | sb.append(sent.getKey()); sb.append(":\n"); |
| 2784 | sb.append(prefix); sb.append(" Created for: "); |
| 2785 | formatTimeMs(sb, startTime / 1000); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 2786 | sb.append("uptime\n"); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 2787 | sb.append(prefix); sb.append(" Starts: "); |
| 2788 | sb.append(starts); |
| 2789 | sb.append(", launches: "); sb.append(launches); |
| 2790 | pw.println(sb.toString()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2791 | apkActivity = true; |
| 2792 | } |
| 2793 | } |
| 2794 | } |
| 2795 | if (!apkActivity) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 2796 | pw.print(prefix); pw.println(" (nothing executed)"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2797 | } |
| 2798 | uidActivity = true; |
| 2799 | } |
| 2800 | } |
| 2801 | if (!uidActivity) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 2802 | pw.print(prefix); pw.println(" (nothing executed)"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2803 | } |
| 2804 | } |
| 2805 | } |
| 2806 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2807 | static void printBitDescriptions(PrintWriter pw, int oldval, int newval, HistoryTag wakelockTag, |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2808 | BitDescription[] descriptions, boolean longNames) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2809 | int diff = oldval ^ newval; |
| 2810 | if (diff == 0) return; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2811 | boolean didWake = false; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2812 | for (int i=0; i<descriptions.length; i++) { |
| 2813 | BitDescription bd = descriptions[i]; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2814 | if ((diff&bd.mask) != 0) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2815 | pw.print(longNames ? " " : ","); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2816 | if (bd.shift < 0) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2817 | pw.print((newval&bd.mask) != 0 ? "+" : "-"); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2818 | pw.print(longNames ? bd.name : bd.shortName); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2819 | if (bd.mask == HistoryItem.STATE_WAKE_LOCK_FLAG && wakelockTag != null) { |
| 2820 | didWake = true; |
| 2821 | pw.print("="); |
| 2822 | if (longNames) { |
| 2823 | UserHandle.formatUid(pw, wakelockTag.uid); |
| 2824 | pw.print(":\""); |
| 2825 | pw.print(wakelockTag.string); |
| 2826 | pw.print("\""); |
| 2827 | } else { |
| 2828 | pw.print(wakelockTag.poolIdx); |
| 2829 | } |
| 2830 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2831 | } else { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2832 | pw.print(longNames ? bd.name : bd.shortName); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2833 | pw.print("="); |
| 2834 | int val = (newval&bd.mask)>>bd.shift; |
| 2835 | if (bd.values != null && val >= 0 && val < bd.values.length) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2836 | pw.print(longNames? bd.values[val] : bd.shortValues[val]); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2837 | } else { |
| 2838 | pw.print(val); |
| 2839 | } |
| 2840 | } |
| 2841 | } |
| 2842 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2843 | if (!didWake && wakelockTag != null) { |
| 2844 | pw.print(longNames ? "wake_lock=" : "w="); |
| 2845 | if (longNames) { |
| 2846 | UserHandle.formatUid(pw, wakelockTag.uid); |
| 2847 | pw.print(":\""); |
| 2848 | pw.print(wakelockTag.string); |
| 2849 | pw.print("\""); |
| 2850 | } else { |
| 2851 | pw.print(wakelockTag.poolIdx); |
| 2852 | } |
| 2853 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2854 | } |
| 2855 | |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2856 | public void prepareForDumpLocked() { |
| 2857 | } |
| 2858 | |
| 2859 | public static class HistoryPrinter { |
| 2860 | int oldState = 0; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame^] | 2861 | int oldState2 = 0; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2862 | int oldLevel = -1; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2863 | int oldStatus = -1; |
| 2864 | int oldHealth = -1; |
| 2865 | int oldPlug = -1; |
| 2866 | int oldTemp = -1; |
| 2867 | int oldVolt = -1; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2868 | long lastTime = -1; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2869 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame^] | 2870 | public void printNextItem(PrintWriter pw, HistoryItem rec, long now, boolean checkin, |
| 2871 | boolean verbose) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2872 | if (!checkin) { |
| 2873 | pw.print(" "); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 2874 | if (now >= 0) { |
| 2875 | TimeUtils.formatDuration(rec.time-now, pw, TimeUtils.HUNDRED_DAY_FIELD_LEN); |
| 2876 | } else { |
| 2877 | TimeUtils.formatDuration(rec.time, pw, TimeUtils.HUNDRED_DAY_FIELD_LEN); |
| 2878 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2879 | pw.print(" ("); |
| 2880 | pw.print(rec.numReadInts); |
| 2881 | pw.print(") "); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2882 | } else { |
| 2883 | if (lastTime < 0) { |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 2884 | if (now >= 0) { |
| 2885 | pw.print("@"); |
| 2886 | pw.print(rec.time-now); |
| 2887 | } else { |
| 2888 | pw.print(rec.time); |
| 2889 | } |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2890 | } else { |
| 2891 | pw.print(rec.time-lastTime); |
| 2892 | } |
| 2893 | lastTime = rec.time; |
| 2894 | } |
| 2895 | if (rec.cmd == HistoryItem.CMD_START) { |
| 2896 | if (checkin) { |
| 2897 | pw.print(":"); |
| 2898 | } |
| 2899 | pw.println("START"); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 2900 | } else if (rec.cmd == HistoryItem.CMD_CURRENT_TIME) { |
| 2901 | if (checkin) { |
| 2902 | pw.print(":"); |
| 2903 | } |
| 2904 | pw.print("TIME:"); |
| 2905 | if (checkin) { |
| 2906 | pw.println(rec.currentTime); |
| 2907 | } else { |
| 2908 | pw.print(" "); |
| 2909 | pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss", |
| 2910 | rec.currentTime).toString()); |
| 2911 | } |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2912 | } else if (rec.cmd == HistoryItem.CMD_OVERFLOW) { |
| 2913 | if (checkin) { |
| 2914 | pw.print(":"); |
| 2915 | } |
| 2916 | pw.println("*OVERFLOW*"); |
| 2917 | } else { |
| 2918 | if (!checkin) { |
| 2919 | if (rec.batteryLevel < 10) pw.print("00"); |
| 2920 | else if (rec.batteryLevel < 100) pw.print("0"); |
| 2921 | pw.print(rec.batteryLevel); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame^] | 2922 | if (verbose) { |
| 2923 | pw.print(" "); |
| 2924 | if (rec.states < 0) ; |
| 2925 | else if (rec.states < 0x10) pw.print("0000000"); |
| 2926 | else if (rec.states < 0x100) pw.print("000000"); |
| 2927 | else if (rec.states < 0x1000) pw.print("00000"); |
| 2928 | else if (rec.states < 0x10000) pw.print("0000"); |
| 2929 | else if (rec.states < 0x100000) pw.print("000"); |
| 2930 | else if (rec.states < 0x1000000) pw.print("00"); |
| 2931 | else if (rec.states < 0x10000000) pw.print("0"); |
| 2932 | pw.print(Integer.toHexString(rec.states)); |
| 2933 | } |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2934 | } else { |
| 2935 | if (oldLevel != rec.batteryLevel) { |
| 2936 | oldLevel = rec.batteryLevel; |
| 2937 | pw.print(",Bl="); pw.print(rec.batteryLevel); |
| 2938 | } |
| 2939 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2940 | if (oldStatus != rec.batteryStatus) { |
| 2941 | oldStatus = rec.batteryStatus; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2942 | pw.print(checkin ? ",Bs=" : " status="); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2943 | switch (oldStatus) { |
| 2944 | case BatteryManager.BATTERY_STATUS_UNKNOWN: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2945 | pw.print(checkin ? "?" : "unknown"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2946 | break; |
| 2947 | case BatteryManager.BATTERY_STATUS_CHARGING: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2948 | pw.print(checkin ? "c" : "charging"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2949 | break; |
| 2950 | case BatteryManager.BATTERY_STATUS_DISCHARGING: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2951 | pw.print(checkin ? "d" : "discharging"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2952 | break; |
| 2953 | case BatteryManager.BATTERY_STATUS_NOT_CHARGING: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2954 | pw.print(checkin ? "n" : "not-charging"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2955 | break; |
| 2956 | case BatteryManager.BATTERY_STATUS_FULL: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2957 | pw.print(checkin ? "f" : "full"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2958 | break; |
| 2959 | default: |
| 2960 | pw.print(oldStatus); |
| 2961 | break; |
| 2962 | } |
| 2963 | } |
| 2964 | if (oldHealth != rec.batteryHealth) { |
| 2965 | oldHealth = rec.batteryHealth; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2966 | pw.print(checkin ? ",Bh=" : " health="); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2967 | switch (oldHealth) { |
| 2968 | case BatteryManager.BATTERY_HEALTH_UNKNOWN: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2969 | pw.print(checkin ? "?" : "unknown"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2970 | break; |
| 2971 | case BatteryManager.BATTERY_HEALTH_GOOD: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2972 | pw.print(checkin ? "g" : "good"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2973 | break; |
| 2974 | case BatteryManager.BATTERY_HEALTH_OVERHEAT: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2975 | pw.print(checkin ? "h" : "overheat"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2976 | break; |
| 2977 | case BatteryManager.BATTERY_HEALTH_DEAD: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2978 | pw.print(checkin ? "d" : "dead"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2979 | break; |
| 2980 | case BatteryManager.BATTERY_HEALTH_OVER_VOLTAGE: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2981 | pw.print(checkin ? "v" : "over-voltage"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2982 | break; |
| 2983 | case BatteryManager.BATTERY_HEALTH_UNSPECIFIED_FAILURE: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2984 | pw.print(checkin ? "f" : "failure"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2985 | break; |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 2986 | case BatteryManager.BATTERY_HEALTH_COLD: |
| 2987 | pw.print(checkin ? "c" : "cold"); |
| 2988 | break; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2989 | default: |
| 2990 | pw.print(oldHealth); |
| 2991 | break; |
| 2992 | } |
| 2993 | } |
| 2994 | if (oldPlug != rec.batteryPlugType) { |
| 2995 | oldPlug = rec.batteryPlugType; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2996 | pw.print(checkin ? ",Bp=" : " plug="); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2997 | switch (oldPlug) { |
| 2998 | case 0: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2999 | pw.print(checkin ? "n" : "none"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 3000 | break; |
| 3001 | case BatteryManager.BATTERY_PLUGGED_AC: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3002 | pw.print(checkin ? "a" : "ac"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 3003 | break; |
| 3004 | case BatteryManager.BATTERY_PLUGGED_USB: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3005 | pw.print(checkin ? "u" : "usb"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 3006 | break; |
Brian Muramatsu | 37a37f4 | 2012-08-14 15:21:02 -0700 | [diff] [blame] | 3007 | case BatteryManager.BATTERY_PLUGGED_WIRELESS: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3008 | pw.print(checkin ? "w" : "wireless"); |
Brian Muramatsu | 37a37f4 | 2012-08-14 15:21:02 -0700 | [diff] [blame] | 3009 | break; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 3010 | default: |
| 3011 | pw.print(oldPlug); |
| 3012 | break; |
| 3013 | } |
| 3014 | } |
| 3015 | if (oldTemp != rec.batteryTemperature) { |
| 3016 | oldTemp = rec.batteryTemperature; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3017 | pw.print(checkin ? ",Bt=" : " temp="); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 3018 | pw.print(oldTemp); |
| 3019 | } |
| 3020 | if (oldVolt != rec.batteryVoltage) { |
| 3021 | oldVolt = rec.batteryVoltage; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3022 | pw.print(checkin ? ",Bv=" : " volt="); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 3023 | pw.print(oldVolt); |
| 3024 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3025 | printBitDescriptions(pw, oldState, rec.states, rec.wakelockTag, |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3026 | HISTORY_STATE_DESCRIPTIONS, !checkin); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame^] | 3027 | printBitDescriptions(pw, oldState2, rec.states2, null, |
| 3028 | HISTORY_STATE2_DESCRIPTIONS, !checkin); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 3029 | if (rec.wakeReasonTag != null) { |
| 3030 | if (checkin) { |
| 3031 | pw.print(",Wr="); |
| 3032 | pw.print(rec.wakeReasonTag.poolIdx); |
| 3033 | } else { |
| 3034 | pw.print(" wake_reason="); |
| 3035 | pw.print(rec.wakeReasonTag.uid); |
| 3036 | pw.print(":\""); |
| 3037 | pw.print(rec.wakeReasonTag.string); |
| 3038 | pw.print("\""); |
| 3039 | } |
| 3040 | } |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3041 | if (rec.eventCode != HistoryItem.EVENT_NONE) { |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 3042 | pw.print(checkin ? "," : " "); |
| 3043 | if ((rec.eventCode&HistoryItem.EVENT_FLAG_START) != 0) { |
| 3044 | pw.print("+"); |
| 3045 | } else if ((rec.eventCode&HistoryItem.EVENT_FLAG_FINISH) != 0) { |
| 3046 | pw.print("-"); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3047 | } |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 3048 | String[] eventNames = checkin ? HISTORY_EVENT_CHECKIN_NAMES |
| 3049 | : HISTORY_EVENT_NAMES; |
| 3050 | int idx = rec.eventCode & ~(HistoryItem.EVENT_FLAG_START |
| 3051 | | HistoryItem.EVENT_FLAG_FINISH); |
| 3052 | if (idx >= 0 && idx < eventNames.length) { |
| 3053 | pw.print(eventNames[idx]); |
| 3054 | } else { |
| 3055 | pw.print(checkin ? "Ev" : "event"); |
| 3056 | pw.print(idx); |
| 3057 | } |
| 3058 | pw.print("="); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3059 | if (checkin) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3060 | pw.print(rec.eventTag.poolIdx); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3061 | } else { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3062 | UserHandle.formatUid(pw, rec.eventTag.uid); |
| 3063 | pw.print(":\""); |
| 3064 | pw.print(rec.eventTag.string); |
| 3065 | pw.print("\""); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3066 | } |
| 3067 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 3068 | pw.println(); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 3069 | oldState = rec.states; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 3070 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 3071 | } |
| 3072 | } |
| 3073 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3074 | private void printSizeValue(PrintWriter pw, long size) { |
| 3075 | float result = size; |
| 3076 | String suffix = ""; |
| 3077 | if (result >= 10*1024) { |
| 3078 | suffix = "KB"; |
| 3079 | result = result / 1024; |
| 3080 | } |
| 3081 | if (result >= 10*1024) { |
| 3082 | suffix = "MB"; |
| 3083 | result = result / 1024; |
| 3084 | } |
| 3085 | if (result >= 10*1024) { |
| 3086 | suffix = "GB"; |
| 3087 | result = result / 1024; |
| 3088 | } |
| 3089 | if (result >= 10*1024) { |
| 3090 | suffix = "TB"; |
| 3091 | result = result / 1024; |
| 3092 | } |
| 3093 | if (result >= 10*1024) { |
| 3094 | suffix = "PB"; |
| 3095 | result = result / 1024; |
| 3096 | } |
| 3097 | pw.print((int)result); |
| 3098 | pw.print(suffix); |
| 3099 | } |
| 3100 | |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 3101 | public static final int DUMP_UNPLUGGED_ONLY = 1<<0; |
| 3102 | public static final int DUMP_CHARGED_ONLY = 1<<1; |
| 3103 | public static final int DUMP_HISTORY_ONLY = 1<<2; |
| 3104 | public static final int DUMP_INCLUDE_HISTORY = 1<<3; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame^] | 3105 | public static final int DUMP_VERBOSE = 1<<4; |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 3106 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3107 | /** |
| 3108 | * Dumps a human-readable summary of the battery statistics to the given PrintWriter. |
| 3109 | * |
| 3110 | * @param pw a Printer to receive the dump output. |
| 3111 | */ |
| 3112 | @SuppressWarnings("unused") |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 3113 | public void dumpLocked(Context context, PrintWriter pw, int flags, int reqUid, long histStart) { |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 3114 | prepareForDumpLocked(); |
| 3115 | |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 3116 | final boolean filtering = |
| 3117 | (flags&(DUMP_HISTORY_ONLY|DUMP_UNPLUGGED_ONLY|DUMP_CHARGED_ONLY)) != 0; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 3118 | |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 3119 | if ((flags&DUMP_HISTORY_ONLY) != 0 || !filtering) { |
| 3120 | long now = getHistoryBaseTime() + SystemClock.elapsedRealtime(); |
| 3121 | |
| 3122 | final HistoryItem rec = new HistoryItem(); |
| 3123 | final long historyTotalSize = getHistoryTotalSize(); |
| 3124 | final long historyUsedSize = getHistoryUsedSize(); |
| 3125 | if (startIteratingHistoryLocked()) { |
| 3126 | try { |
| 3127 | pw.print("Battery History ("); |
| 3128 | pw.print((100*historyUsedSize)/historyTotalSize); |
| 3129 | pw.print("% used, "); |
| 3130 | printSizeValue(pw, historyUsedSize); |
| 3131 | pw.print(" used of "); |
| 3132 | printSizeValue(pw, historyTotalSize); |
| 3133 | pw.print(", "); |
| 3134 | pw.print(getHistoryStringPoolSize()); |
| 3135 | pw.print(" strings using "); |
| 3136 | printSizeValue(pw, getHistoryStringPoolBytes()); |
| 3137 | pw.println("):"); |
| 3138 | HistoryPrinter hprinter = new HistoryPrinter(); |
| 3139 | long lastTime = -1; |
| 3140 | while (getNextHistoryLocked(rec)) { |
| 3141 | lastTime = rec.time; |
| 3142 | if (rec.time >= histStart) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame^] | 3143 | hprinter.printNextItem(pw, rec, histStart >= 0 ? -1 : now, false, |
| 3144 | (flags&DUMP_VERBOSE) != 0); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 3145 | } |
| 3146 | } |
| 3147 | if (histStart >= 0) { |
| 3148 | pw.print(" NEXT: "); pw.println(lastTime+1); |
| 3149 | } |
| 3150 | pw.println(); |
| 3151 | } finally { |
| 3152 | finishIteratingHistoryLocked(); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3153 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 3154 | } |
| 3155 | |
| 3156 | if (startIteratingOldHistoryLocked()) { |
| 3157 | try { |
| 3158 | pw.println("Old battery History:"); |
| 3159 | HistoryPrinter hprinter = new HistoryPrinter(); |
| 3160 | while (getNextOldHistoryLocked(rec)) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame^] | 3161 | hprinter.printNextItem(pw, rec, now, false, (flags&DUMP_VERBOSE) != 0); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 3162 | } |
| 3163 | pw.println(); |
| 3164 | } finally { |
| 3165 | finishIteratingOldHistoryLocked(); |
| 3166 | } |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3167 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 3168 | } |
| 3169 | |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 3170 | if (filtering && (flags&(DUMP_UNPLUGGED_ONLY|DUMP_CHARGED_ONLY)) == 0) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3171 | return; |
| 3172 | } |
| 3173 | |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 3174 | if (!filtering) { |
| 3175 | SparseArray<? extends Uid> uidStats = getUidStats(); |
| 3176 | final int NU = uidStats.size(); |
| 3177 | boolean didPid = false; |
| 3178 | long nowRealtime = SystemClock.elapsedRealtime(); |
| 3179 | for (int i=0; i<NU; i++) { |
| 3180 | Uid uid = uidStats.valueAt(i); |
| 3181 | SparseArray<? extends Uid.Pid> pids = uid.getPidStats(); |
| 3182 | if (pids != null) { |
| 3183 | for (int j=0; j<pids.size(); j++) { |
| 3184 | Uid.Pid pid = pids.valueAt(j); |
| 3185 | if (!didPid) { |
| 3186 | pw.println("Per-PID Stats:"); |
| 3187 | didPid = true; |
| 3188 | } |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 3189 | long time = pid.mWakeSumMs + (pid.mWakeNesting > 0 |
| 3190 | ? (nowRealtime - pid.mWakeStartMs) : 0); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 3191 | pw.print(" PID "); pw.print(pids.keyAt(j)); |
| 3192 | pw.print(" wake time: "); |
| 3193 | TimeUtils.formatDuration(time, pw); |
| 3194 | pw.println(""); |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 3195 | } |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 3196 | } |
| 3197 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 3198 | if (didPid) { |
| 3199 | pw.println(""); |
| 3200 | } |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3201 | } |
Jeff Sharkey | ec43a6b | 2013-04-30 13:33:18 -0700 | [diff] [blame] | 3202 | |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 3203 | if (!filtering || (flags&DUMP_CHARGED_ONLY) != 0) { |
Jeff Sharkey | ec43a6b | 2013-04-30 13:33:18 -0700 | [diff] [blame] | 3204 | pw.println("Statistics since last charge:"); |
| 3205 | pw.println(" System starts: " + getStartCount() |
| 3206 | + ", currently on battery: " + getIsOnBattery()); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3207 | dumpLocked(context, pw, "", STATS_SINCE_CHARGED, reqUid); |
Jeff Sharkey | ec43a6b | 2013-04-30 13:33:18 -0700 | [diff] [blame] | 3208 | pw.println(""); |
| 3209 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 3210 | if (!filtering || (flags&DUMP_UNPLUGGED_ONLY) != 0) { |
| 3211 | pw.println("Statistics since last unplugged:"); |
| 3212 | dumpLocked(context, pw, "", STATS_SINCE_UNPLUGGED, reqUid); |
| 3213 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3214 | } |
| 3215 | |
| 3216 | @SuppressWarnings("unused") |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 3217 | public void dumpCheckinLocked(Context context, PrintWriter pw, |
| 3218 | List<ApplicationInfo> apps, int flags, long histStart) { |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 3219 | prepareForDumpLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3220 | |
Dianne Hackborn | 13ac041 | 2013-06-25 19:34:49 -0700 | [diff] [blame] | 3221 | long now = getHistoryBaseTime() + SystemClock.elapsedRealtime(); |
| 3222 | |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 3223 | final boolean filtering = |
| 3224 | (flags&(DUMP_HISTORY_ONLY|DUMP_UNPLUGGED_ONLY|DUMP_CHARGED_ONLY)) != 0; |
| 3225 | |
| 3226 | if ((flags&DUMP_INCLUDE_HISTORY) != 0 || (flags&DUMP_HISTORY_ONLY) != 0) { |
Dianne Hackborn | 49021f5 | 2013-09-04 18:03:40 -0700 | [diff] [blame] | 3227 | final HistoryItem rec = new HistoryItem(); |
| 3228 | if (startIteratingHistoryLocked()) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3229 | try { |
| 3230 | for (int i=0; i<getHistoryStringPoolSize(); i++) { |
| 3231 | pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(','); |
| 3232 | pw.print(HISTORY_STRING_POOL); pw.print(','); |
| 3233 | pw.print(i); |
| 3234 | pw.print(','); |
| 3235 | pw.print(getHistoryTagPoolString(i)); |
| 3236 | pw.print(','); |
| 3237 | pw.print(getHistoryTagPoolUid(i)); |
| 3238 | pw.println(); |
| 3239 | } |
| 3240 | HistoryPrinter hprinter = new HistoryPrinter(); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 3241 | long lastTime = -1; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3242 | while (getNextHistoryLocked(rec)) { |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 3243 | lastTime = rec.time; |
| 3244 | if (rec.time >= histStart) { |
| 3245 | pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(','); |
| 3246 | pw.print(HISTORY_DATA); pw.print(','); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame^] | 3247 | hprinter.printNextItem(pw, rec, histStart >= 0 ? -1 : now, true, false); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 3248 | } |
| 3249 | } |
| 3250 | if (histStart >= 0) { |
| 3251 | pw.print("NEXT: "); pw.println(lastTime+1); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3252 | } |
| 3253 | } finally { |
| 3254 | finishIteratingHistoryLocked(); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3255 | } |
Dianne Hackborn | 13ac041 | 2013-06-25 19:34:49 -0700 | [diff] [blame] | 3256 | } |
Dianne Hackborn | 13ac041 | 2013-06-25 19:34:49 -0700 | [diff] [blame] | 3257 | } |
| 3258 | |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 3259 | if (filtering && (flags&(DUMP_UNPLUGGED_ONLY|DUMP_CHARGED_ONLY)) == 0) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3260 | return; |
| 3261 | } |
| 3262 | |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3263 | if (apps != null) { |
| 3264 | SparseArray<ArrayList<String>> uids = new SparseArray<ArrayList<String>>(); |
| 3265 | for (int i=0; i<apps.size(); i++) { |
| 3266 | ApplicationInfo ai = apps.get(i); |
| 3267 | ArrayList<String> pkgs = uids.get(ai.uid); |
| 3268 | if (pkgs == null) { |
| 3269 | pkgs = new ArrayList<String>(); |
| 3270 | uids.put(ai.uid, pkgs); |
| 3271 | } |
| 3272 | pkgs.add(ai.packageName); |
| 3273 | } |
| 3274 | SparseArray<? extends Uid> uidStats = getUidStats(); |
| 3275 | final int NU = uidStats.size(); |
| 3276 | String[] lineArgs = new String[2]; |
| 3277 | for (int i=0; i<NU; i++) { |
| 3278 | int uid = uidStats.keyAt(i); |
| 3279 | ArrayList<String> pkgs = uids.get(uid); |
| 3280 | if (pkgs != null) { |
| 3281 | for (int j=0; j<pkgs.size(); j++) { |
| 3282 | lineArgs[0] = Integer.toString(uid); |
| 3283 | lineArgs[1] = pkgs.get(j); |
| 3284 | dumpLine(pw, 0 /* uid */, "i" /* category */, UID_DATA, |
| 3285 | (Object[])lineArgs); |
| 3286 | } |
| 3287 | } |
| 3288 | } |
| 3289 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 3290 | if (!filtering || (flags&DUMP_CHARGED_ONLY) != 0) { |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3291 | dumpCheckinLocked(context, pw, STATS_SINCE_CHARGED, -1); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 3292 | } |
| 3293 | if (!filtering || (flags&DUMP_UNPLUGGED_ONLY) != 0) { |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3294 | dumpCheckinLocked(context, pw, STATS_SINCE_UNPLUGGED, -1); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3295 | } |
| 3296 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3297 | } |