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