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