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 | 2bffb5b | 2017-04-13 11:59:33 -0700 | [diff] [blame] | 185 | * - Background timers and counters for: Sensor, BluetoothScan, WifiScan, Jobs, Syncs. |
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(); |
Bookatz | 956f36bf | 2017-04-28 09:48:17 -0700 | [diff] [blame^] | 516 | public abstract Counter getBluetoothScanResultCounter(); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 517 | |
Dianne Hackborn | a0200e3 | 2016-03-30 18:01:41 -0700 | [diff] [blame] | 518 | // Note: the following times are disjoint. They can be added together to find the |
| 519 | // total time a uid has had any processes running at all. |
| 520 | |
| 521 | /** |
| 522 | * Time this uid has any processes in the top state (or above such as persistent). |
| 523 | */ |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 524 | public static final int PROCESS_STATE_TOP = 0; |
Dianne Hackborn | a0200e3 | 2016-03-30 18:01:41 -0700 | [diff] [blame] | 525 | /** |
| 526 | * Time this uid has any process with a started out bound foreground service, but |
| 527 | * none in the "top" state. |
| 528 | */ |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 529 | public static final int PROCESS_STATE_FOREGROUND_SERVICE = 1; |
Dianne Hackborn | a0200e3 | 2016-03-30 18:01:41 -0700 | [diff] [blame] | 530 | /** |
| 531 | * Time this uid has any process that is top while the device is sleeping, but none |
| 532 | * in the "foreground service" or better state. |
| 533 | */ |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 534 | public static final int PROCESS_STATE_TOP_SLEEPING = 2; |
Dianne Hackborn | a0200e3 | 2016-03-30 18:01:41 -0700 | [diff] [blame] | 535 | /** |
| 536 | * Time this uid has any process in an active foreground state, but none in the |
| 537 | * "top sleeping" or better state. |
| 538 | */ |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 539 | public static final int PROCESS_STATE_FOREGROUND = 3; |
Dianne Hackborn | a0200e3 | 2016-03-30 18:01:41 -0700 | [diff] [blame] | 540 | /** |
| 541 | * Time this uid has any process in an active background state, but none in the |
| 542 | * "foreground" or better state. |
| 543 | */ |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 544 | public static final int PROCESS_STATE_BACKGROUND = 4; |
Dianne Hackborn | a0200e3 | 2016-03-30 18:01:41 -0700 | [diff] [blame] | 545 | /** |
| 546 | * Time this uid has any processes that are sitting around cached, not in one of the |
| 547 | * other active states. |
| 548 | */ |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 549 | public static final int PROCESS_STATE_CACHED = 5; |
Dianne Hackborn | a0200e3 | 2016-03-30 18:01:41 -0700 | [diff] [blame] | 550 | /** |
| 551 | * Total number of process states we track. |
| 552 | */ |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 553 | public static final int NUM_PROCESS_STATE = 6; |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 554 | |
| 555 | static final String[] PROCESS_STATE_NAMES = { |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 556 | "Top", "Fg Service", "Top Sleeping", "Foreground", "Background", "Cached" |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 557 | }; |
| 558 | |
| 559 | public abstract long getProcessStateTime(int state, long elapsedRealtimeUs, int which); |
Joe Onorato | 713fec8 | 2016-03-04 10:34:02 -0800 | [diff] [blame] | 560 | public abstract Timer getProcessStateTimer(int state); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 561 | |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 562 | public abstract Timer getVibratorOnTimer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 563 | |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 564 | public static final int NUM_WIFI_BATCHED_SCAN_BINS = 5; |
| 565 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 566 | /** |
Jeff Brown | df693de | 2012-07-27 12:03:38 -0700 | [diff] [blame] | 567 | * Note that these must match the constants in android.os.PowerManager. |
| 568 | * Also, if the user activity types change, the BatteryStatsImpl.VERSION must |
| 569 | * also be bumped. |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 570 | */ |
| 571 | static final String[] USER_ACTIVITY_TYPES = { |
Phil Weaver | da80d67 | 2016-03-15 16:25:46 -0700 | [diff] [blame] | 572 | "other", "button", "touch", "accessibility" |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 573 | }; |
| 574 | |
Phil Weaver | da80d67 | 2016-03-15 16:25:46 -0700 | [diff] [blame] | 575 | public static final int NUM_USER_ACTIVITY_TYPES = 4; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 576 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 577 | public abstract void noteUserActivityLocked(int type); |
| 578 | public abstract boolean hasUserActivity(); |
| 579 | public abstract int getUserActivityCount(int type, int which); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 580 | |
| 581 | public abstract boolean hasNetworkActivity(); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 582 | public abstract long getNetworkActivityBytes(int type, int which); |
| 583 | public abstract long getNetworkActivityPackets(int type, int which); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 584 | public abstract long getMobileRadioActiveTime(int which); |
| 585 | public abstract int getMobileRadioActiveCount(int which); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 586 | |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 587 | /** |
| 588 | * Get the total cpu time (in microseconds) this UID had processes executing in userspace. |
| 589 | */ |
| 590 | public abstract long getUserCpuTimeUs(int which); |
| 591 | |
| 592 | /** |
| 593 | * Get the total cpu time (in microseconds) this UID had processes executing kernel syscalls. |
| 594 | */ |
| 595 | public abstract long getSystemCpuTimeUs(int which); |
| 596 | |
| 597 | /** |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 598 | * Returns the approximate cpu time (in milliseconds) spent at a certain CPU speed for a |
| 599 | * given CPU cluster. |
| 600 | * @param cluster the index of the CPU cluster. |
Adam Lesinski | a7a4ccc | 2015-06-26 17:43:04 -0700 | [diff] [blame] | 601 | * @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] | 602 | * @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] | 603 | * @see com.android.internal.os.PowerProfile#getNumCpuClusters() |
| 604 | * @see com.android.internal.os.PowerProfile#getNumSpeedStepsInCpuCluster(int) |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 605 | */ |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 606 | public abstract long getTimeAtCpuSpeed(int cluster, int step, int which); |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 607 | |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 608 | /** |
| 609 | * Returns the number of times this UID woke up the Application Processor to |
| 610 | * process a mobile radio packet. |
| 611 | * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT. |
| 612 | */ |
| 613 | public abstract long getMobileRadioApWakeupCount(int which); |
| 614 | |
| 615 | /** |
| 616 | * Returns the number of times this UID woke up the Application Processor to |
| 617 | * process a WiFi packet. |
| 618 | * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT. |
| 619 | */ |
| 620 | public abstract long getWifiRadioApWakeupCount(int which); |
| 621 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 622 | public static abstract class Sensor { |
Mathias Agopian | 7f84c06 | 2013-02-04 19:22:47 -0800 | [diff] [blame] | 623 | /* |
| 624 | * FIXME: it's not correct to use this magic value because it |
| 625 | * could clash with a sensor handle (which are defined by |
| 626 | * the sensor HAL, and therefore out of our control |
| 627 | */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 628 | // Magic sensor number for the GPS. |
| 629 | public static final int GPS = -10000; |
Amith Yamasani | ab9ad19 | 2016-12-06 12:46:59 -0800 | [diff] [blame] | 630 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 631 | public abstract int getHandle(); |
Amith Yamasani | ab9ad19 | 2016-12-06 12:46:59 -0800 | [diff] [blame] | 632 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 633 | public abstract Timer getSensorTime(); |
Amith Yamasani | ab9ad19 | 2016-12-06 12:46:59 -0800 | [diff] [blame] | 634 | |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 635 | /** Returns a Timer for sensor usage when app is in the background. */ |
| 636 | public abstract Timer getSensorBackgroundTime(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 637 | } |
| 638 | |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 639 | public class Pid { |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 640 | public int mWakeNesting; |
| 641 | public long mWakeSumMs; |
| 642 | public long mWakeStartMs; |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 643 | } |
| 644 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 645 | /** |
| 646 | * The statistics associated with a particular process. |
| 647 | */ |
| 648 | public static abstract class Proc { |
| 649 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 650 | public static class ExcessivePower { |
| 651 | public static final int TYPE_WAKE = 1; |
| 652 | public static final int TYPE_CPU = 2; |
| 653 | |
| 654 | public int type; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 655 | public long overTime; |
| 656 | public long usedTime; |
| 657 | } |
| 658 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 659 | /** |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 660 | * Returns true if this process is still active in the battery stats. |
| 661 | */ |
| 662 | public abstract boolean isActive(); |
| 663 | |
| 664 | /** |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 665 | * 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] | 666 | * |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 667 | * @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] | 668 | */ |
| 669 | public abstract long getUserTime(int which); |
| 670 | |
| 671 | /** |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 672 | * 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] | 673 | * |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 674 | * @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] | 675 | */ |
| 676 | public abstract long getSystemTime(int which); |
| 677 | |
| 678 | /** |
| 679 | * Returns the number of times the process has been started. |
| 680 | * |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 681 | * @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] | 682 | */ |
| 683 | public abstract int getStarts(int which); |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 684 | |
| 685 | /** |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 686 | * Returns the number of times the process has crashed. |
| 687 | * |
| 688 | * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT. |
| 689 | */ |
| 690 | public abstract int getNumCrashes(int which); |
| 691 | |
| 692 | /** |
| 693 | * Returns the number of times the process has ANRed. |
| 694 | * |
| 695 | * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT. |
| 696 | */ |
| 697 | public abstract int getNumAnrs(int which); |
| 698 | |
| 699 | /** |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 700 | * 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] | 701 | * @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] | 702 | * @return foreground cpu time in microseconds |
| 703 | */ |
| 704 | public abstract long getForegroundTime(int which); |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 705 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 706 | public abstract int countExcessivePowers(); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 707 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 708 | public abstract ExcessivePower getExcessivePower(int i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 709 | } |
| 710 | |
| 711 | /** |
| 712 | * The statistics associated with a particular package. |
| 713 | */ |
| 714 | public static abstract class Pkg { |
| 715 | |
| 716 | /** |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 717 | * Returns information about all wakeup alarms that have been triggered for this |
| 718 | * package. The mapping keys are tag names for the alarms, the counter contains |
| 719 | * 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] | 720 | */ |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 721 | public abstract ArrayMap<String, ? extends Counter> getWakeupAlarmStats(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 722 | |
| 723 | /** |
| 724 | * Returns a mapping containing service statistics. |
| 725 | */ |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 726 | public abstract ArrayMap<String, ? extends Serv> getServiceStats(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 727 | |
| 728 | /** |
| 729 | * The statistics associated with a particular service. |
| 730 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 731 | public static abstract class Serv { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 732 | |
| 733 | /** |
| 734 | * Returns the amount of time spent started. |
| 735 | * |
| 736 | * @param batteryUptime elapsed uptime on battery in microseconds. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 737 | * @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] | 738 | * @return |
| 739 | */ |
| 740 | public abstract long getStartTime(long batteryUptime, int which); |
| 741 | |
| 742 | /** |
| 743 | * Returns the total number of times startService() has been called. |
| 744 | * |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 745 | * @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] | 746 | */ |
| 747 | public abstract int getStarts(int which); |
| 748 | |
| 749 | /** |
| 750 | * Returns the total number times the service has been launched. |
| 751 | * |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 752 | * @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] | 753 | */ |
| 754 | public abstract int getLaunches(int which); |
| 755 | } |
| 756 | } |
| 757 | } |
| 758 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 759 | public static final class LevelStepTracker { |
| 760 | public long mLastStepTime = -1; |
| 761 | public int mNumStepDurations; |
| 762 | public final long[] mStepDurations; |
| 763 | |
| 764 | public LevelStepTracker(int maxLevelSteps) { |
| 765 | mStepDurations = new long[maxLevelSteps]; |
| 766 | } |
| 767 | |
| 768 | public LevelStepTracker(int numSteps, long[] steps) { |
| 769 | mNumStepDurations = numSteps; |
| 770 | mStepDurations = new long[numSteps]; |
| 771 | System.arraycopy(steps, 0, mStepDurations, 0, numSteps); |
| 772 | } |
| 773 | |
| 774 | public long getDurationAt(int index) { |
| 775 | return mStepDurations[index] & STEP_LEVEL_TIME_MASK; |
| 776 | } |
| 777 | |
| 778 | public int getLevelAt(int index) { |
| 779 | return (int)((mStepDurations[index] & STEP_LEVEL_LEVEL_MASK) |
| 780 | >> STEP_LEVEL_LEVEL_SHIFT); |
| 781 | } |
| 782 | |
| 783 | public int getInitModeAt(int index) { |
| 784 | return (int)((mStepDurations[index] & STEP_LEVEL_INITIAL_MODE_MASK) |
| 785 | >> STEP_LEVEL_INITIAL_MODE_SHIFT); |
| 786 | } |
| 787 | |
| 788 | public int getModModeAt(int index) { |
| 789 | return (int)((mStepDurations[index] & STEP_LEVEL_MODIFIED_MODE_MASK) |
| 790 | >> STEP_LEVEL_MODIFIED_MODE_SHIFT); |
| 791 | } |
| 792 | |
| 793 | private void appendHex(long val, int topOffset, StringBuilder out) { |
| 794 | boolean hasData = false; |
| 795 | while (topOffset >= 0) { |
| 796 | int digit = (int)( (val>>topOffset) & 0xf ); |
| 797 | topOffset -= 4; |
| 798 | if (!hasData && digit == 0) { |
| 799 | continue; |
| 800 | } |
| 801 | hasData = true; |
| 802 | if (digit >= 0 && digit <= 9) { |
| 803 | out.append((char)('0' + digit)); |
| 804 | } else { |
| 805 | out.append((char)('a' + digit - 10)); |
| 806 | } |
| 807 | } |
| 808 | } |
| 809 | |
| 810 | public void encodeEntryAt(int index, StringBuilder out) { |
| 811 | long item = mStepDurations[index]; |
| 812 | long duration = item & STEP_LEVEL_TIME_MASK; |
| 813 | int level = (int)((item & STEP_LEVEL_LEVEL_MASK) |
| 814 | >> STEP_LEVEL_LEVEL_SHIFT); |
| 815 | int initMode = (int)((item & STEP_LEVEL_INITIAL_MODE_MASK) |
| 816 | >> STEP_LEVEL_INITIAL_MODE_SHIFT); |
| 817 | int modMode = (int)((item & STEP_LEVEL_MODIFIED_MODE_MASK) |
| 818 | >> STEP_LEVEL_MODIFIED_MODE_SHIFT); |
| 819 | switch ((initMode&STEP_LEVEL_MODE_SCREEN_STATE) + 1) { |
| 820 | case Display.STATE_OFF: out.append('f'); break; |
| 821 | case Display.STATE_ON: out.append('o'); break; |
| 822 | case Display.STATE_DOZE: out.append('d'); break; |
| 823 | case Display.STATE_DOZE_SUSPEND: out.append('z'); break; |
| 824 | } |
| 825 | if ((initMode&STEP_LEVEL_MODE_POWER_SAVE) != 0) { |
| 826 | out.append('p'); |
| 827 | } |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 828 | if ((initMode&STEP_LEVEL_MODE_DEVICE_IDLE) != 0) { |
| 829 | out.append('i'); |
| 830 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 831 | switch ((modMode&STEP_LEVEL_MODE_SCREEN_STATE) + 1) { |
| 832 | case Display.STATE_OFF: out.append('F'); break; |
| 833 | case Display.STATE_ON: out.append('O'); break; |
| 834 | case Display.STATE_DOZE: out.append('D'); break; |
| 835 | case Display.STATE_DOZE_SUSPEND: out.append('Z'); break; |
| 836 | } |
| 837 | if ((modMode&STEP_LEVEL_MODE_POWER_SAVE) != 0) { |
| 838 | out.append('P'); |
| 839 | } |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 840 | if ((modMode&STEP_LEVEL_MODE_DEVICE_IDLE) != 0) { |
| 841 | out.append('I'); |
| 842 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 843 | out.append('-'); |
| 844 | appendHex(level, 4, out); |
| 845 | out.append('-'); |
| 846 | appendHex(duration, STEP_LEVEL_LEVEL_SHIFT-4, out); |
| 847 | } |
| 848 | |
| 849 | public void decodeEntryAt(int index, String value) { |
| 850 | final int N = value.length(); |
| 851 | int i = 0; |
| 852 | char c; |
| 853 | long out = 0; |
| 854 | while (i < N && (c=value.charAt(i)) != '-') { |
| 855 | i++; |
| 856 | switch (c) { |
Dianne Hackborn | 8cfb58b | 2015-03-04 13:28:36 -0800 | [diff] [blame] | 857 | 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] | 858 | break; |
Dianne Hackborn | 8cfb58b | 2015-03-04 13:28:36 -0800 | [diff] [blame] | 859 | 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] | 860 | break; |
Dianne Hackborn | 8cfb58b | 2015-03-04 13:28:36 -0800 | [diff] [blame] | 861 | 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] | 862 | break; |
Dianne Hackborn | 8cfb58b | 2015-03-04 13:28:36 -0800 | [diff] [blame] | 863 | case 'z': out |= (((long)Display.STATE_DOZE_SUSPEND-1) |
| 864 | << STEP_LEVEL_INITIAL_MODE_SHIFT); |
| 865 | break; |
| 866 | case 'p': out |= (((long)STEP_LEVEL_MODE_POWER_SAVE) |
| 867 | << STEP_LEVEL_INITIAL_MODE_SHIFT); |
| 868 | break; |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 869 | case 'i': out |= (((long)STEP_LEVEL_MODE_DEVICE_IDLE) |
| 870 | << STEP_LEVEL_INITIAL_MODE_SHIFT); |
| 871 | break; |
Dianne Hackborn | 8cfb58b | 2015-03-04 13:28:36 -0800 | [diff] [blame] | 872 | case 'F': out |= (((long)Display.STATE_OFF-1)<<STEP_LEVEL_MODIFIED_MODE_SHIFT); |
| 873 | break; |
| 874 | case 'O': out |= (((long)Display.STATE_ON-1)<<STEP_LEVEL_MODIFIED_MODE_SHIFT); |
| 875 | break; |
| 876 | case 'D': out |= (((long)Display.STATE_DOZE-1)<<STEP_LEVEL_MODIFIED_MODE_SHIFT); |
| 877 | break; |
| 878 | case 'Z': out |= (((long)Display.STATE_DOZE_SUSPEND-1) |
| 879 | << STEP_LEVEL_MODIFIED_MODE_SHIFT); |
| 880 | break; |
| 881 | case 'P': out |= (((long)STEP_LEVEL_MODE_POWER_SAVE) |
| 882 | << STEP_LEVEL_MODIFIED_MODE_SHIFT); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 883 | break; |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 884 | case 'I': out |= (((long)STEP_LEVEL_MODE_DEVICE_IDLE) |
| 885 | << STEP_LEVEL_MODIFIED_MODE_SHIFT); |
| 886 | break; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 887 | } |
| 888 | } |
| 889 | i++; |
Dianne Hackborn | 8cfb58b | 2015-03-04 13:28:36 -0800 | [diff] [blame] | 890 | long level = 0; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 891 | while (i < N && (c=value.charAt(i)) != '-') { |
| 892 | i++; |
| 893 | level <<= 4; |
| 894 | if (c >= '0' && c <= '9') { |
| 895 | level += c - '0'; |
| 896 | } else if (c >= 'a' && c <= 'f') { |
| 897 | level += c - 'a' + 10; |
| 898 | } else if (c >= 'A' && c <= 'F') { |
| 899 | level += c - 'A' + 10; |
| 900 | } |
| 901 | } |
Dianne Hackborn | 8cfb58b | 2015-03-04 13:28:36 -0800 | [diff] [blame] | 902 | i++; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 903 | out |= (level << STEP_LEVEL_LEVEL_SHIFT) & STEP_LEVEL_LEVEL_MASK; |
| 904 | long duration = 0; |
| 905 | while (i < N && (c=value.charAt(i)) != '-') { |
| 906 | i++; |
| 907 | duration <<= 4; |
| 908 | if (c >= '0' && c <= '9') { |
| 909 | duration += c - '0'; |
| 910 | } else if (c >= 'a' && c <= 'f') { |
| 911 | duration += c - 'a' + 10; |
| 912 | } else if (c >= 'A' && c <= 'F') { |
| 913 | duration += c - 'A' + 10; |
| 914 | } |
| 915 | } |
| 916 | mStepDurations[index] = out | (duration & STEP_LEVEL_TIME_MASK); |
| 917 | } |
| 918 | |
| 919 | public void init() { |
| 920 | mLastStepTime = -1; |
| 921 | mNumStepDurations = 0; |
| 922 | } |
| 923 | |
| 924 | public void clearTime() { |
| 925 | mLastStepTime = -1; |
| 926 | } |
| 927 | |
| 928 | public long computeTimePerLevel() { |
| 929 | final long[] steps = mStepDurations; |
| 930 | final int numSteps = mNumStepDurations; |
| 931 | |
| 932 | // For now we'll do a simple average across all steps. |
| 933 | if (numSteps <= 0) { |
| 934 | return -1; |
| 935 | } |
| 936 | long total = 0; |
| 937 | for (int i=0; i<numSteps; i++) { |
| 938 | total += steps[i] & STEP_LEVEL_TIME_MASK; |
| 939 | } |
| 940 | return total / numSteps; |
| 941 | /* |
| 942 | long[] buckets = new long[numSteps]; |
| 943 | int numBuckets = 0; |
| 944 | int numToAverage = 4; |
| 945 | int i = 0; |
| 946 | while (i < numSteps) { |
| 947 | long totalTime = 0; |
| 948 | int num = 0; |
| 949 | for (int j=0; j<numToAverage && (i+j)<numSteps; j++) { |
| 950 | totalTime += steps[i+j] & STEP_LEVEL_TIME_MASK; |
| 951 | num++; |
| 952 | } |
| 953 | buckets[numBuckets] = totalTime / num; |
| 954 | numBuckets++; |
| 955 | numToAverage *= 2; |
| 956 | i += num; |
| 957 | } |
| 958 | if (numBuckets < 1) { |
| 959 | return -1; |
| 960 | } |
| 961 | long averageTime = buckets[numBuckets-1]; |
| 962 | for (i=numBuckets-2; i>=0; i--) { |
| 963 | averageTime = (averageTime + buckets[i]) / 2; |
| 964 | } |
| 965 | return averageTime; |
| 966 | */ |
| 967 | } |
| 968 | |
| 969 | public long computeTimeEstimate(long modesOfInterest, long modeValues, |
| 970 | int[] outNumOfInterest) { |
| 971 | final long[] steps = mStepDurations; |
| 972 | final int count = mNumStepDurations; |
| 973 | if (count <= 0) { |
| 974 | return -1; |
| 975 | } |
| 976 | long total = 0; |
| 977 | int numOfInterest = 0; |
| 978 | for (int i=0; i<count; i++) { |
| 979 | long initMode = (steps[i] & STEP_LEVEL_INITIAL_MODE_MASK) |
| 980 | >> STEP_LEVEL_INITIAL_MODE_SHIFT; |
| 981 | long modMode = (steps[i] & STEP_LEVEL_MODIFIED_MODE_MASK) |
| 982 | >> STEP_LEVEL_MODIFIED_MODE_SHIFT; |
| 983 | // If the modes of interest didn't change during this step period... |
| 984 | if ((modMode&modesOfInterest) == 0) { |
| 985 | // And the mode values during this period match those we are measuring... |
| 986 | if ((initMode&modesOfInterest) == modeValues) { |
| 987 | // Then this can be used to estimate the total time! |
| 988 | numOfInterest++; |
| 989 | total += steps[i] & STEP_LEVEL_TIME_MASK; |
| 990 | } |
| 991 | } |
| 992 | } |
| 993 | if (numOfInterest <= 0) { |
| 994 | return -1; |
| 995 | } |
| 996 | |
| 997 | if (outNumOfInterest != null) { |
| 998 | outNumOfInterest[0] = numOfInterest; |
| 999 | } |
| 1000 | |
| 1001 | // The estimated time is the average time we spend in each level, multipled |
| 1002 | // by 100 -- the total number of battery levels |
| 1003 | return (total / numOfInterest) * 100; |
| 1004 | } |
| 1005 | |
| 1006 | public void addLevelSteps(int numStepLevels, long modeBits, long elapsedRealtime) { |
| 1007 | int stepCount = mNumStepDurations; |
| 1008 | final long lastStepTime = mLastStepTime; |
| 1009 | if (lastStepTime >= 0 && numStepLevels > 0) { |
| 1010 | final long[] steps = mStepDurations; |
| 1011 | long duration = elapsedRealtime - lastStepTime; |
| 1012 | for (int i=0; i<numStepLevels; i++) { |
| 1013 | System.arraycopy(steps, 0, steps, 1, steps.length-1); |
| 1014 | long thisDuration = duration / (numStepLevels-i); |
| 1015 | duration -= thisDuration; |
| 1016 | if (thisDuration > STEP_LEVEL_TIME_MASK) { |
| 1017 | thisDuration = STEP_LEVEL_TIME_MASK; |
| 1018 | } |
| 1019 | steps[0] = thisDuration | modeBits; |
| 1020 | } |
| 1021 | stepCount += numStepLevels; |
| 1022 | if (stepCount > steps.length) { |
| 1023 | stepCount = steps.length; |
| 1024 | } |
| 1025 | } |
| 1026 | mNumStepDurations = stepCount; |
| 1027 | mLastStepTime = elapsedRealtime; |
| 1028 | } |
| 1029 | |
| 1030 | public void readFromParcel(Parcel in) { |
| 1031 | final int N = in.readInt(); |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 1032 | if (N > mStepDurations.length) { |
| 1033 | throw new ParcelFormatException("more step durations than available: " + N); |
| 1034 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 1035 | mNumStepDurations = N; |
| 1036 | for (int i=0; i<N; i++) { |
| 1037 | mStepDurations[i] = in.readLong(); |
| 1038 | } |
| 1039 | } |
| 1040 | |
| 1041 | public void writeToParcel(Parcel out) { |
| 1042 | final int N = mNumStepDurations; |
| 1043 | out.writeInt(N); |
| 1044 | for (int i=0; i<N; i++) { |
| 1045 | out.writeLong(mStepDurations[i]); |
| 1046 | } |
| 1047 | } |
| 1048 | } |
| 1049 | |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 1050 | public static final class PackageChange { |
| 1051 | public String mPackageName; |
| 1052 | public boolean mUpdate; |
| 1053 | public int mVersionCode; |
| 1054 | } |
| 1055 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 1056 | public static final class DailyItem { |
| 1057 | public long mStartTime; |
| 1058 | public long mEndTime; |
| 1059 | public LevelStepTracker mDischargeSteps; |
| 1060 | public LevelStepTracker mChargeSteps; |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 1061 | public ArrayList<PackageChange> mPackageChanges; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 1062 | } |
| 1063 | |
| 1064 | public abstract DailyItem getDailyItemLocked(int daysAgo); |
| 1065 | |
| 1066 | public abstract long getCurrentDailyStartTime(); |
| 1067 | |
| 1068 | public abstract long getNextMinDailyDeadline(); |
| 1069 | |
| 1070 | public abstract long getNextMaxDailyDeadline(); |
| 1071 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1072 | public final static class HistoryTag { |
| 1073 | public String string; |
| 1074 | public int uid; |
| 1075 | |
| 1076 | public int poolIdx; |
| 1077 | |
| 1078 | public void setTo(HistoryTag o) { |
| 1079 | string = o.string; |
| 1080 | uid = o.uid; |
| 1081 | poolIdx = o.poolIdx; |
| 1082 | } |
| 1083 | |
| 1084 | public void setTo(String _string, int _uid) { |
| 1085 | string = _string; |
| 1086 | uid = _uid; |
| 1087 | poolIdx = -1; |
| 1088 | } |
| 1089 | |
| 1090 | public void writeToParcel(Parcel dest, int flags) { |
| 1091 | dest.writeString(string); |
| 1092 | dest.writeInt(uid); |
| 1093 | } |
| 1094 | |
| 1095 | public void readFromParcel(Parcel src) { |
| 1096 | string = src.readString(); |
| 1097 | uid = src.readInt(); |
| 1098 | poolIdx = -1; |
| 1099 | } |
| 1100 | |
| 1101 | @Override |
| 1102 | public boolean equals(Object o) { |
| 1103 | if (this == o) return true; |
| 1104 | if (o == null || getClass() != o.getClass()) return false; |
| 1105 | |
| 1106 | HistoryTag that = (HistoryTag) o; |
| 1107 | |
| 1108 | if (uid != that.uid) return false; |
| 1109 | if (!string.equals(that.string)) return false; |
| 1110 | |
| 1111 | return true; |
| 1112 | } |
| 1113 | |
| 1114 | @Override |
| 1115 | public int hashCode() { |
| 1116 | int result = string.hashCode(); |
| 1117 | result = 31 * result + uid; |
| 1118 | return result; |
| 1119 | } |
| 1120 | } |
| 1121 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 1122 | /** |
| 1123 | * Optional detailed information that can go into a history step. This is typically |
| 1124 | * generated each time the battery level changes. |
| 1125 | */ |
| 1126 | public final static class HistoryStepDetails { |
| 1127 | // Time (in 1/100 second) spent in user space and the kernel since the last step. |
| 1128 | public int userTime; |
| 1129 | public int systemTime; |
| 1130 | |
| 1131 | // Top three apps using CPU in the last step, with times in 1/100 second. |
| 1132 | public int appCpuUid1; |
| 1133 | public int appCpuUTime1; |
| 1134 | public int appCpuSTime1; |
| 1135 | public int appCpuUid2; |
| 1136 | public int appCpuUTime2; |
| 1137 | public int appCpuSTime2; |
| 1138 | public int appCpuUid3; |
| 1139 | public int appCpuUTime3; |
| 1140 | public int appCpuSTime3; |
| 1141 | |
| 1142 | // Information from /proc/stat |
| 1143 | public int statUserTime; |
| 1144 | public int statSystemTime; |
| 1145 | public int statIOWaitTime; |
| 1146 | public int statIrqTime; |
| 1147 | public int statSoftIrqTime; |
| 1148 | public int statIdlTime; |
| 1149 | |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 1150 | // Platform-level low power state stats |
| 1151 | public String statPlatformIdleState; |
| 1152 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 1153 | public HistoryStepDetails() { |
| 1154 | clear(); |
| 1155 | } |
| 1156 | |
| 1157 | public void clear() { |
| 1158 | userTime = systemTime = 0; |
| 1159 | appCpuUid1 = appCpuUid2 = appCpuUid3 = -1; |
| 1160 | appCpuUTime1 = appCpuSTime1 = appCpuUTime2 = appCpuSTime2 |
| 1161 | = appCpuUTime3 = appCpuSTime3 = 0; |
| 1162 | } |
| 1163 | |
| 1164 | public void writeToParcel(Parcel out) { |
| 1165 | out.writeInt(userTime); |
| 1166 | out.writeInt(systemTime); |
| 1167 | out.writeInt(appCpuUid1); |
| 1168 | out.writeInt(appCpuUTime1); |
| 1169 | out.writeInt(appCpuSTime1); |
| 1170 | out.writeInt(appCpuUid2); |
| 1171 | out.writeInt(appCpuUTime2); |
| 1172 | out.writeInt(appCpuSTime2); |
| 1173 | out.writeInt(appCpuUid3); |
| 1174 | out.writeInt(appCpuUTime3); |
| 1175 | out.writeInt(appCpuSTime3); |
| 1176 | out.writeInt(statUserTime); |
| 1177 | out.writeInt(statSystemTime); |
| 1178 | out.writeInt(statIOWaitTime); |
| 1179 | out.writeInt(statIrqTime); |
| 1180 | out.writeInt(statSoftIrqTime); |
| 1181 | out.writeInt(statIdlTime); |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 1182 | out.writeString(statPlatformIdleState); |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 1183 | } |
| 1184 | |
| 1185 | public void readFromParcel(Parcel in) { |
| 1186 | userTime = in.readInt(); |
| 1187 | systemTime = in.readInt(); |
| 1188 | appCpuUid1 = in.readInt(); |
| 1189 | appCpuUTime1 = in.readInt(); |
| 1190 | appCpuSTime1 = in.readInt(); |
| 1191 | appCpuUid2 = in.readInt(); |
| 1192 | appCpuUTime2 = in.readInt(); |
| 1193 | appCpuSTime2 = in.readInt(); |
| 1194 | appCpuUid3 = in.readInt(); |
| 1195 | appCpuUTime3 = in.readInt(); |
| 1196 | appCpuSTime3 = in.readInt(); |
| 1197 | statUserTime = in.readInt(); |
| 1198 | statSystemTime = in.readInt(); |
| 1199 | statIOWaitTime = in.readInt(); |
| 1200 | statIrqTime = in.readInt(); |
| 1201 | statSoftIrqTime = in.readInt(); |
| 1202 | statIdlTime = in.readInt(); |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 1203 | statPlatformIdleState = in.readString(); |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 1204 | } |
| 1205 | } |
| 1206 | |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 1207 | public final static class HistoryItem implements Parcelable { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1208 | public HistoryItem next; |
Dianne Hackborn | 9a75543 | 2014-05-15 17:05:22 -0700 | [diff] [blame] | 1209 | |
| 1210 | // The time of this event in milliseconds, as per SystemClock.elapsedRealtime(). |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1211 | public long time; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1212 | |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 1213 | 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] | 1214 | public static final byte CMD_NULL = -1; |
| 1215 | public static final byte CMD_START = 4; |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1216 | public static final byte CMD_CURRENT_TIME = 5; |
| 1217 | public static final byte CMD_OVERFLOW = 6; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 1218 | public static final byte CMD_RESET = 7; |
Dianne Hackborn | 29cd7f1 | 2015-01-08 10:37:05 -0800 | [diff] [blame] | 1219 | public static final byte CMD_SHUTDOWN = 8; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1220 | |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 1221 | public byte cmd = CMD_NULL; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1222 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1223 | /** |
| 1224 | * Return whether the command code is a delta data update. |
| 1225 | */ |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1226 | public boolean isDeltaData() { |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 1227 | return cmd == CMD_UPDATE; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1228 | } |
| 1229 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1230 | public byte batteryLevel; |
| 1231 | public byte batteryStatus; |
| 1232 | public byte batteryHealth; |
| 1233 | public byte batteryPlugType; |
| 1234 | |
Sungmin Choi | c7e9e8b | 2013-01-16 12:57:36 +0900 | [diff] [blame] | 1235 | public short batteryTemperature; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1236 | public char batteryVoltage; |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 1237 | |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 1238 | // The charge of the battery in micro-Ampere-hours. |
| 1239 | public int batteryChargeUAh; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1240 | |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 1241 | // Constants from SCREEN_BRIGHTNESS_* |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1242 | public static final int STATE_BRIGHTNESS_SHIFT = 0; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1243 | public static final int STATE_BRIGHTNESS_MASK = 0x7; |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 1244 | // Constants from SIGNAL_STRENGTH_* |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 1245 | public static final int STATE_PHONE_SIGNAL_STRENGTH_SHIFT = 3; |
| 1246 | 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] | 1247 | // Constants from ServiceState.STATE_* |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1248 | public static final int STATE_PHONE_STATE_SHIFT = 6; |
| 1249 | 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] | 1250 | // Constants from DATA_CONNECTION_* |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1251 | public static final int STATE_DATA_CONNECTION_SHIFT = 9; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1252 | 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] | 1253 | |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 1254 | // These states always appear directly in the first int token |
| 1255 | // of a delta change; they should be ones that change relatively |
| 1256 | // frequently. |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1257 | public static final int STATE_CPU_RUNNING_FLAG = 1<<31; |
| 1258 | public static final int STATE_WAKE_LOCK_FLAG = 1<<30; |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 1259 | public static final int STATE_GPS_ON_FLAG = 1<<29; |
| 1260 | public static final int STATE_WIFI_FULL_LOCK_FLAG = 1<<28; |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 1261 | public static final int STATE_WIFI_SCAN_FLAG = 1<<27; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 1262 | public static final int STATE_WIFI_RADIO_ACTIVE_FLAG = 1<<26; |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 1263 | public static final int STATE_MOBILE_RADIO_ACTIVE_FLAG = 1<<25; |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 1264 | // Do not use, this is used for coulomb delta count. |
| 1265 | private static final int STATE_RESERVED_0 = 1<<24; |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 1266 | // These are on the lower bits used for the command; if they change |
| 1267 | // we need to write another int of data. |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1268 | public static final int STATE_SENSOR_ON_FLAG = 1<<23; |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 1269 | public static final int STATE_AUDIO_ON_FLAG = 1<<22; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1270 | public static final int STATE_PHONE_SCANNING_FLAG = 1<<21; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 1271 | public static final int STATE_SCREEN_ON_FLAG = 1<<20; // consider moving to states2 |
| 1272 | public static final int STATE_BATTERY_PLUGGED_FLAG = 1<<19; // consider moving to states2 |
| 1273 | // empty slot |
| 1274 | // empty slot |
| 1275 | public static final int STATE_WIFI_MULTICAST_ON_FLAG = 1<<16; |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 1276 | |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 1277 | public static final int MOST_INTERESTING_STATES = |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 1278 | STATE_BATTERY_PLUGGED_FLAG | STATE_SCREEN_ON_FLAG; |
| 1279 | |
| 1280 | public static final int SETTLE_TO_ZERO_STATES = 0xffff0000 & ~MOST_INTERESTING_STATES; |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 1281 | |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1282 | public int states; |
| 1283 | |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 1284 | // Constants from WIFI_SUPPL_STATE_* |
| 1285 | public static final int STATE2_WIFI_SUPPL_STATE_SHIFT = 0; |
| 1286 | public static final int STATE2_WIFI_SUPPL_STATE_MASK = 0xf; |
| 1287 | // Values for NUM_WIFI_SIGNAL_STRENGTH_BINS |
| 1288 | public static final int STATE2_WIFI_SIGNAL_STRENGTH_SHIFT = 4; |
| 1289 | public static final int STATE2_WIFI_SIGNAL_STRENGTH_MASK = |
| 1290 | 0x7 << STATE2_WIFI_SIGNAL_STRENGTH_SHIFT; |
| 1291 | |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 1292 | public static final int STATE2_POWER_SAVE_FLAG = 1<<31; |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 1293 | public static final int STATE2_VIDEO_ON_FLAG = 1<<30; |
| 1294 | public static final int STATE2_WIFI_RUNNING_FLAG = 1<<29; |
| 1295 | public static final int STATE2_WIFI_ON_FLAG = 1<<28; |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 1296 | public static final int STATE2_FLASHLIGHT_FLAG = 1<<27; |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 1297 | public static final int STATE2_DEVICE_IDLE_SHIFT = 25; |
| 1298 | public static final int STATE2_DEVICE_IDLE_MASK = 0x3 << STATE2_DEVICE_IDLE_SHIFT; |
| 1299 | public static final int STATE2_CHARGING_FLAG = 1<<24; |
| 1300 | public static final int STATE2_PHONE_IN_CALL_FLAG = 1<<23; |
| 1301 | public static final int STATE2_BLUETOOTH_ON_FLAG = 1<<22; |
| 1302 | public static final int STATE2_CAMERA_FLAG = 1<<21; |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 1303 | public static final int STATE2_BLUETOOTH_SCAN_FLAG = 1 << 20; |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 1304 | |
| 1305 | public static final int MOST_INTERESTING_STATES2 = |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 1306 | STATE2_POWER_SAVE_FLAG | STATE2_WIFI_ON_FLAG | STATE2_DEVICE_IDLE_MASK |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 1307 | | STATE2_CHARGING_FLAG | STATE2_PHONE_IN_CALL_FLAG | STATE2_BLUETOOTH_ON_FLAG; |
| 1308 | |
| 1309 | public static final int SETTLE_TO_ZERO_STATES2 = 0xffff0000 & ~MOST_INTERESTING_STATES2; |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 1310 | |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 1311 | public int states2; |
| 1312 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1313 | // The wake lock that was acquired at this point. |
| 1314 | public HistoryTag wakelockTag; |
| 1315 | |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1316 | // Kernel wakeup reason at this point. |
| 1317 | public HistoryTag wakeReasonTag; |
| 1318 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 1319 | // Non-null when there is more detailed information at this step. |
| 1320 | public HistoryStepDetails stepDetails; |
| 1321 | |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 1322 | public static final int EVENT_FLAG_START = 0x8000; |
| 1323 | public static final int EVENT_FLAG_FINISH = 0x4000; |
| 1324 | |
| 1325 | // No event in this item. |
| 1326 | public static final int EVENT_NONE = 0x0000; |
| 1327 | // Event is about a process that is running. |
| 1328 | public static final int EVENT_PROC = 0x0001; |
| 1329 | // Event is about an application package that is in the foreground. |
| 1330 | public static final int EVENT_FOREGROUND = 0x0002; |
| 1331 | // Event is about an application package that is at the top of the screen. |
| 1332 | public static final int EVENT_TOP = 0x0003; |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 1333 | // Event is about active sync operations. |
Dianne Hackborn | a1f1a3c | 2014-02-24 18:12:28 -0800 | [diff] [blame] | 1334 | public static final int EVENT_SYNC = 0x0004; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 1335 | // Events for all additional wake locks aquired/release within a wake block. |
| 1336 | // These are not generated by default. |
| 1337 | public static final int EVENT_WAKE_LOCK = 0x0005; |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 1338 | // Event is about an application executing a scheduled job. |
| 1339 | public static final int EVENT_JOB = 0x0006; |
| 1340 | // Events for users running. |
| 1341 | public static final int EVENT_USER_RUNNING = 0x0007; |
| 1342 | // Events for foreground user. |
| 1343 | public static final int EVENT_USER_FOREGROUND = 0x0008; |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 1344 | // Event for connectivity changed. |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 1345 | public static final int EVENT_CONNECTIVITY_CHANGED = 0x0009; |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 1346 | // Event for becoming active taking us out of idle mode. |
Dianne Hackborn | b6683c4 | 2015-06-18 17:40:33 -0700 | [diff] [blame] | 1347 | public static final int EVENT_ACTIVE = 0x000a; |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 1348 | // Event for a package being installed. |
Dianne Hackborn | b6683c4 | 2015-06-18 17:40:33 -0700 | [diff] [blame] | 1349 | public static final int EVENT_PACKAGE_INSTALLED = 0x000b; |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 1350 | // Event for a package being uninstalled. |
Dianne Hackborn | b6683c4 | 2015-06-18 17:40:33 -0700 | [diff] [blame] | 1351 | public static final int EVENT_PACKAGE_UNINSTALLED = 0x000c; |
Dianne Hackborn | 1e38382 | 2015-04-10 14:02:33 -0700 | [diff] [blame] | 1352 | // Event for a package being uninstalled. |
Dianne Hackborn | b6683c4 | 2015-06-18 17:40:33 -0700 | [diff] [blame] | 1353 | public static final int EVENT_ALARM = 0x000d; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 1354 | // Record that we have decided we need to collect new stats data. |
Dianne Hackborn | b6683c4 | 2015-06-18 17:40:33 -0700 | [diff] [blame] | 1355 | public static final int EVENT_COLLECT_EXTERNAL_STATS = 0x000e; |
Amith Yamasani | 6776849 | 2015-06-09 12:23:58 -0700 | [diff] [blame] | 1356 | // 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] | 1357 | public static final int EVENT_PACKAGE_INACTIVE = 0x000f; |
Amith Yamasani | 6776849 | 2015-06-09 12:23:58 -0700 | [diff] [blame] | 1358 | // Event for a package becoming active due to an interaction. |
Dianne Hackborn | b6683c4 | 2015-06-18 17:40:33 -0700 | [diff] [blame] | 1359 | public static final int EVENT_PACKAGE_ACTIVE = 0x0010; |
Dianne Hackborn | fd854ee | 2015-07-13 18:00:37 -0700 | [diff] [blame] | 1360 | // Event for a package being on the temporary whitelist. |
| 1361 | public static final int EVENT_TEMP_WHITELIST = 0x0011; |
Dianne Hackborn | 280a64e | 2015-07-13 14:48:08 -0700 | [diff] [blame] | 1362 | // Event for the screen waking up. |
| 1363 | public static final int EVENT_SCREEN_WAKE_UP = 0x0012; |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 1364 | // Event for the UID that woke up the application processor. |
| 1365 | // Used for wakeups coming from WiFi, modem, etc. |
| 1366 | public static final int EVENT_WAKEUP_AP = 0x0013; |
Dianne Hackborn | d0db6f0 | 2016-07-18 14:14:20 -0700 | [diff] [blame] | 1367 | // Event for reporting that a specific partial wake lock has been held for a long duration. |
| 1368 | public static final int EVENT_LONG_WAKE_LOCK = 0x0014; |
Amith Yamasani | 6776849 | 2015-06-09 12:23:58 -0700 | [diff] [blame] | 1369 | |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 1370 | // Number of event types. |
Adam Lesinski | 041d917 | 2016-12-12 12:03:56 -0800 | [diff] [blame] | 1371 | public static final int EVENT_COUNT = 0x0016; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 1372 | // Mask to extract out only the type part of the event. |
| 1373 | 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] | 1374 | |
| 1375 | public static final int EVENT_PROC_START = EVENT_PROC | EVENT_FLAG_START; |
| 1376 | public static final int EVENT_PROC_FINISH = EVENT_PROC | EVENT_FLAG_FINISH; |
| 1377 | public static final int EVENT_FOREGROUND_START = EVENT_FOREGROUND | EVENT_FLAG_START; |
| 1378 | public static final int EVENT_FOREGROUND_FINISH = EVENT_FOREGROUND | EVENT_FLAG_FINISH; |
| 1379 | public static final int EVENT_TOP_START = EVENT_TOP | EVENT_FLAG_START; |
| 1380 | public static final int EVENT_TOP_FINISH = EVENT_TOP | EVENT_FLAG_FINISH; |
Dianne Hackborn | a1f1a3c | 2014-02-24 18:12:28 -0800 | [diff] [blame] | 1381 | public static final int EVENT_SYNC_START = EVENT_SYNC | EVENT_FLAG_START; |
| 1382 | public static final int EVENT_SYNC_FINISH = EVENT_SYNC | EVENT_FLAG_FINISH; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 1383 | public static final int EVENT_WAKE_LOCK_START = EVENT_WAKE_LOCK | EVENT_FLAG_START; |
| 1384 | 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] | 1385 | public static final int EVENT_JOB_START = EVENT_JOB | EVENT_FLAG_START; |
| 1386 | public static final int EVENT_JOB_FINISH = EVENT_JOB | EVENT_FLAG_FINISH; |
| 1387 | public static final int EVENT_USER_RUNNING_START = EVENT_USER_RUNNING | EVENT_FLAG_START; |
| 1388 | public static final int EVENT_USER_RUNNING_FINISH = EVENT_USER_RUNNING | EVENT_FLAG_FINISH; |
| 1389 | public static final int EVENT_USER_FOREGROUND_START = |
| 1390 | EVENT_USER_FOREGROUND | EVENT_FLAG_START; |
| 1391 | public static final int EVENT_USER_FOREGROUND_FINISH = |
| 1392 | EVENT_USER_FOREGROUND | EVENT_FLAG_FINISH; |
Dianne Hackborn | 1e38382 | 2015-04-10 14:02:33 -0700 | [diff] [blame] | 1393 | public static final int EVENT_ALARM_START = EVENT_ALARM | EVENT_FLAG_START; |
| 1394 | public static final int EVENT_ALARM_FINISH = EVENT_ALARM | EVENT_FLAG_FINISH; |
Dianne Hackborn | fd854ee | 2015-07-13 18:00:37 -0700 | [diff] [blame] | 1395 | public static final int EVENT_TEMP_WHITELIST_START = |
| 1396 | EVENT_TEMP_WHITELIST | EVENT_FLAG_START; |
| 1397 | public static final int EVENT_TEMP_WHITELIST_FINISH = |
| 1398 | EVENT_TEMP_WHITELIST | EVENT_FLAG_FINISH; |
Dianne Hackborn | d0db6f0 | 2016-07-18 14:14:20 -0700 | [diff] [blame] | 1399 | public static final int EVENT_LONG_WAKE_LOCK_START = |
| 1400 | EVENT_LONG_WAKE_LOCK | EVENT_FLAG_START; |
| 1401 | public static final int EVENT_LONG_WAKE_LOCK_FINISH = |
| 1402 | EVENT_LONG_WAKE_LOCK | EVENT_FLAG_FINISH; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1403 | |
| 1404 | // For CMD_EVENT. |
| 1405 | public int eventCode; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1406 | public HistoryTag eventTag; |
| 1407 | |
Dianne Hackborn | 9a75543 | 2014-05-15 17:05:22 -0700 | [diff] [blame] | 1408 | // 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] | 1409 | public long currentTime; |
| 1410 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1411 | // Meta-data when reading. |
| 1412 | public int numReadInts; |
| 1413 | |
| 1414 | // Pre-allocated objects. |
| 1415 | public final HistoryTag localWakelockTag = new HistoryTag(); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1416 | public final HistoryTag localWakeReasonTag = new HistoryTag(); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1417 | public final HistoryTag localEventTag = new HistoryTag(); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1418 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1419 | public HistoryItem() { |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1420 | } |
| 1421 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1422 | public HistoryItem(long time, Parcel src) { |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1423 | this.time = time; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1424 | numReadInts = 2; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 1425 | readFromParcel(src); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1426 | } |
| 1427 | |
| 1428 | public int describeContents() { |
| 1429 | return 0; |
| 1430 | } |
| 1431 | |
| 1432 | public void writeToParcel(Parcel dest, int flags) { |
| 1433 | dest.writeLong(time); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1434 | int bat = (((int)cmd)&0xff) |
| 1435 | | ((((int)batteryLevel)<<8)&0xff00) |
| 1436 | | ((((int)batteryStatus)<<16)&0xf0000) |
| 1437 | | ((((int)batteryHealth)<<20)&0xf00000) |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1438 | | ((((int)batteryPlugType)<<24)&0xf000000) |
| 1439 | | (wakelockTag != null ? 0x10000000 : 0) |
| 1440 | | (wakeReasonTag != null ? 0x20000000 : 0) |
| 1441 | | (eventCode != EVENT_NONE ? 0x40000000 : 0); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1442 | dest.writeInt(bat); |
| 1443 | bat = (((int)batteryTemperature)&0xffff) |
| 1444 | | ((((int)batteryVoltage)<<16)&0xffff0000); |
| 1445 | dest.writeInt(bat); |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 1446 | dest.writeInt(batteryChargeUAh); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1447 | dest.writeInt(states); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1448 | dest.writeInt(states2); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1449 | if (wakelockTag != null) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1450 | wakelockTag.writeToParcel(dest, flags); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1451 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1452 | if (wakeReasonTag != null) { |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1453 | wakeReasonTag.writeToParcel(dest, flags); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1454 | } |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 1455 | if (eventCode != EVENT_NONE) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1456 | dest.writeInt(eventCode); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1457 | eventTag.writeToParcel(dest, flags); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1458 | } |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 1459 | if (cmd == CMD_CURRENT_TIME || cmd == CMD_RESET) { |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1460 | dest.writeLong(currentTime); |
| 1461 | } |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1462 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 1463 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1464 | public void readFromParcel(Parcel src) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1465 | int start = src.dataPosition(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 1466 | int bat = src.readInt(); |
| 1467 | cmd = (byte)(bat&0xff); |
| 1468 | batteryLevel = (byte)((bat>>8)&0xff); |
| 1469 | batteryStatus = (byte)((bat>>16)&0xf); |
| 1470 | batteryHealth = (byte)((bat>>20)&0xf); |
| 1471 | batteryPlugType = (byte)((bat>>24)&0xf); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1472 | int bat2 = src.readInt(); |
| 1473 | batteryTemperature = (short)(bat2&0xffff); |
| 1474 | batteryVoltage = (char)((bat2>>16)&0xffff); |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 1475 | batteryChargeUAh = src.readInt(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 1476 | states = src.readInt(); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1477 | states2 = src.readInt(); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1478 | if ((bat&0x10000000) != 0) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1479 | wakelockTag = localWakelockTag; |
| 1480 | wakelockTag.readFromParcel(src); |
| 1481 | } else { |
| 1482 | wakelockTag = null; |
| 1483 | } |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1484 | if ((bat&0x20000000) != 0) { |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1485 | wakeReasonTag = localWakeReasonTag; |
| 1486 | wakeReasonTag.readFromParcel(src); |
| 1487 | } else { |
| 1488 | wakeReasonTag = null; |
| 1489 | } |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1490 | if ((bat&0x40000000) != 0) { |
| 1491 | eventCode = src.readInt(); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1492 | eventTag = localEventTag; |
| 1493 | eventTag.readFromParcel(src); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1494 | } else { |
| 1495 | eventCode = EVENT_NONE; |
| 1496 | eventTag = null; |
| 1497 | } |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 1498 | if (cmd == CMD_CURRENT_TIME || cmd == CMD_RESET) { |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1499 | currentTime = src.readLong(); |
| 1500 | } else { |
| 1501 | currentTime = 0; |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 1502 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1503 | numReadInts += (src.dataPosition()-start)/4; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 1504 | } |
| 1505 | |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 1506 | public void clear() { |
| 1507 | time = 0; |
| 1508 | cmd = CMD_NULL; |
| 1509 | batteryLevel = 0; |
| 1510 | batteryStatus = 0; |
| 1511 | batteryHealth = 0; |
| 1512 | batteryPlugType = 0; |
| 1513 | batteryTemperature = 0; |
| 1514 | batteryVoltage = 0; |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 1515 | batteryChargeUAh = 0; |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 1516 | states = 0; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1517 | states2 = 0; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1518 | wakelockTag = null; |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1519 | wakeReasonTag = null; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1520 | eventCode = EVENT_NONE; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1521 | eventTag = null; |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 1522 | } |
| 1523 | |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 1524 | public void setTo(HistoryItem o) { |
| 1525 | time = o.time; |
| 1526 | cmd = o.cmd; |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 1527 | setToCommon(o); |
| 1528 | } |
| 1529 | |
| 1530 | public void setTo(long time, byte cmd, HistoryItem o) { |
| 1531 | this.time = time; |
| 1532 | this.cmd = cmd; |
| 1533 | setToCommon(o); |
| 1534 | } |
| 1535 | |
| 1536 | private void setToCommon(HistoryItem o) { |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 1537 | batteryLevel = o.batteryLevel; |
| 1538 | batteryStatus = o.batteryStatus; |
| 1539 | batteryHealth = o.batteryHealth; |
| 1540 | batteryPlugType = o.batteryPlugType; |
| 1541 | batteryTemperature = o.batteryTemperature; |
| 1542 | batteryVoltage = o.batteryVoltage; |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 1543 | batteryChargeUAh = o.batteryChargeUAh; |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 1544 | states = o.states; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1545 | states2 = o.states2; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1546 | if (o.wakelockTag != null) { |
| 1547 | wakelockTag = localWakelockTag; |
| 1548 | wakelockTag.setTo(o.wakelockTag); |
| 1549 | } else { |
| 1550 | wakelockTag = null; |
| 1551 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1552 | if (o.wakeReasonTag != null) { |
| 1553 | wakeReasonTag = localWakeReasonTag; |
| 1554 | wakeReasonTag.setTo(o.wakeReasonTag); |
| 1555 | } else { |
| 1556 | wakeReasonTag = null; |
| 1557 | } |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1558 | eventCode = o.eventCode; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1559 | if (o.eventTag != null) { |
| 1560 | eventTag = localEventTag; |
| 1561 | eventTag.setTo(o.eventTag); |
| 1562 | } else { |
| 1563 | eventTag = null; |
| 1564 | } |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1565 | currentTime = o.currentTime; |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 1566 | } |
| 1567 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1568 | public boolean sameNonEvent(HistoryItem o) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 1569 | return batteryLevel == o.batteryLevel |
| 1570 | && batteryStatus == o.batteryStatus |
| 1571 | && batteryHealth == o.batteryHealth |
| 1572 | && batteryPlugType == o.batteryPlugType |
| 1573 | && batteryTemperature == o.batteryTemperature |
| 1574 | && batteryVoltage == o.batteryVoltage |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 1575 | && batteryChargeUAh == o.batteryChargeUAh |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1576 | && states == o.states |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1577 | && states2 == o.states2 |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1578 | && currentTime == o.currentTime; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 1579 | } |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1580 | |
| 1581 | public boolean same(HistoryItem o) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1582 | if (!sameNonEvent(o) || eventCode != o.eventCode) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1583 | return false; |
| 1584 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1585 | if (wakelockTag != o.wakelockTag) { |
| 1586 | if (wakelockTag == null || o.wakelockTag == null) { |
| 1587 | return false; |
| 1588 | } |
| 1589 | if (!wakelockTag.equals(o.wakelockTag)) { |
| 1590 | return false; |
| 1591 | } |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1592 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1593 | if (wakeReasonTag != o.wakeReasonTag) { |
| 1594 | if (wakeReasonTag == null || o.wakeReasonTag == null) { |
| 1595 | return false; |
| 1596 | } |
| 1597 | if (!wakeReasonTag.equals(o.wakeReasonTag)) { |
| 1598 | return false; |
| 1599 | } |
| 1600 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1601 | if (eventTag != o.eventTag) { |
| 1602 | if (eventTag == null || o.eventTag == null) { |
| 1603 | return false; |
| 1604 | } |
| 1605 | if (!eventTag.equals(o.eventTag)) { |
| 1606 | return false; |
| 1607 | } |
| 1608 | } |
| 1609 | return true; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1610 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1611 | } |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 1612 | |
| 1613 | public final static class HistoryEventTracker { |
| 1614 | private final HashMap<String, SparseIntArray>[] mActiveEvents |
| 1615 | = (HashMap<String, SparseIntArray>[]) new HashMap[HistoryItem.EVENT_COUNT]; |
| 1616 | |
| 1617 | public boolean updateState(int code, String name, int uid, int poolIdx) { |
| 1618 | if ((code&HistoryItem.EVENT_FLAG_START) != 0) { |
| 1619 | int idx = code&HistoryItem.EVENT_TYPE_MASK; |
| 1620 | HashMap<String, SparseIntArray> active = mActiveEvents[idx]; |
| 1621 | if (active == null) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 1622 | active = new HashMap<>(); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 1623 | mActiveEvents[idx] = active; |
| 1624 | } |
| 1625 | SparseIntArray uids = active.get(name); |
| 1626 | if (uids == null) { |
| 1627 | uids = new SparseIntArray(); |
| 1628 | active.put(name, uids); |
| 1629 | } |
| 1630 | if (uids.indexOfKey(uid) >= 0) { |
| 1631 | // Already set, nothing to do! |
| 1632 | return false; |
| 1633 | } |
| 1634 | uids.put(uid, poolIdx); |
| 1635 | } else if ((code&HistoryItem.EVENT_FLAG_FINISH) != 0) { |
| 1636 | int idx = code&HistoryItem.EVENT_TYPE_MASK; |
| 1637 | HashMap<String, SparseIntArray> active = mActiveEvents[idx]; |
| 1638 | if (active == null) { |
| 1639 | // not currently active, nothing to do. |
| 1640 | return false; |
| 1641 | } |
| 1642 | SparseIntArray uids = active.get(name); |
| 1643 | if (uids == null) { |
| 1644 | // not currently active, nothing to do. |
| 1645 | return false; |
| 1646 | } |
| 1647 | idx = uids.indexOfKey(uid); |
| 1648 | if (idx < 0) { |
| 1649 | // not currently active, nothing to do. |
| 1650 | return false; |
| 1651 | } |
| 1652 | uids.removeAt(idx); |
| 1653 | if (uids.size() <= 0) { |
| 1654 | active.remove(name); |
| 1655 | } |
| 1656 | } |
| 1657 | return true; |
| 1658 | } |
| 1659 | |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 1660 | public void removeEvents(int code) { |
| 1661 | int idx = code&HistoryItem.EVENT_TYPE_MASK; |
| 1662 | mActiveEvents[idx] = null; |
| 1663 | } |
| 1664 | |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 1665 | public HashMap<String, SparseIntArray> getStateForEvent(int code) { |
| 1666 | return mActiveEvents[code]; |
| 1667 | } |
| 1668 | } |
| 1669 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1670 | public static final class BitDescription { |
| 1671 | public final int mask; |
| 1672 | public final int shift; |
| 1673 | public final String name; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1674 | public final String shortName; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1675 | public final String[] values; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1676 | public final String[] shortValues; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1677 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1678 | public BitDescription(int mask, String name, String shortName) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1679 | this.mask = mask; |
| 1680 | this.shift = -1; |
| 1681 | this.name = name; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1682 | this.shortName = shortName; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1683 | this.values = null; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1684 | this.shortValues = null; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1685 | } |
| 1686 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1687 | public BitDescription(int mask, int shift, String name, String shortName, |
| 1688 | String[] values, String[] shortValues) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1689 | this.mask = mask; |
| 1690 | this.shift = shift; |
| 1691 | this.name = name; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1692 | this.shortName = shortName; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1693 | this.values = values; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1694 | this.shortValues = shortValues; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1695 | } |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1696 | } |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 1697 | |
Dianne Hackborn | fc06413 | 2014-06-02 12:42:12 -0700 | [diff] [blame] | 1698 | /** |
| 1699 | * Don't allow any more batching in to the current history event. This |
| 1700 | * is called when printing partial histories, so to ensure that the next |
| 1701 | * history event will go in to a new batch after what was printed in the |
| 1702 | * last partial history. |
| 1703 | */ |
| 1704 | public abstract void commitCurrentHistoryBatchLocked(); |
| 1705 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1706 | public abstract int getHistoryTotalSize(); |
| 1707 | |
| 1708 | public abstract int getHistoryUsedSize(); |
| 1709 | |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 1710 | public abstract boolean startIteratingHistoryLocked(); |
| 1711 | |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 1712 | public abstract int getHistoryStringPoolSize(); |
| 1713 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1714 | public abstract int getHistoryStringPoolBytes(); |
| 1715 | |
| 1716 | public abstract String getHistoryTagPoolString(int index); |
| 1717 | |
| 1718 | public abstract int getHistoryTagPoolUid(int index); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 1719 | |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 1720 | public abstract boolean getNextHistoryLocked(HistoryItem out); |
| 1721 | |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 1722 | public abstract void finishIteratingHistoryLocked(); |
| 1723 | |
| 1724 | public abstract boolean startIteratingOldHistoryLocked(); |
| 1725 | |
| 1726 | public abstract boolean getNextOldHistoryLocked(HistoryItem out); |
| 1727 | |
| 1728 | public abstract void finishIteratingOldHistoryLocked(); |
| 1729 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1730 | /** |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 1731 | * Return the base time offset for the battery history. |
| 1732 | */ |
| 1733 | public abstract long getHistoryBaseTime(); |
| 1734 | |
| 1735 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1736 | * Returns the number of times the device has been started. |
| 1737 | */ |
| 1738 | public abstract int getStartCount(); |
| 1739 | |
| 1740 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 1741 | * 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] | 1742 | * running on battery. |
| 1743 | * |
| 1744 | * {@hide} |
| 1745 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1746 | public abstract long getScreenOnTime(long elapsedRealtimeUs, int which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1747 | |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 1748 | /** |
| 1749 | * Returns the number of times the screen was turned on. |
| 1750 | * |
| 1751 | * {@hide} |
| 1752 | */ |
| 1753 | public abstract int getScreenOnCount(int which); |
| 1754 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 1755 | public abstract long getInteractiveTime(long elapsedRealtimeUs, int which); |
| 1756 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1757 | public static final int SCREEN_BRIGHTNESS_DARK = 0; |
| 1758 | public static final int SCREEN_BRIGHTNESS_DIM = 1; |
| 1759 | public static final int SCREEN_BRIGHTNESS_MEDIUM = 2; |
| 1760 | public static final int SCREEN_BRIGHTNESS_LIGHT = 3; |
| 1761 | public static final int SCREEN_BRIGHTNESS_BRIGHT = 4; |
| 1762 | |
| 1763 | static final String[] SCREEN_BRIGHTNESS_NAMES = { |
| 1764 | "dark", "dim", "medium", "light", "bright" |
| 1765 | }; |
| 1766 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1767 | static final String[] SCREEN_BRIGHTNESS_SHORT_NAMES = { |
| 1768 | "0", "1", "2", "3", "4" |
| 1769 | }; |
| 1770 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1771 | public static final int NUM_SCREEN_BRIGHTNESS_BINS = 5; |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 1772 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1773 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 1774 | * Returns the time in microseconds that the screen has been on with |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1775 | * the given brightness |
| 1776 | * |
| 1777 | * {@hide} |
| 1778 | */ |
| 1779 | public abstract long getScreenBrightnessTime(int brightnessBin, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1780 | long elapsedRealtimeUs, int which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1781 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1782 | /** |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 1783 | * 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] | 1784 | * running on battery. |
| 1785 | * |
| 1786 | * {@hide} |
| 1787 | */ |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 1788 | public abstract long getPowerSaveModeEnabledTime(long elapsedRealtimeUs, int which); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 1789 | |
| 1790 | /** |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 1791 | * Returns the number of times that power save mode was enabled. |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 1792 | * |
| 1793 | * {@hide} |
| 1794 | */ |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 1795 | public abstract int getPowerSaveModeEnabledCount(int which); |
| 1796 | |
| 1797 | /** |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 1798 | * Constant for device idle mode: not active. |
| 1799 | */ |
| 1800 | public static final int DEVICE_IDLE_MODE_OFF = 0; |
| 1801 | |
| 1802 | /** |
| 1803 | * Constant for device idle mode: active in lightweight mode. |
| 1804 | */ |
| 1805 | public static final int DEVICE_IDLE_MODE_LIGHT = 1; |
| 1806 | |
| 1807 | /** |
| 1808 | * Constant for device idle mode: active in full mode. |
| 1809 | */ |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 1810 | public static final int DEVICE_IDLE_MODE_DEEP = 2; |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 1811 | |
| 1812 | /** |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 1813 | * Returns the time in microseconds that device has been in idle mode while |
| 1814 | * running on battery. |
| 1815 | * |
| 1816 | * {@hide} |
| 1817 | */ |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 1818 | public abstract long getDeviceIdleModeTime(int mode, long elapsedRealtimeUs, int which); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 1819 | |
| 1820 | /** |
| 1821 | * Returns the number of times that the devie has gone in to idle mode. |
| 1822 | * |
| 1823 | * {@hide} |
| 1824 | */ |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 1825 | public abstract int getDeviceIdleModeCount(int mode, int which); |
| 1826 | |
| 1827 | /** |
| 1828 | * Return the longest duration we spent in a particular device idle mode (fully in the |
| 1829 | * mode, not in idle maintenance etc). |
| 1830 | */ |
| 1831 | public abstract long getLongestDeviceIdleModeTime(int mode); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 1832 | |
| 1833 | /** |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 1834 | * 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] | 1835 | * battery. This is broader than {@link #getDeviceIdleModeTime} -- it |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 1836 | * counts all of the time that we consider the device to be idle, whether or not |
| 1837 | * it is currently in the actual device idle mode. |
| 1838 | * |
| 1839 | * {@hide} |
| 1840 | */ |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 1841 | public abstract long getDeviceIdlingTime(int mode, long elapsedRealtimeUs, int which); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 1842 | |
| 1843 | /** |
| 1844 | * Returns the number of times that the devie has started idling. |
| 1845 | * |
| 1846 | * {@hide} |
| 1847 | */ |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 1848 | public abstract int getDeviceIdlingCount(int mode, int which); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 1849 | |
| 1850 | /** |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 1851 | * Returns the number of times that connectivity state changed. |
| 1852 | * |
| 1853 | * {@hide} |
| 1854 | */ |
| 1855 | public abstract int getNumConnectivityChange(int which); |
| 1856 | |
| 1857 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 1858 | * 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] | 1859 | * running on battery. |
| 1860 | * |
| 1861 | * {@hide} |
| 1862 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1863 | public abstract long getPhoneOnTime(long elapsedRealtimeUs, int which); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 1864 | |
| 1865 | /** |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 1866 | * Returns the number of times a phone call was activated. |
| 1867 | * |
| 1868 | * {@hide} |
| 1869 | */ |
| 1870 | public abstract int getPhoneOnCount(int which); |
| 1871 | |
| 1872 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 1873 | * Returns the time in microseconds that the phone has been running with |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 1874 | * the given signal strength. |
| 1875 | * |
| 1876 | * {@hide} |
| 1877 | */ |
| 1878 | public abstract long getPhoneSignalStrengthTime(int strengthBin, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1879 | long elapsedRealtimeUs, int which); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 1880 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1881 | /** |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 1882 | * Returns the time in microseconds that the phone has been trying to |
| 1883 | * acquire a signal. |
| 1884 | * |
| 1885 | * {@hide} |
| 1886 | */ |
| 1887 | public abstract long getPhoneSignalScanningTime( |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1888 | long elapsedRealtimeUs, int which); |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 1889 | |
| 1890 | /** |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1891 | * Returns the number of times the phone has entered the given signal strength. |
| 1892 | * |
| 1893 | * {@hide} |
| 1894 | */ |
| 1895 | public abstract int getPhoneSignalStrengthCount(int strengthBin, int which); |
| 1896 | |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 1897 | /** |
| 1898 | * Returns the time in microseconds that the mobile network has been active |
| 1899 | * (in a high power state). |
| 1900 | * |
| 1901 | * {@hide} |
| 1902 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1903 | public abstract long getMobileRadioActiveTime(long elapsedRealtimeUs, int which); |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 1904 | |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 1905 | /** |
| 1906 | * Returns the number of times that the mobile network has transitioned to the |
| 1907 | * active state. |
| 1908 | * |
| 1909 | * {@hide} |
| 1910 | */ |
| 1911 | public abstract int getMobileRadioActiveCount(int which); |
| 1912 | |
| 1913 | /** |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1914 | * Returns the time in microseconds that is the difference between the mobile radio |
| 1915 | * time we saw based on the elapsed timestamp when going down vs. the given time stamp |
| 1916 | * from the radio. |
| 1917 | * |
| 1918 | * {@hide} |
| 1919 | */ |
| 1920 | public abstract long getMobileRadioActiveAdjustedTime(int which); |
| 1921 | |
| 1922 | /** |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 1923 | * Returns the time in microseconds that the mobile network has been active |
| 1924 | * (in a high power state) but not being able to blame on an app. |
| 1925 | * |
| 1926 | * {@hide} |
| 1927 | */ |
| 1928 | public abstract long getMobileRadioActiveUnknownTime(int which); |
| 1929 | |
| 1930 | /** |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 1931 | * 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] | 1932 | * |
| 1933 | * {@hide} |
| 1934 | */ |
| 1935 | public abstract int getMobileRadioActiveUnknownCount(int which); |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 1936 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 1937 | public static final int DATA_CONNECTION_NONE = 0; |
| 1938 | public static final int DATA_CONNECTION_GPRS = 1; |
| 1939 | public static final int DATA_CONNECTION_EDGE = 2; |
| 1940 | public static final int DATA_CONNECTION_UMTS = 3; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1941 | public static final int DATA_CONNECTION_CDMA = 4; |
| 1942 | public static final int DATA_CONNECTION_EVDO_0 = 5; |
| 1943 | public static final int DATA_CONNECTION_EVDO_A = 6; |
| 1944 | public static final int DATA_CONNECTION_1xRTT = 7; |
| 1945 | public static final int DATA_CONNECTION_HSDPA = 8; |
| 1946 | public static final int DATA_CONNECTION_HSUPA = 9; |
| 1947 | public static final int DATA_CONNECTION_HSPA = 10; |
| 1948 | public static final int DATA_CONNECTION_IDEN = 11; |
| 1949 | public static final int DATA_CONNECTION_EVDO_B = 12; |
Robert Greenwalt | 962a990 | 2010-11-02 11:10:25 -0700 | [diff] [blame] | 1950 | public static final int DATA_CONNECTION_LTE = 13; |
| 1951 | public static final int DATA_CONNECTION_EHRPD = 14; |
Patrick Tjin | b71703c | 2013-11-06 09:27:03 -0800 | [diff] [blame] | 1952 | public static final int DATA_CONNECTION_HSPAP = 15; |
| 1953 | public static final int DATA_CONNECTION_OTHER = 16; |
Robert Greenwalt | 962a990 | 2010-11-02 11:10:25 -0700 | [diff] [blame] | 1954 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 1955 | static final String[] DATA_CONNECTION_NAMES = { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1956 | "none", "gprs", "edge", "umts", "cdma", "evdo_0", "evdo_A", |
Robert Greenwalt | 962a990 | 2010-11-02 11:10:25 -0700 | [diff] [blame] | 1957 | "1xrtt", "hsdpa", "hsupa", "hspa", "iden", "evdo_b", "lte", |
Patrick Tjin | b71703c | 2013-11-06 09:27:03 -0800 | [diff] [blame] | 1958 | "ehrpd", "hspap", "other" |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 1959 | }; |
| 1960 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1961 | public static final int NUM_DATA_CONNECTION_TYPES = DATA_CONNECTION_OTHER+1; |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 1962 | |
| 1963 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 1964 | * Returns the time in microseconds that the phone has been running with |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 1965 | * the given data connection. |
| 1966 | * |
| 1967 | * {@hide} |
| 1968 | */ |
| 1969 | public abstract long getPhoneDataConnectionTime(int dataType, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1970 | long elapsedRealtimeUs, int which); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 1971 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1972 | /** |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1973 | * Returns the number of times the phone has entered the given data |
| 1974 | * connection type. |
| 1975 | * |
| 1976 | * {@hide} |
| 1977 | */ |
| 1978 | public abstract int getPhoneDataConnectionCount(int dataType, int which); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1979 | |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 1980 | public static final int WIFI_SUPPL_STATE_INVALID = 0; |
| 1981 | public static final int WIFI_SUPPL_STATE_DISCONNECTED = 1; |
| 1982 | public static final int WIFI_SUPPL_STATE_INTERFACE_DISABLED = 2; |
| 1983 | public static final int WIFI_SUPPL_STATE_INACTIVE = 3; |
| 1984 | public static final int WIFI_SUPPL_STATE_SCANNING = 4; |
| 1985 | public static final int WIFI_SUPPL_STATE_AUTHENTICATING = 5; |
| 1986 | public static final int WIFI_SUPPL_STATE_ASSOCIATING = 6; |
| 1987 | public static final int WIFI_SUPPL_STATE_ASSOCIATED = 7; |
| 1988 | public static final int WIFI_SUPPL_STATE_FOUR_WAY_HANDSHAKE = 8; |
| 1989 | public static final int WIFI_SUPPL_STATE_GROUP_HANDSHAKE = 9; |
| 1990 | public static final int WIFI_SUPPL_STATE_COMPLETED = 10; |
| 1991 | public static final int WIFI_SUPPL_STATE_DORMANT = 11; |
| 1992 | public static final int WIFI_SUPPL_STATE_UNINITIALIZED = 12; |
| 1993 | |
| 1994 | public static final int NUM_WIFI_SUPPL_STATES = WIFI_SUPPL_STATE_UNINITIALIZED+1; |
| 1995 | |
| 1996 | static final String[] WIFI_SUPPL_STATE_NAMES = { |
| 1997 | "invalid", "disconn", "disabled", "inactive", "scanning", |
| 1998 | "authenticating", "associating", "associated", "4-way-handshake", |
| 1999 | "group-handshake", "completed", "dormant", "uninit" |
| 2000 | }; |
| 2001 | |
| 2002 | static final String[] WIFI_SUPPL_STATE_SHORT_NAMES = { |
| 2003 | "inv", "dsc", "dis", "inact", "scan", |
| 2004 | "auth", "ascing", "asced", "4-way", |
| 2005 | "group", "compl", "dorm", "uninit" |
| 2006 | }; |
| 2007 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2008 | public static final BitDescription[] HISTORY_STATE_DESCRIPTIONS |
| 2009 | = new BitDescription[] { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2010 | new BitDescription(HistoryItem.STATE_CPU_RUNNING_FLAG, "running", "r"), |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2011 | new BitDescription(HistoryItem.STATE_WAKE_LOCK_FLAG, "wake_lock", "w"), |
| 2012 | new BitDescription(HistoryItem.STATE_SENSOR_ON_FLAG, "sensor", "s"), |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2013 | new BitDescription(HistoryItem.STATE_GPS_ON_FLAG, "gps", "g"), |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2014 | new BitDescription(HistoryItem.STATE_WIFI_FULL_LOCK_FLAG, "wifi_full_lock", "Wl"), |
| 2015 | new BitDescription(HistoryItem.STATE_WIFI_SCAN_FLAG, "wifi_scan", "Ws"), |
| 2016 | new BitDescription(HistoryItem.STATE_WIFI_MULTICAST_ON_FLAG, "wifi_multicast", "Wm"), |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 2017 | new BitDescription(HistoryItem.STATE_WIFI_RADIO_ACTIVE_FLAG, "wifi_radio", "Wr"), |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 2018 | new BitDescription(HistoryItem.STATE_MOBILE_RADIO_ACTIVE_FLAG, "mobile_radio", "Pr"), |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2019 | new BitDescription(HistoryItem.STATE_PHONE_SCANNING_FLAG, "phone_scanning", "Psc"), |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2020 | new BitDescription(HistoryItem.STATE_AUDIO_ON_FLAG, "audio", "a"), |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2021 | new BitDescription(HistoryItem.STATE_SCREEN_ON_FLAG, "screen", "S"), |
| 2022 | new BitDescription(HistoryItem.STATE_BATTERY_PLUGGED_FLAG, "plugged", "BP"), |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2023 | new BitDescription(HistoryItem.STATE_DATA_CONNECTION_MASK, |
| 2024 | HistoryItem.STATE_DATA_CONNECTION_SHIFT, "data_conn", "Pcn", |
| 2025 | DATA_CONNECTION_NAMES, DATA_CONNECTION_NAMES), |
| 2026 | new BitDescription(HistoryItem.STATE_PHONE_STATE_MASK, |
| 2027 | HistoryItem.STATE_PHONE_STATE_SHIFT, "phone_state", "Pst", |
| 2028 | new String[] {"in", "out", "emergency", "off"}, |
| 2029 | new String[] {"in", "out", "em", "off"}), |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 2030 | new BitDescription(HistoryItem.STATE_PHONE_SIGNAL_STRENGTH_MASK, |
| 2031 | HistoryItem.STATE_PHONE_SIGNAL_STRENGTH_SHIFT, "phone_signal_strength", "Pss", |
| 2032 | SignalStrength.SIGNAL_STRENGTH_NAMES, |
| 2033 | new String[] { "0", "1", "2", "3", "4" }), |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2034 | new BitDescription(HistoryItem.STATE_BRIGHTNESS_MASK, |
| 2035 | HistoryItem.STATE_BRIGHTNESS_SHIFT, "brightness", "Sb", |
| 2036 | SCREEN_BRIGHTNESS_NAMES, SCREEN_BRIGHTNESS_SHORT_NAMES), |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2037 | }; |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2038 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2039 | public static final BitDescription[] HISTORY_STATE2_DESCRIPTIONS |
| 2040 | = new BitDescription[] { |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 2041 | new BitDescription(HistoryItem.STATE2_POWER_SAVE_FLAG, "power_save", "ps"), |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 2042 | new BitDescription(HistoryItem.STATE2_VIDEO_ON_FLAG, "video", "v"), |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 2043 | new BitDescription(HistoryItem.STATE2_WIFI_RUNNING_FLAG, "wifi_running", "Ww"), |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 2044 | new BitDescription(HistoryItem.STATE2_WIFI_ON_FLAG, "wifi", "W"), |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 2045 | new BitDescription(HistoryItem.STATE2_FLASHLIGHT_FLAG, "flashlight", "fl"), |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 2046 | new BitDescription(HistoryItem.STATE2_DEVICE_IDLE_MASK, |
| 2047 | HistoryItem.STATE2_DEVICE_IDLE_SHIFT, "device_idle", "di", |
| 2048 | new String[] { "off", "light", "full", "???" }, |
| 2049 | new String[] { "off", "light", "full", "???" }), |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 2050 | new BitDescription(HistoryItem.STATE2_CHARGING_FLAG, "charging", "ch"), |
| 2051 | new BitDescription(HistoryItem.STATE2_PHONE_IN_CALL_FLAG, "phone_in_call", "Pcl"), |
| 2052 | new BitDescription(HistoryItem.STATE2_BLUETOOTH_ON_FLAG, "bluetooth", "b"), |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 2053 | new BitDescription(HistoryItem.STATE2_WIFI_SIGNAL_STRENGTH_MASK, |
| 2054 | HistoryItem.STATE2_WIFI_SIGNAL_STRENGTH_SHIFT, "wifi_signal_strength", "Wss", |
| 2055 | new String[] { "0", "1", "2", "3", "4" }, |
| 2056 | new String[] { "0", "1", "2", "3", "4" }), |
| 2057 | new BitDescription(HistoryItem.STATE2_WIFI_SUPPL_STATE_MASK, |
| 2058 | HistoryItem.STATE2_WIFI_SUPPL_STATE_SHIFT, "wifi_suppl", "Wsp", |
| 2059 | WIFI_SUPPL_STATE_NAMES, WIFI_SUPPL_STATE_SHORT_NAMES), |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 2060 | new BitDescription(HistoryItem.STATE2_CAMERA_FLAG, "camera", "ca"), |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 2061 | new BitDescription(HistoryItem.STATE2_BLUETOOTH_SCAN_FLAG, "ble_scan", "bles"), |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2062 | }; |
| 2063 | |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 2064 | public static final String[] HISTORY_EVENT_NAMES = new String[] { |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 2065 | "null", "proc", "fg", "top", "sync", "wake_lock_in", "job", "user", "userfg", "conn", |
Kweku Adams | 134c59b | 2017-03-08 16:48:01 -0800 | [diff] [blame] | 2066 | "active", "pkginst", "pkgunin", "alarm", "stats", "pkginactive", "pkgactive", |
| 2067 | "tmpwhitelist", "screenwake", "wakeupap", "longwake", "est_capacity" |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 2068 | }; |
| 2069 | |
| 2070 | public static final String[] HISTORY_EVENT_CHECKIN_NAMES = new String[] { |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 2071 | "Enl", "Epr", "Efg", "Etp", "Esy", "Ewl", "Ejb", "Eur", "Euf", "Ecn", |
Dianne Hackborn | 280a64e | 2015-07-13 14:48:08 -0700 | [diff] [blame] | 2072 | "Eac", "Epi", "Epu", "Eal", "Est", "Eai", "Eaa", "Etw", |
Adam Lesinski | 041d917 | 2016-12-12 12:03:56 -0800 | [diff] [blame] | 2073 | "Esw", "Ewa", "Elw", "Eec" |
| 2074 | }; |
| 2075 | |
| 2076 | @FunctionalInterface |
| 2077 | public interface IntToString { |
| 2078 | String applyAsString(int val); |
| 2079 | } |
| 2080 | |
| 2081 | private static final IntToString sUidToString = UserHandle::formatUid; |
| 2082 | private static final IntToString sIntToString = Integer::toString; |
| 2083 | |
| 2084 | public static final IntToString[] HISTORY_EVENT_INT_FORMATTERS = new IntToString[] { |
| 2085 | sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, |
| 2086 | sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, |
| 2087 | sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, |
| 2088 | sUidToString, sUidToString, sUidToString, sIntToString |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 2089 | }; |
| 2090 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2091 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 2092 | * 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] | 2093 | * running on battery. |
| 2094 | * |
| 2095 | * {@hide} |
| 2096 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2097 | public abstract long getWifiOnTime(long elapsedRealtimeUs, int which); |
Eric Shienbrood | d4c5f89 | 2009-03-24 18:13:20 -0700 | [diff] [blame] | 2098 | |
| 2099 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 2100 | * 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] | 2101 | * been in the running state while the device was running on battery. |
| 2102 | * |
| 2103 | * {@hide} |
| 2104 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2105 | public abstract long getGlobalWifiRunningTime(long elapsedRealtimeUs, int which); |
Eric Shienbrood | d4c5f89 | 2009-03-24 18:13:20 -0700 | [diff] [blame] | 2106 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 2107 | public static final int WIFI_STATE_OFF = 0; |
| 2108 | public static final int WIFI_STATE_OFF_SCANNING = 1; |
| 2109 | public static final int WIFI_STATE_ON_NO_NETWORKS = 2; |
| 2110 | public static final int WIFI_STATE_ON_DISCONNECTED = 3; |
| 2111 | public static final int WIFI_STATE_ON_CONNECTED_STA = 4; |
| 2112 | public static final int WIFI_STATE_ON_CONNECTED_P2P = 5; |
| 2113 | public static final int WIFI_STATE_ON_CONNECTED_STA_P2P = 6; |
| 2114 | public static final int WIFI_STATE_SOFT_AP = 7; |
| 2115 | |
| 2116 | static final String[] WIFI_STATE_NAMES = { |
| 2117 | "off", "scanning", "no_net", "disconn", |
| 2118 | "sta", "p2p", "sta_p2p", "soft_ap" |
| 2119 | }; |
| 2120 | |
| 2121 | public static final int NUM_WIFI_STATES = WIFI_STATE_SOFT_AP+1; |
| 2122 | |
| 2123 | /** |
| 2124 | * Returns the time in microseconds that WiFi has been running in the given state. |
| 2125 | * |
| 2126 | * {@hide} |
| 2127 | */ |
| 2128 | public abstract long getWifiStateTime(int wifiState, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2129 | long elapsedRealtimeUs, int which); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 2130 | |
| 2131 | /** |
| 2132 | * Returns the number of times that WiFi has entered the given state. |
| 2133 | * |
| 2134 | * {@hide} |
| 2135 | */ |
| 2136 | public abstract int getWifiStateCount(int wifiState, int which); |
| 2137 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2138 | /** |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 2139 | * Returns the time in microseconds that the wifi supplicant has been |
| 2140 | * in a given state. |
| 2141 | * |
| 2142 | * {@hide} |
| 2143 | */ |
| 2144 | public abstract long getWifiSupplStateTime(int state, long elapsedRealtimeUs, int which); |
| 2145 | |
| 2146 | /** |
| 2147 | * Returns the number of times that the wifi supplicant has transitioned |
| 2148 | * to a given state. |
| 2149 | * |
| 2150 | * {@hide} |
| 2151 | */ |
| 2152 | public abstract int getWifiSupplStateCount(int state, int which); |
| 2153 | |
| 2154 | public static final int NUM_WIFI_SIGNAL_STRENGTH_BINS = 5; |
| 2155 | |
| 2156 | /** |
| 2157 | * Returns the time in microseconds that WIFI has been running with |
| 2158 | * the given signal strength. |
| 2159 | * |
| 2160 | * {@hide} |
| 2161 | */ |
| 2162 | public abstract long getWifiSignalStrengthTime(int strengthBin, |
| 2163 | long elapsedRealtimeUs, int which); |
| 2164 | |
| 2165 | /** |
| 2166 | * Returns the number of times WIFI has entered the given signal strength. |
| 2167 | * |
| 2168 | * {@hide} |
| 2169 | */ |
| 2170 | public abstract int getWifiSignalStrengthCount(int strengthBin, int which); |
| 2171 | |
| 2172 | /** |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 2173 | * Returns the time in microseconds that the flashlight has been on while the device was |
| 2174 | * running on battery. |
| 2175 | * |
| 2176 | * {@hide} |
| 2177 | */ |
| 2178 | public abstract long getFlashlightOnTime(long elapsedRealtimeUs, int which); |
| 2179 | |
| 2180 | /** |
| 2181 | * Returns the number of times that the flashlight has been turned on while the device was |
| 2182 | * running on battery. |
| 2183 | * |
| 2184 | * {@hide} |
| 2185 | */ |
| 2186 | public abstract long getFlashlightOnCount(int which); |
| 2187 | |
Ruben Brunk | 5b1308f | 2015-06-03 18:49:27 -0700 | [diff] [blame] | 2188 | /** |
| 2189 | * Returns the time in microseconds that the camera has been on while the device was |
| 2190 | * running on battery. |
| 2191 | * |
| 2192 | * {@hide} |
| 2193 | */ |
| 2194 | public abstract long getCameraOnTime(long elapsedRealtimeUs, int which); |
| 2195 | |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 2196 | /** |
| 2197 | * Returns the time in microseconds that bluetooth scans were running while the device was |
| 2198 | * on battery. |
| 2199 | * |
| 2200 | * {@hide} |
| 2201 | */ |
| 2202 | public abstract long getBluetoothScanTime(long elapsedRealtimeUs, int which); |
Ruben Brunk | 5b1308f | 2015-06-03 18:49:27 -0700 | [diff] [blame] | 2203 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2204 | public static final int NETWORK_MOBILE_RX_DATA = 0; |
| 2205 | public static final int NETWORK_MOBILE_TX_DATA = 1; |
| 2206 | public static final int NETWORK_WIFI_RX_DATA = 2; |
| 2207 | public static final int NETWORK_WIFI_TX_DATA = 3; |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 2208 | public static final int NETWORK_BT_RX_DATA = 4; |
| 2209 | public static final int NETWORK_BT_TX_DATA = 5; |
Amith Yamasani | 59fe841 | 2017-03-03 16:28:52 -0800 | [diff] [blame] | 2210 | public static final int NETWORK_MOBILE_BG_RX_DATA = 6; |
| 2211 | public static final int NETWORK_MOBILE_BG_TX_DATA = 7; |
| 2212 | public static final int NETWORK_WIFI_BG_RX_DATA = 8; |
| 2213 | public static final int NETWORK_WIFI_BG_TX_DATA = 9; |
| 2214 | 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] | 2215 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2216 | public abstract long getNetworkActivityBytes(int type, int which); |
| 2217 | public abstract long getNetworkActivityPackets(int type, int which); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 2218 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 2219 | /** |
Adam Lesinski | 1739076 | 2015-04-10 13:17:47 -0700 | [diff] [blame] | 2220 | * Returns true if the BatteryStats object has detailed WiFi power reports. |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 2221 | * When true, calling {@link #getWifiControllerActivity()} will yield the |
Adam Lesinski | 1739076 | 2015-04-10 13:17:47 -0700 | [diff] [blame] | 2222 | * actual power data. |
| 2223 | */ |
| 2224 | public abstract boolean hasWifiActivityReporting(); |
| 2225 | |
| 2226 | /** |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 2227 | * Returns a {@link ControllerActivityCounter} which is an aggregate of the times spent |
| 2228 | * in various radio controller states, such as transmit, receive, and idle. |
| 2229 | * @return non-null {@link ControllerActivityCounter} |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 2230 | */ |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 2231 | public abstract ControllerActivityCounter getWifiControllerActivity(); |
| 2232 | |
| 2233 | /** |
| 2234 | * Returns true if the BatteryStats object has detailed bluetooth power reports. |
| 2235 | * When true, calling {@link #getBluetoothControllerActivity()} will yield the |
| 2236 | * actual power data. |
| 2237 | */ |
| 2238 | public abstract boolean hasBluetoothActivityReporting(); |
| 2239 | |
| 2240 | /** |
| 2241 | * Returns a {@link ControllerActivityCounter} which is an aggregate of the times spent |
| 2242 | * in various radio controller states, such as transmit, receive, and idle. |
| 2243 | * @return non-null {@link ControllerActivityCounter} |
| 2244 | */ |
| 2245 | public abstract ControllerActivityCounter getBluetoothControllerActivity(); |
| 2246 | |
| 2247 | /** |
| 2248 | * Returns true if the BatteryStats object has detailed modem power reports. |
| 2249 | * When true, calling {@link #getModemControllerActivity()} will yield the |
| 2250 | * actual power data. |
| 2251 | */ |
| 2252 | public abstract boolean hasModemActivityReporting(); |
| 2253 | |
| 2254 | /** |
| 2255 | * Returns a {@link ControllerActivityCounter} which is an aggregate of the times spent |
| 2256 | * in various radio controller states, such as transmit, receive, and idle. |
| 2257 | * @return non-null {@link ControllerActivityCounter} |
| 2258 | */ |
| 2259 | public abstract ControllerActivityCounter getModemControllerActivity(); |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 2260 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2261 | /** |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 2262 | * Return the wall clock time when battery stats data collection started. |
| 2263 | */ |
| 2264 | public abstract long getStartClockTime(); |
| 2265 | |
| 2266 | /** |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 2267 | * Return platform version tag that we were running in when the battery stats started. |
| 2268 | */ |
| 2269 | public abstract String getStartPlatformVersion(); |
| 2270 | |
| 2271 | /** |
| 2272 | * Return platform version tag that we were running in when the battery stats ended. |
| 2273 | */ |
| 2274 | public abstract String getEndPlatformVersion(); |
| 2275 | |
| 2276 | /** |
| 2277 | * Return the internal version code of the parcelled format. |
| 2278 | */ |
| 2279 | public abstract int getParcelVersion(); |
| 2280 | |
| 2281 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2282 | * Return whether we are currently running on battery. |
| 2283 | */ |
| 2284 | public abstract boolean getIsOnBattery(); |
| 2285 | |
| 2286 | /** |
| 2287 | * Returns a SparseArray containing the statistics for each uid. |
| 2288 | */ |
| 2289 | public abstract SparseArray<? extends Uid> getUidStats(); |
| 2290 | |
| 2291 | /** |
| 2292 | * Returns the current battery uptime in microseconds. |
| 2293 | * |
| 2294 | * @param curTime the amount of elapsed realtime in microseconds. |
| 2295 | */ |
| 2296 | public abstract long getBatteryUptime(long curTime); |
| 2297 | |
| 2298 | /** |
| 2299 | * Returns the current battery realtime in microseconds. |
| 2300 | * |
| 2301 | * @param curTime the amount of elapsed realtime in microseconds. |
| 2302 | */ |
| 2303 | public abstract long getBatteryRealtime(long curTime); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2304 | |
| 2305 | /** |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 2306 | * Returns the battery percentage level at the last time the device was unplugged from power, or |
| 2307 | * the last time it booted on battery power. |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2308 | */ |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 2309 | public abstract int getDischargeStartLevel(); |
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 current battery percentage level if we are in a discharge cycle, otherwise |
| 2313 | * returns the level at the last plug event. |
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 getDischargeCurrentLevel(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2316 | |
| 2317 | /** |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 2318 | * Get the amount the battery has discharged since the stats were |
| 2319 | * last reset after charging, as a lower-end approximation. |
| 2320 | */ |
| 2321 | public abstract int getLowDischargeAmountSinceCharge(); |
| 2322 | |
| 2323 | /** |
| 2324 | * Get the amount the battery has discharged since the stats were |
| 2325 | * last reset after charging, as an upper-end approximation. |
| 2326 | */ |
| 2327 | public abstract int getHighDischargeAmountSinceCharge(); |
| 2328 | |
| 2329 | /** |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2330 | * Retrieve the discharge amount over the selected discharge period <var>which</var>. |
| 2331 | */ |
| 2332 | public abstract int getDischargeAmount(int which); |
| 2333 | |
| 2334 | /** |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 2335 | * Get the amount the battery has discharged while the screen was on, |
| 2336 | * since the last time power was unplugged. |
| 2337 | */ |
| 2338 | public abstract int getDischargeAmountScreenOn(); |
| 2339 | |
| 2340 | /** |
| 2341 | * Get the amount the battery has discharged while the screen was on, |
| 2342 | * since the last time the device was charged. |
| 2343 | */ |
| 2344 | public abstract int getDischargeAmountScreenOnSinceCharge(); |
| 2345 | |
| 2346 | /** |
| 2347 | * Get the amount the battery has discharged while the screen was off, |
| 2348 | * since the last time power was unplugged. |
| 2349 | */ |
| 2350 | public abstract int getDischargeAmountScreenOff(); |
| 2351 | |
| 2352 | /** |
| 2353 | * Get the amount the battery has discharged while the screen was off, |
| 2354 | * since the last time the device was charged. |
| 2355 | */ |
| 2356 | public abstract int getDischargeAmountScreenOffSinceCharge(); |
| 2357 | |
| 2358 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2359 | * Returns the total, last, or current battery uptime in microseconds. |
| 2360 | * |
| 2361 | * @param curTime the elapsed realtime in microseconds. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2362 | * @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] | 2363 | */ |
| 2364 | public abstract long computeBatteryUptime(long curTime, int which); |
| 2365 | |
| 2366 | /** |
| 2367 | * Returns the total, last, or current battery realtime in microseconds. |
| 2368 | * |
| 2369 | * @param curTime the current elapsed realtime in microseconds. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2370 | * @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] | 2371 | */ |
| 2372 | public abstract long computeBatteryRealtime(long curTime, int which); |
| 2373 | |
| 2374 | /** |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2375 | * Returns the total, last, or current battery screen off uptime in microseconds. |
| 2376 | * |
| 2377 | * @param curTime the elapsed realtime in microseconds. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2378 | * @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] | 2379 | */ |
| 2380 | public abstract long computeBatteryScreenOffUptime(long curTime, int which); |
| 2381 | |
| 2382 | /** |
| 2383 | * Returns the total, last, or current battery screen off realtime in microseconds. |
| 2384 | * |
| 2385 | * @param curTime the current elapsed realtime in microseconds. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2386 | * @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] | 2387 | */ |
| 2388 | public abstract long computeBatteryScreenOffRealtime(long curTime, int which); |
| 2389 | |
| 2390 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2391 | * Returns the total, last, or current uptime in microseconds. |
| 2392 | * |
| 2393 | * @param curTime the current elapsed realtime in microseconds. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2394 | * @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] | 2395 | */ |
| 2396 | public abstract long computeUptime(long curTime, int which); |
| 2397 | |
| 2398 | /** |
| 2399 | * Returns the total, last, or current realtime in microseconds. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2400 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2401 | * @param curTime the current elapsed realtime in microseconds. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2402 | * @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] | 2403 | */ |
| 2404 | public abstract long computeRealtime(long curTime, int which); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2405 | |
| 2406 | /** |
| 2407 | * Compute an approximation for how much run time (in microseconds) is remaining on |
| 2408 | * the battery. Returns -1 if no time can be computed: either there is not |
| 2409 | * enough current data to make a decision, or the battery is currently |
| 2410 | * charging. |
| 2411 | * |
| 2412 | * @param curTime The current elepsed realtime in microseconds. |
| 2413 | */ |
| 2414 | public abstract long computeBatteryTimeRemaining(long curTime); |
| 2415 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 2416 | // The part of a step duration that is the actual time. |
| 2417 | public static final long STEP_LEVEL_TIME_MASK = 0x000000ffffffffffL; |
| 2418 | |
| 2419 | // Bits in a step duration that are the new battery level we are at. |
| 2420 | public static final long STEP_LEVEL_LEVEL_MASK = 0x0000ff0000000000L; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2421 | public static final int STEP_LEVEL_LEVEL_SHIFT = 40; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 2422 | |
| 2423 | // Bits in a step duration that are the initial mode we were in at that step. |
| 2424 | public static final long STEP_LEVEL_INITIAL_MODE_MASK = 0x00ff000000000000L; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2425 | public static final int STEP_LEVEL_INITIAL_MODE_SHIFT = 48; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 2426 | |
| 2427 | // Bits in a step duration that indicate which modes changed during that step. |
| 2428 | public static final long STEP_LEVEL_MODIFIED_MODE_MASK = 0xff00000000000000L; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2429 | public static final int STEP_LEVEL_MODIFIED_MODE_SHIFT = 56; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 2430 | |
| 2431 | // Step duration mode: the screen is on, off, dozed, etc; value is Display.STATE_* - 1. |
| 2432 | public static final int STEP_LEVEL_MODE_SCREEN_STATE = 0x03; |
| 2433 | |
Santos Cordon | e94f050 | 2017-02-24 12:31:20 -0800 | [diff] [blame] | 2434 | // The largest value for screen state that is tracked in battery states. Any values above |
| 2435 | // this should be mapped back to one of the tracked values before being tracked here. |
| 2436 | public static final int MAX_TRACKED_SCREEN_STATE = Display.STATE_DOZE_SUSPEND; |
| 2437 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 2438 | // Step duration mode: power save is on. |
| 2439 | public static final int STEP_LEVEL_MODE_POWER_SAVE = 0x04; |
| 2440 | |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2441 | // Step duration mode: device is currently in idle mode. |
| 2442 | public static final int STEP_LEVEL_MODE_DEVICE_IDLE = 0x08; |
| 2443 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2444 | public static final int[] STEP_LEVEL_MODES_OF_INTEREST = new int[] { |
| 2445 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE, |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2446 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE|STEP_LEVEL_MODE_DEVICE_IDLE, |
| 2447 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_DEVICE_IDLE, |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2448 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE, |
| 2449 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE, |
| 2450 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE, |
| 2451 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE, |
| 2452 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE, |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2453 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE|STEP_LEVEL_MODE_DEVICE_IDLE, |
| 2454 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_DEVICE_IDLE, |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2455 | }; |
| 2456 | public static final int[] STEP_LEVEL_MODE_VALUES = new int[] { |
| 2457 | (Display.STATE_OFF-1), |
| 2458 | (Display.STATE_OFF-1)|STEP_LEVEL_MODE_POWER_SAVE, |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2459 | (Display.STATE_OFF-1)|STEP_LEVEL_MODE_DEVICE_IDLE, |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2460 | (Display.STATE_ON-1), |
| 2461 | (Display.STATE_ON-1)|STEP_LEVEL_MODE_POWER_SAVE, |
| 2462 | (Display.STATE_DOZE-1), |
| 2463 | (Display.STATE_DOZE-1)|STEP_LEVEL_MODE_POWER_SAVE, |
| 2464 | (Display.STATE_DOZE_SUSPEND-1), |
| 2465 | (Display.STATE_DOZE_SUSPEND-1)|STEP_LEVEL_MODE_POWER_SAVE, |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2466 | (Display.STATE_DOZE_SUSPEND-1)|STEP_LEVEL_MODE_DEVICE_IDLE, |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2467 | }; |
| 2468 | public static final String[] STEP_LEVEL_MODE_LABELS = new String[] { |
| 2469 | "screen off", |
| 2470 | "screen off power save", |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2471 | "screen off device idle", |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2472 | "screen on", |
| 2473 | "screen on power save", |
| 2474 | "screen doze", |
| 2475 | "screen doze power save", |
| 2476 | "screen doze-suspend", |
| 2477 | "screen doze-suspend power save", |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2478 | "screen doze-suspend device idle", |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2479 | }; |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 2480 | |
| 2481 | /** |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 2482 | * Return the counter keeping track of the amount of battery discharge while the screen was off, |
| 2483 | * measured in micro-Ampere-hours. This will be non-zero only if the device's battery has |
| 2484 | * a coulomb counter. |
| 2485 | */ |
| 2486 | public abstract LongCounter getDischargeScreenOffCoulombCounter(); |
| 2487 | |
| 2488 | /** |
| 2489 | * Return the counter keeping track of the amount of battery discharge measured in |
| 2490 | * micro-Ampere-hours. This will be non-zero only if the device's battery has |
| 2491 | * a coulomb counter. |
| 2492 | */ |
| 2493 | public abstract LongCounter getDischargeCoulombCounter(); |
| 2494 | |
| 2495 | /** |
Adam Lesinski | f9b20a9 | 2016-06-17 17:30:01 -0700 | [diff] [blame] | 2496 | * Returns the estimated real battery capacity, which may be less than the capacity |
| 2497 | * declared by the PowerProfile. |
| 2498 | * @return The estimated battery capacity in mAh. |
| 2499 | */ |
| 2500 | public abstract int getEstimatedBatteryCapacity(); |
| 2501 | |
| 2502 | /** |
Jocelyn Dang | c627d10 | 2017-04-14 13:15:14 -0700 | [diff] [blame] | 2503 | * @return The minimum learned battery capacity in uAh. |
| 2504 | */ |
| 2505 | public abstract int getMinLearnedBatteryCapacity(); |
| 2506 | |
| 2507 | /** |
| 2508 | * @return The maximum learned battery capacity in uAh. |
| 2509 | */ |
| 2510 | public abstract int getMaxLearnedBatteryCapacity() ; |
| 2511 | |
| 2512 | /** |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2513 | * Return the array of discharge step durations. |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 2514 | */ |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2515 | public abstract LevelStepTracker getDischargeLevelStepTracker(); |
| 2516 | |
| 2517 | /** |
| 2518 | * Return the array of daily discharge step durations. |
| 2519 | */ |
| 2520 | public abstract LevelStepTracker getDailyDischargeLevelStepTracker(); |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 2521 | |
| 2522 | /** |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2523 | * Compute an approximation for how much time (in microseconds) remains until the battery |
| 2524 | * is fully charged. Returns -1 if no time can be computed: either there is not |
| 2525 | * enough current data to make a decision, or the battery is currently |
| 2526 | * discharging. |
| 2527 | * |
| 2528 | * @param curTime The current elepsed realtime in microseconds. |
| 2529 | */ |
| 2530 | public abstract long computeChargeTimeRemaining(long curTime); |
| 2531 | |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 2532 | /** |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2533 | * Return the array of charge step durations. |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 2534 | */ |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2535 | public abstract LevelStepTracker getChargeLevelStepTracker(); |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 2536 | |
| 2537 | /** |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2538 | * Return the array of daily charge step durations. |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 2539 | */ |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2540 | public abstract LevelStepTracker getDailyChargeLevelStepTracker(); |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 2541 | |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2542 | public abstract ArrayList<PackageChange> getDailyPackageChanges(); |
| 2543 | |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 2544 | public abstract Map<String, ? extends Timer> getWakeupReasonStats(); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2545 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2546 | public abstract Map<String, ? extends Timer> getKernelWakelockStats(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2547 | |
James Carr | 2dd7e5e | 2016-07-20 18:48:39 -0700 | [diff] [blame] | 2548 | public abstract LongSparseArray<? extends Timer> getKernelMemoryStats(); |
| 2549 | |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 2550 | public abstract void writeToParcelWithoutUids(Parcel out, int flags); |
| 2551 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 2552 | private final static void formatTimeRaw(StringBuilder out, long seconds) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2553 | long days = seconds / (60 * 60 * 24); |
| 2554 | if (days != 0) { |
| 2555 | out.append(days); |
| 2556 | out.append("d "); |
| 2557 | } |
| 2558 | long used = days * 60 * 60 * 24; |
| 2559 | |
| 2560 | long hours = (seconds - used) / (60 * 60); |
| 2561 | if (hours != 0 || used != 0) { |
| 2562 | out.append(hours); |
| 2563 | out.append("h "); |
| 2564 | } |
| 2565 | used += hours * 60 * 60; |
| 2566 | |
| 2567 | long mins = (seconds-used) / 60; |
| 2568 | if (mins != 0 || used != 0) { |
| 2569 | out.append(mins); |
| 2570 | out.append("m "); |
| 2571 | } |
| 2572 | used += mins * 60; |
| 2573 | |
| 2574 | if (seconds != 0 || used != 0) { |
| 2575 | out.append(seconds-used); |
| 2576 | out.append("s "); |
| 2577 | } |
| 2578 | } |
| 2579 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2580 | public final static void formatTimeMs(StringBuilder sb, long time) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2581 | long sec = time / 1000; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 2582 | formatTimeRaw(sb, sec); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2583 | sb.append(time - (sec * 1000)); |
| 2584 | sb.append("ms "); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2585 | } |
| 2586 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2587 | public final static void formatTimeMsNoSpace(StringBuilder sb, long time) { |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 2588 | long sec = time / 1000; |
| 2589 | formatTimeRaw(sb, sec); |
| 2590 | sb.append(time - (sec * 1000)); |
| 2591 | sb.append("ms"); |
| 2592 | } |
| 2593 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2594 | public final String formatRatioLocked(long num, long den) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2595 | if (den == 0L) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2596 | return "--%"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2597 | } |
| 2598 | float perc = ((float)num) / ((float)den) * 100; |
| 2599 | mFormatBuilder.setLength(0); |
| 2600 | mFormatter.format("%.1f%%", perc); |
| 2601 | return mFormatBuilder.toString(); |
| 2602 | } |
| 2603 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2604 | final String formatBytesLocked(long bytes) { |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 2605 | mFormatBuilder.setLength(0); |
| 2606 | |
| 2607 | if (bytes < BYTES_PER_KB) { |
| 2608 | return bytes + "B"; |
| 2609 | } else if (bytes < BYTES_PER_MB) { |
| 2610 | mFormatter.format("%.2fKB", bytes / (double) BYTES_PER_KB); |
| 2611 | return mFormatBuilder.toString(); |
| 2612 | } else if (bytes < BYTES_PER_GB){ |
| 2613 | mFormatter.format("%.2fMB", bytes / (double) BYTES_PER_MB); |
| 2614 | return mFormatBuilder.toString(); |
| 2615 | } else { |
| 2616 | mFormatter.format("%.2fGB", bytes / (double) BYTES_PER_GB); |
| 2617 | return mFormatBuilder.toString(); |
| 2618 | } |
| 2619 | } |
| 2620 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2621 | private static long computeWakeLock(Timer timer, long elapsedRealtimeUs, int which) { |
Dianne Hackborn | c24ab86 | 2011-10-18 15:55:03 -0700 | [diff] [blame] | 2622 | if (timer != null) { |
| 2623 | // Convert from microseconds to milliseconds with rounding |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2624 | long totalTimeMicros = timer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Dianne Hackborn | c24ab86 | 2011-10-18 15:55:03 -0700 | [diff] [blame] | 2625 | long totalTimeMillis = (totalTimeMicros + 500) / 1000; |
| 2626 | return totalTimeMillis; |
| 2627 | } |
| 2628 | return 0; |
| 2629 | } |
| 2630 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2631 | /** |
| 2632 | * |
| 2633 | * @param sb a StringBuilder object. |
| 2634 | * @param timer a Timer object contining the wakelock times. |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2635 | * @param elapsedRealtimeUs the current on-battery time in microseconds. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2636 | * @param name the name of the wakelock. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2637 | * @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] | 2638 | * @param linePrefix a String to be prepended to each line of output. |
| 2639 | * @return the line prefix |
| 2640 | */ |
| 2641 | private static final String printWakeLock(StringBuilder sb, Timer timer, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2642 | long elapsedRealtimeUs, String name, int which, String linePrefix) { |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 2643 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2644 | if (timer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2645 | long totalTimeMillis = computeWakeLock(timer, elapsedRealtimeUs, which); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 2646 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2647 | int count = timer.getCountLocked(which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2648 | if (totalTimeMillis != 0) { |
| 2649 | sb.append(linePrefix); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 2650 | formatTimeMs(sb, totalTimeMillis); |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 2651 | if (name != null) { |
| 2652 | sb.append(name); |
| 2653 | sb.append(' '); |
| 2654 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2655 | sb.append('('); |
| 2656 | sb.append(count); |
| 2657 | sb.append(" times)"); |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2658 | final long maxDurationMs = timer.getMaxDurationMsLocked(elapsedRealtimeUs/1000); |
| 2659 | if (maxDurationMs >= 0) { |
| 2660 | sb.append(" max="); |
| 2661 | sb.append(maxDurationMs); |
| 2662 | } |
| 2663 | if (timer.isRunningLocked()) { |
| 2664 | final long currentMs = timer.getCurrentDurationMsLocked(elapsedRealtimeUs/1000); |
| 2665 | if (currentMs >= 0) { |
| 2666 | sb.append(" (running for "); |
| 2667 | sb.append(currentMs); |
| 2668 | sb.append("ms)"); |
| 2669 | } else { |
| 2670 | sb.append(" (running)"); |
| 2671 | } |
| 2672 | } |
| 2673 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2674 | return ", "; |
| 2675 | } |
| 2676 | } |
| 2677 | return linePrefix; |
| 2678 | } |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 2679 | |
| 2680 | /** |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2681 | * 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] | 2682 | * |
| 2683 | * @param pw a PrintWriter object to print to. |
| 2684 | * @param sb a StringBuilder object. |
| 2685 | * @param timer a Timer object contining the wakelock times. |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2686 | * @param rawRealtimeUs the current on-battery time in microseconds. |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 2687 | * @param which which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT. |
| 2688 | * @param prefix a String to be prepended to each line of output. |
| 2689 | * @param type the name of the timer. |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2690 | * @return true if anything was printed. |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 2691 | */ |
| 2692 | private static final boolean printTimer(PrintWriter pw, StringBuilder sb, Timer timer, |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2693 | long rawRealtimeUs, int which, String prefix, String type) { |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 2694 | if (timer != null) { |
| 2695 | // Convert from microseconds to milliseconds with rounding |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2696 | final long totalTimeMs = (timer.getTotalTimeLocked( |
| 2697 | rawRealtimeUs, which) + 500) / 1000; |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 2698 | final int count = timer.getCountLocked(which); |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2699 | if (totalTimeMs != 0) { |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 2700 | sb.setLength(0); |
| 2701 | sb.append(prefix); |
| 2702 | sb.append(" "); |
| 2703 | sb.append(type); |
| 2704 | sb.append(": "); |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2705 | formatTimeMs(sb, totalTimeMs); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 2706 | sb.append("realtime ("); |
| 2707 | sb.append(count); |
| 2708 | sb.append(" times)"); |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2709 | final long maxDurationMs = timer.getMaxDurationMsLocked(rawRealtimeUs/1000); |
| 2710 | if (maxDurationMs >= 0) { |
| 2711 | sb.append(" max="); |
| 2712 | sb.append(maxDurationMs); |
| 2713 | } |
| 2714 | if (timer.isRunningLocked()) { |
| 2715 | final long currentMs = timer.getCurrentDurationMsLocked(rawRealtimeUs/1000); |
| 2716 | if (currentMs >= 0) { |
| 2717 | sb.append(" (running for "); |
| 2718 | sb.append(currentMs); |
| 2719 | sb.append("ms)"); |
| 2720 | } else { |
| 2721 | sb.append(" (running)"); |
| 2722 | } |
| 2723 | } |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 2724 | pw.println(sb.toString()); |
| 2725 | return true; |
| 2726 | } |
| 2727 | } |
| 2728 | return false; |
| 2729 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2730 | |
| 2731 | /** |
| 2732 | * Checkin version of wakelock printer. Prints simple comma-separated list. |
| 2733 | * |
| 2734 | * @param sb a StringBuilder object. |
| 2735 | * @param timer a Timer object contining the wakelock times. |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2736 | * @param elapsedRealtimeUs the current time in microseconds. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2737 | * @param name the name of the wakelock. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2738 | * @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] | 2739 | * @param linePrefix a String to be prepended to each line of output. |
| 2740 | * @return the line prefix |
| 2741 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2742 | private static final String printWakeLockCheckin(StringBuilder sb, Timer timer, |
| 2743 | long elapsedRealtimeUs, String name, int which, String linePrefix) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2744 | long totalTimeMicros = 0; |
| 2745 | int count = 0; |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2746 | long max = -1; |
| 2747 | long current = -1; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2748 | if (timer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2749 | totalTimeMicros = timer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2750 | count = timer.getCountLocked(which); |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2751 | current = timer.getCurrentDurationMsLocked(elapsedRealtimeUs/1000); |
| 2752 | max = timer.getMaxDurationMsLocked(elapsedRealtimeUs/1000); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2753 | } |
| 2754 | sb.append(linePrefix); |
| 2755 | sb.append((totalTimeMicros + 500) / 1000); // microseconds to milliseconds with rounding |
| 2756 | sb.append(','); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2757 | sb.append(name != null ? name + "," : ""); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2758 | sb.append(count); |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2759 | sb.append(','); |
| 2760 | sb.append(current); |
| 2761 | sb.append(','); |
| 2762 | sb.append(max); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2763 | return ","; |
| 2764 | } |
| 2765 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 2766 | private static final void dumpLineHeader(PrintWriter pw, int uid, String category, |
| 2767 | String type) { |
| 2768 | pw.print(BATTERY_STATS_CHECKIN_VERSION); |
| 2769 | pw.print(','); |
| 2770 | pw.print(uid); |
| 2771 | pw.print(','); |
| 2772 | pw.print(category); |
| 2773 | pw.print(','); |
| 2774 | pw.print(type); |
| 2775 | } |
| 2776 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2777 | /** |
| 2778 | * Dump a comma-separated line of values for terse checkin mode. |
| 2779 | * |
| 2780 | * @param pw the PageWriter to dump log to |
| 2781 | * @param category category of data (e.g. "total", "last", "unplugged", "current" ) |
| 2782 | * @param type type of data (e.g. "wakelock", "sensor", "process", "apk" , "process", "network") |
| 2783 | * @param args type-dependent data arguments |
| 2784 | */ |
| 2785 | private static final void dumpLine(PrintWriter pw, int uid, String category, String type, |
| 2786 | Object... args ) { |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 2787 | dumpLineHeader(pw, uid, category, type); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 2788 | for (Object arg : args) { |
Dianne Hackborn | 13ac041 | 2013-06-25 19:34:49 -0700 | [diff] [blame] | 2789 | pw.print(','); |
| 2790 | pw.print(arg); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2791 | } |
Dianne Hackborn | 13ac041 | 2013-06-25 19:34:49 -0700 | [diff] [blame] | 2792 | pw.println(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2793 | } |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 2794 | |
| 2795 | /** |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 2796 | * Dump a given timer stat for terse checkin mode. |
| 2797 | * |
| 2798 | * @param pw the PageWriter to dump log to |
| 2799 | * @param uid the UID to log |
| 2800 | * @param category category of data (e.g. "total", "last", "unplugged", "current" ) |
| 2801 | * @param type type of data (e.g. "wakelock", "sensor", "process", "apk" , "process", "network") |
| 2802 | * @param timer a {@link Timer} to dump stats for |
| 2803 | * @param rawRealtime the current elapsed realtime of the system in microseconds |
| 2804 | * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT |
| 2805 | */ |
| 2806 | private static final void dumpTimer(PrintWriter pw, int uid, String category, String type, |
| 2807 | Timer timer, long rawRealtime, int which) { |
| 2808 | if (timer != null) { |
| 2809 | // Convert from microseconds to milliseconds with rounding |
| 2810 | final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) |
| 2811 | / 1000; |
| 2812 | final int count = timer.getCountLocked(which); |
| 2813 | if (totalTime != 0) { |
| 2814 | dumpLine(pw, uid, category, type, totalTime, count); |
| 2815 | } |
| 2816 | } |
| 2817 | } |
| 2818 | |
| 2819 | /** |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 2820 | * Checks if the ControllerActivityCounter has any data worth dumping. |
| 2821 | */ |
| 2822 | private static boolean controllerActivityHasData(ControllerActivityCounter counter, int which) { |
| 2823 | if (counter == null) { |
| 2824 | return false; |
| 2825 | } |
| 2826 | |
| 2827 | if (counter.getIdleTimeCounter().getCountLocked(which) != 0 |
| 2828 | || counter.getRxTimeCounter().getCountLocked(which) != 0 |
| 2829 | || counter.getPowerCounter().getCountLocked(which) != 0) { |
| 2830 | return true; |
| 2831 | } |
| 2832 | |
| 2833 | for (LongCounter c : counter.getTxTimeCounters()) { |
| 2834 | if (c.getCountLocked(which) != 0) { |
| 2835 | return true; |
| 2836 | } |
| 2837 | } |
| 2838 | return false; |
| 2839 | } |
| 2840 | |
| 2841 | /** |
| 2842 | * Dumps the ControllerActivityCounter if it has any data worth dumping. |
| 2843 | * The order of the arguments in the final check in line is: |
| 2844 | * |
| 2845 | * idle, rx, power, tx... |
| 2846 | * |
| 2847 | * where tx... is one or more transmit level times. |
| 2848 | */ |
| 2849 | private static final void dumpControllerActivityLine(PrintWriter pw, int uid, String category, |
| 2850 | String type, |
| 2851 | ControllerActivityCounter counter, |
| 2852 | int which) { |
| 2853 | if (!controllerActivityHasData(counter, which)) { |
| 2854 | return; |
| 2855 | } |
| 2856 | |
| 2857 | dumpLineHeader(pw, uid, category, type); |
| 2858 | pw.print(","); |
| 2859 | pw.print(counter.getIdleTimeCounter().getCountLocked(which)); |
| 2860 | pw.print(","); |
| 2861 | pw.print(counter.getRxTimeCounter().getCountLocked(which)); |
| 2862 | pw.print(","); |
| 2863 | pw.print(counter.getPowerCounter().getCountLocked(which) / (1000 * 60 * 60)); |
| 2864 | for (LongCounter c : counter.getTxTimeCounters()) { |
| 2865 | pw.print(","); |
| 2866 | pw.print(c.getCountLocked(which)); |
| 2867 | } |
| 2868 | pw.println(); |
| 2869 | } |
| 2870 | |
| 2871 | private final void printControllerActivityIfInteresting(PrintWriter pw, StringBuilder sb, |
| 2872 | String prefix, String controllerName, |
| 2873 | ControllerActivityCounter counter, |
| 2874 | int which) { |
| 2875 | if (controllerActivityHasData(counter, which)) { |
| 2876 | printControllerActivity(pw, sb, prefix, controllerName, counter, which); |
| 2877 | } |
| 2878 | } |
| 2879 | |
| 2880 | private final void printControllerActivity(PrintWriter pw, StringBuilder sb, String prefix, |
| 2881 | String controllerName, |
| 2882 | ControllerActivityCounter counter, int which) { |
| 2883 | final long idleTimeMs = counter.getIdleTimeCounter().getCountLocked(which); |
| 2884 | final long rxTimeMs = counter.getRxTimeCounter().getCountLocked(which); |
| 2885 | final long powerDrainMaMs = counter.getPowerCounter().getCountLocked(which); |
| 2886 | long totalTxTimeMs = 0; |
| 2887 | for (LongCounter txState : counter.getTxTimeCounters()) { |
| 2888 | totalTxTimeMs += txState.getCountLocked(which); |
| 2889 | } |
| 2890 | |
| 2891 | final long totalTimeMs = idleTimeMs + rxTimeMs + totalTxTimeMs; |
| 2892 | |
| 2893 | sb.setLength(0); |
| 2894 | sb.append(prefix); |
| 2895 | sb.append(" "); |
| 2896 | sb.append(controllerName); |
| 2897 | sb.append(" Idle time: "); |
| 2898 | formatTimeMs(sb, idleTimeMs); |
| 2899 | sb.append("("); |
| 2900 | sb.append(formatRatioLocked(idleTimeMs, totalTimeMs)); |
| 2901 | sb.append(")"); |
| 2902 | pw.println(sb.toString()); |
| 2903 | |
| 2904 | sb.setLength(0); |
| 2905 | sb.append(prefix); |
| 2906 | sb.append(" "); |
| 2907 | sb.append(controllerName); |
| 2908 | sb.append(" Rx time: "); |
| 2909 | formatTimeMs(sb, rxTimeMs); |
| 2910 | sb.append("("); |
| 2911 | sb.append(formatRatioLocked(rxTimeMs, totalTimeMs)); |
| 2912 | sb.append(")"); |
| 2913 | pw.println(sb.toString()); |
| 2914 | |
| 2915 | sb.setLength(0); |
| 2916 | sb.append(prefix); |
| 2917 | sb.append(" "); |
| 2918 | sb.append(controllerName); |
| 2919 | sb.append(" Tx time: "); |
| 2920 | formatTimeMs(sb, totalTxTimeMs); |
| 2921 | sb.append("("); |
| 2922 | sb.append(formatRatioLocked(totalTxTimeMs, totalTimeMs)); |
| 2923 | sb.append(")"); |
| 2924 | pw.println(sb.toString()); |
| 2925 | |
| 2926 | final int numTxLvls = counter.getTxTimeCounters().length; |
| 2927 | if (numTxLvls > 1) { |
| 2928 | for (int lvl = 0; lvl < numTxLvls; lvl++) { |
| 2929 | final long txLvlTimeMs = counter.getTxTimeCounters()[lvl].getCountLocked(which); |
| 2930 | sb.setLength(0); |
| 2931 | sb.append(prefix); |
| 2932 | sb.append(" ["); |
| 2933 | sb.append(lvl); |
| 2934 | sb.append("] "); |
| 2935 | formatTimeMs(sb, txLvlTimeMs); |
| 2936 | sb.append("("); |
| 2937 | sb.append(formatRatioLocked(txLvlTimeMs, totalTxTimeMs)); |
| 2938 | sb.append(")"); |
| 2939 | pw.println(sb.toString()); |
| 2940 | } |
| 2941 | } |
| 2942 | |
| 2943 | sb.setLength(0); |
| 2944 | sb.append(prefix); |
| 2945 | sb.append(" "); |
| 2946 | sb.append(controllerName); |
| 2947 | sb.append(" Power drain: ").append( |
| 2948 | BatteryStatsHelper.makemAh(powerDrainMaMs / (double) (1000*60*60))); |
| 2949 | sb.append("mAh"); |
| 2950 | pw.println(sb.toString()); |
| 2951 | } |
| 2952 | |
| 2953 | /** |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 2954 | * Temporary for settings. |
| 2955 | */ |
| 2956 | public final void dumpCheckinLocked(Context context, PrintWriter pw, int which, int reqUid) { |
| 2957 | dumpCheckinLocked(context, pw, which, reqUid, BatteryStatsHelper.checkWifiOnly(context)); |
| 2958 | } |
| 2959 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2960 | /** |
| 2961 | * Checkin server version of dump to produce more compact, computer-readable log. |
| 2962 | * |
| 2963 | * NOTE: all times are expressed in 'ms'. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2964 | */ |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 2965 | public final void dumpCheckinLocked(Context context, PrintWriter pw, int which, int reqUid, |
| 2966 | boolean wifiOnly) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2967 | final long rawUptime = SystemClock.uptimeMillis() * 1000; |
| 2968 | final long rawRealtime = SystemClock.elapsedRealtime() * 1000; |
| 2969 | final long batteryUptime = getBatteryUptime(rawUptime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2970 | final long whichBatteryUptime = computeBatteryUptime(rawUptime, which); |
| 2971 | final long whichBatteryRealtime = computeBatteryRealtime(rawRealtime, which); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2972 | final long whichBatteryScreenOffUptime = computeBatteryScreenOffUptime(rawUptime, which); |
| 2973 | final long whichBatteryScreenOffRealtime = computeBatteryScreenOffRealtime(rawRealtime, |
| 2974 | which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2975 | final long totalRealtime = computeRealtime(rawRealtime, which); |
| 2976 | final long totalUptime = computeUptime(rawUptime, which); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2977 | final long screenOnTime = getScreenOnTime(rawRealtime, which); |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 2978 | final long interactiveTime = getInteractiveTime(rawRealtime, which); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 2979 | final long powerSaveModeEnabledTime = getPowerSaveModeEnabledTime(rawRealtime, which); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 2980 | final long deviceIdleModeLightTime = getDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT, |
| 2981 | rawRealtime, which); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 2982 | final long deviceIdleModeFullTime = getDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP, |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 2983 | rawRealtime, which); |
| 2984 | final long deviceLightIdlingTime = getDeviceIdlingTime(DEVICE_IDLE_MODE_LIGHT, |
| 2985 | rawRealtime, which); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 2986 | final long deviceIdlingTime = getDeviceIdlingTime(DEVICE_IDLE_MODE_DEEP, |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 2987 | rawRealtime, which); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 2988 | final int connChanges = getNumConnectivityChange(which); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2989 | final long phoneOnTime = getPhoneOnTime(rawRealtime, which); |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 2990 | final long dischargeCount = getDischargeCoulombCounter().getCountLocked(which); |
| 2991 | final long dischargeScreenOffCount = getDischargeScreenOffCoulombCounter() |
| 2992 | .getCountLocked(which); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 2993 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 2994 | final StringBuilder sb = new StringBuilder(128); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2995 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 2996 | final SparseArray<? extends Uid> uidStats = getUidStats(); |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 2997 | final int NU = uidStats.size(); |
| 2998 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 2999 | final String category = STAT_NAMES[which]; |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 3000 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3001 | // Dump "battery" stat |
Jocelyn Dang | c627d10 | 2017-04-14 13:15:14 -0700 | [diff] [blame] | 3002 | dumpLine(pw, 0 /* uid */, category, BATTERY_DATA, |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3003 | which == STATS_SINCE_CHARGED ? getStartCount() : "N/A", |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3004 | whichBatteryRealtime / 1000, whichBatteryUptime / 1000, |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 3005 | totalRealtime / 1000, totalUptime / 1000, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3006 | getStartClockTime(), |
Adam Lesinski | f9b20a9 | 2016-06-17 17:30:01 -0700 | [diff] [blame] | 3007 | whichBatteryScreenOffRealtime / 1000, whichBatteryScreenOffUptime / 1000, |
Jocelyn Dang | c627d10 | 2017-04-14 13:15:14 -0700 | [diff] [blame] | 3008 | getEstimatedBatteryCapacity(), |
| 3009 | getMinLearnedBatteryCapacity(), getMaxLearnedBatteryCapacity()); |
Adam Lesinski | 67c134f | 2016-06-10 15:15:08 -0700 | [diff] [blame] | 3010 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3011 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3012 | // Calculate wakelock times across all uids. |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 3013 | long fullWakeLockTimeTotal = 0; |
| 3014 | long partialWakeLockTimeTotal = 0; |
| 3015 | |
| 3016 | for (int iu = 0; iu < NU; iu++) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3017 | final Uid u = uidStats.valueAt(iu); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 3018 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3019 | final ArrayMap<String, ? extends BatteryStats.Uid.Wakelock> wakelocks |
| 3020 | = u.getWakelockStats(); |
| 3021 | for (int iw=wakelocks.size()-1; iw>=0; iw--) { |
| 3022 | final Uid.Wakelock wl = wakelocks.valueAt(iw); |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 3023 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3024 | final Timer fullWakeTimer = wl.getWakeTime(WAKE_TYPE_FULL); |
| 3025 | if (fullWakeTimer != null) { |
| 3026 | fullWakeLockTimeTotal += fullWakeTimer.getTotalTimeLocked(rawRealtime, |
| 3027 | which); |
| 3028 | } |
| 3029 | |
| 3030 | final Timer partialWakeTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL); |
| 3031 | if (partialWakeTimer != null) { |
| 3032 | partialWakeLockTimeTotal += partialWakeTimer.getTotalTimeLocked( |
| 3033 | rawRealtime, which); |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 3034 | } |
| 3035 | } |
| 3036 | } |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 3037 | |
| 3038 | // Dump network stats |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3039 | final long mobileRxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which); |
| 3040 | final long mobileTxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which); |
| 3041 | final long wifiRxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which); |
| 3042 | final long wifiTxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which); |
| 3043 | final long mobileRxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which); |
| 3044 | final long mobileTxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which); |
| 3045 | final long wifiRxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which); |
| 3046 | final long wifiTxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 3047 | final long btRxTotalBytes = getNetworkActivityBytes(NETWORK_BT_RX_DATA, which); |
| 3048 | final long btTxTotalBytes = getNetworkActivityBytes(NETWORK_BT_TX_DATA, which); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3049 | dumpLine(pw, 0 /* uid */, category, GLOBAL_NETWORK_DATA, |
| 3050 | mobileRxTotalBytes, mobileTxTotalBytes, wifiRxTotalBytes, wifiTxTotalBytes, |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 3051 | mobileRxTotalPackets, mobileTxTotalPackets, wifiRxTotalPackets, wifiTxTotalPackets, |
| 3052 | btRxTotalBytes, btTxTotalBytes); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3053 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3054 | // Dump Modem controller stats |
| 3055 | dumpControllerActivityLine(pw, 0 /* uid */, category, GLOBAL_MODEM_CONTROLLER_DATA, |
| 3056 | getModemControllerActivity(), which); |
| 3057 | |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 3058 | // Dump Wifi controller stats |
| 3059 | final long wifiOnTime = getWifiOnTime(rawRealtime, which); |
| 3060 | final long wifiRunningTime = getGlobalWifiRunningTime(rawRealtime, which); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3061 | dumpLine(pw, 0 /* uid */, category, GLOBAL_WIFI_DATA, wifiOnTime / 1000, |
Adam Lesinski | 2208e74 | 2016-02-19 12:53:31 -0800 | [diff] [blame] | 3062 | wifiRunningTime / 1000, /* legacy fields follow, keep at 0 */ 0, 0, 0); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3063 | |
| 3064 | dumpControllerActivityLine(pw, 0 /* uid */, category, GLOBAL_WIFI_CONTROLLER_DATA, |
| 3065 | getWifiControllerActivity(), which); |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 3066 | |
| 3067 | // Dump Bluetooth controller stats |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3068 | dumpControllerActivityLine(pw, 0 /* uid */, category, GLOBAL_BLUETOOTH_CONTROLLER_DATA, |
| 3069 | getBluetoothControllerActivity(), which); |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 3070 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3071 | // Dump misc stats |
| 3072 | dumpLine(pw, 0 /* uid */, category, MISC_DATA, |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 3073 | screenOnTime / 1000, phoneOnTime / 1000, |
Ashish Sharma | 213bb2f | 2014-07-07 17:14:52 -0700 | [diff] [blame] | 3074 | fullWakeLockTimeTotal / 1000, partialWakeLockTimeTotal / 1000, |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 3075 | getMobileRadioActiveTime(rawRealtime, which) / 1000, |
Ashish Sharma | 213bb2f | 2014-07-07 17:14:52 -0700 | [diff] [blame] | 3076 | getMobileRadioActiveAdjustedTime(which) / 1000, interactiveTime / 1000, |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3077 | powerSaveModeEnabledTime / 1000, connChanges, deviceIdleModeFullTime / 1000, |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 3078 | getDeviceIdleModeCount(DEVICE_IDLE_MODE_DEEP, which), deviceIdlingTime / 1000, |
| 3079 | getDeviceIdlingCount(DEVICE_IDLE_MODE_DEEP, which), |
Adam Lesinski | 782327b | 2015-07-30 16:36:29 -0700 | [diff] [blame] | 3080 | getMobileRadioActiveCount(which), |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3081 | getMobileRadioActiveUnknownTime(which) / 1000, deviceIdleModeLightTime / 1000, |
| 3082 | getDeviceIdleModeCount(DEVICE_IDLE_MODE_LIGHT, which), deviceLightIdlingTime / 1000, |
| 3083 | getDeviceIdlingCount(DEVICE_IDLE_MODE_LIGHT, which), |
| 3084 | getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT), |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 3085 | getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP)); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3086 | |
| 3087 | // Dump screen brightness stats |
| 3088 | Object[] args = new Object[NUM_SCREEN_BRIGHTNESS_BINS]; |
| 3089 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3090 | args[i] = getScreenBrightnessTime(i, rawRealtime, which) / 1000; |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3091 | } |
| 3092 | dumpLine(pw, 0 /* uid */, category, SCREEN_BRIGHTNESS_DATA, args); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3093 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3094 | // Dump signal strength stats |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 3095 | args = new Object[SignalStrength.NUM_SIGNAL_STRENGTH_BINS]; |
| 3096 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3097 | args[i] = getPhoneSignalStrengthTime(i, rawRealtime, which) / 1000; |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3098 | } |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3099 | dumpLine(pw, 0 /* uid */, category, SIGNAL_STRENGTH_TIME_DATA, args); |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 3100 | dumpLine(pw, 0 /* uid */, category, SIGNAL_SCANNING_TIME_DATA, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3101 | getPhoneSignalScanningTime(rawRealtime, which) / 1000); |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 3102 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3103 | args[i] = getPhoneSignalStrengthCount(i, which); |
| 3104 | } |
| 3105 | dumpLine(pw, 0 /* uid */, category, SIGNAL_STRENGTH_COUNT_DATA, args); |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 3106 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3107 | // Dump network type stats |
| 3108 | args = new Object[NUM_DATA_CONNECTION_TYPES]; |
| 3109 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3110 | args[i] = getPhoneDataConnectionTime(i, rawRealtime, which) / 1000; |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3111 | } |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3112 | dumpLine(pw, 0 /* uid */, category, DATA_CONNECTION_TIME_DATA, args); |
| 3113 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
| 3114 | args[i] = getPhoneDataConnectionCount(i, which); |
| 3115 | } |
| 3116 | dumpLine(pw, 0 /* uid */, category, DATA_CONNECTION_COUNT_DATA, args); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3117 | |
| 3118 | // Dump wifi state stats |
| 3119 | args = new Object[NUM_WIFI_STATES]; |
| 3120 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3121 | args[i] = getWifiStateTime(i, rawRealtime, which) / 1000; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3122 | } |
| 3123 | dumpLine(pw, 0 /* uid */, category, WIFI_STATE_TIME_DATA, args); |
| 3124 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
| 3125 | args[i] = getWifiStateCount(i, which); |
| 3126 | } |
| 3127 | dumpLine(pw, 0 /* uid */, category, WIFI_STATE_COUNT_DATA, args); |
| 3128 | |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 3129 | // Dump wifi suppl state stats |
| 3130 | args = new Object[NUM_WIFI_SUPPL_STATES]; |
| 3131 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
| 3132 | args[i] = getWifiSupplStateTime(i, rawRealtime, which) / 1000; |
| 3133 | } |
| 3134 | dumpLine(pw, 0 /* uid */, category, WIFI_SUPPL_STATE_TIME_DATA, args); |
| 3135 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
| 3136 | args[i] = getWifiSupplStateCount(i, which); |
| 3137 | } |
| 3138 | dumpLine(pw, 0 /* uid */, category, WIFI_SUPPL_STATE_COUNT_DATA, args); |
| 3139 | |
| 3140 | // Dump wifi signal strength stats |
| 3141 | args = new Object[NUM_WIFI_SIGNAL_STRENGTH_BINS]; |
| 3142 | for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 3143 | args[i] = getWifiSignalStrengthTime(i, rawRealtime, which) / 1000; |
| 3144 | } |
| 3145 | dumpLine(pw, 0 /* uid */, category, WIFI_SIGNAL_STRENGTH_TIME_DATA, args); |
| 3146 | for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 3147 | args[i] = getWifiSignalStrengthCount(i, which); |
| 3148 | } |
| 3149 | dumpLine(pw, 0 /* uid */, category, WIFI_SIGNAL_STRENGTH_COUNT_DATA, args); |
| 3150 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3151 | if (which == STATS_SINCE_UNPLUGGED) { |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 3152 | dumpLine(pw, 0 /* uid */, category, BATTERY_LEVEL_DATA, getDischargeStartLevel(), |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 3153 | getDischargeCurrentLevel()); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3154 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3155 | |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 3156 | if (which == STATS_SINCE_UNPLUGGED) { |
| 3157 | dumpLine(pw, 0 /* uid */, category, BATTERY_DISCHARGE_DATA, |
| 3158 | getDischargeStartLevel()-getDischargeCurrentLevel(), |
| 3159 | getDischargeStartLevel()-getDischargeCurrentLevel(), |
Adam Lesinski | 67c134f | 2016-06-10 15:15:08 -0700 | [diff] [blame] | 3160 | getDischargeAmountScreenOn(), getDischargeAmountScreenOff(), |
| 3161 | dischargeCount / 1000, dischargeScreenOffCount / 1000); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 3162 | } else { |
| 3163 | dumpLine(pw, 0 /* uid */, category, BATTERY_DISCHARGE_DATA, |
| 3164 | getLowDischargeAmountSinceCharge(), getHighDischargeAmountSinceCharge(), |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 3165 | getDischargeAmountScreenOnSinceCharge(), |
Adam Lesinski | 67c134f | 2016-06-10 15:15:08 -0700 | [diff] [blame] | 3166 | getDischargeAmountScreenOffSinceCharge(), |
| 3167 | dischargeCount / 1000, dischargeScreenOffCount / 1000); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 3168 | } |
| 3169 | |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 3170 | if (reqUid < 0) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3171 | final Map<String, ? extends Timer> kernelWakelocks = getKernelWakelockStats(); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 3172 | if (kernelWakelocks.size() > 0) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3173 | for (Map.Entry<String, ? extends Timer> ent : kernelWakelocks.entrySet()) { |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 3174 | sb.setLength(0); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3175 | printWakeLockCheckin(sb, ent.getValue(), rawRealtime, null, which, ""); |
Kweku Adams | e0dd9c1 | 2017-03-08 08:12:15 -0800 | [diff] [blame] | 3176 | dumpLine(pw, 0 /* uid */, category, KERNEL_WAKELOCK_DATA, |
| 3177 | "\"" + ent.getKey() + "\"", sb.toString()); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 3178 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 3179 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3180 | final Map<String, ? extends Timer> wakeupReasons = getWakeupReasonStats(); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3181 | if (wakeupReasons.size() > 0) { |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 3182 | for (Map.Entry<String, ? extends Timer> ent : wakeupReasons.entrySet()) { |
| 3183 | // Not doing the regular wake lock formatting to remain compatible |
| 3184 | // with the old checkin format. |
| 3185 | long totalTimeMicros = ent.getValue().getTotalTimeLocked(rawRealtime, which); |
| 3186 | int count = ent.getValue().getCountLocked(which); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3187 | dumpLine(pw, 0 /* uid */, category, WAKEUP_REASON_DATA, |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 3188 | "\"" + ent.getKey() + "\"", (totalTimeMicros + 500) / 1000, count); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3189 | } |
| 3190 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 3191 | } |
| 3192 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3193 | final BatteryStatsHelper helper = new BatteryStatsHelper(context, false, wifiOnly); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3194 | helper.create(this); |
| 3195 | helper.refreshStats(which, UserHandle.USER_ALL); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3196 | final List<BatterySipper> sippers = helper.getUsageList(); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3197 | if (sippers != null && sippers.size() > 0) { |
| 3198 | dumpLine(pw, 0 /* uid */, category, POWER_USE_SUMMARY_DATA, |
| 3199 | BatteryStatsHelper.makemAh(helper.getPowerProfile().getBatteryCapacity()), |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3200 | BatteryStatsHelper.makemAh(helper.getComputedPower()), |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3201 | BatteryStatsHelper.makemAh(helper.getMinDrainedPower()), |
| 3202 | BatteryStatsHelper.makemAh(helper.getMaxDrainedPower())); |
| 3203 | for (int i=0; i<sippers.size(); i++) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3204 | final BatterySipper bs = sippers.get(i); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3205 | int uid = 0; |
| 3206 | String label; |
| 3207 | switch (bs.drainType) { |
| 3208 | case IDLE: |
| 3209 | label="idle"; |
| 3210 | break; |
| 3211 | case CELL: |
| 3212 | label="cell"; |
| 3213 | break; |
| 3214 | case PHONE: |
| 3215 | label="phone"; |
| 3216 | break; |
| 3217 | case WIFI: |
| 3218 | label="wifi"; |
| 3219 | break; |
| 3220 | case BLUETOOTH: |
| 3221 | label="blue"; |
| 3222 | break; |
| 3223 | case SCREEN: |
| 3224 | label="scrn"; |
| 3225 | break; |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 3226 | case FLASHLIGHT: |
| 3227 | label="flashlight"; |
| 3228 | break; |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3229 | case APP: |
| 3230 | uid = bs.uidObj.getUid(); |
| 3231 | label = "uid"; |
| 3232 | break; |
| 3233 | case USER: |
| 3234 | uid = UserHandle.getUid(bs.userId, 0); |
| 3235 | label = "user"; |
| 3236 | break; |
| 3237 | case UNACCOUNTED: |
| 3238 | label = "unacc"; |
| 3239 | break; |
| 3240 | case OVERCOUNTED: |
| 3241 | label = "over"; |
| 3242 | break; |
Ruben Brunk | 5b1308f | 2015-06-03 18:49:27 -0700 | [diff] [blame] | 3243 | case CAMERA: |
| 3244 | label = "camera"; |
| 3245 | break; |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3246 | default: |
| 3247 | label = "???"; |
| 3248 | } |
| 3249 | dumpLine(pw, uid, category, POWER_USE_ITEM_DATA, label, |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 3250 | BatteryStatsHelper.makemAh(bs.totalPowerMah)); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3251 | } |
| 3252 | } |
| 3253 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3254 | for (int iu = 0; iu < NU; iu++) { |
| 3255 | final int uid = uidStats.keyAt(iu); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 3256 | if (reqUid >= 0 && uid != reqUid) { |
| 3257 | continue; |
| 3258 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3259 | final Uid u = uidStats.valueAt(iu); |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 3260 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3261 | // Dump Network stats per uid, if any |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3262 | final long mobileBytesRx = u.getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which); |
| 3263 | final long mobileBytesTx = u.getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which); |
| 3264 | final long wifiBytesRx = u.getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which); |
| 3265 | final long wifiBytesTx = u.getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which); |
| 3266 | final long mobilePacketsRx = u.getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which); |
| 3267 | final long mobilePacketsTx = u.getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which); |
| 3268 | final long mobileActiveTime = u.getMobileRadioActiveTime(which); |
| 3269 | final int mobileActiveCount = u.getMobileRadioActiveCount(which); |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 3270 | final long mobileWakeup = u.getMobileRadioApWakeupCount(which); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3271 | final long wifiPacketsRx = u.getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which); |
| 3272 | final long wifiPacketsTx = u.getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which); |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 3273 | final long wifiWakeup = u.getWifiRadioApWakeupCount(which); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 3274 | final long btBytesRx = u.getNetworkActivityBytes(NETWORK_BT_RX_DATA, which); |
| 3275 | final long btBytesTx = u.getNetworkActivityBytes(NETWORK_BT_TX_DATA, which); |
Amith Yamasani | 59fe841 | 2017-03-03 16:28:52 -0800 | [diff] [blame] | 3276 | // Background data transfers |
| 3277 | final long mobileBytesBgRx = u.getNetworkActivityBytes(NETWORK_MOBILE_BG_RX_DATA, |
| 3278 | which); |
| 3279 | final long mobileBytesBgTx = u.getNetworkActivityBytes(NETWORK_MOBILE_BG_TX_DATA, |
| 3280 | which); |
| 3281 | final long wifiBytesBgRx = u.getNetworkActivityBytes(NETWORK_WIFI_BG_RX_DATA, which); |
| 3282 | final long wifiBytesBgTx = u.getNetworkActivityBytes(NETWORK_WIFI_BG_TX_DATA, which); |
| 3283 | final long mobilePacketsBgRx = u.getNetworkActivityPackets(NETWORK_MOBILE_BG_RX_DATA, |
| 3284 | which); |
| 3285 | final long mobilePacketsBgTx = u.getNetworkActivityPackets(NETWORK_MOBILE_BG_TX_DATA, |
| 3286 | which); |
| 3287 | final long wifiPacketsBgRx = u.getNetworkActivityPackets(NETWORK_WIFI_BG_RX_DATA, |
| 3288 | which); |
| 3289 | final long wifiPacketsBgTx = u.getNetworkActivityPackets(NETWORK_WIFI_BG_TX_DATA, |
| 3290 | which); |
| 3291 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3292 | if (mobileBytesRx > 0 || mobileBytesTx > 0 || wifiBytesRx > 0 || wifiBytesTx > 0 |
| 3293 | || mobilePacketsRx > 0 || mobilePacketsTx > 0 || wifiPacketsRx > 0 |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 3294 | || wifiPacketsTx > 0 || mobileActiveTime > 0 || mobileActiveCount > 0 |
Amith Yamasani | 59fe841 | 2017-03-03 16:28:52 -0800 | [diff] [blame] | 3295 | || btBytesRx > 0 || btBytesTx > 0 || mobileWakeup > 0 || wifiWakeup > 0 |
| 3296 | || mobileBytesBgRx > 0 || mobileBytesBgTx > 0 || wifiBytesBgRx > 0 |
| 3297 | || wifiBytesBgTx > 0 |
| 3298 | || mobilePacketsBgRx > 0 || mobilePacketsBgTx > 0 || wifiPacketsBgRx > 0 |
| 3299 | || wifiPacketsBgTx > 0) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3300 | dumpLine(pw, uid, category, NETWORK_DATA, mobileBytesRx, mobileBytesTx, |
| 3301 | wifiBytesRx, wifiBytesTx, |
| 3302 | mobilePacketsRx, mobilePacketsTx, |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 3303 | wifiPacketsRx, wifiPacketsTx, |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 3304 | mobileActiveTime, mobileActiveCount, |
Amith Yamasani | 59fe841 | 2017-03-03 16:28:52 -0800 | [diff] [blame] | 3305 | btBytesRx, btBytesTx, mobileWakeup, wifiWakeup, |
| 3306 | mobileBytesBgRx, mobileBytesBgTx, wifiBytesBgRx, wifiBytesBgTx, |
| 3307 | mobilePacketsBgRx, mobilePacketsBgTx, wifiPacketsBgRx, wifiPacketsBgTx |
| 3308 | ); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 3309 | } |
| 3310 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3311 | // Dump modem controller data, per UID. |
| 3312 | dumpControllerActivityLine(pw, uid, category, MODEM_CONTROLLER_DATA, |
| 3313 | u.getModemControllerActivity(), which); |
| 3314 | |
| 3315 | // Dump Wifi controller data, per UID. |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 3316 | final long fullWifiLockOnTime = u.getFullWifiLockTime(rawRealtime, which); |
| 3317 | final long wifiScanTime = u.getWifiScanTime(rawRealtime, which); |
| 3318 | final int wifiScanCount = u.getWifiScanCount(which); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 3319 | final int wifiScanCountBg = u.getWifiScanBackgroundCount(which); |
| 3320 | // Note that 'ActualTime' are unpooled and always since reset (regardless of 'which') |
Bookatz | ce49aca | 2017-04-03 09:47:05 -0700 | [diff] [blame] | 3321 | final long wifiScanActualTimeMs = (u.getWifiScanActualTime(rawRealtime) + 500) / 1000; |
| 3322 | final long wifiScanActualTimeMsBg = (u.getWifiScanBackgroundTime(rawRealtime) + 500) |
| 3323 | / 1000; |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 3324 | final long uidWifiRunningTime = u.getWifiRunningTime(rawRealtime, which); |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 3325 | if (fullWifiLockOnTime != 0 || wifiScanTime != 0 || wifiScanCount != 0 |
Bookatz | ce49aca | 2017-04-03 09:47:05 -0700 | [diff] [blame] | 3326 | || wifiScanCountBg != 0 || wifiScanActualTimeMs != 0 |
| 3327 | || wifiScanActualTimeMsBg != 0 || uidWifiRunningTime != 0) { |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3328 | dumpLine(pw, uid, category, WIFI_DATA, fullWifiLockOnTime, wifiScanTime, |
| 3329 | uidWifiRunningTime, wifiScanCount, |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 3330 | /* legacy fields follow, keep at 0 */ 0, 0, 0, |
Bookatz | ce49aca | 2017-04-03 09:47:05 -0700 | [diff] [blame] | 3331 | wifiScanCountBg, wifiScanActualTimeMs, wifiScanActualTimeMsBg); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3332 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3333 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3334 | dumpControllerActivityLine(pw, uid, category, WIFI_CONTROLLER_DATA, |
| 3335 | u.getWifiControllerActivity(), which); |
| 3336 | |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 3337 | final Timer bleTimer = u.getBluetoothScanTimer(); |
| 3338 | if (bleTimer != null) { |
| 3339 | // Convert from microseconds to milliseconds with rounding |
| 3340 | final long totalTime = (bleTimer.getTotalTimeLocked(rawRealtime, which) + 500) |
| 3341 | / 1000; |
| 3342 | if (totalTime != 0) { |
| 3343 | final int count = bleTimer.getCountLocked(which); |
| 3344 | final Timer bleTimerBg = u.getBluetoothScanBackgroundTimer(); |
| 3345 | final int countBg = bleTimerBg != null ? bleTimerBg.getCountLocked(which) : 0; |
| 3346 | final long rawRealtimeMs = (rawRealtime + 500) / 1000; |
| 3347 | // 'actualTime' are unpooled and always since reset (regardless of 'which') |
| 3348 | final long actualTime = bleTimer.getTotalDurationMsLocked(rawRealtimeMs); |
| 3349 | final long actualTimeBg = bleTimerBg != null ? |
| 3350 | bleTimerBg.getTotalDurationMsLocked(rawRealtimeMs) : 0; |
Bookatz | 956f36bf | 2017-04-28 09:48:17 -0700 | [diff] [blame^] | 3351 | final int resultCount = u.getBluetoothScanResultCounter() != null ? |
| 3352 | u.getBluetoothScanResultCounter().getCountLocked(which) : 0; |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 3353 | dumpLine(pw, uid, category, BLUETOOTH_MISC_DATA, totalTime, count, |
Bookatz | 956f36bf | 2017-04-28 09:48:17 -0700 | [diff] [blame^] | 3354 | countBg, actualTime, actualTimeBg, resultCount); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 3355 | } |
| 3356 | } |
Adam Lesinski | d9b99be | 2016-03-30 16:58:51 -0700 | [diff] [blame] | 3357 | |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 3358 | dumpControllerActivityLine(pw, uid, category, BLUETOOTH_CONTROLLER_DATA, |
| 3359 | u.getBluetoothControllerActivity(), which); |
| 3360 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3361 | if (u.hasUserActivity()) { |
| 3362 | args = new Object[Uid.NUM_USER_ACTIVITY_TYPES]; |
| 3363 | boolean hasData = false; |
| 3364 | for (int i=0; i<Uid.NUM_USER_ACTIVITY_TYPES; i++) { |
| 3365 | int val = u.getUserActivityCount(i, which); |
| 3366 | args[i] = val; |
| 3367 | if (val != 0) hasData = true; |
| 3368 | } |
| 3369 | if (hasData) { |
Ashish Sharma | cba1215 | 2014-07-07 17:14:52 -0700 | [diff] [blame] | 3370 | dumpLine(pw, uid /* uid */, category, USER_ACTIVITY_DATA, args); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3371 | } |
| 3372 | } |
| 3373 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3374 | final ArrayMap<String, ? extends Uid.Wakelock> wakelocks = u.getWakelockStats(); |
| 3375 | for (int iw=wakelocks.size()-1; iw>=0; iw--) { |
| 3376 | final Uid.Wakelock wl = wakelocks.valueAt(iw); |
| 3377 | String linePrefix = ""; |
| 3378 | sb.setLength(0); |
| 3379 | linePrefix = printWakeLockCheckin(sb, wl.getWakeTime(WAKE_TYPE_FULL), |
| 3380 | rawRealtime, "f", which, linePrefix); |
| 3381 | linePrefix = printWakeLockCheckin(sb, wl.getWakeTime(WAKE_TYPE_PARTIAL), |
| 3382 | rawRealtime, "p", which, linePrefix); |
| 3383 | linePrefix = printWakeLockCheckin(sb, wl.getWakeTime(WAKE_TYPE_WINDOW), |
| 3384 | rawRealtime, "w", which, linePrefix); |
| 3385 | |
| 3386 | // Only log if we had at lease one wakelock... |
| 3387 | if (sb.length() > 0) { |
| 3388 | String name = wakelocks.keyAt(iw); |
| 3389 | if (name.indexOf(',') >= 0) { |
| 3390 | name = name.replace(',', '_'); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3391 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3392 | dumpLine(pw, uid, category, WAKELOCK_DATA, name, sb.toString()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3393 | } |
| 3394 | } |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 3395 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3396 | final ArrayMap<String, ? extends Timer> syncs = u.getSyncStats(); |
| 3397 | for (int isy=syncs.size()-1; isy>=0; isy--) { |
| 3398 | final Timer timer = syncs.valueAt(isy); |
| 3399 | // Convert from microseconds to milliseconds with rounding |
| 3400 | final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000; |
| 3401 | final int count = timer.getCountLocked(which); |
Bookatz | 2bffb5b | 2017-04-13 11:59:33 -0700 | [diff] [blame] | 3402 | final Timer bgTimer = timer.getSubTimer(); |
| 3403 | final long bgTime = bgTimer != null ? |
| 3404 | (bgTimer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000 : -1; |
| 3405 | final int bgCount = bgTimer != null ? bgTimer.getCountLocked(which) : -1; |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3406 | if (totalTime != 0) { |
Kweku Adams | e0dd9c1 | 2017-03-08 08:12:15 -0800 | [diff] [blame] | 3407 | dumpLine(pw, uid, category, SYNC_DATA, "\"" + syncs.keyAt(isy) + "\"", |
Bookatz | 2bffb5b | 2017-04-13 11:59:33 -0700 | [diff] [blame] | 3408 | totalTime, count, bgTime, bgCount); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 3409 | } |
| 3410 | } |
| 3411 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3412 | final ArrayMap<String, ? extends Timer> jobs = u.getJobStats(); |
| 3413 | for (int ij=jobs.size()-1; ij>=0; ij--) { |
| 3414 | final Timer timer = jobs.valueAt(ij); |
| 3415 | // Convert from microseconds to milliseconds with rounding |
| 3416 | final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000; |
| 3417 | final int count = timer.getCountLocked(which); |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 3418 | final Timer bgTimer = timer.getSubTimer(); |
| 3419 | final long bgTime = bgTimer != null ? |
| 3420 | (bgTimer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000 : -1; |
| 3421 | final int bgCount = bgTimer != null ? bgTimer.getCountLocked(which) : -1; |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3422 | if (totalTime != 0) { |
Kweku Adams | e0dd9c1 | 2017-03-08 08:12:15 -0800 | [diff] [blame] | 3423 | dumpLine(pw, uid, category, JOB_DATA, "\"" + jobs.keyAt(ij) + "\"", |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 3424 | totalTime, count, bgTime, bgCount); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 3425 | } |
| 3426 | } |
| 3427 | |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 3428 | dumpTimer(pw, uid, category, FLASHLIGHT_DATA, u.getFlashlightTurnedOnTimer(), |
| 3429 | rawRealtime, which); |
| 3430 | dumpTimer(pw, uid, category, CAMERA_DATA, u.getCameraTurnedOnTimer(), |
| 3431 | rawRealtime, which); |
| 3432 | dumpTimer(pw, uid, category, VIDEO_DATA, u.getVideoTurnedOnTimer(), |
| 3433 | rawRealtime, which); |
| 3434 | dumpTimer(pw, uid, category, AUDIO_DATA, u.getAudioTurnedOnTimer(), |
| 3435 | rawRealtime, which); |
| 3436 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3437 | final SparseArray<? extends BatteryStats.Uid.Sensor> sensors = u.getSensorStats(); |
| 3438 | final int NSE = sensors.size(); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 3439 | for (int ise=0; ise<NSE; ise++) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3440 | final Uid.Sensor se = sensors.valueAt(ise); |
| 3441 | final int sensorNumber = sensors.keyAt(ise); |
| 3442 | final Timer timer = se.getSensorTime(); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 3443 | if (timer != null) { |
| 3444 | // Convert from microseconds to milliseconds with rounding |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3445 | final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) |
| 3446 | / 1000; |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 3447 | if (totalTime != 0) { |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 3448 | final int count = timer.getCountLocked(which); |
| 3449 | final Timer bgTimer = se.getSensorBackgroundTime(); |
| 3450 | final int bgCount = bgTimer != null ? bgTimer.getCountLocked(which) : 0; |
| 3451 | final long rawRealtimeMs = (rawRealtime + 500) / 1000; |
| 3452 | // 'actualTime' are unpooled and always since reset (regardless of 'which') |
| 3453 | final long actualTime = timer.getTotalDurationMsLocked(rawRealtimeMs); |
| 3454 | final long bgActualTime = bgTimer != null ? |
| 3455 | bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : 0; |
| 3456 | dumpLine(pw, uid, category, SENSOR_DATA, sensorNumber, totalTime, |
| 3457 | count, bgCount, actualTime, bgActualTime); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 3458 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3459 | } |
| 3460 | } |
| 3461 | |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 3462 | dumpTimer(pw, uid, category, VIBRATOR_DATA, u.getVibratorOnTimer(), |
| 3463 | rawRealtime, which); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 3464 | |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 3465 | dumpTimer(pw, uid, category, FOREGROUND_DATA, u.getForegroundActivityTimer(), |
| 3466 | rawRealtime, which); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 3467 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3468 | final Object[] stateTimes = new Object[Uid.NUM_PROCESS_STATE]; |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 3469 | long totalStateTime = 0; |
| 3470 | for (int ips=0; ips<Uid.NUM_PROCESS_STATE; ips++) { |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 3471 | final long time = u.getProcessStateTime(ips, rawRealtime, which); |
| 3472 | totalStateTime += time; |
| 3473 | stateTimes[ips] = (time + 500) / 1000; |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 3474 | } |
| 3475 | if (totalStateTime > 0) { |
| 3476 | dumpLine(pw, uid, category, STATE_TIME_DATA, stateTimes); |
| 3477 | } |
| 3478 | |
Adam Lesinski | a7a4ccc | 2015-06-26 17:43:04 -0700 | [diff] [blame] | 3479 | final long userCpuTimeUs = u.getUserCpuTimeUs(which); |
| 3480 | final long systemCpuTimeUs = u.getSystemCpuTimeUs(which); |
Adam Lesinski | d4abd1e | 2017-04-12 11:29:13 -0700 | [diff] [blame] | 3481 | if (userCpuTimeUs > 0 || systemCpuTimeUs > 0) { |
Adam Lesinski | a7a4ccc | 2015-06-26 17:43:04 -0700 | [diff] [blame] | 3482 | dumpLine(pw, uid, category, CPU_DATA, userCpuTimeUs / 1000, systemCpuTimeUs / 1000, |
Adam Lesinski | d4abd1e | 2017-04-12 11:29:13 -0700 | [diff] [blame] | 3483 | 0 /* old cpu power, keep for compatibility */); |
Adam Lesinski | a7a4ccc | 2015-06-26 17:43:04 -0700 | [diff] [blame] | 3484 | } |
| 3485 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3486 | final ArrayMap<String, ? extends BatteryStats.Uid.Proc> processStats |
| 3487 | = u.getProcessStats(); |
| 3488 | for (int ipr=processStats.size()-1; ipr>=0; ipr--) { |
| 3489 | final Uid.Proc ps = processStats.valueAt(ipr); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 3490 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3491 | final long userMillis = ps.getUserTime(which); |
| 3492 | final long systemMillis = ps.getSystemTime(which); |
| 3493 | final long foregroundMillis = ps.getForegroundTime(which); |
| 3494 | final int starts = ps.getStarts(which); |
| 3495 | final int numCrashes = ps.getNumCrashes(which); |
| 3496 | final int numAnrs = ps.getNumAnrs(which); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 3497 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3498 | if (userMillis != 0 || systemMillis != 0 || foregroundMillis != 0 |
| 3499 | || starts != 0 || numAnrs != 0 || numCrashes != 0) { |
Kweku Adams | e0dd9c1 | 2017-03-08 08:12:15 -0800 | [diff] [blame] | 3500 | dumpLine(pw, uid, category, PROCESS_DATA, "\"" + processStats.keyAt(ipr) + "\"", |
| 3501 | userMillis, systemMillis, foregroundMillis, starts, numAnrs, numCrashes); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3502 | } |
| 3503 | } |
| 3504 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3505 | final ArrayMap<String, ? extends BatteryStats.Uid.Pkg> packageStats |
| 3506 | = u.getPackageStats(); |
| 3507 | for (int ipkg=packageStats.size()-1; ipkg>=0; ipkg--) { |
| 3508 | final Uid.Pkg ps = packageStats.valueAt(ipkg); |
| 3509 | int wakeups = 0; |
| 3510 | final ArrayMap<String, ? extends Counter> alarms = ps.getWakeupAlarmStats(); |
| 3511 | for (int iwa=alarms.size()-1; iwa>=0; iwa--) { |
Joe Onorato | 1476d32 | 2016-05-05 14:46:15 -0700 | [diff] [blame] | 3512 | int count = alarms.valueAt(iwa).getCountLocked(which); |
| 3513 | wakeups += count; |
| 3514 | String name = alarms.keyAt(iwa).replace(',', '_'); |
| 3515 | dumpLine(pw, uid, category, WAKEUP_ALARM_DATA, name, count); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3516 | } |
| 3517 | final ArrayMap<String, ? extends Uid.Pkg.Serv> serviceStats = ps.getServiceStats(); |
| 3518 | for (int isvc=serviceStats.size()-1; isvc>=0; isvc--) { |
| 3519 | final BatteryStats.Uid.Pkg.Serv ss = serviceStats.valueAt(isvc); |
| 3520 | final long startTime = ss.getStartTime(batteryUptime, which); |
| 3521 | final int starts = ss.getStarts(which); |
| 3522 | final int launches = ss.getLaunches(which); |
| 3523 | if (startTime != 0 || starts != 0 || launches != 0) { |
| 3524 | dumpLine(pw, uid, category, APK_DATA, |
| 3525 | wakeups, // wakeup alarms |
| 3526 | packageStats.keyAt(ipkg), // Apk |
| 3527 | serviceStats.keyAt(isvc), // service |
| 3528 | startTime / 1000, // time spent started, in ms |
| 3529 | starts, |
| 3530 | launches); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3531 | } |
| 3532 | } |
| 3533 | } |
| 3534 | } |
| 3535 | } |
| 3536 | |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 3537 | static final class TimerEntry { |
| 3538 | final String mName; |
| 3539 | final int mId; |
| 3540 | final BatteryStats.Timer mTimer; |
| 3541 | final long mTime; |
| 3542 | TimerEntry(String name, int id, BatteryStats.Timer timer, long time) { |
| 3543 | mName = name; |
| 3544 | mId = id; |
| 3545 | mTimer = timer; |
| 3546 | mTime = time; |
| 3547 | } |
| 3548 | } |
| 3549 | |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3550 | private void printmAh(PrintWriter printer, double power) { |
| 3551 | printer.print(BatteryStatsHelper.makemAh(power)); |
| 3552 | } |
| 3553 | |
Adam Lesinski | a7a4ccc | 2015-06-26 17:43:04 -0700 | [diff] [blame] | 3554 | private void printmAh(StringBuilder sb, double power) { |
| 3555 | sb.append(BatteryStatsHelper.makemAh(power)); |
| 3556 | } |
| 3557 | |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 3558 | /** |
| 3559 | * Temporary for settings. |
| 3560 | */ |
| 3561 | public final void dumpLocked(Context context, PrintWriter pw, String prefix, int which, |
| 3562 | int reqUid) { |
| 3563 | dumpLocked(context, pw, prefix, which, reqUid, BatteryStatsHelper.checkWifiOnly(context)); |
| 3564 | } |
| 3565 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3566 | @SuppressWarnings("unused") |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3567 | 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] | 3568 | int reqUid, boolean wifiOnly) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3569 | final long rawUptime = SystemClock.uptimeMillis() * 1000; |
| 3570 | final long rawRealtime = SystemClock.elapsedRealtime() * 1000; |
| 3571 | final long batteryUptime = getBatteryUptime(rawUptime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3572 | |
| 3573 | final long whichBatteryUptime = computeBatteryUptime(rawUptime, which); |
| 3574 | final long whichBatteryRealtime = computeBatteryRealtime(rawRealtime, which); |
| 3575 | final long totalRealtime = computeRealtime(rawRealtime, which); |
| 3576 | final long totalUptime = computeUptime(rawUptime, which); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3577 | final long whichBatteryScreenOffUptime = computeBatteryScreenOffUptime(rawUptime, which); |
| 3578 | final long whichBatteryScreenOffRealtime = computeBatteryScreenOffRealtime(rawRealtime, |
| 3579 | which); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 3580 | final long batteryTimeRemaining = computeBatteryTimeRemaining(rawRealtime); |
| 3581 | final long chargeTimeRemaining = computeChargeTimeRemaining(rawRealtime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3582 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3583 | final StringBuilder sb = new StringBuilder(128); |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 3584 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3585 | final SparseArray<? extends Uid> uidStats = getUidStats(); |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 3586 | final int NU = uidStats.size(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3587 | |
Adam Lesinski | f9b20a9 | 2016-06-17 17:30:01 -0700 | [diff] [blame] | 3588 | final int estimatedBatteryCapacity = getEstimatedBatteryCapacity(); |
| 3589 | if (estimatedBatteryCapacity > 0) { |
| 3590 | sb.setLength(0); |
| 3591 | sb.append(prefix); |
| 3592 | sb.append(" Estimated battery capacity: "); |
| 3593 | sb.append(BatteryStatsHelper.makemAh(estimatedBatteryCapacity)); |
| 3594 | sb.append(" mAh"); |
| 3595 | pw.println(sb.toString()); |
| 3596 | } |
| 3597 | |
Jocelyn Dang | c627d10 | 2017-04-14 13:15:14 -0700 | [diff] [blame] | 3598 | final int minLearnedBatteryCapacity = getMinLearnedBatteryCapacity(); |
| 3599 | if (minLearnedBatteryCapacity > 0) { |
| 3600 | sb.setLength(0); |
| 3601 | sb.append(prefix); |
| 3602 | sb.append(" Min learned battery capacity: "); |
| 3603 | sb.append(BatteryStatsHelper.makemAh(minLearnedBatteryCapacity / 1000)); |
| 3604 | sb.append(" mAh"); |
| 3605 | pw.println(sb.toString()); |
| 3606 | } |
| 3607 | final int maxLearnedBatteryCapacity = getMaxLearnedBatteryCapacity(); |
| 3608 | if (maxLearnedBatteryCapacity > 0) { |
| 3609 | sb.setLength(0); |
| 3610 | sb.append(prefix); |
| 3611 | sb.append(" Max learned battery capacity: "); |
| 3612 | sb.append(BatteryStatsHelper.makemAh(maxLearnedBatteryCapacity / 1000)); |
| 3613 | sb.append(" mAh"); |
| 3614 | pw.println(sb.toString()); |
| 3615 | } |
| 3616 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3617 | sb.setLength(0); |
| 3618 | sb.append(prefix); |
| 3619 | sb.append(" Time on battery: "); |
| 3620 | formatTimeMs(sb, whichBatteryRealtime / 1000); sb.append("("); |
| 3621 | sb.append(formatRatioLocked(whichBatteryRealtime, totalRealtime)); |
| 3622 | sb.append(") realtime, "); |
| 3623 | formatTimeMs(sb, whichBatteryUptime / 1000); |
| 3624 | sb.append("("); sb.append(formatRatioLocked(whichBatteryUptime, totalRealtime)); |
| 3625 | sb.append(") uptime"); |
| 3626 | pw.println(sb.toString()); |
| 3627 | sb.setLength(0); |
| 3628 | sb.append(prefix); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3629 | sb.append(" Time on battery screen off: "); |
| 3630 | formatTimeMs(sb, whichBatteryScreenOffRealtime / 1000); sb.append("("); |
| 3631 | sb.append(formatRatioLocked(whichBatteryScreenOffRealtime, totalRealtime)); |
| 3632 | sb.append(") realtime, "); |
| 3633 | formatTimeMs(sb, whichBatteryScreenOffUptime / 1000); |
| 3634 | sb.append("("); |
| 3635 | sb.append(formatRatioLocked(whichBatteryScreenOffUptime, totalRealtime)); |
| 3636 | sb.append(") uptime"); |
| 3637 | pw.println(sb.toString()); |
| 3638 | sb.setLength(0); |
| 3639 | sb.append(prefix); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3640 | sb.append(" Total run time: "); |
| 3641 | formatTimeMs(sb, totalRealtime / 1000); |
| 3642 | sb.append("realtime, "); |
| 3643 | formatTimeMs(sb, totalUptime / 1000); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 3644 | sb.append("uptime"); |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 3645 | pw.println(sb.toString()); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 3646 | if (batteryTimeRemaining >= 0) { |
| 3647 | sb.setLength(0); |
| 3648 | sb.append(prefix); |
| 3649 | sb.append(" Battery time remaining: "); |
| 3650 | formatTimeMs(sb, batteryTimeRemaining / 1000); |
| 3651 | pw.println(sb.toString()); |
| 3652 | } |
| 3653 | if (chargeTimeRemaining >= 0) { |
| 3654 | sb.setLength(0); |
| 3655 | sb.append(prefix); |
| 3656 | sb.append(" Charge time remaining: "); |
| 3657 | formatTimeMs(sb, chargeTimeRemaining / 1000); |
| 3658 | pw.println(sb.toString()); |
| 3659 | } |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 3660 | |
| 3661 | final LongCounter dischargeCounter = getDischargeCoulombCounter(); |
| 3662 | final long dischargeCount = dischargeCounter.getCountLocked(which); |
| 3663 | if (dischargeCount >= 0) { |
| 3664 | sb.setLength(0); |
| 3665 | sb.append(prefix); |
| 3666 | sb.append(" Discharge: "); |
| 3667 | sb.append(BatteryStatsHelper.makemAh(dischargeCount / 1000.0)); |
| 3668 | sb.append(" mAh"); |
| 3669 | pw.println(sb.toString()); |
| 3670 | } |
| 3671 | |
| 3672 | final LongCounter dischargeScreenOffCounter = getDischargeScreenOffCoulombCounter(); |
| 3673 | final long dischargeScreenOffCount = dischargeScreenOffCounter.getCountLocked(which); |
| 3674 | if (dischargeScreenOffCount >= 0) { |
| 3675 | sb.setLength(0); |
| 3676 | sb.append(prefix); |
| 3677 | sb.append(" Screen off discharge: "); |
| 3678 | sb.append(BatteryStatsHelper.makemAh(dischargeScreenOffCount / 1000.0)); |
| 3679 | sb.append(" mAh"); |
| 3680 | pw.println(sb.toString()); |
| 3681 | } |
| 3682 | |
| 3683 | final long dischargeScreenOnCount = dischargeCount - dischargeScreenOffCount; |
| 3684 | if (dischargeScreenOnCount >= 0) { |
| 3685 | sb.setLength(0); |
| 3686 | sb.append(prefix); |
| 3687 | sb.append(" Screen on discharge: "); |
| 3688 | sb.append(BatteryStatsHelper.makemAh(dischargeScreenOnCount / 1000.0)); |
| 3689 | sb.append(" mAh"); |
| 3690 | pw.println(sb.toString()); |
| 3691 | } |
| 3692 | |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 3693 | pw.print(" Start clock time: "); |
| 3694 | pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss", getStartClockTime()).toString()); |
| 3695 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3696 | final long screenOnTime = getScreenOnTime(rawRealtime, which); |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 3697 | final long interactiveTime = getInteractiveTime(rawRealtime, which); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3698 | final long powerSaveModeEnabledTime = getPowerSaveModeEnabledTime(rawRealtime, which); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3699 | final long deviceIdleModeLightTime = getDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT, |
| 3700 | rawRealtime, which); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 3701 | final long deviceIdleModeFullTime = getDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP, |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3702 | rawRealtime, which); |
| 3703 | final long deviceLightIdlingTime = getDeviceIdlingTime(DEVICE_IDLE_MODE_LIGHT, |
| 3704 | rawRealtime, which); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 3705 | final long deviceIdlingTime = getDeviceIdlingTime(DEVICE_IDLE_MODE_DEEP, |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3706 | rawRealtime, which); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3707 | final long phoneOnTime = getPhoneOnTime(rawRealtime, which); |
| 3708 | final long wifiRunningTime = getGlobalWifiRunningTime(rawRealtime, which); |
| 3709 | final long wifiOnTime = getWifiOnTime(rawRealtime, which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3710 | sb.setLength(0); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3711 | sb.append(prefix); |
| 3712 | sb.append(" Screen on: "); formatTimeMs(sb, screenOnTime / 1000); |
| 3713 | sb.append("("); sb.append(formatRatioLocked(screenOnTime, whichBatteryRealtime)); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 3714 | sb.append(") "); sb.append(getScreenOnCount(which)); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3715 | sb.append("x, Interactive: "); formatTimeMs(sb, interactiveTime / 1000); |
| 3716 | sb.append("("); sb.append(formatRatioLocked(interactiveTime, whichBatteryRealtime)); |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 3717 | sb.append(")"); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3718 | pw.println(sb.toString()); |
| 3719 | sb.setLength(0); |
| 3720 | sb.append(prefix); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 3721 | sb.append(" Screen brightnesses:"); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3722 | boolean didOne = false; |
| 3723 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3724 | final long time = getScreenBrightnessTime(i, rawRealtime, which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3725 | if (time == 0) { |
| 3726 | continue; |
| 3727 | } |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 3728 | sb.append("\n "); |
| 3729 | sb.append(prefix); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3730 | didOne = true; |
| 3731 | sb.append(SCREEN_BRIGHTNESS_NAMES[i]); |
| 3732 | sb.append(" "); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3733 | formatTimeMs(sb, time/1000); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3734 | sb.append("("); |
| 3735 | sb.append(formatRatioLocked(time, screenOnTime)); |
| 3736 | sb.append(")"); |
| 3737 | } |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 3738 | if (!didOne) sb.append(" (no activity)"); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3739 | pw.println(sb.toString()); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3740 | if (powerSaveModeEnabledTime != 0) { |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3741 | sb.setLength(0); |
| 3742 | sb.append(prefix); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3743 | sb.append(" Power save mode enabled: "); |
| 3744 | formatTimeMs(sb, powerSaveModeEnabledTime / 1000); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3745 | sb.append("("); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3746 | sb.append(formatRatioLocked(powerSaveModeEnabledTime, whichBatteryRealtime)); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3747 | sb.append(")"); |
| 3748 | pw.println(sb.toString()); |
| 3749 | } |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3750 | if (deviceLightIdlingTime != 0) { |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3751 | sb.setLength(0); |
| 3752 | sb.append(prefix); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3753 | sb.append(" Device light idling: "); |
| 3754 | formatTimeMs(sb, deviceLightIdlingTime / 1000); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 3755 | sb.append("("); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3756 | sb.append(formatRatioLocked(deviceLightIdlingTime, whichBatteryRealtime)); |
| 3757 | sb.append(") "); sb.append(getDeviceIdlingCount(DEVICE_IDLE_MODE_LIGHT, which)); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 3758 | sb.append("x"); |
| 3759 | pw.println(sb.toString()); |
| 3760 | } |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3761 | if (deviceIdleModeLightTime != 0) { |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 3762 | sb.setLength(0); |
| 3763 | sb.append(prefix); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3764 | sb.append(" Idle mode light time: "); |
| 3765 | formatTimeMs(sb, deviceIdleModeLightTime / 1000); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3766 | sb.append("("); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3767 | sb.append(formatRatioLocked(deviceIdleModeLightTime, whichBatteryRealtime)); |
| 3768 | sb.append(") "); |
| 3769 | sb.append(getDeviceIdleModeCount(DEVICE_IDLE_MODE_LIGHT, which)); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3770 | sb.append("x"); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3771 | sb.append(" -- longest "); |
| 3772 | formatTimeMs(sb, getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT)); |
| 3773 | pw.println(sb.toString()); |
| 3774 | } |
| 3775 | if (deviceIdlingTime != 0) { |
| 3776 | sb.setLength(0); |
| 3777 | sb.append(prefix); |
| 3778 | sb.append(" Device full idling: "); |
| 3779 | formatTimeMs(sb, deviceIdlingTime / 1000); |
| 3780 | sb.append("("); |
| 3781 | sb.append(formatRatioLocked(deviceIdlingTime, whichBatteryRealtime)); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 3782 | sb.append(") "); sb.append(getDeviceIdlingCount(DEVICE_IDLE_MODE_DEEP, which)); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3783 | sb.append("x"); |
| 3784 | pw.println(sb.toString()); |
| 3785 | } |
| 3786 | if (deviceIdleModeFullTime != 0) { |
| 3787 | sb.setLength(0); |
| 3788 | sb.append(prefix); |
| 3789 | sb.append(" Idle mode full time: "); |
| 3790 | formatTimeMs(sb, deviceIdleModeFullTime / 1000); |
| 3791 | sb.append("("); |
| 3792 | sb.append(formatRatioLocked(deviceIdleModeFullTime, whichBatteryRealtime)); |
| 3793 | sb.append(") "); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 3794 | sb.append(getDeviceIdleModeCount(DEVICE_IDLE_MODE_DEEP, which)); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3795 | sb.append("x"); |
| 3796 | sb.append(" -- longest "); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 3797 | formatTimeMs(sb, getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP)); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3798 | pw.println(sb.toString()); |
| 3799 | } |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3800 | if (phoneOnTime != 0) { |
| 3801 | sb.setLength(0); |
| 3802 | sb.append(prefix); |
| 3803 | sb.append(" Active phone call: "); formatTimeMs(sb, phoneOnTime / 1000); |
| 3804 | sb.append("("); sb.append(formatRatioLocked(phoneOnTime, whichBatteryRealtime)); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3805 | sb.append(") "); sb.append(getPhoneOnCount(which)); sb.append("x"); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3806 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3807 | final int connChanges = getNumConnectivityChange(which); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 3808 | if (connChanges != 0) { |
| 3809 | pw.print(prefix); |
| 3810 | pw.print(" Connectivity changes: "); pw.println(connChanges); |
| 3811 | } |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3812 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3813 | // Calculate wakelock times across all uids. |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 3814 | long fullWakeLockTimeTotalMicros = 0; |
| 3815 | long partialWakeLockTimeTotalMicros = 0; |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 3816 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3817 | final ArrayList<TimerEntry> timers = new ArrayList<>(); |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 3818 | |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 3819 | for (int iu = 0; iu < NU; iu++) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3820 | final Uid u = uidStats.valueAt(iu); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 3821 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3822 | final ArrayMap<String, ? extends BatteryStats.Uid.Wakelock> wakelocks |
| 3823 | = u.getWakelockStats(); |
| 3824 | for (int iw=wakelocks.size()-1; iw>=0; iw--) { |
| 3825 | final Uid.Wakelock wl = wakelocks.valueAt(iw); |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 3826 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3827 | final Timer fullWakeTimer = wl.getWakeTime(WAKE_TYPE_FULL); |
| 3828 | if (fullWakeTimer != null) { |
| 3829 | fullWakeLockTimeTotalMicros += fullWakeTimer.getTotalTimeLocked( |
| 3830 | rawRealtime, which); |
| 3831 | } |
| 3832 | |
| 3833 | final Timer partialWakeTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL); |
| 3834 | if (partialWakeTimer != null) { |
| 3835 | final long totalTimeMicros = partialWakeTimer.getTotalTimeLocked( |
| 3836 | rawRealtime, which); |
| 3837 | if (totalTimeMicros > 0) { |
| 3838 | if (reqUid < 0) { |
| 3839 | // Only show the ordered list of all wake |
| 3840 | // locks if the caller is not asking for data |
| 3841 | // about a specific uid. |
| 3842 | timers.add(new TimerEntry(wakelocks.keyAt(iw), u.getUid(), |
| 3843 | partialWakeTimer, totalTimeMicros)); |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 3844 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3845 | partialWakeLockTimeTotalMicros += totalTimeMicros; |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 3846 | } |
| 3847 | } |
| 3848 | } |
| 3849 | } |
| 3850 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3851 | final long mobileRxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which); |
| 3852 | final long mobileTxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which); |
| 3853 | final long wifiRxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which); |
| 3854 | final long wifiTxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which); |
| 3855 | final long mobileRxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which); |
| 3856 | final long mobileTxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which); |
| 3857 | final long wifiRxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which); |
| 3858 | final long wifiTxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which); |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 3859 | final long btRxTotalBytes = getNetworkActivityBytes(NETWORK_BT_RX_DATA, which); |
| 3860 | final long btTxTotalBytes = getNetworkActivityBytes(NETWORK_BT_TX_DATA, which); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3861 | |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 3862 | if (fullWakeLockTimeTotalMicros != 0) { |
| 3863 | sb.setLength(0); |
| 3864 | sb.append(prefix); |
| 3865 | sb.append(" Total full wakelock time: "); formatTimeMsNoSpace(sb, |
| 3866 | (fullWakeLockTimeTotalMicros + 500) / 1000); |
| 3867 | pw.println(sb.toString()); |
| 3868 | } |
| 3869 | |
| 3870 | if (partialWakeLockTimeTotalMicros != 0) { |
| 3871 | sb.setLength(0); |
| 3872 | sb.append(prefix); |
| 3873 | sb.append(" Total partial wakelock time: "); formatTimeMsNoSpace(sb, |
| 3874 | (partialWakeLockTimeTotalMicros + 500) / 1000); |
| 3875 | pw.println(sb.toString()); |
| 3876 | } |
| 3877 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3878 | pw.print(prefix); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3879 | pw.print(" Mobile total received: "); pw.print(formatBytesLocked(mobileRxTotalBytes)); |
| 3880 | pw.print(", sent: "); pw.print(formatBytesLocked(mobileTxTotalBytes)); |
| 3881 | pw.print(" (packets received "); pw.print(mobileRxTotalPackets); |
| 3882 | pw.print(", sent "); pw.print(mobileTxTotalPackets); pw.println(")"); |
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 | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 3885 | sb.append(" Phone signal levels:"); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3886 | didOne = false; |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 3887 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3888 | final long time = getPhoneSignalStrengthTime(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; |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 3895 | sb.append(SignalStrength.SIGNAL_STRENGTH_NAMES[i]); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 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(getPhoneSignalStrengthCount(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 | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 3906 | |
| 3907 | sb.setLength(0); |
| 3908 | sb.append(prefix); |
| 3909 | sb.append(" Signal scanning time: "); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3910 | formatTimeMsNoSpace(sb, getPhoneSignalScanningTime(rawRealtime, which) / 1000); |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 3911 | pw.println(sb.toString()); |
| 3912 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3913 | sb.setLength(0); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3914 | sb.append(prefix); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3915 | sb.append(" Radio types:"); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3916 | didOne = false; |
| 3917 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3918 | final long time = getPhoneDataConnectionTime(i, rawRealtime, which); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3919 | if (time == 0) { |
| 3920 | continue; |
| 3921 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3922 | sb.append("\n "); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 3923 | sb.append(prefix); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3924 | didOne = true; |
| 3925 | sb.append(DATA_CONNECTION_NAMES[i]); |
| 3926 | sb.append(" "); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3927 | formatTimeMs(sb, time/1000); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3928 | sb.append("("); |
| 3929 | sb.append(formatRatioLocked(time, whichBatteryRealtime)); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3930 | sb.append(") "); |
| 3931 | sb.append(getPhoneDataConnectionCount(i, which)); |
| 3932 | sb.append("x"); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3933 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3934 | if (!didOne) sb.append(" (no activity)"); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3935 | pw.println(sb.toString()); |
Amith Yamasani | 3f7e35c | 2009-07-13 16:02:45 -0700 | [diff] [blame] | 3936 | |
| 3937 | sb.setLength(0); |
| 3938 | sb.append(prefix); |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 3939 | sb.append(" Mobile radio active time: "); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3940 | final long mobileActiveTime = getMobileRadioActiveTime(rawRealtime, which); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 3941 | formatTimeMs(sb, mobileActiveTime / 1000); |
| 3942 | sb.append("("); sb.append(formatRatioLocked(mobileActiveTime, whichBatteryRealtime)); |
| 3943 | sb.append(") "); sb.append(getMobileRadioActiveCount(which)); |
| 3944 | sb.append("x"); |
Amith Yamasani | 3f7e35c | 2009-07-13 16:02:45 -0700 | [diff] [blame] | 3945 | pw.println(sb.toString()); |
| 3946 | |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 3947 | final long mobileActiveUnknownTime = getMobileRadioActiveUnknownTime(which); |
| 3948 | if (mobileActiveUnknownTime != 0) { |
| 3949 | sb.setLength(0); |
| 3950 | sb.append(prefix); |
| 3951 | sb.append(" Mobile radio active unknown time: "); |
| 3952 | formatTimeMs(sb, mobileActiveUnknownTime / 1000); |
| 3953 | sb.append("("); |
| 3954 | sb.append(formatRatioLocked(mobileActiveUnknownTime, whichBatteryRealtime)); |
| 3955 | sb.append(") "); sb.append(getMobileRadioActiveUnknownCount(which)); |
| 3956 | sb.append("x"); |
| 3957 | pw.println(sb.toString()); |
| 3958 | } |
| 3959 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3960 | final long mobileActiveAdjustedTime = getMobileRadioActiveAdjustedTime(which); |
| 3961 | if (mobileActiveAdjustedTime != 0) { |
| 3962 | sb.setLength(0); |
| 3963 | sb.append(prefix); |
| 3964 | sb.append(" Mobile radio active adjusted time: "); |
| 3965 | formatTimeMs(sb, mobileActiveAdjustedTime / 1000); |
| 3966 | sb.append("("); |
| 3967 | sb.append(formatRatioLocked(mobileActiveAdjustedTime, whichBatteryRealtime)); |
| 3968 | sb.append(")"); |
| 3969 | pw.println(sb.toString()); |
| 3970 | } |
| 3971 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3972 | printControllerActivity(pw, sb, prefix, "Radio", getModemControllerActivity(), which); |
| 3973 | |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 3974 | pw.print(prefix); |
| 3975 | pw.print(" Wi-Fi total received: "); pw.print(formatBytesLocked(wifiRxTotalBytes)); |
| 3976 | pw.print(", sent: "); pw.print(formatBytesLocked(wifiTxTotalBytes)); |
| 3977 | pw.print(" (packets received "); pw.print(wifiRxTotalPackets); |
| 3978 | pw.print(", sent "); pw.print(wifiTxTotalPackets); pw.println(")"); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3979 | sb.setLength(0); |
| 3980 | sb.append(prefix); |
| 3981 | sb.append(" Wifi on: "); formatTimeMs(sb, wifiOnTime / 1000); |
| 3982 | sb.append("("); sb.append(formatRatioLocked(wifiOnTime, whichBatteryRealtime)); |
| 3983 | sb.append("), Wifi running: "); formatTimeMs(sb, wifiRunningTime / 1000); |
| 3984 | sb.append("("); sb.append(formatRatioLocked(wifiRunningTime, whichBatteryRealtime)); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3985 | sb.append(")"); |
| 3986 | pw.println(sb.toString()); |
| 3987 | |
| 3988 | sb.setLength(0); |
| 3989 | sb.append(prefix); |
| 3990 | sb.append(" Wifi states:"); |
| 3991 | didOne = false; |
| 3992 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3993 | final long time = getWifiStateTime(i, rawRealtime, which); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3994 | if (time == 0) { |
| 3995 | continue; |
| 3996 | } |
| 3997 | sb.append("\n "); |
| 3998 | didOne = true; |
| 3999 | sb.append(WIFI_STATE_NAMES[i]); |
| 4000 | sb.append(" "); |
| 4001 | formatTimeMs(sb, time/1000); |
| 4002 | sb.append("("); |
| 4003 | sb.append(formatRatioLocked(time, whichBatteryRealtime)); |
| 4004 | sb.append(") "); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 4005 | sb.append(getWifiStateCount(i, which)); |
| 4006 | sb.append("x"); |
| 4007 | } |
| 4008 | if (!didOne) sb.append(" (no activity)"); |
| 4009 | pw.println(sb.toString()); |
| 4010 | |
| 4011 | sb.setLength(0); |
| 4012 | sb.append(prefix); |
| 4013 | sb.append(" Wifi supplicant states:"); |
| 4014 | didOne = false; |
| 4015 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
| 4016 | final long time = getWifiSupplStateTime(i, rawRealtime, which); |
| 4017 | if (time == 0) { |
| 4018 | continue; |
| 4019 | } |
| 4020 | sb.append("\n "); |
| 4021 | didOne = true; |
| 4022 | sb.append(WIFI_SUPPL_STATE_NAMES[i]); |
| 4023 | sb.append(" "); |
| 4024 | formatTimeMs(sb, time/1000); |
| 4025 | sb.append("("); |
| 4026 | sb.append(formatRatioLocked(time, whichBatteryRealtime)); |
| 4027 | sb.append(") "); |
| 4028 | sb.append(getWifiSupplStateCount(i, which)); |
| 4029 | sb.append("x"); |
| 4030 | } |
| 4031 | if (!didOne) sb.append(" (no activity)"); |
| 4032 | pw.println(sb.toString()); |
| 4033 | |
| 4034 | sb.setLength(0); |
| 4035 | sb.append(prefix); |
| 4036 | sb.append(" Wifi signal levels:"); |
| 4037 | didOne = false; |
| 4038 | for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 4039 | final long time = getWifiSignalStrengthTime(i, rawRealtime, which); |
| 4040 | if (time == 0) { |
| 4041 | continue; |
| 4042 | } |
| 4043 | sb.append("\n "); |
| 4044 | sb.append(prefix); |
| 4045 | didOne = true; |
| 4046 | sb.append("level("); |
| 4047 | sb.append(i); |
| 4048 | sb.append(") "); |
| 4049 | formatTimeMs(sb, time/1000); |
| 4050 | sb.append("("); |
| 4051 | sb.append(formatRatioLocked(time, whichBatteryRealtime)); |
| 4052 | sb.append(") "); |
| 4053 | sb.append(getWifiSignalStrengthCount(i, which)); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4054 | sb.append("x"); |
| 4055 | } |
| 4056 | if (!didOne) sb.append(" (no activity)"); |
| 4057 | pw.println(sb.toString()); |
| 4058 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 4059 | printControllerActivity(pw, sb, prefix, "WiFi", getWifiControllerActivity(), which); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 4060 | |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 4061 | pw.print(prefix); |
| 4062 | pw.print(" Bluetooth total received: "); pw.print(formatBytesLocked(btRxTotalBytes)); |
| 4063 | pw.print(", sent: "); pw.println(formatBytesLocked(btTxTotalBytes)); |
| 4064 | |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 4065 | final long bluetoothScanTimeMs = getBluetoothScanTime(rawRealtime, which) / 1000; |
| 4066 | sb.setLength(0); |
| 4067 | sb.append(prefix); |
| 4068 | sb.append(" Bluetooth scan time: "); formatTimeMs(sb, bluetoothScanTimeMs); |
| 4069 | pw.println(sb.toString()); |
| 4070 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 4071 | printControllerActivity(pw, sb, prefix, "Bluetooth", getBluetoothControllerActivity(), |
| 4072 | which); |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 4073 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4074 | pw.println(); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4075 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4076 | if (which == STATS_SINCE_UNPLUGGED) { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4077 | if (getIsOnBattery()) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4078 | pw.print(prefix); pw.println(" Device is currently unplugged"); |
| 4079 | pw.print(prefix); pw.print(" Discharge cycle start level: "); |
| 4080 | pw.println(getDischargeStartLevel()); |
| 4081 | pw.print(prefix); pw.print(" Discharge cycle current level: "); |
| 4082 | pw.println(getDischargeCurrentLevel()); |
Dianne Hackborn | 99d0452 | 2010-08-20 13:43:00 -0700 | [diff] [blame] | 4083 | } else { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4084 | pw.print(prefix); pw.println(" Device is currently plugged into power"); |
| 4085 | pw.print(prefix); pw.print(" Last discharge cycle start level: "); |
| 4086 | pw.println(getDischargeStartLevel()); |
| 4087 | pw.print(prefix); pw.print(" Last discharge cycle end level: "); |
| 4088 | pw.println(getDischargeCurrentLevel()); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4089 | } |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 4090 | pw.print(prefix); pw.print(" Amount discharged while screen on: "); |
| 4091 | pw.println(getDischargeAmountScreenOn()); |
| 4092 | pw.print(prefix); pw.print(" Amount discharged while screen off: "); |
| 4093 | pw.println(getDischargeAmountScreenOff()); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4094 | pw.println(" "); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4095 | } else { |
| 4096 | pw.print(prefix); pw.println(" Device battery use since last full charge"); |
| 4097 | pw.print(prefix); pw.print(" Amount discharged (lower bound): "); |
| 4098 | pw.println(getLowDischargeAmountSinceCharge()); |
| 4099 | pw.print(prefix); pw.print(" Amount discharged (upper bound): "); |
| 4100 | pw.println(getHighDischargeAmountSinceCharge()); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 4101 | pw.print(prefix); pw.print(" Amount discharged while screen on: "); |
| 4102 | pw.println(getDischargeAmountScreenOnSinceCharge()); |
| 4103 | pw.print(prefix); pw.print(" Amount discharged while screen off: "); |
| 4104 | pw.println(getDischargeAmountScreenOffSinceCharge()); |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 4105 | pw.println(); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4106 | } |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 4107 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4108 | final BatteryStatsHelper helper = new BatteryStatsHelper(context, false, wifiOnly); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4109 | helper.create(this); |
| 4110 | helper.refreshStats(which, UserHandle.USER_ALL); |
| 4111 | List<BatterySipper> sippers = helper.getUsageList(); |
| 4112 | if (sippers != null && sippers.size() > 0) { |
| 4113 | pw.print(prefix); pw.println(" Estimated power use (mAh):"); |
| 4114 | pw.print(prefix); pw.print(" Capacity: "); |
| 4115 | printmAh(pw, helper.getPowerProfile().getBatteryCapacity()); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4116 | pw.print(", Computed drain: "); printmAh(pw, helper.getComputedPower()); |
Dianne Hackborn | 536456f | 2014-05-23 16:51:05 -0700 | [diff] [blame] | 4117 | pw.print(", actual drain: "); printmAh(pw, helper.getMinDrainedPower()); |
| 4118 | if (helper.getMinDrainedPower() != helper.getMaxDrainedPower()) { |
| 4119 | pw.print("-"); printmAh(pw, helper.getMaxDrainedPower()); |
| 4120 | } |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4121 | pw.println(); |
| 4122 | for (int i=0; i<sippers.size(); i++) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4123 | final BatterySipper bs = sippers.get(i); |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4124 | pw.print(prefix); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4125 | switch (bs.drainType) { |
| 4126 | case IDLE: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4127 | pw.print(" Idle: "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4128 | break; |
| 4129 | case CELL: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4130 | pw.print(" Cell standby: "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4131 | break; |
| 4132 | case PHONE: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4133 | pw.print(" Phone calls: "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4134 | break; |
| 4135 | case WIFI: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4136 | pw.print(" Wifi: "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4137 | break; |
| 4138 | case BLUETOOTH: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4139 | pw.print(" Bluetooth: "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4140 | break; |
| 4141 | case SCREEN: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4142 | pw.print(" Screen: "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4143 | break; |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 4144 | case FLASHLIGHT: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4145 | pw.print(" Flashlight: "); |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 4146 | break; |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4147 | case APP: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4148 | pw.print(" Uid "); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4149 | UserHandle.formatUid(pw, bs.uidObj.getUid()); |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4150 | pw.print(": "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4151 | break; |
| 4152 | case USER: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4153 | pw.print(" User "); pw.print(bs.userId); |
| 4154 | pw.print(": "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4155 | break; |
| 4156 | case UNACCOUNTED: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4157 | pw.print(" Unaccounted: "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4158 | break; |
| 4159 | case OVERCOUNTED: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4160 | pw.print(" Over-counted: "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4161 | break; |
Ruben Brunk | 5b1308f | 2015-06-03 18:49:27 -0700 | [diff] [blame] | 4162 | case CAMERA: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4163 | pw.print(" Camera: "); |
| 4164 | break; |
| 4165 | default: |
| 4166 | pw.print(" ???: "); |
Ruben Brunk | 5b1308f | 2015-06-03 18:49:27 -0700 | [diff] [blame] | 4167 | break; |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4168 | } |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4169 | printmAh(pw, bs.totalPowerMah); |
| 4170 | |
Adam Lesinski | 5712300 | 2015-06-12 16:12:07 -0700 | [diff] [blame] | 4171 | if (bs.usagePowerMah != bs.totalPowerMah) { |
| 4172 | // If the usage (generic power) isn't the whole amount, we list out |
| 4173 | // what components are involved in the calculation. |
| 4174 | |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4175 | pw.print(" ("); |
Adam Lesinski | 5712300 | 2015-06-12 16:12:07 -0700 | [diff] [blame] | 4176 | if (bs.usagePowerMah != 0) { |
| 4177 | pw.print(" usage="); |
| 4178 | printmAh(pw, bs.usagePowerMah); |
| 4179 | } |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4180 | if (bs.cpuPowerMah != 0) { |
| 4181 | pw.print(" cpu="); |
| 4182 | printmAh(pw, bs.cpuPowerMah); |
| 4183 | } |
| 4184 | if (bs.wakeLockPowerMah != 0) { |
| 4185 | pw.print(" wake="); |
| 4186 | printmAh(pw, bs.wakeLockPowerMah); |
| 4187 | } |
| 4188 | if (bs.mobileRadioPowerMah != 0) { |
| 4189 | pw.print(" radio="); |
| 4190 | printmAh(pw, bs.mobileRadioPowerMah); |
| 4191 | } |
| 4192 | if (bs.wifiPowerMah != 0) { |
| 4193 | pw.print(" wifi="); |
| 4194 | printmAh(pw, bs.wifiPowerMah); |
| 4195 | } |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 4196 | if (bs.bluetoothPowerMah != 0) { |
| 4197 | pw.print(" bt="); |
| 4198 | printmAh(pw, bs.bluetoothPowerMah); |
| 4199 | } |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4200 | if (bs.gpsPowerMah != 0) { |
| 4201 | pw.print(" gps="); |
| 4202 | printmAh(pw, bs.gpsPowerMah); |
| 4203 | } |
| 4204 | if (bs.sensorPowerMah != 0) { |
| 4205 | pw.print(" sensor="); |
| 4206 | printmAh(pw, bs.sensorPowerMah); |
| 4207 | } |
| 4208 | if (bs.cameraPowerMah != 0) { |
| 4209 | pw.print(" camera="); |
| 4210 | printmAh(pw, bs.cameraPowerMah); |
| 4211 | } |
| 4212 | if (bs.flashlightPowerMah != 0) { |
| 4213 | pw.print(" flash="); |
| 4214 | printmAh(pw, bs.flashlightPowerMah); |
| 4215 | } |
| 4216 | pw.print(" )"); |
| 4217 | } |
| 4218 | pw.println(); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4219 | } |
Dianne Hackborn | c46809e | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4220 | pw.println(); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4221 | } |
| 4222 | |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4223 | sippers = helper.getMobilemsppList(); |
| 4224 | if (sippers != null && sippers.size() > 0) { |
| 4225 | pw.print(prefix); pw.println(" Per-app mobile ms per packet:"); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 4226 | long totalTime = 0; |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4227 | for (int i=0; i<sippers.size(); i++) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4228 | final BatterySipper bs = sippers.get(i); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4229 | sb.setLength(0); |
| 4230 | sb.append(prefix); sb.append(" Uid "); |
| 4231 | UserHandle.formatUid(sb, bs.uidObj.getUid()); |
| 4232 | sb.append(": "); sb.append(BatteryStatsHelper.makemAh(bs.mobilemspp)); |
| 4233 | sb.append(" ("); sb.append(bs.mobileRxPackets+bs.mobileTxPackets); |
| 4234 | sb.append(" packets over "); formatTimeMsNoSpace(sb, bs.mobileActive); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 4235 | sb.append(") "); sb.append(bs.mobileActiveCount); sb.append("x"); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4236 | pw.println(sb.toString()); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 4237 | totalTime += bs.mobileActive; |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4238 | } |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 4239 | sb.setLength(0); |
| 4240 | sb.append(prefix); |
| 4241 | sb.append(" TOTAL TIME: "); |
| 4242 | formatTimeMs(sb, totalTime); |
| 4243 | sb.append("("); sb.append(formatRatioLocked(totalTime, whichBatteryRealtime)); |
| 4244 | sb.append(")"); |
| 4245 | pw.println(sb.toString()); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4246 | pw.println(); |
| 4247 | } |
| 4248 | |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 4249 | final Comparator<TimerEntry> timerComparator = new Comparator<TimerEntry>() { |
| 4250 | @Override |
| 4251 | public int compare(TimerEntry lhs, TimerEntry rhs) { |
| 4252 | long lhsTime = lhs.mTime; |
| 4253 | long rhsTime = rhs.mTime; |
| 4254 | if (lhsTime < rhsTime) { |
| 4255 | return 1; |
| 4256 | } |
| 4257 | if (lhsTime > rhsTime) { |
| 4258 | return -1; |
| 4259 | } |
| 4260 | return 0; |
| 4261 | } |
| 4262 | }; |
| 4263 | |
| 4264 | if (reqUid < 0) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4265 | final Map<String, ? extends BatteryStats.Timer> kernelWakelocks |
| 4266 | = getKernelWakelockStats(); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 4267 | if (kernelWakelocks.size() > 0) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4268 | final ArrayList<TimerEntry> ktimers = new ArrayList<>(); |
| 4269 | for (Map.Entry<String, ? extends BatteryStats.Timer> ent |
| 4270 | : kernelWakelocks.entrySet()) { |
| 4271 | final BatteryStats.Timer timer = ent.getValue(); |
| 4272 | final long totalTimeMillis = computeWakeLock(timer, rawRealtime, which); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 4273 | if (totalTimeMillis > 0) { |
| 4274 | ktimers.add(new TimerEntry(ent.getKey(), 0, timer, totalTimeMillis)); |
| 4275 | } |
| 4276 | } |
| 4277 | if (ktimers.size() > 0) { |
| 4278 | Collections.sort(ktimers, timerComparator); |
| 4279 | pw.print(prefix); pw.println(" All kernel wake locks:"); |
| 4280 | for (int i=0; i<ktimers.size(); i++) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4281 | final TimerEntry timer = ktimers.get(i); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 4282 | String linePrefix = ": "; |
| 4283 | sb.setLength(0); |
| 4284 | sb.append(prefix); |
| 4285 | sb.append(" Kernel Wake lock "); |
| 4286 | sb.append(timer.mName); |
| 4287 | linePrefix = printWakeLock(sb, timer.mTimer, rawRealtime, null, |
| 4288 | which, linePrefix); |
| 4289 | if (!linePrefix.equals(": ")) { |
| 4290 | sb.append(" realtime"); |
| 4291 | // Only print out wake locks that were held |
| 4292 | pw.println(sb.toString()); |
| 4293 | } |
| 4294 | } |
| 4295 | pw.println(); |
| 4296 | } |
| 4297 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 4298 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 4299 | if (timers.size() > 0) { |
| 4300 | Collections.sort(timers, timerComparator); |
| 4301 | pw.print(prefix); pw.println(" All partial wake locks:"); |
| 4302 | for (int i=0; i<timers.size(); i++) { |
| 4303 | TimerEntry timer = timers.get(i); |
| 4304 | sb.setLength(0); |
| 4305 | sb.append(" Wake lock "); |
| 4306 | UserHandle.formatUid(sb, timer.mId); |
| 4307 | sb.append(" "); |
| 4308 | sb.append(timer.mName); |
| 4309 | printWakeLock(sb, timer.mTimer, rawRealtime, null, which, ": "); |
| 4310 | sb.append(" realtime"); |
| 4311 | pw.println(sb.toString()); |
| 4312 | } |
| 4313 | timers.clear(); |
| 4314 | pw.println(); |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 4315 | } |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 4316 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4317 | final Map<String, ? extends Timer> wakeupReasons = getWakeupReasonStats(); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 4318 | if (wakeupReasons.size() > 0) { |
| 4319 | pw.print(prefix); pw.println(" All wakeup reasons:"); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4320 | final ArrayList<TimerEntry> reasons = new ArrayList<>(); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 4321 | for (Map.Entry<String, ? extends Timer> ent : wakeupReasons.entrySet()) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4322 | final Timer timer = ent.getValue(); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 4323 | reasons.add(new TimerEntry(ent.getKey(), 0, timer, |
| 4324 | timer.getCountLocked(which))); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 4325 | } |
| 4326 | Collections.sort(reasons, timerComparator); |
| 4327 | for (int i=0; i<reasons.size(); i++) { |
| 4328 | TimerEntry timer = reasons.get(i); |
| 4329 | String linePrefix = ": "; |
| 4330 | sb.setLength(0); |
| 4331 | sb.append(prefix); |
| 4332 | sb.append(" Wakeup reason "); |
| 4333 | sb.append(timer.mName); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 4334 | printWakeLock(sb, timer.mTimer, rawRealtime, null, which, ": "); |
| 4335 | sb.append(" realtime"); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 4336 | pw.println(sb.toString()); |
| 4337 | } |
| 4338 | pw.println(); |
| 4339 | } |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 4340 | } |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 4341 | |
James Carr | 2dd7e5e | 2016-07-20 18:48:39 -0700 | [diff] [blame] | 4342 | final LongSparseArray<? extends Timer> mMemoryStats = getKernelMemoryStats(); |
| 4343 | pw.println("Memory Stats"); |
| 4344 | for (int i = 0; i < mMemoryStats.size(); i++) { |
| 4345 | sb.setLength(0); |
| 4346 | sb.append("Bandwidth "); |
| 4347 | sb.append(mMemoryStats.keyAt(i)); |
| 4348 | sb.append(" Time "); |
| 4349 | sb.append(mMemoryStats.valueAt(i).getTotalTimeLocked(rawRealtime, which)); |
| 4350 | pw.println(sb.toString()); |
| 4351 | } |
| 4352 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4353 | for (int iu=0; iu<NU; iu++) { |
| 4354 | final int uid = uidStats.keyAt(iu); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 4355 | if (reqUid >= 0 && uid != reqUid && uid != Process.SYSTEM_UID) { |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 4356 | continue; |
| 4357 | } |
| 4358 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4359 | final Uid u = uidStats.valueAt(iu); |
Dianne Hackborn | a4cc205 | 2013-07-08 17:31:25 -0700 | [diff] [blame] | 4360 | |
| 4361 | pw.print(prefix); |
| 4362 | pw.print(" "); |
| 4363 | UserHandle.formatUid(pw, uid); |
| 4364 | pw.println(":"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4365 | boolean uidActivity = false; |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4366 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4367 | final long mobileRxBytes = u.getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which); |
| 4368 | final long mobileTxBytes = u.getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which); |
| 4369 | final long wifiRxBytes = u.getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which); |
| 4370 | final long wifiTxBytes = u.getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which); |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 4371 | final long btRxBytes = u.getNetworkActivityBytes(NETWORK_BT_RX_DATA, which); |
| 4372 | final long btTxBytes = u.getNetworkActivityBytes(NETWORK_BT_TX_DATA, which); |
| 4373 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4374 | final long mobileRxPackets = u.getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which); |
| 4375 | final long mobileTxPackets = u.getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4376 | final long wifiRxPackets = u.getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which); |
| 4377 | final long wifiTxPackets = u.getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which); |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 4378 | |
| 4379 | final long uidMobileActiveTime = u.getMobileRadioActiveTime(which); |
| 4380 | final int uidMobileActiveCount = u.getMobileRadioActiveCount(which); |
| 4381 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4382 | final long fullWifiLockOnTime = u.getFullWifiLockTime(rawRealtime, which); |
| 4383 | final long wifiScanTime = u.getWifiScanTime(rawRealtime, which); |
| 4384 | final int wifiScanCount = u.getWifiScanCount(which); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 4385 | final int wifiScanCountBg = u.getWifiScanBackgroundCount(which); |
| 4386 | // 'actualTime' are unpooled and always since reset (regardless of 'which') |
| 4387 | final long wifiScanActualTime = u.getWifiScanActualTime(rawRealtime); |
| 4388 | final long wifiScanActualTimeBg = u.getWifiScanBackgroundTime(rawRealtime); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4389 | final long uidWifiRunningTime = u.getWifiRunningTime(rawRealtime, which); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 4390 | |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 4391 | final long mobileWakeup = u.getMobileRadioApWakeupCount(which); |
| 4392 | final long wifiWakeup = u.getWifiRadioApWakeupCount(which); |
| 4393 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4394 | if (mobileRxBytes > 0 || mobileTxBytes > 0 |
| 4395 | || mobileRxPackets > 0 || mobileTxPackets > 0) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 4396 | pw.print(prefix); pw.print(" Mobile network: "); |
| 4397 | pw.print(formatBytesLocked(mobileRxBytes)); pw.print(" received, "); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4398 | pw.print(formatBytesLocked(mobileTxBytes)); |
| 4399 | pw.print(" sent (packets "); pw.print(mobileRxPackets); |
| 4400 | pw.print(" received, "); pw.print(mobileTxPackets); pw.println(" sent)"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4401 | } |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4402 | if (uidMobileActiveTime > 0 || uidMobileActiveCount > 0) { |
| 4403 | sb.setLength(0); |
| 4404 | sb.append(prefix); sb.append(" Mobile radio active: "); |
| 4405 | formatTimeMs(sb, uidMobileActiveTime / 1000); |
| 4406 | sb.append("("); |
| 4407 | sb.append(formatRatioLocked(uidMobileActiveTime, mobileActiveTime)); |
| 4408 | sb.append(") "); sb.append(uidMobileActiveCount); sb.append("x"); |
| 4409 | long packets = mobileRxPackets + mobileTxPackets; |
| 4410 | if (packets == 0) { |
| 4411 | packets = 1; |
| 4412 | } |
| 4413 | sb.append(" @ "); |
| 4414 | sb.append(BatteryStatsHelper.makemAh(uidMobileActiveTime / 1000 / (double)packets)); |
| 4415 | sb.append(" mspp"); |
| 4416 | pw.println(sb.toString()); |
| 4417 | } |
| 4418 | |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 4419 | if (mobileWakeup > 0) { |
| 4420 | sb.setLength(0); |
| 4421 | sb.append(prefix); |
| 4422 | sb.append(" Mobile radio AP wakeups: "); |
| 4423 | sb.append(mobileWakeup); |
| 4424 | pw.println(sb.toString()); |
| 4425 | } |
| 4426 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 4427 | printControllerActivityIfInteresting(pw, sb, prefix + " ", "Modem", |
| 4428 | u.getModemControllerActivity(), which); |
| 4429 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4430 | if (wifiRxBytes > 0 || wifiTxBytes > 0 || wifiRxPackets > 0 || wifiTxPackets > 0) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 4431 | pw.print(prefix); pw.print(" Wi-Fi network: "); |
| 4432 | pw.print(formatBytesLocked(wifiRxBytes)); pw.print(" received, "); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4433 | pw.print(formatBytesLocked(wifiTxBytes)); |
| 4434 | pw.print(" sent (packets "); pw.print(wifiRxPackets); |
| 4435 | pw.print(" received, "); pw.print(wifiTxPackets); pw.println(" sent)"); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 4436 | } |
| 4437 | |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 4438 | if (fullWifiLockOnTime != 0 || wifiScanTime != 0 || wifiScanCount != 0 |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 4439 | || wifiScanCountBg != 0 || wifiScanActualTime != 0 || wifiScanActualTimeBg != 0 |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4440 | || uidWifiRunningTime != 0) { |
| 4441 | sb.setLength(0); |
| 4442 | sb.append(prefix); sb.append(" Wifi Running: "); |
| 4443 | formatTimeMs(sb, uidWifiRunningTime / 1000); |
| 4444 | sb.append("("); sb.append(formatRatioLocked(uidWifiRunningTime, |
| 4445 | whichBatteryRealtime)); sb.append(")\n"); |
| 4446 | sb.append(prefix); sb.append(" Full Wifi Lock: "); |
| 4447 | formatTimeMs(sb, fullWifiLockOnTime / 1000); |
| 4448 | sb.append("("); sb.append(formatRatioLocked(fullWifiLockOnTime, |
| 4449 | whichBatteryRealtime)); sb.append(")\n"); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 4450 | sb.append(prefix); sb.append(" Wifi Scan (blamed): "); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4451 | formatTimeMs(sb, wifiScanTime / 1000); |
| 4452 | sb.append("("); sb.append(formatRatioLocked(wifiScanTime, |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 4453 | whichBatteryRealtime)); sb.append(") "); |
| 4454 | sb.append(wifiScanCount); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 4455 | sb.append("x\n"); |
| 4456 | // actual and background times are unpooled and since reset (regardless of 'which') |
| 4457 | sb.append(prefix); sb.append(" Wifi Scan (actual): "); |
| 4458 | formatTimeMs(sb, wifiScanActualTime / 1000); |
| 4459 | sb.append("("); sb.append(formatRatioLocked(wifiScanActualTime, |
| 4460 | computeBatteryRealtime(rawRealtime, STATS_SINCE_CHARGED))); |
| 4461 | sb.append(") "); |
| 4462 | sb.append(wifiScanCount); |
| 4463 | sb.append("x\n"); |
| 4464 | sb.append(prefix); sb.append(" Background Wifi Scan: "); |
| 4465 | formatTimeMs(sb, wifiScanActualTimeBg / 1000); |
| 4466 | sb.append("("); sb.append(formatRatioLocked(wifiScanActualTimeBg, |
| 4467 | computeBatteryRealtime(rawRealtime, STATS_SINCE_CHARGED))); |
| 4468 | sb.append(") "); |
| 4469 | sb.append(wifiScanCountBg); |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 4470 | sb.append("x"); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4471 | pw.println(sb.toString()); |
| 4472 | } |
| 4473 | |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 4474 | if (wifiWakeup > 0) { |
| 4475 | sb.setLength(0); |
| 4476 | sb.append(prefix); |
| 4477 | sb.append(" WiFi AP wakeups: "); |
| 4478 | sb.append(wifiWakeup); |
| 4479 | pw.println(sb.toString()); |
| 4480 | } |
| 4481 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 4482 | printControllerActivityIfInteresting(pw, sb, prefix + " ", "WiFi", |
| 4483 | u.getWifiControllerActivity(), which); |
Adam Lesinski | 049c88b | 2015-05-28 11:38:12 -0700 | [diff] [blame] | 4484 | |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 4485 | if (btRxBytes > 0 || btTxBytes > 0) { |
| 4486 | pw.print(prefix); pw.print(" Bluetooth network: "); |
| 4487 | pw.print(formatBytesLocked(btRxBytes)); pw.print(" received, "); |
| 4488 | pw.print(formatBytesLocked(btTxBytes)); |
| 4489 | pw.println(" sent"); |
| 4490 | } |
| 4491 | |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 4492 | final Timer bleTimer = u.getBluetoothScanTimer(); |
| 4493 | if (bleTimer != null) { |
| 4494 | // Convert from microseconds to milliseconds with rounding |
| 4495 | final long totalTimeMs = (bleTimer.getTotalTimeLocked(rawRealtime, which) + 500) |
| 4496 | / 1000; |
| 4497 | if (totalTimeMs != 0) { |
| 4498 | final int count = bleTimer.getCountLocked(which); |
| 4499 | final Timer bleTimerBg = u.getBluetoothScanBackgroundTimer(); |
| 4500 | final int countBg = bleTimerBg != null ? bleTimerBg.getCountLocked(which) : 0; |
| 4501 | final long rawRealtimeMs = (rawRealtime + 500) / 1000; |
| 4502 | // 'actualTime' are unpooled and always since reset (regardless of 'which') |
| 4503 | final long actualTimeMs = bleTimer.getTotalDurationMsLocked(rawRealtimeMs); |
| 4504 | final long actualTimeMsBg = bleTimerBg != null ? |
| 4505 | bleTimerBg.getTotalDurationMsLocked(rawRealtimeMs) : 0; |
Bookatz | 956f36bf | 2017-04-28 09:48:17 -0700 | [diff] [blame^] | 4506 | final int resultCount = u.getBluetoothScanResultCounter() != null ? |
| 4507 | u.getBluetoothScanResultCounter().getCountLocked(which) : 0; |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 4508 | |
| 4509 | sb.setLength(0); |
| 4510 | sb.append(prefix); |
| 4511 | sb.append(" "); |
| 4512 | sb.append("Bluetooth Scan"); |
| 4513 | sb.append(": "); |
| 4514 | if (actualTimeMs != totalTimeMs) { |
| 4515 | formatTimeMs(sb, totalTimeMs); |
| 4516 | sb.append("blamed realtime, "); |
| 4517 | } |
| 4518 | formatTimeMs(sb, actualTimeMs); // since reset, regardless of 'which' |
| 4519 | sb.append("realtime ("); |
| 4520 | sb.append(count); |
| 4521 | sb.append(" times)"); |
| 4522 | if (bleTimer.isRunningLocked()) { |
| 4523 | sb.append(" (running)"); |
| 4524 | } |
| 4525 | if (actualTimeMsBg != 0 || countBg > 0) { |
| 4526 | sb.append(", "); |
| 4527 | formatTimeMs(sb, actualTimeMsBg); // since reset, regardless of 'which' |
| 4528 | sb.append("background ("); |
| 4529 | sb.append(countBg); |
| 4530 | sb.append(" times)"); |
| 4531 | } |
Bookatz | 956f36bf | 2017-04-28 09:48:17 -0700 | [diff] [blame^] | 4532 | sb.append("; Results count "); |
| 4533 | sb.append(resultCount); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 4534 | pw.println(sb.toString()); |
| 4535 | uidActivity = true; |
| 4536 | } |
| 4537 | } |
| 4538 | |
| 4539 | |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 4540 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4541 | if (u.hasUserActivity()) { |
| 4542 | boolean hasData = false; |
Raph Levien | 4c7a4a7 | 2012-08-03 14:32:39 -0700 | [diff] [blame] | 4543 | for (int i=0; i<Uid.NUM_USER_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4544 | final int val = u.getUserActivityCount(i, which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4545 | if (val != 0) { |
| 4546 | if (!hasData) { |
| 4547 | sb.setLength(0); |
| 4548 | sb.append(" User activity: "); |
| 4549 | hasData = true; |
| 4550 | } else { |
| 4551 | sb.append(", "); |
| 4552 | } |
| 4553 | sb.append(val); |
| 4554 | sb.append(" "); |
| 4555 | sb.append(Uid.USER_ACTIVITY_TYPES[i]); |
| 4556 | } |
| 4557 | } |
| 4558 | if (hasData) { |
| 4559 | pw.println(sb.toString()); |
| 4560 | } |
| 4561 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4562 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4563 | final ArrayMap<String, ? extends BatteryStats.Uid.Wakelock> wakelocks |
| 4564 | = u.getWakelockStats(); |
| 4565 | long totalFullWakelock = 0, totalPartialWakelock = 0, totalWindowWakelock = 0; |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 4566 | long totalDrawWakelock = 0; |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4567 | int countWakelock = 0; |
| 4568 | for (int iw=wakelocks.size()-1; iw>=0; iw--) { |
| 4569 | final Uid.Wakelock wl = wakelocks.valueAt(iw); |
| 4570 | String linePrefix = ": "; |
| 4571 | sb.setLength(0); |
| 4572 | sb.append(prefix); |
| 4573 | sb.append(" Wake lock "); |
| 4574 | sb.append(wakelocks.keyAt(iw)); |
| 4575 | linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_FULL), rawRealtime, |
| 4576 | "full", which, linePrefix); |
| 4577 | linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_PARTIAL), rawRealtime, |
| 4578 | "partial", which, linePrefix); |
| 4579 | linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_WINDOW), rawRealtime, |
| 4580 | "window", which, linePrefix); |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 4581 | linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_DRAW), rawRealtime, |
| 4582 | "draw", which, linePrefix); |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 4583 | sb.append(" realtime"); |
| 4584 | pw.println(sb.toString()); |
| 4585 | uidActivity = true; |
| 4586 | countWakelock++; |
| 4587 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4588 | totalFullWakelock += computeWakeLock(wl.getWakeTime(WAKE_TYPE_FULL), |
| 4589 | rawRealtime, which); |
| 4590 | totalPartialWakelock += computeWakeLock(wl.getWakeTime(WAKE_TYPE_PARTIAL), |
| 4591 | rawRealtime, which); |
| 4592 | totalWindowWakelock += computeWakeLock(wl.getWakeTime(WAKE_TYPE_WINDOW), |
| 4593 | rawRealtime, which); |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 4594 | totalDrawWakelock += computeWakeLock(wl.getWakeTime(WAKE_TYPE_DRAW), |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 4595 | rawRealtime, which); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 4596 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4597 | if (countWakelock > 1) { |
| 4598 | if (totalFullWakelock != 0 || totalPartialWakelock != 0 |
| 4599 | || totalWindowWakelock != 0) { |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 4600 | sb.setLength(0); |
| 4601 | sb.append(prefix); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4602 | sb.append(" TOTAL wake: "); |
| 4603 | boolean needComma = false; |
| 4604 | if (totalFullWakelock != 0) { |
| 4605 | needComma = true; |
| 4606 | formatTimeMs(sb, totalFullWakelock); |
| 4607 | sb.append("full"); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 4608 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4609 | if (totalPartialWakelock != 0) { |
| 4610 | if (needComma) { |
| 4611 | sb.append(", "); |
| 4612 | } |
| 4613 | needComma = true; |
| 4614 | formatTimeMs(sb, totalPartialWakelock); |
| 4615 | sb.append("partial"); |
| 4616 | } |
| 4617 | if (totalWindowWakelock != 0) { |
| 4618 | if (needComma) { |
| 4619 | sb.append(", "); |
| 4620 | } |
| 4621 | needComma = true; |
| 4622 | formatTimeMs(sb, totalWindowWakelock); |
| 4623 | sb.append("window"); |
| 4624 | } |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 4625 | if (totalDrawWakelock != 0) { |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 4626 | if (needComma) { |
| 4627 | sb.append(","); |
| 4628 | } |
| 4629 | needComma = true; |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 4630 | formatTimeMs(sb, totalDrawWakelock); |
| 4631 | sb.append("draw"); |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 4632 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4633 | sb.append(" realtime"); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 4634 | pw.println(sb.toString()); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 4635 | } |
| 4636 | } |
| 4637 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4638 | final ArrayMap<String, ? extends Timer> syncs = u.getSyncStats(); |
| 4639 | for (int isy=syncs.size()-1; isy>=0; isy--) { |
| 4640 | final Timer timer = syncs.valueAt(isy); |
| 4641 | // Convert from microseconds to milliseconds with rounding |
| 4642 | final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000; |
| 4643 | final int count = timer.getCountLocked(which); |
Bookatz | 2bffb5b | 2017-04-13 11:59:33 -0700 | [diff] [blame] | 4644 | final Timer bgTimer = timer.getSubTimer(); |
| 4645 | final long bgTime = bgTimer != null ? |
| 4646 | (bgTimer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000 : -1; |
| 4647 | final int bgCount = bgTimer != null ? bgTimer.getCountLocked(which) : -1; |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4648 | sb.setLength(0); |
| 4649 | sb.append(prefix); |
| 4650 | sb.append(" Sync "); |
| 4651 | sb.append(syncs.keyAt(isy)); |
| 4652 | sb.append(": "); |
| 4653 | if (totalTime != 0) { |
| 4654 | formatTimeMs(sb, totalTime); |
| 4655 | sb.append("realtime ("); |
| 4656 | sb.append(count); |
| 4657 | sb.append(" times)"); |
Bookatz | 2bffb5b | 2017-04-13 11:59:33 -0700 | [diff] [blame] | 4658 | if (bgTime > 0) { |
| 4659 | sb.append(", "); |
| 4660 | formatTimeMs(sb, bgTime); |
| 4661 | sb.append("background ("); |
| 4662 | sb.append(bgCount); |
| 4663 | sb.append(" times)"); |
| 4664 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4665 | } else { |
| 4666 | sb.append("(not used)"); |
| 4667 | } |
| 4668 | pw.println(sb.toString()); |
| 4669 | uidActivity = true; |
| 4670 | } |
| 4671 | |
| 4672 | final ArrayMap<String, ? extends Timer> jobs = u.getJobStats(); |
| 4673 | for (int ij=jobs.size()-1; ij>=0; ij--) { |
| 4674 | final Timer timer = jobs.valueAt(ij); |
| 4675 | // Convert from microseconds to milliseconds with rounding |
| 4676 | final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000; |
| 4677 | final int count = timer.getCountLocked(which); |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 4678 | final Timer bgTimer = timer.getSubTimer(); |
| 4679 | final long bgTime = bgTimer != null ? |
| 4680 | (bgTimer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000 : -1; |
| 4681 | final int bgCount = bgTimer != null ? bgTimer.getCountLocked(which) : -1; |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4682 | sb.setLength(0); |
| 4683 | sb.append(prefix); |
| 4684 | sb.append(" Job "); |
| 4685 | sb.append(jobs.keyAt(ij)); |
| 4686 | sb.append(": "); |
| 4687 | if (totalTime != 0) { |
| 4688 | formatTimeMs(sb, totalTime); |
| 4689 | sb.append("realtime ("); |
| 4690 | sb.append(count); |
| 4691 | sb.append(" times)"); |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 4692 | if (bgTime > 0) { |
| 4693 | sb.append(", "); |
| 4694 | formatTimeMs(sb, bgTime); |
| 4695 | sb.append("background ("); |
| 4696 | sb.append(bgCount); |
| 4697 | sb.append(" times)"); |
| 4698 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4699 | } else { |
| 4700 | sb.append("(not used)"); |
| 4701 | } |
| 4702 | pw.println(sb.toString()); |
| 4703 | uidActivity = true; |
| 4704 | } |
| 4705 | |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 4706 | uidActivity |= printTimer(pw, sb, u.getFlashlightTurnedOnTimer(), rawRealtime, which, |
| 4707 | prefix, "Flashlight"); |
| 4708 | uidActivity |= printTimer(pw, sb, u.getCameraTurnedOnTimer(), rawRealtime, which, |
| 4709 | prefix, "Camera"); |
| 4710 | uidActivity |= printTimer(pw, sb, u.getVideoTurnedOnTimer(), rawRealtime, which, |
| 4711 | prefix, "Video"); |
| 4712 | uidActivity |= printTimer(pw, sb, u.getAudioTurnedOnTimer(), rawRealtime, which, |
| 4713 | prefix, "Audio"); |
| 4714 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4715 | final SparseArray<? extends BatteryStats.Uid.Sensor> sensors = u.getSensorStats(); |
| 4716 | final int NSE = sensors.size(); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 4717 | for (int ise=0; ise<NSE; ise++) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4718 | final Uid.Sensor se = sensors.valueAt(ise); |
| 4719 | final int sensorNumber = sensors.keyAt(ise); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 4720 | sb.setLength(0); |
| 4721 | sb.append(prefix); |
| 4722 | sb.append(" Sensor "); |
| 4723 | int handle = se.getHandle(); |
| 4724 | if (handle == Uid.Sensor.GPS) { |
| 4725 | sb.append("GPS"); |
| 4726 | } else { |
| 4727 | sb.append(handle); |
| 4728 | } |
| 4729 | sb.append(": "); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4730 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4731 | final Timer timer = se.getSensorTime(); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 4732 | if (timer != null) { |
| 4733 | // Convert from microseconds to milliseconds with rounding |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 4734 | final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) |
| 4735 | / 1000; |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4736 | final int count = timer.getCountLocked(which); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 4737 | final Timer bgTimer = se.getSensorBackgroundTime(); |
| 4738 | final int bgCount = bgTimer != null ? bgTimer.getCountLocked(which) : 0; |
| 4739 | final long rawRealtimeMs = (rawRealtime + 500) / 1000; |
| 4740 | // 'actualTime' are unpooled and always since reset (regardless of 'which') |
| 4741 | final long actualTime = timer.getTotalDurationMsLocked(rawRealtimeMs); |
| 4742 | final long bgActualTime = bgTimer != null ? |
| 4743 | bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : 0; |
| 4744 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 4745 | //timer.logState(); |
| 4746 | if (totalTime != 0) { |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 4747 | if (actualTime != totalTime) { |
| 4748 | formatTimeMs(sb, totalTime); |
| 4749 | sb.append("blamed realtime, "); |
| 4750 | } |
| 4751 | |
| 4752 | formatTimeMs(sb, actualTime); // since reset, regardless of 'which' |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 4753 | sb.append("realtime ("); |
| 4754 | sb.append(count); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 4755 | sb.append(" times)"); |
| 4756 | |
| 4757 | if (bgActualTime != 0 || bgCount > 0) { |
Amith Yamasani | ab9ad19 | 2016-12-06 12:46:59 -0800 | [diff] [blame] | 4758 | sb.append(", "); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 4759 | formatTimeMs(sb, bgActualTime); // since reset, regardless of 'which' |
| 4760 | sb.append("background ("); |
Amith Yamasani | ab9ad19 | 2016-12-06 12:46:59 -0800 | [diff] [blame] | 4761 | sb.append(bgCount); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 4762 | sb.append(" times)"); |
Amith Yamasani | ab9ad19 | 2016-12-06 12:46:59 -0800 | [diff] [blame] | 4763 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4764 | } else { |
| 4765 | sb.append("(not used)"); |
| 4766 | } |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 4767 | } else { |
| 4768 | sb.append("(not used)"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4769 | } |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 4770 | |
| 4771 | pw.println(sb.toString()); |
| 4772 | uidActivity = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4773 | } |
| 4774 | |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 4775 | uidActivity |= printTimer(pw, sb, u.getVibratorOnTimer(), rawRealtime, which, prefix, |
| 4776 | "Vibrator"); |
| 4777 | uidActivity |= printTimer(pw, sb, u.getForegroundActivityTimer(), rawRealtime, which, |
| 4778 | prefix, "Foreground activities"); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 4779 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 4780 | long totalStateTime = 0; |
| 4781 | for (int ips=0; ips<Uid.NUM_PROCESS_STATE; ips++) { |
| 4782 | long time = u.getProcessStateTime(ips, rawRealtime, which); |
| 4783 | if (time > 0) { |
| 4784 | totalStateTime += time; |
| 4785 | sb.setLength(0); |
| 4786 | sb.append(prefix); |
| 4787 | sb.append(" "); |
| 4788 | sb.append(Uid.PROCESS_STATE_NAMES[ips]); |
| 4789 | sb.append(" for: "); |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 4790 | formatTimeMs(sb, (time + 500) / 1000); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 4791 | pw.println(sb.toString()); |
| 4792 | uidActivity = true; |
| 4793 | } |
| 4794 | } |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 4795 | if (totalStateTime > 0) { |
| 4796 | sb.setLength(0); |
| 4797 | sb.append(prefix); |
| 4798 | sb.append(" Total running: "); |
| 4799 | formatTimeMs(sb, (totalStateTime + 500) / 1000); |
| 4800 | pw.println(sb.toString()); |
| 4801 | } |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 4802 | |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 4803 | final long userCpuTimeUs = u.getUserCpuTimeUs(which); |
| 4804 | final long systemCpuTimeUs = u.getSystemCpuTimeUs(which); |
Adam Lesinski | d4abd1e | 2017-04-12 11:29:13 -0700 | [diff] [blame] | 4805 | if (userCpuTimeUs > 0 || systemCpuTimeUs > 0) { |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 4806 | sb.setLength(0); |
| 4807 | sb.append(prefix); |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 4808 | sb.append(" Total cpu time: u="); |
| 4809 | formatTimeMs(sb, userCpuTimeUs / 1000); |
| 4810 | sb.append("s="); |
| 4811 | formatTimeMs(sb, systemCpuTimeUs / 1000); |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 4812 | pw.println(sb.toString()); |
| 4813 | } |
| 4814 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4815 | final ArrayMap<String, ? extends BatteryStats.Uid.Proc> processStats |
| 4816 | = u.getProcessStats(); |
| 4817 | for (int ipr=processStats.size()-1; ipr>=0; ipr--) { |
| 4818 | final Uid.Proc ps = processStats.valueAt(ipr); |
| 4819 | long userTime; |
| 4820 | long systemTime; |
| 4821 | long foregroundTime; |
| 4822 | int starts; |
| 4823 | int numExcessive; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4824 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4825 | userTime = ps.getUserTime(which); |
| 4826 | systemTime = ps.getSystemTime(which); |
| 4827 | foregroundTime = ps.getForegroundTime(which); |
| 4828 | starts = ps.getStarts(which); |
| 4829 | final int numCrashes = ps.getNumCrashes(which); |
| 4830 | final int numAnrs = ps.getNumAnrs(which); |
| 4831 | numExcessive = which == STATS_SINCE_CHARGED |
| 4832 | ? ps.countExcessivePowers() : 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4833 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4834 | if (userTime != 0 || systemTime != 0 || foregroundTime != 0 || starts != 0 |
| 4835 | || numExcessive != 0 || numCrashes != 0 || numAnrs != 0) { |
| 4836 | sb.setLength(0); |
| 4837 | sb.append(prefix); sb.append(" Proc "); |
| 4838 | sb.append(processStats.keyAt(ipr)); sb.append(":\n"); |
| 4839 | sb.append(prefix); sb.append(" CPU: "); |
| 4840 | formatTimeMs(sb, userTime); sb.append("usr + "); |
| 4841 | formatTimeMs(sb, systemTime); sb.append("krn ; "); |
| 4842 | formatTimeMs(sb, foregroundTime); sb.append("fg"); |
| 4843 | if (starts != 0 || numCrashes != 0 || numAnrs != 0) { |
| 4844 | sb.append("\n"); sb.append(prefix); sb.append(" "); |
| 4845 | boolean hasOne = false; |
| 4846 | if (starts != 0) { |
| 4847 | hasOne = true; |
| 4848 | sb.append(starts); sb.append(" starts"); |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 4849 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4850 | if (numCrashes != 0) { |
| 4851 | if (hasOne) { |
| 4852 | sb.append(", "); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4853 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4854 | hasOne = true; |
| 4855 | sb.append(numCrashes); sb.append(" crashes"); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4856 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4857 | if (numAnrs != 0) { |
| 4858 | if (hasOne) { |
| 4859 | sb.append(", "); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4860 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4861 | sb.append(numAnrs); sb.append(" anrs"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4862 | } |
| 4863 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4864 | pw.println(sb.toString()); |
| 4865 | for (int e=0; e<numExcessive; e++) { |
| 4866 | Uid.Proc.ExcessivePower ew = ps.getExcessivePower(e); |
| 4867 | if (ew != null) { |
| 4868 | pw.print(prefix); pw.print(" * Killed for "); |
| 4869 | if (ew.type == Uid.Proc.ExcessivePower.TYPE_WAKE) { |
| 4870 | pw.print("wake lock"); |
| 4871 | } else if (ew.type == Uid.Proc.ExcessivePower.TYPE_CPU) { |
| 4872 | pw.print("cpu"); |
| 4873 | } else { |
| 4874 | pw.print("unknown"); |
| 4875 | } |
| 4876 | pw.print(" use: "); |
| 4877 | TimeUtils.formatDuration(ew.usedTime, pw); |
| 4878 | pw.print(" over "); |
| 4879 | TimeUtils.formatDuration(ew.overTime, pw); |
| 4880 | if (ew.overTime != 0) { |
| 4881 | pw.print(" ("); |
| 4882 | pw.print((ew.usedTime*100)/ew.overTime); |
| 4883 | pw.println("%)"); |
| 4884 | } |
| 4885 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4886 | } |
| 4887 | uidActivity = true; |
| 4888 | } |
| 4889 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4890 | |
| 4891 | final ArrayMap<String, ? extends BatteryStats.Uid.Pkg> packageStats |
| 4892 | = u.getPackageStats(); |
| 4893 | for (int ipkg=packageStats.size()-1; ipkg>=0; ipkg--) { |
| 4894 | pw.print(prefix); pw.print(" Apk "); pw.print(packageStats.keyAt(ipkg)); |
| 4895 | pw.println(":"); |
| 4896 | boolean apkActivity = false; |
| 4897 | final Uid.Pkg ps = packageStats.valueAt(ipkg); |
| 4898 | final ArrayMap<String, ? extends Counter> alarms = ps.getWakeupAlarmStats(); |
| 4899 | for (int iwa=alarms.size()-1; iwa>=0; iwa--) { |
| 4900 | pw.print(prefix); pw.print(" Wakeup alarm "); |
| 4901 | pw.print(alarms.keyAt(iwa)); pw.print(": "); |
| 4902 | pw.print(alarms.valueAt(iwa).getCountLocked(which)); |
| 4903 | pw.println(" times"); |
| 4904 | apkActivity = true; |
| 4905 | } |
| 4906 | final ArrayMap<String, ? extends Uid.Pkg.Serv> serviceStats = ps.getServiceStats(); |
| 4907 | for (int isvc=serviceStats.size()-1; isvc>=0; isvc--) { |
| 4908 | final BatteryStats.Uid.Pkg.Serv ss = serviceStats.valueAt(isvc); |
| 4909 | final long startTime = ss.getStartTime(batteryUptime, which); |
| 4910 | final int starts = ss.getStarts(which); |
| 4911 | final int launches = ss.getLaunches(which); |
| 4912 | if (startTime != 0 || starts != 0 || launches != 0) { |
| 4913 | sb.setLength(0); |
| 4914 | sb.append(prefix); sb.append(" Service "); |
| 4915 | sb.append(serviceStats.keyAt(isvc)); sb.append(":\n"); |
| 4916 | sb.append(prefix); sb.append(" Created for: "); |
| 4917 | formatTimeMs(sb, startTime / 1000); |
| 4918 | sb.append("uptime\n"); |
| 4919 | sb.append(prefix); sb.append(" Starts: "); |
| 4920 | sb.append(starts); |
| 4921 | sb.append(", launches: "); sb.append(launches); |
| 4922 | pw.println(sb.toString()); |
| 4923 | apkActivity = true; |
| 4924 | } |
| 4925 | } |
| 4926 | if (!apkActivity) { |
| 4927 | pw.print(prefix); pw.println(" (nothing executed)"); |
| 4928 | } |
| 4929 | uidActivity = true; |
| 4930 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4931 | if (!uidActivity) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4932 | pw.print(prefix); pw.println(" (nothing executed)"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4933 | } |
| 4934 | } |
| 4935 | } |
| 4936 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 4937 | static void printBitDescriptions(PrintWriter pw, int oldval, int newval, HistoryTag wakelockTag, |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4938 | BitDescription[] descriptions, boolean longNames) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4939 | int diff = oldval ^ newval; |
| 4940 | if (diff == 0) return; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 4941 | boolean didWake = false; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4942 | for (int i=0; i<descriptions.length; i++) { |
| 4943 | BitDescription bd = descriptions[i]; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 4944 | if ((diff&bd.mask) != 0) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4945 | pw.print(longNames ? " " : ","); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4946 | if (bd.shift < 0) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 4947 | pw.print((newval&bd.mask) != 0 ? "+" : "-"); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4948 | pw.print(longNames ? bd.name : bd.shortName); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 4949 | if (bd.mask == HistoryItem.STATE_WAKE_LOCK_FLAG && wakelockTag != null) { |
| 4950 | didWake = true; |
| 4951 | pw.print("="); |
| 4952 | if (longNames) { |
| 4953 | UserHandle.formatUid(pw, wakelockTag.uid); |
| 4954 | pw.print(":\""); |
| 4955 | pw.print(wakelockTag.string); |
| 4956 | pw.print("\""); |
| 4957 | } else { |
| 4958 | pw.print(wakelockTag.poolIdx); |
| 4959 | } |
| 4960 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4961 | } else { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4962 | pw.print(longNames ? bd.name : bd.shortName); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4963 | pw.print("="); |
| 4964 | int val = (newval&bd.mask)>>bd.shift; |
| 4965 | if (bd.values != null && val >= 0 && val < bd.values.length) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4966 | pw.print(longNames? bd.values[val] : bd.shortValues[val]); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4967 | } else { |
| 4968 | pw.print(val); |
| 4969 | } |
| 4970 | } |
| 4971 | } |
| 4972 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 4973 | if (!didWake && wakelockTag != null) { |
Ashish Sharma | 81850c4 | 2014-05-05 13:57:07 -0700 | [diff] [blame] | 4974 | pw.print(longNames ? " wake_lock=" : ",w="); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 4975 | if (longNames) { |
| 4976 | UserHandle.formatUid(pw, wakelockTag.uid); |
| 4977 | pw.print(":\""); |
| 4978 | pw.print(wakelockTag.string); |
| 4979 | pw.print("\""); |
| 4980 | } else { |
| 4981 | pw.print(wakelockTag.poolIdx); |
| 4982 | } |
| 4983 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4984 | } |
| 4985 | |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 4986 | public void prepareForDumpLocked() { |
| 4987 | } |
| 4988 | |
| 4989 | public static class HistoryPrinter { |
| 4990 | int oldState = 0; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 4991 | int oldState2 = 0; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4992 | int oldLevel = -1; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 4993 | int oldStatus = -1; |
| 4994 | int oldHealth = -1; |
| 4995 | int oldPlug = -1; |
| 4996 | int oldTemp = -1; |
| 4997 | int oldVolt = -1; |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 4998 | int oldChargeMAh = -1; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4999 | long lastTime = -1; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5000 | |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 5001 | void reset() { |
| 5002 | oldState = oldState2 = 0; |
| 5003 | oldLevel = -1; |
| 5004 | oldStatus = -1; |
| 5005 | oldHealth = -1; |
| 5006 | oldPlug = -1; |
| 5007 | oldTemp = -1; |
| 5008 | oldVolt = -1; |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 5009 | oldChargeMAh = -1; |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 5010 | } |
| 5011 | |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 5012 | public void printNextItem(PrintWriter pw, HistoryItem rec, long baseTime, boolean checkin, |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 5013 | boolean verbose) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5014 | if (!checkin) { |
| 5015 | pw.print(" "); |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 5016 | TimeUtils.formatDuration(rec.time - baseTime, pw, TimeUtils.HUNDRED_DAY_FIELD_LEN); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 5017 | pw.print(" ("); |
| 5018 | pw.print(rec.numReadInts); |
| 5019 | pw.print(") "); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5020 | } else { |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 5021 | pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(','); |
| 5022 | pw.print(HISTORY_DATA); pw.print(','); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5023 | if (lastTime < 0) { |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 5024 | pw.print(rec.time - baseTime); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5025 | } else { |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 5026 | pw.print(rec.time - lastTime); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5027 | } |
| 5028 | lastTime = rec.time; |
| 5029 | } |
| 5030 | if (rec.cmd == HistoryItem.CMD_START) { |
| 5031 | if (checkin) { |
| 5032 | pw.print(":"); |
| 5033 | } |
| 5034 | pw.println("START"); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 5035 | reset(); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 5036 | } else if (rec.cmd == HistoryItem.CMD_CURRENT_TIME |
| 5037 | || rec.cmd == HistoryItem.CMD_RESET) { |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 5038 | if (checkin) { |
| 5039 | pw.print(":"); |
| 5040 | } |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 5041 | if (rec.cmd == HistoryItem.CMD_RESET) { |
| 5042 | pw.print("RESET:"); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 5043 | reset(); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 5044 | } |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 5045 | pw.print("TIME:"); |
| 5046 | if (checkin) { |
| 5047 | pw.println(rec.currentTime); |
| 5048 | } else { |
| 5049 | pw.print(" "); |
| 5050 | pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss", |
| 5051 | rec.currentTime).toString()); |
| 5052 | } |
Dianne Hackborn | 29cd7f1 | 2015-01-08 10:37:05 -0800 | [diff] [blame] | 5053 | } else if (rec.cmd == HistoryItem.CMD_SHUTDOWN) { |
| 5054 | if (checkin) { |
| 5055 | pw.print(":"); |
| 5056 | } |
| 5057 | pw.println("SHUTDOWN"); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5058 | } else if (rec.cmd == HistoryItem.CMD_OVERFLOW) { |
| 5059 | if (checkin) { |
| 5060 | pw.print(":"); |
| 5061 | } |
| 5062 | pw.println("*OVERFLOW*"); |
| 5063 | } else { |
| 5064 | if (!checkin) { |
| 5065 | if (rec.batteryLevel < 10) pw.print("00"); |
| 5066 | else if (rec.batteryLevel < 100) pw.print("0"); |
| 5067 | pw.print(rec.batteryLevel); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 5068 | if (verbose) { |
| 5069 | pw.print(" "); |
| 5070 | if (rec.states < 0) ; |
| 5071 | else if (rec.states < 0x10) pw.print("0000000"); |
| 5072 | else if (rec.states < 0x100) pw.print("000000"); |
| 5073 | else if (rec.states < 0x1000) pw.print("00000"); |
| 5074 | else if (rec.states < 0x10000) pw.print("0000"); |
| 5075 | else if (rec.states < 0x100000) pw.print("000"); |
| 5076 | else if (rec.states < 0x1000000) pw.print("00"); |
| 5077 | else if (rec.states < 0x10000000) pw.print("0"); |
| 5078 | pw.print(Integer.toHexString(rec.states)); |
| 5079 | } |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5080 | } else { |
| 5081 | if (oldLevel != rec.batteryLevel) { |
| 5082 | oldLevel = rec.batteryLevel; |
| 5083 | pw.print(",Bl="); pw.print(rec.batteryLevel); |
| 5084 | } |
| 5085 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5086 | if (oldStatus != rec.batteryStatus) { |
| 5087 | oldStatus = rec.batteryStatus; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5088 | pw.print(checkin ? ",Bs=" : " status="); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5089 | switch (oldStatus) { |
| 5090 | case BatteryManager.BATTERY_STATUS_UNKNOWN: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5091 | pw.print(checkin ? "?" : "unknown"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5092 | break; |
| 5093 | case BatteryManager.BATTERY_STATUS_CHARGING: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5094 | pw.print(checkin ? "c" : "charging"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5095 | break; |
| 5096 | case BatteryManager.BATTERY_STATUS_DISCHARGING: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5097 | pw.print(checkin ? "d" : "discharging"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5098 | break; |
| 5099 | case BatteryManager.BATTERY_STATUS_NOT_CHARGING: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5100 | pw.print(checkin ? "n" : "not-charging"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5101 | break; |
| 5102 | case BatteryManager.BATTERY_STATUS_FULL: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5103 | pw.print(checkin ? "f" : "full"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5104 | break; |
| 5105 | default: |
| 5106 | pw.print(oldStatus); |
| 5107 | break; |
| 5108 | } |
| 5109 | } |
| 5110 | if (oldHealth != rec.batteryHealth) { |
| 5111 | oldHealth = rec.batteryHealth; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5112 | pw.print(checkin ? ",Bh=" : " health="); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5113 | switch (oldHealth) { |
| 5114 | case BatteryManager.BATTERY_HEALTH_UNKNOWN: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5115 | pw.print(checkin ? "?" : "unknown"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5116 | break; |
| 5117 | case BatteryManager.BATTERY_HEALTH_GOOD: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5118 | pw.print(checkin ? "g" : "good"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5119 | break; |
| 5120 | case BatteryManager.BATTERY_HEALTH_OVERHEAT: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5121 | pw.print(checkin ? "h" : "overheat"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5122 | break; |
| 5123 | case BatteryManager.BATTERY_HEALTH_DEAD: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5124 | pw.print(checkin ? "d" : "dead"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5125 | break; |
| 5126 | case BatteryManager.BATTERY_HEALTH_OVER_VOLTAGE: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5127 | pw.print(checkin ? "v" : "over-voltage"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5128 | break; |
| 5129 | case BatteryManager.BATTERY_HEALTH_UNSPECIFIED_FAILURE: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5130 | pw.print(checkin ? "f" : "failure"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5131 | break; |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 5132 | case BatteryManager.BATTERY_HEALTH_COLD: |
| 5133 | pw.print(checkin ? "c" : "cold"); |
| 5134 | break; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5135 | default: |
| 5136 | pw.print(oldHealth); |
| 5137 | break; |
| 5138 | } |
| 5139 | } |
| 5140 | if (oldPlug != rec.batteryPlugType) { |
| 5141 | oldPlug = rec.batteryPlugType; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5142 | pw.print(checkin ? ",Bp=" : " plug="); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5143 | switch (oldPlug) { |
| 5144 | case 0: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5145 | pw.print(checkin ? "n" : "none"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5146 | break; |
| 5147 | case BatteryManager.BATTERY_PLUGGED_AC: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5148 | pw.print(checkin ? "a" : "ac"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5149 | break; |
| 5150 | case BatteryManager.BATTERY_PLUGGED_USB: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5151 | pw.print(checkin ? "u" : "usb"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5152 | break; |
Brian Muramatsu | 37a37f4 | 2012-08-14 15:21:02 -0700 | [diff] [blame] | 5153 | case BatteryManager.BATTERY_PLUGGED_WIRELESS: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5154 | pw.print(checkin ? "w" : "wireless"); |
Brian Muramatsu | 37a37f4 | 2012-08-14 15:21:02 -0700 | [diff] [blame] | 5155 | break; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5156 | default: |
| 5157 | pw.print(oldPlug); |
| 5158 | break; |
| 5159 | } |
| 5160 | } |
| 5161 | if (oldTemp != rec.batteryTemperature) { |
| 5162 | oldTemp = rec.batteryTemperature; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5163 | pw.print(checkin ? ",Bt=" : " temp="); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5164 | pw.print(oldTemp); |
| 5165 | } |
| 5166 | if (oldVolt != rec.batteryVoltage) { |
| 5167 | oldVolt = rec.batteryVoltage; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5168 | pw.print(checkin ? ",Bv=" : " volt="); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5169 | pw.print(oldVolt); |
| 5170 | } |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 5171 | final int chargeMAh = rec.batteryChargeUAh / 1000; |
| 5172 | if (oldChargeMAh != chargeMAh) { |
| 5173 | oldChargeMAh = chargeMAh; |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 5174 | pw.print(checkin ? ",Bcc=" : " charge="); |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 5175 | pw.print(oldChargeMAh); |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 5176 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 5177 | printBitDescriptions(pw, oldState, rec.states, rec.wakelockTag, |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5178 | HISTORY_STATE_DESCRIPTIONS, !checkin); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 5179 | printBitDescriptions(pw, oldState2, rec.states2, null, |
| 5180 | HISTORY_STATE2_DESCRIPTIONS, !checkin); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 5181 | if (rec.wakeReasonTag != null) { |
| 5182 | if (checkin) { |
Dianne Hackborn | d06dcfd | 2014-05-02 13:49:30 -0700 | [diff] [blame] | 5183 | pw.print(",wr="); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 5184 | pw.print(rec.wakeReasonTag.poolIdx); |
| 5185 | } else { |
| 5186 | pw.print(" wake_reason="); |
| 5187 | pw.print(rec.wakeReasonTag.uid); |
| 5188 | pw.print(":\""); |
| 5189 | pw.print(rec.wakeReasonTag.string); |
| 5190 | pw.print("\""); |
| 5191 | } |
| 5192 | } |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 5193 | if (rec.eventCode != HistoryItem.EVENT_NONE) { |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 5194 | pw.print(checkin ? "," : " "); |
| 5195 | if ((rec.eventCode&HistoryItem.EVENT_FLAG_START) != 0) { |
| 5196 | pw.print("+"); |
| 5197 | } else if ((rec.eventCode&HistoryItem.EVENT_FLAG_FINISH) != 0) { |
| 5198 | pw.print("-"); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 5199 | } |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 5200 | String[] eventNames = checkin ? HISTORY_EVENT_CHECKIN_NAMES |
| 5201 | : HISTORY_EVENT_NAMES; |
| 5202 | int idx = rec.eventCode & ~(HistoryItem.EVENT_FLAG_START |
| 5203 | | HistoryItem.EVENT_FLAG_FINISH); |
| 5204 | if (idx >= 0 && idx < eventNames.length) { |
| 5205 | pw.print(eventNames[idx]); |
| 5206 | } else { |
| 5207 | pw.print(checkin ? "Ev" : "event"); |
| 5208 | pw.print(idx); |
| 5209 | } |
| 5210 | pw.print("="); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 5211 | if (checkin) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 5212 | pw.print(rec.eventTag.poolIdx); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 5213 | } else { |
Adam Lesinski | 041d917 | 2016-12-12 12:03:56 -0800 | [diff] [blame] | 5214 | pw.append(HISTORY_EVENT_INT_FORMATTERS[idx] |
| 5215 | .applyAsString(rec.eventTag.uid)); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 5216 | pw.print(":\""); |
| 5217 | pw.print(rec.eventTag.string); |
| 5218 | pw.print("\""); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 5219 | } |
| 5220 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5221 | pw.println(); |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 5222 | if (rec.stepDetails != null) { |
| 5223 | if (!checkin) { |
| 5224 | pw.print(" Details: cpu="); |
| 5225 | pw.print(rec.stepDetails.userTime); |
| 5226 | pw.print("u+"); |
| 5227 | pw.print(rec.stepDetails.systemTime); |
| 5228 | pw.print("s"); |
| 5229 | if (rec.stepDetails.appCpuUid1 >= 0) { |
| 5230 | pw.print(" ("); |
| 5231 | printStepCpuUidDetails(pw, rec.stepDetails.appCpuUid1, |
| 5232 | rec.stepDetails.appCpuUTime1, rec.stepDetails.appCpuSTime1); |
| 5233 | if (rec.stepDetails.appCpuUid2 >= 0) { |
| 5234 | pw.print(", "); |
| 5235 | printStepCpuUidDetails(pw, rec.stepDetails.appCpuUid2, |
| 5236 | rec.stepDetails.appCpuUTime2, rec.stepDetails.appCpuSTime2); |
| 5237 | } |
| 5238 | if (rec.stepDetails.appCpuUid3 >= 0) { |
| 5239 | pw.print(", "); |
| 5240 | printStepCpuUidDetails(pw, rec.stepDetails.appCpuUid3, |
| 5241 | rec.stepDetails.appCpuUTime3, rec.stepDetails.appCpuSTime3); |
| 5242 | } |
| 5243 | pw.print(')'); |
| 5244 | } |
| 5245 | pw.println(); |
| 5246 | pw.print(" /proc/stat="); |
| 5247 | pw.print(rec.stepDetails.statUserTime); |
| 5248 | pw.print(" usr, "); |
| 5249 | pw.print(rec.stepDetails.statSystemTime); |
| 5250 | pw.print(" sys, "); |
| 5251 | pw.print(rec.stepDetails.statIOWaitTime); |
| 5252 | pw.print(" io, "); |
| 5253 | pw.print(rec.stepDetails.statIrqTime); |
| 5254 | pw.print(" irq, "); |
| 5255 | pw.print(rec.stepDetails.statSoftIrqTime); |
| 5256 | pw.print(" sirq, "); |
| 5257 | pw.print(rec.stepDetails.statIdlTime); |
| 5258 | pw.print(" idle"); |
| 5259 | int totalRun = rec.stepDetails.statUserTime + rec.stepDetails.statSystemTime |
| 5260 | + rec.stepDetails.statIOWaitTime + rec.stepDetails.statIrqTime |
| 5261 | + rec.stepDetails.statSoftIrqTime; |
| 5262 | int total = totalRun + rec.stepDetails.statIdlTime; |
| 5263 | if (total > 0) { |
| 5264 | pw.print(" ("); |
| 5265 | float perc = ((float)totalRun) / ((float)total) * 100; |
| 5266 | pw.print(String.format("%.1f%%", perc)); |
| 5267 | pw.print(" of "); |
| 5268 | StringBuilder sb = new StringBuilder(64); |
| 5269 | formatTimeMsNoSpace(sb, total*10); |
| 5270 | pw.print(sb); |
| 5271 | pw.print(")"); |
| 5272 | } |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 5273 | pw.print(", PlatformIdleStat "); |
| 5274 | pw.print(rec.stepDetails.statPlatformIdleState); |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 5275 | pw.println(); |
| 5276 | } else { |
| 5277 | pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(','); |
| 5278 | pw.print(HISTORY_DATA); pw.print(",0,Dcpu="); |
| 5279 | pw.print(rec.stepDetails.userTime); |
| 5280 | pw.print(":"); |
| 5281 | pw.print(rec.stepDetails.systemTime); |
| 5282 | if (rec.stepDetails.appCpuUid1 >= 0) { |
| 5283 | printStepCpuUidCheckinDetails(pw, rec.stepDetails.appCpuUid1, |
| 5284 | rec.stepDetails.appCpuUTime1, rec.stepDetails.appCpuSTime1); |
| 5285 | if (rec.stepDetails.appCpuUid2 >= 0) { |
| 5286 | printStepCpuUidCheckinDetails(pw, rec.stepDetails.appCpuUid2, |
| 5287 | rec.stepDetails.appCpuUTime2, rec.stepDetails.appCpuSTime2); |
| 5288 | } |
| 5289 | if (rec.stepDetails.appCpuUid3 >= 0) { |
| 5290 | printStepCpuUidCheckinDetails(pw, rec.stepDetails.appCpuUid3, |
| 5291 | rec.stepDetails.appCpuUTime3, rec.stepDetails.appCpuSTime3); |
| 5292 | } |
| 5293 | } |
| 5294 | pw.println(); |
| 5295 | pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(','); |
| 5296 | pw.print(HISTORY_DATA); pw.print(",0,Dpst="); |
| 5297 | pw.print(rec.stepDetails.statUserTime); |
| 5298 | pw.print(','); |
| 5299 | pw.print(rec.stepDetails.statSystemTime); |
| 5300 | pw.print(','); |
| 5301 | pw.print(rec.stepDetails.statIOWaitTime); |
| 5302 | pw.print(','); |
| 5303 | pw.print(rec.stepDetails.statIrqTime); |
| 5304 | pw.print(','); |
| 5305 | pw.print(rec.stepDetails.statSoftIrqTime); |
| 5306 | pw.print(','); |
| 5307 | pw.print(rec.stepDetails.statIdlTime); |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 5308 | pw.print(','); |
Adam Lesinski | 8568d8f | 2016-07-15 18:13:23 -0700 | [diff] [blame] | 5309 | if (rec.stepDetails.statPlatformIdleState != null) { |
| 5310 | pw.print(rec.stepDetails.statPlatformIdleState); |
| 5311 | } |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 5312 | pw.println(); |
| 5313 | } |
| 5314 | } |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 5315 | oldState = rec.states; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 5316 | oldState2 = rec.states2; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5317 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5318 | } |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 5319 | |
| 5320 | private void printStepCpuUidDetails(PrintWriter pw, int uid, int utime, int stime) { |
| 5321 | UserHandle.formatUid(pw, uid); |
| 5322 | pw.print("="); |
| 5323 | pw.print(utime); |
| 5324 | pw.print("u+"); |
| 5325 | pw.print(stime); |
| 5326 | pw.print("s"); |
| 5327 | } |
| 5328 | |
| 5329 | private void printStepCpuUidCheckinDetails(PrintWriter pw, int uid, int utime, int stime) { |
| 5330 | pw.print('/'); |
| 5331 | pw.print(uid); |
| 5332 | pw.print(":"); |
| 5333 | pw.print(utime); |
| 5334 | pw.print(":"); |
| 5335 | pw.print(stime); |
| 5336 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5337 | } |
| 5338 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 5339 | private void printSizeValue(PrintWriter pw, long size) { |
| 5340 | float result = size; |
| 5341 | String suffix = ""; |
| 5342 | if (result >= 10*1024) { |
| 5343 | suffix = "KB"; |
| 5344 | result = result / 1024; |
| 5345 | } |
| 5346 | if (result >= 10*1024) { |
| 5347 | suffix = "MB"; |
| 5348 | result = result / 1024; |
| 5349 | } |
| 5350 | if (result >= 10*1024) { |
| 5351 | suffix = "GB"; |
| 5352 | result = result / 1024; |
| 5353 | } |
| 5354 | if (result >= 10*1024) { |
| 5355 | suffix = "TB"; |
| 5356 | result = result / 1024; |
| 5357 | } |
| 5358 | if (result >= 10*1024) { |
| 5359 | suffix = "PB"; |
| 5360 | result = result / 1024; |
| 5361 | } |
| 5362 | pw.print((int)result); |
| 5363 | pw.print(suffix); |
| 5364 | } |
| 5365 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 5366 | private static boolean dumpTimeEstimate(PrintWriter pw, String label1, String label2, |
| 5367 | String label3, long estimatedTime) { |
| 5368 | if (estimatedTime < 0) { |
Dianne Hackborn | ad6a99b | 2014-11-18 10:11:10 -0800 | [diff] [blame] | 5369 | return false; |
| 5370 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 5371 | pw.print(label1); |
| 5372 | pw.print(label2); |
| 5373 | pw.print(label3); |
Dianne Hackborn | ad6a99b | 2014-11-18 10:11:10 -0800 | [diff] [blame] | 5374 | StringBuilder sb = new StringBuilder(64); |
| 5375 | formatTimeMs(sb, estimatedTime); |
| 5376 | pw.print(sb); |
| 5377 | pw.println(); |
Dianne Hackborn | ad6a99b | 2014-11-18 10:11:10 -0800 | [diff] [blame] | 5378 | return true; |
| 5379 | } |
| 5380 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 5381 | private static boolean dumpDurationSteps(PrintWriter pw, String prefix, String header, |
| 5382 | LevelStepTracker steps, boolean checkin) { |
| 5383 | if (steps == null) { |
| 5384 | return false; |
| 5385 | } |
| 5386 | int count = steps.mNumStepDurations; |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 5387 | if (count <= 0) { |
| 5388 | return false; |
| 5389 | } |
| 5390 | if (!checkin) { |
| 5391 | pw.println(header); |
| 5392 | } |
Kweku Adams | 030980a | 2015-04-01 16:07:48 -0700 | [diff] [blame] | 5393 | String[] lineArgs = new String[5]; |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 5394 | for (int i=0; i<count; i++) { |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 5395 | long duration = steps.getDurationAt(i); |
| 5396 | int level = steps.getLevelAt(i); |
| 5397 | long initMode = steps.getInitModeAt(i); |
| 5398 | long modMode = steps.getModModeAt(i); |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 5399 | if (checkin) { |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 5400 | lineArgs[0] = Long.toString(duration); |
| 5401 | lineArgs[1] = Integer.toString(level); |
| 5402 | if ((modMode&STEP_LEVEL_MODE_SCREEN_STATE) == 0) { |
| 5403 | switch ((int)(initMode&STEP_LEVEL_MODE_SCREEN_STATE) + 1) { |
| 5404 | case Display.STATE_OFF: lineArgs[2] = "s-"; break; |
| 5405 | case Display.STATE_ON: lineArgs[2] = "s+"; break; |
| 5406 | case Display.STATE_DOZE: lineArgs[2] = "sd"; break; |
| 5407 | case Display.STATE_DOZE_SUSPEND: lineArgs[2] = "sds"; break; |
Kweku Adams | 030980a | 2015-04-01 16:07:48 -0700 | [diff] [blame] | 5408 | default: lineArgs[2] = "?"; break; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 5409 | } |
| 5410 | } else { |
| 5411 | lineArgs[2] = ""; |
| 5412 | } |
| 5413 | if ((modMode&STEP_LEVEL_MODE_POWER_SAVE) == 0) { |
| 5414 | lineArgs[3] = (initMode&STEP_LEVEL_MODE_POWER_SAVE) != 0 ? "p+" : "p-"; |
| 5415 | } else { |
| 5416 | lineArgs[3] = ""; |
| 5417 | } |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 5418 | if ((modMode&STEP_LEVEL_MODE_DEVICE_IDLE) == 0) { |
Kweku Adams | 030980a | 2015-04-01 16:07:48 -0700 | [diff] [blame] | 5419 | lineArgs[4] = (initMode&STEP_LEVEL_MODE_DEVICE_IDLE) != 0 ? "i+" : "i-"; |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 5420 | } else { |
Kweku Adams | 030980a | 2015-04-01 16:07:48 -0700 | [diff] [blame] | 5421 | lineArgs[4] = ""; |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 5422 | } |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 5423 | dumpLine(pw, 0 /* uid */, "i" /* category */, header, (Object[])lineArgs); |
| 5424 | } else { |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 5425 | pw.print(prefix); |
| 5426 | pw.print("#"); pw.print(i); pw.print(": "); |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 5427 | TimeUtils.formatDuration(duration, pw); |
| 5428 | pw.print(" to "); pw.print(level); |
| 5429 | boolean haveModes = false; |
| 5430 | if ((modMode&STEP_LEVEL_MODE_SCREEN_STATE) == 0) { |
| 5431 | pw.print(" ("); |
| 5432 | switch ((int)(initMode&STEP_LEVEL_MODE_SCREEN_STATE) + 1) { |
| 5433 | case Display.STATE_OFF: pw.print("screen-off"); break; |
| 5434 | case Display.STATE_ON: pw.print("screen-on"); break; |
| 5435 | case Display.STATE_DOZE: pw.print("screen-doze"); break; |
| 5436 | case Display.STATE_DOZE_SUSPEND: pw.print("screen-doze-suspend"); break; |
Kweku Adams | 030980a | 2015-04-01 16:07:48 -0700 | [diff] [blame] | 5437 | default: pw.print("screen-?"); break; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 5438 | } |
| 5439 | haveModes = true; |
| 5440 | } |
| 5441 | if ((modMode&STEP_LEVEL_MODE_POWER_SAVE) == 0) { |
| 5442 | pw.print(haveModes ? ", " : " ("); |
| 5443 | pw.print((initMode&STEP_LEVEL_MODE_POWER_SAVE) != 0 |
| 5444 | ? "power-save-on" : "power-save-off"); |
| 5445 | haveModes = true; |
| 5446 | } |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 5447 | if ((modMode&STEP_LEVEL_MODE_DEVICE_IDLE) == 0) { |
| 5448 | pw.print(haveModes ? ", " : " ("); |
| 5449 | pw.print((initMode&STEP_LEVEL_MODE_DEVICE_IDLE) != 0 |
| 5450 | ? "device-idle-on" : "device-idle-off"); |
| 5451 | haveModes = true; |
| 5452 | } |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 5453 | if (haveModes) { |
| 5454 | pw.print(")"); |
| 5455 | } |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 5456 | pw.println(); |
| 5457 | } |
| 5458 | } |
| 5459 | return true; |
| 5460 | } |
| 5461 | |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 5462 | public static final int DUMP_CHARGED_ONLY = 1<<1; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 5463 | public static final int DUMP_DAILY_ONLY = 1<<2; |
| 5464 | public static final int DUMP_HISTORY_ONLY = 1<<3; |
| 5465 | public static final int DUMP_INCLUDE_HISTORY = 1<<4; |
| 5466 | public static final int DUMP_VERBOSE = 1<<5; |
| 5467 | public static final int DUMP_DEVICE_WIFI_ONLY = 1<<6; |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 5468 | |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 5469 | private void dumpHistoryLocked(PrintWriter pw, int flags, long histStart, boolean checkin) { |
| 5470 | final HistoryPrinter hprinter = new HistoryPrinter(); |
| 5471 | final HistoryItem rec = new HistoryItem(); |
| 5472 | long lastTime = -1; |
| 5473 | long baseTime = -1; |
| 5474 | boolean printed = false; |
| 5475 | HistoryEventTracker tracker = null; |
| 5476 | while (getNextHistoryLocked(rec)) { |
| 5477 | lastTime = rec.time; |
| 5478 | if (baseTime < 0) { |
| 5479 | baseTime = lastTime; |
| 5480 | } |
| 5481 | if (rec.time >= histStart) { |
| 5482 | if (histStart >= 0 && !printed) { |
| 5483 | if (rec.cmd == HistoryItem.CMD_CURRENT_TIME |
Ashish Sharma | 6020071 | 2014-05-23 18:22:20 -0700 | [diff] [blame] | 5484 | || rec.cmd == HistoryItem.CMD_RESET |
Dianne Hackborn | 29cd7f1 | 2015-01-08 10:37:05 -0800 | [diff] [blame] | 5485 | || rec.cmd == HistoryItem.CMD_START |
| 5486 | || rec.cmd == HistoryItem.CMD_SHUTDOWN) { |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 5487 | printed = true; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 5488 | hprinter.printNextItem(pw, rec, baseTime, checkin, |
| 5489 | (flags&DUMP_VERBOSE) != 0); |
| 5490 | rec.cmd = HistoryItem.CMD_UPDATE; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 5491 | } else if (rec.currentTime != 0) { |
| 5492 | printed = true; |
| 5493 | byte cmd = rec.cmd; |
| 5494 | rec.cmd = HistoryItem.CMD_CURRENT_TIME; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 5495 | hprinter.printNextItem(pw, rec, baseTime, checkin, |
| 5496 | (flags&DUMP_VERBOSE) != 0); |
| 5497 | rec.cmd = cmd; |
| 5498 | } |
| 5499 | if (tracker != null) { |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 5500 | if (rec.cmd != HistoryItem.CMD_UPDATE) { |
| 5501 | hprinter.printNextItem(pw, rec, baseTime, checkin, |
| 5502 | (flags&DUMP_VERBOSE) != 0); |
| 5503 | rec.cmd = HistoryItem.CMD_UPDATE; |
| 5504 | } |
| 5505 | int oldEventCode = rec.eventCode; |
| 5506 | HistoryTag oldEventTag = rec.eventTag; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 5507 | rec.eventTag = new HistoryTag(); |
| 5508 | for (int i=0; i<HistoryItem.EVENT_COUNT; i++) { |
| 5509 | HashMap<String, SparseIntArray> active |
| 5510 | = tracker.getStateForEvent(i); |
| 5511 | if (active == null) { |
| 5512 | continue; |
| 5513 | } |
| 5514 | for (HashMap.Entry<String, SparseIntArray> ent |
| 5515 | : active.entrySet()) { |
| 5516 | SparseIntArray uids = ent.getValue(); |
| 5517 | for (int j=0; j<uids.size(); j++) { |
| 5518 | rec.eventCode = i; |
| 5519 | rec.eventTag.string = ent.getKey(); |
| 5520 | rec.eventTag.uid = uids.keyAt(j); |
| 5521 | rec.eventTag.poolIdx = uids.valueAt(j); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 5522 | hprinter.printNextItem(pw, rec, baseTime, checkin, |
| 5523 | (flags&DUMP_VERBOSE) != 0); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 5524 | rec.wakeReasonTag = null; |
| 5525 | rec.wakelockTag = null; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 5526 | } |
| 5527 | } |
| 5528 | } |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 5529 | rec.eventCode = oldEventCode; |
| 5530 | rec.eventTag = oldEventTag; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 5531 | tracker = null; |
| 5532 | } |
| 5533 | } |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 5534 | hprinter.printNextItem(pw, rec, baseTime, checkin, |
| 5535 | (flags&DUMP_VERBOSE) != 0); |
Dianne Hackborn | 536456f | 2014-05-23 16:51:05 -0700 | [diff] [blame] | 5536 | } else if (false && rec.eventCode != HistoryItem.EVENT_NONE) { |
| 5537 | // This is an attempt to aggregate the previous state and generate |
| 5538 | //Â fake events to reflect that state at the point where we start |
| 5539 | // 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] | 5540 | if (tracker == null) { |
| 5541 | tracker = new HistoryEventTracker(); |
| 5542 | } |
| 5543 | tracker.updateState(rec.eventCode, rec.eventTag.string, |
| 5544 | rec.eventTag.uid, rec.eventTag.poolIdx); |
| 5545 | } |
| 5546 | } |
| 5547 | if (histStart >= 0) { |
Dianne Hackborn | fc06413 | 2014-06-02 12:42:12 -0700 | [diff] [blame] | 5548 | commitCurrentHistoryBatchLocked(); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 5549 | pw.print(checkin ? "NEXT: " : " NEXT: "); pw.println(lastTime+1); |
| 5550 | } |
| 5551 | } |
| 5552 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 5553 | private void dumpDailyLevelStepSummary(PrintWriter pw, String prefix, String label, |
| 5554 | LevelStepTracker steps, StringBuilder tmpSb, int[] tmpOutInt) { |
| 5555 | if (steps == null) { |
| 5556 | return; |
| 5557 | } |
| 5558 | long timeRemaining = steps.computeTimeEstimate(0, 0, tmpOutInt); |
| 5559 | if (timeRemaining >= 0) { |
| 5560 | pw.print(prefix); pw.print(label); pw.print(" total time: "); |
| 5561 | tmpSb.setLength(0); |
| 5562 | formatTimeMs(tmpSb, timeRemaining); |
| 5563 | pw.print(tmpSb); |
| 5564 | pw.print(" (from "); pw.print(tmpOutInt[0]); |
| 5565 | pw.println(" steps)"); |
| 5566 | } |
| 5567 | for (int i=0; i< STEP_LEVEL_MODES_OF_INTEREST.length; i++) { |
| 5568 | long estimatedTime = steps.computeTimeEstimate(STEP_LEVEL_MODES_OF_INTEREST[i], |
| 5569 | STEP_LEVEL_MODE_VALUES[i], tmpOutInt); |
| 5570 | if (estimatedTime > 0) { |
| 5571 | pw.print(prefix); pw.print(label); pw.print(" "); |
| 5572 | pw.print(STEP_LEVEL_MODE_LABELS[i]); |
| 5573 | pw.print(" time: "); |
| 5574 | tmpSb.setLength(0); |
| 5575 | formatTimeMs(tmpSb, estimatedTime); |
| 5576 | pw.print(tmpSb); |
| 5577 | pw.print(" (from "); pw.print(tmpOutInt[0]); |
| 5578 | pw.println(" steps)"); |
| 5579 | } |
| 5580 | } |
| 5581 | } |
| 5582 | |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 5583 | private void dumpDailyPackageChanges(PrintWriter pw, String prefix, |
| 5584 | ArrayList<PackageChange> changes) { |
| 5585 | if (changes == null) { |
| 5586 | return; |
| 5587 | } |
| 5588 | pw.print(prefix); pw.println("Package changes:"); |
| 5589 | for (int i=0; i<changes.size(); i++) { |
| 5590 | PackageChange pc = changes.get(i); |
| 5591 | if (pc.mUpdate) { |
| 5592 | pw.print(prefix); pw.print(" Update "); pw.print(pc.mPackageName); |
| 5593 | pw.print(" vers="); pw.println(pc.mVersionCode); |
| 5594 | } else { |
| 5595 | pw.print(prefix); pw.print(" Uninstall "); pw.println(pc.mPackageName); |
| 5596 | } |
| 5597 | } |
| 5598 | } |
| 5599 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5600 | /** |
| 5601 | * Dumps a human-readable summary of the battery statistics to the given PrintWriter. |
| 5602 | * |
| 5603 | * @param pw a Printer to receive the dump output. |
| 5604 | */ |
| 5605 | @SuppressWarnings("unused") |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 5606 | 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] | 5607 | prepareForDumpLocked(); |
| 5608 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 5609 | final boolean filtering = (flags |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5610 | & (DUMP_HISTORY_ONLY|DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) != 0; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5611 | |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 5612 | if ((flags&DUMP_HISTORY_ONLY) != 0 || !filtering) { |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 5613 | final long historyTotalSize = getHistoryTotalSize(); |
| 5614 | final long historyUsedSize = getHistoryUsedSize(); |
| 5615 | if (startIteratingHistoryLocked()) { |
| 5616 | try { |
| 5617 | pw.print("Battery History ("); |
| 5618 | pw.print((100*historyUsedSize)/historyTotalSize); |
| 5619 | pw.print("% used, "); |
| 5620 | printSizeValue(pw, historyUsedSize); |
| 5621 | pw.print(" used of "); |
| 5622 | printSizeValue(pw, historyTotalSize); |
| 5623 | pw.print(", "); |
| 5624 | pw.print(getHistoryStringPoolSize()); |
| 5625 | pw.print(" strings using "); |
| 5626 | printSizeValue(pw, getHistoryStringPoolBytes()); |
| 5627 | pw.println("):"); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 5628 | dumpHistoryLocked(pw, flags, histStart, false); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 5629 | pw.println(); |
| 5630 | } finally { |
| 5631 | finishIteratingHistoryLocked(); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 5632 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 5633 | } |
| 5634 | |
| 5635 | if (startIteratingOldHistoryLocked()) { |
| 5636 | try { |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 5637 | final HistoryItem rec = new HistoryItem(); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 5638 | pw.println("Old battery History:"); |
| 5639 | HistoryPrinter hprinter = new HistoryPrinter(); |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 5640 | long baseTime = -1; |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 5641 | while (getNextOldHistoryLocked(rec)) { |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 5642 | if (baseTime < 0) { |
| 5643 | baseTime = rec.time; |
| 5644 | } |
| 5645 | hprinter.printNextItem(pw, rec, baseTime, false, (flags&DUMP_VERBOSE) != 0); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 5646 | } |
| 5647 | pw.println(); |
| 5648 | } finally { |
| 5649 | finishIteratingOldHistoryLocked(); |
| 5650 | } |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 5651 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5652 | } |
| 5653 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5654 | if (filtering && (flags&(DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) == 0) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 5655 | return; |
| 5656 | } |
| 5657 | |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 5658 | if (!filtering) { |
| 5659 | SparseArray<? extends Uid> uidStats = getUidStats(); |
| 5660 | final int NU = uidStats.size(); |
| 5661 | boolean didPid = false; |
| 5662 | long nowRealtime = SystemClock.elapsedRealtime(); |
| 5663 | for (int i=0; i<NU; i++) { |
| 5664 | Uid uid = uidStats.valueAt(i); |
| 5665 | SparseArray<? extends Uid.Pid> pids = uid.getPidStats(); |
| 5666 | if (pids != null) { |
| 5667 | for (int j=0; j<pids.size(); j++) { |
| 5668 | Uid.Pid pid = pids.valueAt(j); |
| 5669 | if (!didPid) { |
| 5670 | pw.println("Per-PID Stats:"); |
| 5671 | didPid = true; |
| 5672 | } |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 5673 | long time = pid.mWakeSumMs + (pid.mWakeNesting > 0 |
| 5674 | ? (nowRealtime - pid.mWakeStartMs) : 0); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 5675 | pw.print(" PID "); pw.print(pids.keyAt(j)); |
| 5676 | pw.print(" wake time: "); |
| 5677 | TimeUtils.formatDuration(time, pw); |
| 5678 | pw.println(""); |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 5679 | } |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 5680 | } |
| 5681 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 5682 | if (didPid) { |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 5683 | pw.println(); |
| 5684 | } |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 5685 | } |
| 5686 | |
| 5687 | if (!filtering || (flags&DUMP_CHARGED_ONLY) != 0) { |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 5688 | if (dumpDurationSteps(pw, " ", "Discharge step durations:", |
| 5689 | getDischargeLevelStepTracker(), false)) { |
Kweku Adams | b0449e0 | 2016-10-12 14:18:27 -0700 | [diff] [blame] | 5690 | long timeRemaining = computeBatteryTimeRemaining( |
| 5691 | SystemClock.elapsedRealtime() * 1000); |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 5692 | if (timeRemaining >= 0) { |
| 5693 | pw.print(" Estimated discharge time remaining: "); |
| 5694 | TimeUtils.formatDuration(timeRemaining / 1000, pw); |
| 5695 | pw.println(); |
| 5696 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 5697 | final LevelStepTracker steps = getDischargeLevelStepTracker(); |
| 5698 | for (int i=0; i< STEP_LEVEL_MODES_OF_INTEREST.length; i++) { |
| 5699 | dumpTimeEstimate(pw, " Estimated ", STEP_LEVEL_MODE_LABELS[i], " time: ", |
| 5700 | steps.computeTimeEstimate(STEP_LEVEL_MODES_OF_INTEREST[i], |
| 5701 | STEP_LEVEL_MODE_VALUES[i], null)); |
| 5702 | } |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 5703 | pw.println(); |
| 5704 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 5705 | if (dumpDurationSteps(pw, " ", "Charge step durations:", |
| 5706 | getChargeLevelStepTracker(), false)) { |
Kweku Adams | b0449e0 | 2016-10-12 14:18:27 -0700 | [diff] [blame] | 5707 | long timeRemaining = computeChargeTimeRemaining( |
| 5708 | SystemClock.elapsedRealtime() * 1000); |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 5709 | if (timeRemaining >= 0) { |
| 5710 | pw.print(" Estimated charge time remaining: "); |
| 5711 | TimeUtils.formatDuration(timeRemaining / 1000, pw); |
| 5712 | pw.println(); |
| 5713 | } |
| 5714 | pw.println(); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 5715 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 5716 | } |
| 5717 | if (!filtering || (flags&(DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) != 0) { |
| 5718 | pw.println("Daily stats:"); |
| 5719 | pw.print(" Current start time: "); |
| 5720 | pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss", |
| 5721 | getCurrentDailyStartTime()).toString()); |
| 5722 | pw.print(" Next min deadline: "); |
| 5723 | pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss", |
| 5724 | getNextMinDailyDeadline()).toString()); |
| 5725 | pw.print(" Next max deadline: "); |
| 5726 | pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss", |
| 5727 | getNextMaxDailyDeadline()).toString()); |
| 5728 | StringBuilder sb = new StringBuilder(64); |
| 5729 | int[] outInt = new int[1]; |
| 5730 | LevelStepTracker dsteps = getDailyDischargeLevelStepTracker(); |
| 5731 | LevelStepTracker csteps = getDailyChargeLevelStepTracker(); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 5732 | ArrayList<PackageChange> pkgc = getDailyPackageChanges(); |
| 5733 | if (dsteps.mNumStepDurations > 0 || csteps.mNumStepDurations > 0 || pkgc != null) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5734 | if ((flags&DUMP_DAILY_ONLY) != 0 || !filtering) { |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 5735 | if (dumpDurationSteps(pw, " ", " Current daily discharge step durations:", |
| 5736 | dsteps, false)) { |
| 5737 | dumpDailyLevelStepSummary(pw, " ", "Discharge", dsteps, |
| 5738 | sb, outInt); |
| 5739 | } |
| 5740 | if (dumpDurationSteps(pw, " ", " Current daily charge step durations:", |
| 5741 | csteps, false)) { |
| 5742 | dumpDailyLevelStepSummary(pw, " ", "Charge", csteps, |
| 5743 | sb, outInt); |
| 5744 | } |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 5745 | dumpDailyPackageChanges(pw, " ", pkgc); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 5746 | } else { |
| 5747 | pw.println(" Current daily steps:"); |
| 5748 | dumpDailyLevelStepSummary(pw, " ", "Discharge", dsteps, |
| 5749 | sb, outInt); |
| 5750 | dumpDailyLevelStepSummary(pw, " ", "Charge", csteps, |
| 5751 | sb, outInt); |
| 5752 | } |
| 5753 | } |
| 5754 | DailyItem dit; |
| 5755 | int curIndex = 0; |
| 5756 | while ((dit=getDailyItemLocked(curIndex)) != null) { |
| 5757 | curIndex++; |
| 5758 | if ((flags&DUMP_DAILY_ONLY) != 0) { |
| 5759 | pw.println(); |
| 5760 | } |
| 5761 | pw.print(" Daily from "); |
| 5762 | pw.print(DateFormat.format("yyyy-MM-dd-HH-mm-ss", dit.mStartTime).toString()); |
| 5763 | pw.print(" to "); |
| 5764 | pw.print(DateFormat.format("yyyy-MM-dd-HH-mm-ss", dit.mEndTime).toString()); |
| 5765 | pw.println(":"); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5766 | if ((flags&DUMP_DAILY_ONLY) != 0 || !filtering) { |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 5767 | if (dumpDurationSteps(pw, " ", |
| 5768 | " Discharge step durations:", dit.mDischargeSteps, false)) { |
| 5769 | dumpDailyLevelStepSummary(pw, " ", "Discharge", dit.mDischargeSteps, |
| 5770 | sb, outInt); |
| 5771 | } |
| 5772 | if (dumpDurationSteps(pw, " ", |
| 5773 | " Charge step durations:", dit.mChargeSteps, false)) { |
| 5774 | dumpDailyLevelStepSummary(pw, " ", "Charge", dit.mChargeSteps, |
| 5775 | sb, outInt); |
| 5776 | } |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 5777 | dumpDailyPackageChanges(pw, " ", dit.mPackageChanges); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 5778 | } else { |
| 5779 | dumpDailyLevelStepSummary(pw, " ", "Discharge", dit.mDischargeSteps, |
| 5780 | sb, outInt); |
| 5781 | dumpDailyLevelStepSummary(pw, " ", "Charge", dit.mChargeSteps, |
| 5782 | sb, outInt); |
| 5783 | } |
| 5784 | } |
| 5785 | pw.println(); |
| 5786 | } |
| 5787 | if (!filtering || (flags&DUMP_CHARGED_ONLY) != 0) { |
Jeff Sharkey | ec43a6b | 2013-04-30 13:33:18 -0700 | [diff] [blame] | 5788 | pw.println("Statistics since last charge:"); |
| 5789 | pw.println(" System starts: " + getStartCount() |
| 5790 | + ", currently on battery: " + getIsOnBattery()); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 5791 | dumpLocked(context, pw, "", STATS_SINCE_CHARGED, reqUid, |
| 5792 | (flags&DUMP_DEVICE_WIFI_ONLY) != 0); |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 5793 | pw.println(); |
Jeff Sharkey | ec43a6b | 2013-04-30 13:33:18 -0700 | [diff] [blame] | 5794 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5795 | } |
| 5796 | |
| 5797 | @SuppressWarnings("unused") |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 5798 | public void dumpCheckinLocked(Context context, PrintWriter pw, |
| 5799 | List<ApplicationInfo> apps, int flags, long histStart) { |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5800 | prepareForDumpLocked(); |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 5801 | |
| 5802 | dumpLine(pw, 0 /* uid */, "i" /* category */, VERSION_DATA, |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 5803 | CHECKIN_VERSION, getParcelVersion(), getStartPlatformVersion(), |
| 5804 | getEndPlatformVersion()); |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 5805 | |
Dianne Hackborn | 13ac041 | 2013-06-25 19:34:49 -0700 | [diff] [blame] | 5806 | long now = getHistoryBaseTime() + SystemClock.elapsedRealtime(); |
| 5807 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 5808 | final boolean filtering = (flags & |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5809 | (DUMP_HISTORY_ONLY|DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) != 0; |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 5810 | |
| 5811 | if ((flags&DUMP_INCLUDE_HISTORY) != 0 || (flags&DUMP_HISTORY_ONLY) != 0) { |
Dianne Hackborn | 49021f5 | 2013-09-04 18:03:40 -0700 | [diff] [blame] | 5812 | if (startIteratingHistoryLocked()) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 5813 | try { |
| 5814 | for (int i=0; i<getHistoryStringPoolSize(); i++) { |
| 5815 | pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(','); |
| 5816 | pw.print(HISTORY_STRING_POOL); pw.print(','); |
| 5817 | pw.print(i); |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 5818 | pw.print(","); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 5819 | pw.print(getHistoryTagPoolUid(i)); |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 5820 | pw.print(",\""); |
| 5821 | String str = getHistoryTagPoolString(i); |
| 5822 | str = str.replace("\\", "\\\\"); |
| 5823 | str = str.replace("\"", "\\\""); |
| 5824 | pw.print(str); |
| 5825 | pw.print("\""); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 5826 | pw.println(); |
| 5827 | } |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 5828 | dumpHistoryLocked(pw, flags, histStart, true); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 5829 | } finally { |
| 5830 | finishIteratingHistoryLocked(); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 5831 | } |
Dianne Hackborn | 13ac041 | 2013-06-25 19:34:49 -0700 | [diff] [blame] | 5832 | } |
Dianne Hackborn | 13ac041 | 2013-06-25 19:34:49 -0700 | [diff] [blame] | 5833 | } |
| 5834 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5835 | if (filtering && (flags&(DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) == 0) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 5836 | return; |
| 5837 | } |
| 5838 | |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 5839 | if (apps != null) { |
Dianne Hackborn | 9cfba35 | 2016-03-24 17:31:28 -0700 | [diff] [blame] | 5840 | SparseArray<Pair<ArrayList<String>, MutableBoolean>> uids = new SparseArray<>(); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 5841 | for (int i=0; i<apps.size(); i++) { |
| 5842 | ApplicationInfo ai = apps.get(i); |
Dianne Hackborn | 9cfba35 | 2016-03-24 17:31:28 -0700 | [diff] [blame] | 5843 | Pair<ArrayList<String>, MutableBoolean> pkgs = uids.get( |
| 5844 | UserHandle.getAppId(ai.uid)); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 5845 | if (pkgs == null) { |
Dianne Hackborn | 9cfba35 | 2016-03-24 17:31:28 -0700 | [diff] [blame] | 5846 | pkgs = new Pair<>(new ArrayList<String>(), new MutableBoolean(false)); |
| 5847 | uids.put(UserHandle.getAppId(ai.uid), pkgs); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 5848 | } |
Dianne Hackborn | 9cfba35 | 2016-03-24 17:31:28 -0700 | [diff] [blame] | 5849 | pkgs.first.add(ai.packageName); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 5850 | } |
| 5851 | SparseArray<? extends Uid> uidStats = getUidStats(); |
| 5852 | final int NU = uidStats.size(); |
| 5853 | String[] lineArgs = new String[2]; |
| 5854 | for (int i=0; i<NU; i++) { |
Dianne Hackborn | 9cfba35 | 2016-03-24 17:31:28 -0700 | [diff] [blame] | 5855 | int uid = UserHandle.getAppId(uidStats.keyAt(i)); |
| 5856 | Pair<ArrayList<String>, MutableBoolean> pkgs = uids.get(uid); |
| 5857 | if (pkgs != null && !pkgs.second.value) { |
| 5858 | pkgs.second.value = true; |
| 5859 | for (int j=0; j<pkgs.first.size(); j++) { |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 5860 | lineArgs[0] = Integer.toString(uid); |
Dianne Hackborn | 9cfba35 | 2016-03-24 17:31:28 -0700 | [diff] [blame] | 5861 | lineArgs[1] = pkgs.first.get(j); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 5862 | dumpLine(pw, 0 /* uid */, "i" /* category */, UID_DATA, |
| 5863 | (Object[])lineArgs); |
| 5864 | } |
| 5865 | } |
| 5866 | } |
| 5867 | } |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 5868 | if (!filtering || (flags&DUMP_CHARGED_ONLY) != 0) { |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 5869 | dumpDurationSteps(pw, "", DISCHARGE_STEP_DATA, getDischargeLevelStepTracker(), true); |
Dianne Hackborn | d06dcfd | 2014-05-02 13:49:30 -0700 | [diff] [blame] | 5870 | String[] lineArgs = new String[1]; |
Kweku Adams | b0449e0 | 2016-10-12 14:18:27 -0700 | [diff] [blame] | 5871 | long timeRemaining = computeBatteryTimeRemaining(SystemClock.elapsedRealtime() * 1000); |
Dianne Hackborn | d06dcfd | 2014-05-02 13:49:30 -0700 | [diff] [blame] | 5872 | if (timeRemaining >= 0) { |
| 5873 | lineArgs[0] = Long.toString(timeRemaining); |
| 5874 | dumpLine(pw, 0 /* uid */, "i" /* category */, DISCHARGE_TIME_REMAIN_DATA, |
| 5875 | (Object[])lineArgs); |
| 5876 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 5877 | dumpDurationSteps(pw, "", CHARGE_STEP_DATA, getChargeLevelStepTracker(), true); |
Kweku Adams | b0449e0 | 2016-10-12 14:18:27 -0700 | [diff] [blame] | 5878 | timeRemaining = computeChargeTimeRemaining(SystemClock.elapsedRealtime() * 1000); |
Dianne Hackborn | d06dcfd | 2014-05-02 13:49:30 -0700 | [diff] [blame] | 5879 | if (timeRemaining >= 0) { |
| 5880 | lineArgs[0] = Long.toString(timeRemaining); |
| 5881 | dumpLine(pw, 0 /* uid */, "i" /* category */, CHARGE_TIME_REMAIN_DATA, |
| 5882 | (Object[])lineArgs); |
| 5883 | } |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 5884 | dumpCheckinLocked(context, pw, STATS_SINCE_CHARGED, -1, |
| 5885 | (flags&DUMP_DEVICE_WIFI_ONLY) != 0); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 5886 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5887 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5888 | } |