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