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