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; |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 32 | import android.util.ArrayMap; |
Dianne Hackborn | 9cfba35 | 2016-03-24 17:31:28 -0700 | [diff] [blame] | 33 | import android.util.MutableBoolean; |
| 34 | import android.util.Pair; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 35 | import android.util.Printer; |
| 36 | import android.util.SparseArray; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 37 | import android.util.SparseIntArray; |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 38 | import android.util.TimeUtils; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 39 | import android.view.Display; |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 40 | import com.android.internal.os.BatterySipper; |
| 41 | import com.android.internal.os.BatteryStatsHelper; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 42 | |
| 43 | /** |
| 44 | * A class providing access to battery usage statistics, including information on |
| 45 | * wakelocks, processes, packages, and services. All times are represented in microseconds |
| 46 | * except where indicated otherwise. |
| 47 | * @hide |
| 48 | */ |
| 49 | public abstract class BatteryStats implements Parcelable { |
| 50 | |
| 51 | private static final boolean LOCAL_LOGV = false; |
Dianne Hackborn | 91268cf | 2013-06-13 19:06:50 -0700 | [diff] [blame] | 52 | |
| 53 | /** @hide */ |
| 54 | public static final String SERVICE_NAME = "batterystats"; |
| 55 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 56 | /** |
| 57 | * A constant indicating a partial wake lock timer. |
| 58 | */ |
| 59 | public static final int WAKE_TYPE_PARTIAL = 0; |
| 60 | |
| 61 | /** |
| 62 | * A constant indicating a full wake lock timer. |
| 63 | */ |
| 64 | public static final int WAKE_TYPE_FULL = 1; |
| 65 | |
| 66 | /** |
| 67 | * A constant indicating a window wake lock timer. |
| 68 | */ |
| 69 | public static final int WAKE_TYPE_WINDOW = 2; |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 70 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 71 | /** |
| 72 | * A constant indicating a sensor timer. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 73 | */ |
| 74 | public static final int SENSOR = 3; |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 75 | |
| 76 | /** |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 77 | * A constant indicating a a wifi running timer |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 78 | */ |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 79 | public static final int WIFI_RUNNING = 4; |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 80 | |
| 81 | /** |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 82 | * A constant indicating a full wifi lock timer |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 83 | */ |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 84 | public static final int FULL_WIFI_LOCK = 5; |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 85 | |
| 86 | /** |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 87 | * A constant indicating a wifi scan |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 88 | */ |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 89 | public static final int WIFI_SCAN = 6; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 90 | |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 91 | /** |
| 92 | * A constant indicating a wifi multicast timer |
| 93 | */ |
| 94 | public static final int WIFI_MULTICAST_ENABLED = 7; |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 95 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 96 | /** |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 97 | * A constant indicating a video turn on timer |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 98 | */ |
| 99 | public static final int VIDEO_TURNED_ON = 8; |
| 100 | |
| 101 | /** |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 102 | * A constant indicating a vibrator on timer |
| 103 | */ |
| 104 | public static final int VIBRATOR_ON = 9; |
| 105 | |
| 106 | /** |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 107 | * A constant indicating a foreground activity timer |
| 108 | */ |
| 109 | public static final int FOREGROUND_ACTIVITY = 10; |
| 110 | |
| 111 | /** |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 112 | * A constant indicating a wifi batched scan is active |
| 113 | */ |
| 114 | public static final int WIFI_BATCHED_SCAN = 11; |
| 115 | |
| 116 | /** |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 117 | * A constant indicating a process state timer |
| 118 | */ |
| 119 | public static final int PROCESS_STATE = 12; |
| 120 | |
| 121 | /** |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 122 | * A constant indicating a sync timer |
| 123 | */ |
| 124 | public static final int SYNC = 13; |
| 125 | |
| 126 | /** |
| 127 | * A constant indicating a job timer |
| 128 | */ |
| 129 | public static final int JOB = 14; |
| 130 | |
| 131 | /** |
Kweku Adams | d537987 | 2014-11-24 17:34:05 -0800 | [diff] [blame] | 132 | * A constant indicating an audio turn on timer |
| 133 | */ |
| 134 | public static final int AUDIO_TURNED_ON = 15; |
| 135 | |
| 136 | /** |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 137 | * A constant indicating a flashlight turn on timer |
| 138 | */ |
| 139 | public static final int FLASHLIGHT_TURNED_ON = 16; |
| 140 | |
| 141 | /** |
| 142 | * A constant indicating a camera turn on timer |
| 143 | */ |
| 144 | public static final int CAMERA_TURNED_ON = 17; |
| 145 | |
| 146 | /** |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 147 | * A constant indicating a draw wake lock timer. |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 148 | */ |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 149 | public static final int WAKE_TYPE_DRAW = 18; |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 150 | |
| 151 | /** |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 152 | * A constant indicating a bluetooth scan timer. |
| 153 | */ |
| 154 | public static final int BLUETOOTH_SCAN_ON = 19; |
| 155 | |
| 156 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 157 | * Include all of the data in the stats, including previously saved data. |
| 158 | */ |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 159 | public static final int STATS_SINCE_CHARGED = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 160 | |
| 161 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 162 | * Include only the current run in the stats. |
| 163 | */ |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 164 | public static final int STATS_CURRENT = 1; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 165 | |
| 166 | /** |
| 167 | * Include only the run since the last time the device was unplugged in the stats. |
| 168 | */ |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 169 | public static final int STATS_SINCE_UNPLUGGED = 2; |
Evan Millar | e84de8d | 2009-04-02 22:16:12 -0700 | [diff] [blame] | 170 | |
| 171 | // NOTE: Update this list if you add/change any stats above. |
| 172 | // These characters are supposed to represent "total", "last", "current", |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 173 | // and "unplugged". They were shortened for efficiency sake. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 174 | private static final String[] STAT_NAMES = { "l", "c", "u" }; |
| 175 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 176 | /** |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 177 | * Current version of checkin data format. |
| 178 | */ |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 179 | static final String CHECKIN_VERSION = "17"; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 180 | |
| 181 | /** |
| 182 | * Old version, we hit 9 and ran out of room, need to remove. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 183 | */ |
Ashish Sharma | 213bb2f | 2014-07-07 17:14:52 -0700 | [diff] [blame] | 184 | private static final int BATTERY_STATS_CHECKIN_VERSION = 9; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 185 | |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 186 | private static final long BYTES_PER_KB = 1024; |
| 187 | private static final long BYTES_PER_MB = 1048576; // 1024^2 |
| 188 | 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] | 189 | |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 190 | private static final String VERSION_DATA = "vers"; |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 191 | private static final String UID_DATA = "uid"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 192 | private static final String APK_DATA = "apk"; |
Evan Millar | e84de8d | 2009-04-02 22:16:12 -0700 | [diff] [blame] | 193 | private static final String PROCESS_DATA = "pr"; |
Adam Lesinski | a7a4ccc | 2015-06-26 17:43:04 -0700 | [diff] [blame] | 194 | private static final String CPU_DATA = "cpu"; |
Evan Millar | e84de8d | 2009-04-02 22:16:12 -0700 | [diff] [blame] | 195 | private static final String SENSOR_DATA = "sr"; |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 196 | private static final String VIBRATOR_DATA = "vib"; |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 197 | private static final String FOREGROUND_DATA = "fg"; |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 198 | private static final String STATE_TIME_DATA = "st"; |
Evan Millar | e84de8d | 2009-04-02 22:16:12 -0700 | [diff] [blame] | 199 | private static final String WAKELOCK_DATA = "wl"; |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 200 | private static final String SYNC_DATA = "sy"; |
| 201 | private static final String JOB_DATA = "jb"; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 202 | private static final String KERNEL_WAKELOCK_DATA = "kwl"; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 203 | private static final String WAKEUP_REASON_DATA = "wr"; |
Evan Millar | e84de8d | 2009-04-02 22:16:12 -0700 | [diff] [blame] | 204 | private static final String NETWORK_DATA = "nt"; |
| 205 | private static final String USER_ACTIVITY_DATA = "ua"; |
| 206 | private static final String BATTERY_DATA = "bt"; |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 207 | private static final String BATTERY_DISCHARGE_DATA = "dc"; |
Evan Millar | e84de8d | 2009-04-02 22:16:12 -0700 | [diff] [blame] | 208 | private static final String BATTERY_LEVEL_DATA = "lv"; |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 209 | private static final String GLOBAL_WIFI_DATA = "gwfl"; |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 210 | private static final String WIFI_DATA = "wfl"; |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 211 | private static final String GLOBAL_WIFI_CONTROLLER_DATA = "gwfcd"; |
| 212 | private static final String WIFI_CONTROLLER_DATA = "wfcd"; |
| 213 | private static final String GLOBAL_BLUETOOTH_CONTROLLER_DATA = "gble"; |
| 214 | private static final String BLUETOOTH_CONTROLLER_DATA = "ble"; |
Adam Lesinski | d9b99be | 2016-03-30 16:58:51 -0700 | [diff] [blame^] | 215 | private static final String BLUETOOTH_MISC_DATA = "blem"; |
Evan Millar | e84de8d | 2009-04-02 22:16:12 -0700 | [diff] [blame] | 216 | private static final String MISC_DATA = "m"; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 217 | private static final String GLOBAL_NETWORK_DATA = "gn"; |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 218 | private static final String GLOBAL_MODEM_CONTROLLER_DATA = "gmcd"; |
| 219 | private static final String MODEM_CONTROLLER_DATA = "mcd"; |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 220 | private static final String HISTORY_STRING_POOL = "hsp"; |
Dianne Hackborn | 8a0de58 | 2013-08-07 15:22:07 -0700 | [diff] [blame] | 221 | private static final String HISTORY_DATA = "h"; |
Evan Millar | e84de8d | 2009-04-02 22:16:12 -0700 | [diff] [blame] | 222 | private static final String SCREEN_BRIGHTNESS_DATA = "br"; |
| 223 | private static final String SIGNAL_STRENGTH_TIME_DATA = "sgt"; |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 224 | private static final String SIGNAL_SCANNING_TIME_DATA = "sst"; |
Evan Millar | e84de8d | 2009-04-02 22:16:12 -0700 | [diff] [blame] | 225 | private static final String SIGNAL_STRENGTH_COUNT_DATA = "sgc"; |
| 226 | private static final String DATA_CONNECTION_TIME_DATA = "dct"; |
| 227 | private static final String DATA_CONNECTION_COUNT_DATA = "dcc"; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 228 | private static final String WIFI_STATE_TIME_DATA = "wst"; |
| 229 | private static final String WIFI_STATE_COUNT_DATA = "wsc"; |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 230 | private static final String WIFI_SUPPL_STATE_TIME_DATA = "wsst"; |
| 231 | private static final String WIFI_SUPPL_STATE_COUNT_DATA = "wssc"; |
| 232 | private static final String WIFI_SIGNAL_STRENGTH_TIME_DATA = "wsgt"; |
| 233 | private static final String WIFI_SIGNAL_STRENGTH_COUNT_DATA = "wsgc"; |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 234 | private static final String POWER_USE_SUMMARY_DATA = "pws"; |
| 235 | private static final String POWER_USE_ITEM_DATA = "pwi"; |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 236 | private static final String DISCHARGE_STEP_DATA = "dsd"; |
| 237 | private static final String CHARGE_STEP_DATA = "csd"; |
Dianne Hackborn | d06dcfd | 2014-05-02 13:49:30 -0700 | [diff] [blame] | 238 | private static final String DISCHARGE_TIME_REMAIN_DATA = "dtr"; |
| 239 | private static final String CHARGE_TIME_REMAIN_DATA = "ctr"; |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 240 | private static final String FLASHLIGHT_DATA = "fla"; |
| 241 | private static final String CAMERA_DATA = "cam"; |
| 242 | private static final String VIDEO_DATA = "vid"; |
| 243 | private static final String AUDIO_DATA = "aud"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 244 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 245 | private final StringBuilder mFormatBuilder = new StringBuilder(32); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 246 | private final Formatter mFormatter = new Formatter(mFormatBuilder); |
| 247 | |
| 248 | /** |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 249 | * State for keeping track of counting information. |
| 250 | */ |
| 251 | public static abstract class Counter { |
| 252 | |
| 253 | /** |
| 254 | * Returns the count associated with this Counter for the |
| 255 | * selected type of statistics. |
| 256 | * |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 257 | * @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] | 258 | */ |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 259 | public abstract int getCountLocked(int which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 260 | |
| 261 | /** |
| 262 | * Temporary for debugging. |
| 263 | */ |
| 264 | public abstract void logState(Printer pw, String prefix); |
| 265 | } |
| 266 | |
| 267 | /** |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 268 | * State for keeping track of long counting information. |
| 269 | */ |
| 270 | public static abstract class LongCounter { |
| 271 | |
| 272 | /** |
| 273 | * Returns the count associated with this Counter for the |
| 274 | * selected type of statistics. |
| 275 | * |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 276 | * @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] | 277 | */ |
| 278 | public abstract long getCountLocked(int which); |
| 279 | |
| 280 | /** |
| 281 | * Temporary for debugging. |
| 282 | */ |
| 283 | public abstract void logState(Printer pw, String prefix); |
| 284 | } |
| 285 | |
| 286 | /** |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 287 | * Container class that aggregates counters for transmit, receive, and idle state of a |
| 288 | * radio controller. |
| 289 | */ |
| 290 | public static abstract class ControllerActivityCounter { |
| 291 | /** |
| 292 | * @return a non-null {@link LongCounter} representing time spent (milliseconds) in the |
| 293 | * idle state. |
| 294 | */ |
| 295 | public abstract LongCounter getIdleTimeCounter(); |
| 296 | |
| 297 | /** |
| 298 | * @return a non-null {@link LongCounter} representing time spent (milliseconds) in the |
| 299 | * receive state. |
| 300 | */ |
| 301 | public abstract LongCounter getRxTimeCounter(); |
| 302 | |
| 303 | /** |
| 304 | * An array of {@link LongCounter}, representing various transmit levels, where each level |
| 305 | * may draw a different amount of power. The levels themselves are controller-specific. |
| 306 | * @return non-null array of {@link LongCounter}s representing time spent (milliseconds) in |
| 307 | * various transmit level states. |
| 308 | */ |
| 309 | public abstract LongCounter[] getTxTimeCounters(); |
| 310 | |
| 311 | /** |
| 312 | * @return a non-null {@link LongCounter} representing the power consumed by the controller |
| 313 | * in all states, measured in milli-ampere-milliseconds (mAms). The counter may always |
| 314 | * yield a value of 0 if the device doesn't support power calculations. |
| 315 | */ |
| 316 | public abstract LongCounter getPowerCounter(); |
| 317 | } |
| 318 | |
| 319 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 320 | * State for keeping track of timing information. |
| 321 | */ |
| 322 | public static abstract class Timer { |
| 323 | |
| 324 | /** |
| 325 | * Returns the count associated with this Timer for the |
| 326 | * selected type of statistics. |
| 327 | * |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 328 | * @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] | 329 | */ |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 330 | public abstract int getCountLocked(int which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 331 | |
| 332 | /** |
| 333 | * Returns the total time in microseconds associated with this Timer for the |
| 334 | * selected type of statistics. |
| 335 | * |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 336 | * @param elapsedRealtimeUs current elapsed realtime of system in microseconds |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 337 | * @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] | 338 | * @return a time in microseconds |
| 339 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 340 | public abstract long getTotalTimeLocked(long elapsedRealtimeUs, int which); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 341 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 342 | /** |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 343 | * Returns the total time in microseconds associated with this Timer since the |
| 344 | * 'mark' was last set. |
| 345 | * |
| 346 | * @param elapsedRealtimeUs current elapsed realtime of system in microseconds |
| 347 | * @return a time in microseconds |
| 348 | */ |
| 349 | public abstract long getTimeSinceMarkLocked(long elapsedRealtimeUs); |
| 350 | |
| 351 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 352 | * Temporary for debugging. |
| 353 | */ |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 354 | public abstract void logState(Printer pw, String prefix); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 355 | } |
| 356 | |
| 357 | /** |
| 358 | * The statistics associated with a particular uid. |
| 359 | */ |
| 360 | public static abstract class Uid { |
| 361 | |
| 362 | /** |
| 363 | * Returns a mapping containing wakelock statistics. |
| 364 | * |
| 365 | * @return a Map from Strings to Uid.Wakelock objects. |
| 366 | */ |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 367 | public abstract ArrayMap<String, ? extends Wakelock> getWakelockStats(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 368 | |
| 369 | /** |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 370 | * Returns a mapping containing sync statistics. |
| 371 | * |
| 372 | * @return a Map from Strings to Timer objects. |
| 373 | */ |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 374 | public abstract ArrayMap<String, ? extends Timer> getSyncStats(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 375 | |
| 376 | /** |
| 377 | * Returns a mapping containing scheduled job statistics. |
| 378 | * |
| 379 | * @return a Map from Strings to Timer objects. |
| 380 | */ |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 381 | public abstract ArrayMap<String, ? extends Timer> getJobStats(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 382 | |
| 383 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 384 | * The statistics associated with a particular wake lock. |
| 385 | */ |
| 386 | public static abstract class Wakelock { |
| 387 | public abstract Timer getWakeTime(int type); |
| 388 | } |
| 389 | |
| 390 | /** |
| 391 | * Returns a mapping containing sensor statistics. |
| 392 | * |
| 393 | * @return a Map from Integer sensor ids to Uid.Sensor objects. |
| 394 | */ |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 395 | public abstract SparseArray<? extends Sensor> getSensorStats(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 396 | |
| 397 | /** |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 398 | * Returns a mapping containing active process data. |
| 399 | */ |
| 400 | public abstract SparseArray<? extends Pid> getPidStats(); |
| 401 | |
| 402 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 403 | * Returns a mapping containing process statistics. |
| 404 | * |
| 405 | * @return a Map from Strings to Uid.Proc objects. |
| 406 | */ |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 407 | public abstract ArrayMap<String, ? extends Proc> getProcessStats(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 408 | |
| 409 | /** |
| 410 | * Returns a mapping containing package statistics. |
| 411 | * |
| 412 | * @return a Map from Strings to Uid.Pkg objects. |
| 413 | */ |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 414 | public abstract ArrayMap<String, ? extends Pkg> getPackageStats(); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 415 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 416 | public abstract ControllerActivityCounter getWifiControllerActivity(); |
| 417 | public abstract ControllerActivityCounter getBluetoothControllerActivity(); |
| 418 | public abstract ControllerActivityCounter getModemControllerActivity(); |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 419 | |
| 420 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 421 | * {@hide} |
| 422 | */ |
| 423 | public abstract int getUid(); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 424 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 425 | public abstract void noteWifiRunningLocked(long elapsedRealtime); |
| 426 | public abstract void noteWifiStoppedLocked(long elapsedRealtime); |
| 427 | public abstract void noteFullWifiLockAcquiredLocked(long elapsedRealtime); |
| 428 | public abstract void noteFullWifiLockReleasedLocked(long elapsedRealtime); |
| 429 | public abstract void noteWifiScanStartedLocked(long elapsedRealtime); |
| 430 | public abstract void noteWifiScanStoppedLocked(long elapsedRealtime); |
| 431 | public abstract void noteWifiBatchedScanStartedLocked(int csph, long elapsedRealtime); |
| 432 | public abstract void noteWifiBatchedScanStoppedLocked(long elapsedRealtime); |
| 433 | public abstract void noteWifiMulticastEnabledLocked(long elapsedRealtime); |
| 434 | public abstract void noteWifiMulticastDisabledLocked(long elapsedRealtime); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 435 | public abstract void noteActivityResumedLocked(long elapsedRealtime); |
| 436 | public abstract void noteActivityPausedLocked(long elapsedRealtime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 437 | public abstract long getWifiRunningTime(long elapsedRealtimeUs, int which); |
| 438 | public abstract long getFullWifiLockTime(long elapsedRealtimeUs, int which); |
| 439 | public abstract long getWifiScanTime(long elapsedRealtimeUs, int which); |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 440 | public abstract int getWifiScanCount(int which); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 441 | public abstract long getWifiBatchedScanTime(int csphBin, long elapsedRealtimeUs, int which); |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 442 | public abstract int getWifiBatchedScanCount(int csphBin, int which); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 443 | public abstract long getWifiMulticastTime(long elapsedRealtimeUs, int which); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 444 | public abstract Timer getAudioTurnedOnTimer(); |
| 445 | public abstract Timer getVideoTurnedOnTimer(); |
| 446 | public abstract Timer getFlashlightTurnedOnTimer(); |
| 447 | public abstract Timer getCameraTurnedOnTimer(); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 448 | public abstract Timer getForegroundActivityTimer(); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 449 | public abstract Timer getBluetoothScanTimer(); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 450 | |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 451 | // Time this uid has any processes in the top state. |
| 452 | public static final int PROCESS_STATE_TOP = 0; |
| 453 | // Time this uid has any process with a started out bound foreground service. |
| 454 | public static final int PROCESS_STATE_FOREGROUND_SERVICE = 1; |
| 455 | // Time this uid has any process that is top while the device is sleeping. |
| 456 | public static final int PROCESS_STATE_TOP_SLEEPING = 2; |
| 457 | // Time this uid has any process in an active foreground state. |
| 458 | public static final int PROCESS_STATE_FOREGROUND = 3; |
| 459 | // Time this uid has any process in an active background state. |
| 460 | public static final int PROCESS_STATE_BACKGROUND = 4; |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 461 | // Time this uid has any processes running at all. |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 462 | public static final int PROCESS_STATE_CACHED = 5; |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 463 | // Total number of process states we track. |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 464 | public static final int NUM_PROCESS_STATE = 6; |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 465 | |
| 466 | static final String[] PROCESS_STATE_NAMES = { |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 467 | "Top", "Fg Service", "Top Sleeping", "Foreground", "Background", "Cached" |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 468 | }; |
| 469 | |
| 470 | public abstract long getProcessStateTime(int state, long elapsedRealtimeUs, int which); |
Joe Onorato | 713fec8 | 2016-03-04 10:34:02 -0800 | [diff] [blame] | 471 | public abstract Timer getProcessStateTimer(int state); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 472 | |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 473 | public abstract Timer getVibratorOnTimer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 474 | |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 475 | public static final int NUM_WIFI_BATCHED_SCAN_BINS = 5; |
| 476 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 477 | /** |
Jeff Brown | df693de | 2012-07-27 12:03:38 -0700 | [diff] [blame] | 478 | * Note that these must match the constants in android.os.PowerManager. |
| 479 | * Also, if the user activity types change, the BatteryStatsImpl.VERSION must |
| 480 | * also be bumped. |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 481 | */ |
| 482 | static final String[] USER_ACTIVITY_TYPES = { |
Phil Weaver | da80d67 | 2016-03-15 16:25:46 -0700 | [diff] [blame] | 483 | "other", "button", "touch", "accessibility" |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 484 | }; |
| 485 | |
Phil Weaver | da80d67 | 2016-03-15 16:25:46 -0700 | [diff] [blame] | 486 | public static final int NUM_USER_ACTIVITY_TYPES = 4; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 487 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 488 | public abstract void noteUserActivityLocked(int type); |
| 489 | public abstract boolean hasUserActivity(); |
| 490 | public abstract int getUserActivityCount(int type, int which); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 491 | |
| 492 | public abstract boolean hasNetworkActivity(); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 493 | public abstract long getNetworkActivityBytes(int type, int which); |
| 494 | public abstract long getNetworkActivityPackets(int type, int which); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 495 | public abstract long getMobileRadioActiveTime(int which); |
| 496 | public abstract int getMobileRadioActiveCount(int which); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 497 | |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 498 | /** |
| 499 | * Get the total cpu time (in microseconds) this UID had processes executing in userspace. |
| 500 | */ |
| 501 | public abstract long getUserCpuTimeUs(int which); |
| 502 | |
| 503 | /** |
| 504 | * Get the total cpu time (in microseconds) this UID had processes executing kernel syscalls. |
| 505 | */ |
| 506 | public abstract long getSystemCpuTimeUs(int which); |
| 507 | |
| 508 | /** |
Adam Lesinski | a7a4ccc | 2015-06-26 17:43:04 -0700 | [diff] [blame] | 509 | * Get the total cpu power consumed (in milli-ampere-microseconds). |
| 510 | */ |
| 511 | public abstract long getCpuPowerMaUs(int which); |
| 512 | |
| 513 | /** |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 514 | * Returns the approximate cpu time (in milliseconds) spent at a certain CPU speed for a |
| 515 | * given CPU cluster. |
| 516 | * @param cluster the index of the CPU cluster. |
Adam Lesinski | a7a4ccc | 2015-06-26 17:43:04 -0700 | [diff] [blame] | 517 | * @param step the index of the CPU speed. This is not the actual speed of the CPU. |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 518 | * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT. |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 519 | * @see com.android.internal.os.PowerProfile#getNumCpuClusters() |
| 520 | * @see com.android.internal.os.PowerProfile#getNumSpeedStepsInCpuCluster(int) |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 521 | */ |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 522 | public abstract long getTimeAtCpuSpeed(int cluster, int step, int which); |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 523 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 524 | public static abstract class Sensor { |
Mathias Agopian | 7f84c06 | 2013-02-04 19:22:47 -0800 | [diff] [blame] | 525 | /* |
| 526 | * FIXME: it's not correct to use this magic value because it |
| 527 | * could clash with a sensor handle (which are defined by |
| 528 | * the sensor HAL, and therefore out of our control |
| 529 | */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 530 | // Magic sensor number for the GPS. |
| 531 | public static final int GPS = -10000; |
| 532 | |
| 533 | public abstract int getHandle(); |
| 534 | |
| 535 | public abstract Timer getSensorTime(); |
| 536 | } |
| 537 | |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 538 | public class Pid { |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 539 | public int mWakeNesting; |
| 540 | public long mWakeSumMs; |
| 541 | public long mWakeStartMs; |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 542 | } |
| 543 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 544 | /** |
| 545 | * The statistics associated with a particular process. |
| 546 | */ |
| 547 | public static abstract class Proc { |
| 548 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 549 | public static class ExcessivePower { |
| 550 | public static final int TYPE_WAKE = 1; |
| 551 | public static final int TYPE_CPU = 2; |
| 552 | |
| 553 | public int type; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 554 | public long overTime; |
| 555 | public long usedTime; |
| 556 | } |
| 557 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 558 | /** |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 559 | * Returns true if this process is still active in the battery stats. |
| 560 | */ |
| 561 | public abstract boolean isActive(); |
| 562 | |
| 563 | /** |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 564 | * 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] | 565 | * |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 566 | * @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] | 567 | */ |
| 568 | public abstract long getUserTime(int which); |
| 569 | |
| 570 | /** |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 571 | * 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] | 572 | * |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 573 | * @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] | 574 | */ |
| 575 | public abstract long getSystemTime(int which); |
| 576 | |
| 577 | /** |
| 578 | * Returns the number of times the process has been started. |
| 579 | * |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 580 | * @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] | 581 | */ |
| 582 | public abstract int getStarts(int which); |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 583 | |
| 584 | /** |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 585 | * Returns the number of times the process has crashed. |
| 586 | * |
| 587 | * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT. |
| 588 | */ |
| 589 | public abstract int getNumCrashes(int which); |
| 590 | |
| 591 | /** |
| 592 | * Returns the number of times the process has ANRed. |
| 593 | * |
| 594 | * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT. |
| 595 | */ |
| 596 | public abstract int getNumAnrs(int which); |
| 597 | |
| 598 | /** |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 599 | * 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] | 600 | * @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] | 601 | * @return foreground cpu time in microseconds |
| 602 | */ |
| 603 | public abstract long getForegroundTime(int which); |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 604 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 605 | public abstract int countExcessivePowers(); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 606 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 607 | public abstract ExcessivePower getExcessivePower(int i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 608 | } |
| 609 | |
| 610 | /** |
| 611 | * The statistics associated with a particular package. |
| 612 | */ |
| 613 | public static abstract class Pkg { |
| 614 | |
| 615 | /** |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 616 | * Returns information about all wakeup alarms that have been triggered for this |
| 617 | * package. The mapping keys are tag names for the alarms, the counter contains |
| 618 | * the number of times the alarm was triggered while on battery. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 619 | */ |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 620 | public abstract ArrayMap<String, ? extends Counter> getWakeupAlarmStats(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 621 | |
| 622 | /** |
| 623 | * Returns a mapping containing service statistics. |
| 624 | */ |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 625 | public abstract ArrayMap<String, ? extends Serv> getServiceStats(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 626 | |
| 627 | /** |
| 628 | * The statistics associated with a particular service. |
| 629 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 630 | public static abstract class Serv { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 631 | |
| 632 | /** |
| 633 | * Returns the amount of time spent started. |
| 634 | * |
| 635 | * @param batteryUptime elapsed uptime on battery in microseconds. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 636 | * @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] | 637 | * @return |
| 638 | */ |
| 639 | public abstract long getStartTime(long batteryUptime, int which); |
| 640 | |
| 641 | /** |
| 642 | * Returns the total number of times startService() has been called. |
| 643 | * |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 644 | * @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] | 645 | */ |
| 646 | public abstract int getStarts(int which); |
| 647 | |
| 648 | /** |
| 649 | * Returns the total number times the service has been launched. |
| 650 | * |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 651 | * @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] | 652 | */ |
| 653 | public abstract int getLaunches(int which); |
| 654 | } |
| 655 | } |
| 656 | } |
| 657 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 658 | public static final class LevelStepTracker { |
| 659 | public long mLastStepTime = -1; |
| 660 | public int mNumStepDurations; |
| 661 | public final long[] mStepDurations; |
| 662 | |
| 663 | public LevelStepTracker(int maxLevelSteps) { |
| 664 | mStepDurations = new long[maxLevelSteps]; |
| 665 | } |
| 666 | |
| 667 | public LevelStepTracker(int numSteps, long[] steps) { |
| 668 | mNumStepDurations = numSteps; |
| 669 | mStepDurations = new long[numSteps]; |
| 670 | System.arraycopy(steps, 0, mStepDurations, 0, numSteps); |
| 671 | } |
| 672 | |
| 673 | public long getDurationAt(int index) { |
| 674 | return mStepDurations[index] & STEP_LEVEL_TIME_MASK; |
| 675 | } |
| 676 | |
| 677 | public int getLevelAt(int index) { |
| 678 | return (int)((mStepDurations[index] & STEP_LEVEL_LEVEL_MASK) |
| 679 | >> STEP_LEVEL_LEVEL_SHIFT); |
| 680 | } |
| 681 | |
| 682 | public int getInitModeAt(int index) { |
| 683 | return (int)((mStepDurations[index] & STEP_LEVEL_INITIAL_MODE_MASK) |
| 684 | >> STEP_LEVEL_INITIAL_MODE_SHIFT); |
| 685 | } |
| 686 | |
| 687 | public int getModModeAt(int index) { |
| 688 | return (int)((mStepDurations[index] & STEP_LEVEL_MODIFIED_MODE_MASK) |
| 689 | >> STEP_LEVEL_MODIFIED_MODE_SHIFT); |
| 690 | } |
| 691 | |
| 692 | private void appendHex(long val, int topOffset, StringBuilder out) { |
| 693 | boolean hasData = false; |
| 694 | while (topOffset >= 0) { |
| 695 | int digit = (int)( (val>>topOffset) & 0xf ); |
| 696 | topOffset -= 4; |
| 697 | if (!hasData && digit == 0) { |
| 698 | continue; |
| 699 | } |
| 700 | hasData = true; |
| 701 | if (digit >= 0 && digit <= 9) { |
| 702 | out.append((char)('0' + digit)); |
| 703 | } else { |
| 704 | out.append((char)('a' + digit - 10)); |
| 705 | } |
| 706 | } |
| 707 | } |
| 708 | |
| 709 | public void encodeEntryAt(int index, StringBuilder out) { |
| 710 | long item = mStepDurations[index]; |
| 711 | long duration = item & STEP_LEVEL_TIME_MASK; |
| 712 | int level = (int)((item & STEP_LEVEL_LEVEL_MASK) |
| 713 | >> STEP_LEVEL_LEVEL_SHIFT); |
| 714 | int initMode = (int)((item & STEP_LEVEL_INITIAL_MODE_MASK) |
| 715 | >> STEP_LEVEL_INITIAL_MODE_SHIFT); |
| 716 | int modMode = (int)((item & STEP_LEVEL_MODIFIED_MODE_MASK) |
| 717 | >> STEP_LEVEL_MODIFIED_MODE_SHIFT); |
| 718 | switch ((initMode&STEP_LEVEL_MODE_SCREEN_STATE) + 1) { |
| 719 | case Display.STATE_OFF: out.append('f'); break; |
| 720 | case Display.STATE_ON: out.append('o'); break; |
| 721 | case Display.STATE_DOZE: out.append('d'); break; |
| 722 | case Display.STATE_DOZE_SUSPEND: out.append('z'); break; |
| 723 | } |
| 724 | if ((initMode&STEP_LEVEL_MODE_POWER_SAVE) != 0) { |
| 725 | out.append('p'); |
| 726 | } |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 727 | if ((initMode&STEP_LEVEL_MODE_DEVICE_IDLE) != 0) { |
| 728 | out.append('i'); |
| 729 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 730 | switch ((modMode&STEP_LEVEL_MODE_SCREEN_STATE) + 1) { |
| 731 | case Display.STATE_OFF: out.append('F'); break; |
| 732 | case Display.STATE_ON: out.append('O'); break; |
| 733 | case Display.STATE_DOZE: out.append('D'); break; |
| 734 | case Display.STATE_DOZE_SUSPEND: out.append('Z'); break; |
| 735 | } |
| 736 | if ((modMode&STEP_LEVEL_MODE_POWER_SAVE) != 0) { |
| 737 | out.append('P'); |
| 738 | } |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 739 | if ((modMode&STEP_LEVEL_MODE_DEVICE_IDLE) != 0) { |
| 740 | out.append('I'); |
| 741 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 742 | out.append('-'); |
| 743 | appendHex(level, 4, out); |
| 744 | out.append('-'); |
| 745 | appendHex(duration, STEP_LEVEL_LEVEL_SHIFT-4, out); |
| 746 | } |
| 747 | |
| 748 | public void decodeEntryAt(int index, String value) { |
| 749 | final int N = value.length(); |
| 750 | int i = 0; |
| 751 | char c; |
| 752 | long out = 0; |
| 753 | while (i < N && (c=value.charAt(i)) != '-') { |
| 754 | i++; |
| 755 | switch (c) { |
Dianne Hackborn | 8cfb58b | 2015-03-04 13:28:36 -0800 | [diff] [blame] | 756 | 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] | 757 | break; |
Dianne Hackborn | 8cfb58b | 2015-03-04 13:28:36 -0800 | [diff] [blame] | 758 | 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] | 759 | break; |
Dianne Hackborn | 8cfb58b | 2015-03-04 13:28:36 -0800 | [diff] [blame] | 760 | 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] | 761 | break; |
Dianne Hackborn | 8cfb58b | 2015-03-04 13:28:36 -0800 | [diff] [blame] | 762 | case 'z': out |= (((long)Display.STATE_DOZE_SUSPEND-1) |
| 763 | << STEP_LEVEL_INITIAL_MODE_SHIFT); |
| 764 | break; |
| 765 | case 'p': out |= (((long)STEP_LEVEL_MODE_POWER_SAVE) |
| 766 | << STEP_LEVEL_INITIAL_MODE_SHIFT); |
| 767 | break; |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 768 | case 'i': out |= (((long)STEP_LEVEL_MODE_DEVICE_IDLE) |
| 769 | << STEP_LEVEL_INITIAL_MODE_SHIFT); |
| 770 | break; |
Dianne Hackborn | 8cfb58b | 2015-03-04 13:28:36 -0800 | [diff] [blame] | 771 | case 'F': out |= (((long)Display.STATE_OFF-1)<<STEP_LEVEL_MODIFIED_MODE_SHIFT); |
| 772 | break; |
| 773 | case 'O': out |= (((long)Display.STATE_ON-1)<<STEP_LEVEL_MODIFIED_MODE_SHIFT); |
| 774 | break; |
| 775 | case 'D': out |= (((long)Display.STATE_DOZE-1)<<STEP_LEVEL_MODIFIED_MODE_SHIFT); |
| 776 | break; |
| 777 | case 'Z': out |= (((long)Display.STATE_DOZE_SUSPEND-1) |
| 778 | << STEP_LEVEL_MODIFIED_MODE_SHIFT); |
| 779 | break; |
| 780 | case 'P': out |= (((long)STEP_LEVEL_MODE_POWER_SAVE) |
| 781 | << STEP_LEVEL_MODIFIED_MODE_SHIFT); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 782 | break; |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 783 | case 'I': out |= (((long)STEP_LEVEL_MODE_DEVICE_IDLE) |
| 784 | << STEP_LEVEL_MODIFIED_MODE_SHIFT); |
| 785 | break; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 786 | } |
| 787 | } |
| 788 | i++; |
Dianne Hackborn | 8cfb58b | 2015-03-04 13:28:36 -0800 | [diff] [blame] | 789 | long level = 0; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 790 | while (i < N && (c=value.charAt(i)) != '-') { |
| 791 | i++; |
| 792 | level <<= 4; |
| 793 | if (c >= '0' && c <= '9') { |
| 794 | level += c - '0'; |
| 795 | } else if (c >= 'a' && c <= 'f') { |
| 796 | level += c - 'a' + 10; |
| 797 | } else if (c >= 'A' && c <= 'F') { |
| 798 | level += c - 'A' + 10; |
| 799 | } |
| 800 | } |
Dianne Hackborn | 8cfb58b | 2015-03-04 13:28:36 -0800 | [diff] [blame] | 801 | i++; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 802 | out |= (level << STEP_LEVEL_LEVEL_SHIFT) & STEP_LEVEL_LEVEL_MASK; |
| 803 | long duration = 0; |
| 804 | while (i < N && (c=value.charAt(i)) != '-') { |
| 805 | i++; |
| 806 | duration <<= 4; |
| 807 | if (c >= '0' && c <= '9') { |
| 808 | duration += c - '0'; |
| 809 | } else if (c >= 'a' && c <= 'f') { |
| 810 | duration += c - 'a' + 10; |
| 811 | } else if (c >= 'A' && c <= 'F') { |
| 812 | duration += c - 'A' + 10; |
| 813 | } |
| 814 | } |
| 815 | mStepDurations[index] = out | (duration & STEP_LEVEL_TIME_MASK); |
| 816 | } |
| 817 | |
| 818 | public void init() { |
| 819 | mLastStepTime = -1; |
| 820 | mNumStepDurations = 0; |
| 821 | } |
| 822 | |
| 823 | public void clearTime() { |
| 824 | mLastStepTime = -1; |
| 825 | } |
| 826 | |
| 827 | public long computeTimePerLevel() { |
| 828 | final long[] steps = mStepDurations; |
| 829 | final int numSteps = mNumStepDurations; |
| 830 | |
| 831 | // For now we'll do a simple average across all steps. |
| 832 | if (numSteps <= 0) { |
| 833 | return -1; |
| 834 | } |
| 835 | long total = 0; |
| 836 | for (int i=0; i<numSteps; i++) { |
| 837 | total += steps[i] & STEP_LEVEL_TIME_MASK; |
| 838 | } |
| 839 | return total / numSteps; |
| 840 | /* |
| 841 | long[] buckets = new long[numSteps]; |
| 842 | int numBuckets = 0; |
| 843 | int numToAverage = 4; |
| 844 | int i = 0; |
| 845 | while (i < numSteps) { |
| 846 | long totalTime = 0; |
| 847 | int num = 0; |
| 848 | for (int j=0; j<numToAverage && (i+j)<numSteps; j++) { |
| 849 | totalTime += steps[i+j] & STEP_LEVEL_TIME_MASK; |
| 850 | num++; |
| 851 | } |
| 852 | buckets[numBuckets] = totalTime / num; |
| 853 | numBuckets++; |
| 854 | numToAverage *= 2; |
| 855 | i += num; |
| 856 | } |
| 857 | if (numBuckets < 1) { |
| 858 | return -1; |
| 859 | } |
| 860 | long averageTime = buckets[numBuckets-1]; |
| 861 | for (i=numBuckets-2; i>=0; i--) { |
| 862 | averageTime = (averageTime + buckets[i]) / 2; |
| 863 | } |
| 864 | return averageTime; |
| 865 | */ |
| 866 | } |
| 867 | |
| 868 | public long computeTimeEstimate(long modesOfInterest, long modeValues, |
| 869 | int[] outNumOfInterest) { |
| 870 | final long[] steps = mStepDurations; |
| 871 | final int count = mNumStepDurations; |
| 872 | if (count <= 0) { |
| 873 | return -1; |
| 874 | } |
| 875 | long total = 0; |
| 876 | int numOfInterest = 0; |
| 877 | for (int i=0; i<count; i++) { |
| 878 | long initMode = (steps[i] & STEP_LEVEL_INITIAL_MODE_MASK) |
| 879 | >> STEP_LEVEL_INITIAL_MODE_SHIFT; |
| 880 | long modMode = (steps[i] & STEP_LEVEL_MODIFIED_MODE_MASK) |
| 881 | >> STEP_LEVEL_MODIFIED_MODE_SHIFT; |
| 882 | // If the modes of interest didn't change during this step period... |
| 883 | if ((modMode&modesOfInterest) == 0) { |
| 884 | // And the mode values during this period match those we are measuring... |
| 885 | if ((initMode&modesOfInterest) == modeValues) { |
| 886 | // Then this can be used to estimate the total time! |
| 887 | numOfInterest++; |
| 888 | total += steps[i] & STEP_LEVEL_TIME_MASK; |
| 889 | } |
| 890 | } |
| 891 | } |
| 892 | if (numOfInterest <= 0) { |
| 893 | return -1; |
| 894 | } |
| 895 | |
| 896 | if (outNumOfInterest != null) { |
| 897 | outNumOfInterest[0] = numOfInterest; |
| 898 | } |
| 899 | |
| 900 | // The estimated time is the average time we spend in each level, multipled |
| 901 | // by 100 -- the total number of battery levels |
| 902 | return (total / numOfInterest) * 100; |
| 903 | } |
| 904 | |
| 905 | public void addLevelSteps(int numStepLevels, long modeBits, long elapsedRealtime) { |
| 906 | int stepCount = mNumStepDurations; |
| 907 | final long lastStepTime = mLastStepTime; |
| 908 | if (lastStepTime >= 0 && numStepLevels > 0) { |
| 909 | final long[] steps = mStepDurations; |
| 910 | long duration = elapsedRealtime - lastStepTime; |
| 911 | for (int i=0; i<numStepLevels; i++) { |
| 912 | System.arraycopy(steps, 0, steps, 1, steps.length-1); |
| 913 | long thisDuration = duration / (numStepLevels-i); |
| 914 | duration -= thisDuration; |
| 915 | if (thisDuration > STEP_LEVEL_TIME_MASK) { |
| 916 | thisDuration = STEP_LEVEL_TIME_MASK; |
| 917 | } |
| 918 | steps[0] = thisDuration | modeBits; |
| 919 | } |
| 920 | stepCount += numStepLevels; |
| 921 | if (stepCount > steps.length) { |
| 922 | stepCount = steps.length; |
| 923 | } |
| 924 | } |
| 925 | mNumStepDurations = stepCount; |
| 926 | mLastStepTime = elapsedRealtime; |
| 927 | } |
| 928 | |
| 929 | public void readFromParcel(Parcel in) { |
| 930 | final int N = in.readInt(); |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 931 | if (N > mStepDurations.length) { |
| 932 | throw new ParcelFormatException("more step durations than available: " + N); |
| 933 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 934 | mNumStepDurations = N; |
| 935 | for (int i=0; i<N; i++) { |
| 936 | mStepDurations[i] = in.readLong(); |
| 937 | } |
| 938 | } |
| 939 | |
| 940 | public void writeToParcel(Parcel out) { |
| 941 | final int N = mNumStepDurations; |
| 942 | out.writeInt(N); |
| 943 | for (int i=0; i<N; i++) { |
| 944 | out.writeLong(mStepDurations[i]); |
| 945 | } |
| 946 | } |
| 947 | } |
| 948 | |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 949 | public static final class PackageChange { |
| 950 | public String mPackageName; |
| 951 | public boolean mUpdate; |
| 952 | public int mVersionCode; |
| 953 | } |
| 954 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 955 | public static final class DailyItem { |
| 956 | public long mStartTime; |
| 957 | public long mEndTime; |
| 958 | public LevelStepTracker mDischargeSteps; |
| 959 | public LevelStepTracker mChargeSteps; |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 960 | public ArrayList<PackageChange> mPackageChanges; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 961 | } |
| 962 | |
| 963 | public abstract DailyItem getDailyItemLocked(int daysAgo); |
| 964 | |
| 965 | public abstract long getCurrentDailyStartTime(); |
| 966 | |
| 967 | public abstract long getNextMinDailyDeadline(); |
| 968 | |
| 969 | public abstract long getNextMaxDailyDeadline(); |
| 970 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 971 | public final static class HistoryTag { |
| 972 | public String string; |
| 973 | public int uid; |
| 974 | |
| 975 | public int poolIdx; |
| 976 | |
| 977 | public void setTo(HistoryTag o) { |
| 978 | string = o.string; |
| 979 | uid = o.uid; |
| 980 | poolIdx = o.poolIdx; |
| 981 | } |
| 982 | |
| 983 | public void setTo(String _string, int _uid) { |
| 984 | string = _string; |
| 985 | uid = _uid; |
| 986 | poolIdx = -1; |
| 987 | } |
| 988 | |
| 989 | public void writeToParcel(Parcel dest, int flags) { |
| 990 | dest.writeString(string); |
| 991 | dest.writeInt(uid); |
| 992 | } |
| 993 | |
| 994 | public void readFromParcel(Parcel src) { |
| 995 | string = src.readString(); |
| 996 | uid = src.readInt(); |
| 997 | poolIdx = -1; |
| 998 | } |
| 999 | |
| 1000 | @Override |
| 1001 | public boolean equals(Object o) { |
| 1002 | if (this == o) return true; |
| 1003 | if (o == null || getClass() != o.getClass()) return false; |
| 1004 | |
| 1005 | HistoryTag that = (HistoryTag) o; |
| 1006 | |
| 1007 | if (uid != that.uid) return false; |
| 1008 | if (!string.equals(that.string)) return false; |
| 1009 | |
| 1010 | return true; |
| 1011 | } |
| 1012 | |
| 1013 | @Override |
| 1014 | public int hashCode() { |
| 1015 | int result = string.hashCode(); |
| 1016 | result = 31 * result + uid; |
| 1017 | return result; |
| 1018 | } |
| 1019 | } |
| 1020 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 1021 | /** |
| 1022 | * Optional detailed information that can go into a history step. This is typically |
| 1023 | * generated each time the battery level changes. |
| 1024 | */ |
| 1025 | public final static class HistoryStepDetails { |
| 1026 | // Time (in 1/100 second) spent in user space and the kernel since the last step. |
| 1027 | public int userTime; |
| 1028 | public int systemTime; |
| 1029 | |
| 1030 | // Top three apps using CPU in the last step, with times in 1/100 second. |
| 1031 | public int appCpuUid1; |
| 1032 | public int appCpuUTime1; |
| 1033 | public int appCpuSTime1; |
| 1034 | public int appCpuUid2; |
| 1035 | public int appCpuUTime2; |
| 1036 | public int appCpuSTime2; |
| 1037 | public int appCpuUid3; |
| 1038 | public int appCpuUTime3; |
| 1039 | public int appCpuSTime3; |
| 1040 | |
| 1041 | // Information from /proc/stat |
| 1042 | public int statUserTime; |
| 1043 | public int statSystemTime; |
| 1044 | public int statIOWaitTime; |
| 1045 | public int statIrqTime; |
| 1046 | public int statSoftIrqTime; |
| 1047 | public int statIdlTime; |
| 1048 | |
| 1049 | public HistoryStepDetails() { |
| 1050 | clear(); |
| 1051 | } |
| 1052 | |
| 1053 | public void clear() { |
| 1054 | userTime = systemTime = 0; |
| 1055 | appCpuUid1 = appCpuUid2 = appCpuUid3 = -1; |
| 1056 | appCpuUTime1 = appCpuSTime1 = appCpuUTime2 = appCpuSTime2 |
| 1057 | = appCpuUTime3 = appCpuSTime3 = 0; |
| 1058 | } |
| 1059 | |
| 1060 | public void writeToParcel(Parcel out) { |
| 1061 | out.writeInt(userTime); |
| 1062 | out.writeInt(systemTime); |
| 1063 | out.writeInt(appCpuUid1); |
| 1064 | out.writeInt(appCpuUTime1); |
| 1065 | out.writeInt(appCpuSTime1); |
| 1066 | out.writeInt(appCpuUid2); |
| 1067 | out.writeInt(appCpuUTime2); |
| 1068 | out.writeInt(appCpuSTime2); |
| 1069 | out.writeInt(appCpuUid3); |
| 1070 | out.writeInt(appCpuUTime3); |
| 1071 | out.writeInt(appCpuSTime3); |
| 1072 | out.writeInt(statUserTime); |
| 1073 | out.writeInt(statSystemTime); |
| 1074 | out.writeInt(statIOWaitTime); |
| 1075 | out.writeInt(statIrqTime); |
| 1076 | out.writeInt(statSoftIrqTime); |
| 1077 | out.writeInt(statIdlTime); |
| 1078 | } |
| 1079 | |
| 1080 | public void readFromParcel(Parcel in) { |
| 1081 | userTime = in.readInt(); |
| 1082 | systemTime = in.readInt(); |
| 1083 | appCpuUid1 = in.readInt(); |
| 1084 | appCpuUTime1 = in.readInt(); |
| 1085 | appCpuSTime1 = in.readInt(); |
| 1086 | appCpuUid2 = in.readInt(); |
| 1087 | appCpuUTime2 = in.readInt(); |
| 1088 | appCpuSTime2 = in.readInt(); |
| 1089 | appCpuUid3 = in.readInt(); |
| 1090 | appCpuUTime3 = in.readInt(); |
| 1091 | appCpuSTime3 = in.readInt(); |
| 1092 | statUserTime = in.readInt(); |
| 1093 | statSystemTime = in.readInt(); |
| 1094 | statIOWaitTime = in.readInt(); |
| 1095 | statIrqTime = in.readInt(); |
| 1096 | statSoftIrqTime = in.readInt(); |
| 1097 | statIdlTime = in.readInt(); |
| 1098 | } |
| 1099 | } |
| 1100 | |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 1101 | public final static class HistoryItem implements Parcelable { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1102 | public HistoryItem next; |
Dianne Hackborn | 9a75543 | 2014-05-15 17:05:22 -0700 | [diff] [blame] | 1103 | |
| 1104 | // The time of this event in milliseconds, as per SystemClock.elapsedRealtime(). |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1105 | public long time; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1106 | |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 1107 | 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] | 1108 | public static final byte CMD_NULL = -1; |
| 1109 | public static final byte CMD_START = 4; |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1110 | public static final byte CMD_CURRENT_TIME = 5; |
| 1111 | public static final byte CMD_OVERFLOW = 6; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 1112 | public static final byte CMD_RESET = 7; |
Dianne Hackborn | 29cd7f1 | 2015-01-08 10:37:05 -0800 | [diff] [blame] | 1113 | public static final byte CMD_SHUTDOWN = 8; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1114 | |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 1115 | public byte cmd = CMD_NULL; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1116 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1117 | /** |
| 1118 | * Return whether the command code is a delta data update. |
| 1119 | */ |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1120 | public boolean isDeltaData() { |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 1121 | return cmd == CMD_UPDATE; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1122 | } |
| 1123 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1124 | public byte batteryLevel; |
| 1125 | public byte batteryStatus; |
| 1126 | public byte batteryHealth; |
| 1127 | public byte batteryPlugType; |
| 1128 | |
Sungmin Choi | c7e9e8b | 2013-01-16 12:57:36 +0900 | [diff] [blame] | 1129 | public short batteryTemperature; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1130 | public char batteryVoltage; |
| 1131 | |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 1132 | // Constants from SCREEN_BRIGHTNESS_* |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1133 | public static final int STATE_BRIGHTNESS_SHIFT = 0; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1134 | public static final int STATE_BRIGHTNESS_MASK = 0x7; |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 1135 | // Constants from SIGNAL_STRENGTH_* |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 1136 | public static final int STATE_PHONE_SIGNAL_STRENGTH_SHIFT = 3; |
| 1137 | 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] | 1138 | // Constants from ServiceState.STATE_* |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1139 | public static final int STATE_PHONE_STATE_SHIFT = 6; |
| 1140 | 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] | 1141 | // Constants from DATA_CONNECTION_* |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1142 | public static final int STATE_DATA_CONNECTION_SHIFT = 9; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1143 | 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] | 1144 | |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 1145 | // These states always appear directly in the first int token |
| 1146 | // of a delta change; they should be ones that change relatively |
| 1147 | // frequently. |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1148 | public static final int STATE_CPU_RUNNING_FLAG = 1<<31; |
| 1149 | public static final int STATE_WAKE_LOCK_FLAG = 1<<30; |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 1150 | public static final int STATE_GPS_ON_FLAG = 1<<29; |
| 1151 | public static final int STATE_WIFI_FULL_LOCK_FLAG = 1<<28; |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 1152 | public static final int STATE_WIFI_SCAN_FLAG = 1<<27; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 1153 | public static final int STATE_WIFI_RADIO_ACTIVE_FLAG = 1<<26; |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 1154 | public static final int STATE_MOBILE_RADIO_ACTIVE_FLAG = 1<<25; |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 1155 | // These are on the lower bits used for the command; if they change |
| 1156 | // we need to write another int of data. |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1157 | public static final int STATE_SENSOR_ON_FLAG = 1<<23; |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 1158 | public static final int STATE_AUDIO_ON_FLAG = 1<<22; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1159 | public static final int STATE_PHONE_SCANNING_FLAG = 1<<21; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 1160 | public static final int STATE_SCREEN_ON_FLAG = 1<<20; // consider moving to states2 |
| 1161 | public static final int STATE_BATTERY_PLUGGED_FLAG = 1<<19; // consider moving to states2 |
| 1162 | // empty slot |
| 1163 | // empty slot |
| 1164 | public static final int STATE_WIFI_MULTICAST_ON_FLAG = 1<<16; |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 1165 | |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 1166 | public static final int MOST_INTERESTING_STATES = |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 1167 | STATE_BATTERY_PLUGGED_FLAG | STATE_SCREEN_ON_FLAG; |
| 1168 | |
| 1169 | public static final int SETTLE_TO_ZERO_STATES = 0xffff0000 & ~MOST_INTERESTING_STATES; |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 1170 | |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1171 | public int states; |
| 1172 | |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 1173 | // Constants from WIFI_SUPPL_STATE_* |
| 1174 | public static final int STATE2_WIFI_SUPPL_STATE_SHIFT = 0; |
| 1175 | public static final int STATE2_WIFI_SUPPL_STATE_MASK = 0xf; |
| 1176 | // Values for NUM_WIFI_SIGNAL_STRENGTH_BINS |
| 1177 | public static final int STATE2_WIFI_SIGNAL_STRENGTH_SHIFT = 4; |
| 1178 | public static final int STATE2_WIFI_SIGNAL_STRENGTH_MASK = |
| 1179 | 0x7 << STATE2_WIFI_SIGNAL_STRENGTH_SHIFT; |
| 1180 | |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 1181 | public static final int STATE2_POWER_SAVE_FLAG = 1<<31; |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 1182 | public static final int STATE2_VIDEO_ON_FLAG = 1<<30; |
| 1183 | public static final int STATE2_WIFI_RUNNING_FLAG = 1<<29; |
| 1184 | public static final int STATE2_WIFI_ON_FLAG = 1<<28; |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 1185 | public static final int STATE2_FLASHLIGHT_FLAG = 1<<27; |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 1186 | public static final int STATE2_DEVICE_IDLE_SHIFT = 25; |
| 1187 | public static final int STATE2_DEVICE_IDLE_MASK = 0x3 << STATE2_DEVICE_IDLE_SHIFT; |
| 1188 | public static final int STATE2_CHARGING_FLAG = 1<<24; |
| 1189 | public static final int STATE2_PHONE_IN_CALL_FLAG = 1<<23; |
| 1190 | public static final int STATE2_BLUETOOTH_ON_FLAG = 1<<22; |
| 1191 | public static final int STATE2_CAMERA_FLAG = 1<<21; |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 1192 | public static final int STATE2_BLUETOOTH_SCAN_FLAG = 1 << 20; |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 1193 | |
| 1194 | public static final int MOST_INTERESTING_STATES2 = |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 1195 | STATE2_POWER_SAVE_FLAG | STATE2_WIFI_ON_FLAG | STATE2_DEVICE_IDLE_MASK |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 1196 | | STATE2_CHARGING_FLAG | STATE2_PHONE_IN_CALL_FLAG | STATE2_BLUETOOTH_ON_FLAG; |
| 1197 | |
| 1198 | public static final int SETTLE_TO_ZERO_STATES2 = 0xffff0000 & ~MOST_INTERESTING_STATES2; |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 1199 | |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 1200 | public int states2; |
| 1201 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1202 | // The wake lock that was acquired at this point. |
| 1203 | public HistoryTag wakelockTag; |
| 1204 | |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1205 | // Kernel wakeup reason at this point. |
| 1206 | public HistoryTag wakeReasonTag; |
| 1207 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 1208 | // Non-null when there is more detailed information at this step. |
| 1209 | public HistoryStepDetails stepDetails; |
| 1210 | |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 1211 | public static final int EVENT_FLAG_START = 0x8000; |
| 1212 | public static final int EVENT_FLAG_FINISH = 0x4000; |
| 1213 | |
| 1214 | // No event in this item. |
| 1215 | public static final int EVENT_NONE = 0x0000; |
| 1216 | // Event is about a process that is running. |
| 1217 | public static final int EVENT_PROC = 0x0001; |
| 1218 | // Event is about an application package that is in the foreground. |
| 1219 | public static final int EVENT_FOREGROUND = 0x0002; |
| 1220 | // Event is about an application package that is at the top of the screen. |
| 1221 | public static final int EVENT_TOP = 0x0003; |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 1222 | // Event is about active sync operations. |
Dianne Hackborn | a1f1a3c | 2014-02-24 18:12:28 -0800 | [diff] [blame] | 1223 | public static final int EVENT_SYNC = 0x0004; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 1224 | // Events for all additional wake locks aquired/release within a wake block. |
| 1225 | // These are not generated by default. |
| 1226 | public static final int EVENT_WAKE_LOCK = 0x0005; |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 1227 | // Event is about an application executing a scheduled job. |
| 1228 | public static final int EVENT_JOB = 0x0006; |
| 1229 | // Events for users running. |
| 1230 | public static final int EVENT_USER_RUNNING = 0x0007; |
| 1231 | // Events for foreground user. |
| 1232 | public static final int EVENT_USER_FOREGROUND = 0x0008; |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 1233 | // Event for connectivity changed. |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 1234 | public static final int EVENT_CONNECTIVITY_CHANGED = 0x0009; |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 1235 | // Event for becoming active taking us out of idle mode. |
Dianne Hackborn | b6683c4 | 2015-06-18 17:40:33 -0700 | [diff] [blame] | 1236 | public static final int EVENT_ACTIVE = 0x000a; |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 1237 | // Event for a package being installed. |
Dianne Hackborn | b6683c4 | 2015-06-18 17:40:33 -0700 | [diff] [blame] | 1238 | public static final int EVENT_PACKAGE_INSTALLED = 0x000b; |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 1239 | // Event for a package being uninstalled. |
Dianne Hackborn | b6683c4 | 2015-06-18 17:40:33 -0700 | [diff] [blame] | 1240 | public static final int EVENT_PACKAGE_UNINSTALLED = 0x000c; |
Dianne Hackborn | 1e38382 | 2015-04-10 14:02:33 -0700 | [diff] [blame] | 1241 | // Event for a package being uninstalled. |
Dianne Hackborn | b6683c4 | 2015-06-18 17:40:33 -0700 | [diff] [blame] | 1242 | public static final int EVENT_ALARM = 0x000d; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 1243 | // Record that we have decided we need to collect new stats data. |
Dianne Hackborn | b6683c4 | 2015-06-18 17:40:33 -0700 | [diff] [blame] | 1244 | public static final int EVENT_COLLECT_EXTERNAL_STATS = 0x000e; |
Amith Yamasani | 6776849 | 2015-06-09 12:23:58 -0700 | [diff] [blame] | 1245 | // Event for a package becoming inactive due to being unused for a period of time. |
Dianne Hackborn | b6683c4 | 2015-06-18 17:40:33 -0700 | [diff] [blame] | 1246 | public static final int EVENT_PACKAGE_INACTIVE = 0x000f; |
Amith Yamasani | 6776849 | 2015-06-09 12:23:58 -0700 | [diff] [blame] | 1247 | // Event for a package becoming active due to an interaction. |
Dianne Hackborn | b6683c4 | 2015-06-18 17:40:33 -0700 | [diff] [blame] | 1248 | public static final int EVENT_PACKAGE_ACTIVE = 0x0010; |
Dianne Hackborn | fd854ee | 2015-07-13 18:00:37 -0700 | [diff] [blame] | 1249 | // Event for a package being on the temporary whitelist. |
| 1250 | public static final int EVENT_TEMP_WHITELIST = 0x0011; |
Dianne Hackborn | 280a64e | 2015-07-13 14:48:08 -0700 | [diff] [blame] | 1251 | // Event for the screen waking up. |
| 1252 | public static final int EVENT_SCREEN_WAKE_UP = 0x0012; |
Amith Yamasani | 6776849 | 2015-06-09 12:23:58 -0700 | [diff] [blame] | 1253 | |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 1254 | // Number of event types. |
Dianne Hackborn | 280a64e | 2015-07-13 14:48:08 -0700 | [diff] [blame] | 1255 | public static final int EVENT_COUNT = 0x0013; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 1256 | // Mask to extract out only the type part of the event. |
| 1257 | 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] | 1258 | |
| 1259 | public static final int EVENT_PROC_START = EVENT_PROC | EVENT_FLAG_START; |
| 1260 | public static final int EVENT_PROC_FINISH = EVENT_PROC | EVENT_FLAG_FINISH; |
| 1261 | public static final int EVENT_FOREGROUND_START = EVENT_FOREGROUND | EVENT_FLAG_START; |
| 1262 | public static final int EVENT_FOREGROUND_FINISH = EVENT_FOREGROUND | EVENT_FLAG_FINISH; |
| 1263 | public static final int EVENT_TOP_START = EVENT_TOP | EVENT_FLAG_START; |
| 1264 | public static final int EVENT_TOP_FINISH = EVENT_TOP | EVENT_FLAG_FINISH; |
Dianne Hackborn | a1f1a3c | 2014-02-24 18:12:28 -0800 | [diff] [blame] | 1265 | public static final int EVENT_SYNC_START = EVENT_SYNC | EVENT_FLAG_START; |
| 1266 | public static final int EVENT_SYNC_FINISH = EVENT_SYNC | EVENT_FLAG_FINISH; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 1267 | public static final int EVENT_WAKE_LOCK_START = EVENT_WAKE_LOCK | EVENT_FLAG_START; |
| 1268 | 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] | 1269 | public static final int EVENT_JOB_START = EVENT_JOB | EVENT_FLAG_START; |
| 1270 | public static final int EVENT_JOB_FINISH = EVENT_JOB | EVENT_FLAG_FINISH; |
| 1271 | public static final int EVENT_USER_RUNNING_START = EVENT_USER_RUNNING | EVENT_FLAG_START; |
| 1272 | public static final int EVENT_USER_RUNNING_FINISH = EVENT_USER_RUNNING | EVENT_FLAG_FINISH; |
| 1273 | public static final int EVENT_USER_FOREGROUND_START = |
| 1274 | EVENT_USER_FOREGROUND | EVENT_FLAG_START; |
| 1275 | public static final int EVENT_USER_FOREGROUND_FINISH = |
| 1276 | EVENT_USER_FOREGROUND | EVENT_FLAG_FINISH; |
Dianne Hackborn | 1e38382 | 2015-04-10 14:02:33 -0700 | [diff] [blame] | 1277 | public static final int EVENT_ALARM_START = EVENT_ALARM | EVENT_FLAG_START; |
| 1278 | public static final int EVENT_ALARM_FINISH = EVENT_ALARM | EVENT_FLAG_FINISH; |
Dianne Hackborn | fd854ee | 2015-07-13 18:00:37 -0700 | [diff] [blame] | 1279 | public static final int EVENT_TEMP_WHITELIST_START = |
| 1280 | EVENT_TEMP_WHITELIST | EVENT_FLAG_START; |
| 1281 | public static final int EVENT_TEMP_WHITELIST_FINISH = |
| 1282 | EVENT_TEMP_WHITELIST | EVENT_FLAG_FINISH; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1283 | |
| 1284 | // For CMD_EVENT. |
| 1285 | public int eventCode; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1286 | public HistoryTag eventTag; |
| 1287 | |
Dianne Hackborn | 9a75543 | 2014-05-15 17:05:22 -0700 | [diff] [blame] | 1288 | // 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] | 1289 | public long currentTime; |
| 1290 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1291 | // Meta-data when reading. |
| 1292 | public int numReadInts; |
| 1293 | |
| 1294 | // Pre-allocated objects. |
| 1295 | public final HistoryTag localWakelockTag = new HistoryTag(); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1296 | public final HistoryTag localWakeReasonTag = new HistoryTag(); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1297 | public final HistoryTag localEventTag = new HistoryTag(); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1298 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1299 | public HistoryItem() { |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1300 | } |
| 1301 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1302 | public HistoryItem(long time, Parcel src) { |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1303 | this.time = time; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1304 | numReadInts = 2; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 1305 | readFromParcel(src); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1306 | } |
| 1307 | |
| 1308 | public int describeContents() { |
| 1309 | return 0; |
| 1310 | } |
| 1311 | |
| 1312 | public void writeToParcel(Parcel dest, int flags) { |
| 1313 | dest.writeLong(time); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1314 | int bat = (((int)cmd)&0xff) |
| 1315 | | ((((int)batteryLevel)<<8)&0xff00) |
| 1316 | | ((((int)batteryStatus)<<16)&0xf0000) |
| 1317 | | ((((int)batteryHealth)<<20)&0xf00000) |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1318 | | ((((int)batteryPlugType)<<24)&0xf000000) |
| 1319 | | (wakelockTag != null ? 0x10000000 : 0) |
| 1320 | | (wakeReasonTag != null ? 0x20000000 : 0) |
| 1321 | | (eventCode != EVENT_NONE ? 0x40000000 : 0); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1322 | dest.writeInt(bat); |
| 1323 | bat = (((int)batteryTemperature)&0xffff) |
| 1324 | | ((((int)batteryVoltage)<<16)&0xffff0000); |
| 1325 | dest.writeInt(bat); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1326 | dest.writeInt(states); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1327 | dest.writeInt(states2); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1328 | if (wakelockTag != null) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1329 | wakelockTag.writeToParcel(dest, flags); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1330 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1331 | if (wakeReasonTag != null) { |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1332 | wakeReasonTag.writeToParcel(dest, flags); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1333 | } |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 1334 | if (eventCode != EVENT_NONE) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1335 | dest.writeInt(eventCode); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1336 | eventTag.writeToParcel(dest, flags); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1337 | } |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 1338 | if (cmd == CMD_CURRENT_TIME || cmd == CMD_RESET) { |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1339 | dest.writeLong(currentTime); |
| 1340 | } |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1341 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 1342 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1343 | public void readFromParcel(Parcel src) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1344 | int start = src.dataPosition(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 1345 | int bat = src.readInt(); |
| 1346 | cmd = (byte)(bat&0xff); |
| 1347 | batteryLevel = (byte)((bat>>8)&0xff); |
| 1348 | batteryStatus = (byte)((bat>>16)&0xf); |
| 1349 | batteryHealth = (byte)((bat>>20)&0xf); |
| 1350 | batteryPlugType = (byte)((bat>>24)&0xf); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1351 | int bat2 = src.readInt(); |
| 1352 | batteryTemperature = (short)(bat2&0xffff); |
| 1353 | batteryVoltage = (char)((bat2>>16)&0xffff); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 1354 | states = src.readInt(); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1355 | states2 = src.readInt(); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1356 | if ((bat&0x10000000) != 0) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1357 | wakelockTag = localWakelockTag; |
| 1358 | wakelockTag.readFromParcel(src); |
| 1359 | } else { |
| 1360 | wakelockTag = null; |
| 1361 | } |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1362 | if ((bat&0x20000000) != 0) { |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1363 | wakeReasonTag = localWakeReasonTag; |
| 1364 | wakeReasonTag.readFromParcel(src); |
| 1365 | } else { |
| 1366 | wakeReasonTag = null; |
| 1367 | } |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1368 | if ((bat&0x40000000) != 0) { |
| 1369 | eventCode = src.readInt(); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1370 | eventTag = localEventTag; |
| 1371 | eventTag.readFromParcel(src); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1372 | } else { |
| 1373 | eventCode = EVENT_NONE; |
| 1374 | eventTag = null; |
| 1375 | } |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 1376 | if (cmd == CMD_CURRENT_TIME || cmd == CMD_RESET) { |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1377 | currentTime = src.readLong(); |
| 1378 | } else { |
| 1379 | currentTime = 0; |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 1380 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1381 | numReadInts += (src.dataPosition()-start)/4; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 1382 | } |
| 1383 | |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 1384 | public void clear() { |
| 1385 | time = 0; |
| 1386 | cmd = CMD_NULL; |
| 1387 | batteryLevel = 0; |
| 1388 | batteryStatus = 0; |
| 1389 | batteryHealth = 0; |
| 1390 | batteryPlugType = 0; |
| 1391 | batteryTemperature = 0; |
| 1392 | batteryVoltage = 0; |
| 1393 | states = 0; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1394 | states2 = 0; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1395 | wakelockTag = null; |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1396 | wakeReasonTag = null; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1397 | eventCode = EVENT_NONE; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1398 | eventTag = null; |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 1399 | } |
| 1400 | |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 1401 | public void setTo(HistoryItem o) { |
| 1402 | time = o.time; |
| 1403 | cmd = o.cmd; |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 1404 | setToCommon(o); |
| 1405 | } |
| 1406 | |
| 1407 | public void setTo(long time, byte cmd, HistoryItem o) { |
| 1408 | this.time = time; |
| 1409 | this.cmd = cmd; |
| 1410 | setToCommon(o); |
| 1411 | } |
| 1412 | |
| 1413 | private void setToCommon(HistoryItem o) { |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 1414 | batteryLevel = o.batteryLevel; |
| 1415 | batteryStatus = o.batteryStatus; |
| 1416 | batteryHealth = o.batteryHealth; |
| 1417 | batteryPlugType = o.batteryPlugType; |
| 1418 | batteryTemperature = o.batteryTemperature; |
| 1419 | batteryVoltage = o.batteryVoltage; |
| 1420 | states = o.states; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1421 | states2 = o.states2; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1422 | if (o.wakelockTag != null) { |
| 1423 | wakelockTag = localWakelockTag; |
| 1424 | wakelockTag.setTo(o.wakelockTag); |
| 1425 | } else { |
| 1426 | wakelockTag = null; |
| 1427 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1428 | if (o.wakeReasonTag != null) { |
| 1429 | wakeReasonTag = localWakeReasonTag; |
| 1430 | wakeReasonTag.setTo(o.wakeReasonTag); |
| 1431 | } else { |
| 1432 | wakeReasonTag = null; |
| 1433 | } |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1434 | eventCode = o.eventCode; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1435 | if (o.eventTag != null) { |
| 1436 | eventTag = localEventTag; |
| 1437 | eventTag.setTo(o.eventTag); |
| 1438 | } else { |
| 1439 | eventTag = null; |
| 1440 | } |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1441 | currentTime = o.currentTime; |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 1442 | } |
| 1443 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1444 | public boolean sameNonEvent(HistoryItem o) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 1445 | return batteryLevel == o.batteryLevel |
| 1446 | && batteryStatus == o.batteryStatus |
| 1447 | && batteryHealth == o.batteryHealth |
| 1448 | && batteryPlugType == o.batteryPlugType |
| 1449 | && batteryTemperature == o.batteryTemperature |
| 1450 | && batteryVoltage == o.batteryVoltage |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1451 | && states == o.states |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1452 | && states2 == o.states2 |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1453 | && currentTime == o.currentTime; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 1454 | } |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1455 | |
| 1456 | public boolean same(HistoryItem o) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1457 | if (!sameNonEvent(o) || eventCode != o.eventCode) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1458 | return false; |
| 1459 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1460 | if (wakelockTag != o.wakelockTag) { |
| 1461 | if (wakelockTag == null || o.wakelockTag == null) { |
| 1462 | return false; |
| 1463 | } |
| 1464 | if (!wakelockTag.equals(o.wakelockTag)) { |
| 1465 | return false; |
| 1466 | } |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1467 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1468 | if (wakeReasonTag != o.wakeReasonTag) { |
| 1469 | if (wakeReasonTag == null || o.wakeReasonTag == null) { |
| 1470 | return false; |
| 1471 | } |
| 1472 | if (!wakeReasonTag.equals(o.wakeReasonTag)) { |
| 1473 | return false; |
| 1474 | } |
| 1475 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1476 | if (eventTag != o.eventTag) { |
| 1477 | if (eventTag == null || o.eventTag == null) { |
| 1478 | return false; |
| 1479 | } |
| 1480 | if (!eventTag.equals(o.eventTag)) { |
| 1481 | return false; |
| 1482 | } |
| 1483 | } |
| 1484 | return true; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1485 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1486 | } |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 1487 | |
| 1488 | public final static class HistoryEventTracker { |
| 1489 | private final HashMap<String, SparseIntArray>[] mActiveEvents |
| 1490 | = (HashMap<String, SparseIntArray>[]) new HashMap[HistoryItem.EVENT_COUNT]; |
| 1491 | |
| 1492 | public boolean updateState(int code, String name, int uid, int poolIdx) { |
| 1493 | if ((code&HistoryItem.EVENT_FLAG_START) != 0) { |
| 1494 | int idx = code&HistoryItem.EVENT_TYPE_MASK; |
| 1495 | HashMap<String, SparseIntArray> active = mActiveEvents[idx]; |
| 1496 | if (active == null) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 1497 | active = new HashMap<>(); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 1498 | mActiveEvents[idx] = active; |
| 1499 | } |
| 1500 | SparseIntArray uids = active.get(name); |
| 1501 | if (uids == null) { |
| 1502 | uids = new SparseIntArray(); |
| 1503 | active.put(name, uids); |
| 1504 | } |
| 1505 | if (uids.indexOfKey(uid) >= 0) { |
| 1506 | // Already set, nothing to do! |
| 1507 | return false; |
| 1508 | } |
| 1509 | uids.put(uid, poolIdx); |
| 1510 | } else if ((code&HistoryItem.EVENT_FLAG_FINISH) != 0) { |
| 1511 | int idx = code&HistoryItem.EVENT_TYPE_MASK; |
| 1512 | HashMap<String, SparseIntArray> active = mActiveEvents[idx]; |
| 1513 | if (active == null) { |
| 1514 | // not currently active, nothing to do. |
| 1515 | return false; |
| 1516 | } |
| 1517 | SparseIntArray uids = active.get(name); |
| 1518 | if (uids == null) { |
| 1519 | // not currently active, nothing to do. |
| 1520 | return false; |
| 1521 | } |
| 1522 | idx = uids.indexOfKey(uid); |
| 1523 | if (idx < 0) { |
| 1524 | // not currently active, nothing to do. |
| 1525 | return false; |
| 1526 | } |
| 1527 | uids.removeAt(idx); |
| 1528 | if (uids.size() <= 0) { |
| 1529 | active.remove(name); |
| 1530 | } |
| 1531 | } |
| 1532 | return true; |
| 1533 | } |
| 1534 | |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 1535 | public void removeEvents(int code) { |
| 1536 | int idx = code&HistoryItem.EVENT_TYPE_MASK; |
| 1537 | mActiveEvents[idx] = null; |
| 1538 | } |
| 1539 | |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 1540 | public HashMap<String, SparseIntArray> getStateForEvent(int code) { |
| 1541 | return mActiveEvents[code]; |
| 1542 | } |
| 1543 | } |
| 1544 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1545 | public static final class BitDescription { |
| 1546 | public final int mask; |
| 1547 | public final int shift; |
| 1548 | public final String name; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1549 | public final String shortName; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1550 | public final String[] values; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1551 | public final String[] shortValues; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1552 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1553 | public BitDescription(int mask, String name, String shortName) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1554 | this.mask = mask; |
| 1555 | this.shift = -1; |
| 1556 | this.name = name; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1557 | this.shortName = shortName; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1558 | this.values = null; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1559 | this.shortValues = null; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1560 | } |
| 1561 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1562 | public BitDescription(int mask, int shift, String name, String shortName, |
| 1563 | String[] values, String[] shortValues) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1564 | this.mask = mask; |
| 1565 | this.shift = shift; |
| 1566 | this.name = name; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1567 | this.shortName = shortName; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1568 | this.values = values; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1569 | this.shortValues = shortValues; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1570 | } |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1571 | } |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 1572 | |
Dianne Hackborn | fc06413 | 2014-06-02 12:42:12 -0700 | [diff] [blame] | 1573 | /** |
| 1574 | * Don't allow any more batching in to the current history event. This |
| 1575 | * is called when printing partial histories, so to ensure that the next |
| 1576 | * history event will go in to a new batch after what was printed in the |
| 1577 | * last partial history. |
| 1578 | */ |
| 1579 | public abstract void commitCurrentHistoryBatchLocked(); |
| 1580 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1581 | public abstract int getHistoryTotalSize(); |
| 1582 | |
| 1583 | public abstract int getHistoryUsedSize(); |
| 1584 | |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 1585 | public abstract boolean startIteratingHistoryLocked(); |
| 1586 | |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 1587 | public abstract int getHistoryStringPoolSize(); |
| 1588 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1589 | public abstract int getHistoryStringPoolBytes(); |
| 1590 | |
| 1591 | public abstract String getHistoryTagPoolString(int index); |
| 1592 | |
| 1593 | public abstract int getHistoryTagPoolUid(int index); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 1594 | |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 1595 | public abstract boolean getNextHistoryLocked(HistoryItem out); |
| 1596 | |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 1597 | public abstract void finishIteratingHistoryLocked(); |
| 1598 | |
| 1599 | public abstract boolean startIteratingOldHistoryLocked(); |
| 1600 | |
| 1601 | public abstract boolean getNextOldHistoryLocked(HistoryItem out); |
| 1602 | |
| 1603 | public abstract void finishIteratingOldHistoryLocked(); |
| 1604 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1605 | /** |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 1606 | * Return the base time offset for the battery history. |
| 1607 | */ |
| 1608 | public abstract long getHistoryBaseTime(); |
| 1609 | |
| 1610 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1611 | * Returns the number of times the device has been started. |
| 1612 | */ |
| 1613 | public abstract int getStartCount(); |
| 1614 | |
| 1615 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 1616 | * 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] | 1617 | * running on battery. |
| 1618 | * |
| 1619 | * {@hide} |
| 1620 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1621 | public abstract long getScreenOnTime(long elapsedRealtimeUs, int which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1622 | |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 1623 | /** |
| 1624 | * Returns the number of times the screen was turned on. |
| 1625 | * |
| 1626 | * {@hide} |
| 1627 | */ |
| 1628 | public abstract int getScreenOnCount(int which); |
| 1629 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 1630 | public abstract long getInteractiveTime(long elapsedRealtimeUs, int which); |
| 1631 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1632 | public static final int SCREEN_BRIGHTNESS_DARK = 0; |
| 1633 | public static final int SCREEN_BRIGHTNESS_DIM = 1; |
| 1634 | public static final int SCREEN_BRIGHTNESS_MEDIUM = 2; |
| 1635 | public static final int SCREEN_BRIGHTNESS_LIGHT = 3; |
| 1636 | public static final int SCREEN_BRIGHTNESS_BRIGHT = 4; |
| 1637 | |
| 1638 | static final String[] SCREEN_BRIGHTNESS_NAMES = { |
| 1639 | "dark", "dim", "medium", "light", "bright" |
| 1640 | }; |
| 1641 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1642 | static final String[] SCREEN_BRIGHTNESS_SHORT_NAMES = { |
| 1643 | "0", "1", "2", "3", "4" |
| 1644 | }; |
| 1645 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1646 | public static final int NUM_SCREEN_BRIGHTNESS_BINS = 5; |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 1647 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1648 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 1649 | * Returns the time in microseconds that the screen has been on with |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1650 | * the given brightness |
| 1651 | * |
| 1652 | * {@hide} |
| 1653 | */ |
| 1654 | public abstract long getScreenBrightnessTime(int brightnessBin, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1655 | long elapsedRealtimeUs, int which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1656 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1657 | /** |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 1658 | * 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] | 1659 | * running on battery. |
| 1660 | * |
| 1661 | * {@hide} |
| 1662 | */ |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 1663 | public abstract long getPowerSaveModeEnabledTime(long elapsedRealtimeUs, int which); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 1664 | |
| 1665 | /** |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 1666 | * Returns the number of times that power save mode was enabled. |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 1667 | * |
| 1668 | * {@hide} |
| 1669 | */ |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 1670 | public abstract int getPowerSaveModeEnabledCount(int which); |
| 1671 | |
| 1672 | /** |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 1673 | * Constant for device idle mode: not active. |
| 1674 | */ |
| 1675 | public static final int DEVICE_IDLE_MODE_OFF = 0; |
| 1676 | |
| 1677 | /** |
| 1678 | * Constant for device idle mode: active in lightweight mode. |
| 1679 | */ |
| 1680 | public static final int DEVICE_IDLE_MODE_LIGHT = 1; |
| 1681 | |
| 1682 | /** |
| 1683 | * Constant for device idle mode: active in full mode. |
| 1684 | */ |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 1685 | public static final int DEVICE_IDLE_MODE_DEEP = 2; |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 1686 | |
| 1687 | /** |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 1688 | * Returns the time in microseconds that device has been in idle mode while |
| 1689 | * running on battery. |
| 1690 | * |
| 1691 | * {@hide} |
| 1692 | */ |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 1693 | public abstract long getDeviceIdleModeTime(int mode, long elapsedRealtimeUs, int which); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 1694 | |
| 1695 | /** |
| 1696 | * Returns the number of times that the devie has gone in to idle mode. |
| 1697 | * |
| 1698 | * {@hide} |
| 1699 | */ |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 1700 | public abstract int getDeviceIdleModeCount(int mode, int which); |
| 1701 | |
| 1702 | /** |
| 1703 | * Return the longest duration we spent in a particular device idle mode (fully in the |
| 1704 | * mode, not in idle maintenance etc). |
| 1705 | */ |
| 1706 | public abstract long getLongestDeviceIdleModeTime(int mode); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 1707 | |
| 1708 | /** |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 1709 | * Returns the time in microseconds that device has been in idling while on |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 1710 | * battery. This is broader than {@link #getDeviceIdleModeTime} -- it |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 1711 | * counts all of the time that we consider the device to be idle, whether or not |
| 1712 | * it is currently in the actual device idle mode. |
| 1713 | * |
| 1714 | * {@hide} |
| 1715 | */ |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 1716 | public abstract long getDeviceIdlingTime(int mode, long elapsedRealtimeUs, int which); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 1717 | |
| 1718 | /** |
| 1719 | * Returns the number of times that the devie has started idling. |
| 1720 | * |
| 1721 | * {@hide} |
| 1722 | */ |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 1723 | public abstract int getDeviceIdlingCount(int mode, int which); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 1724 | |
| 1725 | /** |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 1726 | * Returns the number of times that connectivity state changed. |
| 1727 | * |
| 1728 | * {@hide} |
| 1729 | */ |
| 1730 | public abstract int getNumConnectivityChange(int which); |
| 1731 | |
| 1732 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 1733 | * 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] | 1734 | * running on battery. |
| 1735 | * |
| 1736 | * {@hide} |
| 1737 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1738 | public abstract long getPhoneOnTime(long elapsedRealtimeUs, int which); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 1739 | |
| 1740 | /** |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 1741 | * Returns the number of times a phone call was activated. |
| 1742 | * |
| 1743 | * {@hide} |
| 1744 | */ |
| 1745 | public abstract int getPhoneOnCount(int which); |
| 1746 | |
| 1747 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 1748 | * Returns the time in microseconds that the phone has been running with |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 1749 | * the given signal strength. |
| 1750 | * |
| 1751 | * {@hide} |
| 1752 | */ |
| 1753 | public abstract long getPhoneSignalStrengthTime(int strengthBin, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1754 | long elapsedRealtimeUs, int which); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 1755 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1756 | /** |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 1757 | * Returns the time in microseconds that the phone has been trying to |
| 1758 | * acquire a signal. |
| 1759 | * |
| 1760 | * {@hide} |
| 1761 | */ |
| 1762 | public abstract long getPhoneSignalScanningTime( |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1763 | long elapsedRealtimeUs, int which); |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 1764 | |
| 1765 | /** |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1766 | * Returns the number of times the phone has entered the given signal strength. |
| 1767 | * |
| 1768 | * {@hide} |
| 1769 | */ |
| 1770 | public abstract int getPhoneSignalStrengthCount(int strengthBin, int which); |
| 1771 | |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 1772 | /** |
| 1773 | * Returns the time in microseconds that the mobile network has been active |
| 1774 | * (in a high power state). |
| 1775 | * |
| 1776 | * {@hide} |
| 1777 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1778 | public abstract long getMobileRadioActiveTime(long elapsedRealtimeUs, int which); |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 1779 | |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 1780 | /** |
| 1781 | * Returns the number of times that the mobile network has transitioned to the |
| 1782 | * active state. |
| 1783 | * |
| 1784 | * {@hide} |
| 1785 | */ |
| 1786 | public abstract int getMobileRadioActiveCount(int which); |
| 1787 | |
| 1788 | /** |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1789 | * Returns the time in microseconds that is the difference between the mobile radio |
| 1790 | * time we saw based on the elapsed timestamp when going down vs. the given time stamp |
| 1791 | * from the radio. |
| 1792 | * |
| 1793 | * {@hide} |
| 1794 | */ |
| 1795 | public abstract long getMobileRadioActiveAdjustedTime(int which); |
| 1796 | |
| 1797 | /** |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 1798 | * Returns the time in microseconds that the mobile network has been active |
| 1799 | * (in a high power state) but not being able to blame on an app. |
| 1800 | * |
| 1801 | * {@hide} |
| 1802 | */ |
| 1803 | public abstract long getMobileRadioActiveUnknownTime(int which); |
| 1804 | |
| 1805 | /** |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 1806 | * 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] | 1807 | * |
| 1808 | * {@hide} |
| 1809 | */ |
| 1810 | public abstract int getMobileRadioActiveUnknownCount(int which); |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 1811 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 1812 | public static final int DATA_CONNECTION_NONE = 0; |
| 1813 | public static final int DATA_CONNECTION_GPRS = 1; |
| 1814 | public static final int DATA_CONNECTION_EDGE = 2; |
| 1815 | public static final int DATA_CONNECTION_UMTS = 3; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1816 | public static final int DATA_CONNECTION_CDMA = 4; |
| 1817 | public static final int DATA_CONNECTION_EVDO_0 = 5; |
| 1818 | public static final int DATA_CONNECTION_EVDO_A = 6; |
| 1819 | public static final int DATA_CONNECTION_1xRTT = 7; |
| 1820 | public static final int DATA_CONNECTION_HSDPA = 8; |
| 1821 | public static final int DATA_CONNECTION_HSUPA = 9; |
| 1822 | public static final int DATA_CONNECTION_HSPA = 10; |
| 1823 | public static final int DATA_CONNECTION_IDEN = 11; |
| 1824 | public static final int DATA_CONNECTION_EVDO_B = 12; |
Robert Greenwalt | 962a990 | 2010-11-02 11:10:25 -0700 | [diff] [blame] | 1825 | public static final int DATA_CONNECTION_LTE = 13; |
| 1826 | public static final int DATA_CONNECTION_EHRPD = 14; |
Patrick Tjin | b71703c | 2013-11-06 09:27:03 -0800 | [diff] [blame] | 1827 | public static final int DATA_CONNECTION_HSPAP = 15; |
| 1828 | public static final int DATA_CONNECTION_OTHER = 16; |
Robert Greenwalt | 962a990 | 2010-11-02 11:10:25 -0700 | [diff] [blame] | 1829 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 1830 | static final String[] DATA_CONNECTION_NAMES = { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1831 | "none", "gprs", "edge", "umts", "cdma", "evdo_0", "evdo_A", |
Robert Greenwalt | 962a990 | 2010-11-02 11:10:25 -0700 | [diff] [blame] | 1832 | "1xrtt", "hsdpa", "hsupa", "hspa", "iden", "evdo_b", "lte", |
Patrick Tjin | b71703c | 2013-11-06 09:27:03 -0800 | [diff] [blame] | 1833 | "ehrpd", "hspap", "other" |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 1834 | }; |
| 1835 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1836 | public static final int NUM_DATA_CONNECTION_TYPES = DATA_CONNECTION_OTHER+1; |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 1837 | |
| 1838 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 1839 | * Returns the time in microseconds that the phone has been running with |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 1840 | * the given data connection. |
| 1841 | * |
| 1842 | * {@hide} |
| 1843 | */ |
| 1844 | public abstract long getPhoneDataConnectionTime(int dataType, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1845 | long elapsedRealtimeUs, int which); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 1846 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1847 | /** |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1848 | * Returns the number of times the phone has entered the given data |
| 1849 | * connection type. |
| 1850 | * |
| 1851 | * {@hide} |
| 1852 | */ |
| 1853 | public abstract int getPhoneDataConnectionCount(int dataType, int which); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1854 | |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 1855 | public static final int WIFI_SUPPL_STATE_INVALID = 0; |
| 1856 | public static final int WIFI_SUPPL_STATE_DISCONNECTED = 1; |
| 1857 | public static final int WIFI_SUPPL_STATE_INTERFACE_DISABLED = 2; |
| 1858 | public static final int WIFI_SUPPL_STATE_INACTIVE = 3; |
| 1859 | public static final int WIFI_SUPPL_STATE_SCANNING = 4; |
| 1860 | public static final int WIFI_SUPPL_STATE_AUTHENTICATING = 5; |
| 1861 | public static final int WIFI_SUPPL_STATE_ASSOCIATING = 6; |
| 1862 | public static final int WIFI_SUPPL_STATE_ASSOCIATED = 7; |
| 1863 | public static final int WIFI_SUPPL_STATE_FOUR_WAY_HANDSHAKE = 8; |
| 1864 | public static final int WIFI_SUPPL_STATE_GROUP_HANDSHAKE = 9; |
| 1865 | public static final int WIFI_SUPPL_STATE_COMPLETED = 10; |
| 1866 | public static final int WIFI_SUPPL_STATE_DORMANT = 11; |
| 1867 | public static final int WIFI_SUPPL_STATE_UNINITIALIZED = 12; |
| 1868 | |
| 1869 | public static final int NUM_WIFI_SUPPL_STATES = WIFI_SUPPL_STATE_UNINITIALIZED+1; |
| 1870 | |
| 1871 | static final String[] WIFI_SUPPL_STATE_NAMES = { |
| 1872 | "invalid", "disconn", "disabled", "inactive", "scanning", |
| 1873 | "authenticating", "associating", "associated", "4-way-handshake", |
| 1874 | "group-handshake", "completed", "dormant", "uninit" |
| 1875 | }; |
| 1876 | |
| 1877 | static final String[] WIFI_SUPPL_STATE_SHORT_NAMES = { |
| 1878 | "inv", "dsc", "dis", "inact", "scan", |
| 1879 | "auth", "ascing", "asced", "4-way", |
| 1880 | "group", "compl", "dorm", "uninit" |
| 1881 | }; |
| 1882 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1883 | public static final BitDescription[] HISTORY_STATE_DESCRIPTIONS |
| 1884 | = new BitDescription[] { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1885 | new BitDescription(HistoryItem.STATE_CPU_RUNNING_FLAG, "running", "r"), |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 1886 | new BitDescription(HistoryItem.STATE_WAKE_LOCK_FLAG, "wake_lock", "w"), |
| 1887 | new BitDescription(HistoryItem.STATE_SENSOR_ON_FLAG, "sensor", "s"), |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1888 | new BitDescription(HistoryItem.STATE_GPS_ON_FLAG, "gps", "g"), |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1889 | new BitDescription(HistoryItem.STATE_WIFI_FULL_LOCK_FLAG, "wifi_full_lock", "Wl"), |
| 1890 | new BitDescription(HistoryItem.STATE_WIFI_SCAN_FLAG, "wifi_scan", "Ws"), |
| 1891 | new BitDescription(HistoryItem.STATE_WIFI_MULTICAST_ON_FLAG, "wifi_multicast", "Wm"), |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 1892 | new BitDescription(HistoryItem.STATE_WIFI_RADIO_ACTIVE_FLAG, "wifi_radio", "Wr"), |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 1893 | new BitDescription(HistoryItem.STATE_MOBILE_RADIO_ACTIVE_FLAG, "mobile_radio", "Pr"), |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 1894 | new BitDescription(HistoryItem.STATE_PHONE_SCANNING_FLAG, "phone_scanning", "Psc"), |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1895 | new BitDescription(HistoryItem.STATE_AUDIO_ON_FLAG, "audio", "a"), |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 1896 | new BitDescription(HistoryItem.STATE_SCREEN_ON_FLAG, "screen", "S"), |
| 1897 | new BitDescription(HistoryItem.STATE_BATTERY_PLUGGED_FLAG, "plugged", "BP"), |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 1898 | new BitDescription(HistoryItem.STATE_DATA_CONNECTION_MASK, |
| 1899 | HistoryItem.STATE_DATA_CONNECTION_SHIFT, "data_conn", "Pcn", |
| 1900 | DATA_CONNECTION_NAMES, DATA_CONNECTION_NAMES), |
| 1901 | new BitDescription(HistoryItem.STATE_PHONE_STATE_MASK, |
| 1902 | HistoryItem.STATE_PHONE_STATE_SHIFT, "phone_state", "Pst", |
| 1903 | new String[] {"in", "out", "emergency", "off"}, |
| 1904 | new String[] {"in", "out", "em", "off"}), |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 1905 | new BitDescription(HistoryItem.STATE_PHONE_SIGNAL_STRENGTH_MASK, |
| 1906 | HistoryItem.STATE_PHONE_SIGNAL_STRENGTH_SHIFT, "phone_signal_strength", "Pss", |
| 1907 | SignalStrength.SIGNAL_STRENGTH_NAMES, |
| 1908 | new String[] { "0", "1", "2", "3", "4" }), |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 1909 | new BitDescription(HistoryItem.STATE_BRIGHTNESS_MASK, |
| 1910 | HistoryItem.STATE_BRIGHTNESS_SHIFT, "brightness", "Sb", |
| 1911 | SCREEN_BRIGHTNESS_NAMES, SCREEN_BRIGHTNESS_SHORT_NAMES), |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1912 | }; |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1913 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1914 | public static final BitDescription[] HISTORY_STATE2_DESCRIPTIONS |
| 1915 | = new BitDescription[] { |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 1916 | new BitDescription(HistoryItem.STATE2_POWER_SAVE_FLAG, "power_save", "ps"), |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 1917 | new BitDescription(HistoryItem.STATE2_VIDEO_ON_FLAG, "video", "v"), |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 1918 | new BitDescription(HistoryItem.STATE2_WIFI_RUNNING_FLAG, "wifi_running", "Ww"), |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 1919 | new BitDescription(HistoryItem.STATE2_WIFI_ON_FLAG, "wifi", "W"), |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 1920 | new BitDescription(HistoryItem.STATE2_FLASHLIGHT_FLAG, "flashlight", "fl"), |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 1921 | new BitDescription(HistoryItem.STATE2_DEVICE_IDLE_MASK, |
| 1922 | HistoryItem.STATE2_DEVICE_IDLE_SHIFT, "device_idle", "di", |
| 1923 | new String[] { "off", "light", "full", "???" }, |
| 1924 | new String[] { "off", "light", "full", "???" }), |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 1925 | new BitDescription(HistoryItem.STATE2_CHARGING_FLAG, "charging", "ch"), |
| 1926 | new BitDescription(HistoryItem.STATE2_PHONE_IN_CALL_FLAG, "phone_in_call", "Pcl"), |
| 1927 | new BitDescription(HistoryItem.STATE2_BLUETOOTH_ON_FLAG, "bluetooth", "b"), |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 1928 | new BitDescription(HistoryItem.STATE2_WIFI_SIGNAL_STRENGTH_MASK, |
| 1929 | HistoryItem.STATE2_WIFI_SIGNAL_STRENGTH_SHIFT, "wifi_signal_strength", "Wss", |
| 1930 | new String[] { "0", "1", "2", "3", "4" }, |
| 1931 | new String[] { "0", "1", "2", "3", "4" }), |
| 1932 | new BitDescription(HistoryItem.STATE2_WIFI_SUPPL_STATE_MASK, |
| 1933 | HistoryItem.STATE2_WIFI_SUPPL_STATE_SHIFT, "wifi_suppl", "Wsp", |
| 1934 | WIFI_SUPPL_STATE_NAMES, WIFI_SUPPL_STATE_SHORT_NAMES), |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 1935 | new BitDescription(HistoryItem.STATE2_CAMERA_FLAG, "camera", "ca"), |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 1936 | new BitDescription(HistoryItem.STATE2_BLUETOOTH_SCAN_FLAG, "ble_scan", "bles"), |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1937 | }; |
| 1938 | |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 1939 | public static final String[] HISTORY_EVENT_NAMES = new String[] { |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 1940 | "null", "proc", "fg", "top", "sync", "wake_lock_in", "job", "user", "userfg", "conn", |
Dianne Hackborn | 280a64e | 2015-07-13 14:48:08 -0700 | [diff] [blame] | 1941 | "active", "pkginst", "pkgunin", "alarm", "stats", "inactive", "active", "tmpwhitelist", |
| 1942 | "screenwake", |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 1943 | }; |
| 1944 | |
| 1945 | public static final String[] HISTORY_EVENT_CHECKIN_NAMES = new String[] { |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 1946 | "Enl", "Epr", "Efg", "Etp", "Esy", "Ewl", "Ejb", "Eur", "Euf", "Ecn", |
Dianne Hackborn | 280a64e | 2015-07-13 14:48:08 -0700 | [diff] [blame] | 1947 | "Eac", "Epi", "Epu", "Eal", "Est", "Eai", "Eaa", "Etw", |
| 1948 | "Esw", |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 1949 | }; |
| 1950 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1951 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 1952 | * 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] | 1953 | * running on battery. |
| 1954 | * |
| 1955 | * {@hide} |
| 1956 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1957 | public abstract long getWifiOnTime(long elapsedRealtimeUs, int which); |
Eric Shienbrood | d4c5f89 | 2009-03-24 18:13:20 -0700 | [diff] [blame] | 1958 | |
| 1959 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 1960 | * 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] | 1961 | * been in the running state while the device was running on battery. |
| 1962 | * |
| 1963 | * {@hide} |
| 1964 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1965 | public abstract long getGlobalWifiRunningTime(long elapsedRealtimeUs, int which); |
Eric Shienbrood | d4c5f89 | 2009-03-24 18:13:20 -0700 | [diff] [blame] | 1966 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 1967 | public static final int WIFI_STATE_OFF = 0; |
| 1968 | public static final int WIFI_STATE_OFF_SCANNING = 1; |
| 1969 | public static final int WIFI_STATE_ON_NO_NETWORKS = 2; |
| 1970 | public static final int WIFI_STATE_ON_DISCONNECTED = 3; |
| 1971 | public static final int WIFI_STATE_ON_CONNECTED_STA = 4; |
| 1972 | public static final int WIFI_STATE_ON_CONNECTED_P2P = 5; |
| 1973 | public static final int WIFI_STATE_ON_CONNECTED_STA_P2P = 6; |
| 1974 | public static final int WIFI_STATE_SOFT_AP = 7; |
| 1975 | |
| 1976 | static final String[] WIFI_STATE_NAMES = { |
| 1977 | "off", "scanning", "no_net", "disconn", |
| 1978 | "sta", "p2p", "sta_p2p", "soft_ap" |
| 1979 | }; |
| 1980 | |
| 1981 | public static final int NUM_WIFI_STATES = WIFI_STATE_SOFT_AP+1; |
| 1982 | |
| 1983 | /** |
| 1984 | * Returns the time in microseconds that WiFi has been running in the given state. |
| 1985 | * |
| 1986 | * {@hide} |
| 1987 | */ |
| 1988 | public abstract long getWifiStateTime(int wifiState, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1989 | long elapsedRealtimeUs, int which); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 1990 | |
| 1991 | /** |
| 1992 | * Returns the number of times that WiFi has entered the given state. |
| 1993 | * |
| 1994 | * {@hide} |
| 1995 | */ |
| 1996 | public abstract int getWifiStateCount(int wifiState, int which); |
| 1997 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 1998 | /** |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 1999 | * Returns the time in microseconds that the wifi supplicant has been |
| 2000 | * in a given state. |
| 2001 | * |
| 2002 | * {@hide} |
| 2003 | */ |
| 2004 | public abstract long getWifiSupplStateTime(int state, long elapsedRealtimeUs, int which); |
| 2005 | |
| 2006 | /** |
| 2007 | * Returns the number of times that the wifi supplicant has transitioned |
| 2008 | * to a given state. |
| 2009 | * |
| 2010 | * {@hide} |
| 2011 | */ |
| 2012 | public abstract int getWifiSupplStateCount(int state, int which); |
| 2013 | |
| 2014 | public static final int NUM_WIFI_SIGNAL_STRENGTH_BINS = 5; |
| 2015 | |
| 2016 | /** |
| 2017 | * Returns the time in microseconds that WIFI has been running with |
| 2018 | * the given signal strength. |
| 2019 | * |
| 2020 | * {@hide} |
| 2021 | */ |
| 2022 | public abstract long getWifiSignalStrengthTime(int strengthBin, |
| 2023 | long elapsedRealtimeUs, int which); |
| 2024 | |
| 2025 | /** |
| 2026 | * Returns the number of times WIFI has entered the given signal strength. |
| 2027 | * |
| 2028 | * {@hide} |
| 2029 | */ |
| 2030 | public abstract int getWifiSignalStrengthCount(int strengthBin, int which); |
| 2031 | |
| 2032 | /** |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 2033 | * Returns the time in microseconds that the flashlight has been on while the device was |
| 2034 | * running on battery. |
| 2035 | * |
| 2036 | * {@hide} |
| 2037 | */ |
| 2038 | public abstract long getFlashlightOnTime(long elapsedRealtimeUs, int which); |
| 2039 | |
| 2040 | /** |
| 2041 | * Returns the number of times that the flashlight has been turned on while the device was |
| 2042 | * running on battery. |
| 2043 | * |
| 2044 | * {@hide} |
| 2045 | */ |
| 2046 | public abstract long getFlashlightOnCount(int which); |
| 2047 | |
Ruben Brunk | 5b1308f | 2015-06-03 18:49:27 -0700 | [diff] [blame] | 2048 | /** |
| 2049 | * Returns the time in microseconds that the camera has been on while the device was |
| 2050 | * running on battery. |
| 2051 | * |
| 2052 | * {@hide} |
| 2053 | */ |
| 2054 | public abstract long getCameraOnTime(long elapsedRealtimeUs, int which); |
| 2055 | |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 2056 | /** |
| 2057 | * Returns the time in microseconds that bluetooth scans were running while the device was |
| 2058 | * on battery. |
| 2059 | * |
| 2060 | * {@hide} |
| 2061 | */ |
| 2062 | public abstract long getBluetoothScanTime(long elapsedRealtimeUs, int which); |
Ruben Brunk | 5b1308f | 2015-06-03 18:49:27 -0700 | [diff] [blame] | 2063 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2064 | public static final int NETWORK_MOBILE_RX_DATA = 0; |
| 2065 | public static final int NETWORK_MOBILE_TX_DATA = 1; |
| 2066 | public static final int NETWORK_WIFI_RX_DATA = 2; |
| 2067 | public static final int NETWORK_WIFI_TX_DATA = 3; |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 2068 | public static final int NETWORK_BT_RX_DATA = 4; |
| 2069 | public static final int NETWORK_BT_TX_DATA = 5; |
| 2070 | public static final int NUM_NETWORK_ACTIVITY_TYPES = NETWORK_BT_TX_DATA + 1; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 2071 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2072 | public abstract long getNetworkActivityBytes(int type, int which); |
| 2073 | public abstract long getNetworkActivityPackets(int type, int which); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 2074 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 2075 | /** |
Adam Lesinski | 1739076 | 2015-04-10 13:17:47 -0700 | [diff] [blame] | 2076 | * Returns true if the BatteryStats object has detailed WiFi power reports. |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 2077 | * When true, calling {@link #getWifiControllerActivity()} will yield the |
Adam Lesinski | 1739076 | 2015-04-10 13:17:47 -0700 | [diff] [blame] | 2078 | * actual power data. |
| 2079 | */ |
| 2080 | public abstract boolean hasWifiActivityReporting(); |
| 2081 | |
| 2082 | /** |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 2083 | * Returns a {@link ControllerActivityCounter} which is an aggregate of the times spent |
| 2084 | * in various radio controller states, such as transmit, receive, and idle. |
| 2085 | * @return non-null {@link ControllerActivityCounter} |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 2086 | */ |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 2087 | public abstract ControllerActivityCounter getWifiControllerActivity(); |
| 2088 | |
| 2089 | /** |
| 2090 | * Returns true if the BatteryStats object has detailed bluetooth power reports. |
| 2091 | * When true, calling {@link #getBluetoothControllerActivity()} will yield the |
| 2092 | * actual power data. |
| 2093 | */ |
| 2094 | public abstract boolean hasBluetoothActivityReporting(); |
| 2095 | |
| 2096 | /** |
| 2097 | * Returns a {@link ControllerActivityCounter} which is an aggregate of the times spent |
| 2098 | * in various radio controller states, such as transmit, receive, and idle. |
| 2099 | * @return non-null {@link ControllerActivityCounter} |
| 2100 | */ |
| 2101 | public abstract ControllerActivityCounter getBluetoothControllerActivity(); |
| 2102 | |
| 2103 | /** |
| 2104 | * Returns true if the BatteryStats object has detailed modem power reports. |
| 2105 | * When true, calling {@link #getModemControllerActivity()} will yield the |
| 2106 | * actual power data. |
| 2107 | */ |
| 2108 | public abstract boolean hasModemActivityReporting(); |
| 2109 | |
| 2110 | /** |
| 2111 | * Returns a {@link ControllerActivityCounter} which is an aggregate of the times spent |
| 2112 | * in various radio controller states, such as transmit, receive, and idle. |
| 2113 | * @return non-null {@link ControllerActivityCounter} |
| 2114 | */ |
| 2115 | public abstract ControllerActivityCounter getModemControllerActivity(); |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 2116 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2117 | /** |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 2118 | * Return the wall clock time when battery stats data collection started. |
| 2119 | */ |
| 2120 | public abstract long getStartClockTime(); |
| 2121 | |
| 2122 | /** |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 2123 | * Return platform version tag that we were running in when the battery stats started. |
| 2124 | */ |
| 2125 | public abstract String getStartPlatformVersion(); |
| 2126 | |
| 2127 | /** |
| 2128 | * Return platform version tag that we were running in when the battery stats ended. |
| 2129 | */ |
| 2130 | public abstract String getEndPlatformVersion(); |
| 2131 | |
| 2132 | /** |
| 2133 | * Return the internal version code of the parcelled format. |
| 2134 | */ |
| 2135 | public abstract int getParcelVersion(); |
| 2136 | |
| 2137 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2138 | * Return whether we are currently running on battery. |
| 2139 | */ |
| 2140 | public abstract boolean getIsOnBattery(); |
| 2141 | |
| 2142 | /** |
| 2143 | * Returns a SparseArray containing the statistics for each uid. |
| 2144 | */ |
| 2145 | public abstract SparseArray<? extends Uid> getUidStats(); |
| 2146 | |
| 2147 | /** |
| 2148 | * Returns the current battery uptime in microseconds. |
| 2149 | * |
| 2150 | * @param curTime the amount of elapsed realtime in microseconds. |
| 2151 | */ |
| 2152 | public abstract long getBatteryUptime(long curTime); |
| 2153 | |
| 2154 | /** |
| 2155 | * Returns the current battery realtime in microseconds. |
| 2156 | * |
| 2157 | * @param curTime the amount of elapsed realtime in microseconds. |
| 2158 | */ |
| 2159 | public abstract long getBatteryRealtime(long curTime); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2160 | |
| 2161 | /** |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 2162 | * Returns the battery percentage level at the last time the device was unplugged from power, or |
| 2163 | * the last time it booted on battery power. |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2164 | */ |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 2165 | public abstract int getDischargeStartLevel(); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2166 | |
| 2167 | /** |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 2168 | * Returns the current battery percentage level if we are in a discharge cycle, otherwise |
| 2169 | * returns the level at the last plug event. |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2170 | */ |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 2171 | public abstract int getDischargeCurrentLevel(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2172 | |
| 2173 | /** |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 2174 | * Get the amount the battery has discharged since the stats were |
| 2175 | * last reset after charging, as a lower-end approximation. |
| 2176 | */ |
| 2177 | public abstract int getLowDischargeAmountSinceCharge(); |
| 2178 | |
| 2179 | /** |
| 2180 | * Get the amount the battery has discharged since the stats were |
| 2181 | * last reset after charging, as an upper-end approximation. |
| 2182 | */ |
| 2183 | public abstract int getHighDischargeAmountSinceCharge(); |
| 2184 | |
| 2185 | /** |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2186 | * Retrieve the discharge amount over the selected discharge period <var>which</var>. |
| 2187 | */ |
| 2188 | public abstract int getDischargeAmount(int which); |
| 2189 | |
| 2190 | /** |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 2191 | * Get the amount the battery has discharged while the screen was on, |
| 2192 | * since the last time power was unplugged. |
| 2193 | */ |
| 2194 | public abstract int getDischargeAmountScreenOn(); |
| 2195 | |
| 2196 | /** |
| 2197 | * Get the amount the battery has discharged while the screen was on, |
| 2198 | * since the last time the device was charged. |
| 2199 | */ |
| 2200 | public abstract int getDischargeAmountScreenOnSinceCharge(); |
| 2201 | |
| 2202 | /** |
| 2203 | * Get the amount the battery has discharged while the screen was off, |
| 2204 | * since the last time power was unplugged. |
| 2205 | */ |
| 2206 | public abstract int getDischargeAmountScreenOff(); |
| 2207 | |
| 2208 | /** |
| 2209 | * Get the amount the battery has discharged while the screen was off, |
| 2210 | * since the last time the device was charged. |
| 2211 | */ |
| 2212 | public abstract int getDischargeAmountScreenOffSinceCharge(); |
| 2213 | |
| 2214 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2215 | * Returns the total, last, or current battery uptime in microseconds. |
| 2216 | * |
| 2217 | * @param curTime the elapsed realtime in microseconds. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2218 | * @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] | 2219 | */ |
| 2220 | public abstract long computeBatteryUptime(long curTime, int which); |
| 2221 | |
| 2222 | /** |
| 2223 | * Returns the total, last, or current battery realtime in microseconds. |
| 2224 | * |
| 2225 | * @param curTime the current elapsed realtime in microseconds. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2226 | * @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] | 2227 | */ |
| 2228 | public abstract long computeBatteryRealtime(long curTime, int which); |
| 2229 | |
| 2230 | /** |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2231 | * Returns the total, last, or current battery screen off uptime in microseconds. |
| 2232 | * |
| 2233 | * @param curTime the elapsed realtime in microseconds. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2234 | * @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] | 2235 | */ |
| 2236 | public abstract long computeBatteryScreenOffUptime(long curTime, int which); |
| 2237 | |
| 2238 | /** |
| 2239 | * Returns the total, last, or current battery screen off realtime in microseconds. |
| 2240 | * |
| 2241 | * @param curTime the current elapsed realtime in microseconds. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2242 | * @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] | 2243 | */ |
| 2244 | public abstract long computeBatteryScreenOffRealtime(long curTime, int which); |
| 2245 | |
| 2246 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2247 | * Returns the total, last, or current uptime in microseconds. |
| 2248 | * |
| 2249 | * @param curTime the current elapsed realtime in microseconds. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2250 | * @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] | 2251 | */ |
| 2252 | public abstract long computeUptime(long curTime, int which); |
| 2253 | |
| 2254 | /** |
| 2255 | * Returns the total, last, or current realtime in microseconds. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2256 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2257 | * @param curTime the current elapsed realtime in microseconds. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2258 | * @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] | 2259 | */ |
| 2260 | public abstract long computeRealtime(long curTime, int which); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2261 | |
| 2262 | /** |
| 2263 | * Compute an approximation for how much run time (in microseconds) is remaining on |
| 2264 | * the battery. Returns -1 if no time can be computed: either there is not |
| 2265 | * enough current data to make a decision, or the battery is currently |
| 2266 | * charging. |
| 2267 | * |
| 2268 | * @param curTime The current elepsed realtime in microseconds. |
| 2269 | */ |
| 2270 | public abstract long computeBatteryTimeRemaining(long curTime); |
| 2271 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 2272 | // The part of a step duration that is the actual time. |
| 2273 | public static final long STEP_LEVEL_TIME_MASK = 0x000000ffffffffffL; |
| 2274 | |
| 2275 | // Bits in a step duration that are the new battery level we are at. |
| 2276 | public static final long STEP_LEVEL_LEVEL_MASK = 0x0000ff0000000000L; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2277 | public static final int STEP_LEVEL_LEVEL_SHIFT = 40; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 2278 | |
| 2279 | // Bits in a step duration that are the initial mode we were in at that step. |
| 2280 | public static final long STEP_LEVEL_INITIAL_MODE_MASK = 0x00ff000000000000L; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2281 | public static final int STEP_LEVEL_INITIAL_MODE_SHIFT = 48; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 2282 | |
| 2283 | // Bits in a step duration that indicate which modes changed during that step. |
| 2284 | public static final long STEP_LEVEL_MODIFIED_MODE_MASK = 0xff00000000000000L; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2285 | public static final int STEP_LEVEL_MODIFIED_MODE_SHIFT = 56; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 2286 | |
| 2287 | // Step duration mode: the screen is on, off, dozed, etc; value is Display.STATE_* - 1. |
| 2288 | public static final int STEP_LEVEL_MODE_SCREEN_STATE = 0x03; |
| 2289 | |
| 2290 | // Step duration mode: power save is on. |
| 2291 | public static final int STEP_LEVEL_MODE_POWER_SAVE = 0x04; |
| 2292 | |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2293 | // Step duration mode: device is currently in idle mode. |
| 2294 | public static final int STEP_LEVEL_MODE_DEVICE_IDLE = 0x08; |
| 2295 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2296 | public static final int[] STEP_LEVEL_MODES_OF_INTEREST = new int[] { |
| 2297 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE, |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2298 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE|STEP_LEVEL_MODE_DEVICE_IDLE, |
| 2299 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_DEVICE_IDLE, |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2300 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE, |
| 2301 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE, |
| 2302 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE, |
| 2303 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE, |
| 2304 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE, |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2305 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE|STEP_LEVEL_MODE_DEVICE_IDLE, |
| 2306 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_DEVICE_IDLE, |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2307 | }; |
| 2308 | public static final int[] STEP_LEVEL_MODE_VALUES = new int[] { |
| 2309 | (Display.STATE_OFF-1), |
| 2310 | (Display.STATE_OFF-1)|STEP_LEVEL_MODE_POWER_SAVE, |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2311 | (Display.STATE_OFF-1)|STEP_LEVEL_MODE_DEVICE_IDLE, |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2312 | (Display.STATE_ON-1), |
| 2313 | (Display.STATE_ON-1)|STEP_LEVEL_MODE_POWER_SAVE, |
| 2314 | (Display.STATE_DOZE-1), |
| 2315 | (Display.STATE_DOZE-1)|STEP_LEVEL_MODE_POWER_SAVE, |
| 2316 | (Display.STATE_DOZE_SUSPEND-1), |
| 2317 | (Display.STATE_DOZE_SUSPEND-1)|STEP_LEVEL_MODE_POWER_SAVE, |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2318 | (Display.STATE_DOZE_SUSPEND-1)|STEP_LEVEL_MODE_DEVICE_IDLE, |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2319 | }; |
| 2320 | public static final String[] STEP_LEVEL_MODE_LABELS = new String[] { |
| 2321 | "screen off", |
| 2322 | "screen off power save", |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2323 | "screen off device idle", |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2324 | "screen on", |
| 2325 | "screen on power save", |
| 2326 | "screen doze", |
| 2327 | "screen doze power save", |
| 2328 | "screen doze-suspend", |
| 2329 | "screen doze-suspend power save", |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2330 | "screen doze-suspend device idle", |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2331 | }; |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 2332 | |
| 2333 | /** |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2334 | * Return the array of discharge step durations. |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 2335 | */ |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2336 | public abstract LevelStepTracker getDischargeLevelStepTracker(); |
| 2337 | |
| 2338 | /** |
| 2339 | * Return the array of daily discharge step durations. |
| 2340 | */ |
| 2341 | public abstract LevelStepTracker getDailyDischargeLevelStepTracker(); |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 2342 | |
| 2343 | /** |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2344 | * Compute an approximation for how much time (in microseconds) remains until the battery |
| 2345 | * is fully charged. Returns -1 if no time can be computed: either there is not |
| 2346 | * enough current data to make a decision, or the battery is currently |
| 2347 | * discharging. |
| 2348 | * |
| 2349 | * @param curTime The current elepsed realtime in microseconds. |
| 2350 | */ |
| 2351 | public abstract long computeChargeTimeRemaining(long curTime); |
| 2352 | |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 2353 | /** |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2354 | * Return the array of charge step durations. |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 2355 | */ |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2356 | public abstract LevelStepTracker getChargeLevelStepTracker(); |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 2357 | |
| 2358 | /** |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2359 | * Return the array of daily charge step durations. |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 2360 | */ |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2361 | public abstract LevelStepTracker getDailyChargeLevelStepTracker(); |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 2362 | |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2363 | public abstract ArrayList<PackageChange> getDailyPackageChanges(); |
| 2364 | |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 2365 | public abstract Map<String, ? extends Timer> getWakeupReasonStats(); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2366 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2367 | public abstract Map<String, ? extends Timer> getKernelWakelockStats(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2368 | |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 2369 | public abstract void writeToParcelWithoutUids(Parcel out, int flags); |
| 2370 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 2371 | private final static void formatTimeRaw(StringBuilder out, long seconds) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2372 | long days = seconds / (60 * 60 * 24); |
| 2373 | if (days != 0) { |
| 2374 | out.append(days); |
| 2375 | out.append("d "); |
| 2376 | } |
| 2377 | long used = days * 60 * 60 * 24; |
| 2378 | |
| 2379 | long hours = (seconds - used) / (60 * 60); |
| 2380 | if (hours != 0 || used != 0) { |
| 2381 | out.append(hours); |
| 2382 | out.append("h "); |
| 2383 | } |
| 2384 | used += hours * 60 * 60; |
| 2385 | |
| 2386 | long mins = (seconds-used) / 60; |
| 2387 | if (mins != 0 || used != 0) { |
| 2388 | out.append(mins); |
| 2389 | out.append("m "); |
| 2390 | } |
| 2391 | used += mins * 60; |
| 2392 | |
| 2393 | if (seconds != 0 || used != 0) { |
| 2394 | out.append(seconds-used); |
| 2395 | out.append("s "); |
| 2396 | } |
| 2397 | } |
| 2398 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2399 | public final static void formatTimeMs(StringBuilder sb, long time) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2400 | long sec = time / 1000; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 2401 | formatTimeRaw(sb, sec); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2402 | sb.append(time - (sec * 1000)); |
| 2403 | sb.append("ms "); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2404 | } |
| 2405 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2406 | public final static void formatTimeMsNoSpace(StringBuilder sb, long time) { |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 2407 | long sec = time / 1000; |
| 2408 | formatTimeRaw(sb, sec); |
| 2409 | sb.append(time - (sec * 1000)); |
| 2410 | sb.append("ms"); |
| 2411 | } |
| 2412 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2413 | public final String formatRatioLocked(long num, long den) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2414 | if (den == 0L) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2415 | return "--%"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2416 | } |
| 2417 | float perc = ((float)num) / ((float)den) * 100; |
| 2418 | mFormatBuilder.setLength(0); |
| 2419 | mFormatter.format("%.1f%%", perc); |
| 2420 | return mFormatBuilder.toString(); |
| 2421 | } |
| 2422 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2423 | final String formatBytesLocked(long bytes) { |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 2424 | mFormatBuilder.setLength(0); |
| 2425 | |
| 2426 | if (bytes < BYTES_PER_KB) { |
| 2427 | return bytes + "B"; |
| 2428 | } else if (bytes < BYTES_PER_MB) { |
| 2429 | mFormatter.format("%.2fKB", bytes / (double) BYTES_PER_KB); |
| 2430 | return mFormatBuilder.toString(); |
| 2431 | } else if (bytes < BYTES_PER_GB){ |
| 2432 | mFormatter.format("%.2fMB", bytes / (double) BYTES_PER_MB); |
| 2433 | return mFormatBuilder.toString(); |
| 2434 | } else { |
| 2435 | mFormatter.format("%.2fGB", bytes / (double) BYTES_PER_GB); |
| 2436 | return mFormatBuilder.toString(); |
| 2437 | } |
| 2438 | } |
| 2439 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2440 | private static long computeWakeLock(Timer timer, long elapsedRealtimeUs, int which) { |
Dianne Hackborn | c24ab86 | 2011-10-18 15:55:03 -0700 | [diff] [blame] | 2441 | if (timer != null) { |
| 2442 | // Convert from microseconds to milliseconds with rounding |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2443 | long totalTimeMicros = timer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Dianne Hackborn | c24ab86 | 2011-10-18 15:55:03 -0700 | [diff] [blame] | 2444 | long totalTimeMillis = (totalTimeMicros + 500) / 1000; |
| 2445 | return totalTimeMillis; |
| 2446 | } |
| 2447 | return 0; |
| 2448 | } |
| 2449 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2450 | /** |
| 2451 | * |
| 2452 | * @param sb a StringBuilder object. |
| 2453 | * @param timer a Timer object contining the wakelock times. |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2454 | * @param elapsedRealtimeUs the current on-battery time in microseconds. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2455 | * @param name the name of the wakelock. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2456 | * @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] | 2457 | * @param linePrefix a String to be prepended to each line of output. |
| 2458 | * @return the line prefix |
| 2459 | */ |
| 2460 | private static final String printWakeLock(StringBuilder sb, Timer timer, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2461 | long elapsedRealtimeUs, String name, int which, String linePrefix) { |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 2462 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2463 | if (timer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2464 | long totalTimeMillis = computeWakeLock(timer, elapsedRealtimeUs, which); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 2465 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2466 | int count = timer.getCountLocked(which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2467 | if (totalTimeMillis != 0) { |
| 2468 | sb.append(linePrefix); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 2469 | formatTimeMs(sb, totalTimeMillis); |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 2470 | if (name != null) { |
| 2471 | sb.append(name); |
| 2472 | sb.append(' '); |
| 2473 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2474 | sb.append('('); |
| 2475 | sb.append(count); |
| 2476 | sb.append(" times)"); |
| 2477 | return ", "; |
| 2478 | } |
| 2479 | } |
| 2480 | return linePrefix; |
| 2481 | } |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 2482 | |
| 2483 | /** |
| 2484 | * |
| 2485 | * @param pw a PrintWriter object to print to. |
| 2486 | * @param sb a StringBuilder object. |
| 2487 | * @param timer a Timer object contining the wakelock times. |
| 2488 | * @param rawRealtime the current on-battery time in microseconds. |
| 2489 | * @param which which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT. |
| 2490 | * @param prefix a String to be prepended to each line of output. |
| 2491 | * @param type the name of the timer. |
| 2492 | */ |
| 2493 | private static final boolean printTimer(PrintWriter pw, StringBuilder sb, Timer timer, |
| 2494 | long rawRealtime, int which, String prefix, String type) { |
| 2495 | if (timer != null) { |
| 2496 | // Convert from microseconds to milliseconds with rounding |
| 2497 | final long totalTime = (timer.getTotalTimeLocked( |
| 2498 | rawRealtime, which) + 500) / 1000; |
| 2499 | final int count = timer.getCountLocked(which); |
| 2500 | if (totalTime != 0) { |
| 2501 | sb.setLength(0); |
| 2502 | sb.append(prefix); |
| 2503 | sb.append(" "); |
| 2504 | sb.append(type); |
| 2505 | sb.append(": "); |
| 2506 | formatTimeMs(sb, totalTime); |
| 2507 | sb.append("realtime ("); |
| 2508 | sb.append(count); |
| 2509 | sb.append(" times)"); |
| 2510 | pw.println(sb.toString()); |
| 2511 | return true; |
| 2512 | } |
| 2513 | } |
| 2514 | return false; |
| 2515 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2516 | |
| 2517 | /** |
| 2518 | * Checkin version of wakelock printer. Prints simple comma-separated list. |
| 2519 | * |
| 2520 | * @param sb a StringBuilder object. |
| 2521 | * @param timer a Timer object contining the wakelock times. |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2522 | * @param elapsedRealtimeUs the current time in microseconds. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2523 | * @param name the name of the wakelock. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2524 | * @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] | 2525 | * @param linePrefix a String to be prepended to each line of output. |
| 2526 | * @return the line prefix |
| 2527 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2528 | private static final String printWakeLockCheckin(StringBuilder sb, Timer timer, |
| 2529 | long elapsedRealtimeUs, String name, int which, String linePrefix) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2530 | long totalTimeMicros = 0; |
| 2531 | int count = 0; |
| 2532 | if (timer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2533 | totalTimeMicros = timer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2534 | count = timer.getCountLocked(which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2535 | } |
| 2536 | sb.append(linePrefix); |
| 2537 | sb.append((totalTimeMicros + 500) / 1000); // microseconds to milliseconds with rounding |
| 2538 | sb.append(','); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2539 | sb.append(name != null ? name + "," : ""); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2540 | sb.append(count); |
| 2541 | return ","; |
| 2542 | } |
| 2543 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 2544 | private static final void dumpLineHeader(PrintWriter pw, int uid, String category, |
| 2545 | String type) { |
| 2546 | pw.print(BATTERY_STATS_CHECKIN_VERSION); |
| 2547 | pw.print(','); |
| 2548 | pw.print(uid); |
| 2549 | pw.print(','); |
| 2550 | pw.print(category); |
| 2551 | pw.print(','); |
| 2552 | pw.print(type); |
| 2553 | } |
| 2554 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2555 | /** |
| 2556 | * Dump a comma-separated line of values for terse checkin mode. |
| 2557 | * |
| 2558 | * @param pw the PageWriter to dump log to |
| 2559 | * @param category category of data (e.g. "total", "last", "unplugged", "current" ) |
| 2560 | * @param type type of data (e.g. "wakelock", "sensor", "process", "apk" , "process", "network") |
| 2561 | * @param args type-dependent data arguments |
| 2562 | */ |
| 2563 | private static final void dumpLine(PrintWriter pw, int uid, String category, String type, |
| 2564 | Object... args ) { |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 2565 | dumpLineHeader(pw, uid, category, type); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 2566 | for (Object arg : args) { |
Dianne Hackborn | 13ac041 | 2013-06-25 19:34:49 -0700 | [diff] [blame] | 2567 | pw.print(','); |
| 2568 | pw.print(arg); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2569 | } |
Dianne Hackborn | 13ac041 | 2013-06-25 19:34:49 -0700 | [diff] [blame] | 2570 | pw.println(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2571 | } |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 2572 | |
| 2573 | /** |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 2574 | * Dump a given timer stat for terse checkin mode. |
| 2575 | * |
| 2576 | * @param pw the PageWriter to dump log to |
| 2577 | * @param uid the UID to log |
| 2578 | * @param category category of data (e.g. "total", "last", "unplugged", "current" ) |
| 2579 | * @param type type of data (e.g. "wakelock", "sensor", "process", "apk" , "process", "network") |
| 2580 | * @param timer a {@link Timer} to dump stats for |
| 2581 | * @param rawRealtime the current elapsed realtime of the system in microseconds |
| 2582 | * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT |
| 2583 | */ |
| 2584 | private static final void dumpTimer(PrintWriter pw, int uid, String category, String type, |
| 2585 | Timer timer, long rawRealtime, int which) { |
| 2586 | if (timer != null) { |
| 2587 | // Convert from microseconds to milliseconds with rounding |
| 2588 | final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) |
| 2589 | / 1000; |
| 2590 | final int count = timer.getCountLocked(which); |
| 2591 | if (totalTime != 0) { |
| 2592 | dumpLine(pw, uid, category, type, totalTime, count); |
| 2593 | } |
| 2594 | } |
| 2595 | } |
| 2596 | |
| 2597 | /** |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 2598 | * Checks if the ControllerActivityCounter has any data worth dumping. |
| 2599 | */ |
| 2600 | private static boolean controllerActivityHasData(ControllerActivityCounter counter, int which) { |
| 2601 | if (counter == null) { |
| 2602 | return false; |
| 2603 | } |
| 2604 | |
| 2605 | if (counter.getIdleTimeCounter().getCountLocked(which) != 0 |
| 2606 | || counter.getRxTimeCounter().getCountLocked(which) != 0 |
| 2607 | || counter.getPowerCounter().getCountLocked(which) != 0) { |
| 2608 | return true; |
| 2609 | } |
| 2610 | |
| 2611 | for (LongCounter c : counter.getTxTimeCounters()) { |
| 2612 | if (c.getCountLocked(which) != 0) { |
| 2613 | return true; |
| 2614 | } |
| 2615 | } |
| 2616 | return false; |
| 2617 | } |
| 2618 | |
| 2619 | /** |
| 2620 | * Dumps the ControllerActivityCounter if it has any data worth dumping. |
| 2621 | * The order of the arguments in the final check in line is: |
| 2622 | * |
| 2623 | * idle, rx, power, tx... |
| 2624 | * |
| 2625 | * where tx... is one or more transmit level times. |
| 2626 | */ |
| 2627 | private static final void dumpControllerActivityLine(PrintWriter pw, int uid, String category, |
| 2628 | String type, |
| 2629 | ControllerActivityCounter counter, |
| 2630 | int which) { |
| 2631 | if (!controllerActivityHasData(counter, which)) { |
| 2632 | return; |
| 2633 | } |
| 2634 | |
| 2635 | dumpLineHeader(pw, uid, category, type); |
| 2636 | pw.print(","); |
| 2637 | pw.print(counter.getIdleTimeCounter().getCountLocked(which)); |
| 2638 | pw.print(","); |
| 2639 | pw.print(counter.getRxTimeCounter().getCountLocked(which)); |
| 2640 | pw.print(","); |
| 2641 | pw.print(counter.getPowerCounter().getCountLocked(which) / (1000 * 60 * 60)); |
| 2642 | for (LongCounter c : counter.getTxTimeCounters()) { |
| 2643 | pw.print(","); |
| 2644 | pw.print(c.getCountLocked(which)); |
| 2645 | } |
| 2646 | pw.println(); |
| 2647 | } |
| 2648 | |
| 2649 | private final void printControllerActivityIfInteresting(PrintWriter pw, StringBuilder sb, |
| 2650 | String prefix, String controllerName, |
| 2651 | ControllerActivityCounter counter, |
| 2652 | int which) { |
| 2653 | if (controllerActivityHasData(counter, which)) { |
| 2654 | printControllerActivity(pw, sb, prefix, controllerName, counter, which); |
| 2655 | } |
| 2656 | } |
| 2657 | |
| 2658 | private final void printControllerActivity(PrintWriter pw, StringBuilder sb, String prefix, |
| 2659 | String controllerName, |
| 2660 | ControllerActivityCounter counter, int which) { |
| 2661 | final long idleTimeMs = counter.getIdleTimeCounter().getCountLocked(which); |
| 2662 | final long rxTimeMs = counter.getRxTimeCounter().getCountLocked(which); |
| 2663 | final long powerDrainMaMs = counter.getPowerCounter().getCountLocked(which); |
| 2664 | long totalTxTimeMs = 0; |
| 2665 | for (LongCounter txState : counter.getTxTimeCounters()) { |
| 2666 | totalTxTimeMs += txState.getCountLocked(which); |
| 2667 | } |
| 2668 | |
| 2669 | final long totalTimeMs = idleTimeMs + rxTimeMs + totalTxTimeMs; |
| 2670 | |
| 2671 | sb.setLength(0); |
| 2672 | sb.append(prefix); |
| 2673 | sb.append(" "); |
| 2674 | sb.append(controllerName); |
| 2675 | sb.append(" Idle time: "); |
| 2676 | formatTimeMs(sb, idleTimeMs); |
| 2677 | sb.append("("); |
| 2678 | sb.append(formatRatioLocked(idleTimeMs, totalTimeMs)); |
| 2679 | sb.append(")"); |
| 2680 | pw.println(sb.toString()); |
| 2681 | |
| 2682 | sb.setLength(0); |
| 2683 | sb.append(prefix); |
| 2684 | sb.append(" "); |
| 2685 | sb.append(controllerName); |
| 2686 | sb.append(" Rx time: "); |
| 2687 | formatTimeMs(sb, rxTimeMs); |
| 2688 | sb.append("("); |
| 2689 | sb.append(formatRatioLocked(rxTimeMs, totalTimeMs)); |
| 2690 | sb.append(")"); |
| 2691 | pw.println(sb.toString()); |
| 2692 | |
| 2693 | sb.setLength(0); |
| 2694 | sb.append(prefix); |
| 2695 | sb.append(" "); |
| 2696 | sb.append(controllerName); |
| 2697 | sb.append(" Tx time: "); |
| 2698 | formatTimeMs(sb, totalTxTimeMs); |
| 2699 | sb.append("("); |
| 2700 | sb.append(formatRatioLocked(totalTxTimeMs, totalTimeMs)); |
| 2701 | sb.append(")"); |
| 2702 | pw.println(sb.toString()); |
| 2703 | |
| 2704 | final int numTxLvls = counter.getTxTimeCounters().length; |
| 2705 | if (numTxLvls > 1) { |
| 2706 | for (int lvl = 0; lvl < numTxLvls; lvl++) { |
| 2707 | final long txLvlTimeMs = counter.getTxTimeCounters()[lvl].getCountLocked(which); |
| 2708 | sb.setLength(0); |
| 2709 | sb.append(prefix); |
| 2710 | sb.append(" ["); |
| 2711 | sb.append(lvl); |
| 2712 | sb.append("] "); |
| 2713 | formatTimeMs(sb, txLvlTimeMs); |
| 2714 | sb.append("("); |
| 2715 | sb.append(formatRatioLocked(txLvlTimeMs, totalTxTimeMs)); |
| 2716 | sb.append(")"); |
| 2717 | pw.println(sb.toString()); |
| 2718 | } |
| 2719 | } |
| 2720 | |
| 2721 | sb.setLength(0); |
| 2722 | sb.append(prefix); |
| 2723 | sb.append(" "); |
| 2724 | sb.append(controllerName); |
| 2725 | sb.append(" Power drain: ").append( |
| 2726 | BatteryStatsHelper.makemAh(powerDrainMaMs / (double) (1000*60*60))); |
| 2727 | sb.append("mAh"); |
| 2728 | pw.println(sb.toString()); |
| 2729 | } |
| 2730 | |
| 2731 | /** |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 2732 | * Temporary for settings. |
| 2733 | */ |
| 2734 | public final void dumpCheckinLocked(Context context, PrintWriter pw, int which, int reqUid) { |
| 2735 | dumpCheckinLocked(context, pw, which, reqUid, BatteryStatsHelper.checkWifiOnly(context)); |
| 2736 | } |
| 2737 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2738 | /** |
| 2739 | * Checkin server version of dump to produce more compact, computer-readable log. |
| 2740 | * |
| 2741 | * NOTE: all times are expressed in 'ms'. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2742 | */ |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 2743 | public final void dumpCheckinLocked(Context context, PrintWriter pw, int which, int reqUid, |
| 2744 | boolean wifiOnly) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2745 | final long rawUptime = SystemClock.uptimeMillis() * 1000; |
| 2746 | final long rawRealtime = SystemClock.elapsedRealtime() * 1000; |
| 2747 | final long batteryUptime = getBatteryUptime(rawUptime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2748 | final long whichBatteryUptime = computeBatteryUptime(rawUptime, which); |
| 2749 | final long whichBatteryRealtime = computeBatteryRealtime(rawRealtime, which); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2750 | final long whichBatteryScreenOffUptime = computeBatteryScreenOffUptime(rawUptime, which); |
| 2751 | final long whichBatteryScreenOffRealtime = computeBatteryScreenOffRealtime(rawRealtime, |
| 2752 | which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2753 | final long totalRealtime = computeRealtime(rawRealtime, which); |
| 2754 | final long totalUptime = computeUptime(rawUptime, which); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2755 | final long screenOnTime = getScreenOnTime(rawRealtime, which); |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 2756 | final long interactiveTime = getInteractiveTime(rawRealtime, which); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 2757 | final long powerSaveModeEnabledTime = getPowerSaveModeEnabledTime(rawRealtime, which); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 2758 | final long deviceIdleModeLightTime = getDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT, |
| 2759 | rawRealtime, which); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 2760 | final long deviceIdleModeFullTime = getDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP, |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 2761 | rawRealtime, which); |
| 2762 | final long deviceLightIdlingTime = getDeviceIdlingTime(DEVICE_IDLE_MODE_LIGHT, |
| 2763 | rawRealtime, which); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 2764 | final long deviceIdlingTime = getDeviceIdlingTime(DEVICE_IDLE_MODE_DEEP, |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 2765 | rawRealtime, which); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 2766 | final int connChanges = getNumConnectivityChange(which); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2767 | final long phoneOnTime = getPhoneOnTime(rawRealtime, which); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 2768 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 2769 | final StringBuilder sb = new StringBuilder(128); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2770 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 2771 | final SparseArray<? extends Uid> uidStats = getUidStats(); |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 2772 | final int NU = uidStats.size(); |
| 2773 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 2774 | final String category = STAT_NAMES[which]; |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 2775 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2776 | // Dump "battery" stat |
| 2777 | dumpLine(pw, 0 /* uid */, category, BATTERY_DATA, |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2778 | which == STATS_SINCE_CHARGED ? getStartCount() : "N/A", |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2779 | whichBatteryRealtime / 1000, whichBatteryUptime / 1000, |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 2780 | totalRealtime / 1000, totalUptime / 1000, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2781 | getStartClockTime(), |
| 2782 | whichBatteryScreenOffRealtime / 1000, whichBatteryScreenOffUptime / 1000); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2783 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2784 | // Calculate wakelock times across all uids. |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 2785 | long fullWakeLockTimeTotal = 0; |
| 2786 | long partialWakeLockTimeTotal = 0; |
| 2787 | |
| 2788 | for (int iu = 0; iu < NU; iu++) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 2789 | final Uid u = uidStats.valueAt(iu); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 2790 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 2791 | final ArrayMap<String, ? extends BatteryStats.Uid.Wakelock> wakelocks |
| 2792 | = u.getWakelockStats(); |
| 2793 | for (int iw=wakelocks.size()-1; iw>=0; iw--) { |
| 2794 | final Uid.Wakelock wl = wakelocks.valueAt(iw); |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 2795 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 2796 | final Timer fullWakeTimer = wl.getWakeTime(WAKE_TYPE_FULL); |
| 2797 | if (fullWakeTimer != null) { |
| 2798 | fullWakeLockTimeTotal += fullWakeTimer.getTotalTimeLocked(rawRealtime, |
| 2799 | which); |
| 2800 | } |
| 2801 | |
| 2802 | final Timer partialWakeTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL); |
| 2803 | if (partialWakeTimer != null) { |
| 2804 | partialWakeLockTimeTotal += partialWakeTimer.getTotalTimeLocked( |
| 2805 | rawRealtime, which); |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 2806 | } |
| 2807 | } |
| 2808 | } |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 2809 | |
| 2810 | // Dump network stats |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 2811 | final long mobileRxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which); |
| 2812 | final long mobileTxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which); |
| 2813 | final long wifiRxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which); |
| 2814 | final long wifiTxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which); |
| 2815 | final long mobileRxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which); |
| 2816 | final long mobileTxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which); |
| 2817 | final long wifiRxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which); |
| 2818 | final long wifiTxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 2819 | final long btRxTotalBytes = getNetworkActivityBytes(NETWORK_BT_RX_DATA, which); |
| 2820 | final long btTxTotalBytes = getNetworkActivityBytes(NETWORK_BT_TX_DATA, which); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2821 | dumpLine(pw, 0 /* uid */, category, GLOBAL_NETWORK_DATA, |
| 2822 | mobileRxTotalBytes, mobileTxTotalBytes, wifiRxTotalBytes, wifiTxTotalBytes, |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 2823 | mobileRxTotalPackets, mobileTxTotalPackets, wifiRxTotalPackets, wifiTxTotalPackets, |
| 2824 | btRxTotalBytes, btTxTotalBytes); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2825 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 2826 | // Dump Modem controller stats |
| 2827 | dumpControllerActivityLine(pw, 0 /* uid */, category, GLOBAL_MODEM_CONTROLLER_DATA, |
| 2828 | getModemControllerActivity(), which); |
| 2829 | |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 2830 | // Dump Wifi controller stats |
| 2831 | final long wifiOnTime = getWifiOnTime(rawRealtime, which); |
| 2832 | final long wifiRunningTime = getGlobalWifiRunningTime(rawRealtime, which); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 2833 | dumpLine(pw, 0 /* uid */, category, GLOBAL_WIFI_DATA, wifiOnTime / 1000, |
Adam Lesinski | 2208e74 | 2016-02-19 12:53:31 -0800 | [diff] [blame] | 2834 | wifiRunningTime / 1000, /* legacy fields follow, keep at 0 */ 0, 0, 0); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 2835 | |
| 2836 | dumpControllerActivityLine(pw, 0 /* uid */, category, GLOBAL_WIFI_CONTROLLER_DATA, |
| 2837 | getWifiControllerActivity(), which); |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 2838 | |
| 2839 | // Dump Bluetooth controller stats |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 2840 | dumpControllerActivityLine(pw, 0 /* uid */, category, GLOBAL_BLUETOOTH_CONTROLLER_DATA, |
| 2841 | getBluetoothControllerActivity(), which); |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 2842 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2843 | // Dump misc stats |
| 2844 | dumpLine(pw, 0 /* uid */, category, MISC_DATA, |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 2845 | screenOnTime / 1000, phoneOnTime / 1000, |
Ashish Sharma | 213bb2f | 2014-07-07 17:14:52 -0700 | [diff] [blame] | 2846 | fullWakeLockTimeTotal / 1000, partialWakeLockTimeTotal / 1000, |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 2847 | getMobileRadioActiveTime(rawRealtime, which) / 1000, |
Ashish Sharma | 213bb2f | 2014-07-07 17:14:52 -0700 | [diff] [blame] | 2848 | getMobileRadioActiveAdjustedTime(which) / 1000, interactiveTime / 1000, |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 2849 | powerSaveModeEnabledTime / 1000, connChanges, deviceIdleModeFullTime / 1000, |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 2850 | getDeviceIdleModeCount(DEVICE_IDLE_MODE_DEEP, which), deviceIdlingTime / 1000, |
| 2851 | getDeviceIdlingCount(DEVICE_IDLE_MODE_DEEP, which), |
Adam Lesinski | 782327b | 2015-07-30 16:36:29 -0700 | [diff] [blame] | 2852 | getMobileRadioActiveCount(which), |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 2853 | getMobileRadioActiveUnknownTime(which) / 1000, deviceIdleModeLightTime / 1000, |
| 2854 | getDeviceIdleModeCount(DEVICE_IDLE_MODE_LIGHT, which), deviceLightIdlingTime / 1000, |
| 2855 | getDeviceIdlingCount(DEVICE_IDLE_MODE_LIGHT, which), |
| 2856 | getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT), |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 2857 | getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP)); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2858 | |
| 2859 | // Dump screen brightness stats |
| 2860 | Object[] args = new Object[NUM_SCREEN_BRIGHTNESS_BINS]; |
| 2861 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2862 | args[i] = getScreenBrightnessTime(i, rawRealtime, which) / 1000; |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2863 | } |
| 2864 | dumpLine(pw, 0 /* uid */, category, SCREEN_BRIGHTNESS_DATA, args); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2865 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 2866 | // Dump signal strength stats |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 2867 | args = new Object[SignalStrength.NUM_SIGNAL_STRENGTH_BINS]; |
| 2868 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2869 | args[i] = getPhoneSignalStrengthTime(i, rawRealtime, which) / 1000; |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 2870 | } |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2871 | dumpLine(pw, 0 /* uid */, category, SIGNAL_STRENGTH_TIME_DATA, args); |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 2872 | dumpLine(pw, 0 /* uid */, category, SIGNAL_SCANNING_TIME_DATA, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2873 | getPhoneSignalScanningTime(rawRealtime, which) / 1000); |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 2874 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2875 | args[i] = getPhoneSignalStrengthCount(i, which); |
| 2876 | } |
| 2877 | dumpLine(pw, 0 /* uid */, category, SIGNAL_STRENGTH_COUNT_DATA, args); |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 2878 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 2879 | // Dump network type stats |
| 2880 | args = new Object[NUM_DATA_CONNECTION_TYPES]; |
| 2881 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2882 | args[i] = getPhoneDataConnectionTime(i, rawRealtime, which) / 1000; |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 2883 | } |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2884 | dumpLine(pw, 0 /* uid */, category, DATA_CONNECTION_TIME_DATA, args); |
| 2885 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
| 2886 | args[i] = getPhoneDataConnectionCount(i, which); |
| 2887 | } |
| 2888 | dumpLine(pw, 0 /* uid */, category, DATA_CONNECTION_COUNT_DATA, args); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 2889 | |
| 2890 | // Dump wifi state stats |
| 2891 | args = new Object[NUM_WIFI_STATES]; |
| 2892 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2893 | args[i] = getWifiStateTime(i, rawRealtime, which) / 1000; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 2894 | } |
| 2895 | dumpLine(pw, 0 /* uid */, category, WIFI_STATE_TIME_DATA, args); |
| 2896 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
| 2897 | args[i] = getWifiStateCount(i, which); |
| 2898 | } |
| 2899 | dumpLine(pw, 0 /* uid */, category, WIFI_STATE_COUNT_DATA, args); |
| 2900 | |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 2901 | // Dump wifi suppl state stats |
| 2902 | args = new Object[NUM_WIFI_SUPPL_STATES]; |
| 2903 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
| 2904 | args[i] = getWifiSupplStateTime(i, rawRealtime, which) / 1000; |
| 2905 | } |
| 2906 | dumpLine(pw, 0 /* uid */, category, WIFI_SUPPL_STATE_TIME_DATA, args); |
| 2907 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
| 2908 | args[i] = getWifiSupplStateCount(i, which); |
| 2909 | } |
| 2910 | dumpLine(pw, 0 /* uid */, category, WIFI_SUPPL_STATE_COUNT_DATA, args); |
| 2911 | |
| 2912 | // Dump wifi signal strength stats |
| 2913 | args = new Object[NUM_WIFI_SIGNAL_STRENGTH_BINS]; |
| 2914 | for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 2915 | args[i] = getWifiSignalStrengthTime(i, rawRealtime, which) / 1000; |
| 2916 | } |
| 2917 | dumpLine(pw, 0 /* uid */, category, WIFI_SIGNAL_STRENGTH_TIME_DATA, args); |
| 2918 | for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 2919 | args[i] = getWifiSignalStrengthCount(i, which); |
| 2920 | } |
| 2921 | dumpLine(pw, 0 /* uid */, category, WIFI_SIGNAL_STRENGTH_COUNT_DATA, args); |
| 2922 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2923 | if (which == STATS_SINCE_UNPLUGGED) { |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 2924 | dumpLine(pw, 0 /* uid */, category, BATTERY_LEVEL_DATA, getDischargeStartLevel(), |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 2925 | getDischargeCurrentLevel()); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2926 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2927 | |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 2928 | if (which == STATS_SINCE_UNPLUGGED) { |
| 2929 | dumpLine(pw, 0 /* uid */, category, BATTERY_DISCHARGE_DATA, |
| 2930 | getDischargeStartLevel()-getDischargeCurrentLevel(), |
| 2931 | getDischargeStartLevel()-getDischargeCurrentLevel(), |
| 2932 | getDischargeAmountScreenOn(), getDischargeAmountScreenOff()); |
| 2933 | } else { |
| 2934 | dumpLine(pw, 0 /* uid */, category, BATTERY_DISCHARGE_DATA, |
| 2935 | getLowDischargeAmountSinceCharge(), getHighDischargeAmountSinceCharge(), |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 2936 | getDischargeAmountScreenOnSinceCharge(), |
| 2937 | getDischargeAmountScreenOffSinceCharge()); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 2938 | } |
| 2939 | |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 2940 | if (reqUid < 0) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 2941 | final Map<String, ? extends Timer> kernelWakelocks = getKernelWakelockStats(); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 2942 | if (kernelWakelocks.size() > 0) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2943 | for (Map.Entry<String, ? extends Timer> ent : kernelWakelocks.entrySet()) { |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 2944 | sb.setLength(0); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2945 | printWakeLockCheckin(sb, ent.getValue(), rawRealtime, null, which, ""); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2946 | dumpLine(pw, 0 /* uid */, category, KERNEL_WAKELOCK_DATA, ent.getKey(), |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 2947 | sb.toString()); |
| 2948 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2949 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 2950 | final Map<String, ? extends Timer> wakeupReasons = getWakeupReasonStats(); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2951 | if (wakeupReasons.size() > 0) { |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 2952 | for (Map.Entry<String, ? extends Timer> ent : wakeupReasons.entrySet()) { |
| 2953 | // Not doing the regular wake lock formatting to remain compatible |
| 2954 | // with the old checkin format. |
| 2955 | long totalTimeMicros = ent.getValue().getTotalTimeLocked(rawRealtime, which); |
| 2956 | int count = ent.getValue().getCountLocked(which); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2957 | dumpLine(pw, 0 /* uid */, category, WAKEUP_REASON_DATA, |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 2958 | "\"" + ent.getKey() + "\"", (totalTimeMicros + 500) / 1000, count); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2959 | } |
| 2960 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2961 | } |
| 2962 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 2963 | final BatteryStatsHelper helper = new BatteryStatsHelper(context, false, wifiOnly); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 2964 | helper.create(this); |
| 2965 | helper.refreshStats(which, UserHandle.USER_ALL); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 2966 | final List<BatterySipper> sippers = helper.getUsageList(); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 2967 | if (sippers != null && sippers.size() > 0) { |
| 2968 | dumpLine(pw, 0 /* uid */, category, POWER_USE_SUMMARY_DATA, |
| 2969 | BatteryStatsHelper.makemAh(helper.getPowerProfile().getBatteryCapacity()), |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 2970 | BatteryStatsHelper.makemAh(helper.getComputedPower()), |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 2971 | BatteryStatsHelper.makemAh(helper.getMinDrainedPower()), |
| 2972 | BatteryStatsHelper.makemAh(helper.getMaxDrainedPower())); |
| 2973 | for (int i=0; i<sippers.size(); i++) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 2974 | final BatterySipper bs = sippers.get(i); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 2975 | int uid = 0; |
| 2976 | String label; |
| 2977 | switch (bs.drainType) { |
| 2978 | case IDLE: |
| 2979 | label="idle"; |
| 2980 | break; |
| 2981 | case CELL: |
| 2982 | label="cell"; |
| 2983 | break; |
| 2984 | case PHONE: |
| 2985 | label="phone"; |
| 2986 | break; |
| 2987 | case WIFI: |
| 2988 | label="wifi"; |
| 2989 | break; |
| 2990 | case BLUETOOTH: |
| 2991 | label="blue"; |
| 2992 | break; |
| 2993 | case SCREEN: |
| 2994 | label="scrn"; |
| 2995 | break; |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 2996 | case FLASHLIGHT: |
| 2997 | label="flashlight"; |
| 2998 | break; |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 2999 | case APP: |
| 3000 | uid = bs.uidObj.getUid(); |
| 3001 | label = "uid"; |
| 3002 | break; |
| 3003 | case USER: |
| 3004 | uid = UserHandle.getUid(bs.userId, 0); |
| 3005 | label = "user"; |
| 3006 | break; |
| 3007 | case UNACCOUNTED: |
| 3008 | label = "unacc"; |
| 3009 | break; |
| 3010 | case OVERCOUNTED: |
| 3011 | label = "over"; |
| 3012 | break; |
Ruben Brunk | 5b1308f | 2015-06-03 18:49:27 -0700 | [diff] [blame] | 3013 | case CAMERA: |
| 3014 | label = "camera"; |
| 3015 | break; |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3016 | default: |
| 3017 | label = "???"; |
| 3018 | } |
| 3019 | dumpLine(pw, uid, category, POWER_USE_ITEM_DATA, label, |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 3020 | BatteryStatsHelper.makemAh(bs.totalPowerMah)); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3021 | } |
| 3022 | } |
| 3023 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3024 | for (int iu = 0; iu < NU; iu++) { |
| 3025 | final int uid = uidStats.keyAt(iu); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 3026 | if (reqUid >= 0 && uid != reqUid) { |
| 3027 | continue; |
| 3028 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3029 | final Uid u = uidStats.valueAt(iu); |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 3030 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3031 | // Dump Network stats per uid, if any |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3032 | final long mobileBytesRx = u.getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which); |
| 3033 | final long mobileBytesTx = u.getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which); |
| 3034 | final long wifiBytesRx = u.getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which); |
| 3035 | final long wifiBytesTx = u.getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which); |
| 3036 | final long mobilePacketsRx = u.getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which); |
| 3037 | final long mobilePacketsTx = u.getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which); |
| 3038 | final long mobileActiveTime = u.getMobileRadioActiveTime(which); |
| 3039 | final int mobileActiveCount = u.getMobileRadioActiveCount(which); |
| 3040 | final long wifiPacketsRx = u.getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which); |
| 3041 | final long wifiPacketsTx = u.getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 3042 | final long btBytesRx = u.getNetworkActivityBytes(NETWORK_BT_RX_DATA, which); |
| 3043 | final long btBytesTx = u.getNetworkActivityBytes(NETWORK_BT_TX_DATA, which); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3044 | if (mobileBytesRx > 0 || mobileBytesTx > 0 || wifiBytesRx > 0 || wifiBytesTx > 0 |
| 3045 | || mobilePacketsRx > 0 || mobilePacketsTx > 0 || wifiPacketsRx > 0 |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 3046 | || wifiPacketsTx > 0 || mobileActiveTime > 0 || mobileActiveCount > 0 |
| 3047 | || btBytesRx > 0 || btBytesTx > 0) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3048 | dumpLine(pw, uid, category, NETWORK_DATA, mobileBytesRx, mobileBytesTx, |
| 3049 | wifiBytesRx, wifiBytesTx, |
| 3050 | mobilePacketsRx, mobilePacketsTx, |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 3051 | wifiPacketsRx, wifiPacketsTx, |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 3052 | mobileActiveTime, mobileActiveCount, |
| 3053 | btBytesRx, btBytesTx); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 3054 | } |
| 3055 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3056 | // Dump modem controller data, per UID. |
| 3057 | dumpControllerActivityLine(pw, uid, category, MODEM_CONTROLLER_DATA, |
| 3058 | u.getModemControllerActivity(), which); |
| 3059 | |
| 3060 | // Dump Wifi controller data, per UID. |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 3061 | final long fullWifiLockOnTime = u.getFullWifiLockTime(rawRealtime, which); |
| 3062 | final long wifiScanTime = u.getWifiScanTime(rawRealtime, which); |
| 3063 | final int wifiScanCount = u.getWifiScanCount(which); |
| 3064 | final long uidWifiRunningTime = u.getWifiRunningTime(rawRealtime, which); |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 3065 | if (fullWifiLockOnTime != 0 || wifiScanTime != 0 || wifiScanCount != 0 |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3066 | || uidWifiRunningTime != 0) { |
| 3067 | dumpLine(pw, uid, category, WIFI_DATA, fullWifiLockOnTime, wifiScanTime, |
| 3068 | uidWifiRunningTime, wifiScanCount, |
| 3069 | /* legacy fields follow, keep at 0 */ 0, 0, 0, 0); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3070 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3071 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3072 | dumpControllerActivityLine(pw, uid, category, WIFI_CONTROLLER_DATA, |
| 3073 | u.getWifiControllerActivity(), which); |
| 3074 | |
Adam Lesinski | d9b99be | 2016-03-30 16:58:51 -0700 | [diff] [blame^] | 3075 | // Dump Bluetooth scan data, per UID. |
| 3076 | final long bleScanTimeUs = u.getBluetoothScanTimer().getTotalTimeLocked( |
| 3077 | rawRealtime, which); |
| 3078 | final int bleScanCount = u.getBluetoothScanTimer().getCountLocked(which); |
| 3079 | if (bleScanTimeUs != 0 || bleScanCount != 0) { |
| 3080 | dumpLine(pw, uid, category, BLUETOOTH_MISC_DATA, |
| 3081 | bleScanTimeUs / 1000, bleScanCount); |
| 3082 | } |
| 3083 | |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 3084 | dumpControllerActivityLine(pw, uid, category, BLUETOOTH_CONTROLLER_DATA, |
| 3085 | u.getBluetoothControllerActivity(), which); |
| 3086 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3087 | if (u.hasUserActivity()) { |
| 3088 | args = new Object[Uid.NUM_USER_ACTIVITY_TYPES]; |
| 3089 | boolean hasData = false; |
| 3090 | for (int i=0; i<Uid.NUM_USER_ACTIVITY_TYPES; i++) { |
| 3091 | int val = u.getUserActivityCount(i, which); |
| 3092 | args[i] = val; |
| 3093 | if (val != 0) hasData = true; |
| 3094 | } |
| 3095 | if (hasData) { |
Ashish Sharma | cba1215 | 2014-07-07 17:14:52 -0700 | [diff] [blame] | 3096 | dumpLine(pw, uid /* uid */, category, USER_ACTIVITY_DATA, args); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3097 | } |
| 3098 | } |
| 3099 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3100 | final ArrayMap<String, ? extends Uid.Wakelock> wakelocks = u.getWakelockStats(); |
| 3101 | for (int iw=wakelocks.size()-1; iw>=0; iw--) { |
| 3102 | final Uid.Wakelock wl = wakelocks.valueAt(iw); |
| 3103 | String linePrefix = ""; |
| 3104 | sb.setLength(0); |
| 3105 | linePrefix = printWakeLockCheckin(sb, wl.getWakeTime(WAKE_TYPE_FULL), |
| 3106 | rawRealtime, "f", which, linePrefix); |
| 3107 | linePrefix = printWakeLockCheckin(sb, wl.getWakeTime(WAKE_TYPE_PARTIAL), |
| 3108 | rawRealtime, "p", which, linePrefix); |
| 3109 | linePrefix = printWakeLockCheckin(sb, wl.getWakeTime(WAKE_TYPE_WINDOW), |
| 3110 | rawRealtime, "w", which, linePrefix); |
| 3111 | |
| 3112 | // Only log if we had at lease one wakelock... |
| 3113 | if (sb.length() > 0) { |
| 3114 | String name = wakelocks.keyAt(iw); |
| 3115 | if (name.indexOf(',') >= 0) { |
| 3116 | name = name.replace(',', '_'); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3117 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3118 | dumpLine(pw, uid, category, WAKELOCK_DATA, name, sb.toString()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3119 | } |
| 3120 | } |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 3121 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3122 | final ArrayMap<String, ? extends Timer> syncs = u.getSyncStats(); |
| 3123 | for (int isy=syncs.size()-1; isy>=0; isy--) { |
| 3124 | final Timer timer = syncs.valueAt(isy); |
| 3125 | // Convert from microseconds to milliseconds with rounding |
| 3126 | final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000; |
| 3127 | final int count = timer.getCountLocked(which); |
| 3128 | if (totalTime != 0) { |
| 3129 | dumpLine(pw, uid, category, SYNC_DATA, syncs.keyAt(isy), totalTime, count); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 3130 | } |
| 3131 | } |
| 3132 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3133 | final ArrayMap<String, ? extends Timer> jobs = u.getJobStats(); |
| 3134 | for (int ij=jobs.size()-1; ij>=0; ij--) { |
| 3135 | final Timer timer = jobs.valueAt(ij); |
| 3136 | // Convert from microseconds to milliseconds with rounding |
| 3137 | final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000; |
| 3138 | final int count = timer.getCountLocked(which); |
| 3139 | if (totalTime != 0) { |
| 3140 | dumpLine(pw, uid, category, JOB_DATA, jobs.keyAt(ij), totalTime, count); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 3141 | } |
| 3142 | } |
| 3143 | |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 3144 | dumpTimer(pw, uid, category, FLASHLIGHT_DATA, u.getFlashlightTurnedOnTimer(), |
| 3145 | rawRealtime, which); |
| 3146 | dumpTimer(pw, uid, category, CAMERA_DATA, u.getCameraTurnedOnTimer(), |
| 3147 | rawRealtime, which); |
| 3148 | dumpTimer(pw, uid, category, VIDEO_DATA, u.getVideoTurnedOnTimer(), |
| 3149 | rawRealtime, which); |
| 3150 | dumpTimer(pw, uid, category, AUDIO_DATA, u.getAudioTurnedOnTimer(), |
| 3151 | rawRealtime, which); |
| 3152 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3153 | final SparseArray<? extends BatteryStats.Uid.Sensor> sensors = u.getSensorStats(); |
| 3154 | final int NSE = sensors.size(); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 3155 | for (int ise=0; ise<NSE; ise++) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3156 | final Uid.Sensor se = sensors.valueAt(ise); |
| 3157 | final int sensorNumber = sensors.keyAt(ise); |
| 3158 | final Timer timer = se.getSensorTime(); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 3159 | if (timer != null) { |
| 3160 | // Convert from microseconds to milliseconds with rounding |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3161 | final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) |
| 3162 | / 1000; |
| 3163 | final int count = timer.getCountLocked(which); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 3164 | if (totalTime != 0) { |
| 3165 | dumpLine(pw, uid, category, SENSOR_DATA, sensorNumber, totalTime, count); |
| 3166 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3167 | } |
| 3168 | } |
| 3169 | |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 3170 | dumpTimer(pw, uid, category, VIBRATOR_DATA, u.getVibratorOnTimer(), |
| 3171 | rawRealtime, which); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 3172 | |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 3173 | dumpTimer(pw, uid, category, FOREGROUND_DATA, u.getForegroundActivityTimer(), |
| 3174 | rawRealtime, which); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 3175 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3176 | final Object[] stateTimes = new Object[Uid.NUM_PROCESS_STATE]; |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 3177 | long totalStateTime = 0; |
| 3178 | for (int ips=0; ips<Uid.NUM_PROCESS_STATE; ips++) { |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 3179 | final long time = u.getProcessStateTime(ips, rawRealtime, which); |
| 3180 | totalStateTime += time; |
| 3181 | stateTimes[ips] = (time + 500) / 1000; |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 3182 | } |
| 3183 | if (totalStateTime > 0) { |
| 3184 | dumpLine(pw, uid, category, STATE_TIME_DATA, stateTimes); |
| 3185 | } |
| 3186 | |
Adam Lesinski | a7a4ccc | 2015-06-26 17:43:04 -0700 | [diff] [blame] | 3187 | final long userCpuTimeUs = u.getUserCpuTimeUs(which); |
| 3188 | final long systemCpuTimeUs = u.getSystemCpuTimeUs(which); |
| 3189 | final long powerCpuMaUs = u.getCpuPowerMaUs(which); |
| 3190 | if (userCpuTimeUs > 0 || systemCpuTimeUs > 0 || powerCpuMaUs > 0) { |
| 3191 | dumpLine(pw, uid, category, CPU_DATA, userCpuTimeUs / 1000, systemCpuTimeUs / 1000, |
| 3192 | powerCpuMaUs / 1000); |
| 3193 | } |
| 3194 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3195 | final ArrayMap<String, ? extends BatteryStats.Uid.Proc> processStats |
| 3196 | = u.getProcessStats(); |
| 3197 | for (int ipr=processStats.size()-1; ipr>=0; ipr--) { |
| 3198 | final Uid.Proc ps = processStats.valueAt(ipr); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 3199 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3200 | final long userMillis = ps.getUserTime(which); |
| 3201 | final long systemMillis = ps.getSystemTime(which); |
| 3202 | final long foregroundMillis = ps.getForegroundTime(which); |
| 3203 | final int starts = ps.getStarts(which); |
| 3204 | final int numCrashes = ps.getNumCrashes(which); |
| 3205 | final int numAnrs = ps.getNumAnrs(which); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 3206 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3207 | if (userMillis != 0 || systemMillis != 0 || foregroundMillis != 0 |
| 3208 | || starts != 0 || numAnrs != 0 || numCrashes != 0) { |
| 3209 | dumpLine(pw, uid, category, PROCESS_DATA, processStats.keyAt(ipr), userMillis, |
| 3210 | systemMillis, foregroundMillis, starts, numAnrs, numCrashes); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3211 | } |
| 3212 | } |
| 3213 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3214 | final ArrayMap<String, ? extends BatteryStats.Uid.Pkg> packageStats |
| 3215 | = u.getPackageStats(); |
| 3216 | for (int ipkg=packageStats.size()-1; ipkg>=0; ipkg--) { |
| 3217 | final Uid.Pkg ps = packageStats.valueAt(ipkg); |
| 3218 | int wakeups = 0; |
| 3219 | final ArrayMap<String, ? extends Counter> alarms = ps.getWakeupAlarmStats(); |
| 3220 | for (int iwa=alarms.size()-1; iwa>=0; iwa--) { |
| 3221 | wakeups += alarms.valueAt(iwa).getCountLocked(which); |
| 3222 | } |
| 3223 | final ArrayMap<String, ? extends Uid.Pkg.Serv> serviceStats = ps.getServiceStats(); |
| 3224 | for (int isvc=serviceStats.size()-1; isvc>=0; isvc--) { |
| 3225 | final BatteryStats.Uid.Pkg.Serv ss = serviceStats.valueAt(isvc); |
| 3226 | final long startTime = ss.getStartTime(batteryUptime, which); |
| 3227 | final int starts = ss.getStarts(which); |
| 3228 | final int launches = ss.getLaunches(which); |
| 3229 | if (startTime != 0 || starts != 0 || launches != 0) { |
| 3230 | dumpLine(pw, uid, category, APK_DATA, |
| 3231 | wakeups, // wakeup alarms |
| 3232 | packageStats.keyAt(ipkg), // Apk |
| 3233 | serviceStats.keyAt(isvc), // service |
| 3234 | startTime / 1000, // time spent started, in ms |
| 3235 | starts, |
| 3236 | launches); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3237 | } |
| 3238 | } |
| 3239 | } |
| 3240 | } |
| 3241 | } |
| 3242 | |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 3243 | static final class TimerEntry { |
| 3244 | final String mName; |
| 3245 | final int mId; |
| 3246 | final BatteryStats.Timer mTimer; |
| 3247 | final long mTime; |
| 3248 | TimerEntry(String name, int id, BatteryStats.Timer timer, long time) { |
| 3249 | mName = name; |
| 3250 | mId = id; |
| 3251 | mTimer = timer; |
| 3252 | mTime = time; |
| 3253 | } |
| 3254 | } |
| 3255 | |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3256 | private void printmAh(PrintWriter printer, double power) { |
| 3257 | printer.print(BatteryStatsHelper.makemAh(power)); |
| 3258 | } |
| 3259 | |
Adam Lesinski | a7a4ccc | 2015-06-26 17:43:04 -0700 | [diff] [blame] | 3260 | private void printmAh(StringBuilder sb, double power) { |
| 3261 | sb.append(BatteryStatsHelper.makemAh(power)); |
| 3262 | } |
| 3263 | |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 3264 | /** |
| 3265 | * Temporary for settings. |
| 3266 | */ |
| 3267 | public final void dumpLocked(Context context, PrintWriter pw, String prefix, int which, |
| 3268 | int reqUid) { |
| 3269 | dumpLocked(context, pw, prefix, which, reqUid, BatteryStatsHelper.checkWifiOnly(context)); |
| 3270 | } |
| 3271 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3272 | @SuppressWarnings("unused") |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3273 | 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] | 3274 | int reqUid, boolean wifiOnly) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3275 | final long rawUptime = SystemClock.uptimeMillis() * 1000; |
| 3276 | final long rawRealtime = SystemClock.elapsedRealtime() * 1000; |
| 3277 | final long batteryUptime = getBatteryUptime(rawUptime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3278 | |
| 3279 | final long whichBatteryUptime = computeBatteryUptime(rawUptime, which); |
| 3280 | final long whichBatteryRealtime = computeBatteryRealtime(rawRealtime, which); |
| 3281 | final long totalRealtime = computeRealtime(rawRealtime, which); |
| 3282 | final long totalUptime = computeUptime(rawUptime, which); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3283 | final long whichBatteryScreenOffUptime = computeBatteryScreenOffUptime(rawUptime, which); |
| 3284 | final long whichBatteryScreenOffRealtime = computeBatteryScreenOffRealtime(rawRealtime, |
| 3285 | which); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 3286 | final long batteryTimeRemaining = computeBatteryTimeRemaining(rawRealtime); |
| 3287 | final long chargeTimeRemaining = computeChargeTimeRemaining(rawRealtime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3288 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3289 | final StringBuilder sb = new StringBuilder(128); |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 3290 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3291 | final SparseArray<? extends Uid> uidStats = getUidStats(); |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 3292 | final int NU = uidStats.size(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3293 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3294 | sb.setLength(0); |
| 3295 | sb.append(prefix); |
| 3296 | sb.append(" Time on battery: "); |
| 3297 | formatTimeMs(sb, whichBatteryRealtime / 1000); sb.append("("); |
| 3298 | sb.append(formatRatioLocked(whichBatteryRealtime, totalRealtime)); |
| 3299 | sb.append(") realtime, "); |
| 3300 | formatTimeMs(sb, whichBatteryUptime / 1000); |
| 3301 | sb.append("("); sb.append(formatRatioLocked(whichBatteryUptime, totalRealtime)); |
| 3302 | sb.append(") uptime"); |
| 3303 | pw.println(sb.toString()); |
| 3304 | sb.setLength(0); |
| 3305 | sb.append(prefix); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3306 | sb.append(" Time on battery screen off: "); |
| 3307 | formatTimeMs(sb, whichBatteryScreenOffRealtime / 1000); sb.append("("); |
| 3308 | sb.append(formatRatioLocked(whichBatteryScreenOffRealtime, totalRealtime)); |
| 3309 | sb.append(") realtime, "); |
| 3310 | formatTimeMs(sb, whichBatteryScreenOffUptime / 1000); |
| 3311 | sb.append("("); |
| 3312 | sb.append(formatRatioLocked(whichBatteryScreenOffUptime, totalRealtime)); |
| 3313 | sb.append(") uptime"); |
| 3314 | pw.println(sb.toString()); |
| 3315 | sb.setLength(0); |
| 3316 | sb.append(prefix); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3317 | sb.append(" Total run time: "); |
| 3318 | formatTimeMs(sb, totalRealtime / 1000); |
| 3319 | sb.append("realtime, "); |
| 3320 | formatTimeMs(sb, totalUptime / 1000); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 3321 | sb.append("uptime"); |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 3322 | pw.println(sb.toString()); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 3323 | if (batteryTimeRemaining >= 0) { |
| 3324 | sb.setLength(0); |
| 3325 | sb.append(prefix); |
| 3326 | sb.append(" Battery time remaining: "); |
| 3327 | formatTimeMs(sb, batteryTimeRemaining / 1000); |
| 3328 | pw.println(sb.toString()); |
| 3329 | } |
| 3330 | if (chargeTimeRemaining >= 0) { |
| 3331 | sb.setLength(0); |
| 3332 | sb.append(prefix); |
| 3333 | sb.append(" Charge time remaining: "); |
| 3334 | formatTimeMs(sb, chargeTimeRemaining / 1000); |
| 3335 | pw.println(sb.toString()); |
| 3336 | } |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 3337 | pw.print(" Start clock time: "); |
| 3338 | pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss", getStartClockTime()).toString()); |
| 3339 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3340 | final long screenOnTime = getScreenOnTime(rawRealtime, which); |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 3341 | final long interactiveTime = getInteractiveTime(rawRealtime, which); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3342 | final long powerSaveModeEnabledTime = getPowerSaveModeEnabledTime(rawRealtime, which); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3343 | final long deviceIdleModeLightTime = getDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT, |
| 3344 | rawRealtime, which); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 3345 | final long deviceIdleModeFullTime = getDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP, |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3346 | rawRealtime, which); |
| 3347 | final long deviceLightIdlingTime = getDeviceIdlingTime(DEVICE_IDLE_MODE_LIGHT, |
| 3348 | rawRealtime, which); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 3349 | final long deviceIdlingTime = getDeviceIdlingTime(DEVICE_IDLE_MODE_DEEP, |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3350 | rawRealtime, which); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3351 | final long phoneOnTime = getPhoneOnTime(rawRealtime, which); |
| 3352 | final long wifiRunningTime = getGlobalWifiRunningTime(rawRealtime, which); |
| 3353 | final long wifiOnTime = getWifiOnTime(rawRealtime, which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3354 | sb.setLength(0); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3355 | sb.append(prefix); |
| 3356 | sb.append(" Screen on: "); formatTimeMs(sb, screenOnTime / 1000); |
| 3357 | sb.append("("); sb.append(formatRatioLocked(screenOnTime, whichBatteryRealtime)); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 3358 | sb.append(") "); sb.append(getScreenOnCount(which)); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3359 | sb.append("x, Interactive: "); formatTimeMs(sb, interactiveTime / 1000); |
| 3360 | sb.append("("); sb.append(formatRatioLocked(interactiveTime, whichBatteryRealtime)); |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 3361 | sb.append(")"); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3362 | pw.println(sb.toString()); |
| 3363 | sb.setLength(0); |
| 3364 | sb.append(prefix); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 3365 | sb.append(" Screen brightnesses:"); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3366 | boolean didOne = false; |
| 3367 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3368 | final long time = getScreenBrightnessTime(i, rawRealtime, which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3369 | if (time == 0) { |
| 3370 | continue; |
| 3371 | } |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 3372 | sb.append("\n "); |
| 3373 | sb.append(prefix); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3374 | didOne = true; |
| 3375 | sb.append(SCREEN_BRIGHTNESS_NAMES[i]); |
| 3376 | sb.append(" "); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3377 | formatTimeMs(sb, time/1000); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3378 | sb.append("("); |
| 3379 | sb.append(formatRatioLocked(time, screenOnTime)); |
| 3380 | sb.append(")"); |
| 3381 | } |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 3382 | if (!didOne) sb.append(" (no activity)"); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3383 | pw.println(sb.toString()); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3384 | if (powerSaveModeEnabledTime != 0) { |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3385 | sb.setLength(0); |
| 3386 | sb.append(prefix); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3387 | sb.append(" Power save mode enabled: "); |
| 3388 | formatTimeMs(sb, powerSaveModeEnabledTime / 1000); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3389 | sb.append("("); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3390 | sb.append(formatRatioLocked(powerSaveModeEnabledTime, whichBatteryRealtime)); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3391 | sb.append(")"); |
| 3392 | pw.println(sb.toString()); |
| 3393 | } |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3394 | if (deviceLightIdlingTime != 0) { |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3395 | sb.setLength(0); |
| 3396 | sb.append(prefix); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3397 | sb.append(" Device light idling: "); |
| 3398 | formatTimeMs(sb, deviceLightIdlingTime / 1000); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 3399 | sb.append("("); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3400 | sb.append(formatRatioLocked(deviceLightIdlingTime, whichBatteryRealtime)); |
| 3401 | sb.append(") "); sb.append(getDeviceIdlingCount(DEVICE_IDLE_MODE_LIGHT, which)); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 3402 | sb.append("x"); |
| 3403 | pw.println(sb.toString()); |
| 3404 | } |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3405 | if (deviceIdleModeLightTime != 0) { |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 3406 | sb.setLength(0); |
| 3407 | sb.append(prefix); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3408 | sb.append(" Idle mode light time: "); |
| 3409 | formatTimeMs(sb, deviceIdleModeLightTime / 1000); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3410 | sb.append("("); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3411 | sb.append(formatRatioLocked(deviceIdleModeLightTime, whichBatteryRealtime)); |
| 3412 | sb.append(") "); |
| 3413 | sb.append(getDeviceIdleModeCount(DEVICE_IDLE_MODE_LIGHT, which)); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3414 | sb.append("x"); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3415 | sb.append(" -- longest "); |
| 3416 | formatTimeMs(sb, getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT)); |
| 3417 | pw.println(sb.toString()); |
| 3418 | } |
| 3419 | if (deviceIdlingTime != 0) { |
| 3420 | sb.setLength(0); |
| 3421 | sb.append(prefix); |
| 3422 | sb.append(" Device full idling: "); |
| 3423 | formatTimeMs(sb, deviceIdlingTime / 1000); |
| 3424 | sb.append("("); |
| 3425 | sb.append(formatRatioLocked(deviceIdlingTime, whichBatteryRealtime)); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 3426 | sb.append(") "); sb.append(getDeviceIdlingCount(DEVICE_IDLE_MODE_DEEP, which)); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3427 | sb.append("x"); |
| 3428 | pw.println(sb.toString()); |
| 3429 | } |
| 3430 | if (deviceIdleModeFullTime != 0) { |
| 3431 | sb.setLength(0); |
| 3432 | sb.append(prefix); |
| 3433 | sb.append(" Idle mode full time: "); |
| 3434 | formatTimeMs(sb, deviceIdleModeFullTime / 1000); |
| 3435 | sb.append("("); |
| 3436 | sb.append(formatRatioLocked(deviceIdleModeFullTime, whichBatteryRealtime)); |
| 3437 | sb.append(") "); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 3438 | sb.append(getDeviceIdleModeCount(DEVICE_IDLE_MODE_DEEP, which)); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3439 | sb.append("x"); |
| 3440 | sb.append(" -- longest "); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 3441 | formatTimeMs(sb, getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP)); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3442 | pw.println(sb.toString()); |
| 3443 | } |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3444 | if (phoneOnTime != 0) { |
| 3445 | sb.setLength(0); |
| 3446 | sb.append(prefix); |
| 3447 | sb.append(" Active phone call: "); formatTimeMs(sb, phoneOnTime / 1000); |
| 3448 | sb.append("("); sb.append(formatRatioLocked(phoneOnTime, whichBatteryRealtime)); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3449 | sb.append(") "); sb.append(getPhoneOnCount(which)); sb.append("x"); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3450 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3451 | final int connChanges = getNumConnectivityChange(which); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 3452 | if (connChanges != 0) { |
| 3453 | pw.print(prefix); |
| 3454 | pw.print(" Connectivity changes: "); pw.println(connChanges); |
| 3455 | } |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3456 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3457 | // Calculate wakelock times across all uids. |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 3458 | long fullWakeLockTimeTotalMicros = 0; |
| 3459 | long partialWakeLockTimeTotalMicros = 0; |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 3460 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3461 | final ArrayList<TimerEntry> timers = new ArrayList<>(); |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 3462 | |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 3463 | for (int iu = 0; iu < NU; iu++) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3464 | final Uid u = uidStats.valueAt(iu); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 3465 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3466 | final ArrayMap<String, ? extends BatteryStats.Uid.Wakelock> wakelocks |
| 3467 | = u.getWakelockStats(); |
| 3468 | for (int iw=wakelocks.size()-1; iw>=0; iw--) { |
| 3469 | final Uid.Wakelock wl = wakelocks.valueAt(iw); |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 3470 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3471 | final Timer fullWakeTimer = wl.getWakeTime(WAKE_TYPE_FULL); |
| 3472 | if (fullWakeTimer != null) { |
| 3473 | fullWakeLockTimeTotalMicros += fullWakeTimer.getTotalTimeLocked( |
| 3474 | rawRealtime, which); |
| 3475 | } |
| 3476 | |
| 3477 | final Timer partialWakeTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL); |
| 3478 | if (partialWakeTimer != null) { |
| 3479 | final long totalTimeMicros = partialWakeTimer.getTotalTimeLocked( |
| 3480 | rawRealtime, which); |
| 3481 | if (totalTimeMicros > 0) { |
| 3482 | if (reqUid < 0) { |
| 3483 | // Only show the ordered list of all wake |
| 3484 | // locks if the caller is not asking for data |
| 3485 | // about a specific uid. |
| 3486 | timers.add(new TimerEntry(wakelocks.keyAt(iw), u.getUid(), |
| 3487 | partialWakeTimer, totalTimeMicros)); |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 3488 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3489 | partialWakeLockTimeTotalMicros += totalTimeMicros; |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 3490 | } |
| 3491 | } |
| 3492 | } |
| 3493 | } |
| 3494 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3495 | final long mobileRxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which); |
| 3496 | final long mobileTxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which); |
| 3497 | final long wifiRxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which); |
| 3498 | final long wifiTxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which); |
| 3499 | final long mobileRxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which); |
| 3500 | final long mobileTxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which); |
| 3501 | final long wifiRxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which); |
| 3502 | final long wifiTxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which); |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 3503 | final long btRxTotalBytes = getNetworkActivityBytes(NETWORK_BT_RX_DATA, which); |
| 3504 | final long btTxTotalBytes = getNetworkActivityBytes(NETWORK_BT_TX_DATA, which); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3505 | |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 3506 | if (fullWakeLockTimeTotalMicros != 0) { |
| 3507 | sb.setLength(0); |
| 3508 | sb.append(prefix); |
| 3509 | sb.append(" Total full wakelock time: "); formatTimeMsNoSpace(sb, |
| 3510 | (fullWakeLockTimeTotalMicros + 500) / 1000); |
| 3511 | pw.println(sb.toString()); |
| 3512 | } |
| 3513 | |
| 3514 | if (partialWakeLockTimeTotalMicros != 0) { |
| 3515 | sb.setLength(0); |
| 3516 | sb.append(prefix); |
| 3517 | sb.append(" Total partial wakelock time: "); formatTimeMsNoSpace(sb, |
| 3518 | (partialWakeLockTimeTotalMicros + 500) / 1000); |
| 3519 | pw.println(sb.toString()); |
| 3520 | } |
| 3521 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3522 | pw.print(prefix); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3523 | pw.print(" Mobile total received: "); pw.print(formatBytesLocked(mobileRxTotalBytes)); |
| 3524 | pw.print(", sent: "); pw.print(formatBytesLocked(mobileTxTotalBytes)); |
| 3525 | pw.print(" (packets received "); pw.print(mobileRxTotalPackets); |
| 3526 | pw.print(", sent "); pw.print(mobileTxTotalPackets); pw.println(")"); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3527 | sb.setLength(0); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3528 | sb.append(prefix); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 3529 | sb.append(" Phone signal levels:"); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3530 | didOne = false; |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 3531 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3532 | final long time = getPhoneSignalStrengthTime(i, rawRealtime, which); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3533 | if (time == 0) { |
| 3534 | continue; |
| 3535 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3536 | sb.append("\n "); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 3537 | sb.append(prefix); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3538 | didOne = true; |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 3539 | sb.append(SignalStrength.SIGNAL_STRENGTH_NAMES[i]); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3540 | sb.append(" "); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3541 | formatTimeMs(sb, time/1000); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3542 | sb.append("("); |
| 3543 | sb.append(formatRatioLocked(time, whichBatteryRealtime)); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3544 | sb.append(") "); |
| 3545 | sb.append(getPhoneSignalStrengthCount(i, which)); |
| 3546 | sb.append("x"); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3547 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3548 | if (!didOne) sb.append(" (no activity)"); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3549 | pw.println(sb.toString()); |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 3550 | |
| 3551 | sb.setLength(0); |
| 3552 | sb.append(prefix); |
| 3553 | sb.append(" Signal scanning time: "); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3554 | formatTimeMsNoSpace(sb, getPhoneSignalScanningTime(rawRealtime, which) / 1000); |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 3555 | pw.println(sb.toString()); |
| 3556 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3557 | sb.setLength(0); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3558 | sb.append(prefix); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3559 | sb.append(" Radio types:"); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3560 | didOne = false; |
| 3561 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3562 | final long time = getPhoneDataConnectionTime(i, rawRealtime, which); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3563 | if (time == 0) { |
| 3564 | continue; |
| 3565 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3566 | sb.append("\n "); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 3567 | sb.append(prefix); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3568 | didOne = true; |
| 3569 | sb.append(DATA_CONNECTION_NAMES[i]); |
| 3570 | sb.append(" "); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3571 | formatTimeMs(sb, time/1000); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3572 | sb.append("("); |
| 3573 | sb.append(formatRatioLocked(time, whichBatteryRealtime)); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3574 | sb.append(") "); |
| 3575 | sb.append(getPhoneDataConnectionCount(i, which)); |
| 3576 | sb.append("x"); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3577 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3578 | if (!didOne) sb.append(" (no activity)"); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3579 | pw.println(sb.toString()); |
Amith Yamasani | 3f7e35c | 2009-07-13 16:02:45 -0700 | [diff] [blame] | 3580 | |
| 3581 | sb.setLength(0); |
| 3582 | sb.append(prefix); |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 3583 | sb.append(" Mobile radio active time: "); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3584 | final long mobileActiveTime = getMobileRadioActiveTime(rawRealtime, which); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 3585 | formatTimeMs(sb, mobileActiveTime / 1000); |
| 3586 | sb.append("("); sb.append(formatRatioLocked(mobileActiveTime, whichBatteryRealtime)); |
| 3587 | sb.append(") "); sb.append(getMobileRadioActiveCount(which)); |
| 3588 | sb.append("x"); |
Amith Yamasani | 3f7e35c | 2009-07-13 16:02:45 -0700 | [diff] [blame] | 3589 | pw.println(sb.toString()); |
| 3590 | |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 3591 | final long mobileActiveUnknownTime = getMobileRadioActiveUnknownTime(which); |
| 3592 | if (mobileActiveUnknownTime != 0) { |
| 3593 | sb.setLength(0); |
| 3594 | sb.append(prefix); |
| 3595 | sb.append(" Mobile radio active unknown time: "); |
| 3596 | formatTimeMs(sb, mobileActiveUnknownTime / 1000); |
| 3597 | sb.append("("); |
| 3598 | sb.append(formatRatioLocked(mobileActiveUnknownTime, whichBatteryRealtime)); |
| 3599 | sb.append(") "); sb.append(getMobileRadioActiveUnknownCount(which)); |
| 3600 | sb.append("x"); |
| 3601 | pw.println(sb.toString()); |
| 3602 | } |
| 3603 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3604 | final long mobileActiveAdjustedTime = getMobileRadioActiveAdjustedTime(which); |
| 3605 | if (mobileActiveAdjustedTime != 0) { |
| 3606 | sb.setLength(0); |
| 3607 | sb.append(prefix); |
| 3608 | sb.append(" Mobile radio active adjusted time: "); |
| 3609 | formatTimeMs(sb, mobileActiveAdjustedTime / 1000); |
| 3610 | sb.append("("); |
| 3611 | sb.append(formatRatioLocked(mobileActiveAdjustedTime, whichBatteryRealtime)); |
| 3612 | sb.append(")"); |
| 3613 | pw.println(sb.toString()); |
| 3614 | } |
| 3615 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3616 | printControllerActivity(pw, sb, prefix, "Radio", getModemControllerActivity(), which); |
| 3617 | |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 3618 | pw.print(prefix); |
| 3619 | pw.print(" Wi-Fi total received: "); pw.print(formatBytesLocked(wifiRxTotalBytes)); |
| 3620 | pw.print(", sent: "); pw.print(formatBytesLocked(wifiTxTotalBytes)); |
| 3621 | pw.print(" (packets received "); pw.print(wifiRxTotalPackets); |
| 3622 | pw.print(", sent "); pw.print(wifiTxTotalPackets); pw.println(")"); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3623 | sb.setLength(0); |
| 3624 | sb.append(prefix); |
| 3625 | sb.append(" Wifi on: "); formatTimeMs(sb, wifiOnTime / 1000); |
| 3626 | sb.append("("); sb.append(formatRatioLocked(wifiOnTime, whichBatteryRealtime)); |
| 3627 | sb.append("), Wifi running: "); formatTimeMs(sb, wifiRunningTime / 1000); |
| 3628 | sb.append("("); sb.append(formatRatioLocked(wifiRunningTime, whichBatteryRealtime)); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3629 | sb.append(")"); |
| 3630 | pw.println(sb.toString()); |
| 3631 | |
| 3632 | sb.setLength(0); |
| 3633 | sb.append(prefix); |
| 3634 | sb.append(" Wifi states:"); |
| 3635 | didOne = false; |
| 3636 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3637 | final long time = getWifiStateTime(i, rawRealtime, which); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3638 | if (time == 0) { |
| 3639 | continue; |
| 3640 | } |
| 3641 | sb.append("\n "); |
| 3642 | didOne = true; |
| 3643 | sb.append(WIFI_STATE_NAMES[i]); |
| 3644 | sb.append(" "); |
| 3645 | formatTimeMs(sb, time/1000); |
| 3646 | sb.append("("); |
| 3647 | sb.append(formatRatioLocked(time, whichBatteryRealtime)); |
| 3648 | sb.append(") "); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 3649 | sb.append(getWifiStateCount(i, which)); |
| 3650 | sb.append("x"); |
| 3651 | } |
| 3652 | if (!didOne) sb.append(" (no activity)"); |
| 3653 | pw.println(sb.toString()); |
| 3654 | |
| 3655 | sb.setLength(0); |
| 3656 | sb.append(prefix); |
| 3657 | sb.append(" Wifi supplicant states:"); |
| 3658 | didOne = false; |
| 3659 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
| 3660 | final long time = getWifiSupplStateTime(i, rawRealtime, which); |
| 3661 | if (time == 0) { |
| 3662 | continue; |
| 3663 | } |
| 3664 | sb.append("\n "); |
| 3665 | didOne = true; |
| 3666 | sb.append(WIFI_SUPPL_STATE_NAMES[i]); |
| 3667 | sb.append(" "); |
| 3668 | formatTimeMs(sb, time/1000); |
| 3669 | sb.append("("); |
| 3670 | sb.append(formatRatioLocked(time, whichBatteryRealtime)); |
| 3671 | sb.append(") "); |
| 3672 | sb.append(getWifiSupplStateCount(i, which)); |
| 3673 | sb.append("x"); |
| 3674 | } |
| 3675 | if (!didOne) sb.append(" (no activity)"); |
| 3676 | pw.println(sb.toString()); |
| 3677 | |
| 3678 | sb.setLength(0); |
| 3679 | sb.append(prefix); |
| 3680 | sb.append(" Wifi signal levels:"); |
| 3681 | didOne = false; |
| 3682 | for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 3683 | final long time = getWifiSignalStrengthTime(i, rawRealtime, which); |
| 3684 | if (time == 0) { |
| 3685 | continue; |
| 3686 | } |
| 3687 | sb.append("\n "); |
| 3688 | sb.append(prefix); |
| 3689 | didOne = true; |
| 3690 | sb.append("level("); |
| 3691 | sb.append(i); |
| 3692 | sb.append(") "); |
| 3693 | formatTimeMs(sb, time/1000); |
| 3694 | sb.append("("); |
| 3695 | sb.append(formatRatioLocked(time, whichBatteryRealtime)); |
| 3696 | sb.append(") "); |
| 3697 | sb.append(getWifiSignalStrengthCount(i, which)); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3698 | sb.append("x"); |
| 3699 | } |
| 3700 | if (!didOne) sb.append(" (no activity)"); |
| 3701 | pw.println(sb.toString()); |
| 3702 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3703 | printControllerActivity(pw, sb, prefix, "WiFi", getWifiControllerActivity(), which); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 3704 | |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 3705 | pw.print(prefix); |
| 3706 | pw.print(" Bluetooth total received: "); pw.print(formatBytesLocked(btRxTotalBytes)); |
| 3707 | pw.print(", sent: "); pw.println(formatBytesLocked(btTxTotalBytes)); |
| 3708 | |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 3709 | final long bluetoothScanTimeMs = getBluetoothScanTime(rawRealtime, which) / 1000; |
| 3710 | sb.setLength(0); |
| 3711 | sb.append(prefix); |
| 3712 | sb.append(" Bluetooth scan time: "); formatTimeMs(sb, bluetoothScanTimeMs); |
| 3713 | pw.println(sb.toString()); |
| 3714 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3715 | printControllerActivity(pw, sb, prefix, "Bluetooth", getBluetoothControllerActivity(), |
| 3716 | which); |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 3717 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3718 | pw.println(); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3719 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3720 | if (which == STATS_SINCE_UNPLUGGED) { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3721 | if (getIsOnBattery()) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3722 | pw.print(prefix); pw.println(" Device is currently unplugged"); |
| 3723 | pw.print(prefix); pw.print(" Discharge cycle start level: "); |
| 3724 | pw.println(getDischargeStartLevel()); |
| 3725 | pw.print(prefix); pw.print(" Discharge cycle current level: "); |
| 3726 | pw.println(getDischargeCurrentLevel()); |
Dianne Hackborn | 99d0452 | 2010-08-20 13:43:00 -0700 | [diff] [blame] | 3727 | } else { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3728 | pw.print(prefix); pw.println(" Device is currently plugged into power"); |
| 3729 | pw.print(prefix); pw.print(" Last discharge cycle start level: "); |
| 3730 | pw.println(getDischargeStartLevel()); |
| 3731 | pw.print(prefix); pw.print(" Last discharge cycle end level: "); |
| 3732 | pw.println(getDischargeCurrentLevel()); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3733 | } |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 3734 | pw.print(prefix); pw.print(" Amount discharged while screen on: "); |
| 3735 | pw.println(getDischargeAmountScreenOn()); |
| 3736 | pw.print(prefix); pw.print(" Amount discharged while screen off: "); |
| 3737 | pw.println(getDischargeAmountScreenOff()); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3738 | pw.println(" "); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3739 | } else { |
| 3740 | pw.print(prefix); pw.println(" Device battery use since last full charge"); |
| 3741 | pw.print(prefix); pw.print(" Amount discharged (lower bound): "); |
| 3742 | pw.println(getLowDischargeAmountSinceCharge()); |
| 3743 | pw.print(prefix); pw.print(" Amount discharged (upper bound): "); |
| 3744 | pw.println(getHighDischargeAmountSinceCharge()); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 3745 | pw.print(prefix); pw.print(" Amount discharged while screen on: "); |
| 3746 | pw.println(getDischargeAmountScreenOnSinceCharge()); |
| 3747 | pw.print(prefix); pw.print(" Amount discharged while screen off: "); |
| 3748 | pw.println(getDischargeAmountScreenOffSinceCharge()); |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 3749 | pw.println(); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3750 | } |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 3751 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3752 | final BatteryStatsHelper helper = new BatteryStatsHelper(context, false, wifiOnly); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3753 | helper.create(this); |
| 3754 | helper.refreshStats(which, UserHandle.USER_ALL); |
| 3755 | List<BatterySipper> sippers = helper.getUsageList(); |
| 3756 | if (sippers != null && sippers.size() > 0) { |
| 3757 | pw.print(prefix); pw.println(" Estimated power use (mAh):"); |
| 3758 | pw.print(prefix); pw.print(" Capacity: "); |
| 3759 | printmAh(pw, helper.getPowerProfile().getBatteryCapacity()); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3760 | pw.print(", Computed drain: "); printmAh(pw, helper.getComputedPower()); |
Dianne Hackborn | 536456f | 2014-05-23 16:51:05 -0700 | [diff] [blame] | 3761 | pw.print(", actual drain: "); printmAh(pw, helper.getMinDrainedPower()); |
| 3762 | if (helper.getMinDrainedPower() != helper.getMaxDrainedPower()) { |
| 3763 | pw.print("-"); printmAh(pw, helper.getMaxDrainedPower()); |
| 3764 | } |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3765 | pw.println(); |
| 3766 | for (int i=0; i<sippers.size(); i++) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3767 | final BatterySipper bs = sippers.get(i); |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 3768 | pw.print(prefix); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3769 | switch (bs.drainType) { |
| 3770 | case IDLE: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 3771 | pw.print(" Idle: "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3772 | break; |
| 3773 | case CELL: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 3774 | pw.print(" Cell standby: "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3775 | break; |
| 3776 | case PHONE: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 3777 | pw.print(" Phone calls: "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3778 | break; |
| 3779 | case WIFI: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 3780 | pw.print(" Wifi: "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3781 | break; |
| 3782 | case BLUETOOTH: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 3783 | pw.print(" Bluetooth: "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3784 | break; |
| 3785 | case SCREEN: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 3786 | pw.print(" Screen: "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3787 | break; |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 3788 | case FLASHLIGHT: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 3789 | pw.print(" Flashlight: "); |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 3790 | break; |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3791 | case APP: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 3792 | pw.print(" Uid "); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 3793 | UserHandle.formatUid(pw, bs.uidObj.getUid()); |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 3794 | pw.print(": "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3795 | break; |
| 3796 | case USER: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 3797 | pw.print(" User "); pw.print(bs.userId); |
| 3798 | pw.print(": "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3799 | break; |
| 3800 | case UNACCOUNTED: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 3801 | pw.print(" Unaccounted: "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3802 | break; |
| 3803 | case OVERCOUNTED: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 3804 | pw.print(" Over-counted: "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3805 | break; |
Ruben Brunk | 5b1308f | 2015-06-03 18:49:27 -0700 | [diff] [blame] | 3806 | case CAMERA: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 3807 | pw.print(" Camera: "); |
| 3808 | break; |
| 3809 | default: |
| 3810 | pw.print(" ???: "); |
Ruben Brunk | 5b1308f | 2015-06-03 18:49:27 -0700 | [diff] [blame] | 3811 | break; |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3812 | } |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 3813 | printmAh(pw, bs.totalPowerMah); |
| 3814 | |
Adam Lesinski | 5712300 | 2015-06-12 16:12:07 -0700 | [diff] [blame] | 3815 | if (bs.usagePowerMah != bs.totalPowerMah) { |
| 3816 | // If the usage (generic power) isn't the whole amount, we list out |
| 3817 | // what components are involved in the calculation. |
| 3818 | |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 3819 | pw.print(" ("); |
Adam Lesinski | 5712300 | 2015-06-12 16:12:07 -0700 | [diff] [blame] | 3820 | if (bs.usagePowerMah != 0) { |
| 3821 | pw.print(" usage="); |
| 3822 | printmAh(pw, bs.usagePowerMah); |
| 3823 | } |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 3824 | if (bs.cpuPowerMah != 0) { |
| 3825 | pw.print(" cpu="); |
| 3826 | printmAh(pw, bs.cpuPowerMah); |
| 3827 | } |
| 3828 | if (bs.wakeLockPowerMah != 0) { |
| 3829 | pw.print(" wake="); |
| 3830 | printmAh(pw, bs.wakeLockPowerMah); |
| 3831 | } |
| 3832 | if (bs.mobileRadioPowerMah != 0) { |
| 3833 | pw.print(" radio="); |
| 3834 | printmAh(pw, bs.mobileRadioPowerMah); |
| 3835 | } |
| 3836 | if (bs.wifiPowerMah != 0) { |
| 3837 | pw.print(" wifi="); |
| 3838 | printmAh(pw, bs.wifiPowerMah); |
| 3839 | } |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 3840 | if (bs.bluetoothPowerMah != 0) { |
| 3841 | pw.print(" bt="); |
| 3842 | printmAh(pw, bs.bluetoothPowerMah); |
| 3843 | } |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 3844 | if (bs.gpsPowerMah != 0) { |
| 3845 | pw.print(" gps="); |
| 3846 | printmAh(pw, bs.gpsPowerMah); |
| 3847 | } |
| 3848 | if (bs.sensorPowerMah != 0) { |
| 3849 | pw.print(" sensor="); |
| 3850 | printmAh(pw, bs.sensorPowerMah); |
| 3851 | } |
| 3852 | if (bs.cameraPowerMah != 0) { |
| 3853 | pw.print(" camera="); |
| 3854 | printmAh(pw, bs.cameraPowerMah); |
| 3855 | } |
| 3856 | if (bs.flashlightPowerMah != 0) { |
| 3857 | pw.print(" flash="); |
| 3858 | printmAh(pw, bs.flashlightPowerMah); |
| 3859 | } |
| 3860 | pw.print(" )"); |
| 3861 | } |
| 3862 | pw.println(); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3863 | } |
Dianne Hackborn | c46809e | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3864 | pw.println(); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3865 | } |
| 3866 | |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 3867 | sippers = helper.getMobilemsppList(); |
| 3868 | if (sippers != null && sippers.size() > 0) { |
| 3869 | pw.print(prefix); pw.println(" Per-app mobile ms per packet:"); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 3870 | long totalTime = 0; |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 3871 | for (int i=0; i<sippers.size(); i++) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3872 | final BatterySipper bs = sippers.get(i); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 3873 | sb.setLength(0); |
| 3874 | sb.append(prefix); sb.append(" Uid "); |
| 3875 | UserHandle.formatUid(sb, bs.uidObj.getUid()); |
| 3876 | sb.append(": "); sb.append(BatteryStatsHelper.makemAh(bs.mobilemspp)); |
| 3877 | sb.append(" ("); sb.append(bs.mobileRxPackets+bs.mobileTxPackets); |
| 3878 | sb.append(" packets over "); formatTimeMsNoSpace(sb, bs.mobileActive); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 3879 | sb.append(") "); sb.append(bs.mobileActiveCount); sb.append("x"); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 3880 | pw.println(sb.toString()); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 3881 | totalTime += bs.mobileActive; |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 3882 | } |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 3883 | sb.setLength(0); |
| 3884 | sb.append(prefix); |
| 3885 | sb.append(" TOTAL TIME: "); |
| 3886 | formatTimeMs(sb, totalTime); |
| 3887 | sb.append("("); sb.append(formatRatioLocked(totalTime, whichBatteryRealtime)); |
| 3888 | sb.append(")"); |
| 3889 | pw.println(sb.toString()); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 3890 | pw.println(); |
| 3891 | } |
| 3892 | |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 3893 | final Comparator<TimerEntry> timerComparator = new Comparator<TimerEntry>() { |
| 3894 | @Override |
| 3895 | public int compare(TimerEntry lhs, TimerEntry rhs) { |
| 3896 | long lhsTime = lhs.mTime; |
| 3897 | long rhsTime = rhs.mTime; |
| 3898 | if (lhsTime < rhsTime) { |
| 3899 | return 1; |
| 3900 | } |
| 3901 | if (lhsTime > rhsTime) { |
| 3902 | return -1; |
| 3903 | } |
| 3904 | return 0; |
| 3905 | } |
| 3906 | }; |
| 3907 | |
| 3908 | if (reqUid < 0) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3909 | final Map<String, ? extends BatteryStats.Timer> kernelWakelocks |
| 3910 | = getKernelWakelockStats(); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 3911 | if (kernelWakelocks.size() > 0) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3912 | final ArrayList<TimerEntry> ktimers = new ArrayList<>(); |
| 3913 | for (Map.Entry<String, ? extends BatteryStats.Timer> ent |
| 3914 | : kernelWakelocks.entrySet()) { |
| 3915 | final BatteryStats.Timer timer = ent.getValue(); |
| 3916 | final long totalTimeMillis = computeWakeLock(timer, rawRealtime, which); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 3917 | if (totalTimeMillis > 0) { |
| 3918 | ktimers.add(new TimerEntry(ent.getKey(), 0, timer, totalTimeMillis)); |
| 3919 | } |
| 3920 | } |
| 3921 | if (ktimers.size() > 0) { |
| 3922 | Collections.sort(ktimers, timerComparator); |
| 3923 | pw.print(prefix); pw.println(" All kernel wake locks:"); |
| 3924 | for (int i=0; i<ktimers.size(); i++) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3925 | final TimerEntry timer = ktimers.get(i); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 3926 | String linePrefix = ": "; |
| 3927 | sb.setLength(0); |
| 3928 | sb.append(prefix); |
| 3929 | sb.append(" Kernel Wake lock "); |
| 3930 | sb.append(timer.mName); |
| 3931 | linePrefix = printWakeLock(sb, timer.mTimer, rawRealtime, null, |
| 3932 | which, linePrefix); |
| 3933 | if (!linePrefix.equals(": ")) { |
| 3934 | sb.append(" realtime"); |
| 3935 | // Only print out wake locks that were held |
| 3936 | pw.println(sb.toString()); |
| 3937 | } |
| 3938 | } |
| 3939 | pw.println(); |
| 3940 | } |
| 3941 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 3942 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3943 | if (timers.size() > 0) { |
| 3944 | Collections.sort(timers, timerComparator); |
| 3945 | pw.print(prefix); pw.println(" All partial wake locks:"); |
| 3946 | for (int i=0; i<timers.size(); i++) { |
| 3947 | TimerEntry timer = timers.get(i); |
| 3948 | sb.setLength(0); |
| 3949 | sb.append(" Wake lock "); |
| 3950 | UserHandle.formatUid(sb, timer.mId); |
| 3951 | sb.append(" "); |
| 3952 | sb.append(timer.mName); |
| 3953 | printWakeLock(sb, timer.mTimer, rawRealtime, null, which, ": "); |
| 3954 | sb.append(" realtime"); |
| 3955 | pw.println(sb.toString()); |
| 3956 | } |
| 3957 | timers.clear(); |
| 3958 | pw.println(); |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 3959 | } |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3960 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3961 | final Map<String, ? extends Timer> wakeupReasons = getWakeupReasonStats(); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3962 | if (wakeupReasons.size() > 0) { |
| 3963 | pw.print(prefix); pw.println(" All wakeup reasons:"); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3964 | final ArrayList<TimerEntry> reasons = new ArrayList<>(); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 3965 | for (Map.Entry<String, ? extends Timer> ent : wakeupReasons.entrySet()) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3966 | final Timer timer = ent.getValue(); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 3967 | reasons.add(new TimerEntry(ent.getKey(), 0, timer, |
| 3968 | timer.getCountLocked(which))); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3969 | } |
| 3970 | Collections.sort(reasons, timerComparator); |
| 3971 | for (int i=0; i<reasons.size(); i++) { |
| 3972 | TimerEntry timer = reasons.get(i); |
| 3973 | String linePrefix = ": "; |
| 3974 | sb.setLength(0); |
| 3975 | sb.append(prefix); |
| 3976 | sb.append(" Wakeup reason "); |
| 3977 | sb.append(timer.mName); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 3978 | printWakeLock(sb, timer.mTimer, rawRealtime, null, which, ": "); |
| 3979 | sb.append(" realtime"); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3980 | pw.println(sb.toString()); |
| 3981 | } |
| 3982 | pw.println(); |
| 3983 | } |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 3984 | } |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 3985 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3986 | for (int iu=0; iu<NU; iu++) { |
| 3987 | final int uid = uidStats.keyAt(iu); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3988 | if (reqUid >= 0 && uid != reqUid && uid != Process.SYSTEM_UID) { |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 3989 | continue; |
| 3990 | } |
| 3991 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3992 | final Uid u = uidStats.valueAt(iu); |
Dianne Hackborn | a4cc205 | 2013-07-08 17:31:25 -0700 | [diff] [blame] | 3993 | |
| 3994 | pw.print(prefix); |
| 3995 | pw.print(" "); |
| 3996 | UserHandle.formatUid(pw, uid); |
| 3997 | pw.println(":"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3998 | boolean uidActivity = false; |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 3999 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4000 | final long mobileRxBytes = u.getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which); |
| 4001 | final long mobileTxBytes = u.getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which); |
| 4002 | final long wifiRxBytes = u.getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which); |
| 4003 | final long wifiTxBytes = u.getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which); |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 4004 | final long btRxBytes = u.getNetworkActivityBytes(NETWORK_BT_RX_DATA, which); |
| 4005 | final long btTxBytes = u.getNetworkActivityBytes(NETWORK_BT_TX_DATA, which); |
| 4006 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4007 | final long mobileRxPackets = u.getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which); |
| 4008 | final long mobileTxPackets = u.getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4009 | final long wifiRxPackets = u.getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which); |
| 4010 | final long wifiTxPackets = u.getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which); |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 4011 | |
| 4012 | final long uidMobileActiveTime = u.getMobileRadioActiveTime(which); |
| 4013 | final int uidMobileActiveCount = u.getMobileRadioActiveCount(which); |
| 4014 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4015 | final long fullWifiLockOnTime = u.getFullWifiLockTime(rawRealtime, which); |
| 4016 | final long wifiScanTime = u.getWifiScanTime(rawRealtime, which); |
| 4017 | final int wifiScanCount = u.getWifiScanCount(which); |
| 4018 | final long uidWifiRunningTime = u.getWifiRunningTime(rawRealtime, which); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 4019 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4020 | if (mobileRxBytes > 0 || mobileTxBytes > 0 |
| 4021 | || mobileRxPackets > 0 || mobileTxPackets > 0) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 4022 | pw.print(prefix); pw.print(" Mobile network: "); |
| 4023 | pw.print(formatBytesLocked(mobileRxBytes)); pw.print(" received, "); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4024 | pw.print(formatBytesLocked(mobileTxBytes)); |
| 4025 | pw.print(" sent (packets "); pw.print(mobileRxPackets); |
| 4026 | pw.print(" received, "); pw.print(mobileTxPackets); pw.println(" sent)"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4027 | } |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4028 | if (uidMobileActiveTime > 0 || uidMobileActiveCount > 0) { |
| 4029 | sb.setLength(0); |
| 4030 | sb.append(prefix); sb.append(" Mobile radio active: "); |
| 4031 | formatTimeMs(sb, uidMobileActiveTime / 1000); |
| 4032 | sb.append("("); |
| 4033 | sb.append(formatRatioLocked(uidMobileActiveTime, mobileActiveTime)); |
| 4034 | sb.append(") "); sb.append(uidMobileActiveCount); sb.append("x"); |
| 4035 | long packets = mobileRxPackets + mobileTxPackets; |
| 4036 | if (packets == 0) { |
| 4037 | packets = 1; |
| 4038 | } |
| 4039 | sb.append(" @ "); |
| 4040 | sb.append(BatteryStatsHelper.makemAh(uidMobileActiveTime / 1000 / (double)packets)); |
| 4041 | sb.append(" mspp"); |
| 4042 | pw.println(sb.toString()); |
| 4043 | } |
| 4044 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 4045 | printControllerActivityIfInteresting(pw, sb, prefix + " ", "Modem", |
| 4046 | u.getModemControllerActivity(), which); |
| 4047 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4048 | if (wifiRxBytes > 0 || wifiTxBytes > 0 || wifiRxPackets > 0 || wifiTxPackets > 0) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 4049 | pw.print(prefix); pw.print(" Wi-Fi network: "); |
| 4050 | pw.print(formatBytesLocked(wifiRxBytes)); pw.print(" received, "); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4051 | pw.print(formatBytesLocked(wifiTxBytes)); |
| 4052 | pw.print(" sent (packets "); pw.print(wifiRxPackets); |
| 4053 | pw.print(" received, "); pw.print(wifiTxPackets); pw.println(" sent)"); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 4054 | } |
| 4055 | |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 4056 | if (fullWifiLockOnTime != 0 || wifiScanTime != 0 || wifiScanCount != 0 |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4057 | || uidWifiRunningTime != 0) { |
| 4058 | sb.setLength(0); |
| 4059 | sb.append(prefix); sb.append(" Wifi Running: "); |
| 4060 | formatTimeMs(sb, uidWifiRunningTime / 1000); |
| 4061 | sb.append("("); sb.append(formatRatioLocked(uidWifiRunningTime, |
| 4062 | whichBatteryRealtime)); sb.append(")\n"); |
| 4063 | sb.append(prefix); sb.append(" Full Wifi Lock: "); |
| 4064 | formatTimeMs(sb, fullWifiLockOnTime / 1000); |
| 4065 | sb.append("("); sb.append(formatRatioLocked(fullWifiLockOnTime, |
| 4066 | whichBatteryRealtime)); sb.append(")\n"); |
| 4067 | sb.append(prefix); sb.append(" Wifi Scan: "); |
| 4068 | formatTimeMs(sb, wifiScanTime / 1000); |
| 4069 | sb.append("("); sb.append(formatRatioLocked(wifiScanTime, |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 4070 | whichBatteryRealtime)); sb.append(") "); |
| 4071 | sb.append(wifiScanCount); |
| 4072 | sb.append("x"); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4073 | pw.println(sb.toString()); |
| 4074 | } |
| 4075 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 4076 | printControllerActivityIfInteresting(pw, sb, prefix + " ", "WiFi", |
| 4077 | u.getWifiControllerActivity(), which); |
Adam Lesinski | 049c88b | 2015-05-28 11:38:12 -0700 | [diff] [blame] | 4078 | |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 4079 | if (btRxBytes > 0 || btTxBytes > 0) { |
| 4080 | pw.print(prefix); pw.print(" Bluetooth network: "); |
| 4081 | pw.print(formatBytesLocked(btRxBytes)); pw.print(" received, "); |
| 4082 | pw.print(formatBytesLocked(btTxBytes)); |
| 4083 | pw.println(" sent"); |
| 4084 | } |
| 4085 | |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 4086 | uidActivity |= printTimer(pw, sb, u.getBluetoothScanTimer(), rawRealtime, which, prefix, |
| 4087 | "Bluetooth Scan"); |
| 4088 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4089 | if (u.hasUserActivity()) { |
| 4090 | boolean hasData = false; |
Raph Levien | 4c7a4a7 | 2012-08-03 14:32:39 -0700 | [diff] [blame] | 4091 | for (int i=0; i<Uid.NUM_USER_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4092 | final int val = u.getUserActivityCount(i, which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4093 | if (val != 0) { |
| 4094 | if (!hasData) { |
| 4095 | sb.setLength(0); |
| 4096 | sb.append(" User activity: "); |
| 4097 | hasData = true; |
| 4098 | } else { |
| 4099 | sb.append(", "); |
| 4100 | } |
| 4101 | sb.append(val); |
| 4102 | sb.append(" "); |
| 4103 | sb.append(Uid.USER_ACTIVITY_TYPES[i]); |
| 4104 | } |
| 4105 | } |
| 4106 | if (hasData) { |
| 4107 | pw.println(sb.toString()); |
| 4108 | } |
| 4109 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4110 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4111 | final ArrayMap<String, ? extends BatteryStats.Uid.Wakelock> wakelocks |
| 4112 | = u.getWakelockStats(); |
| 4113 | long totalFullWakelock = 0, totalPartialWakelock = 0, totalWindowWakelock = 0; |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 4114 | long totalDrawWakelock = 0; |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4115 | int countWakelock = 0; |
| 4116 | for (int iw=wakelocks.size()-1; iw>=0; iw--) { |
| 4117 | final Uid.Wakelock wl = wakelocks.valueAt(iw); |
| 4118 | String linePrefix = ": "; |
| 4119 | sb.setLength(0); |
| 4120 | sb.append(prefix); |
| 4121 | sb.append(" Wake lock "); |
| 4122 | sb.append(wakelocks.keyAt(iw)); |
| 4123 | linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_FULL), rawRealtime, |
| 4124 | "full", which, linePrefix); |
| 4125 | linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_PARTIAL), rawRealtime, |
| 4126 | "partial", which, linePrefix); |
| 4127 | linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_WINDOW), rawRealtime, |
| 4128 | "window", which, linePrefix); |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 4129 | linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_DRAW), rawRealtime, |
| 4130 | "draw", which, linePrefix); |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 4131 | sb.append(" realtime"); |
| 4132 | pw.println(sb.toString()); |
| 4133 | uidActivity = true; |
| 4134 | countWakelock++; |
| 4135 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4136 | totalFullWakelock += computeWakeLock(wl.getWakeTime(WAKE_TYPE_FULL), |
| 4137 | rawRealtime, which); |
| 4138 | totalPartialWakelock += computeWakeLock(wl.getWakeTime(WAKE_TYPE_PARTIAL), |
| 4139 | rawRealtime, which); |
| 4140 | totalWindowWakelock += computeWakeLock(wl.getWakeTime(WAKE_TYPE_WINDOW), |
| 4141 | rawRealtime, which); |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 4142 | totalDrawWakelock += computeWakeLock(wl.getWakeTime(WAKE_TYPE_DRAW), |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 4143 | rawRealtime, which); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 4144 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4145 | if (countWakelock > 1) { |
| 4146 | if (totalFullWakelock != 0 || totalPartialWakelock != 0 |
| 4147 | || totalWindowWakelock != 0) { |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 4148 | sb.setLength(0); |
| 4149 | sb.append(prefix); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4150 | sb.append(" TOTAL wake: "); |
| 4151 | boolean needComma = false; |
| 4152 | if (totalFullWakelock != 0) { |
| 4153 | needComma = true; |
| 4154 | formatTimeMs(sb, totalFullWakelock); |
| 4155 | sb.append("full"); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 4156 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4157 | if (totalPartialWakelock != 0) { |
| 4158 | if (needComma) { |
| 4159 | sb.append(", "); |
| 4160 | } |
| 4161 | needComma = true; |
| 4162 | formatTimeMs(sb, totalPartialWakelock); |
| 4163 | sb.append("partial"); |
| 4164 | } |
| 4165 | if (totalWindowWakelock != 0) { |
| 4166 | if (needComma) { |
| 4167 | sb.append(", "); |
| 4168 | } |
| 4169 | needComma = true; |
| 4170 | formatTimeMs(sb, totalWindowWakelock); |
| 4171 | sb.append("window"); |
| 4172 | } |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 4173 | if (totalDrawWakelock != 0) { |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 4174 | if (needComma) { |
| 4175 | sb.append(","); |
| 4176 | } |
| 4177 | needComma = true; |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 4178 | formatTimeMs(sb, totalDrawWakelock); |
| 4179 | sb.append("draw"); |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 4180 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4181 | sb.append(" realtime"); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 4182 | pw.println(sb.toString()); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 4183 | } |
| 4184 | } |
| 4185 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4186 | final ArrayMap<String, ? extends Timer> syncs = u.getSyncStats(); |
| 4187 | for (int isy=syncs.size()-1; isy>=0; isy--) { |
| 4188 | final Timer timer = syncs.valueAt(isy); |
| 4189 | // Convert from microseconds to milliseconds with rounding |
| 4190 | final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000; |
| 4191 | final int count = timer.getCountLocked(which); |
| 4192 | sb.setLength(0); |
| 4193 | sb.append(prefix); |
| 4194 | sb.append(" Sync "); |
| 4195 | sb.append(syncs.keyAt(isy)); |
| 4196 | sb.append(": "); |
| 4197 | if (totalTime != 0) { |
| 4198 | formatTimeMs(sb, totalTime); |
| 4199 | sb.append("realtime ("); |
| 4200 | sb.append(count); |
| 4201 | sb.append(" times)"); |
| 4202 | } else { |
| 4203 | sb.append("(not used)"); |
| 4204 | } |
| 4205 | pw.println(sb.toString()); |
| 4206 | uidActivity = true; |
| 4207 | } |
| 4208 | |
| 4209 | final ArrayMap<String, ? extends Timer> jobs = u.getJobStats(); |
| 4210 | for (int ij=jobs.size()-1; ij>=0; ij--) { |
| 4211 | final Timer timer = jobs.valueAt(ij); |
| 4212 | // Convert from microseconds to milliseconds with rounding |
| 4213 | final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000; |
| 4214 | final int count = timer.getCountLocked(which); |
| 4215 | sb.setLength(0); |
| 4216 | sb.append(prefix); |
| 4217 | sb.append(" Job "); |
| 4218 | sb.append(jobs.keyAt(ij)); |
| 4219 | sb.append(": "); |
| 4220 | if (totalTime != 0) { |
| 4221 | formatTimeMs(sb, totalTime); |
| 4222 | sb.append("realtime ("); |
| 4223 | sb.append(count); |
| 4224 | sb.append(" times)"); |
| 4225 | } else { |
| 4226 | sb.append("(not used)"); |
| 4227 | } |
| 4228 | pw.println(sb.toString()); |
| 4229 | uidActivity = true; |
| 4230 | } |
| 4231 | |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 4232 | uidActivity |= printTimer(pw, sb, u.getFlashlightTurnedOnTimer(), rawRealtime, which, |
| 4233 | prefix, "Flashlight"); |
| 4234 | uidActivity |= printTimer(pw, sb, u.getCameraTurnedOnTimer(), rawRealtime, which, |
| 4235 | prefix, "Camera"); |
| 4236 | uidActivity |= printTimer(pw, sb, u.getVideoTurnedOnTimer(), rawRealtime, which, |
| 4237 | prefix, "Video"); |
| 4238 | uidActivity |= printTimer(pw, sb, u.getAudioTurnedOnTimer(), rawRealtime, which, |
| 4239 | prefix, "Audio"); |
| 4240 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4241 | final SparseArray<? extends BatteryStats.Uid.Sensor> sensors = u.getSensorStats(); |
| 4242 | final int NSE = sensors.size(); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 4243 | for (int ise=0; ise<NSE; ise++) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4244 | final Uid.Sensor se = sensors.valueAt(ise); |
| 4245 | final int sensorNumber = sensors.keyAt(ise); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 4246 | sb.setLength(0); |
| 4247 | sb.append(prefix); |
| 4248 | sb.append(" Sensor "); |
| 4249 | int handle = se.getHandle(); |
| 4250 | if (handle == Uid.Sensor.GPS) { |
| 4251 | sb.append("GPS"); |
| 4252 | } else { |
| 4253 | sb.append(handle); |
| 4254 | } |
| 4255 | sb.append(": "); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4256 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4257 | final Timer timer = se.getSensorTime(); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 4258 | if (timer != null) { |
| 4259 | // Convert from microseconds to milliseconds with rounding |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4260 | final long totalTime = (timer.getTotalTimeLocked( |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 4261 | rawRealtime, which) + 500) / 1000; |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4262 | final int count = timer.getCountLocked(which); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 4263 | //timer.logState(); |
| 4264 | if (totalTime != 0) { |
| 4265 | formatTimeMs(sb, totalTime); |
| 4266 | sb.append("realtime ("); |
| 4267 | sb.append(count); |
| 4268 | sb.append(" times)"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4269 | } else { |
| 4270 | sb.append("(not used)"); |
| 4271 | } |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 4272 | } else { |
| 4273 | sb.append("(not used)"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4274 | } |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 4275 | |
| 4276 | pw.println(sb.toString()); |
| 4277 | uidActivity = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4278 | } |
| 4279 | |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 4280 | uidActivity |= printTimer(pw, sb, u.getVibratorOnTimer(), rawRealtime, which, prefix, |
| 4281 | "Vibrator"); |
| 4282 | uidActivity |= printTimer(pw, sb, u.getForegroundActivityTimer(), rawRealtime, which, |
| 4283 | prefix, "Foreground activities"); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 4284 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 4285 | long totalStateTime = 0; |
| 4286 | for (int ips=0; ips<Uid.NUM_PROCESS_STATE; ips++) { |
| 4287 | long time = u.getProcessStateTime(ips, rawRealtime, which); |
| 4288 | if (time > 0) { |
| 4289 | totalStateTime += time; |
| 4290 | sb.setLength(0); |
| 4291 | sb.append(prefix); |
| 4292 | sb.append(" "); |
| 4293 | sb.append(Uid.PROCESS_STATE_NAMES[ips]); |
| 4294 | sb.append(" for: "); |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 4295 | formatTimeMs(sb, (time + 500) / 1000); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 4296 | pw.println(sb.toString()); |
| 4297 | uidActivity = true; |
| 4298 | } |
| 4299 | } |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 4300 | if (totalStateTime > 0) { |
| 4301 | sb.setLength(0); |
| 4302 | sb.append(prefix); |
| 4303 | sb.append(" Total running: "); |
| 4304 | formatTimeMs(sb, (totalStateTime + 500) / 1000); |
| 4305 | pw.println(sb.toString()); |
| 4306 | } |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 4307 | |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 4308 | final long userCpuTimeUs = u.getUserCpuTimeUs(which); |
| 4309 | final long systemCpuTimeUs = u.getSystemCpuTimeUs(which); |
Adam Lesinski | a7a4ccc | 2015-06-26 17:43:04 -0700 | [diff] [blame] | 4310 | final long powerCpuMaUs = u.getCpuPowerMaUs(which); |
| 4311 | if (userCpuTimeUs > 0 || systemCpuTimeUs > 0 || powerCpuMaUs > 0) { |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 4312 | sb.setLength(0); |
| 4313 | sb.append(prefix); |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 4314 | sb.append(" Total cpu time: u="); |
| 4315 | formatTimeMs(sb, userCpuTimeUs / 1000); |
| 4316 | sb.append("s="); |
| 4317 | formatTimeMs(sb, systemCpuTimeUs / 1000); |
Adam Lesinski | a7a4ccc | 2015-06-26 17:43:04 -0700 | [diff] [blame] | 4318 | sb.append("p="); |
| 4319 | printmAh(sb, powerCpuMaUs / (1000.0 * 1000.0 * 60.0 * 60.0)); |
| 4320 | sb.append("mAh"); |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 4321 | pw.println(sb.toString()); |
| 4322 | } |
| 4323 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4324 | final ArrayMap<String, ? extends BatteryStats.Uid.Proc> processStats |
| 4325 | = u.getProcessStats(); |
| 4326 | for (int ipr=processStats.size()-1; ipr>=0; ipr--) { |
| 4327 | final Uid.Proc ps = processStats.valueAt(ipr); |
| 4328 | long userTime; |
| 4329 | long systemTime; |
| 4330 | long foregroundTime; |
| 4331 | int starts; |
| 4332 | int numExcessive; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4333 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4334 | userTime = ps.getUserTime(which); |
| 4335 | systemTime = ps.getSystemTime(which); |
| 4336 | foregroundTime = ps.getForegroundTime(which); |
| 4337 | starts = ps.getStarts(which); |
| 4338 | final int numCrashes = ps.getNumCrashes(which); |
| 4339 | final int numAnrs = ps.getNumAnrs(which); |
| 4340 | numExcessive = which == STATS_SINCE_CHARGED |
| 4341 | ? ps.countExcessivePowers() : 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4342 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4343 | if (userTime != 0 || systemTime != 0 || foregroundTime != 0 || starts != 0 |
| 4344 | || numExcessive != 0 || numCrashes != 0 || numAnrs != 0) { |
| 4345 | sb.setLength(0); |
| 4346 | sb.append(prefix); sb.append(" Proc "); |
| 4347 | sb.append(processStats.keyAt(ipr)); sb.append(":\n"); |
| 4348 | sb.append(prefix); sb.append(" CPU: "); |
| 4349 | formatTimeMs(sb, userTime); sb.append("usr + "); |
| 4350 | formatTimeMs(sb, systemTime); sb.append("krn ; "); |
| 4351 | formatTimeMs(sb, foregroundTime); sb.append("fg"); |
| 4352 | if (starts != 0 || numCrashes != 0 || numAnrs != 0) { |
| 4353 | sb.append("\n"); sb.append(prefix); sb.append(" "); |
| 4354 | boolean hasOne = false; |
| 4355 | if (starts != 0) { |
| 4356 | hasOne = true; |
| 4357 | sb.append(starts); sb.append(" starts"); |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 4358 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4359 | if (numCrashes != 0) { |
| 4360 | if (hasOne) { |
| 4361 | sb.append(", "); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4362 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4363 | hasOne = true; |
| 4364 | sb.append(numCrashes); sb.append(" crashes"); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4365 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4366 | if (numAnrs != 0) { |
| 4367 | if (hasOne) { |
| 4368 | sb.append(", "); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4369 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4370 | sb.append(numAnrs); sb.append(" anrs"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4371 | } |
| 4372 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4373 | pw.println(sb.toString()); |
| 4374 | for (int e=0; e<numExcessive; e++) { |
| 4375 | Uid.Proc.ExcessivePower ew = ps.getExcessivePower(e); |
| 4376 | if (ew != null) { |
| 4377 | pw.print(prefix); pw.print(" * Killed for "); |
| 4378 | if (ew.type == Uid.Proc.ExcessivePower.TYPE_WAKE) { |
| 4379 | pw.print("wake lock"); |
| 4380 | } else if (ew.type == Uid.Proc.ExcessivePower.TYPE_CPU) { |
| 4381 | pw.print("cpu"); |
| 4382 | } else { |
| 4383 | pw.print("unknown"); |
| 4384 | } |
| 4385 | pw.print(" use: "); |
| 4386 | TimeUtils.formatDuration(ew.usedTime, pw); |
| 4387 | pw.print(" over "); |
| 4388 | TimeUtils.formatDuration(ew.overTime, pw); |
| 4389 | if (ew.overTime != 0) { |
| 4390 | pw.print(" ("); |
| 4391 | pw.print((ew.usedTime*100)/ew.overTime); |
| 4392 | pw.println("%)"); |
| 4393 | } |
| 4394 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4395 | } |
| 4396 | uidActivity = true; |
| 4397 | } |
| 4398 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4399 | |
| 4400 | final ArrayMap<String, ? extends BatteryStats.Uid.Pkg> packageStats |
| 4401 | = u.getPackageStats(); |
| 4402 | for (int ipkg=packageStats.size()-1; ipkg>=0; ipkg--) { |
| 4403 | pw.print(prefix); pw.print(" Apk "); pw.print(packageStats.keyAt(ipkg)); |
| 4404 | pw.println(":"); |
| 4405 | boolean apkActivity = false; |
| 4406 | final Uid.Pkg ps = packageStats.valueAt(ipkg); |
| 4407 | final ArrayMap<String, ? extends Counter> alarms = ps.getWakeupAlarmStats(); |
| 4408 | for (int iwa=alarms.size()-1; iwa>=0; iwa--) { |
| 4409 | pw.print(prefix); pw.print(" Wakeup alarm "); |
| 4410 | pw.print(alarms.keyAt(iwa)); pw.print(": "); |
| 4411 | pw.print(alarms.valueAt(iwa).getCountLocked(which)); |
| 4412 | pw.println(" times"); |
| 4413 | apkActivity = true; |
| 4414 | } |
| 4415 | final ArrayMap<String, ? extends Uid.Pkg.Serv> serviceStats = ps.getServiceStats(); |
| 4416 | for (int isvc=serviceStats.size()-1; isvc>=0; isvc--) { |
| 4417 | final BatteryStats.Uid.Pkg.Serv ss = serviceStats.valueAt(isvc); |
| 4418 | final long startTime = ss.getStartTime(batteryUptime, which); |
| 4419 | final int starts = ss.getStarts(which); |
| 4420 | final int launches = ss.getLaunches(which); |
| 4421 | if (startTime != 0 || starts != 0 || launches != 0) { |
| 4422 | sb.setLength(0); |
| 4423 | sb.append(prefix); sb.append(" Service "); |
| 4424 | sb.append(serviceStats.keyAt(isvc)); sb.append(":\n"); |
| 4425 | sb.append(prefix); sb.append(" Created for: "); |
| 4426 | formatTimeMs(sb, startTime / 1000); |
| 4427 | sb.append("uptime\n"); |
| 4428 | sb.append(prefix); sb.append(" Starts: "); |
| 4429 | sb.append(starts); |
| 4430 | sb.append(", launches: "); sb.append(launches); |
| 4431 | pw.println(sb.toString()); |
| 4432 | apkActivity = true; |
| 4433 | } |
| 4434 | } |
| 4435 | if (!apkActivity) { |
| 4436 | pw.print(prefix); pw.println(" (nothing executed)"); |
| 4437 | } |
| 4438 | uidActivity = true; |
| 4439 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4440 | if (!uidActivity) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4441 | pw.print(prefix); pw.println(" (nothing executed)"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4442 | } |
| 4443 | } |
| 4444 | } |
| 4445 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 4446 | static void printBitDescriptions(PrintWriter pw, int oldval, int newval, HistoryTag wakelockTag, |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4447 | BitDescription[] descriptions, boolean longNames) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4448 | int diff = oldval ^ newval; |
| 4449 | if (diff == 0) return; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 4450 | boolean didWake = false; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4451 | for (int i=0; i<descriptions.length; i++) { |
| 4452 | BitDescription bd = descriptions[i]; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 4453 | if ((diff&bd.mask) != 0) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4454 | pw.print(longNames ? " " : ","); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4455 | if (bd.shift < 0) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 4456 | pw.print((newval&bd.mask) != 0 ? "+" : "-"); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4457 | pw.print(longNames ? bd.name : bd.shortName); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 4458 | if (bd.mask == HistoryItem.STATE_WAKE_LOCK_FLAG && wakelockTag != null) { |
| 4459 | didWake = true; |
| 4460 | pw.print("="); |
| 4461 | if (longNames) { |
| 4462 | UserHandle.formatUid(pw, wakelockTag.uid); |
| 4463 | pw.print(":\""); |
| 4464 | pw.print(wakelockTag.string); |
| 4465 | pw.print("\""); |
| 4466 | } else { |
| 4467 | pw.print(wakelockTag.poolIdx); |
| 4468 | } |
| 4469 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4470 | } else { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4471 | pw.print(longNames ? bd.name : bd.shortName); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4472 | pw.print("="); |
| 4473 | int val = (newval&bd.mask)>>bd.shift; |
| 4474 | if (bd.values != null && val >= 0 && val < bd.values.length) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4475 | pw.print(longNames? bd.values[val] : bd.shortValues[val]); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4476 | } else { |
| 4477 | pw.print(val); |
| 4478 | } |
| 4479 | } |
| 4480 | } |
| 4481 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 4482 | if (!didWake && wakelockTag != null) { |
Ashish Sharma | 81850c4 | 2014-05-05 13:57:07 -0700 | [diff] [blame] | 4483 | pw.print(longNames ? " wake_lock=" : ",w="); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 4484 | if (longNames) { |
| 4485 | UserHandle.formatUid(pw, wakelockTag.uid); |
| 4486 | pw.print(":\""); |
| 4487 | pw.print(wakelockTag.string); |
| 4488 | pw.print("\""); |
| 4489 | } else { |
| 4490 | pw.print(wakelockTag.poolIdx); |
| 4491 | } |
| 4492 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4493 | } |
| 4494 | |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 4495 | public void prepareForDumpLocked() { |
| 4496 | } |
| 4497 | |
| 4498 | public static class HistoryPrinter { |
| 4499 | int oldState = 0; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 4500 | int oldState2 = 0; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4501 | int oldLevel = -1; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 4502 | int oldStatus = -1; |
| 4503 | int oldHealth = -1; |
| 4504 | int oldPlug = -1; |
| 4505 | int oldTemp = -1; |
| 4506 | int oldVolt = -1; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4507 | long lastTime = -1; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 4508 | |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 4509 | void reset() { |
| 4510 | oldState = oldState2 = 0; |
| 4511 | oldLevel = -1; |
| 4512 | oldStatus = -1; |
| 4513 | oldHealth = -1; |
| 4514 | oldPlug = -1; |
| 4515 | oldTemp = -1; |
| 4516 | oldVolt = -1; |
| 4517 | } |
| 4518 | |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 4519 | public void printNextItem(PrintWriter pw, HistoryItem rec, long baseTime, boolean checkin, |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 4520 | boolean verbose) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4521 | if (!checkin) { |
| 4522 | pw.print(" "); |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 4523 | TimeUtils.formatDuration(rec.time - baseTime, pw, TimeUtils.HUNDRED_DAY_FIELD_LEN); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 4524 | pw.print(" ("); |
| 4525 | pw.print(rec.numReadInts); |
| 4526 | pw.print(") "); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4527 | } else { |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 4528 | pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(','); |
| 4529 | pw.print(HISTORY_DATA); pw.print(','); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4530 | if (lastTime < 0) { |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 4531 | pw.print(rec.time - baseTime); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4532 | } else { |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 4533 | pw.print(rec.time - lastTime); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4534 | } |
| 4535 | lastTime = rec.time; |
| 4536 | } |
| 4537 | if (rec.cmd == HistoryItem.CMD_START) { |
| 4538 | if (checkin) { |
| 4539 | pw.print(":"); |
| 4540 | } |
| 4541 | pw.println("START"); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 4542 | reset(); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 4543 | } else if (rec.cmd == HistoryItem.CMD_CURRENT_TIME |
| 4544 | || rec.cmd == HistoryItem.CMD_RESET) { |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 4545 | if (checkin) { |
| 4546 | pw.print(":"); |
| 4547 | } |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 4548 | if (rec.cmd == HistoryItem.CMD_RESET) { |
| 4549 | pw.print("RESET:"); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 4550 | reset(); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 4551 | } |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 4552 | pw.print("TIME:"); |
| 4553 | if (checkin) { |
| 4554 | pw.println(rec.currentTime); |
| 4555 | } else { |
| 4556 | pw.print(" "); |
| 4557 | pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss", |
| 4558 | rec.currentTime).toString()); |
| 4559 | } |
Dianne Hackborn | 29cd7f1 | 2015-01-08 10:37:05 -0800 | [diff] [blame] | 4560 | } else if (rec.cmd == HistoryItem.CMD_SHUTDOWN) { |
| 4561 | if (checkin) { |
| 4562 | pw.print(":"); |
| 4563 | } |
| 4564 | pw.println("SHUTDOWN"); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4565 | } else if (rec.cmd == HistoryItem.CMD_OVERFLOW) { |
| 4566 | if (checkin) { |
| 4567 | pw.print(":"); |
| 4568 | } |
| 4569 | pw.println("*OVERFLOW*"); |
| 4570 | } else { |
| 4571 | if (!checkin) { |
| 4572 | if (rec.batteryLevel < 10) pw.print("00"); |
| 4573 | else if (rec.batteryLevel < 100) pw.print("0"); |
| 4574 | pw.print(rec.batteryLevel); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 4575 | if (verbose) { |
| 4576 | pw.print(" "); |
| 4577 | if (rec.states < 0) ; |
| 4578 | else if (rec.states < 0x10) pw.print("0000000"); |
| 4579 | else if (rec.states < 0x100) pw.print("000000"); |
| 4580 | else if (rec.states < 0x1000) pw.print("00000"); |
| 4581 | else if (rec.states < 0x10000) pw.print("0000"); |
| 4582 | else if (rec.states < 0x100000) pw.print("000"); |
| 4583 | else if (rec.states < 0x1000000) pw.print("00"); |
| 4584 | else if (rec.states < 0x10000000) pw.print("0"); |
| 4585 | pw.print(Integer.toHexString(rec.states)); |
| 4586 | } |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4587 | } else { |
| 4588 | if (oldLevel != rec.batteryLevel) { |
| 4589 | oldLevel = rec.batteryLevel; |
| 4590 | pw.print(",Bl="); pw.print(rec.batteryLevel); |
| 4591 | } |
| 4592 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 4593 | if (oldStatus != rec.batteryStatus) { |
| 4594 | oldStatus = rec.batteryStatus; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4595 | pw.print(checkin ? ",Bs=" : " status="); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 4596 | switch (oldStatus) { |
| 4597 | case BatteryManager.BATTERY_STATUS_UNKNOWN: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4598 | pw.print(checkin ? "?" : "unknown"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 4599 | break; |
| 4600 | case BatteryManager.BATTERY_STATUS_CHARGING: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4601 | pw.print(checkin ? "c" : "charging"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 4602 | break; |
| 4603 | case BatteryManager.BATTERY_STATUS_DISCHARGING: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4604 | pw.print(checkin ? "d" : "discharging"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 4605 | break; |
| 4606 | case BatteryManager.BATTERY_STATUS_NOT_CHARGING: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4607 | pw.print(checkin ? "n" : "not-charging"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 4608 | break; |
| 4609 | case BatteryManager.BATTERY_STATUS_FULL: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4610 | pw.print(checkin ? "f" : "full"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 4611 | break; |
| 4612 | default: |
| 4613 | pw.print(oldStatus); |
| 4614 | break; |
| 4615 | } |
| 4616 | } |
| 4617 | if (oldHealth != rec.batteryHealth) { |
| 4618 | oldHealth = rec.batteryHealth; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4619 | pw.print(checkin ? ",Bh=" : " health="); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 4620 | switch (oldHealth) { |
| 4621 | case BatteryManager.BATTERY_HEALTH_UNKNOWN: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4622 | pw.print(checkin ? "?" : "unknown"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 4623 | break; |
| 4624 | case BatteryManager.BATTERY_HEALTH_GOOD: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4625 | pw.print(checkin ? "g" : "good"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 4626 | break; |
| 4627 | case BatteryManager.BATTERY_HEALTH_OVERHEAT: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4628 | pw.print(checkin ? "h" : "overheat"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 4629 | break; |
| 4630 | case BatteryManager.BATTERY_HEALTH_DEAD: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4631 | pw.print(checkin ? "d" : "dead"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 4632 | break; |
| 4633 | case BatteryManager.BATTERY_HEALTH_OVER_VOLTAGE: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4634 | pw.print(checkin ? "v" : "over-voltage"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 4635 | break; |
| 4636 | case BatteryManager.BATTERY_HEALTH_UNSPECIFIED_FAILURE: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4637 | pw.print(checkin ? "f" : "failure"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 4638 | break; |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 4639 | case BatteryManager.BATTERY_HEALTH_COLD: |
| 4640 | pw.print(checkin ? "c" : "cold"); |
| 4641 | break; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 4642 | default: |
| 4643 | pw.print(oldHealth); |
| 4644 | break; |
| 4645 | } |
| 4646 | } |
| 4647 | if (oldPlug != rec.batteryPlugType) { |
| 4648 | oldPlug = rec.batteryPlugType; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4649 | pw.print(checkin ? ",Bp=" : " plug="); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 4650 | switch (oldPlug) { |
| 4651 | case 0: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4652 | pw.print(checkin ? "n" : "none"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 4653 | break; |
| 4654 | case BatteryManager.BATTERY_PLUGGED_AC: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4655 | pw.print(checkin ? "a" : "ac"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 4656 | break; |
| 4657 | case BatteryManager.BATTERY_PLUGGED_USB: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4658 | pw.print(checkin ? "u" : "usb"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 4659 | break; |
Brian Muramatsu | 37a37f4 | 2012-08-14 15:21:02 -0700 | [diff] [blame] | 4660 | case BatteryManager.BATTERY_PLUGGED_WIRELESS: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4661 | pw.print(checkin ? "w" : "wireless"); |
Brian Muramatsu | 37a37f4 | 2012-08-14 15:21:02 -0700 | [diff] [blame] | 4662 | break; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 4663 | default: |
| 4664 | pw.print(oldPlug); |
| 4665 | break; |
| 4666 | } |
| 4667 | } |
| 4668 | if (oldTemp != rec.batteryTemperature) { |
| 4669 | oldTemp = rec.batteryTemperature; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4670 | pw.print(checkin ? ",Bt=" : " temp="); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 4671 | pw.print(oldTemp); |
| 4672 | } |
| 4673 | if (oldVolt != rec.batteryVoltage) { |
| 4674 | oldVolt = rec.batteryVoltage; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4675 | pw.print(checkin ? ",Bv=" : " volt="); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 4676 | pw.print(oldVolt); |
| 4677 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 4678 | printBitDescriptions(pw, oldState, rec.states, rec.wakelockTag, |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4679 | HISTORY_STATE_DESCRIPTIONS, !checkin); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 4680 | printBitDescriptions(pw, oldState2, rec.states2, null, |
| 4681 | HISTORY_STATE2_DESCRIPTIONS, !checkin); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 4682 | if (rec.wakeReasonTag != null) { |
| 4683 | if (checkin) { |
Dianne Hackborn | d06dcfd | 2014-05-02 13:49:30 -0700 | [diff] [blame] | 4684 | pw.print(",wr="); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 4685 | pw.print(rec.wakeReasonTag.poolIdx); |
| 4686 | } else { |
| 4687 | pw.print(" wake_reason="); |
| 4688 | pw.print(rec.wakeReasonTag.uid); |
| 4689 | pw.print(":\""); |
| 4690 | pw.print(rec.wakeReasonTag.string); |
| 4691 | pw.print("\""); |
| 4692 | } |
| 4693 | } |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4694 | if (rec.eventCode != HistoryItem.EVENT_NONE) { |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 4695 | pw.print(checkin ? "," : " "); |
| 4696 | if ((rec.eventCode&HistoryItem.EVENT_FLAG_START) != 0) { |
| 4697 | pw.print("+"); |
| 4698 | } else if ((rec.eventCode&HistoryItem.EVENT_FLAG_FINISH) != 0) { |
| 4699 | pw.print("-"); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4700 | } |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 4701 | String[] eventNames = checkin ? HISTORY_EVENT_CHECKIN_NAMES |
| 4702 | : HISTORY_EVENT_NAMES; |
| 4703 | int idx = rec.eventCode & ~(HistoryItem.EVENT_FLAG_START |
| 4704 | | HistoryItem.EVENT_FLAG_FINISH); |
| 4705 | if (idx >= 0 && idx < eventNames.length) { |
| 4706 | pw.print(eventNames[idx]); |
| 4707 | } else { |
| 4708 | pw.print(checkin ? "Ev" : "event"); |
| 4709 | pw.print(idx); |
| 4710 | } |
| 4711 | pw.print("="); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4712 | if (checkin) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 4713 | pw.print(rec.eventTag.poolIdx); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4714 | } else { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 4715 | UserHandle.formatUid(pw, rec.eventTag.uid); |
| 4716 | pw.print(":\""); |
| 4717 | pw.print(rec.eventTag.string); |
| 4718 | pw.print("\""); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4719 | } |
| 4720 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 4721 | pw.println(); |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 4722 | if (rec.stepDetails != null) { |
| 4723 | if (!checkin) { |
| 4724 | pw.print(" Details: cpu="); |
| 4725 | pw.print(rec.stepDetails.userTime); |
| 4726 | pw.print("u+"); |
| 4727 | pw.print(rec.stepDetails.systemTime); |
| 4728 | pw.print("s"); |
| 4729 | if (rec.stepDetails.appCpuUid1 >= 0) { |
| 4730 | pw.print(" ("); |
| 4731 | printStepCpuUidDetails(pw, rec.stepDetails.appCpuUid1, |
| 4732 | rec.stepDetails.appCpuUTime1, rec.stepDetails.appCpuSTime1); |
| 4733 | if (rec.stepDetails.appCpuUid2 >= 0) { |
| 4734 | pw.print(", "); |
| 4735 | printStepCpuUidDetails(pw, rec.stepDetails.appCpuUid2, |
| 4736 | rec.stepDetails.appCpuUTime2, rec.stepDetails.appCpuSTime2); |
| 4737 | } |
| 4738 | if (rec.stepDetails.appCpuUid3 >= 0) { |
| 4739 | pw.print(", "); |
| 4740 | printStepCpuUidDetails(pw, rec.stepDetails.appCpuUid3, |
| 4741 | rec.stepDetails.appCpuUTime3, rec.stepDetails.appCpuSTime3); |
| 4742 | } |
| 4743 | pw.print(')'); |
| 4744 | } |
| 4745 | pw.println(); |
| 4746 | pw.print(" /proc/stat="); |
| 4747 | pw.print(rec.stepDetails.statUserTime); |
| 4748 | pw.print(" usr, "); |
| 4749 | pw.print(rec.stepDetails.statSystemTime); |
| 4750 | pw.print(" sys, "); |
| 4751 | pw.print(rec.stepDetails.statIOWaitTime); |
| 4752 | pw.print(" io, "); |
| 4753 | pw.print(rec.stepDetails.statIrqTime); |
| 4754 | pw.print(" irq, "); |
| 4755 | pw.print(rec.stepDetails.statSoftIrqTime); |
| 4756 | pw.print(" sirq, "); |
| 4757 | pw.print(rec.stepDetails.statIdlTime); |
| 4758 | pw.print(" idle"); |
| 4759 | int totalRun = rec.stepDetails.statUserTime + rec.stepDetails.statSystemTime |
| 4760 | + rec.stepDetails.statIOWaitTime + rec.stepDetails.statIrqTime |
| 4761 | + rec.stepDetails.statSoftIrqTime; |
| 4762 | int total = totalRun + rec.stepDetails.statIdlTime; |
| 4763 | if (total > 0) { |
| 4764 | pw.print(" ("); |
| 4765 | float perc = ((float)totalRun) / ((float)total) * 100; |
| 4766 | pw.print(String.format("%.1f%%", perc)); |
| 4767 | pw.print(" of "); |
| 4768 | StringBuilder sb = new StringBuilder(64); |
| 4769 | formatTimeMsNoSpace(sb, total*10); |
| 4770 | pw.print(sb); |
| 4771 | pw.print(")"); |
| 4772 | } |
| 4773 | pw.println(); |
| 4774 | } else { |
| 4775 | pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(','); |
| 4776 | pw.print(HISTORY_DATA); pw.print(",0,Dcpu="); |
| 4777 | pw.print(rec.stepDetails.userTime); |
| 4778 | pw.print(":"); |
| 4779 | pw.print(rec.stepDetails.systemTime); |
| 4780 | if (rec.stepDetails.appCpuUid1 >= 0) { |
| 4781 | printStepCpuUidCheckinDetails(pw, rec.stepDetails.appCpuUid1, |
| 4782 | rec.stepDetails.appCpuUTime1, rec.stepDetails.appCpuSTime1); |
| 4783 | if (rec.stepDetails.appCpuUid2 >= 0) { |
| 4784 | printStepCpuUidCheckinDetails(pw, rec.stepDetails.appCpuUid2, |
| 4785 | rec.stepDetails.appCpuUTime2, rec.stepDetails.appCpuSTime2); |
| 4786 | } |
| 4787 | if (rec.stepDetails.appCpuUid3 >= 0) { |
| 4788 | printStepCpuUidCheckinDetails(pw, rec.stepDetails.appCpuUid3, |
| 4789 | rec.stepDetails.appCpuUTime3, rec.stepDetails.appCpuSTime3); |
| 4790 | } |
| 4791 | } |
| 4792 | pw.println(); |
| 4793 | pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(','); |
| 4794 | pw.print(HISTORY_DATA); pw.print(",0,Dpst="); |
| 4795 | pw.print(rec.stepDetails.statUserTime); |
| 4796 | pw.print(','); |
| 4797 | pw.print(rec.stepDetails.statSystemTime); |
| 4798 | pw.print(','); |
| 4799 | pw.print(rec.stepDetails.statIOWaitTime); |
| 4800 | pw.print(','); |
| 4801 | pw.print(rec.stepDetails.statIrqTime); |
| 4802 | pw.print(','); |
| 4803 | pw.print(rec.stepDetails.statSoftIrqTime); |
| 4804 | pw.print(','); |
| 4805 | pw.print(rec.stepDetails.statIdlTime); |
| 4806 | pw.println(); |
| 4807 | } |
| 4808 | } |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 4809 | oldState = rec.states; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 4810 | oldState2 = rec.states2; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 4811 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 4812 | } |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 4813 | |
| 4814 | private void printStepCpuUidDetails(PrintWriter pw, int uid, int utime, int stime) { |
| 4815 | UserHandle.formatUid(pw, uid); |
| 4816 | pw.print("="); |
| 4817 | pw.print(utime); |
| 4818 | pw.print("u+"); |
| 4819 | pw.print(stime); |
| 4820 | pw.print("s"); |
| 4821 | } |
| 4822 | |
| 4823 | private void printStepCpuUidCheckinDetails(PrintWriter pw, int uid, int utime, int stime) { |
| 4824 | pw.print('/'); |
| 4825 | pw.print(uid); |
| 4826 | pw.print(":"); |
| 4827 | pw.print(utime); |
| 4828 | pw.print(":"); |
| 4829 | pw.print(stime); |
| 4830 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 4831 | } |
| 4832 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 4833 | private void printSizeValue(PrintWriter pw, long size) { |
| 4834 | float result = size; |
| 4835 | String suffix = ""; |
| 4836 | if (result >= 10*1024) { |
| 4837 | suffix = "KB"; |
| 4838 | result = result / 1024; |
| 4839 | } |
| 4840 | if (result >= 10*1024) { |
| 4841 | suffix = "MB"; |
| 4842 | result = result / 1024; |
| 4843 | } |
| 4844 | if (result >= 10*1024) { |
| 4845 | suffix = "GB"; |
| 4846 | result = result / 1024; |
| 4847 | } |
| 4848 | if (result >= 10*1024) { |
| 4849 | suffix = "TB"; |
| 4850 | result = result / 1024; |
| 4851 | } |
| 4852 | if (result >= 10*1024) { |
| 4853 | suffix = "PB"; |
| 4854 | result = result / 1024; |
| 4855 | } |
| 4856 | pw.print((int)result); |
| 4857 | pw.print(suffix); |
| 4858 | } |
| 4859 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 4860 | private static boolean dumpTimeEstimate(PrintWriter pw, String label1, String label2, |
| 4861 | String label3, long estimatedTime) { |
| 4862 | if (estimatedTime < 0) { |
Dianne Hackborn | ad6a99b | 2014-11-18 10:11:10 -0800 | [diff] [blame] | 4863 | return false; |
| 4864 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 4865 | pw.print(label1); |
| 4866 | pw.print(label2); |
| 4867 | pw.print(label3); |
Dianne Hackborn | ad6a99b | 2014-11-18 10:11:10 -0800 | [diff] [blame] | 4868 | StringBuilder sb = new StringBuilder(64); |
| 4869 | formatTimeMs(sb, estimatedTime); |
| 4870 | pw.print(sb); |
| 4871 | pw.println(); |
Dianne Hackborn | ad6a99b | 2014-11-18 10:11:10 -0800 | [diff] [blame] | 4872 | return true; |
| 4873 | } |
| 4874 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 4875 | private static boolean dumpDurationSteps(PrintWriter pw, String prefix, String header, |
| 4876 | LevelStepTracker steps, boolean checkin) { |
| 4877 | if (steps == null) { |
| 4878 | return false; |
| 4879 | } |
| 4880 | int count = steps.mNumStepDurations; |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 4881 | if (count <= 0) { |
| 4882 | return false; |
| 4883 | } |
| 4884 | if (!checkin) { |
| 4885 | pw.println(header); |
| 4886 | } |
Kweku Adams | 030980a | 2015-04-01 16:07:48 -0700 | [diff] [blame] | 4887 | String[] lineArgs = new String[5]; |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 4888 | for (int i=0; i<count; i++) { |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 4889 | long duration = steps.getDurationAt(i); |
| 4890 | int level = steps.getLevelAt(i); |
| 4891 | long initMode = steps.getInitModeAt(i); |
| 4892 | long modMode = steps.getModModeAt(i); |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 4893 | if (checkin) { |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 4894 | lineArgs[0] = Long.toString(duration); |
| 4895 | lineArgs[1] = Integer.toString(level); |
| 4896 | if ((modMode&STEP_LEVEL_MODE_SCREEN_STATE) == 0) { |
| 4897 | switch ((int)(initMode&STEP_LEVEL_MODE_SCREEN_STATE) + 1) { |
| 4898 | case Display.STATE_OFF: lineArgs[2] = "s-"; break; |
| 4899 | case Display.STATE_ON: lineArgs[2] = "s+"; break; |
| 4900 | case Display.STATE_DOZE: lineArgs[2] = "sd"; break; |
| 4901 | case Display.STATE_DOZE_SUSPEND: lineArgs[2] = "sds"; break; |
Kweku Adams | 030980a | 2015-04-01 16:07:48 -0700 | [diff] [blame] | 4902 | default: lineArgs[2] = "?"; break; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 4903 | } |
| 4904 | } else { |
| 4905 | lineArgs[2] = ""; |
| 4906 | } |
| 4907 | if ((modMode&STEP_LEVEL_MODE_POWER_SAVE) == 0) { |
| 4908 | lineArgs[3] = (initMode&STEP_LEVEL_MODE_POWER_SAVE) != 0 ? "p+" : "p-"; |
| 4909 | } else { |
| 4910 | lineArgs[3] = ""; |
| 4911 | } |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 4912 | if ((modMode&STEP_LEVEL_MODE_DEVICE_IDLE) == 0) { |
Kweku Adams | 030980a | 2015-04-01 16:07:48 -0700 | [diff] [blame] | 4913 | lineArgs[4] = (initMode&STEP_LEVEL_MODE_DEVICE_IDLE) != 0 ? "i+" : "i-"; |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 4914 | } else { |
Kweku Adams | 030980a | 2015-04-01 16:07:48 -0700 | [diff] [blame] | 4915 | lineArgs[4] = ""; |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 4916 | } |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 4917 | dumpLine(pw, 0 /* uid */, "i" /* category */, header, (Object[])lineArgs); |
| 4918 | } else { |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 4919 | pw.print(prefix); |
| 4920 | pw.print("#"); pw.print(i); pw.print(": "); |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 4921 | TimeUtils.formatDuration(duration, pw); |
| 4922 | pw.print(" to "); pw.print(level); |
| 4923 | boolean haveModes = false; |
| 4924 | if ((modMode&STEP_LEVEL_MODE_SCREEN_STATE) == 0) { |
| 4925 | pw.print(" ("); |
| 4926 | switch ((int)(initMode&STEP_LEVEL_MODE_SCREEN_STATE) + 1) { |
| 4927 | case Display.STATE_OFF: pw.print("screen-off"); break; |
| 4928 | case Display.STATE_ON: pw.print("screen-on"); break; |
| 4929 | case Display.STATE_DOZE: pw.print("screen-doze"); break; |
| 4930 | case Display.STATE_DOZE_SUSPEND: pw.print("screen-doze-suspend"); break; |
Kweku Adams | 030980a | 2015-04-01 16:07:48 -0700 | [diff] [blame] | 4931 | default: pw.print("screen-?"); break; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 4932 | } |
| 4933 | haveModes = true; |
| 4934 | } |
| 4935 | if ((modMode&STEP_LEVEL_MODE_POWER_SAVE) == 0) { |
| 4936 | pw.print(haveModes ? ", " : " ("); |
| 4937 | pw.print((initMode&STEP_LEVEL_MODE_POWER_SAVE) != 0 |
| 4938 | ? "power-save-on" : "power-save-off"); |
| 4939 | haveModes = true; |
| 4940 | } |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 4941 | if ((modMode&STEP_LEVEL_MODE_DEVICE_IDLE) == 0) { |
| 4942 | pw.print(haveModes ? ", " : " ("); |
| 4943 | pw.print((initMode&STEP_LEVEL_MODE_DEVICE_IDLE) != 0 |
| 4944 | ? "device-idle-on" : "device-idle-off"); |
| 4945 | haveModes = true; |
| 4946 | } |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 4947 | if (haveModes) { |
| 4948 | pw.print(")"); |
| 4949 | } |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 4950 | pw.println(); |
| 4951 | } |
| 4952 | } |
| 4953 | return true; |
| 4954 | } |
| 4955 | |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 4956 | public static final int DUMP_CHARGED_ONLY = 1<<1; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 4957 | public static final int DUMP_DAILY_ONLY = 1<<2; |
| 4958 | public static final int DUMP_HISTORY_ONLY = 1<<3; |
| 4959 | public static final int DUMP_INCLUDE_HISTORY = 1<<4; |
| 4960 | public static final int DUMP_VERBOSE = 1<<5; |
| 4961 | public static final int DUMP_DEVICE_WIFI_ONLY = 1<<6; |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 4962 | |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 4963 | private void dumpHistoryLocked(PrintWriter pw, int flags, long histStart, boolean checkin) { |
| 4964 | final HistoryPrinter hprinter = new HistoryPrinter(); |
| 4965 | final HistoryItem rec = new HistoryItem(); |
| 4966 | long lastTime = -1; |
| 4967 | long baseTime = -1; |
| 4968 | boolean printed = false; |
| 4969 | HistoryEventTracker tracker = null; |
| 4970 | while (getNextHistoryLocked(rec)) { |
| 4971 | lastTime = rec.time; |
| 4972 | if (baseTime < 0) { |
| 4973 | baseTime = lastTime; |
| 4974 | } |
| 4975 | if (rec.time >= histStart) { |
| 4976 | if (histStart >= 0 && !printed) { |
| 4977 | if (rec.cmd == HistoryItem.CMD_CURRENT_TIME |
Ashish Sharma | 6020071 | 2014-05-23 18:22:20 -0700 | [diff] [blame] | 4978 | || rec.cmd == HistoryItem.CMD_RESET |
Dianne Hackborn | 29cd7f1 | 2015-01-08 10:37:05 -0800 | [diff] [blame] | 4979 | || rec.cmd == HistoryItem.CMD_START |
| 4980 | || rec.cmd == HistoryItem.CMD_SHUTDOWN) { |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 4981 | printed = true; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 4982 | hprinter.printNextItem(pw, rec, baseTime, checkin, |
| 4983 | (flags&DUMP_VERBOSE) != 0); |
| 4984 | rec.cmd = HistoryItem.CMD_UPDATE; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 4985 | } else if (rec.currentTime != 0) { |
| 4986 | printed = true; |
| 4987 | byte cmd = rec.cmd; |
| 4988 | rec.cmd = HistoryItem.CMD_CURRENT_TIME; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 4989 | hprinter.printNextItem(pw, rec, baseTime, checkin, |
| 4990 | (flags&DUMP_VERBOSE) != 0); |
| 4991 | rec.cmd = cmd; |
| 4992 | } |
| 4993 | if (tracker != null) { |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 4994 | if (rec.cmd != HistoryItem.CMD_UPDATE) { |
| 4995 | hprinter.printNextItem(pw, rec, baseTime, checkin, |
| 4996 | (flags&DUMP_VERBOSE) != 0); |
| 4997 | rec.cmd = HistoryItem.CMD_UPDATE; |
| 4998 | } |
| 4999 | int oldEventCode = rec.eventCode; |
| 5000 | HistoryTag oldEventTag = rec.eventTag; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 5001 | rec.eventTag = new HistoryTag(); |
| 5002 | for (int i=0; i<HistoryItem.EVENT_COUNT; i++) { |
| 5003 | HashMap<String, SparseIntArray> active |
| 5004 | = tracker.getStateForEvent(i); |
| 5005 | if (active == null) { |
| 5006 | continue; |
| 5007 | } |
| 5008 | for (HashMap.Entry<String, SparseIntArray> ent |
| 5009 | : active.entrySet()) { |
| 5010 | SparseIntArray uids = ent.getValue(); |
| 5011 | for (int j=0; j<uids.size(); j++) { |
| 5012 | rec.eventCode = i; |
| 5013 | rec.eventTag.string = ent.getKey(); |
| 5014 | rec.eventTag.uid = uids.keyAt(j); |
| 5015 | rec.eventTag.poolIdx = uids.valueAt(j); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 5016 | hprinter.printNextItem(pw, rec, baseTime, checkin, |
| 5017 | (flags&DUMP_VERBOSE) != 0); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 5018 | rec.wakeReasonTag = null; |
| 5019 | rec.wakelockTag = null; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 5020 | } |
| 5021 | } |
| 5022 | } |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 5023 | rec.eventCode = oldEventCode; |
| 5024 | rec.eventTag = oldEventTag; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 5025 | tracker = null; |
| 5026 | } |
| 5027 | } |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 5028 | hprinter.printNextItem(pw, rec, baseTime, checkin, |
| 5029 | (flags&DUMP_VERBOSE) != 0); |
Dianne Hackborn | 536456f | 2014-05-23 16:51:05 -0700 | [diff] [blame] | 5030 | } else if (false && rec.eventCode != HistoryItem.EVENT_NONE) { |
| 5031 | // This is an attempt to aggregate the previous state and generate |
| 5032 | //Â fake events to reflect that state at the point where we start |
| 5033 | // 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] | 5034 | if (tracker == null) { |
| 5035 | tracker = new HistoryEventTracker(); |
| 5036 | } |
| 5037 | tracker.updateState(rec.eventCode, rec.eventTag.string, |
| 5038 | rec.eventTag.uid, rec.eventTag.poolIdx); |
| 5039 | } |
| 5040 | } |
| 5041 | if (histStart >= 0) { |
Dianne Hackborn | fc06413 | 2014-06-02 12:42:12 -0700 | [diff] [blame] | 5042 | commitCurrentHistoryBatchLocked(); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 5043 | pw.print(checkin ? "NEXT: " : " NEXT: "); pw.println(lastTime+1); |
| 5044 | } |
| 5045 | } |
| 5046 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 5047 | private void dumpDailyLevelStepSummary(PrintWriter pw, String prefix, String label, |
| 5048 | LevelStepTracker steps, StringBuilder tmpSb, int[] tmpOutInt) { |
| 5049 | if (steps == null) { |
| 5050 | return; |
| 5051 | } |
| 5052 | long timeRemaining = steps.computeTimeEstimate(0, 0, tmpOutInt); |
| 5053 | if (timeRemaining >= 0) { |
| 5054 | pw.print(prefix); pw.print(label); pw.print(" total time: "); |
| 5055 | tmpSb.setLength(0); |
| 5056 | formatTimeMs(tmpSb, timeRemaining); |
| 5057 | pw.print(tmpSb); |
| 5058 | pw.print(" (from "); pw.print(tmpOutInt[0]); |
| 5059 | pw.println(" steps)"); |
| 5060 | } |
| 5061 | for (int i=0; i< STEP_LEVEL_MODES_OF_INTEREST.length; i++) { |
| 5062 | long estimatedTime = steps.computeTimeEstimate(STEP_LEVEL_MODES_OF_INTEREST[i], |
| 5063 | STEP_LEVEL_MODE_VALUES[i], tmpOutInt); |
| 5064 | if (estimatedTime > 0) { |
| 5065 | pw.print(prefix); pw.print(label); pw.print(" "); |
| 5066 | pw.print(STEP_LEVEL_MODE_LABELS[i]); |
| 5067 | pw.print(" time: "); |
| 5068 | tmpSb.setLength(0); |
| 5069 | formatTimeMs(tmpSb, estimatedTime); |
| 5070 | pw.print(tmpSb); |
| 5071 | pw.print(" (from "); pw.print(tmpOutInt[0]); |
| 5072 | pw.println(" steps)"); |
| 5073 | } |
| 5074 | } |
| 5075 | } |
| 5076 | |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 5077 | private void dumpDailyPackageChanges(PrintWriter pw, String prefix, |
| 5078 | ArrayList<PackageChange> changes) { |
| 5079 | if (changes == null) { |
| 5080 | return; |
| 5081 | } |
| 5082 | pw.print(prefix); pw.println("Package changes:"); |
| 5083 | for (int i=0; i<changes.size(); i++) { |
| 5084 | PackageChange pc = changes.get(i); |
| 5085 | if (pc.mUpdate) { |
| 5086 | pw.print(prefix); pw.print(" Update "); pw.print(pc.mPackageName); |
| 5087 | pw.print(" vers="); pw.println(pc.mVersionCode); |
| 5088 | } else { |
| 5089 | pw.print(prefix); pw.print(" Uninstall "); pw.println(pc.mPackageName); |
| 5090 | } |
| 5091 | } |
| 5092 | } |
| 5093 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5094 | /** |
| 5095 | * Dumps a human-readable summary of the battery statistics to the given PrintWriter. |
| 5096 | * |
| 5097 | * @param pw a Printer to receive the dump output. |
| 5098 | */ |
| 5099 | @SuppressWarnings("unused") |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 5100 | 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] | 5101 | prepareForDumpLocked(); |
| 5102 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 5103 | final boolean filtering = (flags |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5104 | & (DUMP_HISTORY_ONLY|DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) != 0; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5105 | |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 5106 | if ((flags&DUMP_HISTORY_ONLY) != 0 || !filtering) { |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 5107 | final long historyTotalSize = getHistoryTotalSize(); |
| 5108 | final long historyUsedSize = getHistoryUsedSize(); |
| 5109 | if (startIteratingHistoryLocked()) { |
| 5110 | try { |
| 5111 | pw.print("Battery History ("); |
| 5112 | pw.print((100*historyUsedSize)/historyTotalSize); |
| 5113 | pw.print("% used, "); |
| 5114 | printSizeValue(pw, historyUsedSize); |
| 5115 | pw.print(" used of "); |
| 5116 | printSizeValue(pw, historyTotalSize); |
| 5117 | pw.print(", "); |
| 5118 | pw.print(getHistoryStringPoolSize()); |
| 5119 | pw.print(" strings using "); |
| 5120 | printSizeValue(pw, getHistoryStringPoolBytes()); |
| 5121 | pw.println("):"); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 5122 | dumpHistoryLocked(pw, flags, histStart, false); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 5123 | pw.println(); |
| 5124 | } finally { |
| 5125 | finishIteratingHistoryLocked(); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 5126 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 5127 | } |
| 5128 | |
| 5129 | if (startIteratingOldHistoryLocked()) { |
| 5130 | try { |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 5131 | final HistoryItem rec = new HistoryItem(); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 5132 | pw.println("Old battery History:"); |
| 5133 | HistoryPrinter hprinter = new HistoryPrinter(); |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 5134 | long baseTime = -1; |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 5135 | while (getNextOldHistoryLocked(rec)) { |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 5136 | if (baseTime < 0) { |
| 5137 | baseTime = rec.time; |
| 5138 | } |
| 5139 | hprinter.printNextItem(pw, rec, baseTime, false, (flags&DUMP_VERBOSE) != 0); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 5140 | } |
| 5141 | pw.println(); |
| 5142 | } finally { |
| 5143 | finishIteratingOldHistoryLocked(); |
| 5144 | } |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 5145 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5146 | } |
| 5147 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5148 | if (filtering && (flags&(DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) == 0) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 5149 | return; |
| 5150 | } |
| 5151 | |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 5152 | if (!filtering) { |
| 5153 | SparseArray<? extends Uid> uidStats = getUidStats(); |
| 5154 | final int NU = uidStats.size(); |
| 5155 | boolean didPid = false; |
| 5156 | long nowRealtime = SystemClock.elapsedRealtime(); |
| 5157 | for (int i=0; i<NU; i++) { |
| 5158 | Uid uid = uidStats.valueAt(i); |
| 5159 | SparseArray<? extends Uid.Pid> pids = uid.getPidStats(); |
| 5160 | if (pids != null) { |
| 5161 | for (int j=0; j<pids.size(); j++) { |
| 5162 | Uid.Pid pid = pids.valueAt(j); |
| 5163 | if (!didPid) { |
| 5164 | pw.println("Per-PID Stats:"); |
| 5165 | didPid = true; |
| 5166 | } |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 5167 | long time = pid.mWakeSumMs + (pid.mWakeNesting > 0 |
| 5168 | ? (nowRealtime - pid.mWakeStartMs) : 0); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 5169 | pw.print(" PID "); pw.print(pids.keyAt(j)); |
| 5170 | pw.print(" wake time: "); |
| 5171 | TimeUtils.formatDuration(time, pw); |
| 5172 | pw.println(""); |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 5173 | } |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 5174 | } |
| 5175 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 5176 | if (didPid) { |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 5177 | pw.println(); |
| 5178 | } |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 5179 | } |
| 5180 | |
| 5181 | if (!filtering || (flags&DUMP_CHARGED_ONLY) != 0) { |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 5182 | if (dumpDurationSteps(pw, " ", "Discharge step durations:", |
| 5183 | getDischargeLevelStepTracker(), false)) { |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 5184 | long timeRemaining = computeBatteryTimeRemaining(SystemClock.elapsedRealtime()); |
| 5185 | if (timeRemaining >= 0) { |
| 5186 | pw.print(" Estimated discharge time remaining: "); |
| 5187 | TimeUtils.formatDuration(timeRemaining / 1000, pw); |
| 5188 | pw.println(); |
| 5189 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 5190 | final LevelStepTracker steps = getDischargeLevelStepTracker(); |
| 5191 | for (int i=0; i< STEP_LEVEL_MODES_OF_INTEREST.length; i++) { |
| 5192 | dumpTimeEstimate(pw, " Estimated ", STEP_LEVEL_MODE_LABELS[i], " time: ", |
| 5193 | steps.computeTimeEstimate(STEP_LEVEL_MODES_OF_INTEREST[i], |
| 5194 | STEP_LEVEL_MODE_VALUES[i], null)); |
| 5195 | } |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 5196 | pw.println(); |
| 5197 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 5198 | if (dumpDurationSteps(pw, " ", "Charge step durations:", |
| 5199 | getChargeLevelStepTracker(), false)) { |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 5200 | long timeRemaining = computeChargeTimeRemaining(SystemClock.elapsedRealtime()); |
| 5201 | if (timeRemaining >= 0) { |
| 5202 | pw.print(" Estimated charge time remaining: "); |
| 5203 | TimeUtils.formatDuration(timeRemaining / 1000, pw); |
| 5204 | pw.println(); |
| 5205 | } |
| 5206 | pw.println(); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 5207 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 5208 | } |
| 5209 | if (!filtering || (flags&(DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) != 0) { |
| 5210 | pw.println("Daily stats:"); |
| 5211 | pw.print(" Current start time: "); |
| 5212 | pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss", |
| 5213 | getCurrentDailyStartTime()).toString()); |
| 5214 | pw.print(" Next min deadline: "); |
| 5215 | pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss", |
| 5216 | getNextMinDailyDeadline()).toString()); |
| 5217 | pw.print(" Next max deadline: "); |
| 5218 | pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss", |
| 5219 | getNextMaxDailyDeadline()).toString()); |
| 5220 | StringBuilder sb = new StringBuilder(64); |
| 5221 | int[] outInt = new int[1]; |
| 5222 | LevelStepTracker dsteps = getDailyDischargeLevelStepTracker(); |
| 5223 | LevelStepTracker csteps = getDailyChargeLevelStepTracker(); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 5224 | ArrayList<PackageChange> pkgc = getDailyPackageChanges(); |
| 5225 | if (dsteps.mNumStepDurations > 0 || csteps.mNumStepDurations > 0 || pkgc != null) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5226 | if ((flags&DUMP_DAILY_ONLY) != 0 || !filtering) { |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 5227 | if (dumpDurationSteps(pw, " ", " Current daily discharge step durations:", |
| 5228 | dsteps, false)) { |
| 5229 | dumpDailyLevelStepSummary(pw, " ", "Discharge", dsteps, |
| 5230 | sb, outInt); |
| 5231 | } |
| 5232 | if (dumpDurationSteps(pw, " ", " Current daily charge step durations:", |
| 5233 | csteps, false)) { |
| 5234 | dumpDailyLevelStepSummary(pw, " ", "Charge", csteps, |
| 5235 | sb, outInt); |
| 5236 | } |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 5237 | dumpDailyPackageChanges(pw, " ", pkgc); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 5238 | } else { |
| 5239 | pw.println(" Current daily steps:"); |
| 5240 | dumpDailyLevelStepSummary(pw, " ", "Discharge", dsteps, |
| 5241 | sb, outInt); |
| 5242 | dumpDailyLevelStepSummary(pw, " ", "Charge", csteps, |
| 5243 | sb, outInt); |
| 5244 | } |
| 5245 | } |
| 5246 | DailyItem dit; |
| 5247 | int curIndex = 0; |
| 5248 | while ((dit=getDailyItemLocked(curIndex)) != null) { |
| 5249 | curIndex++; |
| 5250 | if ((flags&DUMP_DAILY_ONLY) != 0) { |
| 5251 | pw.println(); |
| 5252 | } |
| 5253 | pw.print(" Daily from "); |
| 5254 | pw.print(DateFormat.format("yyyy-MM-dd-HH-mm-ss", dit.mStartTime).toString()); |
| 5255 | pw.print(" to "); |
| 5256 | pw.print(DateFormat.format("yyyy-MM-dd-HH-mm-ss", dit.mEndTime).toString()); |
| 5257 | pw.println(":"); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5258 | if ((flags&DUMP_DAILY_ONLY) != 0 || !filtering) { |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 5259 | if (dumpDurationSteps(pw, " ", |
| 5260 | " Discharge step durations:", dit.mDischargeSteps, false)) { |
| 5261 | dumpDailyLevelStepSummary(pw, " ", "Discharge", dit.mDischargeSteps, |
| 5262 | sb, outInt); |
| 5263 | } |
| 5264 | if (dumpDurationSteps(pw, " ", |
| 5265 | " Charge step durations:", dit.mChargeSteps, false)) { |
| 5266 | dumpDailyLevelStepSummary(pw, " ", "Charge", dit.mChargeSteps, |
| 5267 | sb, outInt); |
| 5268 | } |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 5269 | dumpDailyPackageChanges(pw, " ", dit.mPackageChanges); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 5270 | } else { |
| 5271 | dumpDailyLevelStepSummary(pw, " ", "Discharge", dit.mDischargeSteps, |
| 5272 | sb, outInt); |
| 5273 | dumpDailyLevelStepSummary(pw, " ", "Charge", dit.mChargeSteps, |
| 5274 | sb, outInt); |
| 5275 | } |
| 5276 | } |
| 5277 | pw.println(); |
| 5278 | } |
| 5279 | if (!filtering || (flags&DUMP_CHARGED_ONLY) != 0) { |
Jeff Sharkey | ec43a6b | 2013-04-30 13:33:18 -0700 | [diff] [blame] | 5280 | pw.println("Statistics since last charge:"); |
| 5281 | pw.println(" System starts: " + getStartCount() |
| 5282 | + ", currently on battery: " + getIsOnBattery()); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 5283 | dumpLocked(context, pw, "", STATS_SINCE_CHARGED, reqUid, |
| 5284 | (flags&DUMP_DEVICE_WIFI_ONLY) != 0); |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 5285 | pw.println(); |
Jeff Sharkey | ec43a6b | 2013-04-30 13:33:18 -0700 | [diff] [blame] | 5286 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5287 | } |
| 5288 | |
| 5289 | @SuppressWarnings("unused") |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 5290 | public void dumpCheckinLocked(Context context, PrintWriter pw, |
| 5291 | List<ApplicationInfo> apps, int flags, long histStart) { |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5292 | prepareForDumpLocked(); |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 5293 | |
| 5294 | dumpLine(pw, 0 /* uid */, "i" /* category */, VERSION_DATA, |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 5295 | CHECKIN_VERSION, getParcelVersion(), getStartPlatformVersion(), |
| 5296 | getEndPlatformVersion()); |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 5297 | |
Dianne Hackborn | 13ac041 | 2013-06-25 19:34:49 -0700 | [diff] [blame] | 5298 | long now = getHistoryBaseTime() + SystemClock.elapsedRealtime(); |
| 5299 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 5300 | final boolean filtering = (flags & |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5301 | (DUMP_HISTORY_ONLY|DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) != 0; |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 5302 | |
| 5303 | if ((flags&DUMP_INCLUDE_HISTORY) != 0 || (flags&DUMP_HISTORY_ONLY) != 0) { |
Dianne Hackborn | 49021f5 | 2013-09-04 18:03:40 -0700 | [diff] [blame] | 5304 | if (startIteratingHistoryLocked()) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 5305 | try { |
| 5306 | for (int i=0; i<getHistoryStringPoolSize(); i++) { |
| 5307 | pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(','); |
| 5308 | pw.print(HISTORY_STRING_POOL); pw.print(','); |
| 5309 | pw.print(i); |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 5310 | pw.print(","); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 5311 | pw.print(getHistoryTagPoolUid(i)); |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 5312 | pw.print(",\""); |
| 5313 | String str = getHistoryTagPoolString(i); |
| 5314 | str = str.replace("\\", "\\\\"); |
| 5315 | str = str.replace("\"", "\\\""); |
| 5316 | pw.print(str); |
| 5317 | pw.print("\""); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 5318 | pw.println(); |
| 5319 | } |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 5320 | dumpHistoryLocked(pw, flags, histStart, true); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 5321 | } finally { |
| 5322 | finishIteratingHistoryLocked(); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 5323 | } |
Dianne Hackborn | 13ac041 | 2013-06-25 19:34:49 -0700 | [diff] [blame] | 5324 | } |
Dianne Hackborn | 13ac041 | 2013-06-25 19:34:49 -0700 | [diff] [blame] | 5325 | } |
| 5326 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5327 | if (filtering && (flags&(DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) == 0) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 5328 | return; |
| 5329 | } |
| 5330 | |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 5331 | if (apps != null) { |
Dianne Hackborn | 9cfba35 | 2016-03-24 17:31:28 -0700 | [diff] [blame] | 5332 | SparseArray<Pair<ArrayList<String>, MutableBoolean>> uids = new SparseArray<>(); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 5333 | for (int i=0; i<apps.size(); i++) { |
| 5334 | ApplicationInfo ai = apps.get(i); |
Dianne Hackborn | 9cfba35 | 2016-03-24 17:31:28 -0700 | [diff] [blame] | 5335 | Pair<ArrayList<String>, MutableBoolean> pkgs = uids.get( |
| 5336 | UserHandle.getAppId(ai.uid)); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 5337 | if (pkgs == null) { |
Dianne Hackborn | 9cfba35 | 2016-03-24 17:31:28 -0700 | [diff] [blame] | 5338 | pkgs = new Pair<>(new ArrayList<String>(), new MutableBoolean(false)); |
| 5339 | uids.put(UserHandle.getAppId(ai.uid), pkgs); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 5340 | } |
Dianne Hackborn | 9cfba35 | 2016-03-24 17:31:28 -0700 | [diff] [blame] | 5341 | pkgs.first.add(ai.packageName); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 5342 | } |
| 5343 | SparseArray<? extends Uid> uidStats = getUidStats(); |
| 5344 | final int NU = uidStats.size(); |
| 5345 | String[] lineArgs = new String[2]; |
| 5346 | for (int i=0; i<NU; i++) { |
Dianne Hackborn | 9cfba35 | 2016-03-24 17:31:28 -0700 | [diff] [blame] | 5347 | int uid = UserHandle.getAppId(uidStats.keyAt(i)); |
| 5348 | Pair<ArrayList<String>, MutableBoolean> pkgs = uids.get(uid); |
| 5349 | if (pkgs != null && !pkgs.second.value) { |
| 5350 | pkgs.second.value = true; |
| 5351 | for (int j=0; j<pkgs.first.size(); j++) { |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 5352 | lineArgs[0] = Integer.toString(uid); |
Dianne Hackborn | 9cfba35 | 2016-03-24 17:31:28 -0700 | [diff] [blame] | 5353 | lineArgs[1] = pkgs.first.get(j); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 5354 | dumpLine(pw, 0 /* uid */, "i" /* category */, UID_DATA, |
| 5355 | (Object[])lineArgs); |
| 5356 | } |
| 5357 | } |
| 5358 | } |
| 5359 | } |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 5360 | if (!filtering || (flags&DUMP_CHARGED_ONLY) != 0) { |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 5361 | dumpDurationSteps(pw, "", DISCHARGE_STEP_DATA, getDischargeLevelStepTracker(), true); |
Dianne Hackborn | d06dcfd | 2014-05-02 13:49:30 -0700 | [diff] [blame] | 5362 | String[] lineArgs = new String[1]; |
| 5363 | long timeRemaining = computeBatteryTimeRemaining(SystemClock.elapsedRealtime()); |
| 5364 | if (timeRemaining >= 0) { |
| 5365 | lineArgs[0] = Long.toString(timeRemaining); |
| 5366 | dumpLine(pw, 0 /* uid */, "i" /* category */, DISCHARGE_TIME_REMAIN_DATA, |
| 5367 | (Object[])lineArgs); |
| 5368 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 5369 | dumpDurationSteps(pw, "", CHARGE_STEP_DATA, getChargeLevelStepTracker(), true); |
Dianne Hackborn | d06dcfd | 2014-05-02 13:49:30 -0700 | [diff] [blame] | 5370 | timeRemaining = computeChargeTimeRemaining(SystemClock.elapsedRealtime()); |
| 5371 | if (timeRemaining >= 0) { |
| 5372 | lineArgs[0] = Long.toString(timeRemaining); |
| 5373 | dumpLine(pw, 0 /* uid */, "i" /* category */, CHARGE_TIME_REMAIN_DATA, |
| 5374 | (Object[])lineArgs); |
| 5375 | } |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 5376 | dumpCheckinLocked(context, pw, STATS_SINCE_CHARGED, -1, |
| 5377 | (flags&DUMP_DEVICE_WIFI_ONLY) != 0); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 5378 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5379 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5380 | } |