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 | |
Dianne Hackborn | 94326cb | 2017-06-28 16:17:20 -0700 | [diff] [blame] | 19 | import android.app.job.JobParameters; |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 20 | import android.content.Context; |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 21 | import android.content.pm.ApplicationInfo; |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 22 | import android.telephony.SignalStrength; |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 23 | import android.text.format.DateFormat; |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 24 | import android.util.ArrayMap; |
James Carr | 2dd7e5e | 2016-07-20 18:48:39 -0700 | [diff] [blame] | 25 | import android.util.LongSparseArray; |
Dianne Hackborn | 9cfba35 | 2016-03-24 17:31:28 -0700 | [diff] [blame] | 26 | import android.util.MutableBoolean; |
| 27 | import android.util.Pair; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 28 | import android.util.Printer; |
| 29 | import android.util.SparseArray; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 30 | import android.util.SparseIntArray; |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 31 | import android.util.TimeUtils; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 32 | import android.view.Display; |
Amith Yamasani | ab9ad19 | 2016-12-06 12:46:59 -0800 | [diff] [blame] | 33 | |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 34 | import com.android.internal.os.BatterySipper; |
| 35 | import com.android.internal.os.BatteryStatsHelper; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 36 | |
Michael Wachenschwanz | b05a3c5 | 2017-07-07 17:47:04 -0700 | [diff] [blame] | 37 | import java.io.PrintWriter; |
| 38 | import java.util.ArrayList; |
| 39 | import java.util.Collections; |
| 40 | import java.util.Comparator; |
| 41 | import java.util.Formatter; |
| 42 | import java.util.HashMap; |
| 43 | import java.util.List; |
| 44 | import java.util.Map; |
| 45 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 46 | /** |
| 47 | * A class providing access to battery usage statistics, including information on |
| 48 | * wakelocks, processes, packages, and services. All times are represented in microseconds |
| 49 | * except where indicated otherwise. |
| 50 | * @hide |
| 51 | */ |
| 52 | public abstract class BatteryStats implements Parcelable { |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 53 | private static final String TAG = "BatteryStats"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 54 | |
| 55 | private static final boolean LOCAL_LOGV = false; |
Dianne Hackborn | 91268cf | 2013-06-13 19:06:50 -0700 | [diff] [blame] | 56 | |
| 57 | /** @hide */ |
| 58 | public static final String SERVICE_NAME = "batterystats"; |
| 59 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 60 | /** |
| 61 | * A constant indicating a partial wake lock timer. |
| 62 | */ |
| 63 | public static final int WAKE_TYPE_PARTIAL = 0; |
| 64 | |
| 65 | /** |
| 66 | * A constant indicating a full wake lock timer. |
| 67 | */ |
| 68 | public static final int WAKE_TYPE_FULL = 1; |
| 69 | |
| 70 | /** |
| 71 | * A constant indicating a window wake lock timer. |
| 72 | */ |
| 73 | public static final int WAKE_TYPE_WINDOW = 2; |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 74 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 75 | /** |
| 76 | * A constant indicating a sensor timer. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 77 | */ |
| 78 | public static final int SENSOR = 3; |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 79 | |
| 80 | /** |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 81 | * A constant indicating a a wifi running timer |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 82 | */ |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 83 | public static final int WIFI_RUNNING = 4; |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 84 | |
| 85 | /** |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 86 | * A constant indicating a full wifi lock timer |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 87 | */ |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 88 | public static final int FULL_WIFI_LOCK = 5; |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 89 | |
| 90 | /** |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 91 | * A constant indicating a wifi scan |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 92 | */ |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 93 | public static final int WIFI_SCAN = 6; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 94 | |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 95 | /** |
| 96 | * A constant indicating a wifi multicast timer |
| 97 | */ |
| 98 | public static final int WIFI_MULTICAST_ENABLED = 7; |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 99 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 100 | /** |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 101 | * A constant indicating a video turn on timer |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 102 | */ |
| 103 | public static final int VIDEO_TURNED_ON = 8; |
| 104 | |
| 105 | /** |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 106 | * A constant indicating a vibrator on timer |
| 107 | */ |
| 108 | public static final int VIBRATOR_ON = 9; |
| 109 | |
| 110 | /** |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 111 | * A constant indicating a foreground activity timer |
| 112 | */ |
| 113 | public static final int FOREGROUND_ACTIVITY = 10; |
| 114 | |
| 115 | /** |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 116 | * A constant indicating a wifi batched scan is active |
| 117 | */ |
| 118 | public static final int WIFI_BATCHED_SCAN = 11; |
| 119 | |
| 120 | /** |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 121 | * A constant indicating a process state timer |
| 122 | */ |
| 123 | public static final int PROCESS_STATE = 12; |
| 124 | |
| 125 | /** |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 126 | * A constant indicating a sync timer |
| 127 | */ |
| 128 | public static final int SYNC = 13; |
| 129 | |
| 130 | /** |
| 131 | * A constant indicating a job timer |
| 132 | */ |
| 133 | public static final int JOB = 14; |
| 134 | |
| 135 | /** |
Kweku Adams | d537987 | 2014-11-24 17:34:05 -0800 | [diff] [blame] | 136 | * A constant indicating an audio turn on timer |
| 137 | */ |
| 138 | public static final int AUDIO_TURNED_ON = 15; |
| 139 | |
| 140 | /** |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 141 | * A constant indicating a flashlight turn on timer |
| 142 | */ |
| 143 | public static final int FLASHLIGHT_TURNED_ON = 16; |
| 144 | |
| 145 | /** |
| 146 | * A constant indicating a camera turn on timer |
| 147 | */ |
| 148 | public static final int CAMERA_TURNED_ON = 17; |
| 149 | |
| 150 | /** |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 151 | * A constant indicating a draw wake lock timer. |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 152 | */ |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 153 | public static final int WAKE_TYPE_DRAW = 18; |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 154 | |
| 155 | /** |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 156 | * A constant indicating a bluetooth scan timer. |
| 157 | */ |
| 158 | public static final int BLUETOOTH_SCAN_ON = 19; |
| 159 | |
| 160 | /** |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 161 | * A constant indicating an aggregated partial wake lock timer. |
| 162 | */ |
| 163 | public static final int AGGREGATED_WAKE_TYPE_PARTIAL = 20; |
| 164 | |
| 165 | /** |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 166 | * A constant indicating a bluetooth scan timer for unoptimized scans. |
| 167 | */ |
| 168 | public static final int BLUETOOTH_UNOPTIMIZED_SCAN_ON = 21; |
| 169 | |
| 170 | /** |
Michael Wachenschwanz | b05a3c5 | 2017-07-07 17:47:04 -0700 | [diff] [blame] | 171 | * A constant indicating a foreground service timer |
| 172 | */ |
| 173 | public static final int FOREGROUND_SERVICE = 22; |
| 174 | |
| 175 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 176 | * Include all of the data in the stats, including previously saved data. |
| 177 | */ |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 178 | public static final int STATS_SINCE_CHARGED = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 179 | |
| 180 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 181 | * Include only the current run in the stats. |
| 182 | */ |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 183 | public static final int STATS_CURRENT = 1; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 184 | |
| 185 | /** |
| 186 | * Include only the run since the last time the device was unplugged in the stats. |
| 187 | */ |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 188 | public static final int STATS_SINCE_UNPLUGGED = 2; |
Evan Millar | e84de8d | 2009-04-02 22:16:12 -0700 | [diff] [blame] | 189 | |
| 190 | // NOTE: Update this list if you add/change any stats above. |
| 191 | // These characters are supposed to represent "total", "last", "current", |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 192 | // and "unplugged". They were shortened for efficiency sake. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 193 | private static final String[] STAT_NAMES = { "l", "c", "u" }; |
| 194 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 195 | /** |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 196 | * Current version of checkin data format. |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 197 | * |
| 198 | * New in version 19: |
| 199 | * - Wakelock data (wl) gets current and max times. |
Amith Yamasani | ab9ad19 | 2016-12-06 12:46:59 -0800 | [diff] [blame] | 200 | * New in version 20: |
Bookatz | 2bffb5b | 2017-04-13 11:59:33 -0700 | [diff] [blame] | 201 | * - Background timers and counters for: Sensor, BluetoothScan, WifiScan, Jobs, Syncs. |
Bookatz | 506a818 | 2017-05-01 14:18:42 -0700 | [diff] [blame] | 202 | * New in version 21: |
| 203 | * - Actual (not just apportioned) Wakelock time is also recorded. |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 204 | * - Aggregated partial wakelock time (per uid, instead of per wakelock) is recorded. |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 205 | * - BLE scan result count |
| 206 | * - CPU frequency time per uid |
| 207 | * New in version 22: |
| 208 | * - BLE scan result background count, BLE unoptimized scan time |
Bookatz | 98d4d5c | 2017-08-01 19:07:54 -0700 | [diff] [blame] | 209 | * - Background partial wakelock time & count |
| 210 | * New in version 23: |
| 211 | * - Logging smeared power model values |
| 212 | * New in version 24: |
| 213 | * - Fixed bugs in background timers and BLE scan time |
| 214 | * New in version 25: |
| 215 | * - Package wakeup alarms are now on screen-off timebase |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame^] | 216 | * New in version 26: |
| 217 | * - Resource power manager (rpm) states |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 218 | */ |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame^] | 219 | static final String CHECKIN_VERSION = "26"; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 220 | |
| 221 | /** |
| 222 | * 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] | 223 | */ |
Ashish Sharma | 213bb2f | 2014-07-07 17:14:52 -0700 | [diff] [blame] | 224 | private static final int BATTERY_STATS_CHECKIN_VERSION = 9; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 225 | |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 226 | private static final long BYTES_PER_KB = 1024; |
| 227 | private static final long BYTES_PER_MB = 1048576; // 1024^2 |
| 228 | private static final long BYTES_PER_GB = 1073741824; //1024^3 |
Bookatz | 506a818 | 2017-05-01 14:18:42 -0700 | [diff] [blame] | 229 | |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 230 | private static final String VERSION_DATA = "vers"; |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 231 | private static final String UID_DATA = "uid"; |
Joe Onorato | 1476d32 | 2016-05-05 14:46:15 -0700 | [diff] [blame] | 232 | private static final String WAKEUP_ALARM_DATA = "wua"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 233 | private static final String APK_DATA = "apk"; |
Evan Millar | e84de8d | 2009-04-02 22:16:12 -0700 | [diff] [blame] | 234 | private static final String PROCESS_DATA = "pr"; |
Adam Lesinski | a7a4ccc | 2015-06-26 17:43:04 -0700 | [diff] [blame] | 235 | private static final String CPU_DATA = "cpu"; |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 236 | private static final String GLOBAL_CPU_FREQ_DATA = "gcf"; |
| 237 | private static final String CPU_TIMES_AT_FREQ_DATA = "ctf"; |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame^] | 238 | // rpm line is: |
| 239 | // BATTERY_STATS_CHECKIN_VERSION, uid, which, "rpm", state/voter name, total time, total count, |
| 240 | // screen-off time, screen-off count |
| 241 | private static final String RESOURCE_POWER_MANAGER_DATA = "rpm"; |
Evan Millar | e84de8d | 2009-04-02 22:16:12 -0700 | [diff] [blame] | 242 | private static final String SENSOR_DATA = "sr"; |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 243 | private static final String VIBRATOR_DATA = "vib"; |
Michael Wachenschwanz | b05a3c5 | 2017-07-07 17:47:04 -0700 | [diff] [blame] | 244 | private static final String FOREGROUND_ACTIVITY_DATA = "fg"; |
| 245 | // fgs line is: |
| 246 | // BATTERY_STATS_CHECKIN_VERSION, uid, category, "fgs", |
| 247 | // foreground service time, count |
| 248 | private static final String FOREGROUND_SERVICE_DATA = "fgs"; |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 249 | private static final String STATE_TIME_DATA = "st"; |
Bookatz | 506a818 | 2017-05-01 14:18:42 -0700 | [diff] [blame] | 250 | // wl line is: |
| 251 | // BATTERY_STATS_CHECKIN_VERSION, uid, which, "wl", name, |
Bookatz | 5b5ec32 | 2017-05-26 09:40:38 -0700 | [diff] [blame] | 252 | // full totalTime, 'f', count, current duration, max duration, total duration, |
| 253 | // partial totalTime, 'p', count, current duration, max duration, total duration, |
| 254 | // bg partial totalTime, 'bp', count, current duration, max duration, total duration, |
| 255 | // window totalTime, 'w', count, current duration, max duration, total duration |
Bookatz | 506a818 | 2017-05-01 14:18:42 -0700 | [diff] [blame] | 256 | // [Currently, full and window wakelocks have durations current = max = total = -1] |
Evan Millar | e84de8d | 2009-04-02 22:16:12 -0700 | [diff] [blame] | 257 | private static final String WAKELOCK_DATA = "wl"; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 258 | // awl line is: |
| 259 | // BATTERY_STATS_CHECKIN_VERSION, uid, which, "awl", |
| 260 | // cumulative partial wakelock duration, cumulative background partial wakelock duration |
| 261 | private static final String AGGREGATED_WAKELOCK_DATA = "awl"; |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 262 | private static final String SYNC_DATA = "sy"; |
| 263 | private static final String JOB_DATA = "jb"; |
Dianne Hackborn | 94326cb | 2017-06-28 16:17:20 -0700 | [diff] [blame] | 264 | private static final String JOB_COMPLETION_DATA = "jbc"; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 265 | private static final String KERNEL_WAKELOCK_DATA = "kwl"; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 266 | private static final String WAKEUP_REASON_DATA = "wr"; |
Evan Millar | e84de8d | 2009-04-02 22:16:12 -0700 | [diff] [blame] | 267 | private static final String NETWORK_DATA = "nt"; |
| 268 | private static final String USER_ACTIVITY_DATA = "ua"; |
| 269 | private static final String BATTERY_DATA = "bt"; |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 270 | private static final String BATTERY_DISCHARGE_DATA = "dc"; |
Evan Millar | e84de8d | 2009-04-02 22:16:12 -0700 | [diff] [blame] | 271 | private static final String BATTERY_LEVEL_DATA = "lv"; |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 272 | private static final String GLOBAL_WIFI_DATA = "gwfl"; |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 273 | private static final String WIFI_DATA = "wfl"; |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 274 | private static final String GLOBAL_WIFI_CONTROLLER_DATA = "gwfcd"; |
| 275 | private static final String WIFI_CONTROLLER_DATA = "wfcd"; |
| 276 | private static final String GLOBAL_BLUETOOTH_CONTROLLER_DATA = "gble"; |
| 277 | private static final String BLUETOOTH_CONTROLLER_DATA = "ble"; |
Adam Lesinski | d9b99be | 2016-03-30 16:58:51 -0700 | [diff] [blame] | 278 | private static final String BLUETOOTH_MISC_DATA = "blem"; |
Evan Millar | e84de8d | 2009-04-02 22:16:12 -0700 | [diff] [blame] | 279 | private static final String MISC_DATA = "m"; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 280 | private static final String GLOBAL_NETWORK_DATA = "gn"; |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 281 | private static final String GLOBAL_MODEM_CONTROLLER_DATA = "gmcd"; |
| 282 | private static final String MODEM_CONTROLLER_DATA = "mcd"; |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 283 | private static final String HISTORY_STRING_POOL = "hsp"; |
Dianne Hackborn | 8a0de58 | 2013-08-07 15:22:07 -0700 | [diff] [blame] | 284 | private static final String HISTORY_DATA = "h"; |
Evan Millar | e84de8d | 2009-04-02 22:16:12 -0700 | [diff] [blame] | 285 | private static final String SCREEN_BRIGHTNESS_DATA = "br"; |
| 286 | private static final String SIGNAL_STRENGTH_TIME_DATA = "sgt"; |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 287 | private static final String SIGNAL_SCANNING_TIME_DATA = "sst"; |
Evan Millar | e84de8d | 2009-04-02 22:16:12 -0700 | [diff] [blame] | 288 | private static final String SIGNAL_STRENGTH_COUNT_DATA = "sgc"; |
| 289 | private static final String DATA_CONNECTION_TIME_DATA = "dct"; |
| 290 | private static final String DATA_CONNECTION_COUNT_DATA = "dcc"; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 291 | private static final String WIFI_STATE_TIME_DATA = "wst"; |
| 292 | private static final String WIFI_STATE_COUNT_DATA = "wsc"; |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 293 | private static final String WIFI_SUPPL_STATE_TIME_DATA = "wsst"; |
| 294 | private static final String WIFI_SUPPL_STATE_COUNT_DATA = "wssc"; |
| 295 | private static final String WIFI_SIGNAL_STRENGTH_TIME_DATA = "wsgt"; |
| 296 | private static final String WIFI_SIGNAL_STRENGTH_COUNT_DATA = "wsgc"; |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 297 | private static final String POWER_USE_SUMMARY_DATA = "pws"; |
| 298 | private static final String POWER_USE_ITEM_DATA = "pwi"; |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 299 | private static final String DISCHARGE_STEP_DATA = "dsd"; |
| 300 | private static final String CHARGE_STEP_DATA = "csd"; |
Dianne Hackborn | d06dcfd | 2014-05-02 13:49:30 -0700 | [diff] [blame] | 301 | private static final String DISCHARGE_TIME_REMAIN_DATA = "dtr"; |
| 302 | private static final String CHARGE_TIME_REMAIN_DATA = "ctr"; |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 303 | private static final String FLASHLIGHT_DATA = "fla"; |
| 304 | private static final String CAMERA_DATA = "cam"; |
| 305 | private static final String VIDEO_DATA = "vid"; |
| 306 | private static final String AUDIO_DATA = "aud"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 307 | |
Adam Lesinski | 010bf37 | 2016-04-11 12:18:18 -0700 | [diff] [blame] | 308 | public static final String RESULT_RECEIVER_CONTROLLER_KEY = "controller_activity"; |
| 309 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 310 | private final StringBuilder mFormatBuilder = new StringBuilder(32); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 311 | private final Formatter mFormatter = new Formatter(mFormatBuilder); |
| 312 | |
| 313 | /** |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 314 | * Indicates times spent by the uid at each cpu frequency in all process states. |
| 315 | * |
| 316 | * Other types might include times spent in foreground, background etc. |
| 317 | */ |
| 318 | private final String UID_TIMES_TYPE_ALL = "A"; |
| 319 | |
| 320 | /** |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 321 | * State for keeping track of counting information. |
| 322 | */ |
| 323 | public static abstract class Counter { |
| 324 | |
| 325 | /** |
| 326 | * Returns the count associated with this Counter for the |
| 327 | * selected type of statistics. |
| 328 | * |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 329 | * @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] | 330 | */ |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 331 | public abstract int getCountLocked(int which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 332 | |
| 333 | /** |
| 334 | * Temporary for debugging. |
| 335 | */ |
| 336 | public abstract void logState(Printer pw, String prefix); |
| 337 | } |
| 338 | |
| 339 | /** |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 340 | * State for keeping track of long counting information. |
| 341 | */ |
| 342 | public static abstract class LongCounter { |
| 343 | |
| 344 | /** |
| 345 | * Returns the count associated with this Counter for the |
| 346 | * selected type of statistics. |
| 347 | * |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 348 | * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 349 | */ |
| 350 | public abstract long getCountLocked(int which); |
| 351 | |
| 352 | /** |
| 353 | * Temporary for debugging. |
| 354 | */ |
| 355 | public abstract void logState(Printer pw, String prefix); |
| 356 | } |
| 357 | |
| 358 | /** |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 359 | * State for keeping track of array of long counting information. |
| 360 | */ |
| 361 | public static abstract class LongCounterArray { |
| 362 | /** |
| 363 | * Returns the counts associated with this Counter for the |
| 364 | * selected type of statistics. |
| 365 | * |
| 366 | * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT |
| 367 | */ |
| 368 | public abstract long[] getCountsLocked(int which); |
| 369 | |
| 370 | /** |
| 371 | * Temporary for debugging. |
| 372 | */ |
| 373 | public abstract void logState(Printer pw, String prefix); |
| 374 | } |
| 375 | |
| 376 | /** |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 377 | * Container class that aggregates counters for transmit, receive, and idle state of a |
| 378 | * radio controller. |
| 379 | */ |
| 380 | public static abstract class ControllerActivityCounter { |
| 381 | /** |
| 382 | * @return a non-null {@link LongCounter} representing time spent (milliseconds) in the |
| 383 | * idle state. |
| 384 | */ |
| 385 | public abstract LongCounter getIdleTimeCounter(); |
| 386 | |
| 387 | /** |
| 388 | * @return a non-null {@link LongCounter} representing time spent (milliseconds) in the |
| 389 | * receive state. |
| 390 | */ |
| 391 | public abstract LongCounter getRxTimeCounter(); |
| 392 | |
| 393 | /** |
| 394 | * An array of {@link LongCounter}, representing various transmit levels, where each level |
| 395 | * may draw a different amount of power. The levels themselves are controller-specific. |
| 396 | * @return non-null array of {@link LongCounter}s representing time spent (milliseconds) in |
| 397 | * various transmit level states. |
| 398 | */ |
| 399 | public abstract LongCounter[] getTxTimeCounters(); |
| 400 | |
| 401 | /** |
| 402 | * @return a non-null {@link LongCounter} representing the power consumed by the controller |
| 403 | * in all states, measured in milli-ampere-milliseconds (mAms). The counter may always |
| 404 | * yield a value of 0 if the device doesn't support power calculations. |
| 405 | */ |
| 406 | public abstract LongCounter getPowerCounter(); |
| 407 | } |
| 408 | |
| 409 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 410 | * State for keeping track of timing information. |
| 411 | */ |
| 412 | public static abstract class Timer { |
| 413 | |
| 414 | /** |
| 415 | * Returns the count associated with this Timer for the |
| 416 | * selected type of statistics. |
| 417 | * |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 418 | * @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] | 419 | */ |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 420 | public abstract int getCountLocked(int which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 421 | |
| 422 | /** |
| 423 | * Returns the total time in microseconds associated with this Timer for the |
| 424 | * selected type of statistics. |
| 425 | * |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 426 | * @param elapsedRealtimeUs current elapsed realtime of system in microseconds |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 427 | * @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] | 428 | * @return a time in microseconds |
| 429 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 430 | public abstract long getTotalTimeLocked(long elapsedRealtimeUs, int which); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 431 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 432 | /** |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 433 | * Returns the total time in microseconds associated with this Timer since the |
| 434 | * 'mark' was last set. |
| 435 | * |
| 436 | * @param elapsedRealtimeUs current elapsed realtime of system in microseconds |
| 437 | * @return a time in microseconds |
| 438 | */ |
| 439 | public abstract long getTimeSinceMarkLocked(long elapsedRealtimeUs); |
| 440 | |
| 441 | /** |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 442 | * Returns the max duration if it is being tracked. |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 443 | * Not all Timer subclasses track the max, total, current durations. |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 444 | |
| 445 | */ |
| 446 | public long getMaxDurationMsLocked(long elapsedRealtimeMs) { |
| 447 | return -1; |
| 448 | } |
| 449 | |
| 450 | /** |
| 451 | * 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] | 452 | * Not all Timer subclasses track the max, total, current durations. |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 453 | */ |
| 454 | public long getCurrentDurationMsLocked(long elapsedRealtimeMs) { |
| 455 | return -1; |
| 456 | } |
| 457 | |
| 458 | /** |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 459 | * Returns the current time the timer has been active, if it is being tracked. |
| 460 | * |
| 461 | * Returns the total cumulative duration (i.e. sum of past durations) that this timer has |
| 462 | * been on since reset. |
| 463 | * This may differ from getTotalTimeLocked(elapsedRealtimeUs, STATS_SINCE_CHARGED)/1000 since, |
| 464 | * depending on the Timer, getTotalTimeLocked may represent the total 'blamed' or 'pooled' |
| 465 | * time, rather than the actual time. By contrast, getTotalDurationMsLocked always gives |
| 466 | * the actual total time. |
| 467 | * Not all Timer subclasses track the max, total, current durations. |
| 468 | */ |
| 469 | public long getTotalDurationMsLocked(long elapsedRealtimeMs) { |
| 470 | return -1; |
| 471 | } |
| 472 | |
| 473 | /** |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 474 | * Returns the secondary Timer held by the Timer, if one exists. This secondary timer may be |
| 475 | * used, for example, for tracking background usage. Secondary timers are never pooled. |
| 476 | * |
| 477 | * Not all Timer subclasses have a secondary timer; those that don't return null. |
| 478 | */ |
| 479 | public Timer getSubTimer() { |
| 480 | return null; |
| 481 | } |
| 482 | |
| 483 | /** |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 484 | * Returns whether the timer is currently running. Some types of timers |
| 485 | * (e.g. BatchTimers) don't know whether the event is currently active, |
| 486 | * and report false. |
| 487 | */ |
| 488 | public boolean isRunningLocked() { |
| 489 | return false; |
| 490 | } |
| 491 | |
| 492 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 493 | * Temporary for debugging. |
| 494 | */ |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 495 | public abstract void logState(Printer pw, String prefix); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 496 | } |
| 497 | |
| 498 | /** |
| 499 | * The statistics associated with a particular uid. |
| 500 | */ |
| 501 | public static abstract class Uid { |
| 502 | |
| 503 | /** |
| 504 | * Returns a mapping containing wakelock statistics. |
| 505 | * |
| 506 | * @return a Map from Strings to Uid.Wakelock objects. |
| 507 | */ |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 508 | public abstract ArrayMap<String, ? extends Wakelock> getWakelockStats(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 509 | |
| 510 | /** |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 511 | * Returns a mapping containing sync statistics. |
| 512 | * |
| 513 | * @return a Map from Strings to Timer objects. |
| 514 | */ |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 515 | public abstract ArrayMap<String, ? extends Timer> getSyncStats(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 516 | |
| 517 | /** |
| 518 | * Returns a mapping containing scheduled job statistics. |
| 519 | * |
| 520 | * @return a Map from Strings to Timer objects. |
| 521 | */ |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 522 | public abstract ArrayMap<String, ? extends Timer> getJobStats(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 523 | |
| 524 | /** |
Dianne Hackborn | 94326cb | 2017-06-28 16:17:20 -0700 | [diff] [blame] | 525 | * Returns statistics about how jobs have completed. |
| 526 | * |
| 527 | * @return A Map of String job names to completion type -> count mapping. |
| 528 | */ |
| 529 | public abstract ArrayMap<String, SparseIntArray> getJobCompletionStats(); |
| 530 | |
| 531 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 532 | * The statistics associated with a particular wake lock. |
| 533 | */ |
| 534 | public static abstract class Wakelock { |
| 535 | public abstract Timer getWakeTime(int type); |
| 536 | } |
| 537 | |
| 538 | /** |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 539 | * The cumulative time the uid spent holding any partial wakelocks. This will generally |
| 540 | * differ from summing over the Wakelocks in getWakelockStats since the latter may have |
| 541 | * wakelocks that overlap in time (and therefore over-counts). |
| 542 | */ |
| 543 | public abstract Timer getAggregatedPartialWakelockTimer(); |
| 544 | |
| 545 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 546 | * Returns a mapping containing sensor statistics. |
| 547 | * |
| 548 | * @return a Map from Integer sensor ids to Uid.Sensor objects. |
| 549 | */ |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 550 | public abstract SparseArray<? extends Sensor> getSensorStats(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 551 | |
| 552 | /** |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 553 | * Returns a mapping containing active process data. |
| 554 | */ |
| 555 | public abstract SparseArray<? extends Pid> getPidStats(); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 556 | |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 557 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 558 | * Returns a mapping containing process statistics. |
| 559 | * |
| 560 | * @return a Map from Strings to Uid.Proc objects. |
| 561 | */ |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 562 | public abstract ArrayMap<String, ? extends Proc> getProcessStats(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 563 | |
| 564 | /** |
| 565 | * Returns a mapping containing package statistics. |
| 566 | * |
| 567 | * @return a Map from Strings to Uid.Pkg objects. |
| 568 | */ |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 569 | public abstract ArrayMap<String, ? extends Pkg> getPackageStats(); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 570 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 571 | public abstract ControllerActivityCounter getWifiControllerActivity(); |
| 572 | public abstract ControllerActivityCounter getBluetoothControllerActivity(); |
| 573 | public abstract ControllerActivityCounter getModemControllerActivity(); |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 574 | |
| 575 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 576 | * {@hide} |
| 577 | */ |
| 578 | public abstract int getUid(); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 579 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 580 | public abstract void noteWifiRunningLocked(long elapsedRealtime); |
| 581 | public abstract void noteWifiStoppedLocked(long elapsedRealtime); |
| 582 | public abstract void noteFullWifiLockAcquiredLocked(long elapsedRealtime); |
| 583 | public abstract void noteFullWifiLockReleasedLocked(long elapsedRealtime); |
| 584 | public abstract void noteWifiScanStartedLocked(long elapsedRealtime); |
| 585 | public abstract void noteWifiScanStoppedLocked(long elapsedRealtime); |
| 586 | public abstract void noteWifiBatchedScanStartedLocked(int csph, long elapsedRealtime); |
| 587 | public abstract void noteWifiBatchedScanStoppedLocked(long elapsedRealtime); |
| 588 | public abstract void noteWifiMulticastEnabledLocked(long elapsedRealtime); |
| 589 | public abstract void noteWifiMulticastDisabledLocked(long elapsedRealtime); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 590 | public abstract void noteActivityResumedLocked(long elapsedRealtime); |
| 591 | public abstract void noteActivityPausedLocked(long elapsedRealtime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 592 | public abstract long getWifiRunningTime(long elapsedRealtimeUs, int which); |
| 593 | public abstract long getFullWifiLockTime(long elapsedRealtimeUs, int which); |
| 594 | public abstract long getWifiScanTime(long elapsedRealtimeUs, int which); |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 595 | public abstract int getWifiScanCount(int which); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 596 | public abstract int getWifiScanBackgroundCount(int which); |
| 597 | public abstract long getWifiScanActualTime(long elapsedRealtimeUs); |
| 598 | public abstract long getWifiScanBackgroundTime(long elapsedRealtimeUs); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 599 | public abstract long getWifiBatchedScanTime(int csphBin, long elapsedRealtimeUs, int which); |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 600 | public abstract int getWifiBatchedScanCount(int csphBin, int which); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 601 | public abstract long getWifiMulticastTime(long elapsedRealtimeUs, int which); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 602 | public abstract Timer getAudioTurnedOnTimer(); |
| 603 | public abstract Timer getVideoTurnedOnTimer(); |
| 604 | public abstract Timer getFlashlightTurnedOnTimer(); |
| 605 | public abstract Timer getCameraTurnedOnTimer(); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 606 | public abstract Timer getForegroundActivityTimer(); |
Michael Wachenschwanz | b05a3c5 | 2017-07-07 17:47:04 -0700 | [diff] [blame] | 607 | |
| 608 | /** |
| 609 | * Returns the timer keeping track of Foreground Service time |
| 610 | */ |
| 611 | public abstract Timer getForegroundServiceTimer(); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 612 | public abstract Timer getBluetoothScanTimer(); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 613 | public abstract Timer getBluetoothScanBackgroundTimer(); |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 614 | public abstract Timer getBluetoothUnoptimizedScanTimer(); |
| 615 | public abstract Timer getBluetoothUnoptimizedScanBackgroundTimer(); |
Bookatz | 956f36bf | 2017-04-28 09:48:17 -0700 | [diff] [blame] | 616 | public abstract Counter getBluetoothScanResultCounter(); |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 617 | public abstract Counter getBluetoothScanResultBgCounter(); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 618 | |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 619 | public abstract long[] getCpuFreqTimes(int which); |
| 620 | public abstract long[] getScreenOffCpuFreqTimes(int which); |
| 621 | |
Dianne Hackborn | a0200e3 | 2016-03-30 18:01:41 -0700 | [diff] [blame] | 622 | // Note: the following times are disjoint. They can be added together to find the |
| 623 | // total time a uid has had any processes running at all. |
| 624 | |
| 625 | /** |
| 626 | * Time this uid has any processes in the top state (or above such as persistent). |
| 627 | */ |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 628 | public static final int PROCESS_STATE_TOP = 0; |
Dianne Hackborn | a0200e3 | 2016-03-30 18:01:41 -0700 | [diff] [blame] | 629 | /** |
| 630 | * Time this uid has any process with a started out bound foreground service, but |
| 631 | * none in the "top" state. |
| 632 | */ |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 633 | public static final int PROCESS_STATE_FOREGROUND_SERVICE = 1; |
Dianne Hackborn | a0200e3 | 2016-03-30 18:01:41 -0700 | [diff] [blame] | 634 | /** |
| 635 | * Time this uid has any process that is top while the device is sleeping, but none |
| 636 | * in the "foreground service" or better state. |
| 637 | */ |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 638 | public static final int PROCESS_STATE_TOP_SLEEPING = 2; |
Dianne Hackborn | a0200e3 | 2016-03-30 18:01:41 -0700 | [diff] [blame] | 639 | /** |
| 640 | * Time this uid has any process in an active foreground state, but none in the |
| 641 | * "top sleeping" or better state. |
| 642 | */ |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 643 | public static final int PROCESS_STATE_FOREGROUND = 3; |
Dianne Hackborn | a0200e3 | 2016-03-30 18:01:41 -0700 | [diff] [blame] | 644 | /** |
| 645 | * Time this uid has any process in an active background state, but none in the |
| 646 | * "foreground" or better state. |
| 647 | */ |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 648 | public static final int PROCESS_STATE_BACKGROUND = 4; |
Dianne Hackborn | a0200e3 | 2016-03-30 18:01:41 -0700 | [diff] [blame] | 649 | /** |
| 650 | * Time this uid has any processes that are sitting around cached, not in one of the |
| 651 | * other active states. |
| 652 | */ |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 653 | public static final int PROCESS_STATE_CACHED = 5; |
Dianne Hackborn | a0200e3 | 2016-03-30 18:01:41 -0700 | [diff] [blame] | 654 | /** |
| 655 | * Total number of process states we track. |
| 656 | */ |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 657 | public static final int NUM_PROCESS_STATE = 6; |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 658 | |
| 659 | static final String[] PROCESS_STATE_NAMES = { |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 660 | "Top", "Fg Service", "Top Sleeping", "Foreground", "Background", "Cached" |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 661 | }; |
| 662 | |
| 663 | public abstract long getProcessStateTime(int state, long elapsedRealtimeUs, int which); |
Joe Onorato | 713fec8 | 2016-03-04 10:34:02 -0800 | [diff] [blame] | 664 | public abstract Timer getProcessStateTimer(int state); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 665 | |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 666 | public abstract Timer getVibratorOnTimer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 667 | |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 668 | public static final int NUM_WIFI_BATCHED_SCAN_BINS = 5; |
| 669 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 670 | /** |
Jeff Brown | df693de | 2012-07-27 12:03:38 -0700 | [diff] [blame] | 671 | * Note that these must match the constants in android.os.PowerManager. |
| 672 | * Also, if the user activity types change, the BatteryStatsImpl.VERSION must |
| 673 | * also be bumped. |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 674 | */ |
| 675 | static final String[] USER_ACTIVITY_TYPES = { |
Phil Weaver | da80d67 | 2016-03-15 16:25:46 -0700 | [diff] [blame] | 676 | "other", "button", "touch", "accessibility" |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 677 | }; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 678 | |
Phil Weaver | da80d67 | 2016-03-15 16:25:46 -0700 | [diff] [blame] | 679 | public static final int NUM_USER_ACTIVITY_TYPES = 4; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 680 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 681 | public abstract void noteUserActivityLocked(int type); |
| 682 | public abstract boolean hasUserActivity(); |
| 683 | public abstract int getUserActivityCount(int type, int which); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 684 | |
| 685 | public abstract boolean hasNetworkActivity(); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 686 | public abstract long getNetworkActivityBytes(int type, int which); |
| 687 | public abstract long getNetworkActivityPackets(int type, int which); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 688 | public abstract long getMobileRadioActiveTime(int which); |
| 689 | public abstract int getMobileRadioActiveCount(int which); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 690 | |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 691 | /** |
| 692 | * Get the total cpu time (in microseconds) this UID had processes executing in userspace. |
| 693 | */ |
| 694 | public abstract long getUserCpuTimeUs(int which); |
| 695 | |
| 696 | /** |
| 697 | * Get the total cpu time (in microseconds) this UID had processes executing kernel syscalls. |
| 698 | */ |
| 699 | public abstract long getSystemCpuTimeUs(int which); |
| 700 | |
| 701 | /** |
Sudheer Shanka | 71f34b3 | 2017-07-21 00:14:24 -0700 | [diff] [blame] | 702 | * Returns the approximate cpu time (in microseconds) spent at a certain CPU speed for a |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 703 | * given CPU cluster. |
| 704 | * @param cluster the index of the CPU cluster. |
Adam Lesinski | a7a4ccc | 2015-06-26 17:43:04 -0700 | [diff] [blame] | 705 | * @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] | 706 | * @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] | 707 | * @see com.android.internal.os.PowerProfile#getNumCpuClusters() |
| 708 | * @see com.android.internal.os.PowerProfile#getNumSpeedStepsInCpuCluster(int) |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 709 | */ |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 710 | public abstract long getTimeAtCpuSpeed(int cluster, int step, int which); |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 711 | |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 712 | /** |
| 713 | * Returns the number of times this UID woke up the Application Processor to |
| 714 | * process a mobile radio packet. |
| 715 | * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT. |
| 716 | */ |
| 717 | public abstract long getMobileRadioApWakeupCount(int which); |
| 718 | |
| 719 | /** |
| 720 | * Returns the number of times this UID woke up the Application Processor to |
| 721 | * process a WiFi packet. |
| 722 | * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT. |
| 723 | */ |
| 724 | public abstract long getWifiRadioApWakeupCount(int which); |
| 725 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 726 | public static abstract class Sensor { |
Mathias Agopian | 7f84c06 | 2013-02-04 19:22:47 -0800 | [diff] [blame] | 727 | /* |
| 728 | * FIXME: it's not correct to use this magic value because it |
| 729 | * could clash with a sensor handle (which are defined by |
| 730 | * the sensor HAL, and therefore out of our control |
| 731 | */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 732 | // Magic sensor number for the GPS. |
| 733 | public static final int GPS = -10000; |
Amith Yamasani | ab9ad19 | 2016-12-06 12:46:59 -0800 | [diff] [blame] | 734 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 735 | public abstract int getHandle(); |
Amith Yamasani | ab9ad19 | 2016-12-06 12:46:59 -0800 | [diff] [blame] | 736 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 737 | public abstract Timer getSensorTime(); |
Amith Yamasani | ab9ad19 | 2016-12-06 12:46:59 -0800 | [diff] [blame] | 738 | |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 739 | /** Returns a Timer for sensor usage when app is in the background. */ |
| 740 | public abstract Timer getSensorBackgroundTime(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 741 | } |
| 742 | |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 743 | public class Pid { |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 744 | public int mWakeNesting; |
| 745 | public long mWakeSumMs; |
| 746 | public long mWakeStartMs; |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 747 | } |
| 748 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 749 | /** |
| 750 | * The statistics associated with a particular process. |
| 751 | */ |
| 752 | public static abstract class Proc { |
| 753 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 754 | public static class ExcessivePower { |
| 755 | public static final int TYPE_WAKE = 1; |
| 756 | public static final int TYPE_CPU = 2; |
| 757 | |
| 758 | public int type; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 759 | public long overTime; |
| 760 | public long usedTime; |
| 761 | } |
| 762 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 763 | /** |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 764 | * Returns true if this process is still active in the battery stats. |
| 765 | */ |
| 766 | public abstract boolean isActive(); |
| 767 | |
| 768 | /** |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 769 | * 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] | 770 | * |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 771 | * @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] | 772 | */ |
| 773 | public abstract long getUserTime(int which); |
| 774 | |
| 775 | /** |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 776 | * 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] | 777 | * |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 778 | * @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] | 779 | */ |
| 780 | public abstract long getSystemTime(int which); |
| 781 | |
| 782 | /** |
| 783 | * Returns the number of times the process has been started. |
| 784 | * |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 785 | * @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] | 786 | */ |
| 787 | public abstract int getStarts(int which); |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 788 | |
| 789 | /** |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 790 | * Returns the number of times the process has crashed. |
| 791 | * |
| 792 | * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT. |
| 793 | */ |
| 794 | public abstract int getNumCrashes(int which); |
| 795 | |
| 796 | /** |
| 797 | * Returns the number of times the process has ANRed. |
| 798 | * |
| 799 | * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT. |
| 800 | */ |
| 801 | public abstract int getNumAnrs(int which); |
| 802 | |
| 803 | /** |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 804 | * 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] | 805 | * @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] | 806 | * @return foreground cpu time in microseconds |
| 807 | */ |
| 808 | public abstract long getForegroundTime(int which); |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 809 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 810 | public abstract int countExcessivePowers(); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 811 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 812 | public abstract ExcessivePower getExcessivePower(int i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 813 | } |
| 814 | |
| 815 | /** |
| 816 | * The statistics associated with a particular package. |
| 817 | */ |
| 818 | public static abstract class Pkg { |
| 819 | |
| 820 | /** |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 821 | * Returns information about all wakeup alarms that have been triggered for this |
| 822 | * package. The mapping keys are tag names for the alarms, the counter contains |
| 823 | * 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] | 824 | */ |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 825 | public abstract ArrayMap<String, ? extends Counter> getWakeupAlarmStats(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 826 | |
| 827 | /** |
| 828 | * Returns a mapping containing service statistics. |
| 829 | */ |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 830 | public abstract ArrayMap<String, ? extends Serv> getServiceStats(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 831 | |
| 832 | /** |
| 833 | * The statistics associated with a particular service. |
| 834 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 835 | public static abstract class Serv { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 836 | |
| 837 | /** |
| 838 | * Returns the amount of time spent started. |
| 839 | * |
| 840 | * @param batteryUptime elapsed uptime on battery in microseconds. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 841 | * @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] | 842 | * @return |
| 843 | */ |
| 844 | public abstract long getStartTime(long batteryUptime, int which); |
| 845 | |
| 846 | /** |
| 847 | * Returns the total number of times startService() has been called. |
| 848 | * |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 849 | * @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] | 850 | */ |
| 851 | public abstract int getStarts(int which); |
| 852 | |
| 853 | /** |
| 854 | * Returns the total number times the service has been launched. |
| 855 | * |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 856 | * @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] | 857 | */ |
| 858 | public abstract int getLaunches(int which); |
| 859 | } |
| 860 | } |
| 861 | } |
| 862 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 863 | public static final class LevelStepTracker { |
| 864 | public long mLastStepTime = -1; |
| 865 | public int mNumStepDurations; |
| 866 | public final long[] mStepDurations; |
| 867 | |
| 868 | public LevelStepTracker(int maxLevelSteps) { |
| 869 | mStepDurations = new long[maxLevelSteps]; |
| 870 | } |
| 871 | |
| 872 | public LevelStepTracker(int numSteps, long[] steps) { |
| 873 | mNumStepDurations = numSteps; |
| 874 | mStepDurations = new long[numSteps]; |
| 875 | System.arraycopy(steps, 0, mStepDurations, 0, numSteps); |
| 876 | } |
| 877 | |
| 878 | public long getDurationAt(int index) { |
| 879 | return mStepDurations[index] & STEP_LEVEL_TIME_MASK; |
| 880 | } |
| 881 | |
| 882 | public int getLevelAt(int index) { |
| 883 | return (int)((mStepDurations[index] & STEP_LEVEL_LEVEL_MASK) |
| 884 | >> STEP_LEVEL_LEVEL_SHIFT); |
| 885 | } |
| 886 | |
| 887 | public int getInitModeAt(int index) { |
| 888 | return (int)((mStepDurations[index] & STEP_LEVEL_INITIAL_MODE_MASK) |
| 889 | >> STEP_LEVEL_INITIAL_MODE_SHIFT); |
| 890 | } |
| 891 | |
| 892 | public int getModModeAt(int index) { |
| 893 | return (int)((mStepDurations[index] & STEP_LEVEL_MODIFIED_MODE_MASK) |
| 894 | >> STEP_LEVEL_MODIFIED_MODE_SHIFT); |
| 895 | } |
| 896 | |
| 897 | private void appendHex(long val, int topOffset, StringBuilder out) { |
| 898 | boolean hasData = false; |
| 899 | while (topOffset >= 0) { |
| 900 | int digit = (int)( (val>>topOffset) & 0xf ); |
| 901 | topOffset -= 4; |
| 902 | if (!hasData && digit == 0) { |
| 903 | continue; |
| 904 | } |
| 905 | hasData = true; |
| 906 | if (digit >= 0 && digit <= 9) { |
| 907 | out.append((char)('0' + digit)); |
| 908 | } else { |
| 909 | out.append((char)('a' + digit - 10)); |
| 910 | } |
| 911 | } |
| 912 | } |
| 913 | |
| 914 | public void encodeEntryAt(int index, StringBuilder out) { |
| 915 | long item = mStepDurations[index]; |
| 916 | long duration = item & STEP_LEVEL_TIME_MASK; |
| 917 | int level = (int)((item & STEP_LEVEL_LEVEL_MASK) |
| 918 | >> STEP_LEVEL_LEVEL_SHIFT); |
| 919 | int initMode = (int)((item & STEP_LEVEL_INITIAL_MODE_MASK) |
| 920 | >> STEP_LEVEL_INITIAL_MODE_SHIFT); |
| 921 | int modMode = (int)((item & STEP_LEVEL_MODIFIED_MODE_MASK) |
| 922 | >> STEP_LEVEL_MODIFIED_MODE_SHIFT); |
| 923 | switch ((initMode&STEP_LEVEL_MODE_SCREEN_STATE) + 1) { |
| 924 | case Display.STATE_OFF: out.append('f'); break; |
| 925 | case Display.STATE_ON: out.append('o'); break; |
| 926 | case Display.STATE_DOZE: out.append('d'); break; |
| 927 | case Display.STATE_DOZE_SUSPEND: out.append('z'); break; |
| 928 | } |
| 929 | if ((initMode&STEP_LEVEL_MODE_POWER_SAVE) != 0) { |
| 930 | out.append('p'); |
| 931 | } |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 932 | if ((initMode&STEP_LEVEL_MODE_DEVICE_IDLE) != 0) { |
| 933 | out.append('i'); |
| 934 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 935 | switch ((modMode&STEP_LEVEL_MODE_SCREEN_STATE) + 1) { |
| 936 | case Display.STATE_OFF: out.append('F'); break; |
| 937 | case Display.STATE_ON: out.append('O'); break; |
| 938 | case Display.STATE_DOZE: out.append('D'); break; |
| 939 | case Display.STATE_DOZE_SUSPEND: out.append('Z'); break; |
| 940 | } |
| 941 | if ((modMode&STEP_LEVEL_MODE_POWER_SAVE) != 0) { |
| 942 | out.append('P'); |
| 943 | } |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 944 | if ((modMode&STEP_LEVEL_MODE_DEVICE_IDLE) != 0) { |
| 945 | out.append('I'); |
| 946 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 947 | out.append('-'); |
| 948 | appendHex(level, 4, out); |
| 949 | out.append('-'); |
| 950 | appendHex(duration, STEP_LEVEL_LEVEL_SHIFT-4, out); |
| 951 | } |
| 952 | |
| 953 | public void decodeEntryAt(int index, String value) { |
| 954 | final int N = value.length(); |
| 955 | int i = 0; |
| 956 | char c; |
| 957 | long out = 0; |
| 958 | while (i < N && (c=value.charAt(i)) != '-') { |
| 959 | i++; |
| 960 | switch (c) { |
Dianne Hackborn | 8cfb58b | 2015-03-04 13:28:36 -0800 | [diff] [blame] | 961 | 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] | 962 | break; |
Dianne Hackborn | 8cfb58b | 2015-03-04 13:28:36 -0800 | [diff] [blame] | 963 | 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] | 964 | break; |
Dianne Hackborn | 8cfb58b | 2015-03-04 13:28:36 -0800 | [diff] [blame] | 965 | 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] | 966 | break; |
Dianne Hackborn | 8cfb58b | 2015-03-04 13:28:36 -0800 | [diff] [blame] | 967 | case 'z': out |= (((long)Display.STATE_DOZE_SUSPEND-1) |
| 968 | << STEP_LEVEL_INITIAL_MODE_SHIFT); |
| 969 | break; |
| 970 | case 'p': out |= (((long)STEP_LEVEL_MODE_POWER_SAVE) |
| 971 | << STEP_LEVEL_INITIAL_MODE_SHIFT); |
| 972 | break; |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 973 | case 'i': out |= (((long)STEP_LEVEL_MODE_DEVICE_IDLE) |
| 974 | << STEP_LEVEL_INITIAL_MODE_SHIFT); |
| 975 | break; |
Dianne Hackborn | 8cfb58b | 2015-03-04 13:28:36 -0800 | [diff] [blame] | 976 | case 'F': out |= (((long)Display.STATE_OFF-1)<<STEP_LEVEL_MODIFIED_MODE_SHIFT); |
| 977 | break; |
| 978 | case 'O': out |= (((long)Display.STATE_ON-1)<<STEP_LEVEL_MODIFIED_MODE_SHIFT); |
| 979 | break; |
| 980 | case 'D': out |= (((long)Display.STATE_DOZE-1)<<STEP_LEVEL_MODIFIED_MODE_SHIFT); |
| 981 | break; |
| 982 | case 'Z': out |= (((long)Display.STATE_DOZE_SUSPEND-1) |
| 983 | << STEP_LEVEL_MODIFIED_MODE_SHIFT); |
| 984 | break; |
| 985 | case 'P': out |= (((long)STEP_LEVEL_MODE_POWER_SAVE) |
| 986 | << STEP_LEVEL_MODIFIED_MODE_SHIFT); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 987 | break; |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 988 | case 'I': out |= (((long)STEP_LEVEL_MODE_DEVICE_IDLE) |
| 989 | << STEP_LEVEL_MODIFIED_MODE_SHIFT); |
| 990 | break; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 991 | } |
| 992 | } |
| 993 | i++; |
Dianne Hackborn | 8cfb58b | 2015-03-04 13:28:36 -0800 | [diff] [blame] | 994 | long level = 0; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 995 | while (i < N && (c=value.charAt(i)) != '-') { |
| 996 | i++; |
| 997 | level <<= 4; |
| 998 | if (c >= '0' && c <= '9') { |
| 999 | level += c - '0'; |
| 1000 | } else if (c >= 'a' && c <= 'f') { |
| 1001 | level += c - 'a' + 10; |
| 1002 | } else if (c >= 'A' && c <= 'F') { |
| 1003 | level += c - 'A' + 10; |
| 1004 | } |
| 1005 | } |
Dianne Hackborn | 8cfb58b | 2015-03-04 13:28:36 -0800 | [diff] [blame] | 1006 | i++; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 1007 | out |= (level << STEP_LEVEL_LEVEL_SHIFT) & STEP_LEVEL_LEVEL_MASK; |
| 1008 | long duration = 0; |
| 1009 | while (i < N && (c=value.charAt(i)) != '-') { |
| 1010 | i++; |
| 1011 | duration <<= 4; |
| 1012 | if (c >= '0' && c <= '9') { |
| 1013 | duration += c - '0'; |
| 1014 | } else if (c >= 'a' && c <= 'f') { |
| 1015 | duration += c - 'a' + 10; |
| 1016 | } else if (c >= 'A' && c <= 'F') { |
| 1017 | duration += c - 'A' + 10; |
| 1018 | } |
| 1019 | } |
| 1020 | mStepDurations[index] = out | (duration & STEP_LEVEL_TIME_MASK); |
| 1021 | } |
| 1022 | |
| 1023 | public void init() { |
| 1024 | mLastStepTime = -1; |
| 1025 | mNumStepDurations = 0; |
| 1026 | } |
| 1027 | |
| 1028 | public void clearTime() { |
| 1029 | mLastStepTime = -1; |
| 1030 | } |
| 1031 | |
| 1032 | public long computeTimePerLevel() { |
| 1033 | final long[] steps = mStepDurations; |
| 1034 | final int numSteps = mNumStepDurations; |
| 1035 | |
| 1036 | // For now we'll do a simple average across all steps. |
| 1037 | if (numSteps <= 0) { |
| 1038 | return -1; |
| 1039 | } |
| 1040 | long total = 0; |
| 1041 | for (int i=0; i<numSteps; i++) { |
| 1042 | total += steps[i] & STEP_LEVEL_TIME_MASK; |
| 1043 | } |
| 1044 | return total / numSteps; |
| 1045 | /* |
| 1046 | long[] buckets = new long[numSteps]; |
| 1047 | int numBuckets = 0; |
| 1048 | int numToAverage = 4; |
| 1049 | int i = 0; |
| 1050 | while (i < numSteps) { |
| 1051 | long totalTime = 0; |
| 1052 | int num = 0; |
| 1053 | for (int j=0; j<numToAverage && (i+j)<numSteps; j++) { |
| 1054 | totalTime += steps[i+j] & STEP_LEVEL_TIME_MASK; |
| 1055 | num++; |
| 1056 | } |
| 1057 | buckets[numBuckets] = totalTime / num; |
| 1058 | numBuckets++; |
| 1059 | numToAverage *= 2; |
| 1060 | i += num; |
| 1061 | } |
| 1062 | if (numBuckets < 1) { |
| 1063 | return -1; |
| 1064 | } |
| 1065 | long averageTime = buckets[numBuckets-1]; |
| 1066 | for (i=numBuckets-2; i>=0; i--) { |
| 1067 | averageTime = (averageTime + buckets[i]) / 2; |
| 1068 | } |
| 1069 | return averageTime; |
| 1070 | */ |
| 1071 | } |
| 1072 | |
| 1073 | public long computeTimeEstimate(long modesOfInterest, long modeValues, |
| 1074 | int[] outNumOfInterest) { |
| 1075 | final long[] steps = mStepDurations; |
| 1076 | final int count = mNumStepDurations; |
| 1077 | if (count <= 0) { |
| 1078 | return -1; |
| 1079 | } |
| 1080 | long total = 0; |
| 1081 | int numOfInterest = 0; |
| 1082 | for (int i=0; i<count; i++) { |
| 1083 | long initMode = (steps[i] & STEP_LEVEL_INITIAL_MODE_MASK) |
| 1084 | >> STEP_LEVEL_INITIAL_MODE_SHIFT; |
| 1085 | long modMode = (steps[i] & STEP_LEVEL_MODIFIED_MODE_MASK) |
| 1086 | >> STEP_LEVEL_MODIFIED_MODE_SHIFT; |
| 1087 | // If the modes of interest didn't change during this step period... |
| 1088 | if ((modMode&modesOfInterest) == 0) { |
| 1089 | // And the mode values during this period match those we are measuring... |
| 1090 | if ((initMode&modesOfInterest) == modeValues) { |
| 1091 | // Then this can be used to estimate the total time! |
| 1092 | numOfInterest++; |
| 1093 | total += steps[i] & STEP_LEVEL_TIME_MASK; |
| 1094 | } |
| 1095 | } |
| 1096 | } |
| 1097 | if (numOfInterest <= 0) { |
| 1098 | return -1; |
| 1099 | } |
| 1100 | |
| 1101 | if (outNumOfInterest != null) { |
| 1102 | outNumOfInterest[0] = numOfInterest; |
| 1103 | } |
| 1104 | |
| 1105 | // The estimated time is the average time we spend in each level, multipled |
| 1106 | // by 100 -- the total number of battery levels |
| 1107 | return (total / numOfInterest) * 100; |
| 1108 | } |
| 1109 | |
| 1110 | public void addLevelSteps(int numStepLevels, long modeBits, long elapsedRealtime) { |
| 1111 | int stepCount = mNumStepDurations; |
| 1112 | final long lastStepTime = mLastStepTime; |
| 1113 | if (lastStepTime >= 0 && numStepLevels > 0) { |
| 1114 | final long[] steps = mStepDurations; |
| 1115 | long duration = elapsedRealtime - lastStepTime; |
| 1116 | for (int i=0; i<numStepLevels; i++) { |
| 1117 | System.arraycopy(steps, 0, steps, 1, steps.length-1); |
| 1118 | long thisDuration = duration / (numStepLevels-i); |
| 1119 | duration -= thisDuration; |
| 1120 | if (thisDuration > STEP_LEVEL_TIME_MASK) { |
| 1121 | thisDuration = STEP_LEVEL_TIME_MASK; |
| 1122 | } |
| 1123 | steps[0] = thisDuration | modeBits; |
| 1124 | } |
| 1125 | stepCount += numStepLevels; |
| 1126 | if (stepCount > steps.length) { |
| 1127 | stepCount = steps.length; |
| 1128 | } |
| 1129 | } |
| 1130 | mNumStepDurations = stepCount; |
| 1131 | mLastStepTime = elapsedRealtime; |
| 1132 | } |
| 1133 | |
| 1134 | public void readFromParcel(Parcel in) { |
| 1135 | final int N = in.readInt(); |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 1136 | if (N > mStepDurations.length) { |
| 1137 | throw new ParcelFormatException("more step durations than available: " + N); |
| 1138 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 1139 | mNumStepDurations = N; |
| 1140 | for (int i=0; i<N; i++) { |
| 1141 | mStepDurations[i] = in.readLong(); |
| 1142 | } |
| 1143 | } |
| 1144 | |
| 1145 | public void writeToParcel(Parcel out) { |
| 1146 | final int N = mNumStepDurations; |
| 1147 | out.writeInt(N); |
| 1148 | for (int i=0; i<N; i++) { |
| 1149 | out.writeLong(mStepDurations[i]); |
| 1150 | } |
| 1151 | } |
| 1152 | } |
| 1153 | |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 1154 | public static final class PackageChange { |
| 1155 | public String mPackageName; |
| 1156 | public boolean mUpdate; |
| 1157 | public int mVersionCode; |
| 1158 | } |
| 1159 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 1160 | public static final class DailyItem { |
| 1161 | public long mStartTime; |
| 1162 | public long mEndTime; |
| 1163 | public LevelStepTracker mDischargeSteps; |
| 1164 | public LevelStepTracker mChargeSteps; |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 1165 | public ArrayList<PackageChange> mPackageChanges; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 1166 | } |
| 1167 | |
| 1168 | public abstract DailyItem getDailyItemLocked(int daysAgo); |
| 1169 | |
| 1170 | public abstract long getCurrentDailyStartTime(); |
| 1171 | |
| 1172 | public abstract long getNextMinDailyDeadline(); |
| 1173 | |
| 1174 | public abstract long getNextMaxDailyDeadline(); |
| 1175 | |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 1176 | public abstract long[] getCpuFreqs(); |
| 1177 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1178 | public final static class HistoryTag { |
| 1179 | public String string; |
| 1180 | public int uid; |
| 1181 | |
| 1182 | public int poolIdx; |
| 1183 | |
| 1184 | public void setTo(HistoryTag o) { |
| 1185 | string = o.string; |
| 1186 | uid = o.uid; |
| 1187 | poolIdx = o.poolIdx; |
| 1188 | } |
| 1189 | |
| 1190 | public void setTo(String _string, int _uid) { |
| 1191 | string = _string; |
| 1192 | uid = _uid; |
| 1193 | poolIdx = -1; |
| 1194 | } |
| 1195 | |
| 1196 | public void writeToParcel(Parcel dest, int flags) { |
| 1197 | dest.writeString(string); |
| 1198 | dest.writeInt(uid); |
| 1199 | } |
| 1200 | |
| 1201 | public void readFromParcel(Parcel src) { |
| 1202 | string = src.readString(); |
| 1203 | uid = src.readInt(); |
| 1204 | poolIdx = -1; |
| 1205 | } |
| 1206 | |
| 1207 | @Override |
| 1208 | public boolean equals(Object o) { |
| 1209 | if (this == o) return true; |
| 1210 | if (o == null || getClass() != o.getClass()) return false; |
| 1211 | |
| 1212 | HistoryTag that = (HistoryTag) o; |
| 1213 | |
| 1214 | if (uid != that.uid) return false; |
| 1215 | if (!string.equals(that.string)) return false; |
| 1216 | |
| 1217 | return true; |
| 1218 | } |
| 1219 | |
| 1220 | @Override |
| 1221 | public int hashCode() { |
| 1222 | int result = string.hashCode(); |
| 1223 | result = 31 * result + uid; |
| 1224 | return result; |
| 1225 | } |
| 1226 | } |
| 1227 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 1228 | /** |
| 1229 | * Optional detailed information that can go into a history step. This is typically |
| 1230 | * generated each time the battery level changes. |
| 1231 | */ |
| 1232 | public final static class HistoryStepDetails { |
| 1233 | // Time (in 1/100 second) spent in user space and the kernel since the last step. |
| 1234 | public int userTime; |
| 1235 | public int systemTime; |
| 1236 | |
| 1237 | // Top three apps using CPU in the last step, with times in 1/100 second. |
| 1238 | public int appCpuUid1; |
| 1239 | public int appCpuUTime1; |
| 1240 | public int appCpuSTime1; |
| 1241 | public int appCpuUid2; |
| 1242 | public int appCpuUTime2; |
| 1243 | public int appCpuSTime2; |
| 1244 | public int appCpuUid3; |
| 1245 | public int appCpuUTime3; |
| 1246 | public int appCpuSTime3; |
| 1247 | |
| 1248 | // Information from /proc/stat |
| 1249 | public int statUserTime; |
| 1250 | public int statSystemTime; |
| 1251 | public int statIOWaitTime; |
| 1252 | public int statIrqTime; |
| 1253 | public int statSoftIrqTime; |
| 1254 | public int statIdlTime; |
| 1255 | |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 1256 | // Platform-level low power state stats |
| 1257 | public String statPlatformIdleState; |
Ahmed ElArabawy | d8b4411 | 2017-05-23 21:25:02 +0000 | [diff] [blame] | 1258 | public String statSubsystemPowerState; |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 1259 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 1260 | public HistoryStepDetails() { |
| 1261 | clear(); |
| 1262 | } |
| 1263 | |
| 1264 | public void clear() { |
| 1265 | userTime = systemTime = 0; |
| 1266 | appCpuUid1 = appCpuUid2 = appCpuUid3 = -1; |
| 1267 | appCpuUTime1 = appCpuSTime1 = appCpuUTime2 = appCpuSTime2 |
| 1268 | = appCpuUTime3 = appCpuSTime3 = 0; |
| 1269 | } |
| 1270 | |
| 1271 | public void writeToParcel(Parcel out) { |
| 1272 | out.writeInt(userTime); |
| 1273 | out.writeInt(systemTime); |
| 1274 | out.writeInt(appCpuUid1); |
| 1275 | out.writeInt(appCpuUTime1); |
| 1276 | out.writeInt(appCpuSTime1); |
| 1277 | out.writeInt(appCpuUid2); |
| 1278 | out.writeInt(appCpuUTime2); |
| 1279 | out.writeInt(appCpuSTime2); |
| 1280 | out.writeInt(appCpuUid3); |
| 1281 | out.writeInt(appCpuUTime3); |
| 1282 | out.writeInt(appCpuSTime3); |
| 1283 | out.writeInt(statUserTime); |
| 1284 | out.writeInt(statSystemTime); |
| 1285 | out.writeInt(statIOWaitTime); |
| 1286 | out.writeInt(statIrqTime); |
| 1287 | out.writeInt(statSoftIrqTime); |
| 1288 | out.writeInt(statIdlTime); |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 1289 | out.writeString(statPlatformIdleState); |
Ahmed ElArabawy | d8b4411 | 2017-05-23 21:25:02 +0000 | [diff] [blame] | 1290 | out.writeString(statSubsystemPowerState); |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 1291 | } |
| 1292 | |
| 1293 | public void readFromParcel(Parcel in) { |
| 1294 | userTime = in.readInt(); |
| 1295 | systemTime = in.readInt(); |
| 1296 | appCpuUid1 = in.readInt(); |
| 1297 | appCpuUTime1 = in.readInt(); |
| 1298 | appCpuSTime1 = in.readInt(); |
| 1299 | appCpuUid2 = in.readInt(); |
| 1300 | appCpuUTime2 = in.readInt(); |
| 1301 | appCpuSTime2 = in.readInt(); |
| 1302 | appCpuUid3 = in.readInt(); |
| 1303 | appCpuUTime3 = in.readInt(); |
| 1304 | appCpuSTime3 = in.readInt(); |
| 1305 | statUserTime = in.readInt(); |
| 1306 | statSystemTime = in.readInt(); |
| 1307 | statIOWaitTime = in.readInt(); |
| 1308 | statIrqTime = in.readInt(); |
| 1309 | statSoftIrqTime = in.readInt(); |
| 1310 | statIdlTime = in.readInt(); |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 1311 | statPlatformIdleState = in.readString(); |
Ahmed ElArabawy | d8b4411 | 2017-05-23 21:25:02 +0000 | [diff] [blame] | 1312 | statSubsystemPowerState = in.readString(); |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 1313 | } |
| 1314 | } |
| 1315 | |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 1316 | public final static class HistoryItem implements Parcelable { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1317 | public HistoryItem next; |
Dianne Hackborn | 9a75543 | 2014-05-15 17:05:22 -0700 | [diff] [blame] | 1318 | |
| 1319 | // The time of this event in milliseconds, as per SystemClock.elapsedRealtime(). |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1320 | public long time; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1321 | |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 1322 | 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] | 1323 | public static final byte CMD_NULL = -1; |
| 1324 | public static final byte CMD_START = 4; |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1325 | public static final byte CMD_CURRENT_TIME = 5; |
| 1326 | public static final byte CMD_OVERFLOW = 6; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 1327 | public static final byte CMD_RESET = 7; |
Dianne Hackborn | 29cd7f1 | 2015-01-08 10:37:05 -0800 | [diff] [blame] | 1328 | public static final byte CMD_SHUTDOWN = 8; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1329 | |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 1330 | public byte cmd = CMD_NULL; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 1331 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1332 | /** |
| 1333 | * Return whether the command code is a delta data update. |
| 1334 | */ |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1335 | public boolean isDeltaData() { |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 1336 | return cmd == CMD_UPDATE; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1337 | } |
| 1338 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1339 | public byte batteryLevel; |
| 1340 | public byte batteryStatus; |
| 1341 | public byte batteryHealth; |
| 1342 | public byte batteryPlugType; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 1343 | |
Sungmin Choi | c7e9e8b | 2013-01-16 12:57:36 +0900 | [diff] [blame] | 1344 | public short batteryTemperature; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1345 | public char batteryVoltage; |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 1346 | |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 1347 | // The charge of the battery in micro-Ampere-hours. |
| 1348 | public int batteryChargeUAh; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 1349 | |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 1350 | // Constants from SCREEN_BRIGHTNESS_* |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1351 | public static final int STATE_BRIGHTNESS_SHIFT = 0; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1352 | public static final int STATE_BRIGHTNESS_MASK = 0x7; |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 1353 | // Constants from SIGNAL_STRENGTH_* |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 1354 | public static final int STATE_PHONE_SIGNAL_STRENGTH_SHIFT = 3; |
| 1355 | 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] | 1356 | // Constants from ServiceState.STATE_* |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1357 | public static final int STATE_PHONE_STATE_SHIFT = 6; |
| 1358 | 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] | 1359 | // Constants from DATA_CONNECTION_* |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1360 | public static final int STATE_DATA_CONNECTION_SHIFT = 9; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1361 | 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] | 1362 | |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 1363 | // These states always appear directly in the first int token |
| 1364 | // of a delta change; they should be ones that change relatively |
| 1365 | // frequently. |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1366 | public static final int STATE_CPU_RUNNING_FLAG = 1<<31; |
| 1367 | public static final int STATE_WAKE_LOCK_FLAG = 1<<30; |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 1368 | public static final int STATE_GPS_ON_FLAG = 1<<29; |
| 1369 | public static final int STATE_WIFI_FULL_LOCK_FLAG = 1<<28; |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 1370 | public static final int STATE_WIFI_SCAN_FLAG = 1<<27; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 1371 | public static final int STATE_WIFI_RADIO_ACTIVE_FLAG = 1<<26; |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 1372 | public static final int STATE_MOBILE_RADIO_ACTIVE_FLAG = 1<<25; |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 1373 | // Do not use, this is used for coulomb delta count. |
| 1374 | private static final int STATE_RESERVED_0 = 1<<24; |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 1375 | // These are on the lower bits used for the command; if they change |
| 1376 | // we need to write another int of data. |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1377 | public static final int STATE_SENSOR_ON_FLAG = 1<<23; |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 1378 | public static final int STATE_AUDIO_ON_FLAG = 1<<22; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1379 | public static final int STATE_PHONE_SCANNING_FLAG = 1<<21; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 1380 | public static final int STATE_SCREEN_ON_FLAG = 1<<20; // consider moving to states2 |
| 1381 | public static final int STATE_BATTERY_PLUGGED_FLAG = 1<<19; // consider moving to states2 |
| 1382 | // empty slot |
| 1383 | // empty slot |
| 1384 | public static final int STATE_WIFI_MULTICAST_ON_FLAG = 1<<16; |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 1385 | |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 1386 | public static final int MOST_INTERESTING_STATES = |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 1387 | STATE_BATTERY_PLUGGED_FLAG | STATE_SCREEN_ON_FLAG; |
| 1388 | |
| 1389 | public static final int SETTLE_TO_ZERO_STATES = 0xffff0000 & ~MOST_INTERESTING_STATES; |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 1390 | |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1391 | public int states; |
| 1392 | |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 1393 | // Constants from WIFI_SUPPL_STATE_* |
| 1394 | public static final int STATE2_WIFI_SUPPL_STATE_SHIFT = 0; |
| 1395 | public static final int STATE2_WIFI_SUPPL_STATE_MASK = 0xf; |
| 1396 | // Values for NUM_WIFI_SIGNAL_STRENGTH_BINS |
| 1397 | public static final int STATE2_WIFI_SIGNAL_STRENGTH_SHIFT = 4; |
| 1398 | public static final int STATE2_WIFI_SIGNAL_STRENGTH_MASK = |
| 1399 | 0x7 << STATE2_WIFI_SIGNAL_STRENGTH_SHIFT; |
| 1400 | |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 1401 | public static final int STATE2_POWER_SAVE_FLAG = 1<<31; |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 1402 | public static final int STATE2_VIDEO_ON_FLAG = 1<<30; |
| 1403 | public static final int STATE2_WIFI_RUNNING_FLAG = 1<<29; |
| 1404 | public static final int STATE2_WIFI_ON_FLAG = 1<<28; |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 1405 | public static final int STATE2_FLASHLIGHT_FLAG = 1<<27; |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 1406 | public static final int STATE2_DEVICE_IDLE_SHIFT = 25; |
| 1407 | public static final int STATE2_DEVICE_IDLE_MASK = 0x3 << STATE2_DEVICE_IDLE_SHIFT; |
| 1408 | public static final int STATE2_CHARGING_FLAG = 1<<24; |
| 1409 | public static final int STATE2_PHONE_IN_CALL_FLAG = 1<<23; |
| 1410 | public static final int STATE2_BLUETOOTH_ON_FLAG = 1<<22; |
| 1411 | public static final int STATE2_CAMERA_FLAG = 1<<21; |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 1412 | public static final int STATE2_BLUETOOTH_SCAN_FLAG = 1 << 20; |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 1413 | |
| 1414 | public static final int MOST_INTERESTING_STATES2 = |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 1415 | STATE2_POWER_SAVE_FLAG | STATE2_WIFI_ON_FLAG | STATE2_DEVICE_IDLE_MASK |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 1416 | | STATE2_CHARGING_FLAG | STATE2_PHONE_IN_CALL_FLAG | STATE2_BLUETOOTH_ON_FLAG; |
| 1417 | |
| 1418 | public static final int SETTLE_TO_ZERO_STATES2 = 0xffff0000 & ~MOST_INTERESTING_STATES2; |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 1419 | |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 1420 | public int states2; |
| 1421 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1422 | // The wake lock that was acquired at this point. |
| 1423 | public HistoryTag wakelockTag; |
| 1424 | |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1425 | // Kernel wakeup reason at this point. |
| 1426 | public HistoryTag wakeReasonTag; |
| 1427 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 1428 | // Non-null when there is more detailed information at this step. |
| 1429 | public HistoryStepDetails stepDetails; |
| 1430 | |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 1431 | public static final int EVENT_FLAG_START = 0x8000; |
| 1432 | public static final int EVENT_FLAG_FINISH = 0x4000; |
| 1433 | |
| 1434 | // No event in this item. |
| 1435 | public static final int EVENT_NONE = 0x0000; |
| 1436 | // Event is about a process that is running. |
| 1437 | public static final int EVENT_PROC = 0x0001; |
| 1438 | // Event is about an application package that is in the foreground. |
| 1439 | public static final int EVENT_FOREGROUND = 0x0002; |
| 1440 | // Event is about an application package that is at the top of the screen. |
| 1441 | public static final int EVENT_TOP = 0x0003; |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 1442 | // Event is about active sync operations. |
Dianne Hackborn | a1f1a3c | 2014-02-24 18:12:28 -0800 | [diff] [blame] | 1443 | public static final int EVENT_SYNC = 0x0004; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 1444 | // Events for all additional wake locks aquired/release within a wake block. |
| 1445 | // These are not generated by default. |
| 1446 | public static final int EVENT_WAKE_LOCK = 0x0005; |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 1447 | // Event is about an application executing a scheduled job. |
| 1448 | public static final int EVENT_JOB = 0x0006; |
| 1449 | // Events for users running. |
| 1450 | public static final int EVENT_USER_RUNNING = 0x0007; |
| 1451 | // Events for foreground user. |
| 1452 | public static final int EVENT_USER_FOREGROUND = 0x0008; |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 1453 | // Event for connectivity changed. |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 1454 | public static final int EVENT_CONNECTIVITY_CHANGED = 0x0009; |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 1455 | // Event for becoming active taking us out of idle mode. |
Dianne Hackborn | b6683c4 | 2015-06-18 17:40:33 -0700 | [diff] [blame] | 1456 | public static final int EVENT_ACTIVE = 0x000a; |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 1457 | // Event for a package being installed. |
Dianne Hackborn | b6683c4 | 2015-06-18 17:40:33 -0700 | [diff] [blame] | 1458 | public static final int EVENT_PACKAGE_INSTALLED = 0x000b; |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 1459 | // Event for a package being uninstalled. |
Dianne Hackborn | b6683c4 | 2015-06-18 17:40:33 -0700 | [diff] [blame] | 1460 | public static final int EVENT_PACKAGE_UNINSTALLED = 0x000c; |
Dianne Hackborn | 1e38382 | 2015-04-10 14:02:33 -0700 | [diff] [blame] | 1461 | // Event for a package being uninstalled. |
Dianne Hackborn | b6683c4 | 2015-06-18 17:40:33 -0700 | [diff] [blame] | 1462 | public static final int EVENT_ALARM = 0x000d; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 1463 | // Record that we have decided we need to collect new stats data. |
Dianne Hackborn | b6683c4 | 2015-06-18 17:40:33 -0700 | [diff] [blame] | 1464 | public static final int EVENT_COLLECT_EXTERNAL_STATS = 0x000e; |
Amith Yamasani | 6776849 | 2015-06-09 12:23:58 -0700 | [diff] [blame] | 1465 | // 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] | 1466 | public static final int EVENT_PACKAGE_INACTIVE = 0x000f; |
Amith Yamasani | 6776849 | 2015-06-09 12:23:58 -0700 | [diff] [blame] | 1467 | // Event for a package becoming active due to an interaction. |
Dianne Hackborn | b6683c4 | 2015-06-18 17:40:33 -0700 | [diff] [blame] | 1468 | public static final int EVENT_PACKAGE_ACTIVE = 0x0010; |
Dianne Hackborn | fd854ee | 2015-07-13 18:00:37 -0700 | [diff] [blame] | 1469 | // Event for a package being on the temporary whitelist. |
| 1470 | public static final int EVENT_TEMP_WHITELIST = 0x0011; |
Dianne Hackborn | 280a64e | 2015-07-13 14:48:08 -0700 | [diff] [blame] | 1471 | // Event for the screen waking up. |
| 1472 | public static final int EVENT_SCREEN_WAKE_UP = 0x0012; |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 1473 | // Event for the UID that woke up the application processor. |
| 1474 | // Used for wakeups coming from WiFi, modem, etc. |
| 1475 | public static final int EVENT_WAKEUP_AP = 0x0013; |
Dianne Hackborn | d0db6f0 | 2016-07-18 14:14:20 -0700 | [diff] [blame] | 1476 | // Event for reporting that a specific partial wake lock has been held for a long duration. |
| 1477 | public static final int EVENT_LONG_WAKE_LOCK = 0x0014; |
Amith Yamasani | 6776849 | 2015-06-09 12:23:58 -0700 | [diff] [blame] | 1478 | |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 1479 | // Number of event types. |
Adam Lesinski | 041d917 | 2016-12-12 12:03:56 -0800 | [diff] [blame] | 1480 | public static final int EVENT_COUNT = 0x0016; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 1481 | // Mask to extract out only the type part of the event. |
| 1482 | 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] | 1483 | |
| 1484 | public static final int EVENT_PROC_START = EVENT_PROC | EVENT_FLAG_START; |
| 1485 | public static final int EVENT_PROC_FINISH = EVENT_PROC | EVENT_FLAG_FINISH; |
| 1486 | public static final int EVENT_FOREGROUND_START = EVENT_FOREGROUND | EVENT_FLAG_START; |
| 1487 | public static final int EVENT_FOREGROUND_FINISH = EVENT_FOREGROUND | EVENT_FLAG_FINISH; |
| 1488 | public static final int EVENT_TOP_START = EVENT_TOP | EVENT_FLAG_START; |
| 1489 | public static final int EVENT_TOP_FINISH = EVENT_TOP | EVENT_FLAG_FINISH; |
Dianne Hackborn | a1f1a3c | 2014-02-24 18:12:28 -0800 | [diff] [blame] | 1490 | public static final int EVENT_SYNC_START = EVENT_SYNC | EVENT_FLAG_START; |
| 1491 | public static final int EVENT_SYNC_FINISH = EVENT_SYNC | EVENT_FLAG_FINISH; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 1492 | public static final int EVENT_WAKE_LOCK_START = EVENT_WAKE_LOCK | EVENT_FLAG_START; |
| 1493 | 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] | 1494 | public static final int EVENT_JOB_START = EVENT_JOB | EVENT_FLAG_START; |
| 1495 | public static final int EVENT_JOB_FINISH = EVENT_JOB | EVENT_FLAG_FINISH; |
| 1496 | public static final int EVENT_USER_RUNNING_START = EVENT_USER_RUNNING | EVENT_FLAG_START; |
| 1497 | public static final int EVENT_USER_RUNNING_FINISH = EVENT_USER_RUNNING | EVENT_FLAG_FINISH; |
| 1498 | public static final int EVENT_USER_FOREGROUND_START = |
| 1499 | EVENT_USER_FOREGROUND | EVENT_FLAG_START; |
| 1500 | public static final int EVENT_USER_FOREGROUND_FINISH = |
| 1501 | EVENT_USER_FOREGROUND | EVENT_FLAG_FINISH; |
Dianne Hackborn | 1e38382 | 2015-04-10 14:02:33 -0700 | [diff] [blame] | 1502 | public static final int EVENT_ALARM_START = EVENT_ALARM | EVENT_FLAG_START; |
| 1503 | public static final int EVENT_ALARM_FINISH = EVENT_ALARM | EVENT_FLAG_FINISH; |
Dianne Hackborn | fd854ee | 2015-07-13 18:00:37 -0700 | [diff] [blame] | 1504 | public static final int EVENT_TEMP_WHITELIST_START = |
| 1505 | EVENT_TEMP_WHITELIST | EVENT_FLAG_START; |
| 1506 | public static final int EVENT_TEMP_WHITELIST_FINISH = |
| 1507 | EVENT_TEMP_WHITELIST | EVENT_FLAG_FINISH; |
Dianne Hackborn | d0db6f0 | 2016-07-18 14:14:20 -0700 | [diff] [blame] | 1508 | public static final int EVENT_LONG_WAKE_LOCK_START = |
| 1509 | EVENT_LONG_WAKE_LOCK | EVENT_FLAG_START; |
| 1510 | public static final int EVENT_LONG_WAKE_LOCK_FINISH = |
| 1511 | EVENT_LONG_WAKE_LOCK | EVENT_FLAG_FINISH; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1512 | |
| 1513 | // For CMD_EVENT. |
| 1514 | public int eventCode; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1515 | public HistoryTag eventTag; |
| 1516 | |
Dianne Hackborn | 9a75543 | 2014-05-15 17:05:22 -0700 | [diff] [blame] | 1517 | // 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] | 1518 | public long currentTime; |
| 1519 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1520 | // Meta-data when reading. |
| 1521 | public int numReadInts; |
| 1522 | |
| 1523 | // Pre-allocated objects. |
| 1524 | public final HistoryTag localWakelockTag = new HistoryTag(); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1525 | public final HistoryTag localWakeReasonTag = new HistoryTag(); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1526 | public final HistoryTag localEventTag = new HistoryTag(); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1527 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1528 | public HistoryItem() { |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1529 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 1530 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1531 | public HistoryItem(long time, Parcel src) { |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1532 | this.time = time; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1533 | numReadInts = 2; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 1534 | readFromParcel(src); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1535 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 1536 | |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1537 | public int describeContents() { |
| 1538 | return 0; |
| 1539 | } |
| 1540 | |
| 1541 | public void writeToParcel(Parcel dest, int flags) { |
| 1542 | dest.writeLong(time); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1543 | int bat = (((int)cmd)&0xff) |
| 1544 | | ((((int)batteryLevel)<<8)&0xff00) |
| 1545 | | ((((int)batteryStatus)<<16)&0xf0000) |
| 1546 | | ((((int)batteryHealth)<<20)&0xf00000) |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1547 | | ((((int)batteryPlugType)<<24)&0xf000000) |
| 1548 | | (wakelockTag != null ? 0x10000000 : 0) |
| 1549 | | (wakeReasonTag != null ? 0x20000000 : 0) |
| 1550 | | (eventCode != EVENT_NONE ? 0x40000000 : 0); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1551 | dest.writeInt(bat); |
| 1552 | bat = (((int)batteryTemperature)&0xffff) |
| 1553 | | ((((int)batteryVoltage)<<16)&0xffff0000); |
| 1554 | dest.writeInt(bat); |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 1555 | dest.writeInt(batteryChargeUAh); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1556 | dest.writeInt(states); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1557 | dest.writeInt(states2); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1558 | if (wakelockTag != null) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1559 | wakelockTag.writeToParcel(dest, flags); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1560 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1561 | if (wakeReasonTag != null) { |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1562 | wakeReasonTag.writeToParcel(dest, flags); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1563 | } |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 1564 | if (eventCode != EVENT_NONE) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1565 | dest.writeInt(eventCode); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1566 | eventTag.writeToParcel(dest, flags); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1567 | } |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 1568 | if (cmd == CMD_CURRENT_TIME || cmd == CMD_RESET) { |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1569 | dest.writeLong(currentTime); |
| 1570 | } |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1571 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 1572 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1573 | public void readFromParcel(Parcel src) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1574 | int start = src.dataPosition(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 1575 | int bat = src.readInt(); |
| 1576 | cmd = (byte)(bat&0xff); |
| 1577 | batteryLevel = (byte)((bat>>8)&0xff); |
| 1578 | batteryStatus = (byte)((bat>>16)&0xf); |
| 1579 | batteryHealth = (byte)((bat>>20)&0xf); |
| 1580 | batteryPlugType = (byte)((bat>>24)&0xf); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1581 | int bat2 = src.readInt(); |
| 1582 | batteryTemperature = (short)(bat2&0xffff); |
| 1583 | batteryVoltage = (char)((bat2>>16)&0xffff); |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 1584 | batteryChargeUAh = src.readInt(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 1585 | states = src.readInt(); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1586 | states2 = src.readInt(); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1587 | if ((bat&0x10000000) != 0) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1588 | wakelockTag = localWakelockTag; |
| 1589 | wakelockTag.readFromParcel(src); |
| 1590 | } else { |
| 1591 | wakelockTag = null; |
| 1592 | } |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1593 | if ((bat&0x20000000) != 0) { |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1594 | wakeReasonTag = localWakeReasonTag; |
| 1595 | wakeReasonTag.readFromParcel(src); |
| 1596 | } else { |
| 1597 | wakeReasonTag = null; |
| 1598 | } |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1599 | if ((bat&0x40000000) != 0) { |
| 1600 | eventCode = src.readInt(); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1601 | eventTag = localEventTag; |
| 1602 | eventTag.readFromParcel(src); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1603 | } else { |
| 1604 | eventCode = EVENT_NONE; |
| 1605 | eventTag = null; |
| 1606 | } |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 1607 | if (cmd == CMD_CURRENT_TIME || cmd == CMD_RESET) { |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1608 | currentTime = src.readLong(); |
| 1609 | } else { |
| 1610 | currentTime = 0; |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 1611 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1612 | numReadInts += (src.dataPosition()-start)/4; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 1613 | } |
| 1614 | |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 1615 | public void clear() { |
| 1616 | time = 0; |
| 1617 | cmd = CMD_NULL; |
| 1618 | batteryLevel = 0; |
| 1619 | batteryStatus = 0; |
| 1620 | batteryHealth = 0; |
| 1621 | batteryPlugType = 0; |
| 1622 | batteryTemperature = 0; |
| 1623 | batteryVoltage = 0; |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 1624 | batteryChargeUAh = 0; |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 1625 | states = 0; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1626 | states2 = 0; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1627 | wakelockTag = null; |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1628 | wakeReasonTag = null; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1629 | eventCode = EVENT_NONE; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1630 | eventTag = null; |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 1631 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 1632 | |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 1633 | public void setTo(HistoryItem o) { |
| 1634 | time = o.time; |
| 1635 | cmd = o.cmd; |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 1636 | setToCommon(o); |
| 1637 | } |
| 1638 | |
| 1639 | public void setTo(long time, byte cmd, HistoryItem o) { |
| 1640 | this.time = time; |
| 1641 | this.cmd = cmd; |
| 1642 | setToCommon(o); |
| 1643 | } |
| 1644 | |
| 1645 | private void setToCommon(HistoryItem o) { |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 1646 | batteryLevel = o.batteryLevel; |
| 1647 | batteryStatus = o.batteryStatus; |
| 1648 | batteryHealth = o.batteryHealth; |
| 1649 | batteryPlugType = o.batteryPlugType; |
| 1650 | batteryTemperature = o.batteryTemperature; |
| 1651 | batteryVoltage = o.batteryVoltage; |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 1652 | batteryChargeUAh = o.batteryChargeUAh; |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 1653 | states = o.states; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1654 | states2 = o.states2; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1655 | if (o.wakelockTag != null) { |
| 1656 | wakelockTag = localWakelockTag; |
| 1657 | wakelockTag.setTo(o.wakelockTag); |
| 1658 | } else { |
| 1659 | wakelockTag = null; |
| 1660 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1661 | if (o.wakeReasonTag != null) { |
| 1662 | wakeReasonTag = localWakeReasonTag; |
| 1663 | wakeReasonTag.setTo(o.wakeReasonTag); |
| 1664 | } else { |
| 1665 | wakeReasonTag = null; |
| 1666 | } |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1667 | eventCode = o.eventCode; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1668 | if (o.eventTag != null) { |
| 1669 | eventTag = localEventTag; |
| 1670 | eventTag.setTo(o.eventTag); |
| 1671 | } else { |
| 1672 | eventTag = null; |
| 1673 | } |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1674 | currentTime = o.currentTime; |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 1675 | } |
| 1676 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1677 | public boolean sameNonEvent(HistoryItem o) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 1678 | return batteryLevel == o.batteryLevel |
| 1679 | && batteryStatus == o.batteryStatus |
| 1680 | && batteryHealth == o.batteryHealth |
| 1681 | && batteryPlugType == o.batteryPlugType |
| 1682 | && batteryTemperature == o.batteryTemperature |
| 1683 | && batteryVoltage == o.batteryVoltage |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 1684 | && batteryChargeUAh == o.batteryChargeUAh |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1685 | && states == o.states |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1686 | && states2 == o.states2 |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1687 | && currentTime == o.currentTime; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 1688 | } |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1689 | |
| 1690 | public boolean same(HistoryItem o) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1691 | if (!sameNonEvent(o) || eventCode != o.eventCode) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1692 | return false; |
| 1693 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1694 | if (wakelockTag != o.wakelockTag) { |
| 1695 | if (wakelockTag == null || o.wakelockTag == null) { |
| 1696 | return false; |
| 1697 | } |
| 1698 | if (!wakelockTag.equals(o.wakelockTag)) { |
| 1699 | return false; |
| 1700 | } |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1701 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1702 | if (wakeReasonTag != o.wakeReasonTag) { |
| 1703 | if (wakeReasonTag == null || o.wakeReasonTag == null) { |
| 1704 | return false; |
| 1705 | } |
| 1706 | if (!wakeReasonTag.equals(o.wakeReasonTag)) { |
| 1707 | return false; |
| 1708 | } |
| 1709 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1710 | if (eventTag != o.eventTag) { |
| 1711 | if (eventTag == null || o.eventTag == null) { |
| 1712 | return false; |
| 1713 | } |
| 1714 | if (!eventTag.equals(o.eventTag)) { |
| 1715 | return false; |
| 1716 | } |
| 1717 | } |
| 1718 | return true; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1719 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1720 | } |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 1721 | |
| 1722 | public final static class HistoryEventTracker { |
| 1723 | private final HashMap<String, SparseIntArray>[] mActiveEvents |
| 1724 | = (HashMap<String, SparseIntArray>[]) new HashMap[HistoryItem.EVENT_COUNT]; |
| 1725 | |
| 1726 | public boolean updateState(int code, String name, int uid, int poolIdx) { |
| 1727 | if ((code&HistoryItem.EVENT_FLAG_START) != 0) { |
| 1728 | int idx = code&HistoryItem.EVENT_TYPE_MASK; |
| 1729 | HashMap<String, SparseIntArray> active = mActiveEvents[idx]; |
| 1730 | if (active == null) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 1731 | active = new HashMap<>(); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 1732 | mActiveEvents[idx] = active; |
| 1733 | } |
| 1734 | SparseIntArray uids = active.get(name); |
| 1735 | if (uids == null) { |
| 1736 | uids = new SparseIntArray(); |
| 1737 | active.put(name, uids); |
| 1738 | } |
| 1739 | if (uids.indexOfKey(uid) >= 0) { |
| 1740 | // Already set, nothing to do! |
| 1741 | return false; |
| 1742 | } |
| 1743 | uids.put(uid, poolIdx); |
| 1744 | } else if ((code&HistoryItem.EVENT_FLAG_FINISH) != 0) { |
| 1745 | int idx = code&HistoryItem.EVENT_TYPE_MASK; |
| 1746 | HashMap<String, SparseIntArray> active = mActiveEvents[idx]; |
| 1747 | if (active == null) { |
| 1748 | // not currently active, nothing to do. |
| 1749 | return false; |
| 1750 | } |
| 1751 | SparseIntArray uids = active.get(name); |
| 1752 | if (uids == null) { |
| 1753 | // not currently active, nothing to do. |
| 1754 | return false; |
| 1755 | } |
| 1756 | idx = uids.indexOfKey(uid); |
| 1757 | if (idx < 0) { |
| 1758 | // not currently active, nothing to do. |
| 1759 | return false; |
| 1760 | } |
| 1761 | uids.removeAt(idx); |
| 1762 | if (uids.size() <= 0) { |
| 1763 | active.remove(name); |
| 1764 | } |
| 1765 | } |
| 1766 | return true; |
| 1767 | } |
| 1768 | |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 1769 | public void removeEvents(int code) { |
| 1770 | int idx = code&HistoryItem.EVENT_TYPE_MASK; |
| 1771 | mActiveEvents[idx] = null; |
| 1772 | } |
| 1773 | |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 1774 | public HashMap<String, SparseIntArray> getStateForEvent(int code) { |
| 1775 | return mActiveEvents[code]; |
| 1776 | } |
| 1777 | } |
| 1778 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1779 | public static final class BitDescription { |
| 1780 | public final int mask; |
| 1781 | public final int shift; |
| 1782 | public final String name; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1783 | public final String shortName; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1784 | public final String[] values; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1785 | public final String[] shortValues; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 1786 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1787 | public BitDescription(int mask, String name, String shortName) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1788 | this.mask = mask; |
| 1789 | this.shift = -1; |
| 1790 | this.name = name; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1791 | this.shortName = shortName; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1792 | this.values = null; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1793 | this.shortValues = null; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1794 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 1795 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1796 | public BitDescription(int mask, int shift, String name, String shortName, |
| 1797 | String[] values, String[] shortValues) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1798 | this.mask = mask; |
| 1799 | this.shift = shift; |
| 1800 | this.name = name; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1801 | this.shortName = shortName; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1802 | this.values = values; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1803 | this.shortValues = shortValues; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1804 | } |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1805 | } |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 1806 | |
Dianne Hackborn | fc06413 | 2014-06-02 12:42:12 -0700 | [diff] [blame] | 1807 | /** |
| 1808 | * Don't allow any more batching in to the current history event. This |
| 1809 | * is called when printing partial histories, so to ensure that the next |
| 1810 | * history event will go in to a new batch after what was printed in the |
| 1811 | * last partial history. |
| 1812 | */ |
| 1813 | public abstract void commitCurrentHistoryBatchLocked(); |
| 1814 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1815 | public abstract int getHistoryTotalSize(); |
| 1816 | |
| 1817 | public abstract int getHistoryUsedSize(); |
| 1818 | |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 1819 | public abstract boolean startIteratingHistoryLocked(); |
| 1820 | |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 1821 | public abstract int getHistoryStringPoolSize(); |
| 1822 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1823 | public abstract int getHistoryStringPoolBytes(); |
| 1824 | |
| 1825 | public abstract String getHistoryTagPoolString(int index); |
| 1826 | |
| 1827 | public abstract int getHistoryTagPoolUid(int index); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 1828 | |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 1829 | public abstract boolean getNextHistoryLocked(HistoryItem out); |
| 1830 | |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 1831 | public abstract void finishIteratingHistoryLocked(); |
| 1832 | |
| 1833 | public abstract boolean startIteratingOldHistoryLocked(); |
| 1834 | |
| 1835 | public abstract boolean getNextOldHistoryLocked(HistoryItem out); |
| 1836 | |
| 1837 | public abstract void finishIteratingOldHistoryLocked(); |
| 1838 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1839 | /** |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 1840 | * Return the base time offset for the battery history. |
| 1841 | */ |
| 1842 | public abstract long getHistoryBaseTime(); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 1843 | |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 1844 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1845 | * Returns the number of times the device has been started. |
| 1846 | */ |
| 1847 | public abstract int getStartCount(); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 1848 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1849 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 1850 | * 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] | 1851 | * running on battery. |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 1852 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1853 | * {@hide} |
| 1854 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1855 | public abstract long getScreenOnTime(long elapsedRealtimeUs, int which); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 1856 | |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 1857 | /** |
| 1858 | * Returns the number of times the screen was turned on. |
| 1859 | * |
| 1860 | * {@hide} |
| 1861 | */ |
| 1862 | public abstract int getScreenOnCount(int which); |
| 1863 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 1864 | public abstract long getInteractiveTime(long elapsedRealtimeUs, int which); |
| 1865 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1866 | public static final int SCREEN_BRIGHTNESS_DARK = 0; |
| 1867 | public static final int SCREEN_BRIGHTNESS_DIM = 1; |
| 1868 | public static final int SCREEN_BRIGHTNESS_MEDIUM = 2; |
| 1869 | public static final int SCREEN_BRIGHTNESS_LIGHT = 3; |
| 1870 | public static final int SCREEN_BRIGHTNESS_BRIGHT = 4; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 1871 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1872 | static final String[] SCREEN_BRIGHTNESS_NAMES = { |
| 1873 | "dark", "dim", "medium", "light", "bright" |
| 1874 | }; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 1875 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1876 | static final String[] SCREEN_BRIGHTNESS_SHORT_NAMES = { |
| 1877 | "0", "1", "2", "3", "4" |
| 1878 | }; |
| 1879 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1880 | public static final int NUM_SCREEN_BRIGHTNESS_BINS = 5; |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 1881 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1882 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 1883 | * Returns the time in microseconds that the screen has been on with |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1884 | * the given brightness |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 1885 | * |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1886 | * {@hide} |
| 1887 | */ |
| 1888 | public abstract long getScreenBrightnessTime(int brightnessBin, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1889 | long elapsedRealtimeUs, int which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1890 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1891 | /** |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 1892 | * 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] | 1893 | * running on battery. |
| 1894 | * |
| 1895 | * {@hide} |
| 1896 | */ |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 1897 | public abstract long getPowerSaveModeEnabledTime(long elapsedRealtimeUs, int which); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 1898 | |
| 1899 | /** |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 1900 | * Returns the number of times that power save mode was enabled. |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 1901 | * |
| 1902 | * {@hide} |
| 1903 | */ |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 1904 | public abstract int getPowerSaveModeEnabledCount(int which); |
| 1905 | |
| 1906 | /** |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 1907 | * Constant for device idle mode: not active. |
| 1908 | */ |
| 1909 | public static final int DEVICE_IDLE_MODE_OFF = 0; |
| 1910 | |
| 1911 | /** |
| 1912 | * Constant for device idle mode: active in lightweight mode. |
| 1913 | */ |
| 1914 | public static final int DEVICE_IDLE_MODE_LIGHT = 1; |
| 1915 | |
| 1916 | /** |
| 1917 | * Constant for device idle mode: active in full mode. |
| 1918 | */ |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 1919 | public static final int DEVICE_IDLE_MODE_DEEP = 2; |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 1920 | |
| 1921 | /** |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 1922 | * Returns the time in microseconds that device has been in idle mode while |
| 1923 | * running on battery. |
| 1924 | * |
| 1925 | * {@hide} |
| 1926 | */ |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 1927 | public abstract long getDeviceIdleModeTime(int mode, long elapsedRealtimeUs, int which); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 1928 | |
| 1929 | /** |
| 1930 | * Returns the number of times that the devie has gone in to idle mode. |
| 1931 | * |
| 1932 | * {@hide} |
| 1933 | */ |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 1934 | public abstract int getDeviceIdleModeCount(int mode, int which); |
| 1935 | |
| 1936 | /** |
| 1937 | * Return the longest duration we spent in a particular device idle mode (fully in the |
| 1938 | * mode, not in idle maintenance etc). |
| 1939 | */ |
| 1940 | public abstract long getLongestDeviceIdleModeTime(int mode); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 1941 | |
| 1942 | /** |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 1943 | * 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] | 1944 | * battery. This is broader than {@link #getDeviceIdleModeTime} -- it |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 1945 | * counts all of the time that we consider the device to be idle, whether or not |
| 1946 | * it is currently in the actual device idle mode. |
| 1947 | * |
| 1948 | * {@hide} |
| 1949 | */ |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 1950 | public abstract long getDeviceIdlingTime(int mode, long elapsedRealtimeUs, int which); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 1951 | |
| 1952 | /** |
| 1953 | * Returns the number of times that the devie has started idling. |
| 1954 | * |
| 1955 | * {@hide} |
| 1956 | */ |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 1957 | public abstract int getDeviceIdlingCount(int mode, int which); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 1958 | |
| 1959 | /** |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 1960 | * Returns the number of times that connectivity state changed. |
| 1961 | * |
| 1962 | * {@hide} |
| 1963 | */ |
| 1964 | public abstract int getNumConnectivityChange(int which); |
| 1965 | |
| 1966 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 1967 | * 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] | 1968 | * running on battery. |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 1969 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1970 | * {@hide} |
| 1971 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1972 | public abstract long getPhoneOnTime(long elapsedRealtimeUs, int which); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 1973 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 1974 | /** |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 1975 | * Returns the number of times a phone call was activated. |
| 1976 | * |
| 1977 | * {@hide} |
| 1978 | */ |
| 1979 | public abstract int getPhoneOnCount(int which); |
| 1980 | |
| 1981 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 1982 | * Returns the time in microseconds that the phone has been running with |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 1983 | * the given signal strength. |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 1984 | * |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 1985 | * {@hide} |
| 1986 | */ |
| 1987 | public abstract long getPhoneSignalStrengthTime(int strengthBin, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1988 | long elapsedRealtimeUs, int which); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 1989 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1990 | /** |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 1991 | * Returns the time in microseconds that the phone has been trying to |
| 1992 | * acquire a signal. |
| 1993 | * |
| 1994 | * {@hide} |
| 1995 | */ |
| 1996 | public abstract long getPhoneSignalScanningTime( |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1997 | long elapsedRealtimeUs, int which); |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 1998 | |
| 1999 | /** |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2000 | * Returns the number of times the phone has entered the given signal strength. |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2001 | * |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2002 | * {@hide} |
| 2003 | */ |
| 2004 | public abstract int getPhoneSignalStrengthCount(int strengthBin, int which); |
| 2005 | |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 2006 | /** |
| 2007 | * Returns the time in microseconds that the mobile network has been active |
| 2008 | * (in a high power state). |
| 2009 | * |
| 2010 | * {@hide} |
| 2011 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2012 | public abstract long getMobileRadioActiveTime(long elapsedRealtimeUs, int which); |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 2013 | |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 2014 | /** |
| 2015 | * Returns the number of times that the mobile network has transitioned to the |
| 2016 | * active state. |
| 2017 | * |
| 2018 | * {@hide} |
| 2019 | */ |
| 2020 | public abstract int getMobileRadioActiveCount(int which); |
| 2021 | |
| 2022 | /** |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2023 | * Returns the time in microseconds that is the difference between the mobile radio |
| 2024 | * time we saw based on the elapsed timestamp when going down vs. the given time stamp |
| 2025 | * from the radio. |
| 2026 | * |
| 2027 | * {@hide} |
| 2028 | */ |
| 2029 | public abstract long getMobileRadioActiveAdjustedTime(int which); |
| 2030 | |
| 2031 | /** |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 2032 | * Returns the time in microseconds that the mobile network has been active |
| 2033 | * (in a high power state) but not being able to blame on an app. |
| 2034 | * |
| 2035 | * {@hide} |
| 2036 | */ |
| 2037 | public abstract long getMobileRadioActiveUnknownTime(int which); |
| 2038 | |
| 2039 | /** |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 2040 | * 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] | 2041 | * |
| 2042 | * {@hide} |
| 2043 | */ |
| 2044 | public abstract int getMobileRadioActiveUnknownCount(int which); |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 2045 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 2046 | public static final int DATA_CONNECTION_NONE = 0; |
| 2047 | public static final int DATA_CONNECTION_GPRS = 1; |
| 2048 | public static final int DATA_CONNECTION_EDGE = 2; |
| 2049 | public static final int DATA_CONNECTION_UMTS = 3; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2050 | public static final int DATA_CONNECTION_CDMA = 4; |
| 2051 | public static final int DATA_CONNECTION_EVDO_0 = 5; |
| 2052 | public static final int DATA_CONNECTION_EVDO_A = 6; |
| 2053 | public static final int DATA_CONNECTION_1xRTT = 7; |
| 2054 | public static final int DATA_CONNECTION_HSDPA = 8; |
| 2055 | public static final int DATA_CONNECTION_HSUPA = 9; |
| 2056 | public static final int DATA_CONNECTION_HSPA = 10; |
| 2057 | public static final int DATA_CONNECTION_IDEN = 11; |
| 2058 | public static final int DATA_CONNECTION_EVDO_B = 12; |
Robert Greenwalt | 962a990 | 2010-11-02 11:10:25 -0700 | [diff] [blame] | 2059 | public static final int DATA_CONNECTION_LTE = 13; |
| 2060 | public static final int DATA_CONNECTION_EHRPD = 14; |
Patrick Tjin | b71703c | 2013-11-06 09:27:03 -0800 | [diff] [blame] | 2061 | public static final int DATA_CONNECTION_HSPAP = 15; |
| 2062 | public static final int DATA_CONNECTION_OTHER = 16; |
Robert Greenwalt | 962a990 | 2010-11-02 11:10:25 -0700 | [diff] [blame] | 2063 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 2064 | static final String[] DATA_CONNECTION_NAMES = { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2065 | "none", "gprs", "edge", "umts", "cdma", "evdo_0", "evdo_A", |
Robert Greenwalt | 962a990 | 2010-11-02 11:10:25 -0700 | [diff] [blame] | 2066 | "1xrtt", "hsdpa", "hsupa", "hspa", "iden", "evdo_b", "lte", |
Patrick Tjin | b71703c | 2013-11-06 09:27:03 -0800 | [diff] [blame] | 2067 | "ehrpd", "hspap", "other" |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 2068 | }; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2069 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2070 | public static final int NUM_DATA_CONNECTION_TYPES = DATA_CONNECTION_OTHER+1; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2071 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 2072 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 2073 | * Returns the time in microseconds that the phone has been running with |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 2074 | * the given data connection. |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2075 | * |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 2076 | * {@hide} |
| 2077 | */ |
| 2078 | public abstract long getPhoneDataConnectionTime(int dataType, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2079 | long elapsedRealtimeUs, int which); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 2080 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2081 | /** |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2082 | * Returns the number of times the phone has entered the given data |
| 2083 | * connection type. |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2084 | * |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2085 | * {@hide} |
| 2086 | */ |
| 2087 | public abstract int getPhoneDataConnectionCount(int dataType, int which); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2088 | |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 2089 | public static final int WIFI_SUPPL_STATE_INVALID = 0; |
| 2090 | public static final int WIFI_SUPPL_STATE_DISCONNECTED = 1; |
| 2091 | public static final int WIFI_SUPPL_STATE_INTERFACE_DISABLED = 2; |
| 2092 | public static final int WIFI_SUPPL_STATE_INACTIVE = 3; |
| 2093 | public static final int WIFI_SUPPL_STATE_SCANNING = 4; |
| 2094 | public static final int WIFI_SUPPL_STATE_AUTHENTICATING = 5; |
| 2095 | public static final int WIFI_SUPPL_STATE_ASSOCIATING = 6; |
| 2096 | public static final int WIFI_SUPPL_STATE_ASSOCIATED = 7; |
| 2097 | public static final int WIFI_SUPPL_STATE_FOUR_WAY_HANDSHAKE = 8; |
| 2098 | public static final int WIFI_SUPPL_STATE_GROUP_HANDSHAKE = 9; |
| 2099 | public static final int WIFI_SUPPL_STATE_COMPLETED = 10; |
| 2100 | public static final int WIFI_SUPPL_STATE_DORMANT = 11; |
| 2101 | public static final int WIFI_SUPPL_STATE_UNINITIALIZED = 12; |
| 2102 | |
| 2103 | public static final int NUM_WIFI_SUPPL_STATES = WIFI_SUPPL_STATE_UNINITIALIZED+1; |
| 2104 | |
| 2105 | static final String[] WIFI_SUPPL_STATE_NAMES = { |
| 2106 | "invalid", "disconn", "disabled", "inactive", "scanning", |
| 2107 | "authenticating", "associating", "associated", "4-way-handshake", |
| 2108 | "group-handshake", "completed", "dormant", "uninit" |
| 2109 | }; |
| 2110 | |
| 2111 | static final String[] WIFI_SUPPL_STATE_SHORT_NAMES = { |
| 2112 | "inv", "dsc", "dis", "inact", "scan", |
| 2113 | "auth", "ascing", "asced", "4-way", |
| 2114 | "group", "compl", "dorm", "uninit" |
| 2115 | }; |
| 2116 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2117 | public static final BitDescription[] HISTORY_STATE_DESCRIPTIONS |
| 2118 | = new BitDescription[] { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2119 | new BitDescription(HistoryItem.STATE_CPU_RUNNING_FLAG, "running", "r"), |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2120 | new BitDescription(HistoryItem.STATE_WAKE_LOCK_FLAG, "wake_lock", "w"), |
| 2121 | new BitDescription(HistoryItem.STATE_SENSOR_ON_FLAG, "sensor", "s"), |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2122 | new BitDescription(HistoryItem.STATE_GPS_ON_FLAG, "gps", "g"), |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2123 | new BitDescription(HistoryItem.STATE_WIFI_FULL_LOCK_FLAG, "wifi_full_lock", "Wl"), |
| 2124 | new BitDescription(HistoryItem.STATE_WIFI_SCAN_FLAG, "wifi_scan", "Ws"), |
| 2125 | new BitDescription(HistoryItem.STATE_WIFI_MULTICAST_ON_FLAG, "wifi_multicast", "Wm"), |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 2126 | new BitDescription(HistoryItem.STATE_WIFI_RADIO_ACTIVE_FLAG, "wifi_radio", "Wr"), |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 2127 | new BitDescription(HistoryItem.STATE_MOBILE_RADIO_ACTIVE_FLAG, "mobile_radio", "Pr"), |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2128 | new BitDescription(HistoryItem.STATE_PHONE_SCANNING_FLAG, "phone_scanning", "Psc"), |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2129 | new BitDescription(HistoryItem.STATE_AUDIO_ON_FLAG, "audio", "a"), |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2130 | new BitDescription(HistoryItem.STATE_SCREEN_ON_FLAG, "screen", "S"), |
| 2131 | new BitDescription(HistoryItem.STATE_BATTERY_PLUGGED_FLAG, "plugged", "BP"), |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2132 | new BitDescription(HistoryItem.STATE_DATA_CONNECTION_MASK, |
| 2133 | HistoryItem.STATE_DATA_CONNECTION_SHIFT, "data_conn", "Pcn", |
| 2134 | DATA_CONNECTION_NAMES, DATA_CONNECTION_NAMES), |
| 2135 | new BitDescription(HistoryItem.STATE_PHONE_STATE_MASK, |
| 2136 | HistoryItem.STATE_PHONE_STATE_SHIFT, "phone_state", "Pst", |
| 2137 | new String[] {"in", "out", "emergency", "off"}, |
| 2138 | new String[] {"in", "out", "em", "off"}), |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 2139 | new BitDescription(HistoryItem.STATE_PHONE_SIGNAL_STRENGTH_MASK, |
| 2140 | HistoryItem.STATE_PHONE_SIGNAL_STRENGTH_SHIFT, "phone_signal_strength", "Pss", |
| 2141 | SignalStrength.SIGNAL_STRENGTH_NAMES, |
| 2142 | new String[] { "0", "1", "2", "3", "4" }), |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2143 | new BitDescription(HistoryItem.STATE_BRIGHTNESS_MASK, |
| 2144 | HistoryItem.STATE_BRIGHTNESS_SHIFT, "brightness", "Sb", |
| 2145 | SCREEN_BRIGHTNESS_NAMES, SCREEN_BRIGHTNESS_SHORT_NAMES), |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2146 | }; |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2147 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2148 | public static final BitDescription[] HISTORY_STATE2_DESCRIPTIONS |
| 2149 | = new BitDescription[] { |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 2150 | new BitDescription(HistoryItem.STATE2_POWER_SAVE_FLAG, "power_save", "ps"), |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 2151 | new BitDescription(HistoryItem.STATE2_VIDEO_ON_FLAG, "video", "v"), |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 2152 | new BitDescription(HistoryItem.STATE2_WIFI_RUNNING_FLAG, "wifi_running", "Ww"), |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 2153 | new BitDescription(HistoryItem.STATE2_WIFI_ON_FLAG, "wifi", "W"), |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 2154 | new BitDescription(HistoryItem.STATE2_FLASHLIGHT_FLAG, "flashlight", "fl"), |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 2155 | new BitDescription(HistoryItem.STATE2_DEVICE_IDLE_MASK, |
| 2156 | HistoryItem.STATE2_DEVICE_IDLE_SHIFT, "device_idle", "di", |
| 2157 | new String[] { "off", "light", "full", "???" }, |
| 2158 | new String[] { "off", "light", "full", "???" }), |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 2159 | new BitDescription(HistoryItem.STATE2_CHARGING_FLAG, "charging", "ch"), |
| 2160 | new BitDescription(HistoryItem.STATE2_PHONE_IN_CALL_FLAG, "phone_in_call", "Pcl"), |
| 2161 | new BitDescription(HistoryItem.STATE2_BLUETOOTH_ON_FLAG, "bluetooth", "b"), |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 2162 | new BitDescription(HistoryItem.STATE2_WIFI_SIGNAL_STRENGTH_MASK, |
| 2163 | HistoryItem.STATE2_WIFI_SIGNAL_STRENGTH_SHIFT, "wifi_signal_strength", "Wss", |
| 2164 | new String[] { "0", "1", "2", "3", "4" }, |
| 2165 | new String[] { "0", "1", "2", "3", "4" }), |
| 2166 | new BitDescription(HistoryItem.STATE2_WIFI_SUPPL_STATE_MASK, |
| 2167 | HistoryItem.STATE2_WIFI_SUPPL_STATE_SHIFT, "wifi_suppl", "Wsp", |
| 2168 | WIFI_SUPPL_STATE_NAMES, WIFI_SUPPL_STATE_SHORT_NAMES), |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 2169 | new BitDescription(HistoryItem.STATE2_CAMERA_FLAG, "camera", "ca"), |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 2170 | new BitDescription(HistoryItem.STATE2_BLUETOOTH_SCAN_FLAG, "ble_scan", "bles"), |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2171 | }; |
| 2172 | |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 2173 | public static final String[] HISTORY_EVENT_NAMES = new String[] { |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 2174 | "null", "proc", "fg", "top", "sync", "wake_lock_in", "job", "user", "userfg", "conn", |
Kweku Adams | 134c59b | 2017-03-08 16:48:01 -0800 | [diff] [blame] | 2175 | "active", "pkginst", "pkgunin", "alarm", "stats", "pkginactive", "pkgactive", |
| 2176 | "tmpwhitelist", "screenwake", "wakeupap", "longwake", "est_capacity" |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 2177 | }; |
| 2178 | |
| 2179 | public static final String[] HISTORY_EVENT_CHECKIN_NAMES = new String[] { |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 2180 | "Enl", "Epr", "Efg", "Etp", "Esy", "Ewl", "Ejb", "Eur", "Euf", "Ecn", |
Dianne Hackborn | 280a64e | 2015-07-13 14:48:08 -0700 | [diff] [blame] | 2181 | "Eac", "Epi", "Epu", "Eal", "Est", "Eai", "Eaa", "Etw", |
Adam Lesinski | 041d917 | 2016-12-12 12:03:56 -0800 | [diff] [blame] | 2182 | "Esw", "Ewa", "Elw", "Eec" |
| 2183 | }; |
| 2184 | |
| 2185 | @FunctionalInterface |
| 2186 | public interface IntToString { |
| 2187 | String applyAsString(int val); |
| 2188 | } |
| 2189 | |
| 2190 | private static final IntToString sUidToString = UserHandle::formatUid; |
| 2191 | private static final IntToString sIntToString = Integer::toString; |
| 2192 | |
| 2193 | public static final IntToString[] HISTORY_EVENT_INT_FORMATTERS = new IntToString[] { |
| 2194 | sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, |
| 2195 | sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, |
| 2196 | sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, |
| 2197 | sUidToString, sUidToString, sUidToString, sIntToString |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 2198 | }; |
| 2199 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2200 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 2201 | * 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] | 2202 | * running on battery. |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2203 | * |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2204 | * {@hide} |
| 2205 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2206 | public abstract long getWifiOnTime(long elapsedRealtimeUs, int which); |
Eric Shienbrood | d4c5f89 | 2009-03-24 18:13:20 -0700 | [diff] [blame] | 2207 | |
| 2208 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 2209 | * 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] | 2210 | * been in the running state while the device was running on battery. |
| 2211 | * |
| 2212 | * {@hide} |
| 2213 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2214 | public abstract long getGlobalWifiRunningTime(long elapsedRealtimeUs, int which); |
Eric Shienbrood | d4c5f89 | 2009-03-24 18:13:20 -0700 | [diff] [blame] | 2215 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 2216 | public static final int WIFI_STATE_OFF = 0; |
| 2217 | public static final int WIFI_STATE_OFF_SCANNING = 1; |
| 2218 | public static final int WIFI_STATE_ON_NO_NETWORKS = 2; |
| 2219 | public static final int WIFI_STATE_ON_DISCONNECTED = 3; |
| 2220 | public static final int WIFI_STATE_ON_CONNECTED_STA = 4; |
| 2221 | public static final int WIFI_STATE_ON_CONNECTED_P2P = 5; |
| 2222 | public static final int WIFI_STATE_ON_CONNECTED_STA_P2P = 6; |
| 2223 | public static final int WIFI_STATE_SOFT_AP = 7; |
| 2224 | |
| 2225 | static final String[] WIFI_STATE_NAMES = { |
| 2226 | "off", "scanning", "no_net", "disconn", |
| 2227 | "sta", "p2p", "sta_p2p", "soft_ap" |
| 2228 | }; |
| 2229 | |
| 2230 | public static final int NUM_WIFI_STATES = WIFI_STATE_SOFT_AP+1; |
| 2231 | |
| 2232 | /** |
| 2233 | * Returns the time in microseconds that WiFi has been running in the given state. |
| 2234 | * |
| 2235 | * {@hide} |
| 2236 | */ |
| 2237 | public abstract long getWifiStateTime(int wifiState, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2238 | long elapsedRealtimeUs, int which); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 2239 | |
| 2240 | /** |
| 2241 | * Returns the number of times that WiFi has entered the given state. |
| 2242 | * |
| 2243 | * {@hide} |
| 2244 | */ |
| 2245 | public abstract int getWifiStateCount(int wifiState, int which); |
| 2246 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2247 | /** |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 2248 | * Returns the time in microseconds that the wifi supplicant has been |
| 2249 | * in a given state. |
| 2250 | * |
| 2251 | * {@hide} |
| 2252 | */ |
| 2253 | public abstract long getWifiSupplStateTime(int state, long elapsedRealtimeUs, int which); |
| 2254 | |
| 2255 | /** |
| 2256 | * Returns the number of times that the wifi supplicant has transitioned |
| 2257 | * to a given state. |
| 2258 | * |
| 2259 | * {@hide} |
| 2260 | */ |
| 2261 | public abstract int getWifiSupplStateCount(int state, int which); |
| 2262 | |
| 2263 | public static final int NUM_WIFI_SIGNAL_STRENGTH_BINS = 5; |
| 2264 | |
| 2265 | /** |
| 2266 | * Returns the time in microseconds that WIFI has been running with |
| 2267 | * the given signal strength. |
| 2268 | * |
| 2269 | * {@hide} |
| 2270 | */ |
| 2271 | public abstract long getWifiSignalStrengthTime(int strengthBin, |
| 2272 | long elapsedRealtimeUs, int which); |
| 2273 | |
| 2274 | /** |
| 2275 | * Returns the number of times WIFI has entered the given signal strength. |
| 2276 | * |
| 2277 | * {@hide} |
| 2278 | */ |
| 2279 | public abstract int getWifiSignalStrengthCount(int strengthBin, int which); |
| 2280 | |
| 2281 | /** |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 2282 | * Returns the time in microseconds that the flashlight has been on while the device was |
| 2283 | * running on battery. |
| 2284 | * |
| 2285 | * {@hide} |
| 2286 | */ |
| 2287 | public abstract long getFlashlightOnTime(long elapsedRealtimeUs, int which); |
| 2288 | |
| 2289 | /** |
| 2290 | * Returns the number of times that the flashlight has been turned on while the device was |
| 2291 | * running on battery. |
| 2292 | * |
| 2293 | * {@hide} |
| 2294 | */ |
| 2295 | public abstract long getFlashlightOnCount(int which); |
| 2296 | |
Ruben Brunk | 5b1308f | 2015-06-03 18:49:27 -0700 | [diff] [blame] | 2297 | /** |
| 2298 | * Returns the time in microseconds that the camera has been on while the device was |
| 2299 | * running on battery. |
| 2300 | * |
| 2301 | * {@hide} |
| 2302 | */ |
| 2303 | public abstract long getCameraOnTime(long elapsedRealtimeUs, int which); |
| 2304 | |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 2305 | /** |
| 2306 | * Returns the time in microseconds that bluetooth scans were running while the device was |
| 2307 | * on battery. |
| 2308 | * |
| 2309 | * {@hide} |
| 2310 | */ |
| 2311 | public abstract long getBluetoothScanTime(long elapsedRealtimeUs, int which); |
Ruben Brunk | 5b1308f | 2015-06-03 18:49:27 -0700 | [diff] [blame] | 2312 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2313 | public static final int NETWORK_MOBILE_RX_DATA = 0; |
| 2314 | public static final int NETWORK_MOBILE_TX_DATA = 1; |
| 2315 | public static final int NETWORK_WIFI_RX_DATA = 2; |
| 2316 | public static final int NETWORK_WIFI_TX_DATA = 3; |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 2317 | public static final int NETWORK_BT_RX_DATA = 4; |
| 2318 | public static final int NETWORK_BT_TX_DATA = 5; |
Amith Yamasani | 59fe841 | 2017-03-03 16:28:52 -0800 | [diff] [blame] | 2319 | public static final int NETWORK_MOBILE_BG_RX_DATA = 6; |
| 2320 | public static final int NETWORK_MOBILE_BG_TX_DATA = 7; |
| 2321 | public static final int NETWORK_WIFI_BG_RX_DATA = 8; |
| 2322 | public static final int NETWORK_WIFI_BG_TX_DATA = 9; |
| 2323 | 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] | 2324 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2325 | public abstract long getNetworkActivityBytes(int type, int which); |
| 2326 | public abstract long getNetworkActivityPackets(int type, int which); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 2327 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 2328 | /** |
Adam Lesinski | 1739076 | 2015-04-10 13:17:47 -0700 | [diff] [blame] | 2329 | * Returns true if the BatteryStats object has detailed WiFi power reports. |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 2330 | * When true, calling {@link #getWifiControllerActivity()} will yield the |
Adam Lesinski | 1739076 | 2015-04-10 13:17:47 -0700 | [diff] [blame] | 2331 | * actual power data. |
| 2332 | */ |
| 2333 | public abstract boolean hasWifiActivityReporting(); |
| 2334 | |
| 2335 | /** |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 2336 | * Returns a {@link ControllerActivityCounter} which is an aggregate of the times spent |
| 2337 | * in various radio controller states, such as transmit, receive, and idle. |
| 2338 | * @return non-null {@link ControllerActivityCounter} |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 2339 | */ |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 2340 | public abstract ControllerActivityCounter getWifiControllerActivity(); |
| 2341 | |
| 2342 | /** |
| 2343 | * Returns true if the BatteryStats object has detailed bluetooth power reports. |
| 2344 | * When true, calling {@link #getBluetoothControllerActivity()} will yield the |
| 2345 | * actual power data. |
| 2346 | */ |
| 2347 | public abstract boolean hasBluetoothActivityReporting(); |
| 2348 | |
| 2349 | /** |
| 2350 | * Returns a {@link ControllerActivityCounter} which is an aggregate of the times spent |
| 2351 | * in various radio controller states, such as transmit, receive, and idle. |
| 2352 | * @return non-null {@link ControllerActivityCounter} |
| 2353 | */ |
| 2354 | public abstract ControllerActivityCounter getBluetoothControllerActivity(); |
| 2355 | |
| 2356 | /** |
| 2357 | * Returns true if the BatteryStats object has detailed modem power reports. |
| 2358 | * When true, calling {@link #getModemControllerActivity()} will yield the |
| 2359 | * actual power data. |
| 2360 | */ |
| 2361 | public abstract boolean hasModemActivityReporting(); |
| 2362 | |
| 2363 | /** |
| 2364 | * Returns a {@link ControllerActivityCounter} which is an aggregate of the times spent |
| 2365 | * in various radio controller states, such as transmit, receive, and idle. |
| 2366 | * @return non-null {@link ControllerActivityCounter} |
| 2367 | */ |
| 2368 | public abstract ControllerActivityCounter getModemControllerActivity(); |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 2369 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2370 | /** |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 2371 | * Return the wall clock time when battery stats data collection started. |
| 2372 | */ |
| 2373 | public abstract long getStartClockTime(); |
| 2374 | |
| 2375 | /** |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 2376 | * Return platform version tag that we were running in when the battery stats started. |
| 2377 | */ |
| 2378 | public abstract String getStartPlatformVersion(); |
| 2379 | |
| 2380 | /** |
| 2381 | * Return platform version tag that we were running in when the battery stats ended. |
| 2382 | */ |
| 2383 | public abstract String getEndPlatformVersion(); |
| 2384 | |
| 2385 | /** |
| 2386 | * Return the internal version code of the parcelled format. |
| 2387 | */ |
| 2388 | public abstract int getParcelVersion(); |
| 2389 | |
| 2390 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2391 | * Return whether we are currently running on battery. |
| 2392 | */ |
| 2393 | public abstract boolean getIsOnBattery(); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2394 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2395 | /** |
| 2396 | * Returns a SparseArray containing the statistics for each uid. |
| 2397 | */ |
| 2398 | public abstract SparseArray<? extends Uid> getUidStats(); |
| 2399 | |
| 2400 | /** |
| 2401 | * Returns the current battery uptime in microseconds. |
| 2402 | * |
| 2403 | * @param curTime the amount of elapsed realtime in microseconds. |
| 2404 | */ |
| 2405 | public abstract long getBatteryUptime(long curTime); |
| 2406 | |
| 2407 | /** |
| 2408 | * Returns the current battery realtime in microseconds. |
| 2409 | * |
| 2410 | * @param curTime the amount of elapsed realtime in microseconds. |
| 2411 | */ |
| 2412 | public abstract long getBatteryRealtime(long curTime); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2413 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2414 | /** |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 2415 | * 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] | 2416 | * the last time it booted on battery power. |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2417 | */ |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 2418 | public abstract int getDischargeStartLevel(); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2419 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2420 | /** |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 2421 | * Returns the current battery percentage level if we are in a discharge cycle, otherwise |
| 2422 | * returns the level at the last plug event. |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2423 | */ |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 2424 | public abstract int getDischargeCurrentLevel(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2425 | |
| 2426 | /** |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 2427 | * Get the amount the battery has discharged since the stats were |
| 2428 | * last reset after charging, as a lower-end approximation. |
| 2429 | */ |
| 2430 | public abstract int getLowDischargeAmountSinceCharge(); |
| 2431 | |
| 2432 | /** |
| 2433 | * Get the amount the battery has discharged since the stats were |
| 2434 | * last reset after charging, as an upper-end approximation. |
| 2435 | */ |
| 2436 | public abstract int getHighDischargeAmountSinceCharge(); |
| 2437 | |
| 2438 | /** |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2439 | * Retrieve the discharge amount over the selected discharge period <var>which</var>. |
| 2440 | */ |
| 2441 | public abstract int getDischargeAmount(int which); |
| 2442 | |
| 2443 | /** |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 2444 | * Get the amount the battery has discharged while the screen was on, |
| 2445 | * since the last time power was unplugged. |
| 2446 | */ |
| 2447 | public abstract int getDischargeAmountScreenOn(); |
| 2448 | |
| 2449 | /** |
| 2450 | * Get the amount the battery has discharged while the screen was on, |
| 2451 | * since the last time the device was charged. |
| 2452 | */ |
| 2453 | public abstract int getDischargeAmountScreenOnSinceCharge(); |
| 2454 | |
| 2455 | /** |
| 2456 | * Get the amount the battery has discharged while the screen was off, |
| 2457 | * since the last time power was unplugged. |
| 2458 | */ |
| 2459 | public abstract int getDischargeAmountScreenOff(); |
| 2460 | |
| 2461 | /** |
| 2462 | * Get the amount the battery has discharged while the screen was off, |
| 2463 | * since the last time the device was charged. |
| 2464 | */ |
| 2465 | public abstract int getDischargeAmountScreenOffSinceCharge(); |
| 2466 | |
| 2467 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2468 | * Returns the total, last, or current battery uptime in microseconds. |
| 2469 | * |
| 2470 | * @param curTime the elapsed realtime in microseconds. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2471 | * @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] | 2472 | */ |
| 2473 | public abstract long computeBatteryUptime(long curTime, int which); |
| 2474 | |
| 2475 | /** |
| 2476 | * Returns the total, last, or current battery realtime in microseconds. |
| 2477 | * |
| 2478 | * @param curTime the current elapsed realtime in microseconds. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2479 | * @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] | 2480 | */ |
| 2481 | public abstract long computeBatteryRealtime(long curTime, int which); |
| 2482 | |
| 2483 | /** |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2484 | * Returns the total, last, or current battery screen off uptime in microseconds. |
| 2485 | * |
| 2486 | * @param curTime the elapsed realtime in microseconds. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2487 | * @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] | 2488 | */ |
| 2489 | public abstract long computeBatteryScreenOffUptime(long curTime, int which); |
| 2490 | |
| 2491 | /** |
| 2492 | * Returns the total, last, or current battery screen off realtime in microseconds. |
| 2493 | * |
| 2494 | * @param curTime the current elapsed realtime in microseconds. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2495 | * @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] | 2496 | */ |
| 2497 | public abstract long computeBatteryScreenOffRealtime(long curTime, int which); |
| 2498 | |
| 2499 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2500 | * Returns the total, last, or current uptime in microseconds. |
| 2501 | * |
| 2502 | * @param curTime the current elapsed realtime in microseconds. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2503 | * @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] | 2504 | */ |
| 2505 | public abstract long computeUptime(long curTime, int which); |
| 2506 | |
| 2507 | /** |
| 2508 | * Returns the total, last, or current realtime in microseconds. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2509 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2510 | * @param curTime the current elapsed realtime in microseconds. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2511 | * @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] | 2512 | */ |
| 2513 | public abstract long computeRealtime(long curTime, int which); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2514 | |
| 2515 | /** |
| 2516 | * Compute an approximation for how much run time (in microseconds) is remaining on |
| 2517 | * the battery. Returns -1 if no time can be computed: either there is not |
| 2518 | * enough current data to make a decision, or the battery is currently |
| 2519 | * charging. |
| 2520 | * |
| 2521 | * @param curTime The current elepsed realtime in microseconds. |
| 2522 | */ |
| 2523 | public abstract long computeBatteryTimeRemaining(long curTime); |
| 2524 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 2525 | // The part of a step duration that is the actual time. |
| 2526 | public static final long STEP_LEVEL_TIME_MASK = 0x000000ffffffffffL; |
| 2527 | |
| 2528 | // Bits in a step duration that are the new battery level we are at. |
| 2529 | public static final long STEP_LEVEL_LEVEL_MASK = 0x0000ff0000000000L; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2530 | public static final int STEP_LEVEL_LEVEL_SHIFT = 40; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 2531 | |
| 2532 | // Bits in a step duration that are the initial mode we were in at that step. |
| 2533 | public static final long STEP_LEVEL_INITIAL_MODE_MASK = 0x00ff000000000000L; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2534 | public static final int STEP_LEVEL_INITIAL_MODE_SHIFT = 48; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 2535 | |
| 2536 | // Bits in a step duration that indicate which modes changed during that step. |
| 2537 | public static final long STEP_LEVEL_MODIFIED_MODE_MASK = 0xff00000000000000L; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2538 | public static final int STEP_LEVEL_MODIFIED_MODE_SHIFT = 56; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 2539 | |
| 2540 | // Step duration mode: the screen is on, off, dozed, etc; value is Display.STATE_* - 1. |
| 2541 | public static final int STEP_LEVEL_MODE_SCREEN_STATE = 0x03; |
| 2542 | |
Santos Cordon | e94f050 | 2017-02-24 12:31:20 -0800 | [diff] [blame] | 2543 | // The largest value for screen state that is tracked in battery states. Any values above |
| 2544 | // this should be mapped back to one of the tracked values before being tracked here. |
| 2545 | public static final int MAX_TRACKED_SCREEN_STATE = Display.STATE_DOZE_SUSPEND; |
| 2546 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 2547 | // Step duration mode: power save is on. |
| 2548 | public static final int STEP_LEVEL_MODE_POWER_SAVE = 0x04; |
| 2549 | |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2550 | // Step duration mode: device is currently in idle mode. |
| 2551 | public static final int STEP_LEVEL_MODE_DEVICE_IDLE = 0x08; |
| 2552 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2553 | public static final int[] STEP_LEVEL_MODES_OF_INTEREST = new int[] { |
| 2554 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE, |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2555 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE|STEP_LEVEL_MODE_DEVICE_IDLE, |
| 2556 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_DEVICE_IDLE, |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2557 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE, |
| 2558 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE, |
| 2559 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE, |
| 2560 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE, |
| 2561 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE, |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2562 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE|STEP_LEVEL_MODE_DEVICE_IDLE, |
| 2563 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_DEVICE_IDLE, |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2564 | }; |
| 2565 | public static final int[] STEP_LEVEL_MODE_VALUES = new int[] { |
| 2566 | (Display.STATE_OFF-1), |
| 2567 | (Display.STATE_OFF-1)|STEP_LEVEL_MODE_POWER_SAVE, |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2568 | (Display.STATE_OFF-1)|STEP_LEVEL_MODE_DEVICE_IDLE, |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2569 | (Display.STATE_ON-1), |
| 2570 | (Display.STATE_ON-1)|STEP_LEVEL_MODE_POWER_SAVE, |
| 2571 | (Display.STATE_DOZE-1), |
| 2572 | (Display.STATE_DOZE-1)|STEP_LEVEL_MODE_POWER_SAVE, |
| 2573 | (Display.STATE_DOZE_SUSPEND-1), |
| 2574 | (Display.STATE_DOZE_SUSPEND-1)|STEP_LEVEL_MODE_POWER_SAVE, |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2575 | (Display.STATE_DOZE_SUSPEND-1)|STEP_LEVEL_MODE_DEVICE_IDLE, |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2576 | }; |
| 2577 | public static final String[] STEP_LEVEL_MODE_LABELS = new String[] { |
| 2578 | "screen off", |
| 2579 | "screen off power save", |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2580 | "screen off device idle", |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2581 | "screen on", |
| 2582 | "screen on power save", |
| 2583 | "screen doze", |
| 2584 | "screen doze power save", |
| 2585 | "screen doze-suspend", |
| 2586 | "screen doze-suspend power save", |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2587 | "screen doze-suspend device idle", |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2588 | }; |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 2589 | |
| 2590 | /** |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 2591 | * Return the counter keeping track of the amount of battery discharge while the screen was off, |
| 2592 | * measured in micro-Ampere-hours. This will be non-zero only if the device's battery has |
| 2593 | * a coulomb counter. |
| 2594 | */ |
| 2595 | public abstract LongCounter getDischargeScreenOffCoulombCounter(); |
| 2596 | |
| 2597 | /** |
| 2598 | * Return the counter keeping track of the amount of battery discharge measured in |
| 2599 | * micro-Ampere-hours. This will be non-zero only if the device's battery has |
| 2600 | * a coulomb counter. |
| 2601 | */ |
| 2602 | public abstract LongCounter getDischargeCoulombCounter(); |
| 2603 | |
| 2604 | /** |
Adam Lesinski | f9b20a9 | 2016-06-17 17:30:01 -0700 | [diff] [blame] | 2605 | * Returns the estimated real battery capacity, which may be less than the capacity |
| 2606 | * declared by the PowerProfile. |
| 2607 | * @return The estimated battery capacity in mAh. |
| 2608 | */ |
| 2609 | public abstract int getEstimatedBatteryCapacity(); |
| 2610 | |
| 2611 | /** |
Jocelyn Dang | c627d10 | 2017-04-14 13:15:14 -0700 | [diff] [blame] | 2612 | * @return The minimum learned battery capacity in uAh. |
| 2613 | */ |
| 2614 | public abstract int getMinLearnedBatteryCapacity(); |
| 2615 | |
| 2616 | /** |
| 2617 | * @return The maximum learned battery capacity in uAh. |
| 2618 | */ |
| 2619 | public abstract int getMaxLearnedBatteryCapacity() ; |
| 2620 | |
| 2621 | /** |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2622 | * Return the array of discharge step durations. |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 2623 | */ |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2624 | public abstract LevelStepTracker getDischargeLevelStepTracker(); |
| 2625 | |
| 2626 | /** |
| 2627 | * Return the array of daily discharge step durations. |
| 2628 | */ |
| 2629 | public abstract LevelStepTracker getDailyDischargeLevelStepTracker(); |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 2630 | |
| 2631 | /** |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2632 | * Compute an approximation for how much time (in microseconds) remains until the battery |
| 2633 | * is fully charged. Returns -1 if no time can be computed: either there is not |
| 2634 | * enough current data to make a decision, or the battery is currently |
| 2635 | * discharging. |
| 2636 | * |
| 2637 | * @param curTime The current elepsed realtime in microseconds. |
| 2638 | */ |
| 2639 | public abstract long computeChargeTimeRemaining(long curTime); |
| 2640 | |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 2641 | /** |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2642 | * Return the array of charge step durations. |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 2643 | */ |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2644 | public abstract LevelStepTracker getChargeLevelStepTracker(); |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 2645 | |
| 2646 | /** |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2647 | * Return the array of daily charge step durations. |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 2648 | */ |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2649 | public abstract LevelStepTracker getDailyChargeLevelStepTracker(); |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 2650 | |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2651 | public abstract ArrayList<PackageChange> getDailyPackageChanges(); |
| 2652 | |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 2653 | public abstract Map<String, ? extends Timer> getWakeupReasonStats(); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2654 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2655 | public abstract Map<String, ? extends Timer> getKernelWakelockStats(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2656 | |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame^] | 2657 | /** |
| 2658 | * Returns Timers tracking the total time of each Resource Power Manager state and voter. |
| 2659 | */ |
| 2660 | public abstract Map<String, ? extends Timer> getRpmStats(); |
| 2661 | /** |
| 2662 | * Returns Timers tracking the screen-off time of each Resource Power Manager state and voter. |
| 2663 | */ |
| 2664 | public abstract Map<String, ? extends Timer> getScreenOffRpmStats(); |
| 2665 | |
| 2666 | |
James Carr | 2dd7e5e | 2016-07-20 18:48:39 -0700 | [diff] [blame] | 2667 | public abstract LongSparseArray<? extends Timer> getKernelMemoryStats(); |
| 2668 | |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 2669 | public abstract void writeToParcelWithoutUids(Parcel out, int flags); |
| 2670 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 2671 | private final static void formatTimeRaw(StringBuilder out, long seconds) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2672 | long days = seconds / (60 * 60 * 24); |
| 2673 | if (days != 0) { |
| 2674 | out.append(days); |
| 2675 | out.append("d "); |
| 2676 | } |
| 2677 | long used = days * 60 * 60 * 24; |
| 2678 | |
| 2679 | long hours = (seconds - used) / (60 * 60); |
| 2680 | if (hours != 0 || used != 0) { |
| 2681 | out.append(hours); |
| 2682 | out.append("h "); |
| 2683 | } |
| 2684 | used += hours * 60 * 60; |
| 2685 | |
| 2686 | long mins = (seconds-used) / 60; |
| 2687 | if (mins != 0 || used != 0) { |
| 2688 | out.append(mins); |
| 2689 | out.append("m "); |
| 2690 | } |
| 2691 | used += mins * 60; |
| 2692 | |
| 2693 | if (seconds != 0 || used != 0) { |
| 2694 | out.append(seconds-used); |
| 2695 | out.append("s "); |
| 2696 | } |
| 2697 | } |
| 2698 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2699 | public final static void formatTimeMs(StringBuilder sb, long time) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2700 | long sec = time / 1000; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 2701 | formatTimeRaw(sb, sec); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2702 | sb.append(time - (sec * 1000)); |
| 2703 | sb.append("ms "); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2704 | } |
| 2705 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2706 | public final static void formatTimeMsNoSpace(StringBuilder sb, long time) { |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 2707 | long sec = time / 1000; |
| 2708 | formatTimeRaw(sb, sec); |
| 2709 | sb.append(time - (sec * 1000)); |
| 2710 | sb.append("ms"); |
| 2711 | } |
| 2712 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2713 | public final String formatRatioLocked(long num, long den) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2714 | if (den == 0L) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2715 | return "--%"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2716 | } |
| 2717 | float perc = ((float)num) / ((float)den) * 100; |
| 2718 | mFormatBuilder.setLength(0); |
| 2719 | mFormatter.format("%.1f%%", perc); |
| 2720 | return mFormatBuilder.toString(); |
| 2721 | } |
| 2722 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2723 | final String formatBytesLocked(long bytes) { |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 2724 | mFormatBuilder.setLength(0); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2725 | |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 2726 | if (bytes < BYTES_PER_KB) { |
| 2727 | return bytes + "B"; |
| 2728 | } else if (bytes < BYTES_PER_MB) { |
| 2729 | mFormatter.format("%.2fKB", bytes / (double) BYTES_PER_KB); |
| 2730 | return mFormatBuilder.toString(); |
| 2731 | } else if (bytes < BYTES_PER_GB){ |
| 2732 | mFormatter.format("%.2fMB", bytes / (double) BYTES_PER_MB); |
| 2733 | return mFormatBuilder.toString(); |
| 2734 | } else { |
| 2735 | mFormatter.format("%.2fGB", bytes / (double) BYTES_PER_GB); |
| 2736 | return mFormatBuilder.toString(); |
| 2737 | } |
| 2738 | } |
| 2739 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2740 | private static long computeWakeLock(Timer timer, long elapsedRealtimeUs, int which) { |
Dianne Hackborn | c24ab86 | 2011-10-18 15:55:03 -0700 | [diff] [blame] | 2741 | if (timer != null) { |
| 2742 | // Convert from microseconds to milliseconds with rounding |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2743 | long totalTimeMicros = timer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Dianne Hackborn | c24ab86 | 2011-10-18 15:55:03 -0700 | [diff] [blame] | 2744 | long totalTimeMillis = (totalTimeMicros + 500) / 1000; |
| 2745 | return totalTimeMillis; |
| 2746 | } |
| 2747 | return 0; |
| 2748 | } |
| 2749 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2750 | /** |
| 2751 | * |
| 2752 | * @param sb a StringBuilder object. |
| 2753 | * @param timer a Timer object contining the wakelock times. |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2754 | * @param elapsedRealtimeUs the current on-battery time in microseconds. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2755 | * @param name the name of the wakelock. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2756 | * @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] | 2757 | * @param linePrefix a String to be prepended to each line of output. |
| 2758 | * @return the line prefix |
| 2759 | */ |
| 2760 | private static final String printWakeLock(StringBuilder sb, Timer timer, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2761 | long elapsedRealtimeUs, String name, int which, String linePrefix) { |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 2762 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2763 | if (timer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2764 | long totalTimeMillis = computeWakeLock(timer, elapsedRealtimeUs, which); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 2765 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2766 | int count = timer.getCountLocked(which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2767 | if (totalTimeMillis != 0) { |
| 2768 | sb.append(linePrefix); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 2769 | formatTimeMs(sb, totalTimeMillis); |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 2770 | if (name != null) { |
| 2771 | sb.append(name); |
| 2772 | sb.append(' '); |
| 2773 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2774 | sb.append('('); |
| 2775 | sb.append(count); |
| 2776 | sb.append(" times)"); |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2777 | final long maxDurationMs = timer.getMaxDurationMsLocked(elapsedRealtimeUs/1000); |
| 2778 | if (maxDurationMs >= 0) { |
| 2779 | sb.append(" max="); |
| 2780 | sb.append(maxDurationMs); |
| 2781 | } |
Bookatz | 506a818 | 2017-05-01 14:18:42 -0700 | [diff] [blame] | 2782 | // Put actual time if it is available and different from totalTimeMillis. |
| 2783 | final long totalDurMs = timer.getTotalDurationMsLocked(elapsedRealtimeUs/1000); |
| 2784 | if (totalDurMs > totalTimeMillis) { |
| 2785 | sb.append(" actual="); |
| 2786 | sb.append(totalDurMs); |
| 2787 | } |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2788 | if (timer.isRunningLocked()) { |
| 2789 | final long currentMs = timer.getCurrentDurationMsLocked(elapsedRealtimeUs/1000); |
| 2790 | if (currentMs >= 0) { |
| 2791 | sb.append(" (running for "); |
| 2792 | sb.append(currentMs); |
| 2793 | sb.append("ms)"); |
| 2794 | } else { |
| 2795 | sb.append(" (running)"); |
| 2796 | } |
| 2797 | } |
| 2798 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2799 | return ", "; |
| 2800 | } |
| 2801 | } |
| 2802 | return linePrefix; |
| 2803 | } |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 2804 | |
| 2805 | /** |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2806 | * 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] | 2807 | * |
| 2808 | * @param pw a PrintWriter object to print to. |
| 2809 | * @param sb a StringBuilder object. |
| 2810 | * @param timer a Timer object contining the wakelock times. |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2811 | * @param rawRealtimeUs the current on-battery time in microseconds. |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 2812 | * @param which which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT. |
| 2813 | * @param prefix a String to be prepended to each line of output. |
| 2814 | * @param type the name of the timer. |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2815 | * @return true if anything was printed. |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 2816 | */ |
| 2817 | private static final boolean printTimer(PrintWriter pw, StringBuilder sb, Timer timer, |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2818 | long rawRealtimeUs, int which, String prefix, String type) { |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 2819 | if (timer != null) { |
| 2820 | // Convert from microseconds to milliseconds with rounding |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2821 | final long totalTimeMs = (timer.getTotalTimeLocked( |
| 2822 | rawRealtimeUs, which) + 500) / 1000; |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 2823 | final int count = timer.getCountLocked(which); |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2824 | if (totalTimeMs != 0) { |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 2825 | sb.setLength(0); |
| 2826 | sb.append(prefix); |
| 2827 | sb.append(" "); |
| 2828 | sb.append(type); |
| 2829 | sb.append(": "); |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2830 | formatTimeMs(sb, totalTimeMs); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 2831 | sb.append("realtime ("); |
| 2832 | sb.append(count); |
| 2833 | sb.append(" times)"); |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2834 | final long maxDurationMs = timer.getMaxDurationMsLocked(rawRealtimeUs/1000); |
| 2835 | if (maxDurationMs >= 0) { |
| 2836 | sb.append(" max="); |
| 2837 | sb.append(maxDurationMs); |
| 2838 | } |
| 2839 | if (timer.isRunningLocked()) { |
| 2840 | final long currentMs = timer.getCurrentDurationMsLocked(rawRealtimeUs/1000); |
| 2841 | if (currentMs >= 0) { |
| 2842 | sb.append(" (running for "); |
| 2843 | sb.append(currentMs); |
| 2844 | sb.append("ms)"); |
| 2845 | } else { |
| 2846 | sb.append(" (running)"); |
| 2847 | } |
| 2848 | } |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 2849 | pw.println(sb.toString()); |
| 2850 | return true; |
| 2851 | } |
| 2852 | } |
| 2853 | return false; |
| 2854 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2855 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2856 | /** |
| 2857 | * Checkin version of wakelock printer. Prints simple comma-separated list. |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2858 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2859 | * @param sb a StringBuilder object. |
| 2860 | * @param timer a Timer object contining the wakelock times. |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2861 | * @param elapsedRealtimeUs the current time in microseconds. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2862 | * @param name the name of the wakelock. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2863 | * @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] | 2864 | * @param linePrefix a String to be prepended to each line of output. |
| 2865 | * @return the line prefix |
| 2866 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2867 | private static final String printWakeLockCheckin(StringBuilder sb, Timer timer, |
| 2868 | long elapsedRealtimeUs, String name, int which, String linePrefix) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2869 | long totalTimeMicros = 0; |
| 2870 | int count = 0; |
Bookatz | 941d98f | 2017-05-02 19:25:18 -0700 | [diff] [blame] | 2871 | long max = 0; |
| 2872 | long current = 0; |
| 2873 | long totalDuration = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2874 | if (timer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2875 | totalTimeMicros = timer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Bookatz | 506a818 | 2017-05-01 14:18:42 -0700 | [diff] [blame] | 2876 | count = timer.getCountLocked(which); |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2877 | current = timer.getCurrentDurationMsLocked(elapsedRealtimeUs/1000); |
| 2878 | max = timer.getMaxDurationMsLocked(elapsedRealtimeUs/1000); |
Bookatz | 506a818 | 2017-05-01 14:18:42 -0700 | [diff] [blame] | 2879 | totalDuration = timer.getTotalDurationMsLocked(elapsedRealtimeUs/1000); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2880 | } |
| 2881 | sb.append(linePrefix); |
| 2882 | sb.append((totalTimeMicros + 500) / 1000); // microseconds to milliseconds with rounding |
| 2883 | sb.append(','); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2884 | sb.append(name != null ? name + "," : ""); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2885 | sb.append(count); |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2886 | sb.append(','); |
| 2887 | sb.append(current); |
| 2888 | sb.append(','); |
| 2889 | sb.append(max); |
Bookatz | 506a818 | 2017-05-01 14:18:42 -0700 | [diff] [blame] | 2890 | // Partial, full, and window wakelocks are pooled, so totalDuration is meaningful (albeit |
| 2891 | // not always tracked). Kernel wakelocks (which have name == null) have no notion of |
| 2892 | // totalDuration independent of totalTimeMicros (since they are not pooled). |
| 2893 | if (name != null) { |
| 2894 | sb.append(','); |
| 2895 | sb.append(totalDuration); |
| 2896 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2897 | return ","; |
| 2898 | } |
Bookatz | 506a818 | 2017-05-01 14:18:42 -0700 | [diff] [blame] | 2899 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 2900 | private static final void dumpLineHeader(PrintWriter pw, int uid, String category, |
| 2901 | String type) { |
| 2902 | pw.print(BATTERY_STATS_CHECKIN_VERSION); |
| 2903 | pw.print(','); |
| 2904 | pw.print(uid); |
| 2905 | pw.print(','); |
| 2906 | pw.print(category); |
| 2907 | pw.print(','); |
| 2908 | pw.print(type); |
| 2909 | } |
| 2910 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2911 | /** |
| 2912 | * Dump a comma-separated line of values for terse checkin mode. |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2913 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2914 | * @param pw the PageWriter to dump log to |
| 2915 | * @param category category of data (e.g. "total", "last", "unplugged", "current" ) |
| 2916 | * @param type type of data (e.g. "wakelock", "sensor", "process", "apk" , "process", "network") |
| 2917 | * @param args type-dependent data arguments |
| 2918 | */ |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2919 | 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] | 2920 | Object... args ) { |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 2921 | dumpLineHeader(pw, uid, category, type); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 2922 | for (Object arg : args) { |
Dianne Hackborn | 13ac041 | 2013-06-25 19:34:49 -0700 | [diff] [blame] | 2923 | pw.print(','); |
| 2924 | pw.print(arg); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2925 | } |
Dianne Hackborn | 13ac041 | 2013-06-25 19:34:49 -0700 | [diff] [blame] | 2926 | pw.println(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2927 | } |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 2928 | |
| 2929 | /** |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 2930 | * Dump a given timer stat for terse checkin mode. |
| 2931 | * |
| 2932 | * @param pw the PageWriter to dump log to |
| 2933 | * @param uid the UID to log |
| 2934 | * @param category category of data (e.g. "total", "last", "unplugged", "current" ) |
| 2935 | * @param type type of data (e.g. "wakelock", "sensor", "process", "apk" , "process", "network") |
| 2936 | * @param timer a {@link Timer} to dump stats for |
| 2937 | * @param rawRealtime the current elapsed realtime of the system in microseconds |
| 2938 | * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT |
| 2939 | */ |
| 2940 | private static final void dumpTimer(PrintWriter pw, int uid, String category, String type, |
| 2941 | Timer timer, long rawRealtime, int which) { |
| 2942 | if (timer != null) { |
| 2943 | // Convert from microseconds to milliseconds with rounding |
| 2944 | final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) |
| 2945 | / 1000; |
| 2946 | final int count = timer.getCountLocked(which); |
| 2947 | if (totalTime != 0) { |
| 2948 | dumpLine(pw, uid, category, type, totalTime, count); |
| 2949 | } |
| 2950 | } |
| 2951 | } |
| 2952 | |
| 2953 | /** |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 2954 | * Checks if the ControllerActivityCounter has any data worth dumping. |
| 2955 | */ |
| 2956 | private static boolean controllerActivityHasData(ControllerActivityCounter counter, int which) { |
| 2957 | if (counter == null) { |
| 2958 | return false; |
| 2959 | } |
| 2960 | |
| 2961 | if (counter.getIdleTimeCounter().getCountLocked(which) != 0 |
| 2962 | || counter.getRxTimeCounter().getCountLocked(which) != 0 |
| 2963 | || counter.getPowerCounter().getCountLocked(which) != 0) { |
| 2964 | return true; |
| 2965 | } |
| 2966 | |
| 2967 | for (LongCounter c : counter.getTxTimeCounters()) { |
| 2968 | if (c.getCountLocked(which) != 0) { |
| 2969 | return true; |
| 2970 | } |
| 2971 | } |
| 2972 | return false; |
| 2973 | } |
| 2974 | |
| 2975 | /** |
| 2976 | * Dumps the ControllerActivityCounter if it has any data worth dumping. |
| 2977 | * The order of the arguments in the final check in line is: |
| 2978 | * |
| 2979 | * idle, rx, power, tx... |
| 2980 | * |
| 2981 | * where tx... is one or more transmit level times. |
| 2982 | */ |
| 2983 | private static final void dumpControllerActivityLine(PrintWriter pw, int uid, String category, |
| 2984 | String type, |
| 2985 | ControllerActivityCounter counter, |
| 2986 | int which) { |
| 2987 | if (!controllerActivityHasData(counter, which)) { |
| 2988 | return; |
| 2989 | } |
| 2990 | |
| 2991 | dumpLineHeader(pw, uid, category, type); |
| 2992 | pw.print(","); |
| 2993 | pw.print(counter.getIdleTimeCounter().getCountLocked(which)); |
| 2994 | pw.print(","); |
| 2995 | pw.print(counter.getRxTimeCounter().getCountLocked(which)); |
| 2996 | pw.print(","); |
| 2997 | pw.print(counter.getPowerCounter().getCountLocked(which) / (1000 * 60 * 60)); |
| 2998 | for (LongCounter c : counter.getTxTimeCounters()) { |
| 2999 | pw.print(","); |
| 3000 | pw.print(c.getCountLocked(which)); |
| 3001 | } |
| 3002 | pw.println(); |
| 3003 | } |
| 3004 | |
| 3005 | private final void printControllerActivityIfInteresting(PrintWriter pw, StringBuilder sb, |
| 3006 | String prefix, String controllerName, |
| 3007 | ControllerActivityCounter counter, |
| 3008 | int which) { |
| 3009 | if (controllerActivityHasData(counter, which)) { |
| 3010 | printControllerActivity(pw, sb, prefix, controllerName, counter, which); |
| 3011 | } |
| 3012 | } |
| 3013 | |
| 3014 | private final void printControllerActivity(PrintWriter pw, StringBuilder sb, String prefix, |
| 3015 | String controllerName, |
| 3016 | ControllerActivityCounter counter, int which) { |
| 3017 | final long idleTimeMs = counter.getIdleTimeCounter().getCountLocked(which); |
| 3018 | final long rxTimeMs = counter.getRxTimeCounter().getCountLocked(which); |
| 3019 | final long powerDrainMaMs = counter.getPowerCounter().getCountLocked(which); |
| 3020 | long totalTxTimeMs = 0; |
| 3021 | for (LongCounter txState : counter.getTxTimeCounters()) { |
| 3022 | totalTxTimeMs += txState.getCountLocked(which); |
| 3023 | } |
| 3024 | |
| 3025 | final long totalTimeMs = idleTimeMs + rxTimeMs + totalTxTimeMs; |
| 3026 | |
| 3027 | sb.setLength(0); |
| 3028 | sb.append(prefix); |
| 3029 | sb.append(" "); |
| 3030 | sb.append(controllerName); |
| 3031 | sb.append(" Idle time: "); |
| 3032 | formatTimeMs(sb, idleTimeMs); |
| 3033 | sb.append("("); |
| 3034 | sb.append(formatRatioLocked(idleTimeMs, totalTimeMs)); |
| 3035 | sb.append(")"); |
| 3036 | pw.println(sb.toString()); |
| 3037 | |
| 3038 | sb.setLength(0); |
| 3039 | sb.append(prefix); |
| 3040 | sb.append(" "); |
| 3041 | sb.append(controllerName); |
| 3042 | sb.append(" Rx time: "); |
| 3043 | formatTimeMs(sb, rxTimeMs); |
| 3044 | sb.append("("); |
| 3045 | sb.append(formatRatioLocked(rxTimeMs, totalTimeMs)); |
| 3046 | sb.append(")"); |
| 3047 | pw.println(sb.toString()); |
| 3048 | |
| 3049 | sb.setLength(0); |
| 3050 | sb.append(prefix); |
| 3051 | sb.append(" "); |
| 3052 | sb.append(controllerName); |
| 3053 | sb.append(" Tx time: "); |
| 3054 | formatTimeMs(sb, totalTxTimeMs); |
| 3055 | sb.append("("); |
| 3056 | sb.append(formatRatioLocked(totalTxTimeMs, totalTimeMs)); |
| 3057 | sb.append(")"); |
| 3058 | pw.println(sb.toString()); |
| 3059 | |
| 3060 | final int numTxLvls = counter.getTxTimeCounters().length; |
| 3061 | if (numTxLvls > 1) { |
| 3062 | for (int lvl = 0; lvl < numTxLvls; lvl++) { |
| 3063 | final long txLvlTimeMs = counter.getTxTimeCounters()[lvl].getCountLocked(which); |
| 3064 | sb.setLength(0); |
| 3065 | sb.append(prefix); |
| 3066 | sb.append(" ["); |
| 3067 | sb.append(lvl); |
| 3068 | sb.append("] "); |
| 3069 | formatTimeMs(sb, txLvlTimeMs); |
| 3070 | sb.append("("); |
| 3071 | sb.append(formatRatioLocked(txLvlTimeMs, totalTxTimeMs)); |
| 3072 | sb.append(")"); |
| 3073 | pw.println(sb.toString()); |
| 3074 | } |
| 3075 | } |
| 3076 | |
| 3077 | sb.setLength(0); |
| 3078 | sb.append(prefix); |
| 3079 | sb.append(" "); |
| 3080 | sb.append(controllerName); |
| 3081 | sb.append(" Power drain: ").append( |
| 3082 | BatteryStatsHelper.makemAh(powerDrainMaMs / (double) (1000*60*60))); |
| 3083 | sb.append("mAh"); |
| 3084 | pw.println(sb.toString()); |
| 3085 | } |
| 3086 | |
| 3087 | /** |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 3088 | * Temporary for settings. |
| 3089 | */ |
| 3090 | public final void dumpCheckinLocked(Context context, PrintWriter pw, int which, int reqUid) { |
| 3091 | dumpCheckinLocked(context, pw, which, reqUid, BatteryStatsHelper.checkWifiOnly(context)); |
| 3092 | } |
| 3093 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3094 | /** |
| 3095 | * Checkin server version of dump to produce more compact, computer-readable log. |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3096 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3097 | * NOTE: all times are expressed in 'ms'. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3098 | */ |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 3099 | public final void dumpCheckinLocked(Context context, PrintWriter pw, int which, int reqUid, |
| 3100 | boolean wifiOnly) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3101 | final long rawUptime = SystemClock.uptimeMillis() * 1000; |
| 3102 | final long rawRealtime = SystemClock.elapsedRealtime() * 1000; |
Bookatz | 6d79993 | 2017-06-07 12:30:07 -0700 | [diff] [blame] | 3103 | final long rawRealtimeMs = (rawRealtime + 500) / 1000; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3104 | final long batteryUptime = getBatteryUptime(rawUptime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3105 | final long whichBatteryUptime = computeBatteryUptime(rawUptime, which); |
| 3106 | final long whichBatteryRealtime = computeBatteryRealtime(rawRealtime, which); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3107 | final long whichBatteryScreenOffUptime = computeBatteryScreenOffUptime(rawUptime, which); |
| 3108 | final long whichBatteryScreenOffRealtime = computeBatteryScreenOffRealtime(rawRealtime, |
| 3109 | which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3110 | final long totalRealtime = computeRealtime(rawRealtime, which); |
| 3111 | final long totalUptime = computeUptime(rawUptime, which); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3112 | final long screenOnTime = getScreenOnTime(rawRealtime, which); |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 3113 | final long interactiveTime = getInteractiveTime(rawRealtime, which); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3114 | final long powerSaveModeEnabledTime = getPowerSaveModeEnabledTime(rawRealtime, which); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3115 | final long deviceIdleModeLightTime = getDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT, |
| 3116 | rawRealtime, which); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 3117 | final long deviceIdleModeFullTime = getDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP, |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3118 | rawRealtime, which); |
| 3119 | final long deviceLightIdlingTime = getDeviceIdlingTime(DEVICE_IDLE_MODE_LIGHT, |
| 3120 | rawRealtime, which); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 3121 | final long deviceIdlingTime = getDeviceIdlingTime(DEVICE_IDLE_MODE_DEEP, |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3122 | rawRealtime, which); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 3123 | final int connChanges = getNumConnectivityChange(which); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3124 | final long phoneOnTime = getPhoneOnTime(rawRealtime, which); |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 3125 | final long dischargeCount = getDischargeCoulombCounter().getCountLocked(which); |
| 3126 | final long dischargeScreenOffCount = getDischargeScreenOffCoulombCounter() |
| 3127 | .getCountLocked(which); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3128 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3129 | final StringBuilder sb = new StringBuilder(128); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3130 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3131 | final SparseArray<? extends Uid> uidStats = getUidStats(); |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 3132 | final int NU = uidStats.size(); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3133 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3134 | final String category = STAT_NAMES[which]; |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 3135 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3136 | // Dump "battery" stat |
Jocelyn Dang | c627d10 | 2017-04-14 13:15:14 -0700 | [diff] [blame] | 3137 | dumpLine(pw, 0 /* uid */, category, BATTERY_DATA, |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3138 | which == STATS_SINCE_CHARGED ? getStartCount() : "N/A", |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3139 | whichBatteryRealtime / 1000, whichBatteryUptime / 1000, |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 3140 | totalRealtime / 1000, totalUptime / 1000, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3141 | getStartClockTime(), |
Adam Lesinski | f9b20a9 | 2016-06-17 17:30:01 -0700 | [diff] [blame] | 3142 | whichBatteryScreenOffRealtime / 1000, whichBatteryScreenOffUptime / 1000, |
Jocelyn Dang | c627d10 | 2017-04-14 13:15:14 -0700 | [diff] [blame] | 3143 | getEstimatedBatteryCapacity(), |
| 3144 | getMinLearnedBatteryCapacity(), getMaxLearnedBatteryCapacity()); |
Adam Lesinski | 67c134f | 2016-06-10 15:15:08 -0700 | [diff] [blame] | 3145 | |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3146 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3147 | // Calculate wakelock times across all uids. |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 3148 | long fullWakeLockTimeTotal = 0; |
| 3149 | long partialWakeLockTimeTotal = 0; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3150 | |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 3151 | for (int iu = 0; iu < NU; iu++) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3152 | final Uid u = uidStats.valueAt(iu); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 3153 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3154 | final ArrayMap<String, ? extends BatteryStats.Uid.Wakelock> wakelocks |
| 3155 | = u.getWakelockStats(); |
| 3156 | for (int iw=wakelocks.size()-1; iw>=0; iw--) { |
| 3157 | final Uid.Wakelock wl = wakelocks.valueAt(iw); |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 3158 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3159 | final Timer fullWakeTimer = wl.getWakeTime(WAKE_TYPE_FULL); |
| 3160 | if (fullWakeTimer != null) { |
| 3161 | fullWakeLockTimeTotal += fullWakeTimer.getTotalTimeLocked(rawRealtime, |
| 3162 | which); |
| 3163 | } |
| 3164 | |
| 3165 | final Timer partialWakeTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL); |
| 3166 | if (partialWakeTimer != null) { |
| 3167 | partialWakeLockTimeTotal += partialWakeTimer.getTotalTimeLocked( |
| 3168 | rawRealtime, which); |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 3169 | } |
| 3170 | } |
| 3171 | } |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 3172 | |
| 3173 | // Dump network stats |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3174 | final long mobileRxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which); |
| 3175 | final long mobileTxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which); |
| 3176 | final long wifiRxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which); |
| 3177 | final long wifiTxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which); |
| 3178 | final long mobileRxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which); |
| 3179 | final long mobileTxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which); |
| 3180 | final long wifiRxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which); |
| 3181 | final long wifiTxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 3182 | final long btRxTotalBytes = getNetworkActivityBytes(NETWORK_BT_RX_DATA, which); |
| 3183 | final long btTxTotalBytes = getNetworkActivityBytes(NETWORK_BT_TX_DATA, which); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3184 | dumpLine(pw, 0 /* uid */, category, GLOBAL_NETWORK_DATA, |
| 3185 | mobileRxTotalBytes, mobileTxTotalBytes, wifiRxTotalBytes, wifiTxTotalBytes, |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 3186 | mobileRxTotalPackets, mobileTxTotalPackets, wifiRxTotalPackets, wifiTxTotalPackets, |
| 3187 | btRxTotalBytes, btTxTotalBytes); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3188 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3189 | // Dump Modem controller stats |
| 3190 | dumpControllerActivityLine(pw, 0 /* uid */, category, GLOBAL_MODEM_CONTROLLER_DATA, |
| 3191 | getModemControllerActivity(), which); |
| 3192 | |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 3193 | // Dump Wifi controller stats |
| 3194 | final long wifiOnTime = getWifiOnTime(rawRealtime, which); |
| 3195 | final long wifiRunningTime = getGlobalWifiRunningTime(rawRealtime, which); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3196 | dumpLine(pw, 0 /* uid */, category, GLOBAL_WIFI_DATA, wifiOnTime / 1000, |
Adam Lesinski | 2208e74 | 2016-02-19 12:53:31 -0800 | [diff] [blame] | 3197 | wifiRunningTime / 1000, /* legacy fields follow, keep at 0 */ 0, 0, 0); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3198 | |
| 3199 | dumpControllerActivityLine(pw, 0 /* uid */, category, GLOBAL_WIFI_CONTROLLER_DATA, |
| 3200 | getWifiControllerActivity(), which); |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 3201 | |
| 3202 | // Dump Bluetooth controller stats |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3203 | dumpControllerActivityLine(pw, 0 /* uid */, category, GLOBAL_BLUETOOTH_CONTROLLER_DATA, |
| 3204 | getBluetoothControllerActivity(), which); |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 3205 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3206 | // Dump misc stats |
| 3207 | dumpLine(pw, 0 /* uid */, category, MISC_DATA, |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 3208 | screenOnTime / 1000, phoneOnTime / 1000, |
Ashish Sharma | 213bb2f | 2014-07-07 17:14:52 -0700 | [diff] [blame] | 3209 | fullWakeLockTimeTotal / 1000, partialWakeLockTimeTotal / 1000, |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 3210 | getMobileRadioActiveTime(rawRealtime, which) / 1000, |
Ashish Sharma | 213bb2f | 2014-07-07 17:14:52 -0700 | [diff] [blame] | 3211 | getMobileRadioActiveAdjustedTime(which) / 1000, interactiveTime / 1000, |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3212 | powerSaveModeEnabledTime / 1000, connChanges, deviceIdleModeFullTime / 1000, |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 3213 | getDeviceIdleModeCount(DEVICE_IDLE_MODE_DEEP, which), deviceIdlingTime / 1000, |
| 3214 | getDeviceIdlingCount(DEVICE_IDLE_MODE_DEEP, which), |
Adam Lesinski | 782327b | 2015-07-30 16:36:29 -0700 | [diff] [blame] | 3215 | getMobileRadioActiveCount(which), |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3216 | getMobileRadioActiveUnknownTime(which) / 1000, deviceIdleModeLightTime / 1000, |
| 3217 | getDeviceIdleModeCount(DEVICE_IDLE_MODE_LIGHT, which), deviceLightIdlingTime / 1000, |
| 3218 | getDeviceIdlingCount(DEVICE_IDLE_MODE_LIGHT, which), |
| 3219 | getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT), |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 3220 | getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP)); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3221 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3222 | // Dump screen brightness stats |
| 3223 | Object[] args = new Object[NUM_SCREEN_BRIGHTNESS_BINS]; |
| 3224 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3225 | args[i] = getScreenBrightnessTime(i, rawRealtime, which) / 1000; |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3226 | } |
| 3227 | dumpLine(pw, 0 /* uid */, category, SCREEN_BRIGHTNESS_DATA, args); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3228 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3229 | // Dump signal strength stats |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 3230 | args = new Object[SignalStrength.NUM_SIGNAL_STRENGTH_BINS]; |
| 3231 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3232 | args[i] = getPhoneSignalStrengthTime(i, rawRealtime, which) / 1000; |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3233 | } |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3234 | dumpLine(pw, 0 /* uid */, category, SIGNAL_STRENGTH_TIME_DATA, args); |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 3235 | dumpLine(pw, 0 /* uid */, category, SIGNAL_SCANNING_TIME_DATA, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3236 | getPhoneSignalScanningTime(rawRealtime, which) / 1000); |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 3237 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3238 | args[i] = getPhoneSignalStrengthCount(i, which); |
| 3239 | } |
| 3240 | dumpLine(pw, 0 /* uid */, category, SIGNAL_STRENGTH_COUNT_DATA, args); |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 3241 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3242 | // Dump network type stats |
| 3243 | args = new Object[NUM_DATA_CONNECTION_TYPES]; |
| 3244 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3245 | args[i] = getPhoneDataConnectionTime(i, rawRealtime, which) / 1000; |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3246 | } |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3247 | dumpLine(pw, 0 /* uid */, category, DATA_CONNECTION_TIME_DATA, args); |
| 3248 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
| 3249 | args[i] = getPhoneDataConnectionCount(i, which); |
| 3250 | } |
| 3251 | dumpLine(pw, 0 /* uid */, category, DATA_CONNECTION_COUNT_DATA, args); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3252 | |
| 3253 | // Dump wifi state stats |
| 3254 | args = new Object[NUM_WIFI_STATES]; |
| 3255 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3256 | args[i] = getWifiStateTime(i, rawRealtime, which) / 1000; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3257 | } |
| 3258 | dumpLine(pw, 0 /* uid */, category, WIFI_STATE_TIME_DATA, args); |
| 3259 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
| 3260 | args[i] = getWifiStateCount(i, which); |
| 3261 | } |
| 3262 | dumpLine(pw, 0 /* uid */, category, WIFI_STATE_COUNT_DATA, args); |
| 3263 | |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 3264 | // Dump wifi suppl state stats |
| 3265 | args = new Object[NUM_WIFI_SUPPL_STATES]; |
| 3266 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
| 3267 | args[i] = getWifiSupplStateTime(i, rawRealtime, which) / 1000; |
| 3268 | } |
| 3269 | dumpLine(pw, 0 /* uid */, category, WIFI_SUPPL_STATE_TIME_DATA, args); |
| 3270 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
| 3271 | args[i] = getWifiSupplStateCount(i, which); |
| 3272 | } |
| 3273 | dumpLine(pw, 0 /* uid */, category, WIFI_SUPPL_STATE_COUNT_DATA, args); |
| 3274 | |
| 3275 | // Dump wifi signal strength stats |
| 3276 | args = new Object[NUM_WIFI_SIGNAL_STRENGTH_BINS]; |
| 3277 | for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 3278 | args[i] = getWifiSignalStrengthTime(i, rawRealtime, which) / 1000; |
| 3279 | } |
| 3280 | dumpLine(pw, 0 /* uid */, category, WIFI_SIGNAL_STRENGTH_TIME_DATA, args); |
| 3281 | for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 3282 | args[i] = getWifiSignalStrengthCount(i, which); |
| 3283 | } |
| 3284 | dumpLine(pw, 0 /* uid */, category, WIFI_SIGNAL_STRENGTH_COUNT_DATA, args); |
| 3285 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3286 | if (which == STATS_SINCE_UNPLUGGED) { |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 3287 | dumpLine(pw, 0 /* uid */, category, BATTERY_LEVEL_DATA, getDischargeStartLevel(), |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 3288 | getDischargeCurrentLevel()); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3289 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3290 | |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 3291 | if (which == STATS_SINCE_UNPLUGGED) { |
| 3292 | dumpLine(pw, 0 /* uid */, category, BATTERY_DISCHARGE_DATA, |
| 3293 | getDischargeStartLevel()-getDischargeCurrentLevel(), |
| 3294 | getDischargeStartLevel()-getDischargeCurrentLevel(), |
Adam Lesinski | 67c134f | 2016-06-10 15:15:08 -0700 | [diff] [blame] | 3295 | getDischargeAmountScreenOn(), getDischargeAmountScreenOff(), |
| 3296 | dischargeCount / 1000, dischargeScreenOffCount / 1000); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 3297 | } else { |
| 3298 | dumpLine(pw, 0 /* uid */, category, BATTERY_DISCHARGE_DATA, |
| 3299 | getLowDischargeAmountSinceCharge(), getHighDischargeAmountSinceCharge(), |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 3300 | getDischargeAmountScreenOnSinceCharge(), |
Adam Lesinski | 67c134f | 2016-06-10 15:15:08 -0700 | [diff] [blame] | 3301 | getDischargeAmountScreenOffSinceCharge(), |
| 3302 | dischargeCount / 1000, dischargeScreenOffCount / 1000); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 3303 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3304 | |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 3305 | if (reqUid < 0) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3306 | final Map<String, ? extends Timer> kernelWakelocks = getKernelWakelockStats(); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 3307 | if (kernelWakelocks.size() > 0) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3308 | for (Map.Entry<String, ? extends Timer> ent : kernelWakelocks.entrySet()) { |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 3309 | sb.setLength(0); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3310 | printWakeLockCheckin(sb, ent.getValue(), rawRealtime, null, which, ""); |
Kweku Adams | e0dd9c1 | 2017-03-08 08:12:15 -0800 | [diff] [blame] | 3311 | dumpLine(pw, 0 /* uid */, category, KERNEL_WAKELOCK_DATA, |
| 3312 | "\"" + ent.getKey() + "\"", sb.toString()); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 3313 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 3314 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3315 | final Map<String, ? extends Timer> wakeupReasons = getWakeupReasonStats(); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3316 | if (wakeupReasons.size() > 0) { |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 3317 | for (Map.Entry<String, ? extends Timer> ent : wakeupReasons.entrySet()) { |
| 3318 | // Not doing the regular wake lock formatting to remain compatible |
| 3319 | // with the old checkin format. |
| 3320 | long totalTimeMicros = ent.getValue().getTotalTimeLocked(rawRealtime, which); |
| 3321 | int count = ent.getValue().getCountLocked(which); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3322 | dumpLine(pw, 0 /* uid */, category, WAKEUP_REASON_DATA, |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 3323 | "\"" + ent.getKey() + "\"", (totalTimeMicros + 500) / 1000, count); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3324 | } |
| 3325 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 3326 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3327 | |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame^] | 3328 | final Map<String, ? extends Timer> rpmStats = getRpmStats(); |
| 3329 | final Map<String, ? extends Timer> screenOffRpmStats = getScreenOffRpmStats(); |
| 3330 | if (rpmStats.size() > 0) { |
| 3331 | for (Map.Entry<String, ? extends Timer> ent : rpmStats.entrySet()) { |
| 3332 | sb.setLength(0); |
| 3333 | Timer totalTimer = ent.getValue(); |
| 3334 | long timeMs = (totalTimer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000; |
| 3335 | int count = totalTimer.getCountLocked(which); |
| 3336 | Timer screenOffTimer = screenOffRpmStats.get(ent.getKey()); |
| 3337 | long screenOffTimeMs = screenOffTimer != null |
| 3338 | ? (screenOffTimer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000 : 0; |
| 3339 | int screenOffCount = screenOffTimer != null |
| 3340 | ? screenOffTimer.getCountLocked(which) : 0; |
| 3341 | dumpLine(pw, 0 /* uid */, category, RESOURCE_POWER_MANAGER_DATA, |
| 3342 | "\"" + ent.getKey() + "\"", timeMs, count, screenOffTimeMs, screenOffCount); |
| 3343 | } |
| 3344 | } |
| 3345 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3346 | final BatteryStatsHelper helper = new BatteryStatsHelper(context, false, wifiOnly); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3347 | helper.create(this); |
| 3348 | helper.refreshStats(which, UserHandle.USER_ALL); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3349 | final List<BatterySipper> sippers = helper.getUsageList(); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3350 | if (sippers != null && sippers.size() > 0) { |
| 3351 | dumpLine(pw, 0 /* uid */, category, POWER_USE_SUMMARY_DATA, |
| 3352 | BatteryStatsHelper.makemAh(helper.getPowerProfile().getBatteryCapacity()), |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3353 | BatteryStatsHelper.makemAh(helper.getComputedPower()), |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3354 | BatteryStatsHelper.makemAh(helper.getMinDrainedPower()), |
| 3355 | BatteryStatsHelper.makemAh(helper.getMaxDrainedPower())); |
| 3356 | for (int i=0; i<sippers.size(); i++) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3357 | final BatterySipper bs = sippers.get(i); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3358 | int uid = 0; |
| 3359 | String label; |
| 3360 | switch (bs.drainType) { |
| 3361 | case IDLE: |
| 3362 | label="idle"; |
| 3363 | break; |
| 3364 | case CELL: |
| 3365 | label="cell"; |
| 3366 | break; |
| 3367 | case PHONE: |
| 3368 | label="phone"; |
| 3369 | break; |
| 3370 | case WIFI: |
| 3371 | label="wifi"; |
| 3372 | break; |
| 3373 | case BLUETOOTH: |
| 3374 | label="blue"; |
| 3375 | break; |
| 3376 | case SCREEN: |
| 3377 | label="scrn"; |
| 3378 | break; |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 3379 | case FLASHLIGHT: |
| 3380 | label="flashlight"; |
| 3381 | break; |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3382 | case APP: |
| 3383 | uid = bs.uidObj.getUid(); |
| 3384 | label = "uid"; |
| 3385 | break; |
| 3386 | case USER: |
| 3387 | uid = UserHandle.getUid(bs.userId, 0); |
| 3388 | label = "user"; |
| 3389 | break; |
| 3390 | case UNACCOUNTED: |
| 3391 | label = "unacc"; |
| 3392 | break; |
| 3393 | case OVERCOUNTED: |
| 3394 | label = "over"; |
| 3395 | break; |
Ruben Brunk | 5b1308f | 2015-06-03 18:49:27 -0700 | [diff] [blame] | 3396 | case CAMERA: |
| 3397 | label = "camera"; |
| 3398 | break; |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3399 | default: |
| 3400 | label = "???"; |
| 3401 | } |
| 3402 | dumpLine(pw, uid, category, POWER_USE_ITEM_DATA, label, |
Bookatz | 17d7d9d | 2017-06-08 14:50:46 -0700 | [diff] [blame] | 3403 | BatteryStatsHelper.makemAh(bs.totalPowerMah), |
| 3404 | bs.shouldHide ? 1 : 0, |
| 3405 | BatteryStatsHelper.makemAh(bs.screenPowerMah), |
| 3406 | BatteryStatsHelper.makemAh(bs.proportionalSmearMah)); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3407 | } |
| 3408 | } |
| 3409 | |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 3410 | final long[] cpuFreqs = getCpuFreqs(); |
| 3411 | if (cpuFreqs != null) { |
| 3412 | sb.setLength(0); |
| 3413 | for (int i = 0; i < cpuFreqs.length; ++i) { |
| 3414 | sb.append((i == 0 ? "" : ",") + cpuFreqs[i]); |
| 3415 | } |
| 3416 | dumpLine(pw, 0 /* uid */, category, GLOBAL_CPU_FREQ_DATA, sb.toString()); |
| 3417 | } |
| 3418 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3419 | for (int iu = 0; iu < NU; iu++) { |
| 3420 | final int uid = uidStats.keyAt(iu); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 3421 | if (reqUid >= 0 && uid != reqUid) { |
| 3422 | continue; |
| 3423 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3424 | final Uid u = uidStats.valueAt(iu); |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 3425 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3426 | // Dump Network stats per uid, if any |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3427 | final long mobileBytesRx = u.getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which); |
| 3428 | final long mobileBytesTx = u.getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which); |
| 3429 | final long wifiBytesRx = u.getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which); |
| 3430 | final long wifiBytesTx = u.getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which); |
| 3431 | final long mobilePacketsRx = u.getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which); |
| 3432 | final long mobilePacketsTx = u.getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which); |
| 3433 | final long mobileActiveTime = u.getMobileRadioActiveTime(which); |
| 3434 | final int mobileActiveCount = u.getMobileRadioActiveCount(which); |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 3435 | final long mobileWakeup = u.getMobileRadioApWakeupCount(which); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3436 | final long wifiPacketsRx = u.getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which); |
| 3437 | final long wifiPacketsTx = u.getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which); |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 3438 | final long wifiWakeup = u.getWifiRadioApWakeupCount(which); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 3439 | final long btBytesRx = u.getNetworkActivityBytes(NETWORK_BT_RX_DATA, which); |
| 3440 | final long btBytesTx = u.getNetworkActivityBytes(NETWORK_BT_TX_DATA, which); |
Amith Yamasani | 59fe841 | 2017-03-03 16:28:52 -0800 | [diff] [blame] | 3441 | // Background data transfers |
| 3442 | final long mobileBytesBgRx = u.getNetworkActivityBytes(NETWORK_MOBILE_BG_RX_DATA, |
| 3443 | which); |
| 3444 | final long mobileBytesBgTx = u.getNetworkActivityBytes(NETWORK_MOBILE_BG_TX_DATA, |
| 3445 | which); |
| 3446 | final long wifiBytesBgRx = u.getNetworkActivityBytes(NETWORK_WIFI_BG_RX_DATA, which); |
| 3447 | final long wifiBytesBgTx = u.getNetworkActivityBytes(NETWORK_WIFI_BG_TX_DATA, which); |
| 3448 | final long mobilePacketsBgRx = u.getNetworkActivityPackets(NETWORK_MOBILE_BG_RX_DATA, |
| 3449 | which); |
| 3450 | final long mobilePacketsBgTx = u.getNetworkActivityPackets(NETWORK_MOBILE_BG_TX_DATA, |
| 3451 | which); |
| 3452 | final long wifiPacketsBgRx = u.getNetworkActivityPackets(NETWORK_WIFI_BG_RX_DATA, |
| 3453 | which); |
| 3454 | final long wifiPacketsBgTx = u.getNetworkActivityPackets(NETWORK_WIFI_BG_TX_DATA, |
| 3455 | which); |
| 3456 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3457 | if (mobileBytesRx > 0 || mobileBytesTx > 0 || wifiBytesRx > 0 || wifiBytesTx > 0 |
| 3458 | || mobilePacketsRx > 0 || mobilePacketsTx > 0 || wifiPacketsRx > 0 |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 3459 | || wifiPacketsTx > 0 || mobileActiveTime > 0 || mobileActiveCount > 0 |
Amith Yamasani | 59fe841 | 2017-03-03 16:28:52 -0800 | [diff] [blame] | 3460 | || btBytesRx > 0 || btBytesTx > 0 || mobileWakeup > 0 || wifiWakeup > 0 |
| 3461 | || mobileBytesBgRx > 0 || mobileBytesBgTx > 0 || wifiBytesBgRx > 0 |
| 3462 | || wifiBytesBgTx > 0 |
| 3463 | || mobilePacketsBgRx > 0 || mobilePacketsBgTx > 0 || wifiPacketsBgRx > 0 |
| 3464 | || wifiPacketsBgTx > 0) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3465 | dumpLine(pw, uid, category, NETWORK_DATA, mobileBytesRx, mobileBytesTx, |
| 3466 | wifiBytesRx, wifiBytesTx, |
| 3467 | mobilePacketsRx, mobilePacketsTx, |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 3468 | wifiPacketsRx, wifiPacketsTx, |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 3469 | mobileActiveTime, mobileActiveCount, |
Amith Yamasani | 59fe841 | 2017-03-03 16:28:52 -0800 | [diff] [blame] | 3470 | btBytesRx, btBytesTx, mobileWakeup, wifiWakeup, |
| 3471 | mobileBytesBgRx, mobileBytesBgTx, wifiBytesBgRx, wifiBytesBgTx, |
| 3472 | mobilePacketsBgRx, mobilePacketsBgTx, wifiPacketsBgRx, wifiPacketsBgTx |
| 3473 | ); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 3474 | } |
| 3475 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3476 | // Dump modem controller data, per UID. |
| 3477 | dumpControllerActivityLine(pw, uid, category, MODEM_CONTROLLER_DATA, |
| 3478 | u.getModemControllerActivity(), which); |
| 3479 | |
| 3480 | // Dump Wifi controller data, per UID. |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 3481 | final long fullWifiLockOnTime = u.getFullWifiLockTime(rawRealtime, which); |
| 3482 | final long wifiScanTime = u.getWifiScanTime(rawRealtime, which); |
| 3483 | final int wifiScanCount = u.getWifiScanCount(which); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 3484 | final int wifiScanCountBg = u.getWifiScanBackgroundCount(which); |
| 3485 | // Note that 'ActualTime' are unpooled and always since reset (regardless of 'which') |
Bookatz | ce49aca | 2017-04-03 09:47:05 -0700 | [diff] [blame] | 3486 | final long wifiScanActualTimeMs = (u.getWifiScanActualTime(rawRealtime) + 500) / 1000; |
| 3487 | final long wifiScanActualTimeMsBg = (u.getWifiScanBackgroundTime(rawRealtime) + 500) |
| 3488 | / 1000; |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 3489 | final long uidWifiRunningTime = u.getWifiRunningTime(rawRealtime, which); |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 3490 | if (fullWifiLockOnTime != 0 || wifiScanTime != 0 || wifiScanCount != 0 |
Bookatz | ce49aca | 2017-04-03 09:47:05 -0700 | [diff] [blame] | 3491 | || wifiScanCountBg != 0 || wifiScanActualTimeMs != 0 |
| 3492 | || wifiScanActualTimeMsBg != 0 || uidWifiRunningTime != 0) { |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3493 | dumpLine(pw, uid, category, WIFI_DATA, fullWifiLockOnTime, wifiScanTime, |
| 3494 | uidWifiRunningTime, wifiScanCount, |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 3495 | /* legacy fields follow, keep at 0 */ 0, 0, 0, |
Bookatz | ce49aca | 2017-04-03 09:47:05 -0700 | [diff] [blame] | 3496 | wifiScanCountBg, wifiScanActualTimeMs, wifiScanActualTimeMsBg); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3497 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3498 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3499 | dumpControllerActivityLine(pw, uid, category, WIFI_CONTROLLER_DATA, |
| 3500 | u.getWifiControllerActivity(), which); |
| 3501 | |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 3502 | final Timer bleTimer = u.getBluetoothScanTimer(); |
| 3503 | if (bleTimer != null) { |
| 3504 | // Convert from microseconds to milliseconds with rounding |
| 3505 | final long totalTime = (bleTimer.getTotalTimeLocked(rawRealtime, which) + 500) |
| 3506 | / 1000; |
| 3507 | if (totalTime != 0) { |
| 3508 | final int count = bleTimer.getCountLocked(which); |
| 3509 | final Timer bleTimerBg = u.getBluetoothScanBackgroundTimer(); |
| 3510 | final int countBg = bleTimerBg != null ? bleTimerBg.getCountLocked(which) : 0; |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 3511 | // 'actualTime' are unpooled and always since reset (regardless of 'which') |
| 3512 | final long actualTime = bleTimer.getTotalDurationMsLocked(rawRealtimeMs); |
| 3513 | final long actualTimeBg = bleTimerBg != null ? |
| 3514 | bleTimerBg.getTotalDurationMsLocked(rawRealtimeMs) : 0; |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 3515 | // Result counters |
Bookatz | 956f36bf | 2017-04-28 09:48:17 -0700 | [diff] [blame] | 3516 | final int resultCount = u.getBluetoothScanResultCounter() != null ? |
| 3517 | u.getBluetoothScanResultCounter().getCountLocked(which) : 0; |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 3518 | final int resultCountBg = u.getBluetoothScanResultBgCounter() != null ? |
| 3519 | u.getBluetoothScanResultBgCounter().getCountLocked(which) : 0; |
| 3520 | // Unoptimized scan timer. Unpooled and since reset (regardless of 'which'). |
| 3521 | final Timer unoptimizedScanTimer = u.getBluetoothUnoptimizedScanTimer(); |
| 3522 | final long unoptimizedScanTotalTime = unoptimizedScanTimer != null ? |
| 3523 | unoptimizedScanTimer.getTotalDurationMsLocked(rawRealtimeMs) : 0; |
| 3524 | final long unoptimizedScanMaxTime = unoptimizedScanTimer != null ? |
| 3525 | unoptimizedScanTimer.getMaxDurationMsLocked(rawRealtimeMs) : 0; |
| 3526 | // Unoptimized bg scan timer. Unpooled and since reset (regardless of 'which'). |
| 3527 | final Timer unoptimizedScanTimerBg = |
| 3528 | u.getBluetoothUnoptimizedScanBackgroundTimer(); |
| 3529 | final long unoptimizedScanTotalTimeBg = unoptimizedScanTimerBg != null ? |
| 3530 | unoptimizedScanTimerBg.getTotalDurationMsLocked(rawRealtimeMs) : 0; |
| 3531 | final long unoptimizedScanMaxTimeBg = unoptimizedScanTimerBg != null ? |
| 3532 | unoptimizedScanTimerBg.getMaxDurationMsLocked(rawRealtimeMs) : 0; |
| 3533 | |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 3534 | dumpLine(pw, uid, category, BLUETOOTH_MISC_DATA, totalTime, count, |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 3535 | countBg, actualTime, actualTimeBg, resultCount, resultCountBg, |
| 3536 | unoptimizedScanTotalTime, unoptimizedScanTotalTimeBg, |
| 3537 | unoptimizedScanMaxTime, unoptimizedScanMaxTimeBg); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 3538 | } |
| 3539 | } |
Adam Lesinski | d9b99be | 2016-03-30 16:58:51 -0700 | [diff] [blame] | 3540 | |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 3541 | dumpControllerActivityLine(pw, uid, category, BLUETOOTH_CONTROLLER_DATA, |
| 3542 | u.getBluetoothControllerActivity(), which); |
| 3543 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3544 | if (u.hasUserActivity()) { |
| 3545 | args = new Object[Uid.NUM_USER_ACTIVITY_TYPES]; |
| 3546 | boolean hasData = false; |
| 3547 | for (int i=0; i<Uid.NUM_USER_ACTIVITY_TYPES; i++) { |
| 3548 | int val = u.getUserActivityCount(i, which); |
| 3549 | args[i] = val; |
| 3550 | if (val != 0) hasData = true; |
| 3551 | } |
| 3552 | if (hasData) { |
Ashish Sharma | cba1215 | 2014-07-07 17:14:52 -0700 | [diff] [blame] | 3553 | dumpLine(pw, uid /* uid */, category, USER_ACTIVITY_DATA, args); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3554 | } |
| 3555 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3556 | |
| 3557 | if (u.getAggregatedPartialWakelockTimer() != null) { |
| 3558 | final Timer timer = u.getAggregatedPartialWakelockTimer(); |
Bookatz | 6d79993 | 2017-06-07 12:30:07 -0700 | [diff] [blame] | 3559 | // Times are since reset (regardless of 'which') |
| 3560 | final long totTimeMs = timer.getTotalDurationMsLocked(rawRealtimeMs); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3561 | final Timer bgTimer = timer.getSubTimer(); |
| 3562 | final long bgTimeMs = bgTimer != null ? |
Bookatz | 6d79993 | 2017-06-07 12:30:07 -0700 | [diff] [blame] | 3563 | bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : 0; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3564 | dumpLine(pw, uid, category, AGGREGATED_WAKELOCK_DATA, totTimeMs, bgTimeMs); |
| 3565 | } |
| 3566 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3567 | final ArrayMap<String, ? extends Uid.Wakelock> wakelocks = u.getWakelockStats(); |
| 3568 | for (int iw=wakelocks.size()-1; iw>=0; iw--) { |
| 3569 | final Uid.Wakelock wl = wakelocks.valueAt(iw); |
| 3570 | String linePrefix = ""; |
| 3571 | sb.setLength(0); |
| 3572 | linePrefix = printWakeLockCheckin(sb, wl.getWakeTime(WAKE_TYPE_FULL), |
| 3573 | rawRealtime, "f", which, linePrefix); |
Bookatz | 5b5ec32 | 2017-05-26 09:40:38 -0700 | [diff] [blame] | 3574 | final Timer pTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL); |
| 3575 | linePrefix = printWakeLockCheckin(sb, pTimer, |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3576 | rawRealtime, "p", which, linePrefix); |
Bookatz | 5b5ec32 | 2017-05-26 09:40:38 -0700 | [diff] [blame] | 3577 | linePrefix = printWakeLockCheckin(sb, pTimer != null ? pTimer.getSubTimer() : null, |
| 3578 | rawRealtime, "bp", which, linePrefix); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3579 | linePrefix = printWakeLockCheckin(sb, wl.getWakeTime(WAKE_TYPE_WINDOW), |
| 3580 | rawRealtime, "w", which, linePrefix); |
| 3581 | |
| 3582 | // Only log if we had at lease one wakelock... |
| 3583 | if (sb.length() > 0) { |
| 3584 | String name = wakelocks.keyAt(iw); |
| 3585 | if (name.indexOf(',') >= 0) { |
| 3586 | name = name.replace(',', '_'); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3587 | } |
Yi Jin | 0248336 | 2017-08-04 11:30:44 -0700 | [diff] [blame] | 3588 | if (name.indexOf('\n') >= 0) { |
| 3589 | name = name.replace('\n', '_'); |
| 3590 | } |
| 3591 | if (name.indexOf('\r') >= 0) { |
| 3592 | name = name.replace('\r', '_'); |
| 3593 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3594 | dumpLine(pw, uid, category, WAKELOCK_DATA, name, sb.toString()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3595 | } |
| 3596 | } |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 3597 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3598 | final ArrayMap<String, ? extends Timer> syncs = u.getSyncStats(); |
| 3599 | for (int isy=syncs.size()-1; isy>=0; isy--) { |
| 3600 | final Timer timer = syncs.valueAt(isy); |
| 3601 | // Convert from microseconds to milliseconds with rounding |
| 3602 | final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000; |
| 3603 | final int count = timer.getCountLocked(which); |
Bookatz | 2bffb5b | 2017-04-13 11:59:33 -0700 | [diff] [blame] | 3604 | final Timer bgTimer = timer.getSubTimer(); |
| 3605 | final long bgTime = bgTimer != null ? |
Bookatz | 6d79993 | 2017-06-07 12:30:07 -0700 | [diff] [blame] | 3606 | bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : -1; |
Bookatz | 2bffb5b | 2017-04-13 11:59:33 -0700 | [diff] [blame] | 3607 | final int bgCount = bgTimer != null ? bgTimer.getCountLocked(which) : -1; |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3608 | if (totalTime != 0) { |
Kweku Adams | e0dd9c1 | 2017-03-08 08:12:15 -0800 | [diff] [blame] | 3609 | dumpLine(pw, uid, category, SYNC_DATA, "\"" + syncs.keyAt(isy) + "\"", |
Bookatz | 2bffb5b | 2017-04-13 11:59:33 -0700 | [diff] [blame] | 3610 | totalTime, count, bgTime, bgCount); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 3611 | } |
| 3612 | } |
| 3613 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3614 | final ArrayMap<String, ? extends Timer> jobs = u.getJobStats(); |
| 3615 | for (int ij=jobs.size()-1; ij>=0; ij--) { |
| 3616 | final Timer timer = jobs.valueAt(ij); |
| 3617 | // Convert from microseconds to milliseconds with rounding |
| 3618 | final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000; |
| 3619 | final int count = timer.getCountLocked(which); |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 3620 | final Timer bgTimer = timer.getSubTimer(); |
| 3621 | final long bgTime = bgTimer != null ? |
Bookatz | 6d79993 | 2017-06-07 12:30:07 -0700 | [diff] [blame] | 3622 | bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : -1; |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 3623 | final int bgCount = bgTimer != null ? bgTimer.getCountLocked(which) : -1; |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3624 | if (totalTime != 0) { |
Kweku Adams | e0dd9c1 | 2017-03-08 08:12:15 -0800 | [diff] [blame] | 3625 | dumpLine(pw, uid, category, JOB_DATA, "\"" + jobs.keyAt(ij) + "\"", |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 3626 | totalTime, count, bgTime, bgCount); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 3627 | } |
| 3628 | } |
| 3629 | |
Dianne Hackborn | 94326cb | 2017-06-28 16:17:20 -0700 | [diff] [blame] | 3630 | final ArrayMap<String, SparseIntArray> completions = u.getJobCompletionStats(); |
| 3631 | for (int ic=completions.size()-1; ic>=0; ic--) { |
| 3632 | SparseIntArray types = completions.valueAt(ic); |
| 3633 | if (types != null) { |
| 3634 | dumpLine(pw, uid, category, JOB_COMPLETION_DATA, |
| 3635 | "\"" + completions.keyAt(ic) + "\"", |
| 3636 | types.get(JobParameters.REASON_CANCELED, 0), |
| 3637 | types.get(JobParameters.REASON_CONSTRAINTS_NOT_SATISFIED, 0), |
| 3638 | types.get(JobParameters.REASON_PREEMPT, 0), |
| 3639 | types.get(JobParameters.REASON_TIMEOUT, 0), |
| 3640 | types.get(JobParameters.REASON_DEVICE_IDLE, 0)); |
| 3641 | } |
| 3642 | } |
| 3643 | |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 3644 | dumpTimer(pw, uid, category, FLASHLIGHT_DATA, u.getFlashlightTurnedOnTimer(), |
| 3645 | rawRealtime, which); |
| 3646 | dumpTimer(pw, uid, category, CAMERA_DATA, u.getCameraTurnedOnTimer(), |
| 3647 | rawRealtime, which); |
| 3648 | dumpTimer(pw, uid, category, VIDEO_DATA, u.getVideoTurnedOnTimer(), |
| 3649 | rawRealtime, which); |
| 3650 | dumpTimer(pw, uid, category, AUDIO_DATA, u.getAudioTurnedOnTimer(), |
| 3651 | rawRealtime, which); |
| 3652 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3653 | final SparseArray<? extends BatteryStats.Uid.Sensor> sensors = u.getSensorStats(); |
| 3654 | final int NSE = sensors.size(); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 3655 | for (int ise=0; ise<NSE; ise++) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3656 | final Uid.Sensor se = sensors.valueAt(ise); |
| 3657 | final int sensorNumber = sensors.keyAt(ise); |
| 3658 | final Timer timer = se.getSensorTime(); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 3659 | if (timer != null) { |
| 3660 | // Convert from microseconds to milliseconds with rounding |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3661 | final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) |
| 3662 | / 1000; |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 3663 | if (totalTime != 0) { |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 3664 | final int count = timer.getCountLocked(which); |
| 3665 | final Timer bgTimer = se.getSensorBackgroundTime(); |
| 3666 | final int bgCount = bgTimer != null ? bgTimer.getCountLocked(which) : 0; |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 3667 | // 'actualTime' are unpooled and always since reset (regardless of 'which') |
| 3668 | final long actualTime = timer.getTotalDurationMsLocked(rawRealtimeMs); |
| 3669 | final long bgActualTime = bgTimer != null ? |
| 3670 | bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : 0; |
| 3671 | dumpLine(pw, uid, category, SENSOR_DATA, sensorNumber, totalTime, |
| 3672 | count, bgCount, actualTime, bgActualTime); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 3673 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3674 | } |
| 3675 | } |
| 3676 | |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 3677 | dumpTimer(pw, uid, category, VIBRATOR_DATA, u.getVibratorOnTimer(), |
| 3678 | rawRealtime, which); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 3679 | |
Michael Wachenschwanz | b05a3c5 | 2017-07-07 17:47:04 -0700 | [diff] [blame] | 3680 | dumpTimer(pw, uid, category, FOREGROUND_ACTIVITY_DATA, u.getForegroundActivityTimer(), |
| 3681 | rawRealtime, which); |
| 3682 | |
| 3683 | dumpTimer(pw, uid, category, FOREGROUND_SERVICE_DATA, u.getForegroundServiceTimer(), |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 3684 | rawRealtime, which); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 3685 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3686 | final Object[] stateTimes = new Object[Uid.NUM_PROCESS_STATE]; |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 3687 | long totalStateTime = 0; |
| 3688 | for (int ips=0; ips<Uid.NUM_PROCESS_STATE; ips++) { |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 3689 | final long time = u.getProcessStateTime(ips, rawRealtime, which); |
| 3690 | totalStateTime += time; |
| 3691 | stateTimes[ips] = (time + 500) / 1000; |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 3692 | } |
| 3693 | if (totalStateTime > 0) { |
| 3694 | dumpLine(pw, uid, category, STATE_TIME_DATA, stateTimes); |
| 3695 | } |
| 3696 | |
Adam Lesinski | a7a4ccc | 2015-06-26 17:43:04 -0700 | [diff] [blame] | 3697 | final long userCpuTimeUs = u.getUserCpuTimeUs(which); |
| 3698 | final long systemCpuTimeUs = u.getSystemCpuTimeUs(which); |
Adam Lesinski | d4abd1e | 2017-04-12 11:29:13 -0700 | [diff] [blame] | 3699 | if (userCpuTimeUs > 0 || systemCpuTimeUs > 0) { |
Adam Lesinski | a7a4ccc | 2015-06-26 17:43:04 -0700 | [diff] [blame] | 3700 | dumpLine(pw, uid, category, CPU_DATA, userCpuTimeUs / 1000, systemCpuTimeUs / 1000, |
Adam Lesinski | d4abd1e | 2017-04-12 11:29:13 -0700 | [diff] [blame] | 3701 | 0 /* old cpu power, keep for compatibility */); |
Adam Lesinski | a7a4ccc | 2015-06-26 17:43:04 -0700 | [diff] [blame] | 3702 | } |
| 3703 | |
Sudheer Shanka | a87245d | 2017-08-10 12:02:31 -0700 | [diff] [blame] | 3704 | // If the cpuFreqs is null, then don't bother checking for cpu freq times. |
| 3705 | if (cpuFreqs != null) { |
| 3706 | final long[] cpuFreqTimeMs = u.getCpuFreqTimes(which); |
| 3707 | // If total cpuFreqTimes is null, then we don't need to check for |
| 3708 | // screenOffCpuFreqTimes. |
| 3709 | if (cpuFreqTimeMs != null && cpuFreqTimeMs.length == cpuFreqs.length) { |
| 3710 | sb.setLength(0); |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 3711 | for (int i = 0; i < cpuFreqTimeMs.length; ++i) { |
Sudheer Shanka | a87245d | 2017-08-10 12:02:31 -0700 | [diff] [blame] | 3712 | sb.append((i == 0 ? "" : ",") + cpuFreqTimeMs[i]); |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 3713 | } |
Sudheer Shanka | a87245d | 2017-08-10 12:02:31 -0700 | [diff] [blame] | 3714 | final long[] screenOffCpuFreqTimeMs = u.getScreenOffCpuFreqTimes(which); |
| 3715 | if (screenOffCpuFreqTimeMs != null) { |
| 3716 | for (int i = 0; i < screenOffCpuFreqTimeMs.length; ++i) { |
| 3717 | sb.append("," + screenOffCpuFreqTimeMs[i]); |
| 3718 | } |
| 3719 | } else { |
| 3720 | for (int i = 0; i < cpuFreqTimeMs.length; ++i) { |
| 3721 | sb.append(",0"); |
| 3722 | } |
| 3723 | } |
| 3724 | dumpLine(pw, uid, category, CPU_TIMES_AT_FREQ_DATA, UID_TIMES_TYPE_ALL, |
| 3725 | cpuFreqTimeMs.length, sb.toString()); |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 3726 | } |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 3727 | } |
| 3728 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3729 | final ArrayMap<String, ? extends BatteryStats.Uid.Proc> processStats |
| 3730 | = u.getProcessStats(); |
| 3731 | for (int ipr=processStats.size()-1; ipr>=0; ipr--) { |
| 3732 | final Uid.Proc ps = processStats.valueAt(ipr); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 3733 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3734 | final long userMillis = ps.getUserTime(which); |
| 3735 | final long systemMillis = ps.getSystemTime(which); |
| 3736 | final long foregroundMillis = ps.getForegroundTime(which); |
| 3737 | final int starts = ps.getStarts(which); |
| 3738 | final int numCrashes = ps.getNumCrashes(which); |
| 3739 | final int numAnrs = ps.getNumAnrs(which); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 3740 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3741 | if (userMillis != 0 || systemMillis != 0 || foregroundMillis != 0 |
| 3742 | || starts != 0 || numAnrs != 0 || numCrashes != 0) { |
Kweku Adams | e0dd9c1 | 2017-03-08 08:12:15 -0800 | [diff] [blame] | 3743 | dumpLine(pw, uid, category, PROCESS_DATA, "\"" + processStats.keyAt(ipr) + "\"", |
| 3744 | userMillis, systemMillis, foregroundMillis, starts, numAnrs, numCrashes); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3745 | } |
| 3746 | } |
| 3747 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3748 | final ArrayMap<String, ? extends BatteryStats.Uid.Pkg> packageStats |
| 3749 | = u.getPackageStats(); |
| 3750 | for (int ipkg=packageStats.size()-1; ipkg>=0; ipkg--) { |
| 3751 | final Uid.Pkg ps = packageStats.valueAt(ipkg); |
| 3752 | int wakeups = 0; |
| 3753 | final ArrayMap<String, ? extends Counter> alarms = ps.getWakeupAlarmStats(); |
| 3754 | for (int iwa=alarms.size()-1; iwa>=0; iwa--) { |
Joe Onorato | 1476d32 | 2016-05-05 14:46:15 -0700 | [diff] [blame] | 3755 | int count = alarms.valueAt(iwa).getCountLocked(which); |
| 3756 | wakeups += count; |
| 3757 | String name = alarms.keyAt(iwa).replace(',', '_'); |
| 3758 | dumpLine(pw, uid, category, WAKEUP_ALARM_DATA, name, count); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3759 | } |
| 3760 | final ArrayMap<String, ? extends Uid.Pkg.Serv> serviceStats = ps.getServiceStats(); |
| 3761 | for (int isvc=serviceStats.size()-1; isvc>=0; isvc--) { |
| 3762 | final BatteryStats.Uid.Pkg.Serv ss = serviceStats.valueAt(isvc); |
| 3763 | final long startTime = ss.getStartTime(batteryUptime, which); |
| 3764 | final int starts = ss.getStarts(which); |
| 3765 | final int launches = ss.getLaunches(which); |
| 3766 | if (startTime != 0 || starts != 0 || launches != 0) { |
| 3767 | dumpLine(pw, uid, category, APK_DATA, |
| 3768 | wakeups, // wakeup alarms |
| 3769 | packageStats.keyAt(ipkg), // Apk |
| 3770 | serviceStats.keyAt(isvc), // service |
| 3771 | startTime / 1000, // time spent started, in ms |
| 3772 | starts, |
| 3773 | launches); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3774 | } |
| 3775 | } |
| 3776 | } |
| 3777 | } |
| 3778 | } |
| 3779 | |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 3780 | static final class TimerEntry { |
| 3781 | final String mName; |
| 3782 | final int mId; |
| 3783 | final BatteryStats.Timer mTimer; |
| 3784 | final long mTime; |
| 3785 | TimerEntry(String name, int id, BatteryStats.Timer timer, long time) { |
| 3786 | mName = name; |
| 3787 | mId = id; |
| 3788 | mTimer = timer; |
| 3789 | mTime = time; |
| 3790 | } |
| 3791 | } |
| 3792 | |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3793 | private void printmAh(PrintWriter printer, double power) { |
| 3794 | printer.print(BatteryStatsHelper.makemAh(power)); |
| 3795 | } |
| 3796 | |
Adam Lesinski | a7a4ccc | 2015-06-26 17:43:04 -0700 | [diff] [blame] | 3797 | private void printmAh(StringBuilder sb, double power) { |
| 3798 | sb.append(BatteryStatsHelper.makemAh(power)); |
| 3799 | } |
| 3800 | |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 3801 | /** |
| 3802 | * Temporary for settings. |
| 3803 | */ |
| 3804 | public final void dumpLocked(Context context, PrintWriter pw, String prefix, int which, |
| 3805 | int reqUid) { |
| 3806 | dumpLocked(context, pw, prefix, which, reqUid, BatteryStatsHelper.checkWifiOnly(context)); |
| 3807 | } |
| 3808 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3809 | @SuppressWarnings("unused") |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3810 | 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] | 3811 | int reqUid, boolean wifiOnly) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3812 | final long rawUptime = SystemClock.uptimeMillis() * 1000; |
| 3813 | final long rawRealtime = SystemClock.elapsedRealtime() * 1000; |
Bookatz | 6d79993 | 2017-06-07 12:30:07 -0700 | [diff] [blame] | 3814 | final long rawRealtimeMs = (rawRealtime + 500) / 1000; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3815 | final long batteryUptime = getBatteryUptime(rawUptime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3816 | |
| 3817 | final long whichBatteryUptime = computeBatteryUptime(rawUptime, which); |
| 3818 | final long whichBatteryRealtime = computeBatteryRealtime(rawRealtime, which); |
| 3819 | final long totalRealtime = computeRealtime(rawRealtime, which); |
| 3820 | final long totalUptime = computeUptime(rawUptime, which); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3821 | final long whichBatteryScreenOffUptime = computeBatteryScreenOffUptime(rawUptime, which); |
| 3822 | final long whichBatteryScreenOffRealtime = computeBatteryScreenOffRealtime(rawRealtime, |
| 3823 | which); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 3824 | final long batteryTimeRemaining = computeBatteryTimeRemaining(rawRealtime); |
| 3825 | final long chargeTimeRemaining = computeChargeTimeRemaining(rawRealtime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3826 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3827 | final StringBuilder sb = new StringBuilder(128); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3828 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3829 | final SparseArray<? extends Uid> uidStats = getUidStats(); |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 3830 | final int NU = uidStats.size(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3831 | |
Adam Lesinski | f9b20a9 | 2016-06-17 17:30:01 -0700 | [diff] [blame] | 3832 | final int estimatedBatteryCapacity = getEstimatedBatteryCapacity(); |
| 3833 | if (estimatedBatteryCapacity > 0) { |
| 3834 | sb.setLength(0); |
| 3835 | sb.append(prefix); |
| 3836 | sb.append(" Estimated battery capacity: "); |
| 3837 | sb.append(BatteryStatsHelper.makemAh(estimatedBatteryCapacity)); |
| 3838 | sb.append(" mAh"); |
| 3839 | pw.println(sb.toString()); |
| 3840 | } |
| 3841 | |
Jocelyn Dang | c627d10 | 2017-04-14 13:15:14 -0700 | [diff] [blame] | 3842 | final int minLearnedBatteryCapacity = getMinLearnedBatteryCapacity(); |
| 3843 | if (minLearnedBatteryCapacity > 0) { |
| 3844 | sb.setLength(0); |
| 3845 | sb.append(prefix); |
| 3846 | sb.append(" Min learned battery capacity: "); |
| 3847 | sb.append(BatteryStatsHelper.makemAh(minLearnedBatteryCapacity / 1000)); |
| 3848 | sb.append(" mAh"); |
| 3849 | pw.println(sb.toString()); |
| 3850 | } |
| 3851 | final int maxLearnedBatteryCapacity = getMaxLearnedBatteryCapacity(); |
| 3852 | if (maxLearnedBatteryCapacity > 0) { |
| 3853 | sb.setLength(0); |
| 3854 | sb.append(prefix); |
| 3855 | sb.append(" Max learned battery capacity: "); |
| 3856 | sb.append(BatteryStatsHelper.makemAh(maxLearnedBatteryCapacity / 1000)); |
| 3857 | sb.append(" mAh"); |
| 3858 | pw.println(sb.toString()); |
| 3859 | } |
| 3860 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3861 | sb.setLength(0); |
| 3862 | sb.append(prefix); |
| 3863 | sb.append(" Time on battery: "); |
| 3864 | formatTimeMs(sb, whichBatteryRealtime / 1000); sb.append("("); |
| 3865 | sb.append(formatRatioLocked(whichBatteryRealtime, totalRealtime)); |
| 3866 | sb.append(") realtime, "); |
| 3867 | formatTimeMs(sb, whichBatteryUptime / 1000); |
| 3868 | sb.append("("); sb.append(formatRatioLocked(whichBatteryUptime, totalRealtime)); |
| 3869 | sb.append(") uptime"); |
| 3870 | pw.println(sb.toString()); |
| 3871 | sb.setLength(0); |
| 3872 | sb.append(prefix); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3873 | sb.append(" Time on battery screen off: "); |
| 3874 | formatTimeMs(sb, whichBatteryScreenOffRealtime / 1000); sb.append("("); |
| 3875 | sb.append(formatRatioLocked(whichBatteryScreenOffRealtime, totalRealtime)); |
| 3876 | sb.append(") realtime, "); |
| 3877 | formatTimeMs(sb, whichBatteryScreenOffUptime / 1000); |
| 3878 | sb.append("("); |
| 3879 | sb.append(formatRatioLocked(whichBatteryScreenOffUptime, totalRealtime)); |
| 3880 | sb.append(") uptime"); |
| 3881 | pw.println(sb.toString()); |
| 3882 | sb.setLength(0); |
| 3883 | sb.append(prefix); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3884 | sb.append(" Total run time: "); |
| 3885 | formatTimeMs(sb, totalRealtime / 1000); |
| 3886 | sb.append("realtime, "); |
| 3887 | formatTimeMs(sb, totalUptime / 1000); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 3888 | sb.append("uptime"); |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 3889 | pw.println(sb.toString()); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 3890 | if (batteryTimeRemaining >= 0) { |
| 3891 | sb.setLength(0); |
| 3892 | sb.append(prefix); |
| 3893 | sb.append(" Battery time remaining: "); |
| 3894 | formatTimeMs(sb, batteryTimeRemaining / 1000); |
| 3895 | pw.println(sb.toString()); |
| 3896 | } |
| 3897 | if (chargeTimeRemaining >= 0) { |
| 3898 | sb.setLength(0); |
| 3899 | sb.append(prefix); |
| 3900 | sb.append(" Charge time remaining: "); |
| 3901 | formatTimeMs(sb, chargeTimeRemaining / 1000); |
| 3902 | pw.println(sb.toString()); |
| 3903 | } |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 3904 | |
| 3905 | final LongCounter dischargeCounter = getDischargeCoulombCounter(); |
| 3906 | final long dischargeCount = dischargeCounter.getCountLocked(which); |
| 3907 | if (dischargeCount >= 0) { |
| 3908 | sb.setLength(0); |
| 3909 | sb.append(prefix); |
| 3910 | sb.append(" Discharge: "); |
| 3911 | sb.append(BatteryStatsHelper.makemAh(dischargeCount / 1000.0)); |
| 3912 | sb.append(" mAh"); |
| 3913 | pw.println(sb.toString()); |
| 3914 | } |
| 3915 | |
| 3916 | final LongCounter dischargeScreenOffCounter = getDischargeScreenOffCoulombCounter(); |
| 3917 | final long dischargeScreenOffCount = dischargeScreenOffCounter.getCountLocked(which); |
| 3918 | if (dischargeScreenOffCount >= 0) { |
| 3919 | sb.setLength(0); |
| 3920 | sb.append(prefix); |
| 3921 | sb.append(" Screen off discharge: "); |
| 3922 | sb.append(BatteryStatsHelper.makemAh(dischargeScreenOffCount / 1000.0)); |
| 3923 | sb.append(" mAh"); |
| 3924 | pw.println(sb.toString()); |
| 3925 | } |
| 3926 | |
| 3927 | final long dischargeScreenOnCount = dischargeCount - dischargeScreenOffCount; |
| 3928 | if (dischargeScreenOnCount >= 0) { |
| 3929 | sb.setLength(0); |
| 3930 | sb.append(prefix); |
| 3931 | sb.append(" Screen on discharge: "); |
| 3932 | sb.append(BatteryStatsHelper.makemAh(dischargeScreenOnCount / 1000.0)); |
| 3933 | sb.append(" mAh"); |
| 3934 | pw.println(sb.toString()); |
| 3935 | } |
| 3936 | |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 3937 | pw.print(" Start clock time: "); |
| 3938 | pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss", getStartClockTime()).toString()); |
| 3939 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3940 | final long screenOnTime = getScreenOnTime(rawRealtime, which); |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 3941 | final long interactiveTime = getInteractiveTime(rawRealtime, which); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3942 | final long powerSaveModeEnabledTime = getPowerSaveModeEnabledTime(rawRealtime, which); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3943 | final long deviceIdleModeLightTime = getDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT, |
| 3944 | rawRealtime, which); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 3945 | final long deviceIdleModeFullTime = getDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP, |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3946 | rawRealtime, which); |
| 3947 | final long deviceLightIdlingTime = getDeviceIdlingTime(DEVICE_IDLE_MODE_LIGHT, |
| 3948 | rawRealtime, which); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 3949 | final long deviceIdlingTime = getDeviceIdlingTime(DEVICE_IDLE_MODE_DEEP, |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3950 | rawRealtime, which); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3951 | final long phoneOnTime = getPhoneOnTime(rawRealtime, which); |
| 3952 | final long wifiRunningTime = getGlobalWifiRunningTime(rawRealtime, which); |
| 3953 | final long wifiOnTime = getWifiOnTime(rawRealtime, which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3954 | sb.setLength(0); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3955 | sb.append(prefix); |
| 3956 | sb.append(" Screen on: "); formatTimeMs(sb, screenOnTime / 1000); |
| 3957 | sb.append("("); sb.append(formatRatioLocked(screenOnTime, whichBatteryRealtime)); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 3958 | sb.append(") "); sb.append(getScreenOnCount(which)); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3959 | sb.append("x, Interactive: "); formatTimeMs(sb, interactiveTime / 1000); |
| 3960 | sb.append("("); sb.append(formatRatioLocked(interactiveTime, whichBatteryRealtime)); |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 3961 | sb.append(")"); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3962 | pw.println(sb.toString()); |
| 3963 | sb.setLength(0); |
| 3964 | sb.append(prefix); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 3965 | sb.append(" Screen brightnesses:"); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3966 | boolean didOne = false; |
| 3967 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3968 | final long time = getScreenBrightnessTime(i, rawRealtime, which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3969 | if (time == 0) { |
| 3970 | continue; |
| 3971 | } |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 3972 | sb.append("\n "); |
| 3973 | sb.append(prefix); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3974 | didOne = true; |
| 3975 | sb.append(SCREEN_BRIGHTNESS_NAMES[i]); |
| 3976 | sb.append(" "); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3977 | formatTimeMs(sb, time/1000); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3978 | sb.append("("); |
| 3979 | sb.append(formatRatioLocked(time, screenOnTime)); |
| 3980 | sb.append(")"); |
| 3981 | } |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 3982 | if (!didOne) sb.append(" (no activity)"); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3983 | pw.println(sb.toString()); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3984 | if (powerSaveModeEnabledTime != 0) { |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3985 | sb.setLength(0); |
| 3986 | sb.append(prefix); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3987 | sb.append(" Power save mode enabled: "); |
| 3988 | formatTimeMs(sb, powerSaveModeEnabledTime / 1000); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3989 | sb.append("("); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3990 | sb.append(formatRatioLocked(powerSaveModeEnabledTime, whichBatteryRealtime)); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3991 | sb.append(")"); |
| 3992 | pw.println(sb.toString()); |
| 3993 | } |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3994 | if (deviceLightIdlingTime != 0) { |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3995 | sb.setLength(0); |
| 3996 | sb.append(prefix); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3997 | sb.append(" Device light idling: "); |
| 3998 | formatTimeMs(sb, deviceLightIdlingTime / 1000); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 3999 | sb.append("("); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4000 | sb.append(formatRatioLocked(deviceLightIdlingTime, whichBatteryRealtime)); |
| 4001 | sb.append(") "); sb.append(getDeviceIdlingCount(DEVICE_IDLE_MODE_LIGHT, which)); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 4002 | sb.append("x"); |
| 4003 | pw.println(sb.toString()); |
| 4004 | } |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4005 | if (deviceIdleModeLightTime != 0) { |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 4006 | sb.setLength(0); |
| 4007 | sb.append(prefix); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4008 | sb.append(" Idle mode light time: "); |
| 4009 | formatTimeMs(sb, deviceIdleModeLightTime / 1000); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4010 | sb.append("("); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4011 | sb.append(formatRatioLocked(deviceIdleModeLightTime, whichBatteryRealtime)); |
| 4012 | sb.append(") "); |
| 4013 | sb.append(getDeviceIdleModeCount(DEVICE_IDLE_MODE_LIGHT, which)); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4014 | sb.append("x"); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4015 | sb.append(" -- longest "); |
| 4016 | formatTimeMs(sb, getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT)); |
| 4017 | pw.println(sb.toString()); |
| 4018 | } |
| 4019 | if (deviceIdlingTime != 0) { |
| 4020 | sb.setLength(0); |
| 4021 | sb.append(prefix); |
| 4022 | sb.append(" Device full idling: "); |
| 4023 | formatTimeMs(sb, deviceIdlingTime / 1000); |
| 4024 | sb.append("("); |
| 4025 | sb.append(formatRatioLocked(deviceIdlingTime, whichBatteryRealtime)); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 4026 | sb.append(") "); sb.append(getDeviceIdlingCount(DEVICE_IDLE_MODE_DEEP, which)); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4027 | sb.append("x"); |
| 4028 | pw.println(sb.toString()); |
| 4029 | } |
| 4030 | if (deviceIdleModeFullTime != 0) { |
| 4031 | sb.setLength(0); |
| 4032 | sb.append(prefix); |
| 4033 | sb.append(" Idle mode full time: "); |
| 4034 | formatTimeMs(sb, deviceIdleModeFullTime / 1000); |
| 4035 | sb.append("("); |
| 4036 | sb.append(formatRatioLocked(deviceIdleModeFullTime, whichBatteryRealtime)); |
| 4037 | sb.append(") "); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 4038 | sb.append(getDeviceIdleModeCount(DEVICE_IDLE_MODE_DEEP, which)); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4039 | sb.append("x"); |
| 4040 | sb.append(" -- longest "); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 4041 | formatTimeMs(sb, getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP)); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4042 | pw.println(sb.toString()); |
| 4043 | } |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 4044 | if (phoneOnTime != 0) { |
| 4045 | sb.setLength(0); |
| 4046 | sb.append(prefix); |
| 4047 | sb.append(" Active phone call: "); formatTimeMs(sb, phoneOnTime / 1000); |
| 4048 | sb.append("("); sb.append(formatRatioLocked(phoneOnTime, whichBatteryRealtime)); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4049 | sb.append(") "); sb.append(getPhoneOnCount(which)); sb.append("x"); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 4050 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4051 | final int connChanges = getNumConnectivityChange(which); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 4052 | if (connChanges != 0) { |
| 4053 | pw.print(prefix); |
| 4054 | pw.print(" Connectivity changes: "); pw.println(connChanges); |
| 4055 | } |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 4056 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4057 | // Calculate wakelock times across all uids. |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 4058 | long fullWakeLockTimeTotalMicros = 0; |
| 4059 | long partialWakeLockTimeTotalMicros = 0; |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 4060 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4061 | final ArrayList<TimerEntry> timers = new ArrayList<>(); |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 4062 | |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 4063 | for (int iu = 0; iu < NU; iu++) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4064 | final Uid u = uidStats.valueAt(iu); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 4065 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4066 | final ArrayMap<String, ? extends BatteryStats.Uid.Wakelock> wakelocks |
| 4067 | = u.getWakelockStats(); |
| 4068 | for (int iw=wakelocks.size()-1; iw>=0; iw--) { |
| 4069 | final Uid.Wakelock wl = wakelocks.valueAt(iw); |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 4070 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4071 | final Timer fullWakeTimer = wl.getWakeTime(WAKE_TYPE_FULL); |
| 4072 | if (fullWakeTimer != null) { |
| 4073 | fullWakeLockTimeTotalMicros += fullWakeTimer.getTotalTimeLocked( |
| 4074 | rawRealtime, which); |
| 4075 | } |
| 4076 | |
| 4077 | final Timer partialWakeTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL); |
| 4078 | if (partialWakeTimer != null) { |
| 4079 | final long totalTimeMicros = partialWakeTimer.getTotalTimeLocked( |
| 4080 | rawRealtime, which); |
| 4081 | if (totalTimeMicros > 0) { |
| 4082 | if (reqUid < 0) { |
| 4083 | // Only show the ordered list of all wake |
| 4084 | // locks if the caller is not asking for data |
| 4085 | // about a specific uid. |
| 4086 | timers.add(new TimerEntry(wakelocks.keyAt(iw), u.getUid(), |
| 4087 | partialWakeTimer, totalTimeMicros)); |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 4088 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4089 | partialWakeLockTimeTotalMicros += totalTimeMicros; |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 4090 | } |
| 4091 | } |
| 4092 | } |
| 4093 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 4094 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4095 | final long mobileRxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which); |
| 4096 | final long mobileTxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which); |
| 4097 | final long wifiRxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which); |
| 4098 | final long wifiTxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which); |
| 4099 | final long mobileRxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which); |
| 4100 | final long mobileTxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which); |
| 4101 | final long wifiRxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which); |
| 4102 | final long wifiTxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which); |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 4103 | final long btRxTotalBytes = getNetworkActivityBytes(NETWORK_BT_RX_DATA, which); |
| 4104 | final long btTxTotalBytes = getNetworkActivityBytes(NETWORK_BT_TX_DATA, which); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4105 | |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 4106 | if (fullWakeLockTimeTotalMicros != 0) { |
| 4107 | sb.setLength(0); |
| 4108 | sb.append(prefix); |
| 4109 | sb.append(" Total full wakelock time: "); formatTimeMsNoSpace(sb, |
| 4110 | (fullWakeLockTimeTotalMicros + 500) / 1000); |
| 4111 | pw.println(sb.toString()); |
| 4112 | } |
| 4113 | |
| 4114 | if (partialWakeLockTimeTotalMicros != 0) { |
| 4115 | sb.setLength(0); |
| 4116 | sb.append(prefix); |
| 4117 | sb.append(" Total partial wakelock time: "); formatTimeMsNoSpace(sb, |
| 4118 | (partialWakeLockTimeTotalMicros + 500) / 1000); |
| 4119 | pw.println(sb.toString()); |
| 4120 | } |
| 4121 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4122 | pw.print(prefix); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4123 | pw.print(" Mobile total received: "); pw.print(formatBytesLocked(mobileRxTotalBytes)); |
| 4124 | pw.print(", sent: "); pw.print(formatBytesLocked(mobileTxTotalBytes)); |
| 4125 | pw.print(" (packets received "); pw.print(mobileRxTotalPackets); |
| 4126 | pw.print(", sent "); pw.print(mobileTxTotalPackets); pw.println(")"); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4127 | sb.setLength(0); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4128 | sb.append(prefix); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 4129 | sb.append(" Phone signal levels:"); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4130 | didOne = false; |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 4131 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4132 | final long time = getPhoneSignalStrengthTime(i, rawRealtime, which); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4133 | if (time == 0) { |
| 4134 | continue; |
| 4135 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 4136 | sb.append("\n "); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 4137 | sb.append(prefix); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4138 | didOne = true; |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 4139 | sb.append(SignalStrength.SIGNAL_STRENGTH_NAMES[i]); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4140 | sb.append(" "); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4141 | formatTimeMs(sb, time/1000); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4142 | sb.append("("); |
| 4143 | sb.append(formatRatioLocked(time, whichBatteryRealtime)); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4144 | sb.append(") "); |
| 4145 | sb.append(getPhoneSignalStrengthCount(i, which)); |
| 4146 | sb.append("x"); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4147 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 4148 | if (!didOne) sb.append(" (no activity)"); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4149 | pw.println(sb.toString()); |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 4150 | |
| 4151 | sb.setLength(0); |
| 4152 | sb.append(prefix); |
| 4153 | sb.append(" Signal scanning time: "); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4154 | formatTimeMsNoSpace(sb, getPhoneSignalScanningTime(rawRealtime, which) / 1000); |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 4155 | pw.println(sb.toString()); |
| 4156 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4157 | sb.setLength(0); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4158 | sb.append(prefix); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 4159 | sb.append(" Radio types:"); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4160 | didOne = false; |
| 4161 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4162 | final long time = getPhoneDataConnectionTime(i, rawRealtime, which); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4163 | if (time == 0) { |
| 4164 | continue; |
| 4165 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 4166 | sb.append("\n "); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 4167 | sb.append(prefix); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4168 | didOne = true; |
| 4169 | sb.append(DATA_CONNECTION_NAMES[i]); |
| 4170 | sb.append(" "); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4171 | formatTimeMs(sb, time/1000); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4172 | sb.append("("); |
| 4173 | sb.append(formatRatioLocked(time, whichBatteryRealtime)); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4174 | sb.append(") "); |
| 4175 | sb.append(getPhoneDataConnectionCount(i, which)); |
| 4176 | sb.append("x"); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4177 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 4178 | if (!didOne) sb.append(" (no activity)"); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4179 | pw.println(sb.toString()); |
Amith Yamasani | 3f7e35c | 2009-07-13 16:02:45 -0700 | [diff] [blame] | 4180 | |
| 4181 | sb.setLength(0); |
| 4182 | sb.append(prefix); |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 4183 | sb.append(" Mobile radio active time: "); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4184 | final long mobileActiveTime = getMobileRadioActiveTime(rawRealtime, which); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4185 | formatTimeMs(sb, mobileActiveTime / 1000); |
| 4186 | sb.append("("); sb.append(formatRatioLocked(mobileActiveTime, whichBatteryRealtime)); |
| 4187 | sb.append(") "); sb.append(getMobileRadioActiveCount(which)); |
| 4188 | sb.append("x"); |
Amith Yamasani | 3f7e35c | 2009-07-13 16:02:45 -0700 | [diff] [blame] | 4189 | pw.println(sb.toString()); |
| 4190 | |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4191 | final long mobileActiveUnknownTime = getMobileRadioActiveUnknownTime(which); |
| 4192 | if (mobileActiveUnknownTime != 0) { |
| 4193 | sb.setLength(0); |
| 4194 | sb.append(prefix); |
| 4195 | sb.append(" Mobile radio active unknown time: "); |
| 4196 | formatTimeMs(sb, mobileActiveUnknownTime / 1000); |
| 4197 | sb.append("("); |
| 4198 | sb.append(formatRatioLocked(mobileActiveUnknownTime, whichBatteryRealtime)); |
| 4199 | sb.append(") "); sb.append(getMobileRadioActiveUnknownCount(which)); |
| 4200 | sb.append("x"); |
| 4201 | pw.println(sb.toString()); |
| 4202 | } |
| 4203 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 4204 | final long mobileActiveAdjustedTime = getMobileRadioActiveAdjustedTime(which); |
| 4205 | if (mobileActiveAdjustedTime != 0) { |
| 4206 | sb.setLength(0); |
| 4207 | sb.append(prefix); |
| 4208 | sb.append(" Mobile radio active adjusted time: "); |
| 4209 | formatTimeMs(sb, mobileActiveAdjustedTime / 1000); |
| 4210 | sb.append("("); |
| 4211 | sb.append(formatRatioLocked(mobileActiveAdjustedTime, whichBatteryRealtime)); |
| 4212 | sb.append(")"); |
| 4213 | pw.println(sb.toString()); |
| 4214 | } |
| 4215 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 4216 | printControllerActivity(pw, sb, prefix, "Radio", getModemControllerActivity(), which); |
| 4217 | |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 4218 | pw.print(prefix); |
| 4219 | pw.print(" Wi-Fi total received: "); pw.print(formatBytesLocked(wifiRxTotalBytes)); |
| 4220 | pw.print(", sent: "); pw.print(formatBytesLocked(wifiTxTotalBytes)); |
| 4221 | pw.print(" (packets received "); pw.print(wifiRxTotalPackets); |
| 4222 | pw.print(", sent "); pw.print(wifiTxTotalPackets); pw.println(")"); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4223 | sb.setLength(0); |
| 4224 | sb.append(prefix); |
| 4225 | sb.append(" Wifi on: "); formatTimeMs(sb, wifiOnTime / 1000); |
| 4226 | sb.append("("); sb.append(formatRatioLocked(wifiOnTime, whichBatteryRealtime)); |
| 4227 | sb.append("), Wifi running: "); formatTimeMs(sb, wifiRunningTime / 1000); |
| 4228 | sb.append("("); sb.append(formatRatioLocked(wifiRunningTime, whichBatteryRealtime)); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4229 | sb.append(")"); |
| 4230 | pw.println(sb.toString()); |
| 4231 | |
| 4232 | sb.setLength(0); |
| 4233 | sb.append(prefix); |
| 4234 | sb.append(" Wifi states:"); |
| 4235 | didOne = false; |
| 4236 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4237 | final long time = getWifiStateTime(i, rawRealtime, which); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4238 | if (time == 0) { |
| 4239 | continue; |
| 4240 | } |
| 4241 | sb.append("\n "); |
| 4242 | didOne = true; |
| 4243 | sb.append(WIFI_STATE_NAMES[i]); |
| 4244 | sb.append(" "); |
| 4245 | formatTimeMs(sb, time/1000); |
| 4246 | sb.append("("); |
| 4247 | sb.append(formatRatioLocked(time, whichBatteryRealtime)); |
| 4248 | sb.append(") "); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 4249 | sb.append(getWifiStateCount(i, which)); |
| 4250 | sb.append("x"); |
| 4251 | } |
| 4252 | if (!didOne) sb.append(" (no activity)"); |
| 4253 | pw.println(sb.toString()); |
| 4254 | |
| 4255 | sb.setLength(0); |
| 4256 | sb.append(prefix); |
| 4257 | sb.append(" Wifi supplicant states:"); |
| 4258 | didOne = false; |
| 4259 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
| 4260 | final long time = getWifiSupplStateTime(i, rawRealtime, which); |
| 4261 | if (time == 0) { |
| 4262 | continue; |
| 4263 | } |
| 4264 | sb.append("\n "); |
| 4265 | didOne = true; |
| 4266 | sb.append(WIFI_SUPPL_STATE_NAMES[i]); |
| 4267 | sb.append(" "); |
| 4268 | formatTimeMs(sb, time/1000); |
| 4269 | sb.append("("); |
| 4270 | sb.append(formatRatioLocked(time, whichBatteryRealtime)); |
| 4271 | sb.append(") "); |
| 4272 | sb.append(getWifiSupplStateCount(i, which)); |
| 4273 | sb.append("x"); |
| 4274 | } |
| 4275 | if (!didOne) sb.append(" (no activity)"); |
| 4276 | pw.println(sb.toString()); |
| 4277 | |
| 4278 | sb.setLength(0); |
| 4279 | sb.append(prefix); |
| 4280 | sb.append(" Wifi signal levels:"); |
| 4281 | didOne = false; |
| 4282 | for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 4283 | final long time = getWifiSignalStrengthTime(i, rawRealtime, which); |
| 4284 | if (time == 0) { |
| 4285 | continue; |
| 4286 | } |
| 4287 | sb.append("\n "); |
| 4288 | sb.append(prefix); |
| 4289 | didOne = true; |
| 4290 | sb.append("level("); |
| 4291 | sb.append(i); |
| 4292 | sb.append(") "); |
| 4293 | formatTimeMs(sb, time/1000); |
| 4294 | sb.append("("); |
| 4295 | sb.append(formatRatioLocked(time, whichBatteryRealtime)); |
| 4296 | sb.append(") "); |
| 4297 | sb.append(getWifiSignalStrengthCount(i, which)); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4298 | sb.append("x"); |
| 4299 | } |
| 4300 | if (!didOne) sb.append(" (no activity)"); |
| 4301 | pw.println(sb.toString()); |
| 4302 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 4303 | printControllerActivity(pw, sb, prefix, "WiFi", getWifiControllerActivity(), which); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 4304 | |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 4305 | pw.print(prefix); |
| 4306 | pw.print(" Bluetooth total received: "); pw.print(formatBytesLocked(btRxTotalBytes)); |
| 4307 | pw.print(", sent: "); pw.println(formatBytesLocked(btTxTotalBytes)); |
| 4308 | |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 4309 | final long bluetoothScanTimeMs = getBluetoothScanTime(rawRealtime, which) / 1000; |
| 4310 | sb.setLength(0); |
| 4311 | sb.append(prefix); |
| 4312 | sb.append(" Bluetooth scan time: "); formatTimeMs(sb, bluetoothScanTimeMs); |
| 4313 | pw.println(sb.toString()); |
| 4314 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 4315 | printControllerActivity(pw, sb, prefix, "Bluetooth", getBluetoothControllerActivity(), |
| 4316 | which); |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 4317 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4318 | pw.println(); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4319 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4320 | if (which == STATS_SINCE_UNPLUGGED) { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4321 | if (getIsOnBattery()) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4322 | pw.print(prefix); pw.println(" Device is currently unplugged"); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 4323 | pw.print(prefix); pw.print(" Discharge cycle start level: "); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4324 | pw.println(getDischargeStartLevel()); |
| 4325 | pw.print(prefix); pw.print(" Discharge cycle current level: "); |
| 4326 | pw.println(getDischargeCurrentLevel()); |
Dianne Hackborn | 99d0452 | 2010-08-20 13:43:00 -0700 | [diff] [blame] | 4327 | } else { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4328 | pw.print(prefix); pw.println(" Device is currently plugged into power"); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 4329 | pw.print(prefix); pw.print(" Last discharge cycle start level: "); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4330 | pw.println(getDischargeStartLevel()); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 4331 | pw.print(prefix); pw.print(" Last discharge cycle end level: "); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4332 | pw.println(getDischargeCurrentLevel()); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4333 | } |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 4334 | pw.print(prefix); pw.print(" Amount discharged while screen on: "); |
| 4335 | pw.println(getDischargeAmountScreenOn()); |
| 4336 | pw.print(prefix); pw.print(" Amount discharged while screen off: "); |
| 4337 | pw.println(getDischargeAmountScreenOff()); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4338 | pw.println(" "); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4339 | } else { |
| 4340 | pw.print(prefix); pw.println(" Device battery use since last full charge"); |
| 4341 | pw.print(prefix); pw.print(" Amount discharged (lower bound): "); |
| 4342 | pw.println(getLowDischargeAmountSinceCharge()); |
| 4343 | pw.print(prefix); pw.print(" Amount discharged (upper bound): "); |
| 4344 | pw.println(getHighDischargeAmountSinceCharge()); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 4345 | pw.print(prefix); pw.print(" Amount discharged while screen on: "); |
| 4346 | pw.println(getDischargeAmountScreenOnSinceCharge()); |
| 4347 | pw.print(prefix); pw.print(" Amount discharged while screen off: "); |
| 4348 | pw.println(getDischargeAmountScreenOffSinceCharge()); |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 4349 | pw.println(); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4350 | } |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 4351 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4352 | final BatteryStatsHelper helper = new BatteryStatsHelper(context, false, wifiOnly); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4353 | helper.create(this); |
| 4354 | helper.refreshStats(which, UserHandle.USER_ALL); |
| 4355 | List<BatterySipper> sippers = helper.getUsageList(); |
| 4356 | if (sippers != null && sippers.size() > 0) { |
| 4357 | pw.print(prefix); pw.println(" Estimated power use (mAh):"); |
| 4358 | pw.print(prefix); pw.print(" Capacity: "); |
| 4359 | printmAh(pw, helper.getPowerProfile().getBatteryCapacity()); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4360 | pw.print(", Computed drain: "); printmAh(pw, helper.getComputedPower()); |
Dianne Hackborn | 536456f | 2014-05-23 16:51:05 -0700 | [diff] [blame] | 4361 | pw.print(", actual drain: "); printmAh(pw, helper.getMinDrainedPower()); |
| 4362 | if (helper.getMinDrainedPower() != helper.getMaxDrainedPower()) { |
| 4363 | pw.print("-"); printmAh(pw, helper.getMaxDrainedPower()); |
| 4364 | } |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4365 | pw.println(); |
| 4366 | for (int i=0; i<sippers.size(); i++) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4367 | final BatterySipper bs = sippers.get(i); |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4368 | pw.print(prefix); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4369 | switch (bs.drainType) { |
| 4370 | case IDLE: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4371 | pw.print(" Idle: "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4372 | break; |
| 4373 | case CELL: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4374 | pw.print(" Cell standby: "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4375 | break; |
| 4376 | case PHONE: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4377 | pw.print(" Phone calls: "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4378 | break; |
| 4379 | case WIFI: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4380 | pw.print(" Wifi: "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4381 | break; |
| 4382 | case BLUETOOTH: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4383 | pw.print(" Bluetooth: "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4384 | break; |
| 4385 | case SCREEN: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4386 | pw.print(" Screen: "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4387 | break; |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 4388 | case FLASHLIGHT: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4389 | pw.print(" Flashlight: "); |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 4390 | break; |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4391 | case APP: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4392 | pw.print(" Uid "); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4393 | UserHandle.formatUid(pw, bs.uidObj.getUid()); |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4394 | pw.print(": "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4395 | break; |
| 4396 | case USER: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4397 | pw.print(" User "); pw.print(bs.userId); |
| 4398 | pw.print(": "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4399 | break; |
| 4400 | case UNACCOUNTED: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4401 | pw.print(" Unaccounted: "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4402 | break; |
| 4403 | case OVERCOUNTED: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4404 | pw.print(" Over-counted: "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4405 | break; |
Ruben Brunk | 5b1308f | 2015-06-03 18:49:27 -0700 | [diff] [blame] | 4406 | case CAMERA: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4407 | pw.print(" Camera: "); |
| 4408 | break; |
| 4409 | default: |
| 4410 | pw.print(" ???: "); |
Ruben Brunk | 5b1308f | 2015-06-03 18:49:27 -0700 | [diff] [blame] | 4411 | break; |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4412 | } |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4413 | printmAh(pw, bs.totalPowerMah); |
| 4414 | |
Adam Lesinski | 5712300 | 2015-06-12 16:12:07 -0700 | [diff] [blame] | 4415 | if (bs.usagePowerMah != bs.totalPowerMah) { |
| 4416 | // If the usage (generic power) isn't the whole amount, we list out |
| 4417 | // what components are involved in the calculation. |
| 4418 | |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4419 | pw.print(" ("); |
Adam Lesinski | 5712300 | 2015-06-12 16:12:07 -0700 | [diff] [blame] | 4420 | if (bs.usagePowerMah != 0) { |
| 4421 | pw.print(" usage="); |
| 4422 | printmAh(pw, bs.usagePowerMah); |
| 4423 | } |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4424 | if (bs.cpuPowerMah != 0) { |
| 4425 | pw.print(" cpu="); |
| 4426 | printmAh(pw, bs.cpuPowerMah); |
| 4427 | } |
| 4428 | if (bs.wakeLockPowerMah != 0) { |
| 4429 | pw.print(" wake="); |
| 4430 | printmAh(pw, bs.wakeLockPowerMah); |
| 4431 | } |
| 4432 | if (bs.mobileRadioPowerMah != 0) { |
| 4433 | pw.print(" radio="); |
| 4434 | printmAh(pw, bs.mobileRadioPowerMah); |
| 4435 | } |
| 4436 | if (bs.wifiPowerMah != 0) { |
| 4437 | pw.print(" wifi="); |
| 4438 | printmAh(pw, bs.wifiPowerMah); |
| 4439 | } |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 4440 | if (bs.bluetoothPowerMah != 0) { |
| 4441 | pw.print(" bt="); |
| 4442 | printmAh(pw, bs.bluetoothPowerMah); |
| 4443 | } |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4444 | if (bs.gpsPowerMah != 0) { |
| 4445 | pw.print(" gps="); |
| 4446 | printmAh(pw, bs.gpsPowerMah); |
| 4447 | } |
| 4448 | if (bs.sensorPowerMah != 0) { |
| 4449 | pw.print(" sensor="); |
| 4450 | printmAh(pw, bs.sensorPowerMah); |
| 4451 | } |
| 4452 | if (bs.cameraPowerMah != 0) { |
| 4453 | pw.print(" camera="); |
| 4454 | printmAh(pw, bs.cameraPowerMah); |
| 4455 | } |
| 4456 | if (bs.flashlightPowerMah != 0) { |
| 4457 | pw.print(" flash="); |
| 4458 | printmAh(pw, bs.flashlightPowerMah); |
| 4459 | } |
| 4460 | pw.print(" )"); |
| 4461 | } |
Bookatz | 17d7d9d | 2017-06-08 14:50:46 -0700 | [diff] [blame] | 4462 | |
| 4463 | // If there is additional smearing information, include it. |
| 4464 | if (bs.totalSmearedPowerMah != bs.totalPowerMah) { |
| 4465 | pw.print(" Including smearing: "); |
| 4466 | printmAh(pw, bs.totalSmearedPowerMah); |
| 4467 | pw.print(" ("); |
| 4468 | if (bs.screenPowerMah != 0) { |
| 4469 | pw.print(" screen="); |
| 4470 | printmAh(pw, bs.screenPowerMah); |
| 4471 | } |
| 4472 | if (bs.proportionalSmearMah != 0) { |
| 4473 | pw.print(" proportional="); |
| 4474 | printmAh(pw, bs.proportionalSmearMah); |
| 4475 | } |
| 4476 | pw.print(" )"); |
| 4477 | } |
| 4478 | if (bs.shouldHide) { |
| 4479 | pw.print(" Excluded from smearing"); |
| 4480 | } |
| 4481 | |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4482 | pw.println(); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4483 | } |
Dianne Hackborn | c46809e | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4484 | pw.println(); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4485 | } |
| 4486 | |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4487 | sippers = helper.getMobilemsppList(); |
| 4488 | if (sippers != null && sippers.size() > 0) { |
| 4489 | pw.print(prefix); pw.println(" Per-app mobile ms per packet:"); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 4490 | long totalTime = 0; |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4491 | for (int i=0; i<sippers.size(); i++) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4492 | final BatterySipper bs = sippers.get(i); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4493 | sb.setLength(0); |
| 4494 | sb.append(prefix); sb.append(" Uid "); |
| 4495 | UserHandle.formatUid(sb, bs.uidObj.getUid()); |
| 4496 | sb.append(": "); sb.append(BatteryStatsHelper.makemAh(bs.mobilemspp)); |
| 4497 | sb.append(" ("); sb.append(bs.mobileRxPackets+bs.mobileTxPackets); |
| 4498 | sb.append(" packets over "); formatTimeMsNoSpace(sb, bs.mobileActive); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 4499 | sb.append(") "); sb.append(bs.mobileActiveCount); sb.append("x"); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4500 | pw.println(sb.toString()); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 4501 | totalTime += bs.mobileActive; |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4502 | } |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 4503 | sb.setLength(0); |
| 4504 | sb.append(prefix); |
| 4505 | sb.append(" TOTAL TIME: "); |
| 4506 | formatTimeMs(sb, totalTime); |
| 4507 | sb.append("("); sb.append(formatRatioLocked(totalTime, whichBatteryRealtime)); |
| 4508 | sb.append(")"); |
| 4509 | pw.println(sb.toString()); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4510 | pw.println(); |
| 4511 | } |
| 4512 | |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 4513 | final Comparator<TimerEntry> timerComparator = new Comparator<TimerEntry>() { |
| 4514 | @Override |
| 4515 | public int compare(TimerEntry lhs, TimerEntry rhs) { |
| 4516 | long lhsTime = lhs.mTime; |
| 4517 | long rhsTime = rhs.mTime; |
| 4518 | if (lhsTime < rhsTime) { |
| 4519 | return 1; |
| 4520 | } |
| 4521 | if (lhsTime > rhsTime) { |
| 4522 | return -1; |
| 4523 | } |
| 4524 | return 0; |
| 4525 | } |
| 4526 | }; |
| 4527 | |
| 4528 | if (reqUid < 0) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4529 | final Map<String, ? extends BatteryStats.Timer> kernelWakelocks |
| 4530 | = getKernelWakelockStats(); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 4531 | if (kernelWakelocks.size() > 0) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4532 | final ArrayList<TimerEntry> ktimers = new ArrayList<>(); |
| 4533 | for (Map.Entry<String, ? extends BatteryStats.Timer> ent |
| 4534 | : kernelWakelocks.entrySet()) { |
| 4535 | final BatteryStats.Timer timer = ent.getValue(); |
| 4536 | final long totalTimeMillis = computeWakeLock(timer, rawRealtime, which); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 4537 | if (totalTimeMillis > 0) { |
| 4538 | ktimers.add(new TimerEntry(ent.getKey(), 0, timer, totalTimeMillis)); |
| 4539 | } |
| 4540 | } |
| 4541 | if (ktimers.size() > 0) { |
| 4542 | Collections.sort(ktimers, timerComparator); |
| 4543 | pw.print(prefix); pw.println(" All kernel wake locks:"); |
| 4544 | for (int i=0; i<ktimers.size(); i++) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4545 | final TimerEntry timer = ktimers.get(i); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 4546 | String linePrefix = ": "; |
| 4547 | sb.setLength(0); |
| 4548 | sb.append(prefix); |
| 4549 | sb.append(" Kernel Wake lock "); |
| 4550 | sb.append(timer.mName); |
| 4551 | linePrefix = printWakeLock(sb, timer.mTimer, rawRealtime, null, |
| 4552 | which, linePrefix); |
| 4553 | if (!linePrefix.equals(": ")) { |
| 4554 | sb.append(" realtime"); |
| 4555 | // Only print out wake locks that were held |
| 4556 | pw.println(sb.toString()); |
| 4557 | } |
| 4558 | } |
| 4559 | pw.println(); |
| 4560 | } |
| 4561 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 4562 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 4563 | if (timers.size() > 0) { |
| 4564 | Collections.sort(timers, timerComparator); |
| 4565 | pw.print(prefix); pw.println(" All partial wake locks:"); |
| 4566 | for (int i=0; i<timers.size(); i++) { |
| 4567 | TimerEntry timer = timers.get(i); |
| 4568 | sb.setLength(0); |
| 4569 | sb.append(" Wake lock "); |
| 4570 | UserHandle.formatUid(sb, timer.mId); |
| 4571 | sb.append(" "); |
| 4572 | sb.append(timer.mName); |
| 4573 | printWakeLock(sb, timer.mTimer, rawRealtime, null, which, ": "); |
| 4574 | sb.append(" realtime"); |
| 4575 | pw.println(sb.toString()); |
| 4576 | } |
| 4577 | timers.clear(); |
| 4578 | pw.println(); |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 4579 | } |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 4580 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4581 | final Map<String, ? extends Timer> wakeupReasons = getWakeupReasonStats(); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 4582 | if (wakeupReasons.size() > 0) { |
| 4583 | pw.print(prefix); pw.println(" All wakeup reasons:"); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4584 | final ArrayList<TimerEntry> reasons = new ArrayList<>(); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 4585 | for (Map.Entry<String, ? extends Timer> ent : wakeupReasons.entrySet()) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4586 | final Timer timer = ent.getValue(); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 4587 | reasons.add(new TimerEntry(ent.getKey(), 0, timer, |
| 4588 | timer.getCountLocked(which))); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 4589 | } |
| 4590 | Collections.sort(reasons, timerComparator); |
| 4591 | for (int i=0; i<reasons.size(); i++) { |
| 4592 | TimerEntry timer = reasons.get(i); |
| 4593 | String linePrefix = ": "; |
| 4594 | sb.setLength(0); |
| 4595 | sb.append(prefix); |
| 4596 | sb.append(" Wakeup reason "); |
| 4597 | sb.append(timer.mName); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 4598 | printWakeLock(sb, timer.mTimer, rawRealtime, null, which, ": "); |
| 4599 | sb.append(" realtime"); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 4600 | pw.println(sb.toString()); |
| 4601 | } |
| 4602 | pw.println(); |
| 4603 | } |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 4604 | } |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 4605 | |
James Carr | 2dd7e5e | 2016-07-20 18:48:39 -0700 | [diff] [blame] | 4606 | final LongSparseArray<? extends Timer> mMemoryStats = getKernelMemoryStats(); |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame^] | 4607 | if (mMemoryStats.size() > 0) { |
| 4608 | pw.println(" Memory Stats"); |
| 4609 | for (int i = 0; i < mMemoryStats.size(); i++) { |
| 4610 | sb.setLength(0); |
| 4611 | sb.append(" Bandwidth "); |
| 4612 | sb.append(mMemoryStats.keyAt(i)); |
| 4613 | sb.append(" Time "); |
| 4614 | sb.append(mMemoryStats.valueAt(i).getTotalTimeLocked(rawRealtime, which)); |
| 4615 | pw.println(sb.toString()); |
| 4616 | } |
| 4617 | pw.println(); |
| 4618 | } |
| 4619 | |
| 4620 | final Map<String, ? extends Timer> rpmStats = getRpmStats(); |
| 4621 | if (rpmStats.size() > 0) { |
| 4622 | pw.print(prefix); pw.println(" Resource Power Manager Stats"); |
| 4623 | if (rpmStats.size() > 0) { |
| 4624 | for (Map.Entry<String, ? extends Timer> ent : rpmStats.entrySet()) { |
| 4625 | final String timerName = ent.getKey(); |
| 4626 | final Timer timer = ent.getValue(); |
| 4627 | printTimer(pw, sb, timer, rawRealtime, which, prefix, timerName); |
| 4628 | } |
| 4629 | } |
| 4630 | pw.println(); |
| 4631 | } |
| 4632 | final Map<String, ? extends Timer> screenOffRpmStats = getScreenOffRpmStats(); |
| 4633 | if (screenOffRpmStats.size() > 0) { |
| 4634 | pw.print(prefix); |
| 4635 | pw.println(" Resource Power Manager Stats for when screen was off"); |
| 4636 | if (screenOffRpmStats.size() > 0) { |
| 4637 | for (Map.Entry<String, ? extends Timer> ent : screenOffRpmStats.entrySet()) { |
| 4638 | final String timerName = ent.getKey(); |
| 4639 | final Timer timer = ent.getValue(); |
| 4640 | printTimer(pw, sb, timer, rawRealtime, which, prefix, timerName); |
| 4641 | } |
| 4642 | } |
| 4643 | pw.println(); |
James Carr | 2dd7e5e | 2016-07-20 18:48:39 -0700 | [diff] [blame] | 4644 | } |
| 4645 | |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 4646 | final long[] cpuFreqs = getCpuFreqs(); |
| 4647 | if (cpuFreqs != null) { |
| 4648 | sb.setLength(0); |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame^] | 4649 | sb.append(" CPU freqs:"); |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 4650 | for (int i = 0; i < cpuFreqs.length; ++i) { |
| 4651 | sb.append(" " + cpuFreqs[i]); |
| 4652 | } |
| 4653 | pw.println(sb.toString()); |
Bookatz | 50df711 | 2017-08-04 14:53:26 -0700 | [diff] [blame^] | 4654 | pw.println(); |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 4655 | } |
| 4656 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4657 | for (int iu=0; iu<NU; iu++) { |
| 4658 | final int uid = uidStats.keyAt(iu); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 4659 | if (reqUid >= 0 && uid != reqUid && uid != Process.SYSTEM_UID) { |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 4660 | continue; |
| 4661 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 4662 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4663 | final Uid u = uidStats.valueAt(iu); |
Dianne Hackborn | a4cc205 | 2013-07-08 17:31:25 -0700 | [diff] [blame] | 4664 | |
| 4665 | pw.print(prefix); |
| 4666 | pw.print(" "); |
| 4667 | UserHandle.formatUid(pw, uid); |
| 4668 | pw.println(":"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4669 | boolean uidActivity = false; |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4670 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4671 | final long mobileRxBytes = u.getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which); |
| 4672 | final long mobileTxBytes = u.getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which); |
| 4673 | final long wifiRxBytes = u.getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which); |
| 4674 | final long wifiTxBytes = u.getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which); |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 4675 | final long btRxBytes = u.getNetworkActivityBytes(NETWORK_BT_RX_DATA, which); |
| 4676 | final long btTxBytes = u.getNetworkActivityBytes(NETWORK_BT_TX_DATA, which); |
| 4677 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4678 | final long mobileRxPackets = u.getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which); |
| 4679 | final long mobileTxPackets = u.getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4680 | final long wifiRxPackets = u.getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which); |
| 4681 | final long wifiTxPackets = u.getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which); |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 4682 | |
| 4683 | final long uidMobileActiveTime = u.getMobileRadioActiveTime(which); |
| 4684 | final int uidMobileActiveCount = u.getMobileRadioActiveCount(which); |
| 4685 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4686 | final long fullWifiLockOnTime = u.getFullWifiLockTime(rawRealtime, which); |
| 4687 | final long wifiScanTime = u.getWifiScanTime(rawRealtime, which); |
| 4688 | final int wifiScanCount = u.getWifiScanCount(which); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 4689 | final int wifiScanCountBg = u.getWifiScanBackgroundCount(which); |
| 4690 | // 'actualTime' are unpooled and always since reset (regardless of 'which') |
| 4691 | final long wifiScanActualTime = u.getWifiScanActualTime(rawRealtime); |
| 4692 | final long wifiScanActualTimeBg = u.getWifiScanBackgroundTime(rawRealtime); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4693 | final long uidWifiRunningTime = u.getWifiRunningTime(rawRealtime, which); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 4694 | |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 4695 | final long mobileWakeup = u.getMobileRadioApWakeupCount(which); |
| 4696 | final long wifiWakeup = u.getWifiRadioApWakeupCount(which); |
| 4697 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4698 | if (mobileRxBytes > 0 || mobileTxBytes > 0 |
| 4699 | || mobileRxPackets > 0 || mobileTxPackets > 0) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 4700 | pw.print(prefix); pw.print(" Mobile network: "); |
| 4701 | pw.print(formatBytesLocked(mobileRxBytes)); pw.print(" received, "); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4702 | pw.print(formatBytesLocked(mobileTxBytes)); |
| 4703 | pw.print(" sent (packets "); pw.print(mobileRxPackets); |
| 4704 | pw.print(" received, "); pw.print(mobileTxPackets); pw.println(" sent)"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4705 | } |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4706 | if (uidMobileActiveTime > 0 || uidMobileActiveCount > 0) { |
| 4707 | sb.setLength(0); |
| 4708 | sb.append(prefix); sb.append(" Mobile radio active: "); |
| 4709 | formatTimeMs(sb, uidMobileActiveTime / 1000); |
| 4710 | sb.append("("); |
| 4711 | sb.append(formatRatioLocked(uidMobileActiveTime, mobileActiveTime)); |
| 4712 | sb.append(") "); sb.append(uidMobileActiveCount); sb.append("x"); |
| 4713 | long packets = mobileRxPackets + mobileTxPackets; |
| 4714 | if (packets == 0) { |
| 4715 | packets = 1; |
| 4716 | } |
| 4717 | sb.append(" @ "); |
| 4718 | sb.append(BatteryStatsHelper.makemAh(uidMobileActiveTime / 1000 / (double)packets)); |
| 4719 | sb.append(" mspp"); |
| 4720 | pw.println(sb.toString()); |
| 4721 | } |
| 4722 | |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 4723 | if (mobileWakeup > 0) { |
| 4724 | sb.setLength(0); |
| 4725 | sb.append(prefix); |
| 4726 | sb.append(" Mobile radio AP wakeups: "); |
| 4727 | sb.append(mobileWakeup); |
| 4728 | pw.println(sb.toString()); |
| 4729 | } |
| 4730 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 4731 | printControllerActivityIfInteresting(pw, sb, prefix + " ", "Modem", |
| 4732 | u.getModemControllerActivity(), which); |
| 4733 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4734 | if (wifiRxBytes > 0 || wifiTxBytes > 0 || wifiRxPackets > 0 || wifiTxPackets > 0) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 4735 | pw.print(prefix); pw.print(" Wi-Fi network: "); |
| 4736 | pw.print(formatBytesLocked(wifiRxBytes)); pw.print(" received, "); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4737 | pw.print(formatBytesLocked(wifiTxBytes)); |
| 4738 | pw.print(" sent (packets "); pw.print(wifiRxPackets); |
| 4739 | pw.print(" received, "); pw.print(wifiTxPackets); pw.println(" sent)"); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 4740 | } |
| 4741 | |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 4742 | if (fullWifiLockOnTime != 0 || wifiScanTime != 0 || wifiScanCount != 0 |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 4743 | || wifiScanCountBg != 0 || wifiScanActualTime != 0 || wifiScanActualTimeBg != 0 |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4744 | || uidWifiRunningTime != 0) { |
| 4745 | sb.setLength(0); |
| 4746 | sb.append(prefix); sb.append(" Wifi Running: "); |
| 4747 | formatTimeMs(sb, uidWifiRunningTime / 1000); |
| 4748 | sb.append("("); sb.append(formatRatioLocked(uidWifiRunningTime, |
| 4749 | whichBatteryRealtime)); sb.append(")\n"); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 4750 | sb.append(prefix); sb.append(" Full Wifi Lock: "); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4751 | formatTimeMs(sb, fullWifiLockOnTime / 1000); |
| 4752 | sb.append("("); sb.append(formatRatioLocked(fullWifiLockOnTime, |
| 4753 | whichBatteryRealtime)); sb.append(")\n"); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 4754 | sb.append(prefix); sb.append(" Wifi Scan (blamed): "); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4755 | formatTimeMs(sb, wifiScanTime / 1000); |
| 4756 | sb.append("("); sb.append(formatRatioLocked(wifiScanTime, |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 4757 | whichBatteryRealtime)); sb.append(") "); |
| 4758 | sb.append(wifiScanCount); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 4759 | sb.append("x\n"); |
| 4760 | // actual and background times are unpooled and since reset (regardless of 'which') |
| 4761 | sb.append(prefix); sb.append(" Wifi Scan (actual): "); |
| 4762 | formatTimeMs(sb, wifiScanActualTime / 1000); |
| 4763 | sb.append("("); sb.append(formatRatioLocked(wifiScanActualTime, |
| 4764 | computeBatteryRealtime(rawRealtime, STATS_SINCE_CHARGED))); |
| 4765 | sb.append(") "); |
| 4766 | sb.append(wifiScanCount); |
| 4767 | sb.append("x\n"); |
| 4768 | sb.append(prefix); sb.append(" Background Wifi Scan: "); |
| 4769 | formatTimeMs(sb, wifiScanActualTimeBg / 1000); |
| 4770 | sb.append("("); sb.append(formatRatioLocked(wifiScanActualTimeBg, |
| 4771 | computeBatteryRealtime(rawRealtime, STATS_SINCE_CHARGED))); |
| 4772 | sb.append(") "); |
| 4773 | sb.append(wifiScanCountBg); |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 4774 | sb.append("x"); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4775 | pw.println(sb.toString()); |
| 4776 | } |
| 4777 | |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 4778 | if (wifiWakeup > 0) { |
| 4779 | sb.setLength(0); |
| 4780 | sb.append(prefix); |
| 4781 | sb.append(" WiFi AP wakeups: "); |
| 4782 | sb.append(wifiWakeup); |
| 4783 | pw.println(sb.toString()); |
| 4784 | } |
| 4785 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 4786 | printControllerActivityIfInteresting(pw, sb, prefix + " ", "WiFi", |
| 4787 | u.getWifiControllerActivity(), which); |
Adam Lesinski | 049c88b | 2015-05-28 11:38:12 -0700 | [diff] [blame] | 4788 | |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 4789 | if (btRxBytes > 0 || btTxBytes > 0) { |
| 4790 | pw.print(prefix); pw.print(" Bluetooth network: "); |
| 4791 | pw.print(formatBytesLocked(btRxBytes)); pw.print(" received, "); |
| 4792 | pw.print(formatBytesLocked(btTxBytes)); |
| 4793 | pw.println(" sent"); |
| 4794 | } |
| 4795 | |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 4796 | final Timer bleTimer = u.getBluetoothScanTimer(); |
| 4797 | if (bleTimer != null) { |
| 4798 | // Convert from microseconds to milliseconds with rounding |
| 4799 | final long totalTimeMs = (bleTimer.getTotalTimeLocked(rawRealtime, which) + 500) |
| 4800 | / 1000; |
| 4801 | if (totalTimeMs != 0) { |
| 4802 | final int count = bleTimer.getCountLocked(which); |
| 4803 | final Timer bleTimerBg = u.getBluetoothScanBackgroundTimer(); |
| 4804 | final int countBg = bleTimerBg != null ? bleTimerBg.getCountLocked(which) : 0; |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 4805 | // 'actualTime' are unpooled and always since reset (regardless of 'which') |
| 4806 | final long actualTimeMs = bleTimer.getTotalDurationMsLocked(rawRealtimeMs); |
| 4807 | final long actualTimeMsBg = bleTimerBg != null ? |
| 4808 | bleTimerBg.getTotalDurationMsLocked(rawRealtimeMs) : 0; |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 4809 | // Result counters |
Bookatz | 956f36bf | 2017-04-28 09:48:17 -0700 | [diff] [blame] | 4810 | final int resultCount = u.getBluetoothScanResultCounter() != null ? |
| 4811 | u.getBluetoothScanResultCounter().getCountLocked(which) : 0; |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 4812 | final int resultCountBg = u.getBluetoothScanResultBgCounter() != null ? |
| 4813 | u.getBluetoothScanResultBgCounter().getCountLocked(which) : 0; |
| 4814 | // Unoptimized scan timer. Unpooled and since reset (regardless of 'which'). |
| 4815 | final Timer unoptimizedScanTimer = u.getBluetoothUnoptimizedScanTimer(); |
| 4816 | final long unoptimizedScanTotalTime = unoptimizedScanTimer != null ? |
| 4817 | unoptimizedScanTimer.getTotalDurationMsLocked(rawRealtimeMs) : 0; |
| 4818 | final long unoptimizedScanMaxTime = unoptimizedScanTimer != null ? |
| 4819 | unoptimizedScanTimer.getMaxDurationMsLocked(rawRealtimeMs) : 0; |
| 4820 | // Unoptimized bg scan timer. Unpooled and since reset (regardless of 'which'). |
| 4821 | final Timer unoptimizedScanTimerBg = |
| 4822 | u.getBluetoothUnoptimizedScanBackgroundTimer(); |
| 4823 | final long unoptimizedScanTotalTimeBg = unoptimizedScanTimerBg != null ? |
| 4824 | unoptimizedScanTimerBg.getTotalDurationMsLocked(rawRealtimeMs) : 0; |
| 4825 | final long unoptimizedScanMaxTimeBg = unoptimizedScanTimerBg != null ? |
| 4826 | unoptimizedScanTimerBg.getMaxDurationMsLocked(rawRealtimeMs) : 0; |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 4827 | |
| 4828 | sb.setLength(0); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 4829 | if (actualTimeMs != totalTimeMs) { |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 4830 | sb.append(prefix); |
| 4831 | sb.append(" Bluetooth Scan (total blamed realtime): "); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 4832 | formatTimeMs(sb, totalTimeMs); |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 4833 | sb.append(" ("); |
| 4834 | sb.append(count); |
| 4835 | sb.append(" times)"); |
| 4836 | if (bleTimer.isRunningLocked()) { |
| 4837 | sb.append(" (currently running)"); |
| 4838 | } |
| 4839 | sb.append("\n"); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 4840 | } |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 4841 | |
| 4842 | sb.append(prefix); |
| 4843 | sb.append(" Bluetooth Scan (total actual realtime): "); |
| 4844 | formatTimeMs(sb, actualTimeMs); // since reset, ignores 'which' |
| 4845 | sb.append(" ("); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 4846 | sb.append(count); |
| 4847 | sb.append(" times)"); |
| 4848 | if (bleTimer.isRunningLocked()) { |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 4849 | sb.append(" (currently running)"); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 4850 | } |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 4851 | sb.append("\n"); |
| 4852 | if (actualTimeMsBg > 0 || countBg > 0) { |
| 4853 | sb.append(prefix); |
| 4854 | sb.append(" Bluetooth Scan (background realtime): "); |
| 4855 | formatTimeMs(sb, actualTimeMsBg); // since reset, ignores 'which' |
| 4856 | sb.append(" ("); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 4857 | sb.append(countBg); |
| 4858 | sb.append(" times)"); |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 4859 | if (bleTimerBg != null && bleTimerBg.isRunningLocked()) { |
| 4860 | sb.append(" (currently running in background)"); |
| 4861 | } |
| 4862 | sb.append("\n"); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 4863 | } |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 4864 | |
| 4865 | sb.append(prefix); |
| 4866 | sb.append(" Bluetooth Scan Results: "); |
Bookatz | 956f36bf | 2017-04-28 09:48:17 -0700 | [diff] [blame] | 4867 | sb.append(resultCount); |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 4868 | sb.append(" ("); |
| 4869 | sb.append(resultCountBg); |
| 4870 | sb.append(" in background)"); |
| 4871 | |
| 4872 | if (unoptimizedScanTotalTime > 0 || unoptimizedScanTotalTimeBg > 0) { |
| 4873 | sb.append("\n"); |
| 4874 | sb.append(prefix); |
| 4875 | sb.append(" Unoptimized Bluetooth Scan (realtime): "); |
| 4876 | formatTimeMs(sb, unoptimizedScanTotalTime); // since reset, ignores 'which' |
| 4877 | sb.append(" (max "); |
| 4878 | formatTimeMs(sb, unoptimizedScanMaxTime); // since reset, ignores 'which' |
| 4879 | sb.append(")"); |
| 4880 | if (unoptimizedScanTimer != null |
| 4881 | && unoptimizedScanTimer.isRunningLocked()) { |
| 4882 | sb.append(" (currently running unoptimized)"); |
| 4883 | } |
| 4884 | if (unoptimizedScanTimerBg != null && unoptimizedScanTotalTimeBg > 0) { |
| 4885 | sb.append("\n"); |
| 4886 | sb.append(prefix); |
| 4887 | sb.append(" Unoptimized Bluetooth Scan (background realtime): "); |
| 4888 | formatTimeMs(sb, unoptimizedScanTotalTimeBg); // since reset |
| 4889 | sb.append(" (max "); |
| 4890 | formatTimeMs(sb, unoptimizedScanMaxTimeBg); // since reset |
| 4891 | sb.append(")"); |
| 4892 | if (unoptimizedScanTimerBg.isRunningLocked()) { |
| 4893 | sb.append(" (currently running unoptimized in background)"); |
| 4894 | } |
| 4895 | } |
| 4896 | } |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 4897 | pw.println(sb.toString()); |
| 4898 | uidActivity = true; |
| 4899 | } |
| 4900 | } |
| 4901 | |
| 4902 | |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 4903 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4904 | if (u.hasUserActivity()) { |
| 4905 | boolean hasData = false; |
Raph Levien | 4c7a4a7 | 2012-08-03 14:32:39 -0700 | [diff] [blame] | 4906 | for (int i=0; i<Uid.NUM_USER_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4907 | final int val = u.getUserActivityCount(i, which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4908 | if (val != 0) { |
| 4909 | if (!hasData) { |
| 4910 | sb.setLength(0); |
| 4911 | sb.append(" User activity: "); |
| 4912 | hasData = true; |
| 4913 | } else { |
| 4914 | sb.append(", "); |
| 4915 | } |
| 4916 | sb.append(val); |
| 4917 | sb.append(" "); |
| 4918 | sb.append(Uid.USER_ACTIVITY_TYPES[i]); |
| 4919 | } |
| 4920 | } |
| 4921 | if (hasData) { |
| 4922 | pw.println(sb.toString()); |
| 4923 | } |
| 4924 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4925 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4926 | final ArrayMap<String, ? extends BatteryStats.Uid.Wakelock> wakelocks |
| 4927 | = u.getWakelockStats(); |
| 4928 | long totalFullWakelock = 0, totalPartialWakelock = 0, totalWindowWakelock = 0; |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 4929 | long totalDrawWakelock = 0; |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4930 | int countWakelock = 0; |
| 4931 | for (int iw=wakelocks.size()-1; iw>=0; iw--) { |
| 4932 | final Uid.Wakelock wl = wakelocks.valueAt(iw); |
| 4933 | String linePrefix = ": "; |
| 4934 | sb.setLength(0); |
| 4935 | sb.append(prefix); |
| 4936 | sb.append(" Wake lock "); |
| 4937 | sb.append(wakelocks.keyAt(iw)); |
| 4938 | linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_FULL), rawRealtime, |
| 4939 | "full", which, linePrefix); |
Bookatz | 5b5ec32 | 2017-05-26 09:40:38 -0700 | [diff] [blame] | 4940 | final Timer pTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL); |
| 4941 | linePrefix = printWakeLock(sb, pTimer, rawRealtime, |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4942 | "partial", which, linePrefix); |
Bookatz | 5b5ec32 | 2017-05-26 09:40:38 -0700 | [diff] [blame] | 4943 | linePrefix = printWakeLock(sb, pTimer != null ? pTimer.getSubTimer() : null, |
| 4944 | rawRealtime, "background partial", which, linePrefix); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4945 | linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_WINDOW), rawRealtime, |
| 4946 | "window", which, linePrefix); |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 4947 | linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_DRAW), rawRealtime, |
| 4948 | "draw", which, linePrefix); |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 4949 | sb.append(" realtime"); |
| 4950 | pw.println(sb.toString()); |
| 4951 | uidActivity = true; |
| 4952 | countWakelock++; |
| 4953 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4954 | totalFullWakelock += computeWakeLock(wl.getWakeTime(WAKE_TYPE_FULL), |
| 4955 | rawRealtime, which); |
| 4956 | totalPartialWakelock += computeWakeLock(wl.getWakeTime(WAKE_TYPE_PARTIAL), |
| 4957 | rawRealtime, which); |
| 4958 | totalWindowWakelock += computeWakeLock(wl.getWakeTime(WAKE_TYPE_WINDOW), |
| 4959 | rawRealtime, which); |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 4960 | totalDrawWakelock += computeWakeLock(wl.getWakeTime(WAKE_TYPE_DRAW), |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 4961 | rawRealtime, which); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 4962 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4963 | if (countWakelock > 1) { |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 4964 | // get unpooled partial wakelock quantities (unlike totalPartialWakelock, which is |
| 4965 | // pooled and therefore just a lower bound) |
| 4966 | long actualTotalPartialWakelock = 0; |
| 4967 | long actualBgPartialWakelock = 0; |
| 4968 | if (u.getAggregatedPartialWakelockTimer() != null) { |
| 4969 | final Timer aggTimer = u.getAggregatedPartialWakelockTimer(); |
| 4970 | // Convert from microseconds to milliseconds with rounding |
| 4971 | actualTotalPartialWakelock = |
Bookatz | 6d79993 | 2017-06-07 12:30:07 -0700 | [diff] [blame] | 4972 | aggTimer.getTotalDurationMsLocked(rawRealtimeMs); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 4973 | final Timer bgAggTimer = aggTimer.getSubTimer(); |
| 4974 | actualBgPartialWakelock = bgAggTimer != null ? |
Bookatz | 6d79993 | 2017-06-07 12:30:07 -0700 | [diff] [blame] | 4975 | bgAggTimer.getTotalDurationMsLocked(rawRealtimeMs) : 0; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 4976 | } |
| 4977 | |
| 4978 | if (actualTotalPartialWakelock != 0 || actualBgPartialWakelock != 0 || |
| 4979 | totalFullWakelock != 0 || totalPartialWakelock != 0 || |
| 4980 | totalWindowWakelock != 0) { |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 4981 | sb.setLength(0); |
| 4982 | sb.append(prefix); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4983 | sb.append(" TOTAL wake: "); |
| 4984 | boolean needComma = false; |
| 4985 | if (totalFullWakelock != 0) { |
| 4986 | needComma = true; |
| 4987 | formatTimeMs(sb, totalFullWakelock); |
| 4988 | sb.append("full"); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 4989 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4990 | if (totalPartialWakelock != 0) { |
| 4991 | if (needComma) { |
| 4992 | sb.append(", "); |
| 4993 | } |
| 4994 | needComma = true; |
| 4995 | formatTimeMs(sb, totalPartialWakelock); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 4996 | sb.append("blamed partial"); |
| 4997 | } |
| 4998 | if (actualTotalPartialWakelock != 0) { |
| 4999 | if (needComma) { |
| 5000 | sb.append(", "); |
| 5001 | } |
| 5002 | needComma = true; |
| 5003 | formatTimeMs(sb, actualTotalPartialWakelock); |
| 5004 | sb.append("actual partial"); |
| 5005 | } |
| 5006 | if (actualBgPartialWakelock != 0) { |
| 5007 | if (needComma) { |
| 5008 | sb.append(", "); |
| 5009 | } |
| 5010 | needComma = true; |
| 5011 | formatTimeMs(sb, actualBgPartialWakelock); |
| 5012 | sb.append("actual background partial"); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5013 | } |
| 5014 | if (totalWindowWakelock != 0) { |
| 5015 | if (needComma) { |
| 5016 | sb.append(", "); |
| 5017 | } |
| 5018 | needComma = true; |
| 5019 | formatTimeMs(sb, totalWindowWakelock); |
| 5020 | sb.append("window"); |
| 5021 | } |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 5022 | if (totalDrawWakelock != 0) { |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 5023 | if (needComma) { |
| 5024 | sb.append(","); |
| 5025 | } |
| 5026 | needComma = true; |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 5027 | formatTimeMs(sb, totalDrawWakelock); |
| 5028 | sb.append("draw"); |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 5029 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5030 | sb.append(" realtime"); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 5031 | pw.println(sb.toString()); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 5032 | } |
| 5033 | } |
| 5034 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5035 | final ArrayMap<String, ? extends Timer> syncs = u.getSyncStats(); |
| 5036 | for (int isy=syncs.size()-1; isy>=0; isy--) { |
| 5037 | final Timer timer = syncs.valueAt(isy); |
| 5038 | // Convert from microseconds to milliseconds with rounding |
| 5039 | final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000; |
| 5040 | final int count = timer.getCountLocked(which); |
Bookatz | 2bffb5b | 2017-04-13 11:59:33 -0700 | [diff] [blame] | 5041 | final Timer bgTimer = timer.getSubTimer(); |
| 5042 | final long bgTime = bgTimer != null ? |
Bookatz | 6d79993 | 2017-06-07 12:30:07 -0700 | [diff] [blame] | 5043 | bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : -1; |
Bookatz | 2bffb5b | 2017-04-13 11:59:33 -0700 | [diff] [blame] | 5044 | final int bgCount = bgTimer != null ? bgTimer.getCountLocked(which) : -1; |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5045 | sb.setLength(0); |
| 5046 | sb.append(prefix); |
| 5047 | sb.append(" Sync "); |
| 5048 | sb.append(syncs.keyAt(isy)); |
| 5049 | sb.append(": "); |
| 5050 | if (totalTime != 0) { |
| 5051 | formatTimeMs(sb, totalTime); |
| 5052 | sb.append("realtime ("); |
| 5053 | sb.append(count); |
| 5054 | sb.append(" times)"); |
Bookatz | 2bffb5b | 2017-04-13 11:59:33 -0700 | [diff] [blame] | 5055 | if (bgTime > 0) { |
| 5056 | sb.append(", "); |
| 5057 | formatTimeMs(sb, bgTime); |
| 5058 | sb.append("background ("); |
| 5059 | sb.append(bgCount); |
| 5060 | sb.append(" times)"); |
| 5061 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5062 | } else { |
| 5063 | sb.append("(not used)"); |
| 5064 | } |
| 5065 | pw.println(sb.toString()); |
| 5066 | uidActivity = true; |
| 5067 | } |
| 5068 | |
| 5069 | final ArrayMap<String, ? extends Timer> jobs = u.getJobStats(); |
| 5070 | for (int ij=jobs.size()-1; ij>=0; ij--) { |
| 5071 | final Timer timer = jobs.valueAt(ij); |
| 5072 | // Convert from microseconds to milliseconds with rounding |
| 5073 | final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000; |
| 5074 | final int count = timer.getCountLocked(which); |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 5075 | final Timer bgTimer = timer.getSubTimer(); |
| 5076 | final long bgTime = bgTimer != null ? |
Bookatz | 6d79993 | 2017-06-07 12:30:07 -0700 | [diff] [blame] | 5077 | bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : -1; |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 5078 | final int bgCount = bgTimer != null ? bgTimer.getCountLocked(which) : -1; |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5079 | sb.setLength(0); |
| 5080 | sb.append(prefix); |
| 5081 | sb.append(" Job "); |
| 5082 | sb.append(jobs.keyAt(ij)); |
| 5083 | sb.append(": "); |
| 5084 | if (totalTime != 0) { |
| 5085 | formatTimeMs(sb, totalTime); |
| 5086 | sb.append("realtime ("); |
| 5087 | sb.append(count); |
| 5088 | sb.append(" times)"); |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 5089 | if (bgTime > 0) { |
| 5090 | sb.append(", "); |
| 5091 | formatTimeMs(sb, bgTime); |
| 5092 | sb.append("background ("); |
| 5093 | sb.append(bgCount); |
| 5094 | sb.append(" times)"); |
| 5095 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5096 | } else { |
| 5097 | sb.append("(not used)"); |
| 5098 | } |
| 5099 | pw.println(sb.toString()); |
| 5100 | uidActivity = true; |
| 5101 | } |
| 5102 | |
Dianne Hackborn | 94326cb | 2017-06-28 16:17:20 -0700 | [diff] [blame] | 5103 | final ArrayMap<String, SparseIntArray> completions = u.getJobCompletionStats(); |
| 5104 | for (int ic=completions.size()-1; ic>=0; ic--) { |
| 5105 | SparseIntArray types = completions.valueAt(ic); |
| 5106 | if (types != null) { |
| 5107 | pw.print(prefix); |
| 5108 | pw.print(" Job Completions "); |
| 5109 | pw.print(completions.keyAt(ic)); |
| 5110 | pw.print(":"); |
| 5111 | for (int it=0; it<types.size(); it++) { |
| 5112 | pw.print(" "); |
| 5113 | pw.print(JobParameters.getReasonName(types.keyAt(it))); |
| 5114 | pw.print("("); |
| 5115 | pw.print(types.valueAt(it)); |
| 5116 | pw.print("x)"); |
| 5117 | } |
| 5118 | pw.println(); |
| 5119 | } |
| 5120 | } |
| 5121 | |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 5122 | uidActivity |= printTimer(pw, sb, u.getFlashlightTurnedOnTimer(), rawRealtime, which, |
| 5123 | prefix, "Flashlight"); |
| 5124 | uidActivity |= printTimer(pw, sb, u.getCameraTurnedOnTimer(), rawRealtime, which, |
| 5125 | prefix, "Camera"); |
| 5126 | uidActivity |= printTimer(pw, sb, u.getVideoTurnedOnTimer(), rawRealtime, which, |
| 5127 | prefix, "Video"); |
| 5128 | uidActivity |= printTimer(pw, sb, u.getAudioTurnedOnTimer(), rawRealtime, which, |
| 5129 | prefix, "Audio"); |
| 5130 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5131 | final SparseArray<? extends BatteryStats.Uid.Sensor> sensors = u.getSensorStats(); |
| 5132 | final int NSE = sensors.size(); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5133 | for (int ise=0; ise<NSE; ise++) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5134 | final Uid.Sensor se = sensors.valueAt(ise); |
| 5135 | final int sensorNumber = sensors.keyAt(ise); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5136 | sb.setLength(0); |
| 5137 | sb.append(prefix); |
| 5138 | sb.append(" Sensor "); |
| 5139 | int handle = se.getHandle(); |
| 5140 | if (handle == Uid.Sensor.GPS) { |
| 5141 | sb.append("GPS"); |
| 5142 | } else { |
| 5143 | sb.append(handle); |
| 5144 | } |
| 5145 | sb.append(": "); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5146 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5147 | final Timer timer = se.getSensorTime(); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5148 | if (timer != null) { |
| 5149 | // Convert from microseconds to milliseconds with rounding |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5150 | final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) |
| 5151 | / 1000; |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5152 | final int count = timer.getCountLocked(which); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5153 | final Timer bgTimer = se.getSensorBackgroundTime(); |
| 5154 | final int bgCount = bgTimer != null ? bgTimer.getCountLocked(which) : 0; |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5155 | // 'actualTime' are unpooled and always since reset (regardless of 'which') |
| 5156 | final long actualTime = timer.getTotalDurationMsLocked(rawRealtimeMs); |
| 5157 | final long bgActualTime = bgTimer != null ? |
| 5158 | bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : 0; |
| 5159 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5160 | //timer.logState(); |
| 5161 | if (totalTime != 0) { |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5162 | if (actualTime != totalTime) { |
| 5163 | formatTimeMs(sb, totalTime); |
| 5164 | sb.append("blamed realtime, "); |
| 5165 | } |
| 5166 | |
| 5167 | formatTimeMs(sb, actualTime); // since reset, regardless of 'which' |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5168 | sb.append("realtime ("); |
| 5169 | sb.append(count); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5170 | sb.append(" times)"); |
| 5171 | |
| 5172 | if (bgActualTime != 0 || bgCount > 0) { |
Amith Yamasani | ab9ad19 | 2016-12-06 12:46:59 -0800 | [diff] [blame] | 5173 | sb.append(", "); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5174 | formatTimeMs(sb, bgActualTime); // since reset, regardless of 'which' |
| 5175 | sb.append("background ("); |
Amith Yamasani | ab9ad19 | 2016-12-06 12:46:59 -0800 | [diff] [blame] | 5176 | sb.append(bgCount); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5177 | sb.append(" times)"); |
Amith Yamasani | ab9ad19 | 2016-12-06 12:46:59 -0800 | [diff] [blame] | 5178 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5179 | } else { |
| 5180 | sb.append("(not used)"); |
| 5181 | } |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5182 | } else { |
| 5183 | sb.append("(not used)"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5184 | } |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5185 | |
| 5186 | pw.println(sb.toString()); |
| 5187 | uidActivity = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5188 | } |
| 5189 | |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 5190 | uidActivity |= printTimer(pw, sb, u.getVibratorOnTimer(), rawRealtime, which, prefix, |
| 5191 | "Vibrator"); |
| 5192 | uidActivity |= printTimer(pw, sb, u.getForegroundActivityTimer(), rawRealtime, which, |
| 5193 | prefix, "Foreground activities"); |
Michael Wachenschwanz | b05a3c5 | 2017-07-07 17:47:04 -0700 | [diff] [blame] | 5194 | uidActivity |= printTimer(pw, sb, u.getForegroundServiceTimer(), rawRealtime, which, |
| 5195 | prefix, "Foreground services"); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 5196 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5197 | long totalStateTime = 0; |
| 5198 | for (int ips=0; ips<Uid.NUM_PROCESS_STATE; ips++) { |
| 5199 | long time = u.getProcessStateTime(ips, rawRealtime, which); |
| 5200 | if (time > 0) { |
| 5201 | totalStateTime += time; |
| 5202 | sb.setLength(0); |
| 5203 | sb.append(prefix); |
| 5204 | sb.append(" "); |
| 5205 | sb.append(Uid.PROCESS_STATE_NAMES[ips]); |
| 5206 | sb.append(" for: "); |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 5207 | formatTimeMs(sb, (time + 500) / 1000); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5208 | pw.println(sb.toString()); |
| 5209 | uidActivity = true; |
| 5210 | } |
| 5211 | } |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 5212 | if (totalStateTime > 0) { |
| 5213 | sb.setLength(0); |
| 5214 | sb.append(prefix); |
| 5215 | sb.append(" Total running: "); |
| 5216 | formatTimeMs(sb, (totalStateTime + 500) / 1000); |
| 5217 | pw.println(sb.toString()); |
| 5218 | } |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5219 | |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 5220 | final long userCpuTimeUs = u.getUserCpuTimeUs(which); |
| 5221 | final long systemCpuTimeUs = u.getSystemCpuTimeUs(which); |
Adam Lesinski | d4abd1e | 2017-04-12 11:29:13 -0700 | [diff] [blame] | 5222 | if (userCpuTimeUs > 0 || systemCpuTimeUs > 0) { |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 5223 | sb.setLength(0); |
| 5224 | sb.append(prefix); |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 5225 | sb.append(" Total cpu time: u="); |
| 5226 | formatTimeMs(sb, userCpuTimeUs / 1000); |
| 5227 | sb.append("s="); |
| 5228 | formatTimeMs(sb, systemCpuTimeUs / 1000); |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 5229 | pw.println(sb.toString()); |
| 5230 | } |
| 5231 | |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 5232 | final long[] cpuFreqTimes = u.getCpuFreqTimes(which); |
| 5233 | if (cpuFreqTimes != null) { |
| 5234 | sb.setLength(0); |
| 5235 | sb.append(" Total cpu time per freq:"); |
| 5236 | for (int i = 0; i < cpuFreqTimes.length; ++i) { |
| 5237 | sb.append(" " + cpuFreqTimes[i]); |
| 5238 | } |
| 5239 | pw.println(sb.toString()); |
| 5240 | } |
| 5241 | final long[] screenOffCpuFreqTimes = u.getScreenOffCpuFreqTimes(which); |
| 5242 | if (screenOffCpuFreqTimes != null) { |
| 5243 | sb.setLength(0); |
| 5244 | sb.append(" Total screen-off cpu time per freq:"); |
| 5245 | for (int i = 0; i < screenOffCpuFreqTimes.length; ++i) { |
| 5246 | sb.append(" " + screenOffCpuFreqTimes[i]); |
| 5247 | } |
| 5248 | pw.println(sb.toString()); |
| 5249 | } |
| 5250 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5251 | final ArrayMap<String, ? extends BatteryStats.Uid.Proc> processStats |
| 5252 | = u.getProcessStats(); |
| 5253 | for (int ipr=processStats.size()-1; ipr>=0; ipr--) { |
| 5254 | final Uid.Proc ps = processStats.valueAt(ipr); |
| 5255 | long userTime; |
| 5256 | long systemTime; |
| 5257 | long foregroundTime; |
| 5258 | int starts; |
| 5259 | int numExcessive; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5260 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5261 | userTime = ps.getUserTime(which); |
| 5262 | systemTime = ps.getSystemTime(which); |
| 5263 | foregroundTime = ps.getForegroundTime(which); |
| 5264 | starts = ps.getStarts(which); |
| 5265 | final int numCrashes = ps.getNumCrashes(which); |
| 5266 | final int numAnrs = ps.getNumAnrs(which); |
| 5267 | numExcessive = which == STATS_SINCE_CHARGED |
| 5268 | ? ps.countExcessivePowers() : 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5269 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5270 | if (userTime != 0 || systemTime != 0 || foregroundTime != 0 || starts != 0 |
| 5271 | || numExcessive != 0 || numCrashes != 0 || numAnrs != 0) { |
| 5272 | sb.setLength(0); |
| 5273 | sb.append(prefix); sb.append(" Proc "); |
| 5274 | sb.append(processStats.keyAt(ipr)); sb.append(":\n"); |
| 5275 | sb.append(prefix); sb.append(" CPU: "); |
| 5276 | formatTimeMs(sb, userTime); sb.append("usr + "); |
| 5277 | formatTimeMs(sb, systemTime); sb.append("krn ; "); |
| 5278 | formatTimeMs(sb, foregroundTime); sb.append("fg"); |
| 5279 | if (starts != 0 || numCrashes != 0 || numAnrs != 0) { |
| 5280 | sb.append("\n"); sb.append(prefix); sb.append(" "); |
| 5281 | boolean hasOne = false; |
| 5282 | if (starts != 0) { |
| 5283 | hasOne = true; |
| 5284 | sb.append(starts); sb.append(" starts"); |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 5285 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5286 | if (numCrashes != 0) { |
| 5287 | if (hasOne) { |
| 5288 | sb.append(", "); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 5289 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5290 | hasOne = true; |
| 5291 | sb.append(numCrashes); sb.append(" crashes"); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 5292 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5293 | if (numAnrs != 0) { |
| 5294 | if (hasOne) { |
| 5295 | sb.append(", "); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5296 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5297 | sb.append(numAnrs); sb.append(" anrs"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5298 | } |
| 5299 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5300 | pw.println(sb.toString()); |
| 5301 | for (int e=0; e<numExcessive; e++) { |
| 5302 | Uid.Proc.ExcessivePower ew = ps.getExcessivePower(e); |
| 5303 | if (ew != null) { |
| 5304 | pw.print(prefix); pw.print(" * Killed for "); |
Dianne Hackborn | ffca58b | 2017-05-24 16:15:45 -0700 | [diff] [blame] | 5305 | if (ew.type == Uid.Proc.ExcessivePower.TYPE_CPU) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5306 | pw.print("cpu"); |
| 5307 | } else { |
| 5308 | pw.print("unknown"); |
| 5309 | } |
| 5310 | pw.print(" use: "); |
| 5311 | TimeUtils.formatDuration(ew.usedTime, pw); |
| 5312 | pw.print(" over "); |
| 5313 | TimeUtils.formatDuration(ew.overTime, pw); |
| 5314 | if (ew.overTime != 0) { |
| 5315 | pw.print(" ("); |
| 5316 | pw.print((ew.usedTime*100)/ew.overTime); |
| 5317 | pw.println("%)"); |
| 5318 | } |
| 5319 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5320 | } |
| 5321 | uidActivity = true; |
| 5322 | } |
| 5323 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5324 | |
| 5325 | final ArrayMap<String, ? extends BatteryStats.Uid.Pkg> packageStats |
| 5326 | = u.getPackageStats(); |
| 5327 | for (int ipkg=packageStats.size()-1; ipkg>=0; ipkg--) { |
| 5328 | pw.print(prefix); pw.print(" Apk "); pw.print(packageStats.keyAt(ipkg)); |
| 5329 | pw.println(":"); |
| 5330 | boolean apkActivity = false; |
| 5331 | final Uid.Pkg ps = packageStats.valueAt(ipkg); |
| 5332 | final ArrayMap<String, ? extends Counter> alarms = ps.getWakeupAlarmStats(); |
| 5333 | for (int iwa=alarms.size()-1; iwa>=0; iwa--) { |
| 5334 | pw.print(prefix); pw.print(" Wakeup alarm "); |
| 5335 | pw.print(alarms.keyAt(iwa)); pw.print(": "); |
| 5336 | pw.print(alarms.valueAt(iwa).getCountLocked(which)); |
| 5337 | pw.println(" times"); |
| 5338 | apkActivity = true; |
| 5339 | } |
| 5340 | final ArrayMap<String, ? extends Uid.Pkg.Serv> serviceStats = ps.getServiceStats(); |
| 5341 | for (int isvc=serviceStats.size()-1; isvc>=0; isvc--) { |
| 5342 | final BatteryStats.Uid.Pkg.Serv ss = serviceStats.valueAt(isvc); |
| 5343 | final long startTime = ss.getStartTime(batteryUptime, which); |
| 5344 | final int starts = ss.getStarts(which); |
| 5345 | final int launches = ss.getLaunches(which); |
| 5346 | if (startTime != 0 || starts != 0 || launches != 0) { |
| 5347 | sb.setLength(0); |
| 5348 | sb.append(prefix); sb.append(" Service "); |
| 5349 | sb.append(serviceStats.keyAt(isvc)); sb.append(":\n"); |
| 5350 | sb.append(prefix); sb.append(" Created for: "); |
| 5351 | formatTimeMs(sb, startTime / 1000); |
| 5352 | sb.append("uptime\n"); |
| 5353 | sb.append(prefix); sb.append(" Starts: "); |
| 5354 | sb.append(starts); |
| 5355 | sb.append(", launches: "); sb.append(launches); |
| 5356 | pw.println(sb.toString()); |
| 5357 | apkActivity = true; |
| 5358 | } |
| 5359 | } |
| 5360 | if (!apkActivity) { |
| 5361 | pw.print(prefix); pw.println(" (nothing executed)"); |
| 5362 | } |
| 5363 | uidActivity = true; |
| 5364 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5365 | if (!uidActivity) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 5366 | pw.print(prefix); pw.println(" (nothing executed)"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5367 | } |
| 5368 | } |
| 5369 | } |
| 5370 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 5371 | static void printBitDescriptions(PrintWriter pw, int oldval, int newval, HistoryTag wakelockTag, |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5372 | BitDescription[] descriptions, boolean longNames) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5373 | int diff = oldval ^ newval; |
| 5374 | if (diff == 0) return; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 5375 | boolean didWake = false; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5376 | for (int i=0; i<descriptions.length; i++) { |
| 5377 | BitDescription bd = descriptions[i]; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 5378 | if ((diff&bd.mask) != 0) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5379 | pw.print(longNames ? " " : ","); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5380 | if (bd.shift < 0) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 5381 | pw.print((newval&bd.mask) != 0 ? "+" : "-"); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5382 | pw.print(longNames ? bd.name : bd.shortName); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 5383 | if (bd.mask == HistoryItem.STATE_WAKE_LOCK_FLAG && wakelockTag != null) { |
| 5384 | didWake = true; |
| 5385 | pw.print("="); |
| 5386 | if (longNames) { |
| 5387 | UserHandle.formatUid(pw, wakelockTag.uid); |
| 5388 | pw.print(":\""); |
| 5389 | pw.print(wakelockTag.string); |
| 5390 | pw.print("\""); |
| 5391 | } else { |
| 5392 | pw.print(wakelockTag.poolIdx); |
| 5393 | } |
| 5394 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5395 | } else { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5396 | pw.print(longNames ? bd.name : bd.shortName); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5397 | pw.print("="); |
| 5398 | int val = (newval&bd.mask)>>bd.shift; |
| 5399 | if (bd.values != null && val >= 0 && val < bd.values.length) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5400 | pw.print(longNames? bd.values[val] : bd.shortValues[val]); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5401 | } else { |
| 5402 | pw.print(val); |
| 5403 | } |
| 5404 | } |
| 5405 | } |
| 5406 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 5407 | if (!didWake && wakelockTag != null) { |
Ashish Sharma | 81850c4 | 2014-05-05 13:57:07 -0700 | [diff] [blame] | 5408 | pw.print(longNames ? " wake_lock=" : ",w="); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 5409 | if (longNames) { |
| 5410 | UserHandle.formatUid(pw, wakelockTag.uid); |
| 5411 | pw.print(":\""); |
| 5412 | pw.print(wakelockTag.string); |
| 5413 | pw.print("\""); |
| 5414 | } else { |
| 5415 | pw.print(wakelockTag.poolIdx); |
| 5416 | } |
| 5417 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5418 | } |
| 5419 | |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5420 | public void prepareForDumpLocked() { |
| 5421 | } |
| 5422 | |
| 5423 | public static class HistoryPrinter { |
| 5424 | int oldState = 0; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 5425 | int oldState2 = 0; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5426 | int oldLevel = -1; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5427 | int oldStatus = -1; |
| 5428 | int oldHealth = -1; |
| 5429 | int oldPlug = -1; |
| 5430 | int oldTemp = -1; |
| 5431 | int oldVolt = -1; |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 5432 | int oldChargeMAh = -1; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5433 | long lastTime = -1; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5434 | |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 5435 | void reset() { |
| 5436 | oldState = oldState2 = 0; |
| 5437 | oldLevel = -1; |
| 5438 | oldStatus = -1; |
| 5439 | oldHealth = -1; |
| 5440 | oldPlug = -1; |
| 5441 | oldTemp = -1; |
| 5442 | oldVolt = -1; |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 5443 | oldChargeMAh = -1; |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 5444 | } |
| 5445 | |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 5446 | public void printNextItem(PrintWriter pw, HistoryItem rec, long baseTime, boolean checkin, |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 5447 | boolean verbose) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5448 | if (!checkin) { |
| 5449 | pw.print(" "); |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 5450 | TimeUtils.formatDuration(rec.time - baseTime, pw, TimeUtils.HUNDRED_DAY_FIELD_LEN); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 5451 | pw.print(" ("); |
| 5452 | pw.print(rec.numReadInts); |
| 5453 | pw.print(") "); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5454 | } else { |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 5455 | pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(','); |
| 5456 | pw.print(HISTORY_DATA); pw.print(','); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5457 | if (lastTime < 0) { |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 5458 | pw.print(rec.time - baseTime); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5459 | } else { |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 5460 | pw.print(rec.time - lastTime); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5461 | } |
| 5462 | lastTime = rec.time; |
| 5463 | } |
| 5464 | if (rec.cmd == HistoryItem.CMD_START) { |
| 5465 | if (checkin) { |
| 5466 | pw.print(":"); |
| 5467 | } |
| 5468 | pw.println("START"); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 5469 | reset(); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 5470 | } else if (rec.cmd == HistoryItem.CMD_CURRENT_TIME |
| 5471 | || rec.cmd == HistoryItem.CMD_RESET) { |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 5472 | if (checkin) { |
| 5473 | pw.print(":"); |
| 5474 | } |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 5475 | if (rec.cmd == HistoryItem.CMD_RESET) { |
| 5476 | pw.print("RESET:"); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 5477 | reset(); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 5478 | } |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 5479 | pw.print("TIME:"); |
| 5480 | if (checkin) { |
| 5481 | pw.println(rec.currentTime); |
| 5482 | } else { |
| 5483 | pw.print(" "); |
| 5484 | pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss", |
| 5485 | rec.currentTime).toString()); |
| 5486 | } |
Dianne Hackborn | 29cd7f1 | 2015-01-08 10:37:05 -0800 | [diff] [blame] | 5487 | } else if (rec.cmd == HistoryItem.CMD_SHUTDOWN) { |
| 5488 | if (checkin) { |
| 5489 | pw.print(":"); |
| 5490 | } |
| 5491 | pw.println("SHUTDOWN"); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5492 | } else if (rec.cmd == HistoryItem.CMD_OVERFLOW) { |
| 5493 | if (checkin) { |
| 5494 | pw.print(":"); |
| 5495 | } |
| 5496 | pw.println("*OVERFLOW*"); |
| 5497 | } else { |
| 5498 | if (!checkin) { |
| 5499 | if (rec.batteryLevel < 10) pw.print("00"); |
| 5500 | else if (rec.batteryLevel < 100) pw.print("0"); |
| 5501 | pw.print(rec.batteryLevel); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 5502 | if (verbose) { |
| 5503 | pw.print(" "); |
| 5504 | if (rec.states < 0) ; |
| 5505 | else if (rec.states < 0x10) pw.print("0000000"); |
| 5506 | else if (rec.states < 0x100) pw.print("000000"); |
| 5507 | else if (rec.states < 0x1000) pw.print("00000"); |
| 5508 | else if (rec.states < 0x10000) pw.print("0000"); |
| 5509 | else if (rec.states < 0x100000) pw.print("000"); |
| 5510 | else if (rec.states < 0x1000000) pw.print("00"); |
| 5511 | else if (rec.states < 0x10000000) pw.print("0"); |
| 5512 | pw.print(Integer.toHexString(rec.states)); |
| 5513 | } |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5514 | } else { |
| 5515 | if (oldLevel != rec.batteryLevel) { |
| 5516 | oldLevel = rec.batteryLevel; |
| 5517 | pw.print(",Bl="); pw.print(rec.batteryLevel); |
| 5518 | } |
| 5519 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5520 | if (oldStatus != rec.batteryStatus) { |
| 5521 | oldStatus = rec.batteryStatus; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5522 | pw.print(checkin ? ",Bs=" : " status="); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5523 | switch (oldStatus) { |
| 5524 | case BatteryManager.BATTERY_STATUS_UNKNOWN: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5525 | pw.print(checkin ? "?" : "unknown"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5526 | break; |
| 5527 | case BatteryManager.BATTERY_STATUS_CHARGING: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5528 | pw.print(checkin ? "c" : "charging"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5529 | break; |
| 5530 | case BatteryManager.BATTERY_STATUS_DISCHARGING: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5531 | pw.print(checkin ? "d" : "discharging"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5532 | break; |
| 5533 | case BatteryManager.BATTERY_STATUS_NOT_CHARGING: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5534 | pw.print(checkin ? "n" : "not-charging"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5535 | break; |
| 5536 | case BatteryManager.BATTERY_STATUS_FULL: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5537 | pw.print(checkin ? "f" : "full"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5538 | break; |
| 5539 | default: |
| 5540 | pw.print(oldStatus); |
| 5541 | break; |
| 5542 | } |
| 5543 | } |
| 5544 | if (oldHealth != rec.batteryHealth) { |
| 5545 | oldHealth = rec.batteryHealth; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5546 | pw.print(checkin ? ",Bh=" : " health="); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5547 | switch (oldHealth) { |
| 5548 | case BatteryManager.BATTERY_HEALTH_UNKNOWN: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5549 | pw.print(checkin ? "?" : "unknown"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5550 | break; |
| 5551 | case BatteryManager.BATTERY_HEALTH_GOOD: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5552 | pw.print(checkin ? "g" : "good"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5553 | break; |
| 5554 | case BatteryManager.BATTERY_HEALTH_OVERHEAT: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5555 | pw.print(checkin ? "h" : "overheat"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5556 | break; |
| 5557 | case BatteryManager.BATTERY_HEALTH_DEAD: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5558 | pw.print(checkin ? "d" : "dead"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5559 | break; |
| 5560 | case BatteryManager.BATTERY_HEALTH_OVER_VOLTAGE: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5561 | pw.print(checkin ? "v" : "over-voltage"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5562 | break; |
| 5563 | case BatteryManager.BATTERY_HEALTH_UNSPECIFIED_FAILURE: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5564 | pw.print(checkin ? "f" : "failure"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5565 | break; |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 5566 | case BatteryManager.BATTERY_HEALTH_COLD: |
| 5567 | pw.print(checkin ? "c" : "cold"); |
| 5568 | break; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5569 | default: |
| 5570 | pw.print(oldHealth); |
| 5571 | break; |
| 5572 | } |
| 5573 | } |
| 5574 | if (oldPlug != rec.batteryPlugType) { |
| 5575 | oldPlug = rec.batteryPlugType; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5576 | pw.print(checkin ? ",Bp=" : " plug="); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5577 | switch (oldPlug) { |
| 5578 | case 0: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5579 | pw.print(checkin ? "n" : "none"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5580 | break; |
| 5581 | case BatteryManager.BATTERY_PLUGGED_AC: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5582 | pw.print(checkin ? "a" : "ac"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5583 | break; |
| 5584 | case BatteryManager.BATTERY_PLUGGED_USB: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5585 | pw.print(checkin ? "u" : "usb"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5586 | break; |
Brian Muramatsu | 37a37f4 | 2012-08-14 15:21:02 -0700 | [diff] [blame] | 5587 | case BatteryManager.BATTERY_PLUGGED_WIRELESS: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5588 | pw.print(checkin ? "w" : "wireless"); |
Brian Muramatsu | 37a37f4 | 2012-08-14 15:21:02 -0700 | [diff] [blame] | 5589 | break; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5590 | default: |
| 5591 | pw.print(oldPlug); |
| 5592 | break; |
| 5593 | } |
| 5594 | } |
| 5595 | if (oldTemp != rec.batteryTemperature) { |
| 5596 | oldTemp = rec.batteryTemperature; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5597 | pw.print(checkin ? ",Bt=" : " temp="); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5598 | pw.print(oldTemp); |
| 5599 | } |
| 5600 | if (oldVolt != rec.batteryVoltage) { |
| 5601 | oldVolt = rec.batteryVoltage; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5602 | pw.print(checkin ? ",Bv=" : " volt="); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5603 | pw.print(oldVolt); |
| 5604 | } |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 5605 | final int chargeMAh = rec.batteryChargeUAh / 1000; |
| 5606 | if (oldChargeMAh != chargeMAh) { |
| 5607 | oldChargeMAh = chargeMAh; |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 5608 | pw.print(checkin ? ",Bcc=" : " charge="); |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 5609 | pw.print(oldChargeMAh); |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 5610 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 5611 | printBitDescriptions(pw, oldState, rec.states, rec.wakelockTag, |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5612 | HISTORY_STATE_DESCRIPTIONS, !checkin); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 5613 | printBitDescriptions(pw, oldState2, rec.states2, null, |
| 5614 | HISTORY_STATE2_DESCRIPTIONS, !checkin); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 5615 | if (rec.wakeReasonTag != null) { |
| 5616 | if (checkin) { |
Dianne Hackborn | d06dcfd | 2014-05-02 13:49:30 -0700 | [diff] [blame] | 5617 | pw.print(",wr="); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 5618 | pw.print(rec.wakeReasonTag.poolIdx); |
| 5619 | } else { |
| 5620 | pw.print(" wake_reason="); |
| 5621 | pw.print(rec.wakeReasonTag.uid); |
| 5622 | pw.print(":\""); |
| 5623 | pw.print(rec.wakeReasonTag.string); |
| 5624 | pw.print("\""); |
| 5625 | } |
| 5626 | } |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 5627 | if (rec.eventCode != HistoryItem.EVENT_NONE) { |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 5628 | pw.print(checkin ? "," : " "); |
| 5629 | if ((rec.eventCode&HistoryItem.EVENT_FLAG_START) != 0) { |
| 5630 | pw.print("+"); |
| 5631 | } else if ((rec.eventCode&HistoryItem.EVENT_FLAG_FINISH) != 0) { |
| 5632 | pw.print("-"); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 5633 | } |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 5634 | String[] eventNames = checkin ? HISTORY_EVENT_CHECKIN_NAMES |
| 5635 | : HISTORY_EVENT_NAMES; |
| 5636 | int idx = rec.eventCode & ~(HistoryItem.EVENT_FLAG_START |
| 5637 | | HistoryItem.EVENT_FLAG_FINISH); |
| 5638 | if (idx >= 0 && idx < eventNames.length) { |
| 5639 | pw.print(eventNames[idx]); |
| 5640 | } else { |
| 5641 | pw.print(checkin ? "Ev" : "event"); |
| 5642 | pw.print(idx); |
| 5643 | } |
| 5644 | pw.print("="); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 5645 | if (checkin) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 5646 | pw.print(rec.eventTag.poolIdx); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 5647 | } else { |
Adam Lesinski | 041d917 | 2016-12-12 12:03:56 -0800 | [diff] [blame] | 5648 | pw.append(HISTORY_EVENT_INT_FORMATTERS[idx] |
| 5649 | .applyAsString(rec.eventTag.uid)); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 5650 | pw.print(":\""); |
| 5651 | pw.print(rec.eventTag.string); |
| 5652 | pw.print("\""); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 5653 | } |
| 5654 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5655 | pw.println(); |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 5656 | if (rec.stepDetails != null) { |
| 5657 | if (!checkin) { |
| 5658 | pw.print(" Details: cpu="); |
| 5659 | pw.print(rec.stepDetails.userTime); |
| 5660 | pw.print("u+"); |
| 5661 | pw.print(rec.stepDetails.systemTime); |
| 5662 | pw.print("s"); |
| 5663 | if (rec.stepDetails.appCpuUid1 >= 0) { |
| 5664 | pw.print(" ("); |
| 5665 | printStepCpuUidDetails(pw, rec.stepDetails.appCpuUid1, |
| 5666 | rec.stepDetails.appCpuUTime1, rec.stepDetails.appCpuSTime1); |
| 5667 | if (rec.stepDetails.appCpuUid2 >= 0) { |
| 5668 | pw.print(", "); |
| 5669 | printStepCpuUidDetails(pw, rec.stepDetails.appCpuUid2, |
| 5670 | rec.stepDetails.appCpuUTime2, rec.stepDetails.appCpuSTime2); |
| 5671 | } |
| 5672 | if (rec.stepDetails.appCpuUid3 >= 0) { |
| 5673 | pw.print(", "); |
| 5674 | printStepCpuUidDetails(pw, rec.stepDetails.appCpuUid3, |
| 5675 | rec.stepDetails.appCpuUTime3, rec.stepDetails.appCpuSTime3); |
| 5676 | } |
| 5677 | pw.print(')'); |
| 5678 | } |
| 5679 | pw.println(); |
| 5680 | pw.print(" /proc/stat="); |
| 5681 | pw.print(rec.stepDetails.statUserTime); |
| 5682 | pw.print(" usr, "); |
| 5683 | pw.print(rec.stepDetails.statSystemTime); |
| 5684 | pw.print(" sys, "); |
| 5685 | pw.print(rec.stepDetails.statIOWaitTime); |
| 5686 | pw.print(" io, "); |
| 5687 | pw.print(rec.stepDetails.statIrqTime); |
| 5688 | pw.print(" irq, "); |
| 5689 | pw.print(rec.stepDetails.statSoftIrqTime); |
| 5690 | pw.print(" sirq, "); |
| 5691 | pw.print(rec.stepDetails.statIdlTime); |
| 5692 | pw.print(" idle"); |
| 5693 | int totalRun = rec.stepDetails.statUserTime + rec.stepDetails.statSystemTime |
| 5694 | + rec.stepDetails.statIOWaitTime + rec.stepDetails.statIrqTime |
| 5695 | + rec.stepDetails.statSoftIrqTime; |
| 5696 | int total = totalRun + rec.stepDetails.statIdlTime; |
| 5697 | if (total > 0) { |
| 5698 | pw.print(" ("); |
| 5699 | float perc = ((float)totalRun) / ((float)total) * 100; |
| 5700 | pw.print(String.format("%.1f%%", perc)); |
| 5701 | pw.print(" of "); |
| 5702 | StringBuilder sb = new StringBuilder(64); |
| 5703 | formatTimeMsNoSpace(sb, total*10); |
| 5704 | pw.print(sb); |
| 5705 | pw.print(")"); |
| 5706 | } |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 5707 | pw.print(", PlatformIdleStat "); |
| 5708 | pw.print(rec.stepDetails.statPlatformIdleState); |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 5709 | pw.println(); |
Ahmed ElArabawy | d8b4411 | 2017-05-23 21:25:02 +0000 | [diff] [blame] | 5710 | |
| 5711 | pw.print(", SubsystemPowerState "); |
| 5712 | pw.print(rec.stepDetails.statSubsystemPowerState); |
| 5713 | pw.println(); |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 5714 | } else { |
| 5715 | pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(','); |
| 5716 | pw.print(HISTORY_DATA); pw.print(",0,Dcpu="); |
| 5717 | pw.print(rec.stepDetails.userTime); |
| 5718 | pw.print(":"); |
| 5719 | pw.print(rec.stepDetails.systemTime); |
| 5720 | if (rec.stepDetails.appCpuUid1 >= 0) { |
| 5721 | printStepCpuUidCheckinDetails(pw, rec.stepDetails.appCpuUid1, |
| 5722 | rec.stepDetails.appCpuUTime1, rec.stepDetails.appCpuSTime1); |
| 5723 | if (rec.stepDetails.appCpuUid2 >= 0) { |
| 5724 | printStepCpuUidCheckinDetails(pw, rec.stepDetails.appCpuUid2, |
| 5725 | rec.stepDetails.appCpuUTime2, rec.stepDetails.appCpuSTime2); |
| 5726 | } |
| 5727 | if (rec.stepDetails.appCpuUid3 >= 0) { |
| 5728 | printStepCpuUidCheckinDetails(pw, rec.stepDetails.appCpuUid3, |
| 5729 | rec.stepDetails.appCpuUTime3, rec.stepDetails.appCpuSTime3); |
| 5730 | } |
| 5731 | } |
| 5732 | pw.println(); |
| 5733 | pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(','); |
| 5734 | pw.print(HISTORY_DATA); pw.print(",0,Dpst="); |
| 5735 | pw.print(rec.stepDetails.statUserTime); |
| 5736 | pw.print(','); |
| 5737 | pw.print(rec.stepDetails.statSystemTime); |
| 5738 | pw.print(','); |
| 5739 | pw.print(rec.stepDetails.statIOWaitTime); |
| 5740 | pw.print(','); |
| 5741 | pw.print(rec.stepDetails.statIrqTime); |
| 5742 | pw.print(','); |
| 5743 | pw.print(rec.stepDetails.statSoftIrqTime); |
| 5744 | pw.print(','); |
| 5745 | pw.print(rec.stepDetails.statIdlTime); |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 5746 | pw.print(','); |
Adam Lesinski | 8568d8f | 2016-07-15 18:13:23 -0700 | [diff] [blame] | 5747 | if (rec.stepDetails.statPlatformIdleState != null) { |
| 5748 | pw.print(rec.stepDetails.statPlatformIdleState); |
Ahmed ElArabawy | 307edcd | 2017-07-07 17:48:13 -0700 | [diff] [blame] | 5749 | if (rec.stepDetails.statSubsystemPowerState != null) { |
| 5750 | pw.print(','); |
| 5751 | } |
Adam Lesinski | 8568d8f | 2016-07-15 18:13:23 -0700 | [diff] [blame] | 5752 | } |
Ahmed ElArabawy | d8b4411 | 2017-05-23 21:25:02 +0000 | [diff] [blame] | 5753 | |
| 5754 | if (rec.stepDetails.statSubsystemPowerState != null) { |
| 5755 | pw.print(rec.stepDetails.statSubsystemPowerState); |
| 5756 | } |
| 5757 | pw.println(); |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 5758 | } |
| 5759 | } |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 5760 | oldState = rec.states; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 5761 | oldState2 = rec.states2; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5762 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5763 | } |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 5764 | |
| 5765 | private void printStepCpuUidDetails(PrintWriter pw, int uid, int utime, int stime) { |
| 5766 | UserHandle.formatUid(pw, uid); |
| 5767 | pw.print("="); |
| 5768 | pw.print(utime); |
| 5769 | pw.print("u+"); |
| 5770 | pw.print(stime); |
| 5771 | pw.print("s"); |
| 5772 | } |
| 5773 | |
| 5774 | private void printStepCpuUidCheckinDetails(PrintWriter pw, int uid, int utime, int stime) { |
| 5775 | pw.print('/'); |
| 5776 | pw.print(uid); |
| 5777 | pw.print(":"); |
| 5778 | pw.print(utime); |
| 5779 | pw.print(":"); |
| 5780 | pw.print(stime); |
| 5781 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5782 | } |
| 5783 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 5784 | private void printSizeValue(PrintWriter pw, long size) { |
| 5785 | float result = size; |
| 5786 | String suffix = ""; |
| 5787 | if (result >= 10*1024) { |
| 5788 | suffix = "KB"; |
| 5789 | result = result / 1024; |
| 5790 | } |
| 5791 | if (result >= 10*1024) { |
| 5792 | suffix = "MB"; |
| 5793 | result = result / 1024; |
| 5794 | } |
| 5795 | if (result >= 10*1024) { |
| 5796 | suffix = "GB"; |
| 5797 | result = result / 1024; |
| 5798 | } |
| 5799 | if (result >= 10*1024) { |
| 5800 | suffix = "TB"; |
| 5801 | result = result / 1024; |
| 5802 | } |
| 5803 | if (result >= 10*1024) { |
| 5804 | suffix = "PB"; |
| 5805 | result = result / 1024; |
| 5806 | } |
| 5807 | pw.print((int)result); |
| 5808 | pw.print(suffix); |
| 5809 | } |
| 5810 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 5811 | private static boolean dumpTimeEstimate(PrintWriter pw, String label1, String label2, |
| 5812 | String label3, long estimatedTime) { |
| 5813 | if (estimatedTime < 0) { |
Dianne Hackborn | ad6a99b | 2014-11-18 10:11:10 -0800 | [diff] [blame] | 5814 | return false; |
| 5815 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 5816 | pw.print(label1); |
| 5817 | pw.print(label2); |
| 5818 | pw.print(label3); |
Dianne Hackborn | ad6a99b | 2014-11-18 10:11:10 -0800 | [diff] [blame] | 5819 | StringBuilder sb = new StringBuilder(64); |
| 5820 | formatTimeMs(sb, estimatedTime); |
| 5821 | pw.print(sb); |
| 5822 | pw.println(); |
Dianne Hackborn | ad6a99b | 2014-11-18 10:11:10 -0800 | [diff] [blame] | 5823 | return true; |
| 5824 | } |
| 5825 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 5826 | private static boolean dumpDurationSteps(PrintWriter pw, String prefix, String header, |
| 5827 | LevelStepTracker steps, boolean checkin) { |
| 5828 | if (steps == null) { |
| 5829 | return false; |
| 5830 | } |
| 5831 | int count = steps.mNumStepDurations; |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 5832 | if (count <= 0) { |
| 5833 | return false; |
| 5834 | } |
| 5835 | if (!checkin) { |
| 5836 | pw.println(header); |
| 5837 | } |
Kweku Adams | 030980a | 2015-04-01 16:07:48 -0700 | [diff] [blame] | 5838 | String[] lineArgs = new String[5]; |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 5839 | for (int i=0; i<count; i++) { |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 5840 | long duration = steps.getDurationAt(i); |
| 5841 | int level = steps.getLevelAt(i); |
| 5842 | long initMode = steps.getInitModeAt(i); |
| 5843 | long modMode = steps.getModModeAt(i); |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 5844 | if (checkin) { |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 5845 | lineArgs[0] = Long.toString(duration); |
| 5846 | lineArgs[1] = Integer.toString(level); |
| 5847 | if ((modMode&STEP_LEVEL_MODE_SCREEN_STATE) == 0) { |
| 5848 | switch ((int)(initMode&STEP_LEVEL_MODE_SCREEN_STATE) + 1) { |
| 5849 | case Display.STATE_OFF: lineArgs[2] = "s-"; break; |
| 5850 | case Display.STATE_ON: lineArgs[2] = "s+"; break; |
| 5851 | case Display.STATE_DOZE: lineArgs[2] = "sd"; break; |
| 5852 | case Display.STATE_DOZE_SUSPEND: lineArgs[2] = "sds"; break; |
Kweku Adams | 030980a | 2015-04-01 16:07:48 -0700 | [diff] [blame] | 5853 | default: lineArgs[2] = "?"; break; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 5854 | } |
| 5855 | } else { |
| 5856 | lineArgs[2] = ""; |
| 5857 | } |
| 5858 | if ((modMode&STEP_LEVEL_MODE_POWER_SAVE) == 0) { |
| 5859 | lineArgs[3] = (initMode&STEP_LEVEL_MODE_POWER_SAVE) != 0 ? "p+" : "p-"; |
| 5860 | } else { |
| 5861 | lineArgs[3] = ""; |
| 5862 | } |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 5863 | if ((modMode&STEP_LEVEL_MODE_DEVICE_IDLE) == 0) { |
Kweku Adams | 030980a | 2015-04-01 16:07:48 -0700 | [diff] [blame] | 5864 | lineArgs[4] = (initMode&STEP_LEVEL_MODE_DEVICE_IDLE) != 0 ? "i+" : "i-"; |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 5865 | } else { |
Kweku Adams | 030980a | 2015-04-01 16:07:48 -0700 | [diff] [blame] | 5866 | lineArgs[4] = ""; |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 5867 | } |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 5868 | dumpLine(pw, 0 /* uid */, "i" /* category */, header, (Object[])lineArgs); |
| 5869 | } else { |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 5870 | pw.print(prefix); |
| 5871 | pw.print("#"); pw.print(i); pw.print(": "); |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 5872 | TimeUtils.formatDuration(duration, pw); |
| 5873 | pw.print(" to "); pw.print(level); |
| 5874 | boolean haveModes = false; |
| 5875 | if ((modMode&STEP_LEVEL_MODE_SCREEN_STATE) == 0) { |
| 5876 | pw.print(" ("); |
| 5877 | switch ((int)(initMode&STEP_LEVEL_MODE_SCREEN_STATE) + 1) { |
| 5878 | case Display.STATE_OFF: pw.print("screen-off"); break; |
| 5879 | case Display.STATE_ON: pw.print("screen-on"); break; |
| 5880 | case Display.STATE_DOZE: pw.print("screen-doze"); break; |
| 5881 | case Display.STATE_DOZE_SUSPEND: pw.print("screen-doze-suspend"); break; |
Kweku Adams | 030980a | 2015-04-01 16:07:48 -0700 | [diff] [blame] | 5882 | default: pw.print("screen-?"); break; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 5883 | } |
| 5884 | haveModes = true; |
| 5885 | } |
| 5886 | if ((modMode&STEP_LEVEL_MODE_POWER_SAVE) == 0) { |
| 5887 | pw.print(haveModes ? ", " : " ("); |
| 5888 | pw.print((initMode&STEP_LEVEL_MODE_POWER_SAVE) != 0 |
| 5889 | ? "power-save-on" : "power-save-off"); |
| 5890 | haveModes = true; |
| 5891 | } |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 5892 | if ((modMode&STEP_LEVEL_MODE_DEVICE_IDLE) == 0) { |
| 5893 | pw.print(haveModes ? ", " : " ("); |
| 5894 | pw.print((initMode&STEP_LEVEL_MODE_DEVICE_IDLE) != 0 |
| 5895 | ? "device-idle-on" : "device-idle-off"); |
| 5896 | haveModes = true; |
| 5897 | } |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 5898 | if (haveModes) { |
| 5899 | pw.print(")"); |
| 5900 | } |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 5901 | pw.println(); |
| 5902 | } |
| 5903 | } |
| 5904 | return true; |
| 5905 | } |
| 5906 | |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 5907 | public static final int DUMP_CHARGED_ONLY = 1<<1; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 5908 | public static final int DUMP_DAILY_ONLY = 1<<2; |
| 5909 | public static final int DUMP_HISTORY_ONLY = 1<<3; |
| 5910 | public static final int DUMP_INCLUDE_HISTORY = 1<<4; |
| 5911 | public static final int DUMP_VERBOSE = 1<<5; |
| 5912 | public static final int DUMP_DEVICE_WIFI_ONLY = 1<<6; |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 5913 | |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 5914 | private void dumpHistoryLocked(PrintWriter pw, int flags, long histStart, boolean checkin) { |
| 5915 | final HistoryPrinter hprinter = new HistoryPrinter(); |
| 5916 | final HistoryItem rec = new HistoryItem(); |
| 5917 | long lastTime = -1; |
| 5918 | long baseTime = -1; |
| 5919 | boolean printed = false; |
| 5920 | HistoryEventTracker tracker = null; |
| 5921 | while (getNextHistoryLocked(rec)) { |
| 5922 | lastTime = rec.time; |
| 5923 | if (baseTime < 0) { |
| 5924 | baseTime = lastTime; |
| 5925 | } |
| 5926 | if (rec.time >= histStart) { |
| 5927 | if (histStart >= 0 && !printed) { |
| 5928 | if (rec.cmd == HistoryItem.CMD_CURRENT_TIME |
Ashish Sharma | 6020071 | 2014-05-23 18:22:20 -0700 | [diff] [blame] | 5929 | || rec.cmd == HistoryItem.CMD_RESET |
Dianne Hackborn | 29cd7f1 | 2015-01-08 10:37:05 -0800 | [diff] [blame] | 5930 | || rec.cmd == HistoryItem.CMD_START |
| 5931 | || rec.cmd == HistoryItem.CMD_SHUTDOWN) { |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 5932 | printed = true; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 5933 | hprinter.printNextItem(pw, rec, baseTime, checkin, |
| 5934 | (flags&DUMP_VERBOSE) != 0); |
| 5935 | rec.cmd = HistoryItem.CMD_UPDATE; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 5936 | } else if (rec.currentTime != 0) { |
| 5937 | printed = true; |
| 5938 | byte cmd = rec.cmd; |
| 5939 | rec.cmd = HistoryItem.CMD_CURRENT_TIME; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 5940 | hprinter.printNextItem(pw, rec, baseTime, checkin, |
| 5941 | (flags&DUMP_VERBOSE) != 0); |
| 5942 | rec.cmd = cmd; |
| 5943 | } |
| 5944 | if (tracker != null) { |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 5945 | if (rec.cmd != HistoryItem.CMD_UPDATE) { |
| 5946 | hprinter.printNextItem(pw, rec, baseTime, checkin, |
| 5947 | (flags&DUMP_VERBOSE) != 0); |
| 5948 | rec.cmd = HistoryItem.CMD_UPDATE; |
| 5949 | } |
| 5950 | int oldEventCode = rec.eventCode; |
| 5951 | HistoryTag oldEventTag = rec.eventTag; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 5952 | rec.eventTag = new HistoryTag(); |
| 5953 | for (int i=0; i<HistoryItem.EVENT_COUNT; i++) { |
| 5954 | HashMap<String, SparseIntArray> active |
| 5955 | = tracker.getStateForEvent(i); |
| 5956 | if (active == null) { |
| 5957 | continue; |
| 5958 | } |
| 5959 | for (HashMap.Entry<String, SparseIntArray> ent |
| 5960 | : active.entrySet()) { |
| 5961 | SparseIntArray uids = ent.getValue(); |
| 5962 | for (int j=0; j<uids.size(); j++) { |
| 5963 | rec.eventCode = i; |
| 5964 | rec.eventTag.string = ent.getKey(); |
| 5965 | rec.eventTag.uid = uids.keyAt(j); |
| 5966 | rec.eventTag.poolIdx = uids.valueAt(j); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 5967 | hprinter.printNextItem(pw, rec, baseTime, checkin, |
| 5968 | (flags&DUMP_VERBOSE) != 0); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 5969 | rec.wakeReasonTag = null; |
| 5970 | rec.wakelockTag = null; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 5971 | } |
| 5972 | } |
| 5973 | } |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 5974 | rec.eventCode = oldEventCode; |
| 5975 | rec.eventTag = oldEventTag; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 5976 | tracker = null; |
| 5977 | } |
| 5978 | } |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 5979 | hprinter.printNextItem(pw, rec, baseTime, checkin, |
| 5980 | (flags&DUMP_VERBOSE) != 0); |
Dianne Hackborn | 536456f | 2014-05-23 16:51:05 -0700 | [diff] [blame] | 5981 | } else if (false && rec.eventCode != HistoryItem.EVENT_NONE) { |
| 5982 | // This is an attempt to aggregate the previous state and generate |
| 5983 | //Â fake events to reflect that state at the point where we start |
| 5984 | // 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] | 5985 | if (tracker == null) { |
| 5986 | tracker = new HistoryEventTracker(); |
| 5987 | } |
| 5988 | tracker.updateState(rec.eventCode, rec.eventTag.string, |
| 5989 | rec.eventTag.uid, rec.eventTag.poolIdx); |
| 5990 | } |
| 5991 | } |
| 5992 | if (histStart >= 0) { |
Dianne Hackborn | fc06413 | 2014-06-02 12:42:12 -0700 | [diff] [blame] | 5993 | commitCurrentHistoryBatchLocked(); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 5994 | pw.print(checkin ? "NEXT: " : " NEXT: "); pw.println(lastTime+1); |
| 5995 | } |
| 5996 | } |
| 5997 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 5998 | private void dumpDailyLevelStepSummary(PrintWriter pw, String prefix, String label, |
| 5999 | LevelStepTracker steps, StringBuilder tmpSb, int[] tmpOutInt) { |
| 6000 | if (steps == null) { |
| 6001 | return; |
| 6002 | } |
| 6003 | long timeRemaining = steps.computeTimeEstimate(0, 0, tmpOutInt); |
| 6004 | if (timeRemaining >= 0) { |
| 6005 | pw.print(prefix); pw.print(label); pw.print(" total time: "); |
| 6006 | tmpSb.setLength(0); |
| 6007 | formatTimeMs(tmpSb, timeRemaining); |
| 6008 | pw.print(tmpSb); |
| 6009 | pw.print(" (from "); pw.print(tmpOutInt[0]); |
| 6010 | pw.println(" steps)"); |
| 6011 | } |
| 6012 | for (int i=0; i< STEP_LEVEL_MODES_OF_INTEREST.length; i++) { |
| 6013 | long estimatedTime = steps.computeTimeEstimate(STEP_LEVEL_MODES_OF_INTEREST[i], |
| 6014 | STEP_LEVEL_MODE_VALUES[i], tmpOutInt); |
| 6015 | if (estimatedTime > 0) { |
| 6016 | pw.print(prefix); pw.print(label); pw.print(" "); |
| 6017 | pw.print(STEP_LEVEL_MODE_LABELS[i]); |
| 6018 | pw.print(" time: "); |
| 6019 | tmpSb.setLength(0); |
| 6020 | formatTimeMs(tmpSb, estimatedTime); |
| 6021 | pw.print(tmpSb); |
| 6022 | pw.print(" (from "); pw.print(tmpOutInt[0]); |
| 6023 | pw.println(" steps)"); |
| 6024 | } |
| 6025 | } |
| 6026 | } |
| 6027 | |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 6028 | private void dumpDailyPackageChanges(PrintWriter pw, String prefix, |
| 6029 | ArrayList<PackageChange> changes) { |
| 6030 | if (changes == null) { |
| 6031 | return; |
| 6032 | } |
| 6033 | pw.print(prefix); pw.println("Package changes:"); |
| 6034 | for (int i=0; i<changes.size(); i++) { |
| 6035 | PackageChange pc = changes.get(i); |
| 6036 | if (pc.mUpdate) { |
| 6037 | pw.print(prefix); pw.print(" Update "); pw.print(pc.mPackageName); |
| 6038 | pw.print(" vers="); pw.println(pc.mVersionCode); |
| 6039 | } else { |
| 6040 | pw.print(prefix); pw.print(" Uninstall "); pw.println(pc.mPackageName); |
| 6041 | } |
| 6042 | } |
| 6043 | } |
| 6044 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6045 | /** |
| 6046 | * Dumps a human-readable summary of the battery statistics to the given PrintWriter. |
| 6047 | * |
| 6048 | * @param pw a Printer to receive the dump output. |
| 6049 | */ |
| 6050 | @SuppressWarnings("unused") |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6051 | 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] | 6052 | prepareForDumpLocked(); |
| 6053 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6054 | final boolean filtering = (flags |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 6055 | & (DUMP_HISTORY_ONLY|DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) != 0; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6056 | |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6057 | if ((flags&DUMP_HISTORY_ONLY) != 0 || !filtering) { |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6058 | final long historyTotalSize = getHistoryTotalSize(); |
| 6059 | final long historyUsedSize = getHistoryUsedSize(); |
| 6060 | if (startIteratingHistoryLocked()) { |
| 6061 | try { |
| 6062 | pw.print("Battery History ("); |
| 6063 | pw.print((100*historyUsedSize)/historyTotalSize); |
| 6064 | pw.print("% used, "); |
| 6065 | printSizeValue(pw, historyUsedSize); |
| 6066 | pw.print(" used of "); |
| 6067 | printSizeValue(pw, historyTotalSize); |
| 6068 | pw.print(", "); |
| 6069 | pw.print(getHistoryStringPoolSize()); |
| 6070 | pw.print(" strings using "); |
| 6071 | printSizeValue(pw, getHistoryStringPoolBytes()); |
| 6072 | pw.println("):"); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 6073 | dumpHistoryLocked(pw, flags, histStart, false); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6074 | pw.println(); |
| 6075 | } finally { |
| 6076 | finishIteratingHistoryLocked(); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 6077 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6078 | } |
| 6079 | |
| 6080 | if (startIteratingOldHistoryLocked()) { |
| 6081 | try { |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 6082 | final HistoryItem rec = new HistoryItem(); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6083 | pw.println("Old battery History:"); |
| 6084 | HistoryPrinter hprinter = new HistoryPrinter(); |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 6085 | long baseTime = -1; |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6086 | while (getNextOldHistoryLocked(rec)) { |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 6087 | if (baseTime < 0) { |
| 6088 | baseTime = rec.time; |
| 6089 | } |
| 6090 | hprinter.printNextItem(pw, rec, baseTime, false, (flags&DUMP_VERBOSE) != 0); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6091 | } |
| 6092 | pw.println(); |
| 6093 | } finally { |
| 6094 | finishIteratingOldHistoryLocked(); |
| 6095 | } |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 6096 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6097 | } |
| 6098 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 6099 | if (filtering && (flags&(DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) == 0) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 6100 | return; |
| 6101 | } |
| 6102 | |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6103 | if (!filtering) { |
| 6104 | SparseArray<? extends Uid> uidStats = getUidStats(); |
| 6105 | final int NU = uidStats.size(); |
| 6106 | boolean didPid = false; |
| 6107 | long nowRealtime = SystemClock.elapsedRealtime(); |
| 6108 | for (int i=0; i<NU; i++) { |
| 6109 | Uid uid = uidStats.valueAt(i); |
| 6110 | SparseArray<? extends Uid.Pid> pids = uid.getPidStats(); |
| 6111 | if (pids != null) { |
| 6112 | for (int j=0; j<pids.size(); j++) { |
| 6113 | Uid.Pid pid = pids.valueAt(j); |
| 6114 | if (!didPid) { |
| 6115 | pw.println("Per-PID Stats:"); |
| 6116 | didPid = true; |
| 6117 | } |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 6118 | long time = pid.mWakeSumMs + (pid.mWakeNesting > 0 |
| 6119 | ? (nowRealtime - pid.mWakeStartMs) : 0); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6120 | pw.print(" PID "); pw.print(pids.keyAt(j)); |
| 6121 | pw.print(" wake time: "); |
| 6122 | TimeUtils.formatDuration(time, pw); |
| 6123 | pw.println(""); |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 6124 | } |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 6125 | } |
| 6126 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6127 | if (didPid) { |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 6128 | pw.println(); |
| 6129 | } |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 6130 | } |
| 6131 | |
| 6132 | if (!filtering || (flags&DUMP_CHARGED_ONLY) != 0) { |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6133 | if (dumpDurationSteps(pw, " ", "Discharge step durations:", |
| 6134 | getDischargeLevelStepTracker(), false)) { |
Kweku Adams | b0449e0 | 2016-10-12 14:18:27 -0700 | [diff] [blame] | 6135 | long timeRemaining = computeBatteryTimeRemaining( |
| 6136 | SystemClock.elapsedRealtime() * 1000); |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 6137 | if (timeRemaining >= 0) { |
| 6138 | pw.print(" Estimated discharge time remaining: "); |
| 6139 | TimeUtils.formatDuration(timeRemaining / 1000, pw); |
| 6140 | pw.println(); |
| 6141 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6142 | final LevelStepTracker steps = getDischargeLevelStepTracker(); |
| 6143 | for (int i=0; i< STEP_LEVEL_MODES_OF_INTEREST.length; i++) { |
| 6144 | dumpTimeEstimate(pw, " Estimated ", STEP_LEVEL_MODE_LABELS[i], " time: ", |
| 6145 | steps.computeTimeEstimate(STEP_LEVEL_MODES_OF_INTEREST[i], |
| 6146 | STEP_LEVEL_MODE_VALUES[i], null)); |
| 6147 | } |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 6148 | pw.println(); |
| 6149 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6150 | if (dumpDurationSteps(pw, " ", "Charge step durations:", |
| 6151 | getChargeLevelStepTracker(), false)) { |
Kweku Adams | b0449e0 | 2016-10-12 14:18:27 -0700 | [diff] [blame] | 6152 | long timeRemaining = computeChargeTimeRemaining( |
| 6153 | SystemClock.elapsedRealtime() * 1000); |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 6154 | if (timeRemaining >= 0) { |
| 6155 | pw.print(" Estimated charge time remaining: "); |
| 6156 | TimeUtils.formatDuration(timeRemaining / 1000, pw); |
| 6157 | pw.println(); |
| 6158 | } |
| 6159 | pw.println(); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6160 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6161 | } |
| 6162 | if (!filtering || (flags&(DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) != 0) { |
| 6163 | pw.println("Daily stats:"); |
| 6164 | pw.print(" Current start time: "); |
| 6165 | pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss", |
| 6166 | getCurrentDailyStartTime()).toString()); |
| 6167 | pw.print(" Next min deadline: "); |
| 6168 | pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss", |
| 6169 | getNextMinDailyDeadline()).toString()); |
| 6170 | pw.print(" Next max deadline: "); |
| 6171 | pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss", |
| 6172 | getNextMaxDailyDeadline()).toString()); |
| 6173 | StringBuilder sb = new StringBuilder(64); |
| 6174 | int[] outInt = new int[1]; |
| 6175 | LevelStepTracker dsteps = getDailyDischargeLevelStepTracker(); |
| 6176 | LevelStepTracker csteps = getDailyChargeLevelStepTracker(); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 6177 | ArrayList<PackageChange> pkgc = getDailyPackageChanges(); |
| 6178 | if (dsteps.mNumStepDurations > 0 || csteps.mNumStepDurations > 0 || pkgc != null) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 6179 | if ((flags&DUMP_DAILY_ONLY) != 0 || !filtering) { |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6180 | if (dumpDurationSteps(pw, " ", " Current daily discharge step durations:", |
| 6181 | dsteps, false)) { |
| 6182 | dumpDailyLevelStepSummary(pw, " ", "Discharge", dsteps, |
| 6183 | sb, outInt); |
| 6184 | } |
| 6185 | if (dumpDurationSteps(pw, " ", " Current daily charge step durations:", |
| 6186 | csteps, false)) { |
| 6187 | dumpDailyLevelStepSummary(pw, " ", "Charge", csteps, |
| 6188 | sb, outInt); |
| 6189 | } |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 6190 | dumpDailyPackageChanges(pw, " ", pkgc); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6191 | } else { |
| 6192 | pw.println(" Current daily steps:"); |
| 6193 | dumpDailyLevelStepSummary(pw, " ", "Discharge", dsteps, |
| 6194 | sb, outInt); |
| 6195 | dumpDailyLevelStepSummary(pw, " ", "Charge", csteps, |
| 6196 | sb, outInt); |
| 6197 | } |
| 6198 | } |
| 6199 | DailyItem dit; |
| 6200 | int curIndex = 0; |
| 6201 | while ((dit=getDailyItemLocked(curIndex)) != null) { |
| 6202 | curIndex++; |
| 6203 | if ((flags&DUMP_DAILY_ONLY) != 0) { |
| 6204 | pw.println(); |
| 6205 | } |
| 6206 | pw.print(" Daily from "); |
| 6207 | pw.print(DateFormat.format("yyyy-MM-dd-HH-mm-ss", dit.mStartTime).toString()); |
| 6208 | pw.print(" to "); |
| 6209 | pw.print(DateFormat.format("yyyy-MM-dd-HH-mm-ss", dit.mEndTime).toString()); |
| 6210 | pw.println(":"); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 6211 | if ((flags&DUMP_DAILY_ONLY) != 0 || !filtering) { |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6212 | if (dumpDurationSteps(pw, " ", |
| 6213 | " Discharge step durations:", dit.mDischargeSteps, false)) { |
| 6214 | dumpDailyLevelStepSummary(pw, " ", "Discharge", dit.mDischargeSteps, |
| 6215 | sb, outInt); |
| 6216 | } |
| 6217 | if (dumpDurationSteps(pw, " ", |
| 6218 | " Charge step durations:", dit.mChargeSteps, false)) { |
| 6219 | dumpDailyLevelStepSummary(pw, " ", "Charge", dit.mChargeSteps, |
| 6220 | sb, outInt); |
| 6221 | } |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 6222 | dumpDailyPackageChanges(pw, " ", dit.mPackageChanges); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6223 | } else { |
| 6224 | dumpDailyLevelStepSummary(pw, " ", "Discharge", dit.mDischargeSteps, |
| 6225 | sb, outInt); |
| 6226 | dumpDailyLevelStepSummary(pw, " ", "Charge", dit.mChargeSteps, |
| 6227 | sb, outInt); |
| 6228 | } |
| 6229 | } |
| 6230 | pw.println(); |
| 6231 | } |
| 6232 | if (!filtering || (flags&DUMP_CHARGED_ONLY) != 0) { |
Jeff Sharkey | ec43a6b | 2013-04-30 13:33:18 -0700 | [diff] [blame] | 6233 | pw.println("Statistics since last charge:"); |
| 6234 | pw.println(" System starts: " + getStartCount() |
| 6235 | + ", currently on battery: " + getIsOnBattery()); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 6236 | dumpLocked(context, pw, "", STATS_SINCE_CHARGED, reqUid, |
| 6237 | (flags&DUMP_DEVICE_WIFI_ONLY) != 0); |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 6238 | pw.println(); |
Jeff Sharkey | ec43a6b | 2013-04-30 13:33:18 -0700 | [diff] [blame] | 6239 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6240 | } |
| 6241 | |
| 6242 | @SuppressWarnings("unused") |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6243 | public void dumpCheckinLocked(Context context, PrintWriter pw, |
| 6244 | List<ApplicationInfo> apps, int flags, long histStart) { |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 6245 | prepareForDumpLocked(); |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 6246 | |
| 6247 | dumpLine(pw, 0 /* uid */, "i" /* category */, VERSION_DATA, |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 6248 | CHECKIN_VERSION, getParcelVersion(), getStartPlatformVersion(), |
| 6249 | getEndPlatformVersion()); |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 6250 | |
Dianne Hackborn | 13ac041 | 2013-06-25 19:34:49 -0700 | [diff] [blame] | 6251 | long now = getHistoryBaseTime() + SystemClock.elapsedRealtime(); |
| 6252 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6253 | final boolean filtering = (flags & |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 6254 | (DUMP_HISTORY_ONLY|DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) != 0; |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6255 | |
| 6256 | if ((flags&DUMP_INCLUDE_HISTORY) != 0 || (flags&DUMP_HISTORY_ONLY) != 0) { |
Dianne Hackborn | 49021f5 | 2013-09-04 18:03:40 -0700 | [diff] [blame] | 6257 | if (startIteratingHistoryLocked()) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 6258 | try { |
| 6259 | for (int i=0; i<getHistoryStringPoolSize(); i++) { |
| 6260 | pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(','); |
| 6261 | pw.print(HISTORY_STRING_POOL); pw.print(','); |
| 6262 | pw.print(i); |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 6263 | pw.print(","); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 6264 | pw.print(getHistoryTagPoolUid(i)); |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 6265 | pw.print(",\""); |
| 6266 | String str = getHistoryTagPoolString(i); |
| 6267 | str = str.replace("\\", "\\\\"); |
| 6268 | str = str.replace("\"", "\\\""); |
| 6269 | pw.print(str); |
| 6270 | pw.print("\""); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 6271 | pw.println(); |
| 6272 | } |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 6273 | dumpHistoryLocked(pw, flags, histStart, true); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 6274 | } finally { |
| 6275 | finishIteratingHistoryLocked(); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 6276 | } |
Dianne Hackborn | 13ac041 | 2013-06-25 19:34:49 -0700 | [diff] [blame] | 6277 | } |
Dianne Hackborn | 13ac041 | 2013-06-25 19:34:49 -0700 | [diff] [blame] | 6278 | } |
| 6279 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 6280 | if (filtering && (flags&(DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) == 0) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 6281 | return; |
| 6282 | } |
| 6283 | |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 6284 | if (apps != null) { |
Dianne Hackborn | 9cfba35 | 2016-03-24 17:31:28 -0700 | [diff] [blame] | 6285 | SparseArray<Pair<ArrayList<String>, MutableBoolean>> uids = new SparseArray<>(); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 6286 | for (int i=0; i<apps.size(); i++) { |
| 6287 | ApplicationInfo ai = apps.get(i); |
Dianne Hackborn | 9cfba35 | 2016-03-24 17:31:28 -0700 | [diff] [blame] | 6288 | Pair<ArrayList<String>, MutableBoolean> pkgs = uids.get( |
| 6289 | UserHandle.getAppId(ai.uid)); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 6290 | if (pkgs == null) { |
Dianne Hackborn | 9cfba35 | 2016-03-24 17:31:28 -0700 | [diff] [blame] | 6291 | pkgs = new Pair<>(new ArrayList<String>(), new MutableBoolean(false)); |
| 6292 | uids.put(UserHandle.getAppId(ai.uid), pkgs); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 6293 | } |
Dianne Hackborn | 9cfba35 | 2016-03-24 17:31:28 -0700 | [diff] [blame] | 6294 | pkgs.first.add(ai.packageName); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 6295 | } |
| 6296 | SparseArray<? extends Uid> uidStats = getUidStats(); |
| 6297 | final int NU = uidStats.size(); |
| 6298 | String[] lineArgs = new String[2]; |
| 6299 | for (int i=0; i<NU; i++) { |
Dianne Hackborn | 9cfba35 | 2016-03-24 17:31:28 -0700 | [diff] [blame] | 6300 | int uid = UserHandle.getAppId(uidStats.keyAt(i)); |
| 6301 | Pair<ArrayList<String>, MutableBoolean> pkgs = uids.get(uid); |
| 6302 | if (pkgs != null && !pkgs.second.value) { |
| 6303 | pkgs.second.value = true; |
| 6304 | for (int j=0; j<pkgs.first.size(); j++) { |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 6305 | lineArgs[0] = Integer.toString(uid); |
Dianne Hackborn | 9cfba35 | 2016-03-24 17:31:28 -0700 | [diff] [blame] | 6306 | lineArgs[1] = pkgs.first.get(j); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 6307 | dumpLine(pw, 0 /* uid */, "i" /* category */, UID_DATA, |
| 6308 | (Object[])lineArgs); |
| 6309 | } |
| 6310 | } |
| 6311 | } |
| 6312 | } |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 6313 | if (!filtering || (flags&DUMP_CHARGED_ONLY) != 0) { |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6314 | dumpDurationSteps(pw, "", DISCHARGE_STEP_DATA, getDischargeLevelStepTracker(), true); |
Dianne Hackborn | d06dcfd | 2014-05-02 13:49:30 -0700 | [diff] [blame] | 6315 | String[] lineArgs = new String[1]; |
Kweku Adams | b0449e0 | 2016-10-12 14:18:27 -0700 | [diff] [blame] | 6316 | long timeRemaining = computeBatteryTimeRemaining(SystemClock.elapsedRealtime() * 1000); |
Dianne Hackborn | d06dcfd | 2014-05-02 13:49:30 -0700 | [diff] [blame] | 6317 | if (timeRemaining >= 0) { |
| 6318 | lineArgs[0] = Long.toString(timeRemaining); |
| 6319 | dumpLine(pw, 0 /* uid */, "i" /* category */, DISCHARGE_TIME_REMAIN_DATA, |
| 6320 | (Object[])lineArgs); |
| 6321 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6322 | dumpDurationSteps(pw, "", CHARGE_STEP_DATA, getChargeLevelStepTracker(), true); |
Kweku Adams | b0449e0 | 2016-10-12 14:18:27 -0700 | [diff] [blame] | 6323 | timeRemaining = computeChargeTimeRemaining(SystemClock.elapsedRealtime() * 1000); |
Dianne Hackborn | d06dcfd | 2014-05-02 13:49:30 -0700 | [diff] [blame] | 6324 | if (timeRemaining >= 0) { |
| 6325 | lineArgs[0] = Long.toString(timeRemaining); |
| 6326 | dumpLine(pw, 0 /* uid */, "i" /* category */, CHARGE_TIME_REMAIN_DATA, |
| 6327 | (Object[])lineArgs); |
| 6328 | } |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 6329 | dumpCheckinLocked(context, pw, STATS_SINCE_CHARGED, -1, |
| 6330 | (flags&DUMP_DEVICE_WIFI_ONLY) != 0); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6331 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6332 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6333 | } |