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