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