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 | /** |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame^] | 160 | * A constant indicating an aggregated partial wake lock timer. |
| 161 | */ |
| 162 | public static final int AGGREGATED_WAKE_TYPE_PARTIAL = 20; |
| 163 | |
| 164 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 165 | * Include all of the data in the stats, including previously saved data. |
| 166 | */ |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 167 | public static final int STATS_SINCE_CHARGED = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 168 | |
| 169 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 170 | * Include only the current run in the stats. |
| 171 | */ |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 172 | public static final int STATS_CURRENT = 1; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 173 | |
| 174 | /** |
| 175 | * Include only the run since the last time the device was unplugged in the stats. |
| 176 | */ |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 177 | public static final int STATS_SINCE_UNPLUGGED = 2; |
Evan Millar | e84de8d | 2009-04-02 22:16:12 -0700 | [diff] [blame] | 178 | |
| 179 | // NOTE: Update this list if you add/change any stats above. |
| 180 | // These characters are supposed to represent "total", "last", "current", |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 181 | // and "unplugged". They were shortened for efficiency sake. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 182 | private static final String[] STAT_NAMES = { "l", "c", "u" }; |
| 183 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 184 | /** |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 185 | * Current version of checkin data format. |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 186 | * |
| 187 | * New in version 19: |
| 188 | * - Wakelock data (wl) gets current and max times. |
Amith Yamasani | ab9ad19 | 2016-12-06 12:46:59 -0800 | [diff] [blame] | 189 | * New in version 20: |
Bookatz | 2bffb5b | 2017-04-13 11:59:33 -0700 | [diff] [blame] | 190 | * - Background timers and counters for: Sensor, BluetoothScan, WifiScan, Jobs, Syncs. |
Bookatz | 506a818 | 2017-05-01 14:18:42 -0700 | [diff] [blame] | 191 | * New in version 21: |
| 192 | * - Actual (not just apportioned) Wakelock time is also recorded. |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame^] | 193 | * - Aggregated partial wakelock time (per uid, instead of per wakelock) is recorded. |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 194 | */ |
Bookatz | 506a818 | 2017-05-01 14:18:42 -0700 | [diff] [blame] | 195 | static final String CHECKIN_VERSION = "21"; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 196 | |
| 197 | /** |
| 198 | * 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] | 199 | */ |
Ashish Sharma | 213bb2f | 2014-07-07 17:14:52 -0700 | [diff] [blame] | 200 | private static final int BATTERY_STATS_CHECKIN_VERSION = 9; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 201 | |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 202 | private static final long BYTES_PER_KB = 1024; |
| 203 | private static final long BYTES_PER_MB = 1048576; // 1024^2 |
| 204 | private static final long BYTES_PER_GB = 1073741824; //1024^3 |
Bookatz | 506a818 | 2017-05-01 14:18:42 -0700 | [diff] [blame] | 205 | |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 206 | private static final String VERSION_DATA = "vers"; |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 207 | private static final String UID_DATA = "uid"; |
Joe Onorato | 1476d32 | 2016-05-05 14:46:15 -0700 | [diff] [blame] | 208 | private static final String WAKEUP_ALARM_DATA = "wua"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 209 | private static final String APK_DATA = "apk"; |
Evan Millar | e84de8d | 2009-04-02 22:16:12 -0700 | [diff] [blame] | 210 | private static final String PROCESS_DATA = "pr"; |
Adam Lesinski | a7a4ccc | 2015-06-26 17:43:04 -0700 | [diff] [blame] | 211 | private static final String CPU_DATA = "cpu"; |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 212 | private static final String GLOBAL_CPU_FREQ_DATA = "gcf"; |
| 213 | private static final String CPU_TIMES_AT_FREQ_DATA = "ctf"; |
Evan Millar | e84de8d | 2009-04-02 22:16:12 -0700 | [diff] [blame] | 214 | private static final String SENSOR_DATA = "sr"; |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 215 | private static final String VIBRATOR_DATA = "vib"; |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 216 | private static final String FOREGROUND_DATA = "fg"; |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 217 | private static final String STATE_TIME_DATA = "st"; |
Bookatz | 506a818 | 2017-05-01 14:18:42 -0700 | [diff] [blame] | 218 | // wl line is: |
| 219 | // BATTERY_STATS_CHECKIN_VERSION, uid, which, "wl", name, |
| 220 | // full totalTime, 'f', count, current duration, max duration, total duration, |
| 221 | // partial totalTime, 'p', count, current duration, max duration, total duration, |
| 222 | // window totalTime, 'w', count, current duration, max duration, total duration |
| 223 | // [Currently, full and window wakelocks have durations current = max = total = -1] |
Evan Millar | e84de8d | 2009-04-02 22:16:12 -0700 | [diff] [blame] | 224 | private static final String WAKELOCK_DATA = "wl"; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame^] | 225 | // awl line is: |
| 226 | // BATTERY_STATS_CHECKIN_VERSION, uid, which, "awl", |
| 227 | // cumulative partial wakelock duration, cumulative background partial wakelock duration |
| 228 | private static final String AGGREGATED_WAKELOCK_DATA = "awl"; |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 229 | private static final String SYNC_DATA = "sy"; |
| 230 | private static final String JOB_DATA = "jb"; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 231 | private static final String KERNEL_WAKELOCK_DATA = "kwl"; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 232 | private static final String WAKEUP_REASON_DATA = "wr"; |
Evan Millar | e84de8d | 2009-04-02 22:16:12 -0700 | [diff] [blame] | 233 | private static final String NETWORK_DATA = "nt"; |
| 234 | private static final String USER_ACTIVITY_DATA = "ua"; |
| 235 | private static final String BATTERY_DATA = "bt"; |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 236 | private static final String BATTERY_DISCHARGE_DATA = "dc"; |
Evan Millar | e84de8d | 2009-04-02 22:16:12 -0700 | [diff] [blame] | 237 | private static final String BATTERY_LEVEL_DATA = "lv"; |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 238 | private static final String GLOBAL_WIFI_DATA = "gwfl"; |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 239 | private static final String WIFI_DATA = "wfl"; |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 240 | private static final String GLOBAL_WIFI_CONTROLLER_DATA = "gwfcd"; |
| 241 | private static final String WIFI_CONTROLLER_DATA = "wfcd"; |
| 242 | private static final String GLOBAL_BLUETOOTH_CONTROLLER_DATA = "gble"; |
| 243 | private static final String BLUETOOTH_CONTROLLER_DATA = "ble"; |
Adam Lesinski | d9b99be | 2016-03-30 16:58:51 -0700 | [diff] [blame] | 244 | private static final String BLUETOOTH_MISC_DATA = "blem"; |
Evan Millar | e84de8d | 2009-04-02 22:16:12 -0700 | [diff] [blame] | 245 | private static final String MISC_DATA = "m"; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 246 | private static final String GLOBAL_NETWORK_DATA = "gn"; |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 247 | private static final String GLOBAL_MODEM_CONTROLLER_DATA = "gmcd"; |
| 248 | private static final String MODEM_CONTROLLER_DATA = "mcd"; |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 249 | private static final String HISTORY_STRING_POOL = "hsp"; |
Dianne Hackborn | 8a0de58 | 2013-08-07 15:22:07 -0700 | [diff] [blame] | 250 | private static final String HISTORY_DATA = "h"; |
Evan Millar | e84de8d | 2009-04-02 22:16:12 -0700 | [diff] [blame] | 251 | private static final String SCREEN_BRIGHTNESS_DATA = "br"; |
| 252 | private static final String SIGNAL_STRENGTH_TIME_DATA = "sgt"; |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 253 | private static final String SIGNAL_SCANNING_TIME_DATA = "sst"; |
Evan Millar | e84de8d | 2009-04-02 22:16:12 -0700 | [diff] [blame] | 254 | private static final String SIGNAL_STRENGTH_COUNT_DATA = "sgc"; |
| 255 | private static final String DATA_CONNECTION_TIME_DATA = "dct"; |
| 256 | private static final String DATA_CONNECTION_COUNT_DATA = "dcc"; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 257 | private static final String WIFI_STATE_TIME_DATA = "wst"; |
| 258 | private static final String WIFI_STATE_COUNT_DATA = "wsc"; |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 259 | private static final String WIFI_SUPPL_STATE_TIME_DATA = "wsst"; |
| 260 | private static final String WIFI_SUPPL_STATE_COUNT_DATA = "wssc"; |
| 261 | private static final String WIFI_SIGNAL_STRENGTH_TIME_DATA = "wsgt"; |
| 262 | private static final String WIFI_SIGNAL_STRENGTH_COUNT_DATA = "wsgc"; |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 263 | private static final String POWER_USE_SUMMARY_DATA = "pws"; |
| 264 | private static final String POWER_USE_ITEM_DATA = "pwi"; |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 265 | private static final String DISCHARGE_STEP_DATA = "dsd"; |
| 266 | private static final String CHARGE_STEP_DATA = "csd"; |
Dianne Hackborn | d06dcfd | 2014-05-02 13:49:30 -0700 | [diff] [blame] | 267 | private static final String DISCHARGE_TIME_REMAIN_DATA = "dtr"; |
| 268 | private static final String CHARGE_TIME_REMAIN_DATA = "ctr"; |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 269 | private static final String FLASHLIGHT_DATA = "fla"; |
| 270 | private static final String CAMERA_DATA = "cam"; |
| 271 | private static final String VIDEO_DATA = "vid"; |
| 272 | private static final String AUDIO_DATA = "aud"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 273 | |
Adam Lesinski | 010bf37 | 2016-04-11 12:18:18 -0700 | [diff] [blame] | 274 | public static final String RESULT_RECEIVER_CONTROLLER_KEY = "controller_activity"; |
| 275 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 276 | private final StringBuilder mFormatBuilder = new StringBuilder(32); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 277 | private final Formatter mFormatter = new Formatter(mFormatBuilder); |
| 278 | |
| 279 | /** |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 280 | * Indicates times spent by the uid at each cpu frequency in all process states. |
| 281 | * |
| 282 | * Other types might include times spent in foreground, background etc. |
| 283 | */ |
| 284 | private final String UID_TIMES_TYPE_ALL = "A"; |
| 285 | |
| 286 | /** |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 287 | * State for keeping track of counting information. |
| 288 | */ |
| 289 | public static abstract class Counter { |
| 290 | |
| 291 | /** |
| 292 | * Returns the count associated with this Counter for the |
| 293 | * selected type of statistics. |
| 294 | * |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 295 | * @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] | 296 | */ |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 297 | public abstract int getCountLocked(int which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 298 | |
| 299 | /** |
| 300 | * Temporary for debugging. |
| 301 | */ |
| 302 | public abstract void logState(Printer pw, String prefix); |
| 303 | } |
| 304 | |
| 305 | /** |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 306 | * State for keeping track of long counting information. |
| 307 | */ |
| 308 | public static abstract class LongCounter { |
| 309 | |
| 310 | /** |
| 311 | * Returns the count associated with this Counter for the |
| 312 | * selected type of statistics. |
| 313 | * |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 314 | * @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] | 315 | */ |
| 316 | public abstract long getCountLocked(int which); |
| 317 | |
| 318 | /** |
| 319 | * Temporary for debugging. |
| 320 | */ |
| 321 | public abstract void logState(Printer pw, String prefix); |
| 322 | } |
| 323 | |
| 324 | /** |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 325 | * State for keeping track of array of long counting information. |
| 326 | */ |
| 327 | public static abstract class LongCounterArray { |
| 328 | /** |
| 329 | * Returns the counts associated with this Counter for the |
| 330 | * selected type of statistics. |
| 331 | * |
| 332 | * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT |
| 333 | */ |
| 334 | public abstract long[] getCountsLocked(int which); |
| 335 | |
| 336 | /** |
| 337 | * Temporary for debugging. |
| 338 | */ |
| 339 | public abstract void logState(Printer pw, String prefix); |
| 340 | } |
| 341 | |
| 342 | /** |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 343 | * Container class that aggregates counters for transmit, receive, and idle state of a |
| 344 | * radio controller. |
| 345 | */ |
| 346 | public static abstract class ControllerActivityCounter { |
| 347 | /** |
| 348 | * @return a non-null {@link LongCounter} representing time spent (milliseconds) in the |
| 349 | * idle state. |
| 350 | */ |
| 351 | public abstract LongCounter getIdleTimeCounter(); |
| 352 | |
| 353 | /** |
| 354 | * @return a non-null {@link LongCounter} representing time spent (milliseconds) in the |
| 355 | * receive state. |
| 356 | */ |
| 357 | public abstract LongCounter getRxTimeCounter(); |
| 358 | |
| 359 | /** |
| 360 | * An array of {@link LongCounter}, representing various transmit levels, where each level |
| 361 | * may draw a different amount of power. The levels themselves are controller-specific. |
| 362 | * @return non-null array of {@link LongCounter}s representing time spent (milliseconds) in |
| 363 | * various transmit level states. |
| 364 | */ |
| 365 | public abstract LongCounter[] getTxTimeCounters(); |
| 366 | |
| 367 | /** |
| 368 | * @return a non-null {@link LongCounter} representing the power consumed by the controller |
| 369 | * in all states, measured in milli-ampere-milliseconds (mAms). The counter may always |
| 370 | * yield a value of 0 if the device doesn't support power calculations. |
| 371 | */ |
| 372 | public abstract LongCounter getPowerCounter(); |
| 373 | } |
| 374 | |
| 375 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 376 | * State for keeping track of timing information. |
| 377 | */ |
| 378 | public static abstract class Timer { |
| 379 | |
| 380 | /** |
| 381 | * Returns the count associated with this Timer for the |
| 382 | * selected type of statistics. |
| 383 | * |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 384 | * @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] | 385 | */ |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 386 | public abstract int getCountLocked(int which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 387 | |
| 388 | /** |
| 389 | * Returns the total time in microseconds associated with this Timer for the |
| 390 | * selected type of statistics. |
| 391 | * |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 392 | * @param elapsedRealtimeUs current elapsed realtime of system in microseconds |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 393 | * @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] | 394 | * @return a time in microseconds |
| 395 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 396 | public abstract long getTotalTimeLocked(long elapsedRealtimeUs, int which); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 397 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 398 | /** |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 399 | * Returns the total time in microseconds associated with this Timer since the |
| 400 | * 'mark' was last set. |
| 401 | * |
| 402 | * @param elapsedRealtimeUs current elapsed realtime of system in microseconds |
| 403 | * @return a time in microseconds |
| 404 | */ |
| 405 | public abstract long getTimeSinceMarkLocked(long elapsedRealtimeUs); |
| 406 | |
| 407 | /** |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 408 | * Returns the max duration if it is being tracked. |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 409 | * Not all Timer subclasses track the max, total, current durations. |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 410 | |
| 411 | */ |
| 412 | public long getMaxDurationMsLocked(long elapsedRealtimeMs) { |
| 413 | return -1; |
| 414 | } |
| 415 | |
| 416 | /** |
| 417 | * 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] | 418 | * Not all Timer subclasses track the max, total, current durations. |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 419 | */ |
| 420 | public long getCurrentDurationMsLocked(long elapsedRealtimeMs) { |
| 421 | return -1; |
| 422 | } |
| 423 | |
| 424 | /** |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 425 | * Returns the current time the timer has been active, if it is being tracked. |
| 426 | * |
| 427 | * Returns the total cumulative duration (i.e. sum of past durations) that this timer has |
| 428 | * been on since reset. |
| 429 | * This may differ from getTotalTimeLocked(elapsedRealtimeUs, STATS_SINCE_CHARGED)/1000 since, |
| 430 | * depending on the Timer, getTotalTimeLocked may represent the total 'blamed' or 'pooled' |
| 431 | * time, rather than the actual time. By contrast, getTotalDurationMsLocked always gives |
| 432 | * the actual total time. |
| 433 | * Not all Timer subclasses track the max, total, current durations. |
| 434 | */ |
| 435 | public long getTotalDurationMsLocked(long elapsedRealtimeMs) { |
| 436 | return -1; |
| 437 | } |
| 438 | |
| 439 | /** |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 440 | * Returns the secondary Timer held by the Timer, if one exists. This secondary timer may be |
| 441 | * used, for example, for tracking background usage. Secondary timers are never pooled. |
| 442 | * |
| 443 | * Not all Timer subclasses have a secondary timer; those that don't return null. |
| 444 | */ |
| 445 | public Timer getSubTimer() { |
| 446 | return null; |
| 447 | } |
| 448 | |
| 449 | /** |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 450 | * Returns whether the timer is currently running. Some types of timers |
| 451 | * (e.g. BatchTimers) don't know whether the event is currently active, |
| 452 | * and report false. |
| 453 | */ |
| 454 | public boolean isRunningLocked() { |
| 455 | return false; |
| 456 | } |
| 457 | |
| 458 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 459 | * Temporary for debugging. |
| 460 | */ |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 461 | public abstract void logState(Printer pw, String prefix); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 462 | } |
| 463 | |
| 464 | /** |
| 465 | * The statistics associated with a particular uid. |
| 466 | */ |
| 467 | public static abstract class Uid { |
| 468 | |
| 469 | /** |
| 470 | * Returns a mapping containing wakelock statistics. |
| 471 | * |
| 472 | * @return a Map from Strings to Uid.Wakelock objects. |
| 473 | */ |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 474 | public abstract ArrayMap<String, ? extends Wakelock> getWakelockStats(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 475 | |
| 476 | /** |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 477 | * Returns a mapping containing sync statistics. |
| 478 | * |
| 479 | * @return a Map from Strings to Timer objects. |
| 480 | */ |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 481 | public abstract ArrayMap<String, ? extends Timer> getSyncStats(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 482 | |
| 483 | /** |
| 484 | * Returns a mapping containing scheduled job statistics. |
| 485 | * |
| 486 | * @return a Map from Strings to Timer objects. |
| 487 | */ |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 488 | public abstract ArrayMap<String, ? extends Timer> getJobStats(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 489 | |
| 490 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 491 | * The statistics associated with a particular wake lock. |
| 492 | */ |
| 493 | public static abstract class Wakelock { |
| 494 | public abstract Timer getWakeTime(int type); |
| 495 | } |
| 496 | |
| 497 | /** |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame^] | 498 | * The cumulative time the uid spent holding any partial wakelocks. This will generally |
| 499 | * differ from summing over the Wakelocks in getWakelockStats since the latter may have |
| 500 | * wakelocks that overlap in time (and therefore over-counts). |
| 501 | */ |
| 502 | public abstract Timer getAggregatedPartialWakelockTimer(); |
| 503 | |
| 504 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 505 | * Returns a mapping containing sensor statistics. |
| 506 | * |
| 507 | * @return a Map from Integer sensor ids to Uid.Sensor objects. |
| 508 | */ |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 509 | public abstract SparseArray<? extends Sensor> getSensorStats(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 510 | |
| 511 | /** |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 512 | * Returns a mapping containing active process data. |
| 513 | */ |
| 514 | public abstract SparseArray<? extends Pid> getPidStats(); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame^] | 515 | |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 516 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 517 | * Returns a mapping containing process statistics. |
| 518 | * |
| 519 | * @return a Map from Strings to Uid.Proc objects. |
| 520 | */ |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 521 | public abstract ArrayMap<String, ? extends Proc> getProcessStats(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 522 | |
| 523 | /** |
| 524 | * Returns a mapping containing package statistics. |
| 525 | * |
| 526 | * @return a Map from Strings to Uid.Pkg objects. |
| 527 | */ |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 528 | public abstract ArrayMap<String, ? extends Pkg> getPackageStats(); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 529 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 530 | public abstract ControllerActivityCounter getWifiControllerActivity(); |
| 531 | public abstract ControllerActivityCounter getBluetoothControllerActivity(); |
| 532 | public abstract ControllerActivityCounter getModemControllerActivity(); |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 533 | |
| 534 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 535 | * {@hide} |
| 536 | */ |
| 537 | public abstract int getUid(); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 538 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 539 | public abstract void noteWifiRunningLocked(long elapsedRealtime); |
| 540 | public abstract void noteWifiStoppedLocked(long elapsedRealtime); |
| 541 | public abstract void noteFullWifiLockAcquiredLocked(long elapsedRealtime); |
| 542 | public abstract void noteFullWifiLockReleasedLocked(long elapsedRealtime); |
| 543 | public abstract void noteWifiScanStartedLocked(long elapsedRealtime); |
| 544 | public abstract void noteWifiScanStoppedLocked(long elapsedRealtime); |
| 545 | public abstract void noteWifiBatchedScanStartedLocked(int csph, long elapsedRealtime); |
| 546 | public abstract void noteWifiBatchedScanStoppedLocked(long elapsedRealtime); |
| 547 | public abstract void noteWifiMulticastEnabledLocked(long elapsedRealtime); |
| 548 | public abstract void noteWifiMulticastDisabledLocked(long elapsedRealtime); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 549 | public abstract void noteActivityResumedLocked(long elapsedRealtime); |
| 550 | public abstract void noteActivityPausedLocked(long elapsedRealtime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 551 | public abstract long getWifiRunningTime(long elapsedRealtimeUs, int which); |
| 552 | public abstract long getFullWifiLockTime(long elapsedRealtimeUs, int which); |
| 553 | public abstract long getWifiScanTime(long elapsedRealtimeUs, int which); |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 554 | public abstract int getWifiScanCount(int which); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 555 | public abstract int getWifiScanBackgroundCount(int which); |
| 556 | public abstract long getWifiScanActualTime(long elapsedRealtimeUs); |
| 557 | public abstract long getWifiScanBackgroundTime(long elapsedRealtimeUs); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 558 | public abstract long getWifiBatchedScanTime(int csphBin, long elapsedRealtimeUs, int which); |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 559 | public abstract int getWifiBatchedScanCount(int csphBin, int which); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 560 | public abstract long getWifiMulticastTime(long elapsedRealtimeUs, int which); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 561 | public abstract Timer getAudioTurnedOnTimer(); |
| 562 | public abstract Timer getVideoTurnedOnTimer(); |
| 563 | public abstract Timer getFlashlightTurnedOnTimer(); |
| 564 | public abstract Timer getCameraTurnedOnTimer(); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 565 | public abstract Timer getForegroundActivityTimer(); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 566 | public abstract Timer getBluetoothScanTimer(); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 567 | public abstract Timer getBluetoothScanBackgroundTimer(); |
Bookatz | 956f36bf | 2017-04-28 09:48:17 -0700 | [diff] [blame] | 568 | public abstract Counter getBluetoothScanResultCounter(); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 569 | |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 570 | public abstract long[] getCpuFreqTimes(int which); |
| 571 | public abstract long[] getScreenOffCpuFreqTimes(int which); |
| 572 | |
Dianne Hackborn | a0200e3 | 2016-03-30 18:01:41 -0700 | [diff] [blame] | 573 | // Note: the following times are disjoint. They can be added together to find the |
| 574 | // total time a uid has had any processes running at all. |
| 575 | |
| 576 | /** |
| 577 | * Time this uid has any processes in the top state (or above such as persistent). |
| 578 | */ |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 579 | public static final int PROCESS_STATE_TOP = 0; |
Dianne Hackborn | a0200e3 | 2016-03-30 18:01:41 -0700 | [diff] [blame] | 580 | /** |
| 581 | * Time this uid has any process with a started out bound foreground service, but |
| 582 | * none in the "top" state. |
| 583 | */ |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 584 | public static final int PROCESS_STATE_FOREGROUND_SERVICE = 1; |
Dianne Hackborn | a0200e3 | 2016-03-30 18:01:41 -0700 | [diff] [blame] | 585 | /** |
| 586 | * Time this uid has any process that is top while the device is sleeping, but none |
| 587 | * in the "foreground service" or better state. |
| 588 | */ |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 589 | public static final int PROCESS_STATE_TOP_SLEEPING = 2; |
Dianne Hackborn | a0200e3 | 2016-03-30 18:01:41 -0700 | [diff] [blame] | 590 | /** |
| 591 | * Time this uid has any process in an active foreground state, but none in the |
| 592 | * "top sleeping" or better state. |
| 593 | */ |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 594 | public static final int PROCESS_STATE_FOREGROUND = 3; |
Dianne Hackborn | a0200e3 | 2016-03-30 18:01:41 -0700 | [diff] [blame] | 595 | /** |
| 596 | * Time this uid has any process in an active background state, but none in the |
| 597 | * "foreground" or better state. |
| 598 | */ |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 599 | public static final int PROCESS_STATE_BACKGROUND = 4; |
Dianne Hackborn | a0200e3 | 2016-03-30 18:01:41 -0700 | [diff] [blame] | 600 | /** |
| 601 | * Time this uid has any processes that are sitting around cached, not in one of the |
| 602 | * other active states. |
| 603 | */ |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 604 | public static final int PROCESS_STATE_CACHED = 5; |
Dianne Hackborn | a0200e3 | 2016-03-30 18:01:41 -0700 | [diff] [blame] | 605 | /** |
| 606 | * Total number of process states we track. |
| 607 | */ |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 608 | public static final int NUM_PROCESS_STATE = 6; |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 609 | |
| 610 | static final String[] PROCESS_STATE_NAMES = { |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 611 | "Top", "Fg Service", "Top Sleeping", "Foreground", "Background", "Cached" |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 612 | }; |
| 613 | |
| 614 | public abstract long getProcessStateTime(int state, long elapsedRealtimeUs, int which); |
Joe Onorato | 713fec8 | 2016-03-04 10:34:02 -0800 | [diff] [blame] | 615 | public abstract Timer getProcessStateTimer(int state); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 616 | |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 617 | public abstract Timer getVibratorOnTimer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 618 | |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 619 | public static final int NUM_WIFI_BATCHED_SCAN_BINS = 5; |
| 620 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 621 | /** |
Jeff Brown | df693de | 2012-07-27 12:03:38 -0700 | [diff] [blame] | 622 | * Note that these must match the constants in android.os.PowerManager. |
| 623 | * Also, if the user activity types change, the BatteryStatsImpl.VERSION must |
| 624 | * also be bumped. |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 625 | */ |
| 626 | static final String[] USER_ACTIVITY_TYPES = { |
Phil Weaver | da80d67 | 2016-03-15 16:25:46 -0700 | [diff] [blame] | 627 | "other", "button", "touch", "accessibility" |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 628 | }; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame^] | 629 | |
Phil Weaver | da80d67 | 2016-03-15 16:25:46 -0700 | [diff] [blame] | 630 | public static final int NUM_USER_ACTIVITY_TYPES = 4; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 631 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 632 | public abstract void noteUserActivityLocked(int type); |
| 633 | public abstract boolean hasUserActivity(); |
| 634 | public abstract int getUserActivityCount(int type, int which); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 635 | |
| 636 | public abstract boolean hasNetworkActivity(); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 637 | public abstract long getNetworkActivityBytes(int type, int which); |
| 638 | public abstract long getNetworkActivityPackets(int type, int which); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 639 | public abstract long getMobileRadioActiveTime(int which); |
| 640 | public abstract int getMobileRadioActiveCount(int which); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 641 | |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 642 | /** |
| 643 | * Get the total cpu time (in microseconds) this UID had processes executing in userspace. |
| 644 | */ |
| 645 | public abstract long getUserCpuTimeUs(int which); |
| 646 | |
| 647 | /** |
| 648 | * Get the total cpu time (in microseconds) this UID had processes executing kernel syscalls. |
| 649 | */ |
| 650 | public abstract long getSystemCpuTimeUs(int which); |
| 651 | |
| 652 | /** |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 653 | * Returns the approximate cpu time (in milliseconds) spent at a certain CPU speed for a |
| 654 | * given CPU cluster. |
| 655 | * @param cluster the index of the CPU cluster. |
Adam Lesinski | a7a4ccc | 2015-06-26 17:43:04 -0700 | [diff] [blame] | 656 | * @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] | 657 | * @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] | 658 | * @see com.android.internal.os.PowerProfile#getNumCpuClusters() |
| 659 | * @see com.android.internal.os.PowerProfile#getNumSpeedStepsInCpuCluster(int) |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 660 | */ |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 661 | public abstract long getTimeAtCpuSpeed(int cluster, int step, int which); |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 662 | |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 663 | /** |
| 664 | * Returns the number of times this UID woke up the Application Processor to |
| 665 | * process a mobile radio packet. |
| 666 | * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT. |
| 667 | */ |
| 668 | public abstract long getMobileRadioApWakeupCount(int which); |
| 669 | |
| 670 | /** |
| 671 | * Returns the number of times this UID woke up the Application Processor to |
| 672 | * process a WiFi packet. |
| 673 | * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT. |
| 674 | */ |
| 675 | public abstract long getWifiRadioApWakeupCount(int which); |
| 676 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 677 | public static abstract class Sensor { |
Mathias Agopian | 7f84c06 | 2013-02-04 19:22:47 -0800 | [diff] [blame] | 678 | /* |
| 679 | * FIXME: it's not correct to use this magic value because it |
| 680 | * could clash with a sensor handle (which are defined by |
| 681 | * the sensor HAL, and therefore out of our control |
| 682 | */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 683 | // Magic sensor number for the GPS. |
| 684 | public static final int GPS = -10000; |
Amith Yamasani | ab9ad19 | 2016-12-06 12:46:59 -0800 | [diff] [blame] | 685 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 686 | public abstract int getHandle(); |
Amith Yamasani | ab9ad19 | 2016-12-06 12:46:59 -0800 | [diff] [blame] | 687 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 688 | public abstract Timer getSensorTime(); |
Amith Yamasani | ab9ad19 | 2016-12-06 12:46:59 -0800 | [diff] [blame] | 689 | |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 690 | /** Returns a Timer for sensor usage when app is in the background. */ |
| 691 | public abstract Timer getSensorBackgroundTime(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 692 | } |
| 693 | |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 694 | public class Pid { |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 695 | public int mWakeNesting; |
| 696 | public long mWakeSumMs; |
| 697 | public long mWakeStartMs; |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 698 | } |
| 699 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 700 | /** |
| 701 | * The statistics associated with a particular process. |
| 702 | */ |
| 703 | public static abstract class Proc { |
| 704 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 705 | public static class ExcessivePower { |
| 706 | public static final int TYPE_WAKE = 1; |
| 707 | public static final int TYPE_CPU = 2; |
| 708 | |
| 709 | public int type; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 710 | public long overTime; |
| 711 | public long usedTime; |
| 712 | } |
| 713 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 714 | /** |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 715 | * Returns true if this process is still active in the battery stats. |
| 716 | */ |
| 717 | public abstract boolean isActive(); |
| 718 | |
| 719 | /** |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 720 | * 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] | 721 | * |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 722 | * @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] | 723 | */ |
| 724 | public abstract long getUserTime(int which); |
| 725 | |
| 726 | /** |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 727 | * 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] | 728 | * |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 729 | * @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] | 730 | */ |
| 731 | public abstract long getSystemTime(int which); |
| 732 | |
| 733 | /** |
| 734 | * Returns the number of times the process has been started. |
| 735 | * |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 736 | * @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] | 737 | */ |
| 738 | public abstract int getStarts(int which); |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 739 | |
| 740 | /** |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 741 | * Returns the number of times the process has crashed. |
| 742 | * |
| 743 | * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT. |
| 744 | */ |
| 745 | public abstract int getNumCrashes(int which); |
| 746 | |
| 747 | /** |
| 748 | * Returns the number of times the process has ANRed. |
| 749 | * |
| 750 | * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT. |
| 751 | */ |
| 752 | public abstract int getNumAnrs(int which); |
| 753 | |
| 754 | /** |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 755 | * 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] | 756 | * @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] | 757 | * @return foreground cpu time in microseconds |
| 758 | */ |
| 759 | public abstract long getForegroundTime(int which); |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 760 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 761 | public abstract int countExcessivePowers(); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 762 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 763 | public abstract ExcessivePower getExcessivePower(int i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 764 | } |
| 765 | |
| 766 | /** |
| 767 | * The statistics associated with a particular package. |
| 768 | */ |
| 769 | public static abstract class Pkg { |
| 770 | |
| 771 | /** |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 772 | * Returns information about all wakeup alarms that have been triggered for this |
| 773 | * package. The mapping keys are tag names for the alarms, the counter contains |
| 774 | * 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] | 775 | */ |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 776 | public abstract ArrayMap<String, ? extends Counter> getWakeupAlarmStats(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 777 | |
| 778 | /** |
| 779 | * Returns a mapping containing service statistics. |
| 780 | */ |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 781 | public abstract ArrayMap<String, ? extends Serv> getServiceStats(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 782 | |
| 783 | /** |
| 784 | * The statistics associated with a particular service. |
| 785 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 786 | public static abstract class Serv { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 787 | |
| 788 | /** |
| 789 | * Returns the amount of time spent started. |
| 790 | * |
| 791 | * @param batteryUptime elapsed uptime on battery in microseconds. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 792 | * @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] | 793 | * @return |
| 794 | */ |
| 795 | public abstract long getStartTime(long batteryUptime, int which); |
| 796 | |
| 797 | /** |
| 798 | * Returns the total number of times startService() has been called. |
| 799 | * |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 800 | * @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] | 801 | */ |
| 802 | public abstract int getStarts(int which); |
| 803 | |
| 804 | /** |
| 805 | * Returns the total number times the service has been launched. |
| 806 | * |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 807 | * @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] | 808 | */ |
| 809 | public abstract int getLaunches(int which); |
| 810 | } |
| 811 | } |
| 812 | } |
| 813 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 814 | public static final class LevelStepTracker { |
| 815 | public long mLastStepTime = -1; |
| 816 | public int mNumStepDurations; |
| 817 | public final long[] mStepDurations; |
| 818 | |
| 819 | public LevelStepTracker(int maxLevelSteps) { |
| 820 | mStepDurations = new long[maxLevelSteps]; |
| 821 | } |
| 822 | |
| 823 | public LevelStepTracker(int numSteps, long[] steps) { |
| 824 | mNumStepDurations = numSteps; |
| 825 | mStepDurations = new long[numSteps]; |
| 826 | System.arraycopy(steps, 0, mStepDurations, 0, numSteps); |
| 827 | } |
| 828 | |
| 829 | public long getDurationAt(int index) { |
| 830 | return mStepDurations[index] & STEP_LEVEL_TIME_MASK; |
| 831 | } |
| 832 | |
| 833 | public int getLevelAt(int index) { |
| 834 | return (int)((mStepDurations[index] & STEP_LEVEL_LEVEL_MASK) |
| 835 | >> STEP_LEVEL_LEVEL_SHIFT); |
| 836 | } |
| 837 | |
| 838 | public int getInitModeAt(int index) { |
| 839 | return (int)((mStepDurations[index] & STEP_LEVEL_INITIAL_MODE_MASK) |
| 840 | >> STEP_LEVEL_INITIAL_MODE_SHIFT); |
| 841 | } |
| 842 | |
| 843 | public int getModModeAt(int index) { |
| 844 | return (int)((mStepDurations[index] & STEP_LEVEL_MODIFIED_MODE_MASK) |
| 845 | >> STEP_LEVEL_MODIFIED_MODE_SHIFT); |
| 846 | } |
| 847 | |
| 848 | private void appendHex(long val, int topOffset, StringBuilder out) { |
| 849 | boolean hasData = false; |
| 850 | while (topOffset >= 0) { |
| 851 | int digit = (int)( (val>>topOffset) & 0xf ); |
| 852 | topOffset -= 4; |
| 853 | if (!hasData && digit == 0) { |
| 854 | continue; |
| 855 | } |
| 856 | hasData = true; |
| 857 | if (digit >= 0 && digit <= 9) { |
| 858 | out.append((char)('0' + digit)); |
| 859 | } else { |
| 860 | out.append((char)('a' + digit - 10)); |
| 861 | } |
| 862 | } |
| 863 | } |
| 864 | |
| 865 | public void encodeEntryAt(int index, StringBuilder out) { |
| 866 | long item = mStepDurations[index]; |
| 867 | long duration = item & STEP_LEVEL_TIME_MASK; |
| 868 | int level = (int)((item & STEP_LEVEL_LEVEL_MASK) |
| 869 | >> STEP_LEVEL_LEVEL_SHIFT); |
| 870 | int initMode = (int)((item & STEP_LEVEL_INITIAL_MODE_MASK) |
| 871 | >> STEP_LEVEL_INITIAL_MODE_SHIFT); |
| 872 | int modMode = (int)((item & STEP_LEVEL_MODIFIED_MODE_MASK) |
| 873 | >> STEP_LEVEL_MODIFIED_MODE_SHIFT); |
| 874 | switch ((initMode&STEP_LEVEL_MODE_SCREEN_STATE) + 1) { |
| 875 | case Display.STATE_OFF: out.append('f'); break; |
| 876 | case Display.STATE_ON: out.append('o'); break; |
| 877 | case Display.STATE_DOZE: out.append('d'); break; |
| 878 | case Display.STATE_DOZE_SUSPEND: out.append('z'); break; |
| 879 | } |
| 880 | if ((initMode&STEP_LEVEL_MODE_POWER_SAVE) != 0) { |
| 881 | out.append('p'); |
| 882 | } |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 883 | if ((initMode&STEP_LEVEL_MODE_DEVICE_IDLE) != 0) { |
| 884 | out.append('i'); |
| 885 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 886 | switch ((modMode&STEP_LEVEL_MODE_SCREEN_STATE) + 1) { |
| 887 | case Display.STATE_OFF: out.append('F'); break; |
| 888 | case Display.STATE_ON: out.append('O'); break; |
| 889 | case Display.STATE_DOZE: out.append('D'); break; |
| 890 | case Display.STATE_DOZE_SUSPEND: out.append('Z'); break; |
| 891 | } |
| 892 | if ((modMode&STEP_LEVEL_MODE_POWER_SAVE) != 0) { |
| 893 | out.append('P'); |
| 894 | } |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 895 | if ((modMode&STEP_LEVEL_MODE_DEVICE_IDLE) != 0) { |
| 896 | out.append('I'); |
| 897 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 898 | out.append('-'); |
| 899 | appendHex(level, 4, out); |
| 900 | out.append('-'); |
| 901 | appendHex(duration, STEP_LEVEL_LEVEL_SHIFT-4, out); |
| 902 | } |
| 903 | |
| 904 | public void decodeEntryAt(int index, String value) { |
| 905 | final int N = value.length(); |
| 906 | int i = 0; |
| 907 | char c; |
| 908 | long out = 0; |
| 909 | while (i < N && (c=value.charAt(i)) != '-') { |
| 910 | i++; |
| 911 | switch (c) { |
Dianne Hackborn | 8cfb58b | 2015-03-04 13:28:36 -0800 | [diff] [blame] | 912 | 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] | 913 | break; |
Dianne Hackborn | 8cfb58b | 2015-03-04 13:28:36 -0800 | [diff] [blame] | 914 | 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] | 915 | break; |
Dianne Hackborn | 8cfb58b | 2015-03-04 13:28:36 -0800 | [diff] [blame] | 916 | 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] | 917 | break; |
Dianne Hackborn | 8cfb58b | 2015-03-04 13:28:36 -0800 | [diff] [blame] | 918 | case 'z': out |= (((long)Display.STATE_DOZE_SUSPEND-1) |
| 919 | << STEP_LEVEL_INITIAL_MODE_SHIFT); |
| 920 | break; |
| 921 | case 'p': out |= (((long)STEP_LEVEL_MODE_POWER_SAVE) |
| 922 | << STEP_LEVEL_INITIAL_MODE_SHIFT); |
| 923 | break; |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 924 | case 'i': out |= (((long)STEP_LEVEL_MODE_DEVICE_IDLE) |
| 925 | << STEP_LEVEL_INITIAL_MODE_SHIFT); |
| 926 | break; |
Dianne Hackborn | 8cfb58b | 2015-03-04 13:28:36 -0800 | [diff] [blame] | 927 | case 'F': out |= (((long)Display.STATE_OFF-1)<<STEP_LEVEL_MODIFIED_MODE_SHIFT); |
| 928 | break; |
| 929 | case 'O': out |= (((long)Display.STATE_ON-1)<<STEP_LEVEL_MODIFIED_MODE_SHIFT); |
| 930 | break; |
| 931 | case 'D': out |= (((long)Display.STATE_DOZE-1)<<STEP_LEVEL_MODIFIED_MODE_SHIFT); |
| 932 | break; |
| 933 | case 'Z': out |= (((long)Display.STATE_DOZE_SUSPEND-1) |
| 934 | << STEP_LEVEL_MODIFIED_MODE_SHIFT); |
| 935 | break; |
| 936 | case 'P': out |= (((long)STEP_LEVEL_MODE_POWER_SAVE) |
| 937 | << STEP_LEVEL_MODIFIED_MODE_SHIFT); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 938 | break; |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 939 | case 'I': out |= (((long)STEP_LEVEL_MODE_DEVICE_IDLE) |
| 940 | << STEP_LEVEL_MODIFIED_MODE_SHIFT); |
| 941 | break; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 942 | } |
| 943 | } |
| 944 | i++; |
Dianne Hackborn | 8cfb58b | 2015-03-04 13:28:36 -0800 | [diff] [blame] | 945 | long level = 0; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 946 | while (i < N && (c=value.charAt(i)) != '-') { |
| 947 | i++; |
| 948 | level <<= 4; |
| 949 | if (c >= '0' && c <= '9') { |
| 950 | level += c - '0'; |
| 951 | } else if (c >= 'a' && c <= 'f') { |
| 952 | level += c - 'a' + 10; |
| 953 | } else if (c >= 'A' && c <= 'F') { |
| 954 | level += c - 'A' + 10; |
| 955 | } |
| 956 | } |
Dianne Hackborn | 8cfb58b | 2015-03-04 13:28:36 -0800 | [diff] [blame] | 957 | i++; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 958 | out |= (level << STEP_LEVEL_LEVEL_SHIFT) & STEP_LEVEL_LEVEL_MASK; |
| 959 | long duration = 0; |
| 960 | while (i < N && (c=value.charAt(i)) != '-') { |
| 961 | i++; |
| 962 | duration <<= 4; |
| 963 | if (c >= '0' && c <= '9') { |
| 964 | duration += c - '0'; |
| 965 | } else if (c >= 'a' && c <= 'f') { |
| 966 | duration += c - 'a' + 10; |
| 967 | } else if (c >= 'A' && c <= 'F') { |
| 968 | duration += c - 'A' + 10; |
| 969 | } |
| 970 | } |
| 971 | mStepDurations[index] = out | (duration & STEP_LEVEL_TIME_MASK); |
| 972 | } |
| 973 | |
| 974 | public void init() { |
| 975 | mLastStepTime = -1; |
| 976 | mNumStepDurations = 0; |
| 977 | } |
| 978 | |
| 979 | public void clearTime() { |
| 980 | mLastStepTime = -1; |
| 981 | } |
| 982 | |
| 983 | public long computeTimePerLevel() { |
| 984 | final long[] steps = mStepDurations; |
| 985 | final int numSteps = mNumStepDurations; |
| 986 | |
| 987 | // For now we'll do a simple average across all steps. |
| 988 | if (numSteps <= 0) { |
| 989 | return -1; |
| 990 | } |
| 991 | long total = 0; |
| 992 | for (int i=0; i<numSteps; i++) { |
| 993 | total += steps[i] & STEP_LEVEL_TIME_MASK; |
| 994 | } |
| 995 | return total / numSteps; |
| 996 | /* |
| 997 | long[] buckets = new long[numSteps]; |
| 998 | int numBuckets = 0; |
| 999 | int numToAverage = 4; |
| 1000 | int i = 0; |
| 1001 | while (i < numSteps) { |
| 1002 | long totalTime = 0; |
| 1003 | int num = 0; |
| 1004 | for (int j=0; j<numToAverage && (i+j)<numSteps; j++) { |
| 1005 | totalTime += steps[i+j] & STEP_LEVEL_TIME_MASK; |
| 1006 | num++; |
| 1007 | } |
| 1008 | buckets[numBuckets] = totalTime / num; |
| 1009 | numBuckets++; |
| 1010 | numToAverage *= 2; |
| 1011 | i += num; |
| 1012 | } |
| 1013 | if (numBuckets < 1) { |
| 1014 | return -1; |
| 1015 | } |
| 1016 | long averageTime = buckets[numBuckets-1]; |
| 1017 | for (i=numBuckets-2; i>=0; i--) { |
| 1018 | averageTime = (averageTime + buckets[i]) / 2; |
| 1019 | } |
| 1020 | return averageTime; |
| 1021 | */ |
| 1022 | } |
| 1023 | |
| 1024 | public long computeTimeEstimate(long modesOfInterest, long modeValues, |
| 1025 | int[] outNumOfInterest) { |
| 1026 | final long[] steps = mStepDurations; |
| 1027 | final int count = mNumStepDurations; |
| 1028 | if (count <= 0) { |
| 1029 | return -1; |
| 1030 | } |
| 1031 | long total = 0; |
| 1032 | int numOfInterest = 0; |
| 1033 | for (int i=0; i<count; i++) { |
| 1034 | long initMode = (steps[i] & STEP_LEVEL_INITIAL_MODE_MASK) |
| 1035 | >> STEP_LEVEL_INITIAL_MODE_SHIFT; |
| 1036 | long modMode = (steps[i] & STEP_LEVEL_MODIFIED_MODE_MASK) |
| 1037 | >> STEP_LEVEL_MODIFIED_MODE_SHIFT; |
| 1038 | // If the modes of interest didn't change during this step period... |
| 1039 | if ((modMode&modesOfInterest) == 0) { |
| 1040 | // And the mode values during this period match those we are measuring... |
| 1041 | if ((initMode&modesOfInterest) == modeValues) { |
| 1042 | // Then this can be used to estimate the total time! |
| 1043 | numOfInterest++; |
| 1044 | total += steps[i] & STEP_LEVEL_TIME_MASK; |
| 1045 | } |
| 1046 | } |
| 1047 | } |
| 1048 | if (numOfInterest <= 0) { |
| 1049 | return -1; |
| 1050 | } |
| 1051 | |
| 1052 | if (outNumOfInterest != null) { |
| 1053 | outNumOfInterest[0] = numOfInterest; |
| 1054 | } |
| 1055 | |
| 1056 | // The estimated time is the average time we spend in each level, multipled |
| 1057 | // by 100 -- the total number of battery levels |
| 1058 | return (total / numOfInterest) * 100; |
| 1059 | } |
| 1060 | |
| 1061 | public void addLevelSteps(int numStepLevels, long modeBits, long elapsedRealtime) { |
| 1062 | int stepCount = mNumStepDurations; |
| 1063 | final long lastStepTime = mLastStepTime; |
| 1064 | if (lastStepTime >= 0 && numStepLevels > 0) { |
| 1065 | final long[] steps = mStepDurations; |
| 1066 | long duration = elapsedRealtime - lastStepTime; |
| 1067 | for (int i=0; i<numStepLevels; i++) { |
| 1068 | System.arraycopy(steps, 0, steps, 1, steps.length-1); |
| 1069 | long thisDuration = duration / (numStepLevels-i); |
| 1070 | duration -= thisDuration; |
| 1071 | if (thisDuration > STEP_LEVEL_TIME_MASK) { |
| 1072 | thisDuration = STEP_LEVEL_TIME_MASK; |
| 1073 | } |
| 1074 | steps[0] = thisDuration | modeBits; |
| 1075 | } |
| 1076 | stepCount += numStepLevels; |
| 1077 | if (stepCount > steps.length) { |
| 1078 | stepCount = steps.length; |
| 1079 | } |
| 1080 | } |
| 1081 | mNumStepDurations = stepCount; |
| 1082 | mLastStepTime = elapsedRealtime; |
| 1083 | } |
| 1084 | |
| 1085 | public void readFromParcel(Parcel in) { |
| 1086 | final int N = in.readInt(); |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 1087 | if (N > mStepDurations.length) { |
| 1088 | throw new ParcelFormatException("more step durations than available: " + N); |
| 1089 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 1090 | mNumStepDurations = N; |
| 1091 | for (int i=0; i<N; i++) { |
| 1092 | mStepDurations[i] = in.readLong(); |
| 1093 | } |
| 1094 | } |
| 1095 | |
| 1096 | public void writeToParcel(Parcel out) { |
| 1097 | final int N = mNumStepDurations; |
| 1098 | out.writeInt(N); |
| 1099 | for (int i=0; i<N; i++) { |
| 1100 | out.writeLong(mStepDurations[i]); |
| 1101 | } |
| 1102 | } |
| 1103 | } |
| 1104 | |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 1105 | public static final class PackageChange { |
| 1106 | public String mPackageName; |
| 1107 | public boolean mUpdate; |
| 1108 | public int mVersionCode; |
| 1109 | } |
| 1110 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 1111 | public static final class DailyItem { |
| 1112 | public long mStartTime; |
| 1113 | public long mEndTime; |
| 1114 | public LevelStepTracker mDischargeSteps; |
| 1115 | public LevelStepTracker mChargeSteps; |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 1116 | public ArrayList<PackageChange> mPackageChanges; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 1117 | } |
| 1118 | |
| 1119 | public abstract DailyItem getDailyItemLocked(int daysAgo); |
| 1120 | |
| 1121 | public abstract long getCurrentDailyStartTime(); |
| 1122 | |
| 1123 | public abstract long getNextMinDailyDeadline(); |
| 1124 | |
| 1125 | public abstract long getNextMaxDailyDeadline(); |
| 1126 | |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 1127 | public abstract long[] getCpuFreqs(); |
| 1128 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1129 | public final static class HistoryTag { |
| 1130 | public String string; |
| 1131 | public int uid; |
| 1132 | |
| 1133 | public int poolIdx; |
| 1134 | |
| 1135 | public void setTo(HistoryTag o) { |
| 1136 | string = o.string; |
| 1137 | uid = o.uid; |
| 1138 | poolIdx = o.poolIdx; |
| 1139 | } |
| 1140 | |
| 1141 | public void setTo(String _string, int _uid) { |
| 1142 | string = _string; |
| 1143 | uid = _uid; |
| 1144 | poolIdx = -1; |
| 1145 | } |
| 1146 | |
| 1147 | public void writeToParcel(Parcel dest, int flags) { |
| 1148 | dest.writeString(string); |
| 1149 | dest.writeInt(uid); |
| 1150 | } |
| 1151 | |
| 1152 | public void readFromParcel(Parcel src) { |
| 1153 | string = src.readString(); |
| 1154 | uid = src.readInt(); |
| 1155 | poolIdx = -1; |
| 1156 | } |
| 1157 | |
| 1158 | @Override |
| 1159 | public boolean equals(Object o) { |
| 1160 | if (this == o) return true; |
| 1161 | if (o == null || getClass() != o.getClass()) return false; |
| 1162 | |
| 1163 | HistoryTag that = (HistoryTag) o; |
| 1164 | |
| 1165 | if (uid != that.uid) return false; |
| 1166 | if (!string.equals(that.string)) return false; |
| 1167 | |
| 1168 | return true; |
| 1169 | } |
| 1170 | |
| 1171 | @Override |
| 1172 | public int hashCode() { |
| 1173 | int result = string.hashCode(); |
| 1174 | result = 31 * result + uid; |
| 1175 | return result; |
| 1176 | } |
| 1177 | } |
| 1178 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 1179 | /** |
| 1180 | * Optional detailed information that can go into a history step. This is typically |
| 1181 | * generated each time the battery level changes. |
| 1182 | */ |
| 1183 | public final static class HistoryStepDetails { |
| 1184 | // Time (in 1/100 second) spent in user space and the kernel since the last step. |
| 1185 | public int userTime; |
| 1186 | public int systemTime; |
| 1187 | |
| 1188 | // Top three apps using CPU in the last step, with times in 1/100 second. |
| 1189 | public int appCpuUid1; |
| 1190 | public int appCpuUTime1; |
| 1191 | public int appCpuSTime1; |
| 1192 | public int appCpuUid2; |
| 1193 | public int appCpuUTime2; |
| 1194 | public int appCpuSTime2; |
| 1195 | public int appCpuUid3; |
| 1196 | public int appCpuUTime3; |
| 1197 | public int appCpuSTime3; |
| 1198 | |
| 1199 | // Information from /proc/stat |
| 1200 | public int statUserTime; |
| 1201 | public int statSystemTime; |
| 1202 | public int statIOWaitTime; |
| 1203 | public int statIrqTime; |
| 1204 | public int statSoftIrqTime; |
| 1205 | public int statIdlTime; |
| 1206 | |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 1207 | // Platform-level low power state stats |
| 1208 | public String statPlatformIdleState; |
| 1209 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 1210 | public HistoryStepDetails() { |
| 1211 | clear(); |
| 1212 | } |
| 1213 | |
| 1214 | public void clear() { |
| 1215 | userTime = systemTime = 0; |
| 1216 | appCpuUid1 = appCpuUid2 = appCpuUid3 = -1; |
| 1217 | appCpuUTime1 = appCpuSTime1 = appCpuUTime2 = appCpuSTime2 |
| 1218 | = appCpuUTime3 = appCpuSTime3 = 0; |
| 1219 | } |
| 1220 | |
| 1221 | public void writeToParcel(Parcel out) { |
| 1222 | out.writeInt(userTime); |
| 1223 | out.writeInt(systemTime); |
| 1224 | out.writeInt(appCpuUid1); |
| 1225 | out.writeInt(appCpuUTime1); |
| 1226 | out.writeInt(appCpuSTime1); |
| 1227 | out.writeInt(appCpuUid2); |
| 1228 | out.writeInt(appCpuUTime2); |
| 1229 | out.writeInt(appCpuSTime2); |
| 1230 | out.writeInt(appCpuUid3); |
| 1231 | out.writeInt(appCpuUTime3); |
| 1232 | out.writeInt(appCpuSTime3); |
| 1233 | out.writeInt(statUserTime); |
| 1234 | out.writeInt(statSystemTime); |
| 1235 | out.writeInt(statIOWaitTime); |
| 1236 | out.writeInt(statIrqTime); |
| 1237 | out.writeInt(statSoftIrqTime); |
| 1238 | out.writeInt(statIdlTime); |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 1239 | out.writeString(statPlatformIdleState); |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 1240 | } |
| 1241 | |
| 1242 | public void readFromParcel(Parcel in) { |
| 1243 | userTime = in.readInt(); |
| 1244 | systemTime = in.readInt(); |
| 1245 | appCpuUid1 = in.readInt(); |
| 1246 | appCpuUTime1 = in.readInt(); |
| 1247 | appCpuSTime1 = in.readInt(); |
| 1248 | appCpuUid2 = in.readInt(); |
| 1249 | appCpuUTime2 = in.readInt(); |
| 1250 | appCpuSTime2 = in.readInt(); |
| 1251 | appCpuUid3 = in.readInt(); |
| 1252 | appCpuUTime3 = in.readInt(); |
| 1253 | appCpuSTime3 = in.readInt(); |
| 1254 | statUserTime = in.readInt(); |
| 1255 | statSystemTime = in.readInt(); |
| 1256 | statIOWaitTime = in.readInt(); |
| 1257 | statIrqTime = in.readInt(); |
| 1258 | statSoftIrqTime = in.readInt(); |
| 1259 | statIdlTime = in.readInt(); |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 1260 | statPlatformIdleState = in.readString(); |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 1261 | } |
| 1262 | } |
| 1263 | |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 1264 | public final static class HistoryItem implements Parcelable { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1265 | public HistoryItem next; |
Dianne Hackborn | 9a75543 | 2014-05-15 17:05:22 -0700 | [diff] [blame] | 1266 | |
| 1267 | // The time of this event in milliseconds, as per SystemClock.elapsedRealtime(). |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1268 | public long time; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1269 | |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 1270 | 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] | 1271 | public static final byte CMD_NULL = -1; |
| 1272 | public static final byte CMD_START = 4; |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1273 | public static final byte CMD_CURRENT_TIME = 5; |
| 1274 | public static final byte CMD_OVERFLOW = 6; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 1275 | public static final byte CMD_RESET = 7; |
Dianne Hackborn | 29cd7f1 | 2015-01-08 10:37:05 -0800 | [diff] [blame] | 1276 | public static final byte CMD_SHUTDOWN = 8; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1277 | |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 1278 | public byte cmd = CMD_NULL; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame^] | 1279 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1280 | /** |
| 1281 | * Return whether the command code is a delta data update. |
| 1282 | */ |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1283 | public boolean isDeltaData() { |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 1284 | return cmd == CMD_UPDATE; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1285 | } |
| 1286 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1287 | public byte batteryLevel; |
| 1288 | public byte batteryStatus; |
| 1289 | public byte batteryHealth; |
| 1290 | public byte batteryPlugType; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame^] | 1291 | |
Sungmin Choi | c7e9e8b | 2013-01-16 12:57:36 +0900 | [diff] [blame] | 1292 | public short batteryTemperature; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1293 | public char batteryVoltage; |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 1294 | |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 1295 | // The charge of the battery in micro-Ampere-hours. |
| 1296 | public int batteryChargeUAh; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame^] | 1297 | |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 1298 | // Constants from SCREEN_BRIGHTNESS_* |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1299 | public static final int STATE_BRIGHTNESS_SHIFT = 0; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1300 | public static final int STATE_BRIGHTNESS_MASK = 0x7; |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 1301 | // Constants from SIGNAL_STRENGTH_* |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 1302 | public static final int STATE_PHONE_SIGNAL_STRENGTH_SHIFT = 3; |
| 1303 | 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] | 1304 | // Constants from ServiceState.STATE_* |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1305 | public static final int STATE_PHONE_STATE_SHIFT = 6; |
| 1306 | 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] | 1307 | // Constants from DATA_CONNECTION_* |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1308 | public static final int STATE_DATA_CONNECTION_SHIFT = 9; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1309 | 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] | 1310 | |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 1311 | // These states always appear directly in the first int token |
| 1312 | // of a delta change; they should be ones that change relatively |
| 1313 | // frequently. |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1314 | public static final int STATE_CPU_RUNNING_FLAG = 1<<31; |
| 1315 | public static final int STATE_WAKE_LOCK_FLAG = 1<<30; |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 1316 | public static final int STATE_GPS_ON_FLAG = 1<<29; |
| 1317 | public static final int STATE_WIFI_FULL_LOCK_FLAG = 1<<28; |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 1318 | public static final int STATE_WIFI_SCAN_FLAG = 1<<27; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 1319 | public static final int STATE_WIFI_RADIO_ACTIVE_FLAG = 1<<26; |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 1320 | public static final int STATE_MOBILE_RADIO_ACTIVE_FLAG = 1<<25; |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 1321 | // Do not use, this is used for coulomb delta count. |
| 1322 | private static final int STATE_RESERVED_0 = 1<<24; |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 1323 | // These are on the lower bits used for the command; if they change |
| 1324 | // we need to write another int of data. |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1325 | public static final int STATE_SENSOR_ON_FLAG = 1<<23; |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 1326 | public static final int STATE_AUDIO_ON_FLAG = 1<<22; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1327 | public static final int STATE_PHONE_SCANNING_FLAG = 1<<21; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 1328 | public static final int STATE_SCREEN_ON_FLAG = 1<<20; // consider moving to states2 |
| 1329 | public static final int STATE_BATTERY_PLUGGED_FLAG = 1<<19; // consider moving to states2 |
| 1330 | // empty slot |
| 1331 | // empty slot |
| 1332 | public static final int STATE_WIFI_MULTICAST_ON_FLAG = 1<<16; |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 1333 | |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 1334 | public static final int MOST_INTERESTING_STATES = |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 1335 | STATE_BATTERY_PLUGGED_FLAG | STATE_SCREEN_ON_FLAG; |
| 1336 | |
| 1337 | public static final int SETTLE_TO_ZERO_STATES = 0xffff0000 & ~MOST_INTERESTING_STATES; |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 1338 | |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1339 | public int states; |
| 1340 | |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 1341 | // Constants from WIFI_SUPPL_STATE_* |
| 1342 | public static final int STATE2_WIFI_SUPPL_STATE_SHIFT = 0; |
| 1343 | public static final int STATE2_WIFI_SUPPL_STATE_MASK = 0xf; |
| 1344 | // Values for NUM_WIFI_SIGNAL_STRENGTH_BINS |
| 1345 | public static final int STATE2_WIFI_SIGNAL_STRENGTH_SHIFT = 4; |
| 1346 | public static final int STATE2_WIFI_SIGNAL_STRENGTH_MASK = |
| 1347 | 0x7 << STATE2_WIFI_SIGNAL_STRENGTH_SHIFT; |
| 1348 | |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 1349 | public static final int STATE2_POWER_SAVE_FLAG = 1<<31; |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 1350 | public static final int STATE2_VIDEO_ON_FLAG = 1<<30; |
| 1351 | public static final int STATE2_WIFI_RUNNING_FLAG = 1<<29; |
| 1352 | public static final int STATE2_WIFI_ON_FLAG = 1<<28; |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 1353 | public static final int STATE2_FLASHLIGHT_FLAG = 1<<27; |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 1354 | public static final int STATE2_DEVICE_IDLE_SHIFT = 25; |
| 1355 | public static final int STATE2_DEVICE_IDLE_MASK = 0x3 << STATE2_DEVICE_IDLE_SHIFT; |
| 1356 | public static final int STATE2_CHARGING_FLAG = 1<<24; |
| 1357 | public static final int STATE2_PHONE_IN_CALL_FLAG = 1<<23; |
| 1358 | public static final int STATE2_BLUETOOTH_ON_FLAG = 1<<22; |
| 1359 | public static final int STATE2_CAMERA_FLAG = 1<<21; |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 1360 | public static final int STATE2_BLUETOOTH_SCAN_FLAG = 1 << 20; |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 1361 | |
| 1362 | public static final int MOST_INTERESTING_STATES2 = |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 1363 | STATE2_POWER_SAVE_FLAG | STATE2_WIFI_ON_FLAG | STATE2_DEVICE_IDLE_MASK |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 1364 | | STATE2_CHARGING_FLAG | STATE2_PHONE_IN_CALL_FLAG | STATE2_BLUETOOTH_ON_FLAG; |
| 1365 | |
| 1366 | public static final int SETTLE_TO_ZERO_STATES2 = 0xffff0000 & ~MOST_INTERESTING_STATES2; |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 1367 | |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 1368 | public int states2; |
| 1369 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1370 | // The wake lock that was acquired at this point. |
| 1371 | public HistoryTag wakelockTag; |
| 1372 | |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1373 | // Kernel wakeup reason at this point. |
| 1374 | public HistoryTag wakeReasonTag; |
| 1375 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 1376 | // Non-null when there is more detailed information at this step. |
| 1377 | public HistoryStepDetails stepDetails; |
| 1378 | |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 1379 | public static final int EVENT_FLAG_START = 0x8000; |
| 1380 | public static final int EVENT_FLAG_FINISH = 0x4000; |
| 1381 | |
| 1382 | // No event in this item. |
| 1383 | public static final int EVENT_NONE = 0x0000; |
| 1384 | // Event is about a process that is running. |
| 1385 | public static final int EVENT_PROC = 0x0001; |
| 1386 | // Event is about an application package that is in the foreground. |
| 1387 | public static final int EVENT_FOREGROUND = 0x0002; |
| 1388 | // Event is about an application package that is at the top of the screen. |
| 1389 | public static final int EVENT_TOP = 0x0003; |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 1390 | // Event is about active sync operations. |
Dianne Hackborn | a1f1a3c | 2014-02-24 18:12:28 -0800 | [diff] [blame] | 1391 | public static final int EVENT_SYNC = 0x0004; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 1392 | // Events for all additional wake locks aquired/release within a wake block. |
| 1393 | // These are not generated by default. |
| 1394 | public static final int EVENT_WAKE_LOCK = 0x0005; |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 1395 | // Event is about an application executing a scheduled job. |
| 1396 | public static final int EVENT_JOB = 0x0006; |
| 1397 | // Events for users running. |
| 1398 | public static final int EVENT_USER_RUNNING = 0x0007; |
| 1399 | // Events for foreground user. |
| 1400 | public static final int EVENT_USER_FOREGROUND = 0x0008; |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 1401 | // Event for connectivity changed. |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 1402 | public static final int EVENT_CONNECTIVITY_CHANGED = 0x0009; |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 1403 | // Event for becoming active taking us out of idle mode. |
Dianne Hackborn | b6683c4 | 2015-06-18 17:40:33 -0700 | [diff] [blame] | 1404 | public static final int EVENT_ACTIVE = 0x000a; |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 1405 | // Event for a package being installed. |
Dianne Hackborn | b6683c4 | 2015-06-18 17:40:33 -0700 | [diff] [blame] | 1406 | public static final int EVENT_PACKAGE_INSTALLED = 0x000b; |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 1407 | // Event for a package being uninstalled. |
Dianne Hackborn | b6683c4 | 2015-06-18 17:40:33 -0700 | [diff] [blame] | 1408 | public static final int EVENT_PACKAGE_UNINSTALLED = 0x000c; |
Dianne Hackborn | 1e38382 | 2015-04-10 14:02:33 -0700 | [diff] [blame] | 1409 | // Event for a package being uninstalled. |
Dianne Hackborn | b6683c4 | 2015-06-18 17:40:33 -0700 | [diff] [blame] | 1410 | public static final int EVENT_ALARM = 0x000d; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 1411 | // Record that we have decided we need to collect new stats data. |
Dianne Hackborn | b6683c4 | 2015-06-18 17:40:33 -0700 | [diff] [blame] | 1412 | public static final int EVENT_COLLECT_EXTERNAL_STATS = 0x000e; |
Amith Yamasani | 6776849 | 2015-06-09 12:23:58 -0700 | [diff] [blame] | 1413 | // 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] | 1414 | public static final int EVENT_PACKAGE_INACTIVE = 0x000f; |
Amith Yamasani | 6776849 | 2015-06-09 12:23:58 -0700 | [diff] [blame] | 1415 | // Event for a package becoming active due to an interaction. |
Dianne Hackborn | b6683c4 | 2015-06-18 17:40:33 -0700 | [diff] [blame] | 1416 | public static final int EVENT_PACKAGE_ACTIVE = 0x0010; |
Dianne Hackborn | fd854ee | 2015-07-13 18:00:37 -0700 | [diff] [blame] | 1417 | // Event for a package being on the temporary whitelist. |
| 1418 | public static final int EVENT_TEMP_WHITELIST = 0x0011; |
Dianne Hackborn | 280a64e | 2015-07-13 14:48:08 -0700 | [diff] [blame] | 1419 | // Event for the screen waking up. |
| 1420 | public static final int EVENT_SCREEN_WAKE_UP = 0x0012; |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 1421 | // Event for the UID that woke up the application processor. |
| 1422 | // Used for wakeups coming from WiFi, modem, etc. |
| 1423 | public static final int EVENT_WAKEUP_AP = 0x0013; |
Dianne Hackborn | d0db6f0 | 2016-07-18 14:14:20 -0700 | [diff] [blame] | 1424 | // Event for reporting that a specific partial wake lock has been held for a long duration. |
| 1425 | public static final int EVENT_LONG_WAKE_LOCK = 0x0014; |
Amith Yamasani | 6776849 | 2015-06-09 12:23:58 -0700 | [diff] [blame] | 1426 | |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 1427 | // Number of event types. |
Adam Lesinski | 041d917 | 2016-12-12 12:03:56 -0800 | [diff] [blame] | 1428 | public static final int EVENT_COUNT = 0x0016; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 1429 | // Mask to extract out only the type part of the event. |
| 1430 | 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] | 1431 | |
| 1432 | public static final int EVENT_PROC_START = EVENT_PROC | EVENT_FLAG_START; |
| 1433 | public static final int EVENT_PROC_FINISH = EVENT_PROC | EVENT_FLAG_FINISH; |
| 1434 | public static final int EVENT_FOREGROUND_START = EVENT_FOREGROUND | EVENT_FLAG_START; |
| 1435 | public static final int EVENT_FOREGROUND_FINISH = EVENT_FOREGROUND | EVENT_FLAG_FINISH; |
| 1436 | public static final int EVENT_TOP_START = EVENT_TOP | EVENT_FLAG_START; |
| 1437 | public static final int EVENT_TOP_FINISH = EVENT_TOP | EVENT_FLAG_FINISH; |
Dianne Hackborn | a1f1a3c | 2014-02-24 18:12:28 -0800 | [diff] [blame] | 1438 | public static final int EVENT_SYNC_START = EVENT_SYNC | EVENT_FLAG_START; |
| 1439 | public static final int EVENT_SYNC_FINISH = EVENT_SYNC | EVENT_FLAG_FINISH; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 1440 | public static final int EVENT_WAKE_LOCK_START = EVENT_WAKE_LOCK | EVENT_FLAG_START; |
| 1441 | 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] | 1442 | public static final int EVENT_JOB_START = EVENT_JOB | EVENT_FLAG_START; |
| 1443 | public static final int EVENT_JOB_FINISH = EVENT_JOB | EVENT_FLAG_FINISH; |
| 1444 | public static final int EVENT_USER_RUNNING_START = EVENT_USER_RUNNING | EVENT_FLAG_START; |
| 1445 | public static final int EVENT_USER_RUNNING_FINISH = EVENT_USER_RUNNING | EVENT_FLAG_FINISH; |
| 1446 | public static final int EVENT_USER_FOREGROUND_START = |
| 1447 | EVENT_USER_FOREGROUND | EVENT_FLAG_START; |
| 1448 | public static final int EVENT_USER_FOREGROUND_FINISH = |
| 1449 | EVENT_USER_FOREGROUND | EVENT_FLAG_FINISH; |
Dianne Hackborn | 1e38382 | 2015-04-10 14:02:33 -0700 | [diff] [blame] | 1450 | public static final int EVENT_ALARM_START = EVENT_ALARM | EVENT_FLAG_START; |
| 1451 | public static final int EVENT_ALARM_FINISH = EVENT_ALARM | EVENT_FLAG_FINISH; |
Dianne Hackborn | fd854ee | 2015-07-13 18:00:37 -0700 | [diff] [blame] | 1452 | public static final int EVENT_TEMP_WHITELIST_START = |
| 1453 | EVENT_TEMP_WHITELIST | EVENT_FLAG_START; |
| 1454 | public static final int EVENT_TEMP_WHITELIST_FINISH = |
| 1455 | EVENT_TEMP_WHITELIST | EVENT_FLAG_FINISH; |
Dianne Hackborn | d0db6f0 | 2016-07-18 14:14:20 -0700 | [diff] [blame] | 1456 | public static final int EVENT_LONG_WAKE_LOCK_START = |
| 1457 | EVENT_LONG_WAKE_LOCK | EVENT_FLAG_START; |
| 1458 | public static final int EVENT_LONG_WAKE_LOCK_FINISH = |
| 1459 | EVENT_LONG_WAKE_LOCK | EVENT_FLAG_FINISH; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1460 | |
| 1461 | // For CMD_EVENT. |
| 1462 | public int eventCode; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1463 | public HistoryTag eventTag; |
| 1464 | |
Dianne Hackborn | 9a75543 | 2014-05-15 17:05:22 -0700 | [diff] [blame] | 1465 | // 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] | 1466 | public long currentTime; |
| 1467 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1468 | // Meta-data when reading. |
| 1469 | public int numReadInts; |
| 1470 | |
| 1471 | // Pre-allocated objects. |
| 1472 | public final HistoryTag localWakelockTag = new HistoryTag(); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1473 | public final HistoryTag localWakeReasonTag = new HistoryTag(); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1474 | public final HistoryTag localEventTag = new HistoryTag(); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1475 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1476 | public HistoryItem() { |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1477 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame^] | 1478 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1479 | public HistoryItem(long time, Parcel src) { |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1480 | this.time = time; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1481 | numReadInts = 2; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 1482 | readFromParcel(src); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1483 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame^] | 1484 | |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1485 | public int describeContents() { |
| 1486 | return 0; |
| 1487 | } |
| 1488 | |
| 1489 | public void writeToParcel(Parcel dest, int flags) { |
| 1490 | dest.writeLong(time); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1491 | int bat = (((int)cmd)&0xff) |
| 1492 | | ((((int)batteryLevel)<<8)&0xff00) |
| 1493 | | ((((int)batteryStatus)<<16)&0xf0000) |
| 1494 | | ((((int)batteryHealth)<<20)&0xf00000) |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1495 | | ((((int)batteryPlugType)<<24)&0xf000000) |
| 1496 | | (wakelockTag != null ? 0x10000000 : 0) |
| 1497 | | (wakeReasonTag != null ? 0x20000000 : 0) |
| 1498 | | (eventCode != EVENT_NONE ? 0x40000000 : 0); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1499 | dest.writeInt(bat); |
| 1500 | bat = (((int)batteryTemperature)&0xffff) |
| 1501 | | ((((int)batteryVoltage)<<16)&0xffff0000); |
| 1502 | dest.writeInt(bat); |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 1503 | dest.writeInt(batteryChargeUAh); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1504 | dest.writeInt(states); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1505 | dest.writeInt(states2); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1506 | if (wakelockTag != null) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1507 | wakelockTag.writeToParcel(dest, flags); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1508 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1509 | if (wakeReasonTag != null) { |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1510 | wakeReasonTag.writeToParcel(dest, flags); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1511 | } |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 1512 | if (eventCode != EVENT_NONE) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1513 | dest.writeInt(eventCode); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1514 | eventTag.writeToParcel(dest, flags); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1515 | } |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 1516 | if (cmd == CMD_CURRENT_TIME || cmd == CMD_RESET) { |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1517 | dest.writeLong(currentTime); |
| 1518 | } |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1519 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 1520 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1521 | public void readFromParcel(Parcel src) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1522 | int start = src.dataPosition(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 1523 | int bat = src.readInt(); |
| 1524 | cmd = (byte)(bat&0xff); |
| 1525 | batteryLevel = (byte)((bat>>8)&0xff); |
| 1526 | batteryStatus = (byte)((bat>>16)&0xf); |
| 1527 | batteryHealth = (byte)((bat>>20)&0xf); |
| 1528 | batteryPlugType = (byte)((bat>>24)&0xf); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1529 | int bat2 = src.readInt(); |
| 1530 | batteryTemperature = (short)(bat2&0xffff); |
| 1531 | batteryVoltage = (char)((bat2>>16)&0xffff); |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 1532 | batteryChargeUAh = src.readInt(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 1533 | states = src.readInt(); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1534 | states2 = src.readInt(); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1535 | if ((bat&0x10000000) != 0) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1536 | wakelockTag = localWakelockTag; |
| 1537 | wakelockTag.readFromParcel(src); |
| 1538 | } else { |
| 1539 | wakelockTag = null; |
| 1540 | } |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1541 | if ((bat&0x20000000) != 0) { |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1542 | wakeReasonTag = localWakeReasonTag; |
| 1543 | wakeReasonTag.readFromParcel(src); |
| 1544 | } else { |
| 1545 | wakeReasonTag = null; |
| 1546 | } |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1547 | if ((bat&0x40000000) != 0) { |
| 1548 | eventCode = src.readInt(); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1549 | eventTag = localEventTag; |
| 1550 | eventTag.readFromParcel(src); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1551 | } else { |
| 1552 | eventCode = EVENT_NONE; |
| 1553 | eventTag = null; |
| 1554 | } |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 1555 | if (cmd == CMD_CURRENT_TIME || cmd == CMD_RESET) { |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1556 | currentTime = src.readLong(); |
| 1557 | } else { |
| 1558 | currentTime = 0; |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 1559 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1560 | numReadInts += (src.dataPosition()-start)/4; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 1561 | } |
| 1562 | |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 1563 | public void clear() { |
| 1564 | time = 0; |
| 1565 | cmd = CMD_NULL; |
| 1566 | batteryLevel = 0; |
| 1567 | batteryStatus = 0; |
| 1568 | batteryHealth = 0; |
| 1569 | batteryPlugType = 0; |
| 1570 | batteryTemperature = 0; |
| 1571 | batteryVoltage = 0; |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 1572 | batteryChargeUAh = 0; |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 1573 | states = 0; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1574 | states2 = 0; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1575 | wakelockTag = null; |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1576 | wakeReasonTag = null; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1577 | eventCode = EVENT_NONE; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1578 | eventTag = null; |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 1579 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame^] | 1580 | |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 1581 | public void setTo(HistoryItem o) { |
| 1582 | time = o.time; |
| 1583 | cmd = o.cmd; |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 1584 | setToCommon(o); |
| 1585 | } |
| 1586 | |
| 1587 | public void setTo(long time, byte cmd, HistoryItem o) { |
| 1588 | this.time = time; |
| 1589 | this.cmd = cmd; |
| 1590 | setToCommon(o); |
| 1591 | } |
| 1592 | |
| 1593 | private void setToCommon(HistoryItem o) { |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 1594 | batteryLevel = o.batteryLevel; |
| 1595 | batteryStatus = o.batteryStatus; |
| 1596 | batteryHealth = o.batteryHealth; |
| 1597 | batteryPlugType = o.batteryPlugType; |
| 1598 | batteryTemperature = o.batteryTemperature; |
| 1599 | batteryVoltage = o.batteryVoltage; |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 1600 | batteryChargeUAh = o.batteryChargeUAh; |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 1601 | states = o.states; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1602 | states2 = o.states2; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1603 | if (o.wakelockTag != null) { |
| 1604 | wakelockTag = localWakelockTag; |
| 1605 | wakelockTag.setTo(o.wakelockTag); |
| 1606 | } else { |
| 1607 | wakelockTag = null; |
| 1608 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1609 | if (o.wakeReasonTag != null) { |
| 1610 | wakeReasonTag = localWakeReasonTag; |
| 1611 | wakeReasonTag.setTo(o.wakeReasonTag); |
| 1612 | } else { |
| 1613 | wakeReasonTag = null; |
| 1614 | } |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1615 | eventCode = o.eventCode; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1616 | if (o.eventTag != null) { |
| 1617 | eventTag = localEventTag; |
| 1618 | eventTag.setTo(o.eventTag); |
| 1619 | } else { |
| 1620 | eventTag = null; |
| 1621 | } |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1622 | currentTime = o.currentTime; |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 1623 | } |
| 1624 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1625 | public boolean sameNonEvent(HistoryItem o) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 1626 | return batteryLevel == o.batteryLevel |
| 1627 | && batteryStatus == o.batteryStatus |
| 1628 | && batteryHealth == o.batteryHealth |
| 1629 | && batteryPlugType == o.batteryPlugType |
| 1630 | && batteryTemperature == o.batteryTemperature |
| 1631 | && batteryVoltage == o.batteryVoltage |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 1632 | && batteryChargeUAh == o.batteryChargeUAh |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1633 | && states == o.states |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1634 | && states2 == o.states2 |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1635 | && currentTime == o.currentTime; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 1636 | } |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1637 | |
| 1638 | public boolean same(HistoryItem o) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1639 | if (!sameNonEvent(o) || eventCode != o.eventCode) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1640 | return false; |
| 1641 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1642 | if (wakelockTag != o.wakelockTag) { |
| 1643 | if (wakelockTag == null || o.wakelockTag == null) { |
| 1644 | return false; |
| 1645 | } |
| 1646 | if (!wakelockTag.equals(o.wakelockTag)) { |
| 1647 | return false; |
| 1648 | } |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1649 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1650 | if (wakeReasonTag != o.wakeReasonTag) { |
| 1651 | if (wakeReasonTag == null || o.wakeReasonTag == null) { |
| 1652 | return false; |
| 1653 | } |
| 1654 | if (!wakeReasonTag.equals(o.wakeReasonTag)) { |
| 1655 | return false; |
| 1656 | } |
| 1657 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1658 | if (eventTag != o.eventTag) { |
| 1659 | if (eventTag == null || o.eventTag == null) { |
| 1660 | return false; |
| 1661 | } |
| 1662 | if (!eventTag.equals(o.eventTag)) { |
| 1663 | return false; |
| 1664 | } |
| 1665 | } |
| 1666 | return true; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1667 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1668 | } |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 1669 | |
| 1670 | public final static class HistoryEventTracker { |
| 1671 | private final HashMap<String, SparseIntArray>[] mActiveEvents |
| 1672 | = (HashMap<String, SparseIntArray>[]) new HashMap[HistoryItem.EVENT_COUNT]; |
| 1673 | |
| 1674 | public boolean updateState(int code, String name, int uid, int poolIdx) { |
| 1675 | if ((code&HistoryItem.EVENT_FLAG_START) != 0) { |
| 1676 | int idx = code&HistoryItem.EVENT_TYPE_MASK; |
| 1677 | HashMap<String, SparseIntArray> active = mActiveEvents[idx]; |
| 1678 | if (active == null) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 1679 | active = new HashMap<>(); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 1680 | mActiveEvents[idx] = active; |
| 1681 | } |
| 1682 | SparseIntArray uids = active.get(name); |
| 1683 | if (uids == null) { |
| 1684 | uids = new SparseIntArray(); |
| 1685 | active.put(name, uids); |
| 1686 | } |
| 1687 | if (uids.indexOfKey(uid) >= 0) { |
| 1688 | // Already set, nothing to do! |
| 1689 | return false; |
| 1690 | } |
| 1691 | uids.put(uid, poolIdx); |
| 1692 | } else if ((code&HistoryItem.EVENT_FLAG_FINISH) != 0) { |
| 1693 | int idx = code&HistoryItem.EVENT_TYPE_MASK; |
| 1694 | HashMap<String, SparseIntArray> active = mActiveEvents[idx]; |
| 1695 | if (active == null) { |
| 1696 | // not currently active, nothing to do. |
| 1697 | return false; |
| 1698 | } |
| 1699 | SparseIntArray uids = active.get(name); |
| 1700 | if (uids == null) { |
| 1701 | // not currently active, nothing to do. |
| 1702 | return false; |
| 1703 | } |
| 1704 | idx = uids.indexOfKey(uid); |
| 1705 | if (idx < 0) { |
| 1706 | // not currently active, nothing to do. |
| 1707 | return false; |
| 1708 | } |
| 1709 | uids.removeAt(idx); |
| 1710 | if (uids.size() <= 0) { |
| 1711 | active.remove(name); |
| 1712 | } |
| 1713 | } |
| 1714 | return true; |
| 1715 | } |
| 1716 | |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 1717 | public void removeEvents(int code) { |
| 1718 | int idx = code&HistoryItem.EVENT_TYPE_MASK; |
| 1719 | mActiveEvents[idx] = null; |
| 1720 | } |
| 1721 | |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 1722 | public HashMap<String, SparseIntArray> getStateForEvent(int code) { |
| 1723 | return mActiveEvents[code]; |
| 1724 | } |
| 1725 | } |
| 1726 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1727 | public static final class BitDescription { |
| 1728 | public final int mask; |
| 1729 | public final int shift; |
| 1730 | public final String name; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1731 | public final String shortName; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1732 | public final String[] values; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1733 | public final String[] shortValues; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame^] | 1734 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1735 | public BitDescription(int mask, String name, String shortName) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1736 | this.mask = mask; |
| 1737 | this.shift = -1; |
| 1738 | this.name = name; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1739 | this.shortName = shortName; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1740 | this.values = null; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1741 | this.shortValues = null; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1742 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame^] | 1743 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1744 | public BitDescription(int mask, int shift, String name, String shortName, |
| 1745 | String[] values, String[] shortValues) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1746 | this.mask = mask; |
| 1747 | this.shift = shift; |
| 1748 | this.name = name; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1749 | this.shortName = shortName; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1750 | this.values = values; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1751 | this.shortValues = shortValues; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1752 | } |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1753 | } |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 1754 | |
Dianne Hackborn | fc06413 | 2014-06-02 12:42:12 -0700 | [diff] [blame] | 1755 | /** |
| 1756 | * Don't allow any more batching in to the current history event. This |
| 1757 | * is called when printing partial histories, so to ensure that the next |
| 1758 | * history event will go in to a new batch after what was printed in the |
| 1759 | * last partial history. |
| 1760 | */ |
| 1761 | public abstract void commitCurrentHistoryBatchLocked(); |
| 1762 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1763 | public abstract int getHistoryTotalSize(); |
| 1764 | |
| 1765 | public abstract int getHistoryUsedSize(); |
| 1766 | |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 1767 | public abstract boolean startIteratingHistoryLocked(); |
| 1768 | |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 1769 | public abstract int getHistoryStringPoolSize(); |
| 1770 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1771 | public abstract int getHistoryStringPoolBytes(); |
| 1772 | |
| 1773 | public abstract String getHistoryTagPoolString(int index); |
| 1774 | |
| 1775 | public abstract int getHistoryTagPoolUid(int index); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 1776 | |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 1777 | public abstract boolean getNextHistoryLocked(HistoryItem out); |
| 1778 | |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 1779 | public abstract void finishIteratingHistoryLocked(); |
| 1780 | |
| 1781 | public abstract boolean startIteratingOldHistoryLocked(); |
| 1782 | |
| 1783 | public abstract boolean getNextOldHistoryLocked(HistoryItem out); |
| 1784 | |
| 1785 | public abstract void finishIteratingOldHistoryLocked(); |
| 1786 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1787 | /** |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 1788 | * Return the base time offset for the battery history. |
| 1789 | */ |
| 1790 | public abstract long getHistoryBaseTime(); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame^] | 1791 | |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 1792 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1793 | * Returns the number of times the device has been started. |
| 1794 | */ |
| 1795 | public abstract int getStartCount(); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame^] | 1796 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1797 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 1798 | * 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] | 1799 | * running on battery. |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame^] | 1800 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1801 | * {@hide} |
| 1802 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1803 | public abstract long getScreenOnTime(long elapsedRealtimeUs, int which); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame^] | 1804 | |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 1805 | /** |
| 1806 | * Returns the number of times the screen was turned on. |
| 1807 | * |
| 1808 | * {@hide} |
| 1809 | */ |
| 1810 | public abstract int getScreenOnCount(int which); |
| 1811 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 1812 | public abstract long getInteractiveTime(long elapsedRealtimeUs, int which); |
| 1813 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1814 | public static final int SCREEN_BRIGHTNESS_DARK = 0; |
| 1815 | public static final int SCREEN_BRIGHTNESS_DIM = 1; |
| 1816 | public static final int SCREEN_BRIGHTNESS_MEDIUM = 2; |
| 1817 | public static final int SCREEN_BRIGHTNESS_LIGHT = 3; |
| 1818 | public static final int SCREEN_BRIGHTNESS_BRIGHT = 4; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame^] | 1819 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1820 | static final String[] SCREEN_BRIGHTNESS_NAMES = { |
| 1821 | "dark", "dim", "medium", "light", "bright" |
| 1822 | }; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame^] | 1823 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1824 | static final String[] SCREEN_BRIGHTNESS_SHORT_NAMES = { |
| 1825 | "0", "1", "2", "3", "4" |
| 1826 | }; |
| 1827 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1828 | public static final int NUM_SCREEN_BRIGHTNESS_BINS = 5; |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 1829 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1830 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 1831 | * Returns the time in microseconds that the screen has been on with |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1832 | * the given brightness |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame^] | 1833 | * |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1834 | * {@hide} |
| 1835 | */ |
| 1836 | public abstract long getScreenBrightnessTime(int brightnessBin, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1837 | long elapsedRealtimeUs, int which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1838 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1839 | /** |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 1840 | * 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] | 1841 | * running on battery. |
| 1842 | * |
| 1843 | * {@hide} |
| 1844 | */ |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 1845 | public abstract long getPowerSaveModeEnabledTime(long elapsedRealtimeUs, int which); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 1846 | |
| 1847 | /** |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 1848 | * Returns the number of times that power save mode was enabled. |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 1849 | * |
| 1850 | * {@hide} |
| 1851 | */ |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 1852 | public abstract int getPowerSaveModeEnabledCount(int which); |
| 1853 | |
| 1854 | /** |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 1855 | * Constant for device idle mode: not active. |
| 1856 | */ |
| 1857 | public static final int DEVICE_IDLE_MODE_OFF = 0; |
| 1858 | |
| 1859 | /** |
| 1860 | * Constant for device idle mode: active in lightweight mode. |
| 1861 | */ |
| 1862 | public static final int DEVICE_IDLE_MODE_LIGHT = 1; |
| 1863 | |
| 1864 | /** |
| 1865 | * Constant for device idle mode: active in full mode. |
| 1866 | */ |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 1867 | public static final int DEVICE_IDLE_MODE_DEEP = 2; |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 1868 | |
| 1869 | /** |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 1870 | * Returns the time in microseconds that device has been in idle mode while |
| 1871 | * running on battery. |
| 1872 | * |
| 1873 | * {@hide} |
| 1874 | */ |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 1875 | public abstract long getDeviceIdleModeTime(int mode, long elapsedRealtimeUs, int which); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 1876 | |
| 1877 | /** |
| 1878 | * Returns the number of times that the devie has gone in to idle mode. |
| 1879 | * |
| 1880 | * {@hide} |
| 1881 | */ |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 1882 | public abstract int getDeviceIdleModeCount(int mode, int which); |
| 1883 | |
| 1884 | /** |
| 1885 | * Return the longest duration we spent in a particular device idle mode (fully in the |
| 1886 | * mode, not in idle maintenance etc). |
| 1887 | */ |
| 1888 | public abstract long getLongestDeviceIdleModeTime(int mode); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 1889 | |
| 1890 | /** |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 1891 | * 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] | 1892 | * battery. This is broader than {@link #getDeviceIdleModeTime} -- it |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 1893 | * counts all of the time that we consider the device to be idle, whether or not |
| 1894 | * it is currently in the actual device idle mode. |
| 1895 | * |
| 1896 | * {@hide} |
| 1897 | */ |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 1898 | public abstract long getDeviceIdlingTime(int mode, long elapsedRealtimeUs, int which); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 1899 | |
| 1900 | /** |
| 1901 | * Returns the number of times that the devie has started idling. |
| 1902 | * |
| 1903 | * {@hide} |
| 1904 | */ |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 1905 | public abstract int getDeviceIdlingCount(int mode, int which); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 1906 | |
| 1907 | /** |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 1908 | * Returns the number of times that connectivity state changed. |
| 1909 | * |
| 1910 | * {@hide} |
| 1911 | */ |
| 1912 | public abstract int getNumConnectivityChange(int which); |
| 1913 | |
| 1914 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 1915 | * 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] | 1916 | * running on battery. |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame^] | 1917 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1918 | * {@hide} |
| 1919 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1920 | public abstract long getPhoneOnTime(long elapsedRealtimeUs, int which); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame^] | 1921 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 1922 | /** |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 1923 | * Returns the number of times a phone call was activated. |
| 1924 | * |
| 1925 | * {@hide} |
| 1926 | */ |
| 1927 | public abstract int getPhoneOnCount(int which); |
| 1928 | |
| 1929 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 1930 | * Returns the time in microseconds that the phone has been running with |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 1931 | * the given signal strength. |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame^] | 1932 | * |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 1933 | * {@hide} |
| 1934 | */ |
| 1935 | public abstract long getPhoneSignalStrengthTime(int strengthBin, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1936 | long elapsedRealtimeUs, int which); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 1937 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1938 | /** |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 1939 | * Returns the time in microseconds that the phone has been trying to |
| 1940 | * acquire a signal. |
| 1941 | * |
| 1942 | * {@hide} |
| 1943 | */ |
| 1944 | public abstract long getPhoneSignalScanningTime( |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1945 | long elapsedRealtimeUs, int which); |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 1946 | |
| 1947 | /** |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1948 | * Returns the number of times the phone has entered the given signal strength. |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame^] | 1949 | * |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1950 | * {@hide} |
| 1951 | */ |
| 1952 | public abstract int getPhoneSignalStrengthCount(int strengthBin, int which); |
| 1953 | |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 1954 | /** |
| 1955 | * Returns the time in microseconds that the mobile network has been active |
| 1956 | * (in a high power state). |
| 1957 | * |
| 1958 | * {@hide} |
| 1959 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1960 | public abstract long getMobileRadioActiveTime(long elapsedRealtimeUs, int which); |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 1961 | |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 1962 | /** |
| 1963 | * Returns the number of times that the mobile network has transitioned to the |
| 1964 | * active state. |
| 1965 | * |
| 1966 | * {@hide} |
| 1967 | */ |
| 1968 | public abstract int getMobileRadioActiveCount(int which); |
| 1969 | |
| 1970 | /** |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1971 | * Returns the time in microseconds that is the difference between the mobile radio |
| 1972 | * time we saw based on the elapsed timestamp when going down vs. the given time stamp |
| 1973 | * from the radio. |
| 1974 | * |
| 1975 | * {@hide} |
| 1976 | */ |
| 1977 | public abstract long getMobileRadioActiveAdjustedTime(int which); |
| 1978 | |
| 1979 | /** |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 1980 | * Returns the time in microseconds that the mobile network has been active |
| 1981 | * (in a high power state) but not being able to blame on an app. |
| 1982 | * |
| 1983 | * {@hide} |
| 1984 | */ |
| 1985 | public abstract long getMobileRadioActiveUnknownTime(int which); |
| 1986 | |
| 1987 | /** |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 1988 | * 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] | 1989 | * |
| 1990 | * {@hide} |
| 1991 | */ |
| 1992 | public abstract int getMobileRadioActiveUnknownCount(int which); |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 1993 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 1994 | public static final int DATA_CONNECTION_NONE = 0; |
| 1995 | public static final int DATA_CONNECTION_GPRS = 1; |
| 1996 | public static final int DATA_CONNECTION_EDGE = 2; |
| 1997 | public static final int DATA_CONNECTION_UMTS = 3; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1998 | public static final int DATA_CONNECTION_CDMA = 4; |
| 1999 | public static final int DATA_CONNECTION_EVDO_0 = 5; |
| 2000 | public static final int DATA_CONNECTION_EVDO_A = 6; |
| 2001 | public static final int DATA_CONNECTION_1xRTT = 7; |
| 2002 | public static final int DATA_CONNECTION_HSDPA = 8; |
| 2003 | public static final int DATA_CONNECTION_HSUPA = 9; |
| 2004 | public static final int DATA_CONNECTION_HSPA = 10; |
| 2005 | public static final int DATA_CONNECTION_IDEN = 11; |
| 2006 | public static final int DATA_CONNECTION_EVDO_B = 12; |
Robert Greenwalt | 962a990 | 2010-11-02 11:10:25 -0700 | [diff] [blame] | 2007 | public static final int DATA_CONNECTION_LTE = 13; |
| 2008 | public static final int DATA_CONNECTION_EHRPD = 14; |
Patrick Tjin | b71703c | 2013-11-06 09:27:03 -0800 | [diff] [blame] | 2009 | public static final int DATA_CONNECTION_HSPAP = 15; |
| 2010 | public static final int DATA_CONNECTION_OTHER = 16; |
Robert Greenwalt | 962a990 | 2010-11-02 11:10:25 -0700 | [diff] [blame] | 2011 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 2012 | static final String[] DATA_CONNECTION_NAMES = { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2013 | "none", "gprs", "edge", "umts", "cdma", "evdo_0", "evdo_A", |
Robert Greenwalt | 962a990 | 2010-11-02 11:10:25 -0700 | [diff] [blame] | 2014 | "1xrtt", "hsdpa", "hsupa", "hspa", "iden", "evdo_b", "lte", |
Patrick Tjin | b71703c | 2013-11-06 09:27:03 -0800 | [diff] [blame] | 2015 | "ehrpd", "hspap", "other" |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 2016 | }; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame^] | 2017 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2018 | public static final int NUM_DATA_CONNECTION_TYPES = DATA_CONNECTION_OTHER+1; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame^] | 2019 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 2020 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 2021 | * Returns the time in microseconds that the phone has been running with |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 2022 | * the given data connection. |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame^] | 2023 | * |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 2024 | * {@hide} |
| 2025 | */ |
| 2026 | public abstract long getPhoneDataConnectionTime(int dataType, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2027 | long elapsedRealtimeUs, int which); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 2028 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2029 | /** |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2030 | * Returns the number of times the phone has entered the given data |
| 2031 | * connection type. |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame^] | 2032 | * |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2033 | * {@hide} |
| 2034 | */ |
| 2035 | public abstract int getPhoneDataConnectionCount(int dataType, int which); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2036 | |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 2037 | public static final int WIFI_SUPPL_STATE_INVALID = 0; |
| 2038 | public static final int WIFI_SUPPL_STATE_DISCONNECTED = 1; |
| 2039 | public static final int WIFI_SUPPL_STATE_INTERFACE_DISABLED = 2; |
| 2040 | public static final int WIFI_SUPPL_STATE_INACTIVE = 3; |
| 2041 | public static final int WIFI_SUPPL_STATE_SCANNING = 4; |
| 2042 | public static final int WIFI_SUPPL_STATE_AUTHENTICATING = 5; |
| 2043 | public static final int WIFI_SUPPL_STATE_ASSOCIATING = 6; |
| 2044 | public static final int WIFI_SUPPL_STATE_ASSOCIATED = 7; |
| 2045 | public static final int WIFI_SUPPL_STATE_FOUR_WAY_HANDSHAKE = 8; |
| 2046 | public static final int WIFI_SUPPL_STATE_GROUP_HANDSHAKE = 9; |
| 2047 | public static final int WIFI_SUPPL_STATE_COMPLETED = 10; |
| 2048 | public static final int WIFI_SUPPL_STATE_DORMANT = 11; |
| 2049 | public static final int WIFI_SUPPL_STATE_UNINITIALIZED = 12; |
| 2050 | |
| 2051 | public static final int NUM_WIFI_SUPPL_STATES = WIFI_SUPPL_STATE_UNINITIALIZED+1; |
| 2052 | |
| 2053 | static final String[] WIFI_SUPPL_STATE_NAMES = { |
| 2054 | "invalid", "disconn", "disabled", "inactive", "scanning", |
| 2055 | "authenticating", "associating", "associated", "4-way-handshake", |
| 2056 | "group-handshake", "completed", "dormant", "uninit" |
| 2057 | }; |
| 2058 | |
| 2059 | static final String[] WIFI_SUPPL_STATE_SHORT_NAMES = { |
| 2060 | "inv", "dsc", "dis", "inact", "scan", |
| 2061 | "auth", "ascing", "asced", "4-way", |
| 2062 | "group", "compl", "dorm", "uninit" |
| 2063 | }; |
| 2064 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2065 | public static final BitDescription[] HISTORY_STATE_DESCRIPTIONS |
| 2066 | = new BitDescription[] { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2067 | new BitDescription(HistoryItem.STATE_CPU_RUNNING_FLAG, "running", "r"), |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2068 | new BitDescription(HistoryItem.STATE_WAKE_LOCK_FLAG, "wake_lock", "w"), |
| 2069 | new BitDescription(HistoryItem.STATE_SENSOR_ON_FLAG, "sensor", "s"), |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2070 | new BitDescription(HistoryItem.STATE_GPS_ON_FLAG, "gps", "g"), |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2071 | new BitDescription(HistoryItem.STATE_WIFI_FULL_LOCK_FLAG, "wifi_full_lock", "Wl"), |
| 2072 | new BitDescription(HistoryItem.STATE_WIFI_SCAN_FLAG, "wifi_scan", "Ws"), |
| 2073 | new BitDescription(HistoryItem.STATE_WIFI_MULTICAST_ON_FLAG, "wifi_multicast", "Wm"), |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 2074 | new BitDescription(HistoryItem.STATE_WIFI_RADIO_ACTIVE_FLAG, "wifi_radio", "Wr"), |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 2075 | new BitDescription(HistoryItem.STATE_MOBILE_RADIO_ACTIVE_FLAG, "mobile_radio", "Pr"), |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2076 | new BitDescription(HistoryItem.STATE_PHONE_SCANNING_FLAG, "phone_scanning", "Psc"), |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2077 | new BitDescription(HistoryItem.STATE_AUDIO_ON_FLAG, "audio", "a"), |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2078 | new BitDescription(HistoryItem.STATE_SCREEN_ON_FLAG, "screen", "S"), |
| 2079 | new BitDescription(HistoryItem.STATE_BATTERY_PLUGGED_FLAG, "plugged", "BP"), |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2080 | new BitDescription(HistoryItem.STATE_DATA_CONNECTION_MASK, |
| 2081 | HistoryItem.STATE_DATA_CONNECTION_SHIFT, "data_conn", "Pcn", |
| 2082 | DATA_CONNECTION_NAMES, DATA_CONNECTION_NAMES), |
| 2083 | new BitDescription(HistoryItem.STATE_PHONE_STATE_MASK, |
| 2084 | HistoryItem.STATE_PHONE_STATE_SHIFT, "phone_state", "Pst", |
| 2085 | new String[] {"in", "out", "emergency", "off"}, |
| 2086 | new String[] {"in", "out", "em", "off"}), |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 2087 | new BitDescription(HistoryItem.STATE_PHONE_SIGNAL_STRENGTH_MASK, |
| 2088 | HistoryItem.STATE_PHONE_SIGNAL_STRENGTH_SHIFT, "phone_signal_strength", "Pss", |
| 2089 | SignalStrength.SIGNAL_STRENGTH_NAMES, |
| 2090 | new String[] { "0", "1", "2", "3", "4" }), |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2091 | new BitDescription(HistoryItem.STATE_BRIGHTNESS_MASK, |
| 2092 | HistoryItem.STATE_BRIGHTNESS_SHIFT, "brightness", "Sb", |
| 2093 | SCREEN_BRIGHTNESS_NAMES, SCREEN_BRIGHTNESS_SHORT_NAMES), |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2094 | }; |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2095 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2096 | public static final BitDescription[] HISTORY_STATE2_DESCRIPTIONS |
| 2097 | = new BitDescription[] { |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 2098 | new BitDescription(HistoryItem.STATE2_POWER_SAVE_FLAG, "power_save", "ps"), |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 2099 | new BitDescription(HistoryItem.STATE2_VIDEO_ON_FLAG, "video", "v"), |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 2100 | new BitDescription(HistoryItem.STATE2_WIFI_RUNNING_FLAG, "wifi_running", "Ww"), |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 2101 | new BitDescription(HistoryItem.STATE2_WIFI_ON_FLAG, "wifi", "W"), |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 2102 | new BitDescription(HistoryItem.STATE2_FLASHLIGHT_FLAG, "flashlight", "fl"), |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 2103 | new BitDescription(HistoryItem.STATE2_DEVICE_IDLE_MASK, |
| 2104 | HistoryItem.STATE2_DEVICE_IDLE_SHIFT, "device_idle", "di", |
| 2105 | new String[] { "off", "light", "full", "???" }, |
| 2106 | new String[] { "off", "light", "full", "???" }), |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 2107 | new BitDescription(HistoryItem.STATE2_CHARGING_FLAG, "charging", "ch"), |
| 2108 | new BitDescription(HistoryItem.STATE2_PHONE_IN_CALL_FLAG, "phone_in_call", "Pcl"), |
| 2109 | new BitDescription(HistoryItem.STATE2_BLUETOOTH_ON_FLAG, "bluetooth", "b"), |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 2110 | new BitDescription(HistoryItem.STATE2_WIFI_SIGNAL_STRENGTH_MASK, |
| 2111 | HistoryItem.STATE2_WIFI_SIGNAL_STRENGTH_SHIFT, "wifi_signal_strength", "Wss", |
| 2112 | new String[] { "0", "1", "2", "3", "4" }, |
| 2113 | new String[] { "0", "1", "2", "3", "4" }), |
| 2114 | new BitDescription(HistoryItem.STATE2_WIFI_SUPPL_STATE_MASK, |
| 2115 | HistoryItem.STATE2_WIFI_SUPPL_STATE_SHIFT, "wifi_suppl", "Wsp", |
| 2116 | WIFI_SUPPL_STATE_NAMES, WIFI_SUPPL_STATE_SHORT_NAMES), |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 2117 | new BitDescription(HistoryItem.STATE2_CAMERA_FLAG, "camera", "ca"), |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 2118 | new BitDescription(HistoryItem.STATE2_BLUETOOTH_SCAN_FLAG, "ble_scan", "bles"), |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2119 | }; |
| 2120 | |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 2121 | public static final String[] HISTORY_EVENT_NAMES = new String[] { |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 2122 | "null", "proc", "fg", "top", "sync", "wake_lock_in", "job", "user", "userfg", "conn", |
Kweku Adams | 134c59b | 2017-03-08 16:48:01 -0800 | [diff] [blame] | 2123 | "active", "pkginst", "pkgunin", "alarm", "stats", "pkginactive", "pkgactive", |
| 2124 | "tmpwhitelist", "screenwake", "wakeupap", "longwake", "est_capacity" |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 2125 | }; |
| 2126 | |
| 2127 | public static final String[] HISTORY_EVENT_CHECKIN_NAMES = new String[] { |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 2128 | "Enl", "Epr", "Efg", "Etp", "Esy", "Ewl", "Ejb", "Eur", "Euf", "Ecn", |
Dianne Hackborn | 280a64e | 2015-07-13 14:48:08 -0700 | [diff] [blame] | 2129 | "Eac", "Epi", "Epu", "Eal", "Est", "Eai", "Eaa", "Etw", |
Adam Lesinski | 041d917 | 2016-12-12 12:03:56 -0800 | [diff] [blame] | 2130 | "Esw", "Ewa", "Elw", "Eec" |
| 2131 | }; |
| 2132 | |
| 2133 | @FunctionalInterface |
| 2134 | public interface IntToString { |
| 2135 | String applyAsString(int val); |
| 2136 | } |
| 2137 | |
| 2138 | private static final IntToString sUidToString = UserHandle::formatUid; |
| 2139 | private static final IntToString sIntToString = Integer::toString; |
| 2140 | |
| 2141 | public static final IntToString[] HISTORY_EVENT_INT_FORMATTERS = new IntToString[] { |
| 2142 | sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, |
| 2143 | sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, |
| 2144 | sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, |
| 2145 | sUidToString, sUidToString, sUidToString, sIntToString |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 2146 | }; |
| 2147 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2148 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 2149 | * 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] | 2150 | * running on battery. |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame^] | 2151 | * |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2152 | * {@hide} |
| 2153 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2154 | public abstract long getWifiOnTime(long elapsedRealtimeUs, int which); |
Eric Shienbrood | d4c5f89 | 2009-03-24 18:13:20 -0700 | [diff] [blame] | 2155 | |
| 2156 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 2157 | * 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] | 2158 | * been in the running state while the device was running on battery. |
| 2159 | * |
| 2160 | * {@hide} |
| 2161 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2162 | public abstract long getGlobalWifiRunningTime(long elapsedRealtimeUs, int which); |
Eric Shienbrood | d4c5f89 | 2009-03-24 18:13:20 -0700 | [diff] [blame] | 2163 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 2164 | public static final int WIFI_STATE_OFF = 0; |
| 2165 | public static final int WIFI_STATE_OFF_SCANNING = 1; |
| 2166 | public static final int WIFI_STATE_ON_NO_NETWORKS = 2; |
| 2167 | public static final int WIFI_STATE_ON_DISCONNECTED = 3; |
| 2168 | public static final int WIFI_STATE_ON_CONNECTED_STA = 4; |
| 2169 | public static final int WIFI_STATE_ON_CONNECTED_P2P = 5; |
| 2170 | public static final int WIFI_STATE_ON_CONNECTED_STA_P2P = 6; |
| 2171 | public static final int WIFI_STATE_SOFT_AP = 7; |
| 2172 | |
| 2173 | static final String[] WIFI_STATE_NAMES = { |
| 2174 | "off", "scanning", "no_net", "disconn", |
| 2175 | "sta", "p2p", "sta_p2p", "soft_ap" |
| 2176 | }; |
| 2177 | |
| 2178 | public static final int NUM_WIFI_STATES = WIFI_STATE_SOFT_AP+1; |
| 2179 | |
| 2180 | /** |
| 2181 | * Returns the time in microseconds that WiFi has been running in the given state. |
| 2182 | * |
| 2183 | * {@hide} |
| 2184 | */ |
| 2185 | public abstract long getWifiStateTime(int wifiState, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2186 | long elapsedRealtimeUs, int which); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 2187 | |
| 2188 | /** |
| 2189 | * Returns the number of times that WiFi has entered the given state. |
| 2190 | * |
| 2191 | * {@hide} |
| 2192 | */ |
| 2193 | public abstract int getWifiStateCount(int wifiState, int which); |
| 2194 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2195 | /** |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 2196 | * Returns the time in microseconds that the wifi supplicant has been |
| 2197 | * in a given state. |
| 2198 | * |
| 2199 | * {@hide} |
| 2200 | */ |
| 2201 | public abstract long getWifiSupplStateTime(int state, long elapsedRealtimeUs, int which); |
| 2202 | |
| 2203 | /** |
| 2204 | * Returns the number of times that the wifi supplicant has transitioned |
| 2205 | * to a given state. |
| 2206 | * |
| 2207 | * {@hide} |
| 2208 | */ |
| 2209 | public abstract int getWifiSupplStateCount(int state, int which); |
| 2210 | |
| 2211 | public static final int NUM_WIFI_SIGNAL_STRENGTH_BINS = 5; |
| 2212 | |
| 2213 | /** |
| 2214 | * Returns the time in microseconds that WIFI has been running with |
| 2215 | * the given signal strength. |
| 2216 | * |
| 2217 | * {@hide} |
| 2218 | */ |
| 2219 | public abstract long getWifiSignalStrengthTime(int strengthBin, |
| 2220 | long elapsedRealtimeUs, int which); |
| 2221 | |
| 2222 | /** |
| 2223 | * Returns the number of times WIFI has entered the given signal strength. |
| 2224 | * |
| 2225 | * {@hide} |
| 2226 | */ |
| 2227 | public abstract int getWifiSignalStrengthCount(int strengthBin, int which); |
| 2228 | |
| 2229 | /** |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 2230 | * Returns the time in microseconds that the flashlight has been on while the device was |
| 2231 | * running on battery. |
| 2232 | * |
| 2233 | * {@hide} |
| 2234 | */ |
| 2235 | public abstract long getFlashlightOnTime(long elapsedRealtimeUs, int which); |
| 2236 | |
| 2237 | /** |
| 2238 | * Returns the number of times that the flashlight has been turned on while the device was |
| 2239 | * running on battery. |
| 2240 | * |
| 2241 | * {@hide} |
| 2242 | */ |
| 2243 | public abstract long getFlashlightOnCount(int which); |
| 2244 | |
Ruben Brunk | 5b1308f | 2015-06-03 18:49:27 -0700 | [diff] [blame] | 2245 | /** |
| 2246 | * Returns the time in microseconds that the camera has been on while the device was |
| 2247 | * running on battery. |
| 2248 | * |
| 2249 | * {@hide} |
| 2250 | */ |
| 2251 | public abstract long getCameraOnTime(long elapsedRealtimeUs, int which); |
| 2252 | |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 2253 | /** |
| 2254 | * Returns the time in microseconds that bluetooth scans were running while the device was |
| 2255 | * on battery. |
| 2256 | * |
| 2257 | * {@hide} |
| 2258 | */ |
| 2259 | public abstract long getBluetoothScanTime(long elapsedRealtimeUs, int which); |
Ruben Brunk | 5b1308f | 2015-06-03 18:49:27 -0700 | [diff] [blame] | 2260 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2261 | public static final int NETWORK_MOBILE_RX_DATA = 0; |
| 2262 | public static final int NETWORK_MOBILE_TX_DATA = 1; |
| 2263 | public static final int NETWORK_WIFI_RX_DATA = 2; |
| 2264 | public static final int NETWORK_WIFI_TX_DATA = 3; |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 2265 | public static final int NETWORK_BT_RX_DATA = 4; |
| 2266 | public static final int NETWORK_BT_TX_DATA = 5; |
Amith Yamasani | 59fe841 | 2017-03-03 16:28:52 -0800 | [diff] [blame] | 2267 | public static final int NETWORK_MOBILE_BG_RX_DATA = 6; |
| 2268 | public static final int NETWORK_MOBILE_BG_TX_DATA = 7; |
| 2269 | public static final int NETWORK_WIFI_BG_RX_DATA = 8; |
| 2270 | public static final int NETWORK_WIFI_BG_TX_DATA = 9; |
| 2271 | 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] | 2272 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2273 | public abstract long getNetworkActivityBytes(int type, int which); |
| 2274 | public abstract long getNetworkActivityPackets(int type, int which); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 2275 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 2276 | /** |
Adam Lesinski | 1739076 | 2015-04-10 13:17:47 -0700 | [diff] [blame] | 2277 | * Returns true if the BatteryStats object has detailed WiFi power reports. |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 2278 | * When true, calling {@link #getWifiControllerActivity()} will yield the |
Adam Lesinski | 1739076 | 2015-04-10 13:17:47 -0700 | [diff] [blame] | 2279 | * actual power data. |
| 2280 | */ |
| 2281 | public abstract boolean hasWifiActivityReporting(); |
| 2282 | |
| 2283 | /** |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 2284 | * Returns a {@link ControllerActivityCounter} which is an aggregate of the times spent |
| 2285 | * in various radio controller states, such as transmit, receive, and idle. |
| 2286 | * @return non-null {@link ControllerActivityCounter} |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 2287 | */ |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 2288 | public abstract ControllerActivityCounter getWifiControllerActivity(); |
| 2289 | |
| 2290 | /** |
| 2291 | * Returns true if the BatteryStats object has detailed bluetooth power reports. |
| 2292 | * When true, calling {@link #getBluetoothControllerActivity()} will yield the |
| 2293 | * actual power data. |
| 2294 | */ |
| 2295 | public abstract boolean hasBluetoothActivityReporting(); |
| 2296 | |
| 2297 | /** |
| 2298 | * Returns a {@link ControllerActivityCounter} which is an aggregate of the times spent |
| 2299 | * in various radio controller states, such as transmit, receive, and idle. |
| 2300 | * @return non-null {@link ControllerActivityCounter} |
| 2301 | */ |
| 2302 | public abstract ControllerActivityCounter getBluetoothControllerActivity(); |
| 2303 | |
| 2304 | /** |
| 2305 | * Returns true if the BatteryStats object has detailed modem power reports. |
| 2306 | * When true, calling {@link #getModemControllerActivity()} will yield the |
| 2307 | * actual power data. |
| 2308 | */ |
| 2309 | public abstract boolean hasModemActivityReporting(); |
| 2310 | |
| 2311 | /** |
| 2312 | * Returns a {@link ControllerActivityCounter} which is an aggregate of the times spent |
| 2313 | * in various radio controller states, such as transmit, receive, and idle. |
| 2314 | * @return non-null {@link ControllerActivityCounter} |
| 2315 | */ |
| 2316 | public abstract ControllerActivityCounter getModemControllerActivity(); |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 2317 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2318 | /** |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 2319 | * Return the wall clock time when battery stats data collection started. |
| 2320 | */ |
| 2321 | public abstract long getStartClockTime(); |
| 2322 | |
| 2323 | /** |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 2324 | * Return platform version tag that we were running in when the battery stats started. |
| 2325 | */ |
| 2326 | public abstract String getStartPlatformVersion(); |
| 2327 | |
| 2328 | /** |
| 2329 | * Return platform version tag that we were running in when the battery stats ended. |
| 2330 | */ |
| 2331 | public abstract String getEndPlatformVersion(); |
| 2332 | |
| 2333 | /** |
| 2334 | * Return the internal version code of the parcelled format. |
| 2335 | */ |
| 2336 | public abstract int getParcelVersion(); |
| 2337 | |
| 2338 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2339 | * Return whether we are currently running on battery. |
| 2340 | */ |
| 2341 | public abstract boolean getIsOnBattery(); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame^] | 2342 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2343 | /** |
| 2344 | * Returns a SparseArray containing the statistics for each uid. |
| 2345 | */ |
| 2346 | public abstract SparseArray<? extends Uid> getUidStats(); |
| 2347 | |
| 2348 | /** |
| 2349 | * Returns the current battery uptime in microseconds. |
| 2350 | * |
| 2351 | * @param curTime the amount of elapsed realtime in microseconds. |
| 2352 | */ |
| 2353 | public abstract long getBatteryUptime(long curTime); |
| 2354 | |
| 2355 | /** |
| 2356 | * Returns the current battery realtime in microseconds. |
| 2357 | * |
| 2358 | * @param curTime the amount of elapsed realtime in microseconds. |
| 2359 | */ |
| 2360 | public abstract long getBatteryRealtime(long curTime); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame^] | 2361 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2362 | /** |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 2363 | * Returns the battery percentage level at the last time the device was unplugged from power, or |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame^] | 2364 | * the last time it booted on battery power. |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2365 | */ |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 2366 | public abstract int getDischargeStartLevel(); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame^] | 2367 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2368 | /** |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 2369 | * Returns the current battery percentage level if we are in a discharge cycle, otherwise |
| 2370 | * returns the level at the last plug event. |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2371 | */ |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 2372 | public abstract int getDischargeCurrentLevel(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2373 | |
| 2374 | /** |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 2375 | * Get the amount the battery has discharged since the stats were |
| 2376 | * last reset after charging, as a lower-end approximation. |
| 2377 | */ |
| 2378 | public abstract int getLowDischargeAmountSinceCharge(); |
| 2379 | |
| 2380 | /** |
| 2381 | * Get the amount the battery has discharged since the stats were |
| 2382 | * last reset after charging, as an upper-end approximation. |
| 2383 | */ |
| 2384 | public abstract int getHighDischargeAmountSinceCharge(); |
| 2385 | |
| 2386 | /** |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2387 | * Retrieve the discharge amount over the selected discharge period <var>which</var>. |
| 2388 | */ |
| 2389 | public abstract int getDischargeAmount(int which); |
| 2390 | |
| 2391 | /** |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 2392 | * Get the amount the battery has discharged while the screen was on, |
| 2393 | * since the last time power was unplugged. |
| 2394 | */ |
| 2395 | public abstract int getDischargeAmountScreenOn(); |
| 2396 | |
| 2397 | /** |
| 2398 | * Get the amount the battery has discharged while the screen was on, |
| 2399 | * since the last time the device was charged. |
| 2400 | */ |
| 2401 | public abstract int getDischargeAmountScreenOnSinceCharge(); |
| 2402 | |
| 2403 | /** |
| 2404 | * Get the amount the battery has discharged while the screen was off, |
| 2405 | * since the last time power was unplugged. |
| 2406 | */ |
| 2407 | public abstract int getDischargeAmountScreenOff(); |
| 2408 | |
| 2409 | /** |
| 2410 | * Get the amount the battery has discharged while the screen was off, |
| 2411 | * since the last time the device was charged. |
| 2412 | */ |
| 2413 | public abstract int getDischargeAmountScreenOffSinceCharge(); |
| 2414 | |
| 2415 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2416 | * Returns the total, last, or current battery uptime in microseconds. |
| 2417 | * |
| 2418 | * @param curTime the elapsed realtime in microseconds. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2419 | * @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] | 2420 | */ |
| 2421 | public abstract long computeBatteryUptime(long curTime, int which); |
| 2422 | |
| 2423 | /** |
| 2424 | * Returns the total, last, or current battery realtime in microseconds. |
| 2425 | * |
| 2426 | * @param curTime the current elapsed realtime in microseconds. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2427 | * @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] | 2428 | */ |
| 2429 | public abstract long computeBatteryRealtime(long curTime, int which); |
| 2430 | |
| 2431 | /** |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2432 | * Returns the total, last, or current battery screen off uptime in microseconds. |
| 2433 | * |
| 2434 | * @param curTime the elapsed realtime in microseconds. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2435 | * @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] | 2436 | */ |
| 2437 | public abstract long computeBatteryScreenOffUptime(long curTime, int which); |
| 2438 | |
| 2439 | /** |
| 2440 | * Returns the total, last, or current battery screen off realtime in microseconds. |
| 2441 | * |
| 2442 | * @param curTime the current elapsed realtime in microseconds. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2443 | * @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] | 2444 | */ |
| 2445 | public abstract long computeBatteryScreenOffRealtime(long curTime, int which); |
| 2446 | |
| 2447 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2448 | * Returns the total, last, or current uptime in microseconds. |
| 2449 | * |
| 2450 | * @param curTime the current elapsed realtime in microseconds. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2451 | * @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] | 2452 | */ |
| 2453 | public abstract long computeUptime(long curTime, int which); |
| 2454 | |
| 2455 | /** |
| 2456 | * Returns the total, last, or current realtime in microseconds. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2457 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2458 | * @param curTime the current elapsed realtime in microseconds. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2459 | * @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] | 2460 | */ |
| 2461 | public abstract long computeRealtime(long curTime, int which); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2462 | |
| 2463 | /** |
| 2464 | * Compute an approximation for how much run time (in microseconds) is remaining on |
| 2465 | * the battery. Returns -1 if no time can be computed: either there is not |
| 2466 | * enough current data to make a decision, or the battery is currently |
| 2467 | * charging. |
| 2468 | * |
| 2469 | * @param curTime The current elepsed realtime in microseconds. |
| 2470 | */ |
| 2471 | public abstract long computeBatteryTimeRemaining(long curTime); |
| 2472 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 2473 | // The part of a step duration that is the actual time. |
| 2474 | public static final long STEP_LEVEL_TIME_MASK = 0x000000ffffffffffL; |
| 2475 | |
| 2476 | // Bits in a step duration that are the new battery level we are at. |
| 2477 | public static final long STEP_LEVEL_LEVEL_MASK = 0x0000ff0000000000L; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2478 | public static final int STEP_LEVEL_LEVEL_SHIFT = 40; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 2479 | |
| 2480 | // Bits in a step duration that are the initial mode we were in at that step. |
| 2481 | public static final long STEP_LEVEL_INITIAL_MODE_MASK = 0x00ff000000000000L; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2482 | public static final int STEP_LEVEL_INITIAL_MODE_SHIFT = 48; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 2483 | |
| 2484 | // Bits in a step duration that indicate which modes changed during that step. |
| 2485 | public static final long STEP_LEVEL_MODIFIED_MODE_MASK = 0xff00000000000000L; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2486 | public static final int STEP_LEVEL_MODIFIED_MODE_SHIFT = 56; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 2487 | |
| 2488 | // Step duration mode: the screen is on, off, dozed, etc; value is Display.STATE_* - 1. |
| 2489 | public static final int STEP_LEVEL_MODE_SCREEN_STATE = 0x03; |
| 2490 | |
Santos Cordon | e94f050 | 2017-02-24 12:31:20 -0800 | [diff] [blame] | 2491 | // The largest value for screen state that is tracked in battery states. Any values above |
| 2492 | // this should be mapped back to one of the tracked values before being tracked here. |
| 2493 | public static final int MAX_TRACKED_SCREEN_STATE = Display.STATE_DOZE_SUSPEND; |
| 2494 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 2495 | // Step duration mode: power save is on. |
| 2496 | public static final int STEP_LEVEL_MODE_POWER_SAVE = 0x04; |
| 2497 | |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2498 | // Step duration mode: device is currently in idle mode. |
| 2499 | public static final int STEP_LEVEL_MODE_DEVICE_IDLE = 0x08; |
| 2500 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2501 | public static final int[] STEP_LEVEL_MODES_OF_INTEREST = new int[] { |
| 2502 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE, |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2503 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE|STEP_LEVEL_MODE_DEVICE_IDLE, |
| 2504 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_DEVICE_IDLE, |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2505 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE, |
| 2506 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE, |
| 2507 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE, |
| 2508 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE, |
| 2509 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE, |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2510 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE|STEP_LEVEL_MODE_DEVICE_IDLE, |
| 2511 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_DEVICE_IDLE, |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2512 | }; |
| 2513 | public static final int[] STEP_LEVEL_MODE_VALUES = new int[] { |
| 2514 | (Display.STATE_OFF-1), |
| 2515 | (Display.STATE_OFF-1)|STEP_LEVEL_MODE_POWER_SAVE, |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2516 | (Display.STATE_OFF-1)|STEP_LEVEL_MODE_DEVICE_IDLE, |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2517 | (Display.STATE_ON-1), |
| 2518 | (Display.STATE_ON-1)|STEP_LEVEL_MODE_POWER_SAVE, |
| 2519 | (Display.STATE_DOZE-1), |
| 2520 | (Display.STATE_DOZE-1)|STEP_LEVEL_MODE_POWER_SAVE, |
| 2521 | (Display.STATE_DOZE_SUSPEND-1), |
| 2522 | (Display.STATE_DOZE_SUSPEND-1)|STEP_LEVEL_MODE_POWER_SAVE, |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2523 | (Display.STATE_DOZE_SUSPEND-1)|STEP_LEVEL_MODE_DEVICE_IDLE, |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2524 | }; |
| 2525 | public static final String[] STEP_LEVEL_MODE_LABELS = new String[] { |
| 2526 | "screen off", |
| 2527 | "screen off power save", |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2528 | "screen off device idle", |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2529 | "screen on", |
| 2530 | "screen on power save", |
| 2531 | "screen doze", |
| 2532 | "screen doze power save", |
| 2533 | "screen doze-suspend", |
| 2534 | "screen doze-suspend power save", |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2535 | "screen doze-suspend device idle", |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2536 | }; |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 2537 | |
| 2538 | /** |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 2539 | * Return the counter keeping track of the amount of battery discharge while the screen was off, |
| 2540 | * measured in micro-Ampere-hours. This will be non-zero only if the device's battery has |
| 2541 | * a coulomb counter. |
| 2542 | */ |
| 2543 | public abstract LongCounter getDischargeScreenOffCoulombCounter(); |
| 2544 | |
| 2545 | /** |
| 2546 | * Return the counter keeping track of the amount of battery discharge measured in |
| 2547 | * micro-Ampere-hours. This will be non-zero only if the device's battery has |
| 2548 | * a coulomb counter. |
| 2549 | */ |
| 2550 | public abstract LongCounter getDischargeCoulombCounter(); |
| 2551 | |
| 2552 | /** |
Adam Lesinski | f9b20a9 | 2016-06-17 17:30:01 -0700 | [diff] [blame] | 2553 | * Returns the estimated real battery capacity, which may be less than the capacity |
| 2554 | * declared by the PowerProfile. |
| 2555 | * @return The estimated battery capacity in mAh. |
| 2556 | */ |
| 2557 | public abstract int getEstimatedBatteryCapacity(); |
| 2558 | |
| 2559 | /** |
Jocelyn Dang | c627d10 | 2017-04-14 13:15:14 -0700 | [diff] [blame] | 2560 | * @return The minimum learned battery capacity in uAh. |
| 2561 | */ |
| 2562 | public abstract int getMinLearnedBatteryCapacity(); |
| 2563 | |
| 2564 | /** |
| 2565 | * @return The maximum learned battery capacity in uAh. |
| 2566 | */ |
| 2567 | public abstract int getMaxLearnedBatteryCapacity() ; |
| 2568 | |
| 2569 | /** |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2570 | * Return the array of discharge step durations. |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 2571 | */ |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2572 | public abstract LevelStepTracker getDischargeLevelStepTracker(); |
| 2573 | |
| 2574 | /** |
| 2575 | * Return the array of daily discharge step durations. |
| 2576 | */ |
| 2577 | public abstract LevelStepTracker getDailyDischargeLevelStepTracker(); |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 2578 | |
| 2579 | /** |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2580 | * Compute an approximation for how much time (in microseconds) remains until the battery |
| 2581 | * is fully charged. Returns -1 if no time can be computed: either there is not |
| 2582 | * enough current data to make a decision, or the battery is currently |
| 2583 | * discharging. |
| 2584 | * |
| 2585 | * @param curTime The current elepsed realtime in microseconds. |
| 2586 | */ |
| 2587 | public abstract long computeChargeTimeRemaining(long curTime); |
| 2588 | |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 2589 | /** |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2590 | * Return the array of charge step durations. |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 2591 | */ |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2592 | public abstract LevelStepTracker getChargeLevelStepTracker(); |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 2593 | |
| 2594 | /** |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2595 | * Return the array of daily charge step durations. |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 2596 | */ |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2597 | public abstract LevelStepTracker getDailyChargeLevelStepTracker(); |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 2598 | |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2599 | public abstract ArrayList<PackageChange> getDailyPackageChanges(); |
| 2600 | |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 2601 | public abstract Map<String, ? extends Timer> getWakeupReasonStats(); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2602 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2603 | public abstract Map<String, ? extends Timer> getKernelWakelockStats(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2604 | |
James Carr | 2dd7e5e | 2016-07-20 18:48:39 -0700 | [diff] [blame] | 2605 | public abstract LongSparseArray<? extends Timer> getKernelMemoryStats(); |
| 2606 | |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 2607 | public abstract void writeToParcelWithoutUids(Parcel out, int flags); |
| 2608 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 2609 | private final static void formatTimeRaw(StringBuilder out, long seconds) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2610 | long days = seconds / (60 * 60 * 24); |
| 2611 | if (days != 0) { |
| 2612 | out.append(days); |
| 2613 | out.append("d "); |
| 2614 | } |
| 2615 | long used = days * 60 * 60 * 24; |
| 2616 | |
| 2617 | long hours = (seconds - used) / (60 * 60); |
| 2618 | if (hours != 0 || used != 0) { |
| 2619 | out.append(hours); |
| 2620 | out.append("h "); |
| 2621 | } |
| 2622 | used += hours * 60 * 60; |
| 2623 | |
| 2624 | long mins = (seconds-used) / 60; |
| 2625 | if (mins != 0 || used != 0) { |
| 2626 | out.append(mins); |
| 2627 | out.append("m "); |
| 2628 | } |
| 2629 | used += mins * 60; |
| 2630 | |
| 2631 | if (seconds != 0 || used != 0) { |
| 2632 | out.append(seconds-used); |
| 2633 | out.append("s "); |
| 2634 | } |
| 2635 | } |
| 2636 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2637 | public final static void formatTimeMs(StringBuilder sb, long time) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2638 | long sec = time / 1000; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 2639 | formatTimeRaw(sb, sec); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2640 | sb.append(time - (sec * 1000)); |
| 2641 | sb.append("ms "); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2642 | } |
| 2643 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2644 | public final static void formatTimeMsNoSpace(StringBuilder sb, long time) { |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 2645 | long sec = time / 1000; |
| 2646 | formatTimeRaw(sb, sec); |
| 2647 | sb.append(time - (sec * 1000)); |
| 2648 | sb.append("ms"); |
| 2649 | } |
| 2650 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2651 | public final String formatRatioLocked(long num, long den) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2652 | if (den == 0L) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2653 | return "--%"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2654 | } |
| 2655 | float perc = ((float)num) / ((float)den) * 100; |
| 2656 | mFormatBuilder.setLength(0); |
| 2657 | mFormatter.format("%.1f%%", perc); |
| 2658 | return mFormatBuilder.toString(); |
| 2659 | } |
| 2660 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2661 | final String formatBytesLocked(long bytes) { |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 2662 | mFormatBuilder.setLength(0); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame^] | 2663 | |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 2664 | if (bytes < BYTES_PER_KB) { |
| 2665 | return bytes + "B"; |
| 2666 | } else if (bytes < BYTES_PER_MB) { |
| 2667 | mFormatter.format("%.2fKB", bytes / (double) BYTES_PER_KB); |
| 2668 | return mFormatBuilder.toString(); |
| 2669 | } else if (bytes < BYTES_PER_GB){ |
| 2670 | mFormatter.format("%.2fMB", bytes / (double) BYTES_PER_MB); |
| 2671 | return mFormatBuilder.toString(); |
| 2672 | } else { |
| 2673 | mFormatter.format("%.2fGB", bytes / (double) BYTES_PER_GB); |
| 2674 | return mFormatBuilder.toString(); |
| 2675 | } |
| 2676 | } |
| 2677 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2678 | private static long computeWakeLock(Timer timer, long elapsedRealtimeUs, int which) { |
Dianne Hackborn | c24ab86 | 2011-10-18 15:55:03 -0700 | [diff] [blame] | 2679 | if (timer != null) { |
| 2680 | // Convert from microseconds to milliseconds with rounding |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2681 | long totalTimeMicros = timer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Dianne Hackborn | c24ab86 | 2011-10-18 15:55:03 -0700 | [diff] [blame] | 2682 | long totalTimeMillis = (totalTimeMicros + 500) / 1000; |
| 2683 | return totalTimeMillis; |
| 2684 | } |
| 2685 | return 0; |
| 2686 | } |
| 2687 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2688 | /** |
| 2689 | * |
| 2690 | * @param sb a StringBuilder object. |
| 2691 | * @param timer a Timer object contining the wakelock times. |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2692 | * @param elapsedRealtimeUs the current on-battery time in microseconds. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2693 | * @param name the name of the wakelock. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2694 | * @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] | 2695 | * @param linePrefix a String to be prepended to each line of output. |
| 2696 | * @return the line prefix |
| 2697 | */ |
| 2698 | private static final String printWakeLock(StringBuilder sb, Timer timer, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2699 | long elapsedRealtimeUs, String name, int which, String linePrefix) { |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 2700 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2701 | if (timer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2702 | long totalTimeMillis = computeWakeLock(timer, elapsedRealtimeUs, which); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 2703 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2704 | int count = timer.getCountLocked(which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2705 | if (totalTimeMillis != 0) { |
| 2706 | sb.append(linePrefix); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 2707 | formatTimeMs(sb, totalTimeMillis); |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 2708 | if (name != null) { |
| 2709 | sb.append(name); |
| 2710 | sb.append(' '); |
| 2711 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2712 | sb.append('('); |
| 2713 | sb.append(count); |
| 2714 | sb.append(" times)"); |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2715 | final long maxDurationMs = timer.getMaxDurationMsLocked(elapsedRealtimeUs/1000); |
| 2716 | if (maxDurationMs >= 0) { |
| 2717 | sb.append(" max="); |
| 2718 | sb.append(maxDurationMs); |
| 2719 | } |
Bookatz | 506a818 | 2017-05-01 14:18:42 -0700 | [diff] [blame] | 2720 | // Put actual time if it is available and different from totalTimeMillis. |
| 2721 | final long totalDurMs = timer.getTotalDurationMsLocked(elapsedRealtimeUs/1000); |
| 2722 | if (totalDurMs > totalTimeMillis) { |
| 2723 | sb.append(" actual="); |
| 2724 | sb.append(totalDurMs); |
| 2725 | } |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2726 | if (timer.isRunningLocked()) { |
| 2727 | final long currentMs = timer.getCurrentDurationMsLocked(elapsedRealtimeUs/1000); |
| 2728 | if (currentMs >= 0) { |
| 2729 | sb.append(" (running for "); |
| 2730 | sb.append(currentMs); |
| 2731 | sb.append("ms)"); |
| 2732 | } else { |
| 2733 | sb.append(" (running)"); |
| 2734 | } |
| 2735 | } |
| 2736 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2737 | return ", "; |
| 2738 | } |
| 2739 | } |
| 2740 | return linePrefix; |
| 2741 | } |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 2742 | |
| 2743 | /** |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2744 | * 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] | 2745 | * |
| 2746 | * @param pw a PrintWriter object to print to. |
| 2747 | * @param sb a StringBuilder object. |
| 2748 | * @param timer a Timer object contining the wakelock times. |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2749 | * @param rawRealtimeUs the current on-battery time in microseconds. |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 2750 | * @param which which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT. |
| 2751 | * @param prefix a String to be prepended to each line of output. |
| 2752 | * @param type the name of the timer. |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2753 | * @return true if anything was printed. |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 2754 | */ |
| 2755 | private static final boolean printTimer(PrintWriter pw, StringBuilder sb, Timer timer, |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2756 | long rawRealtimeUs, int which, String prefix, String type) { |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 2757 | if (timer != null) { |
| 2758 | // Convert from microseconds to milliseconds with rounding |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2759 | final long totalTimeMs = (timer.getTotalTimeLocked( |
| 2760 | rawRealtimeUs, which) + 500) / 1000; |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 2761 | final int count = timer.getCountLocked(which); |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2762 | if (totalTimeMs != 0) { |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 2763 | sb.setLength(0); |
| 2764 | sb.append(prefix); |
| 2765 | sb.append(" "); |
| 2766 | sb.append(type); |
| 2767 | sb.append(": "); |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2768 | formatTimeMs(sb, totalTimeMs); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 2769 | sb.append("realtime ("); |
| 2770 | sb.append(count); |
| 2771 | sb.append(" times)"); |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2772 | final long maxDurationMs = timer.getMaxDurationMsLocked(rawRealtimeUs/1000); |
| 2773 | if (maxDurationMs >= 0) { |
| 2774 | sb.append(" max="); |
| 2775 | sb.append(maxDurationMs); |
| 2776 | } |
| 2777 | if (timer.isRunningLocked()) { |
| 2778 | final long currentMs = timer.getCurrentDurationMsLocked(rawRealtimeUs/1000); |
| 2779 | if (currentMs >= 0) { |
| 2780 | sb.append(" (running for "); |
| 2781 | sb.append(currentMs); |
| 2782 | sb.append("ms)"); |
| 2783 | } else { |
| 2784 | sb.append(" (running)"); |
| 2785 | } |
| 2786 | } |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 2787 | pw.println(sb.toString()); |
| 2788 | return true; |
| 2789 | } |
| 2790 | } |
| 2791 | return false; |
| 2792 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame^] | 2793 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2794 | /** |
| 2795 | * Checkin version of wakelock printer. Prints simple comma-separated list. |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame^] | 2796 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2797 | * @param sb a StringBuilder object. |
| 2798 | * @param timer a Timer object contining the wakelock times. |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2799 | * @param elapsedRealtimeUs the current time in microseconds. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2800 | * @param name the name of the wakelock. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2801 | * @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] | 2802 | * @param linePrefix a String to be prepended to each line of output. |
| 2803 | * @return the line prefix |
| 2804 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2805 | private static final String printWakeLockCheckin(StringBuilder sb, Timer timer, |
| 2806 | long elapsedRealtimeUs, String name, int which, String linePrefix) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2807 | long totalTimeMicros = 0; |
| 2808 | int count = 0; |
Bookatz | 941d98f | 2017-05-02 19:25:18 -0700 | [diff] [blame] | 2809 | long max = 0; |
| 2810 | long current = 0; |
| 2811 | long totalDuration = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2812 | if (timer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2813 | totalTimeMicros = timer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Bookatz | 506a818 | 2017-05-01 14:18:42 -0700 | [diff] [blame] | 2814 | count = timer.getCountLocked(which); |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2815 | current = timer.getCurrentDurationMsLocked(elapsedRealtimeUs/1000); |
| 2816 | max = timer.getMaxDurationMsLocked(elapsedRealtimeUs/1000); |
Bookatz | 506a818 | 2017-05-01 14:18:42 -0700 | [diff] [blame] | 2817 | totalDuration = timer.getTotalDurationMsLocked(elapsedRealtimeUs/1000); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2818 | } |
| 2819 | sb.append(linePrefix); |
| 2820 | sb.append((totalTimeMicros + 500) / 1000); // microseconds to milliseconds with rounding |
| 2821 | sb.append(','); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2822 | sb.append(name != null ? name + "," : ""); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2823 | sb.append(count); |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2824 | sb.append(','); |
| 2825 | sb.append(current); |
| 2826 | sb.append(','); |
| 2827 | sb.append(max); |
Bookatz | 506a818 | 2017-05-01 14:18:42 -0700 | [diff] [blame] | 2828 | // Partial, full, and window wakelocks are pooled, so totalDuration is meaningful (albeit |
| 2829 | // not always tracked). Kernel wakelocks (which have name == null) have no notion of |
| 2830 | // totalDuration independent of totalTimeMicros (since they are not pooled). |
| 2831 | if (name != null) { |
| 2832 | sb.append(','); |
| 2833 | sb.append(totalDuration); |
| 2834 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2835 | return ","; |
| 2836 | } |
Bookatz | 506a818 | 2017-05-01 14:18:42 -0700 | [diff] [blame] | 2837 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 2838 | private static final void dumpLineHeader(PrintWriter pw, int uid, String category, |
| 2839 | String type) { |
| 2840 | pw.print(BATTERY_STATS_CHECKIN_VERSION); |
| 2841 | pw.print(','); |
| 2842 | pw.print(uid); |
| 2843 | pw.print(','); |
| 2844 | pw.print(category); |
| 2845 | pw.print(','); |
| 2846 | pw.print(type); |
| 2847 | } |
| 2848 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2849 | /** |
| 2850 | * Dump a comma-separated line of values for terse checkin mode. |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame^] | 2851 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2852 | * @param pw the PageWriter to dump log to |
| 2853 | * @param category category of data (e.g. "total", "last", "unplugged", "current" ) |
| 2854 | * @param type type of data (e.g. "wakelock", "sensor", "process", "apk" , "process", "network") |
| 2855 | * @param args type-dependent data arguments |
| 2856 | */ |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame^] | 2857 | private static final void dumpLine(PrintWriter pw, int uid, String category, String type, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2858 | Object... args ) { |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 2859 | dumpLineHeader(pw, uid, category, type); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 2860 | for (Object arg : args) { |
Dianne Hackborn | 13ac041 | 2013-06-25 19:34:49 -0700 | [diff] [blame] | 2861 | pw.print(','); |
| 2862 | pw.print(arg); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2863 | } |
Dianne Hackborn | 13ac041 | 2013-06-25 19:34:49 -0700 | [diff] [blame] | 2864 | pw.println(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2865 | } |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 2866 | |
| 2867 | /** |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 2868 | * Dump a given timer stat for terse checkin mode. |
| 2869 | * |
| 2870 | * @param pw the PageWriter to dump log to |
| 2871 | * @param uid the UID to log |
| 2872 | * @param category category of data (e.g. "total", "last", "unplugged", "current" ) |
| 2873 | * @param type type of data (e.g. "wakelock", "sensor", "process", "apk" , "process", "network") |
| 2874 | * @param timer a {@link Timer} to dump stats for |
| 2875 | * @param rawRealtime the current elapsed realtime of the system in microseconds |
| 2876 | * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT |
| 2877 | */ |
| 2878 | private static final void dumpTimer(PrintWriter pw, int uid, String category, String type, |
| 2879 | Timer timer, long rawRealtime, int which) { |
| 2880 | if (timer != null) { |
| 2881 | // Convert from microseconds to milliseconds with rounding |
| 2882 | final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) |
| 2883 | / 1000; |
| 2884 | final int count = timer.getCountLocked(which); |
| 2885 | if (totalTime != 0) { |
| 2886 | dumpLine(pw, uid, category, type, totalTime, count); |
| 2887 | } |
| 2888 | } |
| 2889 | } |
| 2890 | |
| 2891 | /** |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 2892 | * Checks if the ControllerActivityCounter has any data worth dumping. |
| 2893 | */ |
| 2894 | private static boolean controllerActivityHasData(ControllerActivityCounter counter, int which) { |
| 2895 | if (counter == null) { |
| 2896 | return false; |
| 2897 | } |
| 2898 | |
| 2899 | if (counter.getIdleTimeCounter().getCountLocked(which) != 0 |
| 2900 | || counter.getRxTimeCounter().getCountLocked(which) != 0 |
| 2901 | || counter.getPowerCounter().getCountLocked(which) != 0) { |
| 2902 | return true; |
| 2903 | } |
| 2904 | |
| 2905 | for (LongCounter c : counter.getTxTimeCounters()) { |
| 2906 | if (c.getCountLocked(which) != 0) { |
| 2907 | return true; |
| 2908 | } |
| 2909 | } |
| 2910 | return false; |
| 2911 | } |
| 2912 | |
| 2913 | /** |
| 2914 | * Dumps the ControllerActivityCounter if it has any data worth dumping. |
| 2915 | * The order of the arguments in the final check in line is: |
| 2916 | * |
| 2917 | * idle, rx, power, tx... |
| 2918 | * |
| 2919 | * where tx... is one or more transmit level times. |
| 2920 | */ |
| 2921 | private static final void dumpControllerActivityLine(PrintWriter pw, int uid, String category, |
| 2922 | String type, |
| 2923 | ControllerActivityCounter counter, |
| 2924 | int which) { |
| 2925 | if (!controllerActivityHasData(counter, which)) { |
| 2926 | return; |
| 2927 | } |
| 2928 | |
| 2929 | dumpLineHeader(pw, uid, category, type); |
| 2930 | pw.print(","); |
| 2931 | pw.print(counter.getIdleTimeCounter().getCountLocked(which)); |
| 2932 | pw.print(","); |
| 2933 | pw.print(counter.getRxTimeCounter().getCountLocked(which)); |
| 2934 | pw.print(","); |
| 2935 | pw.print(counter.getPowerCounter().getCountLocked(which) / (1000 * 60 * 60)); |
| 2936 | for (LongCounter c : counter.getTxTimeCounters()) { |
| 2937 | pw.print(","); |
| 2938 | pw.print(c.getCountLocked(which)); |
| 2939 | } |
| 2940 | pw.println(); |
| 2941 | } |
| 2942 | |
| 2943 | private final void printControllerActivityIfInteresting(PrintWriter pw, StringBuilder sb, |
| 2944 | String prefix, String controllerName, |
| 2945 | ControllerActivityCounter counter, |
| 2946 | int which) { |
| 2947 | if (controllerActivityHasData(counter, which)) { |
| 2948 | printControllerActivity(pw, sb, prefix, controllerName, counter, which); |
| 2949 | } |
| 2950 | } |
| 2951 | |
| 2952 | private final void printControllerActivity(PrintWriter pw, StringBuilder sb, String prefix, |
| 2953 | String controllerName, |
| 2954 | ControllerActivityCounter counter, int which) { |
| 2955 | final long idleTimeMs = counter.getIdleTimeCounter().getCountLocked(which); |
| 2956 | final long rxTimeMs = counter.getRxTimeCounter().getCountLocked(which); |
| 2957 | final long powerDrainMaMs = counter.getPowerCounter().getCountLocked(which); |
| 2958 | long totalTxTimeMs = 0; |
| 2959 | for (LongCounter txState : counter.getTxTimeCounters()) { |
| 2960 | totalTxTimeMs += txState.getCountLocked(which); |
| 2961 | } |
| 2962 | |
| 2963 | final long totalTimeMs = idleTimeMs + rxTimeMs + totalTxTimeMs; |
| 2964 | |
| 2965 | sb.setLength(0); |
| 2966 | sb.append(prefix); |
| 2967 | sb.append(" "); |
| 2968 | sb.append(controllerName); |
| 2969 | sb.append(" Idle time: "); |
| 2970 | formatTimeMs(sb, idleTimeMs); |
| 2971 | sb.append("("); |
| 2972 | sb.append(formatRatioLocked(idleTimeMs, totalTimeMs)); |
| 2973 | sb.append(")"); |
| 2974 | pw.println(sb.toString()); |
| 2975 | |
| 2976 | sb.setLength(0); |
| 2977 | sb.append(prefix); |
| 2978 | sb.append(" "); |
| 2979 | sb.append(controllerName); |
| 2980 | sb.append(" Rx time: "); |
| 2981 | formatTimeMs(sb, rxTimeMs); |
| 2982 | sb.append("("); |
| 2983 | sb.append(formatRatioLocked(rxTimeMs, totalTimeMs)); |
| 2984 | sb.append(")"); |
| 2985 | pw.println(sb.toString()); |
| 2986 | |
| 2987 | sb.setLength(0); |
| 2988 | sb.append(prefix); |
| 2989 | sb.append(" "); |
| 2990 | sb.append(controllerName); |
| 2991 | sb.append(" Tx time: "); |
| 2992 | formatTimeMs(sb, totalTxTimeMs); |
| 2993 | sb.append("("); |
| 2994 | sb.append(formatRatioLocked(totalTxTimeMs, totalTimeMs)); |
| 2995 | sb.append(")"); |
| 2996 | pw.println(sb.toString()); |
| 2997 | |
| 2998 | final int numTxLvls = counter.getTxTimeCounters().length; |
| 2999 | if (numTxLvls > 1) { |
| 3000 | for (int lvl = 0; lvl < numTxLvls; lvl++) { |
| 3001 | final long txLvlTimeMs = counter.getTxTimeCounters()[lvl].getCountLocked(which); |
| 3002 | sb.setLength(0); |
| 3003 | sb.append(prefix); |
| 3004 | sb.append(" ["); |
| 3005 | sb.append(lvl); |
| 3006 | sb.append("] "); |
| 3007 | formatTimeMs(sb, txLvlTimeMs); |
| 3008 | sb.append("("); |
| 3009 | sb.append(formatRatioLocked(txLvlTimeMs, totalTxTimeMs)); |
| 3010 | sb.append(")"); |
| 3011 | pw.println(sb.toString()); |
| 3012 | } |
| 3013 | } |
| 3014 | |
| 3015 | sb.setLength(0); |
| 3016 | sb.append(prefix); |
| 3017 | sb.append(" "); |
| 3018 | sb.append(controllerName); |
| 3019 | sb.append(" Power drain: ").append( |
| 3020 | BatteryStatsHelper.makemAh(powerDrainMaMs / (double) (1000*60*60))); |
| 3021 | sb.append("mAh"); |
| 3022 | pw.println(sb.toString()); |
| 3023 | } |
| 3024 | |
| 3025 | /** |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 3026 | * Temporary for settings. |
| 3027 | */ |
| 3028 | public final void dumpCheckinLocked(Context context, PrintWriter pw, int which, int reqUid) { |
| 3029 | dumpCheckinLocked(context, pw, which, reqUid, BatteryStatsHelper.checkWifiOnly(context)); |
| 3030 | } |
| 3031 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3032 | /** |
| 3033 | * Checkin server version of dump to produce more compact, computer-readable log. |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame^] | 3034 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3035 | * NOTE: all times are expressed in 'ms'. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3036 | */ |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 3037 | public final void dumpCheckinLocked(Context context, PrintWriter pw, int which, int reqUid, |
| 3038 | boolean wifiOnly) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3039 | final long rawUptime = SystemClock.uptimeMillis() * 1000; |
| 3040 | final long rawRealtime = SystemClock.elapsedRealtime() * 1000; |
| 3041 | final long batteryUptime = getBatteryUptime(rawUptime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3042 | final long whichBatteryUptime = computeBatteryUptime(rawUptime, which); |
| 3043 | final long whichBatteryRealtime = computeBatteryRealtime(rawRealtime, which); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3044 | final long whichBatteryScreenOffUptime = computeBatteryScreenOffUptime(rawUptime, which); |
| 3045 | final long whichBatteryScreenOffRealtime = computeBatteryScreenOffRealtime(rawRealtime, |
| 3046 | which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3047 | final long totalRealtime = computeRealtime(rawRealtime, which); |
| 3048 | final long totalUptime = computeUptime(rawUptime, which); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3049 | final long screenOnTime = getScreenOnTime(rawRealtime, which); |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 3050 | final long interactiveTime = getInteractiveTime(rawRealtime, which); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3051 | final long powerSaveModeEnabledTime = getPowerSaveModeEnabledTime(rawRealtime, which); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3052 | final long deviceIdleModeLightTime = getDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT, |
| 3053 | rawRealtime, which); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 3054 | final long deviceIdleModeFullTime = getDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP, |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3055 | rawRealtime, which); |
| 3056 | final long deviceLightIdlingTime = getDeviceIdlingTime(DEVICE_IDLE_MODE_LIGHT, |
| 3057 | rawRealtime, which); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 3058 | final long deviceIdlingTime = getDeviceIdlingTime(DEVICE_IDLE_MODE_DEEP, |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3059 | rawRealtime, which); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 3060 | final int connChanges = getNumConnectivityChange(which); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3061 | final long phoneOnTime = getPhoneOnTime(rawRealtime, which); |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 3062 | final long dischargeCount = getDischargeCoulombCounter().getCountLocked(which); |
| 3063 | final long dischargeScreenOffCount = getDischargeScreenOffCoulombCounter() |
| 3064 | .getCountLocked(which); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3065 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3066 | final StringBuilder sb = new StringBuilder(128); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame^] | 3067 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3068 | final SparseArray<? extends Uid> uidStats = getUidStats(); |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 3069 | final int NU = uidStats.size(); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame^] | 3070 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3071 | final String category = STAT_NAMES[which]; |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 3072 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3073 | // Dump "battery" stat |
Jocelyn Dang | c627d10 | 2017-04-14 13:15:14 -0700 | [diff] [blame] | 3074 | dumpLine(pw, 0 /* uid */, category, BATTERY_DATA, |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3075 | which == STATS_SINCE_CHARGED ? getStartCount() : "N/A", |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3076 | whichBatteryRealtime / 1000, whichBatteryUptime / 1000, |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 3077 | totalRealtime / 1000, totalUptime / 1000, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3078 | getStartClockTime(), |
Adam Lesinski | f9b20a9 | 2016-06-17 17:30:01 -0700 | [diff] [blame] | 3079 | whichBatteryScreenOffRealtime / 1000, whichBatteryScreenOffUptime / 1000, |
Jocelyn Dang | c627d10 | 2017-04-14 13:15:14 -0700 | [diff] [blame] | 3080 | getEstimatedBatteryCapacity(), |
| 3081 | getMinLearnedBatteryCapacity(), getMaxLearnedBatteryCapacity()); |
Adam Lesinski | 67c134f | 2016-06-10 15:15:08 -0700 | [diff] [blame] | 3082 | |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame^] | 3083 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3084 | // Calculate wakelock times across all uids. |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 3085 | long fullWakeLockTimeTotal = 0; |
| 3086 | long partialWakeLockTimeTotal = 0; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame^] | 3087 | |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 3088 | for (int iu = 0; iu < NU; iu++) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3089 | final Uid u = uidStats.valueAt(iu); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 3090 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3091 | final ArrayMap<String, ? extends BatteryStats.Uid.Wakelock> wakelocks |
| 3092 | = u.getWakelockStats(); |
| 3093 | for (int iw=wakelocks.size()-1; iw>=0; iw--) { |
| 3094 | final Uid.Wakelock wl = wakelocks.valueAt(iw); |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 3095 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3096 | final Timer fullWakeTimer = wl.getWakeTime(WAKE_TYPE_FULL); |
| 3097 | if (fullWakeTimer != null) { |
| 3098 | fullWakeLockTimeTotal += fullWakeTimer.getTotalTimeLocked(rawRealtime, |
| 3099 | which); |
| 3100 | } |
| 3101 | |
| 3102 | final Timer partialWakeTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL); |
| 3103 | if (partialWakeTimer != null) { |
| 3104 | partialWakeLockTimeTotal += partialWakeTimer.getTotalTimeLocked( |
| 3105 | rawRealtime, which); |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 3106 | } |
| 3107 | } |
| 3108 | } |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 3109 | |
| 3110 | // Dump network stats |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3111 | final long mobileRxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which); |
| 3112 | final long mobileTxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which); |
| 3113 | final long wifiRxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which); |
| 3114 | final long wifiTxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which); |
| 3115 | final long mobileRxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which); |
| 3116 | final long mobileTxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which); |
| 3117 | final long wifiRxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which); |
| 3118 | final long wifiTxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 3119 | final long btRxTotalBytes = getNetworkActivityBytes(NETWORK_BT_RX_DATA, which); |
| 3120 | final long btTxTotalBytes = getNetworkActivityBytes(NETWORK_BT_TX_DATA, which); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3121 | dumpLine(pw, 0 /* uid */, category, GLOBAL_NETWORK_DATA, |
| 3122 | mobileRxTotalBytes, mobileTxTotalBytes, wifiRxTotalBytes, wifiTxTotalBytes, |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 3123 | mobileRxTotalPackets, mobileTxTotalPackets, wifiRxTotalPackets, wifiTxTotalPackets, |
| 3124 | btRxTotalBytes, btTxTotalBytes); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3125 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3126 | // Dump Modem controller stats |
| 3127 | dumpControllerActivityLine(pw, 0 /* uid */, category, GLOBAL_MODEM_CONTROLLER_DATA, |
| 3128 | getModemControllerActivity(), which); |
| 3129 | |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 3130 | // Dump Wifi controller stats |
| 3131 | final long wifiOnTime = getWifiOnTime(rawRealtime, which); |
| 3132 | final long wifiRunningTime = getGlobalWifiRunningTime(rawRealtime, which); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3133 | dumpLine(pw, 0 /* uid */, category, GLOBAL_WIFI_DATA, wifiOnTime / 1000, |
Adam Lesinski | 2208e74 | 2016-02-19 12:53:31 -0800 | [diff] [blame] | 3134 | wifiRunningTime / 1000, /* legacy fields follow, keep at 0 */ 0, 0, 0); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3135 | |
| 3136 | dumpControllerActivityLine(pw, 0 /* uid */, category, GLOBAL_WIFI_CONTROLLER_DATA, |
| 3137 | getWifiControllerActivity(), which); |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 3138 | |
| 3139 | // Dump Bluetooth controller stats |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3140 | dumpControllerActivityLine(pw, 0 /* uid */, category, GLOBAL_BLUETOOTH_CONTROLLER_DATA, |
| 3141 | getBluetoothControllerActivity(), which); |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 3142 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3143 | // Dump misc stats |
| 3144 | dumpLine(pw, 0 /* uid */, category, MISC_DATA, |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 3145 | screenOnTime / 1000, phoneOnTime / 1000, |
Ashish Sharma | 213bb2f | 2014-07-07 17:14:52 -0700 | [diff] [blame] | 3146 | fullWakeLockTimeTotal / 1000, partialWakeLockTimeTotal / 1000, |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 3147 | getMobileRadioActiveTime(rawRealtime, which) / 1000, |
Ashish Sharma | 213bb2f | 2014-07-07 17:14:52 -0700 | [diff] [blame] | 3148 | getMobileRadioActiveAdjustedTime(which) / 1000, interactiveTime / 1000, |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3149 | powerSaveModeEnabledTime / 1000, connChanges, deviceIdleModeFullTime / 1000, |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 3150 | getDeviceIdleModeCount(DEVICE_IDLE_MODE_DEEP, which), deviceIdlingTime / 1000, |
| 3151 | getDeviceIdlingCount(DEVICE_IDLE_MODE_DEEP, which), |
Adam Lesinski | 782327b | 2015-07-30 16:36:29 -0700 | [diff] [blame] | 3152 | getMobileRadioActiveCount(which), |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3153 | getMobileRadioActiveUnknownTime(which) / 1000, deviceIdleModeLightTime / 1000, |
| 3154 | getDeviceIdleModeCount(DEVICE_IDLE_MODE_LIGHT, which), deviceLightIdlingTime / 1000, |
| 3155 | getDeviceIdlingCount(DEVICE_IDLE_MODE_LIGHT, which), |
| 3156 | getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT), |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 3157 | getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP)); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame^] | 3158 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3159 | // Dump screen brightness stats |
| 3160 | Object[] args = new Object[NUM_SCREEN_BRIGHTNESS_BINS]; |
| 3161 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3162 | args[i] = getScreenBrightnessTime(i, rawRealtime, which) / 1000; |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3163 | } |
| 3164 | dumpLine(pw, 0 /* uid */, category, SCREEN_BRIGHTNESS_DATA, args); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame^] | 3165 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3166 | // Dump signal strength stats |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 3167 | args = new Object[SignalStrength.NUM_SIGNAL_STRENGTH_BINS]; |
| 3168 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3169 | args[i] = getPhoneSignalStrengthTime(i, rawRealtime, which) / 1000; |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3170 | } |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3171 | dumpLine(pw, 0 /* uid */, category, SIGNAL_STRENGTH_TIME_DATA, args); |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 3172 | dumpLine(pw, 0 /* uid */, category, SIGNAL_SCANNING_TIME_DATA, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3173 | getPhoneSignalScanningTime(rawRealtime, which) / 1000); |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 3174 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3175 | args[i] = getPhoneSignalStrengthCount(i, which); |
| 3176 | } |
| 3177 | dumpLine(pw, 0 /* uid */, category, SIGNAL_STRENGTH_COUNT_DATA, args); |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 3178 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3179 | // Dump network type stats |
| 3180 | args = new Object[NUM_DATA_CONNECTION_TYPES]; |
| 3181 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3182 | args[i] = getPhoneDataConnectionTime(i, rawRealtime, which) / 1000; |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3183 | } |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3184 | dumpLine(pw, 0 /* uid */, category, DATA_CONNECTION_TIME_DATA, args); |
| 3185 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
| 3186 | args[i] = getPhoneDataConnectionCount(i, which); |
| 3187 | } |
| 3188 | dumpLine(pw, 0 /* uid */, category, DATA_CONNECTION_COUNT_DATA, args); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3189 | |
| 3190 | // Dump wifi state stats |
| 3191 | args = new Object[NUM_WIFI_STATES]; |
| 3192 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3193 | args[i] = getWifiStateTime(i, rawRealtime, which) / 1000; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3194 | } |
| 3195 | dumpLine(pw, 0 /* uid */, category, WIFI_STATE_TIME_DATA, args); |
| 3196 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
| 3197 | args[i] = getWifiStateCount(i, which); |
| 3198 | } |
| 3199 | dumpLine(pw, 0 /* uid */, category, WIFI_STATE_COUNT_DATA, args); |
| 3200 | |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 3201 | // Dump wifi suppl state stats |
| 3202 | args = new Object[NUM_WIFI_SUPPL_STATES]; |
| 3203 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
| 3204 | args[i] = getWifiSupplStateTime(i, rawRealtime, which) / 1000; |
| 3205 | } |
| 3206 | dumpLine(pw, 0 /* uid */, category, WIFI_SUPPL_STATE_TIME_DATA, args); |
| 3207 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
| 3208 | args[i] = getWifiSupplStateCount(i, which); |
| 3209 | } |
| 3210 | dumpLine(pw, 0 /* uid */, category, WIFI_SUPPL_STATE_COUNT_DATA, args); |
| 3211 | |
| 3212 | // Dump wifi signal strength stats |
| 3213 | args = new Object[NUM_WIFI_SIGNAL_STRENGTH_BINS]; |
| 3214 | for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 3215 | args[i] = getWifiSignalStrengthTime(i, rawRealtime, which) / 1000; |
| 3216 | } |
| 3217 | dumpLine(pw, 0 /* uid */, category, WIFI_SIGNAL_STRENGTH_TIME_DATA, args); |
| 3218 | for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 3219 | args[i] = getWifiSignalStrengthCount(i, which); |
| 3220 | } |
| 3221 | dumpLine(pw, 0 /* uid */, category, WIFI_SIGNAL_STRENGTH_COUNT_DATA, args); |
| 3222 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3223 | if (which == STATS_SINCE_UNPLUGGED) { |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 3224 | dumpLine(pw, 0 /* uid */, category, BATTERY_LEVEL_DATA, getDischargeStartLevel(), |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 3225 | getDischargeCurrentLevel()); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3226 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame^] | 3227 | |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 3228 | if (which == STATS_SINCE_UNPLUGGED) { |
| 3229 | dumpLine(pw, 0 /* uid */, category, BATTERY_DISCHARGE_DATA, |
| 3230 | getDischargeStartLevel()-getDischargeCurrentLevel(), |
| 3231 | getDischargeStartLevel()-getDischargeCurrentLevel(), |
Adam Lesinski | 67c134f | 2016-06-10 15:15:08 -0700 | [diff] [blame] | 3232 | getDischargeAmountScreenOn(), getDischargeAmountScreenOff(), |
| 3233 | dischargeCount / 1000, dischargeScreenOffCount / 1000); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 3234 | } else { |
| 3235 | dumpLine(pw, 0 /* uid */, category, BATTERY_DISCHARGE_DATA, |
| 3236 | getLowDischargeAmountSinceCharge(), getHighDischargeAmountSinceCharge(), |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 3237 | getDischargeAmountScreenOnSinceCharge(), |
Adam Lesinski | 67c134f | 2016-06-10 15:15:08 -0700 | [diff] [blame] | 3238 | getDischargeAmountScreenOffSinceCharge(), |
| 3239 | dischargeCount / 1000, dischargeScreenOffCount / 1000); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 3240 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame^] | 3241 | |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 3242 | if (reqUid < 0) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3243 | final Map<String, ? extends Timer> kernelWakelocks = getKernelWakelockStats(); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 3244 | if (kernelWakelocks.size() > 0) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3245 | for (Map.Entry<String, ? extends Timer> ent : kernelWakelocks.entrySet()) { |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 3246 | sb.setLength(0); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3247 | printWakeLockCheckin(sb, ent.getValue(), rawRealtime, null, which, ""); |
Kweku Adams | e0dd9c1 | 2017-03-08 08:12:15 -0800 | [diff] [blame] | 3248 | dumpLine(pw, 0 /* uid */, category, KERNEL_WAKELOCK_DATA, |
| 3249 | "\"" + ent.getKey() + "\"", sb.toString()); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 3250 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 3251 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3252 | final Map<String, ? extends Timer> wakeupReasons = getWakeupReasonStats(); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3253 | if (wakeupReasons.size() > 0) { |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 3254 | for (Map.Entry<String, ? extends Timer> ent : wakeupReasons.entrySet()) { |
| 3255 | // Not doing the regular wake lock formatting to remain compatible |
| 3256 | // with the old checkin format. |
| 3257 | long totalTimeMicros = ent.getValue().getTotalTimeLocked(rawRealtime, which); |
| 3258 | int count = ent.getValue().getCountLocked(which); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3259 | dumpLine(pw, 0 /* uid */, category, WAKEUP_REASON_DATA, |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 3260 | "\"" + ent.getKey() + "\"", (totalTimeMicros + 500) / 1000, count); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3261 | } |
| 3262 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 3263 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame^] | 3264 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3265 | final BatteryStatsHelper helper = new BatteryStatsHelper(context, false, wifiOnly); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3266 | helper.create(this); |
| 3267 | helper.refreshStats(which, UserHandle.USER_ALL); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3268 | final List<BatterySipper> sippers = helper.getUsageList(); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3269 | if (sippers != null && sippers.size() > 0) { |
| 3270 | dumpLine(pw, 0 /* uid */, category, POWER_USE_SUMMARY_DATA, |
| 3271 | BatteryStatsHelper.makemAh(helper.getPowerProfile().getBatteryCapacity()), |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3272 | BatteryStatsHelper.makemAh(helper.getComputedPower()), |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3273 | BatteryStatsHelper.makemAh(helper.getMinDrainedPower()), |
| 3274 | BatteryStatsHelper.makemAh(helper.getMaxDrainedPower())); |
| 3275 | for (int i=0; i<sippers.size(); i++) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3276 | final BatterySipper bs = sippers.get(i); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3277 | int uid = 0; |
| 3278 | String label; |
| 3279 | switch (bs.drainType) { |
| 3280 | case IDLE: |
| 3281 | label="idle"; |
| 3282 | break; |
| 3283 | case CELL: |
| 3284 | label="cell"; |
| 3285 | break; |
| 3286 | case PHONE: |
| 3287 | label="phone"; |
| 3288 | break; |
| 3289 | case WIFI: |
| 3290 | label="wifi"; |
| 3291 | break; |
| 3292 | case BLUETOOTH: |
| 3293 | label="blue"; |
| 3294 | break; |
| 3295 | case SCREEN: |
| 3296 | label="scrn"; |
| 3297 | break; |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 3298 | case FLASHLIGHT: |
| 3299 | label="flashlight"; |
| 3300 | break; |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3301 | case APP: |
| 3302 | uid = bs.uidObj.getUid(); |
| 3303 | label = "uid"; |
| 3304 | break; |
| 3305 | case USER: |
| 3306 | uid = UserHandle.getUid(bs.userId, 0); |
| 3307 | label = "user"; |
| 3308 | break; |
| 3309 | case UNACCOUNTED: |
| 3310 | label = "unacc"; |
| 3311 | break; |
| 3312 | case OVERCOUNTED: |
| 3313 | label = "over"; |
| 3314 | break; |
Ruben Brunk | 5b1308f | 2015-06-03 18:49:27 -0700 | [diff] [blame] | 3315 | case CAMERA: |
| 3316 | label = "camera"; |
| 3317 | break; |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3318 | default: |
| 3319 | label = "???"; |
| 3320 | } |
| 3321 | dumpLine(pw, uid, category, POWER_USE_ITEM_DATA, label, |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 3322 | BatteryStatsHelper.makemAh(bs.totalPowerMah)); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3323 | } |
| 3324 | } |
| 3325 | |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 3326 | final long[] cpuFreqs = getCpuFreqs(); |
| 3327 | if (cpuFreqs != null) { |
| 3328 | sb.setLength(0); |
| 3329 | for (int i = 0; i < cpuFreqs.length; ++i) { |
| 3330 | sb.append((i == 0 ? "" : ",") + cpuFreqs[i]); |
| 3331 | } |
| 3332 | dumpLine(pw, 0 /* uid */, category, GLOBAL_CPU_FREQ_DATA, sb.toString()); |
| 3333 | } |
| 3334 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3335 | for (int iu = 0; iu < NU; iu++) { |
| 3336 | final int uid = uidStats.keyAt(iu); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 3337 | if (reqUid >= 0 && uid != reqUid) { |
| 3338 | continue; |
| 3339 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3340 | final Uid u = uidStats.valueAt(iu); |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 3341 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3342 | // Dump Network stats per uid, if any |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3343 | final long mobileBytesRx = u.getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which); |
| 3344 | final long mobileBytesTx = u.getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which); |
| 3345 | final long wifiBytesRx = u.getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which); |
| 3346 | final long wifiBytesTx = u.getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which); |
| 3347 | final long mobilePacketsRx = u.getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which); |
| 3348 | final long mobilePacketsTx = u.getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which); |
| 3349 | final long mobileActiveTime = u.getMobileRadioActiveTime(which); |
| 3350 | final int mobileActiveCount = u.getMobileRadioActiveCount(which); |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 3351 | final long mobileWakeup = u.getMobileRadioApWakeupCount(which); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3352 | final long wifiPacketsRx = u.getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which); |
| 3353 | final long wifiPacketsTx = u.getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which); |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 3354 | final long wifiWakeup = u.getWifiRadioApWakeupCount(which); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 3355 | final long btBytesRx = u.getNetworkActivityBytes(NETWORK_BT_RX_DATA, which); |
| 3356 | final long btBytesTx = u.getNetworkActivityBytes(NETWORK_BT_TX_DATA, which); |
Amith Yamasani | 59fe841 | 2017-03-03 16:28:52 -0800 | [diff] [blame] | 3357 | // Background data transfers |
| 3358 | final long mobileBytesBgRx = u.getNetworkActivityBytes(NETWORK_MOBILE_BG_RX_DATA, |
| 3359 | which); |
| 3360 | final long mobileBytesBgTx = u.getNetworkActivityBytes(NETWORK_MOBILE_BG_TX_DATA, |
| 3361 | which); |
| 3362 | final long wifiBytesBgRx = u.getNetworkActivityBytes(NETWORK_WIFI_BG_RX_DATA, which); |
| 3363 | final long wifiBytesBgTx = u.getNetworkActivityBytes(NETWORK_WIFI_BG_TX_DATA, which); |
| 3364 | final long mobilePacketsBgRx = u.getNetworkActivityPackets(NETWORK_MOBILE_BG_RX_DATA, |
| 3365 | which); |
| 3366 | final long mobilePacketsBgTx = u.getNetworkActivityPackets(NETWORK_MOBILE_BG_TX_DATA, |
| 3367 | which); |
| 3368 | final long wifiPacketsBgRx = u.getNetworkActivityPackets(NETWORK_WIFI_BG_RX_DATA, |
| 3369 | which); |
| 3370 | final long wifiPacketsBgTx = u.getNetworkActivityPackets(NETWORK_WIFI_BG_TX_DATA, |
| 3371 | which); |
| 3372 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3373 | if (mobileBytesRx > 0 || mobileBytesTx > 0 || wifiBytesRx > 0 || wifiBytesTx > 0 |
| 3374 | || mobilePacketsRx > 0 || mobilePacketsTx > 0 || wifiPacketsRx > 0 |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 3375 | || wifiPacketsTx > 0 || mobileActiveTime > 0 || mobileActiveCount > 0 |
Amith Yamasani | 59fe841 | 2017-03-03 16:28:52 -0800 | [diff] [blame] | 3376 | || btBytesRx > 0 || btBytesTx > 0 || mobileWakeup > 0 || wifiWakeup > 0 |
| 3377 | || mobileBytesBgRx > 0 || mobileBytesBgTx > 0 || wifiBytesBgRx > 0 |
| 3378 | || wifiBytesBgTx > 0 |
| 3379 | || mobilePacketsBgRx > 0 || mobilePacketsBgTx > 0 || wifiPacketsBgRx > 0 |
| 3380 | || wifiPacketsBgTx > 0) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3381 | dumpLine(pw, uid, category, NETWORK_DATA, mobileBytesRx, mobileBytesTx, |
| 3382 | wifiBytesRx, wifiBytesTx, |
| 3383 | mobilePacketsRx, mobilePacketsTx, |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 3384 | wifiPacketsRx, wifiPacketsTx, |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 3385 | mobileActiveTime, mobileActiveCount, |
Amith Yamasani | 59fe841 | 2017-03-03 16:28:52 -0800 | [diff] [blame] | 3386 | btBytesRx, btBytesTx, mobileWakeup, wifiWakeup, |
| 3387 | mobileBytesBgRx, mobileBytesBgTx, wifiBytesBgRx, wifiBytesBgTx, |
| 3388 | mobilePacketsBgRx, mobilePacketsBgTx, wifiPacketsBgRx, wifiPacketsBgTx |
| 3389 | ); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 3390 | } |
| 3391 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3392 | // Dump modem controller data, per UID. |
| 3393 | dumpControllerActivityLine(pw, uid, category, MODEM_CONTROLLER_DATA, |
| 3394 | u.getModemControllerActivity(), which); |
| 3395 | |
| 3396 | // Dump Wifi controller data, per UID. |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 3397 | final long fullWifiLockOnTime = u.getFullWifiLockTime(rawRealtime, which); |
| 3398 | final long wifiScanTime = u.getWifiScanTime(rawRealtime, which); |
| 3399 | final int wifiScanCount = u.getWifiScanCount(which); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 3400 | final int wifiScanCountBg = u.getWifiScanBackgroundCount(which); |
| 3401 | // Note that 'ActualTime' are unpooled and always since reset (regardless of 'which') |
Bookatz | ce49aca | 2017-04-03 09:47:05 -0700 | [diff] [blame] | 3402 | final long wifiScanActualTimeMs = (u.getWifiScanActualTime(rawRealtime) + 500) / 1000; |
| 3403 | final long wifiScanActualTimeMsBg = (u.getWifiScanBackgroundTime(rawRealtime) + 500) |
| 3404 | / 1000; |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 3405 | final long uidWifiRunningTime = u.getWifiRunningTime(rawRealtime, which); |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 3406 | if (fullWifiLockOnTime != 0 || wifiScanTime != 0 || wifiScanCount != 0 |
Bookatz | ce49aca | 2017-04-03 09:47:05 -0700 | [diff] [blame] | 3407 | || wifiScanCountBg != 0 || wifiScanActualTimeMs != 0 |
| 3408 | || wifiScanActualTimeMsBg != 0 || uidWifiRunningTime != 0) { |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3409 | dumpLine(pw, uid, category, WIFI_DATA, fullWifiLockOnTime, wifiScanTime, |
| 3410 | uidWifiRunningTime, wifiScanCount, |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 3411 | /* legacy fields follow, keep at 0 */ 0, 0, 0, |
Bookatz | ce49aca | 2017-04-03 09:47:05 -0700 | [diff] [blame] | 3412 | wifiScanCountBg, wifiScanActualTimeMs, wifiScanActualTimeMsBg); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3413 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3414 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3415 | dumpControllerActivityLine(pw, uid, category, WIFI_CONTROLLER_DATA, |
| 3416 | u.getWifiControllerActivity(), which); |
| 3417 | |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 3418 | final Timer bleTimer = u.getBluetoothScanTimer(); |
| 3419 | if (bleTimer != null) { |
| 3420 | // Convert from microseconds to milliseconds with rounding |
| 3421 | final long totalTime = (bleTimer.getTotalTimeLocked(rawRealtime, which) + 500) |
| 3422 | / 1000; |
| 3423 | if (totalTime != 0) { |
| 3424 | final int count = bleTimer.getCountLocked(which); |
| 3425 | final Timer bleTimerBg = u.getBluetoothScanBackgroundTimer(); |
| 3426 | final int countBg = bleTimerBg != null ? bleTimerBg.getCountLocked(which) : 0; |
| 3427 | final long rawRealtimeMs = (rawRealtime + 500) / 1000; |
| 3428 | // 'actualTime' are unpooled and always since reset (regardless of 'which') |
| 3429 | final long actualTime = bleTimer.getTotalDurationMsLocked(rawRealtimeMs); |
| 3430 | final long actualTimeBg = bleTimerBg != null ? |
| 3431 | bleTimerBg.getTotalDurationMsLocked(rawRealtimeMs) : 0; |
Bookatz | 956f36bf | 2017-04-28 09:48:17 -0700 | [diff] [blame] | 3432 | final int resultCount = u.getBluetoothScanResultCounter() != null ? |
| 3433 | u.getBluetoothScanResultCounter().getCountLocked(which) : 0; |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 3434 | dumpLine(pw, uid, category, BLUETOOTH_MISC_DATA, totalTime, count, |
Bookatz | 956f36bf | 2017-04-28 09:48:17 -0700 | [diff] [blame] | 3435 | countBg, actualTime, actualTimeBg, resultCount); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 3436 | } |
| 3437 | } |
Adam Lesinski | d9b99be | 2016-03-30 16:58:51 -0700 | [diff] [blame] | 3438 | |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 3439 | dumpControllerActivityLine(pw, uid, category, BLUETOOTH_CONTROLLER_DATA, |
| 3440 | u.getBluetoothControllerActivity(), which); |
| 3441 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3442 | if (u.hasUserActivity()) { |
| 3443 | args = new Object[Uid.NUM_USER_ACTIVITY_TYPES]; |
| 3444 | boolean hasData = false; |
| 3445 | for (int i=0; i<Uid.NUM_USER_ACTIVITY_TYPES; i++) { |
| 3446 | int val = u.getUserActivityCount(i, which); |
| 3447 | args[i] = val; |
| 3448 | if (val != 0) hasData = true; |
| 3449 | } |
| 3450 | if (hasData) { |
Ashish Sharma | cba1215 | 2014-07-07 17:14:52 -0700 | [diff] [blame] | 3451 | dumpLine(pw, uid /* uid */, category, USER_ACTIVITY_DATA, args); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3452 | } |
| 3453 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame^] | 3454 | |
| 3455 | if (u.getAggregatedPartialWakelockTimer() != null) { |
| 3456 | final Timer timer = u.getAggregatedPartialWakelockTimer(); |
| 3457 | // Convert from microseconds to milliseconds with rounding |
| 3458 | final long totTimeMs = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000; |
| 3459 | final Timer bgTimer = timer.getSubTimer(); |
| 3460 | final long bgTimeMs = bgTimer != null ? |
| 3461 | (bgTimer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000 : 0; |
| 3462 | dumpLine(pw, uid, category, AGGREGATED_WAKELOCK_DATA, totTimeMs, bgTimeMs); |
| 3463 | } |
| 3464 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3465 | final ArrayMap<String, ? extends Uid.Wakelock> wakelocks = u.getWakelockStats(); |
| 3466 | for (int iw=wakelocks.size()-1; iw>=0; iw--) { |
| 3467 | final Uid.Wakelock wl = wakelocks.valueAt(iw); |
| 3468 | String linePrefix = ""; |
| 3469 | sb.setLength(0); |
| 3470 | linePrefix = printWakeLockCheckin(sb, wl.getWakeTime(WAKE_TYPE_FULL), |
| 3471 | rawRealtime, "f", which, linePrefix); |
| 3472 | linePrefix = printWakeLockCheckin(sb, wl.getWakeTime(WAKE_TYPE_PARTIAL), |
| 3473 | rawRealtime, "p", which, linePrefix); |
| 3474 | linePrefix = printWakeLockCheckin(sb, wl.getWakeTime(WAKE_TYPE_WINDOW), |
| 3475 | rawRealtime, "w", which, linePrefix); |
| 3476 | |
| 3477 | // Only log if we had at lease one wakelock... |
| 3478 | if (sb.length() > 0) { |
| 3479 | String name = wakelocks.keyAt(iw); |
| 3480 | if (name.indexOf(',') >= 0) { |
| 3481 | name = name.replace(',', '_'); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3482 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3483 | dumpLine(pw, uid, category, WAKELOCK_DATA, name, sb.toString()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3484 | } |
| 3485 | } |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 3486 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3487 | final ArrayMap<String, ? extends Timer> syncs = u.getSyncStats(); |
| 3488 | for (int isy=syncs.size()-1; isy>=0; isy--) { |
| 3489 | final Timer timer = syncs.valueAt(isy); |
| 3490 | // Convert from microseconds to milliseconds with rounding |
| 3491 | final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000; |
| 3492 | final int count = timer.getCountLocked(which); |
Bookatz | 2bffb5b | 2017-04-13 11:59:33 -0700 | [diff] [blame] | 3493 | final Timer bgTimer = timer.getSubTimer(); |
| 3494 | final long bgTime = bgTimer != null ? |
| 3495 | (bgTimer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000 : -1; |
| 3496 | final int bgCount = bgTimer != null ? bgTimer.getCountLocked(which) : -1; |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3497 | if (totalTime != 0) { |
Kweku Adams | e0dd9c1 | 2017-03-08 08:12:15 -0800 | [diff] [blame] | 3498 | dumpLine(pw, uid, category, SYNC_DATA, "\"" + syncs.keyAt(isy) + "\"", |
Bookatz | 2bffb5b | 2017-04-13 11:59:33 -0700 | [diff] [blame] | 3499 | totalTime, count, bgTime, bgCount); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 3500 | } |
| 3501 | } |
| 3502 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3503 | final ArrayMap<String, ? extends Timer> jobs = u.getJobStats(); |
| 3504 | for (int ij=jobs.size()-1; ij>=0; ij--) { |
| 3505 | final Timer timer = jobs.valueAt(ij); |
| 3506 | // Convert from microseconds to milliseconds with rounding |
| 3507 | final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000; |
| 3508 | final int count = timer.getCountLocked(which); |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 3509 | final Timer bgTimer = timer.getSubTimer(); |
| 3510 | final long bgTime = bgTimer != null ? |
| 3511 | (bgTimer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000 : -1; |
| 3512 | final int bgCount = bgTimer != null ? bgTimer.getCountLocked(which) : -1; |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3513 | if (totalTime != 0) { |
Kweku Adams | e0dd9c1 | 2017-03-08 08:12:15 -0800 | [diff] [blame] | 3514 | dumpLine(pw, uid, category, JOB_DATA, "\"" + jobs.keyAt(ij) + "\"", |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 3515 | totalTime, count, bgTime, bgCount); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 3516 | } |
| 3517 | } |
| 3518 | |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 3519 | dumpTimer(pw, uid, category, FLASHLIGHT_DATA, u.getFlashlightTurnedOnTimer(), |
| 3520 | rawRealtime, which); |
| 3521 | dumpTimer(pw, uid, category, CAMERA_DATA, u.getCameraTurnedOnTimer(), |
| 3522 | rawRealtime, which); |
| 3523 | dumpTimer(pw, uid, category, VIDEO_DATA, u.getVideoTurnedOnTimer(), |
| 3524 | rawRealtime, which); |
| 3525 | dumpTimer(pw, uid, category, AUDIO_DATA, u.getAudioTurnedOnTimer(), |
| 3526 | rawRealtime, which); |
| 3527 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3528 | final SparseArray<? extends BatteryStats.Uid.Sensor> sensors = u.getSensorStats(); |
| 3529 | final int NSE = sensors.size(); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 3530 | for (int ise=0; ise<NSE; ise++) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3531 | final Uid.Sensor se = sensors.valueAt(ise); |
| 3532 | final int sensorNumber = sensors.keyAt(ise); |
| 3533 | final Timer timer = se.getSensorTime(); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 3534 | if (timer != null) { |
| 3535 | // Convert from microseconds to milliseconds with rounding |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3536 | final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) |
| 3537 | / 1000; |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 3538 | if (totalTime != 0) { |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 3539 | final int count = timer.getCountLocked(which); |
| 3540 | final Timer bgTimer = se.getSensorBackgroundTime(); |
| 3541 | final int bgCount = bgTimer != null ? bgTimer.getCountLocked(which) : 0; |
| 3542 | final long rawRealtimeMs = (rawRealtime + 500) / 1000; |
| 3543 | // 'actualTime' are unpooled and always since reset (regardless of 'which') |
| 3544 | final long actualTime = timer.getTotalDurationMsLocked(rawRealtimeMs); |
| 3545 | final long bgActualTime = bgTimer != null ? |
| 3546 | bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : 0; |
| 3547 | dumpLine(pw, uid, category, SENSOR_DATA, sensorNumber, totalTime, |
| 3548 | count, bgCount, actualTime, bgActualTime); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 3549 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3550 | } |
| 3551 | } |
| 3552 | |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 3553 | dumpTimer(pw, uid, category, VIBRATOR_DATA, u.getVibratorOnTimer(), |
| 3554 | rawRealtime, which); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 3555 | |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 3556 | dumpTimer(pw, uid, category, FOREGROUND_DATA, u.getForegroundActivityTimer(), |
| 3557 | rawRealtime, which); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 3558 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3559 | final Object[] stateTimes = new Object[Uid.NUM_PROCESS_STATE]; |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 3560 | long totalStateTime = 0; |
| 3561 | for (int ips=0; ips<Uid.NUM_PROCESS_STATE; ips++) { |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 3562 | final long time = u.getProcessStateTime(ips, rawRealtime, which); |
| 3563 | totalStateTime += time; |
| 3564 | stateTimes[ips] = (time + 500) / 1000; |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 3565 | } |
| 3566 | if (totalStateTime > 0) { |
| 3567 | dumpLine(pw, uid, category, STATE_TIME_DATA, stateTimes); |
| 3568 | } |
| 3569 | |
Adam Lesinski | a7a4ccc | 2015-06-26 17:43:04 -0700 | [diff] [blame] | 3570 | final long userCpuTimeUs = u.getUserCpuTimeUs(which); |
| 3571 | final long systemCpuTimeUs = u.getSystemCpuTimeUs(which); |
Adam Lesinski | d4abd1e | 2017-04-12 11:29:13 -0700 | [diff] [blame] | 3572 | if (userCpuTimeUs > 0 || systemCpuTimeUs > 0) { |
Adam Lesinski | a7a4ccc | 2015-06-26 17:43:04 -0700 | [diff] [blame] | 3573 | dumpLine(pw, uid, category, CPU_DATA, userCpuTimeUs / 1000, systemCpuTimeUs / 1000, |
Adam Lesinski | d4abd1e | 2017-04-12 11:29:13 -0700 | [diff] [blame] | 3574 | 0 /* old cpu power, keep for compatibility */); |
Adam Lesinski | a7a4ccc | 2015-06-26 17:43:04 -0700 | [diff] [blame] | 3575 | } |
| 3576 | |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 3577 | final long[] cpuFreqTimeMs = u.getCpuFreqTimes(which); |
| 3578 | // If total cpuFreqTimes is null, then we don't need to check for screenOffCpuFreqTimes. |
| 3579 | if (cpuFreqTimeMs != null) { |
| 3580 | sb.setLength(0); |
| 3581 | for (int i = 0; i < cpuFreqTimeMs.length; ++i) { |
| 3582 | sb.append((i == 0 ? "" : ",") + cpuFreqTimeMs[i]); |
| 3583 | } |
| 3584 | final long[] screenOffCpuFreqTimeMs = u.getScreenOffCpuFreqTimes(which); |
| 3585 | if (screenOffCpuFreqTimeMs != null) { |
| 3586 | for (int i = 0; i < screenOffCpuFreqTimeMs.length; ++i) { |
| 3587 | sb.append("," + screenOffCpuFreqTimeMs[i]); |
| 3588 | } |
| 3589 | } else { |
| 3590 | for (int i = 0; i < cpuFreqTimeMs.length; ++i) { |
| 3591 | sb.append(",0"); |
| 3592 | } |
| 3593 | } |
| 3594 | dumpLine(pw, uid, category, CPU_TIMES_AT_FREQ_DATA, UID_TIMES_TYPE_ALL, |
| 3595 | cpuFreqTimeMs.length, sb.toString()); |
| 3596 | } |
| 3597 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3598 | final ArrayMap<String, ? extends BatteryStats.Uid.Proc> processStats |
| 3599 | = u.getProcessStats(); |
| 3600 | for (int ipr=processStats.size()-1; ipr>=0; ipr--) { |
| 3601 | final Uid.Proc ps = processStats.valueAt(ipr); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 3602 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3603 | final long userMillis = ps.getUserTime(which); |
| 3604 | final long systemMillis = ps.getSystemTime(which); |
| 3605 | final long foregroundMillis = ps.getForegroundTime(which); |
| 3606 | final int starts = ps.getStarts(which); |
| 3607 | final int numCrashes = ps.getNumCrashes(which); |
| 3608 | final int numAnrs = ps.getNumAnrs(which); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 3609 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3610 | if (userMillis != 0 || systemMillis != 0 || foregroundMillis != 0 |
| 3611 | || starts != 0 || numAnrs != 0 || numCrashes != 0) { |
Kweku Adams | e0dd9c1 | 2017-03-08 08:12:15 -0800 | [diff] [blame] | 3612 | dumpLine(pw, uid, category, PROCESS_DATA, "\"" + processStats.keyAt(ipr) + "\"", |
| 3613 | userMillis, systemMillis, foregroundMillis, starts, numAnrs, numCrashes); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3614 | } |
| 3615 | } |
| 3616 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3617 | final ArrayMap<String, ? extends BatteryStats.Uid.Pkg> packageStats |
| 3618 | = u.getPackageStats(); |
| 3619 | for (int ipkg=packageStats.size()-1; ipkg>=0; ipkg--) { |
| 3620 | final Uid.Pkg ps = packageStats.valueAt(ipkg); |
| 3621 | int wakeups = 0; |
| 3622 | final ArrayMap<String, ? extends Counter> alarms = ps.getWakeupAlarmStats(); |
| 3623 | for (int iwa=alarms.size()-1; iwa>=0; iwa--) { |
Joe Onorato | 1476d32 | 2016-05-05 14:46:15 -0700 | [diff] [blame] | 3624 | int count = alarms.valueAt(iwa).getCountLocked(which); |
| 3625 | wakeups += count; |
| 3626 | String name = alarms.keyAt(iwa).replace(',', '_'); |
| 3627 | dumpLine(pw, uid, category, WAKEUP_ALARM_DATA, name, count); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3628 | } |
| 3629 | final ArrayMap<String, ? extends Uid.Pkg.Serv> serviceStats = ps.getServiceStats(); |
| 3630 | for (int isvc=serviceStats.size()-1; isvc>=0; isvc--) { |
| 3631 | final BatteryStats.Uid.Pkg.Serv ss = serviceStats.valueAt(isvc); |
| 3632 | final long startTime = ss.getStartTime(batteryUptime, which); |
| 3633 | final int starts = ss.getStarts(which); |
| 3634 | final int launches = ss.getLaunches(which); |
| 3635 | if (startTime != 0 || starts != 0 || launches != 0) { |
| 3636 | dumpLine(pw, uid, category, APK_DATA, |
| 3637 | wakeups, // wakeup alarms |
| 3638 | packageStats.keyAt(ipkg), // Apk |
| 3639 | serviceStats.keyAt(isvc), // service |
| 3640 | startTime / 1000, // time spent started, in ms |
| 3641 | starts, |
| 3642 | launches); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3643 | } |
| 3644 | } |
| 3645 | } |
| 3646 | } |
| 3647 | } |
| 3648 | |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 3649 | static final class TimerEntry { |
| 3650 | final String mName; |
| 3651 | final int mId; |
| 3652 | final BatteryStats.Timer mTimer; |
| 3653 | final long mTime; |
| 3654 | TimerEntry(String name, int id, BatteryStats.Timer timer, long time) { |
| 3655 | mName = name; |
| 3656 | mId = id; |
| 3657 | mTimer = timer; |
| 3658 | mTime = time; |
| 3659 | } |
| 3660 | } |
| 3661 | |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3662 | private void printmAh(PrintWriter printer, double power) { |
| 3663 | printer.print(BatteryStatsHelper.makemAh(power)); |
| 3664 | } |
| 3665 | |
Adam Lesinski | a7a4ccc | 2015-06-26 17:43:04 -0700 | [diff] [blame] | 3666 | private void printmAh(StringBuilder sb, double power) { |
| 3667 | sb.append(BatteryStatsHelper.makemAh(power)); |
| 3668 | } |
| 3669 | |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 3670 | /** |
| 3671 | * Temporary for settings. |
| 3672 | */ |
| 3673 | public final void dumpLocked(Context context, PrintWriter pw, String prefix, int which, |
| 3674 | int reqUid) { |
| 3675 | dumpLocked(context, pw, prefix, which, reqUid, BatteryStatsHelper.checkWifiOnly(context)); |
| 3676 | } |
| 3677 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3678 | @SuppressWarnings("unused") |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3679 | 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] | 3680 | int reqUid, boolean wifiOnly) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3681 | final long rawUptime = SystemClock.uptimeMillis() * 1000; |
| 3682 | final long rawRealtime = SystemClock.elapsedRealtime() * 1000; |
| 3683 | final long batteryUptime = getBatteryUptime(rawUptime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3684 | |
| 3685 | final long whichBatteryUptime = computeBatteryUptime(rawUptime, which); |
| 3686 | final long whichBatteryRealtime = computeBatteryRealtime(rawRealtime, which); |
| 3687 | final long totalRealtime = computeRealtime(rawRealtime, which); |
| 3688 | final long totalUptime = computeUptime(rawUptime, which); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3689 | final long whichBatteryScreenOffUptime = computeBatteryScreenOffUptime(rawUptime, which); |
| 3690 | final long whichBatteryScreenOffRealtime = computeBatteryScreenOffRealtime(rawRealtime, |
| 3691 | which); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 3692 | final long batteryTimeRemaining = computeBatteryTimeRemaining(rawRealtime); |
| 3693 | final long chargeTimeRemaining = computeChargeTimeRemaining(rawRealtime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3694 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3695 | final StringBuilder sb = new StringBuilder(128); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame^] | 3696 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3697 | final SparseArray<? extends Uid> uidStats = getUidStats(); |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 3698 | final int NU = uidStats.size(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3699 | |
Adam Lesinski | f9b20a9 | 2016-06-17 17:30:01 -0700 | [diff] [blame] | 3700 | final int estimatedBatteryCapacity = getEstimatedBatteryCapacity(); |
| 3701 | if (estimatedBatteryCapacity > 0) { |
| 3702 | sb.setLength(0); |
| 3703 | sb.append(prefix); |
| 3704 | sb.append(" Estimated battery capacity: "); |
| 3705 | sb.append(BatteryStatsHelper.makemAh(estimatedBatteryCapacity)); |
| 3706 | sb.append(" mAh"); |
| 3707 | pw.println(sb.toString()); |
| 3708 | } |
| 3709 | |
Jocelyn Dang | c627d10 | 2017-04-14 13:15:14 -0700 | [diff] [blame] | 3710 | final int minLearnedBatteryCapacity = getMinLearnedBatteryCapacity(); |
| 3711 | if (minLearnedBatteryCapacity > 0) { |
| 3712 | sb.setLength(0); |
| 3713 | sb.append(prefix); |
| 3714 | sb.append(" Min learned battery capacity: "); |
| 3715 | sb.append(BatteryStatsHelper.makemAh(minLearnedBatteryCapacity / 1000)); |
| 3716 | sb.append(" mAh"); |
| 3717 | pw.println(sb.toString()); |
| 3718 | } |
| 3719 | final int maxLearnedBatteryCapacity = getMaxLearnedBatteryCapacity(); |
| 3720 | if (maxLearnedBatteryCapacity > 0) { |
| 3721 | sb.setLength(0); |
| 3722 | sb.append(prefix); |
| 3723 | sb.append(" Max learned battery capacity: "); |
| 3724 | sb.append(BatteryStatsHelper.makemAh(maxLearnedBatteryCapacity / 1000)); |
| 3725 | sb.append(" mAh"); |
| 3726 | pw.println(sb.toString()); |
| 3727 | } |
| 3728 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3729 | sb.setLength(0); |
| 3730 | sb.append(prefix); |
| 3731 | sb.append(" Time on battery: "); |
| 3732 | formatTimeMs(sb, whichBatteryRealtime / 1000); sb.append("("); |
| 3733 | sb.append(formatRatioLocked(whichBatteryRealtime, totalRealtime)); |
| 3734 | sb.append(") realtime, "); |
| 3735 | formatTimeMs(sb, whichBatteryUptime / 1000); |
| 3736 | sb.append("("); sb.append(formatRatioLocked(whichBatteryUptime, totalRealtime)); |
| 3737 | sb.append(") uptime"); |
| 3738 | pw.println(sb.toString()); |
| 3739 | sb.setLength(0); |
| 3740 | sb.append(prefix); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3741 | sb.append(" Time on battery screen off: "); |
| 3742 | formatTimeMs(sb, whichBatteryScreenOffRealtime / 1000); sb.append("("); |
| 3743 | sb.append(formatRatioLocked(whichBatteryScreenOffRealtime, totalRealtime)); |
| 3744 | sb.append(") realtime, "); |
| 3745 | formatTimeMs(sb, whichBatteryScreenOffUptime / 1000); |
| 3746 | sb.append("("); |
| 3747 | sb.append(formatRatioLocked(whichBatteryScreenOffUptime, totalRealtime)); |
| 3748 | sb.append(") uptime"); |
| 3749 | pw.println(sb.toString()); |
| 3750 | sb.setLength(0); |
| 3751 | sb.append(prefix); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3752 | sb.append(" Total run time: "); |
| 3753 | formatTimeMs(sb, totalRealtime / 1000); |
| 3754 | sb.append("realtime, "); |
| 3755 | formatTimeMs(sb, totalUptime / 1000); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 3756 | sb.append("uptime"); |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 3757 | pw.println(sb.toString()); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 3758 | if (batteryTimeRemaining >= 0) { |
| 3759 | sb.setLength(0); |
| 3760 | sb.append(prefix); |
| 3761 | sb.append(" Battery time remaining: "); |
| 3762 | formatTimeMs(sb, batteryTimeRemaining / 1000); |
| 3763 | pw.println(sb.toString()); |
| 3764 | } |
| 3765 | if (chargeTimeRemaining >= 0) { |
| 3766 | sb.setLength(0); |
| 3767 | sb.append(prefix); |
| 3768 | sb.append(" Charge time remaining: "); |
| 3769 | formatTimeMs(sb, chargeTimeRemaining / 1000); |
| 3770 | pw.println(sb.toString()); |
| 3771 | } |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 3772 | |
| 3773 | final LongCounter dischargeCounter = getDischargeCoulombCounter(); |
| 3774 | final long dischargeCount = dischargeCounter.getCountLocked(which); |
| 3775 | if (dischargeCount >= 0) { |
| 3776 | sb.setLength(0); |
| 3777 | sb.append(prefix); |
| 3778 | sb.append(" Discharge: "); |
| 3779 | sb.append(BatteryStatsHelper.makemAh(dischargeCount / 1000.0)); |
| 3780 | sb.append(" mAh"); |
| 3781 | pw.println(sb.toString()); |
| 3782 | } |
| 3783 | |
| 3784 | final LongCounter dischargeScreenOffCounter = getDischargeScreenOffCoulombCounter(); |
| 3785 | final long dischargeScreenOffCount = dischargeScreenOffCounter.getCountLocked(which); |
| 3786 | if (dischargeScreenOffCount >= 0) { |
| 3787 | sb.setLength(0); |
| 3788 | sb.append(prefix); |
| 3789 | sb.append(" Screen off discharge: "); |
| 3790 | sb.append(BatteryStatsHelper.makemAh(dischargeScreenOffCount / 1000.0)); |
| 3791 | sb.append(" mAh"); |
| 3792 | pw.println(sb.toString()); |
| 3793 | } |
| 3794 | |
| 3795 | final long dischargeScreenOnCount = dischargeCount - dischargeScreenOffCount; |
| 3796 | if (dischargeScreenOnCount >= 0) { |
| 3797 | sb.setLength(0); |
| 3798 | sb.append(prefix); |
| 3799 | sb.append(" Screen on discharge: "); |
| 3800 | sb.append(BatteryStatsHelper.makemAh(dischargeScreenOnCount / 1000.0)); |
| 3801 | sb.append(" mAh"); |
| 3802 | pw.println(sb.toString()); |
| 3803 | } |
| 3804 | |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 3805 | pw.print(" Start clock time: "); |
| 3806 | pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss", getStartClockTime()).toString()); |
| 3807 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3808 | final long screenOnTime = getScreenOnTime(rawRealtime, which); |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 3809 | final long interactiveTime = getInteractiveTime(rawRealtime, which); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3810 | final long powerSaveModeEnabledTime = getPowerSaveModeEnabledTime(rawRealtime, which); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3811 | final long deviceIdleModeLightTime = getDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT, |
| 3812 | rawRealtime, which); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 3813 | final long deviceIdleModeFullTime = getDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP, |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3814 | rawRealtime, which); |
| 3815 | final long deviceLightIdlingTime = getDeviceIdlingTime(DEVICE_IDLE_MODE_LIGHT, |
| 3816 | rawRealtime, which); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 3817 | final long deviceIdlingTime = getDeviceIdlingTime(DEVICE_IDLE_MODE_DEEP, |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3818 | rawRealtime, which); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3819 | final long phoneOnTime = getPhoneOnTime(rawRealtime, which); |
| 3820 | final long wifiRunningTime = getGlobalWifiRunningTime(rawRealtime, which); |
| 3821 | final long wifiOnTime = getWifiOnTime(rawRealtime, which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3822 | sb.setLength(0); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3823 | sb.append(prefix); |
| 3824 | sb.append(" Screen on: "); formatTimeMs(sb, screenOnTime / 1000); |
| 3825 | sb.append("("); sb.append(formatRatioLocked(screenOnTime, whichBatteryRealtime)); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 3826 | sb.append(") "); sb.append(getScreenOnCount(which)); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3827 | sb.append("x, Interactive: "); formatTimeMs(sb, interactiveTime / 1000); |
| 3828 | sb.append("("); sb.append(formatRatioLocked(interactiveTime, whichBatteryRealtime)); |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 3829 | sb.append(")"); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3830 | pw.println(sb.toString()); |
| 3831 | sb.setLength(0); |
| 3832 | sb.append(prefix); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 3833 | sb.append(" Screen brightnesses:"); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3834 | boolean didOne = false; |
| 3835 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3836 | final long time = getScreenBrightnessTime(i, rawRealtime, which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3837 | if (time == 0) { |
| 3838 | continue; |
| 3839 | } |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 3840 | sb.append("\n "); |
| 3841 | sb.append(prefix); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3842 | didOne = true; |
| 3843 | sb.append(SCREEN_BRIGHTNESS_NAMES[i]); |
| 3844 | sb.append(" "); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3845 | formatTimeMs(sb, time/1000); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3846 | sb.append("("); |
| 3847 | sb.append(formatRatioLocked(time, screenOnTime)); |
| 3848 | sb.append(")"); |
| 3849 | } |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 3850 | if (!didOne) sb.append(" (no activity)"); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3851 | pw.println(sb.toString()); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3852 | if (powerSaveModeEnabledTime != 0) { |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3853 | sb.setLength(0); |
| 3854 | sb.append(prefix); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3855 | sb.append(" Power save mode enabled: "); |
| 3856 | formatTimeMs(sb, powerSaveModeEnabledTime / 1000); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3857 | sb.append("("); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3858 | sb.append(formatRatioLocked(powerSaveModeEnabledTime, whichBatteryRealtime)); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3859 | sb.append(")"); |
| 3860 | pw.println(sb.toString()); |
| 3861 | } |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3862 | if (deviceLightIdlingTime != 0) { |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3863 | sb.setLength(0); |
| 3864 | sb.append(prefix); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3865 | sb.append(" Device light idling: "); |
| 3866 | formatTimeMs(sb, deviceLightIdlingTime / 1000); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 3867 | sb.append("("); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3868 | sb.append(formatRatioLocked(deviceLightIdlingTime, whichBatteryRealtime)); |
| 3869 | sb.append(") "); sb.append(getDeviceIdlingCount(DEVICE_IDLE_MODE_LIGHT, which)); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 3870 | sb.append("x"); |
| 3871 | pw.println(sb.toString()); |
| 3872 | } |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3873 | if (deviceIdleModeLightTime != 0) { |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 3874 | sb.setLength(0); |
| 3875 | sb.append(prefix); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3876 | sb.append(" Idle mode light time: "); |
| 3877 | formatTimeMs(sb, deviceIdleModeLightTime / 1000); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3878 | sb.append("("); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3879 | sb.append(formatRatioLocked(deviceIdleModeLightTime, whichBatteryRealtime)); |
| 3880 | sb.append(") "); |
| 3881 | sb.append(getDeviceIdleModeCount(DEVICE_IDLE_MODE_LIGHT, which)); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3882 | sb.append("x"); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3883 | sb.append(" -- longest "); |
| 3884 | formatTimeMs(sb, getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT)); |
| 3885 | pw.println(sb.toString()); |
| 3886 | } |
| 3887 | if (deviceIdlingTime != 0) { |
| 3888 | sb.setLength(0); |
| 3889 | sb.append(prefix); |
| 3890 | sb.append(" Device full idling: "); |
| 3891 | formatTimeMs(sb, deviceIdlingTime / 1000); |
| 3892 | sb.append("("); |
| 3893 | sb.append(formatRatioLocked(deviceIdlingTime, whichBatteryRealtime)); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 3894 | sb.append(") "); sb.append(getDeviceIdlingCount(DEVICE_IDLE_MODE_DEEP, which)); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3895 | sb.append("x"); |
| 3896 | pw.println(sb.toString()); |
| 3897 | } |
| 3898 | if (deviceIdleModeFullTime != 0) { |
| 3899 | sb.setLength(0); |
| 3900 | sb.append(prefix); |
| 3901 | sb.append(" Idle mode full time: "); |
| 3902 | formatTimeMs(sb, deviceIdleModeFullTime / 1000); |
| 3903 | sb.append("("); |
| 3904 | sb.append(formatRatioLocked(deviceIdleModeFullTime, whichBatteryRealtime)); |
| 3905 | sb.append(") "); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 3906 | sb.append(getDeviceIdleModeCount(DEVICE_IDLE_MODE_DEEP, which)); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3907 | sb.append("x"); |
| 3908 | sb.append(" -- longest "); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 3909 | formatTimeMs(sb, getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP)); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3910 | pw.println(sb.toString()); |
| 3911 | } |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3912 | if (phoneOnTime != 0) { |
| 3913 | sb.setLength(0); |
| 3914 | sb.append(prefix); |
| 3915 | sb.append(" Active phone call: "); formatTimeMs(sb, phoneOnTime / 1000); |
| 3916 | sb.append("("); sb.append(formatRatioLocked(phoneOnTime, whichBatteryRealtime)); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3917 | sb.append(") "); sb.append(getPhoneOnCount(which)); sb.append("x"); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3918 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3919 | final int connChanges = getNumConnectivityChange(which); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 3920 | if (connChanges != 0) { |
| 3921 | pw.print(prefix); |
| 3922 | pw.print(" Connectivity changes: "); pw.println(connChanges); |
| 3923 | } |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3924 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3925 | // Calculate wakelock times across all uids. |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 3926 | long fullWakeLockTimeTotalMicros = 0; |
| 3927 | long partialWakeLockTimeTotalMicros = 0; |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 3928 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3929 | final ArrayList<TimerEntry> timers = new ArrayList<>(); |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 3930 | |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 3931 | for (int iu = 0; iu < NU; iu++) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3932 | final Uid u = uidStats.valueAt(iu); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 3933 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3934 | final ArrayMap<String, ? extends BatteryStats.Uid.Wakelock> wakelocks |
| 3935 | = u.getWakelockStats(); |
| 3936 | for (int iw=wakelocks.size()-1; iw>=0; iw--) { |
| 3937 | final Uid.Wakelock wl = wakelocks.valueAt(iw); |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 3938 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3939 | final Timer fullWakeTimer = wl.getWakeTime(WAKE_TYPE_FULL); |
| 3940 | if (fullWakeTimer != null) { |
| 3941 | fullWakeLockTimeTotalMicros += fullWakeTimer.getTotalTimeLocked( |
| 3942 | rawRealtime, which); |
| 3943 | } |
| 3944 | |
| 3945 | final Timer partialWakeTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL); |
| 3946 | if (partialWakeTimer != null) { |
| 3947 | final long totalTimeMicros = partialWakeTimer.getTotalTimeLocked( |
| 3948 | rawRealtime, which); |
| 3949 | if (totalTimeMicros > 0) { |
| 3950 | if (reqUid < 0) { |
| 3951 | // Only show the ordered list of all wake |
| 3952 | // locks if the caller is not asking for data |
| 3953 | // about a specific uid. |
| 3954 | timers.add(new TimerEntry(wakelocks.keyAt(iw), u.getUid(), |
| 3955 | partialWakeTimer, totalTimeMicros)); |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 3956 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3957 | partialWakeLockTimeTotalMicros += totalTimeMicros; |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 3958 | } |
| 3959 | } |
| 3960 | } |
| 3961 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame^] | 3962 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3963 | final long mobileRxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which); |
| 3964 | final long mobileTxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which); |
| 3965 | final long wifiRxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which); |
| 3966 | final long wifiTxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which); |
| 3967 | final long mobileRxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which); |
| 3968 | final long mobileTxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which); |
| 3969 | final long wifiRxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which); |
| 3970 | final long wifiTxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which); |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 3971 | final long btRxTotalBytes = getNetworkActivityBytes(NETWORK_BT_RX_DATA, which); |
| 3972 | final long btTxTotalBytes = getNetworkActivityBytes(NETWORK_BT_TX_DATA, which); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3973 | |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 3974 | if (fullWakeLockTimeTotalMicros != 0) { |
| 3975 | sb.setLength(0); |
| 3976 | sb.append(prefix); |
| 3977 | sb.append(" Total full wakelock time: "); formatTimeMsNoSpace(sb, |
| 3978 | (fullWakeLockTimeTotalMicros + 500) / 1000); |
| 3979 | pw.println(sb.toString()); |
| 3980 | } |
| 3981 | |
| 3982 | if (partialWakeLockTimeTotalMicros != 0) { |
| 3983 | sb.setLength(0); |
| 3984 | sb.append(prefix); |
| 3985 | sb.append(" Total partial wakelock time: "); formatTimeMsNoSpace(sb, |
| 3986 | (partialWakeLockTimeTotalMicros + 500) / 1000); |
| 3987 | pw.println(sb.toString()); |
| 3988 | } |
| 3989 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3990 | pw.print(prefix); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3991 | pw.print(" Mobile total received: "); pw.print(formatBytesLocked(mobileRxTotalBytes)); |
| 3992 | pw.print(", sent: "); pw.print(formatBytesLocked(mobileTxTotalBytes)); |
| 3993 | pw.print(" (packets received "); pw.print(mobileRxTotalPackets); |
| 3994 | pw.print(", sent "); pw.print(mobileTxTotalPackets); pw.println(")"); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3995 | sb.setLength(0); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3996 | sb.append(prefix); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 3997 | sb.append(" Phone signal levels:"); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3998 | didOne = false; |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 3999 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4000 | final long time = getPhoneSignalStrengthTime(i, rawRealtime, which); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4001 | if (time == 0) { |
| 4002 | continue; |
| 4003 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 4004 | sb.append("\n "); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 4005 | sb.append(prefix); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4006 | didOne = true; |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 4007 | sb.append(SignalStrength.SIGNAL_STRENGTH_NAMES[i]); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4008 | sb.append(" "); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4009 | formatTimeMs(sb, time/1000); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4010 | sb.append("("); |
| 4011 | sb.append(formatRatioLocked(time, whichBatteryRealtime)); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4012 | sb.append(") "); |
| 4013 | sb.append(getPhoneSignalStrengthCount(i, which)); |
| 4014 | sb.append("x"); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4015 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 4016 | if (!didOne) sb.append(" (no activity)"); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4017 | pw.println(sb.toString()); |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 4018 | |
| 4019 | sb.setLength(0); |
| 4020 | sb.append(prefix); |
| 4021 | sb.append(" Signal scanning time: "); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4022 | formatTimeMsNoSpace(sb, getPhoneSignalScanningTime(rawRealtime, which) / 1000); |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 4023 | pw.println(sb.toString()); |
| 4024 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4025 | sb.setLength(0); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4026 | sb.append(prefix); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 4027 | sb.append(" Radio types:"); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4028 | didOne = false; |
| 4029 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4030 | final long time = getPhoneDataConnectionTime(i, rawRealtime, which); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4031 | if (time == 0) { |
| 4032 | continue; |
| 4033 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 4034 | sb.append("\n "); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 4035 | sb.append(prefix); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4036 | didOne = true; |
| 4037 | sb.append(DATA_CONNECTION_NAMES[i]); |
| 4038 | sb.append(" "); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4039 | formatTimeMs(sb, time/1000); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4040 | sb.append("("); |
| 4041 | sb.append(formatRatioLocked(time, whichBatteryRealtime)); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4042 | sb.append(") "); |
| 4043 | sb.append(getPhoneDataConnectionCount(i, which)); |
| 4044 | sb.append("x"); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4045 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 4046 | if (!didOne) sb.append(" (no activity)"); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4047 | pw.println(sb.toString()); |
Amith Yamasani | 3f7e35c | 2009-07-13 16:02:45 -0700 | [diff] [blame] | 4048 | |
| 4049 | sb.setLength(0); |
| 4050 | sb.append(prefix); |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 4051 | sb.append(" Mobile radio active time: "); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4052 | final long mobileActiveTime = getMobileRadioActiveTime(rawRealtime, which); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4053 | formatTimeMs(sb, mobileActiveTime / 1000); |
| 4054 | sb.append("("); sb.append(formatRatioLocked(mobileActiveTime, whichBatteryRealtime)); |
| 4055 | sb.append(") "); sb.append(getMobileRadioActiveCount(which)); |
| 4056 | sb.append("x"); |
Amith Yamasani | 3f7e35c | 2009-07-13 16:02:45 -0700 | [diff] [blame] | 4057 | pw.println(sb.toString()); |
| 4058 | |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4059 | final long mobileActiveUnknownTime = getMobileRadioActiveUnknownTime(which); |
| 4060 | if (mobileActiveUnknownTime != 0) { |
| 4061 | sb.setLength(0); |
| 4062 | sb.append(prefix); |
| 4063 | sb.append(" Mobile radio active unknown time: "); |
| 4064 | formatTimeMs(sb, mobileActiveUnknownTime / 1000); |
| 4065 | sb.append("("); |
| 4066 | sb.append(formatRatioLocked(mobileActiveUnknownTime, whichBatteryRealtime)); |
| 4067 | sb.append(") "); sb.append(getMobileRadioActiveUnknownCount(which)); |
| 4068 | sb.append("x"); |
| 4069 | pw.println(sb.toString()); |
| 4070 | } |
| 4071 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 4072 | final long mobileActiveAdjustedTime = getMobileRadioActiveAdjustedTime(which); |
| 4073 | if (mobileActiveAdjustedTime != 0) { |
| 4074 | sb.setLength(0); |
| 4075 | sb.append(prefix); |
| 4076 | sb.append(" Mobile radio active adjusted time: "); |
| 4077 | formatTimeMs(sb, mobileActiveAdjustedTime / 1000); |
| 4078 | sb.append("("); |
| 4079 | sb.append(formatRatioLocked(mobileActiveAdjustedTime, whichBatteryRealtime)); |
| 4080 | sb.append(")"); |
| 4081 | pw.println(sb.toString()); |
| 4082 | } |
| 4083 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 4084 | printControllerActivity(pw, sb, prefix, "Radio", getModemControllerActivity(), which); |
| 4085 | |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 4086 | pw.print(prefix); |
| 4087 | pw.print(" Wi-Fi total received: "); pw.print(formatBytesLocked(wifiRxTotalBytes)); |
| 4088 | pw.print(", sent: "); pw.print(formatBytesLocked(wifiTxTotalBytes)); |
| 4089 | pw.print(" (packets received "); pw.print(wifiRxTotalPackets); |
| 4090 | pw.print(", sent "); pw.print(wifiTxTotalPackets); pw.println(")"); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4091 | sb.setLength(0); |
| 4092 | sb.append(prefix); |
| 4093 | sb.append(" Wifi on: "); formatTimeMs(sb, wifiOnTime / 1000); |
| 4094 | sb.append("("); sb.append(formatRatioLocked(wifiOnTime, whichBatteryRealtime)); |
| 4095 | sb.append("), Wifi running: "); formatTimeMs(sb, wifiRunningTime / 1000); |
| 4096 | sb.append("("); sb.append(formatRatioLocked(wifiRunningTime, whichBatteryRealtime)); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4097 | sb.append(")"); |
| 4098 | pw.println(sb.toString()); |
| 4099 | |
| 4100 | sb.setLength(0); |
| 4101 | sb.append(prefix); |
| 4102 | sb.append(" Wifi states:"); |
| 4103 | didOne = false; |
| 4104 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4105 | final long time = getWifiStateTime(i, rawRealtime, which); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4106 | if (time == 0) { |
| 4107 | continue; |
| 4108 | } |
| 4109 | sb.append("\n "); |
| 4110 | didOne = true; |
| 4111 | sb.append(WIFI_STATE_NAMES[i]); |
| 4112 | sb.append(" "); |
| 4113 | formatTimeMs(sb, time/1000); |
| 4114 | sb.append("("); |
| 4115 | sb.append(formatRatioLocked(time, whichBatteryRealtime)); |
| 4116 | sb.append(") "); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 4117 | sb.append(getWifiStateCount(i, which)); |
| 4118 | sb.append("x"); |
| 4119 | } |
| 4120 | if (!didOne) sb.append(" (no activity)"); |
| 4121 | pw.println(sb.toString()); |
| 4122 | |
| 4123 | sb.setLength(0); |
| 4124 | sb.append(prefix); |
| 4125 | sb.append(" Wifi supplicant states:"); |
| 4126 | didOne = false; |
| 4127 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
| 4128 | final long time = getWifiSupplStateTime(i, rawRealtime, which); |
| 4129 | if (time == 0) { |
| 4130 | continue; |
| 4131 | } |
| 4132 | sb.append("\n "); |
| 4133 | didOne = true; |
| 4134 | sb.append(WIFI_SUPPL_STATE_NAMES[i]); |
| 4135 | sb.append(" "); |
| 4136 | formatTimeMs(sb, time/1000); |
| 4137 | sb.append("("); |
| 4138 | sb.append(formatRatioLocked(time, whichBatteryRealtime)); |
| 4139 | sb.append(") "); |
| 4140 | sb.append(getWifiSupplStateCount(i, which)); |
| 4141 | sb.append("x"); |
| 4142 | } |
| 4143 | if (!didOne) sb.append(" (no activity)"); |
| 4144 | pw.println(sb.toString()); |
| 4145 | |
| 4146 | sb.setLength(0); |
| 4147 | sb.append(prefix); |
| 4148 | sb.append(" Wifi signal levels:"); |
| 4149 | didOne = false; |
| 4150 | for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 4151 | final long time = getWifiSignalStrengthTime(i, rawRealtime, which); |
| 4152 | if (time == 0) { |
| 4153 | continue; |
| 4154 | } |
| 4155 | sb.append("\n "); |
| 4156 | sb.append(prefix); |
| 4157 | didOne = true; |
| 4158 | sb.append("level("); |
| 4159 | sb.append(i); |
| 4160 | sb.append(") "); |
| 4161 | formatTimeMs(sb, time/1000); |
| 4162 | sb.append("("); |
| 4163 | sb.append(formatRatioLocked(time, whichBatteryRealtime)); |
| 4164 | sb.append(") "); |
| 4165 | sb.append(getWifiSignalStrengthCount(i, which)); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4166 | sb.append("x"); |
| 4167 | } |
| 4168 | if (!didOne) sb.append(" (no activity)"); |
| 4169 | pw.println(sb.toString()); |
| 4170 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 4171 | printControllerActivity(pw, sb, prefix, "WiFi", getWifiControllerActivity(), which); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 4172 | |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 4173 | pw.print(prefix); |
| 4174 | pw.print(" Bluetooth total received: "); pw.print(formatBytesLocked(btRxTotalBytes)); |
| 4175 | pw.print(", sent: "); pw.println(formatBytesLocked(btTxTotalBytes)); |
| 4176 | |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 4177 | final long bluetoothScanTimeMs = getBluetoothScanTime(rawRealtime, which) / 1000; |
| 4178 | sb.setLength(0); |
| 4179 | sb.append(prefix); |
| 4180 | sb.append(" Bluetooth scan time: "); formatTimeMs(sb, bluetoothScanTimeMs); |
| 4181 | pw.println(sb.toString()); |
| 4182 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 4183 | printControllerActivity(pw, sb, prefix, "Bluetooth", getBluetoothControllerActivity(), |
| 4184 | which); |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 4185 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4186 | pw.println(); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4187 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4188 | if (which == STATS_SINCE_UNPLUGGED) { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4189 | if (getIsOnBattery()) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4190 | pw.print(prefix); pw.println(" Device is currently unplugged"); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame^] | 4191 | pw.print(prefix); pw.print(" Discharge cycle start level: "); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4192 | pw.println(getDischargeStartLevel()); |
| 4193 | pw.print(prefix); pw.print(" Discharge cycle current level: "); |
| 4194 | pw.println(getDischargeCurrentLevel()); |
Dianne Hackborn | 99d0452 | 2010-08-20 13:43:00 -0700 | [diff] [blame] | 4195 | } else { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4196 | pw.print(prefix); pw.println(" Device is currently plugged into power"); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame^] | 4197 | pw.print(prefix); pw.print(" Last discharge cycle start level: "); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4198 | pw.println(getDischargeStartLevel()); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame^] | 4199 | pw.print(prefix); pw.print(" Last discharge cycle end level: "); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4200 | pw.println(getDischargeCurrentLevel()); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4201 | } |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 4202 | pw.print(prefix); pw.print(" Amount discharged while screen on: "); |
| 4203 | pw.println(getDischargeAmountScreenOn()); |
| 4204 | pw.print(prefix); pw.print(" Amount discharged while screen off: "); |
| 4205 | pw.println(getDischargeAmountScreenOff()); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4206 | pw.println(" "); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4207 | } else { |
| 4208 | pw.print(prefix); pw.println(" Device battery use since last full charge"); |
| 4209 | pw.print(prefix); pw.print(" Amount discharged (lower bound): "); |
| 4210 | pw.println(getLowDischargeAmountSinceCharge()); |
| 4211 | pw.print(prefix); pw.print(" Amount discharged (upper bound): "); |
| 4212 | pw.println(getHighDischargeAmountSinceCharge()); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 4213 | pw.print(prefix); pw.print(" Amount discharged while screen on: "); |
| 4214 | pw.println(getDischargeAmountScreenOnSinceCharge()); |
| 4215 | pw.print(prefix); pw.print(" Amount discharged while screen off: "); |
| 4216 | pw.println(getDischargeAmountScreenOffSinceCharge()); |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 4217 | pw.println(); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4218 | } |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 4219 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4220 | final BatteryStatsHelper helper = new BatteryStatsHelper(context, false, wifiOnly); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4221 | helper.create(this); |
| 4222 | helper.refreshStats(which, UserHandle.USER_ALL); |
| 4223 | List<BatterySipper> sippers = helper.getUsageList(); |
| 4224 | if (sippers != null && sippers.size() > 0) { |
| 4225 | pw.print(prefix); pw.println(" Estimated power use (mAh):"); |
| 4226 | pw.print(prefix); pw.print(" Capacity: "); |
| 4227 | printmAh(pw, helper.getPowerProfile().getBatteryCapacity()); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4228 | pw.print(", Computed drain: "); printmAh(pw, helper.getComputedPower()); |
Dianne Hackborn | 536456f | 2014-05-23 16:51:05 -0700 | [diff] [blame] | 4229 | pw.print(", actual drain: "); printmAh(pw, helper.getMinDrainedPower()); |
| 4230 | if (helper.getMinDrainedPower() != helper.getMaxDrainedPower()) { |
| 4231 | pw.print("-"); printmAh(pw, helper.getMaxDrainedPower()); |
| 4232 | } |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4233 | pw.println(); |
| 4234 | for (int i=0; i<sippers.size(); i++) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4235 | final BatterySipper bs = sippers.get(i); |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4236 | pw.print(prefix); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4237 | switch (bs.drainType) { |
| 4238 | case IDLE: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4239 | pw.print(" Idle: "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4240 | break; |
| 4241 | case CELL: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4242 | pw.print(" Cell standby: "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4243 | break; |
| 4244 | case PHONE: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4245 | pw.print(" Phone calls: "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4246 | break; |
| 4247 | case WIFI: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4248 | pw.print(" Wifi: "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4249 | break; |
| 4250 | case BLUETOOTH: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4251 | pw.print(" Bluetooth: "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4252 | break; |
| 4253 | case SCREEN: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4254 | pw.print(" Screen: "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4255 | break; |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 4256 | case FLASHLIGHT: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4257 | pw.print(" Flashlight: "); |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 4258 | break; |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4259 | case APP: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4260 | pw.print(" Uid "); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4261 | UserHandle.formatUid(pw, bs.uidObj.getUid()); |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4262 | pw.print(": "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4263 | break; |
| 4264 | case USER: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4265 | pw.print(" User "); pw.print(bs.userId); |
| 4266 | pw.print(": "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4267 | break; |
| 4268 | case UNACCOUNTED: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4269 | pw.print(" Unaccounted: "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4270 | break; |
| 4271 | case OVERCOUNTED: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4272 | pw.print(" Over-counted: "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4273 | break; |
Ruben Brunk | 5b1308f | 2015-06-03 18:49:27 -0700 | [diff] [blame] | 4274 | case CAMERA: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4275 | pw.print(" Camera: "); |
| 4276 | break; |
| 4277 | default: |
| 4278 | pw.print(" ???: "); |
Ruben Brunk | 5b1308f | 2015-06-03 18:49:27 -0700 | [diff] [blame] | 4279 | break; |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4280 | } |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4281 | printmAh(pw, bs.totalPowerMah); |
| 4282 | |
Adam Lesinski | 5712300 | 2015-06-12 16:12:07 -0700 | [diff] [blame] | 4283 | if (bs.usagePowerMah != bs.totalPowerMah) { |
| 4284 | // If the usage (generic power) isn't the whole amount, we list out |
| 4285 | // what components are involved in the calculation. |
| 4286 | |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4287 | pw.print(" ("); |
Adam Lesinski | 5712300 | 2015-06-12 16:12:07 -0700 | [diff] [blame] | 4288 | if (bs.usagePowerMah != 0) { |
| 4289 | pw.print(" usage="); |
| 4290 | printmAh(pw, bs.usagePowerMah); |
| 4291 | } |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4292 | if (bs.cpuPowerMah != 0) { |
| 4293 | pw.print(" cpu="); |
| 4294 | printmAh(pw, bs.cpuPowerMah); |
| 4295 | } |
| 4296 | if (bs.wakeLockPowerMah != 0) { |
| 4297 | pw.print(" wake="); |
| 4298 | printmAh(pw, bs.wakeLockPowerMah); |
| 4299 | } |
| 4300 | if (bs.mobileRadioPowerMah != 0) { |
| 4301 | pw.print(" radio="); |
| 4302 | printmAh(pw, bs.mobileRadioPowerMah); |
| 4303 | } |
| 4304 | if (bs.wifiPowerMah != 0) { |
| 4305 | pw.print(" wifi="); |
| 4306 | printmAh(pw, bs.wifiPowerMah); |
| 4307 | } |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 4308 | if (bs.bluetoothPowerMah != 0) { |
| 4309 | pw.print(" bt="); |
| 4310 | printmAh(pw, bs.bluetoothPowerMah); |
| 4311 | } |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4312 | if (bs.gpsPowerMah != 0) { |
| 4313 | pw.print(" gps="); |
| 4314 | printmAh(pw, bs.gpsPowerMah); |
| 4315 | } |
| 4316 | if (bs.sensorPowerMah != 0) { |
| 4317 | pw.print(" sensor="); |
| 4318 | printmAh(pw, bs.sensorPowerMah); |
| 4319 | } |
| 4320 | if (bs.cameraPowerMah != 0) { |
| 4321 | pw.print(" camera="); |
| 4322 | printmAh(pw, bs.cameraPowerMah); |
| 4323 | } |
| 4324 | if (bs.flashlightPowerMah != 0) { |
| 4325 | pw.print(" flash="); |
| 4326 | printmAh(pw, bs.flashlightPowerMah); |
| 4327 | } |
| 4328 | pw.print(" )"); |
| 4329 | } |
| 4330 | pw.println(); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4331 | } |
Dianne Hackborn | c46809e | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4332 | pw.println(); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4333 | } |
| 4334 | |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4335 | sippers = helper.getMobilemsppList(); |
| 4336 | if (sippers != null && sippers.size() > 0) { |
| 4337 | pw.print(prefix); pw.println(" Per-app mobile ms per packet:"); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 4338 | long totalTime = 0; |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4339 | for (int i=0; i<sippers.size(); i++) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4340 | final BatterySipper bs = sippers.get(i); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4341 | sb.setLength(0); |
| 4342 | sb.append(prefix); sb.append(" Uid "); |
| 4343 | UserHandle.formatUid(sb, bs.uidObj.getUid()); |
| 4344 | sb.append(": "); sb.append(BatteryStatsHelper.makemAh(bs.mobilemspp)); |
| 4345 | sb.append(" ("); sb.append(bs.mobileRxPackets+bs.mobileTxPackets); |
| 4346 | sb.append(" packets over "); formatTimeMsNoSpace(sb, bs.mobileActive); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 4347 | sb.append(") "); sb.append(bs.mobileActiveCount); sb.append("x"); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4348 | pw.println(sb.toString()); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 4349 | totalTime += bs.mobileActive; |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4350 | } |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 4351 | sb.setLength(0); |
| 4352 | sb.append(prefix); |
| 4353 | sb.append(" TOTAL TIME: "); |
| 4354 | formatTimeMs(sb, totalTime); |
| 4355 | sb.append("("); sb.append(formatRatioLocked(totalTime, whichBatteryRealtime)); |
| 4356 | sb.append(")"); |
| 4357 | pw.println(sb.toString()); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4358 | pw.println(); |
| 4359 | } |
| 4360 | |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 4361 | final Comparator<TimerEntry> timerComparator = new Comparator<TimerEntry>() { |
| 4362 | @Override |
| 4363 | public int compare(TimerEntry lhs, TimerEntry rhs) { |
| 4364 | long lhsTime = lhs.mTime; |
| 4365 | long rhsTime = rhs.mTime; |
| 4366 | if (lhsTime < rhsTime) { |
| 4367 | return 1; |
| 4368 | } |
| 4369 | if (lhsTime > rhsTime) { |
| 4370 | return -1; |
| 4371 | } |
| 4372 | return 0; |
| 4373 | } |
| 4374 | }; |
| 4375 | |
| 4376 | if (reqUid < 0) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4377 | final Map<String, ? extends BatteryStats.Timer> kernelWakelocks |
| 4378 | = getKernelWakelockStats(); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 4379 | if (kernelWakelocks.size() > 0) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4380 | final ArrayList<TimerEntry> ktimers = new ArrayList<>(); |
| 4381 | for (Map.Entry<String, ? extends BatteryStats.Timer> ent |
| 4382 | : kernelWakelocks.entrySet()) { |
| 4383 | final BatteryStats.Timer timer = ent.getValue(); |
| 4384 | final long totalTimeMillis = computeWakeLock(timer, rawRealtime, which); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 4385 | if (totalTimeMillis > 0) { |
| 4386 | ktimers.add(new TimerEntry(ent.getKey(), 0, timer, totalTimeMillis)); |
| 4387 | } |
| 4388 | } |
| 4389 | if (ktimers.size() > 0) { |
| 4390 | Collections.sort(ktimers, timerComparator); |
| 4391 | pw.print(prefix); pw.println(" All kernel wake locks:"); |
| 4392 | for (int i=0; i<ktimers.size(); i++) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4393 | final TimerEntry timer = ktimers.get(i); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 4394 | String linePrefix = ": "; |
| 4395 | sb.setLength(0); |
| 4396 | sb.append(prefix); |
| 4397 | sb.append(" Kernel Wake lock "); |
| 4398 | sb.append(timer.mName); |
| 4399 | linePrefix = printWakeLock(sb, timer.mTimer, rawRealtime, null, |
| 4400 | which, linePrefix); |
| 4401 | if (!linePrefix.equals(": ")) { |
| 4402 | sb.append(" realtime"); |
| 4403 | // Only print out wake locks that were held |
| 4404 | pw.println(sb.toString()); |
| 4405 | } |
| 4406 | } |
| 4407 | pw.println(); |
| 4408 | } |
| 4409 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 4410 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 4411 | if (timers.size() > 0) { |
| 4412 | Collections.sort(timers, timerComparator); |
| 4413 | pw.print(prefix); pw.println(" All partial wake locks:"); |
| 4414 | for (int i=0; i<timers.size(); i++) { |
| 4415 | TimerEntry timer = timers.get(i); |
| 4416 | sb.setLength(0); |
| 4417 | sb.append(" Wake lock "); |
| 4418 | UserHandle.formatUid(sb, timer.mId); |
| 4419 | sb.append(" "); |
| 4420 | sb.append(timer.mName); |
| 4421 | printWakeLock(sb, timer.mTimer, rawRealtime, null, which, ": "); |
| 4422 | sb.append(" realtime"); |
| 4423 | pw.println(sb.toString()); |
| 4424 | } |
| 4425 | timers.clear(); |
| 4426 | pw.println(); |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 4427 | } |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 4428 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4429 | final Map<String, ? extends Timer> wakeupReasons = getWakeupReasonStats(); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 4430 | if (wakeupReasons.size() > 0) { |
| 4431 | pw.print(prefix); pw.println(" All wakeup reasons:"); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4432 | final ArrayList<TimerEntry> reasons = new ArrayList<>(); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 4433 | for (Map.Entry<String, ? extends Timer> ent : wakeupReasons.entrySet()) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4434 | final Timer timer = ent.getValue(); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 4435 | reasons.add(new TimerEntry(ent.getKey(), 0, timer, |
| 4436 | timer.getCountLocked(which))); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 4437 | } |
| 4438 | Collections.sort(reasons, timerComparator); |
| 4439 | for (int i=0; i<reasons.size(); i++) { |
| 4440 | TimerEntry timer = reasons.get(i); |
| 4441 | String linePrefix = ": "; |
| 4442 | sb.setLength(0); |
| 4443 | sb.append(prefix); |
| 4444 | sb.append(" Wakeup reason "); |
| 4445 | sb.append(timer.mName); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 4446 | printWakeLock(sb, timer.mTimer, rawRealtime, null, which, ": "); |
| 4447 | sb.append(" realtime"); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 4448 | pw.println(sb.toString()); |
| 4449 | } |
| 4450 | pw.println(); |
| 4451 | } |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 4452 | } |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 4453 | |
James Carr | 2dd7e5e | 2016-07-20 18:48:39 -0700 | [diff] [blame] | 4454 | final LongSparseArray<? extends Timer> mMemoryStats = getKernelMemoryStats(); |
| 4455 | pw.println("Memory Stats"); |
| 4456 | for (int i = 0; i < mMemoryStats.size(); i++) { |
| 4457 | sb.setLength(0); |
| 4458 | sb.append("Bandwidth "); |
| 4459 | sb.append(mMemoryStats.keyAt(i)); |
| 4460 | sb.append(" Time "); |
| 4461 | sb.append(mMemoryStats.valueAt(i).getTotalTimeLocked(rawRealtime, which)); |
| 4462 | pw.println(sb.toString()); |
| 4463 | } |
| 4464 | |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 4465 | final long[] cpuFreqs = getCpuFreqs(); |
| 4466 | if (cpuFreqs != null) { |
| 4467 | sb.setLength(0); |
| 4468 | sb.append("CPU freqs:"); |
| 4469 | for (int i = 0; i < cpuFreqs.length; ++i) { |
| 4470 | sb.append(" " + cpuFreqs[i]); |
| 4471 | } |
| 4472 | pw.println(sb.toString()); |
| 4473 | } |
| 4474 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4475 | for (int iu=0; iu<NU; iu++) { |
| 4476 | final int uid = uidStats.keyAt(iu); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 4477 | if (reqUid >= 0 && uid != reqUid && uid != Process.SYSTEM_UID) { |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 4478 | continue; |
| 4479 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame^] | 4480 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4481 | final Uid u = uidStats.valueAt(iu); |
Dianne Hackborn | a4cc205 | 2013-07-08 17:31:25 -0700 | [diff] [blame] | 4482 | |
| 4483 | pw.print(prefix); |
| 4484 | pw.print(" "); |
| 4485 | UserHandle.formatUid(pw, uid); |
| 4486 | pw.println(":"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4487 | boolean uidActivity = false; |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4488 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4489 | final long mobileRxBytes = u.getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which); |
| 4490 | final long mobileTxBytes = u.getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which); |
| 4491 | final long wifiRxBytes = u.getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which); |
| 4492 | final long wifiTxBytes = u.getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which); |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 4493 | final long btRxBytes = u.getNetworkActivityBytes(NETWORK_BT_RX_DATA, which); |
| 4494 | final long btTxBytes = u.getNetworkActivityBytes(NETWORK_BT_TX_DATA, which); |
| 4495 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4496 | final long mobileRxPackets = u.getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which); |
| 4497 | final long mobileTxPackets = u.getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4498 | final long wifiRxPackets = u.getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which); |
| 4499 | final long wifiTxPackets = u.getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which); |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 4500 | |
| 4501 | final long uidMobileActiveTime = u.getMobileRadioActiveTime(which); |
| 4502 | final int uidMobileActiveCount = u.getMobileRadioActiveCount(which); |
| 4503 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4504 | final long fullWifiLockOnTime = u.getFullWifiLockTime(rawRealtime, which); |
| 4505 | final long wifiScanTime = u.getWifiScanTime(rawRealtime, which); |
| 4506 | final int wifiScanCount = u.getWifiScanCount(which); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 4507 | final int wifiScanCountBg = u.getWifiScanBackgroundCount(which); |
| 4508 | // 'actualTime' are unpooled and always since reset (regardless of 'which') |
| 4509 | final long wifiScanActualTime = u.getWifiScanActualTime(rawRealtime); |
| 4510 | final long wifiScanActualTimeBg = u.getWifiScanBackgroundTime(rawRealtime); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4511 | final long uidWifiRunningTime = u.getWifiRunningTime(rawRealtime, which); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 4512 | |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 4513 | final long mobileWakeup = u.getMobileRadioApWakeupCount(which); |
| 4514 | final long wifiWakeup = u.getWifiRadioApWakeupCount(which); |
| 4515 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4516 | if (mobileRxBytes > 0 || mobileTxBytes > 0 |
| 4517 | || mobileRxPackets > 0 || mobileTxPackets > 0) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 4518 | pw.print(prefix); pw.print(" Mobile network: "); |
| 4519 | pw.print(formatBytesLocked(mobileRxBytes)); pw.print(" received, "); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4520 | pw.print(formatBytesLocked(mobileTxBytes)); |
| 4521 | pw.print(" sent (packets "); pw.print(mobileRxPackets); |
| 4522 | pw.print(" received, "); pw.print(mobileTxPackets); pw.println(" sent)"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4523 | } |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4524 | if (uidMobileActiveTime > 0 || uidMobileActiveCount > 0) { |
| 4525 | sb.setLength(0); |
| 4526 | sb.append(prefix); sb.append(" Mobile radio active: "); |
| 4527 | formatTimeMs(sb, uidMobileActiveTime / 1000); |
| 4528 | sb.append("("); |
| 4529 | sb.append(formatRatioLocked(uidMobileActiveTime, mobileActiveTime)); |
| 4530 | sb.append(") "); sb.append(uidMobileActiveCount); sb.append("x"); |
| 4531 | long packets = mobileRxPackets + mobileTxPackets; |
| 4532 | if (packets == 0) { |
| 4533 | packets = 1; |
| 4534 | } |
| 4535 | sb.append(" @ "); |
| 4536 | sb.append(BatteryStatsHelper.makemAh(uidMobileActiveTime / 1000 / (double)packets)); |
| 4537 | sb.append(" mspp"); |
| 4538 | pw.println(sb.toString()); |
| 4539 | } |
| 4540 | |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 4541 | if (mobileWakeup > 0) { |
| 4542 | sb.setLength(0); |
| 4543 | sb.append(prefix); |
| 4544 | sb.append(" Mobile radio AP wakeups: "); |
| 4545 | sb.append(mobileWakeup); |
| 4546 | pw.println(sb.toString()); |
| 4547 | } |
| 4548 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 4549 | printControllerActivityIfInteresting(pw, sb, prefix + " ", "Modem", |
| 4550 | u.getModemControllerActivity(), which); |
| 4551 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4552 | if (wifiRxBytes > 0 || wifiTxBytes > 0 || wifiRxPackets > 0 || wifiTxPackets > 0) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 4553 | pw.print(prefix); pw.print(" Wi-Fi network: "); |
| 4554 | pw.print(formatBytesLocked(wifiRxBytes)); pw.print(" received, "); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4555 | pw.print(formatBytesLocked(wifiTxBytes)); |
| 4556 | pw.print(" sent (packets "); pw.print(wifiRxPackets); |
| 4557 | pw.print(" received, "); pw.print(wifiTxPackets); pw.println(" sent)"); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 4558 | } |
| 4559 | |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 4560 | if (fullWifiLockOnTime != 0 || wifiScanTime != 0 || wifiScanCount != 0 |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 4561 | || wifiScanCountBg != 0 || wifiScanActualTime != 0 || wifiScanActualTimeBg != 0 |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4562 | || uidWifiRunningTime != 0) { |
| 4563 | sb.setLength(0); |
| 4564 | sb.append(prefix); sb.append(" Wifi Running: "); |
| 4565 | formatTimeMs(sb, uidWifiRunningTime / 1000); |
| 4566 | sb.append("("); sb.append(formatRatioLocked(uidWifiRunningTime, |
| 4567 | whichBatteryRealtime)); sb.append(")\n"); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame^] | 4568 | sb.append(prefix); sb.append(" Full Wifi Lock: "); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4569 | formatTimeMs(sb, fullWifiLockOnTime / 1000); |
| 4570 | sb.append("("); sb.append(formatRatioLocked(fullWifiLockOnTime, |
| 4571 | whichBatteryRealtime)); sb.append(")\n"); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 4572 | sb.append(prefix); sb.append(" Wifi Scan (blamed): "); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4573 | formatTimeMs(sb, wifiScanTime / 1000); |
| 4574 | sb.append("("); sb.append(formatRatioLocked(wifiScanTime, |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 4575 | whichBatteryRealtime)); sb.append(") "); |
| 4576 | sb.append(wifiScanCount); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 4577 | sb.append("x\n"); |
| 4578 | // actual and background times are unpooled and since reset (regardless of 'which') |
| 4579 | sb.append(prefix); sb.append(" Wifi Scan (actual): "); |
| 4580 | formatTimeMs(sb, wifiScanActualTime / 1000); |
| 4581 | sb.append("("); sb.append(formatRatioLocked(wifiScanActualTime, |
| 4582 | computeBatteryRealtime(rawRealtime, STATS_SINCE_CHARGED))); |
| 4583 | sb.append(") "); |
| 4584 | sb.append(wifiScanCount); |
| 4585 | sb.append("x\n"); |
| 4586 | sb.append(prefix); sb.append(" Background Wifi Scan: "); |
| 4587 | formatTimeMs(sb, wifiScanActualTimeBg / 1000); |
| 4588 | sb.append("("); sb.append(formatRatioLocked(wifiScanActualTimeBg, |
| 4589 | computeBatteryRealtime(rawRealtime, STATS_SINCE_CHARGED))); |
| 4590 | sb.append(") "); |
| 4591 | sb.append(wifiScanCountBg); |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 4592 | sb.append("x"); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4593 | pw.println(sb.toString()); |
| 4594 | } |
| 4595 | |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 4596 | if (wifiWakeup > 0) { |
| 4597 | sb.setLength(0); |
| 4598 | sb.append(prefix); |
| 4599 | sb.append(" WiFi AP wakeups: "); |
| 4600 | sb.append(wifiWakeup); |
| 4601 | pw.println(sb.toString()); |
| 4602 | } |
| 4603 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 4604 | printControllerActivityIfInteresting(pw, sb, prefix + " ", "WiFi", |
| 4605 | u.getWifiControllerActivity(), which); |
Adam Lesinski | 049c88b | 2015-05-28 11:38:12 -0700 | [diff] [blame] | 4606 | |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 4607 | if (btRxBytes > 0 || btTxBytes > 0) { |
| 4608 | pw.print(prefix); pw.print(" Bluetooth network: "); |
| 4609 | pw.print(formatBytesLocked(btRxBytes)); pw.print(" received, "); |
| 4610 | pw.print(formatBytesLocked(btTxBytes)); |
| 4611 | pw.println(" sent"); |
| 4612 | } |
| 4613 | |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 4614 | final Timer bleTimer = u.getBluetoothScanTimer(); |
| 4615 | if (bleTimer != null) { |
| 4616 | // Convert from microseconds to milliseconds with rounding |
| 4617 | final long totalTimeMs = (bleTimer.getTotalTimeLocked(rawRealtime, which) + 500) |
| 4618 | / 1000; |
| 4619 | if (totalTimeMs != 0) { |
| 4620 | final int count = bleTimer.getCountLocked(which); |
| 4621 | final Timer bleTimerBg = u.getBluetoothScanBackgroundTimer(); |
| 4622 | final int countBg = bleTimerBg != null ? bleTimerBg.getCountLocked(which) : 0; |
| 4623 | final long rawRealtimeMs = (rawRealtime + 500) / 1000; |
| 4624 | // 'actualTime' are unpooled and always since reset (regardless of 'which') |
| 4625 | final long actualTimeMs = bleTimer.getTotalDurationMsLocked(rawRealtimeMs); |
| 4626 | final long actualTimeMsBg = bleTimerBg != null ? |
| 4627 | bleTimerBg.getTotalDurationMsLocked(rawRealtimeMs) : 0; |
Bookatz | 956f36bf | 2017-04-28 09:48:17 -0700 | [diff] [blame] | 4628 | final int resultCount = u.getBluetoothScanResultCounter() != null ? |
| 4629 | u.getBluetoothScanResultCounter().getCountLocked(which) : 0; |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 4630 | |
| 4631 | sb.setLength(0); |
| 4632 | sb.append(prefix); |
| 4633 | sb.append(" "); |
| 4634 | sb.append("Bluetooth Scan"); |
| 4635 | sb.append(": "); |
| 4636 | if (actualTimeMs != totalTimeMs) { |
| 4637 | formatTimeMs(sb, totalTimeMs); |
| 4638 | sb.append("blamed realtime, "); |
| 4639 | } |
| 4640 | formatTimeMs(sb, actualTimeMs); // since reset, regardless of 'which' |
| 4641 | sb.append("realtime ("); |
| 4642 | sb.append(count); |
| 4643 | sb.append(" times)"); |
| 4644 | if (bleTimer.isRunningLocked()) { |
| 4645 | sb.append(" (running)"); |
| 4646 | } |
| 4647 | if (actualTimeMsBg != 0 || countBg > 0) { |
| 4648 | sb.append(", "); |
| 4649 | formatTimeMs(sb, actualTimeMsBg); // since reset, regardless of 'which' |
| 4650 | sb.append("background ("); |
| 4651 | sb.append(countBg); |
| 4652 | sb.append(" times)"); |
| 4653 | } |
Bookatz | 956f36bf | 2017-04-28 09:48:17 -0700 | [diff] [blame] | 4654 | sb.append("; Results count "); |
| 4655 | sb.append(resultCount); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 4656 | pw.println(sb.toString()); |
| 4657 | uidActivity = true; |
| 4658 | } |
| 4659 | } |
| 4660 | |
| 4661 | |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 4662 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4663 | if (u.hasUserActivity()) { |
| 4664 | boolean hasData = false; |
Raph Levien | 4c7a4a7 | 2012-08-03 14:32:39 -0700 | [diff] [blame] | 4665 | for (int i=0; i<Uid.NUM_USER_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4666 | final int val = u.getUserActivityCount(i, which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4667 | if (val != 0) { |
| 4668 | if (!hasData) { |
| 4669 | sb.setLength(0); |
| 4670 | sb.append(" User activity: "); |
| 4671 | hasData = true; |
| 4672 | } else { |
| 4673 | sb.append(", "); |
| 4674 | } |
| 4675 | sb.append(val); |
| 4676 | sb.append(" "); |
| 4677 | sb.append(Uid.USER_ACTIVITY_TYPES[i]); |
| 4678 | } |
| 4679 | } |
| 4680 | if (hasData) { |
| 4681 | pw.println(sb.toString()); |
| 4682 | } |
| 4683 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4684 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4685 | final ArrayMap<String, ? extends BatteryStats.Uid.Wakelock> wakelocks |
| 4686 | = u.getWakelockStats(); |
| 4687 | long totalFullWakelock = 0, totalPartialWakelock = 0, totalWindowWakelock = 0; |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 4688 | long totalDrawWakelock = 0; |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4689 | int countWakelock = 0; |
| 4690 | for (int iw=wakelocks.size()-1; iw>=0; iw--) { |
| 4691 | final Uid.Wakelock wl = wakelocks.valueAt(iw); |
| 4692 | String linePrefix = ": "; |
| 4693 | sb.setLength(0); |
| 4694 | sb.append(prefix); |
| 4695 | sb.append(" Wake lock "); |
| 4696 | sb.append(wakelocks.keyAt(iw)); |
| 4697 | linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_FULL), rawRealtime, |
| 4698 | "full", which, linePrefix); |
| 4699 | linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_PARTIAL), rawRealtime, |
| 4700 | "partial", which, linePrefix); |
| 4701 | linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_WINDOW), rawRealtime, |
| 4702 | "window", which, linePrefix); |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 4703 | linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_DRAW), rawRealtime, |
| 4704 | "draw", which, linePrefix); |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 4705 | sb.append(" realtime"); |
| 4706 | pw.println(sb.toString()); |
| 4707 | uidActivity = true; |
| 4708 | countWakelock++; |
| 4709 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4710 | totalFullWakelock += computeWakeLock(wl.getWakeTime(WAKE_TYPE_FULL), |
| 4711 | rawRealtime, which); |
| 4712 | totalPartialWakelock += computeWakeLock(wl.getWakeTime(WAKE_TYPE_PARTIAL), |
| 4713 | rawRealtime, which); |
| 4714 | totalWindowWakelock += computeWakeLock(wl.getWakeTime(WAKE_TYPE_WINDOW), |
| 4715 | rawRealtime, which); |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 4716 | totalDrawWakelock += computeWakeLock(wl.getWakeTime(WAKE_TYPE_DRAW), |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 4717 | rawRealtime, which); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 4718 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4719 | if (countWakelock > 1) { |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame^] | 4720 | // get unpooled partial wakelock quantities (unlike totalPartialWakelock, which is |
| 4721 | // pooled and therefore just a lower bound) |
| 4722 | long actualTotalPartialWakelock = 0; |
| 4723 | long actualBgPartialWakelock = 0; |
| 4724 | if (u.getAggregatedPartialWakelockTimer() != null) { |
| 4725 | final Timer aggTimer = u.getAggregatedPartialWakelockTimer(); |
| 4726 | // Convert from microseconds to milliseconds with rounding |
| 4727 | actualTotalPartialWakelock = |
| 4728 | (aggTimer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000; |
| 4729 | final Timer bgAggTimer = aggTimer.getSubTimer(); |
| 4730 | actualBgPartialWakelock = bgAggTimer != null ? |
| 4731 | (bgAggTimer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000 : 0; |
| 4732 | } |
| 4733 | |
| 4734 | if (actualTotalPartialWakelock != 0 || actualBgPartialWakelock != 0 || |
| 4735 | totalFullWakelock != 0 || totalPartialWakelock != 0 || |
| 4736 | totalWindowWakelock != 0) { |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 4737 | sb.setLength(0); |
| 4738 | sb.append(prefix); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4739 | sb.append(" TOTAL wake: "); |
| 4740 | boolean needComma = false; |
| 4741 | if (totalFullWakelock != 0) { |
| 4742 | needComma = true; |
| 4743 | formatTimeMs(sb, totalFullWakelock); |
| 4744 | sb.append("full"); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 4745 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4746 | if (totalPartialWakelock != 0) { |
| 4747 | if (needComma) { |
| 4748 | sb.append(", "); |
| 4749 | } |
| 4750 | needComma = true; |
| 4751 | formatTimeMs(sb, totalPartialWakelock); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame^] | 4752 | sb.append("blamed partial"); |
| 4753 | } |
| 4754 | if (actualTotalPartialWakelock != 0) { |
| 4755 | if (needComma) { |
| 4756 | sb.append(", "); |
| 4757 | } |
| 4758 | needComma = true; |
| 4759 | formatTimeMs(sb, actualTotalPartialWakelock); |
| 4760 | sb.append("actual partial"); |
| 4761 | } |
| 4762 | if (actualBgPartialWakelock != 0) { |
| 4763 | if (needComma) { |
| 4764 | sb.append(", "); |
| 4765 | } |
| 4766 | needComma = true; |
| 4767 | formatTimeMs(sb, actualBgPartialWakelock); |
| 4768 | sb.append("actual background partial"); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4769 | } |
| 4770 | if (totalWindowWakelock != 0) { |
| 4771 | if (needComma) { |
| 4772 | sb.append(", "); |
| 4773 | } |
| 4774 | needComma = true; |
| 4775 | formatTimeMs(sb, totalWindowWakelock); |
| 4776 | sb.append("window"); |
| 4777 | } |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 4778 | if (totalDrawWakelock != 0) { |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 4779 | if (needComma) { |
| 4780 | sb.append(","); |
| 4781 | } |
| 4782 | needComma = true; |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 4783 | formatTimeMs(sb, totalDrawWakelock); |
| 4784 | sb.append("draw"); |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 4785 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4786 | sb.append(" realtime"); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 4787 | pw.println(sb.toString()); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 4788 | } |
| 4789 | } |
| 4790 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4791 | final ArrayMap<String, ? extends Timer> syncs = u.getSyncStats(); |
| 4792 | for (int isy=syncs.size()-1; isy>=0; isy--) { |
| 4793 | final Timer timer = syncs.valueAt(isy); |
| 4794 | // Convert from microseconds to milliseconds with rounding |
| 4795 | final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000; |
| 4796 | final int count = timer.getCountLocked(which); |
Bookatz | 2bffb5b | 2017-04-13 11:59:33 -0700 | [diff] [blame] | 4797 | final Timer bgTimer = timer.getSubTimer(); |
| 4798 | final long bgTime = bgTimer != null ? |
| 4799 | (bgTimer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000 : -1; |
| 4800 | final int bgCount = bgTimer != null ? bgTimer.getCountLocked(which) : -1; |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4801 | sb.setLength(0); |
| 4802 | sb.append(prefix); |
| 4803 | sb.append(" Sync "); |
| 4804 | sb.append(syncs.keyAt(isy)); |
| 4805 | sb.append(": "); |
| 4806 | if (totalTime != 0) { |
| 4807 | formatTimeMs(sb, totalTime); |
| 4808 | sb.append("realtime ("); |
| 4809 | sb.append(count); |
| 4810 | sb.append(" times)"); |
Bookatz | 2bffb5b | 2017-04-13 11:59:33 -0700 | [diff] [blame] | 4811 | if (bgTime > 0) { |
| 4812 | sb.append(", "); |
| 4813 | formatTimeMs(sb, bgTime); |
| 4814 | sb.append("background ("); |
| 4815 | sb.append(bgCount); |
| 4816 | sb.append(" times)"); |
| 4817 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4818 | } else { |
| 4819 | sb.append("(not used)"); |
| 4820 | } |
| 4821 | pw.println(sb.toString()); |
| 4822 | uidActivity = true; |
| 4823 | } |
| 4824 | |
| 4825 | final ArrayMap<String, ? extends Timer> jobs = u.getJobStats(); |
| 4826 | for (int ij=jobs.size()-1; ij>=0; ij--) { |
| 4827 | final Timer timer = jobs.valueAt(ij); |
| 4828 | // Convert from microseconds to milliseconds with rounding |
| 4829 | final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000; |
| 4830 | final int count = timer.getCountLocked(which); |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 4831 | final Timer bgTimer = timer.getSubTimer(); |
| 4832 | final long bgTime = bgTimer != null ? |
| 4833 | (bgTimer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000 : -1; |
| 4834 | final int bgCount = bgTimer != null ? bgTimer.getCountLocked(which) : -1; |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4835 | sb.setLength(0); |
| 4836 | sb.append(prefix); |
| 4837 | sb.append(" Job "); |
| 4838 | sb.append(jobs.keyAt(ij)); |
| 4839 | sb.append(": "); |
| 4840 | if (totalTime != 0) { |
| 4841 | formatTimeMs(sb, totalTime); |
| 4842 | sb.append("realtime ("); |
| 4843 | sb.append(count); |
| 4844 | sb.append(" times)"); |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 4845 | if (bgTime > 0) { |
| 4846 | sb.append(", "); |
| 4847 | formatTimeMs(sb, bgTime); |
| 4848 | sb.append("background ("); |
| 4849 | sb.append(bgCount); |
| 4850 | sb.append(" times)"); |
| 4851 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4852 | } else { |
| 4853 | sb.append("(not used)"); |
| 4854 | } |
| 4855 | pw.println(sb.toString()); |
| 4856 | uidActivity = true; |
| 4857 | } |
| 4858 | |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 4859 | uidActivity |= printTimer(pw, sb, u.getFlashlightTurnedOnTimer(), rawRealtime, which, |
| 4860 | prefix, "Flashlight"); |
| 4861 | uidActivity |= printTimer(pw, sb, u.getCameraTurnedOnTimer(), rawRealtime, which, |
| 4862 | prefix, "Camera"); |
| 4863 | uidActivity |= printTimer(pw, sb, u.getVideoTurnedOnTimer(), rawRealtime, which, |
| 4864 | prefix, "Video"); |
| 4865 | uidActivity |= printTimer(pw, sb, u.getAudioTurnedOnTimer(), rawRealtime, which, |
| 4866 | prefix, "Audio"); |
| 4867 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4868 | final SparseArray<? extends BatteryStats.Uid.Sensor> sensors = u.getSensorStats(); |
| 4869 | final int NSE = sensors.size(); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 4870 | for (int ise=0; ise<NSE; ise++) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4871 | final Uid.Sensor se = sensors.valueAt(ise); |
| 4872 | final int sensorNumber = sensors.keyAt(ise); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 4873 | sb.setLength(0); |
| 4874 | sb.append(prefix); |
| 4875 | sb.append(" Sensor "); |
| 4876 | int handle = se.getHandle(); |
| 4877 | if (handle == Uid.Sensor.GPS) { |
| 4878 | sb.append("GPS"); |
| 4879 | } else { |
| 4880 | sb.append(handle); |
| 4881 | } |
| 4882 | sb.append(": "); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4883 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4884 | final Timer timer = se.getSensorTime(); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 4885 | if (timer != null) { |
| 4886 | // Convert from microseconds to milliseconds with rounding |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 4887 | final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) |
| 4888 | / 1000; |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4889 | final int count = timer.getCountLocked(which); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 4890 | final Timer bgTimer = se.getSensorBackgroundTime(); |
| 4891 | final int bgCount = bgTimer != null ? bgTimer.getCountLocked(which) : 0; |
| 4892 | final long rawRealtimeMs = (rawRealtime + 500) / 1000; |
| 4893 | // 'actualTime' are unpooled and always since reset (regardless of 'which') |
| 4894 | final long actualTime = timer.getTotalDurationMsLocked(rawRealtimeMs); |
| 4895 | final long bgActualTime = bgTimer != null ? |
| 4896 | bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : 0; |
| 4897 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 4898 | //timer.logState(); |
| 4899 | if (totalTime != 0) { |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 4900 | if (actualTime != totalTime) { |
| 4901 | formatTimeMs(sb, totalTime); |
| 4902 | sb.append("blamed realtime, "); |
| 4903 | } |
| 4904 | |
| 4905 | formatTimeMs(sb, actualTime); // since reset, regardless of 'which' |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 4906 | sb.append("realtime ("); |
| 4907 | sb.append(count); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 4908 | sb.append(" times)"); |
| 4909 | |
| 4910 | if (bgActualTime != 0 || bgCount > 0) { |
Amith Yamasani | ab9ad19 | 2016-12-06 12:46:59 -0800 | [diff] [blame] | 4911 | sb.append(", "); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 4912 | formatTimeMs(sb, bgActualTime); // since reset, regardless of 'which' |
| 4913 | sb.append("background ("); |
Amith Yamasani | ab9ad19 | 2016-12-06 12:46:59 -0800 | [diff] [blame] | 4914 | sb.append(bgCount); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 4915 | sb.append(" times)"); |
Amith Yamasani | ab9ad19 | 2016-12-06 12:46:59 -0800 | [diff] [blame] | 4916 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4917 | } else { |
| 4918 | sb.append("(not used)"); |
| 4919 | } |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 4920 | } else { |
| 4921 | sb.append("(not used)"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4922 | } |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 4923 | |
| 4924 | pw.println(sb.toString()); |
| 4925 | uidActivity = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4926 | } |
| 4927 | |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 4928 | uidActivity |= printTimer(pw, sb, u.getVibratorOnTimer(), rawRealtime, which, prefix, |
| 4929 | "Vibrator"); |
| 4930 | uidActivity |= printTimer(pw, sb, u.getForegroundActivityTimer(), rawRealtime, which, |
| 4931 | prefix, "Foreground activities"); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 4932 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 4933 | long totalStateTime = 0; |
| 4934 | for (int ips=0; ips<Uid.NUM_PROCESS_STATE; ips++) { |
| 4935 | long time = u.getProcessStateTime(ips, rawRealtime, which); |
| 4936 | if (time > 0) { |
| 4937 | totalStateTime += time; |
| 4938 | sb.setLength(0); |
| 4939 | sb.append(prefix); |
| 4940 | sb.append(" "); |
| 4941 | sb.append(Uid.PROCESS_STATE_NAMES[ips]); |
| 4942 | sb.append(" for: "); |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 4943 | formatTimeMs(sb, (time + 500) / 1000); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 4944 | pw.println(sb.toString()); |
| 4945 | uidActivity = true; |
| 4946 | } |
| 4947 | } |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 4948 | if (totalStateTime > 0) { |
| 4949 | sb.setLength(0); |
| 4950 | sb.append(prefix); |
| 4951 | sb.append(" Total running: "); |
| 4952 | formatTimeMs(sb, (totalStateTime + 500) / 1000); |
| 4953 | pw.println(sb.toString()); |
| 4954 | } |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 4955 | |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 4956 | final long userCpuTimeUs = u.getUserCpuTimeUs(which); |
| 4957 | final long systemCpuTimeUs = u.getSystemCpuTimeUs(which); |
Adam Lesinski | d4abd1e | 2017-04-12 11:29:13 -0700 | [diff] [blame] | 4958 | if (userCpuTimeUs > 0 || systemCpuTimeUs > 0) { |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 4959 | sb.setLength(0); |
| 4960 | sb.append(prefix); |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 4961 | sb.append(" Total cpu time: u="); |
| 4962 | formatTimeMs(sb, userCpuTimeUs / 1000); |
| 4963 | sb.append("s="); |
| 4964 | formatTimeMs(sb, systemCpuTimeUs / 1000); |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 4965 | pw.println(sb.toString()); |
| 4966 | } |
| 4967 | |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 4968 | final long[] cpuFreqTimes = u.getCpuFreqTimes(which); |
| 4969 | if (cpuFreqTimes != null) { |
| 4970 | sb.setLength(0); |
| 4971 | sb.append(" Total cpu time per freq:"); |
| 4972 | for (int i = 0; i < cpuFreqTimes.length; ++i) { |
| 4973 | sb.append(" " + cpuFreqTimes[i]); |
| 4974 | } |
| 4975 | pw.println(sb.toString()); |
| 4976 | } |
| 4977 | final long[] screenOffCpuFreqTimes = u.getScreenOffCpuFreqTimes(which); |
| 4978 | if (screenOffCpuFreqTimes != null) { |
| 4979 | sb.setLength(0); |
| 4980 | sb.append(" Total screen-off cpu time per freq:"); |
| 4981 | for (int i = 0; i < screenOffCpuFreqTimes.length; ++i) { |
| 4982 | sb.append(" " + screenOffCpuFreqTimes[i]); |
| 4983 | } |
| 4984 | pw.println(sb.toString()); |
| 4985 | } |
| 4986 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4987 | final ArrayMap<String, ? extends BatteryStats.Uid.Proc> processStats |
| 4988 | = u.getProcessStats(); |
| 4989 | for (int ipr=processStats.size()-1; ipr>=0; ipr--) { |
| 4990 | final Uid.Proc ps = processStats.valueAt(ipr); |
| 4991 | long userTime; |
| 4992 | long systemTime; |
| 4993 | long foregroundTime; |
| 4994 | int starts; |
| 4995 | int numExcessive; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4996 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4997 | userTime = ps.getUserTime(which); |
| 4998 | systemTime = ps.getSystemTime(which); |
| 4999 | foregroundTime = ps.getForegroundTime(which); |
| 5000 | starts = ps.getStarts(which); |
| 5001 | final int numCrashes = ps.getNumCrashes(which); |
| 5002 | final int numAnrs = ps.getNumAnrs(which); |
| 5003 | numExcessive = which == STATS_SINCE_CHARGED |
| 5004 | ? ps.countExcessivePowers() : 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5005 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5006 | if (userTime != 0 || systemTime != 0 || foregroundTime != 0 || starts != 0 |
| 5007 | || numExcessive != 0 || numCrashes != 0 || numAnrs != 0) { |
| 5008 | sb.setLength(0); |
| 5009 | sb.append(prefix); sb.append(" Proc "); |
| 5010 | sb.append(processStats.keyAt(ipr)); sb.append(":\n"); |
| 5011 | sb.append(prefix); sb.append(" CPU: "); |
| 5012 | formatTimeMs(sb, userTime); sb.append("usr + "); |
| 5013 | formatTimeMs(sb, systemTime); sb.append("krn ; "); |
| 5014 | formatTimeMs(sb, foregroundTime); sb.append("fg"); |
| 5015 | if (starts != 0 || numCrashes != 0 || numAnrs != 0) { |
| 5016 | sb.append("\n"); sb.append(prefix); sb.append(" "); |
| 5017 | boolean hasOne = false; |
| 5018 | if (starts != 0) { |
| 5019 | hasOne = true; |
| 5020 | sb.append(starts); sb.append(" starts"); |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 5021 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5022 | if (numCrashes != 0) { |
| 5023 | if (hasOne) { |
| 5024 | sb.append(", "); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 5025 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5026 | hasOne = true; |
| 5027 | sb.append(numCrashes); sb.append(" crashes"); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 5028 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5029 | if (numAnrs != 0) { |
| 5030 | if (hasOne) { |
| 5031 | sb.append(", "); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5032 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5033 | sb.append(numAnrs); sb.append(" anrs"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5034 | } |
| 5035 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5036 | pw.println(sb.toString()); |
| 5037 | for (int e=0; e<numExcessive; e++) { |
| 5038 | Uid.Proc.ExcessivePower ew = ps.getExcessivePower(e); |
| 5039 | if (ew != null) { |
| 5040 | pw.print(prefix); pw.print(" * Killed for "); |
| 5041 | if (ew.type == Uid.Proc.ExcessivePower.TYPE_WAKE) { |
| 5042 | pw.print("wake lock"); |
| 5043 | } else if (ew.type == Uid.Proc.ExcessivePower.TYPE_CPU) { |
| 5044 | pw.print("cpu"); |
| 5045 | } else { |
| 5046 | pw.print("unknown"); |
| 5047 | } |
| 5048 | pw.print(" use: "); |
| 5049 | TimeUtils.formatDuration(ew.usedTime, pw); |
| 5050 | pw.print(" over "); |
| 5051 | TimeUtils.formatDuration(ew.overTime, pw); |
| 5052 | if (ew.overTime != 0) { |
| 5053 | pw.print(" ("); |
| 5054 | pw.print((ew.usedTime*100)/ew.overTime); |
| 5055 | pw.println("%)"); |
| 5056 | } |
| 5057 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5058 | } |
| 5059 | uidActivity = true; |
| 5060 | } |
| 5061 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5062 | |
| 5063 | final ArrayMap<String, ? extends BatteryStats.Uid.Pkg> packageStats |
| 5064 | = u.getPackageStats(); |
| 5065 | for (int ipkg=packageStats.size()-1; ipkg>=0; ipkg--) { |
| 5066 | pw.print(prefix); pw.print(" Apk "); pw.print(packageStats.keyAt(ipkg)); |
| 5067 | pw.println(":"); |
| 5068 | boolean apkActivity = false; |
| 5069 | final Uid.Pkg ps = packageStats.valueAt(ipkg); |
| 5070 | final ArrayMap<String, ? extends Counter> alarms = ps.getWakeupAlarmStats(); |
| 5071 | for (int iwa=alarms.size()-1; iwa>=0; iwa--) { |
| 5072 | pw.print(prefix); pw.print(" Wakeup alarm "); |
| 5073 | pw.print(alarms.keyAt(iwa)); pw.print(": "); |
| 5074 | pw.print(alarms.valueAt(iwa).getCountLocked(which)); |
| 5075 | pw.println(" times"); |
| 5076 | apkActivity = true; |
| 5077 | } |
| 5078 | final ArrayMap<String, ? extends Uid.Pkg.Serv> serviceStats = ps.getServiceStats(); |
| 5079 | for (int isvc=serviceStats.size()-1; isvc>=0; isvc--) { |
| 5080 | final BatteryStats.Uid.Pkg.Serv ss = serviceStats.valueAt(isvc); |
| 5081 | final long startTime = ss.getStartTime(batteryUptime, which); |
| 5082 | final int starts = ss.getStarts(which); |
| 5083 | final int launches = ss.getLaunches(which); |
| 5084 | if (startTime != 0 || starts != 0 || launches != 0) { |
| 5085 | sb.setLength(0); |
| 5086 | sb.append(prefix); sb.append(" Service "); |
| 5087 | sb.append(serviceStats.keyAt(isvc)); sb.append(":\n"); |
| 5088 | sb.append(prefix); sb.append(" Created for: "); |
| 5089 | formatTimeMs(sb, startTime / 1000); |
| 5090 | sb.append("uptime\n"); |
| 5091 | sb.append(prefix); sb.append(" Starts: "); |
| 5092 | sb.append(starts); |
| 5093 | sb.append(", launches: "); sb.append(launches); |
| 5094 | pw.println(sb.toString()); |
| 5095 | apkActivity = true; |
| 5096 | } |
| 5097 | } |
| 5098 | if (!apkActivity) { |
| 5099 | pw.print(prefix); pw.println(" (nothing executed)"); |
| 5100 | } |
| 5101 | uidActivity = true; |
| 5102 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5103 | if (!uidActivity) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 5104 | pw.print(prefix); pw.println(" (nothing executed)"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5105 | } |
| 5106 | } |
| 5107 | } |
| 5108 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 5109 | static void printBitDescriptions(PrintWriter pw, int oldval, int newval, HistoryTag wakelockTag, |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5110 | BitDescription[] descriptions, boolean longNames) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5111 | int diff = oldval ^ newval; |
| 5112 | if (diff == 0) return; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 5113 | boolean didWake = false; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5114 | for (int i=0; i<descriptions.length; i++) { |
| 5115 | BitDescription bd = descriptions[i]; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 5116 | if ((diff&bd.mask) != 0) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5117 | pw.print(longNames ? " " : ","); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5118 | if (bd.shift < 0) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 5119 | pw.print((newval&bd.mask) != 0 ? "+" : "-"); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5120 | pw.print(longNames ? bd.name : bd.shortName); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 5121 | if (bd.mask == HistoryItem.STATE_WAKE_LOCK_FLAG && wakelockTag != null) { |
| 5122 | didWake = true; |
| 5123 | pw.print("="); |
| 5124 | if (longNames) { |
| 5125 | UserHandle.formatUid(pw, wakelockTag.uid); |
| 5126 | pw.print(":\""); |
| 5127 | pw.print(wakelockTag.string); |
| 5128 | pw.print("\""); |
| 5129 | } else { |
| 5130 | pw.print(wakelockTag.poolIdx); |
| 5131 | } |
| 5132 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5133 | } else { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5134 | pw.print(longNames ? bd.name : bd.shortName); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5135 | pw.print("="); |
| 5136 | int val = (newval&bd.mask)>>bd.shift; |
| 5137 | if (bd.values != null && val >= 0 && val < bd.values.length) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5138 | pw.print(longNames? bd.values[val] : bd.shortValues[val]); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5139 | } else { |
| 5140 | pw.print(val); |
| 5141 | } |
| 5142 | } |
| 5143 | } |
| 5144 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 5145 | if (!didWake && wakelockTag != null) { |
Ashish Sharma | 81850c4 | 2014-05-05 13:57:07 -0700 | [diff] [blame] | 5146 | pw.print(longNames ? " wake_lock=" : ",w="); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 5147 | if (longNames) { |
| 5148 | UserHandle.formatUid(pw, wakelockTag.uid); |
| 5149 | pw.print(":\""); |
| 5150 | pw.print(wakelockTag.string); |
| 5151 | pw.print("\""); |
| 5152 | } else { |
| 5153 | pw.print(wakelockTag.poolIdx); |
| 5154 | } |
| 5155 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5156 | } |
| 5157 | |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5158 | public void prepareForDumpLocked() { |
| 5159 | } |
| 5160 | |
| 5161 | public static class HistoryPrinter { |
| 5162 | int oldState = 0; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 5163 | int oldState2 = 0; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5164 | int oldLevel = -1; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5165 | int oldStatus = -1; |
| 5166 | int oldHealth = -1; |
| 5167 | int oldPlug = -1; |
| 5168 | int oldTemp = -1; |
| 5169 | int oldVolt = -1; |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 5170 | int oldChargeMAh = -1; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5171 | long lastTime = -1; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5172 | |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 5173 | void reset() { |
| 5174 | oldState = oldState2 = 0; |
| 5175 | oldLevel = -1; |
| 5176 | oldStatus = -1; |
| 5177 | oldHealth = -1; |
| 5178 | oldPlug = -1; |
| 5179 | oldTemp = -1; |
| 5180 | oldVolt = -1; |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 5181 | oldChargeMAh = -1; |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 5182 | } |
| 5183 | |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 5184 | public void printNextItem(PrintWriter pw, HistoryItem rec, long baseTime, boolean checkin, |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 5185 | boolean verbose) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5186 | if (!checkin) { |
| 5187 | pw.print(" "); |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 5188 | TimeUtils.formatDuration(rec.time - baseTime, pw, TimeUtils.HUNDRED_DAY_FIELD_LEN); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 5189 | pw.print(" ("); |
| 5190 | pw.print(rec.numReadInts); |
| 5191 | pw.print(") "); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5192 | } else { |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 5193 | pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(','); |
| 5194 | pw.print(HISTORY_DATA); pw.print(','); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5195 | if (lastTime < 0) { |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 5196 | pw.print(rec.time - baseTime); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5197 | } else { |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 5198 | pw.print(rec.time - lastTime); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5199 | } |
| 5200 | lastTime = rec.time; |
| 5201 | } |
| 5202 | if (rec.cmd == HistoryItem.CMD_START) { |
| 5203 | if (checkin) { |
| 5204 | pw.print(":"); |
| 5205 | } |
| 5206 | pw.println("START"); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 5207 | reset(); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 5208 | } else if (rec.cmd == HistoryItem.CMD_CURRENT_TIME |
| 5209 | || rec.cmd == HistoryItem.CMD_RESET) { |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 5210 | if (checkin) { |
| 5211 | pw.print(":"); |
| 5212 | } |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 5213 | if (rec.cmd == HistoryItem.CMD_RESET) { |
| 5214 | pw.print("RESET:"); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 5215 | reset(); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 5216 | } |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 5217 | pw.print("TIME:"); |
| 5218 | if (checkin) { |
| 5219 | pw.println(rec.currentTime); |
| 5220 | } else { |
| 5221 | pw.print(" "); |
| 5222 | pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss", |
| 5223 | rec.currentTime).toString()); |
| 5224 | } |
Dianne Hackborn | 29cd7f1 | 2015-01-08 10:37:05 -0800 | [diff] [blame] | 5225 | } else if (rec.cmd == HistoryItem.CMD_SHUTDOWN) { |
| 5226 | if (checkin) { |
| 5227 | pw.print(":"); |
| 5228 | } |
| 5229 | pw.println("SHUTDOWN"); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5230 | } else if (rec.cmd == HistoryItem.CMD_OVERFLOW) { |
| 5231 | if (checkin) { |
| 5232 | pw.print(":"); |
| 5233 | } |
| 5234 | pw.println("*OVERFLOW*"); |
| 5235 | } else { |
| 5236 | if (!checkin) { |
| 5237 | if (rec.batteryLevel < 10) pw.print("00"); |
| 5238 | else if (rec.batteryLevel < 100) pw.print("0"); |
| 5239 | pw.print(rec.batteryLevel); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 5240 | if (verbose) { |
| 5241 | pw.print(" "); |
| 5242 | if (rec.states < 0) ; |
| 5243 | else if (rec.states < 0x10) pw.print("0000000"); |
| 5244 | else if (rec.states < 0x100) pw.print("000000"); |
| 5245 | else if (rec.states < 0x1000) pw.print("00000"); |
| 5246 | else if (rec.states < 0x10000) pw.print("0000"); |
| 5247 | else if (rec.states < 0x100000) pw.print("000"); |
| 5248 | else if (rec.states < 0x1000000) pw.print("00"); |
| 5249 | else if (rec.states < 0x10000000) pw.print("0"); |
| 5250 | pw.print(Integer.toHexString(rec.states)); |
| 5251 | } |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5252 | } else { |
| 5253 | if (oldLevel != rec.batteryLevel) { |
| 5254 | oldLevel = rec.batteryLevel; |
| 5255 | pw.print(",Bl="); pw.print(rec.batteryLevel); |
| 5256 | } |
| 5257 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5258 | if (oldStatus != rec.batteryStatus) { |
| 5259 | oldStatus = rec.batteryStatus; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5260 | pw.print(checkin ? ",Bs=" : " status="); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5261 | switch (oldStatus) { |
| 5262 | case BatteryManager.BATTERY_STATUS_UNKNOWN: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5263 | pw.print(checkin ? "?" : "unknown"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5264 | break; |
| 5265 | case BatteryManager.BATTERY_STATUS_CHARGING: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5266 | pw.print(checkin ? "c" : "charging"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5267 | break; |
| 5268 | case BatteryManager.BATTERY_STATUS_DISCHARGING: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5269 | pw.print(checkin ? "d" : "discharging"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5270 | break; |
| 5271 | case BatteryManager.BATTERY_STATUS_NOT_CHARGING: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5272 | pw.print(checkin ? "n" : "not-charging"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5273 | break; |
| 5274 | case BatteryManager.BATTERY_STATUS_FULL: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5275 | pw.print(checkin ? "f" : "full"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5276 | break; |
| 5277 | default: |
| 5278 | pw.print(oldStatus); |
| 5279 | break; |
| 5280 | } |
| 5281 | } |
| 5282 | if (oldHealth != rec.batteryHealth) { |
| 5283 | oldHealth = rec.batteryHealth; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5284 | pw.print(checkin ? ",Bh=" : " health="); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5285 | switch (oldHealth) { |
| 5286 | case BatteryManager.BATTERY_HEALTH_UNKNOWN: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5287 | pw.print(checkin ? "?" : "unknown"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5288 | break; |
| 5289 | case BatteryManager.BATTERY_HEALTH_GOOD: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5290 | pw.print(checkin ? "g" : "good"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5291 | break; |
| 5292 | case BatteryManager.BATTERY_HEALTH_OVERHEAT: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5293 | pw.print(checkin ? "h" : "overheat"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5294 | break; |
| 5295 | case BatteryManager.BATTERY_HEALTH_DEAD: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5296 | pw.print(checkin ? "d" : "dead"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5297 | break; |
| 5298 | case BatteryManager.BATTERY_HEALTH_OVER_VOLTAGE: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5299 | pw.print(checkin ? "v" : "over-voltage"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5300 | break; |
| 5301 | case BatteryManager.BATTERY_HEALTH_UNSPECIFIED_FAILURE: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5302 | pw.print(checkin ? "f" : "failure"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5303 | break; |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 5304 | case BatteryManager.BATTERY_HEALTH_COLD: |
| 5305 | pw.print(checkin ? "c" : "cold"); |
| 5306 | break; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5307 | default: |
| 5308 | pw.print(oldHealth); |
| 5309 | break; |
| 5310 | } |
| 5311 | } |
| 5312 | if (oldPlug != rec.batteryPlugType) { |
| 5313 | oldPlug = rec.batteryPlugType; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5314 | pw.print(checkin ? ",Bp=" : " plug="); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5315 | switch (oldPlug) { |
| 5316 | case 0: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5317 | pw.print(checkin ? "n" : "none"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5318 | break; |
| 5319 | case BatteryManager.BATTERY_PLUGGED_AC: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5320 | pw.print(checkin ? "a" : "ac"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5321 | break; |
| 5322 | case BatteryManager.BATTERY_PLUGGED_USB: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5323 | pw.print(checkin ? "u" : "usb"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5324 | break; |
Brian Muramatsu | 37a37f4 | 2012-08-14 15:21:02 -0700 | [diff] [blame] | 5325 | case BatteryManager.BATTERY_PLUGGED_WIRELESS: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5326 | pw.print(checkin ? "w" : "wireless"); |
Brian Muramatsu | 37a37f4 | 2012-08-14 15:21:02 -0700 | [diff] [blame] | 5327 | break; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5328 | default: |
| 5329 | pw.print(oldPlug); |
| 5330 | break; |
| 5331 | } |
| 5332 | } |
| 5333 | if (oldTemp != rec.batteryTemperature) { |
| 5334 | oldTemp = rec.batteryTemperature; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5335 | pw.print(checkin ? ",Bt=" : " temp="); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5336 | pw.print(oldTemp); |
| 5337 | } |
| 5338 | if (oldVolt != rec.batteryVoltage) { |
| 5339 | oldVolt = rec.batteryVoltage; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5340 | pw.print(checkin ? ",Bv=" : " volt="); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5341 | pw.print(oldVolt); |
| 5342 | } |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 5343 | final int chargeMAh = rec.batteryChargeUAh / 1000; |
| 5344 | if (oldChargeMAh != chargeMAh) { |
| 5345 | oldChargeMAh = chargeMAh; |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 5346 | pw.print(checkin ? ",Bcc=" : " charge="); |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 5347 | pw.print(oldChargeMAh); |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 5348 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 5349 | printBitDescriptions(pw, oldState, rec.states, rec.wakelockTag, |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5350 | HISTORY_STATE_DESCRIPTIONS, !checkin); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 5351 | printBitDescriptions(pw, oldState2, rec.states2, null, |
| 5352 | HISTORY_STATE2_DESCRIPTIONS, !checkin); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 5353 | if (rec.wakeReasonTag != null) { |
| 5354 | if (checkin) { |
Dianne Hackborn | d06dcfd | 2014-05-02 13:49:30 -0700 | [diff] [blame] | 5355 | pw.print(",wr="); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 5356 | pw.print(rec.wakeReasonTag.poolIdx); |
| 5357 | } else { |
| 5358 | pw.print(" wake_reason="); |
| 5359 | pw.print(rec.wakeReasonTag.uid); |
| 5360 | pw.print(":\""); |
| 5361 | pw.print(rec.wakeReasonTag.string); |
| 5362 | pw.print("\""); |
| 5363 | } |
| 5364 | } |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 5365 | if (rec.eventCode != HistoryItem.EVENT_NONE) { |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 5366 | pw.print(checkin ? "," : " "); |
| 5367 | if ((rec.eventCode&HistoryItem.EVENT_FLAG_START) != 0) { |
| 5368 | pw.print("+"); |
| 5369 | } else if ((rec.eventCode&HistoryItem.EVENT_FLAG_FINISH) != 0) { |
| 5370 | pw.print("-"); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 5371 | } |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 5372 | String[] eventNames = checkin ? HISTORY_EVENT_CHECKIN_NAMES |
| 5373 | : HISTORY_EVENT_NAMES; |
| 5374 | int idx = rec.eventCode & ~(HistoryItem.EVENT_FLAG_START |
| 5375 | | HistoryItem.EVENT_FLAG_FINISH); |
| 5376 | if (idx >= 0 && idx < eventNames.length) { |
| 5377 | pw.print(eventNames[idx]); |
| 5378 | } else { |
| 5379 | pw.print(checkin ? "Ev" : "event"); |
| 5380 | pw.print(idx); |
| 5381 | } |
| 5382 | pw.print("="); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 5383 | if (checkin) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 5384 | pw.print(rec.eventTag.poolIdx); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 5385 | } else { |
Adam Lesinski | 041d917 | 2016-12-12 12:03:56 -0800 | [diff] [blame] | 5386 | pw.append(HISTORY_EVENT_INT_FORMATTERS[idx] |
| 5387 | .applyAsString(rec.eventTag.uid)); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 5388 | pw.print(":\""); |
| 5389 | pw.print(rec.eventTag.string); |
| 5390 | pw.print("\""); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 5391 | } |
| 5392 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5393 | pw.println(); |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 5394 | if (rec.stepDetails != null) { |
| 5395 | if (!checkin) { |
| 5396 | pw.print(" Details: cpu="); |
| 5397 | pw.print(rec.stepDetails.userTime); |
| 5398 | pw.print("u+"); |
| 5399 | pw.print(rec.stepDetails.systemTime); |
| 5400 | pw.print("s"); |
| 5401 | if (rec.stepDetails.appCpuUid1 >= 0) { |
| 5402 | pw.print(" ("); |
| 5403 | printStepCpuUidDetails(pw, rec.stepDetails.appCpuUid1, |
| 5404 | rec.stepDetails.appCpuUTime1, rec.stepDetails.appCpuSTime1); |
| 5405 | if (rec.stepDetails.appCpuUid2 >= 0) { |
| 5406 | pw.print(", "); |
| 5407 | printStepCpuUidDetails(pw, rec.stepDetails.appCpuUid2, |
| 5408 | rec.stepDetails.appCpuUTime2, rec.stepDetails.appCpuSTime2); |
| 5409 | } |
| 5410 | if (rec.stepDetails.appCpuUid3 >= 0) { |
| 5411 | pw.print(", "); |
| 5412 | printStepCpuUidDetails(pw, rec.stepDetails.appCpuUid3, |
| 5413 | rec.stepDetails.appCpuUTime3, rec.stepDetails.appCpuSTime3); |
| 5414 | } |
| 5415 | pw.print(')'); |
| 5416 | } |
| 5417 | pw.println(); |
| 5418 | pw.print(" /proc/stat="); |
| 5419 | pw.print(rec.stepDetails.statUserTime); |
| 5420 | pw.print(" usr, "); |
| 5421 | pw.print(rec.stepDetails.statSystemTime); |
| 5422 | pw.print(" sys, "); |
| 5423 | pw.print(rec.stepDetails.statIOWaitTime); |
| 5424 | pw.print(" io, "); |
| 5425 | pw.print(rec.stepDetails.statIrqTime); |
| 5426 | pw.print(" irq, "); |
| 5427 | pw.print(rec.stepDetails.statSoftIrqTime); |
| 5428 | pw.print(" sirq, "); |
| 5429 | pw.print(rec.stepDetails.statIdlTime); |
| 5430 | pw.print(" idle"); |
| 5431 | int totalRun = rec.stepDetails.statUserTime + rec.stepDetails.statSystemTime |
| 5432 | + rec.stepDetails.statIOWaitTime + rec.stepDetails.statIrqTime |
| 5433 | + rec.stepDetails.statSoftIrqTime; |
| 5434 | int total = totalRun + rec.stepDetails.statIdlTime; |
| 5435 | if (total > 0) { |
| 5436 | pw.print(" ("); |
| 5437 | float perc = ((float)totalRun) / ((float)total) * 100; |
| 5438 | pw.print(String.format("%.1f%%", perc)); |
| 5439 | pw.print(" of "); |
| 5440 | StringBuilder sb = new StringBuilder(64); |
| 5441 | formatTimeMsNoSpace(sb, total*10); |
| 5442 | pw.print(sb); |
| 5443 | pw.print(")"); |
| 5444 | } |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 5445 | pw.print(", PlatformIdleStat "); |
| 5446 | pw.print(rec.stepDetails.statPlatformIdleState); |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 5447 | pw.println(); |
| 5448 | } else { |
| 5449 | pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(','); |
| 5450 | pw.print(HISTORY_DATA); pw.print(",0,Dcpu="); |
| 5451 | pw.print(rec.stepDetails.userTime); |
| 5452 | pw.print(":"); |
| 5453 | pw.print(rec.stepDetails.systemTime); |
| 5454 | if (rec.stepDetails.appCpuUid1 >= 0) { |
| 5455 | printStepCpuUidCheckinDetails(pw, rec.stepDetails.appCpuUid1, |
| 5456 | rec.stepDetails.appCpuUTime1, rec.stepDetails.appCpuSTime1); |
| 5457 | if (rec.stepDetails.appCpuUid2 >= 0) { |
| 5458 | printStepCpuUidCheckinDetails(pw, rec.stepDetails.appCpuUid2, |
| 5459 | rec.stepDetails.appCpuUTime2, rec.stepDetails.appCpuSTime2); |
| 5460 | } |
| 5461 | if (rec.stepDetails.appCpuUid3 >= 0) { |
| 5462 | printStepCpuUidCheckinDetails(pw, rec.stepDetails.appCpuUid3, |
| 5463 | rec.stepDetails.appCpuUTime3, rec.stepDetails.appCpuSTime3); |
| 5464 | } |
| 5465 | } |
| 5466 | pw.println(); |
| 5467 | pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(','); |
| 5468 | pw.print(HISTORY_DATA); pw.print(",0,Dpst="); |
| 5469 | pw.print(rec.stepDetails.statUserTime); |
| 5470 | pw.print(','); |
| 5471 | pw.print(rec.stepDetails.statSystemTime); |
| 5472 | pw.print(','); |
| 5473 | pw.print(rec.stepDetails.statIOWaitTime); |
| 5474 | pw.print(','); |
| 5475 | pw.print(rec.stepDetails.statIrqTime); |
| 5476 | pw.print(','); |
| 5477 | pw.print(rec.stepDetails.statSoftIrqTime); |
| 5478 | pw.print(','); |
| 5479 | pw.print(rec.stepDetails.statIdlTime); |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 5480 | pw.print(','); |
Adam Lesinski | 8568d8f | 2016-07-15 18:13:23 -0700 | [diff] [blame] | 5481 | if (rec.stepDetails.statPlatformIdleState != null) { |
| 5482 | pw.print(rec.stepDetails.statPlatformIdleState); |
| 5483 | } |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 5484 | pw.println(); |
| 5485 | } |
| 5486 | } |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 5487 | oldState = rec.states; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 5488 | oldState2 = rec.states2; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5489 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5490 | } |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 5491 | |
| 5492 | private void printStepCpuUidDetails(PrintWriter pw, int uid, int utime, int stime) { |
| 5493 | UserHandle.formatUid(pw, uid); |
| 5494 | pw.print("="); |
| 5495 | pw.print(utime); |
| 5496 | pw.print("u+"); |
| 5497 | pw.print(stime); |
| 5498 | pw.print("s"); |
| 5499 | } |
| 5500 | |
| 5501 | private void printStepCpuUidCheckinDetails(PrintWriter pw, int uid, int utime, int stime) { |
| 5502 | pw.print('/'); |
| 5503 | pw.print(uid); |
| 5504 | pw.print(":"); |
| 5505 | pw.print(utime); |
| 5506 | pw.print(":"); |
| 5507 | pw.print(stime); |
| 5508 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5509 | } |
| 5510 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 5511 | private void printSizeValue(PrintWriter pw, long size) { |
| 5512 | float result = size; |
| 5513 | String suffix = ""; |
| 5514 | if (result >= 10*1024) { |
| 5515 | suffix = "KB"; |
| 5516 | result = result / 1024; |
| 5517 | } |
| 5518 | if (result >= 10*1024) { |
| 5519 | suffix = "MB"; |
| 5520 | result = result / 1024; |
| 5521 | } |
| 5522 | if (result >= 10*1024) { |
| 5523 | suffix = "GB"; |
| 5524 | result = result / 1024; |
| 5525 | } |
| 5526 | if (result >= 10*1024) { |
| 5527 | suffix = "TB"; |
| 5528 | result = result / 1024; |
| 5529 | } |
| 5530 | if (result >= 10*1024) { |
| 5531 | suffix = "PB"; |
| 5532 | result = result / 1024; |
| 5533 | } |
| 5534 | pw.print((int)result); |
| 5535 | pw.print(suffix); |
| 5536 | } |
| 5537 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 5538 | private static boolean dumpTimeEstimate(PrintWriter pw, String label1, String label2, |
| 5539 | String label3, long estimatedTime) { |
| 5540 | if (estimatedTime < 0) { |
Dianne Hackborn | ad6a99b | 2014-11-18 10:11:10 -0800 | [diff] [blame] | 5541 | return false; |
| 5542 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 5543 | pw.print(label1); |
| 5544 | pw.print(label2); |
| 5545 | pw.print(label3); |
Dianne Hackborn | ad6a99b | 2014-11-18 10:11:10 -0800 | [diff] [blame] | 5546 | StringBuilder sb = new StringBuilder(64); |
| 5547 | formatTimeMs(sb, estimatedTime); |
| 5548 | pw.print(sb); |
| 5549 | pw.println(); |
Dianne Hackborn | ad6a99b | 2014-11-18 10:11:10 -0800 | [diff] [blame] | 5550 | return true; |
| 5551 | } |
| 5552 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 5553 | private static boolean dumpDurationSteps(PrintWriter pw, String prefix, String header, |
| 5554 | LevelStepTracker steps, boolean checkin) { |
| 5555 | if (steps == null) { |
| 5556 | return false; |
| 5557 | } |
| 5558 | int count = steps.mNumStepDurations; |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 5559 | if (count <= 0) { |
| 5560 | return false; |
| 5561 | } |
| 5562 | if (!checkin) { |
| 5563 | pw.println(header); |
| 5564 | } |
Kweku Adams | 030980a | 2015-04-01 16:07:48 -0700 | [diff] [blame] | 5565 | String[] lineArgs = new String[5]; |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 5566 | for (int i=0; i<count; i++) { |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 5567 | long duration = steps.getDurationAt(i); |
| 5568 | int level = steps.getLevelAt(i); |
| 5569 | long initMode = steps.getInitModeAt(i); |
| 5570 | long modMode = steps.getModModeAt(i); |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 5571 | if (checkin) { |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 5572 | lineArgs[0] = Long.toString(duration); |
| 5573 | lineArgs[1] = Integer.toString(level); |
| 5574 | if ((modMode&STEP_LEVEL_MODE_SCREEN_STATE) == 0) { |
| 5575 | switch ((int)(initMode&STEP_LEVEL_MODE_SCREEN_STATE) + 1) { |
| 5576 | case Display.STATE_OFF: lineArgs[2] = "s-"; break; |
| 5577 | case Display.STATE_ON: lineArgs[2] = "s+"; break; |
| 5578 | case Display.STATE_DOZE: lineArgs[2] = "sd"; break; |
| 5579 | case Display.STATE_DOZE_SUSPEND: lineArgs[2] = "sds"; break; |
Kweku Adams | 030980a | 2015-04-01 16:07:48 -0700 | [diff] [blame] | 5580 | default: lineArgs[2] = "?"; break; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 5581 | } |
| 5582 | } else { |
| 5583 | lineArgs[2] = ""; |
| 5584 | } |
| 5585 | if ((modMode&STEP_LEVEL_MODE_POWER_SAVE) == 0) { |
| 5586 | lineArgs[3] = (initMode&STEP_LEVEL_MODE_POWER_SAVE) != 0 ? "p+" : "p-"; |
| 5587 | } else { |
| 5588 | lineArgs[3] = ""; |
| 5589 | } |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 5590 | if ((modMode&STEP_LEVEL_MODE_DEVICE_IDLE) == 0) { |
Kweku Adams | 030980a | 2015-04-01 16:07:48 -0700 | [diff] [blame] | 5591 | lineArgs[4] = (initMode&STEP_LEVEL_MODE_DEVICE_IDLE) != 0 ? "i+" : "i-"; |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 5592 | } else { |
Kweku Adams | 030980a | 2015-04-01 16:07:48 -0700 | [diff] [blame] | 5593 | lineArgs[4] = ""; |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 5594 | } |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 5595 | dumpLine(pw, 0 /* uid */, "i" /* category */, header, (Object[])lineArgs); |
| 5596 | } else { |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 5597 | pw.print(prefix); |
| 5598 | pw.print("#"); pw.print(i); pw.print(": "); |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 5599 | TimeUtils.formatDuration(duration, pw); |
| 5600 | pw.print(" to "); pw.print(level); |
| 5601 | boolean haveModes = false; |
| 5602 | if ((modMode&STEP_LEVEL_MODE_SCREEN_STATE) == 0) { |
| 5603 | pw.print(" ("); |
| 5604 | switch ((int)(initMode&STEP_LEVEL_MODE_SCREEN_STATE) + 1) { |
| 5605 | case Display.STATE_OFF: pw.print("screen-off"); break; |
| 5606 | case Display.STATE_ON: pw.print("screen-on"); break; |
| 5607 | case Display.STATE_DOZE: pw.print("screen-doze"); break; |
| 5608 | case Display.STATE_DOZE_SUSPEND: pw.print("screen-doze-suspend"); break; |
Kweku Adams | 030980a | 2015-04-01 16:07:48 -0700 | [diff] [blame] | 5609 | default: pw.print("screen-?"); break; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 5610 | } |
| 5611 | haveModes = true; |
| 5612 | } |
| 5613 | if ((modMode&STEP_LEVEL_MODE_POWER_SAVE) == 0) { |
| 5614 | pw.print(haveModes ? ", " : " ("); |
| 5615 | pw.print((initMode&STEP_LEVEL_MODE_POWER_SAVE) != 0 |
| 5616 | ? "power-save-on" : "power-save-off"); |
| 5617 | haveModes = true; |
| 5618 | } |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 5619 | if ((modMode&STEP_LEVEL_MODE_DEVICE_IDLE) == 0) { |
| 5620 | pw.print(haveModes ? ", " : " ("); |
| 5621 | pw.print((initMode&STEP_LEVEL_MODE_DEVICE_IDLE) != 0 |
| 5622 | ? "device-idle-on" : "device-idle-off"); |
| 5623 | haveModes = true; |
| 5624 | } |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 5625 | if (haveModes) { |
| 5626 | pw.print(")"); |
| 5627 | } |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 5628 | pw.println(); |
| 5629 | } |
| 5630 | } |
| 5631 | return true; |
| 5632 | } |
| 5633 | |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 5634 | public static final int DUMP_CHARGED_ONLY = 1<<1; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 5635 | public static final int DUMP_DAILY_ONLY = 1<<2; |
| 5636 | public static final int DUMP_HISTORY_ONLY = 1<<3; |
| 5637 | public static final int DUMP_INCLUDE_HISTORY = 1<<4; |
| 5638 | public static final int DUMP_VERBOSE = 1<<5; |
| 5639 | public static final int DUMP_DEVICE_WIFI_ONLY = 1<<6; |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 5640 | |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 5641 | private void dumpHistoryLocked(PrintWriter pw, int flags, long histStart, boolean checkin) { |
| 5642 | final HistoryPrinter hprinter = new HistoryPrinter(); |
| 5643 | final HistoryItem rec = new HistoryItem(); |
| 5644 | long lastTime = -1; |
| 5645 | long baseTime = -1; |
| 5646 | boolean printed = false; |
| 5647 | HistoryEventTracker tracker = null; |
| 5648 | while (getNextHistoryLocked(rec)) { |
| 5649 | lastTime = rec.time; |
| 5650 | if (baseTime < 0) { |
| 5651 | baseTime = lastTime; |
| 5652 | } |
| 5653 | if (rec.time >= histStart) { |
| 5654 | if (histStart >= 0 && !printed) { |
| 5655 | if (rec.cmd == HistoryItem.CMD_CURRENT_TIME |
Ashish Sharma | 6020071 | 2014-05-23 18:22:20 -0700 | [diff] [blame] | 5656 | || rec.cmd == HistoryItem.CMD_RESET |
Dianne Hackborn | 29cd7f1 | 2015-01-08 10:37:05 -0800 | [diff] [blame] | 5657 | || rec.cmd == HistoryItem.CMD_START |
| 5658 | || rec.cmd == HistoryItem.CMD_SHUTDOWN) { |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 5659 | printed = true; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 5660 | hprinter.printNextItem(pw, rec, baseTime, checkin, |
| 5661 | (flags&DUMP_VERBOSE) != 0); |
| 5662 | rec.cmd = HistoryItem.CMD_UPDATE; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 5663 | } else if (rec.currentTime != 0) { |
| 5664 | printed = true; |
| 5665 | byte cmd = rec.cmd; |
| 5666 | rec.cmd = HistoryItem.CMD_CURRENT_TIME; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 5667 | hprinter.printNextItem(pw, rec, baseTime, checkin, |
| 5668 | (flags&DUMP_VERBOSE) != 0); |
| 5669 | rec.cmd = cmd; |
| 5670 | } |
| 5671 | if (tracker != null) { |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 5672 | if (rec.cmd != HistoryItem.CMD_UPDATE) { |
| 5673 | hprinter.printNextItem(pw, rec, baseTime, checkin, |
| 5674 | (flags&DUMP_VERBOSE) != 0); |
| 5675 | rec.cmd = HistoryItem.CMD_UPDATE; |
| 5676 | } |
| 5677 | int oldEventCode = rec.eventCode; |
| 5678 | HistoryTag oldEventTag = rec.eventTag; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 5679 | rec.eventTag = new HistoryTag(); |
| 5680 | for (int i=0; i<HistoryItem.EVENT_COUNT; i++) { |
| 5681 | HashMap<String, SparseIntArray> active |
| 5682 | = tracker.getStateForEvent(i); |
| 5683 | if (active == null) { |
| 5684 | continue; |
| 5685 | } |
| 5686 | for (HashMap.Entry<String, SparseIntArray> ent |
| 5687 | : active.entrySet()) { |
| 5688 | SparseIntArray uids = ent.getValue(); |
| 5689 | for (int j=0; j<uids.size(); j++) { |
| 5690 | rec.eventCode = i; |
| 5691 | rec.eventTag.string = ent.getKey(); |
| 5692 | rec.eventTag.uid = uids.keyAt(j); |
| 5693 | rec.eventTag.poolIdx = uids.valueAt(j); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 5694 | hprinter.printNextItem(pw, rec, baseTime, checkin, |
| 5695 | (flags&DUMP_VERBOSE) != 0); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 5696 | rec.wakeReasonTag = null; |
| 5697 | rec.wakelockTag = null; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 5698 | } |
| 5699 | } |
| 5700 | } |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 5701 | rec.eventCode = oldEventCode; |
| 5702 | rec.eventTag = oldEventTag; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 5703 | tracker = null; |
| 5704 | } |
| 5705 | } |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 5706 | hprinter.printNextItem(pw, rec, baseTime, checkin, |
| 5707 | (flags&DUMP_VERBOSE) != 0); |
Dianne Hackborn | 536456f | 2014-05-23 16:51:05 -0700 | [diff] [blame] | 5708 | } else if (false && rec.eventCode != HistoryItem.EVENT_NONE) { |
| 5709 | // This is an attempt to aggregate the previous state and generate |
| 5710 | //Â fake events to reflect that state at the point where we start |
| 5711 | // 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] | 5712 | if (tracker == null) { |
| 5713 | tracker = new HistoryEventTracker(); |
| 5714 | } |
| 5715 | tracker.updateState(rec.eventCode, rec.eventTag.string, |
| 5716 | rec.eventTag.uid, rec.eventTag.poolIdx); |
| 5717 | } |
| 5718 | } |
| 5719 | if (histStart >= 0) { |
Dianne Hackborn | fc06413 | 2014-06-02 12:42:12 -0700 | [diff] [blame] | 5720 | commitCurrentHistoryBatchLocked(); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 5721 | pw.print(checkin ? "NEXT: " : " NEXT: "); pw.println(lastTime+1); |
| 5722 | } |
| 5723 | } |
| 5724 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 5725 | private void dumpDailyLevelStepSummary(PrintWriter pw, String prefix, String label, |
| 5726 | LevelStepTracker steps, StringBuilder tmpSb, int[] tmpOutInt) { |
| 5727 | if (steps == null) { |
| 5728 | return; |
| 5729 | } |
| 5730 | long timeRemaining = steps.computeTimeEstimate(0, 0, tmpOutInt); |
| 5731 | if (timeRemaining >= 0) { |
| 5732 | pw.print(prefix); pw.print(label); pw.print(" total time: "); |
| 5733 | tmpSb.setLength(0); |
| 5734 | formatTimeMs(tmpSb, timeRemaining); |
| 5735 | pw.print(tmpSb); |
| 5736 | pw.print(" (from "); pw.print(tmpOutInt[0]); |
| 5737 | pw.println(" steps)"); |
| 5738 | } |
| 5739 | for (int i=0; i< STEP_LEVEL_MODES_OF_INTEREST.length; i++) { |
| 5740 | long estimatedTime = steps.computeTimeEstimate(STEP_LEVEL_MODES_OF_INTEREST[i], |
| 5741 | STEP_LEVEL_MODE_VALUES[i], tmpOutInt); |
| 5742 | if (estimatedTime > 0) { |
| 5743 | pw.print(prefix); pw.print(label); pw.print(" "); |
| 5744 | pw.print(STEP_LEVEL_MODE_LABELS[i]); |
| 5745 | pw.print(" time: "); |
| 5746 | tmpSb.setLength(0); |
| 5747 | formatTimeMs(tmpSb, estimatedTime); |
| 5748 | pw.print(tmpSb); |
| 5749 | pw.print(" (from "); pw.print(tmpOutInt[0]); |
| 5750 | pw.println(" steps)"); |
| 5751 | } |
| 5752 | } |
| 5753 | } |
| 5754 | |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 5755 | private void dumpDailyPackageChanges(PrintWriter pw, String prefix, |
| 5756 | ArrayList<PackageChange> changes) { |
| 5757 | if (changes == null) { |
| 5758 | return; |
| 5759 | } |
| 5760 | pw.print(prefix); pw.println("Package changes:"); |
| 5761 | for (int i=0; i<changes.size(); i++) { |
| 5762 | PackageChange pc = changes.get(i); |
| 5763 | if (pc.mUpdate) { |
| 5764 | pw.print(prefix); pw.print(" Update "); pw.print(pc.mPackageName); |
| 5765 | pw.print(" vers="); pw.println(pc.mVersionCode); |
| 5766 | } else { |
| 5767 | pw.print(prefix); pw.print(" Uninstall "); pw.println(pc.mPackageName); |
| 5768 | } |
| 5769 | } |
| 5770 | } |
| 5771 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5772 | /** |
| 5773 | * Dumps a human-readable summary of the battery statistics to the given PrintWriter. |
| 5774 | * |
| 5775 | * @param pw a Printer to receive the dump output. |
| 5776 | */ |
| 5777 | @SuppressWarnings("unused") |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 5778 | 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] | 5779 | prepareForDumpLocked(); |
| 5780 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 5781 | final boolean filtering = (flags |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5782 | & (DUMP_HISTORY_ONLY|DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) != 0; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5783 | |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 5784 | if ((flags&DUMP_HISTORY_ONLY) != 0 || !filtering) { |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 5785 | final long historyTotalSize = getHistoryTotalSize(); |
| 5786 | final long historyUsedSize = getHistoryUsedSize(); |
| 5787 | if (startIteratingHistoryLocked()) { |
| 5788 | try { |
| 5789 | pw.print("Battery History ("); |
| 5790 | pw.print((100*historyUsedSize)/historyTotalSize); |
| 5791 | pw.print("% used, "); |
| 5792 | printSizeValue(pw, historyUsedSize); |
| 5793 | pw.print(" used of "); |
| 5794 | printSizeValue(pw, historyTotalSize); |
| 5795 | pw.print(", "); |
| 5796 | pw.print(getHistoryStringPoolSize()); |
| 5797 | pw.print(" strings using "); |
| 5798 | printSizeValue(pw, getHistoryStringPoolBytes()); |
| 5799 | pw.println("):"); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 5800 | dumpHistoryLocked(pw, flags, histStart, false); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 5801 | pw.println(); |
| 5802 | } finally { |
| 5803 | finishIteratingHistoryLocked(); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 5804 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 5805 | } |
| 5806 | |
| 5807 | if (startIteratingOldHistoryLocked()) { |
| 5808 | try { |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 5809 | final HistoryItem rec = new HistoryItem(); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 5810 | pw.println("Old battery History:"); |
| 5811 | HistoryPrinter hprinter = new HistoryPrinter(); |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 5812 | long baseTime = -1; |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 5813 | while (getNextOldHistoryLocked(rec)) { |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 5814 | if (baseTime < 0) { |
| 5815 | baseTime = rec.time; |
| 5816 | } |
| 5817 | hprinter.printNextItem(pw, rec, baseTime, false, (flags&DUMP_VERBOSE) != 0); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 5818 | } |
| 5819 | pw.println(); |
| 5820 | } finally { |
| 5821 | finishIteratingOldHistoryLocked(); |
| 5822 | } |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 5823 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5824 | } |
| 5825 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5826 | if (filtering && (flags&(DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) == 0) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 5827 | return; |
| 5828 | } |
| 5829 | |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 5830 | if (!filtering) { |
| 5831 | SparseArray<? extends Uid> uidStats = getUidStats(); |
| 5832 | final int NU = uidStats.size(); |
| 5833 | boolean didPid = false; |
| 5834 | long nowRealtime = SystemClock.elapsedRealtime(); |
| 5835 | for (int i=0; i<NU; i++) { |
| 5836 | Uid uid = uidStats.valueAt(i); |
| 5837 | SparseArray<? extends Uid.Pid> pids = uid.getPidStats(); |
| 5838 | if (pids != null) { |
| 5839 | for (int j=0; j<pids.size(); j++) { |
| 5840 | Uid.Pid pid = pids.valueAt(j); |
| 5841 | if (!didPid) { |
| 5842 | pw.println("Per-PID Stats:"); |
| 5843 | didPid = true; |
| 5844 | } |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 5845 | long time = pid.mWakeSumMs + (pid.mWakeNesting > 0 |
| 5846 | ? (nowRealtime - pid.mWakeStartMs) : 0); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 5847 | pw.print(" PID "); pw.print(pids.keyAt(j)); |
| 5848 | pw.print(" wake time: "); |
| 5849 | TimeUtils.formatDuration(time, pw); |
| 5850 | pw.println(""); |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 5851 | } |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 5852 | } |
| 5853 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 5854 | if (didPid) { |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 5855 | pw.println(); |
| 5856 | } |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 5857 | } |
| 5858 | |
| 5859 | if (!filtering || (flags&DUMP_CHARGED_ONLY) != 0) { |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 5860 | if (dumpDurationSteps(pw, " ", "Discharge step durations:", |
| 5861 | getDischargeLevelStepTracker(), false)) { |
Kweku Adams | b0449e0 | 2016-10-12 14:18:27 -0700 | [diff] [blame] | 5862 | long timeRemaining = computeBatteryTimeRemaining( |
| 5863 | SystemClock.elapsedRealtime() * 1000); |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 5864 | if (timeRemaining >= 0) { |
| 5865 | pw.print(" Estimated discharge time remaining: "); |
| 5866 | TimeUtils.formatDuration(timeRemaining / 1000, pw); |
| 5867 | pw.println(); |
| 5868 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 5869 | final LevelStepTracker steps = getDischargeLevelStepTracker(); |
| 5870 | for (int i=0; i< STEP_LEVEL_MODES_OF_INTEREST.length; i++) { |
| 5871 | dumpTimeEstimate(pw, " Estimated ", STEP_LEVEL_MODE_LABELS[i], " time: ", |
| 5872 | steps.computeTimeEstimate(STEP_LEVEL_MODES_OF_INTEREST[i], |
| 5873 | STEP_LEVEL_MODE_VALUES[i], null)); |
| 5874 | } |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 5875 | pw.println(); |
| 5876 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 5877 | if (dumpDurationSteps(pw, " ", "Charge step durations:", |
| 5878 | getChargeLevelStepTracker(), false)) { |
Kweku Adams | b0449e0 | 2016-10-12 14:18:27 -0700 | [diff] [blame] | 5879 | long timeRemaining = computeChargeTimeRemaining( |
| 5880 | SystemClock.elapsedRealtime() * 1000); |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 5881 | if (timeRemaining >= 0) { |
| 5882 | pw.print(" Estimated charge time remaining: "); |
| 5883 | TimeUtils.formatDuration(timeRemaining / 1000, pw); |
| 5884 | pw.println(); |
| 5885 | } |
| 5886 | pw.println(); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 5887 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 5888 | } |
| 5889 | if (!filtering || (flags&(DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) != 0) { |
| 5890 | pw.println("Daily stats:"); |
| 5891 | pw.print(" Current start time: "); |
| 5892 | pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss", |
| 5893 | getCurrentDailyStartTime()).toString()); |
| 5894 | pw.print(" Next min deadline: "); |
| 5895 | pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss", |
| 5896 | getNextMinDailyDeadline()).toString()); |
| 5897 | pw.print(" Next max deadline: "); |
| 5898 | pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss", |
| 5899 | getNextMaxDailyDeadline()).toString()); |
| 5900 | StringBuilder sb = new StringBuilder(64); |
| 5901 | int[] outInt = new int[1]; |
| 5902 | LevelStepTracker dsteps = getDailyDischargeLevelStepTracker(); |
| 5903 | LevelStepTracker csteps = getDailyChargeLevelStepTracker(); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 5904 | ArrayList<PackageChange> pkgc = getDailyPackageChanges(); |
| 5905 | if (dsteps.mNumStepDurations > 0 || csteps.mNumStepDurations > 0 || pkgc != null) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5906 | if ((flags&DUMP_DAILY_ONLY) != 0 || !filtering) { |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 5907 | if (dumpDurationSteps(pw, " ", " Current daily discharge step durations:", |
| 5908 | dsteps, false)) { |
| 5909 | dumpDailyLevelStepSummary(pw, " ", "Discharge", dsteps, |
| 5910 | sb, outInt); |
| 5911 | } |
| 5912 | if (dumpDurationSteps(pw, " ", " Current daily charge step durations:", |
| 5913 | csteps, false)) { |
| 5914 | dumpDailyLevelStepSummary(pw, " ", "Charge", csteps, |
| 5915 | sb, outInt); |
| 5916 | } |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 5917 | dumpDailyPackageChanges(pw, " ", pkgc); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 5918 | } else { |
| 5919 | pw.println(" Current daily steps:"); |
| 5920 | dumpDailyLevelStepSummary(pw, " ", "Discharge", dsteps, |
| 5921 | sb, outInt); |
| 5922 | dumpDailyLevelStepSummary(pw, " ", "Charge", csteps, |
| 5923 | sb, outInt); |
| 5924 | } |
| 5925 | } |
| 5926 | DailyItem dit; |
| 5927 | int curIndex = 0; |
| 5928 | while ((dit=getDailyItemLocked(curIndex)) != null) { |
| 5929 | curIndex++; |
| 5930 | if ((flags&DUMP_DAILY_ONLY) != 0) { |
| 5931 | pw.println(); |
| 5932 | } |
| 5933 | pw.print(" Daily from "); |
| 5934 | pw.print(DateFormat.format("yyyy-MM-dd-HH-mm-ss", dit.mStartTime).toString()); |
| 5935 | pw.print(" to "); |
| 5936 | pw.print(DateFormat.format("yyyy-MM-dd-HH-mm-ss", dit.mEndTime).toString()); |
| 5937 | pw.println(":"); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5938 | if ((flags&DUMP_DAILY_ONLY) != 0 || !filtering) { |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 5939 | if (dumpDurationSteps(pw, " ", |
| 5940 | " Discharge step durations:", dit.mDischargeSteps, false)) { |
| 5941 | dumpDailyLevelStepSummary(pw, " ", "Discharge", dit.mDischargeSteps, |
| 5942 | sb, outInt); |
| 5943 | } |
| 5944 | if (dumpDurationSteps(pw, " ", |
| 5945 | " Charge step durations:", dit.mChargeSteps, false)) { |
| 5946 | dumpDailyLevelStepSummary(pw, " ", "Charge", dit.mChargeSteps, |
| 5947 | sb, outInt); |
| 5948 | } |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 5949 | dumpDailyPackageChanges(pw, " ", dit.mPackageChanges); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 5950 | } else { |
| 5951 | dumpDailyLevelStepSummary(pw, " ", "Discharge", dit.mDischargeSteps, |
| 5952 | sb, outInt); |
| 5953 | dumpDailyLevelStepSummary(pw, " ", "Charge", dit.mChargeSteps, |
| 5954 | sb, outInt); |
| 5955 | } |
| 5956 | } |
| 5957 | pw.println(); |
| 5958 | } |
| 5959 | if (!filtering || (flags&DUMP_CHARGED_ONLY) != 0) { |
Jeff Sharkey | ec43a6b | 2013-04-30 13:33:18 -0700 | [diff] [blame] | 5960 | pw.println("Statistics since last charge:"); |
| 5961 | pw.println(" System starts: " + getStartCount() |
| 5962 | + ", currently on battery: " + getIsOnBattery()); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 5963 | dumpLocked(context, pw, "", STATS_SINCE_CHARGED, reqUid, |
| 5964 | (flags&DUMP_DEVICE_WIFI_ONLY) != 0); |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 5965 | pw.println(); |
Jeff Sharkey | ec43a6b | 2013-04-30 13:33:18 -0700 | [diff] [blame] | 5966 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5967 | } |
| 5968 | |
| 5969 | @SuppressWarnings("unused") |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 5970 | public void dumpCheckinLocked(Context context, PrintWriter pw, |
| 5971 | List<ApplicationInfo> apps, int flags, long histStart) { |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5972 | prepareForDumpLocked(); |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 5973 | |
| 5974 | dumpLine(pw, 0 /* uid */, "i" /* category */, VERSION_DATA, |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 5975 | CHECKIN_VERSION, getParcelVersion(), getStartPlatformVersion(), |
| 5976 | getEndPlatformVersion()); |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 5977 | |
Dianne Hackborn | 13ac041 | 2013-06-25 19:34:49 -0700 | [diff] [blame] | 5978 | long now = getHistoryBaseTime() + SystemClock.elapsedRealtime(); |
| 5979 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 5980 | final boolean filtering = (flags & |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5981 | (DUMP_HISTORY_ONLY|DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) != 0; |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 5982 | |
| 5983 | if ((flags&DUMP_INCLUDE_HISTORY) != 0 || (flags&DUMP_HISTORY_ONLY) != 0) { |
Dianne Hackborn | 49021f5 | 2013-09-04 18:03:40 -0700 | [diff] [blame] | 5984 | if (startIteratingHistoryLocked()) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 5985 | try { |
| 5986 | for (int i=0; i<getHistoryStringPoolSize(); i++) { |
| 5987 | pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(','); |
| 5988 | pw.print(HISTORY_STRING_POOL); pw.print(','); |
| 5989 | pw.print(i); |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 5990 | pw.print(","); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 5991 | pw.print(getHistoryTagPoolUid(i)); |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 5992 | pw.print(",\""); |
| 5993 | String str = getHistoryTagPoolString(i); |
| 5994 | str = str.replace("\\", "\\\\"); |
| 5995 | str = str.replace("\"", "\\\""); |
| 5996 | pw.print(str); |
| 5997 | pw.print("\""); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 5998 | pw.println(); |
| 5999 | } |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 6000 | dumpHistoryLocked(pw, flags, histStart, true); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 6001 | } finally { |
| 6002 | finishIteratingHistoryLocked(); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 6003 | } |
Dianne Hackborn | 13ac041 | 2013-06-25 19:34:49 -0700 | [diff] [blame] | 6004 | } |
Dianne Hackborn | 13ac041 | 2013-06-25 19:34:49 -0700 | [diff] [blame] | 6005 | } |
| 6006 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 6007 | if (filtering && (flags&(DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) == 0) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 6008 | return; |
| 6009 | } |
| 6010 | |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 6011 | if (apps != null) { |
Dianne Hackborn | 9cfba35 | 2016-03-24 17:31:28 -0700 | [diff] [blame] | 6012 | SparseArray<Pair<ArrayList<String>, MutableBoolean>> uids = new SparseArray<>(); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 6013 | for (int i=0; i<apps.size(); i++) { |
| 6014 | ApplicationInfo ai = apps.get(i); |
Dianne Hackborn | 9cfba35 | 2016-03-24 17:31:28 -0700 | [diff] [blame] | 6015 | Pair<ArrayList<String>, MutableBoolean> pkgs = uids.get( |
| 6016 | UserHandle.getAppId(ai.uid)); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 6017 | if (pkgs == null) { |
Dianne Hackborn | 9cfba35 | 2016-03-24 17:31:28 -0700 | [diff] [blame] | 6018 | pkgs = new Pair<>(new ArrayList<String>(), new MutableBoolean(false)); |
| 6019 | uids.put(UserHandle.getAppId(ai.uid), pkgs); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 6020 | } |
Dianne Hackborn | 9cfba35 | 2016-03-24 17:31:28 -0700 | [diff] [blame] | 6021 | pkgs.first.add(ai.packageName); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 6022 | } |
| 6023 | SparseArray<? extends Uid> uidStats = getUidStats(); |
| 6024 | final int NU = uidStats.size(); |
| 6025 | String[] lineArgs = new String[2]; |
| 6026 | for (int i=0; i<NU; i++) { |
Dianne Hackborn | 9cfba35 | 2016-03-24 17:31:28 -0700 | [diff] [blame] | 6027 | int uid = UserHandle.getAppId(uidStats.keyAt(i)); |
| 6028 | Pair<ArrayList<String>, MutableBoolean> pkgs = uids.get(uid); |
| 6029 | if (pkgs != null && !pkgs.second.value) { |
| 6030 | pkgs.second.value = true; |
| 6031 | for (int j=0; j<pkgs.first.size(); j++) { |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 6032 | lineArgs[0] = Integer.toString(uid); |
Dianne Hackborn | 9cfba35 | 2016-03-24 17:31:28 -0700 | [diff] [blame] | 6033 | lineArgs[1] = pkgs.first.get(j); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 6034 | dumpLine(pw, 0 /* uid */, "i" /* category */, UID_DATA, |
| 6035 | (Object[])lineArgs); |
| 6036 | } |
| 6037 | } |
| 6038 | } |
| 6039 | } |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 6040 | if (!filtering || (flags&DUMP_CHARGED_ONLY) != 0) { |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6041 | dumpDurationSteps(pw, "", DISCHARGE_STEP_DATA, getDischargeLevelStepTracker(), true); |
Dianne Hackborn | d06dcfd | 2014-05-02 13:49:30 -0700 | [diff] [blame] | 6042 | String[] lineArgs = new String[1]; |
Kweku Adams | b0449e0 | 2016-10-12 14:18:27 -0700 | [diff] [blame] | 6043 | long timeRemaining = computeBatteryTimeRemaining(SystemClock.elapsedRealtime() * 1000); |
Dianne Hackborn | d06dcfd | 2014-05-02 13:49:30 -0700 | [diff] [blame] | 6044 | if (timeRemaining >= 0) { |
| 6045 | lineArgs[0] = Long.toString(timeRemaining); |
| 6046 | dumpLine(pw, 0 /* uid */, "i" /* category */, DISCHARGE_TIME_REMAIN_DATA, |
| 6047 | (Object[])lineArgs); |
| 6048 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6049 | dumpDurationSteps(pw, "", CHARGE_STEP_DATA, getChargeLevelStepTracker(), true); |
Kweku Adams | b0449e0 | 2016-10-12 14:18:27 -0700 | [diff] [blame] | 6050 | timeRemaining = computeChargeTimeRemaining(SystemClock.elapsedRealtime() * 1000); |
Dianne Hackborn | d06dcfd | 2014-05-02 13:49:30 -0700 | [diff] [blame] | 6051 | if (timeRemaining >= 0) { |
| 6052 | lineArgs[0] = Long.toString(timeRemaining); |
| 6053 | dumpLine(pw, 0 /* uid */, "i" /* category */, CHARGE_TIME_REMAIN_DATA, |
| 6054 | (Object[])lineArgs); |
| 6055 | } |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 6056 | dumpCheckinLocked(context, pw, STATS_SINCE_CHARGED, -1, |
| 6057 | (flags&DUMP_DEVICE_WIFI_ONLY) != 0); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6058 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6059 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6060 | } |