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