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 | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame^] | 185 | * - Sensor, BluetoothScan, WifiScan get background timers and counter. |
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 | /** |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 395 | * Returns whether the timer is currently running. Some types of timers |
| 396 | * (e.g. BatchTimers) don't know whether the event is currently active, |
| 397 | * and report false. |
| 398 | */ |
| 399 | public boolean isRunningLocked() { |
| 400 | return false; |
| 401 | } |
| 402 | |
| 403 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 404 | * Temporary for debugging. |
| 405 | */ |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 406 | public abstract void logState(Printer pw, String prefix); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 407 | } |
| 408 | |
| 409 | /** |
| 410 | * The statistics associated with a particular uid. |
| 411 | */ |
| 412 | public static abstract class Uid { |
| 413 | |
| 414 | /** |
| 415 | * Returns a mapping containing wakelock statistics. |
| 416 | * |
| 417 | * @return a Map from Strings to Uid.Wakelock objects. |
| 418 | */ |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 419 | public abstract ArrayMap<String, ? extends Wakelock> getWakelockStats(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 420 | |
| 421 | /** |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 422 | * Returns a mapping containing sync statistics. |
| 423 | * |
| 424 | * @return a Map from Strings to Timer objects. |
| 425 | */ |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 426 | public abstract ArrayMap<String, ? extends Timer> getSyncStats(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 427 | |
| 428 | /** |
| 429 | * Returns a mapping containing scheduled job statistics. |
| 430 | * |
| 431 | * @return a Map from Strings to Timer objects. |
| 432 | */ |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 433 | public abstract ArrayMap<String, ? extends Timer> getJobStats(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 434 | |
| 435 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 436 | * The statistics associated with a particular wake lock. |
| 437 | */ |
| 438 | public static abstract class Wakelock { |
| 439 | public abstract Timer getWakeTime(int type); |
| 440 | } |
| 441 | |
| 442 | /** |
| 443 | * Returns a mapping containing sensor statistics. |
| 444 | * |
| 445 | * @return a Map from Integer sensor ids to Uid.Sensor objects. |
| 446 | */ |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 447 | public abstract SparseArray<? extends Sensor> getSensorStats(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 448 | |
| 449 | /** |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 450 | * Returns a mapping containing active process data. |
| 451 | */ |
| 452 | public abstract SparseArray<? extends Pid> getPidStats(); |
| 453 | |
| 454 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 455 | * Returns a mapping containing process statistics. |
| 456 | * |
| 457 | * @return a Map from Strings to Uid.Proc objects. |
| 458 | */ |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 459 | public abstract ArrayMap<String, ? extends Proc> getProcessStats(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 460 | |
| 461 | /** |
| 462 | * Returns a mapping containing package statistics. |
| 463 | * |
| 464 | * @return a Map from Strings to Uid.Pkg objects. |
| 465 | */ |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 466 | public abstract ArrayMap<String, ? extends Pkg> getPackageStats(); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 467 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 468 | public abstract ControllerActivityCounter getWifiControllerActivity(); |
| 469 | public abstract ControllerActivityCounter getBluetoothControllerActivity(); |
| 470 | public abstract ControllerActivityCounter getModemControllerActivity(); |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 471 | |
| 472 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 473 | * {@hide} |
| 474 | */ |
| 475 | public abstract int getUid(); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 476 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 477 | public abstract void noteWifiRunningLocked(long elapsedRealtime); |
| 478 | public abstract void noteWifiStoppedLocked(long elapsedRealtime); |
| 479 | public abstract void noteFullWifiLockAcquiredLocked(long elapsedRealtime); |
| 480 | public abstract void noteFullWifiLockReleasedLocked(long elapsedRealtime); |
| 481 | public abstract void noteWifiScanStartedLocked(long elapsedRealtime); |
| 482 | public abstract void noteWifiScanStoppedLocked(long elapsedRealtime); |
| 483 | public abstract void noteWifiBatchedScanStartedLocked(int csph, long elapsedRealtime); |
| 484 | public abstract void noteWifiBatchedScanStoppedLocked(long elapsedRealtime); |
| 485 | public abstract void noteWifiMulticastEnabledLocked(long elapsedRealtime); |
| 486 | public abstract void noteWifiMulticastDisabledLocked(long elapsedRealtime); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 487 | public abstract void noteActivityResumedLocked(long elapsedRealtime); |
| 488 | public abstract void noteActivityPausedLocked(long elapsedRealtime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 489 | public abstract long getWifiRunningTime(long elapsedRealtimeUs, int which); |
| 490 | public abstract long getFullWifiLockTime(long elapsedRealtimeUs, int which); |
| 491 | public abstract long getWifiScanTime(long elapsedRealtimeUs, int which); |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 492 | public abstract int getWifiScanCount(int which); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame^] | 493 | public abstract int getWifiScanBackgroundCount(int which); |
| 494 | public abstract long getWifiScanActualTime(long elapsedRealtimeUs); |
| 495 | public abstract long getWifiScanBackgroundTime(long elapsedRealtimeUs); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 496 | public abstract long getWifiBatchedScanTime(int csphBin, long elapsedRealtimeUs, int which); |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 497 | public abstract int getWifiBatchedScanCount(int csphBin, int which); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 498 | public abstract long getWifiMulticastTime(long elapsedRealtimeUs, int which); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 499 | public abstract Timer getAudioTurnedOnTimer(); |
| 500 | public abstract Timer getVideoTurnedOnTimer(); |
| 501 | public abstract Timer getFlashlightTurnedOnTimer(); |
| 502 | public abstract Timer getCameraTurnedOnTimer(); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 503 | public abstract Timer getForegroundActivityTimer(); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 504 | public abstract Timer getBluetoothScanTimer(); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame^] | 505 | public abstract Timer getBluetoothScanBackgroundTimer(); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 506 | |
Dianne Hackborn | a0200e3 | 2016-03-30 18:01:41 -0700 | [diff] [blame] | 507 | // Note: the following times are disjoint. They can be added together to find the |
| 508 | // total time a uid has had any processes running at all. |
| 509 | |
| 510 | /** |
| 511 | * Time this uid has any processes in the top state (or above such as persistent). |
| 512 | */ |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 513 | public static final int PROCESS_STATE_TOP = 0; |
Dianne Hackborn | a0200e3 | 2016-03-30 18:01:41 -0700 | [diff] [blame] | 514 | /** |
| 515 | * Time this uid has any process with a started out bound foreground service, but |
| 516 | * none in the "top" state. |
| 517 | */ |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 518 | public static final int PROCESS_STATE_FOREGROUND_SERVICE = 1; |
Dianne Hackborn | a0200e3 | 2016-03-30 18:01:41 -0700 | [diff] [blame] | 519 | /** |
| 520 | * Time this uid has any process that is top while the device is sleeping, but none |
| 521 | * in the "foreground service" or better state. |
| 522 | */ |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 523 | public static final int PROCESS_STATE_TOP_SLEEPING = 2; |
Dianne Hackborn | a0200e3 | 2016-03-30 18:01:41 -0700 | [diff] [blame] | 524 | /** |
| 525 | * Time this uid has any process in an active foreground state, but none in the |
| 526 | * "top sleeping" or better state. |
| 527 | */ |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 528 | public static final int PROCESS_STATE_FOREGROUND = 3; |
Dianne Hackborn | a0200e3 | 2016-03-30 18:01:41 -0700 | [diff] [blame] | 529 | /** |
| 530 | * Time this uid has any process in an active background state, but none in the |
| 531 | * "foreground" or better state. |
| 532 | */ |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 533 | public static final int PROCESS_STATE_BACKGROUND = 4; |
Dianne Hackborn | a0200e3 | 2016-03-30 18:01:41 -0700 | [diff] [blame] | 534 | /** |
| 535 | * Time this uid has any processes that are sitting around cached, not in one of the |
| 536 | * other active states. |
| 537 | */ |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 538 | public static final int PROCESS_STATE_CACHED = 5; |
Dianne Hackborn | a0200e3 | 2016-03-30 18:01:41 -0700 | [diff] [blame] | 539 | /** |
| 540 | * Total number of process states we track. |
| 541 | */ |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 542 | public static final int NUM_PROCESS_STATE = 6; |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 543 | |
| 544 | static final String[] PROCESS_STATE_NAMES = { |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 545 | "Top", "Fg Service", "Top Sleeping", "Foreground", "Background", "Cached" |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 546 | }; |
| 547 | |
| 548 | public abstract long getProcessStateTime(int state, long elapsedRealtimeUs, int which); |
Joe Onorato | 713fec8 | 2016-03-04 10:34:02 -0800 | [diff] [blame] | 549 | public abstract Timer getProcessStateTimer(int state); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 550 | |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 551 | public abstract Timer getVibratorOnTimer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 552 | |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 553 | public static final int NUM_WIFI_BATCHED_SCAN_BINS = 5; |
| 554 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 555 | /** |
Jeff Brown | df693de | 2012-07-27 12:03:38 -0700 | [diff] [blame] | 556 | * Note that these must match the constants in android.os.PowerManager. |
| 557 | * Also, if the user activity types change, the BatteryStatsImpl.VERSION must |
| 558 | * also be bumped. |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 559 | */ |
| 560 | static final String[] USER_ACTIVITY_TYPES = { |
Phil Weaver | da80d67 | 2016-03-15 16:25:46 -0700 | [diff] [blame] | 561 | "other", "button", "touch", "accessibility" |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 562 | }; |
| 563 | |
Phil Weaver | da80d67 | 2016-03-15 16:25:46 -0700 | [diff] [blame] | 564 | public static final int NUM_USER_ACTIVITY_TYPES = 4; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 565 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 566 | public abstract void noteUserActivityLocked(int type); |
| 567 | public abstract boolean hasUserActivity(); |
| 568 | public abstract int getUserActivityCount(int type, int which); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 569 | |
| 570 | public abstract boolean hasNetworkActivity(); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 571 | public abstract long getNetworkActivityBytes(int type, int which); |
| 572 | public abstract long getNetworkActivityPackets(int type, int which); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 573 | public abstract long getMobileRadioActiveTime(int which); |
| 574 | public abstract int getMobileRadioActiveCount(int which); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 575 | |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 576 | /** |
| 577 | * Get the total cpu time (in microseconds) this UID had processes executing in userspace. |
| 578 | */ |
| 579 | public abstract long getUserCpuTimeUs(int which); |
| 580 | |
| 581 | /** |
| 582 | * Get the total cpu time (in microseconds) this UID had processes executing kernel syscalls. |
| 583 | */ |
| 584 | public abstract long getSystemCpuTimeUs(int which); |
| 585 | |
| 586 | /** |
Adam Lesinski | a7a4ccc | 2015-06-26 17:43:04 -0700 | [diff] [blame] | 587 | * Get the total cpu power consumed (in milli-ampere-microseconds). |
| 588 | */ |
| 589 | public abstract long getCpuPowerMaUs(int which); |
| 590 | |
| 591 | /** |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 592 | * Returns the approximate cpu time (in milliseconds) spent at a certain CPU speed for a |
| 593 | * given CPU cluster. |
| 594 | * @param cluster the index of the CPU cluster. |
Adam Lesinski | a7a4ccc | 2015-06-26 17:43:04 -0700 | [diff] [blame] | 595 | * @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] | 596 | * @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] | 597 | * @see com.android.internal.os.PowerProfile#getNumCpuClusters() |
| 598 | * @see com.android.internal.os.PowerProfile#getNumSpeedStepsInCpuCluster(int) |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 599 | */ |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 600 | public abstract long getTimeAtCpuSpeed(int cluster, int step, int which); |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 601 | |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 602 | /** |
| 603 | * Returns the number of times this UID woke up the Application Processor to |
| 604 | * process a mobile radio packet. |
| 605 | * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT. |
| 606 | */ |
| 607 | public abstract long getMobileRadioApWakeupCount(int which); |
| 608 | |
| 609 | /** |
| 610 | * Returns the number of times this UID woke up the Application Processor to |
| 611 | * process a WiFi packet. |
| 612 | * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT. |
| 613 | */ |
| 614 | public abstract long getWifiRadioApWakeupCount(int which); |
| 615 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 616 | public static abstract class Sensor { |
Mathias Agopian | 7f84c06 | 2013-02-04 19:22:47 -0800 | [diff] [blame] | 617 | /* |
| 618 | * FIXME: it's not correct to use this magic value because it |
| 619 | * could clash with a sensor handle (which are defined by |
| 620 | * the sensor HAL, and therefore out of our control |
| 621 | */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 622 | // Magic sensor number for the GPS. |
| 623 | public static final int GPS = -10000; |
Amith Yamasani | ab9ad19 | 2016-12-06 12:46:59 -0800 | [diff] [blame] | 624 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 625 | public abstract int getHandle(); |
Amith Yamasani | ab9ad19 | 2016-12-06 12:46:59 -0800 | [diff] [blame] | 626 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 627 | public abstract Timer getSensorTime(); |
Amith Yamasani | ab9ad19 | 2016-12-06 12:46:59 -0800 | [diff] [blame] | 628 | |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame^] | 629 | /** Returns a Timer for sensor usage when app is in the background. */ |
| 630 | public abstract Timer getSensorBackgroundTime(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 631 | } |
| 632 | |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 633 | public class Pid { |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 634 | public int mWakeNesting; |
| 635 | public long mWakeSumMs; |
| 636 | public long mWakeStartMs; |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 637 | } |
| 638 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 639 | /** |
| 640 | * The statistics associated with a particular process. |
| 641 | */ |
| 642 | public static abstract class Proc { |
| 643 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 644 | public static class ExcessivePower { |
| 645 | public static final int TYPE_WAKE = 1; |
| 646 | public static final int TYPE_CPU = 2; |
| 647 | |
| 648 | public int type; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 649 | public long overTime; |
| 650 | public long usedTime; |
| 651 | } |
| 652 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 653 | /** |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 654 | * Returns true if this process is still active in the battery stats. |
| 655 | */ |
| 656 | public abstract boolean isActive(); |
| 657 | |
| 658 | /** |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 659 | * 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] | 660 | * |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 661 | * @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] | 662 | */ |
| 663 | public abstract long getUserTime(int which); |
| 664 | |
| 665 | /** |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 666 | * 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] | 667 | * |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 668 | * @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] | 669 | */ |
| 670 | public abstract long getSystemTime(int which); |
| 671 | |
| 672 | /** |
| 673 | * Returns the number of times the process has been started. |
| 674 | * |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 675 | * @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] | 676 | */ |
| 677 | public abstract int getStarts(int which); |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 678 | |
| 679 | /** |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 680 | * Returns the number of times the process has crashed. |
| 681 | * |
| 682 | * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT. |
| 683 | */ |
| 684 | public abstract int getNumCrashes(int which); |
| 685 | |
| 686 | /** |
| 687 | * Returns the number of times the process has ANRed. |
| 688 | * |
| 689 | * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT. |
| 690 | */ |
| 691 | public abstract int getNumAnrs(int which); |
| 692 | |
| 693 | /** |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 694 | * 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] | 695 | * @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] | 696 | * @return foreground cpu time in microseconds |
| 697 | */ |
| 698 | public abstract long getForegroundTime(int which); |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 699 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 700 | public abstract int countExcessivePowers(); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 701 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 702 | public abstract ExcessivePower getExcessivePower(int i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 703 | } |
| 704 | |
| 705 | /** |
| 706 | * The statistics associated with a particular package. |
| 707 | */ |
| 708 | public static abstract class Pkg { |
| 709 | |
| 710 | /** |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 711 | * Returns information about all wakeup alarms that have been triggered for this |
| 712 | * package. The mapping keys are tag names for the alarms, the counter contains |
| 713 | * 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] | 714 | */ |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 715 | public abstract ArrayMap<String, ? extends Counter> getWakeupAlarmStats(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 716 | |
| 717 | /** |
| 718 | * Returns a mapping containing service statistics. |
| 719 | */ |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 720 | public abstract ArrayMap<String, ? extends Serv> getServiceStats(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 721 | |
| 722 | /** |
| 723 | * The statistics associated with a particular service. |
| 724 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 725 | public static abstract class Serv { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 726 | |
| 727 | /** |
| 728 | * Returns the amount of time spent started. |
| 729 | * |
| 730 | * @param batteryUptime elapsed uptime on battery in microseconds. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 731 | * @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] | 732 | * @return |
| 733 | */ |
| 734 | public abstract long getStartTime(long batteryUptime, int which); |
| 735 | |
| 736 | /** |
| 737 | * Returns the total number of times startService() has been called. |
| 738 | * |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 739 | * @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] | 740 | */ |
| 741 | public abstract int getStarts(int which); |
| 742 | |
| 743 | /** |
| 744 | * Returns the total number times the service has been launched. |
| 745 | * |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 746 | * @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] | 747 | */ |
| 748 | public abstract int getLaunches(int which); |
| 749 | } |
| 750 | } |
| 751 | } |
| 752 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 753 | public static final class LevelStepTracker { |
| 754 | public long mLastStepTime = -1; |
| 755 | public int mNumStepDurations; |
| 756 | public final long[] mStepDurations; |
| 757 | |
| 758 | public LevelStepTracker(int maxLevelSteps) { |
| 759 | mStepDurations = new long[maxLevelSteps]; |
| 760 | } |
| 761 | |
| 762 | public LevelStepTracker(int numSteps, long[] steps) { |
| 763 | mNumStepDurations = numSteps; |
| 764 | mStepDurations = new long[numSteps]; |
| 765 | System.arraycopy(steps, 0, mStepDurations, 0, numSteps); |
| 766 | } |
| 767 | |
| 768 | public long getDurationAt(int index) { |
| 769 | return mStepDurations[index] & STEP_LEVEL_TIME_MASK; |
| 770 | } |
| 771 | |
| 772 | public int getLevelAt(int index) { |
| 773 | return (int)((mStepDurations[index] & STEP_LEVEL_LEVEL_MASK) |
| 774 | >> STEP_LEVEL_LEVEL_SHIFT); |
| 775 | } |
| 776 | |
| 777 | public int getInitModeAt(int index) { |
| 778 | return (int)((mStepDurations[index] & STEP_LEVEL_INITIAL_MODE_MASK) |
| 779 | >> STEP_LEVEL_INITIAL_MODE_SHIFT); |
| 780 | } |
| 781 | |
| 782 | public int getModModeAt(int index) { |
| 783 | return (int)((mStepDurations[index] & STEP_LEVEL_MODIFIED_MODE_MASK) |
| 784 | >> STEP_LEVEL_MODIFIED_MODE_SHIFT); |
| 785 | } |
| 786 | |
| 787 | private void appendHex(long val, int topOffset, StringBuilder out) { |
| 788 | boolean hasData = false; |
| 789 | while (topOffset >= 0) { |
| 790 | int digit = (int)( (val>>topOffset) & 0xf ); |
| 791 | topOffset -= 4; |
| 792 | if (!hasData && digit == 0) { |
| 793 | continue; |
| 794 | } |
| 795 | hasData = true; |
| 796 | if (digit >= 0 && digit <= 9) { |
| 797 | out.append((char)('0' + digit)); |
| 798 | } else { |
| 799 | out.append((char)('a' + digit - 10)); |
| 800 | } |
| 801 | } |
| 802 | } |
| 803 | |
| 804 | public void encodeEntryAt(int index, StringBuilder out) { |
| 805 | long item = mStepDurations[index]; |
| 806 | long duration = item & STEP_LEVEL_TIME_MASK; |
| 807 | int level = (int)((item & STEP_LEVEL_LEVEL_MASK) |
| 808 | >> STEP_LEVEL_LEVEL_SHIFT); |
| 809 | int initMode = (int)((item & STEP_LEVEL_INITIAL_MODE_MASK) |
| 810 | >> STEP_LEVEL_INITIAL_MODE_SHIFT); |
| 811 | int modMode = (int)((item & STEP_LEVEL_MODIFIED_MODE_MASK) |
| 812 | >> STEP_LEVEL_MODIFIED_MODE_SHIFT); |
| 813 | switch ((initMode&STEP_LEVEL_MODE_SCREEN_STATE) + 1) { |
| 814 | case Display.STATE_OFF: out.append('f'); break; |
| 815 | case Display.STATE_ON: out.append('o'); break; |
| 816 | case Display.STATE_DOZE: out.append('d'); break; |
| 817 | case Display.STATE_DOZE_SUSPEND: out.append('z'); break; |
| 818 | } |
| 819 | if ((initMode&STEP_LEVEL_MODE_POWER_SAVE) != 0) { |
| 820 | out.append('p'); |
| 821 | } |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 822 | if ((initMode&STEP_LEVEL_MODE_DEVICE_IDLE) != 0) { |
| 823 | out.append('i'); |
| 824 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 825 | switch ((modMode&STEP_LEVEL_MODE_SCREEN_STATE) + 1) { |
| 826 | case Display.STATE_OFF: out.append('F'); break; |
| 827 | case Display.STATE_ON: out.append('O'); break; |
| 828 | case Display.STATE_DOZE: out.append('D'); break; |
| 829 | case Display.STATE_DOZE_SUSPEND: out.append('Z'); break; |
| 830 | } |
| 831 | if ((modMode&STEP_LEVEL_MODE_POWER_SAVE) != 0) { |
| 832 | out.append('P'); |
| 833 | } |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 834 | if ((modMode&STEP_LEVEL_MODE_DEVICE_IDLE) != 0) { |
| 835 | out.append('I'); |
| 836 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 837 | out.append('-'); |
| 838 | appendHex(level, 4, out); |
| 839 | out.append('-'); |
| 840 | appendHex(duration, STEP_LEVEL_LEVEL_SHIFT-4, out); |
| 841 | } |
| 842 | |
| 843 | public void decodeEntryAt(int index, String value) { |
| 844 | final int N = value.length(); |
| 845 | int i = 0; |
| 846 | char c; |
| 847 | long out = 0; |
| 848 | while (i < N && (c=value.charAt(i)) != '-') { |
| 849 | i++; |
| 850 | switch (c) { |
Dianne Hackborn | 8cfb58b | 2015-03-04 13:28:36 -0800 | [diff] [blame] | 851 | 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] | 852 | break; |
Dianne Hackborn | 8cfb58b | 2015-03-04 13:28:36 -0800 | [diff] [blame] | 853 | 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] | 854 | break; |
Dianne Hackborn | 8cfb58b | 2015-03-04 13:28:36 -0800 | [diff] [blame] | 855 | 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] | 856 | break; |
Dianne Hackborn | 8cfb58b | 2015-03-04 13:28:36 -0800 | [diff] [blame] | 857 | case 'z': out |= (((long)Display.STATE_DOZE_SUSPEND-1) |
| 858 | << STEP_LEVEL_INITIAL_MODE_SHIFT); |
| 859 | break; |
| 860 | case 'p': out |= (((long)STEP_LEVEL_MODE_POWER_SAVE) |
| 861 | << STEP_LEVEL_INITIAL_MODE_SHIFT); |
| 862 | break; |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 863 | case 'i': out |= (((long)STEP_LEVEL_MODE_DEVICE_IDLE) |
| 864 | << STEP_LEVEL_INITIAL_MODE_SHIFT); |
| 865 | break; |
Dianne Hackborn | 8cfb58b | 2015-03-04 13:28:36 -0800 | [diff] [blame] | 866 | case 'F': out |= (((long)Display.STATE_OFF-1)<<STEP_LEVEL_MODIFIED_MODE_SHIFT); |
| 867 | break; |
| 868 | case 'O': out |= (((long)Display.STATE_ON-1)<<STEP_LEVEL_MODIFIED_MODE_SHIFT); |
| 869 | break; |
| 870 | case 'D': out |= (((long)Display.STATE_DOZE-1)<<STEP_LEVEL_MODIFIED_MODE_SHIFT); |
| 871 | break; |
| 872 | case 'Z': out |= (((long)Display.STATE_DOZE_SUSPEND-1) |
| 873 | << STEP_LEVEL_MODIFIED_MODE_SHIFT); |
| 874 | break; |
| 875 | case 'P': out |= (((long)STEP_LEVEL_MODE_POWER_SAVE) |
| 876 | << STEP_LEVEL_MODIFIED_MODE_SHIFT); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 877 | break; |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 878 | case 'I': out |= (((long)STEP_LEVEL_MODE_DEVICE_IDLE) |
| 879 | << STEP_LEVEL_MODIFIED_MODE_SHIFT); |
| 880 | break; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 881 | } |
| 882 | } |
| 883 | i++; |
Dianne Hackborn | 8cfb58b | 2015-03-04 13:28:36 -0800 | [diff] [blame] | 884 | long level = 0; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 885 | while (i < N && (c=value.charAt(i)) != '-') { |
| 886 | i++; |
| 887 | level <<= 4; |
| 888 | if (c >= '0' && c <= '9') { |
| 889 | level += c - '0'; |
| 890 | } else if (c >= 'a' && c <= 'f') { |
| 891 | level += c - 'a' + 10; |
| 892 | } else if (c >= 'A' && c <= 'F') { |
| 893 | level += c - 'A' + 10; |
| 894 | } |
| 895 | } |
Dianne Hackborn | 8cfb58b | 2015-03-04 13:28:36 -0800 | [diff] [blame] | 896 | i++; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 897 | out |= (level << STEP_LEVEL_LEVEL_SHIFT) & STEP_LEVEL_LEVEL_MASK; |
| 898 | long duration = 0; |
| 899 | while (i < N && (c=value.charAt(i)) != '-') { |
| 900 | i++; |
| 901 | duration <<= 4; |
| 902 | if (c >= '0' && c <= '9') { |
| 903 | duration += c - '0'; |
| 904 | } else if (c >= 'a' && c <= 'f') { |
| 905 | duration += c - 'a' + 10; |
| 906 | } else if (c >= 'A' && c <= 'F') { |
| 907 | duration += c - 'A' + 10; |
| 908 | } |
| 909 | } |
| 910 | mStepDurations[index] = out | (duration & STEP_LEVEL_TIME_MASK); |
| 911 | } |
| 912 | |
| 913 | public void init() { |
| 914 | mLastStepTime = -1; |
| 915 | mNumStepDurations = 0; |
| 916 | } |
| 917 | |
| 918 | public void clearTime() { |
| 919 | mLastStepTime = -1; |
| 920 | } |
| 921 | |
| 922 | public long computeTimePerLevel() { |
| 923 | final long[] steps = mStepDurations; |
| 924 | final int numSteps = mNumStepDurations; |
| 925 | |
| 926 | // For now we'll do a simple average across all steps. |
| 927 | if (numSteps <= 0) { |
| 928 | return -1; |
| 929 | } |
| 930 | long total = 0; |
| 931 | for (int i=0; i<numSteps; i++) { |
| 932 | total += steps[i] & STEP_LEVEL_TIME_MASK; |
| 933 | } |
| 934 | return total / numSteps; |
| 935 | /* |
| 936 | long[] buckets = new long[numSteps]; |
| 937 | int numBuckets = 0; |
| 938 | int numToAverage = 4; |
| 939 | int i = 0; |
| 940 | while (i < numSteps) { |
| 941 | long totalTime = 0; |
| 942 | int num = 0; |
| 943 | for (int j=0; j<numToAverage && (i+j)<numSteps; j++) { |
| 944 | totalTime += steps[i+j] & STEP_LEVEL_TIME_MASK; |
| 945 | num++; |
| 946 | } |
| 947 | buckets[numBuckets] = totalTime / num; |
| 948 | numBuckets++; |
| 949 | numToAverage *= 2; |
| 950 | i += num; |
| 951 | } |
| 952 | if (numBuckets < 1) { |
| 953 | return -1; |
| 954 | } |
| 955 | long averageTime = buckets[numBuckets-1]; |
| 956 | for (i=numBuckets-2; i>=0; i--) { |
| 957 | averageTime = (averageTime + buckets[i]) / 2; |
| 958 | } |
| 959 | return averageTime; |
| 960 | */ |
| 961 | } |
| 962 | |
| 963 | public long computeTimeEstimate(long modesOfInterest, long modeValues, |
| 964 | int[] outNumOfInterest) { |
| 965 | final long[] steps = mStepDurations; |
| 966 | final int count = mNumStepDurations; |
| 967 | if (count <= 0) { |
| 968 | return -1; |
| 969 | } |
| 970 | long total = 0; |
| 971 | int numOfInterest = 0; |
| 972 | for (int i=0; i<count; i++) { |
| 973 | long initMode = (steps[i] & STEP_LEVEL_INITIAL_MODE_MASK) |
| 974 | >> STEP_LEVEL_INITIAL_MODE_SHIFT; |
| 975 | long modMode = (steps[i] & STEP_LEVEL_MODIFIED_MODE_MASK) |
| 976 | >> STEP_LEVEL_MODIFIED_MODE_SHIFT; |
| 977 | // If the modes of interest didn't change during this step period... |
| 978 | if ((modMode&modesOfInterest) == 0) { |
| 979 | // And the mode values during this period match those we are measuring... |
| 980 | if ((initMode&modesOfInterest) == modeValues) { |
| 981 | // Then this can be used to estimate the total time! |
| 982 | numOfInterest++; |
| 983 | total += steps[i] & STEP_LEVEL_TIME_MASK; |
| 984 | } |
| 985 | } |
| 986 | } |
| 987 | if (numOfInterest <= 0) { |
| 988 | return -1; |
| 989 | } |
| 990 | |
| 991 | if (outNumOfInterest != null) { |
| 992 | outNumOfInterest[0] = numOfInterest; |
| 993 | } |
| 994 | |
| 995 | // The estimated time is the average time we spend in each level, multipled |
| 996 | // by 100 -- the total number of battery levels |
| 997 | return (total / numOfInterest) * 100; |
| 998 | } |
| 999 | |
| 1000 | public void addLevelSteps(int numStepLevels, long modeBits, long elapsedRealtime) { |
| 1001 | int stepCount = mNumStepDurations; |
| 1002 | final long lastStepTime = mLastStepTime; |
| 1003 | if (lastStepTime >= 0 && numStepLevels > 0) { |
| 1004 | final long[] steps = mStepDurations; |
| 1005 | long duration = elapsedRealtime - lastStepTime; |
| 1006 | for (int i=0; i<numStepLevels; i++) { |
| 1007 | System.arraycopy(steps, 0, steps, 1, steps.length-1); |
| 1008 | long thisDuration = duration / (numStepLevels-i); |
| 1009 | duration -= thisDuration; |
| 1010 | if (thisDuration > STEP_LEVEL_TIME_MASK) { |
| 1011 | thisDuration = STEP_LEVEL_TIME_MASK; |
| 1012 | } |
| 1013 | steps[0] = thisDuration | modeBits; |
| 1014 | } |
| 1015 | stepCount += numStepLevels; |
| 1016 | if (stepCount > steps.length) { |
| 1017 | stepCount = steps.length; |
| 1018 | } |
| 1019 | } |
| 1020 | mNumStepDurations = stepCount; |
| 1021 | mLastStepTime = elapsedRealtime; |
| 1022 | } |
| 1023 | |
| 1024 | public void readFromParcel(Parcel in) { |
| 1025 | final int N = in.readInt(); |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 1026 | if (N > mStepDurations.length) { |
| 1027 | throw new ParcelFormatException("more step durations than available: " + N); |
| 1028 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 1029 | mNumStepDurations = N; |
| 1030 | for (int i=0; i<N; i++) { |
| 1031 | mStepDurations[i] = in.readLong(); |
| 1032 | } |
| 1033 | } |
| 1034 | |
| 1035 | public void writeToParcel(Parcel out) { |
| 1036 | final int N = mNumStepDurations; |
| 1037 | out.writeInt(N); |
| 1038 | for (int i=0; i<N; i++) { |
| 1039 | out.writeLong(mStepDurations[i]); |
| 1040 | } |
| 1041 | } |
| 1042 | } |
| 1043 | |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 1044 | public static final class PackageChange { |
| 1045 | public String mPackageName; |
| 1046 | public boolean mUpdate; |
| 1047 | public int mVersionCode; |
| 1048 | } |
| 1049 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 1050 | public static final class DailyItem { |
| 1051 | public long mStartTime; |
| 1052 | public long mEndTime; |
| 1053 | public LevelStepTracker mDischargeSteps; |
| 1054 | public LevelStepTracker mChargeSteps; |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 1055 | public ArrayList<PackageChange> mPackageChanges; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 1056 | } |
| 1057 | |
| 1058 | public abstract DailyItem getDailyItemLocked(int daysAgo); |
| 1059 | |
| 1060 | public abstract long getCurrentDailyStartTime(); |
| 1061 | |
| 1062 | public abstract long getNextMinDailyDeadline(); |
| 1063 | |
| 1064 | public abstract long getNextMaxDailyDeadline(); |
| 1065 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1066 | public final static class HistoryTag { |
| 1067 | public String string; |
| 1068 | public int uid; |
| 1069 | |
| 1070 | public int poolIdx; |
| 1071 | |
| 1072 | public void setTo(HistoryTag o) { |
| 1073 | string = o.string; |
| 1074 | uid = o.uid; |
| 1075 | poolIdx = o.poolIdx; |
| 1076 | } |
| 1077 | |
| 1078 | public void setTo(String _string, int _uid) { |
| 1079 | string = _string; |
| 1080 | uid = _uid; |
| 1081 | poolIdx = -1; |
| 1082 | } |
| 1083 | |
| 1084 | public void writeToParcel(Parcel dest, int flags) { |
| 1085 | dest.writeString(string); |
| 1086 | dest.writeInt(uid); |
| 1087 | } |
| 1088 | |
| 1089 | public void readFromParcel(Parcel src) { |
| 1090 | string = src.readString(); |
| 1091 | uid = src.readInt(); |
| 1092 | poolIdx = -1; |
| 1093 | } |
| 1094 | |
| 1095 | @Override |
| 1096 | public boolean equals(Object o) { |
| 1097 | if (this == o) return true; |
| 1098 | if (o == null || getClass() != o.getClass()) return false; |
| 1099 | |
| 1100 | HistoryTag that = (HistoryTag) o; |
| 1101 | |
| 1102 | if (uid != that.uid) return false; |
| 1103 | if (!string.equals(that.string)) return false; |
| 1104 | |
| 1105 | return true; |
| 1106 | } |
| 1107 | |
| 1108 | @Override |
| 1109 | public int hashCode() { |
| 1110 | int result = string.hashCode(); |
| 1111 | result = 31 * result + uid; |
| 1112 | return result; |
| 1113 | } |
| 1114 | } |
| 1115 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 1116 | /** |
| 1117 | * Optional detailed information that can go into a history step. This is typically |
| 1118 | * generated each time the battery level changes. |
| 1119 | */ |
| 1120 | public final static class HistoryStepDetails { |
| 1121 | // Time (in 1/100 second) spent in user space and the kernel since the last step. |
| 1122 | public int userTime; |
| 1123 | public int systemTime; |
| 1124 | |
| 1125 | // Top three apps using CPU in the last step, with times in 1/100 second. |
| 1126 | public int appCpuUid1; |
| 1127 | public int appCpuUTime1; |
| 1128 | public int appCpuSTime1; |
| 1129 | public int appCpuUid2; |
| 1130 | public int appCpuUTime2; |
| 1131 | public int appCpuSTime2; |
| 1132 | public int appCpuUid3; |
| 1133 | public int appCpuUTime3; |
| 1134 | public int appCpuSTime3; |
| 1135 | |
| 1136 | // Information from /proc/stat |
| 1137 | public int statUserTime; |
| 1138 | public int statSystemTime; |
| 1139 | public int statIOWaitTime; |
| 1140 | public int statIrqTime; |
| 1141 | public int statSoftIrqTime; |
| 1142 | public int statIdlTime; |
| 1143 | |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 1144 | // Platform-level low power state stats |
| 1145 | public String statPlatformIdleState; |
| 1146 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 1147 | public HistoryStepDetails() { |
| 1148 | clear(); |
| 1149 | } |
| 1150 | |
| 1151 | public void clear() { |
| 1152 | userTime = systemTime = 0; |
| 1153 | appCpuUid1 = appCpuUid2 = appCpuUid3 = -1; |
| 1154 | appCpuUTime1 = appCpuSTime1 = appCpuUTime2 = appCpuSTime2 |
| 1155 | = appCpuUTime3 = appCpuSTime3 = 0; |
| 1156 | } |
| 1157 | |
| 1158 | public void writeToParcel(Parcel out) { |
| 1159 | out.writeInt(userTime); |
| 1160 | out.writeInt(systemTime); |
| 1161 | out.writeInt(appCpuUid1); |
| 1162 | out.writeInt(appCpuUTime1); |
| 1163 | out.writeInt(appCpuSTime1); |
| 1164 | out.writeInt(appCpuUid2); |
| 1165 | out.writeInt(appCpuUTime2); |
| 1166 | out.writeInt(appCpuSTime2); |
| 1167 | out.writeInt(appCpuUid3); |
| 1168 | out.writeInt(appCpuUTime3); |
| 1169 | out.writeInt(appCpuSTime3); |
| 1170 | out.writeInt(statUserTime); |
| 1171 | out.writeInt(statSystemTime); |
| 1172 | out.writeInt(statIOWaitTime); |
| 1173 | out.writeInt(statIrqTime); |
| 1174 | out.writeInt(statSoftIrqTime); |
| 1175 | out.writeInt(statIdlTime); |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 1176 | out.writeString(statPlatformIdleState); |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 1177 | } |
| 1178 | |
| 1179 | public void readFromParcel(Parcel in) { |
| 1180 | userTime = in.readInt(); |
| 1181 | systemTime = in.readInt(); |
| 1182 | appCpuUid1 = in.readInt(); |
| 1183 | appCpuUTime1 = in.readInt(); |
| 1184 | appCpuSTime1 = in.readInt(); |
| 1185 | appCpuUid2 = in.readInt(); |
| 1186 | appCpuUTime2 = in.readInt(); |
| 1187 | appCpuSTime2 = in.readInt(); |
| 1188 | appCpuUid3 = in.readInt(); |
| 1189 | appCpuUTime3 = in.readInt(); |
| 1190 | appCpuSTime3 = in.readInt(); |
| 1191 | statUserTime = in.readInt(); |
| 1192 | statSystemTime = in.readInt(); |
| 1193 | statIOWaitTime = in.readInt(); |
| 1194 | statIrqTime = in.readInt(); |
| 1195 | statSoftIrqTime = in.readInt(); |
| 1196 | statIdlTime = in.readInt(); |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 1197 | statPlatformIdleState = in.readString(); |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 1198 | } |
| 1199 | } |
| 1200 | |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 1201 | public final static class HistoryItem implements Parcelable { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1202 | public HistoryItem next; |
Dianne Hackborn | 9a75543 | 2014-05-15 17:05:22 -0700 | [diff] [blame] | 1203 | |
| 1204 | // The time of this event in milliseconds, as per SystemClock.elapsedRealtime(). |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1205 | public long time; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1206 | |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 1207 | 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] | 1208 | public static final byte CMD_NULL = -1; |
| 1209 | public static final byte CMD_START = 4; |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1210 | public static final byte CMD_CURRENT_TIME = 5; |
| 1211 | public static final byte CMD_OVERFLOW = 6; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 1212 | public static final byte CMD_RESET = 7; |
Dianne Hackborn | 29cd7f1 | 2015-01-08 10:37:05 -0800 | [diff] [blame] | 1213 | public static final byte CMD_SHUTDOWN = 8; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1214 | |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 1215 | public byte cmd = CMD_NULL; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1216 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1217 | /** |
| 1218 | * Return whether the command code is a delta data update. |
| 1219 | */ |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1220 | public boolean isDeltaData() { |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 1221 | return cmd == CMD_UPDATE; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1222 | } |
| 1223 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1224 | public byte batteryLevel; |
| 1225 | public byte batteryStatus; |
| 1226 | public byte batteryHealth; |
| 1227 | public byte batteryPlugType; |
| 1228 | |
Sungmin Choi | c7e9e8b | 2013-01-16 12:57:36 +0900 | [diff] [blame] | 1229 | public short batteryTemperature; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1230 | public char batteryVoltage; |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 1231 | |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 1232 | // The charge of the battery in micro-Ampere-hours. |
| 1233 | public int batteryChargeUAh; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1234 | |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 1235 | // Constants from SCREEN_BRIGHTNESS_* |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1236 | public static final int STATE_BRIGHTNESS_SHIFT = 0; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1237 | public static final int STATE_BRIGHTNESS_MASK = 0x7; |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 1238 | // Constants from SIGNAL_STRENGTH_* |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 1239 | public static final int STATE_PHONE_SIGNAL_STRENGTH_SHIFT = 3; |
| 1240 | 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] | 1241 | // Constants from ServiceState.STATE_* |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1242 | public static final int STATE_PHONE_STATE_SHIFT = 6; |
| 1243 | 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] | 1244 | // Constants from DATA_CONNECTION_* |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1245 | public static final int STATE_DATA_CONNECTION_SHIFT = 9; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1246 | 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] | 1247 | |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 1248 | // These states always appear directly in the first int token |
| 1249 | // of a delta change; they should be ones that change relatively |
| 1250 | // frequently. |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1251 | public static final int STATE_CPU_RUNNING_FLAG = 1<<31; |
| 1252 | public static final int STATE_WAKE_LOCK_FLAG = 1<<30; |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 1253 | public static final int STATE_GPS_ON_FLAG = 1<<29; |
| 1254 | public static final int STATE_WIFI_FULL_LOCK_FLAG = 1<<28; |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 1255 | public static final int STATE_WIFI_SCAN_FLAG = 1<<27; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 1256 | public static final int STATE_WIFI_RADIO_ACTIVE_FLAG = 1<<26; |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 1257 | public static final int STATE_MOBILE_RADIO_ACTIVE_FLAG = 1<<25; |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 1258 | // Do not use, this is used for coulomb delta count. |
| 1259 | private static final int STATE_RESERVED_0 = 1<<24; |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 1260 | // These are on the lower bits used for the command; if they change |
| 1261 | // we need to write another int of data. |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1262 | public static final int STATE_SENSOR_ON_FLAG = 1<<23; |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 1263 | public static final int STATE_AUDIO_ON_FLAG = 1<<22; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1264 | public static final int STATE_PHONE_SCANNING_FLAG = 1<<21; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 1265 | public static final int STATE_SCREEN_ON_FLAG = 1<<20; // consider moving to states2 |
| 1266 | public static final int STATE_BATTERY_PLUGGED_FLAG = 1<<19; // consider moving to states2 |
| 1267 | // empty slot |
| 1268 | // empty slot |
| 1269 | public static final int STATE_WIFI_MULTICAST_ON_FLAG = 1<<16; |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 1270 | |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 1271 | public static final int MOST_INTERESTING_STATES = |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 1272 | STATE_BATTERY_PLUGGED_FLAG | STATE_SCREEN_ON_FLAG; |
| 1273 | |
| 1274 | public static final int SETTLE_TO_ZERO_STATES = 0xffff0000 & ~MOST_INTERESTING_STATES; |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 1275 | |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1276 | public int states; |
| 1277 | |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 1278 | // Constants from WIFI_SUPPL_STATE_* |
| 1279 | public static final int STATE2_WIFI_SUPPL_STATE_SHIFT = 0; |
| 1280 | public static final int STATE2_WIFI_SUPPL_STATE_MASK = 0xf; |
| 1281 | // Values for NUM_WIFI_SIGNAL_STRENGTH_BINS |
| 1282 | public static final int STATE2_WIFI_SIGNAL_STRENGTH_SHIFT = 4; |
| 1283 | public static final int STATE2_WIFI_SIGNAL_STRENGTH_MASK = |
| 1284 | 0x7 << STATE2_WIFI_SIGNAL_STRENGTH_SHIFT; |
| 1285 | |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 1286 | public static final int STATE2_POWER_SAVE_FLAG = 1<<31; |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 1287 | public static final int STATE2_VIDEO_ON_FLAG = 1<<30; |
| 1288 | public static final int STATE2_WIFI_RUNNING_FLAG = 1<<29; |
| 1289 | public static final int STATE2_WIFI_ON_FLAG = 1<<28; |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 1290 | public static final int STATE2_FLASHLIGHT_FLAG = 1<<27; |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 1291 | public static final int STATE2_DEVICE_IDLE_SHIFT = 25; |
| 1292 | public static final int STATE2_DEVICE_IDLE_MASK = 0x3 << STATE2_DEVICE_IDLE_SHIFT; |
| 1293 | public static final int STATE2_CHARGING_FLAG = 1<<24; |
| 1294 | public static final int STATE2_PHONE_IN_CALL_FLAG = 1<<23; |
| 1295 | public static final int STATE2_BLUETOOTH_ON_FLAG = 1<<22; |
| 1296 | public static final int STATE2_CAMERA_FLAG = 1<<21; |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 1297 | public static final int STATE2_BLUETOOTH_SCAN_FLAG = 1 << 20; |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 1298 | |
| 1299 | public static final int MOST_INTERESTING_STATES2 = |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 1300 | STATE2_POWER_SAVE_FLAG | STATE2_WIFI_ON_FLAG | STATE2_DEVICE_IDLE_MASK |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 1301 | | STATE2_CHARGING_FLAG | STATE2_PHONE_IN_CALL_FLAG | STATE2_BLUETOOTH_ON_FLAG; |
| 1302 | |
| 1303 | public static final int SETTLE_TO_ZERO_STATES2 = 0xffff0000 & ~MOST_INTERESTING_STATES2; |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 1304 | |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 1305 | public int states2; |
| 1306 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1307 | // The wake lock that was acquired at this point. |
| 1308 | public HistoryTag wakelockTag; |
| 1309 | |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1310 | // Kernel wakeup reason at this point. |
| 1311 | public HistoryTag wakeReasonTag; |
| 1312 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 1313 | // Non-null when there is more detailed information at this step. |
| 1314 | public HistoryStepDetails stepDetails; |
| 1315 | |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 1316 | public static final int EVENT_FLAG_START = 0x8000; |
| 1317 | public static final int EVENT_FLAG_FINISH = 0x4000; |
| 1318 | |
| 1319 | // No event in this item. |
| 1320 | public static final int EVENT_NONE = 0x0000; |
| 1321 | // Event is about a process that is running. |
| 1322 | public static final int EVENT_PROC = 0x0001; |
| 1323 | // Event is about an application package that is in the foreground. |
| 1324 | public static final int EVENT_FOREGROUND = 0x0002; |
| 1325 | // Event is about an application package that is at the top of the screen. |
| 1326 | public static final int EVENT_TOP = 0x0003; |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 1327 | // Event is about active sync operations. |
Dianne Hackborn | a1f1a3c | 2014-02-24 18:12:28 -0800 | [diff] [blame] | 1328 | public static final int EVENT_SYNC = 0x0004; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 1329 | // Events for all additional wake locks aquired/release within a wake block. |
| 1330 | // These are not generated by default. |
| 1331 | public static final int EVENT_WAKE_LOCK = 0x0005; |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 1332 | // Event is about an application executing a scheduled job. |
| 1333 | public static final int EVENT_JOB = 0x0006; |
| 1334 | // Events for users running. |
| 1335 | public static final int EVENT_USER_RUNNING = 0x0007; |
| 1336 | // Events for foreground user. |
| 1337 | public static final int EVENT_USER_FOREGROUND = 0x0008; |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 1338 | // Event for connectivity changed. |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 1339 | public static final int EVENT_CONNECTIVITY_CHANGED = 0x0009; |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 1340 | // Event for becoming active taking us out of idle mode. |
Dianne Hackborn | b6683c4 | 2015-06-18 17:40:33 -0700 | [diff] [blame] | 1341 | public static final int EVENT_ACTIVE = 0x000a; |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 1342 | // Event for a package being installed. |
Dianne Hackborn | b6683c4 | 2015-06-18 17:40:33 -0700 | [diff] [blame] | 1343 | public static final int EVENT_PACKAGE_INSTALLED = 0x000b; |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 1344 | // Event for a package being uninstalled. |
Dianne Hackborn | b6683c4 | 2015-06-18 17:40:33 -0700 | [diff] [blame] | 1345 | public static final int EVENT_PACKAGE_UNINSTALLED = 0x000c; |
Dianne Hackborn | 1e38382 | 2015-04-10 14:02:33 -0700 | [diff] [blame] | 1346 | // Event for a package being uninstalled. |
Dianne Hackborn | b6683c4 | 2015-06-18 17:40:33 -0700 | [diff] [blame] | 1347 | public static final int EVENT_ALARM = 0x000d; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 1348 | // Record that we have decided we need to collect new stats data. |
Dianne Hackborn | b6683c4 | 2015-06-18 17:40:33 -0700 | [diff] [blame] | 1349 | public static final int EVENT_COLLECT_EXTERNAL_STATS = 0x000e; |
Amith Yamasani | 6776849 | 2015-06-09 12:23:58 -0700 | [diff] [blame] | 1350 | // 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] | 1351 | public static final int EVENT_PACKAGE_INACTIVE = 0x000f; |
Amith Yamasani | 6776849 | 2015-06-09 12:23:58 -0700 | [diff] [blame] | 1352 | // Event for a package becoming active due to an interaction. |
Dianne Hackborn | b6683c4 | 2015-06-18 17:40:33 -0700 | [diff] [blame] | 1353 | public static final int EVENT_PACKAGE_ACTIVE = 0x0010; |
Dianne Hackborn | fd854ee | 2015-07-13 18:00:37 -0700 | [diff] [blame] | 1354 | // Event for a package being on the temporary whitelist. |
| 1355 | public static final int EVENT_TEMP_WHITELIST = 0x0011; |
Dianne Hackborn | 280a64e | 2015-07-13 14:48:08 -0700 | [diff] [blame] | 1356 | // Event for the screen waking up. |
| 1357 | public static final int EVENT_SCREEN_WAKE_UP = 0x0012; |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 1358 | // Event for the UID that woke up the application processor. |
| 1359 | // Used for wakeups coming from WiFi, modem, etc. |
| 1360 | public static final int EVENT_WAKEUP_AP = 0x0013; |
Dianne Hackborn | d0db6f0 | 2016-07-18 14:14:20 -0700 | [diff] [blame] | 1361 | // Event for reporting that a specific partial wake lock has been held for a long duration. |
| 1362 | public static final int EVENT_LONG_WAKE_LOCK = 0x0014; |
Adam Lesinski | 041d917 | 2016-12-12 12:03:56 -0800 | [diff] [blame] | 1363 | // Event reporting the new estimated (learned) capacity of the battery in mAh. |
| 1364 | public static final int EVENT_ESTIMATED_BATTERY_CAP = 0x0015; |
Amith Yamasani | 6776849 | 2015-06-09 12:23:58 -0700 | [diff] [blame] | 1365 | |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 1366 | // Number of event types. |
Adam Lesinski | 041d917 | 2016-12-12 12:03:56 -0800 | [diff] [blame] | 1367 | public static final int EVENT_COUNT = 0x0016; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 1368 | // Mask to extract out only the type part of the event. |
| 1369 | 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] | 1370 | |
| 1371 | public static final int EVENT_PROC_START = EVENT_PROC | EVENT_FLAG_START; |
| 1372 | public static final int EVENT_PROC_FINISH = EVENT_PROC | EVENT_FLAG_FINISH; |
| 1373 | public static final int EVENT_FOREGROUND_START = EVENT_FOREGROUND | EVENT_FLAG_START; |
| 1374 | public static final int EVENT_FOREGROUND_FINISH = EVENT_FOREGROUND | EVENT_FLAG_FINISH; |
| 1375 | public static final int EVENT_TOP_START = EVENT_TOP | EVENT_FLAG_START; |
| 1376 | public static final int EVENT_TOP_FINISH = EVENT_TOP | EVENT_FLAG_FINISH; |
Dianne Hackborn | a1f1a3c | 2014-02-24 18:12:28 -0800 | [diff] [blame] | 1377 | public static final int EVENT_SYNC_START = EVENT_SYNC | EVENT_FLAG_START; |
| 1378 | public static final int EVENT_SYNC_FINISH = EVENT_SYNC | EVENT_FLAG_FINISH; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 1379 | public static final int EVENT_WAKE_LOCK_START = EVENT_WAKE_LOCK | EVENT_FLAG_START; |
| 1380 | 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] | 1381 | public static final int EVENT_JOB_START = EVENT_JOB | EVENT_FLAG_START; |
| 1382 | public static final int EVENT_JOB_FINISH = EVENT_JOB | EVENT_FLAG_FINISH; |
| 1383 | public static final int EVENT_USER_RUNNING_START = EVENT_USER_RUNNING | EVENT_FLAG_START; |
| 1384 | public static final int EVENT_USER_RUNNING_FINISH = EVENT_USER_RUNNING | EVENT_FLAG_FINISH; |
| 1385 | public static final int EVENT_USER_FOREGROUND_START = |
| 1386 | EVENT_USER_FOREGROUND | EVENT_FLAG_START; |
| 1387 | public static final int EVENT_USER_FOREGROUND_FINISH = |
| 1388 | EVENT_USER_FOREGROUND | EVENT_FLAG_FINISH; |
Dianne Hackborn | 1e38382 | 2015-04-10 14:02:33 -0700 | [diff] [blame] | 1389 | public static final int EVENT_ALARM_START = EVENT_ALARM | EVENT_FLAG_START; |
| 1390 | public static final int EVENT_ALARM_FINISH = EVENT_ALARM | EVENT_FLAG_FINISH; |
Dianne Hackborn | fd854ee | 2015-07-13 18:00:37 -0700 | [diff] [blame] | 1391 | public static final int EVENT_TEMP_WHITELIST_START = |
| 1392 | EVENT_TEMP_WHITELIST | EVENT_FLAG_START; |
| 1393 | public static final int EVENT_TEMP_WHITELIST_FINISH = |
| 1394 | EVENT_TEMP_WHITELIST | EVENT_FLAG_FINISH; |
Dianne Hackborn | d0db6f0 | 2016-07-18 14:14:20 -0700 | [diff] [blame] | 1395 | public static final int EVENT_LONG_WAKE_LOCK_START = |
| 1396 | EVENT_LONG_WAKE_LOCK | EVENT_FLAG_START; |
| 1397 | public static final int EVENT_LONG_WAKE_LOCK_FINISH = |
| 1398 | EVENT_LONG_WAKE_LOCK | EVENT_FLAG_FINISH; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1399 | |
| 1400 | // For CMD_EVENT. |
| 1401 | public int eventCode; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1402 | public HistoryTag eventTag; |
| 1403 | |
Dianne Hackborn | 9a75543 | 2014-05-15 17:05:22 -0700 | [diff] [blame] | 1404 | // 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] | 1405 | public long currentTime; |
| 1406 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1407 | // Meta-data when reading. |
| 1408 | public int numReadInts; |
| 1409 | |
| 1410 | // Pre-allocated objects. |
| 1411 | public final HistoryTag localWakelockTag = new HistoryTag(); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1412 | public final HistoryTag localWakeReasonTag = new HistoryTag(); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1413 | public final HistoryTag localEventTag = new HistoryTag(); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1414 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1415 | public HistoryItem() { |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1416 | } |
| 1417 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1418 | public HistoryItem(long time, Parcel src) { |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1419 | this.time = time; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1420 | numReadInts = 2; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 1421 | readFromParcel(src); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1422 | } |
| 1423 | |
| 1424 | public int describeContents() { |
| 1425 | return 0; |
| 1426 | } |
| 1427 | |
| 1428 | public void writeToParcel(Parcel dest, int flags) { |
| 1429 | dest.writeLong(time); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1430 | int bat = (((int)cmd)&0xff) |
| 1431 | | ((((int)batteryLevel)<<8)&0xff00) |
| 1432 | | ((((int)batteryStatus)<<16)&0xf0000) |
| 1433 | | ((((int)batteryHealth)<<20)&0xf00000) |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1434 | | ((((int)batteryPlugType)<<24)&0xf000000) |
| 1435 | | (wakelockTag != null ? 0x10000000 : 0) |
| 1436 | | (wakeReasonTag != null ? 0x20000000 : 0) |
| 1437 | | (eventCode != EVENT_NONE ? 0x40000000 : 0); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1438 | dest.writeInt(bat); |
| 1439 | bat = (((int)batteryTemperature)&0xffff) |
| 1440 | | ((((int)batteryVoltage)<<16)&0xffff0000); |
| 1441 | dest.writeInt(bat); |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 1442 | dest.writeInt(batteryChargeUAh); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1443 | dest.writeInt(states); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1444 | dest.writeInt(states2); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1445 | if (wakelockTag != null) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1446 | wakelockTag.writeToParcel(dest, flags); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1447 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1448 | if (wakeReasonTag != null) { |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1449 | wakeReasonTag.writeToParcel(dest, flags); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1450 | } |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 1451 | if (eventCode != EVENT_NONE) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1452 | dest.writeInt(eventCode); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1453 | eventTag.writeToParcel(dest, flags); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1454 | } |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 1455 | if (cmd == CMD_CURRENT_TIME || cmd == CMD_RESET) { |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1456 | dest.writeLong(currentTime); |
| 1457 | } |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1458 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 1459 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1460 | public void readFromParcel(Parcel src) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1461 | int start = src.dataPosition(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 1462 | int bat = src.readInt(); |
| 1463 | cmd = (byte)(bat&0xff); |
| 1464 | batteryLevel = (byte)((bat>>8)&0xff); |
| 1465 | batteryStatus = (byte)((bat>>16)&0xf); |
| 1466 | batteryHealth = (byte)((bat>>20)&0xf); |
| 1467 | batteryPlugType = (byte)((bat>>24)&0xf); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1468 | int bat2 = src.readInt(); |
| 1469 | batteryTemperature = (short)(bat2&0xffff); |
| 1470 | batteryVoltage = (char)((bat2>>16)&0xffff); |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 1471 | batteryChargeUAh = src.readInt(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 1472 | states = src.readInt(); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1473 | states2 = src.readInt(); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1474 | if ((bat&0x10000000) != 0) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1475 | wakelockTag = localWakelockTag; |
| 1476 | wakelockTag.readFromParcel(src); |
| 1477 | } else { |
| 1478 | wakelockTag = null; |
| 1479 | } |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1480 | if ((bat&0x20000000) != 0) { |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1481 | wakeReasonTag = localWakeReasonTag; |
| 1482 | wakeReasonTag.readFromParcel(src); |
| 1483 | } else { |
| 1484 | wakeReasonTag = null; |
| 1485 | } |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1486 | if ((bat&0x40000000) != 0) { |
| 1487 | eventCode = src.readInt(); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1488 | eventTag = localEventTag; |
| 1489 | eventTag.readFromParcel(src); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1490 | } else { |
| 1491 | eventCode = EVENT_NONE; |
| 1492 | eventTag = null; |
| 1493 | } |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 1494 | if (cmd == CMD_CURRENT_TIME || cmd == CMD_RESET) { |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1495 | currentTime = src.readLong(); |
| 1496 | } else { |
| 1497 | currentTime = 0; |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 1498 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1499 | numReadInts += (src.dataPosition()-start)/4; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 1500 | } |
| 1501 | |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 1502 | public void clear() { |
| 1503 | time = 0; |
| 1504 | cmd = CMD_NULL; |
| 1505 | batteryLevel = 0; |
| 1506 | batteryStatus = 0; |
| 1507 | batteryHealth = 0; |
| 1508 | batteryPlugType = 0; |
| 1509 | batteryTemperature = 0; |
| 1510 | batteryVoltage = 0; |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 1511 | batteryChargeUAh = 0; |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 1512 | states = 0; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1513 | states2 = 0; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1514 | wakelockTag = null; |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1515 | wakeReasonTag = null; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1516 | eventCode = EVENT_NONE; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1517 | eventTag = null; |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 1518 | } |
| 1519 | |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 1520 | public void setTo(HistoryItem o) { |
| 1521 | time = o.time; |
| 1522 | cmd = o.cmd; |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 1523 | setToCommon(o); |
| 1524 | } |
| 1525 | |
| 1526 | public void setTo(long time, byte cmd, HistoryItem o) { |
| 1527 | this.time = time; |
| 1528 | this.cmd = cmd; |
| 1529 | setToCommon(o); |
| 1530 | } |
| 1531 | |
| 1532 | private void setToCommon(HistoryItem o) { |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 1533 | batteryLevel = o.batteryLevel; |
| 1534 | batteryStatus = o.batteryStatus; |
| 1535 | batteryHealth = o.batteryHealth; |
| 1536 | batteryPlugType = o.batteryPlugType; |
| 1537 | batteryTemperature = o.batteryTemperature; |
| 1538 | batteryVoltage = o.batteryVoltage; |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 1539 | batteryChargeUAh = o.batteryChargeUAh; |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 1540 | states = o.states; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1541 | states2 = o.states2; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1542 | if (o.wakelockTag != null) { |
| 1543 | wakelockTag = localWakelockTag; |
| 1544 | wakelockTag.setTo(o.wakelockTag); |
| 1545 | } else { |
| 1546 | wakelockTag = null; |
| 1547 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1548 | if (o.wakeReasonTag != null) { |
| 1549 | wakeReasonTag = localWakeReasonTag; |
| 1550 | wakeReasonTag.setTo(o.wakeReasonTag); |
| 1551 | } else { |
| 1552 | wakeReasonTag = null; |
| 1553 | } |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1554 | eventCode = o.eventCode; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1555 | if (o.eventTag != null) { |
| 1556 | eventTag = localEventTag; |
| 1557 | eventTag.setTo(o.eventTag); |
| 1558 | } else { |
| 1559 | eventTag = null; |
| 1560 | } |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1561 | currentTime = o.currentTime; |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 1562 | } |
| 1563 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1564 | public boolean sameNonEvent(HistoryItem o) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 1565 | return batteryLevel == o.batteryLevel |
| 1566 | && batteryStatus == o.batteryStatus |
| 1567 | && batteryHealth == o.batteryHealth |
| 1568 | && batteryPlugType == o.batteryPlugType |
| 1569 | && batteryTemperature == o.batteryTemperature |
| 1570 | && batteryVoltage == o.batteryVoltage |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 1571 | && batteryChargeUAh == o.batteryChargeUAh |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1572 | && states == o.states |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1573 | && states2 == o.states2 |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1574 | && currentTime == o.currentTime; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 1575 | } |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1576 | |
| 1577 | public boolean same(HistoryItem o) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1578 | if (!sameNonEvent(o) || eventCode != o.eventCode) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1579 | return false; |
| 1580 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1581 | if (wakelockTag != o.wakelockTag) { |
| 1582 | if (wakelockTag == null || o.wakelockTag == null) { |
| 1583 | return false; |
| 1584 | } |
| 1585 | if (!wakelockTag.equals(o.wakelockTag)) { |
| 1586 | return false; |
| 1587 | } |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1588 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1589 | if (wakeReasonTag != o.wakeReasonTag) { |
| 1590 | if (wakeReasonTag == null || o.wakeReasonTag == null) { |
| 1591 | return false; |
| 1592 | } |
| 1593 | if (!wakeReasonTag.equals(o.wakeReasonTag)) { |
| 1594 | return false; |
| 1595 | } |
| 1596 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1597 | if (eventTag != o.eventTag) { |
| 1598 | if (eventTag == null || o.eventTag == null) { |
| 1599 | return false; |
| 1600 | } |
| 1601 | if (!eventTag.equals(o.eventTag)) { |
| 1602 | return false; |
| 1603 | } |
| 1604 | } |
| 1605 | return true; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1606 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1607 | } |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 1608 | |
| 1609 | public final static class HistoryEventTracker { |
| 1610 | private final HashMap<String, SparseIntArray>[] mActiveEvents |
| 1611 | = (HashMap<String, SparseIntArray>[]) new HashMap[HistoryItem.EVENT_COUNT]; |
| 1612 | |
| 1613 | public boolean updateState(int code, String name, int uid, int poolIdx) { |
| 1614 | if ((code&HistoryItem.EVENT_FLAG_START) != 0) { |
| 1615 | int idx = code&HistoryItem.EVENT_TYPE_MASK; |
| 1616 | HashMap<String, SparseIntArray> active = mActiveEvents[idx]; |
| 1617 | if (active == null) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 1618 | active = new HashMap<>(); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 1619 | mActiveEvents[idx] = active; |
| 1620 | } |
| 1621 | SparseIntArray uids = active.get(name); |
| 1622 | if (uids == null) { |
| 1623 | uids = new SparseIntArray(); |
| 1624 | active.put(name, uids); |
| 1625 | } |
| 1626 | if (uids.indexOfKey(uid) >= 0) { |
| 1627 | // Already set, nothing to do! |
| 1628 | return false; |
| 1629 | } |
| 1630 | uids.put(uid, poolIdx); |
| 1631 | } else if ((code&HistoryItem.EVENT_FLAG_FINISH) != 0) { |
| 1632 | int idx = code&HistoryItem.EVENT_TYPE_MASK; |
| 1633 | HashMap<String, SparseIntArray> active = mActiveEvents[idx]; |
| 1634 | if (active == null) { |
| 1635 | // not currently active, nothing to do. |
| 1636 | return false; |
| 1637 | } |
| 1638 | SparseIntArray uids = active.get(name); |
| 1639 | if (uids == null) { |
| 1640 | // not currently active, nothing to do. |
| 1641 | return false; |
| 1642 | } |
| 1643 | idx = uids.indexOfKey(uid); |
| 1644 | if (idx < 0) { |
| 1645 | // not currently active, nothing to do. |
| 1646 | return false; |
| 1647 | } |
| 1648 | uids.removeAt(idx); |
| 1649 | if (uids.size() <= 0) { |
| 1650 | active.remove(name); |
| 1651 | } |
| 1652 | } |
| 1653 | return true; |
| 1654 | } |
| 1655 | |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 1656 | public void removeEvents(int code) { |
| 1657 | int idx = code&HistoryItem.EVENT_TYPE_MASK; |
| 1658 | mActiveEvents[idx] = null; |
| 1659 | } |
| 1660 | |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 1661 | public HashMap<String, SparseIntArray> getStateForEvent(int code) { |
| 1662 | return mActiveEvents[code]; |
| 1663 | } |
| 1664 | } |
| 1665 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1666 | public static final class BitDescription { |
| 1667 | public final int mask; |
| 1668 | public final int shift; |
| 1669 | public final String name; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1670 | public final String shortName; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1671 | public final String[] values; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1672 | public final String[] shortValues; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1673 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1674 | public BitDescription(int mask, String name, String shortName) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1675 | this.mask = mask; |
| 1676 | this.shift = -1; |
| 1677 | this.name = name; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1678 | this.shortName = shortName; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1679 | this.values = null; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1680 | this.shortValues = null; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1681 | } |
| 1682 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1683 | public BitDescription(int mask, int shift, String name, String shortName, |
| 1684 | String[] values, String[] shortValues) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1685 | this.mask = mask; |
| 1686 | this.shift = shift; |
| 1687 | this.name = name; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1688 | this.shortName = shortName; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1689 | this.values = values; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1690 | this.shortValues = shortValues; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1691 | } |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1692 | } |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 1693 | |
Dianne Hackborn | fc06413 | 2014-06-02 12:42:12 -0700 | [diff] [blame] | 1694 | /** |
| 1695 | * Don't allow any more batching in to the current history event. This |
| 1696 | * is called when printing partial histories, so to ensure that the next |
| 1697 | * history event will go in to a new batch after what was printed in the |
| 1698 | * last partial history. |
| 1699 | */ |
| 1700 | public abstract void commitCurrentHistoryBatchLocked(); |
| 1701 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1702 | public abstract int getHistoryTotalSize(); |
| 1703 | |
| 1704 | public abstract int getHistoryUsedSize(); |
| 1705 | |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 1706 | public abstract boolean startIteratingHistoryLocked(); |
| 1707 | |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 1708 | public abstract int getHistoryStringPoolSize(); |
| 1709 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1710 | public abstract int getHistoryStringPoolBytes(); |
| 1711 | |
| 1712 | public abstract String getHistoryTagPoolString(int index); |
| 1713 | |
| 1714 | public abstract int getHistoryTagPoolUid(int index); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 1715 | |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 1716 | public abstract boolean getNextHistoryLocked(HistoryItem out); |
| 1717 | |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 1718 | public abstract void finishIteratingHistoryLocked(); |
| 1719 | |
| 1720 | public abstract boolean startIteratingOldHistoryLocked(); |
| 1721 | |
| 1722 | public abstract boolean getNextOldHistoryLocked(HistoryItem out); |
| 1723 | |
| 1724 | public abstract void finishIteratingOldHistoryLocked(); |
| 1725 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1726 | /** |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 1727 | * Return the base time offset for the battery history. |
| 1728 | */ |
| 1729 | public abstract long getHistoryBaseTime(); |
| 1730 | |
| 1731 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1732 | * Returns the number of times the device has been started. |
| 1733 | */ |
| 1734 | public abstract int getStartCount(); |
| 1735 | |
| 1736 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 1737 | * 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] | 1738 | * running on battery. |
| 1739 | * |
| 1740 | * {@hide} |
| 1741 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1742 | public abstract long getScreenOnTime(long elapsedRealtimeUs, int which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1743 | |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 1744 | /** |
| 1745 | * Returns the number of times the screen was turned on. |
| 1746 | * |
| 1747 | * {@hide} |
| 1748 | */ |
| 1749 | public abstract int getScreenOnCount(int which); |
| 1750 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 1751 | public abstract long getInteractiveTime(long elapsedRealtimeUs, int which); |
| 1752 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1753 | public static final int SCREEN_BRIGHTNESS_DARK = 0; |
| 1754 | public static final int SCREEN_BRIGHTNESS_DIM = 1; |
| 1755 | public static final int SCREEN_BRIGHTNESS_MEDIUM = 2; |
| 1756 | public static final int SCREEN_BRIGHTNESS_LIGHT = 3; |
| 1757 | public static final int SCREEN_BRIGHTNESS_BRIGHT = 4; |
| 1758 | |
| 1759 | static final String[] SCREEN_BRIGHTNESS_NAMES = { |
| 1760 | "dark", "dim", "medium", "light", "bright" |
| 1761 | }; |
| 1762 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1763 | static final String[] SCREEN_BRIGHTNESS_SHORT_NAMES = { |
| 1764 | "0", "1", "2", "3", "4" |
| 1765 | }; |
| 1766 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1767 | public static final int NUM_SCREEN_BRIGHTNESS_BINS = 5; |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 1768 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1769 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 1770 | * Returns the time in microseconds that the screen has been on with |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1771 | * the given brightness |
| 1772 | * |
| 1773 | * {@hide} |
| 1774 | */ |
| 1775 | public abstract long getScreenBrightnessTime(int brightnessBin, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1776 | long elapsedRealtimeUs, int which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1777 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1778 | /** |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 1779 | * 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] | 1780 | * running on battery. |
| 1781 | * |
| 1782 | * {@hide} |
| 1783 | */ |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 1784 | public abstract long getPowerSaveModeEnabledTime(long elapsedRealtimeUs, int which); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 1785 | |
| 1786 | /** |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 1787 | * Returns the number of times that power save mode was enabled. |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 1788 | * |
| 1789 | * {@hide} |
| 1790 | */ |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 1791 | public abstract int getPowerSaveModeEnabledCount(int which); |
| 1792 | |
| 1793 | /** |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 1794 | * Constant for device idle mode: not active. |
| 1795 | */ |
| 1796 | public static final int DEVICE_IDLE_MODE_OFF = 0; |
| 1797 | |
| 1798 | /** |
| 1799 | * Constant for device idle mode: active in lightweight mode. |
| 1800 | */ |
| 1801 | public static final int DEVICE_IDLE_MODE_LIGHT = 1; |
| 1802 | |
| 1803 | /** |
| 1804 | * Constant for device idle mode: active in full mode. |
| 1805 | */ |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 1806 | public static final int DEVICE_IDLE_MODE_DEEP = 2; |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 1807 | |
| 1808 | /** |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 1809 | * Returns the time in microseconds that device has been in idle mode while |
| 1810 | * running on battery. |
| 1811 | * |
| 1812 | * {@hide} |
| 1813 | */ |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 1814 | public abstract long getDeviceIdleModeTime(int mode, long elapsedRealtimeUs, int which); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 1815 | |
| 1816 | /** |
| 1817 | * Returns the number of times that the devie has gone in to idle mode. |
| 1818 | * |
| 1819 | * {@hide} |
| 1820 | */ |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 1821 | public abstract int getDeviceIdleModeCount(int mode, int which); |
| 1822 | |
| 1823 | /** |
| 1824 | * Return the longest duration we spent in a particular device idle mode (fully in the |
| 1825 | * mode, not in idle maintenance etc). |
| 1826 | */ |
| 1827 | public abstract long getLongestDeviceIdleModeTime(int mode); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 1828 | |
| 1829 | /** |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 1830 | * 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] | 1831 | * battery. This is broader than {@link #getDeviceIdleModeTime} -- it |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 1832 | * counts all of the time that we consider the device to be idle, whether or not |
| 1833 | * it is currently in the actual device idle mode. |
| 1834 | * |
| 1835 | * {@hide} |
| 1836 | */ |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 1837 | public abstract long getDeviceIdlingTime(int mode, long elapsedRealtimeUs, int which); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 1838 | |
| 1839 | /** |
| 1840 | * Returns the number of times that the devie has started idling. |
| 1841 | * |
| 1842 | * {@hide} |
| 1843 | */ |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 1844 | public abstract int getDeviceIdlingCount(int mode, int which); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 1845 | |
| 1846 | /** |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 1847 | * Returns the number of times that connectivity state changed. |
| 1848 | * |
| 1849 | * {@hide} |
| 1850 | */ |
| 1851 | public abstract int getNumConnectivityChange(int which); |
| 1852 | |
| 1853 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 1854 | * 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] | 1855 | * running on battery. |
| 1856 | * |
| 1857 | * {@hide} |
| 1858 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1859 | public abstract long getPhoneOnTime(long elapsedRealtimeUs, int which); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 1860 | |
| 1861 | /** |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 1862 | * Returns the number of times a phone call was activated. |
| 1863 | * |
| 1864 | * {@hide} |
| 1865 | */ |
| 1866 | public abstract int getPhoneOnCount(int which); |
| 1867 | |
| 1868 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 1869 | * Returns the time in microseconds that the phone has been running with |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 1870 | * the given signal strength. |
| 1871 | * |
| 1872 | * {@hide} |
| 1873 | */ |
| 1874 | public abstract long getPhoneSignalStrengthTime(int strengthBin, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1875 | long elapsedRealtimeUs, int which); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 1876 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1877 | /** |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 1878 | * Returns the time in microseconds that the phone has been trying to |
| 1879 | * acquire a signal. |
| 1880 | * |
| 1881 | * {@hide} |
| 1882 | */ |
| 1883 | public abstract long getPhoneSignalScanningTime( |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1884 | long elapsedRealtimeUs, int which); |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 1885 | |
| 1886 | /** |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1887 | * Returns the number of times the phone has entered the given signal strength. |
| 1888 | * |
| 1889 | * {@hide} |
| 1890 | */ |
| 1891 | public abstract int getPhoneSignalStrengthCount(int strengthBin, int which); |
| 1892 | |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 1893 | /** |
| 1894 | * Returns the time in microseconds that the mobile network has been active |
| 1895 | * (in a high power state). |
| 1896 | * |
| 1897 | * {@hide} |
| 1898 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1899 | public abstract long getMobileRadioActiveTime(long elapsedRealtimeUs, int which); |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 1900 | |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 1901 | /** |
| 1902 | * Returns the number of times that the mobile network has transitioned to the |
| 1903 | * active state. |
| 1904 | * |
| 1905 | * {@hide} |
| 1906 | */ |
| 1907 | public abstract int getMobileRadioActiveCount(int which); |
| 1908 | |
| 1909 | /** |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1910 | * Returns the time in microseconds that is the difference between the mobile radio |
| 1911 | * time we saw based on the elapsed timestamp when going down vs. the given time stamp |
| 1912 | * from the radio. |
| 1913 | * |
| 1914 | * {@hide} |
| 1915 | */ |
| 1916 | public abstract long getMobileRadioActiveAdjustedTime(int which); |
| 1917 | |
| 1918 | /** |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 1919 | * Returns the time in microseconds that the mobile network has been active |
| 1920 | * (in a high power state) but not being able to blame on an app. |
| 1921 | * |
| 1922 | * {@hide} |
| 1923 | */ |
| 1924 | public abstract long getMobileRadioActiveUnknownTime(int which); |
| 1925 | |
| 1926 | /** |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 1927 | * 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] | 1928 | * |
| 1929 | * {@hide} |
| 1930 | */ |
| 1931 | public abstract int getMobileRadioActiveUnknownCount(int which); |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 1932 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 1933 | public static final int DATA_CONNECTION_NONE = 0; |
| 1934 | public static final int DATA_CONNECTION_GPRS = 1; |
| 1935 | public static final int DATA_CONNECTION_EDGE = 2; |
| 1936 | public static final int DATA_CONNECTION_UMTS = 3; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1937 | public static final int DATA_CONNECTION_CDMA = 4; |
| 1938 | public static final int DATA_CONNECTION_EVDO_0 = 5; |
| 1939 | public static final int DATA_CONNECTION_EVDO_A = 6; |
| 1940 | public static final int DATA_CONNECTION_1xRTT = 7; |
| 1941 | public static final int DATA_CONNECTION_HSDPA = 8; |
| 1942 | public static final int DATA_CONNECTION_HSUPA = 9; |
| 1943 | public static final int DATA_CONNECTION_HSPA = 10; |
| 1944 | public static final int DATA_CONNECTION_IDEN = 11; |
| 1945 | public static final int DATA_CONNECTION_EVDO_B = 12; |
Robert Greenwalt | 962a990 | 2010-11-02 11:10:25 -0700 | [diff] [blame] | 1946 | public static final int DATA_CONNECTION_LTE = 13; |
| 1947 | public static final int DATA_CONNECTION_EHRPD = 14; |
Patrick Tjin | b71703c | 2013-11-06 09:27:03 -0800 | [diff] [blame] | 1948 | public static final int DATA_CONNECTION_HSPAP = 15; |
| 1949 | public static final int DATA_CONNECTION_OTHER = 16; |
Robert Greenwalt | 962a990 | 2010-11-02 11:10:25 -0700 | [diff] [blame] | 1950 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 1951 | static final String[] DATA_CONNECTION_NAMES = { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1952 | "none", "gprs", "edge", "umts", "cdma", "evdo_0", "evdo_A", |
Robert Greenwalt | 962a990 | 2010-11-02 11:10:25 -0700 | [diff] [blame] | 1953 | "1xrtt", "hsdpa", "hsupa", "hspa", "iden", "evdo_b", "lte", |
Patrick Tjin | b71703c | 2013-11-06 09:27:03 -0800 | [diff] [blame] | 1954 | "ehrpd", "hspap", "other" |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 1955 | }; |
| 1956 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1957 | public static final int NUM_DATA_CONNECTION_TYPES = DATA_CONNECTION_OTHER+1; |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 1958 | |
| 1959 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 1960 | * Returns the time in microseconds that the phone has been running with |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 1961 | * the given data connection. |
| 1962 | * |
| 1963 | * {@hide} |
| 1964 | */ |
| 1965 | public abstract long getPhoneDataConnectionTime(int dataType, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1966 | long elapsedRealtimeUs, int which); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 1967 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1968 | /** |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1969 | * Returns the number of times the phone has entered the given data |
| 1970 | * connection type. |
| 1971 | * |
| 1972 | * {@hide} |
| 1973 | */ |
| 1974 | public abstract int getPhoneDataConnectionCount(int dataType, int which); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1975 | |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 1976 | public static final int WIFI_SUPPL_STATE_INVALID = 0; |
| 1977 | public static final int WIFI_SUPPL_STATE_DISCONNECTED = 1; |
| 1978 | public static final int WIFI_SUPPL_STATE_INTERFACE_DISABLED = 2; |
| 1979 | public static final int WIFI_SUPPL_STATE_INACTIVE = 3; |
| 1980 | public static final int WIFI_SUPPL_STATE_SCANNING = 4; |
| 1981 | public static final int WIFI_SUPPL_STATE_AUTHENTICATING = 5; |
| 1982 | public static final int WIFI_SUPPL_STATE_ASSOCIATING = 6; |
| 1983 | public static final int WIFI_SUPPL_STATE_ASSOCIATED = 7; |
| 1984 | public static final int WIFI_SUPPL_STATE_FOUR_WAY_HANDSHAKE = 8; |
| 1985 | public static final int WIFI_SUPPL_STATE_GROUP_HANDSHAKE = 9; |
| 1986 | public static final int WIFI_SUPPL_STATE_COMPLETED = 10; |
| 1987 | public static final int WIFI_SUPPL_STATE_DORMANT = 11; |
| 1988 | public static final int WIFI_SUPPL_STATE_UNINITIALIZED = 12; |
| 1989 | |
| 1990 | public static final int NUM_WIFI_SUPPL_STATES = WIFI_SUPPL_STATE_UNINITIALIZED+1; |
| 1991 | |
| 1992 | static final String[] WIFI_SUPPL_STATE_NAMES = { |
| 1993 | "invalid", "disconn", "disabled", "inactive", "scanning", |
| 1994 | "authenticating", "associating", "associated", "4-way-handshake", |
| 1995 | "group-handshake", "completed", "dormant", "uninit" |
| 1996 | }; |
| 1997 | |
| 1998 | static final String[] WIFI_SUPPL_STATE_SHORT_NAMES = { |
| 1999 | "inv", "dsc", "dis", "inact", "scan", |
| 2000 | "auth", "ascing", "asced", "4-way", |
| 2001 | "group", "compl", "dorm", "uninit" |
| 2002 | }; |
| 2003 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2004 | public static final BitDescription[] HISTORY_STATE_DESCRIPTIONS |
| 2005 | = new BitDescription[] { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2006 | new BitDescription(HistoryItem.STATE_CPU_RUNNING_FLAG, "running", "r"), |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2007 | new BitDescription(HistoryItem.STATE_WAKE_LOCK_FLAG, "wake_lock", "w"), |
| 2008 | new BitDescription(HistoryItem.STATE_SENSOR_ON_FLAG, "sensor", "s"), |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2009 | new BitDescription(HistoryItem.STATE_GPS_ON_FLAG, "gps", "g"), |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2010 | new BitDescription(HistoryItem.STATE_WIFI_FULL_LOCK_FLAG, "wifi_full_lock", "Wl"), |
| 2011 | new BitDescription(HistoryItem.STATE_WIFI_SCAN_FLAG, "wifi_scan", "Ws"), |
| 2012 | new BitDescription(HistoryItem.STATE_WIFI_MULTICAST_ON_FLAG, "wifi_multicast", "Wm"), |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 2013 | new BitDescription(HistoryItem.STATE_WIFI_RADIO_ACTIVE_FLAG, "wifi_radio", "Wr"), |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 2014 | new BitDescription(HistoryItem.STATE_MOBILE_RADIO_ACTIVE_FLAG, "mobile_radio", "Pr"), |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2015 | new BitDescription(HistoryItem.STATE_PHONE_SCANNING_FLAG, "phone_scanning", "Psc"), |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2016 | new BitDescription(HistoryItem.STATE_AUDIO_ON_FLAG, "audio", "a"), |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2017 | new BitDescription(HistoryItem.STATE_SCREEN_ON_FLAG, "screen", "S"), |
| 2018 | new BitDescription(HistoryItem.STATE_BATTERY_PLUGGED_FLAG, "plugged", "BP"), |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2019 | new BitDescription(HistoryItem.STATE_DATA_CONNECTION_MASK, |
| 2020 | HistoryItem.STATE_DATA_CONNECTION_SHIFT, "data_conn", "Pcn", |
| 2021 | DATA_CONNECTION_NAMES, DATA_CONNECTION_NAMES), |
| 2022 | new BitDescription(HistoryItem.STATE_PHONE_STATE_MASK, |
| 2023 | HistoryItem.STATE_PHONE_STATE_SHIFT, "phone_state", "Pst", |
| 2024 | new String[] {"in", "out", "emergency", "off"}, |
| 2025 | new String[] {"in", "out", "em", "off"}), |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 2026 | new BitDescription(HistoryItem.STATE_PHONE_SIGNAL_STRENGTH_MASK, |
| 2027 | HistoryItem.STATE_PHONE_SIGNAL_STRENGTH_SHIFT, "phone_signal_strength", "Pss", |
| 2028 | SignalStrength.SIGNAL_STRENGTH_NAMES, |
| 2029 | new String[] { "0", "1", "2", "3", "4" }), |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2030 | new BitDescription(HistoryItem.STATE_BRIGHTNESS_MASK, |
| 2031 | HistoryItem.STATE_BRIGHTNESS_SHIFT, "brightness", "Sb", |
| 2032 | SCREEN_BRIGHTNESS_NAMES, SCREEN_BRIGHTNESS_SHORT_NAMES), |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2033 | }; |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2034 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2035 | public static final BitDescription[] HISTORY_STATE2_DESCRIPTIONS |
| 2036 | = new BitDescription[] { |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 2037 | new BitDescription(HistoryItem.STATE2_POWER_SAVE_FLAG, "power_save", "ps"), |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 2038 | new BitDescription(HistoryItem.STATE2_VIDEO_ON_FLAG, "video", "v"), |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 2039 | new BitDescription(HistoryItem.STATE2_WIFI_RUNNING_FLAG, "wifi_running", "Ww"), |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 2040 | new BitDescription(HistoryItem.STATE2_WIFI_ON_FLAG, "wifi", "W"), |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 2041 | new BitDescription(HistoryItem.STATE2_FLASHLIGHT_FLAG, "flashlight", "fl"), |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 2042 | new BitDescription(HistoryItem.STATE2_DEVICE_IDLE_MASK, |
| 2043 | HistoryItem.STATE2_DEVICE_IDLE_SHIFT, "device_idle", "di", |
| 2044 | new String[] { "off", "light", "full", "???" }, |
| 2045 | new String[] { "off", "light", "full", "???" }), |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 2046 | new BitDescription(HistoryItem.STATE2_CHARGING_FLAG, "charging", "ch"), |
| 2047 | new BitDescription(HistoryItem.STATE2_PHONE_IN_CALL_FLAG, "phone_in_call", "Pcl"), |
| 2048 | new BitDescription(HistoryItem.STATE2_BLUETOOTH_ON_FLAG, "bluetooth", "b"), |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 2049 | new BitDescription(HistoryItem.STATE2_WIFI_SIGNAL_STRENGTH_MASK, |
| 2050 | HistoryItem.STATE2_WIFI_SIGNAL_STRENGTH_SHIFT, "wifi_signal_strength", "Wss", |
| 2051 | new String[] { "0", "1", "2", "3", "4" }, |
| 2052 | new String[] { "0", "1", "2", "3", "4" }), |
| 2053 | new BitDescription(HistoryItem.STATE2_WIFI_SUPPL_STATE_MASK, |
| 2054 | HistoryItem.STATE2_WIFI_SUPPL_STATE_SHIFT, "wifi_suppl", "Wsp", |
| 2055 | WIFI_SUPPL_STATE_NAMES, WIFI_SUPPL_STATE_SHORT_NAMES), |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 2056 | new BitDescription(HistoryItem.STATE2_CAMERA_FLAG, "camera", "ca"), |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 2057 | new BitDescription(HistoryItem.STATE2_BLUETOOTH_SCAN_FLAG, "ble_scan", "bles"), |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2058 | }; |
| 2059 | |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 2060 | public static final String[] HISTORY_EVENT_NAMES = new String[] { |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 2061 | "null", "proc", "fg", "top", "sync", "wake_lock_in", "job", "user", "userfg", "conn", |
Kweku Adams | 134c59b | 2017-03-08 16:48:01 -0800 | [diff] [blame] | 2062 | "active", "pkginst", "pkgunin", "alarm", "stats", "pkginactive", "pkgactive", |
| 2063 | "tmpwhitelist", "screenwake", "wakeupap", "longwake", "est_capacity" |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 2064 | }; |
| 2065 | |
| 2066 | public static final String[] HISTORY_EVENT_CHECKIN_NAMES = new String[] { |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 2067 | "Enl", "Epr", "Efg", "Etp", "Esy", "Ewl", "Ejb", "Eur", "Euf", "Ecn", |
Dianne Hackborn | 280a64e | 2015-07-13 14:48:08 -0700 | [diff] [blame] | 2068 | "Eac", "Epi", "Epu", "Eal", "Est", "Eai", "Eaa", "Etw", |
Adam Lesinski | 041d917 | 2016-12-12 12:03:56 -0800 | [diff] [blame] | 2069 | "Esw", "Ewa", "Elw", "Eec" |
| 2070 | }; |
| 2071 | |
| 2072 | @FunctionalInterface |
| 2073 | public interface IntToString { |
| 2074 | String applyAsString(int val); |
| 2075 | } |
| 2076 | |
| 2077 | private static final IntToString sUidToString = UserHandle::formatUid; |
| 2078 | private static final IntToString sIntToString = Integer::toString; |
| 2079 | |
| 2080 | public static final IntToString[] HISTORY_EVENT_INT_FORMATTERS = new IntToString[] { |
| 2081 | sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, |
| 2082 | sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, |
| 2083 | sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, |
| 2084 | sUidToString, sUidToString, sUidToString, sIntToString |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 2085 | }; |
| 2086 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2087 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 2088 | * 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] | 2089 | * running on battery. |
| 2090 | * |
| 2091 | * {@hide} |
| 2092 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2093 | public abstract long getWifiOnTime(long elapsedRealtimeUs, int which); |
Eric Shienbrood | d4c5f89 | 2009-03-24 18:13:20 -0700 | [diff] [blame] | 2094 | |
| 2095 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 2096 | * 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] | 2097 | * been in the running state while the device was running on battery. |
| 2098 | * |
| 2099 | * {@hide} |
| 2100 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2101 | public abstract long getGlobalWifiRunningTime(long elapsedRealtimeUs, int which); |
Eric Shienbrood | d4c5f89 | 2009-03-24 18:13:20 -0700 | [diff] [blame] | 2102 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 2103 | public static final int WIFI_STATE_OFF = 0; |
| 2104 | public static final int WIFI_STATE_OFF_SCANNING = 1; |
| 2105 | public static final int WIFI_STATE_ON_NO_NETWORKS = 2; |
| 2106 | public static final int WIFI_STATE_ON_DISCONNECTED = 3; |
| 2107 | public static final int WIFI_STATE_ON_CONNECTED_STA = 4; |
| 2108 | public static final int WIFI_STATE_ON_CONNECTED_P2P = 5; |
| 2109 | public static final int WIFI_STATE_ON_CONNECTED_STA_P2P = 6; |
| 2110 | public static final int WIFI_STATE_SOFT_AP = 7; |
| 2111 | |
| 2112 | static final String[] WIFI_STATE_NAMES = { |
| 2113 | "off", "scanning", "no_net", "disconn", |
| 2114 | "sta", "p2p", "sta_p2p", "soft_ap" |
| 2115 | }; |
| 2116 | |
| 2117 | public static final int NUM_WIFI_STATES = WIFI_STATE_SOFT_AP+1; |
| 2118 | |
| 2119 | /** |
| 2120 | * Returns the time in microseconds that WiFi has been running in the given state. |
| 2121 | * |
| 2122 | * {@hide} |
| 2123 | */ |
| 2124 | public abstract long getWifiStateTime(int wifiState, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2125 | long elapsedRealtimeUs, int which); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 2126 | |
| 2127 | /** |
| 2128 | * Returns the number of times that WiFi has entered the given state. |
| 2129 | * |
| 2130 | * {@hide} |
| 2131 | */ |
| 2132 | public abstract int getWifiStateCount(int wifiState, int which); |
| 2133 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2134 | /** |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 2135 | * Returns the time in microseconds that the wifi supplicant has been |
| 2136 | * in a given state. |
| 2137 | * |
| 2138 | * {@hide} |
| 2139 | */ |
| 2140 | public abstract long getWifiSupplStateTime(int state, long elapsedRealtimeUs, int which); |
| 2141 | |
| 2142 | /** |
| 2143 | * Returns the number of times that the wifi supplicant has transitioned |
| 2144 | * to a given state. |
| 2145 | * |
| 2146 | * {@hide} |
| 2147 | */ |
| 2148 | public abstract int getWifiSupplStateCount(int state, int which); |
| 2149 | |
| 2150 | public static final int NUM_WIFI_SIGNAL_STRENGTH_BINS = 5; |
| 2151 | |
| 2152 | /** |
| 2153 | * Returns the time in microseconds that WIFI has been running with |
| 2154 | * the given signal strength. |
| 2155 | * |
| 2156 | * {@hide} |
| 2157 | */ |
| 2158 | public abstract long getWifiSignalStrengthTime(int strengthBin, |
| 2159 | long elapsedRealtimeUs, int which); |
| 2160 | |
| 2161 | /** |
| 2162 | * Returns the number of times WIFI has entered the given signal strength. |
| 2163 | * |
| 2164 | * {@hide} |
| 2165 | */ |
| 2166 | public abstract int getWifiSignalStrengthCount(int strengthBin, int which); |
| 2167 | |
| 2168 | /** |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 2169 | * Returns the time in microseconds that the flashlight has been on while the device was |
| 2170 | * running on battery. |
| 2171 | * |
| 2172 | * {@hide} |
| 2173 | */ |
| 2174 | public abstract long getFlashlightOnTime(long elapsedRealtimeUs, int which); |
| 2175 | |
| 2176 | /** |
| 2177 | * Returns the number of times that the flashlight has been turned on while the device was |
| 2178 | * running on battery. |
| 2179 | * |
| 2180 | * {@hide} |
| 2181 | */ |
| 2182 | public abstract long getFlashlightOnCount(int which); |
| 2183 | |
Ruben Brunk | 5b1308f | 2015-06-03 18:49:27 -0700 | [diff] [blame] | 2184 | /** |
| 2185 | * Returns the time in microseconds that the camera has been on while the device was |
| 2186 | * running on battery. |
| 2187 | * |
| 2188 | * {@hide} |
| 2189 | */ |
| 2190 | public abstract long getCameraOnTime(long elapsedRealtimeUs, int which); |
| 2191 | |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 2192 | /** |
| 2193 | * Returns the time in microseconds that bluetooth scans were running while the device was |
| 2194 | * on battery. |
| 2195 | * |
| 2196 | * {@hide} |
| 2197 | */ |
| 2198 | public abstract long getBluetoothScanTime(long elapsedRealtimeUs, int which); |
Ruben Brunk | 5b1308f | 2015-06-03 18:49:27 -0700 | [diff] [blame] | 2199 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2200 | public static final int NETWORK_MOBILE_RX_DATA = 0; |
| 2201 | public static final int NETWORK_MOBILE_TX_DATA = 1; |
| 2202 | public static final int NETWORK_WIFI_RX_DATA = 2; |
| 2203 | public static final int NETWORK_WIFI_TX_DATA = 3; |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 2204 | public static final int NETWORK_BT_RX_DATA = 4; |
| 2205 | public static final int NETWORK_BT_TX_DATA = 5; |
Amith Yamasani | 59fe841 | 2017-03-03 16:28:52 -0800 | [diff] [blame] | 2206 | public static final int NETWORK_MOBILE_BG_RX_DATA = 6; |
| 2207 | public static final int NETWORK_MOBILE_BG_TX_DATA = 7; |
| 2208 | public static final int NETWORK_WIFI_BG_RX_DATA = 8; |
| 2209 | public static final int NETWORK_WIFI_BG_TX_DATA = 9; |
| 2210 | 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] | 2211 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2212 | public abstract long getNetworkActivityBytes(int type, int which); |
| 2213 | public abstract long getNetworkActivityPackets(int type, int which); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 2214 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 2215 | /** |
Adam Lesinski | 1739076 | 2015-04-10 13:17:47 -0700 | [diff] [blame] | 2216 | * Returns true if the BatteryStats object has detailed WiFi power reports. |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 2217 | * When true, calling {@link #getWifiControllerActivity()} will yield the |
Adam Lesinski | 1739076 | 2015-04-10 13:17:47 -0700 | [diff] [blame] | 2218 | * actual power data. |
| 2219 | */ |
| 2220 | public abstract boolean hasWifiActivityReporting(); |
| 2221 | |
| 2222 | /** |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 2223 | * Returns a {@link ControllerActivityCounter} which is an aggregate of the times spent |
| 2224 | * in various radio controller states, such as transmit, receive, and idle. |
| 2225 | * @return non-null {@link ControllerActivityCounter} |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 2226 | */ |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 2227 | public abstract ControllerActivityCounter getWifiControllerActivity(); |
| 2228 | |
| 2229 | /** |
| 2230 | * Returns true if the BatteryStats object has detailed bluetooth power reports. |
| 2231 | * When true, calling {@link #getBluetoothControllerActivity()} will yield the |
| 2232 | * actual power data. |
| 2233 | */ |
| 2234 | public abstract boolean hasBluetoothActivityReporting(); |
| 2235 | |
| 2236 | /** |
| 2237 | * Returns a {@link ControllerActivityCounter} which is an aggregate of the times spent |
| 2238 | * in various radio controller states, such as transmit, receive, and idle. |
| 2239 | * @return non-null {@link ControllerActivityCounter} |
| 2240 | */ |
| 2241 | public abstract ControllerActivityCounter getBluetoothControllerActivity(); |
| 2242 | |
| 2243 | /** |
| 2244 | * Returns true if the BatteryStats object has detailed modem power reports. |
| 2245 | * When true, calling {@link #getModemControllerActivity()} will yield the |
| 2246 | * actual power data. |
| 2247 | */ |
| 2248 | public abstract boolean hasModemActivityReporting(); |
| 2249 | |
| 2250 | /** |
| 2251 | * Returns a {@link ControllerActivityCounter} which is an aggregate of the times spent |
| 2252 | * in various radio controller states, such as transmit, receive, and idle. |
| 2253 | * @return non-null {@link ControllerActivityCounter} |
| 2254 | */ |
| 2255 | public abstract ControllerActivityCounter getModemControllerActivity(); |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 2256 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2257 | /** |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 2258 | * Return the wall clock time when battery stats data collection started. |
| 2259 | */ |
| 2260 | public abstract long getStartClockTime(); |
| 2261 | |
| 2262 | /** |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 2263 | * Return platform version tag that we were running in when the battery stats started. |
| 2264 | */ |
| 2265 | public abstract String getStartPlatformVersion(); |
| 2266 | |
| 2267 | /** |
| 2268 | * Return platform version tag that we were running in when the battery stats ended. |
| 2269 | */ |
| 2270 | public abstract String getEndPlatformVersion(); |
| 2271 | |
| 2272 | /** |
| 2273 | * Return the internal version code of the parcelled format. |
| 2274 | */ |
| 2275 | public abstract int getParcelVersion(); |
| 2276 | |
| 2277 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2278 | * Return whether we are currently running on battery. |
| 2279 | */ |
| 2280 | public abstract boolean getIsOnBattery(); |
| 2281 | |
| 2282 | /** |
| 2283 | * Returns a SparseArray containing the statistics for each uid. |
| 2284 | */ |
| 2285 | public abstract SparseArray<? extends Uid> getUidStats(); |
| 2286 | |
| 2287 | /** |
| 2288 | * Returns the current battery uptime in microseconds. |
| 2289 | * |
| 2290 | * @param curTime the amount of elapsed realtime in microseconds. |
| 2291 | */ |
| 2292 | public abstract long getBatteryUptime(long curTime); |
| 2293 | |
| 2294 | /** |
| 2295 | * Returns the current battery realtime in microseconds. |
| 2296 | * |
| 2297 | * @param curTime the amount of elapsed realtime in microseconds. |
| 2298 | */ |
| 2299 | public abstract long getBatteryRealtime(long curTime); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2300 | |
| 2301 | /** |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 2302 | * Returns the battery percentage level at the last time the device was unplugged from power, or |
| 2303 | * the last time it booted on battery power. |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2304 | */ |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 2305 | public abstract int getDischargeStartLevel(); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2306 | |
| 2307 | /** |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 2308 | * Returns the current battery percentage level if we are in a discharge cycle, otherwise |
| 2309 | * returns the level at the last plug event. |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2310 | */ |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 2311 | public abstract int getDischargeCurrentLevel(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2312 | |
| 2313 | /** |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 2314 | * Get the amount the battery has discharged since the stats were |
| 2315 | * last reset after charging, as a lower-end approximation. |
| 2316 | */ |
| 2317 | public abstract int getLowDischargeAmountSinceCharge(); |
| 2318 | |
| 2319 | /** |
| 2320 | * Get the amount the battery has discharged since the stats were |
| 2321 | * last reset after charging, as an upper-end approximation. |
| 2322 | */ |
| 2323 | public abstract int getHighDischargeAmountSinceCharge(); |
| 2324 | |
| 2325 | /** |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2326 | * Retrieve the discharge amount over the selected discharge period <var>which</var>. |
| 2327 | */ |
| 2328 | public abstract int getDischargeAmount(int which); |
| 2329 | |
| 2330 | /** |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 2331 | * Get the amount the battery has discharged while the screen was on, |
| 2332 | * since the last time power was unplugged. |
| 2333 | */ |
| 2334 | public abstract int getDischargeAmountScreenOn(); |
| 2335 | |
| 2336 | /** |
| 2337 | * Get the amount the battery has discharged while the screen was on, |
| 2338 | * since the last time the device was charged. |
| 2339 | */ |
| 2340 | public abstract int getDischargeAmountScreenOnSinceCharge(); |
| 2341 | |
| 2342 | /** |
| 2343 | * Get the amount the battery has discharged while the screen was off, |
| 2344 | * since the last time power was unplugged. |
| 2345 | */ |
| 2346 | public abstract int getDischargeAmountScreenOff(); |
| 2347 | |
| 2348 | /** |
| 2349 | * Get the amount the battery has discharged while the screen was off, |
| 2350 | * since the last time the device was charged. |
| 2351 | */ |
| 2352 | public abstract int getDischargeAmountScreenOffSinceCharge(); |
| 2353 | |
| 2354 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2355 | * Returns the total, last, or current battery uptime in microseconds. |
| 2356 | * |
| 2357 | * @param curTime the elapsed realtime in microseconds. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2358 | * @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] | 2359 | */ |
| 2360 | public abstract long computeBatteryUptime(long curTime, int which); |
| 2361 | |
| 2362 | /** |
| 2363 | * Returns the total, last, or current battery realtime in microseconds. |
| 2364 | * |
| 2365 | * @param curTime the current elapsed realtime in microseconds. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2366 | * @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] | 2367 | */ |
| 2368 | public abstract long computeBatteryRealtime(long curTime, int which); |
| 2369 | |
| 2370 | /** |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2371 | * Returns the total, last, or current battery screen off uptime in microseconds. |
| 2372 | * |
| 2373 | * @param curTime the elapsed realtime in microseconds. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2374 | * @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] | 2375 | */ |
| 2376 | public abstract long computeBatteryScreenOffUptime(long curTime, int which); |
| 2377 | |
| 2378 | /** |
| 2379 | * Returns the total, last, or current battery screen off realtime in microseconds. |
| 2380 | * |
| 2381 | * @param curTime the current elapsed realtime in microseconds. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2382 | * @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] | 2383 | */ |
| 2384 | public abstract long computeBatteryScreenOffRealtime(long curTime, int which); |
| 2385 | |
| 2386 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2387 | * Returns the total, last, or current uptime in microseconds. |
| 2388 | * |
| 2389 | * @param curTime the current elapsed realtime in microseconds. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2390 | * @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] | 2391 | */ |
| 2392 | public abstract long computeUptime(long curTime, int which); |
| 2393 | |
| 2394 | /** |
| 2395 | * Returns the total, last, or current realtime in microseconds. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2396 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2397 | * @param curTime the current elapsed realtime in microseconds. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2398 | * @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] | 2399 | */ |
| 2400 | public abstract long computeRealtime(long curTime, int which); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2401 | |
| 2402 | /** |
| 2403 | * Compute an approximation for how much run time (in microseconds) is remaining on |
| 2404 | * the battery. Returns -1 if no time can be computed: either there is not |
| 2405 | * enough current data to make a decision, or the battery is currently |
| 2406 | * charging. |
| 2407 | * |
| 2408 | * @param curTime The current elepsed realtime in microseconds. |
| 2409 | */ |
| 2410 | public abstract long computeBatteryTimeRemaining(long curTime); |
| 2411 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 2412 | // The part of a step duration that is the actual time. |
| 2413 | public static final long STEP_LEVEL_TIME_MASK = 0x000000ffffffffffL; |
| 2414 | |
| 2415 | // Bits in a step duration that are the new battery level we are at. |
| 2416 | public static final long STEP_LEVEL_LEVEL_MASK = 0x0000ff0000000000L; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2417 | public static final int STEP_LEVEL_LEVEL_SHIFT = 40; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 2418 | |
| 2419 | // Bits in a step duration that are the initial mode we were in at that step. |
| 2420 | public static final long STEP_LEVEL_INITIAL_MODE_MASK = 0x00ff000000000000L; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2421 | public static final int STEP_LEVEL_INITIAL_MODE_SHIFT = 48; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 2422 | |
| 2423 | // Bits in a step duration that indicate which modes changed during that step. |
| 2424 | public static final long STEP_LEVEL_MODIFIED_MODE_MASK = 0xff00000000000000L; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2425 | public static final int STEP_LEVEL_MODIFIED_MODE_SHIFT = 56; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 2426 | |
| 2427 | // Step duration mode: the screen is on, off, dozed, etc; value is Display.STATE_* - 1. |
| 2428 | public static final int STEP_LEVEL_MODE_SCREEN_STATE = 0x03; |
| 2429 | |
Santos Cordon | e94f050 | 2017-02-24 12:31:20 -0800 | [diff] [blame] | 2430 | // The largest value for screen state that is tracked in battery states. Any values above |
| 2431 | // this should be mapped back to one of the tracked values before being tracked here. |
| 2432 | public static final int MAX_TRACKED_SCREEN_STATE = Display.STATE_DOZE_SUSPEND; |
| 2433 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 2434 | // Step duration mode: power save is on. |
| 2435 | public static final int STEP_LEVEL_MODE_POWER_SAVE = 0x04; |
| 2436 | |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2437 | // Step duration mode: device is currently in idle mode. |
| 2438 | public static final int STEP_LEVEL_MODE_DEVICE_IDLE = 0x08; |
| 2439 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2440 | public static final int[] STEP_LEVEL_MODES_OF_INTEREST = new int[] { |
| 2441 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE, |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2442 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE|STEP_LEVEL_MODE_DEVICE_IDLE, |
| 2443 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_DEVICE_IDLE, |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2444 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE, |
| 2445 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE, |
| 2446 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE, |
| 2447 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE, |
| 2448 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE, |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2449 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE|STEP_LEVEL_MODE_DEVICE_IDLE, |
| 2450 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_DEVICE_IDLE, |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2451 | }; |
| 2452 | public static final int[] STEP_LEVEL_MODE_VALUES = new int[] { |
| 2453 | (Display.STATE_OFF-1), |
| 2454 | (Display.STATE_OFF-1)|STEP_LEVEL_MODE_POWER_SAVE, |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2455 | (Display.STATE_OFF-1)|STEP_LEVEL_MODE_DEVICE_IDLE, |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2456 | (Display.STATE_ON-1), |
| 2457 | (Display.STATE_ON-1)|STEP_LEVEL_MODE_POWER_SAVE, |
| 2458 | (Display.STATE_DOZE-1), |
| 2459 | (Display.STATE_DOZE-1)|STEP_LEVEL_MODE_POWER_SAVE, |
| 2460 | (Display.STATE_DOZE_SUSPEND-1), |
| 2461 | (Display.STATE_DOZE_SUSPEND-1)|STEP_LEVEL_MODE_POWER_SAVE, |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2462 | (Display.STATE_DOZE_SUSPEND-1)|STEP_LEVEL_MODE_DEVICE_IDLE, |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2463 | }; |
| 2464 | public static final String[] STEP_LEVEL_MODE_LABELS = new String[] { |
| 2465 | "screen off", |
| 2466 | "screen off power save", |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2467 | "screen off device idle", |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2468 | "screen on", |
| 2469 | "screen on power save", |
| 2470 | "screen doze", |
| 2471 | "screen doze power save", |
| 2472 | "screen doze-suspend", |
| 2473 | "screen doze-suspend power save", |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2474 | "screen doze-suspend device idle", |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2475 | }; |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 2476 | |
| 2477 | /** |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 2478 | * Return the counter keeping track of the amount of battery discharge while the screen was off, |
| 2479 | * measured in micro-Ampere-hours. This will be non-zero only if the device's battery has |
| 2480 | * a coulomb counter. |
| 2481 | */ |
| 2482 | public abstract LongCounter getDischargeScreenOffCoulombCounter(); |
| 2483 | |
| 2484 | /** |
| 2485 | * Return the counter keeping track of the amount of battery discharge measured in |
| 2486 | * micro-Ampere-hours. This will be non-zero only if the device's battery has |
| 2487 | * a coulomb counter. |
| 2488 | */ |
| 2489 | public abstract LongCounter getDischargeCoulombCounter(); |
| 2490 | |
| 2491 | /** |
Adam Lesinski | f9b20a9 | 2016-06-17 17:30:01 -0700 | [diff] [blame] | 2492 | * Returns the estimated real battery capacity, which may be less than the capacity |
| 2493 | * declared by the PowerProfile. |
| 2494 | * @return The estimated battery capacity in mAh. |
| 2495 | */ |
| 2496 | public abstract int getEstimatedBatteryCapacity(); |
| 2497 | |
| 2498 | /** |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2499 | * Return the array of discharge step durations. |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 2500 | */ |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2501 | public abstract LevelStepTracker getDischargeLevelStepTracker(); |
| 2502 | |
| 2503 | /** |
| 2504 | * Return the array of daily discharge step durations. |
| 2505 | */ |
| 2506 | public abstract LevelStepTracker getDailyDischargeLevelStepTracker(); |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 2507 | |
| 2508 | /** |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2509 | * Compute an approximation for how much time (in microseconds) remains until the battery |
| 2510 | * is fully charged. Returns -1 if no time can be computed: either there is not |
| 2511 | * enough current data to make a decision, or the battery is currently |
| 2512 | * discharging. |
| 2513 | * |
| 2514 | * @param curTime The current elepsed realtime in microseconds. |
| 2515 | */ |
| 2516 | public abstract long computeChargeTimeRemaining(long curTime); |
| 2517 | |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 2518 | /** |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2519 | * Return the array of charge step durations. |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 2520 | */ |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2521 | public abstract LevelStepTracker getChargeLevelStepTracker(); |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 2522 | |
| 2523 | /** |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2524 | * Return the array of daily charge step durations. |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 2525 | */ |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2526 | public abstract LevelStepTracker getDailyChargeLevelStepTracker(); |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 2527 | |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2528 | public abstract ArrayList<PackageChange> getDailyPackageChanges(); |
| 2529 | |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 2530 | public abstract Map<String, ? extends Timer> getWakeupReasonStats(); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2531 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2532 | public abstract Map<String, ? extends Timer> getKernelWakelockStats(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2533 | |
James Carr | 2dd7e5e | 2016-07-20 18:48:39 -0700 | [diff] [blame] | 2534 | public abstract LongSparseArray<? extends Timer> getKernelMemoryStats(); |
| 2535 | |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 2536 | public abstract void writeToParcelWithoutUids(Parcel out, int flags); |
| 2537 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 2538 | private final static void formatTimeRaw(StringBuilder out, long seconds) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2539 | long days = seconds / (60 * 60 * 24); |
| 2540 | if (days != 0) { |
| 2541 | out.append(days); |
| 2542 | out.append("d "); |
| 2543 | } |
| 2544 | long used = days * 60 * 60 * 24; |
| 2545 | |
| 2546 | long hours = (seconds - used) / (60 * 60); |
| 2547 | if (hours != 0 || used != 0) { |
| 2548 | out.append(hours); |
| 2549 | out.append("h "); |
| 2550 | } |
| 2551 | used += hours * 60 * 60; |
| 2552 | |
| 2553 | long mins = (seconds-used) / 60; |
| 2554 | if (mins != 0 || used != 0) { |
| 2555 | out.append(mins); |
| 2556 | out.append("m "); |
| 2557 | } |
| 2558 | used += mins * 60; |
| 2559 | |
| 2560 | if (seconds != 0 || used != 0) { |
| 2561 | out.append(seconds-used); |
| 2562 | out.append("s "); |
| 2563 | } |
| 2564 | } |
| 2565 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2566 | public final static void formatTimeMs(StringBuilder sb, long time) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2567 | long sec = time / 1000; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 2568 | formatTimeRaw(sb, sec); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2569 | sb.append(time - (sec * 1000)); |
| 2570 | sb.append("ms "); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2571 | } |
| 2572 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2573 | public final static void formatTimeMsNoSpace(StringBuilder sb, long time) { |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 2574 | long sec = time / 1000; |
| 2575 | formatTimeRaw(sb, sec); |
| 2576 | sb.append(time - (sec * 1000)); |
| 2577 | sb.append("ms"); |
| 2578 | } |
| 2579 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2580 | public final String formatRatioLocked(long num, long den) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2581 | if (den == 0L) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2582 | return "--%"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2583 | } |
| 2584 | float perc = ((float)num) / ((float)den) * 100; |
| 2585 | mFormatBuilder.setLength(0); |
| 2586 | mFormatter.format("%.1f%%", perc); |
| 2587 | return mFormatBuilder.toString(); |
| 2588 | } |
| 2589 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2590 | final String formatBytesLocked(long bytes) { |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 2591 | mFormatBuilder.setLength(0); |
| 2592 | |
| 2593 | if (bytes < BYTES_PER_KB) { |
| 2594 | return bytes + "B"; |
| 2595 | } else if (bytes < BYTES_PER_MB) { |
| 2596 | mFormatter.format("%.2fKB", bytes / (double) BYTES_PER_KB); |
| 2597 | return mFormatBuilder.toString(); |
| 2598 | } else if (bytes < BYTES_PER_GB){ |
| 2599 | mFormatter.format("%.2fMB", bytes / (double) BYTES_PER_MB); |
| 2600 | return mFormatBuilder.toString(); |
| 2601 | } else { |
| 2602 | mFormatter.format("%.2fGB", bytes / (double) BYTES_PER_GB); |
| 2603 | return mFormatBuilder.toString(); |
| 2604 | } |
| 2605 | } |
| 2606 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2607 | private static long computeWakeLock(Timer timer, long elapsedRealtimeUs, int which) { |
Dianne Hackborn | c24ab86 | 2011-10-18 15:55:03 -0700 | [diff] [blame] | 2608 | if (timer != null) { |
| 2609 | // Convert from microseconds to milliseconds with rounding |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2610 | long totalTimeMicros = timer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Dianne Hackborn | c24ab86 | 2011-10-18 15:55:03 -0700 | [diff] [blame] | 2611 | long totalTimeMillis = (totalTimeMicros + 500) / 1000; |
| 2612 | return totalTimeMillis; |
| 2613 | } |
| 2614 | return 0; |
| 2615 | } |
| 2616 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2617 | /** |
| 2618 | * |
| 2619 | * @param sb a StringBuilder object. |
| 2620 | * @param timer a Timer object contining the wakelock times. |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2621 | * @param elapsedRealtimeUs the current on-battery time in microseconds. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2622 | * @param name the name of the wakelock. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2623 | * @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] | 2624 | * @param linePrefix a String to be prepended to each line of output. |
| 2625 | * @return the line prefix |
| 2626 | */ |
| 2627 | private static final String printWakeLock(StringBuilder sb, Timer timer, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2628 | long elapsedRealtimeUs, String name, int which, String linePrefix) { |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 2629 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2630 | if (timer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2631 | long totalTimeMillis = computeWakeLock(timer, elapsedRealtimeUs, which); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 2632 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2633 | int count = timer.getCountLocked(which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2634 | if (totalTimeMillis != 0) { |
| 2635 | sb.append(linePrefix); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 2636 | formatTimeMs(sb, totalTimeMillis); |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 2637 | if (name != null) { |
| 2638 | sb.append(name); |
| 2639 | sb.append(' '); |
| 2640 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2641 | sb.append('('); |
| 2642 | sb.append(count); |
| 2643 | sb.append(" times)"); |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2644 | final long maxDurationMs = timer.getMaxDurationMsLocked(elapsedRealtimeUs/1000); |
| 2645 | if (maxDurationMs >= 0) { |
| 2646 | sb.append(" max="); |
| 2647 | sb.append(maxDurationMs); |
| 2648 | } |
| 2649 | if (timer.isRunningLocked()) { |
| 2650 | final long currentMs = timer.getCurrentDurationMsLocked(elapsedRealtimeUs/1000); |
| 2651 | if (currentMs >= 0) { |
| 2652 | sb.append(" (running for "); |
| 2653 | sb.append(currentMs); |
| 2654 | sb.append("ms)"); |
| 2655 | } else { |
| 2656 | sb.append(" (running)"); |
| 2657 | } |
| 2658 | } |
| 2659 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2660 | return ", "; |
| 2661 | } |
| 2662 | } |
| 2663 | return linePrefix; |
| 2664 | } |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 2665 | |
| 2666 | /** |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2667 | * 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] | 2668 | * |
| 2669 | * @param pw a PrintWriter object to print to. |
| 2670 | * @param sb a StringBuilder object. |
| 2671 | * @param timer a Timer object contining the wakelock times. |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame^] | 2672 | * @param rawRealtimeUs the current on-battery time in microseconds. |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 2673 | * @param which which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT. |
| 2674 | * @param prefix a String to be prepended to each line of output. |
| 2675 | * @param type the name of the timer. |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2676 | * @return true if anything was printed. |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 2677 | */ |
| 2678 | private static final boolean printTimer(PrintWriter pw, StringBuilder sb, Timer timer, |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2679 | long rawRealtimeUs, int which, String prefix, String type) { |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 2680 | if (timer != null) { |
| 2681 | // Convert from microseconds to milliseconds with rounding |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2682 | final long totalTimeMs = (timer.getTotalTimeLocked( |
| 2683 | rawRealtimeUs, which) + 500) / 1000; |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 2684 | final int count = timer.getCountLocked(which); |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2685 | if (totalTimeMs != 0) { |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 2686 | sb.setLength(0); |
| 2687 | sb.append(prefix); |
| 2688 | sb.append(" "); |
| 2689 | sb.append(type); |
| 2690 | sb.append(": "); |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2691 | formatTimeMs(sb, totalTimeMs); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 2692 | sb.append("realtime ("); |
| 2693 | sb.append(count); |
| 2694 | sb.append(" times)"); |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2695 | final long maxDurationMs = timer.getMaxDurationMsLocked(rawRealtimeUs/1000); |
| 2696 | if (maxDurationMs >= 0) { |
| 2697 | sb.append(" max="); |
| 2698 | sb.append(maxDurationMs); |
| 2699 | } |
| 2700 | if (timer.isRunningLocked()) { |
| 2701 | final long currentMs = timer.getCurrentDurationMsLocked(rawRealtimeUs/1000); |
| 2702 | if (currentMs >= 0) { |
| 2703 | sb.append(" (running for "); |
| 2704 | sb.append(currentMs); |
| 2705 | sb.append("ms)"); |
| 2706 | } else { |
| 2707 | sb.append(" (running)"); |
| 2708 | } |
| 2709 | } |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 2710 | pw.println(sb.toString()); |
| 2711 | return true; |
| 2712 | } |
| 2713 | } |
| 2714 | return false; |
| 2715 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2716 | |
| 2717 | /** |
| 2718 | * Checkin version of wakelock printer. Prints simple comma-separated list. |
| 2719 | * |
| 2720 | * @param sb a StringBuilder object. |
| 2721 | * @param timer a Timer object contining the wakelock times. |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2722 | * @param elapsedRealtimeUs the current time in microseconds. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2723 | * @param name the name of the wakelock. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2724 | * @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] | 2725 | * @param linePrefix a String to be prepended to each line of output. |
| 2726 | * @return the line prefix |
| 2727 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2728 | private static final String printWakeLockCheckin(StringBuilder sb, Timer timer, |
| 2729 | long elapsedRealtimeUs, String name, int which, String linePrefix) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2730 | long totalTimeMicros = 0; |
| 2731 | int count = 0; |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2732 | long max = -1; |
| 2733 | long current = -1; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2734 | if (timer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2735 | totalTimeMicros = timer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2736 | count = timer.getCountLocked(which); |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2737 | current = timer.getCurrentDurationMsLocked(elapsedRealtimeUs/1000); |
| 2738 | max = timer.getMaxDurationMsLocked(elapsedRealtimeUs/1000); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2739 | } |
| 2740 | sb.append(linePrefix); |
| 2741 | sb.append((totalTimeMicros + 500) / 1000); // microseconds to milliseconds with rounding |
| 2742 | sb.append(','); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2743 | sb.append(name != null ? name + "," : ""); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2744 | sb.append(count); |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2745 | sb.append(','); |
| 2746 | sb.append(current); |
| 2747 | sb.append(','); |
| 2748 | sb.append(max); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2749 | return ","; |
| 2750 | } |
| 2751 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 2752 | private static final void dumpLineHeader(PrintWriter pw, int uid, String category, |
| 2753 | String type) { |
| 2754 | pw.print(BATTERY_STATS_CHECKIN_VERSION); |
| 2755 | pw.print(','); |
| 2756 | pw.print(uid); |
| 2757 | pw.print(','); |
| 2758 | pw.print(category); |
| 2759 | pw.print(','); |
| 2760 | pw.print(type); |
| 2761 | } |
| 2762 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2763 | /** |
| 2764 | * Dump a comma-separated line of values for terse checkin mode. |
| 2765 | * |
| 2766 | * @param pw the PageWriter to dump log to |
| 2767 | * @param category category of data (e.g. "total", "last", "unplugged", "current" ) |
| 2768 | * @param type type of data (e.g. "wakelock", "sensor", "process", "apk" , "process", "network") |
| 2769 | * @param args type-dependent data arguments |
| 2770 | */ |
| 2771 | private static final void dumpLine(PrintWriter pw, int uid, String category, String type, |
| 2772 | Object... args ) { |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 2773 | dumpLineHeader(pw, uid, category, type); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 2774 | for (Object arg : args) { |
Dianne Hackborn | 13ac041 | 2013-06-25 19:34:49 -0700 | [diff] [blame] | 2775 | pw.print(','); |
| 2776 | pw.print(arg); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2777 | } |
Dianne Hackborn | 13ac041 | 2013-06-25 19:34:49 -0700 | [diff] [blame] | 2778 | pw.println(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2779 | } |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 2780 | |
| 2781 | /** |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 2782 | * Dump a given timer stat for terse checkin mode. |
| 2783 | * |
| 2784 | * @param pw the PageWriter to dump log to |
| 2785 | * @param uid the UID to log |
| 2786 | * @param category category of data (e.g. "total", "last", "unplugged", "current" ) |
| 2787 | * @param type type of data (e.g. "wakelock", "sensor", "process", "apk" , "process", "network") |
| 2788 | * @param timer a {@link Timer} to dump stats for |
| 2789 | * @param rawRealtime the current elapsed realtime of the system in microseconds |
| 2790 | * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT |
| 2791 | */ |
| 2792 | private static final void dumpTimer(PrintWriter pw, int uid, String category, String type, |
| 2793 | Timer timer, long rawRealtime, int which) { |
| 2794 | if (timer != null) { |
| 2795 | // Convert from microseconds to milliseconds with rounding |
| 2796 | final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) |
| 2797 | / 1000; |
| 2798 | final int count = timer.getCountLocked(which); |
| 2799 | if (totalTime != 0) { |
| 2800 | dumpLine(pw, uid, category, type, totalTime, count); |
| 2801 | } |
| 2802 | } |
| 2803 | } |
| 2804 | |
| 2805 | /** |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 2806 | * Checks if the ControllerActivityCounter has any data worth dumping. |
| 2807 | */ |
| 2808 | private static boolean controllerActivityHasData(ControllerActivityCounter counter, int which) { |
| 2809 | if (counter == null) { |
| 2810 | return false; |
| 2811 | } |
| 2812 | |
| 2813 | if (counter.getIdleTimeCounter().getCountLocked(which) != 0 |
| 2814 | || counter.getRxTimeCounter().getCountLocked(which) != 0 |
| 2815 | || counter.getPowerCounter().getCountLocked(which) != 0) { |
| 2816 | return true; |
| 2817 | } |
| 2818 | |
| 2819 | for (LongCounter c : counter.getTxTimeCounters()) { |
| 2820 | if (c.getCountLocked(which) != 0) { |
| 2821 | return true; |
| 2822 | } |
| 2823 | } |
| 2824 | return false; |
| 2825 | } |
| 2826 | |
| 2827 | /** |
| 2828 | * Dumps the ControllerActivityCounter if it has any data worth dumping. |
| 2829 | * The order of the arguments in the final check in line is: |
| 2830 | * |
| 2831 | * idle, rx, power, tx... |
| 2832 | * |
| 2833 | * where tx... is one or more transmit level times. |
| 2834 | */ |
| 2835 | private static final void dumpControllerActivityLine(PrintWriter pw, int uid, String category, |
| 2836 | String type, |
| 2837 | ControllerActivityCounter counter, |
| 2838 | int which) { |
| 2839 | if (!controllerActivityHasData(counter, which)) { |
| 2840 | return; |
| 2841 | } |
| 2842 | |
| 2843 | dumpLineHeader(pw, uid, category, type); |
| 2844 | pw.print(","); |
| 2845 | pw.print(counter.getIdleTimeCounter().getCountLocked(which)); |
| 2846 | pw.print(","); |
| 2847 | pw.print(counter.getRxTimeCounter().getCountLocked(which)); |
| 2848 | pw.print(","); |
| 2849 | pw.print(counter.getPowerCounter().getCountLocked(which) / (1000 * 60 * 60)); |
| 2850 | for (LongCounter c : counter.getTxTimeCounters()) { |
| 2851 | pw.print(","); |
| 2852 | pw.print(c.getCountLocked(which)); |
| 2853 | } |
| 2854 | pw.println(); |
| 2855 | } |
| 2856 | |
| 2857 | private final void printControllerActivityIfInteresting(PrintWriter pw, StringBuilder sb, |
| 2858 | String prefix, String controllerName, |
| 2859 | ControllerActivityCounter counter, |
| 2860 | int which) { |
| 2861 | if (controllerActivityHasData(counter, which)) { |
| 2862 | printControllerActivity(pw, sb, prefix, controllerName, counter, which); |
| 2863 | } |
| 2864 | } |
| 2865 | |
| 2866 | private final void printControllerActivity(PrintWriter pw, StringBuilder sb, String prefix, |
| 2867 | String controllerName, |
| 2868 | ControllerActivityCounter counter, int which) { |
| 2869 | final long idleTimeMs = counter.getIdleTimeCounter().getCountLocked(which); |
| 2870 | final long rxTimeMs = counter.getRxTimeCounter().getCountLocked(which); |
| 2871 | final long powerDrainMaMs = counter.getPowerCounter().getCountLocked(which); |
| 2872 | long totalTxTimeMs = 0; |
| 2873 | for (LongCounter txState : counter.getTxTimeCounters()) { |
| 2874 | totalTxTimeMs += txState.getCountLocked(which); |
| 2875 | } |
| 2876 | |
| 2877 | final long totalTimeMs = idleTimeMs + rxTimeMs + totalTxTimeMs; |
| 2878 | |
| 2879 | sb.setLength(0); |
| 2880 | sb.append(prefix); |
| 2881 | sb.append(" "); |
| 2882 | sb.append(controllerName); |
| 2883 | sb.append(" Idle time: "); |
| 2884 | formatTimeMs(sb, idleTimeMs); |
| 2885 | sb.append("("); |
| 2886 | sb.append(formatRatioLocked(idleTimeMs, totalTimeMs)); |
| 2887 | sb.append(")"); |
| 2888 | pw.println(sb.toString()); |
| 2889 | |
| 2890 | sb.setLength(0); |
| 2891 | sb.append(prefix); |
| 2892 | sb.append(" "); |
| 2893 | sb.append(controllerName); |
| 2894 | sb.append(" Rx time: "); |
| 2895 | formatTimeMs(sb, rxTimeMs); |
| 2896 | sb.append("("); |
| 2897 | sb.append(formatRatioLocked(rxTimeMs, totalTimeMs)); |
| 2898 | sb.append(")"); |
| 2899 | pw.println(sb.toString()); |
| 2900 | |
| 2901 | sb.setLength(0); |
| 2902 | sb.append(prefix); |
| 2903 | sb.append(" "); |
| 2904 | sb.append(controllerName); |
| 2905 | sb.append(" Tx time: "); |
| 2906 | formatTimeMs(sb, totalTxTimeMs); |
| 2907 | sb.append("("); |
| 2908 | sb.append(formatRatioLocked(totalTxTimeMs, totalTimeMs)); |
| 2909 | sb.append(")"); |
| 2910 | pw.println(sb.toString()); |
| 2911 | |
| 2912 | final int numTxLvls = counter.getTxTimeCounters().length; |
| 2913 | if (numTxLvls > 1) { |
| 2914 | for (int lvl = 0; lvl < numTxLvls; lvl++) { |
| 2915 | final long txLvlTimeMs = counter.getTxTimeCounters()[lvl].getCountLocked(which); |
| 2916 | sb.setLength(0); |
| 2917 | sb.append(prefix); |
| 2918 | sb.append(" ["); |
| 2919 | sb.append(lvl); |
| 2920 | sb.append("] "); |
| 2921 | formatTimeMs(sb, txLvlTimeMs); |
| 2922 | sb.append("("); |
| 2923 | sb.append(formatRatioLocked(txLvlTimeMs, totalTxTimeMs)); |
| 2924 | sb.append(")"); |
| 2925 | pw.println(sb.toString()); |
| 2926 | } |
| 2927 | } |
| 2928 | |
| 2929 | sb.setLength(0); |
| 2930 | sb.append(prefix); |
| 2931 | sb.append(" "); |
| 2932 | sb.append(controllerName); |
| 2933 | sb.append(" Power drain: ").append( |
| 2934 | BatteryStatsHelper.makemAh(powerDrainMaMs / (double) (1000*60*60))); |
| 2935 | sb.append("mAh"); |
| 2936 | pw.println(sb.toString()); |
| 2937 | } |
| 2938 | |
| 2939 | /** |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 2940 | * Temporary for settings. |
| 2941 | */ |
| 2942 | public final void dumpCheckinLocked(Context context, PrintWriter pw, int which, int reqUid) { |
| 2943 | dumpCheckinLocked(context, pw, which, reqUid, BatteryStatsHelper.checkWifiOnly(context)); |
| 2944 | } |
| 2945 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2946 | /** |
| 2947 | * Checkin server version of dump to produce more compact, computer-readable log. |
| 2948 | * |
| 2949 | * NOTE: all times are expressed in 'ms'. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2950 | */ |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 2951 | public final void dumpCheckinLocked(Context context, PrintWriter pw, int which, int reqUid, |
| 2952 | boolean wifiOnly) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2953 | final long rawUptime = SystemClock.uptimeMillis() * 1000; |
| 2954 | final long rawRealtime = SystemClock.elapsedRealtime() * 1000; |
| 2955 | final long batteryUptime = getBatteryUptime(rawUptime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2956 | final long whichBatteryUptime = computeBatteryUptime(rawUptime, which); |
| 2957 | final long whichBatteryRealtime = computeBatteryRealtime(rawRealtime, which); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2958 | final long whichBatteryScreenOffUptime = computeBatteryScreenOffUptime(rawUptime, which); |
| 2959 | final long whichBatteryScreenOffRealtime = computeBatteryScreenOffRealtime(rawRealtime, |
| 2960 | which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2961 | final long totalRealtime = computeRealtime(rawRealtime, which); |
| 2962 | final long totalUptime = computeUptime(rawUptime, which); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2963 | final long screenOnTime = getScreenOnTime(rawRealtime, which); |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 2964 | final long interactiveTime = getInteractiveTime(rawRealtime, which); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 2965 | final long powerSaveModeEnabledTime = getPowerSaveModeEnabledTime(rawRealtime, which); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 2966 | final long deviceIdleModeLightTime = getDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT, |
| 2967 | rawRealtime, which); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 2968 | final long deviceIdleModeFullTime = getDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP, |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 2969 | rawRealtime, which); |
| 2970 | final long deviceLightIdlingTime = getDeviceIdlingTime(DEVICE_IDLE_MODE_LIGHT, |
| 2971 | rawRealtime, which); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 2972 | final long deviceIdlingTime = getDeviceIdlingTime(DEVICE_IDLE_MODE_DEEP, |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 2973 | rawRealtime, which); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 2974 | final int connChanges = getNumConnectivityChange(which); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2975 | final long phoneOnTime = getPhoneOnTime(rawRealtime, which); |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 2976 | final long dischargeCount = getDischargeCoulombCounter().getCountLocked(which); |
| 2977 | final long dischargeScreenOffCount = getDischargeScreenOffCoulombCounter() |
| 2978 | .getCountLocked(which); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 2979 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 2980 | final StringBuilder sb = new StringBuilder(128); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2981 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 2982 | final SparseArray<? extends Uid> uidStats = getUidStats(); |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 2983 | final int NU = uidStats.size(); |
| 2984 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 2985 | final String category = STAT_NAMES[which]; |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 2986 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2987 | // Dump "battery" stat |
| 2988 | dumpLine(pw, 0 /* uid */, category, BATTERY_DATA, |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2989 | which == STATS_SINCE_CHARGED ? getStartCount() : "N/A", |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2990 | whichBatteryRealtime / 1000, whichBatteryUptime / 1000, |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 2991 | totalRealtime / 1000, totalUptime / 1000, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2992 | getStartClockTime(), |
Adam Lesinski | f9b20a9 | 2016-06-17 17:30:01 -0700 | [diff] [blame] | 2993 | whichBatteryScreenOffRealtime / 1000, whichBatteryScreenOffUptime / 1000, |
| 2994 | getEstimatedBatteryCapacity()); |
Adam Lesinski | 67c134f | 2016-06-10 15:15:08 -0700 | [diff] [blame] | 2995 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2996 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2997 | // Calculate wakelock times across all uids. |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 2998 | long fullWakeLockTimeTotal = 0; |
| 2999 | long partialWakeLockTimeTotal = 0; |
| 3000 | |
| 3001 | for (int iu = 0; iu < NU; iu++) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3002 | final Uid u = uidStats.valueAt(iu); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 3003 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3004 | final ArrayMap<String, ? extends BatteryStats.Uid.Wakelock> wakelocks |
| 3005 | = u.getWakelockStats(); |
| 3006 | for (int iw=wakelocks.size()-1; iw>=0; iw--) { |
| 3007 | final Uid.Wakelock wl = wakelocks.valueAt(iw); |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 3008 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3009 | final Timer fullWakeTimer = wl.getWakeTime(WAKE_TYPE_FULL); |
| 3010 | if (fullWakeTimer != null) { |
| 3011 | fullWakeLockTimeTotal += fullWakeTimer.getTotalTimeLocked(rawRealtime, |
| 3012 | which); |
| 3013 | } |
| 3014 | |
| 3015 | final Timer partialWakeTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL); |
| 3016 | if (partialWakeTimer != null) { |
| 3017 | partialWakeLockTimeTotal += partialWakeTimer.getTotalTimeLocked( |
| 3018 | rawRealtime, which); |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 3019 | } |
| 3020 | } |
| 3021 | } |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 3022 | |
| 3023 | // Dump network stats |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3024 | final long mobileRxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which); |
| 3025 | final long mobileTxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which); |
| 3026 | final long wifiRxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which); |
| 3027 | final long wifiTxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which); |
| 3028 | final long mobileRxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which); |
| 3029 | final long mobileTxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which); |
| 3030 | final long wifiRxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which); |
| 3031 | final long wifiTxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 3032 | final long btRxTotalBytes = getNetworkActivityBytes(NETWORK_BT_RX_DATA, which); |
| 3033 | final long btTxTotalBytes = getNetworkActivityBytes(NETWORK_BT_TX_DATA, which); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3034 | dumpLine(pw, 0 /* uid */, category, GLOBAL_NETWORK_DATA, |
| 3035 | mobileRxTotalBytes, mobileTxTotalBytes, wifiRxTotalBytes, wifiTxTotalBytes, |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 3036 | mobileRxTotalPackets, mobileTxTotalPackets, wifiRxTotalPackets, wifiTxTotalPackets, |
| 3037 | btRxTotalBytes, btTxTotalBytes); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3038 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3039 | // Dump Modem controller stats |
| 3040 | dumpControllerActivityLine(pw, 0 /* uid */, category, GLOBAL_MODEM_CONTROLLER_DATA, |
| 3041 | getModemControllerActivity(), which); |
| 3042 | |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 3043 | // Dump Wifi controller stats |
| 3044 | final long wifiOnTime = getWifiOnTime(rawRealtime, which); |
| 3045 | final long wifiRunningTime = getGlobalWifiRunningTime(rawRealtime, which); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3046 | dumpLine(pw, 0 /* uid */, category, GLOBAL_WIFI_DATA, wifiOnTime / 1000, |
Adam Lesinski | 2208e74 | 2016-02-19 12:53:31 -0800 | [diff] [blame] | 3047 | wifiRunningTime / 1000, /* legacy fields follow, keep at 0 */ 0, 0, 0); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3048 | |
| 3049 | dumpControllerActivityLine(pw, 0 /* uid */, category, GLOBAL_WIFI_CONTROLLER_DATA, |
| 3050 | getWifiControllerActivity(), which); |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 3051 | |
| 3052 | // Dump Bluetooth controller stats |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3053 | dumpControllerActivityLine(pw, 0 /* uid */, category, GLOBAL_BLUETOOTH_CONTROLLER_DATA, |
| 3054 | getBluetoothControllerActivity(), which); |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 3055 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3056 | // Dump misc stats |
| 3057 | dumpLine(pw, 0 /* uid */, category, MISC_DATA, |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 3058 | screenOnTime / 1000, phoneOnTime / 1000, |
Ashish Sharma | 213bb2f | 2014-07-07 17:14:52 -0700 | [diff] [blame] | 3059 | fullWakeLockTimeTotal / 1000, partialWakeLockTimeTotal / 1000, |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 3060 | getMobileRadioActiveTime(rawRealtime, which) / 1000, |
Ashish Sharma | 213bb2f | 2014-07-07 17:14:52 -0700 | [diff] [blame] | 3061 | getMobileRadioActiveAdjustedTime(which) / 1000, interactiveTime / 1000, |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3062 | powerSaveModeEnabledTime / 1000, connChanges, deviceIdleModeFullTime / 1000, |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 3063 | getDeviceIdleModeCount(DEVICE_IDLE_MODE_DEEP, which), deviceIdlingTime / 1000, |
| 3064 | getDeviceIdlingCount(DEVICE_IDLE_MODE_DEEP, which), |
Adam Lesinski | 782327b | 2015-07-30 16:36:29 -0700 | [diff] [blame] | 3065 | getMobileRadioActiveCount(which), |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3066 | getMobileRadioActiveUnknownTime(which) / 1000, deviceIdleModeLightTime / 1000, |
| 3067 | getDeviceIdleModeCount(DEVICE_IDLE_MODE_LIGHT, which), deviceLightIdlingTime / 1000, |
| 3068 | getDeviceIdlingCount(DEVICE_IDLE_MODE_LIGHT, which), |
| 3069 | getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT), |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 3070 | getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP)); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3071 | |
| 3072 | // Dump screen brightness stats |
| 3073 | Object[] args = new Object[NUM_SCREEN_BRIGHTNESS_BINS]; |
| 3074 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3075 | args[i] = getScreenBrightnessTime(i, rawRealtime, which) / 1000; |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3076 | } |
| 3077 | dumpLine(pw, 0 /* uid */, category, SCREEN_BRIGHTNESS_DATA, args); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3078 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3079 | // Dump signal strength stats |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 3080 | args = new Object[SignalStrength.NUM_SIGNAL_STRENGTH_BINS]; |
| 3081 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3082 | args[i] = getPhoneSignalStrengthTime(i, rawRealtime, which) / 1000; |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3083 | } |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3084 | dumpLine(pw, 0 /* uid */, category, SIGNAL_STRENGTH_TIME_DATA, args); |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 3085 | dumpLine(pw, 0 /* uid */, category, SIGNAL_SCANNING_TIME_DATA, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3086 | getPhoneSignalScanningTime(rawRealtime, which) / 1000); |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 3087 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3088 | args[i] = getPhoneSignalStrengthCount(i, which); |
| 3089 | } |
| 3090 | dumpLine(pw, 0 /* uid */, category, SIGNAL_STRENGTH_COUNT_DATA, args); |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 3091 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3092 | // Dump network type stats |
| 3093 | args = new Object[NUM_DATA_CONNECTION_TYPES]; |
| 3094 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3095 | args[i] = getPhoneDataConnectionTime(i, rawRealtime, which) / 1000; |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3096 | } |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3097 | dumpLine(pw, 0 /* uid */, category, DATA_CONNECTION_TIME_DATA, args); |
| 3098 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
| 3099 | args[i] = getPhoneDataConnectionCount(i, which); |
| 3100 | } |
| 3101 | dumpLine(pw, 0 /* uid */, category, DATA_CONNECTION_COUNT_DATA, args); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3102 | |
| 3103 | // Dump wifi state stats |
| 3104 | args = new Object[NUM_WIFI_STATES]; |
| 3105 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3106 | args[i] = getWifiStateTime(i, rawRealtime, which) / 1000; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3107 | } |
| 3108 | dumpLine(pw, 0 /* uid */, category, WIFI_STATE_TIME_DATA, args); |
| 3109 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
| 3110 | args[i] = getWifiStateCount(i, which); |
| 3111 | } |
| 3112 | dumpLine(pw, 0 /* uid */, category, WIFI_STATE_COUNT_DATA, args); |
| 3113 | |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 3114 | // Dump wifi suppl state stats |
| 3115 | args = new Object[NUM_WIFI_SUPPL_STATES]; |
| 3116 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
| 3117 | args[i] = getWifiSupplStateTime(i, rawRealtime, which) / 1000; |
| 3118 | } |
| 3119 | dumpLine(pw, 0 /* uid */, category, WIFI_SUPPL_STATE_TIME_DATA, args); |
| 3120 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
| 3121 | args[i] = getWifiSupplStateCount(i, which); |
| 3122 | } |
| 3123 | dumpLine(pw, 0 /* uid */, category, WIFI_SUPPL_STATE_COUNT_DATA, args); |
| 3124 | |
| 3125 | // Dump wifi signal strength stats |
| 3126 | args = new Object[NUM_WIFI_SIGNAL_STRENGTH_BINS]; |
| 3127 | for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 3128 | args[i] = getWifiSignalStrengthTime(i, rawRealtime, which) / 1000; |
| 3129 | } |
| 3130 | dumpLine(pw, 0 /* uid */, category, WIFI_SIGNAL_STRENGTH_TIME_DATA, args); |
| 3131 | for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 3132 | args[i] = getWifiSignalStrengthCount(i, which); |
| 3133 | } |
| 3134 | dumpLine(pw, 0 /* uid */, category, WIFI_SIGNAL_STRENGTH_COUNT_DATA, args); |
| 3135 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3136 | if (which == STATS_SINCE_UNPLUGGED) { |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 3137 | dumpLine(pw, 0 /* uid */, category, BATTERY_LEVEL_DATA, getDischargeStartLevel(), |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 3138 | getDischargeCurrentLevel()); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3139 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3140 | |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 3141 | if (which == STATS_SINCE_UNPLUGGED) { |
| 3142 | dumpLine(pw, 0 /* uid */, category, BATTERY_DISCHARGE_DATA, |
| 3143 | getDischargeStartLevel()-getDischargeCurrentLevel(), |
| 3144 | getDischargeStartLevel()-getDischargeCurrentLevel(), |
Adam Lesinski | 67c134f | 2016-06-10 15:15:08 -0700 | [diff] [blame] | 3145 | getDischargeAmountScreenOn(), getDischargeAmountScreenOff(), |
| 3146 | dischargeCount / 1000, dischargeScreenOffCount / 1000); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 3147 | } else { |
| 3148 | dumpLine(pw, 0 /* uid */, category, BATTERY_DISCHARGE_DATA, |
| 3149 | getLowDischargeAmountSinceCharge(), getHighDischargeAmountSinceCharge(), |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 3150 | getDischargeAmountScreenOnSinceCharge(), |
Adam Lesinski | 67c134f | 2016-06-10 15:15:08 -0700 | [diff] [blame] | 3151 | getDischargeAmountScreenOffSinceCharge(), |
| 3152 | dischargeCount / 1000, dischargeScreenOffCount / 1000); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 3153 | } |
| 3154 | |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 3155 | if (reqUid < 0) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3156 | final Map<String, ? extends Timer> kernelWakelocks = getKernelWakelockStats(); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 3157 | if (kernelWakelocks.size() > 0) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3158 | for (Map.Entry<String, ? extends Timer> ent : kernelWakelocks.entrySet()) { |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 3159 | sb.setLength(0); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3160 | printWakeLockCheckin(sb, ent.getValue(), rawRealtime, null, which, ""); |
Kweku Adams | e0dd9c1 | 2017-03-08 08:12:15 -0800 | [diff] [blame] | 3161 | dumpLine(pw, 0 /* uid */, category, KERNEL_WAKELOCK_DATA, |
| 3162 | "\"" + ent.getKey() + "\"", sb.toString()); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 3163 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 3164 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3165 | final Map<String, ? extends Timer> wakeupReasons = getWakeupReasonStats(); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3166 | if (wakeupReasons.size() > 0) { |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 3167 | for (Map.Entry<String, ? extends Timer> ent : wakeupReasons.entrySet()) { |
| 3168 | // Not doing the regular wake lock formatting to remain compatible |
| 3169 | // with the old checkin format. |
| 3170 | long totalTimeMicros = ent.getValue().getTotalTimeLocked(rawRealtime, which); |
| 3171 | int count = ent.getValue().getCountLocked(which); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3172 | dumpLine(pw, 0 /* uid */, category, WAKEUP_REASON_DATA, |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 3173 | "\"" + ent.getKey() + "\"", (totalTimeMicros + 500) / 1000, count); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3174 | } |
| 3175 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 3176 | } |
| 3177 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3178 | final BatteryStatsHelper helper = new BatteryStatsHelper(context, false, wifiOnly); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3179 | helper.create(this); |
| 3180 | helper.refreshStats(which, UserHandle.USER_ALL); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3181 | final List<BatterySipper> sippers = helper.getUsageList(); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3182 | if (sippers != null && sippers.size() > 0) { |
| 3183 | dumpLine(pw, 0 /* uid */, category, POWER_USE_SUMMARY_DATA, |
| 3184 | BatteryStatsHelper.makemAh(helper.getPowerProfile().getBatteryCapacity()), |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3185 | BatteryStatsHelper.makemAh(helper.getComputedPower()), |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3186 | BatteryStatsHelper.makemAh(helper.getMinDrainedPower()), |
| 3187 | BatteryStatsHelper.makemAh(helper.getMaxDrainedPower())); |
| 3188 | for (int i=0; i<sippers.size(); i++) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3189 | final BatterySipper bs = sippers.get(i); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3190 | int uid = 0; |
| 3191 | String label; |
| 3192 | switch (bs.drainType) { |
| 3193 | case IDLE: |
| 3194 | label="idle"; |
| 3195 | break; |
| 3196 | case CELL: |
| 3197 | label="cell"; |
| 3198 | break; |
| 3199 | case PHONE: |
| 3200 | label="phone"; |
| 3201 | break; |
| 3202 | case WIFI: |
| 3203 | label="wifi"; |
| 3204 | break; |
| 3205 | case BLUETOOTH: |
| 3206 | label="blue"; |
| 3207 | break; |
| 3208 | case SCREEN: |
| 3209 | label="scrn"; |
| 3210 | break; |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 3211 | case FLASHLIGHT: |
| 3212 | label="flashlight"; |
| 3213 | break; |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3214 | case APP: |
| 3215 | uid = bs.uidObj.getUid(); |
| 3216 | label = "uid"; |
| 3217 | break; |
| 3218 | case USER: |
| 3219 | uid = UserHandle.getUid(bs.userId, 0); |
| 3220 | label = "user"; |
| 3221 | break; |
| 3222 | case UNACCOUNTED: |
| 3223 | label = "unacc"; |
| 3224 | break; |
| 3225 | case OVERCOUNTED: |
| 3226 | label = "over"; |
| 3227 | break; |
Ruben Brunk | 5b1308f | 2015-06-03 18:49:27 -0700 | [diff] [blame] | 3228 | case CAMERA: |
| 3229 | label = "camera"; |
| 3230 | break; |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3231 | default: |
| 3232 | label = "???"; |
| 3233 | } |
| 3234 | dumpLine(pw, uid, category, POWER_USE_ITEM_DATA, label, |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 3235 | BatteryStatsHelper.makemAh(bs.totalPowerMah)); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3236 | } |
| 3237 | } |
| 3238 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3239 | for (int iu = 0; iu < NU; iu++) { |
| 3240 | final int uid = uidStats.keyAt(iu); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 3241 | if (reqUid >= 0 && uid != reqUid) { |
| 3242 | continue; |
| 3243 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3244 | final Uid u = uidStats.valueAt(iu); |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 3245 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3246 | // Dump Network stats per uid, if any |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3247 | final long mobileBytesRx = u.getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which); |
| 3248 | final long mobileBytesTx = u.getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which); |
| 3249 | final long wifiBytesRx = u.getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which); |
| 3250 | final long wifiBytesTx = u.getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which); |
| 3251 | final long mobilePacketsRx = u.getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which); |
| 3252 | final long mobilePacketsTx = u.getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which); |
| 3253 | final long mobileActiveTime = u.getMobileRadioActiveTime(which); |
| 3254 | final int mobileActiveCount = u.getMobileRadioActiveCount(which); |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 3255 | final long mobileWakeup = u.getMobileRadioApWakeupCount(which); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3256 | final long wifiPacketsRx = u.getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which); |
| 3257 | final long wifiPacketsTx = u.getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which); |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 3258 | final long wifiWakeup = u.getWifiRadioApWakeupCount(which); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 3259 | final long btBytesRx = u.getNetworkActivityBytes(NETWORK_BT_RX_DATA, which); |
| 3260 | final long btBytesTx = u.getNetworkActivityBytes(NETWORK_BT_TX_DATA, which); |
Amith Yamasani | 59fe841 | 2017-03-03 16:28:52 -0800 | [diff] [blame] | 3261 | // Background data transfers |
| 3262 | final long mobileBytesBgRx = u.getNetworkActivityBytes(NETWORK_MOBILE_BG_RX_DATA, |
| 3263 | which); |
| 3264 | final long mobileBytesBgTx = u.getNetworkActivityBytes(NETWORK_MOBILE_BG_TX_DATA, |
| 3265 | which); |
| 3266 | final long wifiBytesBgRx = u.getNetworkActivityBytes(NETWORK_WIFI_BG_RX_DATA, which); |
| 3267 | final long wifiBytesBgTx = u.getNetworkActivityBytes(NETWORK_WIFI_BG_TX_DATA, which); |
| 3268 | final long mobilePacketsBgRx = u.getNetworkActivityPackets(NETWORK_MOBILE_BG_RX_DATA, |
| 3269 | which); |
| 3270 | final long mobilePacketsBgTx = u.getNetworkActivityPackets(NETWORK_MOBILE_BG_TX_DATA, |
| 3271 | which); |
| 3272 | final long wifiPacketsBgRx = u.getNetworkActivityPackets(NETWORK_WIFI_BG_RX_DATA, |
| 3273 | which); |
| 3274 | final long wifiPacketsBgTx = u.getNetworkActivityPackets(NETWORK_WIFI_BG_TX_DATA, |
| 3275 | which); |
| 3276 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3277 | if (mobileBytesRx > 0 || mobileBytesTx > 0 || wifiBytesRx > 0 || wifiBytesTx > 0 |
| 3278 | || mobilePacketsRx > 0 || mobilePacketsTx > 0 || wifiPacketsRx > 0 |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 3279 | || wifiPacketsTx > 0 || mobileActiveTime > 0 || mobileActiveCount > 0 |
Amith Yamasani | 59fe841 | 2017-03-03 16:28:52 -0800 | [diff] [blame] | 3280 | || btBytesRx > 0 || btBytesTx > 0 || mobileWakeup > 0 || wifiWakeup > 0 |
| 3281 | || mobileBytesBgRx > 0 || mobileBytesBgTx > 0 || wifiBytesBgRx > 0 |
| 3282 | || wifiBytesBgTx > 0 |
| 3283 | || mobilePacketsBgRx > 0 || mobilePacketsBgTx > 0 || wifiPacketsBgRx > 0 |
| 3284 | || wifiPacketsBgTx > 0) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3285 | dumpLine(pw, uid, category, NETWORK_DATA, mobileBytesRx, mobileBytesTx, |
| 3286 | wifiBytesRx, wifiBytesTx, |
| 3287 | mobilePacketsRx, mobilePacketsTx, |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 3288 | wifiPacketsRx, wifiPacketsTx, |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 3289 | mobileActiveTime, mobileActiveCount, |
Amith Yamasani | 59fe841 | 2017-03-03 16:28:52 -0800 | [diff] [blame] | 3290 | btBytesRx, btBytesTx, mobileWakeup, wifiWakeup, |
| 3291 | mobileBytesBgRx, mobileBytesBgTx, wifiBytesBgRx, wifiBytesBgTx, |
| 3292 | mobilePacketsBgRx, mobilePacketsBgTx, wifiPacketsBgRx, wifiPacketsBgTx |
| 3293 | ); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 3294 | } |
| 3295 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3296 | // Dump modem controller data, per UID. |
| 3297 | dumpControllerActivityLine(pw, uid, category, MODEM_CONTROLLER_DATA, |
| 3298 | u.getModemControllerActivity(), which); |
| 3299 | |
| 3300 | // Dump Wifi controller data, per UID. |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 3301 | final long fullWifiLockOnTime = u.getFullWifiLockTime(rawRealtime, which); |
| 3302 | final long wifiScanTime = u.getWifiScanTime(rawRealtime, which); |
| 3303 | final int wifiScanCount = u.getWifiScanCount(which); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame^] | 3304 | final int wifiScanCountBg = u.getWifiScanBackgroundCount(which); |
| 3305 | // Note that 'ActualTime' are unpooled and always since reset (regardless of 'which') |
| 3306 | final long wifiScanActualTime = u.getWifiScanActualTime(rawRealtime); |
| 3307 | final long wifiScanActualTimeBg = u.getWifiScanBackgroundTime(rawRealtime); |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 3308 | final long uidWifiRunningTime = u.getWifiRunningTime(rawRealtime, which); |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 3309 | if (fullWifiLockOnTime != 0 || wifiScanTime != 0 || wifiScanCount != 0 |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame^] | 3310 | || wifiScanCountBg != 0 || wifiScanActualTime != 0 || wifiScanActualTimeBg != 0 |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3311 | || uidWifiRunningTime != 0) { |
| 3312 | dumpLine(pw, uid, category, WIFI_DATA, fullWifiLockOnTime, wifiScanTime, |
| 3313 | uidWifiRunningTime, wifiScanCount, |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame^] | 3314 | /* legacy fields follow, keep at 0 */ 0, 0, 0, |
| 3315 | wifiScanCountBg, wifiScanActualTime, wifiScanActualTimeBg); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3316 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3317 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3318 | dumpControllerActivityLine(pw, uid, category, WIFI_CONTROLLER_DATA, |
| 3319 | u.getWifiControllerActivity(), which); |
| 3320 | |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame^] | 3321 | final Timer bleTimer = u.getBluetoothScanTimer(); |
| 3322 | if (bleTimer != null) { |
| 3323 | // Convert from microseconds to milliseconds with rounding |
| 3324 | final long totalTime = (bleTimer.getTotalTimeLocked(rawRealtime, which) + 500) |
| 3325 | / 1000; |
| 3326 | if (totalTime != 0) { |
| 3327 | final int count = bleTimer.getCountLocked(which); |
| 3328 | final Timer bleTimerBg = u.getBluetoothScanBackgroundTimer(); |
| 3329 | final int countBg = bleTimerBg != null ? bleTimerBg.getCountLocked(which) : 0; |
| 3330 | final long rawRealtimeMs = (rawRealtime + 500) / 1000; |
| 3331 | // 'actualTime' are unpooled and always since reset (regardless of 'which') |
| 3332 | final long actualTime = bleTimer.getTotalDurationMsLocked(rawRealtimeMs); |
| 3333 | final long actualTimeBg = bleTimerBg != null ? |
| 3334 | bleTimerBg.getTotalDurationMsLocked(rawRealtimeMs) : 0; |
| 3335 | dumpLine(pw, uid, category, BLUETOOTH_MISC_DATA, totalTime, count, |
| 3336 | countBg, actualTime, actualTimeBg); |
| 3337 | } |
| 3338 | } |
Adam Lesinski | d9b99be | 2016-03-30 16:58:51 -0700 | [diff] [blame] | 3339 | |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 3340 | dumpControllerActivityLine(pw, uid, category, BLUETOOTH_CONTROLLER_DATA, |
| 3341 | u.getBluetoothControllerActivity(), which); |
| 3342 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3343 | if (u.hasUserActivity()) { |
| 3344 | args = new Object[Uid.NUM_USER_ACTIVITY_TYPES]; |
| 3345 | boolean hasData = false; |
| 3346 | for (int i=0; i<Uid.NUM_USER_ACTIVITY_TYPES; i++) { |
| 3347 | int val = u.getUserActivityCount(i, which); |
| 3348 | args[i] = val; |
| 3349 | if (val != 0) hasData = true; |
| 3350 | } |
| 3351 | if (hasData) { |
Ashish Sharma | cba1215 | 2014-07-07 17:14:52 -0700 | [diff] [blame] | 3352 | dumpLine(pw, uid /* uid */, category, USER_ACTIVITY_DATA, args); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3353 | } |
| 3354 | } |
| 3355 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3356 | final ArrayMap<String, ? extends Uid.Wakelock> wakelocks = u.getWakelockStats(); |
| 3357 | for (int iw=wakelocks.size()-1; iw>=0; iw--) { |
| 3358 | final Uid.Wakelock wl = wakelocks.valueAt(iw); |
| 3359 | String linePrefix = ""; |
| 3360 | sb.setLength(0); |
| 3361 | linePrefix = printWakeLockCheckin(sb, wl.getWakeTime(WAKE_TYPE_FULL), |
| 3362 | rawRealtime, "f", which, linePrefix); |
| 3363 | linePrefix = printWakeLockCheckin(sb, wl.getWakeTime(WAKE_TYPE_PARTIAL), |
| 3364 | rawRealtime, "p", which, linePrefix); |
| 3365 | linePrefix = printWakeLockCheckin(sb, wl.getWakeTime(WAKE_TYPE_WINDOW), |
| 3366 | rawRealtime, "w", which, linePrefix); |
| 3367 | |
| 3368 | // Only log if we had at lease one wakelock... |
| 3369 | if (sb.length() > 0) { |
| 3370 | String name = wakelocks.keyAt(iw); |
| 3371 | if (name.indexOf(',') >= 0) { |
| 3372 | name = name.replace(',', '_'); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3373 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3374 | dumpLine(pw, uid, category, WAKELOCK_DATA, name, sb.toString()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3375 | } |
| 3376 | } |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 3377 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3378 | final ArrayMap<String, ? extends Timer> syncs = u.getSyncStats(); |
| 3379 | for (int isy=syncs.size()-1; isy>=0; isy--) { |
| 3380 | final Timer timer = syncs.valueAt(isy); |
| 3381 | // Convert from microseconds to milliseconds with rounding |
| 3382 | final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000; |
| 3383 | final int count = timer.getCountLocked(which); |
| 3384 | if (totalTime != 0) { |
Kweku Adams | e0dd9c1 | 2017-03-08 08:12:15 -0800 | [diff] [blame] | 3385 | dumpLine(pw, uid, category, SYNC_DATA, "\"" + syncs.keyAt(isy) + "\"", |
| 3386 | totalTime, count); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 3387 | } |
| 3388 | } |
| 3389 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3390 | final ArrayMap<String, ? extends Timer> jobs = u.getJobStats(); |
| 3391 | for (int ij=jobs.size()-1; ij>=0; ij--) { |
| 3392 | final Timer timer = jobs.valueAt(ij); |
| 3393 | // Convert from microseconds to milliseconds with rounding |
| 3394 | final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000; |
| 3395 | final int count = timer.getCountLocked(which); |
| 3396 | if (totalTime != 0) { |
Kweku Adams | e0dd9c1 | 2017-03-08 08:12:15 -0800 | [diff] [blame] | 3397 | dumpLine(pw, uid, category, JOB_DATA, "\"" + jobs.keyAt(ij) + "\"", |
| 3398 | totalTime, count); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 3399 | } |
| 3400 | } |
| 3401 | |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 3402 | dumpTimer(pw, uid, category, FLASHLIGHT_DATA, u.getFlashlightTurnedOnTimer(), |
| 3403 | rawRealtime, which); |
| 3404 | dumpTimer(pw, uid, category, CAMERA_DATA, u.getCameraTurnedOnTimer(), |
| 3405 | rawRealtime, which); |
| 3406 | dumpTimer(pw, uid, category, VIDEO_DATA, u.getVideoTurnedOnTimer(), |
| 3407 | rawRealtime, which); |
| 3408 | dumpTimer(pw, uid, category, AUDIO_DATA, u.getAudioTurnedOnTimer(), |
| 3409 | rawRealtime, which); |
| 3410 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3411 | final SparseArray<? extends BatteryStats.Uid.Sensor> sensors = u.getSensorStats(); |
| 3412 | final int NSE = sensors.size(); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 3413 | for (int ise=0; ise<NSE; ise++) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3414 | final Uid.Sensor se = sensors.valueAt(ise); |
| 3415 | final int sensorNumber = sensors.keyAt(ise); |
| 3416 | final Timer timer = se.getSensorTime(); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 3417 | if (timer != null) { |
| 3418 | // Convert from microseconds to milliseconds with rounding |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3419 | final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) |
| 3420 | / 1000; |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 3421 | if (totalTime != 0) { |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame^] | 3422 | final int count = timer.getCountLocked(which); |
| 3423 | final Timer bgTimer = se.getSensorBackgroundTime(); |
| 3424 | final int bgCount = bgTimer != null ? bgTimer.getCountLocked(which) : 0; |
| 3425 | final long rawRealtimeMs = (rawRealtime + 500) / 1000; |
| 3426 | // 'actualTime' are unpooled and always since reset (regardless of 'which') |
| 3427 | final long actualTime = timer.getTotalDurationMsLocked(rawRealtimeMs); |
| 3428 | final long bgActualTime = bgTimer != null ? |
| 3429 | bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : 0; |
| 3430 | dumpLine(pw, uid, category, SENSOR_DATA, sensorNumber, totalTime, |
| 3431 | count, bgCount, actualTime, bgActualTime); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 3432 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3433 | } |
| 3434 | } |
| 3435 | |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 3436 | dumpTimer(pw, uid, category, VIBRATOR_DATA, u.getVibratorOnTimer(), |
| 3437 | rawRealtime, which); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 3438 | |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 3439 | dumpTimer(pw, uid, category, FOREGROUND_DATA, u.getForegroundActivityTimer(), |
| 3440 | rawRealtime, which); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 3441 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3442 | final Object[] stateTimes = new Object[Uid.NUM_PROCESS_STATE]; |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 3443 | long totalStateTime = 0; |
| 3444 | for (int ips=0; ips<Uid.NUM_PROCESS_STATE; ips++) { |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 3445 | final long time = u.getProcessStateTime(ips, rawRealtime, which); |
| 3446 | totalStateTime += time; |
| 3447 | stateTimes[ips] = (time + 500) / 1000; |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 3448 | } |
| 3449 | if (totalStateTime > 0) { |
| 3450 | dumpLine(pw, uid, category, STATE_TIME_DATA, stateTimes); |
| 3451 | } |
| 3452 | |
Adam Lesinski | a7a4ccc | 2015-06-26 17:43:04 -0700 | [diff] [blame] | 3453 | final long userCpuTimeUs = u.getUserCpuTimeUs(which); |
| 3454 | final long systemCpuTimeUs = u.getSystemCpuTimeUs(which); |
| 3455 | final long powerCpuMaUs = u.getCpuPowerMaUs(which); |
| 3456 | if (userCpuTimeUs > 0 || systemCpuTimeUs > 0 || powerCpuMaUs > 0) { |
| 3457 | dumpLine(pw, uid, category, CPU_DATA, userCpuTimeUs / 1000, systemCpuTimeUs / 1000, |
| 3458 | powerCpuMaUs / 1000); |
| 3459 | } |
| 3460 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3461 | final ArrayMap<String, ? extends BatteryStats.Uid.Proc> processStats |
| 3462 | = u.getProcessStats(); |
| 3463 | for (int ipr=processStats.size()-1; ipr>=0; ipr--) { |
| 3464 | final Uid.Proc ps = processStats.valueAt(ipr); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 3465 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3466 | final long userMillis = ps.getUserTime(which); |
| 3467 | final long systemMillis = ps.getSystemTime(which); |
| 3468 | final long foregroundMillis = ps.getForegroundTime(which); |
| 3469 | final int starts = ps.getStarts(which); |
| 3470 | final int numCrashes = ps.getNumCrashes(which); |
| 3471 | final int numAnrs = ps.getNumAnrs(which); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 3472 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3473 | if (userMillis != 0 || systemMillis != 0 || foregroundMillis != 0 |
| 3474 | || starts != 0 || numAnrs != 0 || numCrashes != 0) { |
Kweku Adams | e0dd9c1 | 2017-03-08 08:12:15 -0800 | [diff] [blame] | 3475 | dumpLine(pw, uid, category, PROCESS_DATA, "\"" + processStats.keyAt(ipr) + "\"", |
| 3476 | userMillis, systemMillis, foregroundMillis, starts, numAnrs, numCrashes); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3477 | } |
| 3478 | } |
| 3479 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3480 | final ArrayMap<String, ? extends BatteryStats.Uid.Pkg> packageStats |
| 3481 | = u.getPackageStats(); |
| 3482 | for (int ipkg=packageStats.size()-1; ipkg>=0; ipkg--) { |
| 3483 | final Uid.Pkg ps = packageStats.valueAt(ipkg); |
| 3484 | int wakeups = 0; |
| 3485 | final ArrayMap<String, ? extends Counter> alarms = ps.getWakeupAlarmStats(); |
| 3486 | for (int iwa=alarms.size()-1; iwa>=0; iwa--) { |
Joe Onorato | 1476d32 | 2016-05-05 14:46:15 -0700 | [diff] [blame] | 3487 | int count = alarms.valueAt(iwa).getCountLocked(which); |
| 3488 | wakeups += count; |
| 3489 | String name = alarms.keyAt(iwa).replace(',', '_'); |
| 3490 | dumpLine(pw, uid, category, WAKEUP_ALARM_DATA, name, count); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3491 | } |
| 3492 | final ArrayMap<String, ? extends Uid.Pkg.Serv> serviceStats = ps.getServiceStats(); |
| 3493 | for (int isvc=serviceStats.size()-1; isvc>=0; isvc--) { |
| 3494 | final BatteryStats.Uid.Pkg.Serv ss = serviceStats.valueAt(isvc); |
| 3495 | final long startTime = ss.getStartTime(batteryUptime, which); |
| 3496 | final int starts = ss.getStarts(which); |
| 3497 | final int launches = ss.getLaunches(which); |
| 3498 | if (startTime != 0 || starts != 0 || launches != 0) { |
| 3499 | dumpLine(pw, uid, category, APK_DATA, |
| 3500 | wakeups, // wakeup alarms |
| 3501 | packageStats.keyAt(ipkg), // Apk |
| 3502 | serviceStats.keyAt(isvc), // service |
| 3503 | startTime / 1000, // time spent started, in ms |
| 3504 | starts, |
| 3505 | launches); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3506 | } |
| 3507 | } |
| 3508 | } |
| 3509 | } |
| 3510 | } |
| 3511 | |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 3512 | static final class TimerEntry { |
| 3513 | final String mName; |
| 3514 | final int mId; |
| 3515 | final BatteryStats.Timer mTimer; |
| 3516 | final long mTime; |
| 3517 | TimerEntry(String name, int id, BatteryStats.Timer timer, long time) { |
| 3518 | mName = name; |
| 3519 | mId = id; |
| 3520 | mTimer = timer; |
| 3521 | mTime = time; |
| 3522 | } |
| 3523 | } |
| 3524 | |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3525 | private void printmAh(PrintWriter printer, double power) { |
| 3526 | printer.print(BatteryStatsHelper.makemAh(power)); |
| 3527 | } |
| 3528 | |
Adam Lesinski | a7a4ccc | 2015-06-26 17:43:04 -0700 | [diff] [blame] | 3529 | private void printmAh(StringBuilder sb, double power) { |
| 3530 | sb.append(BatteryStatsHelper.makemAh(power)); |
| 3531 | } |
| 3532 | |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 3533 | /** |
| 3534 | * Temporary for settings. |
| 3535 | */ |
| 3536 | public final void dumpLocked(Context context, PrintWriter pw, String prefix, int which, |
| 3537 | int reqUid) { |
| 3538 | dumpLocked(context, pw, prefix, which, reqUid, BatteryStatsHelper.checkWifiOnly(context)); |
| 3539 | } |
| 3540 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3541 | @SuppressWarnings("unused") |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3542 | 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] | 3543 | int reqUid, boolean wifiOnly) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3544 | final long rawUptime = SystemClock.uptimeMillis() * 1000; |
| 3545 | final long rawRealtime = SystemClock.elapsedRealtime() * 1000; |
| 3546 | final long batteryUptime = getBatteryUptime(rawUptime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3547 | |
| 3548 | final long whichBatteryUptime = computeBatteryUptime(rawUptime, which); |
| 3549 | final long whichBatteryRealtime = computeBatteryRealtime(rawRealtime, which); |
| 3550 | final long totalRealtime = computeRealtime(rawRealtime, which); |
| 3551 | final long totalUptime = computeUptime(rawUptime, which); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3552 | final long whichBatteryScreenOffUptime = computeBatteryScreenOffUptime(rawUptime, which); |
| 3553 | final long whichBatteryScreenOffRealtime = computeBatteryScreenOffRealtime(rawRealtime, |
| 3554 | which); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 3555 | final long batteryTimeRemaining = computeBatteryTimeRemaining(rawRealtime); |
| 3556 | final long chargeTimeRemaining = computeChargeTimeRemaining(rawRealtime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3557 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3558 | final StringBuilder sb = new StringBuilder(128); |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 3559 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3560 | final SparseArray<? extends Uid> uidStats = getUidStats(); |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 3561 | final int NU = uidStats.size(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3562 | |
Adam Lesinski | f9b20a9 | 2016-06-17 17:30:01 -0700 | [diff] [blame] | 3563 | final int estimatedBatteryCapacity = getEstimatedBatteryCapacity(); |
| 3564 | if (estimatedBatteryCapacity > 0) { |
| 3565 | sb.setLength(0); |
| 3566 | sb.append(prefix); |
| 3567 | sb.append(" Estimated battery capacity: "); |
| 3568 | sb.append(BatteryStatsHelper.makemAh(estimatedBatteryCapacity)); |
| 3569 | sb.append(" mAh"); |
| 3570 | pw.println(sb.toString()); |
| 3571 | } |
| 3572 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3573 | sb.setLength(0); |
| 3574 | sb.append(prefix); |
| 3575 | sb.append(" Time on battery: "); |
| 3576 | formatTimeMs(sb, whichBatteryRealtime / 1000); sb.append("("); |
| 3577 | sb.append(formatRatioLocked(whichBatteryRealtime, totalRealtime)); |
| 3578 | sb.append(") realtime, "); |
| 3579 | formatTimeMs(sb, whichBatteryUptime / 1000); |
| 3580 | sb.append("("); sb.append(formatRatioLocked(whichBatteryUptime, totalRealtime)); |
| 3581 | sb.append(") uptime"); |
| 3582 | pw.println(sb.toString()); |
| 3583 | sb.setLength(0); |
| 3584 | sb.append(prefix); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3585 | sb.append(" Time on battery screen off: "); |
| 3586 | formatTimeMs(sb, whichBatteryScreenOffRealtime / 1000); sb.append("("); |
| 3587 | sb.append(formatRatioLocked(whichBatteryScreenOffRealtime, totalRealtime)); |
| 3588 | sb.append(") realtime, "); |
| 3589 | formatTimeMs(sb, whichBatteryScreenOffUptime / 1000); |
| 3590 | sb.append("("); |
| 3591 | sb.append(formatRatioLocked(whichBatteryScreenOffUptime, totalRealtime)); |
| 3592 | sb.append(") uptime"); |
| 3593 | pw.println(sb.toString()); |
| 3594 | sb.setLength(0); |
| 3595 | sb.append(prefix); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3596 | sb.append(" Total run time: "); |
| 3597 | formatTimeMs(sb, totalRealtime / 1000); |
| 3598 | sb.append("realtime, "); |
| 3599 | formatTimeMs(sb, totalUptime / 1000); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 3600 | sb.append("uptime"); |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 3601 | pw.println(sb.toString()); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 3602 | if (batteryTimeRemaining >= 0) { |
| 3603 | sb.setLength(0); |
| 3604 | sb.append(prefix); |
| 3605 | sb.append(" Battery time remaining: "); |
| 3606 | formatTimeMs(sb, batteryTimeRemaining / 1000); |
| 3607 | pw.println(sb.toString()); |
| 3608 | } |
| 3609 | if (chargeTimeRemaining >= 0) { |
| 3610 | sb.setLength(0); |
| 3611 | sb.append(prefix); |
| 3612 | sb.append(" Charge time remaining: "); |
| 3613 | formatTimeMs(sb, chargeTimeRemaining / 1000); |
| 3614 | pw.println(sb.toString()); |
| 3615 | } |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 3616 | |
| 3617 | final LongCounter dischargeCounter = getDischargeCoulombCounter(); |
| 3618 | final long dischargeCount = dischargeCounter.getCountLocked(which); |
| 3619 | if (dischargeCount >= 0) { |
| 3620 | sb.setLength(0); |
| 3621 | sb.append(prefix); |
| 3622 | sb.append(" Discharge: "); |
| 3623 | sb.append(BatteryStatsHelper.makemAh(dischargeCount / 1000.0)); |
| 3624 | sb.append(" mAh"); |
| 3625 | pw.println(sb.toString()); |
| 3626 | } |
| 3627 | |
| 3628 | final LongCounter dischargeScreenOffCounter = getDischargeScreenOffCoulombCounter(); |
| 3629 | final long dischargeScreenOffCount = dischargeScreenOffCounter.getCountLocked(which); |
| 3630 | if (dischargeScreenOffCount >= 0) { |
| 3631 | sb.setLength(0); |
| 3632 | sb.append(prefix); |
| 3633 | sb.append(" Screen off discharge: "); |
| 3634 | sb.append(BatteryStatsHelper.makemAh(dischargeScreenOffCount / 1000.0)); |
| 3635 | sb.append(" mAh"); |
| 3636 | pw.println(sb.toString()); |
| 3637 | } |
| 3638 | |
| 3639 | final long dischargeScreenOnCount = dischargeCount - dischargeScreenOffCount; |
| 3640 | if (dischargeScreenOnCount >= 0) { |
| 3641 | sb.setLength(0); |
| 3642 | sb.append(prefix); |
| 3643 | sb.append(" Screen on discharge: "); |
| 3644 | sb.append(BatteryStatsHelper.makemAh(dischargeScreenOnCount / 1000.0)); |
| 3645 | sb.append(" mAh"); |
| 3646 | pw.println(sb.toString()); |
| 3647 | } |
| 3648 | |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 3649 | pw.print(" Start clock time: "); |
| 3650 | pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss", getStartClockTime()).toString()); |
| 3651 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3652 | final long screenOnTime = getScreenOnTime(rawRealtime, which); |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 3653 | final long interactiveTime = getInteractiveTime(rawRealtime, which); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3654 | final long powerSaveModeEnabledTime = getPowerSaveModeEnabledTime(rawRealtime, which); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3655 | final long deviceIdleModeLightTime = getDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT, |
| 3656 | rawRealtime, which); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 3657 | final long deviceIdleModeFullTime = getDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP, |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3658 | rawRealtime, which); |
| 3659 | final long deviceLightIdlingTime = getDeviceIdlingTime(DEVICE_IDLE_MODE_LIGHT, |
| 3660 | rawRealtime, which); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 3661 | final long deviceIdlingTime = getDeviceIdlingTime(DEVICE_IDLE_MODE_DEEP, |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3662 | rawRealtime, which); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3663 | final long phoneOnTime = getPhoneOnTime(rawRealtime, which); |
| 3664 | final long wifiRunningTime = getGlobalWifiRunningTime(rawRealtime, which); |
| 3665 | final long wifiOnTime = getWifiOnTime(rawRealtime, which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3666 | sb.setLength(0); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3667 | sb.append(prefix); |
| 3668 | sb.append(" Screen on: "); formatTimeMs(sb, screenOnTime / 1000); |
| 3669 | sb.append("("); sb.append(formatRatioLocked(screenOnTime, whichBatteryRealtime)); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 3670 | sb.append(") "); sb.append(getScreenOnCount(which)); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3671 | sb.append("x, Interactive: "); formatTimeMs(sb, interactiveTime / 1000); |
| 3672 | sb.append("("); sb.append(formatRatioLocked(interactiveTime, whichBatteryRealtime)); |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 3673 | sb.append(")"); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3674 | pw.println(sb.toString()); |
| 3675 | sb.setLength(0); |
| 3676 | sb.append(prefix); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 3677 | sb.append(" Screen brightnesses:"); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3678 | boolean didOne = false; |
| 3679 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3680 | final long time = getScreenBrightnessTime(i, rawRealtime, which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3681 | if (time == 0) { |
| 3682 | continue; |
| 3683 | } |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 3684 | sb.append("\n "); |
| 3685 | sb.append(prefix); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3686 | didOne = true; |
| 3687 | sb.append(SCREEN_BRIGHTNESS_NAMES[i]); |
| 3688 | sb.append(" "); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3689 | formatTimeMs(sb, time/1000); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3690 | sb.append("("); |
| 3691 | sb.append(formatRatioLocked(time, screenOnTime)); |
| 3692 | sb.append(")"); |
| 3693 | } |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 3694 | if (!didOne) sb.append(" (no activity)"); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3695 | pw.println(sb.toString()); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3696 | if (powerSaveModeEnabledTime != 0) { |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3697 | sb.setLength(0); |
| 3698 | sb.append(prefix); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3699 | sb.append(" Power save mode enabled: "); |
| 3700 | formatTimeMs(sb, powerSaveModeEnabledTime / 1000); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3701 | sb.append("("); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3702 | sb.append(formatRatioLocked(powerSaveModeEnabledTime, whichBatteryRealtime)); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3703 | sb.append(")"); |
| 3704 | pw.println(sb.toString()); |
| 3705 | } |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3706 | if (deviceLightIdlingTime != 0) { |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3707 | sb.setLength(0); |
| 3708 | sb.append(prefix); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3709 | sb.append(" Device light idling: "); |
| 3710 | formatTimeMs(sb, deviceLightIdlingTime / 1000); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 3711 | sb.append("("); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3712 | sb.append(formatRatioLocked(deviceLightIdlingTime, whichBatteryRealtime)); |
| 3713 | sb.append(") "); sb.append(getDeviceIdlingCount(DEVICE_IDLE_MODE_LIGHT, which)); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 3714 | sb.append("x"); |
| 3715 | pw.println(sb.toString()); |
| 3716 | } |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3717 | if (deviceIdleModeLightTime != 0) { |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 3718 | sb.setLength(0); |
| 3719 | sb.append(prefix); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3720 | sb.append(" Idle mode light time: "); |
| 3721 | formatTimeMs(sb, deviceIdleModeLightTime / 1000); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3722 | sb.append("("); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3723 | sb.append(formatRatioLocked(deviceIdleModeLightTime, whichBatteryRealtime)); |
| 3724 | sb.append(") "); |
| 3725 | sb.append(getDeviceIdleModeCount(DEVICE_IDLE_MODE_LIGHT, which)); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3726 | sb.append("x"); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3727 | sb.append(" -- longest "); |
| 3728 | formatTimeMs(sb, getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT)); |
| 3729 | pw.println(sb.toString()); |
| 3730 | } |
| 3731 | if (deviceIdlingTime != 0) { |
| 3732 | sb.setLength(0); |
| 3733 | sb.append(prefix); |
| 3734 | sb.append(" Device full idling: "); |
| 3735 | formatTimeMs(sb, deviceIdlingTime / 1000); |
| 3736 | sb.append("("); |
| 3737 | sb.append(formatRatioLocked(deviceIdlingTime, whichBatteryRealtime)); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 3738 | sb.append(") "); sb.append(getDeviceIdlingCount(DEVICE_IDLE_MODE_DEEP, which)); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3739 | sb.append("x"); |
| 3740 | pw.println(sb.toString()); |
| 3741 | } |
| 3742 | if (deviceIdleModeFullTime != 0) { |
| 3743 | sb.setLength(0); |
| 3744 | sb.append(prefix); |
| 3745 | sb.append(" Idle mode full time: "); |
| 3746 | formatTimeMs(sb, deviceIdleModeFullTime / 1000); |
| 3747 | sb.append("("); |
| 3748 | sb.append(formatRatioLocked(deviceIdleModeFullTime, whichBatteryRealtime)); |
| 3749 | sb.append(") "); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 3750 | sb.append(getDeviceIdleModeCount(DEVICE_IDLE_MODE_DEEP, which)); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3751 | sb.append("x"); |
| 3752 | sb.append(" -- longest "); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 3753 | formatTimeMs(sb, getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP)); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3754 | pw.println(sb.toString()); |
| 3755 | } |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3756 | if (phoneOnTime != 0) { |
| 3757 | sb.setLength(0); |
| 3758 | sb.append(prefix); |
| 3759 | sb.append(" Active phone call: "); formatTimeMs(sb, phoneOnTime / 1000); |
| 3760 | sb.append("("); sb.append(formatRatioLocked(phoneOnTime, whichBatteryRealtime)); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3761 | sb.append(") "); sb.append(getPhoneOnCount(which)); sb.append("x"); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3762 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3763 | final int connChanges = getNumConnectivityChange(which); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 3764 | if (connChanges != 0) { |
| 3765 | pw.print(prefix); |
| 3766 | pw.print(" Connectivity changes: "); pw.println(connChanges); |
| 3767 | } |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3768 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3769 | // Calculate wakelock times across all uids. |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 3770 | long fullWakeLockTimeTotalMicros = 0; |
| 3771 | long partialWakeLockTimeTotalMicros = 0; |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 3772 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3773 | final ArrayList<TimerEntry> timers = new ArrayList<>(); |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 3774 | |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 3775 | for (int iu = 0; iu < NU; iu++) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3776 | final Uid u = uidStats.valueAt(iu); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 3777 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3778 | final ArrayMap<String, ? extends BatteryStats.Uid.Wakelock> wakelocks |
| 3779 | = u.getWakelockStats(); |
| 3780 | for (int iw=wakelocks.size()-1; iw>=0; iw--) { |
| 3781 | final Uid.Wakelock wl = wakelocks.valueAt(iw); |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 3782 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3783 | final Timer fullWakeTimer = wl.getWakeTime(WAKE_TYPE_FULL); |
| 3784 | if (fullWakeTimer != null) { |
| 3785 | fullWakeLockTimeTotalMicros += fullWakeTimer.getTotalTimeLocked( |
| 3786 | rawRealtime, which); |
| 3787 | } |
| 3788 | |
| 3789 | final Timer partialWakeTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL); |
| 3790 | if (partialWakeTimer != null) { |
| 3791 | final long totalTimeMicros = partialWakeTimer.getTotalTimeLocked( |
| 3792 | rawRealtime, which); |
| 3793 | if (totalTimeMicros > 0) { |
| 3794 | if (reqUid < 0) { |
| 3795 | // Only show the ordered list of all wake |
| 3796 | // locks if the caller is not asking for data |
| 3797 | // about a specific uid. |
| 3798 | timers.add(new TimerEntry(wakelocks.keyAt(iw), u.getUid(), |
| 3799 | partialWakeTimer, totalTimeMicros)); |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 3800 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3801 | partialWakeLockTimeTotalMicros += totalTimeMicros; |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 3802 | } |
| 3803 | } |
| 3804 | } |
| 3805 | } |
| 3806 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3807 | final long mobileRxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which); |
| 3808 | final long mobileTxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which); |
| 3809 | final long wifiRxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which); |
| 3810 | final long wifiTxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which); |
| 3811 | final long mobileRxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which); |
| 3812 | final long mobileTxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which); |
| 3813 | final long wifiRxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which); |
| 3814 | final long wifiTxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which); |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 3815 | final long btRxTotalBytes = getNetworkActivityBytes(NETWORK_BT_RX_DATA, which); |
| 3816 | final long btTxTotalBytes = getNetworkActivityBytes(NETWORK_BT_TX_DATA, which); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3817 | |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 3818 | if (fullWakeLockTimeTotalMicros != 0) { |
| 3819 | sb.setLength(0); |
| 3820 | sb.append(prefix); |
| 3821 | sb.append(" Total full wakelock time: "); formatTimeMsNoSpace(sb, |
| 3822 | (fullWakeLockTimeTotalMicros + 500) / 1000); |
| 3823 | pw.println(sb.toString()); |
| 3824 | } |
| 3825 | |
| 3826 | if (partialWakeLockTimeTotalMicros != 0) { |
| 3827 | sb.setLength(0); |
| 3828 | sb.append(prefix); |
| 3829 | sb.append(" Total partial wakelock time: "); formatTimeMsNoSpace(sb, |
| 3830 | (partialWakeLockTimeTotalMicros + 500) / 1000); |
| 3831 | pw.println(sb.toString()); |
| 3832 | } |
| 3833 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3834 | pw.print(prefix); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3835 | pw.print(" Mobile total received: "); pw.print(formatBytesLocked(mobileRxTotalBytes)); |
| 3836 | pw.print(", sent: "); pw.print(formatBytesLocked(mobileTxTotalBytes)); |
| 3837 | pw.print(" (packets received "); pw.print(mobileRxTotalPackets); |
| 3838 | pw.print(", sent "); pw.print(mobileTxTotalPackets); pw.println(")"); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3839 | sb.setLength(0); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3840 | sb.append(prefix); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 3841 | sb.append(" Phone signal levels:"); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3842 | didOne = false; |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 3843 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3844 | final long time = getPhoneSignalStrengthTime(i, rawRealtime, which); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3845 | if (time == 0) { |
| 3846 | continue; |
| 3847 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3848 | sb.append("\n "); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 3849 | sb.append(prefix); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3850 | didOne = true; |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 3851 | sb.append(SignalStrength.SIGNAL_STRENGTH_NAMES[i]); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3852 | sb.append(" "); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3853 | formatTimeMs(sb, time/1000); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3854 | sb.append("("); |
| 3855 | sb.append(formatRatioLocked(time, whichBatteryRealtime)); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3856 | sb.append(") "); |
| 3857 | sb.append(getPhoneSignalStrengthCount(i, which)); |
| 3858 | sb.append("x"); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3859 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3860 | if (!didOne) sb.append(" (no activity)"); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3861 | pw.println(sb.toString()); |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 3862 | |
| 3863 | sb.setLength(0); |
| 3864 | sb.append(prefix); |
| 3865 | sb.append(" Signal scanning time: "); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3866 | formatTimeMsNoSpace(sb, getPhoneSignalScanningTime(rawRealtime, which) / 1000); |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 3867 | pw.println(sb.toString()); |
| 3868 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3869 | sb.setLength(0); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3870 | sb.append(prefix); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3871 | sb.append(" Radio types:"); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3872 | didOne = false; |
| 3873 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3874 | final long time = getPhoneDataConnectionTime(i, rawRealtime, which); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3875 | if (time == 0) { |
| 3876 | continue; |
| 3877 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3878 | sb.append("\n "); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 3879 | sb.append(prefix); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3880 | didOne = true; |
| 3881 | sb.append(DATA_CONNECTION_NAMES[i]); |
| 3882 | sb.append(" "); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3883 | formatTimeMs(sb, time/1000); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3884 | sb.append("("); |
| 3885 | sb.append(formatRatioLocked(time, whichBatteryRealtime)); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3886 | sb.append(") "); |
| 3887 | sb.append(getPhoneDataConnectionCount(i, which)); |
| 3888 | sb.append("x"); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3889 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3890 | if (!didOne) sb.append(" (no activity)"); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3891 | pw.println(sb.toString()); |
Amith Yamasani | 3f7e35c | 2009-07-13 16:02:45 -0700 | [diff] [blame] | 3892 | |
| 3893 | sb.setLength(0); |
| 3894 | sb.append(prefix); |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 3895 | sb.append(" Mobile radio active time: "); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3896 | final long mobileActiveTime = getMobileRadioActiveTime(rawRealtime, which); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 3897 | formatTimeMs(sb, mobileActiveTime / 1000); |
| 3898 | sb.append("("); sb.append(formatRatioLocked(mobileActiveTime, whichBatteryRealtime)); |
| 3899 | sb.append(") "); sb.append(getMobileRadioActiveCount(which)); |
| 3900 | sb.append("x"); |
Amith Yamasani | 3f7e35c | 2009-07-13 16:02:45 -0700 | [diff] [blame] | 3901 | pw.println(sb.toString()); |
| 3902 | |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 3903 | final long mobileActiveUnknownTime = getMobileRadioActiveUnknownTime(which); |
| 3904 | if (mobileActiveUnknownTime != 0) { |
| 3905 | sb.setLength(0); |
| 3906 | sb.append(prefix); |
| 3907 | sb.append(" Mobile radio active unknown time: "); |
| 3908 | formatTimeMs(sb, mobileActiveUnknownTime / 1000); |
| 3909 | sb.append("("); |
| 3910 | sb.append(formatRatioLocked(mobileActiveUnknownTime, whichBatteryRealtime)); |
| 3911 | sb.append(") "); sb.append(getMobileRadioActiveUnknownCount(which)); |
| 3912 | sb.append("x"); |
| 3913 | pw.println(sb.toString()); |
| 3914 | } |
| 3915 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3916 | final long mobileActiveAdjustedTime = getMobileRadioActiveAdjustedTime(which); |
| 3917 | if (mobileActiveAdjustedTime != 0) { |
| 3918 | sb.setLength(0); |
| 3919 | sb.append(prefix); |
| 3920 | sb.append(" Mobile radio active adjusted time: "); |
| 3921 | formatTimeMs(sb, mobileActiveAdjustedTime / 1000); |
| 3922 | sb.append("("); |
| 3923 | sb.append(formatRatioLocked(mobileActiveAdjustedTime, whichBatteryRealtime)); |
| 3924 | sb.append(")"); |
| 3925 | pw.println(sb.toString()); |
| 3926 | } |
| 3927 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3928 | printControllerActivity(pw, sb, prefix, "Radio", getModemControllerActivity(), which); |
| 3929 | |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 3930 | pw.print(prefix); |
| 3931 | pw.print(" Wi-Fi total received: "); pw.print(formatBytesLocked(wifiRxTotalBytes)); |
| 3932 | pw.print(", sent: "); pw.print(formatBytesLocked(wifiTxTotalBytes)); |
| 3933 | pw.print(" (packets received "); pw.print(wifiRxTotalPackets); |
| 3934 | pw.print(", sent "); pw.print(wifiTxTotalPackets); pw.println(")"); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3935 | sb.setLength(0); |
| 3936 | sb.append(prefix); |
| 3937 | sb.append(" Wifi on: "); formatTimeMs(sb, wifiOnTime / 1000); |
| 3938 | sb.append("("); sb.append(formatRatioLocked(wifiOnTime, whichBatteryRealtime)); |
| 3939 | sb.append("), Wifi running: "); formatTimeMs(sb, wifiRunningTime / 1000); |
| 3940 | sb.append("("); sb.append(formatRatioLocked(wifiRunningTime, whichBatteryRealtime)); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3941 | sb.append(")"); |
| 3942 | pw.println(sb.toString()); |
| 3943 | |
| 3944 | sb.setLength(0); |
| 3945 | sb.append(prefix); |
| 3946 | sb.append(" Wifi states:"); |
| 3947 | didOne = false; |
| 3948 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3949 | final long time = getWifiStateTime(i, rawRealtime, which); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3950 | if (time == 0) { |
| 3951 | continue; |
| 3952 | } |
| 3953 | sb.append("\n "); |
| 3954 | didOne = true; |
| 3955 | sb.append(WIFI_STATE_NAMES[i]); |
| 3956 | sb.append(" "); |
| 3957 | formatTimeMs(sb, time/1000); |
| 3958 | sb.append("("); |
| 3959 | sb.append(formatRatioLocked(time, whichBatteryRealtime)); |
| 3960 | sb.append(") "); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 3961 | sb.append(getWifiStateCount(i, which)); |
| 3962 | sb.append("x"); |
| 3963 | } |
| 3964 | if (!didOne) sb.append(" (no activity)"); |
| 3965 | pw.println(sb.toString()); |
| 3966 | |
| 3967 | sb.setLength(0); |
| 3968 | sb.append(prefix); |
| 3969 | sb.append(" Wifi supplicant states:"); |
| 3970 | didOne = false; |
| 3971 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
| 3972 | final long time = getWifiSupplStateTime(i, rawRealtime, which); |
| 3973 | if (time == 0) { |
| 3974 | continue; |
| 3975 | } |
| 3976 | sb.append("\n "); |
| 3977 | didOne = true; |
| 3978 | sb.append(WIFI_SUPPL_STATE_NAMES[i]); |
| 3979 | sb.append(" "); |
| 3980 | formatTimeMs(sb, time/1000); |
| 3981 | sb.append("("); |
| 3982 | sb.append(formatRatioLocked(time, whichBatteryRealtime)); |
| 3983 | sb.append(") "); |
| 3984 | sb.append(getWifiSupplStateCount(i, which)); |
| 3985 | sb.append("x"); |
| 3986 | } |
| 3987 | if (!didOne) sb.append(" (no activity)"); |
| 3988 | pw.println(sb.toString()); |
| 3989 | |
| 3990 | sb.setLength(0); |
| 3991 | sb.append(prefix); |
| 3992 | sb.append(" Wifi signal levels:"); |
| 3993 | didOne = false; |
| 3994 | for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 3995 | final long time = getWifiSignalStrengthTime(i, rawRealtime, which); |
| 3996 | if (time == 0) { |
| 3997 | continue; |
| 3998 | } |
| 3999 | sb.append("\n "); |
| 4000 | sb.append(prefix); |
| 4001 | didOne = true; |
| 4002 | sb.append("level("); |
| 4003 | sb.append(i); |
| 4004 | sb.append(") "); |
| 4005 | formatTimeMs(sb, time/1000); |
| 4006 | sb.append("("); |
| 4007 | sb.append(formatRatioLocked(time, whichBatteryRealtime)); |
| 4008 | sb.append(") "); |
| 4009 | sb.append(getWifiSignalStrengthCount(i, which)); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4010 | sb.append("x"); |
| 4011 | } |
| 4012 | if (!didOne) sb.append(" (no activity)"); |
| 4013 | pw.println(sb.toString()); |
| 4014 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 4015 | printControllerActivity(pw, sb, prefix, "WiFi", getWifiControllerActivity(), which); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 4016 | |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 4017 | pw.print(prefix); |
| 4018 | pw.print(" Bluetooth total received: "); pw.print(formatBytesLocked(btRxTotalBytes)); |
| 4019 | pw.print(", sent: "); pw.println(formatBytesLocked(btTxTotalBytes)); |
| 4020 | |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 4021 | final long bluetoothScanTimeMs = getBluetoothScanTime(rawRealtime, which) / 1000; |
| 4022 | sb.setLength(0); |
| 4023 | sb.append(prefix); |
| 4024 | sb.append(" Bluetooth scan time: "); formatTimeMs(sb, bluetoothScanTimeMs); |
| 4025 | pw.println(sb.toString()); |
| 4026 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 4027 | printControllerActivity(pw, sb, prefix, "Bluetooth", getBluetoothControllerActivity(), |
| 4028 | which); |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 4029 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4030 | pw.println(); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4031 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4032 | if (which == STATS_SINCE_UNPLUGGED) { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4033 | if (getIsOnBattery()) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4034 | pw.print(prefix); pw.println(" Device is currently unplugged"); |
| 4035 | pw.print(prefix); pw.print(" Discharge cycle start level: "); |
| 4036 | pw.println(getDischargeStartLevel()); |
| 4037 | pw.print(prefix); pw.print(" Discharge cycle current level: "); |
| 4038 | pw.println(getDischargeCurrentLevel()); |
Dianne Hackborn | 99d0452 | 2010-08-20 13:43:00 -0700 | [diff] [blame] | 4039 | } else { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4040 | pw.print(prefix); pw.println(" Device is currently plugged into power"); |
| 4041 | pw.print(prefix); pw.print(" Last discharge cycle start level: "); |
| 4042 | pw.println(getDischargeStartLevel()); |
| 4043 | pw.print(prefix); pw.print(" Last discharge cycle end level: "); |
| 4044 | pw.println(getDischargeCurrentLevel()); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4045 | } |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 4046 | pw.print(prefix); pw.print(" Amount discharged while screen on: "); |
| 4047 | pw.println(getDischargeAmountScreenOn()); |
| 4048 | pw.print(prefix); pw.print(" Amount discharged while screen off: "); |
| 4049 | pw.println(getDischargeAmountScreenOff()); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4050 | pw.println(" "); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4051 | } else { |
| 4052 | pw.print(prefix); pw.println(" Device battery use since last full charge"); |
| 4053 | pw.print(prefix); pw.print(" Amount discharged (lower bound): "); |
| 4054 | pw.println(getLowDischargeAmountSinceCharge()); |
| 4055 | pw.print(prefix); pw.print(" Amount discharged (upper bound): "); |
| 4056 | pw.println(getHighDischargeAmountSinceCharge()); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 4057 | pw.print(prefix); pw.print(" Amount discharged while screen on: "); |
| 4058 | pw.println(getDischargeAmountScreenOnSinceCharge()); |
| 4059 | pw.print(prefix); pw.print(" Amount discharged while screen off: "); |
| 4060 | pw.println(getDischargeAmountScreenOffSinceCharge()); |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 4061 | pw.println(); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4062 | } |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 4063 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4064 | final BatteryStatsHelper helper = new BatteryStatsHelper(context, false, wifiOnly); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4065 | helper.create(this); |
| 4066 | helper.refreshStats(which, UserHandle.USER_ALL); |
| 4067 | List<BatterySipper> sippers = helper.getUsageList(); |
| 4068 | if (sippers != null && sippers.size() > 0) { |
| 4069 | pw.print(prefix); pw.println(" Estimated power use (mAh):"); |
| 4070 | pw.print(prefix); pw.print(" Capacity: "); |
| 4071 | printmAh(pw, helper.getPowerProfile().getBatteryCapacity()); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4072 | pw.print(", Computed drain: "); printmAh(pw, helper.getComputedPower()); |
Dianne Hackborn | 536456f | 2014-05-23 16:51:05 -0700 | [diff] [blame] | 4073 | pw.print(", actual drain: "); printmAh(pw, helper.getMinDrainedPower()); |
| 4074 | if (helper.getMinDrainedPower() != helper.getMaxDrainedPower()) { |
| 4075 | pw.print("-"); printmAh(pw, helper.getMaxDrainedPower()); |
| 4076 | } |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4077 | pw.println(); |
| 4078 | for (int i=0; i<sippers.size(); i++) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4079 | final BatterySipper bs = sippers.get(i); |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4080 | pw.print(prefix); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4081 | switch (bs.drainType) { |
| 4082 | case IDLE: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4083 | pw.print(" Idle: "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4084 | break; |
| 4085 | case CELL: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4086 | pw.print(" Cell standby: "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4087 | break; |
| 4088 | case PHONE: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4089 | pw.print(" Phone calls: "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4090 | break; |
| 4091 | case WIFI: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4092 | pw.print(" Wifi: "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4093 | break; |
| 4094 | case BLUETOOTH: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4095 | pw.print(" Bluetooth: "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4096 | break; |
| 4097 | case SCREEN: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4098 | pw.print(" Screen: "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4099 | break; |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 4100 | case FLASHLIGHT: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4101 | pw.print(" Flashlight: "); |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 4102 | break; |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4103 | case APP: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4104 | pw.print(" Uid "); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4105 | UserHandle.formatUid(pw, bs.uidObj.getUid()); |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4106 | pw.print(": "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4107 | break; |
| 4108 | case USER: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4109 | pw.print(" User "); pw.print(bs.userId); |
| 4110 | pw.print(": "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4111 | break; |
| 4112 | case UNACCOUNTED: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4113 | pw.print(" Unaccounted: "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4114 | break; |
| 4115 | case OVERCOUNTED: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4116 | pw.print(" Over-counted: "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4117 | break; |
Ruben Brunk | 5b1308f | 2015-06-03 18:49:27 -0700 | [diff] [blame] | 4118 | case CAMERA: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4119 | pw.print(" Camera: "); |
| 4120 | break; |
| 4121 | default: |
| 4122 | pw.print(" ???: "); |
Ruben Brunk | 5b1308f | 2015-06-03 18:49:27 -0700 | [diff] [blame] | 4123 | break; |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4124 | } |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4125 | printmAh(pw, bs.totalPowerMah); |
| 4126 | |
Adam Lesinski | 5712300 | 2015-06-12 16:12:07 -0700 | [diff] [blame] | 4127 | if (bs.usagePowerMah != bs.totalPowerMah) { |
| 4128 | // If the usage (generic power) isn't the whole amount, we list out |
| 4129 | // what components are involved in the calculation. |
| 4130 | |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4131 | pw.print(" ("); |
Adam Lesinski | 5712300 | 2015-06-12 16:12:07 -0700 | [diff] [blame] | 4132 | if (bs.usagePowerMah != 0) { |
| 4133 | pw.print(" usage="); |
| 4134 | printmAh(pw, bs.usagePowerMah); |
| 4135 | } |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4136 | if (bs.cpuPowerMah != 0) { |
| 4137 | pw.print(" cpu="); |
| 4138 | printmAh(pw, bs.cpuPowerMah); |
| 4139 | } |
| 4140 | if (bs.wakeLockPowerMah != 0) { |
| 4141 | pw.print(" wake="); |
| 4142 | printmAh(pw, bs.wakeLockPowerMah); |
| 4143 | } |
| 4144 | if (bs.mobileRadioPowerMah != 0) { |
| 4145 | pw.print(" radio="); |
| 4146 | printmAh(pw, bs.mobileRadioPowerMah); |
| 4147 | } |
| 4148 | if (bs.wifiPowerMah != 0) { |
| 4149 | pw.print(" wifi="); |
| 4150 | printmAh(pw, bs.wifiPowerMah); |
| 4151 | } |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 4152 | if (bs.bluetoothPowerMah != 0) { |
| 4153 | pw.print(" bt="); |
| 4154 | printmAh(pw, bs.bluetoothPowerMah); |
| 4155 | } |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4156 | if (bs.gpsPowerMah != 0) { |
| 4157 | pw.print(" gps="); |
| 4158 | printmAh(pw, bs.gpsPowerMah); |
| 4159 | } |
| 4160 | if (bs.sensorPowerMah != 0) { |
| 4161 | pw.print(" sensor="); |
| 4162 | printmAh(pw, bs.sensorPowerMah); |
| 4163 | } |
| 4164 | if (bs.cameraPowerMah != 0) { |
| 4165 | pw.print(" camera="); |
| 4166 | printmAh(pw, bs.cameraPowerMah); |
| 4167 | } |
| 4168 | if (bs.flashlightPowerMah != 0) { |
| 4169 | pw.print(" flash="); |
| 4170 | printmAh(pw, bs.flashlightPowerMah); |
| 4171 | } |
| 4172 | pw.print(" )"); |
| 4173 | } |
| 4174 | pw.println(); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4175 | } |
Dianne Hackborn | c46809e | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4176 | pw.println(); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4177 | } |
| 4178 | |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4179 | sippers = helper.getMobilemsppList(); |
| 4180 | if (sippers != null && sippers.size() > 0) { |
| 4181 | pw.print(prefix); pw.println(" Per-app mobile ms per packet:"); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 4182 | long totalTime = 0; |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4183 | for (int i=0; i<sippers.size(); i++) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4184 | final BatterySipper bs = sippers.get(i); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4185 | sb.setLength(0); |
| 4186 | sb.append(prefix); sb.append(" Uid "); |
| 4187 | UserHandle.formatUid(sb, bs.uidObj.getUid()); |
| 4188 | sb.append(": "); sb.append(BatteryStatsHelper.makemAh(bs.mobilemspp)); |
| 4189 | sb.append(" ("); sb.append(bs.mobileRxPackets+bs.mobileTxPackets); |
| 4190 | sb.append(" packets over "); formatTimeMsNoSpace(sb, bs.mobileActive); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 4191 | sb.append(") "); sb.append(bs.mobileActiveCount); sb.append("x"); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4192 | pw.println(sb.toString()); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 4193 | totalTime += bs.mobileActive; |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4194 | } |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 4195 | sb.setLength(0); |
| 4196 | sb.append(prefix); |
| 4197 | sb.append(" TOTAL TIME: "); |
| 4198 | formatTimeMs(sb, totalTime); |
| 4199 | sb.append("("); sb.append(formatRatioLocked(totalTime, whichBatteryRealtime)); |
| 4200 | sb.append(")"); |
| 4201 | pw.println(sb.toString()); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4202 | pw.println(); |
| 4203 | } |
| 4204 | |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 4205 | final Comparator<TimerEntry> timerComparator = new Comparator<TimerEntry>() { |
| 4206 | @Override |
| 4207 | public int compare(TimerEntry lhs, TimerEntry rhs) { |
| 4208 | long lhsTime = lhs.mTime; |
| 4209 | long rhsTime = rhs.mTime; |
| 4210 | if (lhsTime < rhsTime) { |
| 4211 | return 1; |
| 4212 | } |
| 4213 | if (lhsTime > rhsTime) { |
| 4214 | return -1; |
| 4215 | } |
| 4216 | return 0; |
| 4217 | } |
| 4218 | }; |
| 4219 | |
| 4220 | if (reqUid < 0) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4221 | final Map<String, ? extends BatteryStats.Timer> kernelWakelocks |
| 4222 | = getKernelWakelockStats(); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 4223 | if (kernelWakelocks.size() > 0) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4224 | final ArrayList<TimerEntry> ktimers = new ArrayList<>(); |
| 4225 | for (Map.Entry<String, ? extends BatteryStats.Timer> ent |
| 4226 | : kernelWakelocks.entrySet()) { |
| 4227 | final BatteryStats.Timer timer = ent.getValue(); |
| 4228 | final long totalTimeMillis = computeWakeLock(timer, rawRealtime, which); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 4229 | if (totalTimeMillis > 0) { |
| 4230 | ktimers.add(new TimerEntry(ent.getKey(), 0, timer, totalTimeMillis)); |
| 4231 | } |
| 4232 | } |
| 4233 | if (ktimers.size() > 0) { |
| 4234 | Collections.sort(ktimers, timerComparator); |
| 4235 | pw.print(prefix); pw.println(" All kernel wake locks:"); |
| 4236 | for (int i=0; i<ktimers.size(); i++) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4237 | final TimerEntry timer = ktimers.get(i); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 4238 | String linePrefix = ": "; |
| 4239 | sb.setLength(0); |
| 4240 | sb.append(prefix); |
| 4241 | sb.append(" Kernel Wake lock "); |
| 4242 | sb.append(timer.mName); |
| 4243 | linePrefix = printWakeLock(sb, timer.mTimer, rawRealtime, null, |
| 4244 | which, linePrefix); |
| 4245 | if (!linePrefix.equals(": ")) { |
| 4246 | sb.append(" realtime"); |
| 4247 | // Only print out wake locks that were held |
| 4248 | pw.println(sb.toString()); |
| 4249 | } |
| 4250 | } |
| 4251 | pw.println(); |
| 4252 | } |
| 4253 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 4254 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 4255 | if (timers.size() > 0) { |
| 4256 | Collections.sort(timers, timerComparator); |
| 4257 | pw.print(prefix); pw.println(" All partial wake locks:"); |
| 4258 | for (int i=0; i<timers.size(); i++) { |
| 4259 | TimerEntry timer = timers.get(i); |
| 4260 | sb.setLength(0); |
| 4261 | sb.append(" Wake lock "); |
| 4262 | UserHandle.formatUid(sb, timer.mId); |
| 4263 | sb.append(" "); |
| 4264 | sb.append(timer.mName); |
| 4265 | printWakeLock(sb, timer.mTimer, rawRealtime, null, which, ": "); |
| 4266 | sb.append(" realtime"); |
| 4267 | pw.println(sb.toString()); |
| 4268 | } |
| 4269 | timers.clear(); |
| 4270 | pw.println(); |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 4271 | } |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 4272 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4273 | final Map<String, ? extends Timer> wakeupReasons = getWakeupReasonStats(); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 4274 | if (wakeupReasons.size() > 0) { |
| 4275 | pw.print(prefix); pw.println(" All wakeup reasons:"); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4276 | final ArrayList<TimerEntry> reasons = new ArrayList<>(); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 4277 | for (Map.Entry<String, ? extends Timer> ent : wakeupReasons.entrySet()) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4278 | final Timer timer = ent.getValue(); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 4279 | reasons.add(new TimerEntry(ent.getKey(), 0, timer, |
| 4280 | timer.getCountLocked(which))); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 4281 | } |
| 4282 | Collections.sort(reasons, timerComparator); |
| 4283 | for (int i=0; i<reasons.size(); i++) { |
| 4284 | TimerEntry timer = reasons.get(i); |
| 4285 | String linePrefix = ": "; |
| 4286 | sb.setLength(0); |
| 4287 | sb.append(prefix); |
| 4288 | sb.append(" Wakeup reason "); |
| 4289 | sb.append(timer.mName); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 4290 | printWakeLock(sb, timer.mTimer, rawRealtime, null, which, ": "); |
| 4291 | sb.append(" realtime"); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 4292 | pw.println(sb.toString()); |
| 4293 | } |
| 4294 | pw.println(); |
| 4295 | } |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 4296 | } |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 4297 | |
James Carr | 2dd7e5e | 2016-07-20 18:48:39 -0700 | [diff] [blame] | 4298 | final LongSparseArray<? extends Timer> mMemoryStats = getKernelMemoryStats(); |
| 4299 | pw.println("Memory Stats"); |
| 4300 | for (int i = 0; i < mMemoryStats.size(); i++) { |
| 4301 | sb.setLength(0); |
| 4302 | sb.append("Bandwidth "); |
| 4303 | sb.append(mMemoryStats.keyAt(i)); |
| 4304 | sb.append(" Time "); |
| 4305 | sb.append(mMemoryStats.valueAt(i).getTotalTimeLocked(rawRealtime, which)); |
| 4306 | pw.println(sb.toString()); |
| 4307 | } |
| 4308 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4309 | for (int iu=0; iu<NU; iu++) { |
| 4310 | final int uid = uidStats.keyAt(iu); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 4311 | if (reqUid >= 0 && uid != reqUid && uid != Process.SYSTEM_UID) { |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 4312 | continue; |
| 4313 | } |
| 4314 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4315 | final Uid u = uidStats.valueAt(iu); |
Dianne Hackborn | a4cc205 | 2013-07-08 17:31:25 -0700 | [diff] [blame] | 4316 | |
| 4317 | pw.print(prefix); |
| 4318 | pw.print(" "); |
| 4319 | UserHandle.formatUid(pw, uid); |
| 4320 | pw.println(":"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4321 | boolean uidActivity = false; |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4322 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4323 | final long mobileRxBytes = u.getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which); |
| 4324 | final long mobileTxBytes = u.getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which); |
| 4325 | final long wifiRxBytes = u.getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which); |
| 4326 | final long wifiTxBytes = u.getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which); |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 4327 | final long btRxBytes = u.getNetworkActivityBytes(NETWORK_BT_RX_DATA, which); |
| 4328 | final long btTxBytes = u.getNetworkActivityBytes(NETWORK_BT_TX_DATA, which); |
| 4329 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4330 | final long mobileRxPackets = u.getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which); |
| 4331 | final long mobileTxPackets = u.getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4332 | final long wifiRxPackets = u.getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which); |
| 4333 | final long wifiTxPackets = u.getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which); |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 4334 | |
| 4335 | final long uidMobileActiveTime = u.getMobileRadioActiveTime(which); |
| 4336 | final int uidMobileActiveCount = u.getMobileRadioActiveCount(which); |
| 4337 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4338 | final long fullWifiLockOnTime = u.getFullWifiLockTime(rawRealtime, which); |
| 4339 | final long wifiScanTime = u.getWifiScanTime(rawRealtime, which); |
| 4340 | final int wifiScanCount = u.getWifiScanCount(which); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame^] | 4341 | final int wifiScanCountBg = u.getWifiScanBackgroundCount(which); |
| 4342 | // 'actualTime' are unpooled and always since reset (regardless of 'which') |
| 4343 | final long wifiScanActualTime = u.getWifiScanActualTime(rawRealtime); |
| 4344 | final long wifiScanActualTimeBg = u.getWifiScanBackgroundTime(rawRealtime); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4345 | final long uidWifiRunningTime = u.getWifiRunningTime(rawRealtime, which); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 4346 | |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 4347 | final long mobileWakeup = u.getMobileRadioApWakeupCount(which); |
| 4348 | final long wifiWakeup = u.getWifiRadioApWakeupCount(which); |
| 4349 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4350 | if (mobileRxBytes > 0 || mobileTxBytes > 0 |
| 4351 | || mobileRxPackets > 0 || mobileTxPackets > 0) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 4352 | pw.print(prefix); pw.print(" Mobile network: "); |
| 4353 | pw.print(formatBytesLocked(mobileRxBytes)); pw.print(" received, "); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4354 | pw.print(formatBytesLocked(mobileTxBytes)); |
| 4355 | pw.print(" sent (packets "); pw.print(mobileRxPackets); |
| 4356 | pw.print(" received, "); pw.print(mobileTxPackets); pw.println(" sent)"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4357 | } |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4358 | if (uidMobileActiveTime > 0 || uidMobileActiveCount > 0) { |
| 4359 | sb.setLength(0); |
| 4360 | sb.append(prefix); sb.append(" Mobile radio active: "); |
| 4361 | formatTimeMs(sb, uidMobileActiveTime / 1000); |
| 4362 | sb.append("("); |
| 4363 | sb.append(formatRatioLocked(uidMobileActiveTime, mobileActiveTime)); |
| 4364 | sb.append(") "); sb.append(uidMobileActiveCount); sb.append("x"); |
| 4365 | long packets = mobileRxPackets + mobileTxPackets; |
| 4366 | if (packets == 0) { |
| 4367 | packets = 1; |
| 4368 | } |
| 4369 | sb.append(" @ "); |
| 4370 | sb.append(BatteryStatsHelper.makemAh(uidMobileActiveTime / 1000 / (double)packets)); |
| 4371 | sb.append(" mspp"); |
| 4372 | pw.println(sb.toString()); |
| 4373 | } |
| 4374 | |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 4375 | if (mobileWakeup > 0) { |
| 4376 | sb.setLength(0); |
| 4377 | sb.append(prefix); |
| 4378 | sb.append(" Mobile radio AP wakeups: "); |
| 4379 | sb.append(mobileWakeup); |
| 4380 | pw.println(sb.toString()); |
| 4381 | } |
| 4382 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 4383 | printControllerActivityIfInteresting(pw, sb, prefix + " ", "Modem", |
| 4384 | u.getModemControllerActivity(), which); |
| 4385 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4386 | if (wifiRxBytes > 0 || wifiTxBytes > 0 || wifiRxPackets > 0 || wifiTxPackets > 0) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 4387 | pw.print(prefix); pw.print(" Wi-Fi network: "); |
| 4388 | pw.print(formatBytesLocked(wifiRxBytes)); pw.print(" received, "); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4389 | pw.print(formatBytesLocked(wifiTxBytes)); |
| 4390 | pw.print(" sent (packets "); pw.print(wifiRxPackets); |
| 4391 | pw.print(" received, "); pw.print(wifiTxPackets); pw.println(" sent)"); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 4392 | } |
| 4393 | |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 4394 | if (fullWifiLockOnTime != 0 || wifiScanTime != 0 || wifiScanCount != 0 |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame^] | 4395 | || wifiScanCountBg != 0 || wifiScanActualTime != 0 || wifiScanActualTimeBg != 0 |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4396 | || uidWifiRunningTime != 0) { |
| 4397 | sb.setLength(0); |
| 4398 | sb.append(prefix); sb.append(" Wifi Running: "); |
| 4399 | formatTimeMs(sb, uidWifiRunningTime / 1000); |
| 4400 | sb.append("("); sb.append(formatRatioLocked(uidWifiRunningTime, |
| 4401 | whichBatteryRealtime)); sb.append(")\n"); |
| 4402 | sb.append(prefix); sb.append(" Full Wifi Lock: "); |
| 4403 | formatTimeMs(sb, fullWifiLockOnTime / 1000); |
| 4404 | sb.append("("); sb.append(formatRatioLocked(fullWifiLockOnTime, |
| 4405 | whichBatteryRealtime)); sb.append(")\n"); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame^] | 4406 | sb.append(prefix); sb.append(" Wifi Scan (blamed): "); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4407 | formatTimeMs(sb, wifiScanTime / 1000); |
| 4408 | sb.append("("); sb.append(formatRatioLocked(wifiScanTime, |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 4409 | whichBatteryRealtime)); sb.append(") "); |
| 4410 | sb.append(wifiScanCount); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame^] | 4411 | sb.append("x\n"); |
| 4412 | // actual and background times are unpooled and since reset (regardless of 'which') |
| 4413 | sb.append(prefix); sb.append(" Wifi Scan (actual): "); |
| 4414 | formatTimeMs(sb, wifiScanActualTime / 1000); |
| 4415 | sb.append("("); sb.append(formatRatioLocked(wifiScanActualTime, |
| 4416 | computeBatteryRealtime(rawRealtime, STATS_SINCE_CHARGED))); |
| 4417 | sb.append(") "); |
| 4418 | sb.append(wifiScanCount); |
| 4419 | sb.append("x\n"); |
| 4420 | sb.append(prefix); sb.append(" Background Wifi Scan: "); |
| 4421 | formatTimeMs(sb, wifiScanActualTimeBg / 1000); |
| 4422 | sb.append("("); sb.append(formatRatioLocked(wifiScanActualTimeBg, |
| 4423 | computeBatteryRealtime(rawRealtime, STATS_SINCE_CHARGED))); |
| 4424 | sb.append(") "); |
| 4425 | sb.append(wifiScanCountBg); |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 4426 | sb.append("x"); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4427 | pw.println(sb.toString()); |
| 4428 | } |
| 4429 | |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 4430 | if (wifiWakeup > 0) { |
| 4431 | sb.setLength(0); |
| 4432 | sb.append(prefix); |
| 4433 | sb.append(" WiFi AP wakeups: "); |
| 4434 | sb.append(wifiWakeup); |
| 4435 | pw.println(sb.toString()); |
| 4436 | } |
| 4437 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 4438 | printControllerActivityIfInteresting(pw, sb, prefix + " ", "WiFi", |
| 4439 | u.getWifiControllerActivity(), which); |
Adam Lesinski | 049c88b | 2015-05-28 11:38:12 -0700 | [diff] [blame] | 4440 | |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 4441 | if (btRxBytes > 0 || btTxBytes > 0) { |
| 4442 | pw.print(prefix); pw.print(" Bluetooth network: "); |
| 4443 | pw.print(formatBytesLocked(btRxBytes)); pw.print(" received, "); |
| 4444 | pw.print(formatBytesLocked(btTxBytes)); |
| 4445 | pw.println(" sent"); |
| 4446 | } |
| 4447 | |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame^] | 4448 | final Timer bleTimer = u.getBluetoothScanTimer(); |
| 4449 | if (bleTimer != null) { |
| 4450 | // Convert from microseconds to milliseconds with rounding |
| 4451 | final long totalTimeMs = (bleTimer.getTotalTimeLocked(rawRealtime, which) + 500) |
| 4452 | / 1000; |
| 4453 | if (totalTimeMs != 0) { |
| 4454 | final int count = bleTimer.getCountLocked(which); |
| 4455 | final Timer bleTimerBg = u.getBluetoothScanBackgroundTimer(); |
| 4456 | final int countBg = bleTimerBg != null ? bleTimerBg.getCountLocked(which) : 0; |
| 4457 | final long rawRealtimeMs = (rawRealtime + 500) / 1000; |
| 4458 | // 'actualTime' are unpooled and always since reset (regardless of 'which') |
| 4459 | final long actualTimeMs = bleTimer.getTotalDurationMsLocked(rawRealtimeMs); |
| 4460 | final long actualTimeMsBg = bleTimerBg != null ? |
| 4461 | bleTimerBg.getTotalDurationMsLocked(rawRealtimeMs) : 0; |
| 4462 | |
| 4463 | sb.setLength(0); |
| 4464 | sb.append(prefix); |
| 4465 | sb.append(" "); |
| 4466 | sb.append("Bluetooth Scan"); |
| 4467 | sb.append(": "); |
| 4468 | if (actualTimeMs != totalTimeMs) { |
| 4469 | formatTimeMs(sb, totalTimeMs); |
| 4470 | sb.append("blamed realtime, "); |
| 4471 | } |
| 4472 | formatTimeMs(sb, actualTimeMs); // since reset, regardless of 'which' |
| 4473 | sb.append("realtime ("); |
| 4474 | sb.append(count); |
| 4475 | sb.append(" times)"); |
| 4476 | if (bleTimer.isRunningLocked()) { |
| 4477 | sb.append(" (running)"); |
| 4478 | } |
| 4479 | if (actualTimeMsBg != 0 || countBg > 0) { |
| 4480 | sb.append(", "); |
| 4481 | formatTimeMs(sb, actualTimeMsBg); // since reset, regardless of 'which' |
| 4482 | sb.append("background ("); |
| 4483 | sb.append(countBg); |
| 4484 | sb.append(" times)"); |
| 4485 | } |
| 4486 | pw.println(sb.toString()); |
| 4487 | uidActivity = true; |
| 4488 | } |
| 4489 | } |
| 4490 | |
| 4491 | |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 4492 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4493 | if (u.hasUserActivity()) { |
| 4494 | boolean hasData = false; |
Raph Levien | 4c7a4a7 | 2012-08-03 14:32:39 -0700 | [diff] [blame] | 4495 | for (int i=0; i<Uid.NUM_USER_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4496 | final int val = u.getUserActivityCount(i, which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4497 | if (val != 0) { |
| 4498 | if (!hasData) { |
| 4499 | sb.setLength(0); |
| 4500 | sb.append(" User activity: "); |
| 4501 | hasData = true; |
| 4502 | } else { |
| 4503 | sb.append(", "); |
| 4504 | } |
| 4505 | sb.append(val); |
| 4506 | sb.append(" "); |
| 4507 | sb.append(Uid.USER_ACTIVITY_TYPES[i]); |
| 4508 | } |
| 4509 | } |
| 4510 | if (hasData) { |
| 4511 | pw.println(sb.toString()); |
| 4512 | } |
| 4513 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4514 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4515 | final ArrayMap<String, ? extends BatteryStats.Uid.Wakelock> wakelocks |
| 4516 | = u.getWakelockStats(); |
| 4517 | long totalFullWakelock = 0, totalPartialWakelock = 0, totalWindowWakelock = 0; |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 4518 | long totalDrawWakelock = 0; |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4519 | int countWakelock = 0; |
| 4520 | for (int iw=wakelocks.size()-1; iw>=0; iw--) { |
| 4521 | final Uid.Wakelock wl = wakelocks.valueAt(iw); |
| 4522 | String linePrefix = ": "; |
| 4523 | sb.setLength(0); |
| 4524 | sb.append(prefix); |
| 4525 | sb.append(" Wake lock "); |
| 4526 | sb.append(wakelocks.keyAt(iw)); |
| 4527 | linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_FULL), rawRealtime, |
| 4528 | "full", which, linePrefix); |
| 4529 | linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_PARTIAL), rawRealtime, |
| 4530 | "partial", which, linePrefix); |
| 4531 | linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_WINDOW), rawRealtime, |
| 4532 | "window", which, linePrefix); |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 4533 | linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_DRAW), rawRealtime, |
| 4534 | "draw", which, linePrefix); |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 4535 | sb.append(" realtime"); |
| 4536 | pw.println(sb.toString()); |
| 4537 | uidActivity = true; |
| 4538 | countWakelock++; |
| 4539 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4540 | totalFullWakelock += computeWakeLock(wl.getWakeTime(WAKE_TYPE_FULL), |
| 4541 | rawRealtime, which); |
| 4542 | totalPartialWakelock += computeWakeLock(wl.getWakeTime(WAKE_TYPE_PARTIAL), |
| 4543 | rawRealtime, which); |
| 4544 | totalWindowWakelock += computeWakeLock(wl.getWakeTime(WAKE_TYPE_WINDOW), |
| 4545 | rawRealtime, which); |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 4546 | totalDrawWakelock += computeWakeLock(wl.getWakeTime(WAKE_TYPE_DRAW), |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 4547 | rawRealtime, which); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 4548 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4549 | if (countWakelock > 1) { |
| 4550 | if (totalFullWakelock != 0 || totalPartialWakelock != 0 |
| 4551 | || totalWindowWakelock != 0) { |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 4552 | sb.setLength(0); |
| 4553 | sb.append(prefix); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4554 | sb.append(" TOTAL wake: "); |
| 4555 | boolean needComma = false; |
| 4556 | if (totalFullWakelock != 0) { |
| 4557 | needComma = true; |
| 4558 | formatTimeMs(sb, totalFullWakelock); |
| 4559 | sb.append("full"); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 4560 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4561 | if (totalPartialWakelock != 0) { |
| 4562 | if (needComma) { |
| 4563 | sb.append(", "); |
| 4564 | } |
| 4565 | needComma = true; |
| 4566 | formatTimeMs(sb, totalPartialWakelock); |
| 4567 | sb.append("partial"); |
| 4568 | } |
| 4569 | if (totalWindowWakelock != 0) { |
| 4570 | if (needComma) { |
| 4571 | sb.append(", "); |
| 4572 | } |
| 4573 | needComma = true; |
| 4574 | formatTimeMs(sb, totalWindowWakelock); |
| 4575 | sb.append("window"); |
| 4576 | } |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 4577 | if (totalDrawWakelock != 0) { |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 4578 | if (needComma) { |
| 4579 | sb.append(","); |
| 4580 | } |
| 4581 | needComma = true; |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 4582 | formatTimeMs(sb, totalDrawWakelock); |
| 4583 | sb.append("draw"); |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 4584 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4585 | sb.append(" realtime"); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 4586 | pw.println(sb.toString()); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 4587 | } |
| 4588 | } |
| 4589 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4590 | final ArrayMap<String, ? extends Timer> syncs = u.getSyncStats(); |
| 4591 | for (int isy=syncs.size()-1; isy>=0; isy--) { |
| 4592 | final Timer timer = syncs.valueAt(isy); |
| 4593 | // Convert from microseconds to milliseconds with rounding |
| 4594 | final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000; |
| 4595 | final int count = timer.getCountLocked(which); |
| 4596 | sb.setLength(0); |
| 4597 | sb.append(prefix); |
| 4598 | sb.append(" Sync "); |
| 4599 | sb.append(syncs.keyAt(isy)); |
| 4600 | sb.append(": "); |
| 4601 | if (totalTime != 0) { |
| 4602 | formatTimeMs(sb, totalTime); |
| 4603 | sb.append("realtime ("); |
| 4604 | sb.append(count); |
| 4605 | sb.append(" times)"); |
| 4606 | } else { |
| 4607 | sb.append("(not used)"); |
| 4608 | } |
| 4609 | pw.println(sb.toString()); |
| 4610 | uidActivity = true; |
| 4611 | } |
| 4612 | |
| 4613 | final ArrayMap<String, ? extends Timer> jobs = u.getJobStats(); |
| 4614 | for (int ij=jobs.size()-1; ij>=0; ij--) { |
| 4615 | final Timer timer = jobs.valueAt(ij); |
| 4616 | // Convert from microseconds to milliseconds with rounding |
| 4617 | final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000; |
| 4618 | final int count = timer.getCountLocked(which); |
| 4619 | sb.setLength(0); |
| 4620 | sb.append(prefix); |
| 4621 | sb.append(" Job "); |
| 4622 | sb.append(jobs.keyAt(ij)); |
| 4623 | sb.append(": "); |
| 4624 | if (totalTime != 0) { |
| 4625 | formatTimeMs(sb, totalTime); |
| 4626 | sb.append("realtime ("); |
| 4627 | sb.append(count); |
| 4628 | sb.append(" times)"); |
| 4629 | } else { |
| 4630 | sb.append("(not used)"); |
| 4631 | } |
| 4632 | pw.println(sb.toString()); |
| 4633 | uidActivity = true; |
| 4634 | } |
| 4635 | |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 4636 | uidActivity |= printTimer(pw, sb, u.getFlashlightTurnedOnTimer(), rawRealtime, which, |
| 4637 | prefix, "Flashlight"); |
| 4638 | uidActivity |= printTimer(pw, sb, u.getCameraTurnedOnTimer(), rawRealtime, which, |
| 4639 | prefix, "Camera"); |
| 4640 | uidActivity |= printTimer(pw, sb, u.getVideoTurnedOnTimer(), rawRealtime, which, |
| 4641 | prefix, "Video"); |
| 4642 | uidActivity |= printTimer(pw, sb, u.getAudioTurnedOnTimer(), rawRealtime, which, |
| 4643 | prefix, "Audio"); |
| 4644 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4645 | final SparseArray<? extends BatteryStats.Uid.Sensor> sensors = u.getSensorStats(); |
| 4646 | final int NSE = sensors.size(); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 4647 | for (int ise=0; ise<NSE; ise++) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4648 | final Uid.Sensor se = sensors.valueAt(ise); |
| 4649 | final int sensorNumber = sensors.keyAt(ise); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 4650 | sb.setLength(0); |
| 4651 | sb.append(prefix); |
| 4652 | sb.append(" Sensor "); |
| 4653 | int handle = se.getHandle(); |
| 4654 | if (handle == Uid.Sensor.GPS) { |
| 4655 | sb.append("GPS"); |
| 4656 | } else { |
| 4657 | sb.append(handle); |
| 4658 | } |
| 4659 | sb.append(": "); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4660 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4661 | final Timer timer = se.getSensorTime(); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 4662 | if (timer != null) { |
| 4663 | // Convert from microseconds to milliseconds with rounding |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame^] | 4664 | final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) |
| 4665 | / 1000; |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4666 | final int count = timer.getCountLocked(which); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame^] | 4667 | final Timer bgTimer = se.getSensorBackgroundTime(); |
| 4668 | final int bgCount = bgTimer != null ? bgTimer.getCountLocked(which) : 0; |
| 4669 | final long rawRealtimeMs = (rawRealtime + 500) / 1000; |
| 4670 | // 'actualTime' are unpooled and always since reset (regardless of 'which') |
| 4671 | final long actualTime = timer.getTotalDurationMsLocked(rawRealtimeMs); |
| 4672 | final long bgActualTime = bgTimer != null ? |
| 4673 | bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : 0; |
| 4674 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 4675 | //timer.logState(); |
| 4676 | if (totalTime != 0) { |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame^] | 4677 | if (actualTime != totalTime) { |
| 4678 | formatTimeMs(sb, totalTime); |
| 4679 | sb.append("blamed realtime, "); |
| 4680 | } |
| 4681 | |
| 4682 | formatTimeMs(sb, actualTime); // since reset, regardless of 'which' |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 4683 | sb.append("realtime ("); |
| 4684 | sb.append(count); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame^] | 4685 | sb.append(" times)"); |
| 4686 | |
| 4687 | if (bgActualTime != 0 || bgCount > 0) { |
Amith Yamasani | ab9ad19 | 2016-12-06 12:46:59 -0800 | [diff] [blame] | 4688 | sb.append(", "); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame^] | 4689 | formatTimeMs(sb, bgActualTime); // since reset, regardless of 'which' |
| 4690 | sb.append("background ("); |
Amith Yamasani | ab9ad19 | 2016-12-06 12:46:59 -0800 | [diff] [blame] | 4691 | sb.append(bgCount); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame^] | 4692 | sb.append(" times)"); |
Amith Yamasani | ab9ad19 | 2016-12-06 12:46:59 -0800 | [diff] [blame] | 4693 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4694 | } else { |
| 4695 | sb.append("(not used)"); |
| 4696 | } |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 4697 | } else { |
| 4698 | sb.append("(not used)"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4699 | } |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 4700 | |
| 4701 | pw.println(sb.toString()); |
| 4702 | uidActivity = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4703 | } |
| 4704 | |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 4705 | uidActivity |= printTimer(pw, sb, u.getVibratorOnTimer(), rawRealtime, which, prefix, |
| 4706 | "Vibrator"); |
| 4707 | uidActivity |= printTimer(pw, sb, u.getForegroundActivityTimer(), rawRealtime, which, |
| 4708 | prefix, "Foreground activities"); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 4709 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 4710 | long totalStateTime = 0; |
| 4711 | for (int ips=0; ips<Uid.NUM_PROCESS_STATE; ips++) { |
| 4712 | long time = u.getProcessStateTime(ips, rawRealtime, which); |
| 4713 | if (time > 0) { |
| 4714 | totalStateTime += time; |
| 4715 | sb.setLength(0); |
| 4716 | sb.append(prefix); |
| 4717 | sb.append(" "); |
| 4718 | sb.append(Uid.PROCESS_STATE_NAMES[ips]); |
| 4719 | sb.append(" for: "); |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 4720 | formatTimeMs(sb, (time + 500) / 1000); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 4721 | pw.println(sb.toString()); |
| 4722 | uidActivity = true; |
| 4723 | } |
| 4724 | } |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 4725 | if (totalStateTime > 0) { |
| 4726 | sb.setLength(0); |
| 4727 | sb.append(prefix); |
| 4728 | sb.append(" Total running: "); |
| 4729 | formatTimeMs(sb, (totalStateTime + 500) / 1000); |
| 4730 | pw.println(sb.toString()); |
| 4731 | } |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 4732 | |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 4733 | final long userCpuTimeUs = u.getUserCpuTimeUs(which); |
| 4734 | final long systemCpuTimeUs = u.getSystemCpuTimeUs(which); |
Adam Lesinski | a7a4ccc | 2015-06-26 17:43:04 -0700 | [diff] [blame] | 4735 | final long powerCpuMaUs = u.getCpuPowerMaUs(which); |
| 4736 | if (userCpuTimeUs > 0 || systemCpuTimeUs > 0 || powerCpuMaUs > 0) { |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 4737 | sb.setLength(0); |
| 4738 | sb.append(prefix); |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 4739 | sb.append(" Total cpu time: u="); |
| 4740 | formatTimeMs(sb, userCpuTimeUs / 1000); |
| 4741 | sb.append("s="); |
| 4742 | formatTimeMs(sb, systemCpuTimeUs / 1000); |
Adam Lesinski | a7a4ccc | 2015-06-26 17:43:04 -0700 | [diff] [blame] | 4743 | sb.append("p="); |
| 4744 | printmAh(sb, powerCpuMaUs / (1000.0 * 1000.0 * 60.0 * 60.0)); |
| 4745 | sb.append("mAh"); |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 4746 | pw.println(sb.toString()); |
| 4747 | } |
| 4748 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4749 | final ArrayMap<String, ? extends BatteryStats.Uid.Proc> processStats |
| 4750 | = u.getProcessStats(); |
| 4751 | for (int ipr=processStats.size()-1; ipr>=0; ipr--) { |
| 4752 | final Uid.Proc ps = processStats.valueAt(ipr); |
| 4753 | long userTime; |
| 4754 | long systemTime; |
| 4755 | long foregroundTime; |
| 4756 | int starts; |
| 4757 | int numExcessive; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4758 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4759 | userTime = ps.getUserTime(which); |
| 4760 | systemTime = ps.getSystemTime(which); |
| 4761 | foregroundTime = ps.getForegroundTime(which); |
| 4762 | starts = ps.getStarts(which); |
| 4763 | final int numCrashes = ps.getNumCrashes(which); |
| 4764 | final int numAnrs = ps.getNumAnrs(which); |
| 4765 | numExcessive = which == STATS_SINCE_CHARGED |
| 4766 | ? ps.countExcessivePowers() : 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4767 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4768 | if (userTime != 0 || systemTime != 0 || foregroundTime != 0 || starts != 0 |
| 4769 | || numExcessive != 0 || numCrashes != 0 || numAnrs != 0) { |
| 4770 | sb.setLength(0); |
| 4771 | sb.append(prefix); sb.append(" Proc "); |
| 4772 | sb.append(processStats.keyAt(ipr)); sb.append(":\n"); |
| 4773 | sb.append(prefix); sb.append(" CPU: "); |
| 4774 | formatTimeMs(sb, userTime); sb.append("usr + "); |
| 4775 | formatTimeMs(sb, systemTime); sb.append("krn ; "); |
| 4776 | formatTimeMs(sb, foregroundTime); sb.append("fg"); |
| 4777 | if (starts != 0 || numCrashes != 0 || numAnrs != 0) { |
| 4778 | sb.append("\n"); sb.append(prefix); sb.append(" "); |
| 4779 | boolean hasOne = false; |
| 4780 | if (starts != 0) { |
| 4781 | hasOne = true; |
| 4782 | sb.append(starts); sb.append(" starts"); |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 4783 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4784 | if (numCrashes != 0) { |
| 4785 | if (hasOne) { |
| 4786 | sb.append(", "); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4787 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4788 | hasOne = true; |
| 4789 | sb.append(numCrashes); sb.append(" crashes"); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4790 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4791 | if (numAnrs != 0) { |
| 4792 | if (hasOne) { |
| 4793 | sb.append(", "); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4794 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4795 | sb.append(numAnrs); sb.append(" anrs"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4796 | } |
| 4797 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4798 | pw.println(sb.toString()); |
| 4799 | for (int e=0; e<numExcessive; e++) { |
| 4800 | Uid.Proc.ExcessivePower ew = ps.getExcessivePower(e); |
| 4801 | if (ew != null) { |
| 4802 | pw.print(prefix); pw.print(" * Killed for "); |
| 4803 | if (ew.type == Uid.Proc.ExcessivePower.TYPE_WAKE) { |
| 4804 | pw.print("wake lock"); |
| 4805 | } else if (ew.type == Uid.Proc.ExcessivePower.TYPE_CPU) { |
| 4806 | pw.print("cpu"); |
| 4807 | } else { |
| 4808 | pw.print("unknown"); |
| 4809 | } |
| 4810 | pw.print(" use: "); |
| 4811 | TimeUtils.formatDuration(ew.usedTime, pw); |
| 4812 | pw.print(" over "); |
| 4813 | TimeUtils.formatDuration(ew.overTime, pw); |
| 4814 | if (ew.overTime != 0) { |
| 4815 | pw.print(" ("); |
| 4816 | pw.print((ew.usedTime*100)/ew.overTime); |
| 4817 | pw.println("%)"); |
| 4818 | } |
| 4819 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4820 | } |
| 4821 | uidActivity = true; |
| 4822 | } |
| 4823 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4824 | |
| 4825 | final ArrayMap<String, ? extends BatteryStats.Uid.Pkg> packageStats |
| 4826 | = u.getPackageStats(); |
| 4827 | for (int ipkg=packageStats.size()-1; ipkg>=0; ipkg--) { |
| 4828 | pw.print(prefix); pw.print(" Apk "); pw.print(packageStats.keyAt(ipkg)); |
| 4829 | pw.println(":"); |
| 4830 | boolean apkActivity = false; |
| 4831 | final Uid.Pkg ps = packageStats.valueAt(ipkg); |
| 4832 | final ArrayMap<String, ? extends Counter> alarms = ps.getWakeupAlarmStats(); |
| 4833 | for (int iwa=alarms.size()-1; iwa>=0; iwa--) { |
| 4834 | pw.print(prefix); pw.print(" Wakeup alarm "); |
| 4835 | pw.print(alarms.keyAt(iwa)); pw.print(": "); |
| 4836 | pw.print(alarms.valueAt(iwa).getCountLocked(which)); |
| 4837 | pw.println(" times"); |
| 4838 | apkActivity = true; |
| 4839 | } |
| 4840 | final ArrayMap<String, ? extends Uid.Pkg.Serv> serviceStats = ps.getServiceStats(); |
| 4841 | for (int isvc=serviceStats.size()-1; isvc>=0; isvc--) { |
| 4842 | final BatteryStats.Uid.Pkg.Serv ss = serviceStats.valueAt(isvc); |
| 4843 | final long startTime = ss.getStartTime(batteryUptime, which); |
| 4844 | final int starts = ss.getStarts(which); |
| 4845 | final int launches = ss.getLaunches(which); |
| 4846 | if (startTime != 0 || starts != 0 || launches != 0) { |
| 4847 | sb.setLength(0); |
| 4848 | sb.append(prefix); sb.append(" Service "); |
| 4849 | sb.append(serviceStats.keyAt(isvc)); sb.append(":\n"); |
| 4850 | sb.append(prefix); sb.append(" Created for: "); |
| 4851 | formatTimeMs(sb, startTime / 1000); |
| 4852 | sb.append("uptime\n"); |
| 4853 | sb.append(prefix); sb.append(" Starts: "); |
| 4854 | sb.append(starts); |
| 4855 | sb.append(", launches: "); sb.append(launches); |
| 4856 | pw.println(sb.toString()); |
| 4857 | apkActivity = true; |
| 4858 | } |
| 4859 | } |
| 4860 | if (!apkActivity) { |
| 4861 | pw.print(prefix); pw.println(" (nothing executed)"); |
| 4862 | } |
| 4863 | uidActivity = true; |
| 4864 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4865 | if (!uidActivity) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4866 | pw.print(prefix); pw.println(" (nothing executed)"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4867 | } |
| 4868 | } |
| 4869 | } |
| 4870 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 4871 | static void printBitDescriptions(PrintWriter pw, int oldval, int newval, HistoryTag wakelockTag, |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4872 | BitDescription[] descriptions, boolean longNames) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4873 | int diff = oldval ^ newval; |
| 4874 | if (diff == 0) return; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 4875 | boolean didWake = false; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4876 | for (int i=0; i<descriptions.length; i++) { |
| 4877 | BitDescription bd = descriptions[i]; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 4878 | if ((diff&bd.mask) != 0) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4879 | pw.print(longNames ? " " : ","); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4880 | if (bd.shift < 0) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 4881 | pw.print((newval&bd.mask) != 0 ? "+" : "-"); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4882 | pw.print(longNames ? bd.name : bd.shortName); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 4883 | if (bd.mask == HistoryItem.STATE_WAKE_LOCK_FLAG && wakelockTag != null) { |
| 4884 | didWake = true; |
| 4885 | pw.print("="); |
| 4886 | if (longNames) { |
| 4887 | UserHandle.formatUid(pw, wakelockTag.uid); |
| 4888 | pw.print(":\""); |
| 4889 | pw.print(wakelockTag.string); |
| 4890 | pw.print("\""); |
| 4891 | } else { |
| 4892 | pw.print(wakelockTag.poolIdx); |
| 4893 | } |
| 4894 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4895 | } else { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4896 | pw.print(longNames ? bd.name : bd.shortName); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4897 | pw.print("="); |
| 4898 | int val = (newval&bd.mask)>>bd.shift; |
| 4899 | if (bd.values != null && val >= 0 && val < bd.values.length) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4900 | pw.print(longNames? bd.values[val] : bd.shortValues[val]); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4901 | } else { |
| 4902 | pw.print(val); |
| 4903 | } |
| 4904 | } |
| 4905 | } |
| 4906 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 4907 | if (!didWake && wakelockTag != null) { |
Ashish Sharma | 81850c4 | 2014-05-05 13:57:07 -0700 | [diff] [blame] | 4908 | pw.print(longNames ? " wake_lock=" : ",w="); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 4909 | if (longNames) { |
| 4910 | UserHandle.formatUid(pw, wakelockTag.uid); |
| 4911 | pw.print(":\""); |
| 4912 | pw.print(wakelockTag.string); |
| 4913 | pw.print("\""); |
| 4914 | } else { |
| 4915 | pw.print(wakelockTag.poolIdx); |
| 4916 | } |
| 4917 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4918 | } |
| 4919 | |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 4920 | public void prepareForDumpLocked() { |
| 4921 | } |
| 4922 | |
| 4923 | public static class HistoryPrinter { |
| 4924 | int oldState = 0; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 4925 | int oldState2 = 0; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4926 | int oldLevel = -1; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 4927 | int oldStatus = -1; |
| 4928 | int oldHealth = -1; |
| 4929 | int oldPlug = -1; |
| 4930 | int oldTemp = -1; |
| 4931 | int oldVolt = -1; |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 4932 | int oldChargeMAh = -1; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4933 | long lastTime = -1; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 4934 | |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 4935 | void reset() { |
| 4936 | oldState = oldState2 = 0; |
| 4937 | oldLevel = -1; |
| 4938 | oldStatus = -1; |
| 4939 | oldHealth = -1; |
| 4940 | oldPlug = -1; |
| 4941 | oldTemp = -1; |
| 4942 | oldVolt = -1; |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 4943 | oldChargeMAh = -1; |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 4944 | } |
| 4945 | |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 4946 | public void printNextItem(PrintWriter pw, HistoryItem rec, long baseTime, boolean checkin, |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 4947 | boolean verbose) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4948 | if (!checkin) { |
| 4949 | pw.print(" "); |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 4950 | TimeUtils.formatDuration(rec.time - baseTime, pw, TimeUtils.HUNDRED_DAY_FIELD_LEN); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 4951 | pw.print(" ("); |
| 4952 | pw.print(rec.numReadInts); |
| 4953 | pw.print(") "); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4954 | } else { |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 4955 | pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(','); |
| 4956 | pw.print(HISTORY_DATA); pw.print(','); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4957 | if (lastTime < 0) { |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 4958 | pw.print(rec.time - baseTime); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4959 | } else { |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 4960 | pw.print(rec.time - lastTime); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4961 | } |
| 4962 | lastTime = rec.time; |
| 4963 | } |
| 4964 | if (rec.cmd == HistoryItem.CMD_START) { |
| 4965 | if (checkin) { |
| 4966 | pw.print(":"); |
| 4967 | } |
| 4968 | pw.println("START"); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 4969 | reset(); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 4970 | } else if (rec.cmd == HistoryItem.CMD_CURRENT_TIME |
| 4971 | || rec.cmd == HistoryItem.CMD_RESET) { |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 4972 | if (checkin) { |
| 4973 | pw.print(":"); |
| 4974 | } |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 4975 | if (rec.cmd == HistoryItem.CMD_RESET) { |
| 4976 | pw.print("RESET:"); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 4977 | reset(); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 4978 | } |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 4979 | pw.print("TIME:"); |
| 4980 | if (checkin) { |
| 4981 | pw.println(rec.currentTime); |
| 4982 | } else { |
| 4983 | pw.print(" "); |
| 4984 | pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss", |
| 4985 | rec.currentTime).toString()); |
| 4986 | } |
Dianne Hackborn | 29cd7f1 | 2015-01-08 10:37:05 -0800 | [diff] [blame] | 4987 | } else if (rec.cmd == HistoryItem.CMD_SHUTDOWN) { |
| 4988 | if (checkin) { |
| 4989 | pw.print(":"); |
| 4990 | } |
| 4991 | pw.println("SHUTDOWN"); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4992 | } else if (rec.cmd == HistoryItem.CMD_OVERFLOW) { |
| 4993 | if (checkin) { |
| 4994 | pw.print(":"); |
| 4995 | } |
| 4996 | pw.println("*OVERFLOW*"); |
| 4997 | } else { |
| 4998 | if (!checkin) { |
| 4999 | if (rec.batteryLevel < 10) pw.print("00"); |
| 5000 | else if (rec.batteryLevel < 100) pw.print("0"); |
| 5001 | pw.print(rec.batteryLevel); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 5002 | if (verbose) { |
| 5003 | pw.print(" "); |
| 5004 | if (rec.states < 0) ; |
| 5005 | else if (rec.states < 0x10) pw.print("0000000"); |
| 5006 | else if (rec.states < 0x100) pw.print("000000"); |
| 5007 | else if (rec.states < 0x1000) pw.print("00000"); |
| 5008 | else if (rec.states < 0x10000) pw.print("0000"); |
| 5009 | else if (rec.states < 0x100000) pw.print("000"); |
| 5010 | else if (rec.states < 0x1000000) pw.print("00"); |
| 5011 | else if (rec.states < 0x10000000) pw.print("0"); |
| 5012 | pw.print(Integer.toHexString(rec.states)); |
| 5013 | } |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5014 | } else { |
| 5015 | if (oldLevel != rec.batteryLevel) { |
| 5016 | oldLevel = rec.batteryLevel; |
| 5017 | pw.print(",Bl="); pw.print(rec.batteryLevel); |
| 5018 | } |
| 5019 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5020 | if (oldStatus != rec.batteryStatus) { |
| 5021 | oldStatus = rec.batteryStatus; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5022 | pw.print(checkin ? ",Bs=" : " status="); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5023 | switch (oldStatus) { |
| 5024 | case BatteryManager.BATTERY_STATUS_UNKNOWN: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5025 | pw.print(checkin ? "?" : "unknown"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5026 | break; |
| 5027 | case BatteryManager.BATTERY_STATUS_CHARGING: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5028 | pw.print(checkin ? "c" : "charging"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5029 | break; |
| 5030 | case BatteryManager.BATTERY_STATUS_DISCHARGING: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5031 | pw.print(checkin ? "d" : "discharging"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5032 | break; |
| 5033 | case BatteryManager.BATTERY_STATUS_NOT_CHARGING: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5034 | pw.print(checkin ? "n" : "not-charging"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5035 | break; |
| 5036 | case BatteryManager.BATTERY_STATUS_FULL: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5037 | pw.print(checkin ? "f" : "full"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5038 | break; |
| 5039 | default: |
| 5040 | pw.print(oldStatus); |
| 5041 | break; |
| 5042 | } |
| 5043 | } |
| 5044 | if (oldHealth != rec.batteryHealth) { |
| 5045 | oldHealth = rec.batteryHealth; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5046 | pw.print(checkin ? ",Bh=" : " health="); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5047 | switch (oldHealth) { |
| 5048 | case BatteryManager.BATTERY_HEALTH_UNKNOWN: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5049 | pw.print(checkin ? "?" : "unknown"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5050 | break; |
| 5051 | case BatteryManager.BATTERY_HEALTH_GOOD: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5052 | pw.print(checkin ? "g" : "good"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5053 | break; |
| 5054 | case BatteryManager.BATTERY_HEALTH_OVERHEAT: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5055 | pw.print(checkin ? "h" : "overheat"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5056 | break; |
| 5057 | case BatteryManager.BATTERY_HEALTH_DEAD: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5058 | pw.print(checkin ? "d" : "dead"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5059 | break; |
| 5060 | case BatteryManager.BATTERY_HEALTH_OVER_VOLTAGE: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5061 | pw.print(checkin ? "v" : "over-voltage"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5062 | break; |
| 5063 | case BatteryManager.BATTERY_HEALTH_UNSPECIFIED_FAILURE: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5064 | pw.print(checkin ? "f" : "failure"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5065 | break; |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 5066 | case BatteryManager.BATTERY_HEALTH_COLD: |
| 5067 | pw.print(checkin ? "c" : "cold"); |
| 5068 | break; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5069 | default: |
| 5070 | pw.print(oldHealth); |
| 5071 | break; |
| 5072 | } |
| 5073 | } |
| 5074 | if (oldPlug != rec.batteryPlugType) { |
| 5075 | oldPlug = rec.batteryPlugType; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5076 | pw.print(checkin ? ",Bp=" : " plug="); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5077 | switch (oldPlug) { |
| 5078 | case 0: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5079 | pw.print(checkin ? "n" : "none"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5080 | break; |
| 5081 | case BatteryManager.BATTERY_PLUGGED_AC: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5082 | pw.print(checkin ? "a" : "ac"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5083 | break; |
| 5084 | case BatteryManager.BATTERY_PLUGGED_USB: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5085 | pw.print(checkin ? "u" : "usb"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5086 | break; |
Brian Muramatsu | 37a37f4 | 2012-08-14 15:21:02 -0700 | [diff] [blame] | 5087 | case BatteryManager.BATTERY_PLUGGED_WIRELESS: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5088 | pw.print(checkin ? "w" : "wireless"); |
Brian Muramatsu | 37a37f4 | 2012-08-14 15:21:02 -0700 | [diff] [blame] | 5089 | break; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5090 | default: |
| 5091 | pw.print(oldPlug); |
| 5092 | break; |
| 5093 | } |
| 5094 | } |
| 5095 | if (oldTemp != rec.batteryTemperature) { |
| 5096 | oldTemp = rec.batteryTemperature; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5097 | pw.print(checkin ? ",Bt=" : " temp="); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5098 | pw.print(oldTemp); |
| 5099 | } |
| 5100 | if (oldVolt != rec.batteryVoltage) { |
| 5101 | oldVolt = rec.batteryVoltage; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5102 | pw.print(checkin ? ",Bv=" : " volt="); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5103 | pw.print(oldVolt); |
| 5104 | } |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 5105 | final int chargeMAh = rec.batteryChargeUAh / 1000; |
| 5106 | if (oldChargeMAh != chargeMAh) { |
| 5107 | oldChargeMAh = chargeMAh; |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 5108 | pw.print(checkin ? ",Bcc=" : " charge="); |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 5109 | pw.print(oldChargeMAh); |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 5110 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 5111 | printBitDescriptions(pw, oldState, rec.states, rec.wakelockTag, |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5112 | HISTORY_STATE_DESCRIPTIONS, !checkin); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 5113 | printBitDescriptions(pw, oldState2, rec.states2, null, |
| 5114 | HISTORY_STATE2_DESCRIPTIONS, !checkin); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 5115 | if (rec.wakeReasonTag != null) { |
| 5116 | if (checkin) { |
Dianne Hackborn | d06dcfd | 2014-05-02 13:49:30 -0700 | [diff] [blame] | 5117 | pw.print(",wr="); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 5118 | pw.print(rec.wakeReasonTag.poolIdx); |
| 5119 | } else { |
| 5120 | pw.print(" wake_reason="); |
| 5121 | pw.print(rec.wakeReasonTag.uid); |
| 5122 | pw.print(":\""); |
| 5123 | pw.print(rec.wakeReasonTag.string); |
| 5124 | pw.print("\""); |
| 5125 | } |
| 5126 | } |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 5127 | if (rec.eventCode != HistoryItem.EVENT_NONE) { |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 5128 | pw.print(checkin ? "," : " "); |
| 5129 | if ((rec.eventCode&HistoryItem.EVENT_FLAG_START) != 0) { |
| 5130 | pw.print("+"); |
| 5131 | } else if ((rec.eventCode&HistoryItem.EVENT_FLAG_FINISH) != 0) { |
| 5132 | pw.print("-"); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 5133 | } |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 5134 | String[] eventNames = checkin ? HISTORY_EVENT_CHECKIN_NAMES |
| 5135 | : HISTORY_EVENT_NAMES; |
| 5136 | int idx = rec.eventCode & ~(HistoryItem.EVENT_FLAG_START |
| 5137 | | HistoryItem.EVENT_FLAG_FINISH); |
| 5138 | if (idx >= 0 && idx < eventNames.length) { |
| 5139 | pw.print(eventNames[idx]); |
| 5140 | } else { |
| 5141 | pw.print(checkin ? "Ev" : "event"); |
| 5142 | pw.print(idx); |
| 5143 | } |
| 5144 | pw.print("="); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 5145 | if (checkin) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 5146 | pw.print(rec.eventTag.poolIdx); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 5147 | } else { |
Adam Lesinski | 041d917 | 2016-12-12 12:03:56 -0800 | [diff] [blame] | 5148 | pw.append(HISTORY_EVENT_INT_FORMATTERS[idx] |
| 5149 | .applyAsString(rec.eventTag.uid)); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 5150 | pw.print(":\""); |
| 5151 | pw.print(rec.eventTag.string); |
| 5152 | pw.print("\""); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 5153 | } |
| 5154 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5155 | pw.println(); |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 5156 | if (rec.stepDetails != null) { |
| 5157 | if (!checkin) { |
| 5158 | pw.print(" Details: cpu="); |
| 5159 | pw.print(rec.stepDetails.userTime); |
| 5160 | pw.print("u+"); |
| 5161 | pw.print(rec.stepDetails.systemTime); |
| 5162 | pw.print("s"); |
| 5163 | if (rec.stepDetails.appCpuUid1 >= 0) { |
| 5164 | pw.print(" ("); |
| 5165 | printStepCpuUidDetails(pw, rec.stepDetails.appCpuUid1, |
| 5166 | rec.stepDetails.appCpuUTime1, rec.stepDetails.appCpuSTime1); |
| 5167 | if (rec.stepDetails.appCpuUid2 >= 0) { |
| 5168 | pw.print(", "); |
| 5169 | printStepCpuUidDetails(pw, rec.stepDetails.appCpuUid2, |
| 5170 | rec.stepDetails.appCpuUTime2, rec.stepDetails.appCpuSTime2); |
| 5171 | } |
| 5172 | if (rec.stepDetails.appCpuUid3 >= 0) { |
| 5173 | pw.print(", "); |
| 5174 | printStepCpuUidDetails(pw, rec.stepDetails.appCpuUid3, |
| 5175 | rec.stepDetails.appCpuUTime3, rec.stepDetails.appCpuSTime3); |
| 5176 | } |
| 5177 | pw.print(')'); |
| 5178 | } |
| 5179 | pw.println(); |
| 5180 | pw.print(" /proc/stat="); |
| 5181 | pw.print(rec.stepDetails.statUserTime); |
| 5182 | pw.print(" usr, "); |
| 5183 | pw.print(rec.stepDetails.statSystemTime); |
| 5184 | pw.print(" sys, "); |
| 5185 | pw.print(rec.stepDetails.statIOWaitTime); |
| 5186 | pw.print(" io, "); |
| 5187 | pw.print(rec.stepDetails.statIrqTime); |
| 5188 | pw.print(" irq, "); |
| 5189 | pw.print(rec.stepDetails.statSoftIrqTime); |
| 5190 | pw.print(" sirq, "); |
| 5191 | pw.print(rec.stepDetails.statIdlTime); |
| 5192 | pw.print(" idle"); |
| 5193 | int totalRun = rec.stepDetails.statUserTime + rec.stepDetails.statSystemTime |
| 5194 | + rec.stepDetails.statIOWaitTime + rec.stepDetails.statIrqTime |
| 5195 | + rec.stepDetails.statSoftIrqTime; |
| 5196 | int total = totalRun + rec.stepDetails.statIdlTime; |
| 5197 | if (total > 0) { |
| 5198 | pw.print(" ("); |
| 5199 | float perc = ((float)totalRun) / ((float)total) * 100; |
| 5200 | pw.print(String.format("%.1f%%", perc)); |
| 5201 | pw.print(" of "); |
| 5202 | StringBuilder sb = new StringBuilder(64); |
| 5203 | formatTimeMsNoSpace(sb, total*10); |
| 5204 | pw.print(sb); |
| 5205 | pw.print(")"); |
| 5206 | } |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 5207 | pw.print(", PlatformIdleStat "); |
| 5208 | pw.print(rec.stepDetails.statPlatformIdleState); |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 5209 | pw.println(); |
| 5210 | } else { |
| 5211 | pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(','); |
| 5212 | pw.print(HISTORY_DATA); pw.print(",0,Dcpu="); |
| 5213 | pw.print(rec.stepDetails.userTime); |
| 5214 | pw.print(":"); |
| 5215 | pw.print(rec.stepDetails.systemTime); |
| 5216 | if (rec.stepDetails.appCpuUid1 >= 0) { |
| 5217 | printStepCpuUidCheckinDetails(pw, rec.stepDetails.appCpuUid1, |
| 5218 | rec.stepDetails.appCpuUTime1, rec.stepDetails.appCpuSTime1); |
| 5219 | if (rec.stepDetails.appCpuUid2 >= 0) { |
| 5220 | printStepCpuUidCheckinDetails(pw, rec.stepDetails.appCpuUid2, |
| 5221 | rec.stepDetails.appCpuUTime2, rec.stepDetails.appCpuSTime2); |
| 5222 | } |
| 5223 | if (rec.stepDetails.appCpuUid3 >= 0) { |
| 5224 | printStepCpuUidCheckinDetails(pw, rec.stepDetails.appCpuUid3, |
| 5225 | rec.stepDetails.appCpuUTime3, rec.stepDetails.appCpuSTime3); |
| 5226 | } |
| 5227 | } |
| 5228 | pw.println(); |
| 5229 | pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(','); |
| 5230 | pw.print(HISTORY_DATA); pw.print(",0,Dpst="); |
| 5231 | pw.print(rec.stepDetails.statUserTime); |
| 5232 | pw.print(','); |
| 5233 | pw.print(rec.stepDetails.statSystemTime); |
| 5234 | pw.print(','); |
| 5235 | pw.print(rec.stepDetails.statIOWaitTime); |
| 5236 | pw.print(','); |
| 5237 | pw.print(rec.stepDetails.statIrqTime); |
| 5238 | pw.print(','); |
| 5239 | pw.print(rec.stepDetails.statSoftIrqTime); |
| 5240 | pw.print(','); |
| 5241 | pw.print(rec.stepDetails.statIdlTime); |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 5242 | pw.print(','); |
Adam Lesinski | 8568d8f | 2016-07-15 18:13:23 -0700 | [diff] [blame] | 5243 | if (rec.stepDetails.statPlatformIdleState != null) { |
| 5244 | pw.print(rec.stepDetails.statPlatformIdleState); |
| 5245 | } |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 5246 | pw.println(); |
| 5247 | } |
| 5248 | } |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 5249 | oldState = rec.states; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 5250 | oldState2 = rec.states2; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5251 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5252 | } |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 5253 | |
| 5254 | private void printStepCpuUidDetails(PrintWriter pw, int uid, int utime, int stime) { |
| 5255 | UserHandle.formatUid(pw, uid); |
| 5256 | pw.print("="); |
| 5257 | pw.print(utime); |
| 5258 | pw.print("u+"); |
| 5259 | pw.print(stime); |
| 5260 | pw.print("s"); |
| 5261 | } |
| 5262 | |
| 5263 | private void printStepCpuUidCheckinDetails(PrintWriter pw, int uid, int utime, int stime) { |
| 5264 | pw.print('/'); |
| 5265 | pw.print(uid); |
| 5266 | pw.print(":"); |
| 5267 | pw.print(utime); |
| 5268 | pw.print(":"); |
| 5269 | pw.print(stime); |
| 5270 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5271 | } |
| 5272 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 5273 | private void printSizeValue(PrintWriter pw, long size) { |
| 5274 | float result = size; |
| 5275 | String suffix = ""; |
| 5276 | if (result >= 10*1024) { |
| 5277 | suffix = "KB"; |
| 5278 | result = result / 1024; |
| 5279 | } |
| 5280 | if (result >= 10*1024) { |
| 5281 | suffix = "MB"; |
| 5282 | result = result / 1024; |
| 5283 | } |
| 5284 | if (result >= 10*1024) { |
| 5285 | suffix = "GB"; |
| 5286 | result = result / 1024; |
| 5287 | } |
| 5288 | if (result >= 10*1024) { |
| 5289 | suffix = "TB"; |
| 5290 | result = result / 1024; |
| 5291 | } |
| 5292 | if (result >= 10*1024) { |
| 5293 | suffix = "PB"; |
| 5294 | result = result / 1024; |
| 5295 | } |
| 5296 | pw.print((int)result); |
| 5297 | pw.print(suffix); |
| 5298 | } |
| 5299 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 5300 | private static boolean dumpTimeEstimate(PrintWriter pw, String label1, String label2, |
| 5301 | String label3, long estimatedTime) { |
| 5302 | if (estimatedTime < 0) { |
Dianne Hackborn | ad6a99b | 2014-11-18 10:11:10 -0800 | [diff] [blame] | 5303 | return false; |
| 5304 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 5305 | pw.print(label1); |
| 5306 | pw.print(label2); |
| 5307 | pw.print(label3); |
Dianne Hackborn | ad6a99b | 2014-11-18 10:11:10 -0800 | [diff] [blame] | 5308 | StringBuilder sb = new StringBuilder(64); |
| 5309 | formatTimeMs(sb, estimatedTime); |
| 5310 | pw.print(sb); |
| 5311 | pw.println(); |
Dianne Hackborn | ad6a99b | 2014-11-18 10:11:10 -0800 | [diff] [blame] | 5312 | return true; |
| 5313 | } |
| 5314 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 5315 | private static boolean dumpDurationSteps(PrintWriter pw, String prefix, String header, |
| 5316 | LevelStepTracker steps, boolean checkin) { |
| 5317 | if (steps == null) { |
| 5318 | return false; |
| 5319 | } |
| 5320 | int count = steps.mNumStepDurations; |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 5321 | if (count <= 0) { |
| 5322 | return false; |
| 5323 | } |
| 5324 | if (!checkin) { |
| 5325 | pw.println(header); |
| 5326 | } |
Kweku Adams | 030980a | 2015-04-01 16:07:48 -0700 | [diff] [blame] | 5327 | String[] lineArgs = new String[5]; |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 5328 | for (int i=0; i<count; i++) { |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 5329 | long duration = steps.getDurationAt(i); |
| 5330 | int level = steps.getLevelAt(i); |
| 5331 | long initMode = steps.getInitModeAt(i); |
| 5332 | long modMode = steps.getModModeAt(i); |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 5333 | if (checkin) { |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 5334 | lineArgs[0] = Long.toString(duration); |
| 5335 | lineArgs[1] = Integer.toString(level); |
| 5336 | if ((modMode&STEP_LEVEL_MODE_SCREEN_STATE) == 0) { |
| 5337 | switch ((int)(initMode&STEP_LEVEL_MODE_SCREEN_STATE) + 1) { |
| 5338 | case Display.STATE_OFF: lineArgs[2] = "s-"; break; |
| 5339 | case Display.STATE_ON: lineArgs[2] = "s+"; break; |
| 5340 | case Display.STATE_DOZE: lineArgs[2] = "sd"; break; |
| 5341 | case Display.STATE_DOZE_SUSPEND: lineArgs[2] = "sds"; break; |
Kweku Adams | 030980a | 2015-04-01 16:07:48 -0700 | [diff] [blame] | 5342 | default: lineArgs[2] = "?"; break; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 5343 | } |
| 5344 | } else { |
| 5345 | lineArgs[2] = ""; |
| 5346 | } |
| 5347 | if ((modMode&STEP_LEVEL_MODE_POWER_SAVE) == 0) { |
| 5348 | lineArgs[3] = (initMode&STEP_LEVEL_MODE_POWER_SAVE) != 0 ? "p+" : "p-"; |
| 5349 | } else { |
| 5350 | lineArgs[3] = ""; |
| 5351 | } |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 5352 | if ((modMode&STEP_LEVEL_MODE_DEVICE_IDLE) == 0) { |
Kweku Adams | 030980a | 2015-04-01 16:07:48 -0700 | [diff] [blame] | 5353 | lineArgs[4] = (initMode&STEP_LEVEL_MODE_DEVICE_IDLE) != 0 ? "i+" : "i-"; |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 5354 | } else { |
Kweku Adams | 030980a | 2015-04-01 16:07:48 -0700 | [diff] [blame] | 5355 | lineArgs[4] = ""; |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 5356 | } |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 5357 | dumpLine(pw, 0 /* uid */, "i" /* category */, header, (Object[])lineArgs); |
| 5358 | } else { |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 5359 | pw.print(prefix); |
| 5360 | pw.print("#"); pw.print(i); pw.print(": "); |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 5361 | TimeUtils.formatDuration(duration, pw); |
| 5362 | pw.print(" to "); pw.print(level); |
| 5363 | boolean haveModes = false; |
| 5364 | if ((modMode&STEP_LEVEL_MODE_SCREEN_STATE) == 0) { |
| 5365 | pw.print(" ("); |
| 5366 | switch ((int)(initMode&STEP_LEVEL_MODE_SCREEN_STATE) + 1) { |
| 5367 | case Display.STATE_OFF: pw.print("screen-off"); break; |
| 5368 | case Display.STATE_ON: pw.print("screen-on"); break; |
| 5369 | case Display.STATE_DOZE: pw.print("screen-doze"); break; |
| 5370 | case Display.STATE_DOZE_SUSPEND: pw.print("screen-doze-suspend"); break; |
Kweku Adams | 030980a | 2015-04-01 16:07:48 -0700 | [diff] [blame] | 5371 | default: pw.print("screen-?"); break; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 5372 | } |
| 5373 | haveModes = true; |
| 5374 | } |
| 5375 | if ((modMode&STEP_LEVEL_MODE_POWER_SAVE) == 0) { |
| 5376 | pw.print(haveModes ? ", " : " ("); |
| 5377 | pw.print((initMode&STEP_LEVEL_MODE_POWER_SAVE) != 0 |
| 5378 | ? "power-save-on" : "power-save-off"); |
| 5379 | haveModes = true; |
| 5380 | } |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 5381 | if ((modMode&STEP_LEVEL_MODE_DEVICE_IDLE) == 0) { |
| 5382 | pw.print(haveModes ? ", " : " ("); |
| 5383 | pw.print((initMode&STEP_LEVEL_MODE_DEVICE_IDLE) != 0 |
| 5384 | ? "device-idle-on" : "device-idle-off"); |
| 5385 | haveModes = true; |
| 5386 | } |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 5387 | if (haveModes) { |
| 5388 | pw.print(")"); |
| 5389 | } |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 5390 | pw.println(); |
| 5391 | } |
| 5392 | } |
| 5393 | return true; |
| 5394 | } |
| 5395 | |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 5396 | public static final int DUMP_CHARGED_ONLY = 1<<1; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 5397 | public static final int DUMP_DAILY_ONLY = 1<<2; |
| 5398 | public static final int DUMP_HISTORY_ONLY = 1<<3; |
| 5399 | public static final int DUMP_INCLUDE_HISTORY = 1<<4; |
| 5400 | public static final int DUMP_VERBOSE = 1<<5; |
| 5401 | public static final int DUMP_DEVICE_WIFI_ONLY = 1<<6; |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 5402 | |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 5403 | private void dumpHistoryLocked(PrintWriter pw, int flags, long histStart, boolean checkin) { |
| 5404 | final HistoryPrinter hprinter = new HistoryPrinter(); |
| 5405 | final HistoryItem rec = new HistoryItem(); |
| 5406 | long lastTime = -1; |
| 5407 | long baseTime = -1; |
| 5408 | boolean printed = false; |
| 5409 | HistoryEventTracker tracker = null; |
| 5410 | while (getNextHistoryLocked(rec)) { |
| 5411 | lastTime = rec.time; |
| 5412 | if (baseTime < 0) { |
| 5413 | baseTime = lastTime; |
| 5414 | } |
| 5415 | if (rec.time >= histStart) { |
| 5416 | if (histStart >= 0 && !printed) { |
| 5417 | if (rec.cmd == HistoryItem.CMD_CURRENT_TIME |
Ashish Sharma | 6020071 | 2014-05-23 18:22:20 -0700 | [diff] [blame] | 5418 | || rec.cmd == HistoryItem.CMD_RESET |
Dianne Hackborn | 29cd7f1 | 2015-01-08 10:37:05 -0800 | [diff] [blame] | 5419 | || rec.cmd == HistoryItem.CMD_START |
| 5420 | || rec.cmd == HistoryItem.CMD_SHUTDOWN) { |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 5421 | printed = true; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 5422 | hprinter.printNextItem(pw, rec, baseTime, checkin, |
| 5423 | (flags&DUMP_VERBOSE) != 0); |
| 5424 | rec.cmd = HistoryItem.CMD_UPDATE; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 5425 | } else if (rec.currentTime != 0) { |
| 5426 | printed = true; |
| 5427 | byte cmd = rec.cmd; |
| 5428 | rec.cmd = HistoryItem.CMD_CURRENT_TIME; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 5429 | hprinter.printNextItem(pw, rec, baseTime, checkin, |
| 5430 | (flags&DUMP_VERBOSE) != 0); |
| 5431 | rec.cmd = cmd; |
| 5432 | } |
| 5433 | if (tracker != null) { |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 5434 | if (rec.cmd != HistoryItem.CMD_UPDATE) { |
| 5435 | hprinter.printNextItem(pw, rec, baseTime, checkin, |
| 5436 | (flags&DUMP_VERBOSE) != 0); |
| 5437 | rec.cmd = HistoryItem.CMD_UPDATE; |
| 5438 | } |
| 5439 | int oldEventCode = rec.eventCode; |
| 5440 | HistoryTag oldEventTag = rec.eventTag; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 5441 | rec.eventTag = new HistoryTag(); |
| 5442 | for (int i=0; i<HistoryItem.EVENT_COUNT; i++) { |
| 5443 | HashMap<String, SparseIntArray> active |
| 5444 | = tracker.getStateForEvent(i); |
| 5445 | if (active == null) { |
| 5446 | continue; |
| 5447 | } |
| 5448 | for (HashMap.Entry<String, SparseIntArray> ent |
| 5449 | : active.entrySet()) { |
| 5450 | SparseIntArray uids = ent.getValue(); |
| 5451 | for (int j=0; j<uids.size(); j++) { |
| 5452 | rec.eventCode = i; |
| 5453 | rec.eventTag.string = ent.getKey(); |
| 5454 | rec.eventTag.uid = uids.keyAt(j); |
| 5455 | rec.eventTag.poolIdx = uids.valueAt(j); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 5456 | hprinter.printNextItem(pw, rec, baseTime, checkin, |
| 5457 | (flags&DUMP_VERBOSE) != 0); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 5458 | rec.wakeReasonTag = null; |
| 5459 | rec.wakelockTag = null; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 5460 | } |
| 5461 | } |
| 5462 | } |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 5463 | rec.eventCode = oldEventCode; |
| 5464 | rec.eventTag = oldEventTag; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 5465 | tracker = null; |
| 5466 | } |
| 5467 | } |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 5468 | hprinter.printNextItem(pw, rec, baseTime, checkin, |
| 5469 | (flags&DUMP_VERBOSE) != 0); |
Dianne Hackborn | 536456f | 2014-05-23 16:51:05 -0700 | [diff] [blame] | 5470 | } else if (false && rec.eventCode != HistoryItem.EVENT_NONE) { |
| 5471 | // This is an attempt to aggregate the previous state and generate |
| 5472 | //Â fake events to reflect that state at the point where we start |
| 5473 | // 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] | 5474 | if (tracker == null) { |
| 5475 | tracker = new HistoryEventTracker(); |
| 5476 | } |
| 5477 | tracker.updateState(rec.eventCode, rec.eventTag.string, |
| 5478 | rec.eventTag.uid, rec.eventTag.poolIdx); |
| 5479 | } |
| 5480 | } |
| 5481 | if (histStart >= 0) { |
Dianne Hackborn | fc06413 | 2014-06-02 12:42:12 -0700 | [diff] [blame] | 5482 | commitCurrentHistoryBatchLocked(); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 5483 | pw.print(checkin ? "NEXT: " : " NEXT: "); pw.println(lastTime+1); |
| 5484 | } |
| 5485 | } |
| 5486 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 5487 | private void dumpDailyLevelStepSummary(PrintWriter pw, String prefix, String label, |
| 5488 | LevelStepTracker steps, StringBuilder tmpSb, int[] tmpOutInt) { |
| 5489 | if (steps == null) { |
| 5490 | return; |
| 5491 | } |
| 5492 | long timeRemaining = steps.computeTimeEstimate(0, 0, tmpOutInt); |
| 5493 | if (timeRemaining >= 0) { |
| 5494 | pw.print(prefix); pw.print(label); pw.print(" total time: "); |
| 5495 | tmpSb.setLength(0); |
| 5496 | formatTimeMs(tmpSb, timeRemaining); |
| 5497 | pw.print(tmpSb); |
| 5498 | pw.print(" (from "); pw.print(tmpOutInt[0]); |
| 5499 | pw.println(" steps)"); |
| 5500 | } |
| 5501 | for (int i=0; i< STEP_LEVEL_MODES_OF_INTEREST.length; i++) { |
| 5502 | long estimatedTime = steps.computeTimeEstimate(STEP_LEVEL_MODES_OF_INTEREST[i], |
| 5503 | STEP_LEVEL_MODE_VALUES[i], tmpOutInt); |
| 5504 | if (estimatedTime > 0) { |
| 5505 | pw.print(prefix); pw.print(label); pw.print(" "); |
| 5506 | pw.print(STEP_LEVEL_MODE_LABELS[i]); |
| 5507 | pw.print(" time: "); |
| 5508 | tmpSb.setLength(0); |
| 5509 | formatTimeMs(tmpSb, estimatedTime); |
| 5510 | pw.print(tmpSb); |
| 5511 | pw.print(" (from "); pw.print(tmpOutInt[0]); |
| 5512 | pw.println(" steps)"); |
| 5513 | } |
| 5514 | } |
| 5515 | } |
| 5516 | |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 5517 | private void dumpDailyPackageChanges(PrintWriter pw, String prefix, |
| 5518 | ArrayList<PackageChange> changes) { |
| 5519 | if (changes == null) { |
| 5520 | return; |
| 5521 | } |
| 5522 | pw.print(prefix); pw.println("Package changes:"); |
| 5523 | for (int i=0; i<changes.size(); i++) { |
| 5524 | PackageChange pc = changes.get(i); |
| 5525 | if (pc.mUpdate) { |
| 5526 | pw.print(prefix); pw.print(" Update "); pw.print(pc.mPackageName); |
| 5527 | pw.print(" vers="); pw.println(pc.mVersionCode); |
| 5528 | } else { |
| 5529 | pw.print(prefix); pw.print(" Uninstall "); pw.println(pc.mPackageName); |
| 5530 | } |
| 5531 | } |
| 5532 | } |
| 5533 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5534 | /** |
| 5535 | * Dumps a human-readable summary of the battery statistics to the given PrintWriter. |
| 5536 | * |
| 5537 | * @param pw a Printer to receive the dump output. |
| 5538 | */ |
| 5539 | @SuppressWarnings("unused") |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 5540 | 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] | 5541 | prepareForDumpLocked(); |
| 5542 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 5543 | final boolean filtering = (flags |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5544 | & (DUMP_HISTORY_ONLY|DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) != 0; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5545 | |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 5546 | if ((flags&DUMP_HISTORY_ONLY) != 0 || !filtering) { |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 5547 | final long historyTotalSize = getHistoryTotalSize(); |
| 5548 | final long historyUsedSize = getHistoryUsedSize(); |
| 5549 | if (startIteratingHistoryLocked()) { |
| 5550 | try { |
| 5551 | pw.print("Battery History ("); |
| 5552 | pw.print((100*historyUsedSize)/historyTotalSize); |
| 5553 | pw.print("% used, "); |
| 5554 | printSizeValue(pw, historyUsedSize); |
| 5555 | pw.print(" used of "); |
| 5556 | printSizeValue(pw, historyTotalSize); |
| 5557 | pw.print(", "); |
| 5558 | pw.print(getHistoryStringPoolSize()); |
| 5559 | pw.print(" strings using "); |
| 5560 | printSizeValue(pw, getHistoryStringPoolBytes()); |
| 5561 | pw.println("):"); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 5562 | dumpHistoryLocked(pw, flags, histStart, false); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 5563 | pw.println(); |
| 5564 | } finally { |
| 5565 | finishIteratingHistoryLocked(); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 5566 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 5567 | } |
| 5568 | |
| 5569 | if (startIteratingOldHistoryLocked()) { |
| 5570 | try { |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 5571 | final HistoryItem rec = new HistoryItem(); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 5572 | pw.println("Old battery History:"); |
| 5573 | HistoryPrinter hprinter = new HistoryPrinter(); |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 5574 | long baseTime = -1; |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 5575 | while (getNextOldHistoryLocked(rec)) { |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 5576 | if (baseTime < 0) { |
| 5577 | baseTime = rec.time; |
| 5578 | } |
| 5579 | hprinter.printNextItem(pw, rec, baseTime, false, (flags&DUMP_VERBOSE) != 0); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 5580 | } |
| 5581 | pw.println(); |
| 5582 | } finally { |
| 5583 | finishIteratingOldHistoryLocked(); |
| 5584 | } |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 5585 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5586 | } |
| 5587 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5588 | if (filtering && (flags&(DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) == 0) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 5589 | return; |
| 5590 | } |
| 5591 | |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 5592 | if (!filtering) { |
| 5593 | SparseArray<? extends Uid> uidStats = getUidStats(); |
| 5594 | final int NU = uidStats.size(); |
| 5595 | boolean didPid = false; |
| 5596 | long nowRealtime = SystemClock.elapsedRealtime(); |
| 5597 | for (int i=0; i<NU; i++) { |
| 5598 | Uid uid = uidStats.valueAt(i); |
| 5599 | SparseArray<? extends Uid.Pid> pids = uid.getPidStats(); |
| 5600 | if (pids != null) { |
| 5601 | for (int j=0; j<pids.size(); j++) { |
| 5602 | Uid.Pid pid = pids.valueAt(j); |
| 5603 | if (!didPid) { |
| 5604 | pw.println("Per-PID Stats:"); |
| 5605 | didPid = true; |
| 5606 | } |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 5607 | long time = pid.mWakeSumMs + (pid.mWakeNesting > 0 |
| 5608 | ? (nowRealtime - pid.mWakeStartMs) : 0); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 5609 | pw.print(" PID "); pw.print(pids.keyAt(j)); |
| 5610 | pw.print(" wake time: "); |
| 5611 | TimeUtils.formatDuration(time, pw); |
| 5612 | pw.println(""); |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 5613 | } |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 5614 | } |
| 5615 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 5616 | if (didPid) { |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 5617 | pw.println(); |
| 5618 | } |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 5619 | } |
| 5620 | |
| 5621 | if (!filtering || (flags&DUMP_CHARGED_ONLY) != 0) { |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 5622 | if (dumpDurationSteps(pw, " ", "Discharge step durations:", |
| 5623 | getDischargeLevelStepTracker(), false)) { |
Kweku Adams | b0449e0 | 2016-10-12 14:18:27 -0700 | [diff] [blame] | 5624 | long timeRemaining = computeBatteryTimeRemaining( |
| 5625 | SystemClock.elapsedRealtime() * 1000); |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 5626 | if (timeRemaining >= 0) { |
| 5627 | pw.print(" Estimated discharge time remaining: "); |
| 5628 | TimeUtils.formatDuration(timeRemaining / 1000, pw); |
| 5629 | pw.println(); |
| 5630 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 5631 | final LevelStepTracker steps = getDischargeLevelStepTracker(); |
| 5632 | for (int i=0; i< STEP_LEVEL_MODES_OF_INTEREST.length; i++) { |
| 5633 | dumpTimeEstimate(pw, " Estimated ", STEP_LEVEL_MODE_LABELS[i], " time: ", |
| 5634 | steps.computeTimeEstimate(STEP_LEVEL_MODES_OF_INTEREST[i], |
| 5635 | STEP_LEVEL_MODE_VALUES[i], null)); |
| 5636 | } |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 5637 | pw.println(); |
| 5638 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 5639 | if (dumpDurationSteps(pw, " ", "Charge step durations:", |
| 5640 | getChargeLevelStepTracker(), false)) { |
Kweku Adams | b0449e0 | 2016-10-12 14:18:27 -0700 | [diff] [blame] | 5641 | long timeRemaining = computeChargeTimeRemaining( |
| 5642 | SystemClock.elapsedRealtime() * 1000); |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 5643 | if (timeRemaining >= 0) { |
| 5644 | pw.print(" Estimated charge time remaining: "); |
| 5645 | TimeUtils.formatDuration(timeRemaining / 1000, pw); |
| 5646 | pw.println(); |
| 5647 | } |
| 5648 | pw.println(); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 5649 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 5650 | } |
| 5651 | if (!filtering || (flags&(DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) != 0) { |
| 5652 | pw.println("Daily stats:"); |
| 5653 | pw.print(" Current start time: "); |
| 5654 | pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss", |
| 5655 | getCurrentDailyStartTime()).toString()); |
| 5656 | pw.print(" Next min deadline: "); |
| 5657 | pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss", |
| 5658 | getNextMinDailyDeadline()).toString()); |
| 5659 | pw.print(" Next max deadline: "); |
| 5660 | pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss", |
| 5661 | getNextMaxDailyDeadline()).toString()); |
| 5662 | StringBuilder sb = new StringBuilder(64); |
| 5663 | int[] outInt = new int[1]; |
| 5664 | LevelStepTracker dsteps = getDailyDischargeLevelStepTracker(); |
| 5665 | LevelStepTracker csteps = getDailyChargeLevelStepTracker(); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 5666 | ArrayList<PackageChange> pkgc = getDailyPackageChanges(); |
| 5667 | if (dsteps.mNumStepDurations > 0 || csteps.mNumStepDurations > 0 || pkgc != null) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5668 | if ((flags&DUMP_DAILY_ONLY) != 0 || !filtering) { |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 5669 | if (dumpDurationSteps(pw, " ", " Current daily discharge step durations:", |
| 5670 | dsteps, false)) { |
| 5671 | dumpDailyLevelStepSummary(pw, " ", "Discharge", dsteps, |
| 5672 | sb, outInt); |
| 5673 | } |
| 5674 | if (dumpDurationSteps(pw, " ", " Current daily charge step durations:", |
| 5675 | csteps, false)) { |
| 5676 | dumpDailyLevelStepSummary(pw, " ", "Charge", csteps, |
| 5677 | sb, outInt); |
| 5678 | } |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 5679 | dumpDailyPackageChanges(pw, " ", pkgc); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 5680 | } else { |
| 5681 | pw.println(" Current daily steps:"); |
| 5682 | dumpDailyLevelStepSummary(pw, " ", "Discharge", dsteps, |
| 5683 | sb, outInt); |
| 5684 | dumpDailyLevelStepSummary(pw, " ", "Charge", csteps, |
| 5685 | sb, outInt); |
| 5686 | } |
| 5687 | } |
| 5688 | DailyItem dit; |
| 5689 | int curIndex = 0; |
| 5690 | while ((dit=getDailyItemLocked(curIndex)) != null) { |
| 5691 | curIndex++; |
| 5692 | if ((flags&DUMP_DAILY_ONLY) != 0) { |
| 5693 | pw.println(); |
| 5694 | } |
| 5695 | pw.print(" Daily from "); |
| 5696 | pw.print(DateFormat.format("yyyy-MM-dd-HH-mm-ss", dit.mStartTime).toString()); |
| 5697 | pw.print(" to "); |
| 5698 | pw.print(DateFormat.format("yyyy-MM-dd-HH-mm-ss", dit.mEndTime).toString()); |
| 5699 | pw.println(":"); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5700 | if ((flags&DUMP_DAILY_ONLY) != 0 || !filtering) { |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 5701 | if (dumpDurationSteps(pw, " ", |
| 5702 | " Discharge step durations:", dit.mDischargeSteps, false)) { |
| 5703 | dumpDailyLevelStepSummary(pw, " ", "Discharge", dit.mDischargeSteps, |
| 5704 | sb, outInt); |
| 5705 | } |
| 5706 | if (dumpDurationSteps(pw, " ", |
| 5707 | " Charge step durations:", dit.mChargeSteps, false)) { |
| 5708 | dumpDailyLevelStepSummary(pw, " ", "Charge", dit.mChargeSteps, |
| 5709 | sb, outInt); |
| 5710 | } |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 5711 | dumpDailyPackageChanges(pw, " ", dit.mPackageChanges); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 5712 | } else { |
| 5713 | dumpDailyLevelStepSummary(pw, " ", "Discharge", dit.mDischargeSteps, |
| 5714 | sb, outInt); |
| 5715 | dumpDailyLevelStepSummary(pw, " ", "Charge", dit.mChargeSteps, |
| 5716 | sb, outInt); |
| 5717 | } |
| 5718 | } |
| 5719 | pw.println(); |
| 5720 | } |
| 5721 | if (!filtering || (flags&DUMP_CHARGED_ONLY) != 0) { |
Jeff Sharkey | ec43a6b | 2013-04-30 13:33:18 -0700 | [diff] [blame] | 5722 | pw.println("Statistics since last charge:"); |
| 5723 | pw.println(" System starts: " + getStartCount() |
| 5724 | + ", currently on battery: " + getIsOnBattery()); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 5725 | dumpLocked(context, pw, "", STATS_SINCE_CHARGED, reqUid, |
| 5726 | (flags&DUMP_DEVICE_WIFI_ONLY) != 0); |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 5727 | pw.println(); |
Jeff Sharkey | ec43a6b | 2013-04-30 13:33:18 -0700 | [diff] [blame] | 5728 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5729 | } |
| 5730 | |
| 5731 | @SuppressWarnings("unused") |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 5732 | public void dumpCheckinLocked(Context context, PrintWriter pw, |
| 5733 | List<ApplicationInfo> apps, int flags, long histStart) { |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5734 | prepareForDumpLocked(); |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 5735 | |
| 5736 | dumpLine(pw, 0 /* uid */, "i" /* category */, VERSION_DATA, |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 5737 | CHECKIN_VERSION, getParcelVersion(), getStartPlatformVersion(), |
| 5738 | getEndPlatformVersion()); |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 5739 | |
Dianne Hackborn | 13ac041 | 2013-06-25 19:34:49 -0700 | [diff] [blame] | 5740 | long now = getHistoryBaseTime() + SystemClock.elapsedRealtime(); |
| 5741 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 5742 | final boolean filtering = (flags & |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5743 | (DUMP_HISTORY_ONLY|DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) != 0; |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 5744 | |
| 5745 | if ((flags&DUMP_INCLUDE_HISTORY) != 0 || (flags&DUMP_HISTORY_ONLY) != 0) { |
Dianne Hackborn | 49021f5 | 2013-09-04 18:03:40 -0700 | [diff] [blame] | 5746 | if (startIteratingHistoryLocked()) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 5747 | try { |
| 5748 | for (int i=0; i<getHistoryStringPoolSize(); i++) { |
| 5749 | pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(','); |
| 5750 | pw.print(HISTORY_STRING_POOL); pw.print(','); |
| 5751 | pw.print(i); |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 5752 | pw.print(","); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 5753 | pw.print(getHistoryTagPoolUid(i)); |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 5754 | pw.print(",\""); |
| 5755 | String str = getHistoryTagPoolString(i); |
| 5756 | str = str.replace("\\", "\\\\"); |
| 5757 | str = str.replace("\"", "\\\""); |
| 5758 | pw.print(str); |
| 5759 | pw.print("\""); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 5760 | pw.println(); |
| 5761 | } |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 5762 | dumpHistoryLocked(pw, flags, histStart, true); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 5763 | } finally { |
| 5764 | finishIteratingHistoryLocked(); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 5765 | } |
Dianne Hackborn | 13ac041 | 2013-06-25 19:34:49 -0700 | [diff] [blame] | 5766 | } |
Dianne Hackborn | 13ac041 | 2013-06-25 19:34:49 -0700 | [diff] [blame] | 5767 | } |
| 5768 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5769 | if (filtering && (flags&(DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) == 0) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 5770 | return; |
| 5771 | } |
| 5772 | |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 5773 | if (apps != null) { |
Dianne Hackborn | 9cfba35 | 2016-03-24 17:31:28 -0700 | [diff] [blame] | 5774 | SparseArray<Pair<ArrayList<String>, MutableBoolean>> uids = new SparseArray<>(); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 5775 | for (int i=0; i<apps.size(); i++) { |
| 5776 | ApplicationInfo ai = apps.get(i); |
Dianne Hackborn | 9cfba35 | 2016-03-24 17:31:28 -0700 | [diff] [blame] | 5777 | Pair<ArrayList<String>, MutableBoolean> pkgs = uids.get( |
| 5778 | UserHandle.getAppId(ai.uid)); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 5779 | if (pkgs == null) { |
Dianne Hackborn | 9cfba35 | 2016-03-24 17:31:28 -0700 | [diff] [blame] | 5780 | pkgs = new Pair<>(new ArrayList<String>(), new MutableBoolean(false)); |
| 5781 | uids.put(UserHandle.getAppId(ai.uid), pkgs); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 5782 | } |
Dianne Hackborn | 9cfba35 | 2016-03-24 17:31:28 -0700 | [diff] [blame] | 5783 | pkgs.first.add(ai.packageName); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 5784 | } |
| 5785 | SparseArray<? extends Uid> uidStats = getUidStats(); |
| 5786 | final int NU = uidStats.size(); |
| 5787 | String[] lineArgs = new String[2]; |
| 5788 | for (int i=0; i<NU; i++) { |
Dianne Hackborn | 9cfba35 | 2016-03-24 17:31:28 -0700 | [diff] [blame] | 5789 | int uid = UserHandle.getAppId(uidStats.keyAt(i)); |
| 5790 | Pair<ArrayList<String>, MutableBoolean> pkgs = uids.get(uid); |
| 5791 | if (pkgs != null && !pkgs.second.value) { |
| 5792 | pkgs.second.value = true; |
| 5793 | for (int j=0; j<pkgs.first.size(); j++) { |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 5794 | lineArgs[0] = Integer.toString(uid); |
Dianne Hackborn | 9cfba35 | 2016-03-24 17:31:28 -0700 | [diff] [blame] | 5795 | lineArgs[1] = pkgs.first.get(j); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 5796 | dumpLine(pw, 0 /* uid */, "i" /* category */, UID_DATA, |
| 5797 | (Object[])lineArgs); |
| 5798 | } |
| 5799 | } |
| 5800 | } |
| 5801 | } |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 5802 | if (!filtering || (flags&DUMP_CHARGED_ONLY) != 0) { |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 5803 | dumpDurationSteps(pw, "", DISCHARGE_STEP_DATA, getDischargeLevelStepTracker(), true); |
Dianne Hackborn | d06dcfd | 2014-05-02 13:49:30 -0700 | [diff] [blame] | 5804 | String[] lineArgs = new String[1]; |
Kweku Adams | b0449e0 | 2016-10-12 14:18:27 -0700 | [diff] [blame] | 5805 | long timeRemaining = computeBatteryTimeRemaining(SystemClock.elapsedRealtime() * 1000); |
Dianne Hackborn | d06dcfd | 2014-05-02 13:49:30 -0700 | [diff] [blame] | 5806 | if (timeRemaining >= 0) { |
| 5807 | lineArgs[0] = Long.toString(timeRemaining); |
| 5808 | dumpLine(pw, 0 /* uid */, "i" /* category */, DISCHARGE_TIME_REMAIN_DATA, |
| 5809 | (Object[])lineArgs); |
| 5810 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 5811 | dumpDurationSteps(pw, "", CHARGE_STEP_DATA, getChargeLevelStepTracker(), true); |
Kweku Adams | b0449e0 | 2016-10-12 14:18:27 -0700 | [diff] [blame] | 5812 | timeRemaining = computeChargeTimeRemaining(SystemClock.elapsedRealtime() * 1000); |
Dianne Hackborn | d06dcfd | 2014-05-02 13:49:30 -0700 | [diff] [blame] | 5813 | if (timeRemaining >= 0) { |
| 5814 | lineArgs[0] = Long.toString(timeRemaining); |
| 5815 | dumpLine(pw, 0 /* uid */, "i" /* category */, CHARGE_TIME_REMAIN_DATA, |
| 5816 | (Object[])lineArgs); |
| 5817 | } |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 5818 | dumpCheckinLocked(context, pw, STATS_SINCE_CHARGED, -1, |
| 5819 | (flags&DUMP_DEVICE_WIFI_ONLY) != 0); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 5820 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5821 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5822 | } |