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