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 | |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 88 | /** |
| 89 | * A constant indicating a wifi multicast timer |
| 90 | */ |
| 91 | public static final int WIFI_MULTICAST_ENABLED = 7; |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 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 a video turn on timer |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 95 | */ |
| 96 | public static final int VIDEO_TURNED_ON = 8; |
| 97 | |
| 98 | /** |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 99 | * A constant indicating a vibrator on timer |
| 100 | */ |
| 101 | public static final int VIBRATOR_ON = 9; |
| 102 | |
| 103 | /** |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 104 | * A constant indicating a foreground activity timer |
| 105 | */ |
| 106 | public static final int FOREGROUND_ACTIVITY = 10; |
| 107 | |
| 108 | /** |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 109 | * A constant indicating a wifi batched scan is active |
| 110 | */ |
| 111 | public static final int WIFI_BATCHED_SCAN = 11; |
| 112 | |
| 113 | /** |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 114 | * A constant indicating a process state timer |
| 115 | */ |
| 116 | public static final int PROCESS_STATE = 12; |
| 117 | |
| 118 | /** |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 119 | * A constant indicating a sync timer |
| 120 | */ |
| 121 | public static final int SYNC = 13; |
| 122 | |
| 123 | /** |
| 124 | * A constant indicating a job timer |
| 125 | */ |
| 126 | public static final int JOB = 14; |
| 127 | |
| 128 | /** |
Kweku Adams | d537987 | 2014-11-24 17:34:05 -0800 | [diff] [blame] | 129 | * A constant indicating an audio turn on timer |
| 130 | */ |
| 131 | public static final int AUDIO_TURNED_ON = 15; |
| 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 | |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 162 | private static final String VERSION_DATA = "vers"; |
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); |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 355 | public abstract int getWifiScanCount(int which); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 356 | public abstract long getWifiBatchedScanTime(int csphBin, long elapsedRealtimeUs, int which); |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 357 | public abstract int getWifiBatchedScanCount(int csphBin, int which); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 358 | public abstract long getWifiMulticastTime(long elapsedRealtimeUs, int which); |
| 359 | public abstract long getAudioTurnedOnTime(long elapsedRealtimeUs, int which); |
| 360 | public abstract long getVideoTurnedOnTime(long elapsedRealtimeUs, int which); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 361 | public abstract Timer getForegroundActivityTimer(); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 362 | |
| 363 | // Time this uid has any processes in foreground state. |
| 364 | public static final int PROCESS_STATE_FOREGROUND = 0; |
| 365 | // Time this uid has any process in active state (not cached). |
| 366 | public static final int PROCESS_STATE_ACTIVE = 1; |
| 367 | // Time this uid has any processes running at all. |
| 368 | public static final int PROCESS_STATE_RUNNING = 2; |
| 369 | // Total number of process states we track. |
| 370 | public static final int NUM_PROCESS_STATE = 3; |
| 371 | |
| 372 | static final String[] PROCESS_STATE_NAMES = { |
| 373 | "Foreground", "Active", "Running" |
| 374 | }; |
| 375 | |
| 376 | public abstract long getProcessStateTime(int state, long elapsedRealtimeUs, int which); |
| 377 | |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 378 | public abstract Timer getVibratorOnTimer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 379 | |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 380 | public static final int NUM_WIFI_BATCHED_SCAN_BINS = 5; |
| 381 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 382 | /** |
Jeff Brown | df693de | 2012-07-27 12:03:38 -0700 | [diff] [blame] | 383 | * Note that these must match the constants in android.os.PowerManager. |
| 384 | * Also, if the user activity types change, the BatteryStatsImpl.VERSION must |
| 385 | * also be bumped. |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 386 | */ |
| 387 | static final String[] USER_ACTIVITY_TYPES = { |
Jeff Brown | df693de | 2012-07-27 12:03:38 -0700 | [diff] [blame] | 388 | "other", "button", "touch" |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 389 | }; |
| 390 | |
Jeff Brown | df693de | 2012-07-27 12:03:38 -0700 | [diff] [blame] | 391 | public static final int NUM_USER_ACTIVITY_TYPES = 3; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 392 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 393 | public abstract void noteUserActivityLocked(int type); |
| 394 | public abstract boolean hasUserActivity(); |
| 395 | public abstract int getUserActivityCount(int type, int which); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 396 | |
| 397 | public abstract boolean hasNetworkActivity(); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 398 | public abstract long getNetworkActivityBytes(int type, int which); |
| 399 | public abstract long getNetworkActivityPackets(int type, int which); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 400 | public abstract long getMobileRadioActiveTime(int which); |
| 401 | public abstract int getMobileRadioActiveCount(int which); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 402 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 403 | public static abstract class Sensor { |
Mathias Agopian | 7f84c06 | 2013-02-04 19:22:47 -0800 | [diff] [blame] | 404 | /* |
| 405 | * FIXME: it's not correct to use this magic value because it |
| 406 | * could clash with a sensor handle (which are defined by |
| 407 | * the sensor HAL, and therefore out of our control |
| 408 | */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 409 | // Magic sensor number for the GPS. |
| 410 | public static final int GPS = -10000; |
| 411 | |
| 412 | public abstract int getHandle(); |
| 413 | |
| 414 | public abstract Timer getSensorTime(); |
| 415 | } |
| 416 | |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 417 | public class Pid { |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 418 | public int mWakeNesting; |
| 419 | public long mWakeSumMs; |
| 420 | public long mWakeStartMs; |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 421 | } |
| 422 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 423 | /** |
| 424 | * The statistics associated with a particular process. |
| 425 | */ |
| 426 | public static abstract class Proc { |
| 427 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 428 | public static class ExcessivePower { |
| 429 | public static final int TYPE_WAKE = 1; |
| 430 | public static final int TYPE_CPU = 2; |
| 431 | |
| 432 | public int type; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 433 | public long overTime; |
| 434 | public long usedTime; |
| 435 | } |
| 436 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 437 | /** |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 438 | * Returns true if this process is still active in the battery stats. |
| 439 | */ |
| 440 | public abstract boolean isActive(); |
| 441 | |
| 442 | /** |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 443 | * Returns the total time (in milliseconds) spent executing in user code. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 444 | * |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 445 | * @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] | 446 | */ |
| 447 | public abstract long getUserTime(int which); |
| 448 | |
| 449 | /** |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 450 | * Returns the total time (in milliseconds) spent executing in system code. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 451 | * |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 452 | * @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] | 453 | */ |
| 454 | public abstract long getSystemTime(int which); |
| 455 | |
| 456 | /** |
| 457 | * Returns the number of times the process has been started. |
| 458 | * |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 459 | * @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] | 460 | */ |
| 461 | public abstract int getStarts(int which); |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 462 | |
| 463 | /** |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 464 | * Returns the number of times the process has crashed. |
| 465 | * |
| 466 | * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT. |
| 467 | */ |
| 468 | public abstract int getNumCrashes(int which); |
| 469 | |
| 470 | /** |
| 471 | * Returns the number of times the process has ANRed. |
| 472 | * |
| 473 | * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT. |
| 474 | */ |
| 475 | public abstract int getNumAnrs(int which); |
| 476 | |
| 477 | /** |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 478 | * Returns the cpu time (milliseconds) spent while the process was in the foreground. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 479 | * @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] | 480 | * @return foreground cpu time in microseconds |
| 481 | */ |
| 482 | public abstract long getForegroundTime(int which); |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 483 | |
| 484 | /** |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 485 | * Returns the approximate cpu time (in milliseconds) spent at a certain CPU speed. |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 486 | * @param speedStep the index of the CPU speed. This is not the actual speed of the |
| 487 | * CPU. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 488 | * @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] | 489 | * @see BatteryStats#getCpuSpeedSteps() |
| 490 | */ |
| 491 | public abstract long getTimeAtCpuSpeedStep(int speedStep, int which); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 492 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 493 | public abstract int countExcessivePowers(); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 494 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 495 | public abstract ExcessivePower getExcessivePower(int i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 496 | } |
| 497 | |
| 498 | /** |
| 499 | * The statistics associated with a particular package. |
| 500 | */ |
| 501 | public static abstract class Pkg { |
| 502 | |
| 503 | /** |
| 504 | * Returns the number of times this package has done something that could wake up the |
| 505 | * device from sleep. |
| 506 | * |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 507 | * @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] | 508 | */ |
| 509 | public abstract int getWakeups(int which); |
| 510 | |
| 511 | /** |
| 512 | * Returns a mapping containing service statistics. |
| 513 | */ |
| 514 | public abstract Map<String, ? extends Serv> getServiceStats(); |
| 515 | |
| 516 | /** |
| 517 | * The statistics associated with a particular service. |
| 518 | */ |
| 519 | public abstract class Serv { |
| 520 | |
| 521 | /** |
| 522 | * Returns the amount of time spent started. |
| 523 | * |
| 524 | * @param batteryUptime elapsed uptime on battery in microseconds. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 525 | * @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] | 526 | * @return |
| 527 | */ |
| 528 | public abstract long getStartTime(long batteryUptime, int which); |
| 529 | |
| 530 | /** |
| 531 | * Returns the total number of times startService() has been called. |
| 532 | * |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 533 | * @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] | 534 | */ |
| 535 | public abstract int getStarts(int which); |
| 536 | |
| 537 | /** |
| 538 | * Returns the total number times the service has been launched. |
| 539 | * |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 540 | * @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] | 541 | */ |
| 542 | public abstract int getLaunches(int which); |
| 543 | } |
| 544 | } |
| 545 | } |
| 546 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 547 | public static final class LevelStepTracker { |
| 548 | public long mLastStepTime = -1; |
| 549 | public int mNumStepDurations; |
| 550 | public final long[] mStepDurations; |
| 551 | |
| 552 | public LevelStepTracker(int maxLevelSteps) { |
| 553 | mStepDurations = new long[maxLevelSteps]; |
| 554 | } |
| 555 | |
| 556 | public LevelStepTracker(int numSteps, long[] steps) { |
| 557 | mNumStepDurations = numSteps; |
| 558 | mStepDurations = new long[numSteps]; |
| 559 | System.arraycopy(steps, 0, mStepDurations, 0, numSteps); |
| 560 | } |
| 561 | |
| 562 | public long getDurationAt(int index) { |
| 563 | return mStepDurations[index] & STEP_LEVEL_TIME_MASK; |
| 564 | } |
| 565 | |
| 566 | public int getLevelAt(int index) { |
| 567 | return (int)((mStepDurations[index] & STEP_LEVEL_LEVEL_MASK) |
| 568 | >> STEP_LEVEL_LEVEL_SHIFT); |
| 569 | } |
| 570 | |
| 571 | public int getInitModeAt(int index) { |
| 572 | return (int)((mStepDurations[index] & STEP_LEVEL_INITIAL_MODE_MASK) |
| 573 | >> STEP_LEVEL_INITIAL_MODE_SHIFT); |
| 574 | } |
| 575 | |
| 576 | public int getModModeAt(int index) { |
| 577 | return (int)((mStepDurations[index] & STEP_LEVEL_MODIFIED_MODE_MASK) |
| 578 | >> STEP_LEVEL_MODIFIED_MODE_SHIFT); |
| 579 | } |
| 580 | |
| 581 | private void appendHex(long val, int topOffset, StringBuilder out) { |
| 582 | boolean hasData = false; |
| 583 | while (topOffset >= 0) { |
| 584 | int digit = (int)( (val>>topOffset) & 0xf ); |
| 585 | topOffset -= 4; |
| 586 | if (!hasData && digit == 0) { |
| 587 | continue; |
| 588 | } |
| 589 | hasData = true; |
| 590 | if (digit >= 0 && digit <= 9) { |
| 591 | out.append((char)('0' + digit)); |
| 592 | } else { |
| 593 | out.append((char)('a' + digit - 10)); |
| 594 | } |
| 595 | } |
| 596 | } |
| 597 | |
| 598 | public void encodeEntryAt(int index, StringBuilder out) { |
| 599 | long item = mStepDurations[index]; |
| 600 | long duration = item & STEP_LEVEL_TIME_MASK; |
| 601 | int level = (int)((item & STEP_LEVEL_LEVEL_MASK) |
| 602 | >> STEP_LEVEL_LEVEL_SHIFT); |
| 603 | int initMode = (int)((item & STEP_LEVEL_INITIAL_MODE_MASK) |
| 604 | >> STEP_LEVEL_INITIAL_MODE_SHIFT); |
| 605 | int modMode = (int)((item & STEP_LEVEL_MODIFIED_MODE_MASK) |
| 606 | >> STEP_LEVEL_MODIFIED_MODE_SHIFT); |
| 607 | switch ((initMode&STEP_LEVEL_MODE_SCREEN_STATE) + 1) { |
| 608 | case Display.STATE_OFF: out.append('f'); break; |
| 609 | case Display.STATE_ON: out.append('o'); break; |
| 610 | case Display.STATE_DOZE: out.append('d'); break; |
| 611 | case Display.STATE_DOZE_SUSPEND: out.append('z'); break; |
| 612 | } |
| 613 | if ((initMode&STEP_LEVEL_MODE_POWER_SAVE) != 0) { |
| 614 | out.append('p'); |
| 615 | } |
| 616 | switch ((modMode&STEP_LEVEL_MODE_SCREEN_STATE) + 1) { |
| 617 | case Display.STATE_OFF: out.append('F'); break; |
| 618 | case Display.STATE_ON: out.append('O'); break; |
| 619 | case Display.STATE_DOZE: out.append('D'); break; |
| 620 | case Display.STATE_DOZE_SUSPEND: out.append('Z'); break; |
| 621 | } |
| 622 | if ((modMode&STEP_LEVEL_MODE_POWER_SAVE) != 0) { |
| 623 | out.append('P'); |
| 624 | } |
| 625 | out.append('-'); |
| 626 | appendHex(level, 4, out); |
| 627 | out.append('-'); |
| 628 | appendHex(duration, STEP_LEVEL_LEVEL_SHIFT-4, out); |
| 629 | } |
| 630 | |
| 631 | public void decodeEntryAt(int index, String value) { |
| 632 | final int N = value.length(); |
| 633 | int i = 0; |
| 634 | char c; |
| 635 | long out = 0; |
| 636 | while (i < N && (c=value.charAt(i)) != '-') { |
| 637 | i++; |
| 638 | switch (c) { |
Dianne Hackborn | 8cfb58b | 2015-03-04 13:28:36 -0800 | [diff] [blame] | 639 | case 'f': out |= (((long)Display.STATE_OFF-1)<<STEP_LEVEL_INITIAL_MODE_SHIFT); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 640 | break; |
Dianne Hackborn | 8cfb58b | 2015-03-04 13:28:36 -0800 | [diff] [blame] | 641 | case 'o': out |= (((long)Display.STATE_ON-1)<<STEP_LEVEL_INITIAL_MODE_SHIFT); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 642 | break; |
Dianne Hackborn | 8cfb58b | 2015-03-04 13:28:36 -0800 | [diff] [blame] | 643 | case 'd': out |= (((long)Display.STATE_DOZE-1)<<STEP_LEVEL_INITIAL_MODE_SHIFT); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 644 | break; |
Dianne Hackborn | 8cfb58b | 2015-03-04 13:28:36 -0800 | [diff] [blame] | 645 | case 'z': out |= (((long)Display.STATE_DOZE_SUSPEND-1) |
| 646 | << STEP_LEVEL_INITIAL_MODE_SHIFT); |
| 647 | break; |
| 648 | case 'p': out |= (((long)STEP_LEVEL_MODE_POWER_SAVE) |
| 649 | << STEP_LEVEL_INITIAL_MODE_SHIFT); |
| 650 | break; |
| 651 | case 'F': out |= (((long)Display.STATE_OFF-1)<<STEP_LEVEL_MODIFIED_MODE_SHIFT); |
| 652 | break; |
| 653 | case 'O': out |= (((long)Display.STATE_ON-1)<<STEP_LEVEL_MODIFIED_MODE_SHIFT); |
| 654 | break; |
| 655 | case 'D': out |= (((long)Display.STATE_DOZE-1)<<STEP_LEVEL_MODIFIED_MODE_SHIFT); |
| 656 | break; |
| 657 | case 'Z': out |= (((long)Display.STATE_DOZE_SUSPEND-1) |
| 658 | << STEP_LEVEL_MODIFIED_MODE_SHIFT); |
| 659 | break; |
| 660 | case 'P': out |= (((long)STEP_LEVEL_MODE_POWER_SAVE) |
| 661 | << STEP_LEVEL_MODIFIED_MODE_SHIFT); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 662 | break; |
| 663 | } |
| 664 | } |
| 665 | i++; |
Dianne Hackborn | 8cfb58b | 2015-03-04 13:28:36 -0800 | [diff] [blame] | 666 | long level = 0; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 667 | while (i < N && (c=value.charAt(i)) != '-') { |
| 668 | i++; |
| 669 | level <<= 4; |
| 670 | if (c >= '0' && c <= '9') { |
| 671 | level += c - '0'; |
| 672 | } else if (c >= 'a' && c <= 'f') { |
| 673 | level += c - 'a' + 10; |
| 674 | } else if (c >= 'A' && c <= 'F') { |
| 675 | level += c - 'A' + 10; |
| 676 | } |
| 677 | } |
Dianne Hackborn | 8cfb58b | 2015-03-04 13:28:36 -0800 | [diff] [blame] | 678 | i++; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 679 | out |= (level << STEP_LEVEL_LEVEL_SHIFT) & STEP_LEVEL_LEVEL_MASK; |
| 680 | long duration = 0; |
| 681 | while (i < N && (c=value.charAt(i)) != '-') { |
| 682 | i++; |
| 683 | duration <<= 4; |
| 684 | if (c >= '0' && c <= '9') { |
| 685 | duration += c - '0'; |
| 686 | } else if (c >= 'a' && c <= 'f') { |
| 687 | duration += c - 'a' + 10; |
| 688 | } else if (c >= 'A' && c <= 'F') { |
| 689 | duration += c - 'A' + 10; |
| 690 | } |
| 691 | } |
| 692 | mStepDurations[index] = out | (duration & STEP_LEVEL_TIME_MASK); |
| 693 | } |
| 694 | |
| 695 | public void init() { |
| 696 | mLastStepTime = -1; |
| 697 | mNumStepDurations = 0; |
| 698 | } |
| 699 | |
| 700 | public void clearTime() { |
| 701 | mLastStepTime = -1; |
| 702 | } |
| 703 | |
| 704 | public long computeTimePerLevel() { |
| 705 | final long[] steps = mStepDurations; |
| 706 | final int numSteps = mNumStepDurations; |
| 707 | |
| 708 | // For now we'll do a simple average across all steps. |
| 709 | if (numSteps <= 0) { |
| 710 | return -1; |
| 711 | } |
| 712 | long total = 0; |
| 713 | for (int i=0; i<numSteps; i++) { |
| 714 | total += steps[i] & STEP_LEVEL_TIME_MASK; |
| 715 | } |
| 716 | return total / numSteps; |
| 717 | /* |
| 718 | long[] buckets = new long[numSteps]; |
| 719 | int numBuckets = 0; |
| 720 | int numToAverage = 4; |
| 721 | int i = 0; |
| 722 | while (i < numSteps) { |
| 723 | long totalTime = 0; |
| 724 | int num = 0; |
| 725 | for (int j=0; j<numToAverage && (i+j)<numSteps; j++) { |
| 726 | totalTime += steps[i+j] & STEP_LEVEL_TIME_MASK; |
| 727 | num++; |
| 728 | } |
| 729 | buckets[numBuckets] = totalTime / num; |
| 730 | numBuckets++; |
| 731 | numToAverage *= 2; |
| 732 | i += num; |
| 733 | } |
| 734 | if (numBuckets < 1) { |
| 735 | return -1; |
| 736 | } |
| 737 | long averageTime = buckets[numBuckets-1]; |
| 738 | for (i=numBuckets-2; i>=0; i--) { |
| 739 | averageTime = (averageTime + buckets[i]) / 2; |
| 740 | } |
| 741 | return averageTime; |
| 742 | */ |
| 743 | } |
| 744 | |
| 745 | public long computeTimeEstimate(long modesOfInterest, long modeValues, |
| 746 | int[] outNumOfInterest) { |
| 747 | final long[] steps = mStepDurations; |
| 748 | final int count = mNumStepDurations; |
| 749 | if (count <= 0) { |
| 750 | return -1; |
| 751 | } |
| 752 | long total = 0; |
| 753 | int numOfInterest = 0; |
| 754 | for (int i=0; i<count; i++) { |
| 755 | long initMode = (steps[i] & STEP_LEVEL_INITIAL_MODE_MASK) |
| 756 | >> STEP_LEVEL_INITIAL_MODE_SHIFT; |
| 757 | long modMode = (steps[i] & STEP_LEVEL_MODIFIED_MODE_MASK) |
| 758 | >> STEP_LEVEL_MODIFIED_MODE_SHIFT; |
| 759 | // If the modes of interest didn't change during this step period... |
| 760 | if ((modMode&modesOfInterest) == 0) { |
| 761 | // And the mode values during this period match those we are measuring... |
| 762 | if ((initMode&modesOfInterest) == modeValues) { |
| 763 | // Then this can be used to estimate the total time! |
| 764 | numOfInterest++; |
| 765 | total += steps[i] & STEP_LEVEL_TIME_MASK; |
| 766 | } |
| 767 | } |
| 768 | } |
| 769 | if (numOfInterest <= 0) { |
| 770 | return -1; |
| 771 | } |
| 772 | |
| 773 | if (outNumOfInterest != null) { |
| 774 | outNumOfInterest[0] = numOfInterest; |
| 775 | } |
| 776 | |
| 777 | // The estimated time is the average time we spend in each level, multipled |
| 778 | // by 100 -- the total number of battery levels |
| 779 | return (total / numOfInterest) * 100; |
| 780 | } |
| 781 | |
| 782 | public void addLevelSteps(int numStepLevels, long modeBits, long elapsedRealtime) { |
| 783 | int stepCount = mNumStepDurations; |
| 784 | final long lastStepTime = mLastStepTime; |
| 785 | if (lastStepTime >= 0 && numStepLevels > 0) { |
| 786 | final long[] steps = mStepDurations; |
| 787 | long duration = elapsedRealtime - lastStepTime; |
| 788 | for (int i=0; i<numStepLevels; i++) { |
| 789 | System.arraycopy(steps, 0, steps, 1, steps.length-1); |
| 790 | long thisDuration = duration / (numStepLevels-i); |
| 791 | duration -= thisDuration; |
| 792 | if (thisDuration > STEP_LEVEL_TIME_MASK) { |
| 793 | thisDuration = STEP_LEVEL_TIME_MASK; |
| 794 | } |
| 795 | steps[0] = thisDuration | modeBits; |
| 796 | } |
| 797 | stepCount += numStepLevels; |
| 798 | if (stepCount > steps.length) { |
| 799 | stepCount = steps.length; |
| 800 | } |
| 801 | } |
| 802 | mNumStepDurations = stepCount; |
| 803 | mLastStepTime = elapsedRealtime; |
| 804 | } |
| 805 | |
| 806 | public void readFromParcel(Parcel in) { |
| 807 | final int N = in.readInt(); |
| 808 | mNumStepDurations = N; |
| 809 | for (int i=0; i<N; i++) { |
| 810 | mStepDurations[i] = in.readLong(); |
| 811 | } |
| 812 | } |
| 813 | |
| 814 | public void writeToParcel(Parcel out) { |
| 815 | final int N = mNumStepDurations; |
| 816 | out.writeInt(N); |
| 817 | for (int i=0; i<N; i++) { |
| 818 | out.writeLong(mStepDurations[i]); |
| 819 | } |
| 820 | } |
| 821 | } |
| 822 | |
| 823 | public static final class DailyItem { |
| 824 | public long mStartTime; |
| 825 | public long mEndTime; |
| 826 | public LevelStepTracker mDischargeSteps; |
| 827 | public LevelStepTracker mChargeSteps; |
| 828 | } |
| 829 | |
| 830 | public abstract DailyItem getDailyItemLocked(int daysAgo); |
| 831 | |
| 832 | public abstract long getCurrentDailyStartTime(); |
| 833 | |
| 834 | public abstract long getNextMinDailyDeadline(); |
| 835 | |
| 836 | public abstract long getNextMaxDailyDeadline(); |
| 837 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 838 | public final static class HistoryTag { |
| 839 | public String string; |
| 840 | public int uid; |
| 841 | |
| 842 | public int poolIdx; |
| 843 | |
| 844 | public void setTo(HistoryTag o) { |
| 845 | string = o.string; |
| 846 | uid = o.uid; |
| 847 | poolIdx = o.poolIdx; |
| 848 | } |
| 849 | |
| 850 | public void setTo(String _string, int _uid) { |
| 851 | string = _string; |
| 852 | uid = _uid; |
| 853 | poolIdx = -1; |
| 854 | } |
| 855 | |
| 856 | public void writeToParcel(Parcel dest, int flags) { |
| 857 | dest.writeString(string); |
| 858 | dest.writeInt(uid); |
| 859 | } |
| 860 | |
| 861 | public void readFromParcel(Parcel src) { |
| 862 | string = src.readString(); |
| 863 | uid = src.readInt(); |
| 864 | poolIdx = -1; |
| 865 | } |
| 866 | |
| 867 | @Override |
| 868 | public boolean equals(Object o) { |
| 869 | if (this == o) return true; |
| 870 | if (o == null || getClass() != o.getClass()) return false; |
| 871 | |
| 872 | HistoryTag that = (HistoryTag) o; |
| 873 | |
| 874 | if (uid != that.uid) return false; |
| 875 | if (!string.equals(that.string)) return false; |
| 876 | |
| 877 | return true; |
| 878 | } |
| 879 | |
| 880 | @Override |
| 881 | public int hashCode() { |
| 882 | int result = string.hashCode(); |
| 883 | result = 31 * result + uid; |
| 884 | return result; |
| 885 | } |
| 886 | } |
| 887 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 888 | /** |
| 889 | * Optional detailed information that can go into a history step. This is typically |
| 890 | * generated each time the battery level changes. |
| 891 | */ |
| 892 | public final static class HistoryStepDetails { |
| 893 | // Time (in 1/100 second) spent in user space and the kernel since the last step. |
| 894 | public int userTime; |
| 895 | public int systemTime; |
| 896 | |
| 897 | // Top three apps using CPU in the last step, with times in 1/100 second. |
| 898 | public int appCpuUid1; |
| 899 | public int appCpuUTime1; |
| 900 | public int appCpuSTime1; |
| 901 | public int appCpuUid2; |
| 902 | public int appCpuUTime2; |
| 903 | public int appCpuSTime2; |
| 904 | public int appCpuUid3; |
| 905 | public int appCpuUTime3; |
| 906 | public int appCpuSTime3; |
| 907 | |
| 908 | // Information from /proc/stat |
| 909 | public int statUserTime; |
| 910 | public int statSystemTime; |
| 911 | public int statIOWaitTime; |
| 912 | public int statIrqTime; |
| 913 | public int statSoftIrqTime; |
| 914 | public int statIdlTime; |
| 915 | |
| 916 | public HistoryStepDetails() { |
| 917 | clear(); |
| 918 | } |
| 919 | |
| 920 | public void clear() { |
| 921 | userTime = systemTime = 0; |
| 922 | appCpuUid1 = appCpuUid2 = appCpuUid3 = -1; |
| 923 | appCpuUTime1 = appCpuSTime1 = appCpuUTime2 = appCpuSTime2 |
| 924 | = appCpuUTime3 = appCpuSTime3 = 0; |
| 925 | } |
| 926 | |
| 927 | public void writeToParcel(Parcel out) { |
| 928 | out.writeInt(userTime); |
| 929 | out.writeInt(systemTime); |
| 930 | out.writeInt(appCpuUid1); |
| 931 | out.writeInt(appCpuUTime1); |
| 932 | out.writeInt(appCpuSTime1); |
| 933 | out.writeInt(appCpuUid2); |
| 934 | out.writeInt(appCpuUTime2); |
| 935 | out.writeInt(appCpuSTime2); |
| 936 | out.writeInt(appCpuUid3); |
| 937 | out.writeInt(appCpuUTime3); |
| 938 | out.writeInt(appCpuSTime3); |
| 939 | out.writeInt(statUserTime); |
| 940 | out.writeInt(statSystemTime); |
| 941 | out.writeInt(statIOWaitTime); |
| 942 | out.writeInt(statIrqTime); |
| 943 | out.writeInt(statSoftIrqTime); |
| 944 | out.writeInt(statIdlTime); |
| 945 | } |
| 946 | |
| 947 | public void readFromParcel(Parcel in) { |
| 948 | userTime = in.readInt(); |
| 949 | systemTime = in.readInt(); |
| 950 | appCpuUid1 = in.readInt(); |
| 951 | appCpuUTime1 = in.readInt(); |
| 952 | appCpuSTime1 = in.readInt(); |
| 953 | appCpuUid2 = in.readInt(); |
| 954 | appCpuUTime2 = in.readInt(); |
| 955 | appCpuSTime2 = in.readInt(); |
| 956 | appCpuUid3 = in.readInt(); |
| 957 | appCpuUTime3 = in.readInt(); |
| 958 | appCpuSTime3 = in.readInt(); |
| 959 | statUserTime = in.readInt(); |
| 960 | statSystemTime = in.readInt(); |
| 961 | statIOWaitTime = in.readInt(); |
| 962 | statIrqTime = in.readInt(); |
| 963 | statSoftIrqTime = in.readInt(); |
| 964 | statIdlTime = in.readInt(); |
| 965 | } |
| 966 | } |
| 967 | |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 968 | public final static class HistoryItem implements Parcelable { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 969 | public HistoryItem next; |
Dianne Hackborn | 9a75543 | 2014-05-15 17:05:22 -0700 | [diff] [blame] | 970 | |
| 971 | // The time of this event in milliseconds, as per SystemClock.elapsedRealtime(). |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 972 | public long time; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 973 | |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 974 | 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] | 975 | public static final byte CMD_NULL = -1; |
| 976 | public static final byte CMD_START = 4; |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 977 | public static final byte CMD_CURRENT_TIME = 5; |
| 978 | public static final byte CMD_OVERFLOW = 6; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 979 | public static final byte CMD_RESET = 7; |
Dianne Hackborn | 29cd7f1 | 2015-01-08 10:37:05 -0800 | [diff] [blame] | 980 | public static final byte CMD_SHUTDOWN = 8; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 981 | |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 982 | public byte cmd = CMD_NULL; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 983 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 984 | /** |
| 985 | * Return whether the command code is a delta data update. |
| 986 | */ |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 987 | public boolean isDeltaData() { |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 988 | return cmd == CMD_UPDATE; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 989 | } |
| 990 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 991 | public byte batteryLevel; |
| 992 | public byte batteryStatus; |
| 993 | public byte batteryHealth; |
| 994 | public byte batteryPlugType; |
| 995 | |
Sungmin Choi | c7e9e8b | 2013-01-16 12:57:36 +0900 | [diff] [blame] | 996 | public short batteryTemperature; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 997 | public char batteryVoltage; |
| 998 | |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 999 | // Constants from SCREEN_BRIGHTNESS_* |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1000 | public static final int STATE_BRIGHTNESS_SHIFT = 0; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1001 | public static final int STATE_BRIGHTNESS_MASK = 0x7; |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 1002 | // Constants from SIGNAL_STRENGTH_* |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 1003 | public static final int STATE_PHONE_SIGNAL_STRENGTH_SHIFT = 3; |
| 1004 | 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] | 1005 | // Constants from ServiceState.STATE_* |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1006 | public static final int STATE_PHONE_STATE_SHIFT = 6; |
| 1007 | 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] | 1008 | // Constants from DATA_CONNECTION_* |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1009 | public static final int STATE_DATA_CONNECTION_SHIFT = 9; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1010 | 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] | 1011 | |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 1012 | // These states always appear directly in the first int token |
| 1013 | // of a delta change; they should be ones that change relatively |
| 1014 | // frequently. |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1015 | public static final int STATE_CPU_RUNNING_FLAG = 1<<31; |
| 1016 | public static final int STATE_WAKE_LOCK_FLAG = 1<<30; |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 1017 | public static final int STATE_GPS_ON_FLAG = 1<<29; |
| 1018 | public static final int STATE_WIFI_FULL_LOCK_FLAG = 1<<28; |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 1019 | public static final int STATE_WIFI_SCAN_FLAG = 1<<27; |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 1020 | public static final int STATE_WIFI_MULTICAST_ON_FLAG = 1<<26; |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 1021 | public static final int STATE_MOBILE_RADIO_ACTIVE_FLAG = 1<<25; |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 1022 | // These are on the lower bits used for the command; if they change |
| 1023 | // we need to write another int of data. |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1024 | public static final int STATE_SENSOR_ON_FLAG = 1<<23; |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 1025 | public static final int STATE_AUDIO_ON_FLAG = 1<<22; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1026 | public static final int STATE_PHONE_SCANNING_FLAG = 1<<21; |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 1027 | public static final int STATE_SCREEN_ON_FLAG = 1<<20; |
| 1028 | public static final int STATE_BATTERY_PLUGGED_FLAG = 1<<19; |
| 1029 | public static final int STATE_PHONE_IN_CALL_FLAG = 1<<18; |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 1030 | public static final int STATE_BLUETOOTH_ON_FLAG = 1<<16; |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 1031 | |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 1032 | public static final int MOST_INTERESTING_STATES = |
| 1033 | STATE_BATTERY_PLUGGED_FLAG | STATE_SCREEN_ON_FLAG |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 1034 | | STATE_PHONE_IN_CALL_FLAG | STATE_BLUETOOTH_ON_FLAG; |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 1035 | |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1036 | public int states; |
| 1037 | |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 1038 | // Constants from WIFI_SUPPL_STATE_* |
| 1039 | public static final int STATE2_WIFI_SUPPL_STATE_SHIFT = 0; |
| 1040 | public static final int STATE2_WIFI_SUPPL_STATE_MASK = 0xf; |
| 1041 | // Values for NUM_WIFI_SIGNAL_STRENGTH_BINS |
| 1042 | public static final int STATE2_WIFI_SIGNAL_STRENGTH_SHIFT = 4; |
| 1043 | public static final int STATE2_WIFI_SIGNAL_STRENGTH_MASK = |
| 1044 | 0x7 << STATE2_WIFI_SIGNAL_STRENGTH_SHIFT; |
| 1045 | |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame^] | 1046 | public static final int STATE2_POWER_SAVE_FLAG = 1<<31; |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 1047 | public static final int STATE2_VIDEO_ON_FLAG = 1<<30; |
| 1048 | public static final int STATE2_WIFI_RUNNING_FLAG = 1<<29; |
| 1049 | public static final int STATE2_WIFI_ON_FLAG = 1<<28; |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 1050 | public static final int STATE2_FLASHLIGHT_FLAG = 1<<27; |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame^] | 1051 | public static final int STATE2_DEVICE_IDLE_FLAG = 1<<26; |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 1052 | |
| 1053 | public static final int MOST_INTERESTING_STATES2 = |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame^] | 1054 | STATE2_POWER_SAVE_FLAG | STATE2_WIFI_ON_FLAG | STATE2_DEVICE_IDLE_FLAG; |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 1055 | |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 1056 | public int states2; |
| 1057 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1058 | // The wake lock that was acquired at this point. |
| 1059 | public HistoryTag wakelockTag; |
| 1060 | |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1061 | // Kernel wakeup reason at this point. |
| 1062 | public HistoryTag wakeReasonTag; |
| 1063 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 1064 | // Non-null when there is more detailed information at this step. |
| 1065 | public HistoryStepDetails stepDetails; |
| 1066 | |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 1067 | public static final int EVENT_FLAG_START = 0x8000; |
| 1068 | public static final int EVENT_FLAG_FINISH = 0x4000; |
| 1069 | |
| 1070 | // No event in this item. |
| 1071 | public static final int EVENT_NONE = 0x0000; |
| 1072 | // Event is about a process that is running. |
| 1073 | public static final int EVENT_PROC = 0x0001; |
| 1074 | // Event is about an application package that is in the foreground. |
| 1075 | public static final int EVENT_FOREGROUND = 0x0002; |
| 1076 | // Event is about an application package that is at the top of the screen. |
| 1077 | public static final int EVENT_TOP = 0x0003; |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 1078 | // Event is about active sync operations. |
Dianne Hackborn | a1f1a3c | 2014-02-24 18:12:28 -0800 | [diff] [blame] | 1079 | public static final int EVENT_SYNC = 0x0004; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 1080 | // Events for all additional wake locks aquired/release within a wake block. |
| 1081 | // These are not generated by default. |
| 1082 | public static final int EVENT_WAKE_LOCK = 0x0005; |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 1083 | // Event is about an application executing a scheduled job. |
| 1084 | public static final int EVENT_JOB = 0x0006; |
| 1085 | // Events for users running. |
| 1086 | public static final int EVENT_USER_RUNNING = 0x0007; |
| 1087 | // Events for foreground user. |
| 1088 | public static final int EVENT_USER_FOREGROUND = 0x0008; |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame^] | 1089 | // Event for connectivity changed. |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 1090 | public static final int EVENT_CONNECTIVITY_CHANGED = 0x0009; |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame^] | 1091 | // Event for significant motion taking us out of idle mode. |
| 1092 | public static final int EVENT_SIGNIFICANT_MOTION = 0x000a; |
| 1093 | // Event for becoming active taking us out of idle mode. |
| 1094 | public static final int EVENT_ACTIVE = 0x000b; |
| 1095 | // Event for a package being installed. |
| 1096 | public static final int EVENT_PACKAGE_INSTALLED = 0x000c; |
| 1097 | // Event for a package being uninstalled. |
| 1098 | public static final int EVENT_PACKAGE_UNINSTALLED = 0x000d; |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 1099 | // Number of event types. |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame^] | 1100 | public static final int EVENT_COUNT = 0x000e; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 1101 | // Mask to extract out only the type part of the event. |
| 1102 | 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] | 1103 | |
| 1104 | public static final int EVENT_PROC_START = EVENT_PROC | EVENT_FLAG_START; |
| 1105 | public static final int EVENT_PROC_FINISH = EVENT_PROC | EVENT_FLAG_FINISH; |
| 1106 | public static final int EVENT_FOREGROUND_START = EVENT_FOREGROUND | EVENT_FLAG_START; |
| 1107 | public static final int EVENT_FOREGROUND_FINISH = EVENT_FOREGROUND | EVENT_FLAG_FINISH; |
| 1108 | public static final int EVENT_TOP_START = EVENT_TOP | EVENT_FLAG_START; |
| 1109 | public static final int EVENT_TOP_FINISH = EVENT_TOP | EVENT_FLAG_FINISH; |
Dianne Hackborn | a1f1a3c | 2014-02-24 18:12:28 -0800 | [diff] [blame] | 1110 | public static final int EVENT_SYNC_START = EVENT_SYNC | EVENT_FLAG_START; |
| 1111 | public static final int EVENT_SYNC_FINISH = EVENT_SYNC | EVENT_FLAG_FINISH; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 1112 | public static final int EVENT_WAKE_LOCK_START = EVENT_WAKE_LOCK | EVENT_FLAG_START; |
| 1113 | 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] | 1114 | public static final int EVENT_JOB_START = EVENT_JOB | EVENT_FLAG_START; |
| 1115 | public static final int EVENT_JOB_FINISH = EVENT_JOB | EVENT_FLAG_FINISH; |
| 1116 | public static final int EVENT_USER_RUNNING_START = EVENT_USER_RUNNING | EVENT_FLAG_START; |
| 1117 | public static final int EVENT_USER_RUNNING_FINISH = EVENT_USER_RUNNING | EVENT_FLAG_FINISH; |
| 1118 | public static final int EVENT_USER_FOREGROUND_START = |
| 1119 | EVENT_USER_FOREGROUND | EVENT_FLAG_START; |
| 1120 | public static final int EVENT_USER_FOREGROUND_FINISH = |
| 1121 | EVENT_USER_FOREGROUND | EVENT_FLAG_FINISH; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1122 | |
| 1123 | // For CMD_EVENT. |
| 1124 | public int eventCode; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1125 | public HistoryTag eventTag; |
| 1126 | |
Dianne Hackborn | 9a75543 | 2014-05-15 17:05:22 -0700 | [diff] [blame] | 1127 | // 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] | 1128 | public long currentTime; |
| 1129 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1130 | // Meta-data when reading. |
| 1131 | public int numReadInts; |
| 1132 | |
| 1133 | // Pre-allocated objects. |
| 1134 | public final HistoryTag localWakelockTag = new HistoryTag(); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1135 | public final HistoryTag localWakeReasonTag = new HistoryTag(); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1136 | public final HistoryTag localEventTag = new HistoryTag(); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1137 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1138 | public HistoryItem() { |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1139 | } |
| 1140 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1141 | public HistoryItem(long time, Parcel src) { |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1142 | this.time = time; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1143 | numReadInts = 2; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 1144 | readFromParcel(src); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1145 | } |
| 1146 | |
| 1147 | public int describeContents() { |
| 1148 | return 0; |
| 1149 | } |
| 1150 | |
| 1151 | public void writeToParcel(Parcel dest, int flags) { |
| 1152 | dest.writeLong(time); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1153 | int bat = (((int)cmd)&0xff) |
| 1154 | | ((((int)batteryLevel)<<8)&0xff00) |
| 1155 | | ((((int)batteryStatus)<<16)&0xf0000) |
| 1156 | | ((((int)batteryHealth)<<20)&0xf00000) |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1157 | | ((((int)batteryPlugType)<<24)&0xf000000) |
| 1158 | | (wakelockTag != null ? 0x10000000 : 0) |
| 1159 | | (wakeReasonTag != null ? 0x20000000 : 0) |
| 1160 | | (eventCode != EVENT_NONE ? 0x40000000 : 0); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1161 | dest.writeInt(bat); |
| 1162 | bat = (((int)batteryTemperature)&0xffff) |
| 1163 | | ((((int)batteryVoltage)<<16)&0xffff0000); |
| 1164 | dest.writeInt(bat); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1165 | dest.writeInt(states); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1166 | dest.writeInt(states2); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1167 | if (wakelockTag != null) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1168 | wakelockTag.writeToParcel(dest, flags); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1169 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1170 | if (wakeReasonTag != null) { |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1171 | wakeReasonTag.writeToParcel(dest, flags); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1172 | } |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 1173 | if (eventCode != EVENT_NONE) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1174 | dest.writeInt(eventCode); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1175 | eventTag.writeToParcel(dest, flags); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1176 | } |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 1177 | if (cmd == CMD_CURRENT_TIME || cmd == CMD_RESET) { |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1178 | dest.writeLong(currentTime); |
| 1179 | } |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1180 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 1181 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1182 | public void readFromParcel(Parcel src) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1183 | int start = src.dataPosition(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 1184 | int bat = src.readInt(); |
| 1185 | cmd = (byte)(bat&0xff); |
| 1186 | batteryLevel = (byte)((bat>>8)&0xff); |
| 1187 | batteryStatus = (byte)((bat>>16)&0xf); |
| 1188 | batteryHealth = (byte)((bat>>20)&0xf); |
| 1189 | batteryPlugType = (byte)((bat>>24)&0xf); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1190 | int bat2 = src.readInt(); |
| 1191 | batteryTemperature = (short)(bat2&0xffff); |
| 1192 | batteryVoltage = (char)((bat2>>16)&0xffff); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 1193 | states = src.readInt(); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1194 | states2 = src.readInt(); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1195 | if ((bat&0x10000000) != 0) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1196 | wakelockTag = localWakelockTag; |
| 1197 | wakelockTag.readFromParcel(src); |
| 1198 | } else { |
| 1199 | wakelockTag = null; |
| 1200 | } |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1201 | if ((bat&0x20000000) != 0) { |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1202 | wakeReasonTag = localWakeReasonTag; |
| 1203 | wakeReasonTag.readFromParcel(src); |
| 1204 | } else { |
| 1205 | wakeReasonTag = null; |
| 1206 | } |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1207 | if ((bat&0x40000000) != 0) { |
| 1208 | eventCode = src.readInt(); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1209 | eventTag = localEventTag; |
| 1210 | eventTag.readFromParcel(src); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1211 | } else { |
| 1212 | eventCode = EVENT_NONE; |
| 1213 | eventTag = null; |
| 1214 | } |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 1215 | if (cmd == CMD_CURRENT_TIME || cmd == CMD_RESET) { |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1216 | currentTime = src.readLong(); |
| 1217 | } else { |
| 1218 | currentTime = 0; |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 1219 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1220 | numReadInts += (src.dataPosition()-start)/4; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 1221 | } |
| 1222 | |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 1223 | public void clear() { |
| 1224 | time = 0; |
| 1225 | cmd = CMD_NULL; |
| 1226 | batteryLevel = 0; |
| 1227 | batteryStatus = 0; |
| 1228 | batteryHealth = 0; |
| 1229 | batteryPlugType = 0; |
| 1230 | batteryTemperature = 0; |
| 1231 | batteryVoltage = 0; |
| 1232 | states = 0; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1233 | states2 = 0; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1234 | wakelockTag = null; |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1235 | wakeReasonTag = null; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1236 | eventCode = EVENT_NONE; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1237 | eventTag = null; |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 1238 | } |
| 1239 | |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 1240 | public void setTo(HistoryItem o) { |
| 1241 | time = o.time; |
| 1242 | cmd = o.cmd; |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 1243 | setToCommon(o); |
| 1244 | } |
| 1245 | |
| 1246 | public void setTo(long time, byte cmd, HistoryItem o) { |
| 1247 | this.time = time; |
| 1248 | this.cmd = cmd; |
| 1249 | setToCommon(o); |
| 1250 | } |
| 1251 | |
| 1252 | private void setToCommon(HistoryItem o) { |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 1253 | batteryLevel = o.batteryLevel; |
| 1254 | batteryStatus = o.batteryStatus; |
| 1255 | batteryHealth = o.batteryHealth; |
| 1256 | batteryPlugType = o.batteryPlugType; |
| 1257 | batteryTemperature = o.batteryTemperature; |
| 1258 | batteryVoltage = o.batteryVoltage; |
| 1259 | states = o.states; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1260 | states2 = o.states2; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1261 | if (o.wakelockTag != null) { |
| 1262 | wakelockTag = localWakelockTag; |
| 1263 | wakelockTag.setTo(o.wakelockTag); |
| 1264 | } else { |
| 1265 | wakelockTag = null; |
| 1266 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1267 | if (o.wakeReasonTag != null) { |
| 1268 | wakeReasonTag = localWakeReasonTag; |
| 1269 | wakeReasonTag.setTo(o.wakeReasonTag); |
| 1270 | } else { |
| 1271 | wakeReasonTag = null; |
| 1272 | } |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1273 | eventCode = o.eventCode; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1274 | if (o.eventTag != null) { |
| 1275 | eventTag = localEventTag; |
| 1276 | eventTag.setTo(o.eventTag); |
| 1277 | } else { |
| 1278 | eventTag = null; |
| 1279 | } |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1280 | currentTime = o.currentTime; |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 1281 | } |
| 1282 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1283 | public boolean sameNonEvent(HistoryItem o) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 1284 | return batteryLevel == o.batteryLevel |
| 1285 | && batteryStatus == o.batteryStatus |
| 1286 | && batteryHealth == o.batteryHealth |
| 1287 | && batteryPlugType == o.batteryPlugType |
| 1288 | && batteryTemperature == o.batteryTemperature |
| 1289 | && batteryVoltage == o.batteryVoltage |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1290 | && states == o.states |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1291 | && states2 == o.states2 |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1292 | && currentTime == o.currentTime; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 1293 | } |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1294 | |
| 1295 | public boolean same(HistoryItem o) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1296 | if (!sameNonEvent(o) || eventCode != o.eventCode) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1297 | return false; |
| 1298 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1299 | if (wakelockTag != o.wakelockTag) { |
| 1300 | if (wakelockTag == null || o.wakelockTag == null) { |
| 1301 | return false; |
| 1302 | } |
| 1303 | if (!wakelockTag.equals(o.wakelockTag)) { |
| 1304 | return false; |
| 1305 | } |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1306 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1307 | if (wakeReasonTag != o.wakeReasonTag) { |
| 1308 | if (wakeReasonTag == null || o.wakeReasonTag == null) { |
| 1309 | return false; |
| 1310 | } |
| 1311 | if (!wakeReasonTag.equals(o.wakeReasonTag)) { |
| 1312 | return false; |
| 1313 | } |
| 1314 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1315 | if (eventTag != o.eventTag) { |
| 1316 | if (eventTag == null || o.eventTag == null) { |
| 1317 | return false; |
| 1318 | } |
| 1319 | if (!eventTag.equals(o.eventTag)) { |
| 1320 | return false; |
| 1321 | } |
| 1322 | } |
| 1323 | return true; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1324 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1325 | } |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 1326 | |
| 1327 | public final static class HistoryEventTracker { |
| 1328 | private final HashMap<String, SparseIntArray>[] mActiveEvents |
| 1329 | = (HashMap<String, SparseIntArray>[]) new HashMap[HistoryItem.EVENT_COUNT]; |
| 1330 | |
| 1331 | public boolean updateState(int code, String name, int uid, int poolIdx) { |
| 1332 | if ((code&HistoryItem.EVENT_FLAG_START) != 0) { |
| 1333 | int idx = code&HistoryItem.EVENT_TYPE_MASK; |
| 1334 | HashMap<String, SparseIntArray> active = mActiveEvents[idx]; |
| 1335 | if (active == null) { |
| 1336 | active = new HashMap<String, SparseIntArray>(); |
| 1337 | mActiveEvents[idx] = active; |
| 1338 | } |
| 1339 | SparseIntArray uids = active.get(name); |
| 1340 | if (uids == null) { |
| 1341 | uids = new SparseIntArray(); |
| 1342 | active.put(name, uids); |
| 1343 | } |
| 1344 | if (uids.indexOfKey(uid) >= 0) { |
| 1345 | // Already set, nothing to do! |
| 1346 | return false; |
| 1347 | } |
| 1348 | uids.put(uid, poolIdx); |
| 1349 | } else if ((code&HistoryItem.EVENT_FLAG_FINISH) != 0) { |
| 1350 | int idx = code&HistoryItem.EVENT_TYPE_MASK; |
| 1351 | HashMap<String, SparseIntArray> active = mActiveEvents[idx]; |
| 1352 | if (active == null) { |
| 1353 | // not currently active, nothing to do. |
| 1354 | return false; |
| 1355 | } |
| 1356 | SparseIntArray uids = active.get(name); |
| 1357 | if (uids == null) { |
| 1358 | // not currently active, nothing to do. |
| 1359 | return false; |
| 1360 | } |
| 1361 | idx = uids.indexOfKey(uid); |
| 1362 | if (idx < 0) { |
| 1363 | // not currently active, nothing to do. |
| 1364 | return false; |
| 1365 | } |
| 1366 | uids.removeAt(idx); |
| 1367 | if (uids.size() <= 0) { |
| 1368 | active.remove(name); |
| 1369 | } |
| 1370 | } |
| 1371 | return true; |
| 1372 | } |
| 1373 | |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 1374 | public void removeEvents(int code) { |
| 1375 | int idx = code&HistoryItem.EVENT_TYPE_MASK; |
| 1376 | mActiveEvents[idx] = null; |
| 1377 | } |
| 1378 | |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 1379 | public HashMap<String, SparseIntArray> getStateForEvent(int code) { |
| 1380 | return mActiveEvents[code]; |
| 1381 | } |
| 1382 | } |
| 1383 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1384 | public static final class BitDescription { |
| 1385 | public final int mask; |
| 1386 | public final int shift; |
| 1387 | public final String name; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1388 | public final String shortName; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1389 | public final String[] values; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1390 | public final String[] shortValues; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1391 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1392 | public BitDescription(int mask, String name, String shortName) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1393 | this.mask = mask; |
| 1394 | this.shift = -1; |
| 1395 | this.name = name; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1396 | this.shortName = shortName; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1397 | this.values = null; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1398 | this.shortValues = null; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1399 | } |
| 1400 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1401 | public BitDescription(int mask, int shift, String name, String shortName, |
| 1402 | String[] values, String[] shortValues) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1403 | this.mask = mask; |
| 1404 | this.shift = shift; |
| 1405 | this.name = name; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1406 | this.shortName = shortName; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1407 | this.values = values; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1408 | this.shortValues = shortValues; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1409 | } |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1410 | } |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 1411 | |
Dianne Hackborn | fc06413 | 2014-06-02 12:42:12 -0700 | [diff] [blame] | 1412 | /** |
| 1413 | * Don't allow any more batching in to the current history event. This |
| 1414 | * is called when printing partial histories, so to ensure that the next |
| 1415 | * history event will go in to a new batch after what was printed in the |
| 1416 | * last partial history. |
| 1417 | */ |
| 1418 | public abstract void commitCurrentHistoryBatchLocked(); |
| 1419 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1420 | public abstract int getHistoryTotalSize(); |
| 1421 | |
| 1422 | public abstract int getHistoryUsedSize(); |
| 1423 | |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 1424 | public abstract boolean startIteratingHistoryLocked(); |
| 1425 | |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 1426 | public abstract int getHistoryStringPoolSize(); |
| 1427 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1428 | public abstract int getHistoryStringPoolBytes(); |
| 1429 | |
| 1430 | public abstract String getHistoryTagPoolString(int index); |
| 1431 | |
| 1432 | public abstract int getHistoryTagPoolUid(int index); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 1433 | |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 1434 | public abstract boolean getNextHistoryLocked(HistoryItem out); |
| 1435 | |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 1436 | public abstract void finishIteratingHistoryLocked(); |
| 1437 | |
| 1438 | public abstract boolean startIteratingOldHistoryLocked(); |
| 1439 | |
| 1440 | public abstract boolean getNextOldHistoryLocked(HistoryItem out); |
| 1441 | |
| 1442 | public abstract void finishIteratingOldHistoryLocked(); |
| 1443 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1444 | /** |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 1445 | * Return the base time offset for the battery history. |
| 1446 | */ |
| 1447 | public abstract long getHistoryBaseTime(); |
| 1448 | |
| 1449 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1450 | * Returns the number of times the device has been started. |
| 1451 | */ |
| 1452 | public abstract int getStartCount(); |
| 1453 | |
| 1454 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 1455 | * 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] | 1456 | * running on battery. |
| 1457 | * |
| 1458 | * {@hide} |
| 1459 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1460 | public abstract long getScreenOnTime(long elapsedRealtimeUs, int which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1461 | |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 1462 | /** |
| 1463 | * Returns the number of times the screen was turned on. |
| 1464 | * |
| 1465 | * {@hide} |
| 1466 | */ |
| 1467 | public abstract int getScreenOnCount(int which); |
| 1468 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 1469 | public abstract long getInteractiveTime(long elapsedRealtimeUs, int which); |
| 1470 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1471 | public static final int SCREEN_BRIGHTNESS_DARK = 0; |
| 1472 | public static final int SCREEN_BRIGHTNESS_DIM = 1; |
| 1473 | public static final int SCREEN_BRIGHTNESS_MEDIUM = 2; |
| 1474 | public static final int SCREEN_BRIGHTNESS_LIGHT = 3; |
| 1475 | public static final int SCREEN_BRIGHTNESS_BRIGHT = 4; |
| 1476 | |
| 1477 | static final String[] SCREEN_BRIGHTNESS_NAMES = { |
| 1478 | "dark", "dim", "medium", "light", "bright" |
| 1479 | }; |
| 1480 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1481 | static final String[] SCREEN_BRIGHTNESS_SHORT_NAMES = { |
| 1482 | "0", "1", "2", "3", "4" |
| 1483 | }; |
| 1484 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1485 | public static final int NUM_SCREEN_BRIGHTNESS_BINS = 5; |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 1486 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1487 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 1488 | * Returns the time in microseconds that the screen has been on with |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1489 | * the given brightness |
| 1490 | * |
| 1491 | * {@hide} |
| 1492 | */ |
| 1493 | public abstract long getScreenBrightnessTime(int brightnessBin, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1494 | long elapsedRealtimeUs, int which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1495 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1496 | /** |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame^] | 1497 | * Returns the time in microseconds that power save mode has been enabled while the device was |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 1498 | * running on battery. |
| 1499 | * |
| 1500 | * {@hide} |
| 1501 | */ |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame^] | 1502 | public abstract long getPowerSaveModeEnabledTime(long elapsedRealtimeUs, int which); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 1503 | |
| 1504 | /** |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame^] | 1505 | * Returns the number of times that power save mode was enabled. |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 1506 | * |
| 1507 | * {@hide} |
| 1508 | */ |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame^] | 1509 | public abstract int getPowerSaveModeEnabledCount(int which); |
| 1510 | |
| 1511 | /** |
| 1512 | * Returns the time in microseconds that device has been in idle mode while |
| 1513 | * running on battery. |
| 1514 | * |
| 1515 | * {@hide} |
| 1516 | */ |
| 1517 | public abstract long getDeviceIdleModeEnabledTime(long elapsedRealtimeUs, int which); |
| 1518 | |
| 1519 | /** |
| 1520 | * Returns the number of times that the devie has gone in to idle mode. |
| 1521 | * |
| 1522 | * {@hide} |
| 1523 | */ |
| 1524 | public abstract int getDeviceIdleModeEnabledCount(int which); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 1525 | |
| 1526 | /** |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 1527 | * Returns the number of times that connectivity state changed. |
| 1528 | * |
| 1529 | * {@hide} |
| 1530 | */ |
| 1531 | public abstract int getNumConnectivityChange(int which); |
| 1532 | |
| 1533 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 1534 | * 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] | 1535 | * running on battery. |
| 1536 | * |
| 1537 | * {@hide} |
| 1538 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1539 | public abstract long getPhoneOnTime(long elapsedRealtimeUs, int which); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 1540 | |
| 1541 | /** |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 1542 | * Returns the number of times a phone call was activated. |
| 1543 | * |
| 1544 | * {@hide} |
| 1545 | */ |
| 1546 | public abstract int getPhoneOnCount(int which); |
| 1547 | |
| 1548 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 1549 | * Returns the time in microseconds that the phone has been running with |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 1550 | * the given signal strength. |
| 1551 | * |
| 1552 | * {@hide} |
| 1553 | */ |
| 1554 | public abstract long getPhoneSignalStrengthTime(int strengthBin, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1555 | long elapsedRealtimeUs, int which); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 1556 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1557 | /** |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 1558 | * Returns the time in microseconds that the phone has been trying to |
| 1559 | * acquire a signal. |
| 1560 | * |
| 1561 | * {@hide} |
| 1562 | */ |
| 1563 | public abstract long getPhoneSignalScanningTime( |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1564 | long elapsedRealtimeUs, int which); |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 1565 | |
| 1566 | /** |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1567 | * Returns the number of times the phone has entered the given signal strength. |
| 1568 | * |
| 1569 | * {@hide} |
| 1570 | */ |
| 1571 | public abstract int getPhoneSignalStrengthCount(int strengthBin, int which); |
| 1572 | |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 1573 | /** |
| 1574 | * Returns the time in microseconds that the mobile network has been active |
| 1575 | * (in a high power state). |
| 1576 | * |
| 1577 | * {@hide} |
| 1578 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1579 | public abstract long getMobileRadioActiveTime(long elapsedRealtimeUs, int which); |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 1580 | |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 1581 | /** |
| 1582 | * Returns the number of times that the mobile network has transitioned to the |
| 1583 | * active state. |
| 1584 | * |
| 1585 | * {@hide} |
| 1586 | */ |
| 1587 | public abstract int getMobileRadioActiveCount(int which); |
| 1588 | |
| 1589 | /** |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1590 | * Returns the time in microseconds that is the difference between the mobile radio |
| 1591 | * time we saw based on the elapsed timestamp when going down vs. the given time stamp |
| 1592 | * from the radio. |
| 1593 | * |
| 1594 | * {@hide} |
| 1595 | */ |
| 1596 | public abstract long getMobileRadioActiveAdjustedTime(int which); |
| 1597 | |
| 1598 | /** |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 1599 | * Returns the time in microseconds that the mobile network has been active |
| 1600 | * (in a high power state) but not being able to blame on an app. |
| 1601 | * |
| 1602 | * {@hide} |
| 1603 | */ |
| 1604 | public abstract long getMobileRadioActiveUnknownTime(int which); |
| 1605 | |
| 1606 | /** |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 1607 | * 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] | 1608 | * |
| 1609 | * {@hide} |
| 1610 | */ |
| 1611 | public abstract int getMobileRadioActiveUnknownCount(int which); |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 1612 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 1613 | public static final int DATA_CONNECTION_NONE = 0; |
| 1614 | public static final int DATA_CONNECTION_GPRS = 1; |
| 1615 | public static final int DATA_CONNECTION_EDGE = 2; |
| 1616 | public static final int DATA_CONNECTION_UMTS = 3; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1617 | public static final int DATA_CONNECTION_CDMA = 4; |
| 1618 | public static final int DATA_CONNECTION_EVDO_0 = 5; |
| 1619 | public static final int DATA_CONNECTION_EVDO_A = 6; |
| 1620 | public static final int DATA_CONNECTION_1xRTT = 7; |
| 1621 | public static final int DATA_CONNECTION_HSDPA = 8; |
| 1622 | public static final int DATA_CONNECTION_HSUPA = 9; |
| 1623 | public static final int DATA_CONNECTION_HSPA = 10; |
| 1624 | public static final int DATA_CONNECTION_IDEN = 11; |
| 1625 | public static final int DATA_CONNECTION_EVDO_B = 12; |
Robert Greenwalt | 962a990 | 2010-11-02 11:10:25 -0700 | [diff] [blame] | 1626 | public static final int DATA_CONNECTION_LTE = 13; |
| 1627 | public static final int DATA_CONNECTION_EHRPD = 14; |
Patrick Tjin | b71703c | 2013-11-06 09:27:03 -0800 | [diff] [blame] | 1628 | public static final int DATA_CONNECTION_HSPAP = 15; |
| 1629 | public static final int DATA_CONNECTION_OTHER = 16; |
Robert Greenwalt | 962a990 | 2010-11-02 11:10:25 -0700 | [diff] [blame] | 1630 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 1631 | static final String[] DATA_CONNECTION_NAMES = { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1632 | "none", "gprs", "edge", "umts", "cdma", "evdo_0", "evdo_A", |
Robert Greenwalt | 962a990 | 2010-11-02 11:10:25 -0700 | [diff] [blame] | 1633 | "1xrtt", "hsdpa", "hsupa", "hspa", "iden", "evdo_b", "lte", |
Patrick Tjin | b71703c | 2013-11-06 09:27:03 -0800 | [diff] [blame] | 1634 | "ehrpd", "hspap", "other" |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 1635 | }; |
| 1636 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1637 | public static final int NUM_DATA_CONNECTION_TYPES = DATA_CONNECTION_OTHER+1; |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 1638 | |
| 1639 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 1640 | * Returns the time in microseconds that the phone has been running with |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 1641 | * the given data connection. |
| 1642 | * |
| 1643 | * {@hide} |
| 1644 | */ |
| 1645 | public abstract long getPhoneDataConnectionTime(int dataType, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1646 | long elapsedRealtimeUs, int which); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 1647 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1648 | /** |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1649 | * Returns the number of times the phone has entered the given data |
| 1650 | * connection type. |
| 1651 | * |
| 1652 | * {@hide} |
| 1653 | */ |
| 1654 | public abstract int getPhoneDataConnectionCount(int dataType, int which); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1655 | |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 1656 | public static final int WIFI_SUPPL_STATE_INVALID = 0; |
| 1657 | public static final int WIFI_SUPPL_STATE_DISCONNECTED = 1; |
| 1658 | public static final int WIFI_SUPPL_STATE_INTERFACE_DISABLED = 2; |
| 1659 | public static final int WIFI_SUPPL_STATE_INACTIVE = 3; |
| 1660 | public static final int WIFI_SUPPL_STATE_SCANNING = 4; |
| 1661 | public static final int WIFI_SUPPL_STATE_AUTHENTICATING = 5; |
| 1662 | public static final int WIFI_SUPPL_STATE_ASSOCIATING = 6; |
| 1663 | public static final int WIFI_SUPPL_STATE_ASSOCIATED = 7; |
| 1664 | public static final int WIFI_SUPPL_STATE_FOUR_WAY_HANDSHAKE = 8; |
| 1665 | public static final int WIFI_SUPPL_STATE_GROUP_HANDSHAKE = 9; |
| 1666 | public static final int WIFI_SUPPL_STATE_COMPLETED = 10; |
| 1667 | public static final int WIFI_SUPPL_STATE_DORMANT = 11; |
| 1668 | public static final int WIFI_SUPPL_STATE_UNINITIALIZED = 12; |
| 1669 | |
| 1670 | public static final int NUM_WIFI_SUPPL_STATES = WIFI_SUPPL_STATE_UNINITIALIZED+1; |
| 1671 | |
| 1672 | static final String[] WIFI_SUPPL_STATE_NAMES = { |
| 1673 | "invalid", "disconn", "disabled", "inactive", "scanning", |
| 1674 | "authenticating", "associating", "associated", "4-way-handshake", |
| 1675 | "group-handshake", "completed", "dormant", "uninit" |
| 1676 | }; |
| 1677 | |
| 1678 | static final String[] WIFI_SUPPL_STATE_SHORT_NAMES = { |
| 1679 | "inv", "dsc", "dis", "inact", "scan", |
| 1680 | "auth", "ascing", "asced", "4-way", |
| 1681 | "group", "compl", "dorm", "uninit" |
| 1682 | }; |
| 1683 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1684 | public static final BitDescription[] HISTORY_STATE_DESCRIPTIONS |
| 1685 | = new BitDescription[] { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1686 | new BitDescription(HistoryItem.STATE_CPU_RUNNING_FLAG, "running", "r"), |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 1687 | new BitDescription(HistoryItem.STATE_WAKE_LOCK_FLAG, "wake_lock", "w"), |
| 1688 | new BitDescription(HistoryItem.STATE_SENSOR_ON_FLAG, "sensor", "s"), |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1689 | new BitDescription(HistoryItem.STATE_GPS_ON_FLAG, "gps", "g"), |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1690 | new BitDescription(HistoryItem.STATE_WIFI_FULL_LOCK_FLAG, "wifi_full_lock", "Wl"), |
| 1691 | new BitDescription(HistoryItem.STATE_WIFI_SCAN_FLAG, "wifi_scan", "Ws"), |
| 1692 | new BitDescription(HistoryItem.STATE_WIFI_MULTICAST_ON_FLAG, "wifi_multicast", "Wm"), |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 1693 | new BitDescription(HistoryItem.STATE_MOBILE_RADIO_ACTIVE_FLAG, "mobile_radio", "Pr"), |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 1694 | new BitDescription(HistoryItem.STATE_PHONE_SCANNING_FLAG, "phone_scanning", "Psc"), |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1695 | new BitDescription(HistoryItem.STATE_AUDIO_ON_FLAG, "audio", "a"), |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 1696 | new BitDescription(HistoryItem.STATE_SCREEN_ON_FLAG, "screen", "S"), |
| 1697 | new BitDescription(HistoryItem.STATE_BATTERY_PLUGGED_FLAG, "plugged", "BP"), |
| 1698 | new BitDescription(HistoryItem.STATE_PHONE_IN_CALL_FLAG, "phone_in_call", "Pcl"), |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 1699 | new BitDescription(HistoryItem.STATE_BLUETOOTH_ON_FLAG, "bluetooth", "b"), |
| 1700 | new BitDescription(HistoryItem.STATE_DATA_CONNECTION_MASK, |
| 1701 | HistoryItem.STATE_DATA_CONNECTION_SHIFT, "data_conn", "Pcn", |
| 1702 | DATA_CONNECTION_NAMES, DATA_CONNECTION_NAMES), |
| 1703 | new BitDescription(HistoryItem.STATE_PHONE_STATE_MASK, |
| 1704 | HistoryItem.STATE_PHONE_STATE_SHIFT, "phone_state", "Pst", |
| 1705 | new String[] {"in", "out", "emergency", "off"}, |
| 1706 | new String[] {"in", "out", "em", "off"}), |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 1707 | new BitDescription(HistoryItem.STATE_PHONE_SIGNAL_STRENGTH_MASK, |
| 1708 | HistoryItem.STATE_PHONE_SIGNAL_STRENGTH_SHIFT, "phone_signal_strength", "Pss", |
| 1709 | SignalStrength.SIGNAL_STRENGTH_NAMES, |
| 1710 | new String[] { "0", "1", "2", "3", "4" }), |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 1711 | new BitDescription(HistoryItem.STATE_BRIGHTNESS_MASK, |
| 1712 | HistoryItem.STATE_BRIGHTNESS_SHIFT, "brightness", "Sb", |
| 1713 | SCREEN_BRIGHTNESS_NAMES, SCREEN_BRIGHTNESS_SHORT_NAMES), |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1714 | }; |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1715 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1716 | public static final BitDescription[] HISTORY_STATE2_DESCRIPTIONS |
| 1717 | = new BitDescription[] { |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame^] | 1718 | new BitDescription(HistoryItem.STATE2_POWER_SAVE_FLAG, "power_save", "ps"), |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 1719 | new BitDescription(HistoryItem.STATE2_VIDEO_ON_FLAG, "video", "v"), |
| 1720 | new BitDescription(HistoryItem.STATE2_WIFI_RUNNING_FLAG, "wifi_running", "Wr"), |
| 1721 | new BitDescription(HistoryItem.STATE2_WIFI_ON_FLAG, "wifi", "W"), |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 1722 | new BitDescription(HistoryItem.STATE2_FLASHLIGHT_FLAG, "flashlight", "fl"), |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame^] | 1723 | new BitDescription(HistoryItem.STATE2_DEVICE_IDLE_FLAG, "device_idle", "di"), |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 1724 | new BitDescription(HistoryItem.STATE2_WIFI_SIGNAL_STRENGTH_MASK, |
| 1725 | HistoryItem.STATE2_WIFI_SIGNAL_STRENGTH_SHIFT, "wifi_signal_strength", "Wss", |
| 1726 | new String[] { "0", "1", "2", "3", "4" }, |
| 1727 | new String[] { "0", "1", "2", "3", "4" }), |
| 1728 | new BitDescription(HistoryItem.STATE2_WIFI_SUPPL_STATE_MASK, |
| 1729 | HistoryItem.STATE2_WIFI_SUPPL_STATE_SHIFT, "wifi_suppl", "Wsp", |
| 1730 | WIFI_SUPPL_STATE_NAMES, WIFI_SUPPL_STATE_SHORT_NAMES), |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1731 | }; |
| 1732 | |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 1733 | public static final String[] HISTORY_EVENT_NAMES = new String[] { |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame^] | 1734 | "null", "proc", "fg", "top", "sync", "wake_lock_in", "job", "user", "userfg", "conn", |
| 1735 | "motion", "active", "pkginst", "pkgunin" |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 1736 | }; |
| 1737 | |
| 1738 | public static final String[] HISTORY_EVENT_CHECKIN_NAMES = new String[] { |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame^] | 1739 | "Enl", "Epr", "Efg", "Etp", "Esy", "Ewl", "Ejb", "Eur", "Euf", "Ecn", |
| 1740 | "Esm", "Eac", "Epi", "Epu" |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 1741 | }; |
| 1742 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1743 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 1744 | * 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] | 1745 | * running on battery. |
| 1746 | * |
| 1747 | * {@hide} |
| 1748 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1749 | public abstract long getWifiOnTime(long elapsedRealtimeUs, int which); |
Eric Shienbrood | d4c5f89 | 2009-03-24 18:13:20 -0700 | [diff] [blame] | 1750 | |
| 1751 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 1752 | * 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] | 1753 | * been in the running state while the device was running on battery. |
| 1754 | * |
| 1755 | * {@hide} |
| 1756 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1757 | public abstract long getGlobalWifiRunningTime(long elapsedRealtimeUs, int which); |
Eric Shienbrood | d4c5f89 | 2009-03-24 18:13:20 -0700 | [diff] [blame] | 1758 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 1759 | public static final int WIFI_STATE_OFF = 0; |
| 1760 | public static final int WIFI_STATE_OFF_SCANNING = 1; |
| 1761 | public static final int WIFI_STATE_ON_NO_NETWORKS = 2; |
| 1762 | public static final int WIFI_STATE_ON_DISCONNECTED = 3; |
| 1763 | public static final int WIFI_STATE_ON_CONNECTED_STA = 4; |
| 1764 | public static final int WIFI_STATE_ON_CONNECTED_P2P = 5; |
| 1765 | public static final int WIFI_STATE_ON_CONNECTED_STA_P2P = 6; |
| 1766 | public static final int WIFI_STATE_SOFT_AP = 7; |
| 1767 | |
| 1768 | static final String[] WIFI_STATE_NAMES = { |
| 1769 | "off", "scanning", "no_net", "disconn", |
| 1770 | "sta", "p2p", "sta_p2p", "soft_ap" |
| 1771 | }; |
| 1772 | |
| 1773 | public static final int NUM_WIFI_STATES = WIFI_STATE_SOFT_AP+1; |
| 1774 | |
| 1775 | /** |
| 1776 | * Returns the time in microseconds that WiFi has been running in the given state. |
| 1777 | * |
| 1778 | * {@hide} |
| 1779 | */ |
| 1780 | public abstract long getWifiStateTime(int wifiState, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1781 | long elapsedRealtimeUs, int which); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 1782 | |
| 1783 | /** |
| 1784 | * Returns the number of times that WiFi has entered the given state. |
| 1785 | * |
| 1786 | * {@hide} |
| 1787 | */ |
| 1788 | public abstract int getWifiStateCount(int wifiState, int which); |
| 1789 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 1790 | /** |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 1791 | * Returns the time in microseconds that the wifi supplicant has been |
| 1792 | * in a given state. |
| 1793 | * |
| 1794 | * {@hide} |
| 1795 | */ |
| 1796 | public abstract long getWifiSupplStateTime(int state, long elapsedRealtimeUs, int which); |
| 1797 | |
| 1798 | /** |
| 1799 | * Returns the number of times that the wifi supplicant has transitioned |
| 1800 | * to a given state. |
| 1801 | * |
| 1802 | * {@hide} |
| 1803 | */ |
| 1804 | public abstract int getWifiSupplStateCount(int state, int which); |
| 1805 | |
| 1806 | public static final int NUM_WIFI_SIGNAL_STRENGTH_BINS = 5; |
| 1807 | |
| 1808 | /** |
| 1809 | * Returns the time in microseconds that WIFI has been running with |
| 1810 | * the given signal strength. |
| 1811 | * |
| 1812 | * {@hide} |
| 1813 | */ |
| 1814 | public abstract long getWifiSignalStrengthTime(int strengthBin, |
| 1815 | long elapsedRealtimeUs, int which); |
| 1816 | |
| 1817 | /** |
| 1818 | * Returns the number of times WIFI has entered the given signal strength. |
| 1819 | * |
| 1820 | * {@hide} |
| 1821 | */ |
| 1822 | public abstract int getWifiSignalStrengthCount(int strengthBin, int which); |
| 1823 | |
| 1824 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 1825 | * 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] | 1826 | * running on battery. |
| 1827 | * |
| 1828 | * {@hide} |
| 1829 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1830 | public abstract long getBluetoothOnTime(long elapsedRealtimeUs, int which); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 1831 | |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 1832 | public abstract int getBluetoothPingCount(); |
| 1833 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 1834 | public static final int BLUETOOTH_STATE_INACTIVE = 0; |
| 1835 | public static final int BLUETOOTH_STATE_LOW = 1; |
| 1836 | public static final int BLUETOOTH_STATE_MEDIUM = 2; |
| 1837 | public static final int BLUETOOTH_STATE_HIGH = 3; |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 1838 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 1839 | static final String[] BLUETOOTH_STATE_NAMES = { |
| 1840 | "inactive", "low", "med", "high" |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 1841 | }; |
| 1842 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 1843 | public static final int NUM_BLUETOOTH_STATES = BLUETOOTH_STATE_HIGH +1; |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 1844 | |
| 1845 | /** |
| 1846 | * Returns the time in microseconds that Bluetooth has been running in the |
| 1847 | * given active state. |
| 1848 | * |
| 1849 | * {@hide} |
| 1850 | */ |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 1851 | public abstract long getBluetoothStateTime(int bluetoothState, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1852 | long elapsedRealtimeUs, int which); |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 1853 | |
| 1854 | /** |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 1855 | * 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] | 1856 | * |
| 1857 | * {@hide} |
| 1858 | */ |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 1859 | public abstract int getBluetoothStateCount(int bluetoothState, int which); |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 1860 | |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 1861 | /** |
| 1862 | * Returns the time in microseconds that the flashlight has been on while the device was |
| 1863 | * running on battery. |
| 1864 | * |
| 1865 | * {@hide} |
| 1866 | */ |
| 1867 | public abstract long getFlashlightOnTime(long elapsedRealtimeUs, int which); |
| 1868 | |
| 1869 | /** |
| 1870 | * Returns the number of times that the flashlight has been turned on while the device was |
| 1871 | * running on battery. |
| 1872 | * |
| 1873 | * {@hide} |
| 1874 | */ |
| 1875 | public abstract long getFlashlightOnCount(int which); |
| 1876 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1877 | public static final int NETWORK_MOBILE_RX_DATA = 0; |
| 1878 | public static final int NETWORK_MOBILE_TX_DATA = 1; |
| 1879 | public static final int NETWORK_WIFI_RX_DATA = 2; |
| 1880 | public static final int NETWORK_WIFI_TX_DATA = 3; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 1881 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1882 | 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] | 1883 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1884 | public abstract long getNetworkActivityBytes(int type, int which); |
| 1885 | public abstract long getNetworkActivityPackets(int type, int which); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 1886 | |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 1887 | public static final int CONTROLLER_IDLE_TIME = 0; |
| 1888 | public static final int CONTROLLER_RX_TIME = 1; |
| 1889 | public static final int CONTROLLER_TX_TIME = 2; |
| 1890 | public static final int CONTROLLER_ENERGY = 3; |
| 1891 | public static final int NUM_CONTROLLER_ACTIVITY_TYPES = CONTROLLER_ENERGY + 1; |
| 1892 | |
| 1893 | public abstract long getBluetoothControllerActivity(int type, int which); |
| 1894 | public abstract long getWifiControllerActivity(int type, int which); |
| 1895 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 1896 | /** |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 1897 | * Return the wall clock time when battery stats data collection started. |
| 1898 | */ |
| 1899 | public abstract long getStartClockTime(); |
| 1900 | |
| 1901 | /** |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 1902 | * Return platform version tag that we were running in when the battery stats started. |
| 1903 | */ |
| 1904 | public abstract String getStartPlatformVersion(); |
| 1905 | |
| 1906 | /** |
| 1907 | * Return platform version tag that we were running in when the battery stats ended. |
| 1908 | */ |
| 1909 | public abstract String getEndPlatformVersion(); |
| 1910 | |
| 1911 | /** |
| 1912 | * Return the internal version code of the parcelled format. |
| 1913 | */ |
| 1914 | public abstract int getParcelVersion(); |
| 1915 | |
| 1916 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1917 | * Return whether we are currently running on battery. |
| 1918 | */ |
| 1919 | public abstract boolean getIsOnBattery(); |
| 1920 | |
| 1921 | /** |
| 1922 | * Returns a SparseArray containing the statistics for each uid. |
| 1923 | */ |
| 1924 | public abstract SparseArray<? extends Uid> getUidStats(); |
| 1925 | |
| 1926 | /** |
| 1927 | * Returns the current battery uptime in microseconds. |
| 1928 | * |
| 1929 | * @param curTime the amount of elapsed realtime in microseconds. |
| 1930 | */ |
| 1931 | public abstract long getBatteryUptime(long curTime); |
| 1932 | |
| 1933 | /** |
| 1934 | * Returns the current battery realtime in microseconds. |
| 1935 | * |
| 1936 | * @param curTime the amount of elapsed realtime in microseconds. |
| 1937 | */ |
| 1938 | public abstract long getBatteryRealtime(long curTime); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 1939 | |
| 1940 | /** |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 1941 | * Returns the battery percentage level at the last time the device was unplugged from power, or |
| 1942 | * the last time it booted on battery power. |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 1943 | */ |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 1944 | public abstract int getDischargeStartLevel(); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 1945 | |
| 1946 | /** |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 1947 | * Returns the current battery percentage level if we are in a discharge cycle, otherwise |
| 1948 | * returns the level at the last plug event. |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 1949 | */ |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 1950 | public abstract int getDischargeCurrentLevel(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1951 | |
| 1952 | /** |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 1953 | * Get the amount the battery has discharged since the stats were |
| 1954 | * last reset after charging, as a lower-end approximation. |
| 1955 | */ |
| 1956 | public abstract int getLowDischargeAmountSinceCharge(); |
| 1957 | |
| 1958 | /** |
| 1959 | * Get the amount the battery has discharged since the stats were |
| 1960 | * last reset after charging, as an upper-end approximation. |
| 1961 | */ |
| 1962 | public abstract int getHighDischargeAmountSinceCharge(); |
| 1963 | |
| 1964 | /** |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 1965 | * Retrieve the discharge amount over the selected discharge period <var>which</var>. |
| 1966 | */ |
| 1967 | public abstract int getDischargeAmount(int which); |
| 1968 | |
| 1969 | /** |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 1970 | * Get the amount the battery has discharged while the screen was on, |
| 1971 | * since the last time power was unplugged. |
| 1972 | */ |
| 1973 | public abstract int getDischargeAmountScreenOn(); |
| 1974 | |
| 1975 | /** |
| 1976 | * Get the amount the battery has discharged while the screen was on, |
| 1977 | * since the last time the device was charged. |
| 1978 | */ |
| 1979 | public abstract int getDischargeAmountScreenOnSinceCharge(); |
| 1980 | |
| 1981 | /** |
| 1982 | * Get the amount the battery has discharged while the screen was off, |
| 1983 | * since the last time power was unplugged. |
| 1984 | */ |
| 1985 | public abstract int getDischargeAmountScreenOff(); |
| 1986 | |
| 1987 | /** |
| 1988 | * Get the amount the battery has discharged while the screen was off, |
| 1989 | * since the last time the device was charged. |
| 1990 | */ |
| 1991 | public abstract int getDischargeAmountScreenOffSinceCharge(); |
| 1992 | |
| 1993 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1994 | * Returns the total, last, or current battery uptime in microseconds. |
| 1995 | * |
| 1996 | * @param curTime the elapsed realtime in microseconds. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 1997 | * @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] | 1998 | */ |
| 1999 | public abstract long computeBatteryUptime(long curTime, int which); |
| 2000 | |
| 2001 | /** |
| 2002 | * Returns the total, last, or current battery realtime in microseconds. |
| 2003 | * |
| 2004 | * @param curTime the current elapsed realtime in microseconds. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2005 | * @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] | 2006 | */ |
| 2007 | public abstract long computeBatteryRealtime(long curTime, int which); |
| 2008 | |
| 2009 | /** |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2010 | * Returns the total, last, or current battery screen off uptime in microseconds. |
| 2011 | * |
| 2012 | * @param curTime the elapsed realtime in microseconds. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2013 | * @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] | 2014 | */ |
| 2015 | public abstract long computeBatteryScreenOffUptime(long curTime, int which); |
| 2016 | |
| 2017 | /** |
| 2018 | * Returns the total, last, or current battery screen off realtime in microseconds. |
| 2019 | * |
| 2020 | * @param curTime the current elapsed realtime in microseconds. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2021 | * @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] | 2022 | */ |
| 2023 | public abstract long computeBatteryScreenOffRealtime(long curTime, int which); |
| 2024 | |
| 2025 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2026 | * Returns the total, last, or current uptime in microseconds. |
| 2027 | * |
| 2028 | * @param curTime the current elapsed realtime in microseconds. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2029 | * @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] | 2030 | */ |
| 2031 | public abstract long computeUptime(long curTime, int which); |
| 2032 | |
| 2033 | /** |
| 2034 | * Returns the total, last, or current realtime in microseconds. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2035 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2036 | * @param curTime the current elapsed realtime in microseconds. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2037 | * @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] | 2038 | */ |
| 2039 | public abstract long computeRealtime(long curTime, int which); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2040 | |
| 2041 | /** |
| 2042 | * Compute an approximation for how much run time (in microseconds) is remaining on |
| 2043 | * the battery. Returns -1 if no time can be computed: either there is not |
| 2044 | * enough current data to make a decision, or the battery is currently |
| 2045 | * charging. |
| 2046 | * |
| 2047 | * @param curTime The current elepsed realtime in microseconds. |
| 2048 | */ |
| 2049 | public abstract long computeBatteryTimeRemaining(long curTime); |
| 2050 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 2051 | // The part of a step duration that is the actual time. |
| 2052 | public static final long STEP_LEVEL_TIME_MASK = 0x000000ffffffffffL; |
| 2053 | |
| 2054 | // Bits in a step duration that are the new battery level we are at. |
| 2055 | public static final long STEP_LEVEL_LEVEL_MASK = 0x0000ff0000000000L; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2056 | public static final int STEP_LEVEL_LEVEL_SHIFT = 40; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 2057 | |
| 2058 | // Bits in a step duration that are the initial mode we were in at that step. |
| 2059 | public static final long STEP_LEVEL_INITIAL_MODE_MASK = 0x00ff000000000000L; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2060 | public static final int STEP_LEVEL_INITIAL_MODE_SHIFT = 48; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 2061 | |
| 2062 | // Bits in a step duration that indicate which modes changed during that step. |
| 2063 | public static final long STEP_LEVEL_MODIFIED_MODE_MASK = 0xff00000000000000L; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2064 | public static final int STEP_LEVEL_MODIFIED_MODE_SHIFT = 56; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 2065 | |
| 2066 | // Step duration mode: the screen is on, off, dozed, etc; value is Display.STATE_* - 1. |
| 2067 | public static final int STEP_LEVEL_MODE_SCREEN_STATE = 0x03; |
| 2068 | |
| 2069 | // Step duration mode: power save is on. |
| 2070 | public static final int STEP_LEVEL_MODE_POWER_SAVE = 0x04; |
| 2071 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2072 | public static final int[] STEP_LEVEL_MODES_OF_INTEREST = new int[] { |
| 2073 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE, |
| 2074 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE, |
| 2075 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE, |
| 2076 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE, |
| 2077 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE, |
| 2078 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE, |
| 2079 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE, |
| 2080 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE, |
| 2081 | }; |
| 2082 | public static final int[] STEP_LEVEL_MODE_VALUES = new int[] { |
| 2083 | (Display.STATE_OFF-1), |
| 2084 | (Display.STATE_OFF-1)|STEP_LEVEL_MODE_POWER_SAVE, |
| 2085 | (Display.STATE_ON-1), |
| 2086 | (Display.STATE_ON-1)|STEP_LEVEL_MODE_POWER_SAVE, |
| 2087 | (Display.STATE_DOZE-1), |
| 2088 | (Display.STATE_DOZE-1)|STEP_LEVEL_MODE_POWER_SAVE, |
| 2089 | (Display.STATE_DOZE_SUSPEND-1), |
| 2090 | (Display.STATE_DOZE_SUSPEND-1)|STEP_LEVEL_MODE_POWER_SAVE, |
| 2091 | }; |
| 2092 | public static final String[] STEP_LEVEL_MODE_LABELS = new String[] { |
| 2093 | "screen off", |
| 2094 | "screen off power save", |
| 2095 | "screen on", |
| 2096 | "screen on power save", |
| 2097 | "screen doze", |
| 2098 | "screen doze power save", |
| 2099 | "screen doze-suspend", |
| 2100 | "screen doze-suspend power save", |
| 2101 | }; |
| 2102 | public static final String[] STEP_LEVEL_MODE_TAGS = new String[] { |
| 2103 | "off", |
| 2104 | "off-save", |
| 2105 | "on", |
| 2106 | "on-save", |
| 2107 | "doze", |
| 2108 | "doze-save", |
| 2109 | "susp", |
| 2110 | "susp-save", |
| 2111 | }; |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 2112 | |
| 2113 | /** |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2114 | * Return the array of discharge step durations. |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 2115 | */ |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2116 | public abstract LevelStepTracker getDischargeLevelStepTracker(); |
| 2117 | |
| 2118 | /** |
| 2119 | * Return the array of daily discharge step durations. |
| 2120 | */ |
| 2121 | public abstract LevelStepTracker getDailyDischargeLevelStepTracker(); |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 2122 | |
| 2123 | /** |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2124 | * Compute an approximation for how much time (in microseconds) remains until the battery |
| 2125 | * is fully charged. Returns -1 if no time can be computed: either there is not |
| 2126 | * enough current data to make a decision, or the battery is currently |
| 2127 | * discharging. |
| 2128 | * |
| 2129 | * @param curTime The current elepsed realtime in microseconds. |
| 2130 | */ |
| 2131 | public abstract long computeChargeTimeRemaining(long curTime); |
| 2132 | |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 2133 | /** |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2134 | * Return the array of charge step durations. |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 2135 | */ |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2136 | public abstract LevelStepTracker getChargeLevelStepTracker(); |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 2137 | |
| 2138 | /** |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2139 | * Return the array of daily charge step durations. |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 2140 | */ |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2141 | public abstract LevelStepTracker getDailyChargeLevelStepTracker(); |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 2142 | |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 2143 | public abstract Map<String, ? extends Timer> getWakeupReasonStats(); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2144 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2145 | public abstract Map<String, ? extends Timer> getKernelWakelockStats(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2146 | |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 2147 | /** Returns the number of different speeds that the CPU can run at */ |
| 2148 | public abstract int getCpuSpeedSteps(); |
| 2149 | |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 2150 | public abstract void writeToParcelWithoutUids(Parcel out, int flags); |
| 2151 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 2152 | private final static void formatTimeRaw(StringBuilder out, long seconds) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2153 | long days = seconds / (60 * 60 * 24); |
| 2154 | if (days != 0) { |
| 2155 | out.append(days); |
| 2156 | out.append("d "); |
| 2157 | } |
| 2158 | long used = days * 60 * 60 * 24; |
| 2159 | |
| 2160 | long hours = (seconds - used) / (60 * 60); |
| 2161 | if (hours != 0 || used != 0) { |
| 2162 | out.append(hours); |
| 2163 | out.append("h "); |
| 2164 | } |
| 2165 | used += hours * 60 * 60; |
| 2166 | |
| 2167 | long mins = (seconds-used) / 60; |
| 2168 | if (mins != 0 || used != 0) { |
| 2169 | out.append(mins); |
| 2170 | out.append("m "); |
| 2171 | } |
| 2172 | used += mins * 60; |
| 2173 | |
| 2174 | if (seconds != 0 || used != 0) { |
| 2175 | out.append(seconds-used); |
| 2176 | out.append("s "); |
| 2177 | } |
| 2178 | } |
| 2179 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2180 | public final static void formatTimeMs(StringBuilder sb, long time) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2181 | long sec = time / 1000; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 2182 | formatTimeRaw(sb, sec); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2183 | sb.append(time - (sec * 1000)); |
| 2184 | sb.append("ms "); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2185 | } |
| 2186 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2187 | public final static void formatTimeMsNoSpace(StringBuilder sb, long time) { |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 2188 | long sec = time / 1000; |
| 2189 | formatTimeRaw(sb, sec); |
| 2190 | sb.append(time - (sec * 1000)); |
| 2191 | sb.append("ms"); |
| 2192 | } |
| 2193 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2194 | public final String formatRatioLocked(long num, long den) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2195 | if (den == 0L) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2196 | return "--%"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2197 | } |
| 2198 | float perc = ((float)num) / ((float)den) * 100; |
| 2199 | mFormatBuilder.setLength(0); |
| 2200 | mFormatter.format("%.1f%%", perc); |
| 2201 | return mFormatBuilder.toString(); |
| 2202 | } |
| 2203 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2204 | final String formatBytesLocked(long bytes) { |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 2205 | mFormatBuilder.setLength(0); |
| 2206 | |
| 2207 | if (bytes < BYTES_PER_KB) { |
| 2208 | return bytes + "B"; |
| 2209 | } else if (bytes < BYTES_PER_MB) { |
| 2210 | mFormatter.format("%.2fKB", bytes / (double) BYTES_PER_KB); |
| 2211 | return mFormatBuilder.toString(); |
| 2212 | } else if (bytes < BYTES_PER_GB){ |
| 2213 | mFormatter.format("%.2fMB", bytes / (double) BYTES_PER_MB); |
| 2214 | return mFormatBuilder.toString(); |
| 2215 | } else { |
| 2216 | mFormatter.format("%.2fGB", bytes / (double) BYTES_PER_GB); |
| 2217 | return mFormatBuilder.toString(); |
| 2218 | } |
| 2219 | } |
| 2220 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2221 | private static long computeWakeLock(Timer timer, long elapsedRealtimeUs, int which) { |
Dianne Hackborn | c24ab86 | 2011-10-18 15:55:03 -0700 | [diff] [blame] | 2222 | if (timer != null) { |
| 2223 | // Convert from microseconds to milliseconds with rounding |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2224 | long totalTimeMicros = timer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Dianne Hackborn | c24ab86 | 2011-10-18 15:55:03 -0700 | [diff] [blame] | 2225 | long totalTimeMillis = (totalTimeMicros + 500) / 1000; |
| 2226 | return totalTimeMillis; |
| 2227 | } |
| 2228 | return 0; |
| 2229 | } |
| 2230 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2231 | /** |
| 2232 | * |
| 2233 | * @param sb a StringBuilder object. |
| 2234 | * @param timer a Timer object contining the wakelock times. |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2235 | * @param elapsedRealtimeUs the current on-battery time in microseconds. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2236 | * @param name the name of the wakelock. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2237 | * @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] | 2238 | * @param linePrefix a String to be prepended to each line of output. |
| 2239 | * @return the line prefix |
| 2240 | */ |
| 2241 | private static final String printWakeLock(StringBuilder sb, Timer timer, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2242 | long elapsedRealtimeUs, String name, int which, String linePrefix) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2243 | |
| 2244 | if (timer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2245 | long totalTimeMillis = computeWakeLock(timer, elapsedRealtimeUs, which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2246 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2247 | int count = timer.getCountLocked(which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2248 | if (totalTimeMillis != 0) { |
| 2249 | sb.append(linePrefix); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 2250 | formatTimeMs(sb, totalTimeMillis); |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 2251 | if (name != null) { |
| 2252 | sb.append(name); |
| 2253 | sb.append(' '); |
| 2254 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2255 | sb.append('('); |
| 2256 | sb.append(count); |
| 2257 | sb.append(" times)"); |
| 2258 | return ", "; |
| 2259 | } |
| 2260 | } |
| 2261 | return linePrefix; |
| 2262 | } |
| 2263 | |
| 2264 | /** |
| 2265 | * Checkin version of wakelock printer. Prints simple comma-separated list. |
| 2266 | * |
| 2267 | * @param sb a StringBuilder object. |
| 2268 | * @param timer a Timer object contining the wakelock times. |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2269 | * @param elapsedRealtimeUs the current time in microseconds. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2270 | * @param name the name of the wakelock. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2271 | * @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] | 2272 | * @param linePrefix a String to be prepended to each line of output. |
| 2273 | * @return the line prefix |
| 2274 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2275 | private static final String printWakeLockCheckin(StringBuilder sb, Timer timer, |
| 2276 | long elapsedRealtimeUs, String name, int which, String linePrefix) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2277 | long totalTimeMicros = 0; |
| 2278 | int count = 0; |
| 2279 | if (timer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2280 | totalTimeMicros = timer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2281 | count = timer.getCountLocked(which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2282 | } |
| 2283 | sb.append(linePrefix); |
| 2284 | sb.append((totalTimeMicros + 500) / 1000); // microseconds to milliseconds with rounding |
| 2285 | sb.append(','); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2286 | sb.append(name != null ? name + "," : ""); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2287 | sb.append(count); |
| 2288 | return ","; |
| 2289 | } |
| 2290 | |
| 2291 | /** |
| 2292 | * Dump a comma-separated line of values for terse checkin mode. |
| 2293 | * |
| 2294 | * @param pw the PageWriter to dump log to |
| 2295 | * @param category category of data (e.g. "total", "last", "unplugged", "current" ) |
| 2296 | * @param type type of data (e.g. "wakelock", "sensor", "process", "apk" , "process", "network") |
| 2297 | * @param args type-dependent data arguments |
| 2298 | */ |
| 2299 | private static final void dumpLine(PrintWriter pw, int uid, String category, String type, |
| 2300 | Object... args ) { |
| 2301 | pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(','); |
| 2302 | pw.print(uid); pw.print(','); |
| 2303 | pw.print(category); pw.print(','); |
Dianne Hackborn | 13ac041 | 2013-06-25 19:34:49 -0700 | [diff] [blame] | 2304 | pw.print(type); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2305 | |
| 2306 | for (Object arg : args) { |
Dianne Hackborn | 13ac041 | 2013-06-25 19:34:49 -0700 | [diff] [blame] | 2307 | pw.print(','); |
| 2308 | pw.print(arg); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2309 | } |
Dianne Hackborn | 13ac041 | 2013-06-25 19:34:49 -0700 | [diff] [blame] | 2310 | pw.println(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2311 | } |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 2312 | |
| 2313 | /** |
| 2314 | * Temporary for settings. |
| 2315 | */ |
| 2316 | public final void dumpCheckinLocked(Context context, PrintWriter pw, int which, int reqUid) { |
| 2317 | dumpCheckinLocked(context, pw, which, reqUid, BatteryStatsHelper.checkWifiOnly(context)); |
| 2318 | } |
| 2319 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2320 | /** |
| 2321 | * Checkin server version of dump to produce more compact, computer-readable log. |
| 2322 | * |
| 2323 | * NOTE: all times are expressed in 'ms'. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2324 | */ |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 2325 | public final void dumpCheckinLocked(Context context, PrintWriter pw, int which, int reqUid, |
| 2326 | boolean wifiOnly) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2327 | final long rawUptime = SystemClock.uptimeMillis() * 1000; |
| 2328 | final long rawRealtime = SystemClock.elapsedRealtime() * 1000; |
| 2329 | final long batteryUptime = getBatteryUptime(rawUptime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2330 | final long whichBatteryUptime = computeBatteryUptime(rawUptime, which); |
| 2331 | final long whichBatteryRealtime = computeBatteryRealtime(rawRealtime, which); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2332 | final long whichBatteryScreenOffUptime = computeBatteryScreenOffUptime(rawUptime, which); |
| 2333 | final long whichBatteryScreenOffRealtime = computeBatteryScreenOffRealtime(rawRealtime, |
| 2334 | which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2335 | final long totalRealtime = computeRealtime(rawRealtime, which); |
| 2336 | final long totalUptime = computeUptime(rawUptime, which); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2337 | final long screenOnTime = getScreenOnTime(rawRealtime, which); |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 2338 | final long interactiveTime = getInteractiveTime(rawRealtime, which); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame^] | 2339 | final long powerSaveModeEnabledTime = getPowerSaveModeEnabledTime(rawRealtime, which); |
| 2340 | final long deviceIdleModeEnabledTime = getDeviceIdleModeEnabledTime(rawRealtime, which); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 2341 | final int connChanges = getNumConnectivityChange(which); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2342 | final long phoneOnTime = getPhoneOnTime(rawRealtime, which); |
| 2343 | final long wifiOnTime = getWifiOnTime(rawRealtime, which); |
| 2344 | final long wifiRunningTime = getGlobalWifiRunningTime(rawRealtime, which); |
| 2345 | final long bluetoothOnTime = getBluetoothOnTime(rawRealtime, which); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 2346 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2347 | StringBuilder sb = new StringBuilder(128); |
| 2348 | |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 2349 | SparseArray<? extends Uid> uidStats = getUidStats(); |
| 2350 | final int NU = uidStats.size(); |
| 2351 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2352 | String category = STAT_NAMES[which]; |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 2353 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2354 | // Dump "battery" stat |
| 2355 | dumpLine(pw, 0 /* uid */, category, BATTERY_DATA, |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2356 | which == STATS_SINCE_CHARGED ? getStartCount() : "N/A", |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2357 | whichBatteryRealtime / 1000, whichBatteryUptime / 1000, |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 2358 | totalRealtime / 1000, totalUptime / 1000, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2359 | getStartClockTime(), |
| 2360 | whichBatteryScreenOffRealtime / 1000, whichBatteryScreenOffUptime / 1000); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2361 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2362 | // Calculate wakelock times across all uids. |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 2363 | long fullWakeLockTimeTotal = 0; |
| 2364 | long partialWakeLockTimeTotal = 0; |
| 2365 | |
| 2366 | for (int iu = 0; iu < NU; iu++) { |
| 2367 | Uid u = uidStats.valueAt(iu); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 2368 | |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 2369 | Map<String, ? extends BatteryStats.Uid.Wakelock> wakelocks = u.getWakelockStats(); |
| 2370 | if (wakelocks.size() > 0) { |
| 2371 | for (Map.Entry<String, ? extends BatteryStats.Uid.Wakelock> ent |
| 2372 | : wakelocks.entrySet()) { |
| 2373 | Uid.Wakelock wl = ent.getValue(); |
| 2374 | |
| 2375 | Timer fullWakeTimer = wl.getWakeTime(WAKE_TYPE_FULL); |
| 2376 | if (fullWakeTimer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2377 | fullWakeLockTimeTotal += fullWakeTimer.getTotalTimeLocked(rawRealtime, |
| 2378 | which); |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 2379 | } |
| 2380 | |
| 2381 | Timer partialWakeTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL); |
| 2382 | if (partialWakeTimer != null) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2383 | partialWakeLockTimeTotal += partialWakeTimer.getTotalTimeLocked( |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2384 | rawRealtime, which); |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 2385 | } |
| 2386 | } |
| 2387 | } |
| 2388 | } |
| 2389 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2390 | long mobileRxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which); |
| 2391 | long mobileTxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which); |
| 2392 | long wifiRxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which); |
| 2393 | long wifiTxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which); |
| 2394 | long mobileRxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which); |
| 2395 | long mobileTxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which); |
| 2396 | long wifiRxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which); |
| 2397 | long wifiTxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which); |
| 2398 | |
| 2399 | // Dump network stats |
| 2400 | dumpLine(pw, 0 /* uid */, category, GLOBAL_NETWORK_DATA, |
| 2401 | mobileRxTotalBytes, mobileTxTotalBytes, wifiRxTotalBytes, wifiTxTotalBytes, |
| 2402 | mobileRxTotalPackets, mobileTxTotalPackets, wifiRxTotalPackets, wifiTxTotalPackets); |
| 2403 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2404 | // Dump misc stats |
| 2405 | dumpLine(pw, 0 /* uid */, category, MISC_DATA, |
Eric Shienbrood | d4c5f89 | 2009-03-24 18:13:20 -0700 | [diff] [blame] | 2406 | screenOnTime / 1000, phoneOnTime / 1000, wifiOnTime / 1000, |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 2407 | wifiRunningTime / 1000, bluetoothOnTime / 1000, |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2408 | mobileRxTotalBytes, mobileTxTotalBytes, wifiRxTotalBytes, wifiTxTotalBytes, |
Ashish Sharma | 213bb2f | 2014-07-07 17:14:52 -0700 | [diff] [blame] | 2409 | fullWakeLockTimeTotal / 1000, partialWakeLockTimeTotal / 1000, |
| 2410 | 0 /*legacy input event count*/, getMobileRadioActiveTime(rawRealtime, which) / 1000, |
| 2411 | getMobileRadioActiveAdjustedTime(which) / 1000, interactiveTime / 1000, |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame^] | 2412 | powerSaveModeEnabledTime / 1000, connChanges, deviceIdleModeEnabledTime / 1000, |
| 2413 | getDeviceIdleModeEnabledCount(which)); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2414 | |
| 2415 | // Dump screen brightness stats |
| 2416 | Object[] args = new Object[NUM_SCREEN_BRIGHTNESS_BINS]; |
| 2417 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2418 | args[i] = getScreenBrightnessTime(i, rawRealtime, which) / 1000; |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2419 | } |
| 2420 | dumpLine(pw, 0 /* uid */, category, SCREEN_BRIGHTNESS_DATA, args); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2421 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 2422 | // Dump signal strength stats |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 2423 | args = new Object[SignalStrength.NUM_SIGNAL_STRENGTH_BINS]; |
| 2424 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2425 | args[i] = getPhoneSignalStrengthTime(i, rawRealtime, which) / 1000; |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 2426 | } |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2427 | dumpLine(pw, 0 /* uid */, category, SIGNAL_STRENGTH_TIME_DATA, args); |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 2428 | dumpLine(pw, 0 /* uid */, category, SIGNAL_SCANNING_TIME_DATA, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2429 | getPhoneSignalScanningTime(rawRealtime, which) / 1000); |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 2430 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2431 | args[i] = getPhoneSignalStrengthCount(i, which); |
| 2432 | } |
| 2433 | dumpLine(pw, 0 /* uid */, category, SIGNAL_STRENGTH_COUNT_DATA, args); |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 2434 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 2435 | // Dump network type stats |
| 2436 | args = new Object[NUM_DATA_CONNECTION_TYPES]; |
| 2437 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2438 | args[i] = getPhoneDataConnectionTime(i, rawRealtime, which) / 1000; |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 2439 | } |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2440 | dumpLine(pw, 0 /* uid */, category, DATA_CONNECTION_TIME_DATA, args); |
| 2441 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
| 2442 | args[i] = getPhoneDataConnectionCount(i, which); |
| 2443 | } |
| 2444 | dumpLine(pw, 0 /* uid */, category, DATA_CONNECTION_COUNT_DATA, args); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 2445 | |
| 2446 | // Dump wifi state stats |
| 2447 | args = new Object[NUM_WIFI_STATES]; |
| 2448 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2449 | args[i] = getWifiStateTime(i, rawRealtime, which) / 1000; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 2450 | } |
| 2451 | dumpLine(pw, 0 /* uid */, category, WIFI_STATE_TIME_DATA, args); |
| 2452 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
| 2453 | args[i] = getWifiStateCount(i, which); |
| 2454 | } |
| 2455 | dumpLine(pw, 0 /* uid */, category, WIFI_STATE_COUNT_DATA, args); |
| 2456 | |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 2457 | // Dump wifi suppl state stats |
| 2458 | args = new Object[NUM_WIFI_SUPPL_STATES]; |
| 2459 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
| 2460 | args[i] = getWifiSupplStateTime(i, rawRealtime, which) / 1000; |
| 2461 | } |
| 2462 | dumpLine(pw, 0 /* uid */, category, WIFI_SUPPL_STATE_TIME_DATA, args); |
| 2463 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
| 2464 | args[i] = getWifiSupplStateCount(i, which); |
| 2465 | } |
| 2466 | dumpLine(pw, 0 /* uid */, category, WIFI_SUPPL_STATE_COUNT_DATA, args); |
| 2467 | |
| 2468 | // Dump wifi signal strength stats |
| 2469 | args = new Object[NUM_WIFI_SIGNAL_STRENGTH_BINS]; |
| 2470 | for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 2471 | args[i] = getWifiSignalStrengthTime(i, rawRealtime, which) / 1000; |
| 2472 | } |
| 2473 | dumpLine(pw, 0 /* uid */, category, WIFI_SIGNAL_STRENGTH_TIME_DATA, args); |
| 2474 | for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 2475 | args[i] = getWifiSignalStrengthCount(i, which); |
| 2476 | } |
| 2477 | dumpLine(pw, 0 /* uid */, category, WIFI_SIGNAL_STRENGTH_COUNT_DATA, args); |
| 2478 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 2479 | // Dump bluetooth state stats |
| 2480 | args = new Object[NUM_BLUETOOTH_STATES]; |
| 2481 | for (int i=0; i<NUM_BLUETOOTH_STATES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2482 | args[i] = getBluetoothStateTime(i, rawRealtime, which) / 1000; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 2483 | } |
| 2484 | dumpLine(pw, 0 /* uid */, category, BLUETOOTH_STATE_TIME_DATA, args); |
| 2485 | for (int i=0; i<NUM_BLUETOOTH_STATES; i++) { |
| 2486 | args[i] = getBluetoothStateCount(i, which); |
| 2487 | } |
| 2488 | dumpLine(pw, 0 /* uid */, category, BLUETOOTH_STATE_COUNT_DATA, args); |
| 2489 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2490 | if (which == STATS_SINCE_UNPLUGGED) { |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 2491 | dumpLine(pw, 0 /* uid */, category, BATTERY_LEVEL_DATA, getDischargeStartLevel(), |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 2492 | getDischargeCurrentLevel()); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2493 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2494 | |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 2495 | if (which == STATS_SINCE_UNPLUGGED) { |
| 2496 | dumpLine(pw, 0 /* uid */, category, BATTERY_DISCHARGE_DATA, |
| 2497 | getDischargeStartLevel()-getDischargeCurrentLevel(), |
| 2498 | getDischargeStartLevel()-getDischargeCurrentLevel(), |
| 2499 | getDischargeAmountScreenOn(), getDischargeAmountScreenOff()); |
| 2500 | } else { |
| 2501 | dumpLine(pw, 0 /* uid */, category, BATTERY_DISCHARGE_DATA, |
| 2502 | getLowDischargeAmountSinceCharge(), getHighDischargeAmountSinceCharge(), |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 2503 | getDischargeAmountScreenOnSinceCharge(), |
| 2504 | getDischargeAmountScreenOffSinceCharge()); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 2505 | } |
| 2506 | |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 2507 | if (reqUid < 0) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2508 | Map<String, ? extends Timer> kernelWakelocks = getKernelWakelockStats(); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 2509 | if (kernelWakelocks.size() > 0) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2510 | for (Map.Entry<String, ? extends Timer> ent : kernelWakelocks.entrySet()) { |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 2511 | sb.setLength(0); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2512 | printWakeLockCheckin(sb, ent.getValue(), rawRealtime, null, which, ""); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2513 | dumpLine(pw, 0 /* uid */, category, KERNEL_WAKELOCK_DATA, ent.getKey(), |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 2514 | sb.toString()); |
| 2515 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2516 | } |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 2517 | Map<String, ? extends Timer> wakeupReasons = getWakeupReasonStats(); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2518 | if (wakeupReasons.size() > 0) { |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 2519 | for (Map.Entry<String, ? extends Timer> ent : wakeupReasons.entrySet()) { |
| 2520 | // Not doing the regular wake lock formatting to remain compatible |
| 2521 | // with the old checkin format. |
| 2522 | long totalTimeMicros = ent.getValue().getTotalTimeLocked(rawRealtime, which); |
| 2523 | int count = ent.getValue().getCountLocked(which); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2524 | dumpLine(pw, 0 /* uid */, category, WAKEUP_REASON_DATA, |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 2525 | "\"" + ent.getKey() + "\"", (totalTimeMicros + 500) / 1000, count); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2526 | } |
| 2527 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2528 | } |
| 2529 | |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 2530 | BatteryStatsHelper helper = new BatteryStatsHelper(context, false, wifiOnly); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 2531 | helper.create(this); |
| 2532 | helper.refreshStats(which, UserHandle.USER_ALL); |
| 2533 | List<BatterySipper> sippers = helper.getUsageList(); |
| 2534 | if (sippers != null && sippers.size() > 0) { |
| 2535 | dumpLine(pw, 0 /* uid */, category, POWER_USE_SUMMARY_DATA, |
| 2536 | BatteryStatsHelper.makemAh(helper.getPowerProfile().getBatteryCapacity()), |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 2537 | BatteryStatsHelper.makemAh(helper.getComputedPower()), |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 2538 | BatteryStatsHelper.makemAh(helper.getMinDrainedPower()), |
| 2539 | BatteryStatsHelper.makemAh(helper.getMaxDrainedPower())); |
| 2540 | for (int i=0; i<sippers.size(); i++) { |
| 2541 | BatterySipper bs = sippers.get(i); |
| 2542 | int uid = 0; |
| 2543 | String label; |
| 2544 | switch (bs.drainType) { |
| 2545 | case IDLE: |
| 2546 | label="idle"; |
| 2547 | break; |
| 2548 | case CELL: |
| 2549 | label="cell"; |
| 2550 | break; |
| 2551 | case PHONE: |
| 2552 | label="phone"; |
| 2553 | break; |
| 2554 | case WIFI: |
| 2555 | label="wifi"; |
| 2556 | break; |
| 2557 | case BLUETOOTH: |
| 2558 | label="blue"; |
| 2559 | break; |
| 2560 | case SCREEN: |
| 2561 | label="scrn"; |
| 2562 | break; |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 2563 | case FLASHLIGHT: |
| 2564 | label="flashlight"; |
| 2565 | break; |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 2566 | case APP: |
| 2567 | uid = bs.uidObj.getUid(); |
| 2568 | label = "uid"; |
| 2569 | break; |
| 2570 | case USER: |
| 2571 | uid = UserHandle.getUid(bs.userId, 0); |
| 2572 | label = "user"; |
| 2573 | break; |
| 2574 | case UNACCOUNTED: |
| 2575 | label = "unacc"; |
| 2576 | break; |
| 2577 | case OVERCOUNTED: |
| 2578 | label = "over"; |
| 2579 | break; |
| 2580 | default: |
| 2581 | label = "???"; |
| 2582 | } |
| 2583 | dumpLine(pw, uid, category, POWER_USE_ITEM_DATA, label, |
| 2584 | BatteryStatsHelper.makemAh(bs.value)); |
| 2585 | } |
| 2586 | } |
| 2587 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2588 | for (int iu = 0; iu < NU; iu++) { |
| 2589 | final int uid = uidStats.keyAt(iu); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 2590 | if (reqUid >= 0 && uid != reqUid) { |
| 2591 | continue; |
| 2592 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2593 | Uid u = uidStats.valueAt(iu); |
| 2594 | // Dump Network stats per uid, if any |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2595 | long mobileBytesRx = u.getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which); |
| 2596 | long mobileBytesTx = u.getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which); |
| 2597 | long wifiBytesRx = u.getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which); |
| 2598 | long wifiBytesTx = u.getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which); |
| 2599 | long mobilePacketsRx = u.getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which); |
| 2600 | long mobilePacketsTx = u.getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 2601 | long mobileActiveTime = u.getMobileRadioActiveTime(which); |
| 2602 | int mobileActiveCount = u.getMobileRadioActiveCount(which); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2603 | long wifiPacketsRx = u.getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which); |
| 2604 | long wifiPacketsTx = u.getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2605 | long fullWifiLockOnTime = u.getFullWifiLockTime(rawRealtime, which); |
| 2606 | long wifiScanTime = u.getWifiScanTime(rawRealtime, which); |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 2607 | int wifiScanCount = u.getWifiScanCount(which); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2608 | long uidWifiRunningTime = u.getWifiRunningTime(rawRealtime, which); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 2609 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2610 | if (mobileBytesRx > 0 || mobileBytesTx > 0 || wifiBytesRx > 0 || wifiBytesTx > 0 |
| 2611 | || mobilePacketsRx > 0 || mobilePacketsTx > 0 || wifiPacketsRx > 0 |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 2612 | || wifiPacketsTx > 0 || mobileActiveTime > 0 || mobileActiveCount > 0) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2613 | dumpLine(pw, uid, category, NETWORK_DATA, mobileBytesRx, mobileBytesTx, |
| 2614 | wifiBytesRx, wifiBytesTx, |
| 2615 | mobilePacketsRx, mobilePacketsTx, |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 2616 | wifiPacketsRx, wifiPacketsTx, |
| 2617 | mobileActiveTime, mobileActiveCount); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 2618 | } |
| 2619 | |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 2620 | if (fullWifiLockOnTime != 0 || wifiScanTime != 0 || wifiScanCount != 0 |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 2621 | || uidWifiRunningTime != 0) { |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 2622 | dumpLine(pw, uid, category, WIFI_DATA, |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 2623 | fullWifiLockOnTime, wifiScanTime, uidWifiRunningTime, wifiScanCount); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2624 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2625 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2626 | if (u.hasUserActivity()) { |
| 2627 | args = new Object[Uid.NUM_USER_ACTIVITY_TYPES]; |
| 2628 | boolean hasData = false; |
| 2629 | for (int i=0; i<Uid.NUM_USER_ACTIVITY_TYPES; i++) { |
| 2630 | int val = u.getUserActivityCount(i, which); |
| 2631 | args[i] = val; |
| 2632 | if (val != 0) hasData = true; |
| 2633 | } |
| 2634 | if (hasData) { |
Ashish Sharma | cba1215 | 2014-07-07 17:14:52 -0700 | [diff] [blame] | 2635 | dumpLine(pw, uid /* uid */, category, USER_ACTIVITY_DATA, args); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2636 | } |
| 2637 | } |
| 2638 | |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 2639 | Map<String, ? extends Uid.Wakelock> wakelocks = u.getWakelockStats(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2640 | if (wakelocks.size() > 0) { |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 2641 | 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] | 2642 | Uid.Wakelock wl = ent.getValue(); |
| 2643 | String linePrefix = ""; |
| 2644 | sb.setLength(0); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2645 | linePrefix = printWakeLockCheckin(sb, wl.getWakeTime(WAKE_TYPE_FULL), |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2646 | rawRealtime, "f", which, linePrefix); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2647 | linePrefix = printWakeLockCheckin(sb, wl.getWakeTime(WAKE_TYPE_PARTIAL), |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2648 | rawRealtime, "p", which, linePrefix); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2649 | linePrefix = printWakeLockCheckin(sb, wl.getWakeTime(WAKE_TYPE_WINDOW), |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2650 | rawRealtime, "w", which, linePrefix); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2651 | |
| 2652 | // Only log if we had at lease one wakelock... |
| 2653 | if (sb.length() > 0) { |
Dianne Hackborn | 13ac041 | 2013-06-25 19:34:49 -0700 | [diff] [blame] | 2654 | String name = ent.getKey(); |
| 2655 | if (name.indexOf(',') >= 0) { |
| 2656 | name = name.replace(',', '_'); |
| 2657 | } |
| 2658 | dumpLine(pw, uid, category, WAKELOCK_DATA, name, sb.toString()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2659 | } |
| 2660 | } |
| 2661 | } |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 2662 | |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 2663 | Map<String, ? extends Timer> syncs = u.getSyncStats(); |
| 2664 | if (syncs.size() > 0) { |
| 2665 | for (Map.Entry<String, ? extends Timer> ent : syncs.entrySet()) { |
| 2666 | Timer timer = ent.getValue(); |
| 2667 | // Convert from microseconds to milliseconds with rounding |
| 2668 | long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000; |
| 2669 | int count = timer.getCountLocked(which); |
| 2670 | if (totalTime != 0) { |
| 2671 | dumpLine(pw, uid, category, SYNC_DATA, ent.getKey(), totalTime, count); |
| 2672 | } |
| 2673 | } |
| 2674 | } |
| 2675 | |
| 2676 | Map<String, ? extends Timer> jobs = u.getJobStats(); |
| 2677 | if (jobs.size() > 0) { |
| 2678 | for (Map.Entry<String, ? extends Timer> ent : jobs.entrySet()) { |
| 2679 | Timer timer = ent.getValue(); |
| 2680 | // Convert from microseconds to milliseconds with rounding |
| 2681 | long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000; |
| 2682 | int count = timer.getCountLocked(which); |
| 2683 | if (totalTime != 0) { |
| 2684 | dumpLine(pw, uid, category, JOB_DATA, ent.getKey(), totalTime, count); |
| 2685 | } |
| 2686 | } |
| 2687 | } |
| 2688 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 2689 | SparseArray<? extends BatteryStats.Uid.Sensor> sensors = u.getSensorStats(); |
| 2690 | int NSE = sensors.size(); |
| 2691 | for (int ise=0; ise<NSE; ise++) { |
| 2692 | Uid.Sensor se = sensors.valueAt(ise); |
| 2693 | int sensorNumber = sensors.keyAt(ise); |
| 2694 | Timer timer = se.getSensorTime(); |
| 2695 | if (timer != null) { |
| 2696 | // Convert from microseconds to milliseconds with rounding |
| 2697 | long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000; |
| 2698 | int count = timer.getCountLocked(which); |
| 2699 | if (totalTime != 0) { |
| 2700 | dumpLine(pw, uid, category, SENSOR_DATA, sensorNumber, totalTime, count); |
| 2701 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2702 | } |
| 2703 | } |
| 2704 | |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 2705 | Timer vibTimer = u.getVibratorOnTimer(); |
| 2706 | if (vibTimer != null) { |
| 2707 | // Convert from microseconds to milliseconds with rounding |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2708 | long totalTime = (vibTimer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000; |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 2709 | int count = vibTimer.getCountLocked(which); |
| 2710 | if (totalTime != 0) { |
| 2711 | dumpLine(pw, uid, category, VIBRATOR_DATA, totalTime, count); |
| 2712 | } |
| 2713 | } |
| 2714 | |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 2715 | Timer fgTimer = u.getForegroundActivityTimer(); |
| 2716 | if (fgTimer != null) { |
| 2717 | // Convert from microseconds to milliseconds with rounding |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2718 | long totalTime = (fgTimer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000; |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 2719 | int count = fgTimer.getCountLocked(which); |
| 2720 | if (totalTime != 0) { |
| 2721 | dumpLine(pw, uid, category, FOREGROUND_DATA, totalTime, count); |
| 2722 | } |
| 2723 | } |
| 2724 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 2725 | Object[] stateTimes = new Object[Uid.NUM_PROCESS_STATE]; |
| 2726 | long totalStateTime = 0; |
| 2727 | for (int ips=0; ips<Uid.NUM_PROCESS_STATE; ips++) { |
| 2728 | totalStateTime += u.getProcessStateTime(ips, rawRealtime, which); |
| 2729 | stateTimes[ips] = (totalStateTime + 500) / 1000; |
| 2730 | } |
| 2731 | if (totalStateTime > 0) { |
| 2732 | dumpLine(pw, uid, category, STATE_TIME_DATA, stateTimes); |
| 2733 | } |
| 2734 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2735 | Map<String, ? extends BatteryStats.Uid.Proc> processStats = u.getProcessStats(); |
| 2736 | if (processStats.size() > 0) { |
| 2737 | for (Map.Entry<String, ? extends BatteryStats.Uid.Proc> ent |
| 2738 | : processStats.entrySet()) { |
| 2739 | Uid.Proc ps = ent.getValue(); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 2740 | |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 2741 | final long userMillis = ps.getUserTime(which); |
| 2742 | final long systemMillis = ps.getSystemTime(which); |
| 2743 | final long foregroundMillis = ps.getForegroundTime(which); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 2744 | final int starts = ps.getStarts(which); |
| 2745 | final int numCrashes = ps.getNumCrashes(which); |
| 2746 | final int numAnrs = ps.getNumAnrs(which); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 2747 | |
| 2748 | if (userMillis != 0 || systemMillis != 0 || foregroundMillis != 0 |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 2749 | || starts != 0 || numAnrs != 0 || numCrashes != 0) { |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 2750 | dumpLine(pw, uid, category, PROCESS_DATA, ent.getKey(), userMillis, |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 2751 | systemMillis, foregroundMillis, starts, numAnrs, numCrashes); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2752 | } |
| 2753 | } |
| 2754 | } |
| 2755 | |
| 2756 | Map<String, ? extends BatteryStats.Uid.Pkg> packageStats = u.getPackageStats(); |
| 2757 | if (packageStats.size() > 0) { |
| 2758 | for (Map.Entry<String, ? extends BatteryStats.Uid.Pkg> ent |
| 2759 | : packageStats.entrySet()) { |
| 2760 | |
| 2761 | Uid.Pkg ps = ent.getValue(); |
| 2762 | int wakeups = ps.getWakeups(which); |
| 2763 | Map<String, ? extends Uid.Pkg.Serv> serviceStats = ps.getServiceStats(); |
| 2764 | for (Map.Entry<String, ? extends BatteryStats.Uid.Pkg.Serv> sent |
| 2765 | : serviceStats.entrySet()) { |
| 2766 | BatteryStats.Uid.Pkg.Serv ss = sent.getValue(); |
| 2767 | long startTime = ss.getStartTime(batteryUptime, which); |
| 2768 | int starts = ss.getStarts(which); |
| 2769 | int launches = ss.getLaunches(which); |
| 2770 | if (startTime != 0 || starts != 0 || launches != 0) { |
| 2771 | dumpLine(pw, uid, category, APK_DATA, |
| 2772 | wakeups, // wakeup alarms |
| 2773 | ent.getKey(), // Apk |
| 2774 | sent.getKey(), // service |
| 2775 | startTime / 1000, // time spent started, in ms |
| 2776 | starts, |
| 2777 | launches); |
| 2778 | } |
| 2779 | } |
| 2780 | } |
| 2781 | } |
| 2782 | } |
| 2783 | } |
| 2784 | |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 2785 | static final class TimerEntry { |
| 2786 | final String mName; |
| 2787 | final int mId; |
| 2788 | final BatteryStats.Timer mTimer; |
| 2789 | final long mTime; |
| 2790 | TimerEntry(String name, int id, BatteryStats.Timer timer, long time) { |
| 2791 | mName = name; |
| 2792 | mId = id; |
| 2793 | mTimer = timer; |
| 2794 | mTime = time; |
| 2795 | } |
| 2796 | } |
| 2797 | |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 2798 | private void printmAh(PrintWriter printer, double power) { |
| 2799 | printer.print(BatteryStatsHelper.makemAh(power)); |
| 2800 | } |
| 2801 | |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 2802 | /** |
| 2803 | * Temporary for settings. |
| 2804 | */ |
| 2805 | public final void dumpLocked(Context context, PrintWriter pw, String prefix, int which, |
| 2806 | int reqUid) { |
| 2807 | dumpLocked(context, pw, prefix, which, reqUid, BatteryStatsHelper.checkWifiOnly(context)); |
| 2808 | } |
| 2809 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2810 | @SuppressWarnings("unused") |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 2811 | public final void dumpLocked(Context context, PrintWriter pw, String prefix, final int which, |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 2812 | int reqUid, boolean wifiOnly) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2813 | final long rawUptime = SystemClock.uptimeMillis() * 1000; |
| 2814 | final long rawRealtime = SystemClock.elapsedRealtime() * 1000; |
| 2815 | final long batteryUptime = getBatteryUptime(rawUptime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2816 | |
| 2817 | final long whichBatteryUptime = computeBatteryUptime(rawUptime, which); |
| 2818 | final long whichBatteryRealtime = computeBatteryRealtime(rawRealtime, which); |
| 2819 | final long totalRealtime = computeRealtime(rawRealtime, which); |
| 2820 | final long totalUptime = computeUptime(rawUptime, which); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2821 | final long whichBatteryScreenOffUptime = computeBatteryScreenOffUptime(rawUptime, which); |
| 2822 | final long whichBatteryScreenOffRealtime = computeBatteryScreenOffRealtime(rawRealtime, |
| 2823 | which); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2824 | final long batteryTimeRemaining = computeBatteryTimeRemaining(rawRealtime); |
| 2825 | final long chargeTimeRemaining = computeChargeTimeRemaining(rawRealtime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2826 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2827 | StringBuilder sb = new StringBuilder(128); |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 2828 | |
| 2829 | SparseArray<? extends Uid> uidStats = getUidStats(); |
| 2830 | final int NU = uidStats.size(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2831 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 2832 | sb.setLength(0); |
| 2833 | sb.append(prefix); |
| 2834 | sb.append(" Time on battery: "); |
| 2835 | formatTimeMs(sb, whichBatteryRealtime / 1000); sb.append("("); |
| 2836 | sb.append(formatRatioLocked(whichBatteryRealtime, totalRealtime)); |
| 2837 | sb.append(") realtime, "); |
| 2838 | formatTimeMs(sb, whichBatteryUptime / 1000); |
| 2839 | sb.append("("); sb.append(formatRatioLocked(whichBatteryUptime, totalRealtime)); |
| 2840 | sb.append(") uptime"); |
| 2841 | pw.println(sb.toString()); |
| 2842 | sb.setLength(0); |
| 2843 | sb.append(prefix); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2844 | sb.append(" Time on battery screen off: "); |
| 2845 | formatTimeMs(sb, whichBatteryScreenOffRealtime / 1000); sb.append("("); |
| 2846 | sb.append(formatRatioLocked(whichBatteryScreenOffRealtime, totalRealtime)); |
| 2847 | sb.append(") realtime, "); |
| 2848 | formatTimeMs(sb, whichBatteryScreenOffUptime / 1000); |
| 2849 | sb.append("("); |
| 2850 | sb.append(formatRatioLocked(whichBatteryScreenOffUptime, totalRealtime)); |
| 2851 | sb.append(") uptime"); |
| 2852 | pw.println(sb.toString()); |
| 2853 | sb.setLength(0); |
| 2854 | sb.append(prefix); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 2855 | sb.append(" Total run time: "); |
| 2856 | formatTimeMs(sb, totalRealtime / 1000); |
| 2857 | sb.append("realtime, "); |
| 2858 | formatTimeMs(sb, totalUptime / 1000); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 2859 | sb.append("uptime"); |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 2860 | pw.println(sb.toString()); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2861 | if (batteryTimeRemaining >= 0) { |
| 2862 | sb.setLength(0); |
| 2863 | sb.append(prefix); |
| 2864 | sb.append(" Battery time remaining: "); |
| 2865 | formatTimeMs(sb, batteryTimeRemaining / 1000); |
| 2866 | pw.println(sb.toString()); |
| 2867 | } |
| 2868 | if (chargeTimeRemaining >= 0) { |
| 2869 | sb.setLength(0); |
| 2870 | sb.append(prefix); |
| 2871 | sb.append(" Charge time remaining: "); |
| 2872 | formatTimeMs(sb, chargeTimeRemaining / 1000); |
| 2873 | pw.println(sb.toString()); |
| 2874 | } |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 2875 | pw.print(" Start clock time: "); |
| 2876 | pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss", getStartClockTime()).toString()); |
| 2877 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2878 | final long screenOnTime = getScreenOnTime(rawRealtime, which); |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 2879 | final long interactiveTime = getInteractiveTime(rawRealtime, which); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame^] | 2880 | final long powerSaveModeEnabledTime = getPowerSaveModeEnabledTime(rawRealtime, which); |
| 2881 | final long deviceIdleModeEnabledTime = getDeviceIdleModeEnabledTime(rawRealtime, which); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2882 | final long phoneOnTime = getPhoneOnTime(rawRealtime, which); |
| 2883 | final long wifiRunningTime = getGlobalWifiRunningTime(rawRealtime, which); |
| 2884 | final long wifiOnTime = getWifiOnTime(rawRealtime, which); |
| 2885 | final long bluetoothOnTime = getBluetoothOnTime(rawRealtime, which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2886 | sb.setLength(0); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 2887 | sb.append(prefix); |
| 2888 | sb.append(" Screen on: "); formatTimeMs(sb, screenOnTime / 1000); |
| 2889 | sb.append("("); sb.append(formatRatioLocked(screenOnTime, whichBatteryRealtime)); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 2890 | sb.append(") "); sb.append(getScreenOnCount(which)); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 2891 | sb.append("x, Interactive: "); formatTimeMs(sb, interactiveTime / 1000); |
| 2892 | sb.append("("); sb.append(formatRatioLocked(interactiveTime, whichBatteryRealtime)); |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 2893 | sb.append(")"); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 2894 | pw.println(sb.toString()); |
| 2895 | sb.setLength(0); |
| 2896 | sb.append(prefix); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 2897 | sb.append(" Screen brightnesses:"); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2898 | boolean didOne = false; |
| 2899 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2900 | final long time = getScreenBrightnessTime(i, rawRealtime, which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2901 | if (time == 0) { |
| 2902 | continue; |
| 2903 | } |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 2904 | sb.append("\n "); |
| 2905 | sb.append(prefix); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2906 | didOne = true; |
| 2907 | sb.append(SCREEN_BRIGHTNESS_NAMES[i]); |
| 2908 | sb.append(" "); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 2909 | formatTimeMs(sb, time/1000); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2910 | sb.append("("); |
| 2911 | sb.append(formatRatioLocked(time, screenOnTime)); |
| 2912 | sb.append(")"); |
| 2913 | } |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 2914 | if (!didOne) sb.append(" (no activity)"); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2915 | pw.println(sb.toString()); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame^] | 2916 | if (powerSaveModeEnabledTime != 0) { |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 2917 | sb.setLength(0); |
| 2918 | sb.append(prefix); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame^] | 2919 | sb.append(" Power save mode enabled: "); |
| 2920 | formatTimeMs(sb, powerSaveModeEnabledTime / 1000); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 2921 | sb.append("("); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame^] | 2922 | sb.append(formatRatioLocked(powerSaveModeEnabledTime, whichBatteryRealtime)); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 2923 | sb.append(")"); |
| 2924 | pw.println(sb.toString()); |
| 2925 | } |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame^] | 2926 | if (deviceIdleModeEnabledTime != 0) { |
| 2927 | sb.setLength(0); |
| 2928 | sb.append(prefix); |
| 2929 | sb.append(" Device idling: "); |
| 2930 | formatTimeMs(sb, deviceIdleModeEnabledTime / 1000); |
| 2931 | sb.append("("); |
| 2932 | sb.append(formatRatioLocked(deviceIdleModeEnabledTime, whichBatteryRealtime)); |
| 2933 | sb.append(") "); sb.append(getDeviceIdleModeEnabledCount(which)); |
| 2934 | sb.append("x"); |
| 2935 | pw.println(sb.toString()); |
| 2936 | } |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 2937 | if (phoneOnTime != 0) { |
| 2938 | sb.setLength(0); |
| 2939 | sb.append(prefix); |
| 2940 | sb.append(" Active phone call: "); formatTimeMs(sb, phoneOnTime / 1000); |
| 2941 | sb.append("("); sb.append(formatRatioLocked(phoneOnTime, whichBatteryRealtime)); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame^] | 2942 | sb.append(") "); sb.append(getPhoneOnCount(which)); sb.append("x"); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 2943 | } |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 2944 | int connChanges = getNumConnectivityChange(which); |
| 2945 | if (connChanges != 0) { |
| 2946 | pw.print(prefix); |
| 2947 | pw.print(" Connectivity changes: "); pw.println(connChanges); |
| 2948 | } |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 2949 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2950 | // Calculate wakelock times across all uids. |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 2951 | long fullWakeLockTimeTotalMicros = 0; |
| 2952 | long partialWakeLockTimeTotalMicros = 0; |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 2953 | |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 2954 | final ArrayList<TimerEntry> timers = new ArrayList<TimerEntry>(); |
| 2955 | |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 2956 | for (int iu = 0; iu < NU; iu++) { |
| 2957 | Uid u = uidStats.valueAt(iu); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 2958 | |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 2959 | Map<String, ? extends BatteryStats.Uid.Wakelock> wakelocks = u.getWakelockStats(); |
| 2960 | if (wakelocks.size() > 0) { |
| 2961 | for (Map.Entry<String, ? extends BatteryStats.Uid.Wakelock> ent |
| 2962 | : wakelocks.entrySet()) { |
| 2963 | Uid.Wakelock wl = ent.getValue(); |
| 2964 | |
| 2965 | Timer fullWakeTimer = wl.getWakeTime(WAKE_TYPE_FULL); |
| 2966 | if (fullWakeTimer != null) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2967 | fullWakeLockTimeTotalMicros += fullWakeTimer.getTotalTimeLocked( |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2968 | rawRealtime, which); |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 2969 | } |
| 2970 | |
| 2971 | Timer partialWakeTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL); |
| 2972 | if (partialWakeTimer != null) { |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 2973 | long totalTimeMicros = partialWakeTimer.getTotalTimeLocked( |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2974 | rawRealtime, which); |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 2975 | if (totalTimeMicros > 0) { |
| 2976 | if (reqUid < 0) { |
| 2977 | // Only show the ordered list of all wake |
| 2978 | // locks if the caller is not asking for data |
| 2979 | // about a specific uid. |
| 2980 | timers.add(new TimerEntry(ent.getKey(), u.getUid(), |
| 2981 | partialWakeTimer, totalTimeMicros)); |
| 2982 | } |
| 2983 | partialWakeLockTimeTotalMicros += totalTimeMicros; |
| 2984 | } |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 2985 | } |
| 2986 | } |
| 2987 | } |
| 2988 | } |
| 2989 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2990 | long mobileRxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which); |
| 2991 | long mobileTxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which); |
| 2992 | long wifiRxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which); |
| 2993 | long wifiTxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which); |
| 2994 | long mobileRxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which); |
| 2995 | long mobileTxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which); |
| 2996 | long wifiRxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which); |
| 2997 | long wifiTxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which); |
| 2998 | |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 2999 | if (fullWakeLockTimeTotalMicros != 0) { |
| 3000 | sb.setLength(0); |
| 3001 | sb.append(prefix); |
| 3002 | sb.append(" Total full wakelock time: "); formatTimeMsNoSpace(sb, |
| 3003 | (fullWakeLockTimeTotalMicros + 500) / 1000); |
| 3004 | pw.println(sb.toString()); |
| 3005 | } |
| 3006 | |
| 3007 | if (partialWakeLockTimeTotalMicros != 0) { |
| 3008 | sb.setLength(0); |
| 3009 | sb.append(prefix); |
| 3010 | sb.append(" Total partial wakelock time: "); formatTimeMsNoSpace(sb, |
| 3011 | (partialWakeLockTimeTotalMicros + 500) / 1000); |
| 3012 | pw.println(sb.toString()); |
| 3013 | } |
| 3014 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3015 | pw.print(prefix); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3016 | pw.print(" Mobile total received: "); pw.print(formatBytesLocked(mobileRxTotalBytes)); |
| 3017 | pw.print(", sent: "); pw.print(formatBytesLocked(mobileTxTotalBytes)); |
| 3018 | pw.print(" (packets received "); pw.print(mobileRxTotalPackets); |
| 3019 | pw.print(", sent "); pw.print(mobileTxTotalPackets); pw.println(")"); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3020 | sb.setLength(0); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3021 | sb.append(prefix); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 3022 | sb.append(" Phone signal levels:"); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3023 | didOne = false; |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 3024 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3025 | final long time = getPhoneSignalStrengthTime(i, rawRealtime, which); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3026 | if (time == 0) { |
| 3027 | continue; |
| 3028 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3029 | sb.append("\n "); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 3030 | sb.append(prefix); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3031 | didOne = true; |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 3032 | sb.append(SignalStrength.SIGNAL_STRENGTH_NAMES[i]); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3033 | sb.append(" "); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3034 | formatTimeMs(sb, time/1000); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3035 | sb.append("("); |
| 3036 | sb.append(formatRatioLocked(time, whichBatteryRealtime)); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3037 | sb.append(") "); |
| 3038 | sb.append(getPhoneSignalStrengthCount(i, which)); |
| 3039 | sb.append("x"); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3040 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3041 | if (!didOne) sb.append(" (no activity)"); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3042 | pw.println(sb.toString()); |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 3043 | |
| 3044 | sb.setLength(0); |
| 3045 | sb.append(prefix); |
| 3046 | sb.append(" Signal scanning time: "); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3047 | formatTimeMsNoSpace(sb, getPhoneSignalScanningTime(rawRealtime, which) / 1000); |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 3048 | pw.println(sb.toString()); |
| 3049 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3050 | sb.setLength(0); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3051 | sb.append(prefix); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3052 | sb.append(" Radio types:"); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3053 | didOne = false; |
| 3054 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3055 | final long time = getPhoneDataConnectionTime(i, rawRealtime, which); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3056 | if (time == 0) { |
| 3057 | continue; |
| 3058 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3059 | sb.append("\n "); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 3060 | sb.append(prefix); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3061 | didOne = true; |
| 3062 | sb.append(DATA_CONNECTION_NAMES[i]); |
| 3063 | sb.append(" "); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3064 | formatTimeMs(sb, time/1000); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3065 | sb.append("("); |
| 3066 | sb.append(formatRatioLocked(time, whichBatteryRealtime)); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3067 | sb.append(") "); |
| 3068 | sb.append(getPhoneDataConnectionCount(i, which)); |
| 3069 | sb.append("x"); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3070 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3071 | if (!didOne) sb.append(" (no activity)"); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3072 | pw.println(sb.toString()); |
Amith Yamasani | 3f7e35c | 2009-07-13 16:02:45 -0700 | [diff] [blame] | 3073 | |
| 3074 | sb.setLength(0); |
| 3075 | sb.append(prefix); |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 3076 | sb.append(" Mobile radio active time: "); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3077 | final long mobileActiveTime = getMobileRadioActiveTime(rawRealtime, which); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 3078 | formatTimeMs(sb, mobileActiveTime / 1000); |
| 3079 | sb.append("("); sb.append(formatRatioLocked(mobileActiveTime, whichBatteryRealtime)); |
| 3080 | sb.append(") "); sb.append(getMobileRadioActiveCount(which)); |
| 3081 | sb.append("x"); |
Amith Yamasani | 3f7e35c | 2009-07-13 16:02:45 -0700 | [diff] [blame] | 3082 | pw.println(sb.toString()); |
| 3083 | |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 3084 | final long mobileActiveUnknownTime = getMobileRadioActiveUnknownTime(which); |
| 3085 | if (mobileActiveUnknownTime != 0) { |
| 3086 | sb.setLength(0); |
| 3087 | sb.append(prefix); |
| 3088 | sb.append(" Mobile radio active unknown time: "); |
| 3089 | formatTimeMs(sb, mobileActiveUnknownTime / 1000); |
| 3090 | sb.append("("); |
| 3091 | sb.append(formatRatioLocked(mobileActiveUnknownTime, whichBatteryRealtime)); |
| 3092 | sb.append(") "); sb.append(getMobileRadioActiveUnknownCount(which)); |
| 3093 | sb.append("x"); |
| 3094 | pw.println(sb.toString()); |
| 3095 | } |
| 3096 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3097 | final long mobileActiveAdjustedTime = getMobileRadioActiveAdjustedTime(which); |
| 3098 | if (mobileActiveAdjustedTime != 0) { |
| 3099 | sb.setLength(0); |
| 3100 | sb.append(prefix); |
| 3101 | sb.append(" Mobile radio active adjusted time: "); |
| 3102 | formatTimeMs(sb, mobileActiveAdjustedTime / 1000); |
| 3103 | sb.append("("); |
| 3104 | sb.append(formatRatioLocked(mobileActiveAdjustedTime, whichBatteryRealtime)); |
| 3105 | sb.append(")"); |
| 3106 | pw.println(sb.toString()); |
| 3107 | } |
| 3108 | |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 3109 | pw.print(prefix); |
| 3110 | pw.print(" Wi-Fi total received: "); pw.print(formatBytesLocked(wifiRxTotalBytes)); |
| 3111 | pw.print(", sent: "); pw.print(formatBytesLocked(wifiTxTotalBytes)); |
| 3112 | pw.print(" (packets received "); pw.print(wifiRxTotalPackets); |
| 3113 | pw.print(", sent "); pw.print(wifiTxTotalPackets); pw.println(")"); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3114 | sb.setLength(0); |
| 3115 | sb.append(prefix); |
| 3116 | sb.append(" Wifi on: "); formatTimeMs(sb, wifiOnTime / 1000); |
| 3117 | sb.append("("); sb.append(formatRatioLocked(wifiOnTime, whichBatteryRealtime)); |
| 3118 | sb.append("), Wifi running: "); formatTimeMs(sb, wifiRunningTime / 1000); |
| 3119 | sb.append("("); sb.append(formatRatioLocked(wifiRunningTime, whichBatteryRealtime)); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3120 | sb.append(")"); |
| 3121 | pw.println(sb.toString()); |
| 3122 | |
| 3123 | sb.setLength(0); |
| 3124 | sb.append(prefix); |
| 3125 | sb.append(" Wifi states:"); |
| 3126 | didOne = false; |
| 3127 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3128 | final long time = getWifiStateTime(i, rawRealtime, which); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3129 | if (time == 0) { |
| 3130 | continue; |
| 3131 | } |
| 3132 | sb.append("\n "); |
| 3133 | didOne = true; |
| 3134 | sb.append(WIFI_STATE_NAMES[i]); |
| 3135 | sb.append(" "); |
| 3136 | formatTimeMs(sb, time/1000); |
| 3137 | sb.append("("); |
| 3138 | sb.append(formatRatioLocked(time, whichBatteryRealtime)); |
| 3139 | sb.append(") "); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 3140 | sb.append(getWifiStateCount(i, which)); |
| 3141 | sb.append("x"); |
| 3142 | } |
| 3143 | if (!didOne) sb.append(" (no activity)"); |
| 3144 | pw.println(sb.toString()); |
| 3145 | |
| 3146 | sb.setLength(0); |
| 3147 | sb.append(prefix); |
| 3148 | sb.append(" Wifi supplicant states:"); |
| 3149 | didOne = false; |
| 3150 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
| 3151 | final long time = getWifiSupplStateTime(i, rawRealtime, which); |
| 3152 | if (time == 0) { |
| 3153 | continue; |
| 3154 | } |
| 3155 | sb.append("\n "); |
| 3156 | didOne = true; |
| 3157 | sb.append(WIFI_SUPPL_STATE_NAMES[i]); |
| 3158 | sb.append(" "); |
| 3159 | formatTimeMs(sb, time/1000); |
| 3160 | sb.append("("); |
| 3161 | sb.append(formatRatioLocked(time, whichBatteryRealtime)); |
| 3162 | sb.append(") "); |
| 3163 | sb.append(getWifiSupplStateCount(i, which)); |
| 3164 | sb.append("x"); |
| 3165 | } |
| 3166 | if (!didOne) sb.append(" (no activity)"); |
| 3167 | pw.println(sb.toString()); |
| 3168 | |
| 3169 | sb.setLength(0); |
| 3170 | sb.append(prefix); |
| 3171 | sb.append(" Wifi signal levels:"); |
| 3172 | didOne = false; |
| 3173 | for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 3174 | final long time = getWifiSignalStrengthTime(i, rawRealtime, which); |
| 3175 | if (time == 0) { |
| 3176 | continue; |
| 3177 | } |
| 3178 | sb.append("\n "); |
| 3179 | sb.append(prefix); |
| 3180 | didOne = true; |
| 3181 | sb.append("level("); |
| 3182 | sb.append(i); |
| 3183 | sb.append(") "); |
| 3184 | formatTimeMs(sb, time/1000); |
| 3185 | sb.append("("); |
| 3186 | sb.append(formatRatioLocked(time, whichBatteryRealtime)); |
| 3187 | sb.append(") "); |
| 3188 | sb.append(getWifiSignalStrengthCount(i, which)); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3189 | sb.append("x"); |
| 3190 | } |
| 3191 | if (!didOne) sb.append(" (no activity)"); |
| 3192 | pw.println(sb.toString()); |
| 3193 | |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 3194 | final long wifiIdleTimeMs = getBluetoothControllerActivity(CONTROLLER_IDLE_TIME, which); |
| 3195 | final long wifiRxTimeMs = getBluetoothControllerActivity(CONTROLLER_RX_TIME, which); |
| 3196 | final long wifiTxTimeMs = getBluetoothControllerActivity(CONTROLLER_TX_TIME, which); |
| 3197 | final long wifiTotalTimeMs = wifiIdleTimeMs + wifiRxTimeMs + wifiTxTimeMs; |
| 3198 | |
| 3199 | sb.setLength(0); |
| 3200 | sb.append(prefix); |
| 3201 | sb.append(" WiFi Idle time: "); formatTimeMs(sb, wifiIdleTimeMs); |
| 3202 | sb.append(" ("); |
| 3203 | sb.append(formatRatioLocked(wifiIdleTimeMs, wifiTotalTimeMs)); |
| 3204 | sb.append(")"); |
| 3205 | pw.println(sb.toString()); |
| 3206 | |
| 3207 | sb.setLength(0); |
| 3208 | sb.append(prefix); |
| 3209 | sb.append(" WiFi Rx time: "); formatTimeMs(sb, wifiRxTimeMs); |
| 3210 | sb.append(" ("); |
| 3211 | sb.append(formatRatioLocked(wifiRxTimeMs, wifiTotalTimeMs)); |
| 3212 | sb.append(")"); |
| 3213 | pw.println(sb.toString()); |
| 3214 | |
| 3215 | sb.setLength(0); |
| 3216 | sb.append(prefix); |
| 3217 | sb.append(" WiFi Tx time: "); formatTimeMs(sb, wifiTxTimeMs); |
| 3218 | sb.append(" ("); |
| 3219 | sb.append(formatRatioLocked(wifiTxTimeMs, wifiTotalTimeMs)); |
| 3220 | sb.append(")"); |
| 3221 | pw.println(sb.toString()); |
| 3222 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3223 | sb.setLength(0); |
| 3224 | sb.append(prefix); |
| 3225 | sb.append(" Bluetooth on: "); formatTimeMs(sb, bluetoothOnTime / 1000); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3226 | sb.append("("); sb.append(formatRatioLocked(bluetoothOnTime, whichBatteryRealtime)); |
| 3227 | sb.append(")"); |
| 3228 | pw.println(sb.toString()); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3229 | |
| 3230 | sb.setLength(0); |
| 3231 | sb.append(prefix); |
| 3232 | sb.append(" Bluetooth states:"); |
| 3233 | didOne = false; |
| 3234 | for (int i=0; i<NUM_BLUETOOTH_STATES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3235 | final long time = getBluetoothStateTime(i, rawRealtime, which); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3236 | if (time == 0) { |
| 3237 | continue; |
| 3238 | } |
| 3239 | sb.append("\n "); |
| 3240 | didOne = true; |
| 3241 | sb.append(BLUETOOTH_STATE_NAMES[i]); |
| 3242 | sb.append(" "); |
| 3243 | formatTimeMs(sb, time/1000); |
| 3244 | sb.append("("); |
| 3245 | sb.append(formatRatioLocked(time, whichBatteryRealtime)); |
| 3246 | sb.append(") "); |
| 3247 | sb.append(getPhoneDataConnectionCount(i, which)); |
| 3248 | sb.append("x"); |
| 3249 | } |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 3250 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3251 | if (!didOne) sb.append(" (no activity)"); |
| 3252 | pw.println(sb.toString()); |
| 3253 | |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 3254 | final long bluetoothIdleTimeMs = |
| 3255 | getBluetoothControllerActivity(CONTROLLER_IDLE_TIME, which); |
| 3256 | final long bluetoothRxTimeMs = getBluetoothControllerActivity(CONTROLLER_RX_TIME, which); |
| 3257 | final long bluetoothTxTimeMs = getBluetoothControllerActivity(CONTROLLER_TX_TIME, which); |
| 3258 | final long bluetoothTotalTimeMs = bluetoothIdleTimeMs + bluetoothRxTimeMs + |
| 3259 | bluetoothTxTimeMs; |
| 3260 | |
| 3261 | sb.setLength(0); |
| 3262 | sb.append(prefix); |
| 3263 | sb.append(" Bluetooth Idle time: "); formatTimeMs(sb, bluetoothIdleTimeMs); |
| 3264 | sb.append(" ("); |
| 3265 | sb.append(formatRatioLocked(bluetoothIdleTimeMs, bluetoothTotalTimeMs)); |
| 3266 | sb.append(")"); |
| 3267 | pw.println(sb.toString()); |
| 3268 | |
| 3269 | sb.setLength(0); |
| 3270 | sb.append(prefix); |
| 3271 | sb.append(" Bluetooth Rx time: "); formatTimeMs(sb, bluetoothRxTimeMs); |
| 3272 | sb.append(" ("); |
| 3273 | sb.append(formatRatioLocked(bluetoothRxTimeMs, bluetoothTotalTimeMs)); |
| 3274 | sb.append(")"); |
| 3275 | pw.println(sb.toString()); |
| 3276 | |
| 3277 | sb.setLength(0); |
| 3278 | sb.append(prefix); |
| 3279 | sb.append(" Bluetooth Tx time: "); formatTimeMs(sb, bluetoothTxTimeMs); |
| 3280 | sb.append(" ("); |
| 3281 | sb.append(formatRatioLocked(bluetoothTxTimeMs, bluetoothTotalTimeMs)); |
| 3282 | sb.append(")"); |
| 3283 | pw.println(sb.toString()); |
| 3284 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3285 | pw.println(); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3286 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3287 | if (which == STATS_SINCE_UNPLUGGED) { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3288 | if (getIsOnBattery()) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3289 | pw.print(prefix); pw.println(" Device is currently unplugged"); |
| 3290 | pw.print(prefix); pw.print(" Discharge cycle start level: "); |
| 3291 | pw.println(getDischargeStartLevel()); |
| 3292 | pw.print(prefix); pw.print(" Discharge cycle current level: "); |
| 3293 | pw.println(getDischargeCurrentLevel()); |
Dianne Hackborn | 99d0452 | 2010-08-20 13:43:00 -0700 | [diff] [blame] | 3294 | } else { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3295 | pw.print(prefix); pw.println(" Device is currently plugged into power"); |
| 3296 | pw.print(prefix); pw.print(" Last discharge cycle start level: "); |
| 3297 | pw.println(getDischargeStartLevel()); |
| 3298 | pw.print(prefix); pw.print(" Last discharge cycle end level: "); |
| 3299 | pw.println(getDischargeCurrentLevel()); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3300 | } |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 3301 | pw.print(prefix); pw.print(" Amount discharged while screen on: "); |
| 3302 | pw.println(getDischargeAmountScreenOn()); |
| 3303 | pw.print(prefix); pw.print(" Amount discharged while screen off: "); |
| 3304 | pw.println(getDischargeAmountScreenOff()); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3305 | pw.println(" "); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3306 | } else { |
| 3307 | pw.print(prefix); pw.println(" Device battery use since last full charge"); |
| 3308 | pw.print(prefix); pw.print(" Amount discharged (lower bound): "); |
| 3309 | pw.println(getLowDischargeAmountSinceCharge()); |
| 3310 | pw.print(prefix); pw.print(" Amount discharged (upper bound): "); |
| 3311 | pw.println(getHighDischargeAmountSinceCharge()); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 3312 | pw.print(prefix); pw.print(" Amount discharged while screen on: "); |
| 3313 | pw.println(getDischargeAmountScreenOnSinceCharge()); |
| 3314 | pw.print(prefix); pw.print(" Amount discharged while screen off: "); |
| 3315 | pw.println(getDischargeAmountScreenOffSinceCharge()); |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 3316 | pw.println(); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3317 | } |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 3318 | |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 3319 | BatteryStatsHelper helper = new BatteryStatsHelper(context, false, wifiOnly); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3320 | helper.create(this); |
| 3321 | helper.refreshStats(which, UserHandle.USER_ALL); |
| 3322 | List<BatterySipper> sippers = helper.getUsageList(); |
| 3323 | if (sippers != null && sippers.size() > 0) { |
| 3324 | pw.print(prefix); pw.println(" Estimated power use (mAh):"); |
| 3325 | pw.print(prefix); pw.print(" Capacity: "); |
| 3326 | printmAh(pw, helper.getPowerProfile().getBatteryCapacity()); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3327 | pw.print(", Computed drain: "); printmAh(pw, helper.getComputedPower()); |
Dianne Hackborn | 536456f | 2014-05-23 16:51:05 -0700 | [diff] [blame] | 3328 | pw.print(", actual drain: "); printmAh(pw, helper.getMinDrainedPower()); |
| 3329 | if (helper.getMinDrainedPower() != helper.getMaxDrainedPower()) { |
| 3330 | pw.print("-"); printmAh(pw, helper.getMaxDrainedPower()); |
| 3331 | } |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3332 | pw.println(); |
| 3333 | for (int i=0; i<sippers.size(); i++) { |
| 3334 | BatterySipper bs = sippers.get(i); |
| 3335 | switch (bs.drainType) { |
| 3336 | case IDLE: |
| 3337 | pw.print(prefix); pw.print(" Idle: "); printmAh(pw, bs.value); |
| 3338 | pw.println(); |
| 3339 | break; |
| 3340 | case CELL: |
| 3341 | pw.print(prefix); pw.print(" Cell standby: "); printmAh(pw, bs.value); |
| 3342 | pw.println(); |
| 3343 | break; |
| 3344 | case PHONE: |
| 3345 | pw.print(prefix); pw.print(" Phone calls: "); printmAh(pw, bs.value); |
| 3346 | pw.println(); |
| 3347 | break; |
| 3348 | case WIFI: |
| 3349 | pw.print(prefix); pw.print(" Wifi: "); printmAh(pw, bs.value); |
| 3350 | pw.println(); |
| 3351 | break; |
| 3352 | case BLUETOOTH: |
| 3353 | pw.print(prefix); pw.print(" Bluetooth: "); printmAh(pw, bs.value); |
| 3354 | pw.println(); |
| 3355 | break; |
| 3356 | case SCREEN: |
| 3357 | pw.print(prefix); pw.print(" Screen: "); printmAh(pw, bs.value); |
| 3358 | pw.println(); |
| 3359 | break; |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 3360 | case FLASHLIGHT: |
| 3361 | pw.print(prefix); pw.print(" Flashlight: "); printmAh(pw, bs.value); |
| 3362 | pw.println(); |
| 3363 | break; |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3364 | case APP: |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 3365 | pw.print(prefix); pw.print(" Uid "); |
| 3366 | UserHandle.formatUid(pw, bs.uidObj.getUid()); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3367 | pw.print(": "); printmAh(pw, bs.value); pw.println(); |
| 3368 | break; |
| 3369 | case USER: |
| 3370 | pw.print(prefix); pw.print(" User "); pw.print(bs.userId); |
| 3371 | pw.print(": "); printmAh(pw, bs.value); pw.println(); |
| 3372 | break; |
| 3373 | case UNACCOUNTED: |
| 3374 | pw.print(prefix); pw.print(" Unaccounted: "); printmAh(pw, bs.value); |
| 3375 | pw.println(); |
| 3376 | break; |
| 3377 | case OVERCOUNTED: |
| 3378 | pw.print(prefix); pw.print(" Over-counted: "); printmAh(pw, bs.value); |
| 3379 | pw.println(); |
| 3380 | break; |
| 3381 | } |
| 3382 | } |
Dianne Hackborn | c46809e | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3383 | pw.println(); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3384 | } |
| 3385 | |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 3386 | sippers = helper.getMobilemsppList(); |
| 3387 | if (sippers != null && sippers.size() > 0) { |
| 3388 | pw.print(prefix); pw.println(" Per-app mobile ms per packet:"); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 3389 | long totalTime = 0; |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 3390 | for (int i=0; i<sippers.size(); i++) { |
| 3391 | BatterySipper bs = sippers.get(i); |
| 3392 | sb.setLength(0); |
| 3393 | sb.append(prefix); sb.append(" Uid "); |
| 3394 | UserHandle.formatUid(sb, bs.uidObj.getUid()); |
| 3395 | sb.append(": "); sb.append(BatteryStatsHelper.makemAh(bs.mobilemspp)); |
| 3396 | sb.append(" ("); sb.append(bs.mobileRxPackets+bs.mobileTxPackets); |
| 3397 | sb.append(" packets over "); formatTimeMsNoSpace(sb, bs.mobileActive); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 3398 | sb.append(") "); sb.append(bs.mobileActiveCount); sb.append("x"); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 3399 | pw.println(sb.toString()); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 3400 | totalTime += bs.mobileActive; |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 3401 | } |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 3402 | sb.setLength(0); |
| 3403 | sb.append(prefix); |
| 3404 | sb.append(" TOTAL TIME: "); |
| 3405 | formatTimeMs(sb, totalTime); |
| 3406 | sb.append("("); sb.append(formatRatioLocked(totalTime, whichBatteryRealtime)); |
| 3407 | sb.append(")"); |
| 3408 | pw.println(sb.toString()); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 3409 | pw.println(); |
| 3410 | } |
| 3411 | |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 3412 | final Comparator<TimerEntry> timerComparator = new Comparator<TimerEntry>() { |
| 3413 | @Override |
| 3414 | public int compare(TimerEntry lhs, TimerEntry rhs) { |
| 3415 | long lhsTime = lhs.mTime; |
| 3416 | long rhsTime = rhs.mTime; |
| 3417 | if (lhsTime < rhsTime) { |
| 3418 | return 1; |
| 3419 | } |
| 3420 | if (lhsTime > rhsTime) { |
| 3421 | return -1; |
| 3422 | } |
| 3423 | return 0; |
| 3424 | } |
| 3425 | }; |
| 3426 | |
| 3427 | if (reqUid < 0) { |
| 3428 | Map<String, ? extends BatteryStats.Timer> kernelWakelocks = getKernelWakelockStats(); |
| 3429 | if (kernelWakelocks.size() > 0) { |
| 3430 | final ArrayList<TimerEntry> ktimers = new ArrayList<TimerEntry>(); |
| 3431 | for (Map.Entry<String, ? extends BatteryStats.Timer> ent : kernelWakelocks.entrySet()) { |
| 3432 | BatteryStats.Timer timer = ent.getValue(); |
| 3433 | long totalTimeMillis = computeWakeLock(timer, rawRealtime, which); |
| 3434 | if (totalTimeMillis > 0) { |
| 3435 | ktimers.add(new TimerEntry(ent.getKey(), 0, timer, totalTimeMillis)); |
| 3436 | } |
| 3437 | } |
| 3438 | if (ktimers.size() > 0) { |
| 3439 | Collections.sort(ktimers, timerComparator); |
| 3440 | pw.print(prefix); pw.println(" All kernel wake locks:"); |
| 3441 | for (int i=0; i<ktimers.size(); i++) { |
| 3442 | TimerEntry timer = ktimers.get(i); |
| 3443 | String linePrefix = ": "; |
| 3444 | sb.setLength(0); |
| 3445 | sb.append(prefix); |
| 3446 | sb.append(" Kernel Wake lock "); |
| 3447 | sb.append(timer.mName); |
| 3448 | linePrefix = printWakeLock(sb, timer.mTimer, rawRealtime, null, |
| 3449 | which, linePrefix); |
| 3450 | if (!linePrefix.equals(": ")) { |
| 3451 | sb.append(" realtime"); |
| 3452 | // Only print out wake locks that were held |
| 3453 | pw.println(sb.toString()); |
| 3454 | } |
| 3455 | } |
| 3456 | pw.println(); |
| 3457 | } |
| 3458 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 3459 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3460 | if (timers.size() > 0) { |
| 3461 | Collections.sort(timers, timerComparator); |
| 3462 | pw.print(prefix); pw.println(" All partial wake locks:"); |
| 3463 | for (int i=0; i<timers.size(); i++) { |
| 3464 | TimerEntry timer = timers.get(i); |
| 3465 | sb.setLength(0); |
| 3466 | sb.append(" Wake lock "); |
| 3467 | UserHandle.formatUid(sb, timer.mId); |
| 3468 | sb.append(" "); |
| 3469 | sb.append(timer.mName); |
| 3470 | printWakeLock(sb, timer.mTimer, rawRealtime, null, which, ": "); |
| 3471 | sb.append(" realtime"); |
| 3472 | pw.println(sb.toString()); |
| 3473 | } |
| 3474 | timers.clear(); |
| 3475 | pw.println(); |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 3476 | } |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3477 | |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 3478 | Map<String, ? extends Timer> wakeupReasons = getWakeupReasonStats(); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3479 | if (wakeupReasons.size() > 0) { |
| 3480 | pw.print(prefix); pw.println(" All wakeup reasons:"); |
| 3481 | final ArrayList<TimerEntry> reasons = new ArrayList<TimerEntry>(); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 3482 | for (Map.Entry<String, ? extends Timer> ent : wakeupReasons.entrySet()) { |
| 3483 | Timer timer = ent.getValue(); |
| 3484 | reasons.add(new TimerEntry(ent.getKey(), 0, timer, |
| 3485 | timer.getCountLocked(which))); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3486 | } |
| 3487 | Collections.sort(reasons, timerComparator); |
| 3488 | for (int i=0; i<reasons.size(); i++) { |
| 3489 | TimerEntry timer = reasons.get(i); |
| 3490 | String linePrefix = ": "; |
| 3491 | sb.setLength(0); |
| 3492 | sb.append(prefix); |
| 3493 | sb.append(" Wakeup reason "); |
| 3494 | sb.append(timer.mName); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 3495 | printWakeLock(sb, timer.mTimer, rawRealtime, null, which, ": "); |
| 3496 | sb.append(" realtime"); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3497 | pw.println(sb.toString()); |
| 3498 | } |
| 3499 | pw.println(); |
| 3500 | } |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 3501 | } |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 3502 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3503 | for (int iu=0; iu<NU; iu++) { |
| 3504 | final int uid = uidStats.keyAt(iu); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3505 | if (reqUid >= 0 && uid != reqUid && uid != Process.SYSTEM_UID) { |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 3506 | continue; |
| 3507 | } |
| 3508 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3509 | Uid u = uidStats.valueAt(iu); |
Dianne Hackborn | a4cc205 | 2013-07-08 17:31:25 -0700 | [diff] [blame] | 3510 | |
| 3511 | pw.print(prefix); |
| 3512 | pw.print(" "); |
| 3513 | UserHandle.formatUid(pw, uid); |
| 3514 | pw.println(":"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3515 | boolean uidActivity = false; |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 3516 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3517 | long mobileRxBytes = u.getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which); |
| 3518 | long mobileTxBytes = u.getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which); |
| 3519 | long wifiRxBytes = u.getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which); |
| 3520 | long wifiTxBytes = u.getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which); |
| 3521 | long mobileRxPackets = u.getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which); |
| 3522 | long mobileTxPackets = u.getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 3523 | long uidMobileActiveTime = u.getMobileRadioActiveTime(which); |
| 3524 | int uidMobileActiveCount = u.getMobileRadioActiveCount(which); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3525 | long wifiRxPackets = u.getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which); |
| 3526 | long wifiTxPackets = u.getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3527 | long fullWifiLockOnTime = u.getFullWifiLockTime(rawRealtime, which); |
| 3528 | long wifiScanTime = u.getWifiScanTime(rawRealtime, which); |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 3529 | int wifiScanCount = u.getWifiScanCount(which); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3530 | long uidWifiRunningTime = u.getWifiRunningTime(rawRealtime, which); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 3531 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3532 | if (mobileRxBytes > 0 || mobileTxBytes > 0 |
| 3533 | || mobileRxPackets > 0 || mobileTxPackets > 0) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 3534 | pw.print(prefix); pw.print(" Mobile network: "); |
| 3535 | pw.print(formatBytesLocked(mobileRxBytes)); pw.print(" received, "); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3536 | pw.print(formatBytesLocked(mobileTxBytes)); |
| 3537 | pw.print(" sent (packets "); pw.print(mobileRxPackets); |
| 3538 | pw.print(" received, "); pw.print(mobileTxPackets); pw.println(" sent)"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3539 | } |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 3540 | if (uidMobileActiveTime > 0 || uidMobileActiveCount > 0) { |
| 3541 | sb.setLength(0); |
| 3542 | sb.append(prefix); sb.append(" Mobile radio active: "); |
| 3543 | formatTimeMs(sb, uidMobileActiveTime / 1000); |
| 3544 | sb.append("("); |
| 3545 | sb.append(formatRatioLocked(uidMobileActiveTime, mobileActiveTime)); |
| 3546 | sb.append(") "); sb.append(uidMobileActiveCount); sb.append("x"); |
| 3547 | long packets = mobileRxPackets + mobileTxPackets; |
| 3548 | if (packets == 0) { |
| 3549 | packets = 1; |
| 3550 | } |
| 3551 | sb.append(" @ "); |
| 3552 | sb.append(BatteryStatsHelper.makemAh(uidMobileActiveTime / 1000 / (double)packets)); |
| 3553 | sb.append(" mspp"); |
| 3554 | pw.println(sb.toString()); |
| 3555 | } |
| 3556 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3557 | if (wifiRxBytes > 0 || wifiTxBytes > 0 || wifiRxPackets > 0 || wifiTxPackets > 0) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 3558 | pw.print(prefix); pw.print(" Wi-Fi network: "); |
| 3559 | pw.print(formatBytesLocked(wifiRxBytes)); pw.print(" received, "); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3560 | pw.print(formatBytesLocked(wifiTxBytes)); |
| 3561 | pw.print(" sent (packets "); pw.print(wifiRxPackets); |
| 3562 | pw.print(" received, "); pw.print(wifiTxPackets); pw.println(" sent)"); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 3563 | } |
| 3564 | |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 3565 | if (fullWifiLockOnTime != 0 || wifiScanTime != 0 || wifiScanCount != 0 |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 3566 | || uidWifiRunningTime != 0) { |
| 3567 | sb.setLength(0); |
| 3568 | sb.append(prefix); sb.append(" Wifi Running: "); |
| 3569 | formatTimeMs(sb, uidWifiRunningTime / 1000); |
| 3570 | sb.append("("); sb.append(formatRatioLocked(uidWifiRunningTime, |
| 3571 | whichBatteryRealtime)); sb.append(")\n"); |
| 3572 | sb.append(prefix); sb.append(" Full Wifi Lock: "); |
| 3573 | formatTimeMs(sb, fullWifiLockOnTime / 1000); |
| 3574 | sb.append("("); sb.append(formatRatioLocked(fullWifiLockOnTime, |
| 3575 | whichBatteryRealtime)); sb.append(")\n"); |
| 3576 | sb.append(prefix); sb.append(" Wifi Scan: "); |
| 3577 | formatTimeMs(sb, wifiScanTime / 1000); |
| 3578 | sb.append("("); sb.append(formatRatioLocked(wifiScanTime, |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 3579 | whichBatteryRealtime)); sb.append(") "); |
| 3580 | sb.append(wifiScanCount); |
| 3581 | sb.append("x"); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 3582 | pw.println(sb.toString()); |
| 3583 | } |
| 3584 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3585 | if (u.hasUserActivity()) { |
| 3586 | boolean hasData = false; |
Raph Levien | 4c7a4a7 | 2012-08-03 14:32:39 -0700 | [diff] [blame] | 3587 | for (int i=0; i<Uid.NUM_USER_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3588 | int val = u.getUserActivityCount(i, which); |
| 3589 | if (val != 0) { |
| 3590 | if (!hasData) { |
| 3591 | sb.setLength(0); |
| 3592 | sb.append(" User activity: "); |
| 3593 | hasData = true; |
| 3594 | } else { |
| 3595 | sb.append(", "); |
| 3596 | } |
| 3597 | sb.append(val); |
| 3598 | sb.append(" "); |
| 3599 | sb.append(Uid.USER_ACTIVITY_TYPES[i]); |
| 3600 | } |
| 3601 | } |
| 3602 | if (hasData) { |
| 3603 | pw.println(sb.toString()); |
| 3604 | } |
| 3605 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3606 | |
| 3607 | Map<String, ? extends BatteryStats.Uid.Wakelock> wakelocks = u.getWakelockStats(); |
| 3608 | if (wakelocks.size() > 0) { |
Dianne Hackborn | c24ab86 | 2011-10-18 15:55:03 -0700 | [diff] [blame] | 3609 | long totalFull = 0, totalPartial = 0, totalWindow = 0; |
| 3610 | int count = 0; |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 3611 | 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] | 3612 | Uid.Wakelock wl = ent.getValue(); |
| 3613 | String linePrefix = ": "; |
| 3614 | sb.setLength(0); |
| 3615 | sb.append(prefix); |
| 3616 | sb.append(" Wake lock "); |
| 3617 | sb.append(ent.getKey()); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3618 | linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_FULL), rawRealtime, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3619 | "full", which, linePrefix); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3620 | linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_PARTIAL), rawRealtime, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3621 | "partial", which, linePrefix); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3622 | linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_WINDOW), rawRealtime, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3623 | "window", which, linePrefix); |
Dianne Hackborn | acc4a12 | 2014-08-18 16:33:44 -0700 | [diff] [blame] | 3624 | if (true || !linePrefix.equals(": ")) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3625 | sb.append(" realtime"); |
Jason Parks | 94b916d | 2010-07-20 12:39:07 -0500 | [diff] [blame] | 3626 | // Only print out wake locks that were held |
| 3627 | pw.println(sb.toString()); |
| 3628 | uidActivity = true; |
Dianne Hackborn | c24ab86 | 2011-10-18 15:55:03 -0700 | [diff] [blame] | 3629 | count++; |
| 3630 | } |
| 3631 | totalFull += computeWakeLock(wl.getWakeTime(WAKE_TYPE_FULL), |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3632 | rawRealtime, which); |
Dianne Hackborn | c24ab86 | 2011-10-18 15:55:03 -0700 | [diff] [blame] | 3633 | totalPartial += computeWakeLock(wl.getWakeTime(WAKE_TYPE_PARTIAL), |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3634 | rawRealtime, which); |
Dianne Hackborn | c24ab86 | 2011-10-18 15:55:03 -0700 | [diff] [blame] | 3635 | totalWindow += computeWakeLock(wl.getWakeTime(WAKE_TYPE_WINDOW), |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3636 | rawRealtime, which); |
Dianne Hackborn | c24ab86 | 2011-10-18 15:55:03 -0700 | [diff] [blame] | 3637 | } |
| 3638 | if (count > 1) { |
| 3639 | if (totalFull != 0 || totalPartial != 0 || totalWindow != 0) { |
| 3640 | sb.setLength(0); |
| 3641 | sb.append(prefix); |
| 3642 | sb.append(" TOTAL wake: "); |
| 3643 | boolean needComma = false; |
| 3644 | if (totalFull != 0) { |
| 3645 | needComma = true; |
| 3646 | formatTimeMs(sb, totalFull); |
| 3647 | sb.append("full"); |
| 3648 | } |
| 3649 | if (totalPartial != 0) { |
| 3650 | if (needComma) { |
| 3651 | sb.append(", "); |
| 3652 | } |
| 3653 | needComma = true; |
| 3654 | formatTimeMs(sb, totalPartial); |
| 3655 | sb.append("partial"); |
| 3656 | } |
| 3657 | if (totalWindow != 0) { |
| 3658 | if (needComma) { |
| 3659 | sb.append(", "); |
| 3660 | } |
| 3661 | needComma = true; |
| 3662 | formatTimeMs(sb, totalWindow); |
| 3663 | sb.append("window"); |
| 3664 | } |
| 3665 | sb.append(" realtime"); |
| 3666 | pw.println(sb.toString()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3667 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3668 | } |
| 3669 | } |
| 3670 | |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 3671 | Map<String, ? extends Timer> syncs = u.getSyncStats(); |
| 3672 | if (syncs.size() > 0) { |
| 3673 | for (Map.Entry<String, ? extends Timer> ent : syncs.entrySet()) { |
| 3674 | Timer timer = ent.getValue(); |
| 3675 | // Convert from microseconds to milliseconds with rounding |
| 3676 | long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000; |
| 3677 | int count = timer.getCountLocked(which); |
| 3678 | sb.setLength(0); |
| 3679 | sb.append(prefix); |
| 3680 | sb.append(" Sync "); |
| 3681 | sb.append(ent.getKey()); |
| 3682 | sb.append(": "); |
| 3683 | if (totalTime != 0) { |
| 3684 | formatTimeMs(sb, totalTime); |
| 3685 | sb.append("realtime ("); |
| 3686 | sb.append(count); |
| 3687 | sb.append(" times)"); |
| 3688 | } else { |
| 3689 | sb.append("(not used)"); |
| 3690 | } |
| 3691 | pw.println(sb.toString()); |
| 3692 | uidActivity = true; |
| 3693 | } |
| 3694 | } |
| 3695 | |
| 3696 | Map<String, ? extends Timer> jobs = u.getJobStats(); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 3697 | if (jobs.size() > 0) { |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 3698 | for (Map.Entry<String, ? extends Timer> ent : jobs.entrySet()) { |
| 3699 | Timer timer = ent.getValue(); |
| 3700 | // Convert from microseconds to milliseconds with rounding |
| 3701 | long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000; |
| 3702 | int count = timer.getCountLocked(which); |
| 3703 | sb.setLength(0); |
| 3704 | sb.append(prefix); |
| 3705 | sb.append(" Job "); |
| 3706 | sb.append(ent.getKey()); |
| 3707 | sb.append(": "); |
| 3708 | if (totalTime != 0) { |
| 3709 | formatTimeMs(sb, totalTime); |
| 3710 | sb.append("realtime ("); |
| 3711 | sb.append(count); |
| 3712 | sb.append(" times)"); |
| 3713 | } else { |
| 3714 | sb.append("(not used)"); |
| 3715 | } |
| 3716 | pw.println(sb.toString()); |
| 3717 | uidActivity = true; |
| 3718 | } |
| 3719 | } |
| 3720 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 3721 | SparseArray<? extends BatteryStats.Uid.Sensor> sensors = u.getSensorStats(); |
| 3722 | int NSE = sensors.size(); |
| 3723 | for (int ise=0; ise<NSE; ise++) { |
| 3724 | Uid.Sensor se = sensors.valueAt(ise); |
| 3725 | int sensorNumber = sensors.keyAt(ise); |
| 3726 | sb.setLength(0); |
| 3727 | sb.append(prefix); |
| 3728 | sb.append(" Sensor "); |
| 3729 | int handle = se.getHandle(); |
| 3730 | if (handle == Uid.Sensor.GPS) { |
| 3731 | sb.append("GPS"); |
| 3732 | } else { |
| 3733 | sb.append(handle); |
| 3734 | } |
| 3735 | sb.append(": "); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3736 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 3737 | Timer timer = se.getSensorTime(); |
| 3738 | if (timer != null) { |
| 3739 | // Convert from microseconds to milliseconds with rounding |
| 3740 | long totalTime = (timer.getTotalTimeLocked( |
| 3741 | rawRealtime, which) + 500) / 1000; |
| 3742 | int count = timer.getCountLocked(which); |
| 3743 | //timer.logState(); |
| 3744 | if (totalTime != 0) { |
| 3745 | formatTimeMs(sb, totalTime); |
| 3746 | sb.append("realtime ("); |
| 3747 | sb.append(count); |
| 3748 | sb.append(" times)"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3749 | } else { |
| 3750 | sb.append("(not used)"); |
| 3751 | } |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 3752 | } else { |
| 3753 | sb.append("(not used)"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3754 | } |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 3755 | |
| 3756 | pw.println(sb.toString()); |
| 3757 | uidActivity = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3758 | } |
| 3759 | |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 3760 | Timer vibTimer = u.getVibratorOnTimer(); |
| 3761 | if (vibTimer != null) { |
| 3762 | // Convert from microseconds to milliseconds with rounding |
| 3763 | long totalTime = (vibTimer.getTotalTimeLocked( |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3764 | rawRealtime, which) + 500) / 1000; |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 3765 | int count = vibTimer.getCountLocked(which); |
| 3766 | //timer.logState(); |
| 3767 | if (totalTime != 0) { |
| 3768 | sb.setLength(0); |
| 3769 | sb.append(prefix); |
| 3770 | sb.append(" Vibrator: "); |
| 3771 | formatTimeMs(sb, totalTime); |
| 3772 | sb.append("realtime ("); |
| 3773 | sb.append(count); |
| 3774 | sb.append(" times)"); |
| 3775 | pw.println(sb.toString()); |
| 3776 | uidActivity = true; |
| 3777 | } |
| 3778 | } |
| 3779 | |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 3780 | Timer fgTimer = u.getForegroundActivityTimer(); |
| 3781 | if (fgTimer != null) { |
| 3782 | // Convert from microseconds to milliseconds with rounding |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3783 | long totalTime = (fgTimer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000; |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 3784 | int count = fgTimer.getCountLocked(which); |
| 3785 | if (totalTime != 0) { |
| 3786 | sb.setLength(0); |
| 3787 | sb.append(prefix); |
| 3788 | sb.append(" Foreground activities: "); |
| 3789 | formatTimeMs(sb, totalTime); |
| 3790 | sb.append("realtime ("); |
| 3791 | sb.append(count); |
| 3792 | sb.append(" times)"); |
| 3793 | pw.println(sb.toString()); |
| 3794 | uidActivity = true; |
| 3795 | } |
| 3796 | } |
| 3797 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 3798 | long totalStateTime = 0; |
| 3799 | for (int ips=0; ips<Uid.NUM_PROCESS_STATE; ips++) { |
| 3800 | long time = u.getProcessStateTime(ips, rawRealtime, which); |
| 3801 | if (time > 0) { |
| 3802 | totalStateTime += time; |
| 3803 | sb.setLength(0); |
| 3804 | sb.append(prefix); |
| 3805 | sb.append(" "); |
| 3806 | sb.append(Uid.PROCESS_STATE_NAMES[ips]); |
| 3807 | sb.append(" for: "); |
| 3808 | formatTimeMs(sb, (totalStateTime + 500) / 1000); |
| 3809 | pw.println(sb.toString()); |
| 3810 | uidActivity = true; |
| 3811 | } |
| 3812 | } |
| 3813 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3814 | Map<String, ? extends BatteryStats.Uid.Proc> processStats = u.getProcessStats(); |
| 3815 | if (processStats.size() > 0) { |
| 3816 | for (Map.Entry<String, ? extends BatteryStats.Uid.Proc> ent |
| 3817 | : processStats.entrySet()) { |
| 3818 | Uid.Proc ps = ent.getValue(); |
| 3819 | long userTime; |
| 3820 | long systemTime; |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 3821 | long foregroundTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3822 | int starts; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3823 | int numExcessive; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3824 | |
| 3825 | userTime = ps.getUserTime(which); |
| 3826 | systemTime = ps.getSystemTime(which); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 3827 | foregroundTime = ps.getForegroundTime(which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3828 | starts = ps.getStarts(which); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 3829 | final int numCrashes = ps.getNumCrashes(which); |
| 3830 | final int numAnrs = ps.getNumAnrs(which); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3831 | numExcessive = which == STATS_SINCE_CHARGED |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 3832 | ? ps.countExcessivePowers() : 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3833 | |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 3834 | if (userTime != 0 || systemTime != 0 || foregroundTime != 0 || starts != 0 |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 3835 | || numExcessive != 0 || numCrashes != 0 || numAnrs != 0) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3836 | sb.setLength(0); |
| 3837 | sb.append(prefix); sb.append(" Proc "); |
| 3838 | sb.append(ent.getKey()); sb.append(":\n"); |
| 3839 | sb.append(prefix); sb.append(" CPU: "); |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 3840 | formatTimeMs(sb, userTime); sb.append("usr + "); |
| 3841 | formatTimeMs(sb, systemTime); sb.append("krn ; "); |
| 3842 | formatTimeMs(sb, foregroundTime); sb.append("fg"); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 3843 | if (starts != 0 || numCrashes != 0 || numAnrs != 0) { |
Dianne Hackborn | b8071d79 | 2010-09-09 16:45:15 -0700 | [diff] [blame] | 3844 | sb.append("\n"); sb.append(prefix); sb.append(" "); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 3845 | boolean hasOne = false; |
| 3846 | if (starts != 0) { |
| 3847 | hasOne = true; |
| 3848 | sb.append(starts); sb.append(" starts"); |
| 3849 | } |
| 3850 | if (numCrashes != 0) { |
| 3851 | if (hasOne) { |
| 3852 | sb.append(", "); |
| 3853 | } |
| 3854 | hasOne = true; |
| 3855 | sb.append(numCrashes); sb.append(" crashes"); |
| 3856 | } |
| 3857 | if (numAnrs != 0) { |
| 3858 | if (hasOne) { |
| 3859 | sb.append(", "); |
| 3860 | } |
| 3861 | sb.append(numAnrs); sb.append(" anrs"); |
| 3862 | } |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 3863 | } |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3864 | pw.println(sb.toString()); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3865 | for (int e=0; e<numExcessive; e++) { |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 3866 | Uid.Proc.ExcessivePower ew = ps.getExcessivePower(e); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3867 | if (ew != null) { |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 3868 | pw.print(prefix); pw.print(" * Killed for "); |
| 3869 | if (ew.type == Uid.Proc.ExcessivePower.TYPE_WAKE) { |
| 3870 | pw.print("wake lock"); |
| 3871 | } else if (ew.type == Uid.Proc.ExcessivePower.TYPE_CPU) { |
| 3872 | pw.print("cpu"); |
| 3873 | } else { |
| 3874 | pw.print("unknown"); |
| 3875 | } |
| 3876 | pw.print(" use: "); |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 3877 | TimeUtils.formatDuration(ew.usedTime, pw); |
| 3878 | pw.print(" over "); |
| 3879 | TimeUtils.formatDuration(ew.overTime, pw); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 3880 | if (ew.overTime != 0) { |
| 3881 | pw.print(" ("); |
| 3882 | pw.print((ew.usedTime*100)/ew.overTime); |
| 3883 | pw.println("%)"); |
| 3884 | } |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3885 | } |
| 3886 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3887 | uidActivity = true; |
| 3888 | } |
| 3889 | } |
| 3890 | } |
| 3891 | |
| 3892 | Map<String, ? extends BatteryStats.Uid.Pkg> packageStats = u.getPackageStats(); |
| 3893 | if (packageStats.size() > 0) { |
| 3894 | for (Map.Entry<String, ? extends BatteryStats.Uid.Pkg> ent |
| 3895 | : packageStats.entrySet()) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3896 | 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] | 3897 | boolean apkActivity = false; |
| 3898 | Uid.Pkg ps = ent.getValue(); |
| 3899 | int wakeups = ps.getWakeups(which); |
| 3900 | if (wakeups != 0) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3901 | pw.print(prefix); pw.print(" "); |
| 3902 | pw.print(wakeups); pw.println(" wakeup alarms"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3903 | apkActivity = true; |
| 3904 | } |
| 3905 | Map<String, ? extends Uid.Pkg.Serv> serviceStats = ps.getServiceStats(); |
| 3906 | if (serviceStats.size() > 0) { |
| 3907 | for (Map.Entry<String, ? extends BatteryStats.Uid.Pkg.Serv> sent |
| 3908 | : serviceStats.entrySet()) { |
| 3909 | BatteryStats.Uid.Pkg.Serv ss = sent.getValue(); |
| 3910 | long startTime = ss.getStartTime(batteryUptime, which); |
| 3911 | int starts = ss.getStarts(which); |
| 3912 | int launches = ss.getLaunches(which); |
| 3913 | if (startTime != 0 || starts != 0 || launches != 0) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3914 | sb.setLength(0); |
| 3915 | sb.append(prefix); sb.append(" Service "); |
| 3916 | sb.append(sent.getKey()); sb.append(":\n"); |
| 3917 | sb.append(prefix); sb.append(" Created for: "); |
| 3918 | formatTimeMs(sb, startTime / 1000); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 3919 | sb.append("uptime\n"); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3920 | sb.append(prefix); sb.append(" Starts: "); |
| 3921 | sb.append(starts); |
| 3922 | sb.append(", launches: "); sb.append(launches); |
| 3923 | pw.println(sb.toString()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3924 | apkActivity = true; |
| 3925 | } |
| 3926 | } |
| 3927 | } |
| 3928 | if (!apkActivity) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3929 | pw.print(prefix); pw.println(" (nothing executed)"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3930 | } |
| 3931 | uidActivity = true; |
| 3932 | } |
| 3933 | } |
| 3934 | if (!uidActivity) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3935 | pw.print(prefix); pw.println(" (nothing executed)"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3936 | } |
| 3937 | } |
| 3938 | } |
| 3939 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3940 | static void printBitDescriptions(PrintWriter pw, int oldval, int newval, HistoryTag wakelockTag, |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3941 | BitDescription[] descriptions, boolean longNames) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3942 | int diff = oldval ^ newval; |
| 3943 | if (diff == 0) return; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3944 | boolean didWake = false; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3945 | for (int i=0; i<descriptions.length; i++) { |
| 3946 | BitDescription bd = descriptions[i]; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3947 | if ((diff&bd.mask) != 0) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3948 | pw.print(longNames ? " " : ","); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3949 | if (bd.shift < 0) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3950 | pw.print((newval&bd.mask) != 0 ? "+" : "-"); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3951 | pw.print(longNames ? bd.name : bd.shortName); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3952 | if (bd.mask == HistoryItem.STATE_WAKE_LOCK_FLAG && wakelockTag != null) { |
| 3953 | didWake = true; |
| 3954 | pw.print("="); |
| 3955 | if (longNames) { |
| 3956 | UserHandle.formatUid(pw, wakelockTag.uid); |
| 3957 | pw.print(":\""); |
| 3958 | pw.print(wakelockTag.string); |
| 3959 | pw.print("\""); |
| 3960 | } else { |
| 3961 | pw.print(wakelockTag.poolIdx); |
| 3962 | } |
| 3963 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3964 | } else { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3965 | pw.print(longNames ? bd.name : bd.shortName); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3966 | pw.print("="); |
| 3967 | int val = (newval&bd.mask)>>bd.shift; |
| 3968 | if (bd.values != null && val >= 0 && val < bd.values.length) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3969 | pw.print(longNames? bd.values[val] : bd.shortValues[val]); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3970 | } else { |
| 3971 | pw.print(val); |
| 3972 | } |
| 3973 | } |
| 3974 | } |
| 3975 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3976 | if (!didWake && wakelockTag != null) { |
Ashish Sharma | 81850c4 | 2014-05-05 13:57:07 -0700 | [diff] [blame] | 3977 | pw.print(longNames ? " wake_lock=" : ",w="); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3978 | if (longNames) { |
| 3979 | UserHandle.formatUid(pw, wakelockTag.uid); |
| 3980 | pw.print(":\""); |
| 3981 | pw.print(wakelockTag.string); |
| 3982 | pw.print("\""); |
| 3983 | } else { |
| 3984 | pw.print(wakelockTag.poolIdx); |
| 3985 | } |
| 3986 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3987 | } |
| 3988 | |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 3989 | public void prepareForDumpLocked() { |
| 3990 | } |
| 3991 | |
| 3992 | public static class HistoryPrinter { |
| 3993 | int oldState = 0; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3994 | int oldState2 = 0; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3995 | int oldLevel = -1; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 3996 | int oldStatus = -1; |
| 3997 | int oldHealth = -1; |
| 3998 | int oldPlug = -1; |
| 3999 | int oldTemp = -1; |
| 4000 | int oldVolt = -1; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4001 | long lastTime = -1; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 4002 | |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 4003 | void reset() { |
| 4004 | oldState = oldState2 = 0; |
| 4005 | oldLevel = -1; |
| 4006 | oldStatus = -1; |
| 4007 | oldHealth = -1; |
| 4008 | oldPlug = -1; |
| 4009 | oldTemp = -1; |
| 4010 | oldVolt = -1; |
| 4011 | } |
| 4012 | |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 4013 | public void printNextItem(PrintWriter pw, HistoryItem rec, long baseTime, boolean checkin, |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 4014 | boolean verbose) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4015 | if (!checkin) { |
| 4016 | pw.print(" "); |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 4017 | TimeUtils.formatDuration(rec.time - baseTime, pw, TimeUtils.HUNDRED_DAY_FIELD_LEN); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 4018 | pw.print(" ("); |
| 4019 | pw.print(rec.numReadInts); |
| 4020 | pw.print(") "); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4021 | } else { |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 4022 | pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(','); |
| 4023 | pw.print(HISTORY_DATA); pw.print(','); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4024 | if (lastTime < 0) { |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 4025 | pw.print(rec.time - baseTime); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4026 | } else { |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 4027 | pw.print(rec.time - lastTime); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4028 | } |
| 4029 | lastTime = rec.time; |
| 4030 | } |
| 4031 | if (rec.cmd == HistoryItem.CMD_START) { |
| 4032 | if (checkin) { |
| 4033 | pw.print(":"); |
| 4034 | } |
| 4035 | pw.println("START"); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 4036 | reset(); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 4037 | } else if (rec.cmd == HistoryItem.CMD_CURRENT_TIME |
| 4038 | || rec.cmd == HistoryItem.CMD_RESET) { |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 4039 | if (checkin) { |
| 4040 | pw.print(":"); |
| 4041 | } |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 4042 | if (rec.cmd == HistoryItem.CMD_RESET) { |
| 4043 | pw.print("RESET:"); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 4044 | reset(); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 4045 | } |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 4046 | pw.print("TIME:"); |
| 4047 | if (checkin) { |
| 4048 | pw.println(rec.currentTime); |
| 4049 | } else { |
| 4050 | pw.print(" "); |
| 4051 | pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss", |
| 4052 | rec.currentTime).toString()); |
| 4053 | } |
Dianne Hackborn | 29cd7f1 | 2015-01-08 10:37:05 -0800 | [diff] [blame] | 4054 | } else if (rec.cmd == HistoryItem.CMD_SHUTDOWN) { |
| 4055 | if (checkin) { |
| 4056 | pw.print(":"); |
| 4057 | } |
| 4058 | pw.println("SHUTDOWN"); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4059 | } else if (rec.cmd == HistoryItem.CMD_OVERFLOW) { |
| 4060 | if (checkin) { |
| 4061 | pw.print(":"); |
| 4062 | } |
| 4063 | pw.println("*OVERFLOW*"); |
| 4064 | } else { |
| 4065 | if (!checkin) { |
| 4066 | if (rec.batteryLevel < 10) pw.print("00"); |
| 4067 | else if (rec.batteryLevel < 100) pw.print("0"); |
| 4068 | pw.print(rec.batteryLevel); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 4069 | if (verbose) { |
| 4070 | pw.print(" "); |
| 4071 | if (rec.states < 0) ; |
| 4072 | else if (rec.states < 0x10) pw.print("0000000"); |
| 4073 | else if (rec.states < 0x100) pw.print("000000"); |
| 4074 | else if (rec.states < 0x1000) pw.print("00000"); |
| 4075 | else if (rec.states < 0x10000) pw.print("0000"); |
| 4076 | else if (rec.states < 0x100000) pw.print("000"); |
| 4077 | else if (rec.states < 0x1000000) pw.print("00"); |
| 4078 | else if (rec.states < 0x10000000) pw.print("0"); |
| 4079 | pw.print(Integer.toHexString(rec.states)); |
| 4080 | } |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4081 | } else { |
| 4082 | if (oldLevel != rec.batteryLevel) { |
| 4083 | oldLevel = rec.batteryLevel; |
| 4084 | pw.print(",Bl="); pw.print(rec.batteryLevel); |
| 4085 | } |
| 4086 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 4087 | if (oldStatus != rec.batteryStatus) { |
| 4088 | oldStatus = rec.batteryStatus; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4089 | pw.print(checkin ? ",Bs=" : " status="); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 4090 | switch (oldStatus) { |
| 4091 | case BatteryManager.BATTERY_STATUS_UNKNOWN: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4092 | pw.print(checkin ? "?" : "unknown"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 4093 | break; |
| 4094 | case BatteryManager.BATTERY_STATUS_CHARGING: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4095 | pw.print(checkin ? "c" : "charging"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 4096 | break; |
| 4097 | case BatteryManager.BATTERY_STATUS_DISCHARGING: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4098 | pw.print(checkin ? "d" : "discharging"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 4099 | break; |
| 4100 | case BatteryManager.BATTERY_STATUS_NOT_CHARGING: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4101 | pw.print(checkin ? "n" : "not-charging"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 4102 | break; |
| 4103 | case BatteryManager.BATTERY_STATUS_FULL: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4104 | pw.print(checkin ? "f" : "full"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 4105 | break; |
| 4106 | default: |
| 4107 | pw.print(oldStatus); |
| 4108 | break; |
| 4109 | } |
| 4110 | } |
| 4111 | if (oldHealth != rec.batteryHealth) { |
| 4112 | oldHealth = rec.batteryHealth; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4113 | pw.print(checkin ? ",Bh=" : " health="); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 4114 | switch (oldHealth) { |
| 4115 | case BatteryManager.BATTERY_HEALTH_UNKNOWN: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4116 | pw.print(checkin ? "?" : "unknown"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 4117 | break; |
| 4118 | case BatteryManager.BATTERY_HEALTH_GOOD: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4119 | pw.print(checkin ? "g" : "good"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 4120 | break; |
| 4121 | case BatteryManager.BATTERY_HEALTH_OVERHEAT: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4122 | pw.print(checkin ? "h" : "overheat"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 4123 | break; |
| 4124 | case BatteryManager.BATTERY_HEALTH_DEAD: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4125 | pw.print(checkin ? "d" : "dead"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 4126 | break; |
| 4127 | case BatteryManager.BATTERY_HEALTH_OVER_VOLTAGE: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4128 | pw.print(checkin ? "v" : "over-voltage"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 4129 | break; |
| 4130 | case BatteryManager.BATTERY_HEALTH_UNSPECIFIED_FAILURE: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4131 | pw.print(checkin ? "f" : "failure"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 4132 | break; |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 4133 | case BatteryManager.BATTERY_HEALTH_COLD: |
| 4134 | pw.print(checkin ? "c" : "cold"); |
| 4135 | break; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 4136 | default: |
| 4137 | pw.print(oldHealth); |
| 4138 | break; |
| 4139 | } |
| 4140 | } |
| 4141 | if (oldPlug != rec.batteryPlugType) { |
| 4142 | oldPlug = rec.batteryPlugType; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4143 | pw.print(checkin ? ",Bp=" : " plug="); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 4144 | switch (oldPlug) { |
| 4145 | case 0: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4146 | pw.print(checkin ? "n" : "none"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 4147 | break; |
| 4148 | case BatteryManager.BATTERY_PLUGGED_AC: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4149 | pw.print(checkin ? "a" : "ac"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 4150 | break; |
| 4151 | case BatteryManager.BATTERY_PLUGGED_USB: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4152 | pw.print(checkin ? "u" : "usb"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 4153 | break; |
Brian Muramatsu | 37a37f4 | 2012-08-14 15:21:02 -0700 | [diff] [blame] | 4154 | case BatteryManager.BATTERY_PLUGGED_WIRELESS: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4155 | pw.print(checkin ? "w" : "wireless"); |
Brian Muramatsu | 37a37f4 | 2012-08-14 15:21:02 -0700 | [diff] [blame] | 4156 | break; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 4157 | default: |
| 4158 | pw.print(oldPlug); |
| 4159 | break; |
| 4160 | } |
| 4161 | } |
| 4162 | if (oldTemp != rec.batteryTemperature) { |
| 4163 | oldTemp = rec.batteryTemperature; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4164 | pw.print(checkin ? ",Bt=" : " temp="); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 4165 | pw.print(oldTemp); |
| 4166 | } |
| 4167 | if (oldVolt != rec.batteryVoltage) { |
| 4168 | oldVolt = rec.batteryVoltage; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4169 | pw.print(checkin ? ",Bv=" : " volt="); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 4170 | pw.print(oldVolt); |
| 4171 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 4172 | printBitDescriptions(pw, oldState, rec.states, rec.wakelockTag, |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4173 | HISTORY_STATE_DESCRIPTIONS, !checkin); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 4174 | printBitDescriptions(pw, oldState2, rec.states2, null, |
| 4175 | HISTORY_STATE2_DESCRIPTIONS, !checkin); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 4176 | if (rec.wakeReasonTag != null) { |
| 4177 | if (checkin) { |
Dianne Hackborn | d06dcfd | 2014-05-02 13:49:30 -0700 | [diff] [blame] | 4178 | pw.print(",wr="); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 4179 | pw.print(rec.wakeReasonTag.poolIdx); |
| 4180 | } else { |
| 4181 | pw.print(" wake_reason="); |
| 4182 | pw.print(rec.wakeReasonTag.uid); |
| 4183 | pw.print(":\""); |
| 4184 | pw.print(rec.wakeReasonTag.string); |
| 4185 | pw.print("\""); |
| 4186 | } |
| 4187 | } |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4188 | if (rec.eventCode != HistoryItem.EVENT_NONE) { |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 4189 | pw.print(checkin ? "," : " "); |
| 4190 | if ((rec.eventCode&HistoryItem.EVENT_FLAG_START) != 0) { |
| 4191 | pw.print("+"); |
| 4192 | } else if ((rec.eventCode&HistoryItem.EVENT_FLAG_FINISH) != 0) { |
| 4193 | pw.print("-"); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4194 | } |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 4195 | String[] eventNames = checkin ? HISTORY_EVENT_CHECKIN_NAMES |
| 4196 | : HISTORY_EVENT_NAMES; |
| 4197 | int idx = rec.eventCode & ~(HistoryItem.EVENT_FLAG_START |
| 4198 | | HistoryItem.EVENT_FLAG_FINISH); |
| 4199 | if (idx >= 0 && idx < eventNames.length) { |
| 4200 | pw.print(eventNames[idx]); |
| 4201 | } else { |
| 4202 | pw.print(checkin ? "Ev" : "event"); |
| 4203 | pw.print(idx); |
| 4204 | } |
| 4205 | pw.print("="); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4206 | if (checkin) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 4207 | pw.print(rec.eventTag.poolIdx); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4208 | } else { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 4209 | UserHandle.formatUid(pw, rec.eventTag.uid); |
| 4210 | pw.print(":\""); |
| 4211 | pw.print(rec.eventTag.string); |
| 4212 | pw.print("\""); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4213 | } |
| 4214 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 4215 | pw.println(); |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 4216 | if (rec.stepDetails != null) { |
| 4217 | if (!checkin) { |
| 4218 | pw.print(" Details: cpu="); |
| 4219 | pw.print(rec.stepDetails.userTime); |
| 4220 | pw.print("u+"); |
| 4221 | pw.print(rec.stepDetails.systemTime); |
| 4222 | pw.print("s"); |
| 4223 | if (rec.stepDetails.appCpuUid1 >= 0) { |
| 4224 | pw.print(" ("); |
| 4225 | printStepCpuUidDetails(pw, rec.stepDetails.appCpuUid1, |
| 4226 | rec.stepDetails.appCpuUTime1, rec.stepDetails.appCpuSTime1); |
| 4227 | if (rec.stepDetails.appCpuUid2 >= 0) { |
| 4228 | pw.print(", "); |
| 4229 | printStepCpuUidDetails(pw, rec.stepDetails.appCpuUid2, |
| 4230 | rec.stepDetails.appCpuUTime2, rec.stepDetails.appCpuSTime2); |
| 4231 | } |
| 4232 | if (rec.stepDetails.appCpuUid3 >= 0) { |
| 4233 | pw.print(", "); |
| 4234 | printStepCpuUidDetails(pw, rec.stepDetails.appCpuUid3, |
| 4235 | rec.stepDetails.appCpuUTime3, rec.stepDetails.appCpuSTime3); |
| 4236 | } |
| 4237 | pw.print(')'); |
| 4238 | } |
| 4239 | pw.println(); |
| 4240 | pw.print(" /proc/stat="); |
| 4241 | pw.print(rec.stepDetails.statUserTime); |
| 4242 | pw.print(" usr, "); |
| 4243 | pw.print(rec.stepDetails.statSystemTime); |
| 4244 | pw.print(" sys, "); |
| 4245 | pw.print(rec.stepDetails.statIOWaitTime); |
| 4246 | pw.print(" io, "); |
| 4247 | pw.print(rec.stepDetails.statIrqTime); |
| 4248 | pw.print(" irq, "); |
| 4249 | pw.print(rec.stepDetails.statSoftIrqTime); |
| 4250 | pw.print(" sirq, "); |
| 4251 | pw.print(rec.stepDetails.statIdlTime); |
| 4252 | pw.print(" idle"); |
| 4253 | int totalRun = rec.stepDetails.statUserTime + rec.stepDetails.statSystemTime |
| 4254 | + rec.stepDetails.statIOWaitTime + rec.stepDetails.statIrqTime |
| 4255 | + rec.stepDetails.statSoftIrqTime; |
| 4256 | int total = totalRun + rec.stepDetails.statIdlTime; |
| 4257 | if (total > 0) { |
| 4258 | pw.print(" ("); |
| 4259 | float perc = ((float)totalRun) / ((float)total) * 100; |
| 4260 | pw.print(String.format("%.1f%%", perc)); |
| 4261 | pw.print(" of "); |
| 4262 | StringBuilder sb = new StringBuilder(64); |
| 4263 | formatTimeMsNoSpace(sb, total*10); |
| 4264 | pw.print(sb); |
| 4265 | pw.print(")"); |
| 4266 | } |
| 4267 | pw.println(); |
| 4268 | } else { |
| 4269 | pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(','); |
| 4270 | pw.print(HISTORY_DATA); pw.print(",0,Dcpu="); |
| 4271 | pw.print(rec.stepDetails.userTime); |
| 4272 | pw.print(":"); |
| 4273 | pw.print(rec.stepDetails.systemTime); |
| 4274 | if (rec.stepDetails.appCpuUid1 >= 0) { |
| 4275 | printStepCpuUidCheckinDetails(pw, rec.stepDetails.appCpuUid1, |
| 4276 | rec.stepDetails.appCpuUTime1, rec.stepDetails.appCpuSTime1); |
| 4277 | if (rec.stepDetails.appCpuUid2 >= 0) { |
| 4278 | printStepCpuUidCheckinDetails(pw, rec.stepDetails.appCpuUid2, |
| 4279 | rec.stepDetails.appCpuUTime2, rec.stepDetails.appCpuSTime2); |
| 4280 | } |
| 4281 | if (rec.stepDetails.appCpuUid3 >= 0) { |
| 4282 | printStepCpuUidCheckinDetails(pw, rec.stepDetails.appCpuUid3, |
| 4283 | rec.stepDetails.appCpuUTime3, rec.stepDetails.appCpuSTime3); |
| 4284 | } |
| 4285 | } |
| 4286 | pw.println(); |
| 4287 | pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(','); |
| 4288 | pw.print(HISTORY_DATA); pw.print(",0,Dpst="); |
| 4289 | pw.print(rec.stepDetails.statUserTime); |
| 4290 | pw.print(','); |
| 4291 | pw.print(rec.stepDetails.statSystemTime); |
| 4292 | pw.print(','); |
| 4293 | pw.print(rec.stepDetails.statIOWaitTime); |
| 4294 | pw.print(','); |
| 4295 | pw.print(rec.stepDetails.statIrqTime); |
| 4296 | pw.print(','); |
| 4297 | pw.print(rec.stepDetails.statSoftIrqTime); |
| 4298 | pw.print(','); |
| 4299 | pw.print(rec.stepDetails.statIdlTime); |
| 4300 | pw.println(); |
| 4301 | } |
| 4302 | } |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 4303 | oldState = rec.states; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 4304 | oldState2 = rec.states2; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 4305 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 4306 | } |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 4307 | |
| 4308 | private void printStepCpuUidDetails(PrintWriter pw, int uid, int utime, int stime) { |
| 4309 | UserHandle.formatUid(pw, uid); |
| 4310 | pw.print("="); |
| 4311 | pw.print(utime); |
| 4312 | pw.print("u+"); |
| 4313 | pw.print(stime); |
| 4314 | pw.print("s"); |
| 4315 | } |
| 4316 | |
| 4317 | private void printStepCpuUidCheckinDetails(PrintWriter pw, int uid, int utime, int stime) { |
| 4318 | pw.print('/'); |
| 4319 | pw.print(uid); |
| 4320 | pw.print(":"); |
| 4321 | pw.print(utime); |
| 4322 | pw.print(":"); |
| 4323 | pw.print(stime); |
| 4324 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 4325 | } |
| 4326 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 4327 | private void printSizeValue(PrintWriter pw, long size) { |
| 4328 | float result = size; |
| 4329 | String suffix = ""; |
| 4330 | if (result >= 10*1024) { |
| 4331 | suffix = "KB"; |
| 4332 | result = result / 1024; |
| 4333 | } |
| 4334 | if (result >= 10*1024) { |
| 4335 | suffix = "MB"; |
| 4336 | result = result / 1024; |
| 4337 | } |
| 4338 | if (result >= 10*1024) { |
| 4339 | suffix = "GB"; |
| 4340 | result = result / 1024; |
| 4341 | } |
| 4342 | if (result >= 10*1024) { |
| 4343 | suffix = "TB"; |
| 4344 | result = result / 1024; |
| 4345 | } |
| 4346 | if (result >= 10*1024) { |
| 4347 | suffix = "PB"; |
| 4348 | result = result / 1024; |
| 4349 | } |
| 4350 | pw.print((int)result); |
| 4351 | pw.print(suffix); |
| 4352 | } |
| 4353 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 4354 | private static boolean dumpTimeEstimate(PrintWriter pw, String label1, String label2, |
| 4355 | String label3, long estimatedTime) { |
| 4356 | if (estimatedTime < 0) { |
Dianne Hackborn | ad6a99b | 2014-11-18 10:11:10 -0800 | [diff] [blame] | 4357 | return false; |
| 4358 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 4359 | pw.print(label1); |
| 4360 | pw.print(label2); |
| 4361 | pw.print(label3); |
Dianne Hackborn | ad6a99b | 2014-11-18 10:11:10 -0800 | [diff] [blame] | 4362 | StringBuilder sb = new StringBuilder(64); |
| 4363 | formatTimeMs(sb, estimatedTime); |
| 4364 | pw.print(sb); |
| 4365 | pw.println(); |
Dianne Hackborn | ad6a99b | 2014-11-18 10:11:10 -0800 | [diff] [blame] | 4366 | return true; |
| 4367 | } |
| 4368 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 4369 | private static boolean dumpDurationSteps(PrintWriter pw, String prefix, String header, |
| 4370 | LevelStepTracker steps, boolean checkin) { |
| 4371 | if (steps == null) { |
| 4372 | return false; |
| 4373 | } |
| 4374 | int count = steps.mNumStepDurations; |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 4375 | if (count <= 0) { |
| 4376 | return false; |
| 4377 | } |
| 4378 | if (!checkin) { |
| 4379 | pw.println(header); |
| 4380 | } |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 4381 | String[] lineArgs = new String[4]; |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 4382 | for (int i=0; i<count; i++) { |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 4383 | long duration = steps.getDurationAt(i); |
| 4384 | int level = steps.getLevelAt(i); |
| 4385 | long initMode = steps.getInitModeAt(i); |
| 4386 | long modMode = steps.getModModeAt(i); |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 4387 | if (checkin) { |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 4388 | lineArgs[0] = Long.toString(duration); |
| 4389 | lineArgs[1] = Integer.toString(level); |
| 4390 | if ((modMode&STEP_LEVEL_MODE_SCREEN_STATE) == 0) { |
| 4391 | switch ((int)(initMode&STEP_LEVEL_MODE_SCREEN_STATE) + 1) { |
| 4392 | case Display.STATE_OFF: lineArgs[2] = "s-"; break; |
| 4393 | case Display.STATE_ON: lineArgs[2] = "s+"; break; |
| 4394 | case Display.STATE_DOZE: lineArgs[2] = "sd"; break; |
| 4395 | case Display.STATE_DOZE_SUSPEND: lineArgs[2] = "sds"; break; |
| 4396 | default: lineArgs[1] = "?"; break; |
| 4397 | } |
| 4398 | } else { |
| 4399 | lineArgs[2] = ""; |
| 4400 | } |
| 4401 | if ((modMode&STEP_LEVEL_MODE_POWER_SAVE) == 0) { |
| 4402 | lineArgs[3] = (initMode&STEP_LEVEL_MODE_POWER_SAVE) != 0 ? "p+" : "p-"; |
| 4403 | } else { |
| 4404 | lineArgs[3] = ""; |
| 4405 | } |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 4406 | dumpLine(pw, 0 /* uid */, "i" /* category */, header, (Object[])lineArgs); |
| 4407 | } else { |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 4408 | pw.print(prefix); |
| 4409 | pw.print("#"); pw.print(i); pw.print(": "); |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 4410 | TimeUtils.formatDuration(duration, pw); |
| 4411 | pw.print(" to "); pw.print(level); |
| 4412 | boolean haveModes = false; |
| 4413 | if ((modMode&STEP_LEVEL_MODE_SCREEN_STATE) == 0) { |
| 4414 | pw.print(" ("); |
| 4415 | switch ((int)(initMode&STEP_LEVEL_MODE_SCREEN_STATE) + 1) { |
| 4416 | case Display.STATE_OFF: pw.print("screen-off"); break; |
| 4417 | case Display.STATE_ON: pw.print("screen-on"); break; |
| 4418 | case Display.STATE_DOZE: pw.print("screen-doze"); break; |
| 4419 | case Display.STATE_DOZE_SUSPEND: pw.print("screen-doze-suspend"); break; |
| 4420 | default: lineArgs[1] = "screen-?"; break; |
| 4421 | } |
| 4422 | haveModes = true; |
| 4423 | } |
| 4424 | if ((modMode&STEP_LEVEL_MODE_POWER_SAVE) == 0) { |
| 4425 | pw.print(haveModes ? ", " : " ("); |
| 4426 | pw.print((initMode&STEP_LEVEL_MODE_POWER_SAVE) != 0 |
| 4427 | ? "power-save-on" : "power-save-off"); |
| 4428 | haveModes = true; |
| 4429 | } |
| 4430 | if (haveModes) { |
| 4431 | pw.print(")"); |
| 4432 | } |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 4433 | pw.println(); |
| 4434 | } |
| 4435 | } |
| 4436 | return true; |
| 4437 | } |
| 4438 | |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 4439 | public static final int DUMP_UNPLUGGED_ONLY = 1<<0; |
| 4440 | public static final int DUMP_CHARGED_ONLY = 1<<1; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 4441 | public static final int DUMP_DAILY_ONLY = 1<<2; |
| 4442 | public static final int DUMP_HISTORY_ONLY = 1<<3; |
| 4443 | public static final int DUMP_INCLUDE_HISTORY = 1<<4; |
| 4444 | public static final int DUMP_VERBOSE = 1<<5; |
| 4445 | public static final int DUMP_DEVICE_WIFI_ONLY = 1<<6; |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 4446 | |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 4447 | private void dumpHistoryLocked(PrintWriter pw, int flags, long histStart, boolean checkin) { |
| 4448 | final HistoryPrinter hprinter = new HistoryPrinter(); |
| 4449 | final HistoryItem rec = new HistoryItem(); |
| 4450 | long lastTime = -1; |
| 4451 | long baseTime = -1; |
| 4452 | boolean printed = false; |
| 4453 | HistoryEventTracker tracker = null; |
| 4454 | while (getNextHistoryLocked(rec)) { |
| 4455 | lastTime = rec.time; |
| 4456 | if (baseTime < 0) { |
| 4457 | baseTime = lastTime; |
| 4458 | } |
| 4459 | if (rec.time >= histStart) { |
| 4460 | if (histStart >= 0 && !printed) { |
| 4461 | if (rec.cmd == HistoryItem.CMD_CURRENT_TIME |
Ashish Sharma | 6020071 | 2014-05-23 18:22:20 -0700 | [diff] [blame] | 4462 | || rec.cmd == HistoryItem.CMD_RESET |
Dianne Hackborn | 29cd7f1 | 2015-01-08 10:37:05 -0800 | [diff] [blame] | 4463 | || rec.cmd == HistoryItem.CMD_START |
| 4464 | || rec.cmd == HistoryItem.CMD_SHUTDOWN) { |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 4465 | printed = true; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 4466 | hprinter.printNextItem(pw, rec, baseTime, checkin, |
| 4467 | (flags&DUMP_VERBOSE) != 0); |
| 4468 | rec.cmd = HistoryItem.CMD_UPDATE; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 4469 | } else if (rec.currentTime != 0) { |
| 4470 | printed = true; |
| 4471 | byte cmd = rec.cmd; |
| 4472 | rec.cmd = HistoryItem.CMD_CURRENT_TIME; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 4473 | hprinter.printNextItem(pw, rec, baseTime, checkin, |
| 4474 | (flags&DUMP_VERBOSE) != 0); |
| 4475 | rec.cmd = cmd; |
| 4476 | } |
| 4477 | if (tracker != null) { |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 4478 | if (rec.cmd != HistoryItem.CMD_UPDATE) { |
| 4479 | hprinter.printNextItem(pw, rec, baseTime, checkin, |
| 4480 | (flags&DUMP_VERBOSE) != 0); |
| 4481 | rec.cmd = HistoryItem.CMD_UPDATE; |
| 4482 | } |
| 4483 | int oldEventCode = rec.eventCode; |
| 4484 | HistoryTag oldEventTag = rec.eventTag; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 4485 | rec.eventTag = new HistoryTag(); |
| 4486 | for (int i=0; i<HistoryItem.EVENT_COUNT; i++) { |
| 4487 | HashMap<String, SparseIntArray> active |
| 4488 | = tracker.getStateForEvent(i); |
| 4489 | if (active == null) { |
| 4490 | continue; |
| 4491 | } |
| 4492 | for (HashMap.Entry<String, SparseIntArray> ent |
| 4493 | : active.entrySet()) { |
| 4494 | SparseIntArray uids = ent.getValue(); |
| 4495 | for (int j=0; j<uids.size(); j++) { |
| 4496 | rec.eventCode = i; |
| 4497 | rec.eventTag.string = ent.getKey(); |
| 4498 | rec.eventTag.uid = uids.keyAt(j); |
| 4499 | rec.eventTag.poolIdx = uids.valueAt(j); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 4500 | hprinter.printNextItem(pw, rec, baseTime, checkin, |
| 4501 | (flags&DUMP_VERBOSE) != 0); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 4502 | rec.wakeReasonTag = null; |
| 4503 | rec.wakelockTag = null; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 4504 | } |
| 4505 | } |
| 4506 | } |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 4507 | rec.eventCode = oldEventCode; |
| 4508 | rec.eventTag = oldEventTag; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 4509 | tracker = null; |
| 4510 | } |
| 4511 | } |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 4512 | hprinter.printNextItem(pw, rec, baseTime, checkin, |
| 4513 | (flags&DUMP_VERBOSE) != 0); |
Dianne Hackborn | 536456f | 2014-05-23 16:51:05 -0700 | [diff] [blame] | 4514 | } else if (false && rec.eventCode != HistoryItem.EVENT_NONE) { |
| 4515 | // This is an attempt to aggregate the previous state and generate |
| 4516 | //Â fake events to reflect that state at the point where we start |
| 4517 | // 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] | 4518 | if (tracker == null) { |
| 4519 | tracker = new HistoryEventTracker(); |
| 4520 | } |
| 4521 | tracker.updateState(rec.eventCode, rec.eventTag.string, |
| 4522 | rec.eventTag.uid, rec.eventTag.poolIdx); |
| 4523 | } |
| 4524 | } |
| 4525 | if (histStart >= 0) { |
Dianne Hackborn | fc06413 | 2014-06-02 12:42:12 -0700 | [diff] [blame] | 4526 | commitCurrentHistoryBatchLocked(); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 4527 | pw.print(checkin ? "NEXT: " : " NEXT: "); pw.println(lastTime+1); |
| 4528 | } |
| 4529 | } |
| 4530 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 4531 | private void dumpDailyLevelStepSummary(PrintWriter pw, String prefix, String label, |
| 4532 | LevelStepTracker steps, StringBuilder tmpSb, int[] tmpOutInt) { |
| 4533 | if (steps == null) { |
| 4534 | return; |
| 4535 | } |
| 4536 | long timeRemaining = steps.computeTimeEstimate(0, 0, tmpOutInt); |
| 4537 | if (timeRemaining >= 0) { |
| 4538 | pw.print(prefix); pw.print(label); pw.print(" total time: "); |
| 4539 | tmpSb.setLength(0); |
| 4540 | formatTimeMs(tmpSb, timeRemaining); |
| 4541 | pw.print(tmpSb); |
| 4542 | pw.print(" (from "); pw.print(tmpOutInt[0]); |
| 4543 | pw.println(" steps)"); |
| 4544 | } |
| 4545 | for (int i=0; i< STEP_LEVEL_MODES_OF_INTEREST.length; i++) { |
| 4546 | long estimatedTime = steps.computeTimeEstimate(STEP_LEVEL_MODES_OF_INTEREST[i], |
| 4547 | STEP_LEVEL_MODE_VALUES[i], tmpOutInt); |
| 4548 | if (estimatedTime > 0) { |
| 4549 | pw.print(prefix); pw.print(label); pw.print(" "); |
| 4550 | pw.print(STEP_LEVEL_MODE_LABELS[i]); |
| 4551 | pw.print(" time: "); |
| 4552 | tmpSb.setLength(0); |
| 4553 | formatTimeMs(tmpSb, estimatedTime); |
| 4554 | pw.print(tmpSb); |
| 4555 | pw.print(" (from "); pw.print(tmpOutInt[0]); |
| 4556 | pw.println(" steps)"); |
| 4557 | } |
| 4558 | } |
| 4559 | } |
| 4560 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4561 | /** |
| 4562 | * Dumps a human-readable summary of the battery statistics to the given PrintWriter. |
| 4563 | * |
| 4564 | * @param pw a Printer to receive the dump output. |
| 4565 | */ |
| 4566 | @SuppressWarnings("unused") |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 4567 | 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] | 4568 | prepareForDumpLocked(); |
| 4569 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 4570 | final boolean filtering = (flags |
| 4571 | & (DUMP_HISTORY_ONLY|DUMP_UNPLUGGED_ONLY|DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) != 0; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 4572 | |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 4573 | if ((flags&DUMP_HISTORY_ONLY) != 0 || !filtering) { |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 4574 | final long historyTotalSize = getHistoryTotalSize(); |
| 4575 | final long historyUsedSize = getHistoryUsedSize(); |
| 4576 | if (startIteratingHistoryLocked()) { |
| 4577 | try { |
| 4578 | pw.print("Battery History ("); |
| 4579 | pw.print((100*historyUsedSize)/historyTotalSize); |
| 4580 | pw.print("% used, "); |
| 4581 | printSizeValue(pw, historyUsedSize); |
| 4582 | pw.print(" used of "); |
| 4583 | printSizeValue(pw, historyTotalSize); |
| 4584 | pw.print(", "); |
| 4585 | pw.print(getHistoryStringPoolSize()); |
| 4586 | pw.print(" strings using "); |
| 4587 | printSizeValue(pw, getHistoryStringPoolBytes()); |
| 4588 | pw.println("):"); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 4589 | dumpHistoryLocked(pw, flags, histStart, false); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 4590 | pw.println(); |
| 4591 | } finally { |
| 4592 | finishIteratingHistoryLocked(); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 4593 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 4594 | } |
| 4595 | |
| 4596 | if (startIteratingOldHistoryLocked()) { |
| 4597 | try { |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 4598 | final HistoryItem rec = new HistoryItem(); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 4599 | pw.println("Old battery History:"); |
| 4600 | HistoryPrinter hprinter = new HistoryPrinter(); |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 4601 | long baseTime = -1; |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 4602 | while (getNextOldHistoryLocked(rec)) { |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 4603 | if (baseTime < 0) { |
| 4604 | baseTime = rec.time; |
| 4605 | } |
| 4606 | hprinter.printNextItem(pw, rec, baseTime, false, (flags&DUMP_VERBOSE) != 0); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 4607 | } |
| 4608 | pw.println(); |
| 4609 | } finally { |
| 4610 | finishIteratingOldHistoryLocked(); |
| 4611 | } |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4612 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 4613 | } |
| 4614 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 4615 | if (filtering && (flags&(DUMP_UNPLUGGED_ONLY|DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) == 0) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4616 | return; |
| 4617 | } |
| 4618 | |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 4619 | if (!filtering) { |
| 4620 | SparseArray<? extends Uid> uidStats = getUidStats(); |
| 4621 | final int NU = uidStats.size(); |
| 4622 | boolean didPid = false; |
| 4623 | long nowRealtime = SystemClock.elapsedRealtime(); |
| 4624 | for (int i=0; i<NU; i++) { |
| 4625 | Uid uid = uidStats.valueAt(i); |
| 4626 | SparseArray<? extends Uid.Pid> pids = uid.getPidStats(); |
| 4627 | if (pids != null) { |
| 4628 | for (int j=0; j<pids.size(); j++) { |
| 4629 | Uid.Pid pid = pids.valueAt(j); |
| 4630 | if (!didPid) { |
| 4631 | pw.println("Per-PID Stats:"); |
| 4632 | didPid = true; |
| 4633 | } |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 4634 | long time = pid.mWakeSumMs + (pid.mWakeNesting > 0 |
| 4635 | ? (nowRealtime - pid.mWakeStartMs) : 0); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 4636 | pw.print(" PID "); pw.print(pids.keyAt(j)); |
| 4637 | pw.print(" wake time: "); |
| 4638 | TimeUtils.formatDuration(time, pw); |
| 4639 | pw.println(""); |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 4640 | } |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 4641 | } |
| 4642 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 4643 | if (didPid) { |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 4644 | pw.println(); |
| 4645 | } |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 4646 | } |
| 4647 | |
| 4648 | if (!filtering || (flags&DUMP_CHARGED_ONLY) != 0) { |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 4649 | if (dumpDurationSteps(pw, " ", "Discharge step durations:", |
| 4650 | getDischargeLevelStepTracker(), false)) { |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 4651 | long timeRemaining = computeBatteryTimeRemaining(SystemClock.elapsedRealtime()); |
| 4652 | if (timeRemaining >= 0) { |
| 4653 | pw.print(" Estimated discharge time remaining: "); |
| 4654 | TimeUtils.formatDuration(timeRemaining / 1000, pw); |
| 4655 | pw.println(); |
| 4656 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 4657 | final LevelStepTracker steps = getDischargeLevelStepTracker(); |
| 4658 | for (int i=0; i< STEP_LEVEL_MODES_OF_INTEREST.length; i++) { |
| 4659 | dumpTimeEstimate(pw, " Estimated ", STEP_LEVEL_MODE_LABELS[i], " time: ", |
| 4660 | steps.computeTimeEstimate(STEP_LEVEL_MODES_OF_INTEREST[i], |
| 4661 | STEP_LEVEL_MODE_VALUES[i], null)); |
| 4662 | } |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 4663 | pw.println(); |
| 4664 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 4665 | if (dumpDurationSteps(pw, " ", "Charge step durations:", |
| 4666 | getChargeLevelStepTracker(), false)) { |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 4667 | long timeRemaining = computeChargeTimeRemaining(SystemClock.elapsedRealtime()); |
| 4668 | if (timeRemaining >= 0) { |
| 4669 | pw.print(" Estimated charge time remaining: "); |
| 4670 | TimeUtils.formatDuration(timeRemaining / 1000, pw); |
| 4671 | pw.println(); |
| 4672 | } |
| 4673 | pw.println(); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 4674 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 4675 | } |
| 4676 | if (!filtering || (flags&(DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) != 0) { |
| 4677 | pw.println("Daily stats:"); |
| 4678 | pw.print(" Current start time: "); |
| 4679 | pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss", |
| 4680 | getCurrentDailyStartTime()).toString()); |
| 4681 | pw.print(" Next min deadline: "); |
| 4682 | pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss", |
| 4683 | getNextMinDailyDeadline()).toString()); |
| 4684 | pw.print(" Next max deadline: "); |
| 4685 | pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss", |
| 4686 | getNextMaxDailyDeadline()).toString()); |
| 4687 | StringBuilder sb = new StringBuilder(64); |
| 4688 | int[] outInt = new int[1]; |
| 4689 | LevelStepTracker dsteps = getDailyDischargeLevelStepTracker(); |
| 4690 | LevelStepTracker csteps = getDailyChargeLevelStepTracker(); |
| 4691 | if (dsteps.mNumStepDurations > 0 || csteps.mNumStepDurations > 0) { |
| 4692 | if ((flags&DUMP_DAILY_ONLY) != 0) { |
| 4693 | if (dumpDurationSteps(pw, " ", " Current daily discharge step durations:", |
| 4694 | dsteps, false)) { |
| 4695 | dumpDailyLevelStepSummary(pw, " ", "Discharge", dsteps, |
| 4696 | sb, outInt); |
| 4697 | } |
| 4698 | if (dumpDurationSteps(pw, " ", " Current daily charge step durations:", |
| 4699 | csteps, false)) { |
| 4700 | dumpDailyLevelStepSummary(pw, " ", "Charge", csteps, |
| 4701 | sb, outInt); |
| 4702 | } |
| 4703 | } else { |
| 4704 | pw.println(" Current daily steps:"); |
| 4705 | dumpDailyLevelStepSummary(pw, " ", "Discharge", dsteps, |
| 4706 | sb, outInt); |
| 4707 | dumpDailyLevelStepSummary(pw, " ", "Charge", csteps, |
| 4708 | sb, outInt); |
| 4709 | } |
| 4710 | } |
| 4711 | DailyItem dit; |
| 4712 | int curIndex = 0; |
| 4713 | while ((dit=getDailyItemLocked(curIndex)) != null) { |
| 4714 | curIndex++; |
| 4715 | if ((flags&DUMP_DAILY_ONLY) != 0) { |
| 4716 | pw.println(); |
| 4717 | } |
| 4718 | pw.print(" Daily from "); |
| 4719 | pw.print(DateFormat.format("yyyy-MM-dd-HH-mm-ss", dit.mStartTime).toString()); |
| 4720 | pw.print(" to "); |
| 4721 | pw.print(DateFormat.format("yyyy-MM-dd-HH-mm-ss", dit.mEndTime).toString()); |
| 4722 | pw.println(":"); |
| 4723 | if ((flags&DUMP_DAILY_ONLY) != 0) { |
| 4724 | if (dumpDurationSteps(pw, " ", |
| 4725 | " Discharge step durations:", dit.mDischargeSteps, false)) { |
| 4726 | dumpDailyLevelStepSummary(pw, " ", "Discharge", dit.mDischargeSteps, |
| 4727 | sb, outInt); |
| 4728 | } |
| 4729 | if (dumpDurationSteps(pw, " ", |
| 4730 | " Charge step durations:", dit.mChargeSteps, false)) { |
| 4731 | dumpDailyLevelStepSummary(pw, " ", "Charge", dit.mChargeSteps, |
| 4732 | sb, outInt); |
| 4733 | } |
| 4734 | } else { |
| 4735 | dumpDailyLevelStepSummary(pw, " ", "Discharge", dit.mDischargeSteps, |
| 4736 | sb, outInt); |
| 4737 | dumpDailyLevelStepSummary(pw, " ", "Charge", dit.mChargeSteps, |
| 4738 | sb, outInt); |
| 4739 | } |
| 4740 | } |
| 4741 | pw.println(); |
| 4742 | } |
| 4743 | if (!filtering || (flags&DUMP_CHARGED_ONLY) != 0) { |
Jeff Sharkey | ec43a6b | 2013-04-30 13:33:18 -0700 | [diff] [blame] | 4744 | pw.println("Statistics since last charge:"); |
| 4745 | pw.println(" System starts: " + getStartCount() |
| 4746 | + ", currently on battery: " + getIsOnBattery()); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 4747 | dumpLocked(context, pw, "", STATS_SINCE_CHARGED, reqUid, |
| 4748 | (flags&DUMP_DEVICE_WIFI_ONLY) != 0); |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 4749 | pw.println(); |
Jeff Sharkey | ec43a6b | 2013-04-30 13:33:18 -0700 | [diff] [blame] | 4750 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 4751 | if (!filtering || (flags&DUMP_UNPLUGGED_ONLY) != 0) { |
| 4752 | pw.println("Statistics since last unplugged:"); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 4753 | dumpLocked(context, pw, "", STATS_SINCE_UNPLUGGED, reqUid, |
| 4754 | (flags&DUMP_DEVICE_WIFI_ONLY) != 0); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 4755 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4756 | } |
| 4757 | |
| 4758 | @SuppressWarnings("unused") |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 4759 | public void dumpCheckinLocked(Context context, PrintWriter pw, |
| 4760 | List<ApplicationInfo> apps, int flags, long histStart) { |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 4761 | prepareForDumpLocked(); |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 4762 | |
| 4763 | dumpLine(pw, 0 /* uid */, "i" /* category */, VERSION_DATA, |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame^] | 4764 | "13", getParcelVersion(), getStartPlatformVersion(), getEndPlatformVersion()); |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 4765 | |
Dianne Hackborn | 13ac041 | 2013-06-25 19:34:49 -0700 | [diff] [blame] | 4766 | long now = getHistoryBaseTime() + SystemClock.elapsedRealtime(); |
| 4767 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 4768 | final boolean filtering = (flags & |
| 4769 | (DUMP_HISTORY_ONLY|DUMP_UNPLUGGED_ONLY|DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) != 0; |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 4770 | |
| 4771 | if ((flags&DUMP_INCLUDE_HISTORY) != 0 || (flags&DUMP_HISTORY_ONLY) != 0) { |
Dianne Hackborn | 49021f5 | 2013-09-04 18:03:40 -0700 | [diff] [blame] | 4772 | if (startIteratingHistoryLocked()) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 4773 | try { |
| 4774 | for (int i=0; i<getHistoryStringPoolSize(); i++) { |
| 4775 | pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(','); |
| 4776 | pw.print(HISTORY_STRING_POOL); pw.print(','); |
| 4777 | pw.print(i); |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 4778 | pw.print(","); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 4779 | pw.print(getHistoryTagPoolUid(i)); |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 4780 | pw.print(",\""); |
| 4781 | String str = getHistoryTagPoolString(i); |
| 4782 | str = str.replace("\\", "\\\\"); |
| 4783 | str = str.replace("\"", "\\\""); |
| 4784 | pw.print(str); |
| 4785 | pw.print("\""); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 4786 | pw.println(); |
| 4787 | } |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 4788 | dumpHistoryLocked(pw, flags, histStart, true); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 4789 | } finally { |
| 4790 | finishIteratingHistoryLocked(); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4791 | } |
Dianne Hackborn | 13ac041 | 2013-06-25 19:34:49 -0700 | [diff] [blame] | 4792 | } |
Dianne Hackborn | 13ac041 | 2013-06-25 19:34:49 -0700 | [diff] [blame] | 4793 | } |
| 4794 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 4795 | if (filtering && (flags&(DUMP_UNPLUGGED_ONLY|DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) == 0) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4796 | return; |
| 4797 | } |
| 4798 | |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 4799 | if (apps != null) { |
| 4800 | SparseArray<ArrayList<String>> uids = new SparseArray<ArrayList<String>>(); |
| 4801 | for (int i=0; i<apps.size(); i++) { |
| 4802 | ApplicationInfo ai = apps.get(i); |
| 4803 | ArrayList<String> pkgs = uids.get(ai.uid); |
| 4804 | if (pkgs == null) { |
| 4805 | pkgs = new ArrayList<String>(); |
| 4806 | uids.put(ai.uid, pkgs); |
| 4807 | } |
| 4808 | pkgs.add(ai.packageName); |
| 4809 | } |
| 4810 | SparseArray<? extends Uid> uidStats = getUidStats(); |
| 4811 | final int NU = uidStats.size(); |
| 4812 | String[] lineArgs = new String[2]; |
| 4813 | for (int i=0; i<NU; i++) { |
| 4814 | int uid = uidStats.keyAt(i); |
| 4815 | ArrayList<String> pkgs = uids.get(uid); |
| 4816 | if (pkgs != null) { |
| 4817 | for (int j=0; j<pkgs.size(); j++) { |
| 4818 | lineArgs[0] = Integer.toString(uid); |
| 4819 | lineArgs[1] = pkgs.get(j); |
| 4820 | dumpLine(pw, 0 /* uid */, "i" /* category */, UID_DATA, |
| 4821 | (Object[])lineArgs); |
| 4822 | } |
| 4823 | } |
| 4824 | } |
| 4825 | } |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 4826 | if (!filtering || (flags&DUMP_CHARGED_ONLY) != 0) { |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 4827 | dumpDurationSteps(pw, "", DISCHARGE_STEP_DATA, getDischargeLevelStepTracker(), true); |
Dianne Hackborn | d06dcfd | 2014-05-02 13:49:30 -0700 | [diff] [blame] | 4828 | String[] lineArgs = new String[1]; |
| 4829 | long timeRemaining = computeBatteryTimeRemaining(SystemClock.elapsedRealtime()); |
| 4830 | if (timeRemaining >= 0) { |
| 4831 | lineArgs[0] = Long.toString(timeRemaining); |
| 4832 | dumpLine(pw, 0 /* uid */, "i" /* category */, DISCHARGE_TIME_REMAIN_DATA, |
| 4833 | (Object[])lineArgs); |
| 4834 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 4835 | dumpDurationSteps(pw, "", CHARGE_STEP_DATA, getChargeLevelStepTracker(), true); |
Dianne Hackborn | d06dcfd | 2014-05-02 13:49:30 -0700 | [diff] [blame] | 4836 | timeRemaining = computeChargeTimeRemaining(SystemClock.elapsedRealtime()); |
| 4837 | if (timeRemaining >= 0) { |
| 4838 | lineArgs[0] = Long.toString(timeRemaining); |
| 4839 | dumpLine(pw, 0 /* uid */, "i" /* category */, CHARGE_TIME_REMAIN_DATA, |
| 4840 | (Object[])lineArgs); |
| 4841 | } |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 4842 | dumpCheckinLocked(context, pw, STATS_SINCE_CHARGED, -1, |
| 4843 | (flags&DUMP_DEVICE_WIFI_ONLY) != 0); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 4844 | } |
| 4845 | if (!filtering || (flags&DUMP_UNPLUGGED_ONLY) != 0) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 4846 | dumpCheckinLocked(context, pw, STATS_SINCE_UNPLUGGED, -1, |
| 4847 | (flags&DUMP_DEVICE_WIFI_ONLY) != 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4848 | } |
| 4849 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4850 | } |