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; |
James Carr | 2dd7e5e | 2016-07-20 18:48:39 -0700 | [diff] [blame] | 33 | import android.util.LongSparseArray; |
Dianne Hackborn | 9cfba35 | 2016-03-24 17:31:28 -0700 | [diff] [blame] | 34 | import android.util.MutableBoolean; |
| 35 | import android.util.Pair; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 36 | import android.util.Printer; |
| 37 | import android.util.SparseArray; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 38 | import android.util.SparseIntArray; |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 39 | import android.util.TimeUtils; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 40 | import android.view.Display; |
Amith Yamasani | ab9ad19 | 2016-12-06 12:46:59 -0800 | [diff] [blame] | 41 | |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 42 | import com.android.internal.os.BatterySipper; |
| 43 | import com.android.internal.os.BatteryStatsHelper; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 44 | |
| 45 | /** |
| 46 | * A class providing access to battery usage statistics, including information on |
| 47 | * wakelocks, processes, packages, and services. All times are represented in microseconds |
| 48 | * except where indicated otherwise. |
| 49 | * @hide |
| 50 | */ |
| 51 | public abstract class BatteryStats implements Parcelable { |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 52 | private static final String TAG = "BatteryStats"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 53 | |
| 54 | private static final boolean LOCAL_LOGV = false; |
Dianne Hackborn | 91268cf | 2013-06-13 19:06:50 -0700 | [diff] [blame] | 55 | |
| 56 | /** @hide */ |
| 57 | public static final String SERVICE_NAME = "batterystats"; |
| 58 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 59 | /** |
| 60 | * A constant indicating a partial wake lock timer. |
| 61 | */ |
| 62 | public static final int WAKE_TYPE_PARTIAL = 0; |
| 63 | |
| 64 | /** |
| 65 | * A constant indicating a full wake lock timer. |
| 66 | */ |
| 67 | public static final int WAKE_TYPE_FULL = 1; |
| 68 | |
| 69 | /** |
| 70 | * A constant indicating a window wake lock timer. |
| 71 | */ |
| 72 | public static final int WAKE_TYPE_WINDOW = 2; |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 73 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 74 | /** |
| 75 | * A constant indicating a sensor timer. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 76 | */ |
| 77 | public static final int SENSOR = 3; |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 78 | |
| 79 | /** |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 80 | * A constant indicating a a wifi running timer |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 81 | */ |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 82 | public static final int WIFI_RUNNING = 4; |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 83 | |
| 84 | /** |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 85 | * A constant indicating a full wifi lock timer |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 86 | */ |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 87 | public static final int FULL_WIFI_LOCK = 5; |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 88 | |
| 89 | /** |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 90 | * A constant indicating a wifi scan |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 91 | */ |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 92 | public static final int WIFI_SCAN = 6; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 93 | |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 94 | /** |
| 95 | * A constant indicating a wifi multicast timer |
| 96 | */ |
| 97 | public static final int WIFI_MULTICAST_ENABLED = 7; |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 98 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 99 | /** |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 100 | * A constant indicating a video turn on timer |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 101 | */ |
| 102 | public static final int VIDEO_TURNED_ON = 8; |
| 103 | |
| 104 | /** |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 105 | * A constant indicating a vibrator on timer |
| 106 | */ |
| 107 | public static final int VIBRATOR_ON = 9; |
| 108 | |
| 109 | /** |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 110 | * A constant indicating a foreground activity timer |
| 111 | */ |
| 112 | public static final int FOREGROUND_ACTIVITY = 10; |
| 113 | |
| 114 | /** |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 115 | * A constant indicating a wifi batched scan is active |
| 116 | */ |
| 117 | public static final int WIFI_BATCHED_SCAN = 11; |
| 118 | |
| 119 | /** |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 120 | * A constant indicating a process state timer |
| 121 | */ |
| 122 | public static final int PROCESS_STATE = 12; |
| 123 | |
| 124 | /** |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 125 | * A constant indicating a sync timer |
| 126 | */ |
| 127 | public static final int SYNC = 13; |
| 128 | |
| 129 | /** |
| 130 | * A constant indicating a job timer |
| 131 | */ |
| 132 | public static final int JOB = 14; |
| 133 | |
| 134 | /** |
Kweku Adams | d537987 | 2014-11-24 17:34:05 -0800 | [diff] [blame] | 135 | * A constant indicating an audio turn on timer |
| 136 | */ |
| 137 | public static final int AUDIO_TURNED_ON = 15; |
| 138 | |
| 139 | /** |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 140 | * A constant indicating a flashlight turn on timer |
| 141 | */ |
| 142 | public static final int FLASHLIGHT_TURNED_ON = 16; |
| 143 | |
| 144 | /** |
| 145 | * A constant indicating a camera turn on timer |
| 146 | */ |
| 147 | public static final int CAMERA_TURNED_ON = 17; |
| 148 | |
| 149 | /** |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 150 | * A constant indicating a draw wake lock timer. |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 151 | */ |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 152 | public static final int WAKE_TYPE_DRAW = 18; |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 153 | |
| 154 | /** |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 155 | * A constant indicating a bluetooth scan timer. |
| 156 | */ |
| 157 | public static final int BLUETOOTH_SCAN_ON = 19; |
| 158 | |
| 159 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 160 | * Include all of the data in the stats, including previously saved data. |
| 161 | */ |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 162 | public static final int STATS_SINCE_CHARGED = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 163 | |
| 164 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 165 | * Include only the current run in the stats. |
| 166 | */ |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 167 | public static final int STATS_CURRENT = 1; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 168 | |
| 169 | /** |
| 170 | * Include only the run since the last time the device was unplugged in the stats. |
| 171 | */ |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 172 | public static final int STATS_SINCE_UNPLUGGED = 2; |
Evan Millar | e84de8d | 2009-04-02 22:16:12 -0700 | [diff] [blame] | 173 | |
| 174 | // NOTE: Update this list if you add/change any stats above. |
| 175 | // These characters are supposed to represent "total", "last", "current", |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 176 | // and "unplugged". They were shortened for efficiency sake. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 177 | private static final String[] STAT_NAMES = { "l", "c", "u" }; |
| 178 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 179 | /** |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 180 | * Current version of checkin data format. |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 181 | * |
| 182 | * New in version 19: |
| 183 | * - Wakelock data (wl) gets current and max times. |
Amith Yamasani | ab9ad19 | 2016-12-06 12:46:59 -0800 | [diff] [blame] | 184 | * New in version 20: |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame^] | 185 | * - Background timers and counters for: Sensor, BluetoothScan, WifiScan, Jobs. |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 186 | */ |
Kweku Adams | 47db5a8 | 2016-12-09 19:04:50 -0800 | [diff] [blame] | 187 | static final String CHECKIN_VERSION = "20"; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 188 | |
| 189 | /** |
| 190 | * 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] | 191 | */ |
Ashish Sharma | 213bb2f | 2014-07-07 17:14:52 -0700 | [diff] [blame] | 192 | private static final int BATTERY_STATS_CHECKIN_VERSION = 9; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 193 | |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 194 | private static final long BYTES_PER_KB = 1024; |
| 195 | private static final long BYTES_PER_MB = 1048576; // 1024^2 |
| 196 | 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] | 197 | |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 198 | private static final String VERSION_DATA = "vers"; |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 199 | private static final String UID_DATA = "uid"; |
Joe Onorato | 1476d32 | 2016-05-05 14:46:15 -0700 | [diff] [blame] | 200 | private static final String WAKEUP_ALARM_DATA = "wua"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 201 | private static final String APK_DATA = "apk"; |
Evan Millar | e84de8d | 2009-04-02 22:16:12 -0700 | [diff] [blame] | 202 | private static final String PROCESS_DATA = "pr"; |
Adam Lesinski | a7a4ccc | 2015-06-26 17:43:04 -0700 | [diff] [blame] | 203 | private static final String CPU_DATA = "cpu"; |
Evan Millar | e84de8d | 2009-04-02 22:16:12 -0700 | [diff] [blame] | 204 | private static final String SENSOR_DATA = "sr"; |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 205 | private static final String VIBRATOR_DATA = "vib"; |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 206 | private static final String FOREGROUND_DATA = "fg"; |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 207 | private static final String STATE_TIME_DATA = "st"; |
Evan Millar | e84de8d | 2009-04-02 22:16:12 -0700 | [diff] [blame] | 208 | private static final String WAKELOCK_DATA = "wl"; |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 209 | private static final String SYNC_DATA = "sy"; |
| 210 | private static final String JOB_DATA = "jb"; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 211 | private static final String KERNEL_WAKELOCK_DATA = "kwl"; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 212 | private static final String WAKEUP_REASON_DATA = "wr"; |
Evan Millar | e84de8d | 2009-04-02 22:16:12 -0700 | [diff] [blame] | 213 | private static final String NETWORK_DATA = "nt"; |
| 214 | private static final String USER_ACTIVITY_DATA = "ua"; |
| 215 | private static final String BATTERY_DATA = "bt"; |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 216 | private static final String BATTERY_DISCHARGE_DATA = "dc"; |
Evan Millar | e84de8d | 2009-04-02 22:16:12 -0700 | [diff] [blame] | 217 | private static final String BATTERY_LEVEL_DATA = "lv"; |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 218 | private static final String GLOBAL_WIFI_DATA = "gwfl"; |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 219 | private static final String WIFI_DATA = "wfl"; |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 220 | private static final String GLOBAL_WIFI_CONTROLLER_DATA = "gwfcd"; |
| 221 | private static final String WIFI_CONTROLLER_DATA = "wfcd"; |
| 222 | private static final String GLOBAL_BLUETOOTH_CONTROLLER_DATA = "gble"; |
| 223 | private static final String BLUETOOTH_CONTROLLER_DATA = "ble"; |
Adam Lesinski | d9b99be | 2016-03-30 16:58:51 -0700 | [diff] [blame] | 224 | private static final String BLUETOOTH_MISC_DATA = "blem"; |
Evan Millar | e84de8d | 2009-04-02 22:16:12 -0700 | [diff] [blame] | 225 | private static final String MISC_DATA = "m"; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 226 | private static final String GLOBAL_NETWORK_DATA = "gn"; |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 227 | private static final String GLOBAL_MODEM_CONTROLLER_DATA = "gmcd"; |
| 228 | private static final String MODEM_CONTROLLER_DATA = "mcd"; |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 229 | private static final String HISTORY_STRING_POOL = "hsp"; |
Dianne Hackborn | 8a0de58 | 2013-08-07 15:22:07 -0700 | [diff] [blame] | 230 | private static final String HISTORY_DATA = "h"; |
Evan Millar | e84de8d | 2009-04-02 22:16:12 -0700 | [diff] [blame] | 231 | private static final String SCREEN_BRIGHTNESS_DATA = "br"; |
| 232 | private static final String SIGNAL_STRENGTH_TIME_DATA = "sgt"; |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 233 | private static final String SIGNAL_SCANNING_TIME_DATA = "sst"; |
Evan Millar | e84de8d | 2009-04-02 22:16:12 -0700 | [diff] [blame] | 234 | private static final String SIGNAL_STRENGTH_COUNT_DATA = "sgc"; |
| 235 | private static final String DATA_CONNECTION_TIME_DATA = "dct"; |
| 236 | private static final String DATA_CONNECTION_COUNT_DATA = "dcc"; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 237 | private static final String WIFI_STATE_TIME_DATA = "wst"; |
| 238 | private static final String WIFI_STATE_COUNT_DATA = "wsc"; |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 239 | private static final String WIFI_SUPPL_STATE_TIME_DATA = "wsst"; |
| 240 | private static final String WIFI_SUPPL_STATE_COUNT_DATA = "wssc"; |
| 241 | private static final String WIFI_SIGNAL_STRENGTH_TIME_DATA = "wsgt"; |
| 242 | private static final String WIFI_SIGNAL_STRENGTH_COUNT_DATA = "wsgc"; |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 243 | private static final String POWER_USE_SUMMARY_DATA = "pws"; |
| 244 | private static final String POWER_USE_ITEM_DATA = "pwi"; |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 245 | private static final String DISCHARGE_STEP_DATA = "dsd"; |
| 246 | private static final String CHARGE_STEP_DATA = "csd"; |
Dianne Hackborn | d06dcfd | 2014-05-02 13:49:30 -0700 | [diff] [blame] | 247 | private static final String DISCHARGE_TIME_REMAIN_DATA = "dtr"; |
| 248 | private static final String CHARGE_TIME_REMAIN_DATA = "ctr"; |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 249 | private static final String FLASHLIGHT_DATA = "fla"; |
| 250 | private static final String CAMERA_DATA = "cam"; |
| 251 | private static final String VIDEO_DATA = "vid"; |
| 252 | private static final String AUDIO_DATA = "aud"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 253 | |
Adam Lesinski | 010bf37 | 2016-04-11 12:18:18 -0700 | [diff] [blame] | 254 | public static final String RESULT_RECEIVER_CONTROLLER_KEY = "controller_activity"; |
| 255 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 256 | private final StringBuilder mFormatBuilder = new StringBuilder(32); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 257 | private final Formatter mFormatter = new Formatter(mFormatBuilder); |
| 258 | |
| 259 | /** |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 260 | * State for keeping track of counting information. |
| 261 | */ |
| 262 | public static abstract class Counter { |
| 263 | |
| 264 | /** |
| 265 | * Returns the count associated with this Counter for the |
| 266 | * selected type of statistics. |
| 267 | * |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 268 | * @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] | 269 | */ |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 270 | public abstract int getCountLocked(int which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 271 | |
| 272 | /** |
| 273 | * Temporary for debugging. |
| 274 | */ |
| 275 | public abstract void logState(Printer pw, String prefix); |
| 276 | } |
| 277 | |
| 278 | /** |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 279 | * State for keeping track of long counting information. |
| 280 | */ |
| 281 | public static abstract class LongCounter { |
| 282 | |
| 283 | /** |
| 284 | * Returns the count associated with this Counter for the |
| 285 | * selected type of statistics. |
| 286 | * |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 287 | * @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] | 288 | */ |
| 289 | public abstract long getCountLocked(int which); |
| 290 | |
| 291 | /** |
| 292 | * Temporary for debugging. |
| 293 | */ |
| 294 | public abstract void logState(Printer pw, String prefix); |
| 295 | } |
| 296 | |
| 297 | /** |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 298 | * Container class that aggregates counters for transmit, receive, and idle state of a |
| 299 | * radio controller. |
| 300 | */ |
| 301 | public static abstract class ControllerActivityCounter { |
| 302 | /** |
| 303 | * @return a non-null {@link LongCounter} representing time spent (milliseconds) in the |
| 304 | * idle state. |
| 305 | */ |
| 306 | public abstract LongCounter getIdleTimeCounter(); |
| 307 | |
| 308 | /** |
| 309 | * @return a non-null {@link LongCounter} representing time spent (milliseconds) in the |
| 310 | * receive state. |
| 311 | */ |
| 312 | public abstract LongCounter getRxTimeCounter(); |
| 313 | |
| 314 | /** |
| 315 | * An array of {@link LongCounter}, representing various transmit levels, where each level |
| 316 | * may draw a different amount of power. The levels themselves are controller-specific. |
| 317 | * @return non-null array of {@link LongCounter}s representing time spent (milliseconds) in |
| 318 | * various transmit level states. |
| 319 | */ |
| 320 | public abstract LongCounter[] getTxTimeCounters(); |
| 321 | |
| 322 | /** |
| 323 | * @return a non-null {@link LongCounter} representing the power consumed by the controller |
| 324 | * in all states, measured in milli-ampere-milliseconds (mAms). The counter may always |
| 325 | * yield a value of 0 if the device doesn't support power calculations. |
| 326 | */ |
| 327 | public abstract LongCounter getPowerCounter(); |
| 328 | } |
| 329 | |
| 330 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 331 | * State for keeping track of timing information. |
| 332 | */ |
| 333 | public static abstract class Timer { |
| 334 | |
| 335 | /** |
| 336 | * Returns the count associated with this Timer for the |
| 337 | * selected type of statistics. |
| 338 | * |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 339 | * @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] | 340 | */ |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 341 | public abstract int getCountLocked(int which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 342 | |
| 343 | /** |
| 344 | * Returns the total time in microseconds associated with this Timer for the |
| 345 | * selected type of statistics. |
| 346 | * |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 347 | * @param elapsedRealtimeUs current elapsed realtime of system in microseconds |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 348 | * @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] | 349 | * @return a time in microseconds |
| 350 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 351 | public abstract long getTotalTimeLocked(long elapsedRealtimeUs, int which); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 352 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 353 | /** |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 354 | * Returns the total time in microseconds associated with this Timer since the |
| 355 | * 'mark' was last set. |
| 356 | * |
| 357 | * @param elapsedRealtimeUs current elapsed realtime of system in microseconds |
| 358 | * @return a time in microseconds |
| 359 | */ |
| 360 | public abstract long getTimeSinceMarkLocked(long elapsedRealtimeUs); |
| 361 | |
| 362 | /** |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 363 | * Returns the max duration if it is being tracked. |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 364 | * Not all Timer subclasses track the max, total, current durations. |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 365 | |
| 366 | */ |
| 367 | public long getMaxDurationMsLocked(long elapsedRealtimeMs) { |
| 368 | return -1; |
| 369 | } |
| 370 | |
| 371 | /** |
| 372 | * Returns the current time the timer has been active, if it is being tracked. |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 373 | * Not all Timer subclasses track the max, total, current durations. |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 374 | */ |
| 375 | public long getCurrentDurationMsLocked(long elapsedRealtimeMs) { |
| 376 | return -1; |
| 377 | } |
| 378 | |
| 379 | /** |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 380 | * Returns the current time the timer has been active, if it is being tracked. |
| 381 | * |
| 382 | * Returns the total cumulative duration (i.e. sum of past durations) that this timer has |
| 383 | * been on since reset. |
| 384 | * This may differ from getTotalTimeLocked(elapsedRealtimeUs, STATS_SINCE_CHARGED)/1000 since, |
| 385 | * depending on the Timer, getTotalTimeLocked may represent the total 'blamed' or 'pooled' |
| 386 | * time, rather than the actual time. By contrast, getTotalDurationMsLocked always gives |
| 387 | * the actual total time. |
| 388 | * Not all Timer subclasses track the max, total, current durations. |
| 389 | */ |
| 390 | public long getTotalDurationMsLocked(long elapsedRealtimeMs) { |
| 391 | return -1; |
| 392 | } |
| 393 | |
| 394 | /** |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame^] | 395 | * Returns the secondary Timer held by the Timer, if one exists. This secondary timer may be |
| 396 | * used, for example, for tracking background usage. Secondary timers are never pooled. |
| 397 | * |
| 398 | * Not all Timer subclasses have a secondary timer; those that don't return null. |
| 399 | */ |
| 400 | public Timer getSubTimer() { |
| 401 | return null; |
| 402 | } |
| 403 | |
| 404 | /** |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 405 | * Returns whether the timer is currently running. Some types of timers |
| 406 | * (e.g. BatchTimers) don't know whether the event is currently active, |
| 407 | * and report false. |
| 408 | */ |
| 409 | public boolean isRunningLocked() { |
| 410 | return false; |
| 411 | } |
| 412 | |
| 413 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 414 | * Temporary for debugging. |
| 415 | */ |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 416 | public abstract void logState(Printer pw, String prefix); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 417 | } |
| 418 | |
| 419 | /** |
| 420 | * The statistics associated with a particular uid. |
| 421 | */ |
| 422 | public static abstract class Uid { |
| 423 | |
| 424 | /** |
| 425 | * Returns a mapping containing wakelock statistics. |
| 426 | * |
| 427 | * @return a Map from Strings to Uid.Wakelock objects. |
| 428 | */ |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 429 | public abstract ArrayMap<String, ? extends Wakelock> getWakelockStats(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 430 | |
| 431 | /** |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 432 | * Returns a mapping containing sync statistics. |
| 433 | * |
| 434 | * @return a Map from Strings to Timer objects. |
| 435 | */ |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 436 | public abstract ArrayMap<String, ? extends Timer> getSyncStats(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 437 | |
| 438 | /** |
| 439 | * Returns a mapping containing scheduled job statistics. |
| 440 | * |
| 441 | * @return a Map from Strings to Timer objects. |
| 442 | */ |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 443 | public abstract ArrayMap<String, ? extends Timer> getJobStats(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 444 | |
| 445 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 446 | * The statistics associated with a particular wake lock. |
| 447 | */ |
| 448 | public static abstract class Wakelock { |
| 449 | public abstract Timer getWakeTime(int type); |
| 450 | } |
| 451 | |
| 452 | /** |
| 453 | * Returns a mapping containing sensor statistics. |
| 454 | * |
| 455 | * @return a Map from Integer sensor ids to Uid.Sensor objects. |
| 456 | */ |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 457 | public abstract SparseArray<? extends Sensor> getSensorStats(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 458 | |
| 459 | /** |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 460 | * Returns a mapping containing active process data. |
| 461 | */ |
| 462 | public abstract SparseArray<? extends Pid> getPidStats(); |
| 463 | |
| 464 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 465 | * Returns a mapping containing process statistics. |
| 466 | * |
| 467 | * @return a Map from Strings to Uid.Proc objects. |
| 468 | */ |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 469 | public abstract ArrayMap<String, ? extends Proc> getProcessStats(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 470 | |
| 471 | /** |
| 472 | * Returns a mapping containing package statistics. |
| 473 | * |
| 474 | * @return a Map from Strings to Uid.Pkg objects. |
| 475 | */ |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 476 | public abstract ArrayMap<String, ? extends Pkg> getPackageStats(); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 477 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 478 | public abstract ControllerActivityCounter getWifiControllerActivity(); |
| 479 | public abstract ControllerActivityCounter getBluetoothControllerActivity(); |
| 480 | public abstract ControllerActivityCounter getModemControllerActivity(); |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 481 | |
| 482 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 483 | * {@hide} |
| 484 | */ |
| 485 | public abstract int getUid(); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 486 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 487 | public abstract void noteWifiRunningLocked(long elapsedRealtime); |
| 488 | public abstract void noteWifiStoppedLocked(long elapsedRealtime); |
| 489 | public abstract void noteFullWifiLockAcquiredLocked(long elapsedRealtime); |
| 490 | public abstract void noteFullWifiLockReleasedLocked(long elapsedRealtime); |
| 491 | public abstract void noteWifiScanStartedLocked(long elapsedRealtime); |
| 492 | public abstract void noteWifiScanStoppedLocked(long elapsedRealtime); |
| 493 | public abstract void noteWifiBatchedScanStartedLocked(int csph, long elapsedRealtime); |
| 494 | public abstract void noteWifiBatchedScanStoppedLocked(long elapsedRealtime); |
| 495 | public abstract void noteWifiMulticastEnabledLocked(long elapsedRealtime); |
| 496 | public abstract void noteWifiMulticastDisabledLocked(long elapsedRealtime); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 497 | public abstract void noteActivityResumedLocked(long elapsedRealtime); |
| 498 | public abstract void noteActivityPausedLocked(long elapsedRealtime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 499 | public abstract long getWifiRunningTime(long elapsedRealtimeUs, int which); |
| 500 | public abstract long getFullWifiLockTime(long elapsedRealtimeUs, int which); |
| 501 | public abstract long getWifiScanTime(long elapsedRealtimeUs, int which); |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 502 | public abstract int getWifiScanCount(int which); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 503 | public abstract int getWifiScanBackgroundCount(int which); |
| 504 | public abstract long getWifiScanActualTime(long elapsedRealtimeUs); |
| 505 | public abstract long getWifiScanBackgroundTime(long elapsedRealtimeUs); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 506 | public abstract long getWifiBatchedScanTime(int csphBin, long elapsedRealtimeUs, int which); |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 507 | public abstract int getWifiBatchedScanCount(int csphBin, int which); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 508 | public abstract long getWifiMulticastTime(long elapsedRealtimeUs, int which); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 509 | public abstract Timer getAudioTurnedOnTimer(); |
| 510 | public abstract Timer getVideoTurnedOnTimer(); |
| 511 | public abstract Timer getFlashlightTurnedOnTimer(); |
| 512 | public abstract Timer getCameraTurnedOnTimer(); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 513 | public abstract Timer getForegroundActivityTimer(); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 514 | public abstract Timer getBluetoothScanTimer(); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 515 | public abstract Timer getBluetoothScanBackgroundTimer(); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 516 | |
Dianne Hackborn | a0200e3 | 2016-03-30 18:01:41 -0700 | [diff] [blame] | 517 | // Note: the following times are disjoint. They can be added together to find the |
| 518 | // total time a uid has had any processes running at all. |
| 519 | |
| 520 | /** |
| 521 | * Time this uid has any processes in the top state (or above such as persistent). |
| 522 | */ |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 523 | public static final int PROCESS_STATE_TOP = 0; |
Dianne Hackborn | a0200e3 | 2016-03-30 18:01:41 -0700 | [diff] [blame] | 524 | /** |
| 525 | * Time this uid has any process with a started out bound foreground service, but |
| 526 | * none in the "top" state. |
| 527 | */ |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 528 | public static final int PROCESS_STATE_FOREGROUND_SERVICE = 1; |
Dianne Hackborn | a0200e3 | 2016-03-30 18:01:41 -0700 | [diff] [blame] | 529 | /** |
| 530 | * Time this uid has any process that is top while the device is sleeping, but none |
| 531 | * in the "foreground service" or better state. |
| 532 | */ |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 533 | public static final int PROCESS_STATE_TOP_SLEEPING = 2; |
Dianne Hackborn | a0200e3 | 2016-03-30 18:01:41 -0700 | [diff] [blame] | 534 | /** |
| 535 | * Time this uid has any process in an active foreground state, but none in the |
| 536 | * "top sleeping" or better state. |
| 537 | */ |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 538 | public static final int PROCESS_STATE_FOREGROUND = 3; |
Dianne Hackborn | a0200e3 | 2016-03-30 18:01:41 -0700 | [diff] [blame] | 539 | /** |
| 540 | * Time this uid has any process in an active background state, but none in the |
| 541 | * "foreground" or better state. |
| 542 | */ |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 543 | public static final int PROCESS_STATE_BACKGROUND = 4; |
Dianne Hackborn | a0200e3 | 2016-03-30 18:01:41 -0700 | [diff] [blame] | 544 | /** |
| 545 | * Time this uid has any processes that are sitting around cached, not in one of the |
| 546 | * other active states. |
| 547 | */ |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 548 | public static final int PROCESS_STATE_CACHED = 5; |
Dianne Hackborn | a0200e3 | 2016-03-30 18:01:41 -0700 | [diff] [blame] | 549 | /** |
| 550 | * Total number of process states we track. |
| 551 | */ |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 552 | public static final int NUM_PROCESS_STATE = 6; |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 553 | |
| 554 | static final String[] PROCESS_STATE_NAMES = { |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 555 | "Top", "Fg Service", "Top Sleeping", "Foreground", "Background", "Cached" |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 556 | }; |
| 557 | |
| 558 | public abstract long getProcessStateTime(int state, long elapsedRealtimeUs, int which); |
Joe Onorato | 713fec8 | 2016-03-04 10:34:02 -0800 | [diff] [blame] | 559 | public abstract Timer getProcessStateTimer(int state); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 560 | |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 561 | public abstract Timer getVibratorOnTimer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 562 | |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 563 | public static final int NUM_WIFI_BATCHED_SCAN_BINS = 5; |
| 564 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 565 | /** |
Jeff Brown | df693de | 2012-07-27 12:03:38 -0700 | [diff] [blame] | 566 | * Note that these must match the constants in android.os.PowerManager. |
| 567 | * Also, if the user activity types change, the BatteryStatsImpl.VERSION must |
| 568 | * also be bumped. |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 569 | */ |
| 570 | static final String[] USER_ACTIVITY_TYPES = { |
Phil Weaver | da80d67 | 2016-03-15 16:25:46 -0700 | [diff] [blame] | 571 | "other", "button", "touch", "accessibility" |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 572 | }; |
| 573 | |
Phil Weaver | da80d67 | 2016-03-15 16:25:46 -0700 | [diff] [blame] | 574 | public static final int NUM_USER_ACTIVITY_TYPES = 4; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 575 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 576 | public abstract void noteUserActivityLocked(int type); |
| 577 | public abstract boolean hasUserActivity(); |
| 578 | public abstract int getUserActivityCount(int type, int which); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 579 | |
| 580 | public abstract boolean hasNetworkActivity(); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 581 | public abstract long getNetworkActivityBytes(int type, int which); |
| 582 | public abstract long getNetworkActivityPackets(int type, int which); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 583 | public abstract long getMobileRadioActiveTime(int which); |
| 584 | public abstract int getMobileRadioActiveCount(int which); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 585 | |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 586 | /** |
| 587 | * Get the total cpu time (in microseconds) this UID had processes executing in userspace. |
| 588 | */ |
| 589 | public abstract long getUserCpuTimeUs(int which); |
| 590 | |
| 591 | /** |
| 592 | * Get the total cpu time (in microseconds) this UID had processes executing kernel syscalls. |
| 593 | */ |
| 594 | public abstract long getSystemCpuTimeUs(int which); |
| 595 | |
| 596 | /** |
Adam Lesinski | a7a4ccc | 2015-06-26 17:43:04 -0700 | [diff] [blame] | 597 | * Get the total cpu power consumed (in milli-ampere-microseconds). |
| 598 | */ |
| 599 | public abstract long getCpuPowerMaUs(int which); |
| 600 | |
| 601 | /** |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 602 | * Returns the approximate cpu time (in milliseconds) spent at a certain CPU speed for a |
| 603 | * given CPU cluster. |
| 604 | * @param cluster the index of the CPU cluster. |
Adam Lesinski | a7a4ccc | 2015-06-26 17:43:04 -0700 | [diff] [blame] | 605 | * @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] | 606 | * @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] | 607 | * @see com.android.internal.os.PowerProfile#getNumCpuClusters() |
| 608 | * @see com.android.internal.os.PowerProfile#getNumSpeedStepsInCpuCluster(int) |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 609 | */ |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 610 | public abstract long getTimeAtCpuSpeed(int cluster, int step, int which); |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 611 | |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 612 | /** |
| 613 | * Returns the number of times this UID woke up the Application Processor to |
| 614 | * process a mobile radio packet. |
| 615 | * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT. |
| 616 | */ |
| 617 | public abstract long getMobileRadioApWakeupCount(int which); |
| 618 | |
| 619 | /** |
| 620 | * Returns the number of times this UID woke up the Application Processor to |
| 621 | * process a WiFi packet. |
| 622 | * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT. |
| 623 | */ |
| 624 | public abstract long getWifiRadioApWakeupCount(int which); |
| 625 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 626 | public static abstract class Sensor { |
Mathias Agopian | 7f84c06 | 2013-02-04 19:22:47 -0800 | [diff] [blame] | 627 | /* |
| 628 | * FIXME: it's not correct to use this magic value because it |
| 629 | * could clash with a sensor handle (which are defined by |
| 630 | * the sensor HAL, and therefore out of our control |
| 631 | */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 632 | // Magic sensor number for the GPS. |
| 633 | public static final int GPS = -10000; |
Amith Yamasani | ab9ad19 | 2016-12-06 12:46:59 -0800 | [diff] [blame] | 634 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 635 | public abstract int getHandle(); |
Amith Yamasani | ab9ad19 | 2016-12-06 12:46:59 -0800 | [diff] [blame] | 636 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 637 | public abstract Timer getSensorTime(); |
Amith Yamasani | ab9ad19 | 2016-12-06 12:46:59 -0800 | [diff] [blame] | 638 | |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 639 | /** Returns a Timer for sensor usage when app is in the background. */ |
| 640 | public abstract Timer getSensorBackgroundTime(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 641 | } |
| 642 | |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 643 | public class Pid { |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 644 | public int mWakeNesting; |
| 645 | public long mWakeSumMs; |
| 646 | public long mWakeStartMs; |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 647 | } |
| 648 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 649 | /** |
| 650 | * The statistics associated with a particular process. |
| 651 | */ |
| 652 | public static abstract class Proc { |
| 653 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 654 | public static class ExcessivePower { |
| 655 | public static final int TYPE_WAKE = 1; |
| 656 | public static final int TYPE_CPU = 2; |
| 657 | |
| 658 | public int type; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 659 | public long overTime; |
| 660 | public long usedTime; |
| 661 | } |
| 662 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 663 | /** |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 664 | * Returns true if this process is still active in the battery stats. |
| 665 | */ |
| 666 | public abstract boolean isActive(); |
| 667 | |
| 668 | /** |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 669 | * 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] | 670 | * |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 671 | * @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] | 672 | */ |
| 673 | public abstract long getUserTime(int which); |
| 674 | |
| 675 | /** |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 676 | * 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] | 677 | * |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 678 | * @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] | 679 | */ |
| 680 | public abstract long getSystemTime(int which); |
| 681 | |
| 682 | /** |
| 683 | * Returns the number of times the process has been started. |
| 684 | * |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 685 | * @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] | 686 | */ |
| 687 | public abstract int getStarts(int which); |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 688 | |
| 689 | /** |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 690 | * Returns the number of times the process has crashed. |
| 691 | * |
| 692 | * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT. |
| 693 | */ |
| 694 | public abstract int getNumCrashes(int which); |
| 695 | |
| 696 | /** |
| 697 | * Returns the number of times the process has ANRed. |
| 698 | * |
| 699 | * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT. |
| 700 | */ |
| 701 | public abstract int getNumAnrs(int which); |
| 702 | |
| 703 | /** |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 704 | * 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] | 705 | * @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] | 706 | * @return foreground cpu time in microseconds |
| 707 | */ |
| 708 | public abstract long getForegroundTime(int which); |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 709 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 710 | public abstract int countExcessivePowers(); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 711 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 712 | public abstract ExcessivePower getExcessivePower(int i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 713 | } |
| 714 | |
| 715 | /** |
| 716 | * The statistics associated with a particular package. |
| 717 | */ |
| 718 | public static abstract class Pkg { |
| 719 | |
| 720 | /** |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 721 | * Returns information about all wakeup alarms that have been triggered for this |
| 722 | * package. The mapping keys are tag names for the alarms, the counter contains |
| 723 | * 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] | 724 | */ |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 725 | public abstract ArrayMap<String, ? extends Counter> getWakeupAlarmStats(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 726 | |
| 727 | /** |
| 728 | * Returns a mapping containing service statistics. |
| 729 | */ |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 730 | public abstract ArrayMap<String, ? extends Serv> getServiceStats(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 731 | |
| 732 | /** |
| 733 | * The statistics associated with a particular service. |
| 734 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 735 | public static abstract class Serv { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 736 | |
| 737 | /** |
| 738 | * Returns the amount of time spent started. |
| 739 | * |
| 740 | * @param batteryUptime elapsed uptime on battery in microseconds. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 741 | * @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] | 742 | * @return |
| 743 | */ |
| 744 | public abstract long getStartTime(long batteryUptime, int which); |
| 745 | |
| 746 | /** |
| 747 | * Returns the total number of times startService() has been called. |
| 748 | * |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 749 | * @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] | 750 | */ |
| 751 | public abstract int getStarts(int which); |
| 752 | |
| 753 | /** |
| 754 | * Returns the total number times the service has been launched. |
| 755 | * |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 756 | * @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] | 757 | */ |
| 758 | public abstract int getLaunches(int which); |
| 759 | } |
| 760 | } |
| 761 | } |
| 762 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 763 | public static final class LevelStepTracker { |
| 764 | public long mLastStepTime = -1; |
| 765 | public int mNumStepDurations; |
| 766 | public final long[] mStepDurations; |
| 767 | |
| 768 | public LevelStepTracker(int maxLevelSteps) { |
| 769 | mStepDurations = new long[maxLevelSteps]; |
| 770 | } |
| 771 | |
| 772 | public LevelStepTracker(int numSteps, long[] steps) { |
| 773 | mNumStepDurations = numSteps; |
| 774 | mStepDurations = new long[numSteps]; |
| 775 | System.arraycopy(steps, 0, mStepDurations, 0, numSteps); |
| 776 | } |
| 777 | |
| 778 | public long getDurationAt(int index) { |
| 779 | return mStepDurations[index] & STEP_LEVEL_TIME_MASK; |
| 780 | } |
| 781 | |
| 782 | public int getLevelAt(int index) { |
| 783 | return (int)((mStepDurations[index] & STEP_LEVEL_LEVEL_MASK) |
| 784 | >> STEP_LEVEL_LEVEL_SHIFT); |
| 785 | } |
| 786 | |
| 787 | public int getInitModeAt(int index) { |
| 788 | return (int)((mStepDurations[index] & STEP_LEVEL_INITIAL_MODE_MASK) |
| 789 | >> STEP_LEVEL_INITIAL_MODE_SHIFT); |
| 790 | } |
| 791 | |
| 792 | public int getModModeAt(int index) { |
| 793 | return (int)((mStepDurations[index] & STEP_LEVEL_MODIFIED_MODE_MASK) |
| 794 | >> STEP_LEVEL_MODIFIED_MODE_SHIFT); |
| 795 | } |
| 796 | |
| 797 | private void appendHex(long val, int topOffset, StringBuilder out) { |
| 798 | boolean hasData = false; |
| 799 | while (topOffset >= 0) { |
| 800 | int digit = (int)( (val>>topOffset) & 0xf ); |
| 801 | topOffset -= 4; |
| 802 | if (!hasData && digit == 0) { |
| 803 | continue; |
| 804 | } |
| 805 | hasData = true; |
| 806 | if (digit >= 0 && digit <= 9) { |
| 807 | out.append((char)('0' + digit)); |
| 808 | } else { |
| 809 | out.append((char)('a' + digit - 10)); |
| 810 | } |
| 811 | } |
| 812 | } |
| 813 | |
| 814 | public void encodeEntryAt(int index, StringBuilder out) { |
| 815 | long item = mStepDurations[index]; |
| 816 | long duration = item & STEP_LEVEL_TIME_MASK; |
| 817 | int level = (int)((item & STEP_LEVEL_LEVEL_MASK) |
| 818 | >> STEP_LEVEL_LEVEL_SHIFT); |
| 819 | int initMode = (int)((item & STEP_LEVEL_INITIAL_MODE_MASK) |
| 820 | >> STEP_LEVEL_INITIAL_MODE_SHIFT); |
| 821 | int modMode = (int)((item & STEP_LEVEL_MODIFIED_MODE_MASK) |
| 822 | >> STEP_LEVEL_MODIFIED_MODE_SHIFT); |
| 823 | switch ((initMode&STEP_LEVEL_MODE_SCREEN_STATE) + 1) { |
| 824 | case Display.STATE_OFF: out.append('f'); break; |
| 825 | case Display.STATE_ON: out.append('o'); break; |
| 826 | case Display.STATE_DOZE: out.append('d'); break; |
| 827 | case Display.STATE_DOZE_SUSPEND: out.append('z'); break; |
| 828 | } |
| 829 | if ((initMode&STEP_LEVEL_MODE_POWER_SAVE) != 0) { |
| 830 | out.append('p'); |
| 831 | } |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 832 | if ((initMode&STEP_LEVEL_MODE_DEVICE_IDLE) != 0) { |
| 833 | out.append('i'); |
| 834 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 835 | switch ((modMode&STEP_LEVEL_MODE_SCREEN_STATE) + 1) { |
| 836 | case Display.STATE_OFF: out.append('F'); break; |
| 837 | case Display.STATE_ON: out.append('O'); break; |
| 838 | case Display.STATE_DOZE: out.append('D'); break; |
| 839 | case Display.STATE_DOZE_SUSPEND: out.append('Z'); break; |
| 840 | } |
| 841 | if ((modMode&STEP_LEVEL_MODE_POWER_SAVE) != 0) { |
| 842 | out.append('P'); |
| 843 | } |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 844 | if ((modMode&STEP_LEVEL_MODE_DEVICE_IDLE) != 0) { |
| 845 | out.append('I'); |
| 846 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 847 | out.append('-'); |
| 848 | appendHex(level, 4, out); |
| 849 | out.append('-'); |
| 850 | appendHex(duration, STEP_LEVEL_LEVEL_SHIFT-4, out); |
| 851 | } |
| 852 | |
| 853 | public void decodeEntryAt(int index, String value) { |
| 854 | final int N = value.length(); |
| 855 | int i = 0; |
| 856 | char c; |
| 857 | long out = 0; |
| 858 | while (i < N && (c=value.charAt(i)) != '-') { |
| 859 | i++; |
| 860 | switch (c) { |
Dianne Hackborn | 8cfb58b | 2015-03-04 13:28:36 -0800 | [diff] [blame] | 861 | 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] | 862 | break; |
Dianne Hackborn | 8cfb58b | 2015-03-04 13:28:36 -0800 | [diff] [blame] | 863 | 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] | 864 | break; |
Dianne Hackborn | 8cfb58b | 2015-03-04 13:28:36 -0800 | [diff] [blame] | 865 | 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] | 866 | break; |
Dianne Hackborn | 8cfb58b | 2015-03-04 13:28:36 -0800 | [diff] [blame] | 867 | case 'z': out |= (((long)Display.STATE_DOZE_SUSPEND-1) |
| 868 | << STEP_LEVEL_INITIAL_MODE_SHIFT); |
| 869 | break; |
| 870 | case 'p': out |= (((long)STEP_LEVEL_MODE_POWER_SAVE) |
| 871 | << STEP_LEVEL_INITIAL_MODE_SHIFT); |
| 872 | break; |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 873 | case 'i': out |= (((long)STEP_LEVEL_MODE_DEVICE_IDLE) |
| 874 | << STEP_LEVEL_INITIAL_MODE_SHIFT); |
| 875 | break; |
Dianne Hackborn | 8cfb58b | 2015-03-04 13:28:36 -0800 | [diff] [blame] | 876 | case 'F': out |= (((long)Display.STATE_OFF-1)<<STEP_LEVEL_MODIFIED_MODE_SHIFT); |
| 877 | break; |
| 878 | case 'O': out |= (((long)Display.STATE_ON-1)<<STEP_LEVEL_MODIFIED_MODE_SHIFT); |
| 879 | break; |
| 880 | case 'D': out |= (((long)Display.STATE_DOZE-1)<<STEP_LEVEL_MODIFIED_MODE_SHIFT); |
| 881 | break; |
| 882 | case 'Z': out |= (((long)Display.STATE_DOZE_SUSPEND-1) |
| 883 | << STEP_LEVEL_MODIFIED_MODE_SHIFT); |
| 884 | break; |
| 885 | case 'P': out |= (((long)STEP_LEVEL_MODE_POWER_SAVE) |
| 886 | << STEP_LEVEL_MODIFIED_MODE_SHIFT); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 887 | break; |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 888 | case 'I': out |= (((long)STEP_LEVEL_MODE_DEVICE_IDLE) |
| 889 | << STEP_LEVEL_MODIFIED_MODE_SHIFT); |
| 890 | break; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 891 | } |
| 892 | } |
| 893 | i++; |
Dianne Hackborn | 8cfb58b | 2015-03-04 13:28:36 -0800 | [diff] [blame] | 894 | long level = 0; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 895 | while (i < N && (c=value.charAt(i)) != '-') { |
| 896 | i++; |
| 897 | level <<= 4; |
| 898 | if (c >= '0' && c <= '9') { |
| 899 | level += c - '0'; |
| 900 | } else if (c >= 'a' && c <= 'f') { |
| 901 | level += c - 'a' + 10; |
| 902 | } else if (c >= 'A' && c <= 'F') { |
| 903 | level += c - 'A' + 10; |
| 904 | } |
| 905 | } |
Dianne Hackborn | 8cfb58b | 2015-03-04 13:28:36 -0800 | [diff] [blame] | 906 | i++; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 907 | out |= (level << STEP_LEVEL_LEVEL_SHIFT) & STEP_LEVEL_LEVEL_MASK; |
| 908 | long duration = 0; |
| 909 | while (i < N && (c=value.charAt(i)) != '-') { |
| 910 | i++; |
| 911 | duration <<= 4; |
| 912 | if (c >= '0' && c <= '9') { |
| 913 | duration += c - '0'; |
| 914 | } else if (c >= 'a' && c <= 'f') { |
| 915 | duration += c - 'a' + 10; |
| 916 | } else if (c >= 'A' && c <= 'F') { |
| 917 | duration += c - 'A' + 10; |
| 918 | } |
| 919 | } |
| 920 | mStepDurations[index] = out | (duration & STEP_LEVEL_TIME_MASK); |
| 921 | } |
| 922 | |
| 923 | public void init() { |
| 924 | mLastStepTime = -1; |
| 925 | mNumStepDurations = 0; |
| 926 | } |
| 927 | |
| 928 | public void clearTime() { |
| 929 | mLastStepTime = -1; |
| 930 | } |
| 931 | |
| 932 | public long computeTimePerLevel() { |
| 933 | final long[] steps = mStepDurations; |
| 934 | final int numSteps = mNumStepDurations; |
| 935 | |
| 936 | // For now we'll do a simple average across all steps. |
| 937 | if (numSteps <= 0) { |
| 938 | return -1; |
| 939 | } |
| 940 | long total = 0; |
| 941 | for (int i=0; i<numSteps; i++) { |
| 942 | total += steps[i] & STEP_LEVEL_TIME_MASK; |
| 943 | } |
| 944 | return total / numSteps; |
| 945 | /* |
| 946 | long[] buckets = new long[numSteps]; |
| 947 | int numBuckets = 0; |
| 948 | int numToAverage = 4; |
| 949 | int i = 0; |
| 950 | while (i < numSteps) { |
| 951 | long totalTime = 0; |
| 952 | int num = 0; |
| 953 | for (int j=0; j<numToAverage && (i+j)<numSteps; j++) { |
| 954 | totalTime += steps[i+j] & STEP_LEVEL_TIME_MASK; |
| 955 | num++; |
| 956 | } |
| 957 | buckets[numBuckets] = totalTime / num; |
| 958 | numBuckets++; |
| 959 | numToAverage *= 2; |
| 960 | i += num; |
| 961 | } |
| 962 | if (numBuckets < 1) { |
| 963 | return -1; |
| 964 | } |
| 965 | long averageTime = buckets[numBuckets-1]; |
| 966 | for (i=numBuckets-2; i>=0; i--) { |
| 967 | averageTime = (averageTime + buckets[i]) / 2; |
| 968 | } |
| 969 | return averageTime; |
| 970 | */ |
| 971 | } |
| 972 | |
| 973 | public long computeTimeEstimate(long modesOfInterest, long modeValues, |
| 974 | int[] outNumOfInterest) { |
| 975 | final long[] steps = mStepDurations; |
| 976 | final int count = mNumStepDurations; |
| 977 | if (count <= 0) { |
| 978 | return -1; |
| 979 | } |
| 980 | long total = 0; |
| 981 | int numOfInterest = 0; |
| 982 | for (int i=0; i<count; i++) { |
| 983 | long initMode = (steps[i] & STEP_LEVEL_INITIAL_MODE_MASK) |
| 984 | >> STEP_LEVEL_INITIAL_MODE_SHIFT; |
| 985 | long modMode = (steps[i] & STEP_LEVEL_MODIFIED_MODE_MASK) |
| 986 | >> STEP_LEVEL_MODIFIED_MODE_SHIFT; |
| 987 | // If the modes of interest didn't change during this step period... |
| 988 | if ((modMode&modesOfInterest) == 0) { |
| 989 | // And the mode values during this period match those we are measuring... |
| 990 | if ((initMode&modesOfInterest) == modeValues) { |
| 991 | // Then this can be used to estimate the total time! |
| 992 | numOfInterest++; |
| 993 | total += steps[i] & STEP_LEVEL_TIME_MASK; |
| 994 | } |
| 995 | } |
| 996 | } |
| 997 | if (numOfInterest <= 0) { |
| 998 | return -1; |
| 999 | } |
| 1000 | |
| 1001 | if (outNumOfInterest != null) { |
| 1002 | outNumOfInterest[0] = numOfInterest; |
| 1003 | } |
| 1004 | |
| 1005 | // The estimated time is the average time we spend in each level, multipled |
| 1006 | // by 100 -- the total number of battery levels |
| 1007 | return (total / numOfInterest) * 100; |
| 1008 | } |
| 1009 | |
| 1010 | public void addLevelSteps(int numStepLevels, long modeBits, long elapsedRealtime) { |
| 1011 | int stepCount = mNumStepDurations; |
| 1012 | final long lastStepTime = mLastStepTime; |
| 1013 | if (lastStepTime >= 0 && numStepLevels > 0) { |
| 1014 | final long[] steps = mStepDurations; |
| 1015 | long duration = elapsedRealtime - lastStepTime; |
| 1016 | for (int i=0; i<numStepLevels; i++) { |
| 1017 | System.arraycopy(steps, 0, steps, 1, steps.length-1); |
| 1018 | long thisDuration = duration / (numStepLevels-i); |
| 1019 | duration -= thisDuration; |
| 1020 | if (thisDuration > STEP_LEVEL_TIME_MASK) { |
| 1021 | thisDuration = STEP_LEVEL_TIME_MASK; |
| 1022 | } |
| 1023 | steps[0] = thisDuration | modeBits; |
| 1024 | } |
| 1025 | stepCount += numStepLevels; |
| 1026 | if (stepCount > steps.length) { |
| 1027 | stepCount = steps.length; |
| 1028 | } |
| 1029 | } |
| 1030 | mNumStepDurations = stepCount; |
| 1031 | mLastStepTime = elapsedRealtime; |
| 1032 | } |
| 1033 | |
| 1034 | public void readFromParcel(Parcel in) { |
| 1035 | final int N = in.readInt(); |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 1036 | if (N > mStepDurations.length) { |
| 1037 | throw new ParcelFormatException("more step durations than available: " + N); |
| 1038 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 1039 | mNumStepDurations = N; |
| 1040 | for (int i=0; i<N; i++) { |
| 1041 | mStepDurations[i] = in.readLong(); |
| 1042 | } |
| 1043 | } |
| 1044 | |
| 1045 | public void writeToParcel(Parcel out) { |
| 1046 | final int N = mNumStepDurations; |
| 1047 | out.writeInt(N); |
| 1048 | for (int i=0; i<N; i++) { |
| 1049 | out.writeLong(mStepDurations[i]); |
| 1050 | } |
| 1051 | } |
| 1052 | } |
| 1053 | |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 1054 | public static final class PackageChange { |
| 1055 | public String mPackageName; |
| 1056 | public boolean mUpdate; |
| 1057 | public int mVersionCode; |
| 1058 | } |
| 1059 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 1060 | public static final class DailyItem { |
| 1061 | public long mStartTime; |
| 1062 | public long mEndTime; |
| 1063 | public LevelStepTracker mDischargeSteps; |
| 1064 | public LevelStepTracker mChargeSteps; |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 1065 | public ArrayList<PackageChange> mPackageChanges; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 1066 | } |
| 1067 | |
| 1068 | public abstract DailyItem getDailyItemLocked(int daysAgo); |
| 1069 | |
| 1070 | public abstract long getCurrentDailyStartTime(); |
| 1071 | |
| 1072 | public abstract long getNextMinDailyDeadline(); |
| 1073 | |
| 1074 | public abstract long getNextMaxDailyDeadline(); |
| 1075 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1076 | public final static class HistoryTag { |
| 1077 | public String string; |
| 1078 | public int uid; |
| 1079 | |
| 1080 | public int poolIdx; |
| 1081 | |
| 1082 | public void setTo(HistoryTag o) { |
| 1083 | string = o.string; |
| 1084 | uid = o.uid; |
| 1085 | poolIdx = o.poolIdx; |
| 1086 | } |
| 1087 | |
| 1088 | public void setTo(String _string, int _uid) { |
| 1089 | string = _string; |
| 1090 | uid = _uid; |
| 1091 | poolIdx = -1; |
| 1092 | } |
| 1093 | |
| 1094 | public void writeToParcel(Parcel dest, int flags) { |
| 1095 | dest.writeString(string); |
| 1096 | dest.writeInt(uid); |
| 1097 | } |
| 1098 | |
| 1099 | public void readFromParcel(Parcel src) { |
| 1100 | string = src.readString(); |
| 1101 | uid = src.readInt(); |
| 1102 | poolIdx = -1; |
| 1103 | } |
| 1104 | |
| 1105 | @Override |
| 1106 | public boolean equals(Object o) { |
| 1107 | if (this == o) return true; |
| 1108 | if (o == null || getClass() != o.getClass()) return false; |
| 1109 | |
| 1110 | HistoryTag that = (HistoryTag) o; |
| 1111 | |
| 1112 | if (uid != that.uid) return false; |
| 1113 | if (!string.equals(that.string)) return false; |
| 1114 | |
| 1115 | return true; |
| 1116 | } |
| 1117 | |
| 1118 | @Override |
| 1119 | public int hashCode() { |
| 1120 | int result = string.hashCode(); |
| 1121 | result = 31 * result + uid; |
| 1122 | return result; |
| 1123 | } |
| 1124 | } |
| 1125 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 1126 | /** |
| 1127 | * Optional detailed information that can go into a history step. This is typically |
| 1128 | * generated each time the battery level changes. |
| 1129 | */ |
| 1130 | public final static class HistoryStepDetails { |
| 1131 | // Time (in 1/100 second) spent in user space and the kernel since the last step. |
| 1132 | public int userTime; |
| 1133 | public int systemTime; |
| 1134 | |
| 1135 | // Top three apps using CPU in the last step, with times in 1/100 second. |
| 1136 | public int appCpuUid1; |
| 1137 | public int appCpuUTime1; |
| 1138 | public int appCpuSTime1; |
| 1139 | public int appCpuUid2; |
| 1140 | public int appCpuUTime2; |
| 1141 | public int appCpuSTime2; |
| 1142 | public int appCpuUid3; |
| 1143 | public int appCpuUTime3; |
| 1144 | public int appCpuSTime3; |
| 1145 | |
| 1146 | // Information from /proc/stat |
| 1147 | public int statUserTime; |
| 1148 | public int statSystemTime; |
| 1149 | public int statIOWaitTime; |
| 1150 | public int statIrqTime; |
| 1151 | public int statSoftIrqTime; |
| 1152 | public int statIdlTime; |
| 1153 | |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 1154 | // Platform-level low power state stats |
| 1155 | public String statPlatformIdleState; |
| 1156 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 1157 | public HistoryStepDetails() { |
| 1158 | clear(); |
| 1159 | } |
| 1160 | |
| 1161 | public void clear() { |
| 1162 | userTime = systemTime = 0; |
| 1163 | appCpuUid1 = appCpuUid2 = appCpuUid3 = -1; |
| 1164 | appCpuUTime1 = appCpuSTime1 = appCpuUTime2 = appCpuSTime2 |
| 1165 | = appCpuUTime3 = appCpuSTime3 = 0; |
| 1166 | } |
| 1167 | |
| 1168 | public void writeToParcel(Parcel out) { |
| 1169 | out.writeInt(userTime); |
| 1170 | out.writeInt(systemTime); |
| 1171 | out.writeInt(appCpuUid1); |
| 1172 | out.writeInt(appCpuUTime1); |
| 1173 | out.writeInt(appCpuSTime1); |
| 1174 | out.writeInt(appCpuUid2); |
| 1175 | out.writeInt(appCpuUTime2); |
| 1176 | out.writeInt(appCpuSTime2); |
| 1177 | out.writeInt(appCpuUid3); |
| 1178 | out.writeInt(appCpuUTime3); |
| 1179 | out.writeInt(appCpuSTime3); |
| 1180 | out.writeInt(statUserTime); |
| 1181 | out.writeInt(statSystemTime); |
| 1182 | out.writeInt(statIOWaitTime); |
| 1183 | out.writeInt(statIrqTime); |
| 1184 | out.writeInt(statSoftIrqTime); |
| 1185 | out.writeInt(statIdlTime); |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 1186 | out.writeString(statPlatformIdleState); |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 1187 | } |
| 1188 | |
| 1189 | public void readFromParcel(Parcel in) { |
| 1190 | userTime = in.readInt(); |
| 1191 | systemTime = in.readInt(); |
| 1192 | appCpuUid1 = in.readInt(); |
| 1193 | appCpuUTime1 = in.readInt(); |
| 1194 | appCpuSTime1 = in.readInt(); |
| 1195 | appCpuUid2 = in.readInt(); |
| 1196 | appCpuUTime2 = in.readInt(); |
| 1197 | appCpuSTime2 = in.readInt(); |
| 1198 | appCpuUid3 = in.readInt(); |
| 1199 | appCpuUTime3 = in.readInt(); |
| 1200 | appCpuSTime3 = in.readInt(); |
| 1201 | statUserTime = in.readInt(); |
| 1202 | statSystemTime = in.readInt(); |
| 1203 | statIOWaitTime = in.readInt(); |
| 1204 | statIrqTime = in.readInt(); |
| 1205 | statSoftIrqTime = in.readInt(); |
| 1206 | statIdlTime = in.readInt(); |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 1207 | statPlatformIdleState = in.readString(); |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 1208 | } |
| 1209 | } |
| 1210 | |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 1211 | public final static class HistoryItem implements Parcelable { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1212 | public HistoryItem next; |
Dianne Hackborn | 9a75543 | 2014-05-15 17:05:22 -0700 | [diff] [blame] | 1213 | |
| 1214 | // The time of this event in milliseconds, as per SystemClock.elapsedRealtime(). |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1215 | public long time; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1216 | |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 1217 | 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] | 1218 | public static final byte CMD_NULL = -1; |
| 1219 | public static final byte CMD_START = 4; |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1220 | public static final byte CMD_CURRENT_TIME = 5; |
| 1221 | public static final byte CMD_OVERFLOW = 6; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 1222 | public static final byte CMD_RESET = 7; |
Dianne Hackborn | 29cd7f1 | 2015-01-08 10:37:05 -0800 | [diff] [blame] | 1223 | public static final byte CMD_SHUTDOWN = 8; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1224 | |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 1225 | public byte cmd = CMD_NULL; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1226 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1227 | /** |
| 1228 | * Return whether the command code is a delta data update. |
| 1229 | */ |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1230 | public boolean isDeltaData() { |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 1231 | return cmd == CMD_UPDATE; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1232 | } |
| 1233 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1234 | public byte batteryLevel; |
| 1235 | public byte batteryStatus; |
| 1236 | public byte batteryHealth; |
| 1237 | public byte batteryPlugType; |
| 1238 | |
Sungmin Choi | c7e9e8b | 2013-01-16 12:57:36 +0900 | [diff] [blame] | 1239 | public short batteryTemperature; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1240 | public char batteryVoltage; |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 1241 | |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 1242 | // The charge of the battery in micro-Ampere-hours. |
| 1243 | public int batteryChargeUAh; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1244 | |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 1245 | // Constants from SCREEN_BRIGHTNESS_* |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1246 | public static final int STATE_BRIGHTNESS_SHIFT = 0; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1247 | public static final int STATE_BRIGHTNESS_MASK = 0x7; |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 1248 | // Constants from SIGNAL_STRENGTH_* |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 1249 | public static final int STATE_PHONE_SIGNAL_STRENGTH_SHIFT = 3; |
| 1250 | 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] | 1251 | // Constants from ServiceState.STATE_* |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1252 | public static final int STATE_PHONE_STATE_SHIFT = 6; |
| 1253 | 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] | 1254 | // Constants from DATA_CONNECTION_* |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1255 | public static final int STATE_DATA_CONNECTION_SHIFT = 9; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1256 | 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] | 1257 | |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 1258 | // These states always appear directly in the first int token |
| 1259 | // of a delta change; they should be ones that change relatively |
| 1260 | // frequently. |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1261 | public static final int STATE_CPU_RUNNING_FLAG = 1<<31; |
| 1262 | public static final int STATE_WAKE_LOCK_FLAG = 1<<30; |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 1263 | public static final int STATE_GPS_ON_FLAG = 1<<29; |
| 1264 | public static final int STATE_WIFI_FULL_LOCK_FLAG = 1<<28; |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 1265 | public static final int STATE_WIFI_SCAN_FLAG = 1<<27; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 1266 | public static final int STATE_WIFI_RADIO_ACTIVE_FLAG = 1<<26; |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 1267 | public static final int STATE_MOBILE_RADIO_ACTIVE_FLAG = 1<<25; |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 1268 | // Do not use, this is used for coulomb delta count. |
| 1269 | private static final int STATE_RESERVED_0 = 1<<24; |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 1270 | // These are on the lower bits used for the command; if they change |
| 1271 | // we need to write another int of data. |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1272 | public static final int STATE_SENSOR_ON_FLAG = 1<<23; |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 1273 | public static final int STATE_AUDIO_ON_FLAG = 1<<22; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1274 | public static final int STATE_PHONE_SCANNING_FLAG = 1<<21; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 1275 | public static final int STATE_SCREEN_ON_FLAG = 1<<20; // consider moving to states2 |
| 1276 | public static final int STATE_BATTERY_PLUGGED_FLAG = 1<<19; // consider moving to states2 |
| 1277 | // empty slot |
| 1278 | // empty slot |
| 1279 | public static final int STATE_WIFI_MULTICAST_ON_FLAG = 1<<16; |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 1280 | |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 1281 | public static final int MOST_INTERESTING_STATES = |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 1282 | STATE_BATTERY_PLUGGED_FLAG | STATE_SCREEN_ON_FLAG; |
| 1283 | |
| 1284 | public static final int SETTLE_TO_ZERO_STATES = 0xffff0000 & ~MOST_INTERESTING_STATES; |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 1285 | |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1286 | public int states; |
| 1287 | |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 1288 | // Constants from WIFI_SUPPL_STATE_* |
| 1289 | public static final int STATE2_WIFI_SUPPL_STATE_SHIFT = 0; |
| 1290 | public static final int STATE2_WIFI_SUPPL_STATE_MASK = 0xf; |
| 1291 | // Values for NUM_WIFI_SIGNAL_STRENGTH_BINS |
| 1292 | public static final int STATE2_WIFI_SIGNAL_STRENGTH_SHIFT = 4; |
| 1293 | public static final int STATE2_WIFI_SIGNAL_STRENGTH_MASK = |
| 1294 | 0x7 << STATE2_WIFI_SIGNAL_STRENGTH_SHIFT; |
| 1295 | |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 1296 | public static final int STATE2_POWER_SAVE_FLAG = 1<<31; |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 1297 | public static final int STATE2_VIDEO_ON_FLAG = 1<<30; |
| 1298 | public static final int STATE2_WIFI_RUNNING_FLAG = 1<<29; |
| 1299 | public static final int STATE2_WIFI_ON_FLAG = 1<<28; |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 1300 | public static final int STATE2_FLASHLIGHT_FLAG = 1<<27; |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 1301 | public static final int STATE2_DEVICE_IDLE_SHIFT = 25; |
| 1302 | public static final int STATE2_DEVICE_IDLE_MASK = 0x3 << STATE2_DEVICE_IDLE_SHIFT; |
| 1303 | public static final int STATE2_CHARGING_FLAG = 1<<24; |
| 1304 | public static final int STATE2_PHONE_IN_CALL_FLAG = 1<<23; |
| 1305 | public static final int STATE2_BLUETOOTH_ON_FLAG = 1<<22; |
| 1306 | public static final int STATE2_CAMERA_FLAG = 1<<21; |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 1307 | public static final int STATE2_BLUETOOTH_SCAN_FLAG = 1 << 20; |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 1308 | |
| 1309 | public static final int MOST_INTERESTING_STATES2 = |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 1310 | STATE2_POWER_SAVE_FLAG | STATE2_WIFI_ON_FLAG | STATE2_DEVICE_IDLE_MASK |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 1311 | | STATE2_CHARGING_FLAG | STATE2_PHONE_IN_CALL_FLAG | STATE2_BLUETOOTH_ON_FLAG; |
| 1312 | |
| 1313 | public static final int SETTLE_TO_ZERO_STATES2 = 0xffff0000 & ~MOST_INTERESTING_STATES2; |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 1314 | |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 1315 | public int states2; |
| 1316 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1317 | // The wake lock that was acquired at this point. |
| 1318 | public HistoryTag wakelockTag; |
| 1319 | |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1320 | // Kernel wakeup reason at this point. |
| 1321 | public HistoryTag wakeReasonTag; |
| 1322 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 1323 | // Non-null when there is more detailed information at this step. |
| 1324 | public HistoryStepDetails stepDetails; |
| 1325 | |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 1326 | public static final int EVENT_FLAG_START = 0x8000; |
| 1327 | public static final int EVENT_FLAG_FINISH = 0x4000; |
| 1328 | |
| 1329 | // No event in this item. |
| 1330 | public static final int EVENT_NONE = 0x0000; |
| 1331 | // Event is about a process that is running. |
| 1332 | public static final int EVENT_PROC = 0x0001; |
| 1333 | // Event is about an application package that is in the foreground. |
| 1334 | public static final int EVENT_FOREGROUND = 0x0002; |
| 1335 | // Event is about an application package that is at the top of the screen. |
| 1336 | public static final int EVENT_TOP = 0x0003; |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 1337 | // Event is about active sync operations. |
Dianne Hackborn | a1f1a3c | 2014-02-24 18:12:28 -0800 | [diff] [blame] | 1338 | public static final int EVENT_SYNC = 0x0004; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 1339 | // Events for all additional wake locks aquired/release within a wake block. |
| 1340 | // These are not generated by default. |
| 1341 | public static final int EVENT_WAKE_LOCK = 0x0005; |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 1342 | // Event is about an application executing a scheduled job. |
| 1343 | public static final int EVENT_JOB = 0x0006; |
| 1344 | // Events for users running. |
| 1345 | public static final int EVENT_USER_RUNNING = 0x0007; |
| 1346 | // Events for foreground user. |
| 1347 | public static final int EVENT_USER_FOREGROUND = 0x0008; |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 1348 | // Event for connectivity changed. |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 1349 | public static final int EVENT_CONNECTIVITY_CHANGED = 0x0009; |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 1350 | // Event for becoming active taking us out of idle mode. |
Dianne Hackborn | b6683c4 | 2015-06-18 17:40:33 -0700 | [diff] [blame] | 1351 | public static final int EVENT_ACTIVE = 0x000a; |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 1352 | // Event for a package being installed. |
Dianne Hackborn | b6683c4 | 2015-06-18 17:40:33 -0700 | [diff] [blame] | 1353 | public static final int EVENT_PACKAGE_INSTALLED = 0x000b; |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 1354 | // Event for a package being uninstalled. |
Dianne Hackborn | b6683c4 | 2015-06-18 17:40:33 -0700 | [diff] [blame] | 1355 | public static final int EVENT_PACKAGE_UNINSTALLED = 0x000c; |
Dianne Hackborn | 1e38382 | 2015-04-10 14:02:33 -0700 | [diff] [blame] | 1356 | // Event for a package being uninstalled. |
Dianne Hackborn | b6683c4 | 2015-06-18 17:40:33 -0700 | [diff] [blame] | 1357 | public static final int EVENT_ALARM = 0x000d; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 1358 | // Record that we have decided we need to collect new stats data. |
Dianne Hackborn | b6683c4 | 2015-06-18 17:40:33 -0700 | [diff] [blame] | 1359 | public static final int EVENT_COLLECT_EXTERNAL_STATS = 0x000e; |
Amith Yamasani | 6776849 | 2015-06-09 12:23:58 -0700 | [diff] [blame] | 1360 | // 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] | 1361 | public static final int EVENT_PACKAGE_INACTIVE = 0x000f; |
Amith Yamasani | 6776849 | 2015-06-09 12:23:58 -0700 | [diff] [blame] | 1362 | // Event for a package becoming active due to an interaction. |
Dianne Hackborn | b6683c4 | 2015-06-18 17:40:33 -0700 | [diff] [blame] | 1363 | public static final int EVENT_PACKAGE_ACTIVE = 0x0010; |
Dianne Hackborn | fd854ee | 2015-07-13 18:00:37 -0700 | [diff] [blame] | 1364 | // Event for a package being on the temporary whitelist. |
| 1365 | public static final int EVENT_TEMP_WHITELIST = 0x0011; |
Dianne Hackborn | 280a64e | 2015-07-13 14:48:08 -0700 | [diff] [blame] | 1366 | // Event for the screen waking up. |
| 1367 | public static final int EVENT_SCREEN_WAKE_UP = 0x0012; |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 1368 | // Event for the UID that woke up the application processor. |
| 1369 | // Used for wakeups coming from WiFi, modem, etc. |
| 1370 | public static final int EVENT_WAKEUP_AP = 0x0013; |
Dianne Hackborn | d0db6f0 | 2016-07-18 14:14:20 -0700 | [diff] [blame] | 1371 | // Event for reporting that a specific partial wake lock has been held for a long duration. |
| 1372 | public static final int EVENT_LONG_WAKE_LOCK = 0x0014; |
Adam Lesinski | 041d917 | 2016-12-12 12:03:56 -0800 | [diff] [blame] | 1373 | // Event reporting the new estimated (learned) capacity of the battery in mAh. |
| 1374 | public static final int EVENT_ESTIMATED_BATTERY_CAP = 0x0015; |
Amith Yamasani | 6776849 | 2015-06-09 12:23:58 -0700 | [diff] [blame] | 1375 | |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 1376 | // Number of event types. |
Adam Lesinski | 041d917 | 2016-12-12 12:03:56 -0800 | [diff] [blame] | 1377 | public static final int EVENT_COUNT = 0x0016; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 1378 | // Mask to extract out only the type part of the event. |
| 1379 | 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] | 1380 | |
| 1381 | public static final int EVENT_PROC_START = EVENT_PROC | EVENT_FLAG_START; |
| 1382 | public static final int EVENT_PROC_FINISH = EVENT_PROC | EVENT_FLAG_FINISH; |
| 1383 | public static final int EVENT_FOREGROUND_START = EVENT_FOREGROUND | EVENT_FLAG_START; |
| 1384 | public static final int EVENT_FOREGROUND_FINISH = EVENT_FOREGROUND | EVENT_FLAG_FINISH; |
| 1385 | public static final int EVENT_TOP_START = EVENT_TOP | EVENT_FLAG_START; |
| 1386 | public static final int EVENT_TOP_FINISH = EVENT_TOP | EVENT_FLAG_FINISH; |
Dianne Hackborn | a1f1a3c | 2014-02-24 18:12:28 -0800 | [diff] [blame] | 1387 | public static final int EVENT_SYNC_START = EVENT_SYNC | EVENT_FLAG_START; |
| 1388 | public static final int EVENT_SYNC_FINISH = EVENT_SYNC | EVENT_FLAG_FINISH; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 1389 | public static final int EVENT_WAKE_LOCK_START = EVENT_WAKE_LOCK | EVENT_FLAG_START; |
| 1390 | 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] | 1391 | public static final int EVENT_JOB_START = EVENT_JOB | EVENT_FLAG_START; |
| 1392 | public static final int EVENT_JOB_FINISH = EVENT_JOB | EVENT_FLAG_FINISH; |
| 1393 | public static final int EVENT_USER_RUNNING_START = EVENT_USER_RUNNING | EVENT_FLAG_START; |
| 1394 | public static final int EVENT_USER_RUNNING_FINISH = EVENT_USER_RUNNING | EVENT_FLAG_FINISH; |
| 1395 | public static final int EVENT_USER_FOREGROUND_START = |
| 1396 | EVENT_USER_FOREGROUND | EVENT_FLAG_START; |
| 1397 | public static final int EVENT_USER_FOREGROUND_FINISH = |
| 1398 | EVENT_USER_FOREGROUND | EVENT_FLAG_FINISH; |
Dianne Hackborn | 1e38382 | 2015-04-10 14:02:33 -0700 | [diff] [blame] | 1399 | public static final int EVENT_ALARM_START = EVENT_ALARM | EVENT_FLAG_START; |
| 1400 | public static final int EVENT_ALARM_FINISH = EVENT_ALARM | EVENT_FLAG_FINISH; |
Dianne Hackborn | fd854ee | 2015-07-13 18:00:37 -0700 | [diff] [blame] | 1401 | public static final int EVENT_TEMP_WHITELIST_START = |
| 1402 | EVENT_TEMP_WHITELIST | EVENT_FLAG_START; |
| 1403 | public static final int EVENT_TEMP_WHITELIST_FINISH = |
| 1404 | EVENT_TEMP_WHITELIST | EVENT_FLAG_FINISH; |
Dianne Hackborn | d0db6f0 | 2016-07-18 14:14:20 -0700 | [diff] [blame] | 1405 | public static final int EVENT_LONG_WAKE_LOCK_START = |
| 1406 | EVENT_LONG_WAKE_LOCK | EVENT_FLAG_START; |
| 1407 | public static final int EVENT_LONG_WAKE_LOCK_FINISH = |
| 1408 | EVENT_LONG_WAKE_LOCK | EVENT_FLAG_FINISH; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1409 | |
| 1410 | // For CMD_EVENT. |
| 1411 | public int eventCode; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1412 | public HistoryTag eventTag; |
| 1413 | |
Dianne Hackborn | 9a75543 | 2014-05-15 17:05:22 -0700 | [diff] [blame] | 1414 | // 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] | 1415 | public long currentTime; |
| 1416 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1417 | // Meta-data when reading. |
| 1418 | public int numReadInts; |
| 1419 | |
| 1420 | // Pre-allocated objects. |
| 1421 | public final HistoryTag localWakelockTag = new HistoryTag(); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1422 | public final HistoryTag localWakeReasonTag = new HistoryTag(); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1423 | public final HistoryTag localEventTag = new HistoryTag(); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1424 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1425 | public HistoryItem() { |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1426 | } |
| 1427 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1428 | public HistoryItem(long time, Parcel src) { |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1429 | this.time = time; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1430 | numReadInts = 2; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 1431 | readFromParcel(src); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1432 | } |
| 1433 | |
| 1434 | public int describeContents() { |
| 1435 | return 0; |
| 1436 | } |
| 1437 | |
| 1438 | public void writeToParcel(Parcel dest, int flags) { |
| 1439 | dest.writeLong(time); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1440 | int bat = (((int)cmd)&0xff) |
| 1441 | | ((((int)batteryLevel)<<8)&0xff00) |
| 1442 | | ((((int)batteryStatus)<<16)&0xf0000) |
| 1443 | | ((((int)batteryHealth)<<20)&0xf00000) |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1444 | | ((((int)batteryPlugType)<<24)&0xf000000) |
| 1445 | | (wakelockTag != null ? 0x10000000 : 0) |
| 1446 | | (wakeReasonTag != null ? 0x20000000 : 0) |
| 1447 | | (eventCode != EVENT_NONE ? 0x40000000 : 0); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1448 | dest.writeInt(bat); |
| 1449 | bat = (((int)batteryTemperature)&0xffff) |
| 1450 | | ((((int)batteryVoltage)<<16)&0xffff0000); |
| 1451 | dest.writeInt(bat); |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 1452 | dest.writeInt(batteryChargeUAh); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1453 | dest.writeInt(states); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1454 | dest.writeInt(states2); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1455 | if (wakelockTag != null) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1456 | wakelockTag.writeToParcel(dest, flags); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1457 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1458 | if (wakeReasonTag != null) { |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1459 | wakeReasonTag.writeToParcel(dest, flags); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1460 | } |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 1461 | if (eventCode != EVENT_NONE) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1462 | dest.writeInt(eventCode); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1463 | eventTag.writeToParcel(dest, flags); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1464 | } |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 1465 | if (cmd == CMD_CURRENT_TIME || cmd == CMD_RESET) { |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1466 | dest.writeLong(currentTime); |
| 1467 | } |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1468 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 1469 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1470 | public void readFromParcel(Parcel src) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1471 | int start = src.dataPosition(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 1472 | int bat = src.readInt(); |
| 1473 | cmd = (byte)(bat&0xff); |
| 1474 | batteryLevel = (byte)((bat>>8)&0xff); |
| 1475 | batteryStatus = (byte)((bat>>16)&0xf); |
| 1476 | batteryHealth = (byte)((bat>>20)&0xf); |
| 1477 | batteryPlugType = (byte)((bat>>24)&0xf); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1478 | int bat2 = src.readInt(); |
| 1479 | batteryTemperature = (short)(bat2&0xffff); |
| 1480 | batteryVoltage = (char)((bat2>>16)&0xffff); |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 1481 | batteryChargeUAh = src.readInt(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 1482 | states = src.readInt(); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1483 | states2 = src.readInt(); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1484 | if ((bat&0x10000000) != 0) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1485 | wakelockTag = localWakelockTag; |
| 1486 | wakelockTag.readFromParcel(src); |
| 1487 | } else { |
| 1488 | wakelockTag = null; |
| 1489 | } |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1490 | if ((bat&0x20000000) != 0) { |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1491 | wakeReasonTag = localWakeReasonTag; |
| 1492 | wakeReasonTag.readFromParcel(src); |
| 1493 | } else { |
| 1494 | wakeReasonTag = null; |
| 1495 | } |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1496 | if ((bat&0x40000000) != 0) { |
| 1497 | eventCode = src.readInt(); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1498 | eventTag = localEventTag; |
| 1499 | eventTag.readFromParcel(src); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1500 | } else { |
| 1501 | eventCode = EVENT_NONE; |
| 1502 | eventTag = null; |
| 1503 | } |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 1504 | if (cmd == CMD_CURRENT_TIME || cmd == CMD_RESET) { |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1505 | currentTime = src.readLong(); |
| 1506 | } else { |
| 1507 | currentTime = 0; |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 1508 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1509 | numReadInts += (src.dataPosition()-start)/4; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 1510 | } |
| 1511 | |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 1512 | public void clear() { |
| 1513 | time = 0; |
| 1514 | cmd = CMD_NULL; |
| 1515 | batteryLevel = 0; |
| 1516 | batteryStatus = 0; |
| 1517 | batteryHealth = 0; |
| 1518 | batteryPlugType = 0; |
| 1519 | batteryTemperature = 0; |
| 1520 | batteryVoltage = 0; |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 1521 | batteryChargeUAh = 0; |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 1522 | states = 0; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1523 | states2 = 0; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1524 | wakelockTag = null; |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1525 | wakeReasonTag = null; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1526 | eventCode = EVENT_NONE; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1527 | eventTag = null; |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 1528 | } |
| 1529 | |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 1530 | public void setTo(HistoryItem o) { |
| 1531 | time = o.time; |
| 1532 | cmd = o.cmd; |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 1533 | setToCommon(o); |
| 1534 | } |
| 1535 | |
| 1536 | public void setTo(long time, byte cmd, HistoryItem o) { |
| 1537 | this.time = time; |
| 1538 | this.cmd = cmd; |
| 1539 | setToCommon(o); |
| 1540 | } |
| 1541 | |
| 1542 | private void setToCommon(HistoryItem o) { |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 1543 | batteryLevel = o.batteryLevel; |
| 1544 | batteryStatus = o.batteryStatus; |
| 1545 | batteryHealth = o.batteryHealth; |
| 1546 | batteryPlugType = o.batteryPlugType; |
| 1547 | batteryTemperature = o.batteryTemperature; |
| 1548 | batteryVoltage = o.batteryVoltage; |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 1549 | batteryChargeUAh = o.batteryChargeUAh; |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 1550 | states = o.states; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1551 | states2 = o.states2; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1552 | if (o.wakelockTag != null) { |
| 1553 | wakelockTag = localWakelockTag; |
| 1554 | wakelockTag.setTo(o.wakelockTag); |
| 1555 | } else { |
| 1556 | wakelockTag = null; |
| 1557 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1558 | if (o.wakeReasonTag != null) { |
| 1559 | wakeReasonTag = localWakeReasonTag; |
| 1560 | wakeReasonTag.setTo(o.wakeReasonTag); |
| 1561 | } else { |
| 1562 | wakeReasonTag = null; |
| 1563 | } |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1564 | eventCode = o.eventCode; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1565 | if (o.eventTag != null) { |
| 1566 | eventTag = localEventTag; |
| 1567 | eventTag.setTo(o.eventTag); |
| 1568 | } else { |
| 1569 | eventTag = null; |
| 1570 | } |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1571 | currentTime = o.currentTime; |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 1572 | } |
| 1573 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1574 | public boolean sameNonEvent(HistoryItem o) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 1575 | return batteryLevel == o.batteryLevel |
| 1576 | && batteryStatus == o.batteryStatus |
| 1577 | && batteryHealth == o.batteryHealth |
| 1578 | && batteryPlugType == o.batteryPlugType |
| 1579 | && batteryTemperature == o.batteryTemperature |
| 1580 | && batteryVoltage == o.batteryVoltage |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 1581 | && batteryChargeUAh == o.batteryChargeUAh |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1582 | && states == o.states |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1583 | && states2 == o.states2 |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1584 | && currentTime == o.currentTime; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 1585 | } |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1586 | |
| 1587 | public boolean same(HistoryItem o) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1588 | if (!sameNonEvent(o) || eventCode != o.eventCode) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1589 | return false; |
| 1590 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1591 | if (wakelockTag != o.wakelockTag) { |
| 1592 | if (wakelockTag == null || o.wakelockTag == null) { |
| 1593 | return false; |
| 1594 | } |
| 1595 | if (!wakelockTag.equals(o.wakelockTag)) { |
| 1596 | return false; |
| 1597 | } |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1598 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1599 | if (wakeReasonTag != o.wakeReasonTag) { |
| 1600 | if (wakeReasonTag == null || o.wakeReasonTag == null) { |
| 1601 | return false; |
| 1602 | } |
| 1603 | if (!wakeReasonTag.equals(o.wakeReasonTag)) { |
| 1604 | return false; |
| 1605 | } |
| 1606 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1607 | if (eventTag != o.eventTag) { |
| 1608 | if (eventTag == null || o.eventTag == null) { |
| 1609 | return false; |
| 1610 | } |
| 1611 | if (!eventTag.equals(o.eventTag)) { |
| 1612 | return false; |
| 1613 | } |
| 1614 | } |
| 1615 | return true; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1616 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1617 | } |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 1618 | |
| 1619 | public final static class HistoryEventTracker { |
| 1620 | private final HashMap<String, SparseIntArray>[] mActiveEvents |
| 1621 | = (HashMap<String, SparseIntArray>[]) new HashMap[HistoryItem.EVENT_COUNT]; |
| 1622 | |
| 1623 | public boolean updateState(int code, String name, int uid, int poolIdx) { |
| 1624 | if ((code&HistoryItem.EVENT_FLAG_START) != 0) { |
| 1625 | int idx = code&HistoryItem.EVENT_TYPE_MASK; |
| 1626 | HashMap<String, SparseIntArray> active = mActiveEvents[idx]; |
| 1627 | if (active == null) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 1628 | active = new HashMap<>(); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 1629 | mActiveEvents[idx] = active; |
| 1630 | } |
| 1631 | SparseIntArray uids = active.get(name); |
| 1632 | if (uids == null) { |
| 1633 | uids = new SparseIntArray(); |
| 1634 | active.put(name, uids); |
| 1635 | } |
| 1636 | if (uids.indexOfKey(uid) >= 0) { |
| 1637 | // Already set, nothing to do! |
| 1638 | return false; |
| 1639 | } |
| 1640 | uids.put(uid, poolIdx); |
| 1641 | } else if ((code&HistoryItem.EVENT_FLAG_FINISH) != 0) { |
| 1642 | int idx = code&HistoryItem.EVENT_TYPE_MASK; |
| 1643 | HashMap<String, SparseIntArray> active = mActiveEvents[idx]; |
| 1644 | if (active == null) { |
| 1645 | // not currently active, nothing to do. |
| 1646 | return false; |
| 1647 | } |
| 1648 | SparseIntArray uids = active.get(name); |
| 1649 | if (uids == null) { |
| 1650 | // not currently active, nothing to do. |
| 1651 | return false; |
| 1652 | } |
| 1653 | idx = uids.indexOfKey(uid); |
| 1654 | if (idx < 0) { |
| 1655 | // not currently active, nothing to do. |
| 1656 | return false; |
| 1657 | } |
| 1658 | uids.removeAt(idx); |
| 1659 | if (uids.size() <= 0) { |
| 1660 | active.remove(name); |
| 1661 | } |
| 1662 | } |
| 1663 | return true; |
| 1664 | } |
| 1665 | |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 1666 | public void removeEvents(int code) { |
| 1667 | int idx = code&HistoryItem.EVENT_TYPE_MASK; |
| 1668 | mActiveEvents[idx] = null; |
| 1669 | } |
| 1670 | |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 1671 | public HashMap<String, SparseIntArray> getStateForEvent(int code) { |
| 1672 | return mActiveEvents[code]; |
| 1673 | } |
| 1674 | } |
| 1675 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1676 | public static final class BitDescription { |
| 1677 | public final int mask; |
| 1678 | public final int shift; |
| 1679 | public final String name; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1680 | public final String shortName; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1681 | public final String[] values; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1682 | public final String[] shortValues; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1683 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1684 | public BitDescription(int mask, String name, String shortName) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1685 | this.mask = mask; |
| 1686 | this.shift = -1; |
| 1687 | this.name = name; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1688 | this.shortName = shortName; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1689 | this.values = null; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1690 | this.shortValues = null; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1691 | } |
| 1692 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1693 | public BitDescription(int mask, int shift, String name, String shortName, |
| 1694 | String[] values, String[] shortValues) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1695 | this.mask = mask; |
| 1696 | this.shift = shift; |
| 1697 | this.name = name; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1698 | this.shortName = shortName; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1699 | this.values = values; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1700 | this.shortValues = shortValues; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1701 | } |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1702 | } |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 1703 | |
Dianne Hackborn | fc06413 | 2014-06-02 12:42:12 -0700 | [diff] [blame] | 1704 | /** |
| 1705 | * Don't allow any more batching in to the current history event. This |
| 1706 | * is called when printing partial histories, so to ensure that the next |
| 1707 | * history event will go in to a new batch after what was printed in the |
| 1708 | * last partial history. |
| 1709 | */ |
| 1710 | public abstract void commitCurrentHistoryBatchLocked(); |
| 1711 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1712 | public abstract int getHistoryTotalSize(); |
| 1713 | |
| 1714 | public abstract int getHistoryUsedSize(); |
| 1715 | |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 1716 | public abstract boolean startIteratingHistoryLocked(); |
| 1717 | |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 1718 | public abstract int getHistoryStringPoolSize(); |
| 1719 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1720 | public abstract int getHistoryStringPoolBytes(); |
| 1721 | |
| 1722 | public abstract String getHistoryTagPoolString(int index); |
| 1723 | |
| 1724 | public abstract int getHistoryTagPoolUid(int index); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 1725 | |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 1726 | public abstract boolean getNextHistoryLocked(HistoryItem out); |
| 1727 | |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 1728 | public abstract void finishIteratingHistoryLocked(); |
| 1729 | |
| 1730 | public abstract boolean startIteratingOldHistoryLocked(); |
| 1731 | |
| 1732 | public abstract boolean getNextOldHistoryLocked(HistoryItem out); |
| 1733 | |
| 1734 | public abstract void finishIteratingOldHistoryLocked(); |
| 1735 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1736 | /** |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 1737 | * Return the base time offset for the battery history. |
| 1738 | */ |
| 1739 | public abstract long getHistoryBaseTime(); |
| 1740 | |
| 1741 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1742 | * Returns the number of times the device has been started. |
| 1743 | */ |
| 1744 | public abstract int getStartCount(); |
| 1745 | |
| 1746 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 1747 | * 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] | 1748 | * running on battery. |
| 1749 | * |
| 1750 | * {@hide} |
| 1751 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1752 | public abstract long getScreenOnTime(long elapsedRealtimeUs, int which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1753 | |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 1754 | /** |
| 1755 | * Returns the number of times the screen was turned on. |
| 1756 | * |
| 1757 | * {@hide} |
| 1758 | */ |
| 1759 | public abstract int getScreenOnCount(int which); |
| 1760 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 1761 | public abstract long getInteractiveTime(long elapsedRealtimeUs, int which); |
| 1762 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1763 | public static final int SCREEN_BRIGHTNESS_DARK = 0; |
| 1764 | public static final int SCREEN_BRIGHTNESS_DIM = 1; |
| 1765 | public static final int SCREEN_BRIGHTNESS_MEDIUM = 2; |
| 1766 | public static final int SCREEN_BRIGHTNESS_LIGHT = 3; |
| 1767 | public static final int SCREEN_BRIGHTNESS_BRIGHT = 4; |
| 1768 | |
| 1769 | static final String[] SCREEN_BRIGHTNESS_NAMES = { |
| 1770 | "dark", "dim", "medium", "light", "bright" |
| 1771 | }; |
| 1772 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1773 | static final String[] SCREEN_BRIGHTNESS_SHORT_NAMES = { |
| 1774 | "0", "1", "2", "3", "4" |
| 1775 | }; |
| 1776 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1777 | public static final int NUM_SCREEN_BRIGHTNESS_BINS = 5; |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 1778 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1779 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 1780 | * Returns the time in microseconds that the screen has been on with |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1781 | * the given brightness |
| 1782 | * |
| 1783 | * {@hide} |
| 1784 | */ |
| 1785 | public abstract long getScreenBrightnessTime(int brightnessBin, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1786 | long elapsedRealtimeUs, int which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1787 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1788 | /** |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 1789 | * 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] | 1790 | * running on battery. |
| 1791 | * |
| 1792 | * {@hide} |
| 1793 | */ |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 1794 | public abstract long getPowerSaveModeEnabledTime(long elapsedRealtimeUs, int which); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 1795 | |
| 1796 | /** |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 1797 | * Returns the number of times that power save mode was enabled. |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 1798 | * |
| 1799 | * {@hide} |
| 1800 | */ |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 1801 | public abstract int getPowerSaveModeEnabledCount(int which); |
| 1802 | |
| 1803 | /** |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 1804 | * Constant for device idle mode: not active. |
| 1805 | */ |
| 1806 | public static final int DEVICE_IDLE_MODE_OFF = 0; |
| 1807 | |
| 1808 | /** |
| 1809 | * Constant for device idle mode: active in lightweight mode. |
| 1810 | */ |
| 1811 | public static final int DEVICE_IDLE_MODE_LIGHT = 1; |
| 1812 | |
| 1813 | /** |
| 1814 | * Constant for device idle mode: active in full mode. |
| 1815 | */ |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 1816 | public static final int DEVICE_IDLE_MODE_DEEP = 2; |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 1817 | |
| 1818 | /** |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 1819 | * Returns the time in microseconds that device has been in idle mode while |
| 1820 | * running on battery. |
| 1821 | * |
| 1822 | * {@hide} |
| 1823 | */ |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 1824 | public abstract long getDeviceIdleModeTime(int mode, long elapsedRealtimeUs, int which); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 1825 | |
| 1826 | /** |
| 1827 | * Returns the number of times that the devie has gone in to idle mode. |
| 1828 | * |
| 1829 | * {@hide} |
| 1830 | */ |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 1831 | public abstract int getDeviceIdleModeCount(int mode, int which); |
| 1832 | |
| 1833 | /** |
| 1834 | * Return the longest duration we spent in a particular device idle mode (fully in the |
| 1835 | * mode, not in idle maintenance etc). |
| 1836 | */ |
| 1837 | public abstract long getLongestDeviceIdleModeTime(int mode); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 1838 | |
| 1839 | /** |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 1840 | * 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] | 1841 | * battery. This is broader than {@link #getDeviceIdleModeTime} -- it |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 1842 | * counts all of the time that we consider the device to be idle, whether or not |
| 1843 | * it is currently in the actual device idle mode. |
| 1844 | * |
| 1845 | * {@hide} |
| 1846 | */ |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 1847 | public abstract long getDeviceIdlingTime(int mode, long elapsedRealtimeUs, int which); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 1848 | |
| 1849 | /** |
| 1850 | * Returns the number of times that the devie has started idling. |
| 1851 | * |
| 1852 | * {@hide} |
| 1853 | */ |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 1854 | public abstract int getDeviceIdlingCount(int mode, int which); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 1855 | |
| 1856 | /** |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 1857 | * Returns the number of times that connectivity state changed. |
| 1858 | * |
| 1859 | * {@hide} |
| 1860 | */ |
| 1861 | public abstract int getNumConnectivityChange(int which); |
| 1862 | |
| 1863 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 1864 | * 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] | 1865 | * running on battery. |
| 1866 | * |
| 1867 | * {@hide} |
| 1868 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1869 | public abstract long getPhoneOnTime(long elapsedRealtimeUs, int which); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 1870 | |
| 1871 | /** |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 1872 | * Returns the number of times a phone call was activated. |
| 1873 | * |
| 1874 | * {@hide} |
| 1875 | */ |
| 1876 | public abstract int getPhoneOnCount(int which); |
| 1877 | |
| 1878 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 1879 | * Returns the time in microseconds that the phone has been running with |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 1880 | * the given signal strength. |
| 1881 | * |
| 1882 | * {@hide} |
| 1883 | */ |
| 1884 | public abstract long getPhoneSignalStrengthTime(int strengthBin, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1885 | long elapsedRealtimeUs, int which); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 1886 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1887 | /** |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 1888 | * Returns the time in microseconds that the phone has been trying to |
| 1889 | * acquire a signal. |
| 1890 | * |
| 1891 | * {@hide} |
| 1892 | */ |
| 1893 | public abstract long getPhoneSignalScanningTime( |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1894 | long elapsedRealtimeUs, int which); |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 1895 | |
| 1896 | /** |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1897 | * Returns the number of times the phone has entered the given signal strength. |
| 1898 | * |
| 1899 | * {@hide} |
| 1900 | */ |
| 1901 | public abstract int getPhoneSignalStrengthCount(int strengthBin, int which); |
| 1902 | |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 1903 | /** |
| 1904 | * Returns the time in microseconds that the mobile network has been active |
| 1905 | * (in a high power state). |
| 1906 | * |
| 1907 | * {@hide} |
| 1908 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1909 | public abstract long getMobileRadioActiveTime(long elapsedRealtimeUs, int which); |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 1910 | |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 1911 | /** |
| 1912 | * Returns the number of times that the mobile network has transitioned to the |
| 1913 | * active state. |
| 1914 | * |
| 1915 | * {@hide} |
| 1916 | */ |
| 1917 | public abstract int getMobileRadioActiveCount(int which); |
| 1918 | |
| 1919 | /** |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1920 | * Returns the time in microseconds that is the difference between the mobile radio |
| 1921 | * time we saw based on the elapsed timestamp when going down vs. the given time stamp |
| 1922 | * from the radio. |
| 1923 | * |
| 1924 | * {@hide} |
| 1925 | */ |
| 1926 | public abstract long getMobileRadioActiveAdjustedTime(int which); |
| 1927 | |
| 1928 | /** |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 1929 | * Returns the time in microseconds that the mobile network has been active |
| 1930 | * (in a high power state) but not being able to blame on an app. |
| 1931 | * |
| 1932 | * {@hide} |
| 1933 | */ |
| 1934 | public abstract long getMobileRadioActiveUnknownTime(int which); |
| 1935 | |
| 1936 | /** |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 1937 | * 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] | 1938 | * |
| 1939 | * {@hide} |
| 1940 | */ |
| 1941 | public abstract int getMobileRadioActiveUnknownCount(int which); |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 1942 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 1943 | public static final int DATA_CONNECTION_NONE = 0; |
| 1944 | public static final int DATA_CONNECTION_GPRS = 1; |
| 1945 | public static final int DATA_CONNECTION_EDGE = 2; |
| 1946 | public static final int DATA_CONNECTION_UMTS = 3; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1947 | public static final int DATA_CONNECTION_CDMA = 4; |
| 1948 | public static final int DATA_CONNECTION_EVDO_0 = 5; |
| 1949 | public static final int DATA_CONNECTION_EVDO_A = 6; |
| 1950 | public static final int DATA_CONNECTION_1xRTT = 7; |
| 1951 | public static final int DATA_CONNECTION_HSDPA = 8; |
| 1952 | public static final int DATA_CONNECTION_HSUPA = 9; |
| 1953 | public static final int DATA_CONNECTION_HSPA = 10; |
| 1954 | public static final int DATA_CONNECTION_IDEN = 11; |
| 1955 | public static final int DATA_CONNECTION_EVDO_B = 12; |
Robert Greenwalt | 962a990 | 2010-11-02 11:10:25 -0700 | [diff] [blame] | 1956 | public static final int DATA_CONNECTION_LTE = 13; |
| 1957 | public static final int DATA_CONNECTION_EHRPD = 14; |
Patrick Tjin | b71703c | 2013-11-06 09:27:03 -0800 | [diff] [blame] | 1958 | public static final int DATA_CONNECTION_HSPAP = 15; |
| 1959 | public static final int DATA_CONNECTION_OTHER = 16; |
Robert Greenwalt | 962a990 | 2010-11-02 11:10:25 -0700 | [diff] [blame] | 1960 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 1961 | static final String[] DATA_CONNECTION_NAMES = { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1962 | "none", "gprs", "edge", "umts", "cdma", "evdo_0", "evdo_A", |
Robert Greenwalt | 962a990 | 2010-11-02 11:10:25 -0700 | [diff] [blame] | 1963 | "1xrtt", "hsdpa", "hsupa", "hspa", "iden", "evdo_b", "lte", |
Patrick Tjin | b71703c | 2013-11-06 09:27:03 -0800 | [diff] [blame] | 1964 | "ehrpd", "hspap", "other" |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 1965 | }; |
| 1966 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1967 | public static final int NUM_DATA_CONNECTION_TYPES = DATA_CONNECTION_OTHER+1; |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 1968 | |
| 1969 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 1970 | * Returns the time in microseconds that the phone has been running with |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 1971 | * the given data connection. |
| 1972 | * |
| 1973 | * {@hide} |
| 1974 | */ |
| 1975 | public abstract long getPhoneDataConnectionTime(int dataType, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1976 | long elapsedRealtimeUs, int which); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 1977 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1978 | /** |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1979 | * Returns the number of times the phone has entered the given data |
| 1980 | * connection type. |
| 1981 | * |
| 1982 | * {@hide} |
| 1983 | */ |
| 1984 | public abstract int getPhoneDataConnectionCount(int dataType, int which); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1985 | |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 1986 | public static final int WIFI_SUPPL_STATE_INVALID = 0; |
| 1987 | public static final int WIFI_SUPPL_STATE_DISCONNECTED = 1; |
| 1988 | public static final int WIFI_SUPPL_STATE_INTERFACE_DISABLED = 2; |
| 1989 | public static final int WIFI_SUPPL_STATE_INACTIVE = 3; |
| 1990 | public static final int WIFI_SUPPL_STATE_SCANNING = 4; |
| 1991 | public static final int WIFI_SUPPL_STATE_AUTHENTICATING = 5; |
| 1992 | public static final int WIFI_SUPPL_STATE_ASSOCIATING = 6; |
| 1993 | public static final int WIFI_SUPPL_STATE_ASSOCIATED = 7; |
| 1994 | public static final int WIFI_SUPPL_STATE_FOUR_WAY_HANDSHAKE = 8; |
| 1995 | public static final int WIFI_SUPPL_STATE_GROUP_HANDSHAKE = 9; |
| 1996 | public static final int WIFI_SUPPL_STATE_COMPLETED = 10; |
| 1997 | public static final int WIFI_SUPPL_STATE_DORMANT = 11; |
| 1998 | public static final int WIFI_SUPPL_STATE_UNINITIALIZED = 12; |
| 1999 | |
| 2000 | public static final int NUM_WIFI_SUPPL_STATES = WIFI_SUPPL_STATE_UNINITIALIZED+1; |
| 2001 | |
| 2002 | static final String[] WIFI_SUPPL_STATE_NAMES = { |
| 2003 | "invalid", "disconn", "disabled", "inactive", "scanning", |
| 2004 | "authenticating", "associating", "associated", "4-way-handshake", |
| 2005 | "group-handshake", "completed", "dormant", "uninit" |
| 2006 | }; |
| 2007 | |
| 2008 | static final String[] WIFI_SUPPL_STATE_SHORT_NAMES = { |
| 2009 | "inv", "dsc", "dis", "inact", "scan", |
| 2010 | "auth", "ascing", "asced", "4-way", |
| 2011 | "group", "compl", "dorm", "uninit" |
| 2012 | }; |
| 2013 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2014 | public static final BitDescription[] HISTORY_STATE_DESCRIPTIONS |
| 2015 | = new BitDescription[] { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2016 | new BitDescription(HistoryItem.STATE_CPU_RUNNING_FLAG, "running", "r"), |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2017 | new BitDescription(HistoryItem.STATE_WAKE_LOCK_FLAG, "wake_lock", "w"), |
| 2018 | new BitDescription(HistoryItem.STATE_SENSOR_ON_FLAG, "sensor", "s"), |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2019 | new BitDescription(HistoryItem.STATE_GPS_ON_FLAG, "gps", "g"), |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2020 | new BitDescription(HistoryItem.STATE_WIFI_FULL_LOCK_FLAG, "wifi_full_lock", "Wl"), |
| 2021 | new BitDescription(HistoryItem.STATE_WIFI_SCAN_FLAG, "wifi_scan", "Ws"), |
| 2022 | new BitDescription(HistoryItem.STATE_WIFI_MULTICAST_ON_FLAG, "wifi_multicast", "Wm"), |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 2023 | new BitDescription(HistoryItem.STATE_WIFI_RADIO_ACTIVE_FLAG, "wifi_radio", "Wr"), |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 2024 | new BitDescription(HistoryItem.STATE_MOBILE_RADIO_ACTIVE_FLAG, "mobile_radio", "Pr"), |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2025 | new BitDescription(HistoryItem.STATE_PHONE_SCANNING_FLAG, "phone_scanning", "Psc"), |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2026 | new BitDescription(HistoryItem.STATE_AUDIO_ON_FLAG, "audio", "a"), |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2027 | new BitDescription(HistoryItem.STATE_SCREEN_ON_FLAG, "screen", "S"), |
| 2028 | new BitDescription(HistoryItem.STATE_BATTERY_PLUGGED_FLAG, "plugged", "BP"), |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2029 | new BitDescription(HistoryItem.STATE_DATA_CONNECTION_MASK, |
| 2030 | HistoryItem.STATE_DATA_CONNECTION_SHIFT, "data_conn", "Pcn", |
| 2031 | DATA_CONNECTION_NAMES, DATA_CONNECTION_NAMES), |
| 2032 | new BitDescription(HistoryItem.STATE_PHONE_STATE_MASK, |
| 2033 | HistoryItem.STATE_PHONE_STATE_SHIFT, "phone_state", "Pst", |
| 2034 | new String[] {"in", "out", "emergency", "off"}, |
| 2035 | new String[] {"in", "out", "em", "off"}), |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 2036 | new BitDescription(HistoryItem.STATE_PHONE_SIGNAL_STRENGTH_MASK, |
| 2037 | HistoryItem.STATE_PHONE_SIGNAL_STRENGTH_SHIFT, "phone_signal_strength", "Pss", |
| 2038 | SignalStrength.SIGNAL_STRENGTH_NAMES, |
| 2039 | new String[] { "0", "1", "2", "3", "4" }), |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2040 | new BitDescription(HistoryItem.STATE_BRIGHTNESS_MASK, |
| 2041 | HistoryItem.STATE_BRIGHTNESS_SHIFT, "brightness", "Sb", |
| 2042 | SCREEN_BRIGHTNESS_NAMES, SCREEN_BRIGHTNESS_SHORT_NAMES), |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2043 | }; |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2044 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2045 | public static final BitDescription[] HISTORY_STATE2_DESCRIPTIONS |
| 2046 | = new BitDescription[] { |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 2047 | new BitDescription(HistoryItem.STATE2_POWER_SAVE_FLAG, "power_save", "ps"), |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 2048 | new BitDescription(HistoryItem.STATE2_VIDEO_ON_FLAG, "video", "v"), |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 2049 | new BitDescription(HistoryItem.STATE2_WIFI_RUNNING_FLAG, "wifi_running", "Ww"), |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 2050 | new BitDescription(HistoryItem.STATE2_WIFI_ON_FLAG, "wifi", "W"), |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 2051 | new BitDescription(HistoryItem.STATE2_FLASHLIGHT_FLAG, "flashlight", "fl"), |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 2052 | new BitDescription(HistoryItem.STATE2_DEVICE_IDLE_MASK, |
| 2053 | HistoryItem.STATE2_DEVICE_IDLE_SHIFT, "device_idle", "di", |
| 2054 | new String[] { "off", "light", "full", "???" }, |
| 2055 | new String[] { "off", "light", "full", "???" }), |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 2056 | new BitDescription(HistoryItem.STATE2_CHARGING_FLAG, "charging", "ch"), |
| 2057 | new BitDescription(HistoryItem.STATE2_PHONE_IN_CALL_FLAG, "phone_in_call", "Pcl"), |
| 2058 | new BitDescription(HistoryItem.STATE2_BLUETOOTH_ON_FLAG, "bluetooth", "b"), |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 2059 | new BitDescription(HistoryItem.STATE2_WIFI_SIGNAL_STRENGTH_MASK, |
| 2060 | HistoryItem.STATE2_WIFI_SIGNAL_STRENGTH_SHIFT, "wifi_signal_strength", "Wss", |
| 2061 | new String[] { "0", "1", "2", "3", "4" }, |
| 2062 | new String[] { "0", "1", "2", "3", "4" }), |
| 2063 | new BitDescription(HistoryItem.STATE2_WIFI_SUPPL_STATE_MASK, |
| 2064 | HistoryItem.STATE2_WIFI_SUPPL_STATE_SHIFT, "wifi_suppl", "Wsp", |
| 2065 | WIFI_SUPPL_STATE_NAMES, WIFI_SUPPL_STATE_SHORT_NAMES), |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 2066 | new BitDescription(HistoryItem.STATE2_CAMERA_FLAG, "camera", "ca"), |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 2067 | new BitDescription(HistoryItem.STATE2_BLUETOOTH_SCAN_FLAG, "ble_scan", "bles"), |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2068 | }; |
| 2069 | |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 2070 | public static final String[] HISTORY_EVENT_NAMES = new String[] { |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 2071 | "null", "proc", "fg", "top", "sync", "wake_lock_in", "job", "user", "userfg", "conn", |
Kweku Adams | 134c59b | 2017-03-08 16:48:01 -0800 | [diff] [blame] | 2072 | "active", "pkginst", "pkgunin", "alarm", "stats", "pkginactive", "pkgactive", |
| 2073 | "tmpwhitelist", "screenwake", "wakeupap", "longwake", "est_capacity" |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 2074 | }; |
| 2075 | |
| 2076 | public static final String[] HISTORY_EVENT_CHECKIN_NAMES = new String[] { |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 2077 | "Enl", "Epr", "Efg", "Etp", "Esy", "Ewl", "Ejb", "Eur", "Euf", "Ecn", |
Dianne Hackborn | 280a64e | 2015-07-13 14:48:08 -0700 | [diff] [blame] | 2078 | "Eac", "Epi", "Epu", "Eal", "Est", "Eai", "Eaa", "Etw", |
Adam Lesinski | 041d917 | 2016-12-12 12:03:56 -0800 | [diff] [blame] | 2079 | "Esw", "Ewa", "Elw", "Eec" |
| 2080 | }; |
| 2081 | |
| 2082 | @FunctionalInterface |
| 2083 | public interface IntToString { |
| 2084 | String applyAsString(int val); |
| 2085 | } |
| 2086 | |
| 2087 | private static final IntToString sUidToString = UserHandle::formatUid; |
| 2088 | private static final IntToString sIntToString = Integer::toString; |
| 2089 | |
| 2090 | public static final IntToString[] HISTORY_EVENT_INT_FORMATTERS = new IntToString[] { |
| 2091 | sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, |
| 2092 | sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, |
| 2093 | sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, |
| 2094 | sUidToString, sUidToString, sUidToString, sIntToString |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 2095 | }; |
| 2096 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2097 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 2098 | * 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] | 2099 | * running on battery. |
| 2100 | * |
| 2101 | * {@hide} |
| 2102 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2103 | public abstract long getWifiOnTime(long elapsedRealtimeUs, int which); |
Eric Shienbrood | d4c5f89 | 2009-03-24 18:13:20 -0700 | [diff] [blame] | 2104 | |
| 2105 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 2106 | * 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] | 2107 | * been in the running state while the device was running on battery. |
| 2108 | * |
| 2109 | * {@hide} |
| 2110 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2111 | public abstract long getGlobalWifiRunningTime(long elapsedRealtimeUs, int which); |
Eric Shienbrood | d4c5f89 | 2009-03-24 18:13:20 -0700 | [diff] [blame] | 2112 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 2113 | public static final int WIFI_STATE_OFF = 0; |
| 2114 | public static final int WIFI_STATE_OFF_SCANNING = 1; |
| 2115 | public static final int WIFI_STATE_ON_NO_NETWORKS = 2; |
| 2116 | public static final int WIFI_STATE_ON_DISCONNECTED = 3; |
| 2117 | public static final int WIFI_STATE_ON_CONNECTED_STA = 4; |
| 2118 | public static final int WIFI_STATE_ON_CONNECTED_P2P = 5; |
| 2119 | public static final int WIFI_STATE_ON_CONNECTED_STA_P2P = 6; |
| 2120 | public static final int WIFI_STATE_SOFT_AP = 7; |
| 2121 | |
| 2122 | static final String[] WIFI_STATE_NAMES = { |
| 2123 | "off", "scanning", "no_net", "disconn", |
| 2124 | "sta", "p2p", "sta_p2p", "soft_ap" |
| 2125 | }; |
| 2126 | |
| 2127 | public static final int NUM_WIFI_STATES = WIFI_STATE_SOFT_AP+1; |
| 2128 | |
| 2129 | /** |
| 2130 | * Returns the time in microseconds that WiFi has been running in the given state. |
| 2131 | * |
| 2132 | * {@hide} |
| 2133 | */ |
| 2134 | public abstract long getWifiStateTime(int wifiState, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2135 | long elapsedRealtimeUs, int which); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 2136 | |
| 2137 | /** |
| 2138 | * Returns the number of times that WiFi has entered the given state. |
| 2139 | * |
| 2140 | * {@hide} |
| 2141 | */ |
| 2142 | public abstract int getWifiStateCount(int wifiState, int which); |
| 2143 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2144 | /** |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 2145 | * Returns the time in microseconds that the wifi supplicant has been |
| 2146 | * in a given state. |
| 2147 | * |
| 2148 | * {@hide} |
| 2149 | */ |
| 2150 | public abstract long getWifiSupplStateTime(int state, long elapsedRealtimeUs, int which); |
| 2151 | |
| 2152 | /** |
| 2153 | * Returns the number of times that the wifi supplicant has transitioned |
| 2154 | * to a given state. |
| 2155 | * |
| 2156 | * {@hide} |
| 2157 | */ |
| 2158 | public abstract int getWifiSupplStateCount(int state, int which); |
| 2159 | |
| 2160 | public static final int NUM_WIFI_SIGNAL_STRENGTH_BINS = 5; |
| 2161 | |
| 2162 | /** |
| 2163 | * Returns the time in microseconds that WIFI has been running with |
| 2164 | * the given signal strength. |
| 2165 | * |
| 2166 | * {@hide} |
| 2167 | */ |
| 2168 | public abstract long getWifiSignalStrengthTime(int strengthBin, |
| 2169 | long elapsedRealtimeUs, int which); |
| 2170 | |
| 2171 | /** |
| 2172 | * Returns the number of times WIFI has entered the given signal strength. |
| 2173 | * |
| 2174 | * {@hide} |
| 2175 | */ |
| 2176 | public abstract int getWifiSignalStrengthCount(int strengthBin, int which); |
| 2177 | |
| 2178 | /** |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 2179 | * Returns the time in microseconds that the flashlight has been on while the device was |
| 2180 | * running on battery. |
| 2181 | * |
| 2182 | * {@hide} |
| 2183 | */ |
| 2184 | public abstract long getFlashlightOnTime(long elapsedRealtimeUs, int which); |
| 2185 | |
| 2186 | /** |
| 2187 | * Returns the number of times that the flashlight has been turned on while the device was |
| 2188 | * running on battery. |
| 2189 | * |
| 2190 | * {@hide} |
| 2191 | */ |
| 2192 | public abstract long getFlashlightOnCount(int which); |
| 2193 | |
Ruben Brunk | 5b1308f | 2015-06-03 18:49:27 -0700 | [diff] [blame] | 2194 | /** |
| 2195 | * Returns the time in microseconds that the camera has been on while the device was |
| 2196 | * running on battery. |
| 2197 | * |
| 2198 | * {@hide} |
| 2199 | */ |
| 2200 | public abstract long getCameraOnTime(long elapsedRealtimeUs, int which); |
| 2201 | |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 2202 | /** |
| 2203 | * Returns the time in microseconds that bluetooth scans were running while the device was |
| 2204 | * on battery. |
| 2205 | * |
| 2206 | * {@hide} |
| 2207 | */ |
| 2208 | public abstract long getBluetoothScanTime(long elapsedRealtimeUs, int which); |
Ruben Brunk | 5b1308f | 2015-06-03 18:49:27 -0700 | [diff] [blame] | 2209 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2210 | public static final int NETWORK_MOBILE_RX_DATA = 0; |
| 2211 | public static final int NETWORK_MOBILE_TX_DATA = 1; |
| 2212 | public static final int NETWORK_WIFI_RX_DATA = 2; |
| 2213 | public static final int NETWORK_WIFI_TX_DATA = 3; |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 2214 | public static final int NETWORK_BT_RX_DATA = 4; |
| 2215 | public static final int NETWORK_BT_TX_DATA = 5; |
Amith Yamasani | 59fe841 | 2017-03-03 16:28:52 -0800 | [diff] [blame] | 2216 | public static final int NETWORK_MOBILE_BG_RX_DATA = 6; |
| 2217 | public static final int NETWORK_MOBILE_BG_TX_DATA = 7; |
| 2218 | public static final int NETWORK_WIFI_BG_RX_DATA = 8; |
| 2219 | public static final int NETWORK_WIFI_BG_TX_DATA = 9; |
| 2220 | public static final int NUM_NETWORK_ACTIVITY_TYPES = NETWORK_WIFI_BG_TX_DATA + 1; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 2221 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2222 | public abstract long getNetworkActivityBytes(int type, int which); |
| 2223 | public abstract long getNetworkActivityPackets(int type, int which); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 2224 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 2225 | /** |
Adam Lesinski | 1739076 | 2015-04-10 13:17:47 -0700 | [diff] [blame] | 2226 | * Returns true if the BatteryStats object has detailed WiFi power reports. |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 2227 | * When true, calling {@link #getWifiControllerActivity()} will yield the |
Adam Lesinski | 1739076 | 2015-04-10 13:17:47 -0700 | [diff] [blame] | 2228 | * actual power data. |
| 2229 | */ |
| 2230 | public abstract boolean hasWifiActivityReporting(); |
| 2231 | |
| 2232 | /** |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 2233 | * Returns a {@link ControllerActivityCounter} which is an aggregate of the times spent |
| 2234 | * in various radio controller states, such as transmit, receive, and idle. |
| 2235 | * @return non-null {@link ControllerActivityCounter} |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 2236 | */ |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 2237 | public abstract ControllerActivityCounter getWifiControllerActivity(); |
| 2238 | |
| 2239 | /** |
| 2240 | * Returns true if the BatteryStats object has detailed bluetooth power reports. |
| 2241 | * When true, calling {@link #getBluetoothControllerActivity()} will yield the |
| 2242 | * actual power data. |
| 2243 | */ |
| 2244 | public abstract boolean hasBluetoothActivityReporting(); |
| 2245 | |
| 2246 | /** |
| 2247 | * Returns a {@link ControllerActivityCounter} which is an aggregate of the times spent |
| 2248 | * in various radio controller states, such as transmit, receive, and idle. |
| 2249 | * @return non-null {@link ControllerActivityCounter} |
| 2250 | */ |
| 2251 | public abstract ControllerActivityCounter getBluetoothControllerActivity(); |
| 2252 | |
| 2253 | /** |
| 2254 | * Returns true if the BatteryStats object has detailed modem power reports. |
| 2255 | * When true, calling {@link #getModemControllerActivity()} will yield the |
| 2256 | * actual power data. |
| 2257 | */ |
| 2258 | public abstract boolean hasModemActivityReporting(); |
| 2259 | |
| 2260 | /** |
| 2261 | * Returns a {@link ControllerActivityCounter} which is an aggregate of the times spent |
| 2262 | * in various radio controller states, such as transmit, receive, and idle. |
| 2263 | * @return non-null {@link ControllerActivityCounter} |
| 2264 | */ |
| 2265 | public abstract ControllerActivityCounter getModemControllerActivity(); |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 2266 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2267 | /** |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 2268 | * Return the wall clock time when battery stats data collection started. |
| 2269 | */ |
| 2270 | public abstract long getStartClockTime(); |
| 2271 | |
| 2272 | /** |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 2273 | * Return platform version tag that we were running in when the battery stats started. |
| 2274 | */ |
| 2275 | public abstract String getStartPlatformVersion(); |
| 2276 | |
| 2277 | /** |
| 2278 | * Return platform version tag that we were running in when the battery stats ended. |
| 2279 | */ |
| 2280 | public abstract String getEndPlatformVersion(); |
| 2281 | |
| 2282 | /** |
| 2283 | * Return the internal version code of the parcelled format. |
| 2284 | */ |
| 2285 | public abstract int getParcelVersion(); |
| 2286 | |
| 2287 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2288 | * Return whether we are currently running on battery. |
| 2289 | */ |
| 2290 | public abstract boolean getIsOnBattery(); |
| 2291 | |
| 2292 | /** |
| 2293 | * Returns a SparseArray containing the statistics for each uid. |
| 2294 | */ |
| 2295 | public abstract SparseArray<? extends Uid> getUidStats(); |
| 2296 | |
| 2297 | /** |
| 2298 | * Returns the current battery uptime in microseconds. |
| 2299 | * |
| 2300 | * @param curTime the amount of elapsed realtime in microseconds. |
| 2301 | */ |
| 2302 | public abstract long getBatteryUptime(long curTime); |
| 2303 | |
| 2304 | /** |
| 2305 | * Returns the current battery realtime in microseconds. |
| 2306 | * |
| 2307 | * @param curTime the amount of elapsed realtime in microseconds. |
| 2308 | */ |
| 2309 | public abstract long getBatteryRealtime(long curTime); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2310 | |
| 2311 | /** |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 2312 | * Returns the battery percentage level at the last time the device was unplugged from power, or |
| 2313 | * the last time it booted on battery power. |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2314 | */ |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 2315 | public abstract int getDischargeStartLevel(); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2316 | |
| 2317 | /** |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 2318 | * Returns the current battery percentage level if we are in a discharge cycle, otherwise |
| 2319 | * returns the level at the last plug event. |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2320 | */ |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 2321 | public abstract int getDischargeCurrentLevel(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2322 | |
| 2323 | /** |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 2324 | * Get the amount the battery has discharged since the stats were |
| 2325 | * last reset after charging, as a lower-end approximation. |
| 2326 | */ |
| 2327 | public abstract int getLowDischargeAmountSinceCharge(); |
| 2328 | |
| 2329 | /** |
| 2330 | * Get the amount the battery has discharged since the stats were |
| 2331 | * last reset after charging, as an upper-end approximation. |
| 2332 | */ |
| 2333 | public abstract int getHighDischargeAmountSinceCharge(); |
| 2334 | |
| 2335 | /** |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2336 | * Retrieve the discharge amount over the selected discharge period <var>which</var>. |
| 2337 | */ |
| 2338 | public abstract int getDischargeAmount(int which); |
| 2339 | |
| 2340 | /** |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 2341 | * Get the amount the battery has discharged while the screen was on, |
| 2342 | * since the last time power was unplugged. |
| 2343 | */ |
| 2344 | public abstract int getDischargeAmountScreenOn(); |
| 2345 | |
| 2346 | /** |
| 2347 | * Get the amount the battery has discharged while the screen was on, |
| 2348 | * since the last time the device was charged. |
| 2349 | */ |
| 2350 | public abstract int getDischargeAmountScreenOnSinceCharge(); |
| 2351 | |
| 2352 | /** |
| 2353 | * Get the amount the battery has discharged while the screen was off, |
| 2354 | * since the last time power was unplugged. |
| 2355 | */ |
| 2356 | public abstract int getDischargeAmountScreenOff(); |
| 2357 | |
| 2358 | /** |
| 2359 | * Get the amount the battery has discharged while the screen was off, |
| 2360 | * since the last time the device was charged. |
| 2361 | */ |
| 2362 | public abstract int getDischargeAmountScreenOffSinceCharge(); |
| 2363 | |
| 2364 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2365 | * Returns the total, last, or current battery uptime in microseconds. |
| 2366 | * |
| 2367 | * @param curTime the elapsed realtime in microseconds. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2368 | * @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] | 2369 | */ |
| 2370 | public abstract long computeBatteryUptime(long curTime, int which); |
| 2371 | |
| 2372 | /** |
| 2373 | * Returns the total, last, or current battery realtime in microseconds. |
| 2374 | * |
| 2375 | * @param curTime the current elapsed realtime in microseconds. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2376 | * @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] | 2377 | */ |
| 2378 | public abstract long computeBatteryRealtime(long curTime, int which); |
| 2379 | |
| 2380 | /** |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2381 | * Returns the total, last, or current battery screen off uptime in microseconds. |
| 2382 | * |
| 2383 | * @param curTime the elapsed realtime in microseconds. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2384 | * @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] | 2385 | */ |
| 2386 | public abstract long computeBatteryScreenOffUptime(long curTime, int which); |
| 2387 | |
| 2388 | /** |
| 2389 | * Returns the total, last, or current battery screen off realtime in microseconds. |
| 2390 | * |
| 2391 | * @param curTime the current elapsed realtime in microseconds. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2392 | * @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] | 2393 | */ |
| 2394 | public abstract long computeBatteryScreenOffRealtime(long curTime, int which); |
| 2395 | |
| 2396 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2397 | * Returns the total, last, or current uptime in microseconds. |
| 2398 | * |
| 2399 | * @param curTime the current elapsed realtime in microseconds. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2400 | * @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] | 2401 | */ |
| 2402 | public abstract long computeUptime(long curTime, int which); |
| 2403 | |
| 2404 | /** |
| 2405 | * Returns the total, last, or current realtime in microseconds. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2406 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2407 | * @param curTime the current elapsed realtime in microseconds. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2408 | * @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] | 2409 | */ |
| 2410 | public abstract long computeRealtime(long curTime, int which); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2411 | |
| 2412 | /** |
| 2413 | * Compute an approximation for how much run time (in microseconds) is remaining on |
| 2414 | * the battery. Returns -1 if no time can be computed: either there is not |
| 2415 | * enough current data to make a decision, or the battery is currently |
| 2416 | * charging. |
| 2417 | * |
| 2418 | * @param curTime The current elepsed realtime in microseconds. |
| 2419 | */ |
| 2420 | public abstract long computeBatteryTimeRemaining(long curTime); |
| 2421 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 2422 | // The part of a step duration that is the actual time. |
| 2423 | public static final long STEP_LEVEL_TIME_MASK = 0x000000ffffffffffL; |
| 2424 | |
| 2425 | // Bits in a step duration that are the new battery level we are at. |
| 2426 | public static final long STEP_LEVEL_LEVEL_MASK = 0x0000ff0000000000L; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2427 | public static final int STEP_LEVEL_LEVEL_SHIFT = 40; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 2428 | |
| 2429 | // Bits in a step duration that are the initial mode we were in at that step. |
| 2430 | public static final long STEP_LEVEL_INITIAL_MODE_MASK = 0x00ff000000000000L; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2431 | public static final int STEP_LEVEL_INITIAL_MODE_SHIFT = 48; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 2432 | |
| 2433 | // Bits in a step duration that indicate which modes changed during that step. |
| 2434 | public static final long STEP_LEVEL_MODIFIED_MODE_MASK = 0xff00000000000000L; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2435 | public static final int STEP_LEVEL_MODIFIED_MODE_SHIFT = 56; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 2436 | |
| 2437 | // Step duration mode: the screen is on, off, dozed, etc; value is Display.STATE_* - 1. |
| 2438 | public static final int STEP_LEVEL_MODE_SCREEN_STATE = 0x03; |
| 2439 | |
Santos Cordon | e94f050 | 2017-02-24 12:31:20 -0800 | [diff] [blame] | 2440 | // The largest value for screen state that is tracked in battery states. Any values above |
| 2441 | // this should be mapped back to one of the tracked values before being tracked here. |
| 2442 | public static final int MAX_TRACKED_SCREEN_STATE = Display.STATE_DOZE_SUSPEND; |
| 2443 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 2444 | // Step duration mode: power save is on. |
| 2445 | public static final int STEP_LEVEL_MODE_POWER_SAVE = 0x04; |
| 2446 | |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2447 | // Step duration mode: device is currently in idle mode. |
| 2448 | public static final int STEP_LEVEL_MODE_DEVICE_IDLE = 0x08; |
| 2449 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2450 | public static final int[] STEP_LEVEL_MODES_OF_INTEREST = new int[] { |
| 2451 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE, |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2452 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE|STEP_LEVEL_MODE_DEVICE_IDLE, |
| 2453 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_DEVICE_IDLE, |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2454 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE, |
| 2455 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE, |
| 2456 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE, |
| 2457 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE, |
| 2458 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE, |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2459 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE|STEP_LEVEL_MODE_DEVICE_IDLE, |
| 2460 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_DEVICE_IDLE, |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2461 | }; |
| 2462 | public static final int[] STEP_LEVEL_MODE_VALUES = new int[] { |
| 2463 | (Display.STATE_OFF-1), |
| 2464 | (Display.STATE_OFF-1)|STEP_LEVEL_MODE_POWER_SAVE, |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2465 | (Display.STATE_OFF-1)|STEP_LEVEL_MODE_DEVICE_IDLE, |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2466 | (Display.STATE_ON-1), |
| 2467 | (Display.STATE_ON-1)|STEP_LEVEL_MODE_POWER_SAVE, |
| 2468 | (Display.STATE_DOZE-1), |
| 2469 | (Display.STATE_DOZE-1)|STEP_LEVEL_MODE_POWER_SAVE, |
| 2470 | (Display.STATE_DOZE_SUSPEND-1), |
| 2471 | (Display.STATE_DOZE_SUSPEND-1)|STEP_LEVEL_MODE_POWER_SAVE, |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2472 | (Display.STATE_DOZE_SUSPEND-1)|STEP_LEVEL_MODE_DEVICE_IDLE, |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2473 | }; |
| 2474 | public static final String[] STEP_LEVEL_MODE_LABELS = new String[] { |
| 2475 | "screen off", |
| 2476 | "screen off power save", |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2477 | "screen off device idle", |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2478 | "screen on", |
| 2479 | "screen on power save", |
| 2480 | "screen doze", |
| 2481 | "screen doze power save", |
| 2482 | "screen doze-suspend", |
| 2483 | "screen doze-suspend power save", |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2484 | "screen doze-suspend device idle", |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2485 | }; |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 2486 | |
| 2487 | /** |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 2488 | * Return the counter keeping track of the amount of battery discharge while the screen was off, |
| 2489 | * measured in micro-Ampere-hours. This will be non-zero only if the device's battery has |
| 2490 | * a coulomb counter. |
| 2491 | */ |
| 2492 | public abstract LongCounter getDischargeScreenOffCoulombCounter(); |
| 2493 | |
| 2494 | /** |
| 2495 | * Return the counter keeping track of the amount of battery discharge measured in |
| 2496 | * micro-Ampere-hours. This will be non-zero only if the device's battery has |
| 2497 | * a coulomb counter. |
| 2498 | */ |
| 2499 | public abstract LongCounter getDischargeCoulombCounter(); |
| 2500 | |
| 2501 | /** |
Adam Lesinski | f9b20a9 | 2016-06-17 17:30:01 -0700 | [diff] [blame] | 2502 | * Returns the estimated real battery capacity, which may be less than the capacity |
| 2503 | * declared by the PowerProfile. |
| 2504 | * @return The estimated battery capacity in mAh. |
| 2505 | */ |
| 2506 | public abstract int getEstimatedBatteryCapacity(); |
| 2507 | |
| 2508 | /** |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2509 | * Return the array of discharge step durations. |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 2510 | */ |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2511 | public abstract LevelStepTracker getDischargeLevelStepTracker(); |
| 2512 | |
| 2513 | /** |
| 2514 | * Return the array of daily discharge step durations. |
| 2515 | */ |
| 2516 | public abstract LevelStepTracker getDailyDischargeLevelStepTracker(); |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 2517 | |
| 2518 | /** |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2519 | * Compute an approximation for how much time (in microseconds) remains until the battery |
| 2520 | * is fully charged. Returns -1 if no time can be computed: either there is not |
| 2521 | * enough current data to make a decision, or the battery is currently |
| 2522 | * discharging. |
| 2523 | * |
| 2524 | * @param curTime The current elepsed realtime in microseconds. |
| 2525 | */ |
| 2526 | public abstract long computeChargeTimeRemaining(long curTime); |
| 2527 | |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 2528 | /** |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2529 | * Return the array of charge step durations. |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 2530 | */ |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2531 | public abstract LevelStepTracker getChargeLevelStepTracker(); |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 2532 | |
| 2533 | /** |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2534 | * Return the array of daily charge step durations. |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 2535 | */ |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2536 | public abstract LevelStepTracker getDailyChargeLevelStepTracker(); |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 2537 | |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2538 | public abstract ArrayList<PackageChange> getDailyPackageChanges(); |
| 2539 | |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 2540 | public abstract Map<String, ? extends Timer> getWakeupReasonStats(); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2541 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2542 | public abstract Map<String, ? extends Timer> getKernelWakelockStats(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2543 | |
James Carr | 2dd7e5e | 2016-07-20 18:48:39 -0700 | [diff] [blame] | 2544 | public abstract LongSparseArray<? extends Timer> getKernelMemoryStats(); |
| 2545 | |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 2546 | public abstract void writeToParcelWithoutUids(Parcel out, int flags); |
| 2547 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 2548 | private final static void formatTimeRaw(StringBuilder out, long seconds) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2549 | long days = seconds / (60 * 60 * 24); |
| 2550 | if (days != 0) { |
| 2551 | out.append(days); |
| 2552 | out.append("d "); |
| 2553 | } |
| 2554 | long used = days * 60 * 60 * 24; |
| 2555 | |
| 2556 | long hours = (seconds - used) / (60 * 60); |
| 2557 | if (hours != 0 || used != 0) { |
| 2558 | out.append(hours); |
| 2559 | out.append("h "); |
| 2560 | } |
| 2561 | used += hours * 60 * 60; |
| 2562 | |
| 2563 | long mins = (seconds-used) / 60; |
| 2564 | if (mins != 0 || used != 0) { |
| 2565 | out.append(mins); |
| 2566 | out.append("m "); |
| 2567 | } |
| 2568 | used += mins * 60; |
| 2569 | |
| 2570 | if (seconds != 0 || used != 0) { |
| 2571 | out.append(seconds-used); |
| 2572 | out.append("s "); |
| 2573 | } |
| 2574 | } |
| 2575 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2576 | public final static void formatTimeMs(StringBuilder sb, long time) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2577 | long sec = time / 1000; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 2578 | formatTimeRaw(sb, sec); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2579 | sb.append(time - (sec * 1000)); |
| 2580 | sb.append("ms "); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2581 | } |
| 2582 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2583 | public final static void formatTimeMsNoSpace(StringBuilder sb, long time) { |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 2584 | long sec = time / 1000; |
| 2585 | formatTimeRaw(sb, sec); |
| 2586 | sb.append(time - (sec * 1000)); |
| 2587 | sb.append("ms"); |
| 2588 | } |
| 2589 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2590 | public final String formatRatioLocked(long num, long den) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2591 | if (den == 0L) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2592 | return "--%"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2593 | } |
| 2594 | float perc = ((float)num) / ((float)den) * 100; |
| 2595 | mFormatBuilder.setLength(0); |
| 2596 | mFormatter.format("%.1f%%", perc); |
| 2597 | return mFormatBuilder.toString(); |
| 2598 | } |
| 2599 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2600 | final String formatBytesLocked(long bytes) { |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 2601 | mFormatBuilder.setLength(0); |
| 2602 | |
| 2603 | if (bytes < BYTES_PER_KB) { |
| 2604 | return bytes + "B"; |
| 2605 | } else if (bytes < BYTES_PER_MB) { |
| 2606 | mFormatter.format("%.2fKB", bytes / (double) BYTES_PER_KB); |
| 2607 | return mFormatBuilder.toString(); |
| 2608 | } else if (bytes < BYTES_PER_GB){ |
| 2609 | mFormatter.format("%.2fMB", bytes / (double) BYTES_PER_MB); |
| 2610 | return mFormatBuilder.toString(); |
| 2611 | } else { |
| 2612 | mFormatter.format("%.2fGB", bytes / (double) BYTES_PER_GB); |
| 2613 | return mFormatBuilder.toString(); |
| 2614 | } |
| 2615 | } |
| 2616 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2617 | private static long computeWakeLock(Timer timer, long elapsedRealtimeUs, int which) { |
Dianne Hackborn | c24ab86 | 2011-10-18 15:55:03 -0700 | [diff] [blame] | 2618 | if (timer != null) { |
| 2619 | // Convert from microseconds to milliseconds with rounding |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2620 | long totalTimeMicros = timer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Dianne Hackborn | c24ab86 | 2011-10-18 15:55:03 -0700 | [diff] [blame] | 2621 | long totalTimeMillis = (totalTimeMicros + 500) / 1000; |
| 2622 | return totalTimeMillis; |
| 2623 | } |
| 2624 | return 0; |
| 2625 | } |
| 2626 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2627 | /** |
| 2628 | * |
| 2629 | * @param sb a StringBuilder object. |
| 2630 | * @param timer a Timer object contining the wakelock times. |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2631 | * @param elapsedRealtimeUs the current on-battery time in microseconds. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2632 | * @param name the name of the wakelock. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2633 | * @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] | 2634 | * @param linePrefix a String to be prepended to each line of output. |
| 2635 | * @return the line prefix |
| 2636 | */ |
| 2637 | private static final String printWakeLock(StringBuilder sb, Timer timer, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2638 | long elapsedRealtimeUs, String name, int which, String linePrefix) { |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 2639 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2640 | if (timer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2641 | long totalTimeMillis = computeWakeLock(timer, elapsedRealtimeUs, which); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 2642 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2643 | int count = timer.getCountLocked(which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2644 | if (totalTimeMillis != 0) { |
| 2645 | sb.append(linePrefix); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 2646 | formatTimeMs(sb, totalTimeMillis); |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 2647 | if (name != null) { |
| 2648 | sb.append(name); |
| 2649 | sb.append(' '); |
| 2650 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2651 | sb.append('('); |
| 2652 | sb.append(count); |
| 2653 | sb.append(" times)"); |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2654 | final long maxDurationMs = timer.getMaxDurationMsLocked(elapsedRealtimeUs/1000); |
| 2655 | if (maxDurationMs >= 0) { |
| 2656 | sb.append(" max="); |
| 2657 | sb.append(maxDurationMs); |
| 2658 | } |
| 2659 | if (timer.isRunningLocked()) { |
| 2660 | final long currentMs = timer.getCurrentDurationMsLocked(elapsedRealtimeUs/1000); |
| 2661 | if (currentMs >= 0) { |
| 2662 | sb.append(" (running for "); |
| 2663 | sb.append(currentMs); |
| 2664 | sb.append("ms)"); |
| 2665 | } else { |
| 2666 | sb.append(" (running)"); |
| 2667 | } |
| 2668 | } |
| 2669 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2670 | return ", "; |
| 2671 | } |
| 2672 | } |
| 2673 | return linePrefix; |
| 2674 | } |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 2675 | |
| 2676 | /** |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2677 | * Prints details about a timer, if its total time was greater than 0. |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 2678 | * |
| 2679 | * @param pw a PrintWriter object to print to. |
| 2680 | * @param sb a StringBuilder object. |
| 2681 | * @param timer a Timer object contining the wakelock times. |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2682 | * @param rawRealtimeUs the current on-battery time in microseconds. |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 2683 | * @param which which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT. |
| 2684 | * @param prefix a String to be prepended to each line of output. |
| 2685 | * @param type the name of the timer. |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2686 | * @return true if anything was printed. |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 2687 | */ |
| 2688 | private static final boolean printTimer(PrintWriter pw, StringBuilder sb, Timer timer, |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2689 | long rawRealtimeUs, int which, String prefix, String type) { |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 2690 | if (timer != null) { |
| 2691 | // Convert from microseconds to milliseconds with rounding |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2692 | final long totalTimeMs = (timer.getTotalTimeLocked( |
| 2693 | rawRealtimeUs, which) + 500) / 1000; |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 2694 | final int count = timer.getCountLocked(which); |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2695 | if (totalTimeMs != 0) { |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 2696 | sb.setLength(0); |
| 2697 | sb.append(prefix); |
| 2698 | sb.append(" "); |
| 2699 | sb.append(type); |
| 2700 | sb.append(": "); |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2701 | formatTimeMs(sb, totalTimeMs); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 2702 | sb.append("realtime ("); |
| 2703 | sb.append(count); |
| 2704 | sb.append(" times)"); |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2705 | final long maxDurationMs = timer.getMaxDurationMsLocked(rawRealtimeUs/1000); |
| 2706 | if (maxDurationMs >= 0) { |
| 2707 | sb.append(" max="); |
| 2708 | sb.append(maxDurationMs); |
| 2709 | } |
| 2710 | if (timer.isRunningLocked()) { |
| 2711 | final long currentMs = timer.getCurrentDurationMsLocked(rawRealtimeUs/1000); |
| 2712 | if (currentMs >= 0) { |
| 2713 | sb.append(" (running for "); |
| 2714 | sb.append(currentMs); |
| 2715 | sb.append("ms)"); |
| 2716 | } else { |
| 2717 | sb.append(" (running)"); |
| 2718 | } |
| 2719 | } |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 2720 | pw.println(sb.toString()); |
| 2721 | return true; |
| 2722 | } |
| 2723 | } |
| 2724 | return false; |
| 2725 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2726 | |
| 2727 | /** |
| 2728 | * Checkin version of wakelock printer. Prints simple comma-separated list. |
| 2729 | * |
| 2730 | * @param sb a StringBuilder object. |
| 2731 | * @param timer a Timer object contining the wakelock times. |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2732 | * @param elapsedRealtimeUs the current time in microseconds. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2733 | * @param name the name of the wakelock. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2734 | * @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] | 2735 | * @param linePrefix a String to be prepended to each line of output. |
| 2736 | * @return the line prefix |
| 2737 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2738 | private static final String printWakeLockCheckin(StringBuilder sb, Timer timer, |
| 2739 | long elapsedRealtimeUs, String name, int which, String linePrefix) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2740 | long totalTimeMicros = 0; |
| 2741 | int count = 0; |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2742 | long max = -1; |
| 2743 | long current = -1; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2744 | if (timer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2745 | totalTimeMicros = timer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2746 | count = timer.getCountLocked(which); |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2747 | current = timer.getCurrentDurationMsLocked(elapsedRealtimeUs/1000); |
| 2748 | max = timer.getMaxDurationMsLocked(elapsedRealtimeUs/1000); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2749 | } |
| 2750 | sb.append(linePrefix); |
| 2751 | sb.append((totalTimeMicros + 500) / 1000); // microseconds to milliseconds with rounding |
| 2752 | sb.append(','); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2753 | sb.append(name != null ? name + "," : ""); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2754 | sb.append(count); |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2755 | sb.append(','); |
| 2756 | sb.append(current); |
| 2757 | sb.append(','); |
| 2758 | sb.append(max); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2759 | return ","; |
| 2760 | } |
| 2761 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 2762 | private static final void dumpLineHeader(PrintWriter pw, int uid, String category, |
| 2763 | String type) { |
| 2764 | pw.print(BATTERY_STATS_CHECKIN_VERSION); |
| 2765 | pw.print(','); |
| 2766 | pw.print(uid); |
| 2767 | pw.print(','); |
| 2768 | pw.print(category); |
| 2769 | pw.print(','); |
| 2770 | pw.print(type); |
| 2771 | } |
| 2772 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2773 | /** |
| 2774 | * Dump a comma-separated line of values for terse checkin mode. |
| 2775 | * |
| 2776 | * @param pw the PageWriter to dump log to |
| 2777 | * @param category category of data (e.g. "total", "last", "unplugged", "current" ) |
| 2778 | * @param type type of data (e.g. "wakelock", "sensor", "process", "apk" , "process", "network") |
| 2779 | * @param args type-dependent data arguments |
| 2780 | */ |
| 2781 | private static final void dumpLine(PrintWriter pw, int uid, String category, String type, |
| 2782 | Object... args ) { |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 2783 | dumpLineHeader(pw, uid, category, type); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 2784 | for (Object arg : args) { |
Dianne Hackborn | 13ac041 | 2013-06-25 19:34:49 -0700 | [diff] [blame] | 2785 | pw.print(','); |
| 2786 | pw.print(arg); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2787 | } |
Dianne Hackborn | 13ac041 | 2013-06-25 19:34:49 -0700 | [diff] [blame] | 2788 | pw.println(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2789 | } |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 2790 | |
| 2791 | /** |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 2792 | * Dump a given timer stat for terse checkin mode. |
| 2793 | * |
| 2794 | * @param pw the PageWriter to dump log to |
| 2795 | * @param uid the UID to log |
| 2796 | * @param category category of data (e.g. "total", "last", "unplugged", "current" ) |
| 2797 | * @param type type of data (e.g. "wakelock", "sensor", "process", "apk" , "process", "network") |
| 2798 | * @param timer a {@link Timer} to dump stats for |
| 2799 | * @param rawRealtime the current elapsed realtime of the system in microseconds |
| 2800 | * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT |
| 2801 | */ |
| 2802 | private static final void dumpTimer(PrintWriter pw, int uid, String category, String type, |
| 2803 | Timer timer, long rawRealtime, int which) { |
| 2804 | if (timer != null) { |
| 2805 | // Convert from microseconds to milliseconds with rounding |
| 2806 | final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) |
| 2807 | / 1000; |
| 2808 | final int count = timer.getCountLocked(which); |
| 2809 | if (totalTime != 0) { |
| 2810 | dumpLine(pw, uid, category, type, totalTime, count); |
| 2811 | } |
| 2812 | } |
| 2813 | } |
| 2814 | |
| 2815 | /** |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 2816 | * Checks if the ControllerActivityCounter has any data worth dumping. |
| 2817 | */ |
| 2818 | private static boolean controllerActivityHasData(ControllerActivityCounter counter, int which) { |
| 2819 | if (counter == null) { |
| 2820 | return false; |
| 2821 | } |
| 2822 | |
| 2823 | if (counter.getIdleTimeCounter().getCountLocked(which) != 0 |
| 2824 | || counter.getRxTimeCounter().getCountLocked(which) != 0 |
| 2825 | || counter.getPowerCounter().getCountLocked(which) != 0) { |
| 2826 | return true; |
| 2827 | } |
| 2828 | |
| 2829 | for (LongCounter c : counter.getTxTimeCounters()) { |
| 2830 | if (c.getCountLocked(which) != 0) { |
| 2831 | return true; |
| 2832 | } |
| 2833 | } |
| 2834 | return false; |
| 2835 | } |
| 2836 | |
| 2837 | /** |
| 2838 | * Dumps the ControllerActivityCounter if it has any data worth dumping. |
| 2839 | * The order of the arguments in the final check in line is: |
| 2840 | * |
| 2841 | * idle, rx, power, tx... |
| 2842 | * |
| 2843 | * where tx... is one or more transmit level times. |
| 2844 | */ |
| 2845 | private static final void dumpControllerActivityLine(PrintWriter pw, int uid, String category, |
| 2846 | String type, |
| 2847 | ControllerActivityCounter counter, |
| 2848 | int which) { |
| 2849 | if (!controllerActivityHasData(counter, which)) { |
| 2850 | return; |
| 2851 | } |
| 2852 | |
| 2853 | dumpLineHeader(pw, uid, category, type); |
| 2854 | pw.print(","); |
| 2855 | pw.print(counter.getIdleTimeCounter().getCountLocked(which)); |
| 2856 | pw.print(","); |
| 2857 | pw.print(counter.getRxTimeCounter().getCountLocked(which)); |
| 2858 | pw.print(","); |
| 2859 | pw.print(counter.getPowerCounter().getCountLocked(which) / (1000 * 60 * 60)); |
| 2860 | for (LongCounter c : counter.getTxTimeCounters()) { |
| 2861 | pw.print(","); |
| 2862 | pw.print(c.getCountLocked(which)); |
| 2863 | } |
| 2864 | pw.println(); |
| 2865 | } |
| 2866 | |
| 2867 | private final void printControllerActivityIfInteresting(PrintWriter pw, StringBuilder sb, |
| 2868 | String prefix, String controllerName, |
| 2869 | ControllerActivityCounter counter, |
| 2870 | int which) { |
| 2871 | if (controllerActivityHasData(counter, which)) { |
| 2872 | printControllerActivity(pw, sb, prefix, controllerName, counter, which); |
| 2873 | } |
| 2874 | } |
| 2875 | |
| 2876 | private final void printControllerActivity(PrintWriter pw, StringBuilder sb, String prefix, |
| 2877 | String controllerName, |
| 2878 | ControllerActivityCounter counter, int which) { |
| 2879 | final long idleTimeMs = counter.getIdleTimeCounter().getCountLocked(which); |
| 2880 | final long rxTimeMs = counter.getRxTimeCounter().getCountLocked(which); |
| 2881 | final long powerDrainMaMs = counter.getPowerCounter().getCountLocked(which); |
| 2882 | long totalTxTimeMs = 0; |
| 2883 | for (LongCounter txState : counter.getTxTimeCounters()) { |
| 2884 | totalTxTimeMs += txState.getCountLocked(which); |
| 2885 | } |
| 2886 | |
| 2887 | final long totalTimeMs = idleTimeMs + rxTimeMs + totalTxTimeMs; |
| 2888 | |
| 2889 | sb.setLength(0); |
| 2890 | sb.append(prefix); |
| 2891 | sb.append(" "); |
| 2892 | sb.append(controllerName); |
| 2893 | sb.append(" Idle time: "); |
| 2894 | formatTimeMs(sb, idleTimeMs); |
| 2895 | sb.append("("); |
| 2896 | sb.append(formatRatioLocked(idleTimeMs, totalTimeMs)); |
| 2897 | sb.append(")"); |
| 2898 | pw.println(sb.toString()); |
| 2899 | |
| 2900 | sb.setLength(0); |
| 2901 | sb.append(prefix); |
| 2902 | sb.append(" "); |
| 2903 | sb.append(controllerName); |
| 2904 | sb.append(" Rx time: "); |
| 2905 | formatTimeMs(sb, rxTimeMs); |
| 2906 | sb.append("("); |
| 2907 | sb.append(formatRatioLocked(rxTimeMs, totalTimeMs)); |
| 2908 | sb.append(")"); |
| 2909 | pw.println(sb.toString()); |
| 2910 | |
| 2911 | sb.setLength(0); |
| 2912 | sb.append(prefix); |
| 2913 | sb.append(" "); |
| 2914 | sb.append(controllerName); |
| 2915 | sb.append(" Tx time: "); |
| 2916 | formatTimeMs(sb, totalTxTimeMs); |
| 2917 | sb.append("("); |
| 2918 | sb.append(formatRatioLocked(totalTxTimeMs, totalTimeMs)); |
| 2919 | sb.append(")"); |
| 2920 | pw.println(sb.toString()); |
| 2921 | |
| 2922 | final int numTxLvls = counter.getTxTimeCounters().length; |
| 2923 | if (numTxLvls > 1) { |
| 2924 | for (int lvl = 0; lvl < numTxLvls; lvl++) { |
| 2925 | final long txLvlTimeMs = counter.getTxTimeCounters()[lvl].getCountLocked(which); |
| 2926 | sb.setLength(0); |
| 2927 | sb.append(prefix); |
| 2928 | sb.append(" ["); |
| 2929 | sb.append(lvl); |
| 2930 | sb.append("] "); |
| 2931 | formatTimeMs(sb, txLvlTimeMs); |
| 2932 | sb.append("("); |
| 2933 | sb.append(formatRatioLocked(txLvlTimeMs, totalTxTimeMs)); |
| 2934 | sb.append(")"); |
| 2935 | pw.println(sb.toString()); |
| 2936 | } |
| 2937 | } |
| 2938 | |
| 2939 | sb.setLength(0); |
| 2940 | sb.append(prefix); |
| 2941 | sb.append(" "); |
| 2942 | sb.append(controllerName); |
| 2943 | sb.append(" Power drain: ").append( |
| 2944 | BatteryStatsHelper.makemAh(powerDrainMaMs / (double) (1000*60*60))); |
| 2945 | sb.append("mAh"); |
| 2946 | pw.println(sb.toString()); |
| 2947 | } |
| 2948 | |
| 2949 | /** |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 2950 | * Temporary for settings. |
| 2951 | */ |
| 2952 | public final void dumpCheckinLocked(Context context, PrintWriter pw, int which, int reqUid) { |
| 2953 | dumpCheckinLocked(context, pw, which, reqUid, BatteryStatsHelper.checkWifiOnly(context)); |
| 2954 | } |
| 2955 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2956 | /** |
| 2957 | * Checkin server version of dump to produce more compact, computer-readable log. |
| 2958 | * |
| 2959 | * NOTE: all times are expressed in 'ms'. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2960 | */ |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 2961 | public final void dumpCheckinLocked(Context context, PrintWriter pw, int which, int reqUid, |
| 2962 | boolean wifiOnly) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2963 | final long rawUptime = SystemClock.uptimeMillis() * 1000; |
| 2964 | final long rawRealtime = SystemClock.elapsedRealtime() * 1000; |
| 2965 | final long batteryUptime = getBatteryUptime(rawUptime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2966 | final long whichBatteryUptime = computeBatteryUptime(rawUptime, which); |
| 2967 | final long whichBatteryRealtime = computeBatteryRealtime(rawRealtime, which); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2968 | final long whichBatteryScreenOffUptime = computeBatteryScreenOffUptime(rawUptime, which); |
| 2969 | final long whichBatteryScreenOffRealtime = computeBatteryScreenOffRealtime(rawRealtime, |
| 2970 | which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2971 | final long totalRealtime = computeRealtime(rawRealtime, which); |
| 2972 | final long totalUptime = computeUptime(rawUptime, which); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2973 | final long screenOnTime = getScreenOnTime(rawRealtime, which); |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 2974 | final long interactiveTime = getInteractiveTime(rawRealtime, which); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 2975 | final long powerSaveModeEnabledTime = getPowerSaveModeEnabledTime(rawRealtime, which); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 2976 | final long deviceIdleModeLightTime = getDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT, |
| 2977 | rawRealtime, which); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 2978 | final long deviceIdleModeFullTime = getDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP, |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 2979 | rawRealtime, which); |
| 2980 | final long deviceLightIdlingTime = getDeviceIdlingTime(DEVICE_IDLE_MODE_LIGHT, |
| 2981 | rawRealtime, which); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 2982 | final long deviceIdlingTime = getDeviceIdlingTime(DEVICE_IDLE_MODE_DEEP, |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 2983 | rawRealtime, which); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 2984 | final int connChanges = getNumConnectivityChange(which); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2985 | final long phoneOnTime = getPhoneOnTime(rawRealtime, which); |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 2986 | final long dischargeCount = getDischargeCoulombCounter().getCountLocked(which); |
| 2987 | final long dischargeScreenOffCount = getDischargeScreenOffCoulombCounter() |
| 2988 | .getCountLocked(which); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 2989 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 2990 | final StringBuilder sb = new StringBuilder(128); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2991 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 2992 | final SparseArray<? extends Uid> uidStats = getUidStats(); |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 2993 | final int NU = uidStats.size(); |
| 2994 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 2995 | final String category = STAT_NAMES[which]; |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 2996 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2997 | // Dump "battery" stat |
| 2998 | dumpLine(pw, 0 /* uid */, category, BATTERY_DATA, |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2999 | which == STATS_SINCE_CHARGED ? getStartCount() : "N/A", |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3000 | whichBatteryRealtime / 1000, whichBatteryUptime / 1000, |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 3001 | totalRealtime / 1000, totalUptime / 1000, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3002 | getStartClockTime(), |
Adam Lesinski | f9b20a9 | 2016-06-17 17:30:01 -0700 | [diff] [blame] | 3003 | whichBatteryScreenOffRealtime / 1000, whichBatteryScreenOffUptime / 1000, |
| 3004 | getEstimatedBatteryCapacity()); |
Adam Lesinski | 67c134f | 2016-06-10 15:15:08 -0700 | [diff] [blame] | 3005 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3006 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3007 | // Calculate wakelock times across all uids. |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 3008 | long fullWakeLockTimeTotal = 0; |
| 3009 | long partialWakeLockTimeTotal = 0; |
| 3010 | |
| 3011 | for (int iu = 0; iu < NU; iu++) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3012 | final Uid u = uidStats.valueAt(iu); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 3013 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3014 | final ArrayMap<String, ? extends BatteryStats.Uid.Wakelock> wakelocks |
| 3015 | = u.getWakelockStats(); |
| 3016 | for (int iw=wakelocks.size()-1; iw>=0; iw--) { |
| 3017 | final Uid.Wakelock wl = wakelocks.valueAt(iw); |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 3018 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3019 | final Timer fullWakeTimer = wl.getWakeTime(WAKE_TYPE_FULL); |
| 3020 | if (fullWakeTimer != null) { |
| 3021 | fullWakeLockTimeTotal += fullWakeTimer.getTotalTimeLocked(rawRealtime, |
| 3022 | which); |
| 3023 | } |
| 3024 | |
| 3025 | final Timer partialWakeTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL); |
| 3026 | if (partialWakeTimer != null) { |
| 3027 | partialWakeLockTimeTotal += partialWakeTimer.getTotalTimeLocked( |
| 3028 | rawRealtime, which); |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 3029 | } |
| 3030 | } |
| 3031 | } |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 3032 | |
| 3033 | // Dump network stats |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3034 | final long mobileRxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which); |
| 3035 | final long mobileTxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which); |
| 3036 | final long wifiRxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which); |
| 3037 | final long wifiTxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which); |
| 3038 | final long mobileRxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which); |
| 3039 | final long mobileTxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which); |
| 3040 | final long wifiRxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which); |
| 3041 | final long wifiTxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 3042 | final long btRxTotalBytes = getNetworkActivityBytes(NETWORK_BT_RX_DATA, which); |
| 3043 | final long btTxTotalBytes = getNetworkActivityBytes(NETWORK_BT_TX_DATA, which); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3044 | dumpLine(pw, 0 /* uid */, category, GLOBAL_NETWORK_DATA, |
| 3045 | mobileRxTotalBytes, mobileTxTotalBytes, wifiRxTotalBytes, wifiTxTotalBytes, |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 3046 | mobileRxTotalPackets, mobileTxTotalPackets, wifiRxTotalPackets, wifiTxTotalPackets, |
| 3047 | btRxTotalBytes, btTxTotalBytes); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3048 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3049 | // Dump Modem controller stats |
| 3050 | dumpControllerActivityLine(pw, 0 /* uid */, category, GLOBAL_MODEM_CONTROLLER_DATA, |
| 3051 | getModemControllerActivity(), which); |
| 3052 | |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 3053 | // Dump Wifi controller stats |
| 3054 | final long wifiOnTime = getWifiOnTime(rawRealtime, which); |
| 3055 | final long wifiRunningTime = getGlobalWifiRunningTime(rawRealtime, which); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3056 | dumpLine(pw, 0 /* uid */, category, GLOBAL_WIFI_DATA, wifiOnTime / 1000, |
Adam Lesinski | 2208e74 | 2016-02-19 12:53:31 -0800 | [diff] [blame] | 3057 | wifiRunningTime / 1000, /* legacy fields follow, keep at 0 */ 0, 0, 0); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3058 | |
| 3059 | dumpControllerActivityLine(pw, 0 /* uid */, category, GLOBAL_WIFI_CONTROLLER_DATA, |
| 3060 | getWifiControllerActivity(), which); |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 3061 | |
| 3062 | // Dump Bluetooth controller stats |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3063 | dumpControllerActivityLine(pw, 0 /* uid */, category, GLOBAL_BLUETOOTH_CONTROLLER_DATA, |
| 3064 | getBluetoothControllerActivity(), which); |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 3065 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3066 | // Dump misc stats |
| 3067 | dumpLine(pw, 0 /* uid */, category, MISC_DATA, |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 3068 | screenOnTime / 1000, phoneOnTime / 1000, |
Ashish Sharma | 213bb2f | 2014-07-07 17:14:52 -0700 | [diff] [blame] | 3069 | fullWakeLockTimeTotal / 1000, partialWakeLockTimeTotal / 1000, |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 3070 | getMobileRadioActiveTime(rawRealtime, which) / 1000, |
Ashish Sharma | 213bb2f | 2014-07-07 17:14:52 -0700 | [diff] [blame] | 3071 | getMobileRadioActiveAdjustedTime(which) / 1000, interactiveTime / 1000, |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3072 | powerSaveModeEnabledTime / 1000, connChanges, deviceIdleModeFullTime / 1000, |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 3073 | getDeviceIdleModeCount(DEVICE_IDLE_MODE_DEEP, which), deviceIdlingTime / 1000, |
| 3074 | getDeviceIdlingCount(DEVICE_IDLE_MODE_DEEP, which), |
Adam Lesinski | 782327b | 2015-07-30 16:36:29 -0700 | [diff] [blame] | 3075 | getMobileRadioActiveCount(which), |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3076 | getMobileRadioActiveUnknownTime(which) / 1000, deviceIdleModeLightTime / 1000, |
| 3077 | getDeviceIdleModeCount(DEVICE_IDLE_MODE_LIGHT, which), deviceLightIdlingTime / 1000, |
| 3078 | getDeviceIdlingCount(DEVICE_IDLE_MODE_LIGHT, which), |
| 3079 | getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT), |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 3080 | getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP)); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3081 | |
| 3082 | // Dump screen brightness stats |
| 3083 | Object[] args = new Object[NUM_SCREEN_BRIGHTNESS_BINS]; |
| 3084 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3085 | args[i] = getScreenBrightnessTime(i, rawRealtime, which) / 1000; |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3086 | } |
| 3087 | dumpLine(pw, 0 /* uid */, category, SCREEN_BRIGHTNESS_DATA, args); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3088 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3089 | // Dump signal strength stats |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 3090 | args = new Object[SignalStrength.NUM_SIGNAL_STRENGTH_BINS]; |
| 3091 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3092 | args[i] = getPhoneSignalStrengthTime(i, rawRealtime, which) / 1000; |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3093 | } |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3094 | dumpLine(pw, 0 /* uid */, category, SIGNAL_STRENGTH_TIME_DATA, args); |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 3095 | dumpLine(pw, 0 /* uid */, category, SIGNAL_SCANNING_TIME_DATA, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3096 | getPhoneSignalScanningTime(rawRealtime, which) / 1000); |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 3097 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3098 | args[i] = getPhoneSignalStrengthCount(i, which); |
| 3099 | } |
| 3100 | dumpLine(pw, 0 /* uid */, category, SIGNAL_STRENGTH_COUNT_DATA, args); |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 3101 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3102 | // Dump network type stats |
| 3103 | args = new Object[NUM_DATA_CONNECTION_TYPES]; |
| 3104 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3105 | args[i] = getPhoneDataConnectionTime(i, rawRealtime, which) / 1000; |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3106 | } |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3107 | dumpLine(pw, 0 /* uid */, category, DATA_CONNECTION_TIME_DATA, args); |
| 3108 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
| 3109 | args[i] = getPhoneDataConnectionCount(i, which); |
| 3110 | } |
| 3111 | dumpLine(pw, 0 /* uid */, category, DATA_CONNECTION_COUNT_DATA, args); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3112 | |
| 3113 | // Dump wifi state stats |
| 3114 | args = new Object[NUM_WIFI_STATES]; |
| 3115 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3116 | args[i] = getWifiStateTime(i, rawRealtime, which) / 1000; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3117 | } |
| 3118 | dumpLine(pw, 0 /* uid */, category, WIFI_STATE_TIME_DATA, args); |
| 3119 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
| 3120 | args[i] = getWifiStateCount(i, which); |
| 3121 | } |
| 3122 | dumpLine(pw, 0 /* uid */, category, WIFI_STATE_COUNT_DATA, args); |
| 3123 | |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 3124 | // Dump wifi suppl state stats |
| 3125 | args = new Object[NUM_WIFI_SUPPL_STATES]; |
| 3126 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
| 3127 | args[i] = getWifiSupplStateTime(i, rawRealtime, which) / 1000; |
| 3128 | } |
| 3129 | dumpLine(pw, 0 /* uid */, category, WIFI_SUPPL_STATE_TIME_DATA, args); |
| 3130 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
| 3131 | args[i] = getWifiSupplStateCount(i, which); |
| 3132 | } |
| 3133 | dumpLine(pw, 0 /* uid */, category, WIFI_SUPPL_STATE_COUNT_DATA, args); |
| 3134 | |
| 3135 | // Dump wifi signal strength stats |
| 3136 | args = new Object[NUM_WIFI_SIGNAL_STRENGTH_BINS]; |
| 3137 | for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 3138 | args[i] = getWifiSignalStrengthTime(i, rawRealtime, which) / 1000; |
| 3139 | } |
| 3140 | dumpLine(pw, 0 /* uid */, category, WIFI_SIGNAL_STRENGTH_TIME_DATA, args); |
| 3141 | for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 3142 | args[i] = getWifiSignalStrengthCount(i, which); |
| 3143 | } |
| 3144 | dumpLine(pw, 0 /* uid */, category, WIFI_SIGNAL_STRENGTH_COUNT_DATA, args); |
| 3145 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3146 | if (which == STATS_SINCE_UNPLUGGED) { |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 3147 | dumpLine(pw, 0 /* uid */, category, BATTERY_LEVEL_DATA, getDischargeStartLevel(), |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 3148 | getDischargeCurrentLevel()); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3149 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3150 | |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 3151 | if (which == STATS_SINCE_UNPLUGGED) { |
| 3152 | dumpLine(pw, 0 /* uid */, category, BATTERY_DISCHARGE_DATA, |
| 3153 | getDischargeStartLevel()-getDischargeCurrentLevel(), |
| 3154 | getDischargeStartLevel()-getDischargeCurrentLevel(), |
Adam Lesinski | 67c134f | 2016-06-10 15:15:08 -0700 | [diff] [blame] | 3155 | getDischargeAmountScreenOn(), getDischargeAmountScreenOff(), |
| 3156 | dischargeCount / 1000, dischargeScreenOffCount / 1000); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 3157 | } else { |
| 3158 | dumpLine(pw, 0 /* uid */, category, BATTERY_DISCHARGE_DATA, |
| 3159 | getLowDischargeAmountSinceCharge(), getHighDischargeAmountSinceCharge(), |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 3160 | getDischargeAmountScreenOnSinceCharge(), |
Adam Lesinski | 67c134f | 2016-06-10 15:15:08 -0700 | [diff] [blame] | 3161 | getDischargeAmountScreenOffSinceCharge(), |
| 3162 | dischargeCount / 1000, dischargeScreenOffCount / 1000); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 3163 | } |
| 3164 | |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 3165 | if (reqUid < 0) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3166 | final Map<String, ? extends Timer> kernelWakelocks = getKernelWakelockStats(); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 3167 | if (kernelWakelocks.size() > 0) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3168 | for (Map.Entry<String, ? extends Timer> ent : kernelWakelocks.entrySet()) { |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 3169 | sb.setLength(0); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3170 | printWakeLockCheckin(sb, ent.getValue(), rawRealtime, null, which, ""); |
Kweku Adams | e0dd9c1 | 2017-03-08 08:12:15 -0800 | [diff] [blame] | 3171 | dumpLine(pw, 0 /* uid */, category, KERNEL_WAKELOCK_DATA, |
| 3172 | "\"" + ent.getKey() + "\"", sb.toString()); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 3173 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 3174 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3175 | final Map<String, ? extends Timer> wakeupReasons = getWakeupReasonStats(); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3176 | if (wakeupReasons.size() > 0) { |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 3177 | for (Map.Entry<String, ? extends Timer> ent : wakeupReasons.entrySet()) { |
| 3178 | // Not doing the regular wake lock formatting to remain compatible |
| 3179 | // with the old checkin format. |
| 3180 | long totalTimeMicros = ent.getValue().getTotalTimeLocked(rawRealtime, which); |
| 3181 | int count = ent.getValue().getCountLocked(which); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3182 | dumpLine(pw, 0 /* uid */, category, WAKEUP_REASON_DATA, |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 3183 | "\"" + ent.getKey() + "\"", (totalTimeMicros + 500) / 1000, count); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3184 | } |
| 3185 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 3186 | } |
| 3187 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3188 | final BatteryStatsHelper helper = new BatteryStatsHelper(context, false, wifiOnly); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3189 | helper.create(this); |
| 3190 | helper.refreshStats(which, UserHandle.USER_ALL); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3191 | final List<BatterySipper> sippers = helper.getUsageList(); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3192 | if (sippers != null && sippers.size() > 0) { |
| 3193 | dumpLine(pw, 0 /* uid */, category, POWER_USE_SUMMARY_DATA, |
| 3194 | BatteryStatsHelper.makemAh(helper.getPowerProfile().getBatteryCapacity()), |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3195 | BatteryStatsHelper.makemAh(helper.getComputedPower()), |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3196 | BatteryStatsHelper.makemAh(helper.getMinDrainedPower()), |
| 3197 | BatteryStatsHelper.makemAh(helper.getMaxDrainedPower())); |
| 3198 | for (int i=0; i<sippers.size(); i++) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3199 | final BatterySipper bs = sippers.get(i); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3200 | int uid = 0; |
| 3201 | String label; |
| 3202 | switch (bs.drainType) { |
| 3203 | case IDLE: |
| 3204 | label="idle"; |
| 3205 | break; |
| 3206 | case CELL: |
| 3207 | label="cell"; |
| 3208 | break; |
| 3209 | case PHONE: |
| 3210 | label="phone"; |
| 3211 | break; |
| 3212 | case WIFI: |
| 3213 | label="wifi"; |
| 3214 | break; |
| 3215 | case BLUETOOTH: |
| 3216 | label="blue"; |
| 3217 | break; |
| 3218 | case SCREEN: |
| 3219 | label="scrn"; |
| 3220 | break; |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 3221 | case FLASHLIGHT: |
| 3222 | label="flashlight"; |
| 3223 | break; |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3224 | case APP: |
| 3225 | uid = bs.uidObj.getUid(); |
| 3226 | label = "uid"; |
| 3227 | break; |
| 3228 | case USER: |
| 3229 | uid = UserHandle.getUid(bs.userId, 0); |
| 3230 | label = "user"; |
| 3231 | break; |
| 3232 | case UNACCOUNTED: |
| 3233 | label = "unacc"; |
| 3234 | break; |
| 3235 | case OVERCOUNTED: |
| 3236 | label = "over"; |
| 3237 | break; |
Ruben Brunk | 5b1308f | 2015-06-03 18:49:27 -0700 | [diff] [blame] | 3238 | case CAMERA: |
| 3239 | label = "camera"; |
| 3240 | break; |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3241 | default: |
| 3242 | label = "???"; |
| 3243 | } |
| 3244 | dumpLine(pw, uid, category, POWER_USE_ITEM_DATA, label, |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 3245 | BatteryStatsHelper.makemAh(bs.totalPowerMah)); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3246 | } |
| 3247 | } |
| 3248 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3249 | for (int iu = 0; iu < NU; iu++) { |
| 3250 | final int uid = uidStats.keyAt(iu); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 3251 | if (reqUid >= 0 && uid != reqUid) { |
| 3252 | continue; |
| 3253 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3254 | final Uid u = uidStats.valueAt(iu); |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 3255 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3256 | // Dump Network stats per uid, if any |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3257 | final long mobileBytesRx = u.getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which); |
| 3258 | final long mobileBytesTx = u.getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which); |
| 3259 | final long wifiBytesRx = u.getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which); |
| 3260 | final long wifiBytesTx = u.getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which); |
| 3261 | final long mobilePacketsRx = u.getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which); |
| 3262 | final long mobilePacketsTx = u.getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which); |
| 3263 | final long mobileActiveTime = u.getMobileRadioActiveTime(which); |
| 3264 | final int mobileActiveCount = u.getMobileRadioActiveCount(which); |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 3265 | final long mobileWakeup = u.getMobileRadioApWakeupCount(which); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3266 | final long wifiPacketsRx = u.getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which); |
| 3267 | final long wifiPacketsTx = u.getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which); |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 3268 | final long wifiWakeup = u.getWifiRadioApWakeupCount(which); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 3269 | final long btBytesRx = u.getNetworkActivityBytes(NETWORK_BT_RX_DATA, which); |
| 3270 | final long btBytesTx = u.getNetworkActivityBytes(NETWORK_BT_TX_DATA, which); |
Amith Yamasani | 59fe841 | 2017-03-03 16:28:52 -0800 | [diff] [blame] | 3271 | // Background data transfers |
| 3272 | final long mobileBytesBgRx = u.getNetworkActivityBytes(NETWORK_MOBILE_BG_RX_DATA, |
| 3273 | which); |
| 3274 | final long mobileBytesBgTx = u.getNetworkActivityBytes(NETWORK_MOBILE_BG_TX_DATA, |
| 3275 | which); |
| 3276 | final long wifiBytesBgRx = u.getNetworkActivityBytes(NETWORK_WIFI_BG_RX_DATA, which); |
| 3277 | final long wifiBytesBgTx = u.getNetworkActivityBytes(NETWORK_WIFI_BG_TX_DATA, which); |
| 3278 | final long mobilePacketsBgRx = u.getNetworkActivityPackets(NETWORK_MOBILE_BG_RX_DATA, |
| 3279 | which); |
| 3280 | final long mobilePacketsBgTx = u.getNetworkActivityPackets(NETWORK_MOBILE_BG_TX_DATA, |
| 3281 | which); |
| 3282 | final long wifiPacketsBgRx = u.getNetworkActivityPackets(NETWORK_WIFI_BG_RX_DATA, |
| 3283 | which); |
| 3284 | final long wifiPacketsBgTx = u.getNetworkActivityPackets(NETWORK_WIFI_BG_TX_DATA, |
| 3285 | which); |
| 3286 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3287 | if (mobileBytesRx > 0 || mobileBytesTx > 0 || wifiBytesRx > 0 || wifiBytesTx > 0 |
| 3288 | || mobilePacketsRx > 0 || mobilePacketsTx > 0 || wifiPacketsRx > 0 |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 3289 | || wifiPacketsTx > 0 || mobileActiveTime > 0 || mobileActiveCount > 0 |
Amith Yamasani | 59fe841 | 2017-03-03 16:28:52 -0800 | [diff] [blame] | 3290 | || btBytesRx > 0 || btBytesTx > 0 || mobileWakeup > 0 || wifiWakeup > 0 |
| 3291 | || mobileBytesBgRx > 0 || mobileBytesBgTx > 0 || wifiBytesBgRx > 0 |
| 3292 | || wifiBytesBgTx > 0 |
| 3293 | || mobilePacketsBgRx > 0 || mobilePacketsBgTx > 0 || wifiPacketsBgRx > 0 |
| 3294 | || wifiPacketsBgTx > 0) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3295 | dumpLine(pw, uid, category, NETWORK_DATA, mobileBytesRx, mobileBytesTx, |
| 3296 | wifiBytesRx, wifiBytesTx, |
| 3297 | mobilePacketsRx, mobilePacketsTx, |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 3298 | wifiPacketsRx, wifiPacketsTx, |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 3299 | mobileActiveTime, mobileActiveCount, |
Amith Yamasani | 59fe841 | 2017-03-03 16:28:52 -0800 | [diff] [blame] | 3300 | btBytesRx, btBytesTx, mobileWakeup, wifiWakeup, |
| 3301 | mobileBytesBgRx, mobileBytesBgTx, wifiBytesBgRx, wifiBytesBgTx, |
| 3302 | mobilePacketsBgRx, mobilePacketsBgTx, wifiPacketsBgRx, wifiPacketsBgTx |
| 3303 | ); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 3304 | } |
| 3305 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3306 | // Dump modem controller data, per UID. |
| 3307 | dumpControllerActivityLine(pw, uid, category, MODEM_CONTROLLER_DATA, |
| 3308 | u.getModemControllerActivity(), which); |
| 3309 | |
| 3310 | // Dump Wifi controller data, per UID. |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 3311 | final long fullWifiLockOnTime = u.getFullWifiLockTime(rawRealtime, which); |
| 3312 | final long wifiScanTime = u.getWifiScanTime(rawRealtime, which); |
| 3313 | final int wifiScanCount = u.getWifiScanCount(which); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 3314 | final int wifiScanCountBg = u.getWifiScanBackgroundCount(which); |
| 3315 | // Note that 'ActualTime' are unpooled and always since reset (regardless of 'which') |
| 3316 | final long wifiScanActualTime = u.getWifiScanActualTime(rawRealtime); |
| 3317 | final long wifiScanActualTimeBg = u.getWifiScanBackgroundTime(rawRealtime); |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 3318 | final long uidWifiRunningTime = u.getWifiRunningTime(rawRealtime, which); |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 3319 | if (fullWifiLockOnTime != 0 || wifiScanTime != 0 || wifiScanCount != 0 |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 3320 | || wifiScanCountBg != 0 || wifiScanActualTime != 0 || wifiScanActualTimeBg != 0 |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3321 | || uidWifiRunningTime != 0) { |
| 3322 | dumpLine(pw, uid, category, WIFI_DATA, fullWifiLockOnTime, wifiScanTime, |
| 3323 | uidWifiRunningTime, wifiScanCount, |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 3324 | /* legacy fields follow, keep at 0 */ 0, 0, 0, |
| 3325 | wifiScanCountBg, wifiScanActualTime, wifiScanActualTimeBg); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3326 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3327 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3328 | dumpControllerActivityLine(pw, uid, category, WIFI_CONTROLLER_DATA, |
| 3329 | u.getWifiControllerActivity(), which); |
| 3330 | |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 3331 | final Timer bleTimer = u.getBluetoothScanTimer(); |
| 3332 | if (bleTimer != null) { |
| 3333 | // Convert from microseconds to milliseconds with rounding |
| 3334 | final long totalTime = (bleTimer.getTotalTimeLocked(rawRealtime, which) + 500) |
| 3335 | / 1000; |
| 3336 | if (totalTime != 0) { |
| 3337 | final int count = bleTimer.getCountLocked(which); |
| 3338 | final Timer bleTimerBg = u.getBluetoothScanBackgroundTimer(); |
| 3339 | final int countBg = bleTimerBg != null ? bleTimerBg.getCountLocked(which) : 0; |
| 3340 | final long rawRealtimeMs = (rawRealtime + 500) / 1000; |
| 3341 | // 'actualTime' are unpooled and always since reset (regardless of 'which') |
| 3342 | final long actualTime = bleTimer.getTotalDurationMsLocked(rawRealtimeMs); |
| 3343 | final long actualTimeBg = bleTimerBg != null ? |
| 3344 | bleTimerBg.getTotalDurationMsLocked(rawRealtimeMs) : 0; |
| 3345 | dumpLine(pw, uid, category, BLUETOOTH_MISC_DATA, totalTime, count, |
| 3346 | countBg, actualTime, actualTimeBg); |
| 3347 | } |
| 3348 | } |
Adam Lesinski | d9b99be | 2016-03-30 16:58:51 -0700 | [diff] [blame] | 3349 | |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 3350 | dumpControllerActivityLine(pw, uid, category, BLUETOOTH_CONTROLLER_DATA, |
| 3351 | u.getBluetoothControllerActivity(), which); |
| 3352 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3353 | if (u.hasUserActivity()) { |
| 3354 | args = new Object[Uid.NUM_USER_ACTIVITY_TYPES]; |
| 3355 | boolean hasData = false; |
| 3356 | for (int i=0; i<Uid.NUM_USER_ACTIVITY_TYPES; i++) { |
| 3357 | int val = u.getUserActivityCount(i, which); |
| 3358 | args[i] = val; |
| 3359 | if (val != 0) hasData = true; |
| 3360 | } |
| 3361 | if (hasData) { |
Ashish Sharma | cba1215 | 2014-07-07 17:14:52 -0700 | [diff] [blame] | 3362 | dumpLine(pw, uid /* uid */, category, USER_ACTIVITY_DATA, args); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3363 | } |
| 3364 | } |
| 3365 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3366 | final ArrayMap<String, ? extends Uid.Wakelock> wakelocks = u.getWakelockStats(); |
| 3367 | for (int iw=wakelocks.size()-1; iw>=0; iw--) { |
| 3368 | final Uid.Wakelock wl = wakelocks.valueAt(iw); |
| 3369 | String linePrefix = ""; |
| 3370 | sb.setLength(0); |
| 3371 | linePrefix = printWakeLockCheckin(sb, wl.getWakeTime(WAKE_TYPE_FULL), |
| 3372 | rawRealtime, "f", which, linePrefix); |
| 3373 | linePrefix = printWakeLockCheckin(sb, wl.getWakeTime(WAKE_TYPE_PARTIAL), |
| 3374 | rawRealtime, "p", which, linePrefix); |
| 3375 | linePrefix = printWakeLockCheckin(sb, wl.getWakeTime(WAKE_TYPE_WINDOW), |
| 3376 | rawRealtime, "w", which, linePrefix); |
| 3377 | |
| 3378 | // Only log if we had at lease one wakelock... |
| 3379 | if (sb.length() > 0) { |
| 3380 | String name = wakelocks.keyAt(iw); |
| 3381 | if (name.indexOf(',') >= 0) { |
| 3382 | name = name.replace(',', '_'); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3383 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3384 | dumpLine(pw, uid, category, WAKELOCK_DATA, name, sb.toString()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3385 | } |
| 3386 | } |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 3387 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3388 | final ArrayMap<String, ? extends Timer> syncs = u.getSyncStats(); |
| 3389 | for (int isy=syncs.size()-1; isy>=0; isy--) { |
| 3390 | final Timer timer = syncs.valueAt(isy); |
| 3391 | // Convert from microseconds to milliseconds with rounding |
| 3392 | final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000; |
| 3393 | final int count = timer.getCountLocked(which); |
| 3394 | if (totalTime != 0) { |
Kweku Adams | e0dd9c1 | 2017-03-08 08:12:15 -0800 | [diff] [blame] | 3395 | dumpLine(pw, uid, category, SYNC_DATA, "\"" + syncs.keyAt(isy) + "\"", |
| 3396 | totalTime, count); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 3397 | } |
| 3398 | } |
| 3399 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3400 | final ArrayMap<String, ? extends Timer> jobs = u.getJobStats(); |
| 3401 | for (int ij=jobs.size()-1; ij>=0; ij--) { |
| 3402 | final Timer timer = jobs.valueAt(ij); |
| 3403 | // Convert from microseconds to milliseconds with rounding |
| 3404 | final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000; |
| 3405 | final int count = timer.getCountLocked(which); |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame^] | 3406 | final Timer bgTimer = timer.getSubTimer(); |
| 3407 | final long bgTime = bgTimer != null ? |
| 3408 | (bgTimer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000 : -1; |
| 3409 | final int bgCount = bgTimer != null ? bgTimer.getCountLocked(which) : -1; |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3410 | if (totalTime != 0) { |
Kweku Adams | e0dd9c1 | 2017-03-08 08:12:15 -0800 | [diff] [blame] | 3411 | dumpLine(pw, uid, category, JOB_DATA, "\"" + jobs.keyAt(ij) + "\"", |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame^] | 3412 | totalTime, count, bgTime, bgCount); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 3413 | } |
| 3414 | } |
| 3415 | |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 3416 | dumpTimer(pw, uid, category, FLASHLIGHT_DATA, u.getFlashlightTurnedOnTimer(), |
| 3417 | rawRealtime, which); |
| 3418 | dumpTimer(pw, uid, category, CAMERA_DATA, u.getCameraTurnedOnTimer(), |
| 3419 | rawRealtime, which); |
| 3420 | dumpTimer(pw, uid, category, VIDEO_DATA, u.getVideoTurnedOnTimer(), |
| 3421 | rawRealtime, which); |
| 3422 | dumpTimer(pw, uid, category, AUDIO_DATA, u.getAudioTurnedOnTimer(), |
| 3423 | rawRealtime, which); |
| 3424 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3425 | final SparseArray<? extends BatteryStats.Uid.Sensor> sensors = u.getSensorStats(); |
| 3426 | final int NSE = sensors.size(); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 3427 | for (int ise=0; ise<NSE; ise++) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3428 | final Uid.Sensor se = sensors.valueAt(ise); |
| 3429 | final int sensorNumber = sensors.keyAt(ise); |
| 3430 | final Timer timer = se.getSensorTime(); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 3431 | if (timer != null) { |
| 3432 | // Convert from microseconds to milliseconds with rounding |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3433 | final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) |
| 3434 | / 1000; |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 3435 | if (totalTime != 0) { |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 3436 | final int count = timer.getCountLocked(which); |
| 3437 | final Timer bgTimer = se.getSensorBackgroundTime(); |
| 3438 | final int bgCount = bgTimer != null ? bgTimer.getCountLocked(which) : 0; |
| 3439 | final long rawRealtimeMs = (rawRealtime + 500) / 1000; |
| 3440 | // 'actualTime' are unpooled and always since reset (regardless of 'which') |
| 3441 | final long actualTime = timer.getTotalDurationMsLocked(rawRealtimeMs); |
| 3442 | final long bgActualTime = bgTimer != null ? |
| 3443 | bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : 0; |
| 3444 | dumpLine(pw, uid, category, SENSOR_DATA, sensorNumber, totalTime, |
| 3445 | count, bgCount, actualTime, bgActualTime); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 3446 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3447 | } |
| 3448 | } |
| 3449 | |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 3450 | dumpTimer(pw, uid, category, VIBRATOR_DATA, u.getVibratorOnTimer(), |
| 3451 | rawRealtime, which); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 3452 | |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 3453 | dumpTimer(pw, uid, category, FOREGROUND_DATA, u.getForegroundActivityTimer(), |
| 3454 | rawRealtime, which); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 3455 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3456 | final Object[] stateTimes = new Object[Uid.NUM_PROCESS_STATE]; |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 3457 | long totalStateTime = 0; |
| 3458 | for (int ips=0; ips<Uid.NUM_PROCESS_STATE; ips++) { |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 3459 | final long time = u.getProcessStateTime(ips, rawRealtime, which); |
| 3460 | totalStateTime += time; |
| 3461 | stateTimes[ips] = (time + 500) / 1000; |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 3462 | } |
| 3463 | if (totalStateTime > 0) { |
| 3464 | dumpLine(pw, uid, category, STATE_TIME_DATA, stateTimes); |
| 3465 | } |
| 3466 | |
Adam Lesinski | a7a4ccc | 2015-06-26 17:43:04 -0700 | [diff] [blame] | 3467 | final long userCpuTimeUs = u.getUserCpuTimeUs(which); |
| 3468 | final long systemCpuTimeUs = u.getSystemCpuTimeUs(which); |
| 3469 | final long powerCpuMaUs = u.getCpuPowerMaUs(which); |
| 3470 | if (userCpuTimeUs > 0 || systemCpuTimeUs > 0 || powerCpuMaUs > 0) { |
| 3471 | dumpLine(pw, uid, category, CPU_DATA, userCpuTimeUs / 1000, systemCpuTimeUs / 1000, |
| 3472 | powerCpuMaUs / 1000); |
| 3473 | } |
| 3474 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3475 | final ArrayMap<String, ? extends BatteryStats.Uid.Proc> processStats |
| 3476 | = u.getProcessStats(); |
| 3477 | for (int ipr=processStats.size()-1; ipr>=0; ipr--) { |
| 3478 | final Uid.Proc ps = processStats.valueAt(ipr); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 3479 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3480 | final long userMillis = ps.getUserTime(which); |
| 3481 | final long systemMillis = ps.getSystemTime(which); |
| 3482 | final long foregroundMillis = ps.getForegroundTime(which); |
| 3483 | final int starts = ps.getStarts(which); |
| 3484 | final int numCrashes = ps.getNumCrashes(which); |
| 3485 | final int numAnrs = ps.getNumAnrs(which); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 3486 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3487 | if (userMillis != 0 || systemMillis != 0 || foregroundMillis != 0 |
| 3488 | || starts != 0 || numAnrs != 0 || numCrashes != 0) { |
Kweku Adams | e0dd9c1 | 2017-03-08 08:12:15 -0800 | [diff] [blame] | 3489 | dumpLine(pw, uid, category, PROCESS_DATA, "\"" + processStats.keyAt(ipr) + "\"", |
| 3490 | userMillis, systemMillis, foregroundMillis, starts, numAnrs, numCrashes); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3491 | } |
| 3492 | } |
| 3493 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3494 | final ArrayMap<String, ? extends BatteryStats.Uid.Pkg> packageStats |
| 3495 | = u.getPackageStats(); |
| 3496 | for (int ipkg=packageStats.size()-1; ipkg>=0; ipkg--) { |
| 3497 | final Uid.Pkg ps = packageStats.valueAt(ipkg); |
| 3498 | int wakeups = 0; |
| 3499 | final ArrayMap<String, ? extends Counter> alarms = ps.getWakeupAlarmStats(); |
| 3500 | for (int iwa=alarms.size()-1; iwa>=0; iwa--) { |
Joe Onorato | 1476d32 | 2016-05-05 14:46:15 -0700 | [diff] [blame] | 3501 | int count = alarms.valueAt(iwa).getCountLocked(which); |
| 3502 | wakeups += count; |
| 3503 | String name = alarms.keyAt(iwa).replace(',', '_'); |
| 3504 | dumpLine(pw, uid, category, WAKEUP_ALARM_DATA, name, count); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3505 | } |
| 3506 | final ArrayMap<String, ? extends Uid.Pkg.Serv> serviceStats = ps.getServiceStats(); |
| 3507 | for (int isvc=serviceStats.size()-1; isvc>=0; isvc--) { |
| 3508 | final BatteryStats.Uid.Pkg.Serv ss = serviceStats.valueAt(isvc); |
| 3509 | final long startTime = ss.getStartTime(batteryUptime, which); |
| 3510 | final int starts = ss.getStarts(which); |
| 3511 | final int launches = ss.getLaunches(which); |
| 3512 | if (startTime != 0 || starts != 0 || launches != 0) { |
| 3513 | dumpLine(pw, uid, category, APK_DATA, |
| 3514 | wakeups, // wakeup alarms |
| 3515 | packageStats.keyAt(ipkg), // Apk |
| 3516 | serviceStats.keyAt(isvc), // service |
| 3517 | startTime / 1000, // time spent started, in ms |
| 3518 | starts, |
| 3519 | launches); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3520 | } |
| 3521 | } |
| 3522 | } |
| 3523 | } |
| 3524 | } |
| 3525 | |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 3526 | static final class TimerEntry { |
| 3527 | final String mName; |
| 3528 | final int mId; |
| 3529 | final BatteryStats.Timer mTimer; |
| 3530 | final long mTime; |
| 3531 | TimerEntry(String name, int id, BatteryStats.Timer timer, long time) { |
| 3532 | mName = name; |
| 3533 | mId = id; |
| 3534 | mTimer = timer; |
| 3535 | mTime = time; |
| 3536 | } |
| 3537 | } |
| 3538 | |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3539 | private void printmAh(PrintWriter printer, double power) { |
| 3540 | printer.print(BatteryStatsHelper.makemAh(power)); |
| 3541 | } |
| 3542 | |
Adam Lesinski | a7a4ccc | 2015-06-26 17:43:04 -0700 | [diff] [blame] | 3543 | private void printmAh(StringBuilder sb, double power) { |
| 3544 | sb.append(BatteryStatsHelper.makemAh(power)); |
| 3545 | } |
| 3546 | |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 3547 | /** |
| 3548 | * Temporary for settings. |
| 3549 | */ |
| 3550 | public final void dumpLocked(Context context, PrintWriter pw, String prefix, int which, |
| 3551 | int reqUid) { |
| 3552 | dumpLocked(context, pw, prefix, which, reqUid, BatteryStatsHelper.checkWifiOnly(context)); |
| 3553 | } |
| 3554 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3555 | @SuppressWarnings("unused") |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3556 | 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] | 3557 | int reqUid, boolean wifiOnly) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3558 | final long rawUptime = SystemClock.uptimeMillis() * 1000; |
| 3559 | final long rawRealtime = SystemClock.elapsedRealtime() * 1000; |
| 3560 | final long batteryUptime = getBatteryUptime(rawUptime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3561 | |
| 3562 | final long whichBatteryUptime = computeBatteryUptime(rawUptime, which); |
| 3563 | final long whichBatteryRealtime = computeBatteryRealtime(rawRealtime, which); |
| 3564 | final long totalRealtime = computeRealtime(rawRealtime, which); |
| 3565 | final long totalUptime = computeUptime(rawUptime, which); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3566 | final long whichBatteryScreenOffUptime = computeBatteryScreenOffUptime(rawUptime, which); |
| 3567 | final long whichBatteryScreenOffRealtime = computeBatteryScreenOffRealtime(rawRealtime, |
| 3568 | which); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 3569 | final long batteryTimeRemaining = computeBatteryTimeRemaining(rawRealtime); |
| 3570 | final long chargeTimeRemaining = computeChargeTimeRemaining(rawRealtime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3571 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3572 | final StringBuilder sb = new StringBuilder(128); |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 3573 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3574 | final SparseArray<? extends Uid> uidStats = getUidStats(); |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 3575 | final int NU = uidStats.size(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3576 | |
Adam Lesinski | f9b20a9 | 2016-06-17 17:30:01 -0700 | [diff] [blame] | 3577 | final int estimatedBatteryCapacity = getEstimatedBatteryCapacity(); |
| 3578 | if (estimatedBatteryCapacity > 0) { |
| 3579 | sb.setLength(0); |
| 3580 | sb.append(prefix); |
| 3581 | sb.append(" Estimated battery capacity: "); |
| 3582 | sb.append(BatteryStatsHelper.makemAh(estimatedBatteryCapacity)); |
| 3583 | sb.append(" mAh"); |
| 3584 | pw.println(sb.toString()); |
| 3585 | } |
| 3586 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3587 | sb.setLength(0); |
| 3588 | sb.append(prefix); |
| 3589 | sb.append(" Time on battery: "); |
| 3590 | formatTimeMs(sb, whichBatteryRealtime / 1000); sb.append("("); |
| 3591 | sb.append(formatRatioLocked(whichBatteryRealtime, totalRealtime)); |
| 3592 | sb.append(") realtime, "); |
| 3593 | formatTimeMs(sb, whichBatteryUptime / 1000); |
| 3594 | sb.append("("); sb.append(formatRatioLocked(whichBatteryUptime, totalRealtime)); |
| 3595 | sb.append(") uptime"); |
| 3596 | pw.println(sb.toString()); |
| 3597 | sb.setLength(0); |
| 3598 | sb.append(prefix); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3599 | sb.append(" Time on battery screen off: "); |
| 3600 | formatTimeMs(sb, whichBatteryScreenOffRealtime / 1000); sb.append("("); |
| 3601 | sb.append(formatRatioLocked(whichBatteryScreenOffRealtime, totalRealtime)); |
| 3602 | sb.append(") realtime, "); |
| 3603 | formatTimeMs(sb, whichBatteryScreenOffUptime / 1000); |
| 3604 | sb.append("("); |
| 3605 | sb.append(formatRatioLocked(whichBatteryScreenOffUptime, totalRealtime)); |
| 3606 | sb.append(") uptime"); |
| 3607 | pw.println(sb.toString()); |
| 3608 | sb.setLength(0); |
| 3609 | sb.append(prefix); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3610 | sb.append(" Total run time: "); |
| 3611 | formatTimeMs(sb, totalRealtime / 1000); |
| 3612 | sb.append("realtime, "); |
| 3613 | formatTimeMs(sb, totalUptime / 1000); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 3614 | sb.append("uptime"); |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 3615 | pw.println(sb.toString()); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 3616 | if (batteryTimeRemaining >= 0) { |
| 3617 | sb.setLength(0); |
| 3618 | sb.append(prefix); |
| 3619 | sb.append(" Battery time remaining: "); |
| 3620 | formatTimeMs(sb, batteryTimeRemaining / 1000); |
| 3621 | pw.println(sb.toString()); |
| 3622 | } |
| 3623 | if (chargeTimeRemaining >= 0) { |
| 3624 | sb.setLength(0); |
| 3625 | sb.append(prefix); |
| 3626 | sb.append(" Charge time remaining: "); |
| 3627 | formatTimeMs(sb, chargeTimeRemaining / 1000); |
| 3628 | pw.println(sb.toString()); |
| 3629 | } |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 3630 | |
| 3631 | final LongCounter dischargeCounter = getDischargeCoulombCounter(); |
| 3632 | final long dischargeCount = dischargeCounter.getCountLocked(which); |
| 3633 | if (dischargeCount >= 0) { |
| 3634 | sb.setLength(0); |
| 3635 | sb.append(prefix); |
| 3636 | sb.append(" Discharge: "); |
| 3637 | sb.append(BatteryStatsHelper.makemAh(dischargeCount / 1000.0)); |
| 3638 | sb.append(" mAh"); |
| 3639 | pw.println(sb.toString()); |
| 3640 | } |
| 3641 | |
| 3642 | final LongCounter dischargeScreenOffCounter = getDischargeScreenOffCoulombCounter(); |
| 3643 | final long dischargeScreenOffCount = dischargeScreenOffCounter.getCountLocked(which); |
| 3644 | if (dischargeScreenOffCount >= 0) { |
| 3645 | sb.setLength(0); |
| 3646 | sb.append(prefix); |
| 3647 | sb.append(" Screen off discharge: "); |
| 3648 | sb.append(BatteryStatsHelper.makemAh(dischargeScreenOffCount / 1000.0)); |
| 3649 | sb.append(" mAh"); |
| 3650 | pw.println(sb.toString()); |
| 3651 | } |
| 3652 | |
| 3653 | final long dischargeScreenOnCount = dischargeCount - dischargeScreenOffCount; |
| 3654 | if (dischargeScreenOnCount >= 0) { |
| 3655 | sb.setLength(0); |
| 3656 | sb.append(prefix); |
| 3657 | sb.append(" Screen on discharge: "); |
| 3658 | sb.append(BatteryStatsHelper.makemAh(dischargeScreenOnCount / 1000.0)); |
| 3659 | sb.append(" mAh"); |
| 3660 | pw.println(sb.toString()); |
| 3661 | } |
| 3662 | |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 3663 | pw.print(" Start clock time: "); |
| 3664 | pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss", getStartClockTime()).toString()); |
| 3665 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3666 | final long screenOnTime = getScreenOnTime(rawRealtime, which); |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 3667 | final long interactiveTime = getInteractiveTime(rawRealtime, which); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3668 | final long powerSaveModeEnabledTime = getPowerSaveModeEnabledTime(rawRealtime, which); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3669 | final long deviceIdleModeLightTime = getDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT, |
| 3670 | rawRealtime, which); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 3671 | final long deviceIdleModeFullTime = getDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP, |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3672 | rawRealtime, which); |
| 3673 | final long deviceLightIdlingTime = getDeviceIdlingTime(DEVICE_IDLE_MODE_LIGHT, |
| 3674 | rawRealtime, which); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 3675 | final long deviceIdlingTime = getDeviceIdlingTime(DEVICE_IDLE_MODE_DEEP, |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3676 | rawRealtime, which); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3677 | final long phoneOnTime = getPhoneOnTime(rawRealtime, which); |
| 3678 | final long wifiRunningTime = getGlobalWifiRunningTime(rawRealtime, which); |
| 3679 | final long wifiOnTime = getWifiOnTime(rawRealtime, which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3680 | sb.setLength(0); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3681 | sb.append(prefix); |
| 3682 | sb.append(" Screen on: "); formatTimeMs(sb, screenOnTime / 1000); |
| 3683 | sb.append("("); sb.append(formatRatioLocked(screenOnTime, whichBatteryRealtime)); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 3684 | sb.append(") "); sb.append(getScreenOnCount(which)); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3685 | sb.append("x, Interactive: "); formatTimeMs(sb, interactiveTime / 1000); |
| 3686 | sb.append("("); sb.append(formatRatioLocked(interactiveTime, whichBatteryRealtime)); |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 3687 | sb.append(")"); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3688 | pw.println(sb.toString()); |
| 3689 | sb.setLength(0); |
| 3690 | sb.append(prefix); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 3691 | sb.append(" Screen brightnesses:"); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3692 | boolean didOne = false; |
| 3693 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3694 | final long time = getScreenBrightnessTime(i, rawRealtime, which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3695 | if (time == 0) { |
| 3696 | continue; |
| 3697 | } |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 3698 | sb.append("\n "); |
| 3699 | sb.append(prefix); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3700 | didOne = true; |
| 3701 | sb.append(SCREEN_BRIGHTNESS_NAMES[i]); |
| 3702 | sb.append(" "); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3703 | formatTimeMs(sb, time/1000); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3704 | sb.append("("); |
| 3705 | sb.append(formatRatioLocked(time, screenOnTime)); |
| 3706 | sb.append(")"); |
| 3707 | } |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 3708 | if (!didOne) sb.append(" (no activity)"); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3709 | pw.println(sb.toString()); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3710 | if (powerSaveModeEnabledTime != 0) { |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3711 | sb.setLength(0); |
| 3712 | sb.append(prefix); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3713 | sb.append(" Power save mode enabled: "); |
| 3714 | formatTimeMs(sb, powerSaveModeEnabledTime / 1000); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3715 | sb.append("("); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3716 | sb.append(formatRatioLocked(powerSaveModeEnabledTime, whichBatteryRealtime)); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3717 | sb.append(")"); |
| 3718 | pw.println(sb.toString()); |
| 3719 | } |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3720 | if (deviceLightIdlingTime != 0) { |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3721 | sb.setLength(0); |
| 3722 | sb.append(prefix); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3723 | sb.append(" Device light idling: "); |
| 3724 | formatTimeMs(sb, deviceLightIdlingTime / 1000); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 3725 | sb.append("("); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3726 | sb.append(formatRatioLocked(deviceLightIdlingTime, whichBatteryRealtime)); |
| 3727 | sb.append(") "); sb.append(getDeviceIdlingCount(DEVICE_IDLE_MODE_LIGHT, which)); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 3728 | sb.append("x"); |
| 3729 | pw.println(sb.toString()); |
| 3730 | } |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3731 | if (deviceIdleModeLightTime != 0) { |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 3732 | sb.setLength(0); |
| 3733 | sb.append(prefix); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3734 | sb.append(" Idle mode light time: "); |
| 3735 | formatTimeMs(sb, deviceIdleModeLightTime / 1000); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3736 | sb.append("("); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3737 | sb.append(formatRatioLocked(deviceIdleModeLightTime, whichBatteryRealtime)); |
| 3738 | sb.append(") "); |
| 3739 | sb.append(getDeviceIdleModeCount(DEVICE_IDLE_MODE_LIGHT, which)); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3740 | sb.append("x"); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3741 | sb.append(" -- longest "); |
| 3742 | formatTimeMs(sb, getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT)); |
| 3743 | pw.println(sb.toString()); |
| 3744 | } |
| 3745 | if (deviceIdlingTime != 0) { |
| 3746 | sb.setLength(0); |
| 3747 | sb.append(prefix); |
| 3748 | sb.append(" Device full idling: "); |
| 3749 | formatTimeMs(sb, deviceIdlingTime / 1000); |
| 3750 | sb.append("("); |
| 3751 | sb.append(formatRatioLocked(deviceIdlingTime, whichBatteryRealtime)); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 3752 | sb.append(") "); sb.append(getDeviceIdlingCount(DEVICE_IDLE_MODE_DEEP, which)); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3753 | sb.append("x"); |
| 3754 | pw.println(sb.toString()); |
| 3755 | } |
| 3756 | if (deviceIdleModeFullTime != 0) { |
| 3757 | sb.setLength(0); |
| 3758 | sb.append(prefix); |
| 3759 | sb.append(" Idle mode full time: "); |
| 3760 | formatTimeMs(sb, deviceIdleModeFullTime / 1000); |
| 3761 | sb.append("("); |
| 3762 | sb.append(formatRatioLocked(deviceIdleModeFullTime, whichBatteryRealtime)); |
| 3763 | sb.append(") "); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 3764 | sb.append(getDeviceIdleModeCount(DEVICE_IDLE_MODE_DEEP, which)); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3765 | sb.append("x"); |
| 3766 | sb.append(" -- longest "); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 3767 | formatTimeMs(sb, getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP)); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3768 | pw.println(sb.toString()); |
| 3769 | } |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3770 | if (phoneOnTime != 0) { |
| 3771 | sb.setLength(0); |
| 3772 | sb.append(prefix); |
| 3773 | sb.append(" Active phone call: "); formatTimeMs(sb, phoneOnTime / 1000); |
| 3774 | sb.append("("); sb.append(formatRatioLocked(phoneOnTime, whichBatteryRealtime)); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3775 | sb.append(") "); sb.append(getPhoneOnCount(which)); sb.append("x"); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3776 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3777 | final int connChanges = getNumConnectivityChange(which); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 3778 | if (connChanges != 0) { |
| 3779 | pw.print(prefix); |
| 3780 | pw.print(" Connectivity changes: "); pw.println(connChanges); |
| 3781 | } |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3782 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3783 | // Calculate wakelock times across all uids. |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 3784 | long fullWakeLockTimeTotalMicros = 0; |
| 3785 | long partialWakeLockTimeTotalMicros = 0; |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 3786 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3787 | final ArrayList<TimerEntry> timers = new ArrayList<>(); |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 3788 | |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 3789 | for (int iu = 0; iu < NU; iu++) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3790 | final Uid u = uidStats.valueAt(iu); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 3791 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3792 | final ArrayMap<String, ? extends BatteryStats.Uid.Wakelock> wakelocks |
| 3793 | = u.getWakelockStats(); |
| 3794 | for (int iw=wakelocks.size()-1; iw>=0; iw--) { |
| 3795 | final Uid.Wakelock wl = wakelocks.valueAt(iw); |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 3796 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3797 | final Timer fullWakeTimer = wl.getWakeTime(WAKE_TYPE_FULL); |
| 3798 | if (fullWakeTimer != null) { |
| 3799 | fullWakeLockTimeTotalMicros += fullWakeTimer.getTotalTimeLocked( |
| 3800 | rawRealtime, which); |
| 3801 | } |
| 3802 | |
| 3803 | final Timer partialWakeTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL); |
| 3804 | if (partialWakeTimer != null) { |
| 3805 | final long totalTimeMicros = partialWakeTimer.getTotalTimeLocked( |
| 3806 | rawRealtime, which); |
| 3807 | if (totalTimeMicros > 0) { |
| 3808 | if (reqUid < 0) { |
| 3809 | // Only show the ordered list of all wake |
| 3810 | // locks if the caller is not asking for data |
| 3811 | // about a specific uid. |
| 3812 | timers.add(new TimerEntry(wakelocks.keyAt(iw), u.getUid(), |
| 3813 | partialWakeTimer, totalTimeMicros)); |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 3814 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3815 | partialWakeLockTimeTotalMicros += totalTimeMicros; |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 3816 | } |
| 3817 | } |
| 3818 | } |
| 3819 | } |
| 3820 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3821 | final long mobileRxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which); |
| 3822 | final long mobileTxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which); |
| 3823 | final long wifiRxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which); |
| 3824 | final long wifiTxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which); |
| 3825 | final long mobileRxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which); |
| 3826 | final long mobileTxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which); |
| 3827 | final long wifiRxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which); |
| 3828 | final long wifiTxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which); |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 3829 | final long btRxTotalBytes = getNetworkActivityBytes(NETWORK_BT_RX_DATA, which); |
| 3830 | final long btTxTotalBytes = getNetworkActivityBytes(NETWORK_BT_TX_DATA, which); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3831 | |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 3832 | if (fullWakeLockTimeTotalMicros != 0) { |
| 3833 | sb.setLength(0); |
| 3834 | sb.append(prefix); |
| 3835 | sb.append(" Total full wakelock time: "); formatTimeMsNoSpace(sb, |
| 3836 | (fullWakeLockTimeTotalMicros + 500) / 1000); |
| 3837 | pw.println(sb.toString()); |
| 3838 | } |
| 3839 | |
| 3840 | if (partialWakeLockTimeTotalMicros != 0) { |
| 3841 | sb.setLength(0); |
| 3842 | sb.append(prefix); |
| 3843 | sb.append(" Total partial wakelock time: "); formatTimeMsNoSpace(sb, |
| 3844 | (partialWakeLockTimeTotalMicros + 500) / 1000); |
| 3845 | pw.println(sb.toString()); |
| 3846 | } |
| 3847 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3848 | pw.print(prefix); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3849 | pw.print(" Mobile total received: "); pw.print(formatBytesLocked(mobileRxTotalBytes)); |
| 3850 | pw.print(", sent: "); pw.print(formatBytesLocked(mobileTxTotalBytes)); |
| 3851 | pw.print(" (packets received "); pw.print(mobileRxTotalPackets); |
| 3852 | pw.print(", sent "); pw.print(mobileTxTotalPackets); pw.println(")"); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3853 | sb.setLength(0); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3854 | sb.append(prefix); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 3855 | sb.append(" Phone signal levels:"); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3856 | didOne = false; |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 3857 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3858 | final long time = getPhoneSignalStrengthTime(i, rawRealtime, which); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3859 | if (time == 0) { |
| 3860 | continue; |
| 3861 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3862 | sb.append("\n "); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 3863 | sb.append(prefix); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3864 | didOne = true; |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 3865 | sb.append(SignalStrength.SIGNAL_STRENGTH_NAMES[i]); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3866 | sb.append(" "); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3867 | formatTimeMs(sb, time/1000); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3868 | sb.append("("); |
| 3869 | sb.append(formatRatioLocked(time, whichBatteryRealtime)); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3870 | sb.append(") "); |
| 3871 | sb.append(getPhoneSignalStrengthCount(i, which)); |
| 3872 | sb.append("x"); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3873 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3874 | if (!didOne) sb.append(" (no activity)"); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3875 | pw.println(sb.toString()); |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 3876 | |
| 3877 | sb.setLength(0); |
| 3878 | sb.append(prefix); |
| 3879 | sb.append(" Signal scanning time: "); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3880 | formatTimeMsNoSpace(sb, getPhoneSignalScanningTime(rawRealtime, which) / 1000); |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 3881 | pw.println(sb.toString()); |
| 3882 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3883 | sb.setLength(0); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3884 | sb.append(prefix); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3885 | sb.append(" Radio types:"); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3886 | didOne = false; |
| 3887 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3888 | final long time = getPhoneDataConnectionTime(i, rawRealtime, which); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3889 | if (time == 0) { |
| 3890 | continue; |
| 3891 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3892 | sb.append("\n "); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 3893 | sb.append(prefix); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3894 | didOne = true; |
| 3895 | sb.append(DATA_CONNECTION_NAMES[i]); |
| 3896 | sb.append(" "); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3897 | formatTimeMs(sb, time/1000); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3898 | sb.append("("); |
| 3899 | sb.append(formatRatioLocked(time, whichBatteryRealtime)); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3900 | sb.append(") "); |
| 3901 | sb.append(getPhoneDataConnectionCount(i, which)); |
| 3902 | sb.append("x"); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3903 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3904 | if (!didOne) sb.append(" (no activity)"); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3905 | pw.println(sb.toString()); |
Amith Yamasani | 3f7e35c | 2009-07-13 16:02:45 -0700 | [diff] [blame] | 3906 | |
| 3907 | sb.setLength(0); |
| 3908 | sb.append(prefix); |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 3909 | sb.append(" Mobile radio active time: "); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3910 | final long mobileActiveTime = getMobileRadioActiveTime(rawRealtime, which); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 3911 | formatTimeMs(sb, mobileActiveTime / 1000); |
| 3912 | sb.append("("); sb.append(formatRatioLocked(mobileActiveTime, whichBatteryRealtime)); |
| 3913 | sb.append(") "); sb.append(getMobileRadioActiveCount(which)); |
| 3914 | sb.append("x"); |
Amith Yamasani | 3f7e35c | 2009-07-13 16:02:45 -0700 | [diff] [blame] | 3915 | pw.println(sb.toString()); |
| 3916 | |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 3917 | final long mobileActiveUnknownTime = getMobileRadioActiveUnknownTime(which); |
| 3918 | if (mobileActiveUnknownTime != 0) { |
| 3919 | sb.setLength(0); |
| 3920 | sb.append(prefix); |
| 3921 | sb.append(" Mobile radio active unknown time: "); |
| 3922 | formatTimeMs(sb, mobileActiveUnknownTime / 1000); |
| 3923 | sb.append("("); |
| 3924 | sb.append(formatRatioLocked(mobileActiveUnknownTime, whichBatteryRealtime)); |
| 3925 | sb.append(") "); sb.append(getMobileRadioActiveUnknownCount(which)); |
| 3926 | sb.append("x"); |
| 3927 | pw.println(sb.toString()); |
| 3928 | } |
| 3929 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3930 | final long mobileActiveAdjustedTime = getMobileRadioActiveAdjustedTime(which); |
| 3931 | if (mobileActiveAdjustedTime != 0) { |
| 3932 | sb.setLength(0); |
| 3933 | sb.append(prefix); |
| 3934 | sb.append(" Mobile radio active adjusted time: "); |
| 3935 | formatTimeMs(sb, mobileActiveAdjustedTime / 1000); |
| 3936 | sb.append("("); |
| 3937 | sb.append(formatRatioLocked(mobileActiveAdjustedTime, whichBatteryRealtime)); |
| 3938 | sb.append(")"); |
| 3939 | pw.println(sb.toString()); |
| 3940 | } |
| 3941 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3942 | printControllerActivity(pw, sb, prefix, "Radio", getModemControllerActivity(), which); |
| 3943 | |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 3944 | pw.print(prefix); |
| 3945 | pw.print(" Wi-Fi total received: "); pw.print(formatBytesLocked(wifiRxTotalBytes)); |
| 3946 | pw.print(", sent: "); pw.print(formatBytesLocked(wifiTxTotalBytes)); |
| 3947 | pw.print(" (packets received "); pw.print(wifiRxTotalPackets); |
| 3948 | pw.print(", sent "); pw.print(wifiTxTotalPackets); pw.println(")"); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3949 | sb.setLength(0); |
| 3950 | sb.append(prefix); |
| 3951 | sb.append(" Wifi on: "); formatTimeMs(sb, wifiOnTime / 1000); |
| 3952 | sb.append("("); sb.append(formatRatioLocked(wifiOnTime, whichBatteryRealtime)); |
| 3953 | sb.append("), Wifi running: "); formatTimeMs(sb, wifiRunningTime / 1000); |
| 3954 | sb.append("("); sb.append(formatRatioLocked(wifiRunningTime, whichBatteryRealtime)); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3955 | sb.append(")"); |
| 3956 | pw.println(sb.toString()); |
| 3957 | |
| 3958 | sb.setLength(0); |
| 3959 | sb.append(prefix); |
| 3960 | sb.append(" Wifi states:"); |
| 3961 | didOne = false; |
| 3962 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3963 | final long time = getWifiStateTime(i, rawRealtime, which); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3964 | if (time == 0) { |
| 3965 | continue; |
| 3966 | } |
| 3967 | sb.append("\n "); |
| 3968 | didOne = true; |
| 3969 | sb.append(WIFI_STATE_NAMES[i]); |
| 3970 | sb.append(" "); |
| 3971 | formatTimeMs(sb, time/1000); |
| 3972 | sb.append("("); |
| 3973 | sb.append(formatRatioLocked(time, whichBatteryRealtime)); |
| 3974 | sb.append(") "); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 3975 | sb.append(getWifiStateCount(i, which)); |
| 3976 | sb.append("x"); |
| 3977 | } |
| 3978 | if (!didOne) sb.append(" (no activity)"); |
| 3979 | pw.println(sb.toString()); |
| 3980 | |
| 3981 | sb.setLength(0); |
| 3982 | sb.append(prefix); |
| 3983 | sb.append(" Wifi supplicant states:"); |
| 3984 | didOne = false; |
| 3985 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
| 3986 | final long time = getWifiSupplStateTime(i, rawRealtime, which); |
| 3987 | if (time == 0) { |
| 3988 | continue; |
| 3989 | } |
| 3990 | sb.append("\n "); |
| 3991 | didOne = true; |
| 3992 | sb.append(WIFI_SUPPL_STATE_NAMES[i]); |
| 3993 | sb.append(" "); |
| 3994 | formatTimeMs(sb, time/1000); |
| 3995 | sb.append("("); |
| 3996 | sb.append(formatRatioLocked(time, whichBatteryRealtime)); |
| 3997 | sb.append(") "); |
| 3998 | sb.append(getWifiSupplStateCount(i, which)); |
| 3999 | sb.append("x"); |
| 4000 | } |
| 4001 | if (!didOne) sb.append(" (no activity)"); |
| 4002 | pw.println(sb.toString()); |
| 4003 | |
| 4004 | sb.setLength(0); |
| 4005 | sb.append(prefix); |
| 4006 | sb.append(" Wifi signal levels:"); |
| 4007 | didOne = false; |
| 4008 | for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 4009 | final long time = getWifiSignalStrengthTime(i, rawRealtime, which); |
| 4010 | if (time == 0) { |
| 4011 | continue; |
| 4012 | } |
| 4013 | sb.append("\n "); |
| 4014 | sb.append(prefix); |
| 4015 | didOne = true; |
| 4016 | sb.append("level("); |
| 4017 | sb.append(i); |
| 4018 | sb.append(") "); |
| 4019 | formatTimeMs(sb, time/1000); |
| 4020 | sb.append("("); |
| 4021 | sb.append(formatRatioLocked(time, whichBatteryRealtime)); |
| 4022 | sb.append(") "); |
| 4023 | sb.append(getWifiSignalStrengthCount(i, which)); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4024 | sb.append("x"); |
| 4025 | } |
| 4026 | if (!didOne) sb.append(" (no activity)"); |
| 4027 | pw.println(sb.toString()); |
| 4028 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 4029 | printControllerActivity(pw, sb, prefix, "WiFi", getWifiControllerActivity(), which); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 4030 | |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 4031 | pw.print(prefix); |
| 4032 | pw.print(" Bluetooth total received: "); pw.print(formatBytesLocked(btRxTotalBytes)); |
| 4033 | pw.print(", sent: "); pw.println(formatBytesLocked(btTxTotalBytes)); |
| 4034 | |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 4035 | final long bluetoothScanTimeMs = getBluetoothScanTime(rawRealtime, which) / 1000; |
| 4036 | sb.setLength(0); |
| 4037 | sb.append(prefix); |
| 4038 | sb.append(" Bluetooth scan time: "); formatTimeMs(sb, bluetoothScanTimeMs); |
| 4039 | pw.println(sb.toString()); |
| 4040 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 4041 | printControllerActivity(pw, sb, prefix, "Bluetooth", getBluetoothControllerActivity(), |
| 4042 | which); |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 4043 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4044 | pw.println(); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4045 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4046 | if (which == STATS_SINCE_UNPLUGGED) { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4047 | if (getIsOnBattery()) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4048 | pw.print(prefix); pw.println(" Device is currently unplugged"); |
| 4049 | pw.print(prefix); pw.print(" Discharge cycle start level: "); |
| 4050 | pw.println(getDischargeStartLevel()); |
| 4051 | pw.print(prefix); pw.print(" Discharge cycle current level: "); |
| 4052 | pw.println(getDischargeCurrentLevel()); |
Dianne Hackborn | 99d0452 | 2010-08-20 13:43:00 -0700 | [diff] [blame] | 4053 | } else { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4054 | pw.print(prefix); pw.println(" Device is currently plugged into power"); |
| 4055 | pw.print(prefix); pw.print(" Last discharge cycle start level: "); |
| 4056 | pw.println(getDischargeStartLevel()); |
| 4057 | pw.print(prefix); pw.print(" Last discharge cycle end level: "); |
| 4058 | pw.println(getDischargeCurrentLevel()); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4059 | } |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 4060 | pw.print(prefix); pw.print(" Amount discharged while screen on: "); |
| 4061 | pw.println(getDischargeAmountScreenOn()); |
| 4062 | pw.print(prefix); pw.print(" Amount discharged while screen off: "); |
| 4063 | pw.println(getDischargeAmountScreenOff()); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4064 | pw.println(" "); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4065 | } else { |
| 4066 | pw.print(prefix); pw.println(" Device battery use since last full charge"); |
| 4067 | pw.print(prefix); pw.print(" Amount discharged (lower bound): "); |
| 4068 | pw.println(getLowDischargeAmountSinceCharge()); |
| 4069 | pw.print(prefix); pw.print(" Amount discharged (upper bound): "); |
| 4070 | pw.println(getHighDischargeAmountSinceCharge()); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 4071 | pw.print(prefix); pw.print(" Amount discharged while screen on: "); |
| 4072 | pw.println(getDischargeAmountScreenOnSinceCharge()); |
| 4073 | pw.print(prefix); pw.print(" Amount discharged while screen off: "); |
| 4074 | pw.println(getDischargeAmountScreenOffSinceCharge()); |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 4075 | pw.println(); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4076 | } |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 4077 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4078 | final BatteryStatsHelper helper = new BatteryStatsHelper(context, false, wifiOnly); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4079 | helper.create(this); |
| 4080 | helper.refreshStats(which, UserHandle.USER_ALL); |
| 4081 | List<BatterySipper> sippers = helper.getUsageList(); |
| 4082 | if (sippers != null && sippers.size() > 0) { |
| 4083 | pw.print(prefix); pw.println(" Estimated power use (mAh):"); |
| 4084 | pw.print(prefix); pw.print(" Capacity: "); |
| 4085 | printmAh(pw, helper.getPowerProfile().getBatteryCapacity()); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4086 | pw.print(", Computed drain: "); printmAh(pw, helper.getComputedPower()); |
Dianne Hackborn | 536456f | 2014-05-23 16:51:05 -0700 | [diff] [blame] | 4087 | pw.print(", actual drain: "); printmAh(pw, helper.getMinDrainedPower()); |
| 4088 | if (helper.getMinDrainedPower() != helper.getMaxDrainedPower()) { |
| 4089 | pw.print("-"); printmAh(pw, helper.getMaxDrainedPower()); |
| 4090 | } |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4091 | pw.println(); |
| 4092 | for (int i=0; i<sippers.size(); i++) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4093 | final BatterySipper bs = sippers.get(i); |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4094 | pw.print(prefix); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4095 | switch (bs.drainType) { |
| 4096 | case IDLE: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4097 | pw.print(" Idle: "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4098 | break; |
| 4099 | case CELL: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4100 | pw.print(" Cell standby: "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4101 | break; |
| 4102 | case PHONE: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4103 | pw.print(" Phone calls: "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4104 | break; |
| 4105 | case WIFI: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4106 | pw.print(" Wifi: "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4107 | break; |
| 4108 | case BLUETOOTH: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4109 | pw.print(" Bluetooth: "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4110 | break; |
| 4111 | case SCREEN: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4112 | pw.print(" Screen: "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4113 | break; |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 4114 | case FLASHLIGHT: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4115 | pw.print(" Flashlight: "); |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 4116 | break; |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4117 | case APP: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4118 | pw.print(" Uid "); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4119 | UserHandle.formatUid(pw, bs.uidObj.getUid()); |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4120 | pw.print(": "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4121 | break; |
| 4122 | case USER: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4123 | pw.print(" User "); pw.print(bs.userId); |
| 4124 | pw.print(": "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4125 | break; |
| 4126 | case UNACCOUNTED: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4127 | pw.print(" Unaccounted: "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4128 | break; |
| 4129 | case OVERCOUNTED: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4130 | pw.print(" Over-counted: "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4131 | break; |
Ruben Brunk | 5b1308f | 2015-06-03 18:49:27 -0700 | [diff] [blame] | 4132 | case CAMERA: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4133 | pw.print(" Camera: "); |
| 4134 | break; |
| 4135 | default: |
| 4136 | pw.print(" ???: "); |
Ruben Brunk | 5b1308f | 2015-06-03 18:49:27 -0700 | [diff] [blame] | 4137 | break; |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4138 | } |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4139 | printmAh(pw, bs.totalPowerMah); |
| 4140 | |
Adam Lesinski | 5712300 | 2015-06-12 16:12:07 -0700 | [diff] [blame] | 4141 | if (bs.usagePowerMah != bs.totalPowerMah) { |
| 4142 | // If the usage (generic power) isn't the whole amount, we list out |
| 4143 | // what components are involved in the calculation. |
| 4144 | |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4145 | pw.print(" ("); |
Adam Lesinski | 5712300 | 2015-06-12 16:12:07 -0700 | [diff] [blame] | 4146 | if (bs.usagePowerMah != 0) { |
| 4147 | pw.print(" usage="); |
| 4148 | printmAh(pw, bs.usagePowerMah); |
| 4149 | } |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4150 | if (bs.cpuPowerMah != 0) { |
| 4151 | pw.print(" cpu="); |
| 4152 | printmAh(pw, bs.cpuPowerMah); |
| 4153 | } |
| 4154 | if (bs.wakeLockPowerMah != 0) { |
| 4155 | pw.print(" wake="); |
| 4156 | printmAh(pw, bs.wakeLockPowerMah); |
| 4157 | } |
| 4158 | if (bs.mobileRadioPowerMah != 0) { |
| 4159 | pw.print(" radio="); |
| 4160 | printmAh(pw, bs.mobileRadioPowerMah); |
| 4161 | } |
| 4162 | if (bs.wifiPowerMah != 0) { |
| 4163 | pw.print(" wifi="); |
| 4164 | printmAh(pw, bs.wifiPowerMah); |
| 4165 | } |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 4166 | if (bs.bluetoothPowerMah != 0) { |
| 4167 | pw.print(" bt="); |
| 4168 | printmAh(pw, bs.bluetoothPowerMah); |
| 4169 | } |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4170 | if (bs.gpsPowerMah != 0) { |
| 4171 | pw.print(" gps="); |
| 4172 | printmAh(pw, bs.gpsPowerMah); |
| 4173 | } |
| 4174 | if (bs.sensorPowerMah != 0) { |
| 4175 | pw.print(" sensor="); |
| 4176 | printmAh(pw, bs.sensorPowerMah); |
| 4177 | } |
| 4178 | if (bs.cameraPowerMah != 0) { |
| 4179 | pw.print(" camera="); |
| 4180 | printmAh(pw, bs.cameraPowerMah); |
| 4181 | } |
| 4182 | if (bs.flashlightPowerMah != 0) { |
| 4183 | pw.print(" flash="); |
| 4184 | printmAh(pw, bs.flashlightPowerMah); |
| 4185 | } |
| 4186 | pw.print(" )"); |
| 4187 | } |
| 4188 | pw.println(); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4189 | } |
Dianne Hackborn | c46809e | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4190 | pw.println(); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4191 | } |
| 4192 | |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4193 | sippers = helper.getMobilemsppList(); |
| 4194 | if (sippers != null && sippers.size() > 0) { |
| 4195 | pw.print(prefix); pw.println(" Per-app mobile ms per packet:"); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 4196 | long totalTime = 0; |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4197 | for (int i=0; i<sippers.size(); i++) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4198 | final BatterySipper bs = sippers.get(i); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4199 | sb.setLength(0); |
| 4200 | sb.append(prefix); sb.append(" Uid "); |
| 4201 | UserHandle.formatUid(sb, bs.uidObj.getUid()); |
| 4202 | sb.append(": "); sb.append(BatteryStatsHelper.makemAh(bs.mobilemspp)); |
| 4203 | sb.append(" ("); sb.append(bs.mobileRxPackets+bs.mobileTxPackets); |
| 4204 | sb.append(" packets over "); formatTimeMsNoSpace(sb, bs.mobileActive); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 4205 | sb.append(") "); sb.append(bs.mobileActiveCount); sb.append("x"); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4206 | pw.println(sb.toString()); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 4207 | totalTime += bs.mobileActive; |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4208 | } |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 4209 | sb.setLength(0); |
| 4210 | sb.append(prefix); |
| 4211 | sb.append(" TOTAL TIME: "); |
| 4212 | formatTimeMs(sb, totalTime); |
| 4213 | sb.append("("); sb.append(formatRatioLocked(totalTime, whichBatteryRealtime)); |
| 4214 | sb.append(")"); |
| 4215 | pw.println(sb.toString()); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4216 | pw.println(); |
| 4217 | } |
| 4218 | |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 4219 | final Comparator<TimerEntry> timerComparator = new Comparator<TimerEntry>() { |
| 4220 | @Override |
| 4221 | public int compare(TimerEntry lhs, TimerEntry rhs) { |
| 4222 | long lhsTime = lhs.mTime; |
| 4223 | long rhsTime = rhs.mTime; |
| 4224 | if (lhsTime < rhsTime) { |
| 4225 | return 1; |
| 4226 | } |
| 4227 | if (lhsTime > rhsTime) { |
| 4228 | return -1; |
| 4229 | } |
| 4230 | return 0; |
| 4231 | } |
| 4232 | }; |
| 4233 | |
| 4234 | if (reqUid < 0) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4235 | final Map<String, ? extends BatteryStats.Timer> kernelWakelocks |
| 4236 | = getKernelWakelockStats(); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 4237 | if (kernelWakelocks.size() > 0) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4238 | final ArrayList<TimerEntry> ktimers = new ArrayList<>(); |
| 4239 | for (Map.Entry<String, ? extends BatteryStats.Timer> ent |
| 4240 | : kernelWakelocks.entrySet()) { |
| 4241 | final BatteryStats.Timer timer = ent.getValue(); |
| 4242 | final long totalTimeMillis = computeWakeLock(timer, rawRealtime, which); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 4243 | if (totalTimeMillis > 0) { |
| 4244 | ktimers.add(new TimerEntry(ent.getKey(), 0, timer, totalTimeMillis)); |
| 4245 | } |
| 4246 | } |
| 4247 | if (ktimers.size() > 0) { |
| 4248 | Collections.sort(ktimers, timerComparator); |
| 4249 | pw.print(prefix); pw.println(" All kernel wake locks:"); |
| 4250 | for (int i=0; i<ktimers.size(); i++) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4251 | final TimerEntry timer = ktimers.get(i); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 4252 | String linePrefix = ": "; |
| 4253 | sb.setLength(0); |
| 4254 | sb.append(prefix); |
| 4255 | sb.append(" Kernel Wake lock "); |
| 4256 | sb.append(timer.mName); |
| 4257 | linePrefix = printWakeLock(sb, timer.mTimer, rawRealtime, null, |
| 4258 | which, linePrefix); |
| 4259 | if (!linePrefix.equals(": ")) { |
| 4260 | sb.append(" realtime"); |
| 4261 | // Only print out wake locks that were held |
| 4262 | pw.println(sb.toString()); |
| 4263 | } |
| 4264 | } |
| 4265 | pw.println(); |
| 4266 | } |
| 4267 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 4268 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 4269 | if (timers.size() > 0) { |
| 4270 | Collections.sort(timers, timerComparator); |
| 4271 | pw.print(prefix); pw.println(" All partial wake locks:"); |
| 4272 | for (int i=0; i<timers.size(); i++) { |
| 4273 | TimerEntry timer = timers.get(i); |
| 4274 | sb.setLength(0); |
| 4275 | sb.append(" Wake lock "); |
| 4276 | UserHandle.formatUid(sb, timer.mId); |
| 4277 | sb.append(" "); |
| 4278 | sb.append(timer.mName); |
| 4279 | printWakeLock(sb, timer.mTimer, rawRealtime, null, which, ": "); |
| 4280 | sb.append(" realtime"); |
| 4281 | pw.println(sb.toString()); |
| 4282 | } |
| 4283 | timers.clear(); |
| 4284 | pw.println(); |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 4285 | } |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 4286 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4287 | final Map<String, ? extends Timer> wakeupReasons = getWakeupReasonStats(); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 4288 | if (wakeupReasons.size() > 0) { |
| 4289 | pw.print(prefix); pw.println(" All wakeup reasons:"); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4290 | final ArrayList<TimerEntry> reasons = new ArrayList<>(); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 4291 | for (Map.Entry<String, ? extends Timer> ent : wakeupReasons.entrySet()) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4292 | final Timer timer = ent.getValue(); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 4293 | reasons.add(new TimerEntry(ent.getKey(), 0, timer, |
| 4294 | timer.getCountLocked(which))); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 4295 | } |
| 4296 | Collections.sort(reasons, timerComparator); |
| 4297 | for (int i=0; i<reasons.size(); i++) { |
| 4298 | TimerEntry timer = reasons.get(i); |
| 4299 | String linePrefix = ": "; |
| 4300 | sb.setLength(0); |
| 4301 | sb.append(prefix); |
| 4302 | sb.append(" Wakeup reason "); |
| 4303 | sb.append(timer.mName); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 4304 | printWakeLock(sb, timer.mTimer, rawRealtime, null, which, ": "); |
| 4305 | sb.append(" realtime"); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 4306 | pw.println(sb.toString()); |
| 4307 | } |
| 4308 | pw.println(); |
| 4309 | } |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 4310 | } |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 4311 | |
James Carr | 2dd7e5e | 2016-07-20 18:48:39 -0700 | [diff] [blame] | 4312 | final LongSparseArray<? extends Timer> mMemoryStats = getKernelMemoryStats(); |
| 4313 | pw.println("Memory Stats"); |
| 4314 | for (int i = 0; i < mMemoryStats.size(); i++) { |
| 4315 | sb.setLength(0); |
| 4316 | sb.append("Bandwidth "); |
| 4317 | sb.append(mMemoryStats.keyAt(i)); |
| 4318 | sb.append(" Time "); |
| 4319 | sb.append(mMemoryStats.valueAt(i).getTotalTimeLocked(rawRealtime, which)); |
| 4320 | pw.println(sb.toString()); |
| 4321 | } |
| 4322 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4323 | for (int iu=0; iu<NU; iu++) { |
| 4324 | final int uid = uidStats.keyAt(iu); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 4325 | if (reqUid >= 0 && uid != reqUid && uid != Process.SYSTEM_UID) { |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 4326 | continue; |
| 4327 | } |
| 4328 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4329 | final Uid u = uidStats.valueAt(iu); |
Dianne Hackborn | a4cc205 | 2013-07-08 17:31:25 -0700 | [diff] [blame] | 4330 | |
| 4331 | pw.print(prefix); |
| 4332 | pw.print(" "); |
| 4333 | UserHandle.formatUid(pw, uid); |
| 4334 | pw.println(":"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4335 | boolean uidActivity = false; |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4336 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4337 | final long mobileRxBytes = u.getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which); |
| 4338 | final long mobileTxBytes = u.getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which); |
| 4339 | final long wifiRxBytes = u.getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which); |
| 4340 | final long wifiTxBytes = u.getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which); |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 4341 | final long btRxBytes = u.getNetworkActivityBytes(NETWORK_BT_RX_DATA, which); |
| 4342 | final long btTxBytes = u.getNetworkActivityBytes(NETWORK_BT_TX_DATA, which); |
| 4343 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4344 | final long mobileRxPackets = u.getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which); |
| 4345 | final long mobileTxPackets = u.getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4346 | final long wifiRxPackets = u.getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which); |
| 4347 | final long wifiTxPackets = u.getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which); |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 4348 | |
| 4349 | final long uidMobileActiveTime = u.getMobileRadioActiveTime(which); |
| 4350 | final int uidMobileActiveCount = u.getMobileRadioActiveCount(which); |
| 4351 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4352 | final long fullWifiLockOnTime = u.getFullWifiLockTime(rawRealtime, which); |
| 4353 | final long wifiScanTime = u.getWifiScanTime(rawRealtime, which); |
| 4354 | final int wifiScanCount = u.getWifiScanCount(which); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 4355 | final int wifiScanCountBg = u.getWifiScanBackgroundCount(which); |
| 4356 | // 'actualTime' are unpooled and always since reset (regardless of 'which') |
| 4357 | final long wifiScanActualTime = u.getWifiScanActualTime(rawRealtime); |
| 4358 | final long wifiScanActualTimeBg = u.getWifiScanBackgroundTime(rawRealtime); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4359 | final long uidWifiRunningTime = u.getWifiRunningTime(rawRealtime, which); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 4360 | |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 4361 | final long mobileWakeup = u.getMobileRadioApWakeupCount(which); |
| 4362 | final long wifiWakeup = u.getWifiRadioApWakeupCount(which); |
| 4363 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4364 | if (mobileRxBytes > 0 || mobileTxBytes > 0 |
| 4365 | || mobileRxPackets > 0 || mobileTxPackets > 0) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 4366 | pw.print(prefix); pw.print(" Mobile network: "); |
| 4367 | pw.print(formatBytesLocked(mobileRxBytes)); pw.print(" received, "); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4368 | pw.print(formatBytesLocked(mobileTxBytes)); |
| 4369 | pw.print(" sent (packets "); pw.print(mobileRxPackets); |
| 4370 | pw.print(" received, "); pw.print(mobileTxPackets); pw.println(" sent)"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4371 | } |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4372 | if (uidMobileActiveTime > 0 || uidMobileActiveCount > 0) { |
| 4373 | sb.setLength(0); |
| 4374 | sb.append(prefix); sb.append(" Mobile radio active: "); |
| 4375 | formatTimeMs(sb, uidMobileActiveTime / 1000); |
| 4376 | sb.append("("); |
| 4377 | sb.append(formatRatioLocked(uidMobileActiveTime, mobileActiveTime)); |
| 4378 | sb.append(") "); sb.append(uidMobileActiveCount); sb.append("x"); |
| 4379 | long packets = mobileRxPackets + mobileTxPackets; |
| 4380 | if (packets == 0) { |
| 4381 | packets = 1; |
| 4382 | } |
| 4383 | sb.append(" @ "); |
| 4384 | sb.append(BatteryStatsHelper.makemAh(uidMobileActiveTime / 1000 / (double)packets)); |
| 4385 | sb.append(" mspp"); |
| 4386 | pw.println(sb.toString()); |
| 4387 | } |
| 4388 | |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 4389 | if (mobileWakeup > 0) { |
| 4390 | sb.setLength(0); |
| 4391 | sb.append(prefix); |
| 4392 | sb.append(" Mobile radio AP wakeups: "); |
| 4393 | sb.append(mobileWakeup); |
| 4394 | pw.println(sb.toString()); |
| 4395 | } |
| 4396 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 4397 | printControllerActivityIfInteresting(pw, sb, prefix + " ", "Modem", |
| 4398 | u.getModemControllerActivity(), which); |
| 4399 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4400 | if (wifiRxBytes > 0 || wifiTxBytes > 0 || wifiRxPackets > 0 || wifiTxPackets > 0) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 4401 | pw.print(prefix); pw.print(" Wi-Fi network: "); |
| 4402 | pw.print(formatBytesLocked(wifiRxBytes)); pw.print(" received, "); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4403 | pw.print(formatBytesLocked(wifiTxBytes)); |
| 4404 | pw.print(" sent (packets "); pw.print(wifiRxPackets); |
| 4405 | pw.print(" received, "); pw.print(wifiTxPackets); pw.println(" sent)"); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 4406 | } |
| 4407 | |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 4408 | if (fullWifiLockOnTime != 0 || wifiScanTime != 0 || wifiScanCount != 0 |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 4409 | || wifiScanCountBg != 0 || wifiScanActualTime != 0 || wifiScanActualTimeBg != 0 |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4410 | || uidWifiRunningTime != 0) { |
| 4411 | sb.setLength(0); |
| 4412 | sb.append(prefix); sb.append(" Wifi Running: "); |
| 4413 | formatTimeMs(sb, uidWifiRunningTime / 1000); |
| 4414 | sb.append("("); sb.append(formatRatioLocked(uidWifiRunningTime, |
| 4415 | whichBatteryRealtime)); sb.append(")\n"); |
| 4416 | sb.append(prefix); sb.append(" Full Wifi Lock: "); |
| 4417 | formatTimeMs(sb, fullWifiLockOnTime / 1000); |
| 4418 | sb.append("("); sb.append(formatRatioLocked(fullWifiLockOnTime, |
| 4419 | whichBatteryRealtime)); sb.append(")\n"); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 4420 | sb.append(prefix); sb.append(" Wifi Scan (blamed): "); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4421 | formatTimeMs(sb, wifiScanTime / 1000); |
| 4422 | sb.append("("); sb.append(formatRatioLocked(wifiScanTime, |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 4423 | whichBatteryRealtime)); sb.append(") "); |
| 4424 | sb.append(wifiScanCount); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 4425 | sb.append("x\n"); |
| 4426 | // actual and background times are unpooled and since reset (regardless of 'which') |
| 4427 | sb.append(prefix); sb.append(" Wifi Scan (actual): "); |
| 4428 | formatTimeMs(sb, wifiScanActualTime / 1000); |
| 4429 | sb.append("("); sb.append(formatRatioLocked(wifiScanActualTime, |
| 4430 | computeBatteryRealtime(rawRealtime, STATS_SINCE_CHARGED))); |
| 4431 | sb.append(") "); |
| 4432 | sb.append(wifiScanCount); |
| 4433 | sb.append("x\n"); |
| 4434 | sb.append(prefix); sb.append(" Background Wifi Scan: "); |
| 4435 | formatTimeMs(sb, wifiScanActualTimeBg / 1000); |
| 4436 | sb.append("("); sb.append(formatRatioLocked(wifiScanActualTimeBg, |
| 4437 | computeBatteryRealtime(rawRealtime, STATS_SINCE_CHARGED))); |
| 4438 | sb.append(") "); |
| 4439 | sb.append(wifiScanCountBg); |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 4440 | sb.append("x"); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4441 | pw.println(sb.toString()); |
| 4442 | } |
| 4443 | |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 4444 | if (wifiWakeup > 0) { |
| 4445 | sb.setLength(0); |
| 4446 | sb.append(prefix); |
| 4447 | sb.append(" WiFi AP wakeups: "); |
| 4448 | sb.append(wifiWakeup); |
| 4449 | pw.println(sb.toString()); |
| 4450 | } |
| 4451 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 4452 | printControllerActivityIfInteresting(pw, sb, prefix + " ", "WiFi", |
| 4453 | u.getWifiControllerActivity(), which); |
Adam Lesinski | 049c88b | 2015-05-28 11:38:12 -0700 | [diff] [blame] | 4454 | |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 4455 | if (btRxBytes > 0 || btTxBytes > 0) { |
| 4456 | pw.print(prefix); pw.print(" Bluetooth network: "); |
| 4457 | pw.print(formatBytesLocked(btRxBytes)); pw.print(" received, "); |
| 4458 | pw.print(formatBytesLocked(btTxBytes)); |
| 4459 | pw.println(" sent"); |
| 4460 | } |
| 4461 | |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 4462 | final Timer bleTimer = u.getBluetoothScanTimer(); |
| 4463 | if (bleTimer != null) { |
| 4464 | // Convert from microseconds to milliseconds with rounding |
| 4465 | final long totalTimeMs = (bleTimer.getTotalTimeLocked(rawRealtime, which) + 500) |
| 4466 | / 1000; |
| 4467 | if (totalTimeMs != 0) { |
| 4468 | final int count = bleTimer.getCountLocked(which); |
| 4469 | final Timer bleTimerBg = u.getBluetoothScanBackgroundTimer(); |
| 4470 | final int countBg = bleTimerBg != null ? bleTimerBg.getCountLocked(which) : 0; |
| 4471 | final long rawRealtimeMs = (rawRealtime + 500) / 1000; |
| 4472 | // 'actualTime' are unpooled and always since reset (regardless of 'which') |
| 4473 | final long actualTimeMs = bleTimer.getTotalDurationMsLocked(rawRealtimeMs); |
| 4474 | final long actualTimeMsBg = bleTimerBg != null ? |
| 4475 | bleTimerBg.getTotalDurationMsLocked(rawRealtimeMs) : 0; |
| 4476 | |
| 4477 | sb.setLength(0); |
| 4478 | sb.append(prefix); |
| 4479 | sb.append(" "); |
| 4480 | sb.append("Bluetooth Scan"); |
| 4481 | sb.append(": "); |
| 4482 | if (actualTimeMs != totalTimeMs) { |
| 4483 | formatTimeMs(sb, totalTimeMs); |
| 4484 | sb.append("blamed realtime, "); |
| 4485 | } |
| 4486 | formatTimeMs(sb, actualTimeMs); // since reset, regardless of 'which' |
| 4487 | sb.append("realtime ("); |
| 4488 | sb.append(count); |
| 4489 | sb.append(" times)"); |
| 4490 | if (bleTimer.isRunningLocked()) { |
| 4491 | sb.append(" (running)"); |
| 4492 | } |
| 4493 | if (actualTimeMsBg != 0 || countBg > 0) { |
| 4494 | sb.append(", "); |
| 4495 | formatTimeMs(sb, actualTimeMsBg); // since reset, regardless of 'which' |
| 4496 | sb.append("background ("); |
| 4497 | sb.append(countBg); |
| 4498 | sb.append(" times)"); |
| 4499 | } |
| 4500 | pw.println(sb.toString()); |
| 4501 | uidActivity = true; |
| 4502 | } |
| 4503 | } |
| 4504 | |
| 4505 | |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 4506 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4507 | if (u.hasUserActivity()) { |
| 4508 | boolean hasData = false; |
Raph Levien | 4c7a4a7 | 2012-08-03 14:32:39 -0700 | [diff] [blame] | 4509 | for (int i=0; i<Uid.NUM_USER_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4510 | final int val = u.getUserActivityCount(i, which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4511 | if (val != 0) { |
| 4512 | if (!hasData) { |
| 4513 | sb.setLength(0); |
| 4514 | sb.append(" User activity: "); |
| 4515 | hasData = true; |
| 4516 | } else { |
| 4517 | sb.append(", "); |
| 4518 | } |
| 4519 | sb.append(val); |
| 4520 | sb.append(" "); |
| 4521 | sb.append(Uid.USER_ACTIVITY_TYPES[i]); |
| 4522 | } |
| 4523 | } |
| 4524 | if (hasData) { |
| 4525 | pw.println(sb.toString()); |
| 4526 | } |
| 4527 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4528 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4529 | final ArrayMap<String, ? extends BatteryStats.Uid.Wakelock> wakelocks |
| 4530 | = u.getWakelockStats(); |
| 4531 | long totalFullWakelock = 0, totalPartialWakelock = 0, totalWindowWakelock = 0; |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 4532 | long totalDrawWakelock = 0; |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4533 | int countWakelock = 0; |
| 4534 | for (int iw=wakelocks.size()-1; iw>=0; iw--) { |
| 4535 | final Uid.Wakelock wl = wakelocks.valueAt(iw); |
| 4536 | String linePrefix = ": "; |
| 4537 | sb.setLength(0); |
| 4538 | sb.append(prefix); |
| 4539 | sb.append(" Wake lock "); |
| 4540 | sb.append(wakelocks.keyAt(iw)); |
| 4541 | linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_FULL), rawRealtime, |
| 4542 | "full", which, linePrefix); |
| 4543 | linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_PARTIAL), rawRealtime, |
| 4544 | "partial", which, linePrefix); |
| 4545 | linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_WINDOW), rawRealtime, |
| 4546 | "window", which, linePrefix); |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 4547 | linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_DRAW), rawRealtime, |
| 4548 | "draw", which, linePrefix); |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 4549 | sb.append(" realtime"); |
| 4550 | pw.println(sb.toString()); |
| 4551 | uidActivity = true; |
| 4552 | countWakelock++; |
| 4553 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4554 | totalFullWakelock += computeWakeLock(wl.getWakeTime(WAKE_TYPE_FULL), |
| 4555 | rawRealtime, which); |
| 4556 | totalPartialWakelock += computeWakeLock(wl.getWakeTime(WAKE_TYPE_PARTIAL), |
| 4557 | rawRealtime, which); |
| 4558 | totalWindowWakelock += computeWakeLock(wl.getWakeTime(WAKE_TYPE_WINDOW), |
| 4559 | rawRealtime, which); |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 4560 | totalDrawWakelock += computeWakeLock(wl.getWakeTime(WAKE_TYPE_DRAW), |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 4561 | rawRealtime, which); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 4562 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4563 | if (countWakelock > 1) { |
| 4564 | if (totalFullWakelock != 0 || totalPartialWakelock != 0 |
| 4565 | || totalWindowWakelock != 0) { |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 4566 | sb.setLength(0); |
| 4567 | sb.append(prefix); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4568 | sb.append(" TOTAL wake: "); |
| 4569 | boolean needComma = false; |
| 4570 | if (totalFullWakelock != 0) { |
| 4571 | needComma = true; |
| 4572 | formatTimeMs(sb, totalFullWakelock); |
| 4573 | sb.append("full"); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 4574 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4575 | if (totalPartialWakelock != 0) { |
| 4576 | if (needComma) { |
| 4577 | sb.append(", "); |
| 4578 | } |
| 4579 | needComma = true; |
| 4580 | formatTimeMs(sb, totalPartialWakelock); |
| 4581 | sb.append("partial"); |
| 4582 | } |
| 4583 | if (totalWindowWakelock != 0) { |
| 4584 | if (needComma) { |
| 4585 | sb.append(", "); |
| 4586 | } |
| 4587 | needComma = true; |
| 4588 | formatTimeMs(sb, totalWindowWakelock); |
| 4589 | sb.append("window"); |
| 4590 | } |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 4591 | if (totalDrawWakelock != 0) { |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 4592 | if (needComma) { |
| 4593 | sb.append(","); |
| 4594 | } |
| 4595 | needComma = true; |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 4596 | formatTimeMs(sb, totalDrawWakelock); |
| 4597 | sb.append("draw"); |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 4598 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4599 | sb.append(" realtime"); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 4600 | pw.println(sb.toString()); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 4601 | } |
| 4602 | } |
| 4603 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4604 | final ArrayMap<String, ? extends Timer> syncs = u.getSyncStats(); |
| 4605 | for (int isy=syncs.size()-1; isy>=0; isy--) { |
| 4606 | final Timer timer = syncs.valueAt(isy); |
| 4607 | // Convert from microseconds to milliseconds with rounding |
| 4608 | final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000; |
| 4609 | final int count = timer.getCountLocked(which); |
| 4610 | sb.setLength(0); |
| 4611 | sb.append(prefix); |
| 4612 | sb.append(" Sync "); |
| 4613 | sb.append(syncs.keyAt(isy)); |
| 4614 | sb.append(": "); |
| 4615 | if (totalTime != 0) { |
| 4616 | formatTimeMs(sb, totalTime); |
| 4617 | sb.append("realtime ("); |
| 4618 | sb.append(count); |
| 4619 | sb.append(" times)"); |
| 4620 | } else { |
| 4621 | sb.append("(not used)"); |
| 4622 | } |
| 4623 | pw.println(sb.toString()); |
| 4624 | uidActivity = true; |
| 4625 | } |
| 4626 | |
| 4627 | final ArrayMap<String, ? extends Timer> jobs = u.getJobStats(); |
| 4628 | for (int ij=jobs.size()-1; ij>=0; ij--) { |
| 4629 | final Timer timer = jobs.valueAt(ij); |
| 4630 | // Convert from microseconds to milliseconds with rounding |
| 4631 | final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000; |
| 4632 | final int count = timer.getCountLocked(which); |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame^] | 4633 | final Timer bgTimer = timer.getSubTimer(); |
| 4634 | final long bgTime = bgTimer != null ? |
| 4635 | (bgTimer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000 : -1; |
| 4636 | final int bgCount = bgTimer != null ? bgTimer.getCountLocked(which) : -1; |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4637 | sb.setLength(0); |
| 4638 | sb.append(prefix); |
| 4639 | sb.append(" Job "); |
| 4640 | sb.append(jobs.keyAt(ij)); |
| 4641 | sb.append(": "); |
| 4642 | if (totalTime != 0) { |
| 4643 | formatTimeMs(sb, totalTime); |
| 4644 | sb.append("realtime ("); |
| 4645 | sb.append(count); |
| 4646 | sb.append(" times)"); |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame^] | 4647 | if (bgTime > 0) { |
| 4648 | sb.append(", "); |
| 4649 | formatTimeMs(sb, bgTime); |
| 4650 | sb.append("background ("); |
| 4651 | sb.append(bgCount); |
| 4652 | sb.append(" times)"); |
| 4653 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4654 | } else { |
| 4655 | sb.append("(not used)"); |
| 4656 | } |
| 4657 | pw.println(sb.toString()); |
| 4658 | uidActivity = true; |
| 4659 | } |
| 4660 | |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 4661 | uidActivity |= printTimer(pw, sb, u.getFlashlightTurnedOnTimer(), rawRealtime, which, |
| 4662 | prefix, "Flashlight"); |
| 4663 | uidActivity |= printTimer(pw, sb, u.getCameraTurnedOnTimer(), rawRealtime, which, |
| 4664 | prefix, "Camera"); |
| 4665 | uidActivity |= printTimer(pw, sb, u.getVideoTurnedOnTimer(), rawRealtime, which, |
| 4666 | prefix, "Video"); |
| 4667 | uidActivity |= printTimer(pw, sb, u.getAudioTurnedOnTimer(), rawRealtime, which, |
| 4668 | prefix, "Audio"); |
| 4669 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4670 | final SparseArray<? extends BatteryStats.Uid.Sensor> sensors = u.getSensorStats(); |
| 4671 | final int NSE = sensors.size(); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 4672 | for (int ise=0; ise<NSE; ise++) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4673 | final Uid.Sensor se = sensors.valueAt(ise); |
| 4674 | final int sensorNumber = sensors.keyAt(ise); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 4675 | sb.setLength(0); |
| 4676 | sb.append(prefix); |
| 4677 | sb.append(" Sensor "); |
| 4678 | int handle = se.getHandle(); |
| 4679 | if (handle == Uid.Sensor.GPS) { |
| 4680 | sb.append("GPS"); |
| 4681 | } else { |
| 4682 | sb.append(handle); |
| 4683 | } |
| 4684 | sb.append(": "); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4685 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4686 | final Timer timer = se.getSensorTime(); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 4687 | if (timer != null) { |
| 4688 | // Convert from microseconds to milliseconds with rounding |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 4689 | final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) |
| 4690 | / 1000; |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4691 | final int count = timer.getCountLocked(which); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 4692 | final Timer bgTimer = se.getSensorBackgroundTime(); |
| 4693 | final int bgCount = bgTimer != null ? bgTimer.getCountLocked(which) : 0; |
| 4694 | final long rawRealtimeMs = (rawRealtime + 500) / 1000; |
| 4695 | // 'actualTime' are unpooled and always since reset (regardless of 'which') |
| 4696 | final long actualTime = timer.getTotalDurationMsLocked(rawRealtimeMs); |
| 4697 | final long bgActualTime = bgTimer != null ? |
| 4698 | bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : 0; |
| 4699 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 4700 | //timer.logState(); |
| 4701 | if (totalTime != 0) { |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 4702 | if (actualTime != totalTime) { |
| 4703 | formatTimeMs(sb, totalTime); |
| 4704 | sb.append("blamed realtime, "); |
| 4705 | } |
| 4706 | |
| 4707 | formatTimeMs(sb, actualTime); // since reset, regardless of 'which' |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 4708 | sb.append("realtime ("); |
| 4709 | sb.append(count); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 4710 | sb.append(" times)"); |
| 4711 | |
| 4712 | if (bgActualTime != 0 || bgCount > 0) { |
Amith Yamasani | ab9ad19 | 2016-12-06 12:46:59 -0800 | [diff] [blame] | 4713 | sb.append(", "); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 4714 | formatTimeMs(sb, bgActualTime); // since reset, regardless of 'which' |
| 4715 | sb.append("background ("); |
Amith Yamasani | ab9ad19 | 2016-12-06 12:46:59 -0800 | [diff] [blame] | 4716 | sb.append(bgCount); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 4717 | sb.append(" times)"); |
Amith Yamasani | ab9ad19 | 2016-12-06 12:46:59 -0800 | [diff] [blame] | 4718 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4719 | } else { |
| 4720 | sb.append("(not used)"); |
| 4721 | } |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 4722 | } else { |
| 4723 | sb.append("(not used)"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4724 | } |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 4725 | |
| 4726 | pw.println(sb.toString()); |
| 4727 | uidActivity = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4728 | } |
| 4729 | |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 4730 | uidActivity |= printTimer(pw, sb, u.getVibratorOnTimer(), rawRealtime, which, prefix, |
| 4731 | "Vibrator"); |
| 4732 | uidActivity |= printTimer(pw, sb, u.getForegroundActivityTimer(), rawRealtime, which, |
| 4733 | prefix, "Foreground activities"); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 4734 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 4735 | long totalStateTime = 0; |
| 4736 | for (int ips=0; ips<Uid.NUM_PROCESS_STATE; ips++) { |
| 4737 | long time = u.getProcessStateTime(ips, rawRealtime, which); |
| 4738 | if (time > 0) { |
| 4739 | totalStateTime += time; |
| 4740 | sb.setLength(0); |
| 4741 | sb.append(prefix); |
| 4742 | sb.append(" "); |
| 4743 | sb.append(Uid.PROCESS_STATE_NAMES[ips]); |
| 4744 | sb.append(" for: "); |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 4745 | formatTimeMs(sb, (time + 500) / 1000); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 4746 | pw.println(sb.toString()); |
| 4747 | uidActivity = true; |
| 4748 | } |
| 4749 | } |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 4750 | if (totalStateTime > 0) { |
| 4751 | sb.setLength(0); |
| 4752 | sb.append(prefix); |
| 4753 | sb.append(" Total running: "); |
| 4754 | formatTimeMs(sb, (totalStateTime + 500) / 1000); |
| 4755 | pw.println(sb.toString()); |
| 4756 | } |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 4757 | |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 4758 | final long userCpuTimeUs = u.getUserCpuTimeUs(which); |
| 4759 | final long systemCpuTimeUs = u.getSystemCpuTimeUs(which); |
Adam Lesinski | a7a4ccc | 2015-06-26 17:43:04 -0700 | [diff] [blame] | 4760 | final long powerCpuMaUs = u.getCpuPowerMaUs(which); |
| 4761 | if (userCpuTimeUs > 0 || systemCpuTimeUs > 0 || powerCpuMaUs > 0) { |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 4762 | sb.setLength(0); |
| 4763 | sb.append(prefix); |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 4764 | sb.append(" Total cpu time: u="); |
| 4765 | formatTimeMs(sb, userCpuTimeUs / 1000); |
| 4766 | sb.append("s="); |
| 4767 | formatTimeMs(sb, systemCpuTimeUs / 1000); |
Adam Lesinski | a7a4ccc | 2015-06-26 17:43:04 -0700 | [diff] [blame] | 4768 | sb.append("p="); |
| 4769 | printmAh(sb, powerCpuMaUs / (1000.0 * 1000.0 * 60.0 * 60.0)); |
| 4770 | sb.append("mAh"); |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 4771 | pw.println(sb.toString()); |
| 4772 | } |
| 4773 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4774 | final ArrayMap<String, ? extends BatteryStats.Uid.Proc> processStats |
| 4775 | = u.getProcessStats(); |
| 4776 | for (int ipr=processStats.size()-1; ipr>=0; ipr--) { |
| 4777 | final Uid.Proc ps = processStats.valueAt(ipr); |
| 4778 | long userTime; |
| 4779 | long systemTime; |
| 4780 | long foregroundTime; |
| 4781 | int starts; |
| 4782 | int numExcessive; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4783 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4784 | userTime = ps.getUserTime(which); |
| 4785 | systemTime = ps.getSystemTime(which); |
| 4786 | foregroundTime = ps.getForegroundTime(which); |
| 4787 | starts = ps.getStarts(which); |
| 4788 | final int numCrashes = ps.getNumCrashes(which); |
| 4789 | final int numAnrs = ps.getNumAnrs(which); |
| 4790 | numExcessive = which == STATS_SINCE_CHARGED |
| 4791 | ? ps.countExcessivePowers() : 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4792 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4793 | if (userTime != 0 || systemTime != 0 || foregroundTime != 0 || starts != 0 |
| 4794 | || numExcessive != 0 || numCrashes != 0 || numAnrs != 0) { |
| 4795 | sb.setLength(0); |
| 4796 | sb.append(prefix); sb.append(" Proc "); |
| 4797 | sb.append(processStats.keyAt(ipr)); sb.append(":\n"); |
| 4798 | sb.append(prefix); sb.append(" CPU: "); |
| 4799 | formatTimeMs(sb, userTime); sb.append("usr + "); |
| 4800 | formatTimeMs(sb, systemTime); sb.append("krn ; "); |
| 4801 | formatTimeMs(sb, foregroundTime); sb.append("fg"); |
| 4802 | if (starts != 0 || numCrashes != 0 || numAnrs != 0) { |
| 4803 | sb.append("\n"); sb.append(prefix); sb.append(" "); |
| 4804 | boolean hasOne = false; |
| 4805 | if (starts != 0) { |
| 4806 | hasOne = true; |
| 4807 | sb.append(starts); sb.append(" starts"); |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 4808 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4809 | if (numCrashes != 0) { |
| 4810 | if (hasOne) { |
| 4811 | sb.append(", "); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4812 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4813 | hasOne = true; |
| 4814 | sb.append(numCrashes); sb.append(" crashes"); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4815 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4816 | if (numAnrs != 0) { |
| 4817 | if (hasOne) { |
| 4818 | sb.append(", "); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4819 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4820 | sb.append(numAnrs); sb.append(" anrs"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4821 | } |
| 4822 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4823 | pw.println(sb.toString()); |
| 4824 | for (int e=0; e<numExcessive; e++) { |
| 4825 | Uid.Proc.ExcessivePower ew = ps.getExcessivePower(e); |
| 4826 | if (ew != null) { |
| 4827 | pw.print(prefix); pw.print(" * Killed for "); |
| 4828 | if (ew.type == Uid.Proc.ExcessivePower.TYPE_WAKE) { |
| 4829 | pw.print("wake lock"); |
| 4830 | } else if (ew.type == Uid.Proc.ExcessivePower.TYPE_CPU) { |
| 4831 | pw.print("cpu"); |
| 4832 | } else { |
| 4833 | pw.print("unknown"); |
| 4834 | } |
| 4835 | pw.print(" use: "); |
| 4836 | TimeUtils.formatDuration(ew.usedTime, pw); |
| 4837 | pw.print(" over "); |
| 4838 | TimeUtils.formatDuration(ew.overTime, pw); |
| 4839 | if (ew.overTime != 0) { |
| 4840 | pw.print(" ("); |
| 4841 | pw.print((ew.usedTime*100)/ew.overTime); |
| 4842 | pw.println("%)"); |
| 4843 | } |
| 4844 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4845 | } |
| 4846 | uidActivity = true; |
| 4847 | } |
| 4848 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4849 | |
| 4850 | final ArrayMap<String, ? extends BatteryStats.Uid.Pkg> packageStats |
| 4851 | = u.getPackageStats(); |
| 4852 | for (int ipkg=packageStats.size()-1; ipkg>=0; ipkg--) { |
| 4853 | pw.print(prefix); pw.print(" Apk "); pw.print(packageStats.keyAt(ipkg)); |
| 4854 | pw.println(":"); |
| 4855 | boolean apkActivity = false; |
| 4856 | final Uid.Pkg ps = packageStats.valueAt(ipkg); |
| 4857 | final ArrayMap<String, ? extends Counter> alarms = ps.getWakeupAlarmStats(); |
| 4858 | for (int iwa=alarms.size()-1; iwa>=0; iwa--) { |
| 4859 | pw.print(prefix); pw.print(" Wakeup alarm "); |
| 4860 | pw.print(alarms.keyAt(iwa)); pw.print(": "); |
| 4861 | pw.print(alarms.valueAt(iwa).getCountLocked(which)); |
| 4862 | pw.println(" times"); |
| 4863 | apkActivity = true; |
| 4864 | } |
| 4865 | final ArrayMap<String, ? extends Uid.Pkg.Serv> serviceStats = ps.getServiceStats(); |
| 4866 | for (int isvc=serviceStats.size()-1; isvc>=0; isvc--) { |
| 4867 | final BatteryStats.Uid.Pkg.Serv ss = serviceStats.valueAt(isvc); |
| 4868 | final long startTime = ss.getStartTime(batteryUptime, which); |
| 4869 | final int starts = ss.getStarts(which); |
| 4870 | final int launches = ss.getLaunches(which); |
| 4871 | if (startTime != 0 || starts != 0 || launches != 0) { |
| 4872 | sb.setLength(0); |
| 4873 | sb.append(prefix); sb.append(" Service "); |
| 4874 | sb.append(serviceStats.keyAt(isvc)); sb.append(":\n"); |
| 4875 | sb.append(prefix); sb.append(" Created for: "); |
| 4876 | formatTimeMs(sb, startTime / 1000); |
| 4877 | sb.append("uptime\n"); |
| 4878 | sb.append(prefix); sb.append(" Starts: "); |
| 4879 | sb.append(starts); |
| 4880 | sb.append(", launches: "); sb.append(launches); |
| 4881 | pw.println(sb.toString()); |
| 4882 | apkActivity = true; |
| 4883 | } |
| 4884 | } |
| 4885 | if (!apkActivity) { |
| 4886 | pw.print(prefix); pw.println(" (nothing executed)"); |
| 4887 | } |
| 4888 | uidActivity = true; |
| 4889 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4890 | if (!uidActivity) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4891 | pw.print(prefix); pw.println(" (nothing executed)"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4892 | } |
| 4893 | } |
| 4894 | } |
| 4895 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 4896 | static void printBitDescriptions(PrintWriter pw, int oldval, int newval, HistoryTag wakelockTag, |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4897 | BitDescription[] descriptions, boolean longNames) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4898 | int diff = oldval ^ newval; |
| 4899 | if (diff == 0) return; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 4900 | boolean didWake = false; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4901 | for (int i=0; i<descriptions.length; i++) { |
| 4902 | BitDescription bd = descriptions[i]; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 4903 | if ((diff&bd.mask) != 0) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4904 | pw.print(longNames ? " " : ","); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4905 | if (bd.shift < 0) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 4906 | pw.print((newval&bd.mask) != 0 ? "+" : "-"); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4907 | pw.print(longNames ? bd.name : bd.shortName); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 4908 | if (bd.mask == HistoryItem.STATE_WAKE_LOCK_FLAG && wakelockTag != null) { |
| 4909 | didWake = true; |
| 4910 | pw.print("="); |
| 4911 | if (longNames) { |
| 4912 | UserHandle.formatUid(pw, wakelockTag.uid); |
| 4913 | pw.print(":\""); |
| 4914 | pw.print(wakelockTag.string); |
| 4915 | pw.print("\""); |
| 4916 | } else { |
| 4917 | pw.print(wakelockTag.poolIdx); |
| 4918 | } |
| 4919 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4920 | } else { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4921 | pw.print(longNames ? bd.name : bd.shortName); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4922 | pw.print("="); |
| 4923 | int val = (newval&bd.mask)>>bd.shift; |
| 4924 | if (bd.values != null && val >= 0 && val < bd.values.length) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4925 | pw.print(longNames? bd.values[val] : bd.shortValues[val]); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4926 | } else { |
| 4927 | pw.print(val); |
| 4928 | } |
| 4929 | } |
| 4930 | } |
| 4931 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 4932 | if (!didWake && wakelockTag != null) { |
Ashish Sharma | 81850c4 | 2014-05-05 13:57:07 -0700 | [diff] [blame] | 4933 | pw.print(longNames ? " wake_lock=" : ",w="); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 4934 | if (longNames) { |
| 4935 | UserHandle.formatUid(pw, wakelockTag.uid); |
| 4936 | pw.print(":\""); |
| 4937 | pw.print(wakelockTag.string); |
| 4938 | pw.print("\""); |
| 4939 | } else { |
| 4940 | pw.print(wakelockTag.poolIdx); |
| 4941 | } |
| 4942 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4943 | } |
| 4944 | |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 4945 | public void prepareForDumpLocked() { |
| 4946 | } |
| 4947 | |
| 4948 | public static class HistoryPrinter { |
| 4949 | int oldState = 0; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 4950 | int oldState2 = 0; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4951 | int oldLevel = -1; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 4952 | int oldStatus = -1; |
| 4953 | int oldHealth = -1; |
| 4954 | int oldPlug = -1; |
| 4955 | int oldTemp = -1; |
| 4956 | int oldVolt = -1; |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 4957 | int oldChargeMAh = -1; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4958 | long lastTime = -1; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 4959 | |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 4960 | void reset() { |
| 4961 | oldState = oldState2 = 0; |
| 4962 | oldLevel = -1; |
| 4963 | oldStatus = -1; |
| 4964 | oldHealth = -1; |
| 4965 | oldPlug = -1; |
| 4966 | oldTemp = -1; |
| 4967 | oldVolt = -1; |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 4968 | oldChargeMAh = -1; |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 4969 | } |
| 4970 | |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 4971 | public void printNextItem(PrintWriter pw, HistoryItem rec, long baseTime, boolean checkin, |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 4972 | boolean verbose) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4973 | if (!checkin) { |
| 4974 | pw.print(" "); |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 4975 | TimeUtils.formatDuration(rec.time - baseTime, pw, TimeUtils.HUNDRED_DAY_FIELD_LEN); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 4976 | pw.print(" ("); |
| 4977 | pw.print(rec.numReadInts); |
| 4978 | pw.print(") "); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4979 | } else { |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 4980 | pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(','); |
| 4981 | pw.print(HISTORY_DATA); pw.print(','); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4982 | if (lastTime < 0) { |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 4983 | pw.print(rec.time - baseTime); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4984 | } else { |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 4985 | pw.print(rec.time - lastTime); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4986 | } |
| 4987 | lastTime = rec.time; |
| 4988 | } |
| 4989 | if (rec.cmd == HistoryItem.CMD_START) { |
| 4990 | if (checkin) { |
| 4991 | pw.print(":"); |
| 4992 | } |
| 4993 | pw.println("START"); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 4994 | reset(); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 4995 | } else if (rec.cmd == HistoryItem.CMD_CURRENT_TIME |
| 4996 | || rec.cmd == HistoryItem.CMD_RESET) { |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 4997 | if (checkin) { |
| 4998 | pw.print(":"); |
| 4999 | } |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 5000 | if (rec.cmd == HistoryItem.CMD_RESET) { |
| 5001 | pw.print("RESET:"); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 5002 | reset(); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 5003 | } |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 5004 | pw.print("TIME:"); |
| 5005 | if (checkin) { |
| 5006 | pw.println(rec.currentTime); |
| 5007 | } else { |
| 5008 | pw.print(" "); |
| 5009 | pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss", |
| 5010 | rec.currentTime).toString()); |
| 5011 | } |
Dianne Hackborn | 29cd7f1 | 2015-01-08 10:37:05 -0800 | [diff] [blame] | 5012 | } else if (rec.cmd == HistoryItem.CMD_SHUTDOWN) { |
| 5013 | if (checkin) { |
| 5014 | pw.print(":"); |
| 5015 | } |
| 5016 | pw.println("SHUTDOWN"); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5017 | } else if (rec.cmd == HistoryItem.CMD_OVERFLOW) { |
| 5018 | if (checkin) { |
| 5019 | pw.print(":"); |
| 5020 | } |
| 5021 | pw.println("*OVERFLOW*"); |
| 5022 | } else { |
| 5023 | if (!checkin) { |
| 5024 | if (rec.batteryLevel < 10) pw.print("00"); |
| 5025 | else if (rec.batteryLevel < 100) pw.print("0"); |
| 5026 | pw.print(rec.batteryLevel); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 5027 | if (verbose) { |
| 5028 | pw.print(" "); |
| 5029 | if (rec.states < 0) ; |
| 5030 | else if (rec.states < 0x10) pw.print("0000000"); |
| 5031 | else if (rec.states < 0x100) pw.print("000000"); |
| 5032 | else if (rec.states < 0x1000) pw.print("00000"); |
| 5033 | else if (rec.states < 0x10000) pw.print("0000"); |
| 5034 | else if (rec.states < 0x100000) pw.print("000"); |
| 5035 | else if (rec.states < 0x1000000) pw.print("00"); |
| 5036 | else if (rec.states < 0x10000000) pw.print("0"); |
| 5037 | pw.print(Integer.toHexString(rec.states)); |
| 5038 | } |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5039 | } else { |
| 5040 | if (oldLevel != rec.batteryLevel) { |
| 5041 | oldLevel = rec.batteryLevel; |
| 5042 | pw.print(",Bl="); pw.print(rec.batteryLevel); |
| 5043 | } |
| 5044 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5045 | if (oldStatus != rec.batteryStatus) { |
| 5046 | oldStatus = rec.batteryStatus; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5047 | pw.print(checkin ? ",Bs=" : " status="); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5048 | switch (oldStatus) { |
| 5049 | case BatteryManager.BATTERY_STATUS_UNKNOWN: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5050 | pw.print(checkin ? "?" : "unknown"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5051 | break; |
| 5052 | case BatteryManager.BATTERY_STATUS_CHARGING: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5053 | pw.print(checkin ? "c" : "charging"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5054 | break; |
| 5055 | case BatteryManager.BATTERY_STATUS_DISCHARGING: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5056 | pw.print(checkin ? "d" : "discharging"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5057 | break; |
| 5058 | case BatteryManager.BATTERY_STATUS_NOT_CHARGING: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5059 | pw.print(checkin ? "n" : "not-charging"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5060 | break; |
| 5061 | case BatteryManager.BATTERY_STATUS_FULL: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5062 | pw.print(checkin ? "f" : "full"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5063 | break; |
| 5064 | default: |
| 5065 | pw.print(oldStatus); |
| 5066 | break; |
| 5067 | } |
| 5068 | } |
| 5069 | if (oldHealth != rec.batteryHealth) { |
| 5070 | oldHealth = rec.batteryHealth; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5071 | pw.print(checkin ? ",Bh=" : " health="); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5072 | switch (oldHealth) { |
| 5073 | case BatteryManager.BATTERY_HEALTH_UNKNOWN: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5074 | pw.print(checkin ? "?" : "unknown"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5075 | break; |
| 5076 | case BatteryManager.BATTERY_HEALTH_GOOD: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5077 | pw.print(checkin ? "g" : "good"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5078 | break; |
| 5079 | case BatteryManager.BATTERY_HEALTH_OVERHEAT: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5080 | pw.print(checkin ? "h" : "overheat"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5081 | break; |
| 5082 | case BatteryManager.BATTERY_HEALTH_DEAD: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5083 | pw.print(checkin ? "d" : "dead"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5084 | break; |
| 5085 | case BatteryManager.BATTERY_HEALTH_OVER_VOLTAGE: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5086 | pw.print(checkin ? "v" : "over-voltage"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5087 | break; |
| 5088 | case BatteryManager.BATTERY_HEALTH_UNSPECIFIED_FAILURE: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5089 | pw.print(checkin ? "f" : "failure"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5090 | break; |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 5091 | case BatteryManager.BATTERY_HEALTH_COLD: |
| 5092 | pw.print(checkin ? "c" : "cold"); |
| 5093 | break; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5094 | default: |
| 5095 | pw.print(oldHealth); |
| 5096 | break; |
| 5097 | } |
| 5098 | } |
| 5099 | if (oldPlug != rec.batteryPlugType) { |
| 5100 | oldPlug = rec.batteryPlugType; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5101 | pw.print(checkin ? ",Bp=" : " plug="); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5102 | switch (oldPlug) { |
| 5103 | case 0: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5104 | pw.print(checkin ? "n" : "none"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5105 | break; |
| 5106 | case BatteryManager.BATTERY_PLUGGED_AC: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5107 | pw.print(checkin ? "a" : "ac"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5108 | break; |
| 5109 | case BatteryManager.BATTERY_PLUGGED_USB: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5110 | pw.print(checkin ? "u" : "usb"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5111 | break; |
Brian Muramatsu | 37a37f4 | 2012-08-14 15:21:02 -0700 | [diff] [blame] | 5112 | case BatteryManager.BATTERY_PLUGGED_WIRELESS: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5113 | pw.print(checkin ? "w" : "wireless"); |
Brian Muramatsu | 37a37f4 | 2012-08-14 15:21:02 -0700 | [diff] [blame] | 5114 | break; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5115 | default: |
| 5116 | pw.print(oldPlug); |
| 5117 | break; |
| 5118 | } |
| 5119 | } |
| 5120 | if (oldTemp != rec.batteryTemperature) { |
| 5121 | oldTemp = rec.batteryTemperature; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5122 | pw.print(checkin ? ",Bt=" : " temp="); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5123 | pw.print(oldTemp); |
| 5124 | } |
| 5125 | if (oldVolt != rec.batteryVoltage) { |
| 5126 | oldVolt = rec.batteryVoltage; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5127 | pw.print(checkin ? ",Bv=" : " volt="); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5128 | pw.print(oldVolt); |
| 5129 | } |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 5130 | final int chargeMAh = rec.batteryChargeUAh / 1000; |
| 5131 | if (oldChargeMAh != chargeMAh) { |
| 5132 | oldChargeMAh = chargeMAh; |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 5133 | pw.print(checkin ? ",Bcc=" : " charge="); |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 5134 | pw.print(oldChargeMAh); |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 5135 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 5136 | printBitDescriptions(pw, oldState, rec.states, rec.wakelockTag, |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5137 | HISTORY_STATE_DESCRIPTIONS, !checkin); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 5138 | printBitDescriptions(pw, oldState2, rec.states2, null, |
| 5139 | HISTORY_STATE2_DESCRIPTIONS, !checkin); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 5140 | if (rec.wakeReasonTag != null) { |
| 5141 | if (checkin) { |
Dianne Hackborn | d06dcfd | 2014-05-02 13:49:30 -0700 | [diff] [blame] | 5142 | pw.print(",wr="); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 5143 | pw.print(rec.wakeReasonTag.poolIdx); |
| 5144 | } else { |
| 5145 | pw.print(" wake_reason="); |
| 5146 | pw.print(rec.wakeReasonTag.uid); |
| 5147 | pw.print(":\""); |
| 5148 | pw.print(rec.wakeReasonTag.string); |
| 5149 | pw.print("\""); |
| 5150 | } |
| 5151 | } |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 5152 | if (rec.eventCode != HistoryItem.EVENT_NONE) { |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 5153 | pw.print(checkin ? "," : " "); |
| 5154 | if ((rec.eventCode&HistoryItem.EVENT_FLAG_START) != 0) { |
| 5155 | pw.print("+"); |
| 5156 | } else if ((rec.eventCode&HistoryItem.EVENT_FLAG_FINISH) != 0) { |
| 5157 | pw.print("-"); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 5158 | } |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 5159 | String[] eventNames = checkin ? HISTORY_EVENT_CHECKIN_NAMES |
| 5160 | : HISTORY_EVENT_NAMES; |
| 5161 | int idx = rec.eventCode & ~(HistoryItem.EVENT_FLAG_START |
| 5162 | | HistoryItem.EVENT_FLAG_FINISH); |
| 5163 | if (idx >= 0 && idx < eventNames.length) { |
| 5164 | pw.print(eventNames[idx]); |
| 5165 | } else { |
| 5166 | pw.print(checkin ? "Ev" : "event"); |
| 5167 | pw.print(idx); |
| 5168 | } |
| 5169 | pw.print("="); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 5170 | if (checkin) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 5171 | pw.print(rec.eventTag.poolIdx); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 5172 | } else { |
Adam Lesinski | 041d917 | 2016-12-12 12:03:56 -0800 | [diff] [blame] | 5173 | pw.append(HISTORY_EVENT_INT_FORMATTERS[idx] |
| 5174 | .applyAsString(rec.eventTag.uid)); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 5175 | pw.print(":\""); |
| 5176 | pw.print(rec.eventTag.string); |
| 5177 | pw.print("\""); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 5178 | } |
| 5179 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5180 | pw.println(); |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 5181 | if (rec.stepDetails != null) { |
| 5182 | if (!checkin) { |
| 5183 | pw.print(" Details: cpu="); |
| 5184 | pw.print(rec.stepDetails.userTime); |
| 5185 | pw.print("u+"); |
| 5186 | pw.print(rec.stepDetails.systemTime); |
| 5187 | pw.print("s"); |
| 5188 | if (rec.stepDetails.appCpuUid1 >= 0) { |
| 5189 | pw.print(" ("); |
| 5190 | printStepCpuUidDetails(pw, rec.stepDetails.appCpuUid1, |
| 5191 | rec.stepDetails.appCpuUTime1, rec.stepDetails.appCpuSTime1); |
| 5192 | if (rec.stepDetails.appCpuUid2 >= 0) { |
| 5193 | pw.print(", "); |
| 5194 | printStepCpuUidDetails(pw, rec.stepDetails.appCpuUid2, |
| 5195 | rec.stepDetails.appCpuUTime2, rec.stepDetails.appCpuSTime2); |
| 5196 | } |
| 5197 | if (rec.stepDetails.appCpuUid3 >= 0) { |
| 5198 | pw.print(", "); |
| 5199 | printStepCpuUidDetails(pw, rec.stepDetails.appCpuUid3, |
| 5200 | rec.stepDetails.appCpuUTime3, rec.stepDetails.appCpuSTime3); |
| 5201 | } |
| 5202 | pw.print(')'); |
| 5203 | } |
| 5204 | pw.println(); |
| 5205 | pw.print(" /proc/stat="); |
| 5206 | pw.print(rec.stepDetails.statUserTime); |
| 5207 | pw.print(" usr, "); |
| 5208 | pw.print(rec.stepDetails.statSystemTime); |
| 5209 | pw.print(" sys, "); |
| 5210 | pw.print(rec.stepDetails.statIOWaitTime); |
| 5211 | pw.print(" io, "); |
| 5212 | pw.print(rec.stepDetails.statIrqTime); |
| 5213 | pw.print(" irq, "); |
| 5214 | pw.print(rec.stepDetails.statSoftIrqTime); |
| 5215 | pw.print(" sirq, "); |
| 5216 | pw.print(rec.stepDetails.statIdlTime); |
| 5217 | pw.print(" idle"); |
| 5218 | int totalRun = rec.stepDetails.statUserTime + rec.stepDetails.statSystemTime |
| 5219 | + rec.stepDetails.statIOWaitTime + rec.stepDetails.statIrqTime |
| 5220 | + rec.stepDetails.statSoftIrqTime; |
| 5221 | int total = totalRun + rec.stepDetails.statIdlTime; |
| 5222 | if (total > 0) { |
| 5223 | pw.print(" ("); |
| 5224 | float perc = ((float)totalRun) / ((float)total) * 100; |
| 5225 | pw.print(String.format("%.1f%%", perc)); |
| 5226 | pw.print(" of "); |
| 5227 | StringBuilder sb = new StringBuilder(64); |
| 5228 | formatTimeMsNoSpace(sb, total*10); |
| 5229 | pw.print(sb); |
| 5230 | pw.print(")"); |
| 5231 | } |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 5232 | pw.print(", PlatformIdleStat "); |
| 5233 | pw.print(rec.stepDetails.statPlatformIdleState); |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 5234 | pw.println(); |
| 5235 | } else { |
| 5236 | pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(','); |
| 5237 | pw.print(HISTORY_DATA); pw.print(",0,Dcpu="); |
| 5238 | pw.print(rec.stepDetails.userTime); |
| 5239 | pw.print(":"); |
| 5240 | pw.print(rec.stepDetails.systemTime); |
| 5241 | if (rec.stepDetails.appCpuUid1 >= 0) { |
| 5242 | printStepCpuUidCheckinDetails(pw, rec.stepDetails.appCpuUid1, |
| 5243 | rec.stepDetails.appCpuUTime1, rec.stepDetails.appCpuSTime1); |
| 5244 | if (rec.stepDetails.appCpuUid2 >= 0) { |
| 5245 | printStepCpuUidCheckinDetails(pw, rec.stepDetails.appCpuUid2, |
| 5246 | rec.stepDetails.appCpuUTime2, rec.stepDetails.appCpuSTime2); |
| 5247 | } |
| 5248 | if (rec.stepDetails.appCpuUid3 >= 0) { |
| 5249 | printStepCpuUidCheckinDetails(pw, rec.stepDetails.appCpuUid3, |
| 5250 | rec.stepDetails.appCpuUTime3, rec.stepDetails.appCpuSTime3); |
| 5251 | } |
| 5252 | } |
| 5253 | pw.println(); |
| 5254 | pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(','); |
| 5255 | pw.print(HISTORY_DATA); pw.print(",0,Dpst="); |
| 5256 | pw.print(rec.stepDetails.statUserTime); |
| 5257 | pw.print(','); |
| 5258 | pw.print(rec.stepDetails.statSystemTime); |
| 5259 | pw.print(','); |
| 5260 | pw.print(rec.stepDetails.statIOWaitTime); |
| 5261 | pw.print(','); |
| 5262 | pw.print(rec.stepDetails.statIrqTime); |
| 5263 | pw.print(','); |
| 5264 | pw.print(rec.stepDetails.statSoftIrqTime); |
| 5265 | pw.print(','); |
| 5266 | pw.print(rec.stepDetails.statIdlTime); |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 5267 | pw.print(','); |
Adam Lesinski | 8568d8f | 2016-07-15 18:13:23 -0700 | [diff] [blame] | 5268 | if (rec.stepDetails.statPlatformIdleState != null) { |
| 5269 | pw.print(rec.stepDetails.statPlatformIdleState); |
| 5270 | } |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 5271 | pw.println(); |
| 5272 | } |
| 5273 | } |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 5274 | oldState = rec.states; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 5275 | oldState2 = rec.states2; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5276 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5277 | } |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 5278 | |
| 5279 | private void printStepCpuUidDetails(PrintWriter pw, int uid, int utime, int stime) { |
| 5280 | UserHandle.formatUid(pw, uid); |
| 5281 | pw.print("="); |
| 5282 | pw.print(utime); |
| 5283 | pw.print("u+"); |
| 5284 | pw.print(stime); |
| 5285 | pw.print("s"); |
| 5286 | } |
| 5287 | |
| 5288 | private void printStepCpuUidCheckinDetails(PrintWriter pw, int uid, int utime, int stime) { |
| 5289 | pw.print('/'); |
| 5290 | pw.print(uid); |
| 5291 | pw.print(":"); |
| 5292 | pw.print(utime); |
| 5293 | pw.print(":"); |
| 5294 | pw.print(stime); |
| 5295 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5296 | } |
| 5297 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 5298 | private void printSizeValue(PrintWriter pw, long size) { |
| 5299 | float result = size; |
| 5300 | String suffix = ""; |
| 5301 | if (result >= 10*1024) { |
| 5302 | suffix = "KB"; |
| 5303 | result = result / 1024; |
| 5304 | } |
| 5305 | if (result >= 10*1024) { |
| 5306 | suffix = "MB"; |
| 5307 | result = result / 1024; |
| 5308 | } |
| 5309 | if (result >= 10*1024) { |
| 5310 | suffix = "GB"; |
| 5311 | result = result / 1024; |
| 5312 | } |
| 5313 | if (result >= 10*1024) { |
| 5314 | suffix = "TB"; |
| 5315 | result = result / 1024; |
| 5316 | } |
| 5317 | if (result >= 10*1024) { |
| 5318 | suffix = "PB"; |
| 5319 | result = result / 1024; |
| 5320 | } |
| 5321 | pw.print((int)result); |
| 5322 | pw.print(suffix); |
| 5323 | } |
| 5324 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 5325 | private static boolean dumpTimeEstimate(PrintWriter pw, String label1, String label2, |
| 5326 | String label3, long estimatedTime) { |
| 5327 | if (estimatedTime < 0) { |
Dianne Hackborn | ad6a99b | 2014-11-18 10:11:10 -0800 | [diff] [blame] | 5328 | return false; |
| 5329 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 5330 | pw.print(label1); |
| 5331 | pw.print(label2); |
| 5332 | pw.print(label3); |
Dianne Hackborn | ad6a99b | 2014-11-18 10:11:10 -0800 | [diff] [blame] | 5333 | StringBuilder sb = new StringBuilder(64); |
| 5334 | formatTimeMs(sb, estimatedTime); |
| 5335 | pw.print(sb); |
| 5336 | pw.println(); |
Dianne Hackborn | ad6a99b | 2014-11-18 10:11:10 -0800 | [diff] [blame] | 5337 | return true; |
| 5338 | } |
| 5339 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 5340 | private static boolean dumpDurationSteps(PrintWriter pw, String prefix, String header, |
| 5341 | LevelStepTracker steps, boolean checkin) { |
| 5342 | if (steps == null) { |
| 5343 | return false; |
| 5344 | } |
| 5345 | int count = steps.mNumStepDurations; |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 5346 | if (count <= 0) { |
| 5347 | return false; |
| 5348 | } |
| 5349 | if (!checkin) { |
| 5350 | pw.println(header); |
| 5351 | } |
Kweku Adams | 030980a | 2015-04-01 16:07:48 -0700 | [diff] [blame] | 5352 | String[] lineArgs = new String[5]; |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 5353 | for (int i=0; i<count; i++) { |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 5354 | long duration = steps.getDurationAt(i); |
| 5355 | int level = steps.getLevelAt(i); |
| 5356 | long initMode = steps.getInitModeAt(i); |
| 5357 | long modMode = steps.getModModeAt(i); |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 5358 | if (checkin) { |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 5359 | lineArgs[0] = Long.toString(duration); |
| 5360 | lineArgs[1] = Integer.toString(level); |
| 5361 | if ((modMode&STEP_LEVEL_MODE_SCREEN_STATE) == 0) { |
| 5362 | switch ((int)(initMode&STEP_LEVEL_MODE_SCREEN_STATE) + 1) { |
| 5363 | case Display.STATE_OFF: lineArgs[2] = "s-"; break; |
| 5364 | case Display.STATE_ON: lineArgs[2] = "s+"; break; |
| 5365 | case Display.STATE_DOZE: lineArgs[2] = "sd"; break; |
| 5366 | case Display.STATE_DOZE_SUSPEND: lineArgs[2] = "sds"; break; |
Kweku Adams | 030980a | 2015-04-01 16:07:48 -0700 | [diff] [blame] | 5367 | default: lineArgs[2] = "?"; break; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 5368 | } |
| 5369 | } else { |
| 5370 | lineArgs[2] = ""; |
| 5371 | } |
| 5372 | if ((modMode&STEP_LEVEL_MODE_POWER_SAVE) == 0) { |
| 5373 | lineArgs[3] = (initMode&STEP_LEVEL_MODE_POWER_SAVE) != 0 ? "p+" : "p-"; |
| 5374 | } else { |
| 5375 | lineArgs[3] = ""; |
| 5376 | } |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 5377 | if ((modMode&STEP_LEVEL_MODE_DEVICE_IDLE) == 0) { |
Kweku Adams | 030980a | 2015-04-01 16:07:48 -0700 | [diff] [blame] | 5378 | lineArgs[4] = (initMode&STEP_LEVEL_MODE_DEVICE_IDLE) != 0 ? "i+" : "i-"; |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 5379 | } else { |
Kweku Adams | 030980a | 2015-04-01 16:07:48 -0700 | [diff] [blame] | 5380 | lineArgs[4] = ""; |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 5381 | } |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 5382 | dumpLine(pw, 0 /* uid */, "i" /* category */, header, (Object[])lineArgs); |
| 5383 | } else { |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 5384 | pw.print(prefix); |
| 5385 | pw.print("#"); pw.print(i); pw.print(": "); |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 5386 | TimeUtils.formatDuration(duration, pw); |
| 5387 | pw.print(" to "); pw.print(level); |
| 5388 | boolean haveModes = false; |
| 5389 | if ((modMode&STEP_LEVEL_MODE_SCREEN_STATE) == 0) { |
| 5390 | pw.print(" ("); |
| 5391 | switch ((int)(initMode&STEP_LEVEL_MODE_SCREEN_STATE) + 1) { |
| 5392 | case Display.STATE_OFF: pw.print("screen-off"); break; |
| 5393 | case Display.STATE_ON: pw.print("screen-on"); break; |
| 5394 | case Display.STATE_DOZE: pw.print("screen-doze"); break; |
| 5395 | case Display.STATE_DOZE_SUSPEND: pw.print("screen-doze-suspend"); break; |
Kweku Adams | 030980a | 2015-04-01 16:07:48 -0700 | [diff] [blame] | 5396 | default: pw.print("screen-?"); break; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 5397 | } |
| 5398 | haveModes = true; |
| 5399 | } |
| 5400 | if ((modMode&STEP_LEVEL_MODE_POWER_SAVE) == 0) { |
| 5401 | pw.print(haveModes ? ", " : " ("); |
| 5402 | pw.print((initMode&STEP_LEVEL_MODE_POWER_SAVE) != 0 |
| 5403 | ? "power-save-on" : "power-save-off"); |
| 5404 | haveModes = true; |
| 5405 | } |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 5406 | if ((modMode&STEP_LEVEL_MODE_DEVICE_IDLE) == 0) { |
| 5407 | pw.print(haveModes ? ", " : " ("); |
| 5408 | pw.print((initMode&STEP_LEVEL_MODE_DEVICE_IDLE) != 0 |
| 5409 | ? "device-idle-on" : "device-idle-off"); |
| 5410 | haveModes = true; |
| 5411 | } |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 5412 | if (haveModes) { |
| 5413 | pw.print(")"); |
| 5414 | } |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 5415 | pw.println(); |
| 5416 | } |
| 5417 | } |
| 5418 | return true; |
| 5419 | } |
| 5420 | |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 5421 | public static final int DUMP_CHARGED_ONLY = 1<<1; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 5422 | public static final int DUMP_DAILY_ONLY = 1<<2; |
| 5423 | public static final int DUMP_HISTORY_ONLY = 1<<3; |
| 5424 | public static final int DUMP_INCLUDE_HISTORY = 1<<4; |
| 5425 | public static final int DUMP_VERBOSE = 1<<5; |
| 5426 | public static final int DUMP_DEVICE_WIFI_ONLY = 1<<6; |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 5427 | |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 5428 | private void dumpHistoryLocked(PrintWriter pw, int flags, long histStart, boolean checkin) { |
| 5429 | final HistoryPrinter hprinter = new HistoryPrinter(); |
| 5430 | final HistoryItem rec = new HistoryItem(); |
| 5431 | long lastTime = -1; |
| 5432 | long baseTime = -1; |
| 5433 | boolean printed = false; |
| 5434 | HistoryEventTracker tracker = null; |
| 5435 | while (getNextHistoryLocked(rec)) { |
| 5436 | lastTime = rec.time; |
| 5437 | if (baseTime < 0) { |
| 5438 | baseTime = lastTime; |
| 5439 | } |
| 5440 | if (rec.time >= histStart) { |
| 5441 | if (histStart >= 0 && !printed) { |
| 5442 | if (rec.cmd == HistoryItem.CMD_CURRENT_TIME |
Ashish Sharma | 6020071 | 2014-05-23 18:22:20 -0700 | [diff] [blame] | 5443 | || rec.cmd == HistoryItem.CMD_RESET |
Dianne Hackborn | 29cd7f1 | 2015-01-08 10:37:05 -0800 | [diff] [blame] | 5444 | || rec.cmd == HistoryItem.CMD_START |
| 5445 | || rec.cmd == HistoryItem.CMD_SHUTDOWN) { |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 5446 | printed = true; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 5447 | hprinter.printNextItem(pw, rec, baseTime, checkin, |
| 5448 | (flags&DUMP_VERBOSE) != 0); |
| 5449 | rec.cmd = HistoryItem.CMD_UPDATE; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 5450 | } else if (rec.currentTime != 0) { |
| 5451 | printed = true; |
| 5452 | byte cmd = rec.cmd; |
| 5453 | rec.cmd = HistoryItem.CMD_CURRENT_TIME; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 5454 | hprinter.printNextItem(pw, rec, baseTime, checkin, |
| 5455 | (flags&DUMP_VERBOSE) != 0); |
| 5456 | rec.cmd = cmd; |
| 5457 | } |
| 5458 | if (tracker != null) { |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 5459 | if (rec.cmd != HistoryItem.CMD_UPDATE) { |
| 5460 | hprinter.printNextItem(pw, rec, baseTime, checkin, |
| 5461 | (flags&DUMP_VERBOSE) != 0); |
| 5462 | rec.cmd = HistoryItem.CMD_UPDATE; |
| 5463 | } |
| 5464 | int oldEventCode = rec.eventCode; |
| 5465 | HistoryTag oldEventTag = rec.eventTag; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 5466 | rec.eventTag = new HistoryTag(); |
| 5467 | for (int i=0; i<HistoryItem.EVENT_COUNT; i++) { |
| 5468 | HashMap<String, SparseIntArray> active |
| 5469 | = tracker.getStateForEvent(i); |
| 5470 | if (active == null) { |
| 5471 | continue; |
| 5472 | } |
| 5473 | for (HashMap.Entry<String, SparseIntArray> ent |
| 5474 | : active.entrySet()) { |
| 5475 | SparseIntArray uids = ent.getValue(); |
| 5476 | for (int j=0; j<uids.size(); j++) { |
| 5477 | rec.eventCode = i; |
| 5478 | rec.eventTag.string = ent.getKey(); |
| 5479 | rec.eventTag.uid = uids.keyAt(j); |
| 5480 | rec.eventTag.poolIdx = uids.valueAt(j); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 5481 | hprinter.printNextItem(pw, rec, baseTime, checkin, |
| 5482 | (flags&DUMP_VERBOSE) != 0); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 5483 | rec.wakeReasonTag = null; |
| 5484 | rec.wakelockTag = null; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 5485 | } |
| 5486 | } |
| 5487 | } |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 5488 | rec.eventCode = oldEventCode; |
| 5489 | rec.eventTag = oldEventTag; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 5490 | tracker = null; |
| 5491 | } |
| 5492 | } |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 5493 | hprinter.printNextItem(pw, rec, baseTime, checkin, |
| 5494 | (flags&DUMP_VERBOSE) != 0); |
Dianne Hackborn | 536456f | 2014-05-23 16:51:05 -0700 | [diff] [blame] | 5495 | } else if (false && rec.eventCode != HistoryItem.EVENT_NONE) { |
| 5496 | // This is an attempt to aggregate the previous state and generate |
| 5497 | //Â fake events to reflect that state at the point where we start |
| 5498 | // 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] | 5499 | if (tracker == null) { |
| 5500 | tracker = new HistoryEventTracker(); |
| 5501 | } |
| 5502 | tracker.updateState(rec.eventCode, rec.eventTag.string, |
| 5503 | rec.eventTag.uid, rec.eventTag.poolIdx); |
| 5504 | } |
| 5505 | } |
| 5506 | if (histStart >= 0) { |
Dianne Hackborn | fc06413 | 2014-06-02 12:42:12 -0700 | [diff] [blame] | 5507 | commitCurrentHistoryBatchLocked(); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 5508 | pw.print(checkin ? "NEXT: " : " NEXT: "); pw.println(lastTime+1); |
| 5509 | } |
| 5510 | } |
| 5511 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 5512 | private void dumpDailyLevelStepSummary(PrintWriter pw, String prefix, String label, |
| 5513 | LevelStepTracker steps, StringBuilder tmpSb, int[] tmpOutInt) { |
| 5514 | if (steps == null) { |
| 5515 | return; |
| 5516 | } |
| 5517 | long timeRemaining = steps.computeTimeEstimate(0, 0, tmpOutInt); |
| 5518 | if (timeRemaining >= 0) { |
| 5519 | pw.print(prefix); pw.print(label); pw.print(" total time: "); |
| 5520 | tmpSb.setLength(0); |
| 5521 | formatTimeMs(tmpSb, timeRemaining); |
| 5522 | pw.print(tmpSb); |
| 5523 | pw.print(" (from "); pw.print(tmpOutInt[0]); |
| 5524 | pw.println(" steps)"); |
| 5525 | } |
| 5526 | for (int i=0; i< STEP_LEVEL_MODES_OF_INTEREST.length; i++) { |
| 5527 | long estimatedTime = steps.computeTimeEstimate(STEP_LEVEL_MODES_OF_INTEREST[i], |
| 5528 | STEP_LEVEL_MODE_VALUES[i], tmpOutInt); |
| 5529 | if (estimatedTime > 0) { |
| 5530 | pw.print(prefix); pw.print(label); pw.print(" "); |
| 5531 | pw.print(STEP_LEVEL_MODE_LABELS[i]); |
| 5532 | pw.print(" time: "); |
| 5533 | tmpSb.setLength(0); |
| 5534 | formatTimeMs(tmpSb, estimatedTime); |
| 5535 | pw.print(tmpSb); |
| 5536 | pw.print(" (from "); pw.print(tmpOutInt[0]); |
| 5537 | pw.println(" steps)"); |
| 5538 | } |
| 5539 | } |
| 5540 | } |
| 5541 | |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 5542 | private void dumpDailyPackageChanges(PrintWriter pw, String prefix, |
| 5543 | ArrayList<PackageChange> changes) { |
| 5544 | if (changes == null) { |
| 5545 | return; |
| 5546 | } |
| 5547 | pw.print(prefix); pw.println("Package changes:"); |
| 5548 | for (int i=0; i<changes.size(); i++) { |
| 5549 | PackageChange pc = changes.get(i); |
| 5550 | if (pc.mUpdate) { |
| 5551 | pw.print(prefix); pw.print(" Update "); pw.print(pc.mPackageName); |
| 5552 | pw.print(" vers="); pw.println(pc.mVersionCode); |
| 5553 | } else { |
| 5554 | pw.print(prefix); pw.print(" Uninstall "); pw.println(pc.mPackageName); |
| 5555 | } |
| 5556 | } |
| 5557 | } |
| 5558 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5559 | /** |
| 5560 | * Dumps a human-readable summary of the battery statistics to the given PrintWriter. |
| 5561 | * |
| 5562 | * @param pw a Printer to receive the dump output. |
| 5563 | */ |
| 5564 | @SuppressWarnings("unused") |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 5565 | 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] | 5566 | prepareForDumpLocked(); |
| 5567 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 5568 | final boolean filtering = (flags |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5569 | & (DUMP_HISTORY_ONLY|DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) != 0; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5570 | |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 5571 | if ((flags&DUMP_HISTORY_ONLY) != 0 || !filtering) { |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 5572 | final long historyTotalSize = getHistoryTotalSize(); |
| 5573 | final long historyUsedSize = getHistoryUsedSize(); |
| 5574 | if (startIteratingHistoryLocked()) { |
| 5575 | try { |
| 5576 | pw.print("Battery History ("); |
| 5577 | pw.print((100*historyUsedSize)/historyTotalSize); |
| 5578 | pw.print("% used, "); |
| 5579 | printSizeValue(pw, historyUsedSize); |
| 5580 | pw.print(" used of "); |
| 5581 | printSizeValue(pw, historyTotalSize); |
| 5582 | pw.print(", "); |
| 5583 | pw.print(getHistoryStringPoolSize()); |
| 5584 | pw.print(" strings using "); |
| 5585 | printSizeValue(pw, getHistoryStringPoolBytes()); |
| 5586 | pw.println("):"); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 5587 | dumpHistoryLocked(pw, flags, histStart, false); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 5588 | pw.println(); |
| 5589 | } finally { |
| 5590 | finishIteratingHistoryLocked(); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 5591 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 5592 | } |
| 5593 | |
| 5594 | if (startIteratingOldHistoryLocked()) { |
| 5595 | try { |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 5596 | final HistoryItem rec = new HistoryItem(); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 5597 | pw.println("Old battery History:"); |
| 5598 | HistoryPrinter hprinter = new HistoryPrinter(); |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 5599 | long baseTime = -1; |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 5600 | while (getNextOldHistoryLocked(rec)) { |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 5601 | if (baseTime < 0) { |
| 5602 | baseTime = rec.time; |
| 5603 | } |
| 5604 | hprinter.printNextItem(pw, rec, baseTime, false, (flags&DUMP_VERBOSE) != 0); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 5605 | } |
| 5606 | pw.println(); |
| 5607 | } finally { |
| 5608 | finishIteratingOldHistoryLocked(); |
| 5609 | } |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 5610 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5611 | } |
| 5612 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5613 | if (filtering && (flags&(DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) == 0) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 5614 | return; |
| 5615 | } |
| 5616 | |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 5617 | if (!filtering) { |
| 5618 | SparseArray<? extends Uid> uidStats = getUidStats(); |
| 5619 | final int NU = uidStats.size(); |
| 5620 | boolean didPid = false; |
| 5621 | long nowRealtime = SystemClock.elapsedRealtime(); |
| 5622 | for (int i=0; i<NU; i++) { |
| 5623 | Uid uid = uidStats.valueAt(i); |
| 5624 | SparseArray<? extends Uid.Pid> pids = uid.getPidStats(); |
| 5625 | if (pids != null) { |
| 5626 | for (int j=0; j<pids.size(); j++) { |
| 5627 | Uid.Pid pid = pids.valueAt(j); |
| 5628 | if (!didPid) { |
| 5629 | pw.println("Per-PID Stats:"); |
| 5630 | didPid = true; |
| 5631 | } |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 5632 | long time = pid.mWakeSumMs + (pid.mWakeNesting > 0 |
| 5633 | ? (nowRealtime - pid.mWakeStartMs) : 0); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 5634 | pw.print(" PID "); pw.print(pids.keyAt(j)); |
| 5635 | pw.print(" wake time: "); |
| 5636 | TimeUtils.formatDuration(time, pw); |
| 5637 | pw.println(""); |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 5638 | } |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 5639 | } |
| 5640 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 5641 | if (didPid) { |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 5642 | pw.println(); |
| 5643 | } |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 5644 | } |
| 5645 | |
| 5646 | if (!filtering || (flags&DUMP_CHARGED_ONLY) != 0) { |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 5647 | if (dumpDurationSteps(pw, " ", "Discharge step durations:", |
| 5648 | getDischargeLevelStepTracker(), false)) { |
Kweku Adams | b0449e0 | 2016-10-12 14:18:27 -0700 | [diff] [blame] | 5649 | long timeRemaining = computeBatteryTimeRemaining( |
| 5650 | SystemClock.elapsedRealtime() * 1000); |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 5651 | if (timeRemaining >= 0) { |
| 5652 | pw.print(" Estimated discharge time remaining: "); |
| 5653 | TimeUtils.formatDuration(timeRemaining / 1000, pw); |
| 5654 | pw.println(); |
| 5655 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 5656 | final LevelStepTracker steps = getDischargeLevelStepTracker(); |
| 5657 | for (int i=0; i< STEP_LEVEL_MODES_OF_INTEREST.length; i++) { |
| 5658 | dumpTimeEstimate(pw, " Estimated ", STEP_LEVEL_MODE_LABELS[i], " time: ", |
| 5659 | steps.computeTimeEstimate(STEP_LEVEL_MODES_OF_INTEREST[i], |
| 5660 | STEP_LEVEL_MODE_VALUES[i], null)); |
| 5661 | } |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 5662 | pw.println(); |
| 5663 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 5664 | if (dumpDurationSteps(pw, " ", "Charge step durations:", |
| 5665 | getChargeLevelStepTracker(), false)) { |
Kweku Adams | b0449e0 | 2016-10-12 14:18:27 -0700 | [diff] [blame] | 5666 | long timeRemaining = computeChargeTimeRemaining( |
| 5667 | SystemClock.elapsedRealtime() * 1000); |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 5668 | if (timeRemaining >= 0) { |
| 5669 | pw.print(" Estimated charge time remaining: "); |
| 5670 | TimeUtils.formatDuration(timeRemaining / 1000, pw); |
| 5671 | pw.println(); |
| 5672 | } |
| 5673 | pw.println(); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 5674 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 5675 | } |
| 5676 | if (!filtering || (flags&(DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) != 0) { |
| 5677 | pw.println("Daily stats:"); |
| 5678 | pw.print(" Current start time: "); |
| 5679 | pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss", |
| 5680 | getCurrentDailyStartTime()).toString()); |
| 5681 | pw.print(" Next min deadline: "); |
| 5682 | pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss", |
| 5683 | getNextMinDailyDeadline()).toString()); |
| 5684 | pw.print(" Next max deadline: "); |
| 5685 | pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss", |
| 5686 | getNextMaxDailyDeadline()).toString()); |
| 5687 | StringBuilder sb = new StringBuilder(64); |
| 5688 | int[] outInt = new int[1]; |
| 5689 | LevelStepTracker dsteps = getDailyDischargeLevelStepTracker(); |
| 5690 | LevelStepTracker csteps = getDailyChargeLevelStepTracker(); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 5691 | ArrayList<PackageChange> pkgc = getDailyPackageChanges(); |
| 5692 | if (dsteps.mNumStepDurations > 0 || csteps.mNumStepDurations > 0 || pkgc != null) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5693 | if ((flags&DUMP_DAILY_ONLY) != 0 || !filtering) { |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 5694 | if (dumpDurationSteps(pw, " ", " Current daily discharge step durations:", |
| 5695 | dsteps, false)) { |
| 5696 | dumpDailyLevelStepSummary(pw, " ", "Discharge", dsteps, |
| 5697 | sb, outInt); |
| 5698 | } |
| 5699 | if (dumpDurationSteps(pw, " ", " Current daily charge step durations:", |
| 5700 | csteps, false)) { |
| 5701 | dumpDailyLevelStepSummary(pw, " ", "Charge", csteps, |
| 5702 | sb, outInt); |
| 5703 | } |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 5704 | dumpDailyPackageChanges(pw, " ", pkgc); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 5705 | } else { |
| 5706 | pw.println(" Current daily steps:"); |
| 5707 | dumpDailyLevelStepSummary(pw, " ", "Discharge", dsteps, |
| 5708 | sb, outInt); |
| 5709 | dumpDailyLevelStepSummary(pw, " ", "Charge", csteps, |
| 5710 | sb, outInt); |
| 5711 | } |
| 5712 | } |
| 5713 | DailyItem dit; |
| 5714 | int curIndex = 0; |
| 5715 | while ((dit=getDailyItemLocked(curIndex)) != null) { |
| 5716 | curIndex++; |
| 5717 | if ((flags&DUMP_DAILY_ONLY) != 0) { |
| 5718 | pw.println(); |
| 5719 | } |
| 5720 | pw.print(" Daily from "); |
| 5721 | pw.print(DateFormat.format("yyyy-MM-dd-HH-mm-ss", dit.mStartTime).toString()); |
| 5722 | pw.print(" to "); |
| 5723 | pw.print(DateFormat.format("yyyy-MM-dd-HH-mm-ss", dit.mEndTime).toString()); |
| 5724 | pw.println(":"); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5725 | if ((flags&DUMP_DAILY_ONLY) != 0 || !filtering) { |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 5726 | if (dumpDurationSteps(pw, " ", |
| 5727 | " Discharge step durations:", dit.mDischargeSteps, false)) { |
| 5728 | dumpDailyLevelStepSummary(pw, " ", "Discharge", dit.mDischargeSteps, |
| 5729 | sb, outInt); |
| 5730 | } |
| 5731 | if (dumpDurationSteps(pw, " ", |
| 5732 | " Charge step durations:", dit.mChargeSteps, false)) { |
| 5733 | dumpDailyLevelStepSummary(pw, " ", "Charge", dit.mChargeSteps, |
| 5734 | sb, outInt); |
| 5735 | } |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 5736 | dumpDailyPackageChanges(pw, " ", dit.mPackageChanges); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 5737 | } else { |
| 5738 | dumpDailyLevelStepSummary(pw, " ", "Discharge", dit.mDischargeSteps, |
| 5739 | sb, outInt); |
| 5740 | dumpDailyLevelStepSummary(pw, " ", "Charge", dit.mChargeSteps, |
| 5741 | sb, outInt); |
| 5742 | } |
| 5743 | } |
| 5744 | pw.println(); |
| 5745 | } |
| 5746 | if (!filtering || (flags&DUMP_CHARGED_ONLY) != 0) { |
Jeff Sharkey | ec43a6b | 2013-04-30 13:33:18 -0700 | [diff] [blame] | 5747 | pw.println("Statistics since last charge:"); |
| 5748 | pw.println(" System starts: " + getStartCount() |
| 5749 | + ", currently on battery: " + getIsOnBattery()); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 5750 | dumpLocked(context, pw, "", STATS_SINCE_CHARGED, reqUid, |
| 5751 | (flags&DUMP_DEVICE_WIFI_ONLY) != 0); |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 5752 | pw.println(); |
Jeff Sharkey | ec43a6b | 2013-04-30 13:33:18 -0700 | [diff] [blame] | 5753 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5754 | } |
| 5755 | |
| 5756 | @SuppressWarnings("unused") |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 5757 | public void dumpCheckinLocked(Context context, PrintWriter pw, |
| 5758 | List<ApplicationInfo> apps, int flags, long histStart) { |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5759 | prepareForDumpLocked(); |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 5760 | |
| 5761 | dumpLine(pw, 0 /* uid */, "i" /* category */, VERSION_DATA, |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 5762 | CHECKIN_VERSION, getParcelVersion(), getStartPlatformVersion(), |
| 5763 | getEndPlatformVersion()); |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 5764 | |
Dianne Hackborn | 13ac041 | 2013-06-25 19:34:49 -0700 | [diff] [blame] | 5765 | long now = getHistoryBaseTime() + SystemClock.elapsedRealtime(); |
| 5766 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 5767 | final boolean filtering = (flags & |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5768 | (DUMP_HISTORY_ONLY|DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) != 0; |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 5769 | |
| 5770 | if ((flags&DUMP_INCLUDE_HISTORY) != 0 || (flags&DUMP_HISTORY_ONLY) != 0) { |
Dianne Hackborn | 49021f5 | 2013-09-04 18:03:40 -0700 | [diff] [blame] | 5771 | if (startIteratingHistoryLocked()) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 5772 | try { |
| 5773 | for (int i=0; i<getHistoryStringPoolSize(); i++) { |
| 5774 | pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(','); |
| 5775 | pw.print(HISTORY_STRING_POOL); pw.print(','); |
| 5776 | pw.print(i); |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 5777 | pw.print(","); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 5778 | pw.print(getHistoryTagPoolUid(i)); |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 5779 | pw.print(",\""); |
| 5780 | String str = getHistoryTagPoolString(i); |
| 5781 | str = str.replace("\\", "\\\\"); |
| 5782 | str = str.replace("\"", "\\\""); |
| 5783 | pw.print(str); |
| 5784 | pw.print("\""); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 5785 | pw.println(); |
| 5786 | } |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 5787 | dumpHistoryLocked(pw, flags, histStart, true); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 5788 | } finally { |
| 5789 | finishIteratingHistoryLocked(); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 5790 | } |
Dianne Hackborn | 13ac041 | 2013-06-25 19:34:49 -0700 | [diff] [blame] | 5791 | } |
Dianne Hackborn | 13ac041 | 2013-06-25 19:34:49 -0700 | [diff] [blame] | 5792 | } |
| 5793 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5794 | if (filtering && (flags&(DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) == 0) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 5795 | return; |
| 5796 | } |
| 5797 | |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 5798 | if (apps != null) { |
Dianne Hackborn | 9cfba35 | 2016-03-24 17:31:28 -0700 | [diff] [blame] | 5799 | SparseArray<Pair<ArrayList<String>, MutableBoolean>> uids = new SparseArray<>(); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 5800 | for (int i=0; i<apps.size(); i++) { |
| 5801 | ApplicationInfo ai = apps.get(i); |
Dianne Hackborn | 9cfba35 | 2016-03-24 17:31:28 -0700 | [diff] [blame] | 5802 | Pair<ArrayList<String>, MutableBoolean> pkgs = uids.get( |
| 5803 | UserHandle.getAppId(ai.uid)); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 5804 | if (pkgs == null) { |
Dianne Hackborn | 9cfba35 | 2016-03-24 17:31:28 -0700 | [diff] [blame] | 5805 | pkgs = new Pair<>(new ArrayList<String>(), new MutableBoolean(false)); |
| 5806 | uids.put(UserHandle.getAppId(ai.uid), pkgs); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 5807 | } |
Dianne Hackborn | 9cfba35 | 2016-03-24 17:31:28 -0700 | [diff] [blame] | 5808 | pkgs.first.add(ai.packageName); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 5809 | } |
| 5810 | SparseArray<? extends Uid> uidStats = getUidStats(); |
| 5811 | final int NU = uidStats.size(); |
| 5812 | String[] lineArgs = new String[2]; |
| 5813 | for (int i=0; i<NU; i++) { |
Dianne Hackborn | 9cfba35 | 2016-03-24 17:31:28 -0700 | [diff] [blame] | 5814 | int uid = UserHandle.getAppId(uidStats.keyAt(i)); |
| 5815 | Pair<ArrayList<String>, MutableBoolean> pkgs = uids.get(uid); |
| 5816 | if (pkgs != null && !pkgs.second.value) { |
| 5817 | pkgs.second.value = true; |
| 5818 | for (int j=0; j<pkgs.first.size(); j++) { |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 5819 | lineArgs[0] = Integer.toString(uid); |
Dianne Hackborn | 9cfba35 | 2016-03-24 17:31:28 -0700 | [diff] [blame] | 5820 | lineArgs[1] = pkgs.first.get(j); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 5821 | dumpLine(pw, 0 /* uid */, "i" /* category */, UID_DATA, |
| 5822 | (Object[])lineArgs); |
| 5823 | } |
| 5824 | } |
| 5825 | } |
| 5826 | } |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 5827 | if (!filtering || (flags&DUMP_CHARGED_ONLY) != 0) { |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 5828 | dumpDurationSteps(pw, "", DISCHARGE_STEP_DATA, getDischargeLevelStepTracker(), true); |
Dianne Hackborn | d06dcfd | 2014-05-02 13:49:30 -0700 | [diff] [blame] | 5829 | String[] lineArgs = new String[1]; |
Kweku Adams | b0449e0 | 2016-10-12 14:18:27 -0700 | [diff] [blame] | 5830 | long timeRemaining = computeBatteryTimeRemaining(SystemClock.elapsedRealtime() * 1000); |
Dianne Hackborn | d06dcfd | 2014-05-02 13:49:30 -0700 | [diff] [blame] | 5831 | if (timeRemaining >= 0) { |
| 5832 | lineArgs[0] = Long.toString(timeRemaining); |
| 5833 | dumpLine(pw, 0 /* uid */, "i" /* category */, DISCHARGE_TIME_REMAIN_DATA, |
| 5834 | (Object[])lineArgs); |
| 5835 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 5836 | dumpDurationSteps(pw, "", CHARGE_STEP_DATA, getChargeLevelStepTracker(), true); |
Kweku Adams | b0449e0 | 2016-10-12 14:18:27 -0700 | [diff] [blame] | 5837 | timeRemaining = computeChargeTimeRemaining(SystemClock.elapsedRealtime() * 1000); |
Dianne Hackborn | d06dcfd | 2014-05-02 13:49:30 -0700 | [diff] [blame] | 5838 | if (timeRemaining >= 0) { |
| 5839 | lineArgs[0] = Long.toString(timeRemaining); |
| 5840 | dumpLine(pw, 0 /* uid */, "i" /* category */, CHARGE_TIME_REMAIN_DATA, |
| 5841 | (Object[])lineArgs); |
| 5842 | } |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 5843 | dumpCheckinLocked(context, pw, STATS_SINCE_CHARGED, -1, |
| 5844 | (flags&DUMP_DEVICE_WIFI_ONLY) != 0); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 5845 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5846 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5847 | } |