Kenny Root | 15a4d2f | 2010-03-11 18:20:12 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2008 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17 | package android.os; |
| 18 | |
| 19 | import java.io.PrintWriter; |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 20 | import java.util.ArrayList; |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 21 | import java.util.Collections; |
| 22 | import java.util.Comparator; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 23 | import java.util.Formatter; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 24 | import java.util.HashMap; |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 25 | import java.util.List; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 26 | import java.util.Map; |
| 27 | |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 28 | import android.content.Context; |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 29 | import android.content.pm.ApplicationInfo; |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 30 | import android.telephony.SignalStrength; |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 31 | import android.text.format.DateFormat; |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 32 | import android.util.ArrayMap; |
James Carr | 2dd7e5e | 2016-07-20 18:48:39 -0700 | [diff] [blame] | 33 | import android.util.LongSparseArray; |
Dianne Hackborn | 9cfba35 | 2016-03-24 17:31:28 -0700 | [diff] [blame] | 34 | import android.util.MutableBoolean; |
| 35 | import android.util.Pair; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 36 | import android.util.Printer; |
| 37 | import android.util.SparseArray; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 38 | import android.util.SparseIntArray; |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 39 | import android.util.TimeUtils; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 40 | import android.view.Display; |
Amith Yamasani | ab9ad19 | 2016-12-06 12:46:59 -0800 | [diff] [blame] | 41 | |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 42 | import com.android.internal.os.BatterySipper; |
| 43 | import com.android.internal.os.BatteryStatsHelper; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 44 | |
| 45 | /** |
| 46 | * A class providing access to battery usage statistics, including information on |
| 47 | * wakelocks, processes, packages, and services. All times are represented in microseconds |
| 48 | * except where indicated otherwise. |
| 49 | * @hide |
| 50 | */ |
| 51 | public abstract class BatteryStats implements Parcelable { |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 52 | private static final String TAG = "BatteryStats"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 53 | |
| 54 | private static final boolean LOCAL_LOGV = false; |
Dianne Hackborn | 91268cf | 2013-06-13 19:06:50 -0700 | [diff] [blame] | 55 | |
| 56 | /** @hide */ |
| 57 | public static final String SERVICE_NAME = "batterystats"; |
| 58 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 59 | /** |
| 60 | * A constant indicating a partial wake lock timer. |
| 61 | */ |
| 62 | public static final int WAKE_TYPE_PARTIAL = 0; |
| 63 | |
| 64 | /** |
| 65 | * A constant indicating a full wake lock timer. |
| 66 | */ |
| 67 | public static final int WAKE_TYPE_FULL = 1; |
| 68 | |
| 69 | /** |
| 70 | * A constant indicating a window wake lock timer. |
| 71 | */ |
| 72 | public static final int WAKE_TYPE_WINDOW = 2; |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 73 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 74 | /** |
| 75 | * A constant indicating a sensor timer. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 76 | */ |
| 77 | public static final int SENSOR = 3; |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 78 | |
| 79 | /** |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 80 | * A constant indicating a a wifi running timer |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 81 | */ |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 82 | public static final int WIFI_RUNNING = 4; |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 83 | |
| 84 | /** |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 85 | * A constant indicating a full wifi lock timer |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 86 | */ |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 87 | public static final int FULL_WIFI_LOCK = 5; |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 88 | |
| 89 | /** |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 90 | * A constant indicating a wifi scan |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 91 | */ |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 92 | public static final int WIFI_SCAN = 6; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 93 | |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 94 | /** |
| 95 | * A constant indicating a wifi multicast timer |
| 96 | */ |
| 97 | public static final int WIFI_MULTICAST_ENABLED = 7; |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 98 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 99 | /** |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 100 | * A constant indicating a video turn on timer |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 101 | */ |
| 102 | public static final int VIDEO_TURNED_ON = 8; |
| 103 | |
| 104 | /** |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 105 | * A constant indicating a vibrator on timer |
| 106 | */ |
| 107 | public static final int VIBRATOR_ON = 9; |
| 108 | |
| 109 | /** |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 110 | * A constant indicating a foreground activity timer |
| 111 | */ |
| 112 | public static final int FOREGROUND_ACTIVITY = 10; |
| 113 | |
| 114 | /** |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 115 | * A constant indicating a wifi batched scan is active |
| 116 | */ |
| 117 | public static final int WIFI_BATCHED_SCAN = 11; |
| 118 | |
| 119 | /** |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 120 | * A constant indicating a process state timer |
| 121 | */ |
| 122 | public static final int PROCESS_STATE = 12; |
| 123 | |
| 124 | /** |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 125 | * A constant indicating a sync timer |
| 126 | */ |
| 127 | public static final int SYNC = 13; |
| 128 | |
| 129 | /** |
| 130 | * A constant indicating a job timer |
| 131 | */ |
| 132 | public static final int JOB = 14; |
| 133 | |
| 134 | /** |
Kweku Adams | d537987 | 2014-11-24 17:34:05 -0800 | [diff] [blame] | 135 | * A constant indicating an audio turn on timer |
| 136 | */ |
| 137 | public static final int AUDIO_TURNED_ON = 15; |
| 138 | |
| 139 | /** |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 140 | * A constant indicating a flashlight turn on timer |
| 141 | */ |
| 142 | public static final int FLASHLIGHT_TURNED_ON = 16; |
| 143 | |
| 144 | /** |
| 145 | * A constant indicating a camera turn on timer |
| 146 | */ |
| 147 | public static final int CAMERA_TURNED_ON = 17; |
| 148 | |
| 149 | /** |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 150 | * A constant indicating a draw wake lock timer. |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 151 | */ |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 152 | public static final int WAKE_TYPE_DRAW = 18; |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 153 | |
| 154 | /** |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 155 | * A constant indicating a bluetooth scan timer. |
| 156 | */ |
| 157 | public static final int BLUETOOTH_SCAN_ON = 19; |
| 158 | |
| 159 | /** |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 160 | * A constant indicating an aggregated partial wake lock timer. |
| 161 | */ |
| 162 | public static final int AGGREGATED_WAKE_TYPE_PARTIAL = 20; |
| 163 | |
| 164 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 165 | * Include all of the data in the stats, including previously saved data. |
| 166 | */ |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 167 | public static final int STATS_SINCE_CHARGED = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 168 | |
| 169 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 170 | * Include only the current run in the stats. |
| 171 | */ |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 172 | public static final int STATS_CURRENT = 1; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 173 | |
| 174 | /** |
| 175 | * Include only the run since the last time the device was unplugged in the stats. |
| 176 | */ |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 177 | public static final int STATS_SINCE_UNPLUGGED = 2; |
Evan Millar | e84de8d | 2009-04-02 22:16:12 -0700 | [diff] [blame] | 178 | |
| 179 | // NOTE: Update this list if you add/change any stats above. |
| 180 | // These characters are supposed to represent "total", "last", "current", |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 181 | // and "unplugged". They were shortened for efficiency sake. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 182 | private static final String[] STAT_NAMES = { "l", "c", "u" }; |
| 183 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 184 | /** |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 185 | * Current version of checkin data format. |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 186 | * |
| 187 | * New in version 19: |
| 188 | * - Wakelock data (wl) gets current and max times. |
Amith Yamasani | ab9ad19 | 2016-12-06 12:46:59 -0800 | [diff] [blame] | 189 | * New in version 20: |
Bookatz | 2bffb5b | 2017-04-13 11:59:33 -0700 | [diff] [blame] | 190 | * - Background timers and counters for: Sensor, BluetoothScan, WifiScan, Jobs, Syncs. |
Bookatz | 506a818 | 2017-05-01 14:18:42 -0700 | [diff] [blame] | 191 | * New in version 21: |
| 192 | * - Actual (not just apportioned) Wakelock time is also recorded. |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 193 | * - Aggregated partial wakelock time (per uid, instead of per wakelock) is recorded. |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 194 | */ |
Bookatz | 506a818 | 2017-05-01 14:18:42 -0700 | [diff] [blame] | 195 | static final String CHECKIN_VERSION = "21"; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 196 | |
| 197 | /** |
| 198 | * Old version, we hit 9 and ran out of room, need to remove. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 199 | */ |
Ashish Sharma | 213bb2f | 2014-07-07 17:14:52 -0700 | [diff] [blame] | 200 | private static final int BATTERY_STATS_CHECKIN_VERSION = 9; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 201 | |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 202 | private static final long BYTES_PER_KB = 1024; |
| 203 | private static final long BYTES_PER_MB = 1048576; // 1024^2 |
| 204 | private static final long BYTES_PER_GB = 1073741824; //1024^3 |
Bookatz | 506a818 | 2017-05-01 14:18:42 -0700 | [diff] [blame] | 205 | |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 206 | private static final String VERSION_DATA = "vers"; |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 207 | private static final String UID_DATA = "uid"; |
Joe Onorato | 1476d32 | 2016-05-05 14:46:15 -0700 | [diff] [blame] | 208 | private static final String WAKEUP_ALARM_DATA = "wua"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 209 | private static final String APK_DATA = "apk"; |
Evan Millar | e84de8d | 2009-04-02 22:16:12 -0700 | [diff] [blame] | 210 | private static final String PROCESS_DATA = "pr"; |
Adam Lesinski | a7a4ccc | 2015-06-26 17:43:04 -0700 | [diff] [blame] | 211 | private static final String CPU_DATA = "cpu"; |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 212 | private static final String GLOBAL_CPU_FREQ_DATA = "gcf"; |
| 213 | private static final String CPU_TIMES_AT_FREQ_DATA = "ctf"; |
Evan Millar | e84de8d | 2009-04-02 22:16:12 -0700 | [diff] [blame] | 214 | private static final String SENSOR_DATA = "sr"; |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 215 | private static final String VIBRATOR_DATA = "vib"; |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 216 | private static final String FOREGROUND_DATA = "fg"; |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 217 | private static final String STATE_TIME_DATA = "st"; |
Bookatz | 506a818 | 2017-05-01 14:18:42 -0700 | [diff] [blame] | 218 | // wl line is: |
| 219 | // BATTERY_STATS_CHECKIN_VERSION, uid, which, "wl", name, |
Bookatz | 5b5ec32 | 2017-05-26 09:40:38 -0700 | [diff] [blame^] | 220 | // full totalTime, 'f', count, current duration, max duration, total duration, |
| 221 | // partial totalTime, 'p', count, current duration, max duration, total duration, |
| 222 | // bg partial totalTime, 'bp', count, current duration, max duration, total duration, |
| 223 | // window totalTime, 'w', count, current duration, max duration, total duration |
Bookatz | 506a818 | 2017-05-01 14:18:42 -0700 | [diff] [blame] | 224 | // [Currently, full and window wakelocks have durations current = max = total = -1] |
Evan Millar | e84de8d | 2009-04-02 22:16:12 -0700 | [diff] [blame] | 225 | private static final String WAKELOCK_DATA = "wl"; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 226 | // awl line is: |
| 227 | // BATTERY_STATS_CHECKIN_VERSION, uid, which, "awl", |
| 228 | // cumulative partial wakelock duration, cumulative background partial wakelock duration |
| 229 | private static final String AGGREGATED_WAKELOCK_DATA = "awl"; |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 230 | private static final String SYNC_DATA = "sy"; |
| 231 | private static final String JOB_DATA = "jb"; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 232 | private static final String KERNEL_WAKELOCK_DATA = "kwl"; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 233 | private static final String WAKEUP_REASON_DATA = "wr"; |
Evan Millar | e84de8d | 2009-04-02 22:16:12 -0700 | [diff] [blame] | 234 | private static final String NETWORK_DATA = "nt"; |
| 235 | private static final String USER_ACTIVITY_DATA = "ua"; |
| 236 | private static final String BATTERY_DATA = "bt"; |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 237 | private static final String BATTERY_DISCHARGE_DATA = "dc"; |
Evan Millar | e84de8d | 2009-04-02 22:16:12 -0700 | [diff] [blame] | 238 | private static final String BATTERY_LEVEL_DATA = "lv"; |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 239 | private static final String GLOBAL_WIFI_DATA = "gwfl"; |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 240 | private static final String WIFI_DATA = "wfl"; |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 241 | private static final String GLOBAL_WIFI_CONTROLLER_DATA = "gwfcd"; |
| 242 | private static final String WIFI_CONTROLLER_DATA = "wfcd"; |
| 243 | private static final String GLOBAL_BLUETOOTH_CONTROLLER_DATA = "gble"; |
| 244 | private static final String BLUETOOTH_CONTROLLER_DATA = "ble"; |
Adam Lesinski | d9b99be | 2016-03-30 16:58:51 -0700 | [diff] [blame] | 245 | private static final String BLUETOOTH_MISC_DATA = "blem"; |
Evan Millar | e84de8d | 2009-04-02 22:16:12 -0700 | [diff] [blame] | 246 | private static final String MISC_DATA = "m"; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 247 | private static final String GLOBAL_NETWORK_DATA = "gn"; |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 248 | private static final String GLOBAL_MODEM_CONTROLLER_DATA = "gmcd"; |
| 249 | private static final String MODEM_CONTROLLER_DATA = "mcd"; |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 250 | private static final String HISTORY_STRING_POOL = "hsp"; |
Dianne Hackborn | 8a0de58 | 2013-08-07 15:22:07 -0700 | [diff] [blame] | 251 | private static final String HISTORY_DATA = "h"; |
Evan Millar | e84de8d | 2009-04-02 22:16:12 -0700 | [diff] [blame] | 252 | private static final String SCREEN_BRIGHTNESS_DATA = "br"; |
| 253 | private static final String SIGNAL_STRENGTH_TIME_DATA = "sgt"; |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 254 | private static final String SIGNAL_SCANNING_TIME_DATA = "sst"; |
Evan Millar | e84de8d | 2009-04-02 22:16:12 -0700 | [diff] [blame] | 255 | private static final String SIGNAL_STRENGTH_COUNT_DATA = "sgc"; |
| 256 | private static final String DATA_CONNECTION_TIME_DATA = "dct"; |
| 257 | private static final String DATA_CONNECTION_COUNT_DATA = "dcc"; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 258 | private static final String WIFI_STATE_TIME_DATA = "wst"; |
| 259 | private static final String WIFI_STATE_COUNT_DATA = "wsc"; |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 260 | private static final String WIFI_SUPPL_STATE_TIME_DATA = "wsst"; |
| 261 | private static final String WIFI_SUPPL_STATE_COUNT_DATA = "wssc"; |
| 262 | private static final String WIFI_SIGNAL_STRENGTH_TIME_DATA = "wsgt"; |
| 263 | private static final String WIFI_SIGNAL_STRENGTH_COUNT_DATA = "wsgc"; |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 264 | private static final String POWER_USE_SUMMARY_DATA = "pws"; |
| 265 | private static final String POWER_USE_ITEM_DATA = "pwi"; |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 266 | private static final String DISCHARGE_STEP_DATA = "dsd"; |
| 267 | private static final String CHARGE_STEP_DATA = "csd"; |
Dianne Hackborn | d06dcfd | 2014-05-02 13:49:30 -0700 | [diff] [blame] | 268 | private static final String DISCHARGE_TIME_REMAIN_DATA = "dtr"; |
| 269 | private static final String CHARGE_TIME_REMAIN_DATA = "ctr"; |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 270 | private static final String FLASHLIGHT_DATA = "fla"; |
| 271 | private static final String CAMERA_DATA = "cam"; |
| 272 | private static final String VIDEO_DATA = "vid"; |
| 273 | private static final String AUDIO_DATA = "aud"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 274 | |
Adam Lesinski | 010bf37 | 2016-04-11 12:18:18 -0700 | [diff] [blame] | 275 | public static final String RESULT_RECEIVER_CONTROLLER_KEY = "controller_activity"; |
| 276 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 277 | private final StringBuilder mFormatBuilder = new StringBuilder(32); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 278 | private final Formatter mFormatter = new Formatter(mFormatBuilder); |
| 279 | |
| 280 | /** |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 281 | * Indicates times spent by the uid at each cpu frequency in all process states. |
| 282 | * |
| 283 | * Other types might include times spent in foreground, background etc. |
| 284 | */ |
| 285 | private final String UID_TIMES_TYPE_ALL = "A"; |
| 286 | |
| 287 | /** |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 288 | * State for keeping track of counting information. |
| 289 | */ |
| 290 | public static abstract class Counter { |
| 291 | |
| 292 | /** |
| 293 | * Returns the count associated with this Counter for the |
| 294 | * selected type of statistics. |
| 295 | * |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 296 | * @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] | 297 | */ |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 298 | public abstract int getCountLocked(int which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 299 | |
| 300 | /** |
| 301 | * Temporary for debugging. |
| 302 | */ |
| 303 | public abstract void logState(Printer pw, String prefix); |
| 304 | } |
| 305 | |
| 306 | /** |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 307 | * State for keeping track of long counting information. |
| 308 | */ |
| 309 | public static abstract class LongCounter { |
| 310 | |
| 311 | /** |
| 312 | * Returns the count associated with this Counter for the |
| 313 | * selected type of statistics. |
| 314 | * |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 315 | * @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] | 316 | */ |
| 317 | public abstract long getCountLocked(int which); |
| 318 | |
| 319 | /** |
| 320 | * Temporary for debugging. |
| 321 | */ |
| 322 | public abstract void logState(Printer pw, String prefix); |
| 323 | } |
| 324 | |
| 325 | /** |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 326 | * State for keeping track of array of long counting information. |
| 327 | */ |
| 328 | public static abstract class LongCounterArray { |
| 329 | /** |
| 330 | * Returns the counts associated with this Counter for the |
| 331 | * selected type of statistics. |
| 332 | * |
| 333 | * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT |
| 334 | */ |
| 335 | public abstract long[] getCountsLocked(int which); |
| 336 | |
| 337 | /** |
| 338 | * Temporary for debugging. |
| 339 | */ |
| 340 | public abstract void logState(Printer pw, String prefix); |
| 341 | } |
| 342 | |
| 343 | /** |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 344 | * Container class that aggregates counters for transmit, receive, and idle state of a |
| 345 | * radio controller. |
| 346 | */ |
| 347 | public static abstract class ControllerActivityCounter { |
| 348 | /** |
| 349 | * @return a non-null {@link LongCounter} representing time spent (milliseconds) in the |
| 350 | * idle state. |
| 351 | */ |
| 352 | public abstract LongCounter getIdleTimeCounter(); |
| 353 | |
| 354 | /** |
| 355 | * @return a non-null {@link LongCounter} representing time spent (milliseconds) in the |
| 356 | * receive state. |
| 357 | */ |
| 358 | public abstract LongCounter getRxTimeCounter(); |
| 359 | |
| 360 | /** |
| 361 | * An array of {@link LongCounter}, representing various transmit levels, where each level |
| 362 | * may draw a different amount of power. The levels themselves are controller-specific. |
| 363 | * @return non-null array of {@link LongCounter}s representing time spent (milliseconds) in |
| 364 | * various transmit level states. |
| 365 | */ |
| 366 | public abstract LongCounter[] getTxTimeCounters(); |
| 367 | |
| 368 | /** |
| 369 | * @return a non-null {@link LongCounter} representing the power consumed by the controller |
| 370 | * in all states, measured in milli-ampere-milliseconds (mAms). The counter may always |
| 371 | * yield a value of 0 if the device doesn't support power calculations. |
| 372 | */ |
| 373 | public abstract LongCounter getPowerCounter(); |
| 374 | } |
| 375 | |
| 376 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 377 | * State for keeping track of timing information. |
| 378 | */ |
| 379 | public static abstract class Timer { |
| 380 | |
| 381 | /** |
| 382 | * Returns the count associated with this Timer for the |
| 383 | * selected type of statistics. |
| 384 | * |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 385 | * @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] | 386 | */ |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 387 | public abstract int getCountLocked(int which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 388 | |
| 389 | /** |
| 390 | * Returns the total time in microseconds associated with this Timer for the |
| 391 | * selected type of statistics. |
| 392 | * |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 393 | * @param elapsedRealtimeUs current elapsed realtime of system in microseconds |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 394 | * @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] | 395 | * @return a time in microseconds |
| 396 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 397 | public abstract long getTotalTimeLocked(long elapsedRealtimeUs, int which); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 398 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 399 | /** |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 400 | * Returns the total time in microseconds associated with this Timer since the |
| 401 | * 'mark' was last set. |
| 402 | * |
| 403 | * @param elapsedRealtimeUs current elapsed realtime of system in microseconds |
| 404 | * @return a time in microseconds |
| 405 | */ |
| 406 | public abstract long getTimeSinceMarkLocked(long elapsedRealtimeUs); |
| 407 | |
| 408 | /** |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 409 | * Returns the max duration if it is being tracked. |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 410 | * Not all Timer subclasses track the max, total, current durations. |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 411 | |
| 412 | */ |
| 413 | public long getMaxDurationMsLocked(long elapsedRealtimeMs) { |
| 414 | return -1; |
| 415 | } |
| 416 | |
| 417 | /** |
| 418 | * 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] | 419 | * Not all Timer subclasses track the max, total, current durations. |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 420 | */ |
| 421 | public long getCurrentDurationMsLocked(long elapsedRealtimeMs) { |
| 422 | return -1; |
| 423 | } |
| 424 | |
| 425 | /** |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 426 | * Returns the current time the timer has been active, if it is being tracked. |
| 427 | * |
| 428 | * Returns the total cumulative duration (i.e. sum of past durations) that this timer has |
| 429 | * been on since reset. |
| 430 | * This may differ from getTotalTimeLocked(elapsedRealtimeUs, STATS_SINCE_CHARGED)/1000 since, |
| 431 | * depending on the Timer, getTotalTimeLocked may represent the total 'blamed' or 'pooled' |
| 432 | * time, rather than the actual time. By contrast, getTotalDurationMsLocked always gives |
| 433 | * the actual total time. |
| 434 | * Not all Timer subclasses track the max, total, current durations. |
| 435 | */ |
| 436 | public long getTotalDurationMsLocked(long elapsedRealtimeMs) { |
| 437 | return -1; |
| 438 | } |
| 439 | |
| 440 | /** |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 441 | * Returns the secondary Timer held by the Timer, if one exists. This secondary timer may be |
| 442 | * used, for example, for tracking background usage. Secondary timers are never pooled. |
| 443 | * |
| 444 | * Not all Timer subclasses have a secondary timer; those that don't return null. |
| 445 | */ |
| 446 | public Timer getSubTimer() { |
| 447 | return null; |
| 448 | } |
| 449 | |
| 450 | /** |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 451 | * Returns whether the timer is currently running. Some types of timers |
| 452 | * (e.g. BatchTimers) don't know whether the event is currently active, |
| 453 | * and report false. |
| 454 | */ |
| 455 | public boolean isRunningLocked() { |
| 456 | return false; |
| 457 | } |
| 458 | |
| 459 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 460 | * Temporary for debugging. |
| 461 | */ |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 462 | public abstract void logState(Printer pw, String prefix); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 463 | } |
| 464 | |
| 465 | /** |
| 466 | * The statistics associated with a particular uid. |
| 467 | */ |
| 468 | public static abstract class Uid { |
| 469 | |
| 470 | /** |
| 471 | * Returns a mapping containing wakelock statistics. |
| 472 | * |
| 473 | * @return a Map from Strings to Uid.Wakelock objects. |
| 474 | */ |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 475 | public abstract ArrayMap<String, ? extends Wakelock> getWakelockStats(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 476 | |
| 477 | /** |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 478 | * Returns a mapping containing sync statistics. |
| 479 | * |
| 480 | * @return a Map from Strings to Timer objects. |
| 481 | */ |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 482 | public abstract ArrayMap<String, ? extends Timer> getSyncStats(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 483 | |
| 484 | /** |
| 485 | * Returns a mapping containing scheduled job statistics. |
| 486 | * |
| 487 | * @return a Map from Strings to Timer objects. |
| 488 | */ |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 489 | public abstract ArrayMap<String, ? extends Timer> getJobStats(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 490 | |
| 491 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 492 | * The statistics associated with a particular wake lock. |
| 493 | */ |
| 494 | public static abstract class Wakelock { |
| 495 | public abstract Timer getWakeTime(int type); |
| 496 | } |
| 497 | |
| 498 | /** |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 499 | * The cumulative time the uid spent holding any partial wakelocks. This will generally |
| 500 | * differ from summing over the Wakelocks in getWakelockStats since the latter may have |
| 501 | * wakelocks that overlap in time (and therefore over-counts). |
| 502 | */ |
| 503 | public abstract Timer getAggregatedPartialWakelockTimer(); |
| 504 | |
| 505 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 506 | * Returns a mapping containing sensor statistics. |
| 507 | * |
| 508 | * @return a Map from Integer sensor ids to Uid.Sensor objects. |
| 509 | */ |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 510 | public abstract SparseArray<? extends Sensor> getSensorStats(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 511 | |
| 512 | /** |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 513 | * Returns a mapping containing active process data. |
| 514 | */ |
| 515 | public abstract SparseArray<? extends Pid> getPidStats(); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 516 | |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 517 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 518 | * Returns a mapping containing process statistics. |
| 519 | * |
| 520 | * @return a Map from Strings to Uid.Proc objects. |
| 521 | */ |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 522 | public abstract ArrayMap<String, ? extends Proc> getProcessStats(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 523 | |
| 524 | /** |
| 525 | * Returns a mapping containing package statistics. |
| 526 | * |
| 527 | * @return a Map from Strings to Uid.Pkg objects. |
| 528 | */ |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 529 | public abstract ArrayMap<String, ? extends Pkg> getPackageStats(); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 530 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 531 | public abstract ControllerActivityCounter getWifiControllerActivity(); |
| 532 | public abstract ControllerActivityCounter getBluetoothControllerActivity(); |
| 533 | public abstract ControllerActivityCounter getModemControllerActivity(); |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 534 | |
| 535 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 536 | * {@hide} |
| 537 | */ |
| 538 | public abstract int getUid(); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 539 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 540 | public abstract void noteWifiRunningLocked(long elapsedRealtime); |
| 541 | public abstract void noteWifiStoppedLocked(long elapsedRealtime); |
| 542 | public abstract void noteFullWifiLockAcquiredLocked(long elapsedRealtime); |
| 543 | public abstract void noteFullWifiLockReleasedLocked(long elapsedRealtime); |
| 544 | public abstract void noteWifiScanStartedLocked(long elapsedRealtime); |
| 545 | public abstract void noteWifiScanStoppedLocked(long elapsedRealtime); |
| 546 | public abstract void noteWifiBatchedScanStartedLocked(int csph, long elapsedRealtime); |
| 547 | public abstract void noteWifiBatchedScanStoppedLocked(long elapsedRealtime); |
| 548 | public abstract void noteWifiMulticastEnabledLocked(long elapsedRealtime); |
| 549 | public abstract void noteWifiMulticastDisabledLocked(long elapsedRealtime); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 550 | public abstract void noteActivityResumedLocked(long elapsedRealtime); |
| 551 | public abstract void noteActivityPausedLocked(long elapsedRealtime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 552 | public abstract long getWifiRunningTime(long elapsedRealtimeUs, int which); |
| 553 | public abstract long getFullWifiLockTime(long elapsedRealtimeUs, int which); |
| 554 | public abstract long getWifiScanTime(long elapsedRealtimeUs, int which); |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 555 | public abstract int getWifiScanCount(int which); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 556 | public abstract int getWifiScanBackgroundCount(int which); |
| 557 | public abstract long getWifiScanActualTime(long elapsedRealtimeUs); |
| 558 | public abstract long getWifiScanBackgroundTime(long elapsedRealtimeUs); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 559 | public abstract long getWifiBatchedScanTime(int csphBin, long elapsedRealtimeUs, int which); |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 560 | public abstract int getWifiBatchedScanCount(int csphBin, int which); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 561 | public abstract long getWifiMulticastTime(long elapsedRealtimeUs, int which); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 562 | public abstract Timer getAudioTurnedOnTimer(); |
| 563 | public abstract Timer getVideoTurnedOnTimer(); |
| 564 | public abstract Timer getFlashlightTurnedOnTimer(); |
| 565 | public abstract Timer getCameraTurnedOnTimer(); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 566 | public abstract Timer getForegroundActivityTimer(); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 567 | public abstract Timer getBluetoothScanTimer(); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 568 | public abstract Timer getBluetoothScanBackgroundTimer(); |
Bookatz | 956f36bf | 2017-04-28 09:48:17 -0700 | [diff] [blame] | 569 | public abstract Counter getBluetoothScanResultCounter(); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 570 | |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 571 | public abstract long[] getCpuFreqTimes(int which); |
| 572 | public abstract long[] getScreenOffCpuFreqTimes(int which); |
| 573 | |
Dianne Hackborn | a0200e3 | 2016-03-30 18:01:41 -0700 | [diff] [blame] | 574 | // Note: the following times are disjoint. They can be added together to find the |
| 575 | // total time a uid has had any processes running at all. |
| 576 | |
| 577 | /** |
| 578 | * Time this uid has any processes in the top state (or above such as persistent). |
| 579 | */ |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 580 | public static final int PROCESS_STATE_TOP = 0; |
Dianne Hackborn | a0200e3 | 2016-03-30 18:01:41 -0700 | [diff] [blame] | 581 | /** |
| 582 | * Time this uid has any process with a started out bound foreground service, but |
| 583 | * none in the "top" state. |
| 584 | */ |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 585 | public static final int PROCESS_STATE_FOREGROUND_SERVICE = 1; |
Dianne Hackborn | a0200e3 | 2016-03-30 18:01:41 -0700 | [diff] [blame] | 586 | /** |
| 587 | * Time this uid has any process that is top while the device is sleeping, but none |
| 588 | * in the "foreground service" or better state. |
| 589 | */ |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 590 | public static final int PROCESS_STATE_TOP_SLEEPING = 2; |
Dianne Hackborn | a0200e3 | 2016-03-30 18:01:41 -0700 | [diff] [blame] | 591 | /** |
| 592 | * Time this uid has any process in an active foreground state, but none in the |
| 593 | * "top sleeping" or better state. |
| 594 | */ |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 595 | public static final int PROCESS_STATE_FOREGROUND = 3; |
Dianne Hackborn | a0200e3 | 2016-03-30 18:01:41 -0700 | [diff] [blame] | 596 | /** |
| 597 | * Time this uid has any process in an active background state, but none in the |
| 598 | * "foreground" or better state. |
| 599 | */ |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 600 | public static final int PROCESS_STATE_BACKGROUND = 4; |
Dianne Hackborn | a0200e3 | 2016-03-30 18:01:41 -0700 | [diff] [blame] | 601 | /** |
| 602 | * Time this uid has any processes that are sitting around cached, not in one of the |
| 603 | * other active states. |
| 604 | */ |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 605 | public static final int PROCESS_STATE_CACHED = 5; |
Dianne Hackborn | a0200e3 | 2016-03-30 18:01:41 -0700 | [diff] [blame] | 606 | /** |
| 607 | * Total number of process states we track. |
| 608 | */ |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 609 | public static final int NUM_PROCESS_STATE = 6; |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 610 | |
| 611 | static final String[] PROCESS_STATE_NAMES = { |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 612 | "Top", "Fg Service", "Top Sleeping", "Foreground", "Background", "Cached" |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 613 | }; |
| 614 | |
| 615 | public abstract long getProcessStateTime(int state, long elapsedRealtimeUs, int which); |
Joe Onorato | 713fec8 | 2016-03-04 10:34:02 -0800 | [diff] [blame] | 616 | public abstract Timer getProcessStateTimer(int state); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 617 | |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 618 | public abstract Timer getVibratorOnTimer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 619 | |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 620 | public static final int NUM_WIFI_BATCHED_SCAN_BINS = 5; |
| 621 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 622 | /** |
Jeff Brown | df693de | 2012-07-27 12:03:38 -0700 | [diff] [blame] | 623 | * Note that these must match the constants in android.os.PowerManager. |
| 624 | * Also, if the user activity types change, the BatteryStatsImpl.VERSION must |
| 625 | * also be bumped. |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 626 | */ |
| 627 | static final String[] USER_ACTIVITY_TYPES = { |
Phil Weaver | da80d67 | 2016-03-15 16:25:46 -0700 | [diff] [blame] | 628 | "other", "button", "touch", "accessibility" |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 629 | }; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 630 | |
Phil Weaver | da80d67 | 2016-03-15 16:25:46 -0700 | [diff] [blame] | 631 | public static final int NUM_USER_ACTIVITY_TYPES = 4; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 632 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 633 | public abstract void noteUserActivityLocked(int type); |
| 634 | public abstract boolean hasUserActivity(); |
| 635 | public abstract int getUserActivityCount(int type, int which); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 636 | |
| 637 | public abstract boolean hasNetworkActivity(); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 638 | public abstract long getNetworkActivityBytes(int type, int which); |
| 639 | public abstract long getNetworkActivityPackets(int type, int which); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 640 | public abstract long getMobileRadioActiveTime(int which); |
| 641 | public abstract int getMobileRadioActiveCount(int which); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 642 | |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 643 | /** |
| 644 | * Get the total cpu time (in microseconds) this UID had processes executing in userspace. |
| 645 | */ |
| 646 | public abstract long getUserCpuTimeUs(int which); |
| 647 | |
| 648 | /** |
| 649 | * Get the total cpu time (in microseconds) this UID had processes executing kernel syscalls. |
| 650 | */ |
| 651 | public abstract long getSystemCpuTimeUs(int which); |
| 652 | |
| 653 | /** |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 654 | * Returns the approximate cpu time (in milliseconds) spent at a certain CPU speed for a |
| 655 | * given CPU cluster. |
| 656 | * @param cluster the index of the CPU cluster. |
Adam Lesinski | a7a4ccc | 2015-06-26 17:43:04 -0700 | [diff] [blame] | 657 | * @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] | 658 | * @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] | 659 | * @see com.android.internal.os.PowerProfile#getNumCpuClusters() |
| 660 | * @see com.android.internal.os.PowerProfile#getNumSpeedStepsInCpuCluster(int) |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 661 | */ |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 662 | public abstract long getTimeAtCpuSpeed(int cluster, int step, int which); |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 663 | |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 664 | /** |
| 665 | * Returns the number of times this UID woke up the Application Processor to |
| 666 | * process a mobile radio packet. |
| 667 | * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT. |
| 668 | */ |
| 669 | public abstract long getMobileRadioApWakeupCount(int which); |
| 670 | |
| 671 | /** |
| 672 | * Returns the number of times this UID woke up the Application Processor to |
| 673 | * process a WiFi packet. |
| 674 | * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT. |
| 675 | */ |
| 676 | public abstract long getWifiRadioApWakeupCount(int which); |
| 677 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 678 | public static abstract class Sensor { |
Mathias Agopian | 7f84c06 | 2013-02-04 19:22:47 -0800 | [diff] [blame] | 679 | /* |
| 680 | * FIXME: it's not correct to use this magic value because it |
| 681 | * could clash with a sensor handle (which are defined by |
| 682 | * the sensor HAL, and therefore out of our control |
| 683 | */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 684 | // Magic sensor number for the GPS. |
| 685 | public static final int GPS = -10000; |
Amith Yamasani | ab9ad19 | 2016-12-06 12:46:59 -0800 | [diff] [blame] | 686 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 687 | public abstract int getHandle(); |
Amith Yamasani | ab9ad19 | 2016-12-06 12:46:59 -0800 | [diff] [blame] | 688 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 689 | public abstract Timer getSensorTime(); |
Amith Yamasani | ab9ad19 | 2016-12-06 12:46:59 -0800 | [diff] [blame] | 690 | |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 691 | /** Returns a Timer for sensor usage when app is in the background. */ |
| 692 | public abstract Timer getSensorBackgroundTime(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 693 | } |
| 694 | |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 695 | public class Pid { |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 696 | public int mWakeNesting; |
| 697 | public long mWakeSumMs; |
| 698 | public long mWakeStartMs; |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 699 | } |
| 700 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 701 | /** |
| 702 | * The statistics associated with a particular process. |
| 703 | */ |
| 704 | public static abstract class Proc { |
| 705 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 706 | public static class ExcessivePower { |
| 707 | public static final int TYPE_WAKE = 1; |
| 708 | public static final int TYPE_CPU = 2; |
| 709 | |
| 710 | public int type; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 711 | public long overTime; |
| 712 | public long usedTime; |
| 713 | } |
| 714 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 715 | /** |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 716 | * Returns true if this process is still active in the battery stats. |
| 717 | */ |
| 718 | public abstract boolean isActive(); |
| 719 | |
| 720 | /** |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 721 | * 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] | 722 | * |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 723 | * @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] | 724 | */ |
| 725 | public abstract long getUserTime(int which); |
| 726 | |
| 727 | /** |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 728 | * 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] | 729 | * |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 730 | * @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] | 731 | */ |
| 732 | public abstract long getSystemTime(int which); |
| 733 | |
| 734 | /** |
| 735 | * Returns the number of times the process has been started. |
| 736 | * |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 737 | * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 738 | */ |
| 739 | public abstract int getStarts(int which); |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 740 | |
| 741 | /** |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 742 | * Returns the number of times the process has crashed. |
| 743 | * |
| 744 | * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT. |
| 745 | */ |
| 746 | public abstract int getNumCrashes(int which); |
| 747 | |
| 748 | /** |
| 749 | * Returns the number of times the process has ANRed. |
| 750 | * |
| 751 | * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT. |
| 752 | */ |
| 753 | public abstract int getNumAnrs(int which); |
| 754 | |
| 755 | /** |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 756 | * 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] | 757 | * @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] | 758 | * @return foreground cpu time in microseconds |
| 759 | */ |
| 760 | public abstract long getForegroundTime(int which); |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 761 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 762 | public abstract int countExcessivePowers(); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 763 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 764 | public abstract ExcessivePower getExcessivePower(int i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 765 | } |
| 766 | |
| 767 | /** |
| 768 | * The statistics associated with a particular package. |
| 769 | */ |
| 770 | public static abstract class Pkg { |
| 771 | |
| 772 | /** |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 773 | * Returns information about all wakeup alarms that have been triggered for this |
| 774 | * package. The mapping keys are tag names for the alarms, the counter contains |
| 775 | * 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] | 776 | */ |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 777 | public abstract ArrayMap<String, ? extends Counter> getWakeupAlarmStats(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 778 | |
| 779 | /** |
| 780 | * Returns a mapping containing service statistics. |
| 781 | */ |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 782 | public abstract ArrayMap<String, ? extends Serv> getServiceStats(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 783 | |
| 784 | /** |
| 785 | * The statistics associated with a particular service. |
| 786 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 787 | public static abstract class Serv { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 788 | |
| 789 | /** |
| 790 | * Returns the amount of time spent started. |
| 791 | * |
| 792 | * @param batteryUptime elapsed uptime on battery in microseconds. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 793 | * @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] | 794 | * @return |
| 795 | */ |
| 796 | public abstract long getStartTime(long batteryUptime, int which); |
| 797 | |
| 798 | /** |
| 799 | * Returns the total number of times startService() has been called. |
| 800 | * |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 801 | * @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] | 802 | */ |
| 803 | public abstract int getStarts(int which); |
| 804 | |
| 805 | /** |
| 806 | * Returns the total number times the service has been launched. |
| 807 | * |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 808 | * @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] | 809 | */ |
| 810 | public abstract int getLaunches(int which); |
| 811 | } |
| 812 | } |
| 813 | } |
| 814 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 815 | public static final class LevelStepTracker { |
| 816 | public long mLastStepTime = -1; |
| 817 | public int mNumStepDurations; |
| 818 | public final long[] mStepDurations; |
| 819 | |
| 820 | public LevelStepTracker(int maxLevelSteps) { |
| 821 | mStepDurations = new long[maxLevelSteps]; |
| 822 | } |
| 823 | |
| 824 | public LevelStepTracker(int numSteps, long[] steps) { |
| 825 | mNumStepDurations = numSteps; |
| 826 | mStepDurations = new long[numSteps]; |
| 827 | System.arraycopy(steps, 0, mStepDurations, 0, numSteps); |
| 828 | } |
| 829 | |
| 830 | public long getDurationAt(int index) { |
| 831 | return mStepDurations[index] & STEP_LEVEL_TIME_MASK; |
| 832 | } |
| 833 | |
| 834 | public int getLevelAt(int index) { |
| 835 | return (int)((mStepDurations[index] & STEP_LEVEL_LEVEL_MASK) |
| 836 | >> STEP_LEVEL_LEVEL_SHIFT); |
| 837 | } |
| 838 | |
| 839 | public int getInitModeAt(int index) { |
| 840 | return (int)((mStepDurations[index] & STEP_LEVEL_INITIAL_MODE_MASK) |
| 841 | >> STEP_LEVEL_INITIAL_MODE_SHIFT); |
| 842 | } |
| 843 | |
| 844 | public int getModModeAt(int index) { |
| 845 | return (int)((mStepDurations[index] & STEP_LEVEL_MODIFIED_MODE_MASK) |
| 846 | >> STEP_LEVEL_MODIFIED_MODE_SHIFT); |
| 847 | } |
| 848 | |
| 849 | private void appendHex(long val, int topOffset, StringBuilder out) { |
| 850 | boolean hasData = false; |
| 851 | while (topOffset >= 0) { |
| 852 | int digit = (int)( (val>>topOffset) & 0xf ); |
| 853 | topOffset -= 4; |
| 854 | if (!hasData && digit == 0) { |
| 855 | continue; |
| 856 | } |
| 857 | hasData = true; |
| 858 | if (digit >= 0 && digit <= 9) { |
| 859 | out.append((char)('0' + digit)); |
| 860 | } else { |
| 861 | out.append((char)('a' + digit - 10)); |
| 862 | } |
| 863 | } |
| 864 | } |
| 865 | |
| 866 | public void encodeEntryAt(int index, StringBuilder out) { |
| 867 | long item = mStepDurations[index]; |
| 868 | long duration = item & STEP_LEVEL_TIME_MASK; |
| 869 | int level = (int)((item & STEP_LEVEL_LEVEL_MASK) |
| 870 | >> STEP_LEVEL_LEVEL_SHIFT); |
| 871 | int initMode = (int)((item & STEP_LEVEL_INITIAL_MODE_MASK) |
| 872 | >> STEP_LEVEL_INITIAL_MODE_SHIFT); |
| 873 | int modMode = (int)((item & STEP_LEVEL_MODIFIED_MODE_MASK) |
| 874 | >> STEP_LEVEL_MODIFIED_MODE_SHIFT); |
| 875 | switch ((initMode&STEP_LEVEL_MODE_SCREEN_STATE) + 1) { |
| 876 | case Display.STATE_OFF: out.append('f'); break; |
| 877 | case Display.STATE_ON: out.append('o'); break; |
| 878 | case Display.STATE_DOZE: out.append('d'); break; |
| 879 | case Display.STATE_DOZE_SUSPEND: out.append('z'); break; |
| 880 | } |
| 881 | if ((initMode&STEP_LEVEL_MODE_POWER_SAVE) != 0) { |
| 882 | out.append('p'); |
| 883 | } |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 884 | if ((initMode&STEP_LEVEL_MODE_DEVICE_IDLE) != 0) { |
| 885 | out.append('i'); |
| 886 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 887 | switch ((modMode&STEP_LEVEL_MODE_SCREEN_STATE) + 1) { |
| 888 | case Display.STATE_OFF: out.append('F'); break; |
| 889 | case Display.STATE_ON: out.append('O'); break; |
| 890 | case Display.STATE_DOZE: out.append('D'); break; |
| 891 | case Display.STATE_DOZE_SUSPEND: out.append('Z'); break; |
| 892 | } |
| 893 | if ((modMode&STEP_LEVEL_MODE_POWER_SAVE) != 0) { |
| 894 | out.append('P'); |
| 895 | } |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 896 | if ((modMode&STEP_LEVEL_MODE_DEVICE_IDLE) != 0) { |
| 897 | out.append('I'); |
| 898 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 899 | out.append('-'); |
| 900 | appendHex(level, 4, out); |
| 901 | out.append('-'); |
| 902 | appendHex(duration, STEP_LEVEL_LEVEL_SHIFT-4, out); |
| 903 | } |
| 904 | |
| 905 | public void decodeEntryAt(int index, String value) { |
| 906 | final int N = value.length(); |
| 907 | int i = 0; |
| 908 | char c; |
| 909 | long out = 0; |
| 910 | while (i < N && (c=value.charAt(i)) != '-') { |
| 911 | i++; |
| 912 | switch (c) { |
Dianne Hackborn | 8cfb58b | 2015-03-04 13:28:36 -0800 | [diff] [blame] | 913 | 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] | 914 | break; |
Dianne Hackborn | 8cfb58b | 2015-03-04 13:28:36 -0800 | [diff] [blame] | 915 | 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] | 916 | break; |
Dianne Hackborn | 8cfb58b | 2015-03-04 13:28:36 -0800 | [diff] [blame] | 917 | 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] | 918 | break; |
Dianne Hackborn | 8cfb58b | 2015-03-04 13:28:36 -0800 | [diff] [blame] | 919 | case 'z': out |= (((long)Display.STATE_DOZE_SUSPEND-1) |
| 920 | << STEP_LEVEL_INITIAL_MODE_SHIFT); |
| 921 | break; |
| 922 | case 'p': out |= (((long)STEP_LEVEL_MODE_POWER_SAVE) |
| 923 | << STEP_LEVEL_INITIAL_MODE_SHIFT); |
| 924 | break; |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 925 | case 'i': out |= (((long)STEP_LEVEL_MODE_DEVICE_IDLE) |
| 926 | << STEP_LEVEL_INITIAL_MODE_SHIFT); |
| 927 | break; |
Dianne Hackborn | 8cfb58b | 2015-03-04 13:28:36 -0800 | [diff] [blame] | 928 | case 'F': out |= (((long)Display.STATE_OFF-1)<<STEP_LEVEL_MODIFIED_MODE_SHIFT); |
| 929 | break; |
| 930 | case 'O': out |= (((long)Display.STATE_ON-1)<<STEP_LEVEL_MODIFIED_MODE_SHIFT); |
| 931 | break; |
| 932 | case 'D': out |= (((long)Display.STATE_DOZE-1)<<STEP_LEVEL_MODIFIED_MODE_SHIFT); |
| 933 | break; |
| 934 | case 'Z': out |= (((long)Display.STATE_DOZE_SUSPEND-1) |
| 935 | << STEP_LEVEL_MODIFIED_MODE_SHIFT); |
| 936 | break; |
| 937 | case 'P': out |= (((long)STEP_LEVEL_MODE_POWER_SAVE) |
| 938 | << STEP_LEVEL_MODIFIED_MODE_SHIFT); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 939 | break; |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 940 | case 'I': out |= (((long)STEP_LEVEL_MODE_DEVICE_IDLE) |
| 941 | << STEP_LEVEL_MODIFIED_MODE_SHIFT); |
| 942 | break; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 943 | } |
| 944 | } |
| 945 | i++; |
Dianne Hackborn | 8cfb58b | 2015-03-04 13:28:36 -0800 | [diff] [blame] | 946 | long level = 0; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 947 | while (i < N && (c=value.charAt(i)) != '-') { |
| 948 | i++; |
| 949 | level <<= 4; |
| 950 | if (c >= '0' && c <= '9') { |
| 951 | level += c - '0'; |
| 952 | } else if (c >= 'a' && c <= 'f') { |
| 953 | level += c - 'a' + 10; |
| 954 | } else if (c >= 'A' && c <= 'F') { |
| 955 | level += c - 'A' + 10; |
| 956 | } |
| 957 | } |
Dianne Hackborn | 8cfb58b | 2015-03-04 13:28:36 -0800 | [diff] [blame] | 958 | i++; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 959 | out |= (level << STEP_LEVEL_LEVEL_SHIFT) & STEP_LEVEL_LEVEL_MASK; |
| 960 | long duration = 0; |
| 961 | while (i < N && (c=value.charAt(i)) != '-') { |
| 962 | i++; |
| 963 | duration <<= 4; |
| 964 | if (c >= '0' && c <= '9') { |
| 965 | duration += c - '0'; |
| 966 | } else if (c >= 'a' && c <= 'f') { |
| 967 | duration += c - 'a' + 10; |
| 968 | } else if (c >= 'A' && c <= 'F') { |
| 969 | duration += c - 'A' + 10; |
| 970 | } |
| 971 | } |
| 972 | mStepDurations[index] = out | (duration & STEP_LEVEL_TIME_MASK); |
| 973 | } |
| 974 | |
| 975 | public void init() { |
| 976 | mLastStepTime = -1; |
| 977 | mNumStepDurations = 0; |
| 978 | } |
| 979 | |
| 980 | public void clearTime() { |
| 981 | mLastStepTime = -1; |
| 982 | } |
| 983 | |
| 984 | public long computeTimePerLevel() { |
| 985 | final long[] steps = mStepDurations; |
| 986 | final int numSteps = mNumStepDurations; |
| 987 | |
| 988 | // For now we'll do a simple average across all steps. |
| 989 | if (numSteps <= 0) { |
| 990 | return -1; |
| 991 | } |
| 992 | long total = 0; |
| 993 | for (int i=0; i<numSteps; i++) { |
| 994 | total += steps[i] & STEP_LEVEL_TIME_MASK; |
| 995 | } |
| 996 | return total / numSteps; |
| 997 | /* |
| 998 | long[] buckets = new long[numSteps]; |
| 999 | int numBuckets = 0; |
| 1000 | int numToAverage = 4; |
| 1001 | int i = 0; |
| 1002 | while (i < numSteps) { |
| 1003 | long totalTime = 0; |
| 1004 | int num = 0; |
| 1005 | for (int j=0; j<numToAverage && (i+j)<numSteps; j++) { |
| 1006 | totalTime += steps[i+j] & STEP_LEVEL_TIME_MASK; |
| 1007 | num++; |
| 1008 | } |
| 1009 | buckets[numBuckets] = totalTime / num; |
| 1010 | numBuckets++; |
| 1011 | numToAverage *= 2; |
| 1012 | i += num; |
| 1013 | } |
| 1014 | if (numBuckets < 1) { |
| 1015 | return -1; |
| 1016 | } |
| 1017 | long averageTime = buckets[numBuckets-1]; |
| 1018 | for (i=numBuckets-2; i>=0; i--) { |
| 1019 | averageTime = (averageTime + buckets[i]) / 2; |
| 1020 | } |
| 1021 | return averageTime; |
| 1022 | */ |
| 1023 | } |
| 1024 | |
| 1025 | public long computeTimeEstimate(long modesOfInterest, long modeValues, |
| 1026 | int[] outNumOfInterest) { |
| 1027 | final long[] steps = mStepDurations; |
| 1028 | final int count = mNumStepDurations; |
| 1029 | if (count <= 0) { |
| 1030 | return -1; |
| 1031 | } |
| 1032 | long total = 0; |
| 1033 | int numOfInterest = 0; |
| 1034 | for (int i=0; i<count; i++) { |
| 1035 | long initMode = (steps[i] & STEP_LEVEL_INITIAL_MODE_MASK) |
| 1036 | >> STEP_LEVEL_INITIAL_MODE_SHIFT; |
| 1037 | long modMode = (steps[i] & STEP_LEVEL_MODIFIED_MODE_MASK) |
| 1038 | >> STEP_LEVEL_MODIFIED_MODE_SHIFT; |
| 1039 | // If the modes of interest didn't change during this step period... |
| 1040 | if ((modMode&modesOfInterest) == 0) { |
| 1041 | // And the mode values during this period match those we are measuring... |
| 1042 | if ((initMode&modesOfInterest) == modeValues) { |
| 1043 | // Then this can be used to estimate the total time! |
| 1044 | numOfInterest++; |
| 1045 | total += steps[i] & STEP_LEVEL_TIME_MASK; |
| 1046 | } |
| 1047 | } |
| 1048 | } |
| 1049 | if (numOfInterest <= 0) { |
| 1050 | return -1; |
| 1051 | } |
| 1052 | |
| 1053 | if (outNumOfInterest != null) { |
| 1054 | outNumOfInterest[0] = numOfInterest; |
| 1055 | } |
| 1056 | |
| 1057 | // The estimated time is the average time we spend in each level, multipled |
| 1058 | // by 100 -- the total number of battery levels |
| 1059 | return (total / numOfInterest) * 100; |
| 1060 | } |
| 1061 | |
| 1062 | public void addLevelSteps(int numStepLevels, long modeBits, long elapsedRealtime) { |
| 1063 | int stepCount = mNumStepDurations; |
| 1064 | final long lastStepTime = mLastStepTime; |
| 1065 | if (lastStepTime >= 0 && numStepLevels > 0) { |
| 1066 | final long[] steps = mStepDurations; |
| 1067 | long duration = elapsedRealtime - lastStepTime; |
| 1068 | for (int i=0; i<numStepLevels; i++) { |
| 1069 | System.arraycopy(steps, 0, steps, 1, steps.length-1); |
| 1070 | long thisDuration = duration / (numStepLevels-i); |
| 1071 | duration -= thisDuration; |
| 1072 | if (thisDuration > STEP_LEVEL_TIME_MASK) { |
| 1073 | thisDuration = STEP_LEVEL_TIME_MASK; |
| 1074 | } |
| 1075 | steps[0] = thisDuration | modeBits; |
| 1076 | } |
| 1077 | stepCount += numStepLevels; |
| 1078 | if (stepCount > steps.length) { |
| 1079 | stepCount = steps.length; |
| 1080 | } |
| 1081 | } |
| 1082 | mNumStepDurations = stepCount; |
| 1083 | mLastStepTime = elapsedRealtime; |
| 1084 | } |
| 1085 | |
| 1086 | public void readFromParcel(Parcel in) { |
| 1087 | final int N = in.readInt(); |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 1088 | if (N > mStepDurations.length) { |
| 1089 | throw new ParcelFormatException("more step durations than available: " + N); |
| 1090 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 1091 | mNumStepDurations = N; |
| 1092 | for (int i=0; i<N; i++) { |
| 1093 | mStepDurations[i] = in.readLong(); |
| 1094 | } |
| 1095 | } |
| 1096 | |
| 1097 | public void writeToParcel(Parcel out) { |
| 1098 | final int N = mNumStepDurations; |
| 1099 | out.writeInt(N); |
| 1100 | for (int i=0; i<N; i++) { |
| 1101 | out.writeLong(mStepDurations[i]); |
| 1102 | } |
| 1103 | } |
| 1104 | } |
| 1105 | |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 1106 | public static final class PackageChange { |
| 1107 | public String mPackageName; |
| 1108 | public boolean mUpdate; |
| 1109 | public int mVersionCode; |
| 1110 | } |
| 1111 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 1112 | public static final class DailyItem { |
| 1113 | public long mStartTime; |
| 1114 | public long mEndTime; |
| 1115 | public LevelStepTracker mDischargeSteps; |
| 1116 | public LevelStepTracker mChargeSteps; |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 1117 | public ArrayList<PackageChange> mPackageChanges; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 1118 | } |
| 1119 | |
| 1120 | public abstract DailyItem getDailyItemLocked(int daysAgo); |
| 1121 | |
| 1122 | public abstract long getCurrentDailyStartTime(); |
| 1123 | |
| 1124 | public abstract long getNextMinDailyDeadline(); |
| 1125 | |
| 1126 | public abstract long getNextMaxDailyDeadline(); |
| 1127 | |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 1128 | public abstract long[] getCpuFreqs(); |
| 1129 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1130 | public final static class HistoryTag { |
| 1131 | public String string; |
| 1132 | public int uid; |
| 1133 | |
| 1134 | public int poolIdx; |
| 1135 | |
| 1136 | public void setTo(HistoryTag o) { |
| 1137 | string = o.string; |
| 1138 | uid = o.uid; |
| 1139 | poolIdx = o.poolIdx; |
| 1140 | } |
| 1141 | |
| 1142 | public void setTo(String _string, int _uid) { |
| 1143 | string = _string; |
| 1144 | uid = _uid; |
| 1145 | poolIdx = -1; |
| 1146 | } |
| 1147 | |
| 1148 | public void writeToParcel(Parcel dest, int flags) { |
| 1149 | dest.writeString(string); |
| 1150 | dest.writeInt(uid); |
| 1151 | } |
| 1152 | |
| 1153 | public void readFromParcel(Parcel src) { |
| 1154 | string = src.readString(); |
| 1155 | uid = src.readInt(); |
| 1156 | poolIdx = -1; |
| 1157 | } |
| 1158 | |
| 1159 | @Override |
| 1160 | public boolean equals(Object o) { |
| 1161 | if (this == o) return true; |
| 1162 | if (o == null || getClass() != o.getClass()) return false; |
| 1163 | |
| 1164 | HistoryTag that = (HistoryTag) o; |
| 1165 | |
| 1166 | if (uid != that.uid) return false; |
| 1167 | if (!string.equals(that.string)) return false; |
| 1168 | |
| 1169 | return true; |
| 1170 | } |
| 1171 | |
| 1172 | @Override |
| 1173 | public int hashCode() { |
| 1174 | int result = string.hashCode(); |
| 1175 | result = 31 * result + uid; |
| 1176 | return result; |
| 1177 | } |
| 1178 | } |
| 1179 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 1180 | /** |
| 1181 | * Optional detailed information that can go into a history step. This is typically |
| 1182 | * generated each time the battery level changes. |
| 1183 | */ |
| 1184 | public final static class HistoryStepDetails { |
| 1185 | // Time (in 1/100 second) spent in user space and the kernel since the last step. |
| 1186 | public int userTime; |
| 1187 | public int systemTime; |
| 1188 | |
| 1189 | // Top three apps using CPU in the last step, with times in 1/100 second. |
| 1190 | public int appCpuUid1; |
| 1191 | public int appCpuUTime1; |
| 1192 | public int appCpuSTime1; |
| 1193 | public int appCpuUid2; |
| 1194 | public int appCpuUTime2; |
| 1195 | public int appCpuSTime2; |
| 1196 | public int appCpuUid3; |
| 1197 | public int appCpuUTime3; |
| 1198 | public int appCpuSTime3; |
| 1199 | |
| 1200 | // Information from /proc/stat |
| 1201 | public int statUserTime; |
| 1202 | public int statSystemTime; |
| 1203 | public int statIOWaitTime; |
| 1204 | public int statIrqTime; |
| 1205 | public int statSoftIrqTime; |
| 1206 | public int statIdlTime; |
| 1207 | |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 1208 | // Platform-level low power state stats |
| 1209 | public String statPlatformIdleState; |
| 1210 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 1211 | public HistoryStepDetails() { |
| 1212 | clear(); |
| 1213 | } |
| 1214 | |
| 1215 | public void clear() { |
| 1216 | userTime = systemTime = 0; |
| 1217 | appCpuUid1 = appCpuUid2 = appCpuUid3 = -1; |
| 1218 | appCpuUTime1 = appCpuSTime1 = appCpuUTime2 = appCpuSTime2 |
| 1219 | = appCpuUTime3 = appCpuSTime3 = 0; |
| 1220 | } |
| 1221 | |
| 1222 | public void writeToParcel(Parcel out) { |
| 1223 | out.writeInt(userTime); |
| 1224 | out.writeInt(systemTime); |
| 1225 | out.writeInt(appCpuUid1); |
| 1226 | out.writeInt(appCpuUTime1); |
| 1227 | out.writeInt(appCpuSTime1); |
| 1228 | out.writeInt(appCpuUid2); |
| 1229 | out.writeInt(appCpuUTime2); |
| 1230 | out.writeInt(appCpuSTime2); |
| 1231 | out.writeInt(appCpuUid3); |
| 1232 | out.writeInt(appCpuUTime3); |
| 1233 | out.writeInt(appCpuSTime3); |
| 1234 | out.writeInt(statUserTime); |
| 1235 | out.writeInt(statSystemTime); |
| 1236 | out.writeInt(statIOWaitTime); |
| 1237 | out.writeInt(statIrqTime); |
| 1238 | out.writeInt(statSoftIrqTime); |
| 1239 | out.writeInt(statIdlTime); |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 1240 | out.writeString(statPlatformIdleState); |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 1241 | } |
| 1242 | |
| 1243 | public void readFromParcel(Parcel in) { |
| 1244 | userTime = in.readInt(); |
| 1245 | systemTime = in.readInt(); |
| 1246 | appCpuUid1 = in.readInt(); |
| 1247 | appCpuUTime1 = in.readInt(); |
| 1248 | appCpuSTime1 = in.readInt(); |
| 1249 | appCpuUid2 = in.readInt(); |
| 1250 | appCpuUTime2 = in.readInt(); |
| 1251 | appCpuSTime2 = in.readInt(); |
| 1252 | appCpuUid3 = in.readInt(); |
| 1253 | appCpuUTime3 = in.readInt(); |
| 1254 | appCpuSTime3 = in.readInt(); |
| 1255 | statUserTime = in.readInt(); |
| 1256 | statSystemTime = in.readInt(); |
| 1257 | statIOWaitTime = in.readInt(); |
| 1258 | statIrqTime = in.readInt(); |
| 1259 | statSoftIrqTime = in.readInt(); |
| 1260 | statIdlTime = in.readInt(); |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 1261 | statPlatformIdleState = in.readString(); |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 1262 | } |
| 1263 | } |
| 1264 | |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 1265 | public final static class HistoryItem implements Parcelable { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1266 | public HistoryItem next; |
Dianne Hackborn | 9a75543 | 2014-05-15 17:05:22 -0700 | [diff] [blame] | 1267 | |
| 1268 | // The time of this event in milliseconds, as per SystemClock.elapsedRealtime(). |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1269 | public long time; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1270 | |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 1271 | 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] | 1272 | public static final byte CMD_NULL = -1; |
| 1273 | public static final byte CMD_START = 4; |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1274 | public static final byte CMD_CURRENT_TIME = 5; |
| 1275 | public static final byte CMD_OVERFLOW = 6; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 1276 | public static final byte CMD_RESET = 7; |
Dianne Hackborn | 29cd7f1 | 2015-01-08 10:37:05 -0800 | [diff] [blame] | 1277 | public static final byte CMD_SHUTDOWN = 8; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1278 | |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 1279 | public byte cmd = CMD_NULL; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 1280 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1281 | /** |
| 1282 | * Return whether the command code is a delta data update. |
| 1283 | */ |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1284 | public boolean isDeltaData() { |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 1285 | return cmd == CMD_UPDATE; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1286 | } |
| 1287 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1288 | public byte batteryLevel; |
| 1289 | public byte batteryStatus; |
| 1290 | public byte batteryHealth; |
| 1291 | public byte batteryPlugType; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 1292 | |
Sungmin Choi | c7e9e8b | 2013-01-16 12:57:36 +0900 | [diff] [blame] | 1293 | public short batteryTemperature; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1294 | public char batteryVoltage; |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 1295 | |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 1296 | // The charge of the battery in micro-Ampere-hours. |
| 1297 | public int batteryChargeUAh; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 1298 | |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 1299 | // Constants from SCREEN_BRIGHTNESS_* |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1300 | public static final int STATE_BRIGHTNESS_SHIFT = 0; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1301 | public static final int STATE_BRIGHTNESS_MASK = 0x7; |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 1302 | // Constants from SIGNAL_STRENGTH_* |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 1303 | public static final int STATE_PHONE_SIGNAL_STRENGTH_SHIFT = 3; |
| 1304 | 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] | 1305 | // Constants from ServiceState.STATE_* |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1306 | public static final int STATE_PHONE_STATE_SHIFT = 6; |
| 1307 | 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] | 1308 | // Constants from DATA_CONNECTION_* |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1309 | public static final int STATE_DATA_CONNECTION_SHIFT = 9; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1310 | 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] | 1311 | |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 1312 | // These states always appear directly in the first int token |
| 1313 | // of a delta change; they should be ones that change relatively |
| 1314 | // frequently. |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1315 | public static final int STATE_CPU_RUNNING_FLAG = 1<<31; |
| 1316 | public static final int STATE_WAKE_LOCK_FLAG = 1<<30; |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 1317 | public static final int STATE_GPS_ON_FLAG = 1<<29; |
| 1318 | public static final int STATE_WIFI_FULL_LOCK_FLAG = 1<<28; |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 1319 | public static final int STATE_WIFI_SCAN_FLAG = 1<<27; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 1320 | public static final int STATE_WIFI_RADIO_ACTIVE_FLAG = 1<<26; |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 1321 | public static final int STATE_MOBILE_RADIO_ACTIVE_FLAG = 1<<25; |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 1322 | // Do not use, this is used for coulomb delta count. |
| 1323 | private static final int STATE_RESERVED_0 = 1<<24; |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 1324 | // These are on the lower bits used for the command; if they change |
| 1325 | // we need to write another int of data. |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1326 | public static final int STATE_SENSOR_ON_FLAG = 1<<23; |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 1327 | public static final int STATE_AUDIO_ON_FLAG = 1<<22; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1328 | public static final int STATE_PHONE_SCANNING_FLAG = 1<<21; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 1329 | public static final int STATE_SCREEN_ON_FLAG = 1<<20; // consider moving to states2 |
| 1330 | public static final int STATE_BATTERY_PLUGGED_FLAG = 1<<19; // consider moving to states2 |
| 1331 | // empty slot |
| 1332 | // empty slot |
| 1333 | public static final int STATE_WIFI_MULTICAST_ON_FLAG = 1<<16; |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 1334 | |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 1335 | public static final int MOST_INTERESTING_STATES = |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 1336 | STATE_BATTERY_PLUGGED_FLAG | STATE_SCREEN_ON_FLAG; |
| 1337 | |
| 1338 | public static final int SETTLE_TO_ZERO_STATES = 0xffff0000 & ~MOST_INTERESTING_STATES; |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 1339 | |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1340 | public int states; |
| 1341 | |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 1342 | // Constants from WIFI_SUPPL_STATE_* |
| 1343 | public static final int STATE2_WIFI_SUPPL_STATE_SHIFT = 0; |
| 1344 | public static final int STATE2_WIFI_SUPPL_STATE_MASK = 0xf; |
| 1345 | // Values for NUM_WIFI_SIGNAL_STRENGTH_BINS |
| 1346 | public static final int STATE2_WIFI_SIGNAL_STRENGTH_SHIFT = 4; |
| 1347 | public static final int STATE2_WIFI_SIGNAL_STRENGTH_MASK = |
| 1348 | 0x7 << STATE2_WIFI_SIGNAL_STRENGTH_SHIFT; |
| 1349 | |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 1350 | public static final int STATE2_POWER_SAVE_FLAG = 1<<31; |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 1351 | public static final int STATE2_VIDEO_ON_FLAG = 1<<30; |
| 1352 | public static final int STATE2_WIFI_RUNNING_FLAG = 1<<29; |
| 1353 | public static final int STATE2_WIFI_ON_FLAG = 1<<28; |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 1354 | public static final int STATE2_FLASHLIGHT_FLAG = 1<<27; |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 1355 | public static final int STATE2_DEVICE_IDLE_SHIFT = 25; |
| 1356 | public static final int STATE2_DEVICE_IDLE_MASK = 0x3 << STATE2_DEVICE_IDLE_SHIFT; |
| 1357 | public static final int STATE2_CHARGING_FLAG = 1<<24; |
| 1358 | public static final int STATE2_PHONE_IN_CALL_FLAG = 1<<23; |
| 1359 | public static final int STATE2_BLUETOOTH_ON_FLAG = 1<<22; |
| 1360 | public static final int STATE2_CAMERA_FLAG = 1<<21; |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 1361 | public static final int STATE2_BLUETOOTH_SCAN_FLAG = 1 << 20; |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 1362 | |
| 1363 | public static final int MOST_INTERESTING_STATES2 = |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 1364 | STATE2_POWER_SAVE_FLAG | STATE2_WIFI_ON_FLAG | STATE2_DEVICE_IDLE_MASK |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 1365 | | STATE2_CHARGING_FLAG | STATE2_PHONE_IN_CALL_FLAG | STATE2_BLUETOOTH_ON_FLAG; |
| 1366 | |
| 1367 | public static final int SETTLE_TO_ZERO_STATES2 = 0xffff0000 & ~MOST_INTERESTING_STATES2; |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 1368 | |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 1369 | public int states2; |
| 1370 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1371 | // The wake lock that was acquired at this point. |
| 1372 | public HistoryTag wakelockTag; |
| 1373 | |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1374 | // Kernel wakeup reason at this point. |
| 1375 | public HistoryTag wakeReasonTag; |
| 1376 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 1377 | // Non-null when there is more detailed information at this step. |
| 1378 | public HistoryStepDetails stepDetails; |
| 1379 | |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 1380 | public static final int EVENT_FLAG_START = 0x8000; |
| 1381 | public static final int EVENT_FLAG_FINISH = 0x4000; |
| 1382 | |
| 1383 | // No event in this item. |
| 1384 | public static final int EVENT_NONE = 0x0000; |
| 1385 | // Event is about a process that is running. |
| 1386 | public static final int EVENT_PROC = 0x0001; |
| 1387 | // Event is about an application package that is in the foreground. |
| 1388 | public static final int EVENT_FOREGROUND = 0x0002; |
| 1389 | // Event is about an application package that is at the top of the screen. |
| 1390 | public static final int EVENT_TOP = 0x0003; |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 1391 | // Event is about active sync operations. |
Dianne Hackborn | a1f1a3c | 2014-02-24 18:12:28 -0800 | [diff] [blame] | 1392 | public static final int EVENT_SYNC = 0x0004; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 1393 | // Events for all additional wake locks aquired/release within a wake block. |
| 1394 | // These are not generated by default. |
| 1395 | public static final int EVENT_WAKE_LOCK = 0x0005; |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 1396 | // Event is about an application executing a scheduled job. |
| 1397 | public static final int EVENT_JOB = 0x0006; |
| 1398 | // Events for users running. |
| 1399 | public static final int EVENT_USER_RUNNING = 0x0007; |
| 1400 | // Events for foreground user. |
| 1401 | public static final int EVENT_USER_FOREGROUND = 0x0008; |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 1402 | // Event for connectivity changed. |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 1403 | public static final int EVENT_CONNECTIVITY_CHANGED = 0x0009; |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 1404 | // Event for becoming active taking us out of idle mode. |
Dianne Hackborn | b6683c4 | 2015-06-18 17:40:33 -0700 | [diff] [blame] | 1405 | public static final int EVENT_ACTIVE = 0x000a; |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 1406 | // Event for a package being installed. |
Dianne Hackborn | b6683c4 | 2015-06-18 17:40:33 -0700 | [diff] [blame] | 1407 | public static final int EVENT_PACKAGE_INSTALLED = 0x000b; |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 1408 | // Event for a package being uninstalled. |
Dianne Hackborn | b6683c4 | 2015-06-18 17:40:33 -0700 | [diff] [blame] | 1409 | public static final int EVENT_PACKAGE_UNINSTALLED = 0x000c; |
Dianne Hackborn | 1e38382 | 2015-04-10 14:02:33 -0700 | [diff] [blame] | 1410 | // Event for a package being uninstalled. |
Dianne Hackborn | b6683c4 | 2015-06-18 17:40:33 -0700 | [diff] [blame] | 1411 | public static final int EVENT_ALARM = 0x000d; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 1412 | // Record that we have decided we need to collect new stats data. |
Dianne Hackborn | b6683c4 | 2015-06-18 17:40:33 -0700 | [diff] [blame] | 1413 | public static final int EVENT_COLLECT_EXTERNAL_STATS = 0x000e; |
Amith Yamasani | 6776849 | 2015-06-09 12:23:58 -0700 | [diff] [blame] | 1414 | // 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] | 1415 | public static final int EVENT_PACKAGE_INACTIVE = 0x000f; |
Amith Yamasani | 6776849 | 2015-06-09 12:23:58 -0700 | [diff] [blame] | 1416 | // Event for a package becoming active due to an interaction. |
Dianne Hackborn | b6683c4 | 2015-06-18 17:40:33 -0700 | [diff] [blame] | 1417 | public static final int EVENT_PACKAGE_ACTIVE = 0x0010; |
Dianne Hackborn | fd854ee | 2015-07-13 18:00:37 -0700 | [diff] [blame] | 1418 | // Event for a package being on the temporary whitelist. |
| 1419 | public static final int EVENT_TEMP_WHITELIST = 0x0011; |
Dianne Hackborn | 280a64e | 2015-07-13 14:48:08 -0700 | [diff] [blame] | 1420 | // Event for the screen waking up. |
| 1421 | public static final int EVENT_SCREEN_WAKE_UP = 0x0012; |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 1422 | // Event for the UID that woke up the application processor. |
| 1423 | // Used for wakeups coming from WiFi, modem, etc. |
| 1424 | public static final int EVENT_WAKEUP_AP = 0x0013; |
Dianne Hackborn | d0db6f0 | 2016-07-18 14:14:20 -0700 | [diff] [blame] | 1425 | // Event for reporting that a specific partial wake lock has been held for a long duration. |
| 1426 | public static final int EVENT_LONG_WAKE_LOCK = 0x0014; |
Amith Yamasani | 6776849 | 2015-06-09 12:23:58 -0700 | [diff] [blame] | 1427 | |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 1428 | // Number of event types. |
Adam Lesinski | 041d917 | 2016-12-12 12:03:56 -0800 | [diff] [blame] | 1429 | public static final int EVENT_COUNT = 0x0016; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 1430 | // Mask to extract out only the type part of the event. |
| 1431 | 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] | 1432 | |
| 1433 | public static final int EVENT_PROC_START = EVENT_PROC | EVENT_FLAG_START; |
| 1434 | public static final int EVENT_PROC_FINISH = EVENT_PROC | EVENT_FLAG_FINISH; |
| 1435 | public static final int EVENT_FOREGROUND_START = EVENT_FOREGROUND | EVENT_FLAG_START; |
| 1436 | public static final int EVENT_FOREGROUND_FINISH = EVENT_FOREGROUND | EVENT_FLAG_FINISH; |
| 1437 | public static final int EVENT_TOP_START = EVENT_TOP | EVENT_FLAG_START; |
| 1438 | public static final int EVENT_TOP_FINISH = EVENT_TOP | EVENT_FLAG_FINISH; |
Dianne Hackborn | a1f1a3c | 2014-02-24 18:12:28 -0800 | [diff] [blame] | 1439 | public static final int EVENT_SYNC_START = EVENT_SYNC | EVENT_FLAG_START; |
| 1440 | public static final int EVENT_SYNC_FINISH = EVENT_SYNC | EVENT_FLAG_FINISH; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 1441 | public static final int EVENT_WAKE_LOCK_START = EVENT_WAKE_LOCK | EVENT_FLAG_START; |
| 1442 | 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] | 1443 | public static final int EVENT_JOB_START = EVENT_JOB | EVENT_FLAG_START; |
| 1444 | public static final int EVENT_JOB_FINISH = EVENT_JOB | EVENT_FLAG_FINISH; |
| 1445 | public static final int EVENT_USER_RUNNING_START = EVENT_USER_RUNNING | EVENT_FLAG_START; |
| 1446 | public static final int EVENT_USER_RUNNING_FINISH = EVENT_USER_RUNNING | EVENT_FLAG_FINISH; |
| 1447 | public static final int EVENT_USER_FOREGROUND_START = |
| 1448 | EVENT_USER_FOREGROUND | EVENT_FLAG_START; |
| 1449 | public static final int EVENT_USER_FOREGROUND_FINISH = |
| 1450 | EVENT_USER_FOREGROUND | EVENT_FLAG_FINISH; |
Dianne Hackborn | 1e38382 | 2015-04-10 14:02:33 -0700 | [diff] [blame] | 1451 | public static final int EVENT_ALARM_START = EVENT_ALARM | EVENT_FLAG_START; |
| 1452 | public static final int EVENT_ALARM_FINISH = EVENT_ALARM | EVENT_FLAG_FINISH; |
Dianne Hackborn | fd854ee | 2015-07-13 18:00:37 -0700 | [diff] [blame] | 1453 | public static final int EVENT_TEMP_WHITELIST_START = |
| 1454 | EVENT_TEMP_WHITELIST | EVENT_FLAG_START; |
| 1455 | public static final int EVENT_TEMP_WHITELIST_FINISH = |
| 1456 | EVENT_TEMP_WHITELIST | EVENT_FLAG_FINISH; |
Dianne Hackborn | d0db6f0 | 2016-07-18 14:14:20 -0700 | [diff] [blame] | 1457 | public static final int EVENT_LONG_WAKE_LOCK_START = |
| 1458 | EVENT_LONG_WAKE_LOCK | EVENT_FLAG_START; |
| 1459 | public static final int EVENT_LONG_WAKE_LOCK_FINISH = |
| 1460 | EVENT_LONG_WAKE_LOCK | EVENT_FLAG_FINISH; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1461 | |
| 1462 | // For CMD_EVENT. |
| 1463 | public int eventCode; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1464 | public HistoryTag eventTag; |
| 1465 | |
Dianne Hackborn | 9a75543 | 2014-05-15 17:05:22 -0700 | [diff] [blame] | 1466 | // 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] | 1467 | public long currentTime; |
| 1468 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1469 | // Meta-data when reading. |
| 1470 | public int numReadInts; |
| 1471 | |
| 1472 | // Pre-allocated objects. |
| 1473 | public final HistoryTag localWakelockTag = new HistoryTag(); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1474 | public final HistoryTag localWakeReasonTag = new HistoryTag(); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1475 | public final HistoryTag localEventTag = new HistoryTag(); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1476 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1477 | public HistoryItem() { |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1478 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 1479 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1480 | public HistoryItem(long time, Parcel src) { |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1481 | this.time = time; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1482 | numReadInts = 2; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 1483 | readFromParcel(src); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1484 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 1485 | |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1486 | public int describeContents() { |
| 1487 | return 0; |
| 1488 | } |
| 1489 | |
| 1490 | public void writeToParcel(Parcel dest, int flags) { |
| 1491 | dest.writeLong(time); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1492 | int bat = (((int)cmd)&0xff) |
| 1493 | | ((((int)batteryLevel)<<8)&0xff00) |
| 1494 | | ((((int)batteryStatus)<<16)&0xf0000) |
| 1495 | | ((((int)batteryHealth)<<20)&0xf00000) |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1496 | | ((((int)batteryPlugType)<<24)&0xf000000) |
| 1497 | | (wakelockTag != null ? 0x10000000 : 0) |
| 1498 | | (wakeReasonTag != null ? 0x20000000 : 0) |
| 1499 | | (eventCode != EVENT_NONE ? 0x40000000 : 0); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1500 | dest.writeInt(bat); |
| 1501 | bat = (((int)batteryTemperature)&0xffff) |
| 1502 | | ((((int)batteryVoltage)<<16)&0xffff0000); |
| 1503 | dest.writeInt(bat); |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 1504 | dest.writeInt(batteryChargeUAh); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1505 | dest.writeInt(states); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1506 | dest.writeInt(states2); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1507 | if (wakelockTag != null) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1508 | wakelockTag.writeToParcel(dest, flags); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1509 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1510 | if (wakeReasonTag != null) { |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1511 | wakeReasonTag.writeToParcel(dest, flags); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1512 | } |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 1513 | if (eventCode != EVENT_NONE) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1514 | dest.writeInt(eventCode); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1515 | eventTag.writeToParcel(dest, flags); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1516 | } |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 1517 | if (cmd == CMD_CURRENT_TIME || cmd == CMD_RESET) { |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1518 | dest.writeLong(currentTime); |
| 1519 | } |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1520 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 1521 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1522 | public void readFromParcel(Parcel src) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1523 | int start = src.dataPosition(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 1524 | int bat = src.readInt(); |
| 1525 | cmd = (byte)(bat&0xff); |
| 1526 | batteryLevel = (byte)((bat>>8)&0xff); |
| 1527 | batteryStatus = (byte)((bat>>16)&0xf); |
| 1528 | batteryHealth = (byte)((bat>>20)&0xf); |
| 1529 | batteryPlugType = (byte)((bat>>24)&0xf); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1530 | int bat2 = src.readInt(); |
| 1531 | batteryTemperature = (short)(bat2&0xffff); |
| 1532 | batteryVoltage = (char)((bat2>>16)&0xffff); |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 1533 | batteryChargeUAh = src.readInt(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 1534 | states = src.readInt(); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1535 | states2 = src.readInt(); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1536 | if ((bat&0x10000000) != 0) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1537 | wakelockTag = localWakelockTag; |
| 1538 | wakelockTag.readFromParcel(src); |
| 1539 | } else { |
| 1540 | wakelockTag = null; |
| 1541 | } |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1542 | if ((bat&0x20000000) != 0) { |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1543 | wakeReasonTag = localWakeReasonTag; |
| 1544 | wakeReasonTag.readFromParcel(src); |
| 1545 | } else { |
| 1546 | wakeReasonTag = null; |
| 1547 | } |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1548 | if ((bat&0x40000000) != 0) { |
| 1549 | eventCode = src.readInt(); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1550 | eventTag = localEventTag; |
| 1551 | eventTag.readFromParcel(src); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1552 | } else { |
| 1553 | eventCode = EVENT_NONE; |
| 1554 | eventTag = null; |
| 1555 | } |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 1556 | if (cmd == CMD_CURRENT_TIME || cmd == CMD_RESET) { |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1557 | currentTime = src.readLong(); |
| 1558 | } else { |
| 1559 | currentTime = 0; |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 1560 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1561 | numReadInts += (src.dataPosition()-start)/4; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 1562 | } |
| 1563 | |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 1564 | public void clear() { |
| 1565 | time = 0; |
| 1566 | cmd = CMD_NULL; |
| 1567 | batteryLevel = 0; |
| 1568 | batteryStatus = 0; |
| 1569 | batteryHealth = 0; |
| 1570 | batteryPlugType = 0; |
| 1571 | batteryTemperature = 0; |
| 1572 | batteryVoltage = 0; |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 1573 | batteryChargeUAh = 0; |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 1574 | states = 0; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1575 | states2 = 0; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1576 | wakelockTag = null; |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1577 | wakeReasonTag = null; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1578 | eventCode = EVENT_NONE; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1579 | eventTag = null; |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 1580 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 1581 | |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 1582 | public void setTo(HistoryItem o) { |
| 1583 | time = o.time; |
| 1584 | cmd = o.cmd; |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 1585 | setToCommon(o); |
| 1586 | } |
| 1587 | |
| 1588 | public void setTo(long time, byte cmd, HistoryItem o) { |
| 1589 | this.time = time; |
| 1590 | this.cmd = cmd; |
| 1591 | setToCommon(o); |
| 1592 | } |
| 1593 | |
| 1594 | private void setToCommon(HistoryItem o) { |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 1595 | batteryLevel = o.batteryLevel; |
| 1596 | batteryStatus = o.batteryStatus; |
| 1597 | batteryHealth = o.batteryHealth; |
| 1598 | batteryPlugType = o.batteryPlugType; |
| 1599 | batteryTemperature = o.batteryTemperature; |
| 1600 | batteryVoltage = o.batteryVoltage; |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 1601 | batteryChargeUAh = o.batteryChargeUAh; |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 1602 | states = o.states; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1603 | states2 = o.states2; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1604 | if (o.wakelockTag != null) { |
| 1605 | wakelockTag = localWakelockTag; |
| 1606 | wakelockTag.setTo(o.wakelockTag); |
| 1607 | } else { |
| 1608 | wakelockTag = null; |
| 1609 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1610 | if (o.wakeReasonTag != null) { |
| 1611 | wakeReasonTag = localWakeReasonTag; |
| 1612 | wakeReasonTag.setTo(o.wakeReasonTag); |
| 1613 | } else { |
| 1614 | wakeReasonTag = null; |
| 1615 | } |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1616 | eventCode = o.eventCode; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1617 | if (o.eventTag != null) { |
| 1618 | eventTag = localEventTag; |
| 1619 | eventTag.setTo(o.eventTag); |
| 1620 | } else { |
| 1621 | eventTag = null; |
| 1622 | } |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1623 | currentTime = o.currentTime; |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 1624 | } |
| 1625 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1626 | public boolean sameNonEvent(HistoryItem o) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 1627 | return batteryLevel == o.batteryLevel |
| 1628 | && batteryStatus == o.batteryStatus |
| 1629 | && batteryHealth == o.batteryHealth |
| 1630 | && batteryPlugType == o.batteryPlugType |
| 1631 | && batteryTemperature == o.batteryTemperature |
| 1632 | && batteryVoltage == o.batteryVoltage |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 1633 | && batteryChargeUAh == o.batteryChargeUAh |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1634 | && states == o.states |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1635 | && states2 == o.states2 |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1636 | && currentTime == o.currentTime; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 1637 | } |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1638 | |
| 1639 | public boolean same(HistoryItem o) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1640 | if (!sameNonEvent(o) || eventCode != o.eventCode) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1641 | return false; |
| 1642 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1643 | if (wakelockTag != o.wakelockTag) { |
| 1644 | if (wakelockTag == null || o.wakelockTag == null) { |
| 1645 | return false; |
| 1646 | } |
| 1647 | if (!wakelockTag.equals(o.wakelockTag)) { |
| 1648 | return false; |
| 1649 | } |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1650 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1651 | if (wakeReasonTag != o.wakeReasonTag) { |
| 1652 | if (wakeReasonTag == null || o.wakeReasonTag == null) { |
| 1653 | return false; |
| 1654 | } |
| 1655 | if (!wakeReasonTag.equals(o.wakeReasonTag)) { |
| 1656 | return false; |
| 1657 | } |
| 1658 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1659 | if (eventTag != o.eventTag) { |
| 1660 | if (eventTag == null || o.eventTag == null) { |
| 1661 | return false; |
| 1662 | } |
| 1663 | if (!eventTag.equals(o.eventTag)) { |
| 1664 | return false; |
| 1665 | } |
| 1666 | } |
| 1667 | return true; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1668 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1669 | } |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 1670 | |
| 1671 | public final static class HistoryEventTracker { |
| 1672 | private final HashMap<String, SparseIntArray>[] mActiveEvents |
| 1673 | = (HashMap<String, SparseIntArray>[]) new HashMap[HistoryItem.EVENT_COUNT]; |
| 1674 | |
| 1675 | public boolean updateState(int code, String name, int uid, int poolIdx) { |
| 1676 | if ((code&HistoryItem.EVENT_FLAG_START) != 0) { |
| 1677 | int idx = code&HistoryItem.EVENT_TYPE_MASK; |
| 1678 | HashMap<String, SparseIntArray> active = mActiveEvents[idx]; |
| 1679 | if (active == null) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 1680 | active = new HashMap<>(); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 1681 | mActiveEvents[idx] = active; |
| 1682 | } |
| 1683 | SparseIntArray uids = active.get(name); |
| 1684 | if (uids == null) { |
| 1685 | uids = new SparseIntArray(); |
| 1686 | active.put(name, uids); |
| 1687 | } |
| 1688 | if (uids.indexOfKey(uid) >= 0) { |
| 1689 | // Already set, nothing to do! |
| 1690 | return false; |
| 1691 | } |
| 1692 | uids.put(uid, poolIdx); |
| 1693 | } else if ((code&HistoryItem.EVENT_FLAG_FINISH) != 0) { |
| 1694 | int idx = code&HistoryItem.EVENT_TYPE_MASK; |
| 1695 | HashMap<String, SparseIntArray> active = mActiveEvents[idx]; |
| 1696 | if (active == null) { |
| 1697 | // not currently active, nothing to do. |
| 1698 | return false; |
| 1699 | } |
| 1700 | SparseIntArray uids = active.get(name); |
| 1701 | if (uids == null) { |
| 1702 | // not currently active, nothing to do. |
| 1703 | return false; |
| 1704 | } |
| 1705 | idx = uids.indexOfKey(uid); |
| 1706 | if (idx < 0) { |
| 1707 | // not currently active, nothing to do. |
| 1708 | return false; |
| 1709 | } |
| 1710 | uids.removeAt(idx); |
| 1711 | if (uids.size() <= 0) { |
| 1712 | active.remove(name); |
| 1713 | } |
| 1714 | } |
| 1715 | return true; |
| 1716 | } |
| 1717 | |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 1718 | public void removeEvents(int code) { |
| 1719 | int idx = code&HistoryItem.EVENT_TYPE_MASK; |
| 1720 | mActiveEvents[idx] = null; |
| 1721 | } |
| 1722 | |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 1723 | public HashMap<String, SparseIntArray> getStateForEvent(int code) { |
| 1724 | return mActiveEvents[code]; |
| 1725 | } |
| 1726 | } |
| 1727 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1728 | public static final class BitDescription { |
| 1729 | public final int mask; |
| 1730 | public final int shift; |
| 1731 | public final String name; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1732 | public final String shortName; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1733 | public final String[] values; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1734 | public final String[] shortValues; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 1735 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1736 | public BitDescription(int mask, String name, String shortName) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1737 | this.mask = mask; |
| 1738 | this.shift = -1; |
| 1739 | this.name = name; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1740 | this.shortName = shortName; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1741 | this.values = null; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1742 | this.shortValues = null; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1743 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 1744 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1745 | public BitDescription(int mask, int shift, String name, String shortName, |
| 1746 | String[] values, String[] shortValues) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1747 | this.mask = mask; |
| 1748 | this.shift = shift; |
| 1749 | this.name = name; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1750 | this.shortName = shortName; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1751 | this.values = values; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1752 | this.shortValues = shortValues; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1753 | } |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1754 | } |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 1755 | |
Dianne Hackborn | fc06413 | 2014-06-02 12:42:12 -0700 | [diff] [blame] | 1756 | /** |
| 1757 | * Don't allow any more batching in to the current history event. This |
| 1758 | * is called when printing partial histories, so to ensure that the next |
| 1759 | * history event will go in to a new batch after what was printed in the |
| 1760 | * last partial history. |
| 1761 | */ |
| 1762 | public abstract void commitCurrentHistoryBatchLocked(); |
| 1763 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1764 | public abstract int getHistoryTotalSize(); |
| 1765 | |
| 1766 | public abstract int getHistoryUsedSize(); |
| 1767 | |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 1768 | public abstract boolean startIteratingHistoryLocked(); |
| 1769 | |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 1770 | public abstract int getHistoryStringPoolSize(); |
| 1771 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1772 | public abstract int getHistoryStringPoolBytes(); |
| 1773 | |
| 1774 | public abstract String getHistoryTagPoolString(int index); |
| 1775 | |
| 1776 | public abstract int getHistoryTagPoolUid(int index); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 1777 | |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 1778 | public abstract boolean getNextHistoryLocked(HistoryItem out); |
| 1779 | |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 1780 | public abstract void finishIteratingHistoryLocked(); |
| 1781 | |
| 1782 | public abstract boolean startIteratingOldHistoryLocked(); |
| 1783 | |
| 1784 | public abstract boolean getNextOldHistoryLocked(HistoryItem out); |
| 1785 | |
| 1786 | public abstract void finishIteratingOldHistoryLocked(); |
| 1787 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1788 | /** |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 1789 | * Return the base time offset for the battery history. |
| 1790 | */ |
| 1791 | public abstract long getHistoryBaseTime(); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 1792 | |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 1793 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1794 | * Returns the number of times the device has been started. |
| 1795 | */ |
| 1796 | public abstract int getStartCount(); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 1797 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1798 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 1799 | * 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] | 1800 | * running on battery. |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 1801 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1802 | * {@hide} |
| 1803 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1804 | public abstract long getScreenOnTime(long elapsedRealtimeUs, int which); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 1805 | |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 1806 | /** |
| 1807 | * Returns the number of times the screen was turned on. |
| 1808 | * |
| 1809 | * {@hide} |
| 1810 | */ |
| 1811 | public abstract int getScreenOnCount(int which); |
| 1812 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 1813 | public abstract long getInteractiveTime(long elapsedRealtimeUs, int which); |
| 1814 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1815 | public static final int SCREEN_BRIGHTNESS_DARK = 0; |
| 1816 | public static final int SCREEN_BRIGHTNESS_DIM = 1; |
| 1817 | public static final int SCREEN_BRIGHTNESS_MEDIUM = 2; |
| 1818 | public static final int SCREEN_BRIGHTNESS_LIGHT = 3; |
| 1819 | public static final int SCREEN_BRIGHTNESS_BRIGHT = 4; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 1820 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1821 | static final String[] SCREEN_BRIGHTNESS_NAMES = { |
| 1822 | "dark", "dim", "medium", "light", "bright" |
| 1823 | }; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 1824 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1825 | static final String[] SCREEN_BRIGHTNESS_SHORT_NAMES = { |
| 1826 | "0", "1", "2", "3", "4" |
| 1827 | }; |
| 1828 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1829 | public static final int NUM_SCREEN_BRIGHTNESS_BINS = 5; |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 1830 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1831 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 1832 | * Returns the time in microseconds that the screen has been on with |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1833 | * the given brightness |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 1834 | * |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1835 | * {@hide} |
| 1836 | */ |
| 1837 | public abstract long getScreenBrightnessTime(int brightnessBin, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1838 | long elapsedRealtimeUs, int which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1839 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1840 | /** |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 1841 | * 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] | 1842 | * running on battery. |
| 1843 | * |
| 1844 | * {@hide} |
| 1845 | */ |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 1846 | public abstract long getPowerSaveModeEnabledTime(long elapsedRealtimeUs, int which); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 1847 | |
| 1848 | /** |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 1849 | * Returns the number of times that power save mode was enabled. |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 1850 | * |
| 1851 | * {@hide} |
| 1852 | */ |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 1853 | public abstract int getPowerSaveModeEnabledCount(int which); |
| 1854 | |
| 1855 | /** |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 1856 | * Constant for device idle mode: not active. |
| 1857 | */ |
| 1858 | public static final int DEVICE_IDLE_MODE_OFF = 0; |
| 1859 | |
| 1860 | /** |
| 1861 | * Constant for device idle mode: active in lightweight mode. |
| 1862 | */ |
| 1863 | public static final int DEVICE_IDLE_MODE_LIGHT = 1; |
| 1864 | |
| 1865 | /** |
| 1866 | * Constant for device idle mode: active in full mode. |
| 1867 | */ |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 1868 | public static final int DEVICE_IDLE_MODE_DEEP = 2; |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 1869 | |
| 1870 | /** |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 1871 | * Returns the time in microseconds that device has been in idle mode while |
| 1872 | * running on battery. |
| 1873 | * |
| 1874 | * {@hide} |
| 1875 | */ |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 1876 | public abstract long getDeviceIdleModeTime(int mode, long elapsedRealtimeUs, int which); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 1877 | |
| 1878 | /** |
| 1879 | * Returns the number of times that the devie has gone in to idle mode. |
| 1880 | * |
| 1881 | * {@hide} |
| 1882 | */ |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 1883 | public abstract int getDeviceIdleModeCount(int mode, int which); |
| 1884 | |
| 1885 | /** |
| 1886 | * Return the longest duration we spent in a particular device idle mode (fully in the |
| 1887 | * mode, not in idle maintenance etc). |
| 1888 | */ |
| 1889 | public abstract long getLongestDeviceIdleModeTime(int mode); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 1890 | |
| 1891 | /** |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 1892 | * 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] | 1893 | * battery. This is broader than {@link #getDeviceIdleModeTime} -- it |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 1894 | * counts all of the time that we consider the device to be idle, whether or not |
| 1895 | * it is currently in the actual device idle mode. |
| 1896 | * |
| 1897 | * {@hide} |
| 1898 | */ |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 1899 | public abstract long getDeviceIdlingTime(int mode, long elapsedRealtimeUs, int which); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 1900 | |
| 1901 | /** |
| 1902 | * Returns the number of times that the devie has started idling. |
| 1903 | * |
| 1904 | * {@hide} |
| 1905 | */ |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 1906 | public abstract int getDeviceIdlingCount(int mode, int which); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 1907 | |
| 1908 | /** |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 1909 | * Returns the number of times that connectivity state changed. |
| 1910 | * |
| 1911 | * {@hide} |
| 1912 | */ |
| 1913 | public abstract int getNumConnectivityChange(int which); |
| 1914 | |
| 1915 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 1916 | * 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] | 1917 | * running on battery. |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 1918 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1919 | * {@hide} |
| 1920 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1921 | public abstract long getPhoneOnTime(long elapsedRealtimeUs, int which); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 1922 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 1923 | /** |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 1924 | * Returns the number of times a phone call was activated. |
| 1925 | * |
| 1926 | * {@hide} |
| 1927 | */ |
| 1928 | public abstract int getPhoneOnCount(int which); |
| 1929 | |
| 1930 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 1931 | * Returns the time in microseconds that the phone has been running with |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 1932 | * the given signal strength. |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 1933 | * |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 1934 | * {@hide} |
| 1935 | */ |
| 1936 | public abstract long getPhoneSignalStrengthTime(int strengthBin, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1937 | long elapsedRealtimeUs, int which); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 1938 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1939 | /** |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 1940 | * Returns the time in microseconds that the phone has been trying to |
| 1941 | * acquire a signal. |
| 1942 | * |
| 1943 | * {@hide} |
| 1944 | */ |
| 1945 | public abstract long getPhoneSignalScanningTime( |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1946 | long elapsedRealtimeUs, int which); |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 1947 | |
| 1948 | /** |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1949 | * Returns the number of times the phone has entered the given signal strength. |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 1950 | * |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1951 | * {@hide} |
| 1952 | */ |
| 1953 | public abstract int getPhoneSignalStrengthCount(int strengthBin, int which); |
| 1954 | |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 1955 | /** |
| 1956 | * Returns the time in microseconds that the mobile network has been active |
| 1957 | * (in a high power state). |
| 1958 | * |
| 1959 | * {@hide} |
| 1960 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1961 | public abstract long getMobileRadioActiveTime(long elapsedRealtimeUs, int which); |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 1962 | |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 1963 | /** |
| 1964 | * Returns the number of times that the mobile network has transitioned to the |
| 1965 | * active state. |
| 1966 | * |
| 1967 | * {@hide} |
| 1968 | */ |
| 1969 | public abstract int getMobileRadioActiveCount(int which); |
| 1970 | |
| 1971 | /** |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1972 | * Returns the time in microseconds that is the difference between the mobile radio |
| 1973 | * time we saw based on the elapsed timestamp when going down vs. the given time stamp |
| 1974 | * from the radio. |
| 1975 | * |
| 1976 | * {@hide} |
| 1977 | */ |
| 1978 | public abstract long getMobileRadioActiveAdjustedTime(int which); |
| 1979 | |
| 1980 | /** |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 1981 | * Returns the time in microseconds that the mobile network has been active |
| 1982 | * (in a high power state) but not being able to blame on an app. |
| 1983 | * |
| 1984 | * {@hide} |
| 1985 | */ |
| 1986 | public abstract long getMobileRadioActiveUnknownTime(int which); |
| 1987 | |
| 1988 | /** |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 1989 | * 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] | 1990 | * |
| 1991 | * {@hide} |
| 1992 | */ |
| 1993 | public abstract int getMobileRadioActiveUnknownCount(int which); |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 1994 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 1995 | public static final int DATA_CONNECTION_NONE = 0; |
| 1996 | public static final int DATA_CONNECTION_GPRS = 1; |
| 1997 | public static final int DATA_CONNECTION_EDGE = 2; |
| 1998 | public static final int DATA_CONNECTION_UMTS = 3; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1999 | public static final int DATA_CONNECTION_CDMA = 4; |
| 2000 | public static final int DATA_CONNECTION_EVDO_0 = 5; |
| 2001 | public static final int DATA_CONNECTION_EVDO_A = 6; |
| 2002 | public static final int DATA_CONNECTION_1xRTT = 7; |
| 2003 | public static final int DATA_CONNECTION_HSDPA = 8; |
| 2004 | public static final int DATA_CONNECTION_HSUPA = 9; |
| 2005 | public static final int DATA_CONNECTION_HSPA = 10; |
| 2006 | public static final int DATA_CONNECTION_IDEN = 11; |
| 2007 | public static final int DATA_CONNECTION_EVDO_B = 12; |
Robert Greenwalt | 962a990 | 2010-11-02 11:10:25 -0700 | [diff] [blame] | 2008 | public static final int DATA_CONNECTION_LTE = 13; |
| 2009 | public static final int DATA_CONNECTION_EHRPD = 14; |
Patrick Tjin | b71703c | 2013-11-06 09:27:03 -0800 | [diff] [blame] | 2010 | public static final int DATA_CONNECTION_HSPAP = 15; |
| 2011 | public static final int DATA_CONNECTION_OTHER = 16; |
Robert Greenwalt | 962a990 | 2010-11-02 11:10:25 -0700 | [diff] [blame] | 2012 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 2013 | static final String[] DATA_CONNECTION_NAMES = { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2014 | "none", "gprs", "edge", "umts", "cdma", "evdo_0", "evdo_A", |
Robert Greenwalt | 962a990 | 2010-11-02 11:10:25 -0700 | [diff] [blame] | 2015 | "1xrtt", "hsdpa", "hsupa", "hspa", "iden", "evdo_b", "lte", |
Patrick Tjin | b71703c | 2013-11-06 09:27:03 -0800 | [diff] [blame] | 2016 | "ehrpd", "hspap", "other" |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 2017 | }; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2018 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2019 | public static final int NUM_DATA_CONNECTION_TYPES = DATA_CONNECTION_OTHER+1; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2020 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 2021 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 2022 | * Returns the time in microseconds that the phone has been running with |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 2023 | * the given data connection. |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2024 | * |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 2025 | * {@hide} |
| 2026 | */ |
| 2027 | public abstract long getPhoneDataConnectionTime(int dataType, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2028 | long elapsedRealtimeUs, int which); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 2029 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2030 | /** |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2031 | * Returns the number of times the phone has entered the given data |
| 2032 | * connection type. |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2033 | * |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2034 | * {@hide} |
| 2035 | */ |
| 2036 | public abstract int getPhoneDataConnectionCount(int dataType, int which); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2037 | |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 2038 | public static final int WIFI_SUPPL_STATE_INVALID = 0; |
| 2039 | public static final int WIFI_SUPPL_STATE_DISCONNECTED = 1; |
| 2040 | public static final int WIFI_SUPPL_STATE_INTERFACE_DISABLED = 2; |
| 2041 | public static final int WIFI_SUPPL_STATE_INACTIVE = 3; |
| 2042 | public static final int WIFI_SUPPL_STATE_SCANNING = 4; |
| 2043 | public static final int WIFI_SUPPL_STATE_AUTHENTICATING = 5; |
| 2044 | public static final int WIFI_SUPPL_STATE_ASSOCIATING = 6; |
| 2045 | public static final int WIFI_SUPPL_STATE_ASSOCIATED = 7; |
| 2046 | public static final int WIFI_SUPPL_STATE_FOUR_WAY_HANDSHAKE = 8; |
| 2047 | public static final int WIFI_SUPPL_STATE_GROUP_HANDSHAKE = 9; |
| 2048 | public static final int WIFI_SUPPL_STATE_COMPLETED = 10; |
| 2049 | public static final int WIFI_SUPPL_STATE_DORMANT = 11; |
| 2050 | public static final int WIFI_SUPPL_STATE_UNINITIALIZED = 12; |
| 2051 | |
| 2052 | public static final int NUM_WIFI_SUPPL_STATES = WIFI_SUPPL_STATE_UNINITIALIZED+1; |
| 2053 | |
| 2054 | static final String[] WIFI_SUPPL_STATE_NAMES = { |
| 2055 | "invalid", "disconn", "disabled", "inactive", "scanning", |
| 2056 | "authenticating", "associating", "associated", "4-way-handshake", |
| 2057 | "group-handshake", "completed", "dormant", "uninit" |
| 2058 | }; |
| 2059 | |
| 2060 | static final String[] WIFI_SUPPL_STATE_SHORT_NAMES = { |
| 2061 | "inv", "dsc", "dis", "inact", "scan", |
| 2062 | "auth", "ascing", "asced", "4-way", |
| 2063 | "group", "compl", "dorm", "uninit" |
| 2064 | }; |
| 2065 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2066 | public static final BitDescription[] HISTORY_STATE_DESCRIPTIONS |
| 2067 | = new BitDescription[] { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2068 | new BitDescription(HistoryItem.STATE_CPU_RUNNING_FLAG, "running", "r"), |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2069 | new BitDescription(HistoryItem.STATE_WAKE_LOCK_FLAG, "wake_lock", "w"), |
| 2070 | new BitDescription(HistoryItem.STATE_SENSOR_ON_FLAG, "sensor", "s"), |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2071 | new BitDescription(HistoryItem.STATE_GPS_ON_FLAG, "gps", "g"), |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2072 | new BitDescription(HistoryItem.STATE_WIFI_FULL_LOCK_FLAG, "wifi_full_lock", "Wl"), |
| 2073 | new BitDescription(HistoryItem.STATE_WIFI_SCAN_FLAG, "wifi_scan", "Ws"), |
| 2074 | new BitDescription(HistoryItem.STATE_WIFI_MULTICAST_ON_FLAG, "wifi_multicast", "Wm"), |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 2075 | new BitDescription(HistoryItem.STATE_WIFI_RADIO_ACTIVE_FLAG, "wifi_radio", "Wr"), |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 2076 | new BitDescription(HistoryItem.STATE_MOBILE_RADIO_ACTIVE_FLAG, "mobile_radio", "Pr"), |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2077 | new BitDescription(HistoryItem.STATE_PHONE_SCANNING_FLAG, "phone_scanning", "Psc"), |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2078 | new BitDescription(HistoryItem.STATE_AUDIO_ON_FLAG, "audio", "a"), |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2079 | new BitDescription(HistoryItem.STATE_SCREEN_ON_FLAG, "screen", "S"), |
| 2080 | new BitDescription(HistoryItem.STATE_BATTERY_PLUGGED_FLAG, "plugged", "BP"), |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2081 | new BitDescription(HistoryItem.STATE_DATA_CONNECTION_MASK, |
| 2082 | HistoryItem.STATE_DATA_CONNECTION_SHIFT, "data_conn", "Pcn", |
| 2083 | DATA_CONNECTION_NAMES, DATA_CONNECTION_NAMES), |
| 2084 | new BitDescription(HistoryItem.STATE_PHONE_STATE_MASK, |
| 2085 | HistoryItem.STATE_PHONE_STATE_SHIFT, "phone_state", "Pst", |
| 2086 | new String[] {"in", "out", "emergency", "off"}, |
| 2087 | new String[] {"in", "out", "em", "off"}), |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 2088 | new BitDescription(HistoryItem.STATE_PHONE_SIGNAL_STRENGTH_MASK, |
| 2089 | HistoryItem.STATE_PHONE_SIGNAL_STRENGTH_SHIFT, "phone_signal_strength", "Pss", |
| 2090 | SignalStrength.SIGNAL_STRENGTH_NAMES, |
| 2091 | new String[] { "0", "1", "2", "3", "4" }), |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2092 | new BitDescription(HistoryItem.STATE_BRIGHTNESS_MASK, |
| 2093 | HistoryItem.STATE_BRIGHTNESS_SHIFT, "brightness", "Sb", |
| 2094 | SCREEN_BRIGHTNESS_NAMES, SCREEN_BRIGHTNESS_SHORT_NAMES), |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2095 | }; |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2096 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2097 | public static final BitDescription[] HISTORY_STATE2_DESCRIPTIONS |
| 2098 | = new BitDescription[] { |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 2099 | new BitDescription(HistoryItem.STATE2_POWER_SAVE_FLAG, "power_save", "ps"), |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 2100 | new BitDescription(HistoryItem.STATE2_VIDEO_ON_FLAG, "video", "v"), |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 2101 | new BitDescription(HistoryItem.STATE2_WIFI_RUNNING_FLAG, "wifi_running", "Ww"), |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 2102 | new BitDescription(HistoryItem.STATE2_WIFI_ON_FLAG, "wifi", "W"), |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 2103 | new BitDescription(HistoryItem.STATE2_FLASHLIGHT_FLAG, "flashlight", "fl"), |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 2104 | new BitDescription(HistoryItem.STATE2_DEVICE_IDLE_MASK, |
| 2105 | HistoryItem.STATE2_DEVICE_IDLE_SHIFT, "device_idle", "di", |
| 2106 | new String[] { "off", "light", "full", "???" }, |
| 2107 | new String[] { "off", "light", "full", "???" }), |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 2108 | new BitDescription(HistoryItem.STATE2_CHARGING_FLAG, "charging", "ch"), |
| 2109 | new BitDescription(HistoryItem.STATE2_PHONE_IN_CALL_FLAG, "phone_in_call", "Pcl"), |
| 2110 | new BitDescription(HistoryItem.STATE2_BLUETOOTH_ON_FLAG, "bluetooth", "b"), |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 2111 | new BitDescription(HistoryItem.STATE2_WIFI_SIGNAL_STRENGTH_MASK, |
| 2112 | HistoryItem.STATE2_WIFI_SIGNAL_STRENGTH_SHIFT, "wifi_signal_strength", "Wss", |
| 2113 | new String[] { "0", "1", "2", "3", "4" }, |
| 2114 | new String[] { "0", "1", "2", "3", "4" }), |
| 2115 | new BitDescription(HistoryItem.STATE2_WIFI_SUPPL_STATE_MASK, |
| 2116 | HistoryItem.STATE2_WIFI_SUPPL_STATE_SHIFT, "wifi_suppl", "Wsp", |
| 2117 | WIFI_SUPPL_STATE_NAMES, WIFI_SUPPL_STATE_SHORT_NAMES), |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 2118 | new BitDescription(HistoryItem.STATE2_CAMERA_FLAG, "camera", "ca"), |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 2119 | new BitDescription(HistoryItem.STATE2_BLUETOOTH_SCAN_FLAG, "ble_scan", "bles"), |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2120 | }; |
| 2121 | |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 2122 | public static final String[] HISTORY_EVENT_NAMES = new String[] { |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 2123 | "null", "proc", "fg", "top", "sync", "wake_lock_in", "job", "user", "userfg", "conn", |
Kweku Adams | 134c59b | 2017-03-08 16:48:01 -0800 | [diff] [blame] | 2124 | "active", "pkginst", "pkgunin", "alarm", "stats", "pkginactive", "pkgactive", |
| 2125 | "tmpwhitelist", "screenwake", "wakeupap", "longwake", "est_capacity" |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 2126 | }; |
| 2127 | |
| 2128 | public static final String[] HISTORY_EVENT_CHECKIN_NAMES = new String[] { |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 2129 | "Enl", "Epr", "Efg", "Etp", "Esy", "Ewl", "Ejb", "Eur", "Euf", "Ecn", |
Dianne Hackborn | 280a64e | 2015-07-13 14:48:08 -0700 | [diff] [blame] | 2130 | "Eac", "Epi", "Epu", "Eal", "Est", "Eai", "Eaa", "Etw", |
Adam Lesinski | 041d917 | 2016-12-12 12:03:56 -0800 | [diff] [blame] | 2131 | "Esw", "Ewa", "Elw", "Eec" |
| 2132 | }; |
| 2133 | |
| 2134 | @FunctionalInterface |
| 2135 | public interface IntToString { |
| 2136 | String applyAsString(int val); |
| 2137 | } |
| 2138 | |
| 2139 | private static final IntToString sUidToString = UserHandle::formatUid; |
| 2140 | private static final IntToString sIntToString = Integer::toString; |
| 2141 | |
| 2142 | public static final IntToString[] HISTORY_EVENT_INT_FORMATTERS = new IntToString[] { |
| 2143 | sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, |
| 2144 | sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, |
| 2145 | sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, |
| 2146 | sUidToString, sUidToString, sUidToString, sIntToString |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 2147 | }; |
| 2148 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2149 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 2150 | * 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] | 2151 | * running on battery. |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2152 | * |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2153 | * {@hide} |
| 2154 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2155 | public abstract long getWifiOnTime(long elapsedRealtimeUs, int which); |
Eric Shienbrood | d4c5f89 | 2009-03-24 18:13:20 -0700 | [diff] [blame] | 2156 | |
| 2157 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 2158 | * 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] | 2159 | * been in the running state while the device was running on battery. |
| 2160 | * |
| 2161 | * {@hide} |
| 2162 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2163 | public abstract long getGlobalWifiRunningTime(long elapsedRealtimeUs, int which); |
Eric Shienbrood | d4c5f89 | 2009-03-24 18:13:20 -0700 | [diff] [blame] | 2164 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 2165 | public static final int WIFI_STATE_OFF = 0; |
| 2166 | public static final int WIFI_STATE_OFF_SCANNING = 1; |
| 2167 | public static final int WIFI_STATE_ON_NO_NETWORKS = 2; |
| 2168 | public static final int WIFI_STATE_ON_DISCONNECTED = 3; |
| 2169 | public static final int WIFI_STATE_ON_CONNECTED_STA = 4; |
| 2170 | public static final int WIFI_STATE_ON_CONNECTED_P2P = 5; |
| 2171 | public static final int WIFI_STATE_ON_CONNECTED_STA_P2P = 6; |
| 2172 | public static final int WIFI_STATE_SOFT_AP = 7; |
| 2173 | |
| 2174 | static final String[] WIFI_STATE_NAMES = { |
| 2175 | "off", "scanning", "no_net", "disconn", |
| 2176 | "sta", "p2p", "sta_p2p", "soft_ap" |
| 2177 | }; |
| 2178 | |
| 2179 | public static final int NUM_WIFI_STATES = WIFI_STATE_SOFT_AP+1; |
| 2180 | |
| 2181 | /** |
| 2182 | * Returns the time in microseconds that WiFi has been running in the given state. |
| 2183 | * |
| 2184 | * {@hide} |
| 2185 | */ |
| 2186 | public abstract long getWifiStateTime(int wifiState, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2187 | long elapsedRealtimeUs, int which); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 2188 | |
| 2189 | /** |
| 2190 | * Returns the number of times that WiFi has entered the given state. |
| 2191 | * |
| 2192 | * {@hide} |
| 2193 | */ |
| 2194 | public abstract int getWifiStateCount(int wifiState, int which); |
| 2195 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2196 | /** |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 2197 | * Returns the time in microseconds that the wifi supplicant has been |
| 2198 | * in a given state. |
| 2199 | * |
| 2200 | * {@hide} |
| 2201 | */ |
| 2202 | public abstract long getWifiSupplStateTime(int state, long elapsedRealtimeUs, int which); |
| 2203 | |
| 2204 | /** |
| 2205 | * Returns the number of times that the wifi supplicant has transitioned |
| 2206 | * to a given state. |
| 2207 | * |
| 2208 | * {@hide} |
| 2209 | */ |
| 2210 | public abstract int getWifiSupplStateCount(int state, int which); |
| 2211 | |
| 2212 | public static final int NUM_WIFI_SIGNAL_STRENGTH_BINS = 5; |
| 2213 | |
| 2214 | /** |
| 2215 | * Returns the time in microseconds that WIFI has been running with |
| 2216 | * the given signal strength. |
| 2217 | * |
| 2218 | * {@hide} |
| 2219 | */ |
| 2220 | public abstract long getWifiSignalStrengthTime(int strengthBin, |
| 2221 | long elapsedRealtimeUs, int which); |
| 2222 | |
| 2223 | /** |
| 2224 | * Returns the number of times WIFI has entered the given signal strength. |
| 2225 | * |
| 2226 | * {@hide} |
| 2227 | */ |
| 2228 | public abstract int getWifiSignalStrengthCount(int strengthBin, int which); |
| 2229 | |
| 2230 | /** |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 2231 | * Returns the time in microseconds that the flashlight has been on while the device was |
| 2232 | * running on battery. |
| 2233 | * |
| 2234 | * {@hide} |
| 2235 | */ |
| 2236 | public abstract long getFlashlightOnTime(long elapsedRealtimeUs, int which); |
| 2237 | |
| 2238 | /** |
| 2239 | * Returns the number of times that the flashlight has been turned on while the device was |
| 2240 | * running on battery. |
| 2241 | * |
| 2242 | * {@hide} |
| 2243 | */ |
| 2244 | public abstract long getFlashlightOnCount(int which); |
| 2245 | |
Ruben Brunk | 5b1308f | 2015-06-03 18:49:27 -0700 | [diff] [blame] | 2246 | /** |
| 2247 | * Returns the time in microseconds that the camera has been on while the device was |
| 2248 | * running on battery. |
| 2249 | * |
| 2250 | * {@hide} |
| 2251 | */ |
| 2252 | public abstract long getCameraOnTime(long elapsedRealtimeUs, int which); |
| 2253 | |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 2254 | /** |
| 2255 | * Returns the time in microseconds that bluetooth scans were running while the device was |
| 2256 | * on battery. |
| 2257 | * |
| 2258 | * {@hide} |
| 2259 | */ |
| 2260 | public abstract long getBluetoothScanTime(long elapsedRealtimeUs, int which); |
Ruben Brunk | 5b1308f | 2015-06-03 18:49:27 -0700 | [diff] [blame] | 2261 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2262 | public static final int NETWORK_MOBILE_RX_DATA = 0; |
| 2263 | public static final int NETWORK_MOBILE_TX_DATA = 1; |
| 2264 | public static final int NETWORK_WIFI_RX_DATA = 2; |
| 2265 | public static final int NETWORK_WIFI_TX_DATA = 3; |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 2266 | public static final int NETWORK_BT_RX_DATA = 4; |
| 2267 | public static final int NETWORK_BT_TX_DATA = 5; |
Amith Yamasani | 59fe841 | 2017-03-03 16:28:52 -0800 | [diff] [blame] | 2268 | public static final int NETWORK_MOBILE_BG_RX_DATA = 6; |
| 2269 | public static final int NETWORK_MOBILE_BG_TX_DATA = 7; |
| 2270 | public static final int NETWORK_WIFI_BG_RX_DATA = 8; |
| 2271 | public static final int NETWORK_WIFI_BG_TX_DATA = 9; |
| 2272 | 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] | 2273 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2274 | public abstract long getNetworkActivityBytes(int type, int which); |
| 2275 | public abstract long getNetworkActivityPackets(int type, int which); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 2276 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 2277 | /** |
Adam Lesinski | 1739076 | 2015-04-10 13:17:47 -0700 | [diff] [blame] | 2278 | * Returns true if the BatteryStats object has detailed WiFi power reports. |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 2279 | * When true, calling {@link #getWifiControllerActivity()} will yield the |
Adam Lesinski | 1739076 | 2015-04-10 13:17:47 -0700 | [diff] [blame] | 2280 | * actual power data. |
| 2281 | */ |
| 2282 | public abstract boolean hasWifiActivityReporting(); |
| 2283 | |
| 2284 | /** |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 2285 | * Returns a {@link ControllerActivityCounter} which is an aggregate of the times spent |
| 2286 | * in various radio controller states, such as transmit, receive, and idle. |
| 2287 | * @return non-null {@link ControllerActivityCounter} |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 2288 | */ |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 2289 | public abstract ControllerActivityCounter getWifiControllerActivity(); |
| 2290 | |
| 2291 | /** |
| 2292 | * Returns true if the BatteryStats object has detailed bluetooth power reports. |
| 2293 | * When true, calling {@link #getBluetoothControllerActivity()} will yield the |
| 2294 | * actual power data. |
| 2295 | */ |
| 2296 | public abstract boolean hasBluetoothActivityReporting(); |
| 2297 | |
| 2298 | /** |
| 2299 | * Returns a {@link ControllerActivityCounter} which is an aggregate of the times spent |
| 2300 | * in various radio controller states, such as transmit, receive, and idle. |
| 2301 | * @return non-null {@link ControllerActivityCounter} |
| 2302 | */ |
| 2303 | public abstract ControllerActivityCounter getBluetoothControllerActivity(); |
| 2304 | |
| 2305 | /** |
| 2306 | * Returns true if the BatteryStats object has detailed modem power reports. |
| 2307 | * When true, calling {@link #getModemControllerActivity()} will yield the |
| 2308 | * actual power data. |
| 2309 | */ |
| 2310 | public abstract boolean hasModemActivityReporting(); |
| 2311 | |
| 2312 | /** |
| 2313 | * Returns a {@link ControllerActivityCounter} which is an aggregate of the times spent |
| 2314 | * in various radio controller states, such as transmit, receive, and idle. |
| 2315 | * @return non-null {@link ControllerActivityCounter} |
| 2316 | */ |
| 2317 | public abstract ControllerActivityCounter getModemControllerActivity(); |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 2318 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2319 | /** |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 2320 | * Return the wall clock time when battery stats data collection started. |
| 2321 | */ |
| 2322 | public abstract long getStartClockTime(); |
| 2323 | |
| 2324 | /** |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 2325 | * Return platform version tag that we were running in when the battery stats started. |
| 2326 | */ |
| 2327 | public abstract String getStartPlatformVersion(); |
| 2328 | |
| 2329 | /** |
| 2330 | * Return platform version tag that we were running in when the battery stats ended. |
| 2331 | */ |
| 2332 | public abstract String getEndPlatformVersion(); |
| 2333 | |
| 2334 | /** |
| 2335 | * Return the internal version code of the parcelled format. |
| 2336 | */ |
| 2337 | public abstract int getParcelVersion(); |
| 2338 | |
| 2339 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2340 | * Return whether we are currently running on battery. |
| 2341 | */ |
| 2342 | public abstract boolean getIsOnBattery(); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2343 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2344 | /** |
| 2345 | * Returns a SparseArray containing the statistics for each uid. |
| 2346 | */ |
| 2347 | public abstract SparseArray<? extends Uid> getUidStats(); |
| 2348 | |
| 2349 | /** |
| 2350 | * Returns the current battery uptime in microseconds. |
| 2351 | * |
| 2352 | * @param curTime the amount of elapsed realtime in microseconds. |
| 2353 | */ |
| 2354 | public abstract long getBatteryUptime(long curTime); |
| 2355 | |
| 2356 | /** |
| 2357 | * Returns the current battery realtime in microseconds. |
| 2358 | * |
| 2359 | * @param curTime the amount of elapsed realtime in microseconds. |
| 2360 | */ |
| 2361 | public abstract long getBatteryRealtime(long curTime); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2362 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2363 | /** |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 2364 | * 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] | 2365 | * the last time it booted on battery power. |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2366 | */ |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 2367 | public abstract int getDischargeStartLevel(); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2368 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2369 | /** |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 2370 | * Returns the current battery percentage level if we are in a discharge cycle, otherwise |
| 2371 | * returns the level at the last plug event. |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2372 | */ |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 2373 | public abstract int getDischargeCurrentLevel(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2374 | |
| 2375 | /** |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 2376 | * Get the amount the battery has discharged since the stats were |
| 2377 | * last reset after charging, as a lower-end approximation. |
| 2378 | */ |
| 2379 | public abstract int getLowDischargeAmountSinceCharge(); |
| 2380 | |
| 2381 | /** |
| 2382 | * Get the amount the battery has discharged since the stats were |
| 2383 | * last reset after charging, as an upper-end approximation. |
| 2384 | */ |
| 2385 | public abstract int getHighDischargeAmountSinceCharge(); |
| 2386 | |
| 2387 | /** |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2388 | * Retrieve the discharge amount over the selected discharge period <var>which</var>. |
| 2389 | */ |
| 2390 | public abstract int getDischargeAmount(int which); |
| 2391 | |
| 2392 | /** |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 2393 | * Get the amount the battery has discharged while the screen was on, |
| 2394 | * since the last time power was unplugged. |
| 2395 | */ |
| 2396 | public abstract int getDischargeAmountScreenOn(); |
| 2397 | |
| 2398 | /** |
| 2399 | * Get the amount the battery has discharged while the screen was on, |
| 2400 | * since the last time the device was charged. |
| 2401 | */ |
| 2402 | public abstract int getDischargeAmountScreenOnSinceCharge(); |
| 2403 | |
| 2404 | /** |
| 2405 | * Get the amount the battery has discharged while the screen was off, |
| 2406 | * since the last time power was unplugged. |
| 2407 | */ |
| 2408 | public abstract int getDischargeAmountScreenOff(); |
| 2409 | |
| 2410 | /** |
| 2411 | * Get the amount the battery has discharged while the screen was off, |
| 2412 | * since the last time the device was charged. |
| 2413 | */ |
| 2414 | public abstract int getDischargeAmountScreenOffSinceCharge(); |
| 2415 | |
| 2416 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2417 | * Returns the total, last, or current battery uptime in microseconds. |
| 2418 | * |
| 2419 | * @param curTime the elapsed realtime in microseconds. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2420 | * @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] | 2421 | */ |
| 2422 | public abstract long computeBatteryUptime(long curTime, int which); |
| 2423 | |
| 2424 | /** |
| 2425 | * Returns the total, last, or current battery realtime in microseconds. |
| 2426 | * |
| 2427 | * @param curTime the current elapsed realtime in microseconds. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2428 | * @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] | 2429 | */ |
| 2430 | public abstract long computeBatteryRealtime(long curTime, int which); |
| 2431 | |
| 2432 | /** |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2433 | * Returns the total, last, or current battery screen off uptime in microseconds. |
| 2434 | * |
| 2435 | * @param curTime the elapsed realtime in microseconds. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2436 | * @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] | 2437 | */ |
| 2438 | public abstract long computeBatteryScreenOffUptime(long curTime, int which); |
| 2439 | |
| 2440 | /** |
| 2441 | * Returns the total, last, or current battery screen off realtime in microseconds. |
| 2442 | * |
| 2443 | * @param curTime the current elapsed realtime in microseconds. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2444 | * @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] | 2445 | */ |
| 2446 | public abstract long computeBatteryScreenOffRealtime(long curTime, int which); |
| 2447 | |
| 2448 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2449 | * Returns the total, last, or current uptime in microseconds. |
| 2450 | * |
| 2451 | * @param curTime the current elapsed realtime in microseconds. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2452 | * @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] | 2453 | */ |
| 2454 | public abstract long computeUptime(long curTime, int which); |
| 2455 | |
| 2456 | /** |
| 2457 | * Returns the total, last, or current realtime in microseconds. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2458 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2459 | * @param curTime the current elapsed realtime in microseconds. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2460 | * @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] | 2461 | */ |
| 2462 | public abstract long computeRealtime(long curTime, int which); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2463 | |
| 2464 | /** |
| 2465 | * Compute an approximation for how much run time (in microseconds) is remaining on |
| 2466 | * the battery. Returns -1 if no time can be computed: either there is not |
| 2467 | * enough current data to make a decision, or the battery is currently |
| 2468 | * charging. |
| 2469 | * |
| 2470 | * @param curTime The current elepsed realtime in microseconds. |
| 2471 | */ |
| 2472 | public abstract long computeBatteryTimeRemaining(long curTime); |
| 2473 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 2474 | // The part of a step duration that is the actual time. |
| 2475 | public static final long STEP_LEVEL_TIME_MASK = 0x000000ffffffffffL; |
| 2476 | |
| 2477 | // Bits in a step duration that are the new battery level we are at. |
| 2478 | public static final long STEP_LEVEL_LEVEL_MASK = 0x0000ff0000000000L; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2479 | public static final int STEP_LEVEL_LEVEL_SHIFT = 40; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 2480 | |
| 2481 | // Bits in a step duration that are the initial mode we were in at that step. |
| 2482 | public static final long STEP_LEVEL_INITIAL_MODE_MASK = 0x00ff000000000000L; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2483 | public static final int STEP_LEVEL_INITIAL_MODE_SHIFT = 48; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 2484 | |
| 2485 | // Bits in a step duration that indicate which modes changed during that step. |
| 2486 | public static final long STEP_LEVEL_MODIFIED_MODE_MASK = 0xff00000000000000L; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2487 | public static final int STEP_LEVEL_MODIFIED_MODE_SHIFT = 56; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 2488 | |
| 2489 | // Step duration mode: the screen is on, off, dozed, etc; value is Display.STATE_* - 1. |
| 2490 | public static final int STEP_LEVEL_MODE_SCREEN_STATE = 0x03; |
| 2491 | |
Santos Cordon | e94f050 | 2017-02-24 12:31:20 -0800 | [diff] [blame] | 2492 | // The largest value for screen state that is tracked in battery states. Any values above |
| 2493 | // this should be mapped back to one of the tracked values before being tracked here. |
| 2494 | public static final int MAX_TRACKED_SCREEN_STATE = Display.STATE_DOZE_SUSPEND; |
| 2495 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 2496 | // Step duration mode: power save is on. |
| 2497 | public static final int STEP_LEVEL_MODE_POWER_SAVE = 0x04; |
| 2498 | |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2499 | // Step duration mode: device is currently in idle mode. |
| 2500 | public static final int STEP_LEVEL_MODE_DEVICE_IDLE = 0x08; |
| 2501 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2502 | public static final int[] STEP_LEVEL_MODES_OF_INTEREST = new int[] { |
| 2503 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE, |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2504 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE|STEP_LEVEL_MODE_DEVICE_IDLE, |
| 2505 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_DEVICE_IDLE, |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2506 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE, |
| 2507 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE, |
| 2508 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE, |
| 2509 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE, |
| 2510 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE, |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2511 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE|STEP_LEVEL_MODE_DEVICE_IDLE, |
| 2512 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_DEVICE_IDLE, |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2513 | }; |
| 2514 | public static final int[] STEP_LEVEL_MODE_VALUES = new int[] { |
| 2515 | (Display.STATE_OFF-1), |
| 2516 | (Display.STATE_OFF-1)|STEP_LEVEL_MODE_POWER_SAVE, |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2517 | (Display.STATE_OFF-1)|STEP_LEVEL_MODE_DEVICE_IDLE, |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2518 | (Display.STATE_ON-1), |
| 2519 | (Display.STATE_ON-1)|STEP_LEVEL_MODE_POWER_SAVE, |
| 2520 | (Display.STATE_DOZE-1), |
| 2521 | (Display.STATE_DOZE-1)|STEP_LEVEL_MODE_POWER_SAVE, |
| 2522 | (Display.STATE_DOZE_SUSPEND-1), |
| 2523 | (Display.STATE_DOZE_SUSPEND-1)|STEP_LEVEL_MODE_POWER_SAVE, |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2524 | (Display.STATE_DOZE_SUSPEND-1)|STEP_LEVEL_MODE_DEVICE_IDLE, |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2525 | }; |
| 2526 | public static final String[] STEP_LEVEL_MODE_LABELS = new String[] { |
| 2527 | "screen off", |
| 2528 | "screen off power save", |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2529 | "screen off device idle", |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2530 | "screen on", |
| 2531 | "screen on power save", |
| 2532 | "screen doze", |
| 2533 | "screen doze power save", |
| 2534 | "screen doze-suspend", |
| 2535 | "screen doze-suspend power save", |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2536 | "screen doze-suspend device idle", |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2537 | }; |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 2538 | |
| 2539 | /** |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 2540 | * Return the counter keeping track of the amount of battery discharge while the screen was off, |
| 2541 | * measured in micro-Ampere-hours. This will be non-zero only if the device's battery has |
| 2542 | * a coulomb counter. |
| 2543 | */ |
| 2544 | public abstract LongCounter getDischargeScreenOffCoulombCounter(); |
| 2545 | |
| 2546 | /** |
| 2547 | * Return the counter keeping track of the amount of battery discharge measured in |
| 2548 | * micro-Ampere-hours. This will be non-zero only if the device's battery has |
| 2549 | * a coulomb counter. |
| 2550 | */ |
| 2551 | public abstract LongCounter getDischargeCoulombCounter(); |
| 2552 | |
| 2553 | /** |
Adam Lesinski | f9b20a9 | 2016-06-17 17:30:01 -0700 | [diff] [blame] | 2554 | * Returns the estimated real battery capacity, which may be less than the capacity |
| 2555 | * declared by the PowerProfile. |
| 2556 | * @return The estimated battery capacity in mAh. |
| 2557 | */ |
| 2558 | public abstract int getEstimatedBatteryCapacity(); |
| 2559 | |
| 2560 | /** |
Jocelyn Dang | c627d10 | 2017-04-14 13:15:14 -0700 | [diff] [blame] | 2561 | * @return The minimum learned battery capacity in uAh. |
| 2562 | */ |
| 2563 | public abstract int getMinLearnedBatteryCapacity(); |
| 2564 | |
| 2565 | /** |
| 2566 | * @return The maximum learned battery capacity in uAh. |
| 2567 | */ |
| 2568 | public abstract int getMaxLearnedBatteryCapacity() ; |
| 2569 | |
| 2570 | /** |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2571 | * Return the array of discharge step durations. |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 2572 | */ |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2573 | public abstract LevelStepTracker getDischargeLevelStepTracker(); |
| 2574 | |
| 2575 | /** |
| 2576 | * Return the array of daily discharge step durations. |
| 2577 | */ |
| 2578 | public abstract LevelStepTracker getDailyDischargeLevelStepTracker(); |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 2579 | |
| 2580 | /** |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2581 | * Compute an approximation for how much time (in microseconds) remains until the battery |
| 2582 | * is fully charged. Returns -1 if no time can be computed: either there is not |
| 2583 | * enough current data to make a decision, or the battery is currently |
| 2584 | * discharging. |
| 2585 | * |
| 2586 | * @param curTime The current elepsed realtime in microseconds. |
| 2587 | */ |
| 2588 | public abstract long computeChargeTimeRemaining(long curTime); |
| 2589 | |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 2590 | /** |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2591 | * Return the array of charge step durations. |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 2592 | */ |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2593 | public abstract LevelStepTracker getChargeLevelStepTracker(); |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 2594 | |
| 2595 | /** |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2596 | * Return the array of daily charge step durations. |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 2597 | */ |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2598 | public abstract LevelStepTracker getDailyChargeLevelStepTracker(); |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 2599 | |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2600 | public abstract ArrayList<PackageChange> getDailyPackageChanges(); |
| 2601 | |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 2602 | public abstract Map<String, ? extends Timer> getWakeupReasonStats(); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2603 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2604 | public abstract Map<String, ? extends Timer> getKernelWakelockStats(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2605 | |
James Carr | 2dd7e5e | 2016-07-20 18:48:39 -0700 | [diff] [blame] | 2606 | public abstract LongSparseArray<? extends Timer> getKernelMemoryStats(); |
| 2607 | |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 2608 | public abstract void writeToParcelWithoutUids(Parcel out, int flags); |
| 2609 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 2610 | private final static void formatTimeRaw(StringBuilder out, long seconds) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2611 | long days = seconds / (60 * 60 * 24); |
| 2612 | if (days != 0) { |
| 2613 | out.append(days); |
| 2614 | out.append("d "); |
| 2615 | } |
| 2616 | long used = days * 60 * 60 * 24; |
| 2617 | |
| 2618 | long hours = (seconds - used) / (60 * 60); |
| 2619 | if (hours != 0 || used != 0) { |
| 2620 | out.append(hours); |
| 2621 | out.append("h "); |
| 2622 | } |
| 2623 | used += hours * 60 * 60; |
| 2624 | |
| 2625 | long mins = (seconds-used) / 60; |
| 2626 | if (mins != 0 || used != 0) { |
| 2627 | out.append(mins); |
| 2628 | out.append("m "); |
| 2629 | } |
| 2630 | used += mins * 60; |
| 2631 | |
| 2632 | if (seconds != 0 || used != 0) { |
| 2633 | out.append(seconds-used); |
| 2634 | out.append("s "); |
| 2635 | } |
| 2636 | } |
| 2637 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2638 | public final static void formatTimeMs(StringBuilder sb, long time) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2639 | long sec = time / 1000; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 2640 | formatTimeRaw(sb, sec); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2641 | sb.append(time - (sec * 1000)); |
| 2642 | sb.append("ms "); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2643 | } |
| 2644 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2645 | public final static void formatTimeMsNoSpace(StringBuilder sb, long time) { |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 2646 | long sec = time / 1000; |
| 2647 | formatTimeRaw(sb, sec); |
| 2648 | sb.append(time - (sec * 1000)); |
| 2649 | sb.append("ms"); |
| 2650 | } |
| 2651 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2652 | public final String formatRatioLocked(long num, long den) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2653 | if (den == 0L) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2654 | return "--%"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2655 | } |
| 2656 | float perc = ((float)num) / ((float)den) * 100; |
| 2657 | mFormatBuilder.setLength(0); |
| 2658 | mFormatter.format("%.1f%%", perc); |
| 2659 | return mFormatBuilder.toString(); |
| 2660 | } |
| 2661 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2662 | final String formatBytesLocked(long bytes) { |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 2663 | mFormatBuilder.setLength(0); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2664 | |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 2665 | if (bytes < BYTES_PER_KB) { |
| 2666 | return bytes + "B"; |
| 2667 | } else if (bytes < BYTES_PER_MB) { |
| 2668 | mFormatter.format("%.2fKB", bytes / (double) BYTES_PER_KB); |
| 2669 | return mFormatBuilder.toString(); |
| 2670 | } else if (bytes < BYTES_PER_GB){ |
| 2671 | mFormatter.format("%.2fMB", bytes / (double) BYTES_PER_MB); |
| 2672 | return mFormatBuilder.toString(); |
| 2673 | } else { |
| 2674 | mFormatter.format("%.2fGB", bytes / (double) BYTES_PER_GB); |
| 2675 | return mFormatBuilder.toString(); |
| 2676 | } |
| 2677 | } |
| 2678 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2679 | private static long computeWakeLock(Timer timer, long elapsedRealtimeUs, int which) { |
Dianne Hackborn | c24ab86 | 2011-10-18 15:55:03 -0700 | [diff] [blame] | 2680 | if (timer != null) { |
| 2681 | // Convert from microseconds to milliseconds with rounding |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2682 | long totalTimeMicros = timer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Dianne Hackborn | c24ab86 | 2011-10-18 15:55:03 -0700 | [diff] [blame] | 2683 | long totalTimeMillis = (totalTimeMicros + 500) / 1000; |
| 2684 | return totalTimeMillis; |
| 2685 | } |
| 2686 | return 0; |
| 2687 | } |
| 2688 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2689 | /** |
| 2690 | * |
| 2691 | * @param sb a StringBuilder object. |
| 2692 | * @param timer a Timer object contining the wakelock times. |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2693 | * @param elapsedRealtimeUs the current on-battery time in microseconds. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2694 | * @param name the name of the wakelock. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2695 | * @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] | 2696 | * @param linePrefix a String to be prepended to each line of output. |
| 2697 | * @return the line prefix |
| 2698 | */ |
| 2699 | private static final String printWakeLock(StringBuilder sb, Timer timer, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2700 | long elapsedRealtimeUs, String name, int which, String linePrefix) { |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 2701 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2702 | if (timer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2703 | long totalTimeMillis = computeWakeLock(timer, elapsedRealtimeUs, which); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 2704 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2705 | int count = timer.getCountLocked(which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2706 | if (totalTimeMillis != 0) { |
| 2707 | sb.append(linePrefix); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 2708 | formatTimeMs(sb, totalTimeMillis); |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 2709 | if (name != null) { |
| 2710 | sb.append(name); |
| 2711 | sb.append(' '); |
| 2712 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2713 | sb.append('('); |
| 2714 | sb.append(count); |
| 2715 | sb.append(" times)"); |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2716 | final long maxDurationMs = timer.getMaxDurationMsLocked(elapsedRealtimeUs/1000); |
| 2717 | if (maxDurationMs >= 0) { |
| 2718 | sb.append(" max="); |
| 2719 | sb.append(maxDurationMs); |
| 2720 | } |
Bookatz | 506a818 | 2017-05-01 14:18:42 -0700 | [diff] [blame] | 2721 | // Put actual time if it is available and different from totalTimeMillis. |
| 2722 | final long totalDurMs = timer.getTotalDurationMsLocked(elapsedRealtimeUs/1000); |
| 2723 | if (totalDurMs > totalTimeMillis) { |
| 2724 | sb.append(" actual="); |
| 2725 | sb.append(totalDurMs); |
| 2726 | } |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2727 | if (timer.isRunningLocked()) { |
| 2728 | final long currentMs = timer.getCurrentDurationMsLocked(elapsedRealtimeUs/1000); |
| 2729 | if (currentMs >= 0) { |
| 2730 | sb.append(" (running for "); |
| 2731 | sb.append(currentMs); |
| 2732 | sb.append("ms)"); |
| 2733 | } else { |
| 2734 | sb.append(" (running)"); |
| 2735 | } |
| 2736 | } |
| 2737 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2738 | return ", "; |
| 2739 | } |
| 2740 | } |
| 2741 | return linePrefix; |
| 2742 | } |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 2743 | |
| 2744 | /** |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2745 | * 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] | 2746 | * |
| 2747 | * @param pw a PrintWriter object to print to. |
| 2748 | * @param sb a StringBuilder object. |
| 2749 | * @param timer a Timer object contining the wakelock times. |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2750 | * @param rawRealtimeUs the current on-battery time in microseconds. |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 2751 | * @param which which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT. |
| 2752 | * @param prefix a String to be prepended to each line of output. |
| 2753 | * @param type the name of the timer. |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2754 | * @return true if anything was printed. |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 2755 | */ |
| 2756 | private static final boolean printTimer(PrintWriter pw, StringBuilder sb, Timer timer, |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2757 | long rawRealtimeUs, int which, String prefix, String type) { |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 2758 | if (timer != null) { |
| 2759 | // Convert from microseconds to milliseconds with rounding |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2760 | final long totalTimeMs = (timer.getTotalTimeLocked( |
| 2761 | rawRealtimeUs, which) + 500) / 1000; |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 2762 | final int count = timer.getCountLocked(which); |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2763 | if (totalTimeMs != 0) { |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 2764 | sb.setLength(0); |
| 2765 | sb.append(prefix); |
| 2766 | sb.append(" "); |
| 2767 | sb.append(type); |
| 2768 | sb.append(": "); |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2769 | formatTimeMs(sb, totalTimeMs); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 2770 | sb.append("realtime ("); |
| 2771 | sb.append(count); |
| 2772 | sb.append(" times)"); |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2773 | final long maxDurationMs = timer.getMaxDurationMsLocked(rawRealtimeUs/1000); |
| 2774 | if (maxDurationMs >= 0) { |
| 2775 | sb.append(" max="); |
| 2776 | sb.append(maxDurationMs); |
| 2777 | } |
| 2778 | if (timer.isRunningLocked()) { |
| 2779 | final long currentMs = timer.getCurrentDurationMsLocked(rawRealtimeUs/1000); |
| 2780 | if (currentMs >= 0) { |
| 2781 | sb.append(" (running for "); |
| 2782 | sb.append(currentMs); |
| 2783 | sb.append("ms)"); |
| 2784 | } else { |
| 2785 | sb.append(" (running)"); |
| 2786 | } |
| 2787 | } |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 2788 | pw.println(sb.toString()); |
| 2789 | return true; |
| 2790 | } |
| 2791 | } |
| 2792 | return false; |
| 2793 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2794 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2795 | /** |
| 2796 | * Checkin version of wakelock printer. Prints simple comma-separated list. |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2797 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2798 | * @param sb a StringBuilder object. |
| 2799 | * @param timer a Timer object contining the wakelock times. |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2800 | * @param elapsedRealtimeUs the current time in microseconds. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2801 | * @param name the name of the wakelock. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2802 | * @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] | 2803 | * @param linePrefix a String to be prepended to each line of output. |
| 2804 | * @return the line prefix |
| 2805 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2806 | private static final String printWakeLockCheckin(StringBuilder sb, Timer timer, |
| 2807 | long elapsedRealtimeUs, String name, int which, String linePrefix) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2808 | long totalTimeMicros = 0; |
| 2809 | int count = 0; |
Bookatz | 941d98f | 2017-05-02 19:25:18 -0700 | [diff] [blame] | 2810 | long max = 0; |
| 2811 | long current = 0; |
| 2812 | long totalDuration = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2813 | if (timer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2814 | totalTimeMicros = timer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Bookatz | 506a818 | 2017-05-01 14:18:42 -0700 | [diff] [blame] | 2815 | count = timer.getCountLocked(which); |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2816 | current = timer.getCurrentDurationMsLocked(elapsedRealtimeUs/1000); |
| 2817 | max = timer.getMaxDurationMsLocked(elapsedRealtimeUs/1000); |
Bookatz | 506a818 | 2017-05-01 14:18:42 -0700 | [diff] [blame] | 2818 | totalDuration = timer.getTotalDurationMsLocked(elapsedRealtimeUs/1000); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2819 | } |
| 2820 | sb.append(linePrefix); |
| 2821 | sb.append((totalTimeMicros + 500) / 1000); // microseconds to milliseconds with rounding |
| 2822 | sb.append(','); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2823 | sb.append(name != null ? name + "," : ""); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2824 | sb.append(count); |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2825 | sb.append(','); |
| 2826 | sb.append(current); |
| 2827 | sb.append(','); |
| 2828 | sb.append(max); |
Bookatz | 506a818 | 2017-05-01 14:18:42 -0700 | [diff] [blame] | 2829 | // Partial, full, and window wakelocks are pooled, so totalDuration is meaningful (albeit |
| 2830 | // not always tracked). Kernel wakelocks (which have name == null) have no notion of |
| 2831 | // totalDuration independent of totalTimeMicros (since they are not pooled). |
| 2832 | if (name != null) { |
| 2833 | sb.append(','); |
| 2834 | sb.append(totalDuration); |
| 2835 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2836 | return ","; |
| 2837 | } |
Bookatz | 506a818 | 2017-05-01 14:18:42 -0700 | [diff] [blame] | 2838 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 2839 | private static final void dumpLineHeader(PrintWriter pw, int uid, String category, |
| 2840 | String type) { |
| 2841 | pw.print(BATTERY_STATS_CHECKIN_VERSION); |
| 2842 | pw.print(','); |
| 2843 | pw.print(uid); |
| 2844 | pw.print(','); |
| 2845 | pw.print(category); |
| 2846 | pw.print(','); |
| 2847 | pw.print(type); |
| 2848 | } |
| 2849 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2850 | /** |
| 2851 | * Dump a comma-separated line of values for terse checkin mode. |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2852 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2853 | * @param pw the PageWriter to dump log to |
| 2854 | * @param category category of data (e.g. "total", "last", "unplugged", "current" ) |
| 2855 | * @param type type of data (e.g. "wakelock", "sensor", "process", "apk" , "process", "network") |
| 2856 | * @param args type-dependent data arguments |
| 2857 | */ |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 2858 | 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] | 2859 | Object... args ) { |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 2860 | dumpLineHeader(pw, uid, category, type); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 2861 | for (Object arg : args) { |
Dianne Hackborn | 13ac041 | 2013-06-25 19:34:49 -0700 | [diff] [blame] | 2862 | pw.print(','); |
| 2863 | pw.print(arg); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2864 | } |
Dianne Hackborn | 13ac041 | 2013-06-25 19:34:49 -0700 | [diff] [blame] | 2865 | pw.println(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2866 | } |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 2867 | |
| 2868 | /** |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 2869 | * Dump a given timer stat for terse checkin mode. |
| 2870 | * |
| 2871 | * @param pw the PageWriter to dump log to |
| 2872 | * @param uid the UID to log |
| 2873 | * @param category category of data (e.g. "total", "last", "unplugged", "current" ) |
| 2874 | * @param type type of data (e.g. "wakelock", "sensor", "process", "apk" , "process", "network") |
| 2875 | * @param timer a {@link Timer} to dump stats for |
| 2876 | * @param rawRealtime the current elapsed realtime of the system in microseconds |
| 2877 | * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT |
| 2878 | */ |
| 2879 | private static final void dumpTimer(PrintWriter pw, int uid, String category, String type, |
| 2880 | Timer timer, long rawRealtime, int which) { |
| 2881 | if (timer != null) { |
| 2882 | // Convert from microseconds to milliseconds with rounding |
| 2883 | final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) |
| 2884 | / 1000; |
| 2885 | final int count = timer.getCountLocked(which); |
| 2886 | if (totalTime != 0) { |
| 2887 | dumpLine(pw, uid, category, type, totalTime, count); |
| 2888 | } |
| 2889 | } |
| 2890 | } |
| 2891 | |
| 2892 | /** |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 2893 | * Checks if the ControllerActivityCounter has any data worth dumping. |
| 2894 | */ |
| 2895 | private static boolean controllerActivityHasData(ControllerActivityCounter counter, int which) { |
| 2896 | if (counter == null) { |
| 2897 | return false; |
| 2898 | } |
| 2899 | |
| 2900 | if (counter.getIdleTimeCounter().getCountLocked(which) != 0 |
| 2901 | || counter.getRxTimeCounter().getCountLocked(which) != 0 |
| 2902 | || counter.getPowerCounter().getCountLocked(which) != 0) { |
| 2903 | return true; |
| 2904 | } |
| 2905 | |
| 2906 | for (LongCounter c : counter.getTxTimeCounters()) { |
| 2907 | if (c.getCountLocked(which) != 0) { |
| 2908 | return true; |
| 2909 | } |
| 2910 | } |
| 2911 | return false; |
| 2912 | } |
| 2913 | |
| 2914 | /** |
| 2915 | * Dumps the ControllerActivityCounter if it has any data worth dumping. |
| 2916 | * The order of the arguments in the final check in line is: |
| 2917 | * |
| 2918 | * idle, rx, power, tx... |
| 2919 | * |
| 2920 | * where tx... is one or more transmit level times. |
| 2921 | */ |
| 2922 | private static final void dumpControllerActivityLine(PrintWriter pw, int uid, String category, |
| 2923 | String type, |
| 2924 | ControllerActivityCounter counter, |
| 2925 | int which) { |
| 2926 | if (!controllerActivityHasData(counter, which)) { |
| 2927 | return; |
| 2928 | } |
| 2929 | |
| 2930 | dumpLineHeader(pw, uid, category, type); |
| 2931 | pw.print(","); |
| 2932 | pw.print(counter.getIdleTimeCounter().getCountLocked(which)); |
| 2933 | pw.print(","); |
| 2934 | pw.print(counter.getRxTimeCounter().getCountLocked(which)); |
| 2935 | pw.print(","); |
| 2936 | pw.print(counter.getPowerCounter().getCountLocked(which) / (1000 * 60 * 60)); |
| 2937 | for (LongCounter c : counter.getTxTimeCounters()) { |
| 2938 | pw.print(","); |
| 2939 | pw.print(c.getCountLocked(which)); |
| 2940 | } |
| 2941 | pw.println(); |
| 2942 | } |
| 2943 | |
| 2944 | private final void printControllerActivityIfInteresting(PrintWriter pw, StringBuilder sb, |
| 2945 | String prefix, String controllerName, |
| 2946 | ControllerActivityCounter counter, |
| 2947 | int which) { |
| 2948 | if (controllerActivityHasData(counter, which)) { |
| 2949 | printControllerActivity(pw, sb, prefix, controllerName, counter, which); |
| 2950 | } |
| 2951 | } |
| 2952 | |
| 2953 | private final void printControllerActivity(PrintWriter pw, StringBuilder sb, String prefix, |
| 2954 | String controllerName, |
| 2955 | ControllerActivityCounter counter, int which) { |
| 2956 | final long idleTimeMs = counter.getIdleTimeCounter().getCountLocked(which); |
| 2957 | final long rxTimeMs = counter.getRxTimeCounter().getCountLocked(which); |
| 2958 | final long powerDrainMaMs = counter.getPowerCounter().getCountLocked(which); |
| 2959 | long totalTxTimeMs = 0; |
| 2960 | for (LongCounter txState : counter.getTxTimeCounters()) { |
| 2961 | totalTxTimeMs += txState.getCountLocked(which); |
| 2962 | } |
| 2963 | |
| 2964 | final long totalTimeMs = idleTimeMs + rxTimeMs + totalTxTimeMs; |
| 2965 | |
| 2966 | sb.setLength(0); |
| 2967 | sb.append(prefix); |
| 2968 | sb.append(" "); |
| 2969 | sb.append(controllerName); |
| 2970 | sb.append(" Idle time: "); |
| 2971 | formatTimeMs(sb, idleTimeMs); |
| 2972 | sb.append("("); |
| 2973 | sb.append(formatRatioLocked(idleTimeMs, totalTimeMs)); |
| 2974 | sb.append(")"); |
| 2975 | pw.println(sb.toString()); |
| 2976 | |
| 2977 | sb.setLength(0); |
| 2978 | sb.append(prefix); |
| 2979 | sb.append(" "); |
| 2980 | sb.append(controllerName); |
| 2981 | sb.append(" Rx time: "); |
| 2982 | formatTimeMs(sb, rxTimeMs); |
| 2983 | sb.append("("); |
| 2984 | sb.append(formatRatioLocked(rxTimeMs, totalTimeMs)); |
| 2985 | sb.append(")"); |
| 2986 | pw.println(sb.toString()); |
| 2987 | |
| 2988 | sb.setLength(0); |
| 2989 | sb.append(prefix); |
| 2990 | sb.append(" "); |
| 2991 | sb.append(controllerName); |
| 2992 | sb.append(" Tx time: "); |
| 2993 | formatTimeMs(sb, totalTxTimeMs); |
| 2994 | sb.append("("); |
| 2995 | sb.append(formatRatioLocked(totalTxTimeMs, totalTimeMs)); |
| 2996 | sb.append(")"); |
| 2997 | pw.println(sb.toString()); |
| 2998 | |
| 2999 | final int numTxLvls = counter.getTxTimeCounters().length; |
| 3000 | if (numTxLvls > 1) { |
| 3001 | for (int lvl = 0; lvl < numTxLvls; lvl++) { |
| 3002 | final long txLvlTimeMs = counter.getTxTimeCounters()[lvl].getCountLocked(which); |
| 3003 | sb.setLength(0); |
| 3004 | sb.append(prefix); |
| 3005 | sb.append(" ["); |
| 3006 | sb.append(lvl); |
| 3007 | sb.append("] "); |
| 3008 | formatTimeMs(sb, txLvlTimeMs); |
| 3009 | sb.append("("); |
| 3010 | sb.append(formatRatioLocked(txLvlTimeMs, totalTxTimeMs)); |
| 3011 | sb.append(")"); |
| 3012 | pw.println(sb.toString()); |
| 3013 | } |
| 3014 | } |
| 3015 | |
| 3016 | sb.setLength(0); |
| 3017 | sb.append(prefix); |
| 3018 | sb.append(" "); |
| 3019 | sb.append(controllerName); |
| 3020 | sb.append(" Power drain: ").append( |
| 3021 | BatteryStatsHelper.makemAh(powerDrainMaMs / (double) (1000*60*60))); |
| 3022 | sb.append("mAh"); |
| 3023 | pw.println(sb.toString()); |
| 3024 | } |
| 3025 | |
| 3026 | /** |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 3027 | * Temporary for settings. |
| 3028 | */ |
| 3029 | public final void dumpCheckinLocked(Context context, PrintWriter pw, int which, int reqUid) { |
| 3030 | dumpCheckinLocked(context, pw, which, reqUid, BatteryStatsHelper.checkWifiOnly(context)); |
| 3031 | } |
| 3032 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3033 | /** |
| 3034 | * Checkin server version of dump to produce more compact, computer-readable log. |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3035 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3036 | * NOTE: all times are expressed in 'ms'. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3037 | */ |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 3038 | public final void dumpCheckinLocked(Context context, PrintWriter pw, int which, int reqUid, |
| 3039 | boolean wifiOnly) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3040 | final long rawUptime = SystemClock.uptimeMillis() * 1000; |
| 3041 | final long rawRealtime = SystemClock.elapsedRealtime() * 1000; |
| 3042 | final long batteryUptime = getBatteryUptime(rawUptime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3043 | final long whichBatteryUptime = computeBatteryUptime(rawUptime, which); |
| 3044 | final long whichBatteryRealtime = computeBatteryRealtime(rawRealtime, which); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3045 | final long whichBatteryScreenOffUptime = computeBatteryScreenOffUptime(rawUptime, which); |
| 3046 | final long whichBatteryScreenOffRealtime = computeBatteryScreenOffRealtime(rawRealtime, |
| 3047 | which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3048 | final long totalRealtime = computeRealtime(rawRealtime, which); |
| 3049 | final long totalUptime = computeUptime(rawUptime, which); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3050 | final long screenOnTime = getScreenOnTime(rawRealtime, which); |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 3051 | final long interactiveTime = getInteractiveTime(rawRealtime, which); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3052 | final long powerSaveModeEnabledTime = getPowerSaveModeEnabledTime(rawRealtime, which); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3053 | final long deviceIdleModeLightTime = getDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT, |
| 3054 | rawRealtime, which); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 3055 | final long deviceIdleModeFullTime = getDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP, |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3056 | rawRealtime, which); |
| 3057 | final long deviceLightIdlingTime = getDeviceIdlingTime(DEVICE_IDLE_MODE_LIGHT, |
| 3058 | rawRealtime, which); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 3059 | final long deviceIdlingTime = getDeviceIdlingTime(DEVICE_IDLE_MODE_DEEP, |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3060 | rawRealtime, which); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 3061 | final int connChanges = getNumConnectivityChange(which); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3062 | final long phoneOnTime = getPhoneOnTime(rawRealtime, which); |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 3063 | final long dischargeCount = getDischargeCoulombCounter().getCountLocked(which); |
| 3064 | final long dischargeScreenOffCount = getDischargeScreenOffCoulombCounter() |
| 3065 | .getCountLocked(which); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3066 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3067 | final StringBuilder sb = new StringBuilder(128); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3068 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3069 | final SparseArray<? extends Uid> uidStats = getUidStats(); |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 3070 | final int NU = uidStats.size(); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3071 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3072 | final String category = STAT_NAMES[which]; |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 3073 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3074 | // Dump "battery" stat |
Jocelyn Dang | c627d10 | 2017-04-14 13:15:14 -0700 | [diff] [blame] | 3075 | dumpLine(pw, 0 /* uid */, category, BATTERY_DATA, |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3076 | which == STATS_SINCE_CHARGED ? getStartCount() : "N/A", |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3077 | whichBatteryRealtime / 1000, whichBatteryUptime / 1000, |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 3078 | totalRealtime / 1000, totalUptime / 1000, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3079 | getStartClockTime(), |
Adam Lesinski | f9b20a9 | 2016-06-17 17:30:01 -0700 | [diff] [blame] | 3080 | whichBatteryScreenOffRealtime / 1000, whichBatteryScreenOffUptime / 1000, |
Jocelyn Dang | c627d10 | 2017-04-14 13:15:14 -0700 | [diff] [blame] | 3081 | getEstimatedBatteryCapacity(), |
| 3082 | getMinLearnedBatteryCapacity(), getMaxLearnedBatteryCapacity()); |
Adam Lesinski | 67c134f | 2016-06-10 15:15:08 -0700 | [diff] [blame] | 3083 | |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3084 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3085 | // Calculate wakelock times across all uids. |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 3086 | long fullWakeLockTimeTotal = 0; |
| 3087 | long partialWakeLockTimeTotal = 0; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3088 | |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 3089 | for (int iu = 0; iu < NU; iu++) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3090 | final Uid u = uidStats.valueAt(iu); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 3091 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3092 | final ArrayMap<String, ? extends BatteryStats.Uid.Wakelock> wakelocks |
| 3093 | = u.getWakelockStats(); |
| 3094 | for (int iw=wakelocks.size()-1; iw>=0; iw--) { |
| 3095 | final Uid.Wakelock wl = wakelocks.valueAt(iw); |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 3096 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3097 | final Timer fullWakeTimer = wl.getWakeTime(WAKE_TYPE_FULL); |
| 3098 | if (fullWakeTimer != null) { |
| 3099 | fullWakeLockTimeTotal += fullWakeTimer.getTotalTimeLocked(rawRealtime, |
| 3100 | which); |
| 3101 | } |
| 3102 | |
| 3103 | final Timer partialWakeTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL); |
| 3104 | if (partialWakeTimer != null) { |
| 3105 | partialWakeLockTimeTotal += partialWakeTimer.getTotalTimeLocked( |
| 3106 | rawRealtime, which); |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 3107 | } |
| 3108 | } |
| 3109 | } |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 3110 | |
| 3111 | // Dump network stats |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3112 | final long mobileRxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which); |
| 3113 | final long mobileTxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which); |
| 3114 | final long wifiRxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which); |
| 3115 | final long wifiTxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which); |
| 3116 | final long mobileRxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which); |
| 3117 | final long mobileTxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which); |
| 3118 | final long wifiRxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which); |
| 3119 | final long wifiTxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 3120 | final long btRxTotalBytes = getNetworkActivityBytes(NETWORK_BT_RX_DATA, which); |
| 3121 | final long btTxTotalBytes = getNetworkActivityBytes(NETWORK_BT_TX_DATA, which); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3122 | dumpLine(pw, 0 /* uid */, category, GLOBAL_NETWORK_DATA, |
| 3123 | mobileRxTotalBytes, mobileTxTotalBytes, wifiRxTotalBytes, wifiTxTotalBytes, |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 3124 | mobileRxTotalPackets, mobileTxTotalPackets, wifiRxTotalPackets, wifiTxTotalPackets, |
| 3125 | btRxTotalBytes, btTxTotalBytes); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3126 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3127 | // Dump Modem controller stats |
| 3128 | dumpControllerActivityLine(pw, 0 /* uid */, category, GLOBAL_MODEM_CONTROLLER_DATA, |
| 3129 | getModemControllerActivity(), which); |
| 3130 | |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 3131 | // Dump Wifi controller stats |
| 3132 | final long wifiOnTime = getWifiOnTime(rawRealtime, which); |
| 3133 | final long wifiRunningTime = getGlobalWifiRunningTime(rawRealtime, which); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3134 | dumpLine(pw, 0 /* uid */, category, GLOBAL_WIFI_DATA, wifiOnTime / 1000, |
Adam Lesinski | 2208e74 | 2016-02-19 12:53:31 -0800 | [diff] [blame] | 3135 | wifiRunningTime / 1000, /* legacy fields follow, keep at 0 */ 0, 0, 0); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3136 | |
| 3137 | dumpControllerActivityLine(pw, 0 /* uid */, category, GLOBAL_WIFI_CONTROLLER_DATA, |
| 3138 | getWifiControllerActivity(), which); |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 3139 | |
| 3140 | // Dump Bluetooth controller stats |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3141 | dumpControllerActivityLine(pw, 0 /* uid */, category, GLOBAL_BLUETOOTH_CONTROLLER_DATA, |
| 3142 | getBluetoothControllerActivity(), which); |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 3143 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3144 | // Dump misc stats |
| 3145 | dumpLine(pw, 0 /* uid */, category, MISC_DATA, |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 3146 | screenOnTime / 1000, phoneOnTime / 1000, |
Ashish Sharma | 213bb2f | 2014-07-07 17:14:52 -0700 | [diff] [blame] | 3147 | fullWakeLockTimeTotal / 1000, partialWakeLockTimeTotal / 1000, |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 3148 | getMobileRadioActiveTime(rawRealtime, which) / 1000, |
Ashish Sharma | 213bb2f | 2014-07-07 17:14:52 -0700 | [diff] [blame] | 3149 | getMobileRadioActiveAdjustedTime(which) / 1000, interactiveTime / 1000, |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3150 | powerSaveModeEnabledTime / 1000, connChanges, deviceIdleModeFullTime / 1000, |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 3151 | getDeviceIdleModeCount(DEVICE_IDLE_MODE_DEEP, which), deviceIdlingTime / 1000, |
| 3152 | getDeviceIdlingCount(DEVICE_IDLE_MODE_DEEP, which), |
Adam Lesinski | 782327b | 2015-07-30 16:36:29 -0700 | [diff] [blame] | 3153 | getMobileRadioActiveCount(which), |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3154 | getMobileRadioActiveUnknownTime(which) / 1000, deviceIdleModeLightTime / 1000, |
| 3155 | getDeviceIdleModeCount(DEVICE_IDLE_MODE_LIGHT, which), deviceLightIdlingTime / 1000, |
| 3156 | getDeviceIdlingCount(DEVICE_IDLE_MODE_LIGHT, which), |
| 3157 | getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT), |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 3158 | getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP)); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3159 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3160 | // Dump screen brightness stats |
| 3161 | Object[] args = new Object[NUM_SCREEN_BRIGHTNESS_BINS]; |
| 3162 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3163 | args[i] = getScreenBrightnessTime(i, rawRealtime, which) / 1000; |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3164 | } |
| 3165 | dumpLine(pw, 0 /* uid */, category, SCREEN_BRIGHTNESS_DATA, args); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3166 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3167 | // Dump signal strength stats |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 3168 | args = new Object[SignalStrength.NUM_SIGNAL_STRENGTH_BINS]; |
| 3169 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3170 | args[i] = getPhoneSignalStrengthTime(i, rawRealtime, which) / 1000; |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3171 | } |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3172 | dumpLine(pw, 0 /* uid */, category, SIGNAL_STRENGTH_TIME_DATA, args); |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 3173 | dumpLine(pw, 0 /* uid */, category, SIGNAL_SCANNING_TIME_DATA, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3174 | getPhoneSignalScanningTime(rawRealtime, which) / 1000); |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 3175 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3176 | args[i] = getPhoneSignalStrengthCount(i, which); |
| 3177 | } |
| 3178 | dumpLine(pw, 0 /* uid */, category, SIGNAL_STRENGTH_COUNT_DATA, args); |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 3179 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3180 | // Dump network type stats |
| 3181 | args = new Object[NUM_DATA_CONNECTION_TYPES]; |
| 3182 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3183 | args[i] = getPhoneDataConnectionTime(i, rawRealtime, which) / 1000; |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3184 | } |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3185 | dumpLine(pw, 0 /* uid */, category, DATA_CONNECTION_TIME_DATA, args); |
| 3186 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
| 3187 | args[i] = getPhoneDataConnectionCount(i, which); |
| 3188 | } |
| 3189 | dumpLine(pw, 0 /* uid */, category, DATA_CONNECTION_COUNT_DATA, args); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3190 | |
| 3191 | // Dump wifi state stats |
| 3192 | args = new Object[NUM_WIFI_STATES]; |
| 3193 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3194 | args[i] = getWifiStateTime(i, rawRealtime, which) / 1000; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3195 | } |
| 3196 | dumpLine(pw, 0 /* uid */, category, WIFI_STATE_TIME_DATA, args); |
| 3197 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
| 3198 | args[i] = getWifiStateCount(i, which); |
| 3199 | } |
| 3200 | dumpLine(pw, 0 /* uid */, category, WIFI_STATE_COUNT_DATA, args); |
| 3201 | |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 3202 | // Dump wifi suppl state stats |
| 3203 | args = new Object[NUM_WIFI_SUPPL_STATES]; |
| 3204 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
| 3205 | args[i] = getWifiSupplStateTime(i, rawRealtime, which) / 1000; |
| 3206 | } |
| 3207 | dumpLine(pw, 0 /* uid */, category, WIFI_SUPPL_STATE_TIME_DATA, args); |
| 3208 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
| 3209 | args[i] = getWifiSupplStateCount(i, which); |
| 3210 | } |
| 3211 | dumpLine(pw, 0 /* uid */, category, WIFI_SUPPL_STATE_COUNT_DATA, args); |
| 3212 | |
| 3213 | // Dump wifi signal strength stats |
| 3214 | args = new Object[NUM_WIFI_SIGNAL_STRENGTH_BINS]; |
| 3215 | for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 3216 | args[i] = getWifiSignalStrengthTime(i, rawRealtime, which) / 1000; |
| 3217 | } |
| 3218 | dumpLine(pw, 0 /* uid */, category, WIFI_SIGNAL_STRENGTH_TIME_DATA, args); |
| 3219 | for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 3220 | args[i] = getWifiSignalStrengthCount(i, which); |
| 3221 | } |
| 3222 | dumpLine(pw, 0 /* uid */, category, WIFI_SIGNAL_STRENGTH_COUNT_DATA, args); |
| 3223 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3224 | if (which == STATS_SINCE_UNPLUGGED) { |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 3225 | dumpLine(pw, 0 /* uid */, category, BATTERY_LEVEL_DATA, getDischargeStartLevel(), |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 3226 | getDischargeCurrentLevel()); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3227 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3228 | |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 3229 | if (which == STATS_SINCE_UNPLUGGED) { |
| 3230 | dumpLine(pw, 0 /* uid */, category, BATTERY_DISCHARGE_DATA, |
| 3231 | getDischargeStartLevel()-getDischargeCurrentLevel(), |
| 3232 | getDischargeStartLevel()-getDischargeCurrentLevel(), |
Adam Lesinski | 67c134f | 2016-06-10 15:15:08 -0700 | [diff] [blame] | 3233 | getDischargeAmountScreenOn(), getDischargeAmountScreenOff(), |
| 3234 | dischargeCount / 1000, dischargeScreenOffCount / 1000); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 3235 | } else { |
| 3236 | dumpLine(pw, 0 /* uid */, category, BATTERY_DISCHARGE_DATA, |
| 3237 | getLowDischargeAmountSinceCharge(), getHighDischargeAmountSinceCharge(), |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 3238 | getDischargeAmountScreenOnSinceCharge(), |
Adam Lesinski | 67c134f | 2016-06-10 15:15:08 -0700 | [diff] [blame] | 3239 | getDischargeAmountScreenOffSinceCharge(), |
| 3240 | dischargeCount / 1000, dischargeScreenOffCount / 1000); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 3241 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3242 | |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 3243 | if (reqUid < 0) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3244 | final Map<String, ? extends Timer> kernelWakelocks = getKernelWakelockStats(); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 3245 | if (kernelWakelocks.size() > 0) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3246 | for (Map.Entry<String, ? extends Timer> ent : kernelWakelocks.entrySet()) { |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 3247 | sb.setLength(0); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3248 | printWakeLockCheckin(sb, ent.getValue(), rawRealtime, null, which, ""); |
Kweku Adams | e0dd9c1 | 2017-03-08 08:12:15 -0800 | [diff] [blame] | 3249 | dumpLine(pw, 0 /* uid */, category, KERNEL_WAKELOCK_DATA, |
| 3250 | "\"" + ent.getKey() + "\"", sb.toString()); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 3251 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 3252 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3253 | final Map<String, ? extends Timer> wakeupReasons = getWakeupReasonStats(); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3254 | if (wakeupReasons.size() > 0) { |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 3255 | for (Map.Entry<String, ? extends Timer> ent : wakeupReasons.entrySet()) { |
| 3256 | // Not doing the regular wake lock formatting to remain compatible |
| 3257 | // with the old checkin format. |
| 3258 | long totalTimeMicros = ent.getValue().getTotalTimeLocked(rawRealtime, which); |
| 3259 | int count = ent.getValue().getCountLocked(which); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3260 | dumpLine(pw, 0 /* uid */, category, WAKEUP_REASON_DATA, |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 3261 | "\"" + ent.getKey() + "\"", (totalTimeMicros + 500) / 1000, count); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3262 | } |
| 3263 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 3264 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3265 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3266 | final BatteryStatsHelper helper = new BatteryStatsHelper(context, false, wifiOnly); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3267 | helper.create(this); |
| 3268 | helper.refreshStats(which, UserHandle.USER_ALL); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3269 | final List<BatterySipper> sippers = helper.getUsageList(); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3270 | if (sippers != null && sippers.size() > 0) { |
| 3271 | dumpLine(pw, 0 /* uid */, category, POWER_USE_SUMMARY_DATA, |
| 3272 | BatteryStatsHelper.makemAh(helper.getPowerProfile().getBatteryCapacity()), |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3273 | BatteryStatsHelper.makemAh(helper.getComputedPower()), |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3274 | BatteryStatsHelper.makemAh(helper.getMinDrainedPower()), |
| 3275 | BatteryStatsHelper.makemAh(helper.getMaxDrainedPower())); |
| 3276 | for (int i=0; i<sippers.size(); i++) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3277 | final BatterySipper bs = sippers.get(i); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3278 | int uid = 0; |
| 3279 | String label; |
| 3280 | switch (bs.drainType) { |
| 3281 | case IDLE: |
| 3282 | label="idle"; |
| 3283 | break; |
| 3284 | case CELL: |
| 3285 | label="cell"; |
| 3286 | break; |
| 3287 | case PHONE: |
| 3288 | label="phone"; |
| 3289 | break; |
| 3290 | case WIFI: |
| 3291 | label="wifi"; |
| 3292 | break; |
| 3293 | case BLUETOOTH: |
| 3294 | label="blue"; |
| 3295 | break; |
| 3296 | case SCREEN: |
| 3297 | label="scrn"; |
| 3298 | break; |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 3299 | case FLASHLIGHT: |
| 3300 | label="flashlight"; |
| 3301 | break; |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3302 | case APP: |
| 3303 | uid = bs.uidObj.getUid(); |
| 3304 | label = "uid"; |
| 3305 | break; |
| 3306 | case USER: |
| 3307 | uid = UserHandle.getUid(bs.userId, 0); |
| 3308 | label = "user"; |
| 3309 | break; |
| 3310 | case UNACCOUNTED: |
| 3311 | label = "unacc"; |
| 3312 | break; |
| 3313 | case OVERCOUNTED: |
| 3314 | label = "over"; |
| 3315 | break; |
Ruben Brunk | 5b1308f | 2015-06-03 18:49:27 -0700 | [diff] [blame] | 3316 | case CAMERA: |
| 3317 | label = "camera"; |
| 3318 | break; |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3319 | default: |
| 3320 | label = "???"; |
| 3321 | } |
| 3322 | dumpLine(pw, uid, category, POWER_USE_ITEM_DATA, label, |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 3323 | BatteryStatsHelper.makemAh(bs.totalPowerMah)); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3324 | } |
| 3325 | } |
| 3326 | |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 3327 | final long[] cpuFreqs = getCpuFreqs(); |
| 3328 | if (cpuFreqs != null) { |
| 3329 | sb.setLength(0); |
| 3330 | for (int i = 0; i < cpuFreqs.length; ++i) { |
| 3331 | sb.append((i == 0 ? "" : ",") + cpuFreqs[i]); |
| 3332 | } |
| 3333 | dumpLine(pw, 0 /* uid */, category, GLOBAL_CPU_FREQ_DATA, sb.toString()); |
| 3334 | } |
| 3335 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3336 | for (int iu = 0; iu < NU; iu++) { |
| 3337 | final int uid = uidStats.keyAt(iu); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 3338 | if (reqUid >= 0 && uid != reqUid) { |
| 3339 | continue; |
| 3340 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3341 | final Uid u = uidStats.valueAt(iu); |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 3342 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3343 | // Dump Network stats per uid, if any |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3344 | final long mobileBytesRx = u.getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which); |
| 3345 | final long mobileBytesTx = u.getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which); |
| 3346 | final long wifiBytesRx = u.getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which); |
| 3347 | final long wifiBytesTx = u.getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which); |
| 3348 | final long mobilePacketsRx = u.getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which); |
| 3349 | final long mobilePacketsTx = u.getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which); |
| 3350 | final long mobileActiveTime = u.getMobileRadioActiveTime(which); |
| 3351 | final int mobileActiveCount = u.getMobileRadioActiveCount(which); |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 3352 | final long mobileWakeup = u.getMobileRadioApWakeupCount(which); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3353 | final long wifiPacketsRx = u.getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which); |
| 3354 | final long wifiPacketsTx = u.getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which); |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 3355 | final long wifiWakeup = u.getWifiRadioApWakeupCount(which); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 3356 | final long btBytesRx = u.getNetworkActivityBytes(NETWORK_BT_RX_DATA, which); |
| 3357 | final long btBytesTx = u.getNetworkActivityBytes(NETWORK_BT_TX_DATA, which); |
Amith Yamasani | 59fe841 | 2017-03-03 16:28:52 -0800 | [diff] [blame] | 3358 | // Background data transfers |
| 3359 | final long mobileBytesBgRx = u.getNetworkActivityBytes(NETWORK_MOBILE_BG_RX_DATA, |
| 3360 | which); |
| 3361 | final long mobileBytesBgTx = u.getNetworkActivityBytes(NETWORK_MOBILE_BG_TX_DATA, |
| 3362 | which); |
| 3363 | final long wifiBytesBgRx = u.getNetworkActivityBytes(NETWORK_WIFI_BG_RX_DATA, which); |
| 3364 | final long wifiBytesBgTx = u.getNetworkActivityBytes(NETWORK_WIFI_BG_TX_DATA, which); |
| 3365 | final long mobilePacketsBgRx = u.getNetworkActivityPackets(NETWORK_MOBILE_BG_RX_DATA, |
| 3366 | which); |
| 3367 | final long mobilePacketsBgTx = u.getNetworkActivityPackets(NETWORK_MOBILE_BG_TX_DATA, |
| 3368 | which); |
| 3369 | final long wifiPacketsBgRx = u.getNetworkActivityPackets(NETWORK_WIFI_BG_RX_DATA, |
| 3370 | which); |
| 3371 | final long wifiPacketsBgTx = u.getNetworkActivityPackets(NETWORK_WIFI_BG_TX_DATA, |
| 3372 | which); |
| 3373 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3374 | if (mobileBytesRx > 0 || mobileBytesTx > 0 || wifiBytesRx > 0 || wifiBytesTx > 0 |
| 3375 | || mobilePacketsRx > 0 || mobilePacketsTx > 0 || wifiPacketsRx > 0 |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 3376 | || wifiPacketsTx > 0 || mobileActiveTime > 0 || mobileActiveCount > 0 |
Amith Yamasani | 59fe841 | 2017-03-03 16:28:52 -0800 | [diff] [blame] | 3377 | || btBytesRx > 0 || btBytesTx > 0 || mobileWakeup > 0 || wifiWakeup > 0 |
| 3378 | || mobileBytesBgRx > 0 || mobileBytesBgTx > 0 || wifiBytesBgRx > 0 |
| 3379 | || wifiBytesBgTx > 0 |
| 3380 | || mobilePacketsBgRx > 0 || mobilePacketsBgTx > 0 || wifiPacketsBgRx > 0 |
| 3381 | || wifiPacketsBgTx > 0) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3382 | dumpLine(pw, uid, category, NETWORK_DATA, mobileBytesRx, mobileBytesTx, |
| 3383 | wifiBytesRx, wifiBytesTx, |
| 3384 | mobilePacketsRx, mobilePacketsTx, |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 3385 | wifiPacketsRx, wifiPacketsTx, |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 3386 | mobileActiveTime, mobileActiveCount, |
Amith Yamasani | 59fe841 | 2017-03-03 16:28:52 -0800 | [diff] [blame] | 3387 | btBytesRx, btBytesTx, mobileWakeup, wifiWakeup, |
| 3388 | mobileBytesBgRx, mobileBytesBgTx, wifiBytesBgRx, wifiBytesBgTx, |
| 3389 | mobilePacketsBgRx, mobilePacketsBgTx, wifiPacketsBgRx, wifiPacketsBgTx |
| 3390 | ); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 3391 | } |
| 3392 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3393 | // Dump modem controller data, per UID. |
| 3394 | dumpControllerActivityLine(pw, uid, category, MODEM_CONTROLLER_DATA, |
| 3395 | u.getModemControllerActivity(), which); |
| 3396 | |
| 3397 | // Dump Wifi controller data, per UID. |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 3398 | final long fullWifiLockOnTime = u.getFullWifiLockTime(rawRealtime, which); |
| 3399 | final long wifiScanTime = u.getWifiScanTime(rawRealtime, which); |
| 3400 | final int wifiScanCount = u.getWifiScanCount(which); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 3401 | final int wifiScanCountBg = u.getWifiScanBackgroundCount(which); |
| 3402 | // Note that 'ActualTime' are unpooled and always since reset (regardless of 'which') |
Bookatz | ce49aca | 2017-04-03 09:47:05 -0700 | [diff] [blame] | 3403 | final long wifiScanActualTimeMs = (u.getWifiScanActualTime(rawRealtime) + 500) / 1000; |
| 3404 | final long wifiScanActualTimeMsBg = (u.getWifiScanBackgroundTime(rawRealtime) + 500) |
| 3405 | / 1000; |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 3406 | final long uidWifiRunningTime = u.getWifiRunningTime(rawRealtime, which); |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 3407 | if (fullWifiLockOnTime != 0 || wifiScanTime != 0 || wifiScanCount != 0 |
Bookatz | ce49aca | 2017-04-03 09:47:05 -0700 | [diff] [blame] | 3408 | || wifiScanCountBg != 0 || wifiScanActualTimeMs != 0 |
| 3409 | || wifiScanActualTimeMsBg != 0 || uidWifiRunningTime != 0) { |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3410 | dumpLine(pw, uid, category, WIFI_DATA, fullWifiLockOnTime, wifiScanTime, |
| 3411 | uidWifiRunningTime, wifiScanCount, |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 3412 | /* legacy fields follow, keep at 0 */ 0, 0, 0, |
Bookatz | ce49aca | 2017-04-03 09:47:05 -0700 | [diff] [blame] | 3413 | wifiScanCountBg, wifiScanActualTimeMs, wifiScanActualTimeMsBg); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3414 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3415 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3416 | dumpControllerActivityLine(pw, uid, category, WIFI_CONTROLLER_DATA, |
| 3417 | u.getWifiControllerActivity(), which); |
| 3418 | |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 3419 | final Timer bleTimer = u.getBluetoothScanTimer(); |
| 3420 | if (bleTimer != null) { |
| 3421 | // Convert from microseconds to milliseconds with rounding |
| 3422 | final long totalTime = (bleTimer.getTotalTimeLocked(rawRealtime, which) + 500) |
| 3423 | / 1000; |
| 3424 | if (totalTime != 0) { |
| 3425 | final int count = bleTimer.getCountLocked(which); |
| 3426 | final Timer bleTimerBg = u.getBluetoothScanBackgroundTimer(); |
| 3427 | final int countBg = bleTimerBg != null ? bleTimerBg.getCountLocked(which) : 0; |
| 3428 | final long rawRealtimeMs = (rawRealtime + 500) / 1000; |
| 3429 | // 'actualTime' are unpooled and always since reset (regardless of 'which') |
| 3430 | final long actualTime = bleTimer.getTotalDurationMsLocked(rawRealtimeMs); |
| 3431 | final long actualTimeBg = bleTimerBg != null ? |
| 3432 | bleTimerBg.getTotalDurationMsLocked(rawRealtimeMs) : 0; |
Bookatz | 956f36bf | 2017-04-28 09:48:17 -0700 | [diff] [blame] | 3433 | final int resultCount = u.getBluetoothScanResultCounter() != null ? |
| 3434 | u.getBluetoothScanResultCounter().getCountLocked(which) : 0; |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 3435 | dumpLine(pw, uid, category, BLUETOOTH_MISC_DATA, totalTime, count, |
Bookatz | 956f36bf | 2017-04-28 09:48:17 -0700 | [diff] [blame] | 3436 | countBg, actualTime, actualTimeBg, resultCount); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 3437 | } |
| 3438 | } |
Adam Lesinski | d9b99be | 2016-03-30 16:58:51 -0700 | [diff] [blame] | 3439 | |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 3440 | dumpControllerActivityLine(pw, uid, category, BLUETOOTH_CONTROLLER_DATA, |
| 3441 | u.getBluetoothControllerActivity(), which); |
| 3442 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3443 | if (u.hasUserActivity()) { |
| 3444 | args = new Object[Uid.NUM_USER_ACTIVITY_TYPES]; |
| 3445 | boolean hasData = false; |
| 3446 | for (int i=0; i<Uid.NUM_USER_ACTIVITY_TYPES; i++) { |
| 3447 | int val = u.getUserActivityCount(i, which); |
| 3448 | args[i] = val; |
| 3449 | if (val != 0) hasData = true; |
| 3450 | } |
| 3451 | if (hasData) { |
Ashish Sharma | cba1215 | 2014-07-07 17:14:52 -0700 | [diff] [blame] | 3452 | dumpLine(pw, uid /* uid */, category, USER_ACTIVITY_DATA, args); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3453 | } |
| 3454 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3455 | |
| 3456 | if (u.getAggregatedPartialWakelockTimer() != null) { |
| 3457 | final Timer timer = u.getAggregatedPartialWakelockTimer(); |
| 3458 | // Convert from microseconds to milliseconds with rounding |
| 3459 | final long totTimeMs = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000; |
| 3460 | final Timer bgTimer = timer.getSubTimer(); |
| 3461 | final long bgTimeMs = bgTimer != null ? |
| 3462 | (bgTimer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000 : 0; |
| 3463 | dumpLine(pw, uid, category, AGGREGATED_WAKELOCK_DATA, totTimeMs, bgTimeMs); |
| 3464 | } |
| 3465 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3466 | final ArrayMap<String, ? extends Uid.Wakelock> wakelocks = u.getWakelockStats(); |
| 3467 | for (int iw=wakelocks.size()-1; iw>=0; iw--) { |
| 3468 | final Uid.Wakelock wl = wakelocks.valueAt(iw); |
| 3469 | String linePrefix = ""; |
| 3470 | sb.setLength(0); |
| 3471 | linePrefix = printWakeLockCheckin(sb, wl.getWakeTime(WAKE_TYPE_FULL), |
| 3472 | rawRealtime, "f", which, linePrefix); |
Bookatz | 5b5ec32 | 2017-05-26 09:40:38 -0700 | [diff] [blame^] | 3473 | final Timer pTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL); |
| 3474 | linePrefix = printWakeLockCheckin(sb, pTimer, |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3475 | rawRealtime, "p", which, linePrefix); |
Bookatz | 5b5ec32 | 2017-05-26 09:40:38 -0700 | [diff] [blame^] | 3476 | linePrefix = printWakeLockCheckin(sb, pTimer != null ? pTimer.getSubTimer() : null, |
| 3477 | rawRealtime, "bp", which, linePrefix); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3478 | linePrefix = printWakeLockCheckin(sb, wl.getWakeTime(WAKE_TYPE_WINDOW), |
| 3479 | rawRealtime, "w", which, linePrefix); |
| 3480 | |
| 3481 | // Only log if we had at lease one wakelock... |
| 3482 | if (sb.length() > 0) { |
| 3483 | String name = wakelocks.keyAt(iw); |
| 3484 | if (name.indexOf(',') >= 0) { |
| 3485 | name = name.replace(',', '_'); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3486 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3487 | dumpLine(pw, uid, category, WAKELOCK_DATA, name, sb.toString()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3488 | } |
| 3489 | } |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 3490 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3491 | final ArrayMap<String, ? extends Timer> syncs = u.getSyncStats(); |
| 3492 | for (int isy=syncs.size()-1; isy>=0; isy--) { |
| 3493 | final Timer timer = syncs.valueAt(isy); |
| 3494 | // Convert from microseconds to milliseconds with rounding |
| 3495 | final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000; |
| 3496 | final int count = timer.getCountLocked(which); |
Bookatz | 2bffb5b | 2017-04-13 11:59:33 -0700 | [diff] [blame] | 3497 | final Timer bgTimer = timer.getSubTimer(); |
| 3498 | final long bgTime = bgTimer != null ? |
| 3499 | (bgTimer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000 : -1; |
| 3500 | final int bgCount = bgTimer != null ? bgTimer.getCountLocked(which) : -1; |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3501 | if (totalTime != 0) { |
Kweku Adams | e0dd9c1 | 2017-03-08 08:12:15 -0800 | [diff] [blame] | 3502 | dumpLine(pw, uid, category, SYNC_DATA, "\"" + syncs.keyAt(isy) + "\"", |
Bookatz | 2bffb5b | 2017-04-13 11:59:33 -0700 | [diff] [blame] | 3503 | totalTime, count, bgTime, bgCount); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 3504 | } |
| 3505 | } |
| 3506 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3507 | final ArrayMap<String, ? extends Timer> jobs = u.getJobStats(); |
| 3508 | for (int ij=jobs.size()-1; ij>=0; ij--) { |
| 3509 | final Timer timer = jobs.valueAt(ij); |
| 3510 | // Convert from microseconds to milliseconds with rounding |
| 3511 | final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000; |
| 3512 | final int count = timer.getCountLocked(which); |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 3513 | final Timer bgTimer = timer.getSubTimer(); |
| 3514 | final long bgTime = bgTimer != null ? |
| 3515 | (bgTimer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000 : -1; |
| 3516 | final int bgCount = bgTimer != null ? bgTimer.getCountLocked(which) : -1; |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3517 | if (totalTime != 0) { |
Kweku Adams | e0dd9c1 | 2017-03-08 08:12:15 -0800 | [diff] [blame] | 3518 | dumpLine(pw, uid, category, JOB_DATA, "\"" + jobs.keyAt(ij) + "\"", |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 3519 | totalTime, count, bgTime, bgCount); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 3520 | } |
| 3521 | } |
| 3522 | |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 3523 | dumpTimer(pw, uid, category, FLASHLIGHT_DATA, u.getFlashlightTurnedOnTimer(), |
| 3524 | rawRealtime, which); |
| 3525 | dumpTimer(pw, uid, category, CAMERA_DATA, u.getCameraTurnedOnTimer(), |
| 3526 | rawRealtime, which); |
| 3527 | dumpTimer(pw, uid, category, VIDEO_DATA, u.getVideoTurnedOnTimer(), |
| 3528 | rawRealtime, which); |
| 3529 | dumpTimer(pw, uid, category, AUDIO_DATA, u.getAudioTurnedOnTimer(), |
| 3530 | rawRealtime, which); |
| 3531 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3532 | final SparseArray<? extends BatteryStats.Uid.Sensor> sensors = u.getSensorStats(); |
| 3533 | final int NSE = sensors.size(); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 3534 | for (int ise=0; ise<NSE; ise++) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3535 | final Uid.Sensor se = sensors.valueAt(ise); |
| 3536 | final int sensorNumber = sensors.keyAt(ise); |
| 3537 | final Timer timer = se.getSensorTime(); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 3538 | if (timer != null) { |
| 3539 | // Convert from microseconds to milliseconds with rounding |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3540 | final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) |
| 3541 | / 1000; |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 3542 | if (totalTime != 0) { |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 3543 | final int count = timer.getCountLocked(which); |
| 3544 | final Timer bgTimer = se.getSensorBackgroundTime(); |
| 3545 | final int bgCount = bgTimer != null ? bgTimer.getCountLocked(which) : 0; |
| 3546 | final long rawRealtimeMs = (rawRealtime + 500) / 1000; |
| 3547 | // 'actualTime' are unpooled and always since reset (regardless of 'which') |
| 3548 | final long actualTime = timer.getTotalDurationMsLocked(rawRealtimeMs); |
| 3549 | final long bgActualTime = bgTimer != null ? |
| 3550 | bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : 0; |
| 3551 | dumpLine(pw, uid, category, SENSOR_DATA, sensorNumber, totalTime, |
| 3552 | count, bgCount, actualTime, bgActualTime); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 3553 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3554 | } |
| 3555 | } |
| 3556 | |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 3557 | dumpTimer(pw, uid, category, VIBRATOR_DATA, u.getVibratorOnTimer(), |
| 3558 | rawRealtime, which); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 3559 | |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 3560 | dumpTimer(pw, uid, category, FOREGROUND_DATA, u.getForegroundActivityTimer(), |
| 3561 | rawRealtime, which); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 3562 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3563 | final Object[] stateTimes = new Object[Uid.NUM_PROCESS_STATE]; |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 3564 | long totalStateTime = 0; |
| 3565 | for (int ips=0; ips<Uid.NUM_PROCESS_STATE; ips++) { |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 3566 | final long time = u.getProcessStateTime(ips, rawRealtime, which); |
| 3567 | totalStateTime += time; |
| 3568 | stateTimes[ips] = (time + 500) / 1000; |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 3569 | } |
| 3570 | if (totalStateTime > 0) { |
| 3571 | dumpLine(pw, uid, category, STATE_TIME_DATA, stateTimes); |
| 3572 | } |
| 3573 | |
Adam Lesinski | a7a4ccc | 2015-06-26 17:43:04 -0700 | [diff] [blame] | 3574 | final long userCpuTimeUs = u.getUserCpuTimeUs(which); |
| 3575 | final long systemCpuTimeUs = u.getSystemCpuTimeUs(which); |
Adam Lesinski | d4abd1e | 2017-04-12 11:29:13 -0700 | [diff] [blame] | 3576 | if (userCpuTimeUs > 0 || systemCpuTimeUs > 0) { |
Adam Lesinski | a7a4ccc | 2015-06-26 17:43:04 -0700 | [diff] [blame] | 3577 | dumpLine(pw, uid, category, CPU_DATA, userCpuTimeUs / 1000, systemCpuTimeUs / 1000, |
Adam Lesinski | d4abd1e | 2017-04-12 11:29:13 -0700 | [diff] [blame] | 3578 | 0 /* old cpu power, keep for compatibility */); |
Adam Lesinski | a7a4ccc | 2015-06-26 17:43:04 -0700 | [diff] [blame] | 3579 | } |
| 3580 | |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 3581 | final long[] cpuFreqTimeMs = u.getCpuFreqTimes(which); |
| 3582 | // If total cpuFreqTimes is null, then we don't need to check for screenOffCpuFreqTimes. |
| 3583 | if (cpuFreqTimeMs != null) { |
| 3584 | sb.setLength(0); |
| 3585 | for (int i = 0; i < cpuFreqTimeMs.length; ++i) { |
| 3586 | sb.append((i == 0 ? "" : ",") + cpuFreqTimeMs[i]); |
| 3587 | } |
| 3588 | final long[] screenOffCpuFreqTimeMs = u.getScreenOffCpuFreqTimes(which); |
| 3589 | if (screenOffCpuFreqTimeMs != null) { |
| 3590 | for (int i = 0; i < screenOffCpuFreqTimeMs.length; ++i) { |
| 3591 | sb.append("," + screenOffCpuFreqTimeMs[i]); |
| 3592 | } |
| 3593 | } else { |
| 3594 | for (int i = 0; i < cpuFreqTimeMs.length; ++i) { |
| 3595 | sb.append(",0"); |
| 3596 | } |
| 3597 | } |
| 3598 | dumpLine(pw, uid, category, CPU_TIMES_AT_FREQ_DATA, UID_TIMES_TYPE_ALL, |
| 3599 | cpuFreqTimeMs.length, sb.toString()); |
| 3600 | } |
| 3601 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3602 | final ArrayMap<String, ? extends BatteryStats.Uid.Proc> processStats |
| 3603 | = u.getProcessStats(); |
| 3604 | for (int ipr=processStats.size()-1; ipr>=0; ipr--) { |
| 3605 | final Uid.Proc ps = processStats.valueAt(ipr); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 3606 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3607 | final long userMillis = ps.getUserTime(which); |
| 3608 | final long systemMillis = ps.getSystemTime(which); |
| 3609 | final long foregroundMillis = ps.getForegroundTime(which); |
| 3610 | final int starts = ps.getStarts(which); |
| 3611 | final int numCrashes = ps.getNumCrashes(which); |
| 3612 | final int numAnrs = ps.getNumAnrs(which); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 3613 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3614 | if (userMillis != 0 || systemMillis != 0 || foregroundMillis != 0 |
| 3615 | || starts != 0 || numAnrs != 0 || numCrashes != 0) { |
Kweku Adams | e0dd9c1 | 2017-03-08 08:12:15 -0800 | [diff] [blame] | 3616 | dumpLine(pw, uid, category, PROCESS_DATA, "\"" + processStats.keyAt(ipr) + "\"", |
| 3617 | userMillis, systemMillis, foregroundMillis, starts, numAnrs, numCrashes); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3618 | } |
| 3619 | } |
| 3620 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3621 | final ArrayMap<String, ? extends BatteryStats.Uid.Pkg> packageStats |
| 3622 | = u.getPackageStats(); |
| 3623 | for (int ipkg=packageStats.size()-1; ipkg>=0; ipkg--) { |
| 3624 | final Uid.Pkg ps = packageStats.valueAt(ipkg); |
| 3625 | int wakeups = 0; |
| 3626 | final ArrayMap<String, ? extends Counter> alarms = ps.getWakeupAlarmStats(); |
| 3627 | for (int iwa=alarms.size()-1; iwa>=0; iwa--) { |
Joe Onorato | 1476d32 | 2016-05-05 14:46:15 -0700 | [diff] [blame] | 3628 | int count = alarms.valueAt(iwa).getCountLocked(which); |
| 3629 | wakeups += count; |
| 3630 | String name = alarms.keyAt(iwa).replace(',', '_'); |
| 3631 | dumpLine(pw, uid, category, WAKEUP_ALARM_DATA, name, count); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3632 | } |
| 3633 | final ArrayMap<String, ? extends Uid.Pkg.Serv> serviceStats = ps.getServiceStats(); |
| 3634 | for (int isvc=serviceStats.size()-1; isvc>=0; isvc--) { |
| 3635 | final BatteryStats.Uid.Pkg.Serv ss = serviceStats.valueAt(isvc); |
| 3636 | final long startTime = ss.getStartTime(batteryUptime, which); |
| 3637 | final int starts = ss.getStarts(which); |
| 3638 | final int launches = ss.getLaunches(which); |
| 3639 | if (startTime != 0 || starts != 0 || launches != 0) { |
| 3640 | dumpLine(pw, uid, category, APK_DATA, |
| 3641 | wakeups, // wakeup alarms |
| 3642 | packageStats.keyAt(ipkg), // Apk |
| 3643 | serviceStats.keyAt(isvc), // service |
| 3644 | startTime / 1000, // time spent started, in ms |
| 3645 | starts, |
| 3646 | launches); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3647 | } |
| 3648 | } |
| 3649 | } |
| 3650 | } |
| 3651 | } |
| 3652 | |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 3653 | static final class TimerEntry { |
| 3654 | final String mName; |
| 3655 | final int mId; |
| 3656 | final BatteryStats.Timer mTimer; |
| 3657 | final long mTime; |
| 3658 | TimerEntry(String name, int id, BatteryStats.Timer timer, long time) { |
| 3659 | mName = name; |
| 3660 | mId = id; |
| 3661 | mTimer = timer; |
| 3662 | mTime = time; |
| 3663 | } |
| 3664 | } |
| 3665 | |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3666 | private void printmAh(PrintWriter printer, double power) { |
| 3667 | printer.print(BatteryStatsHelper.makemAh(power)); |
| 3668 | } |
| 3669 | |
Adam Lesinski | a7a4ccc | 2015-06-26 17:43:04 -0700 | [diff] [blame] | 3670 | private void printmAh(StringBuilder sb, double power) { |
| 3671 | sb.append(BatteryStatsHelper.makemAh(power)); |
| 3672 | } |
| 3673 | |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 3674 | /** |
| 3675 | * Temporary for settings. |
| 3676 | */ |
| 3677 | public final void dumpLocked(Context context, PrintWriter pw, String prefix, int which, |
| 3678 | int reqUid) { |
| 3679 | dumpLocked(context, pw, prefix, which, reqUid, BatteryStatsHelper.checkWifiOnly(context)); |
| 3680 | } |
| 3681 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3682 | @SuppressWarnings("unused") |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3683 | 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] | 3684 | int reqUid, boolean wifiOnly) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3685 | final long rawUptime = SystemClock.uptimeMillis() * 1000; |
| 3686 | final long rawRealtime = SystemClock.elapsedRealtime() * 1000; |
| 3687 | final long batteryUptime = getBatteryUptime(rawUptime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3688 | |
| 3689 | final long whichBatteryUptime = computeBatteryUptime(rawUptime, which); |
| 3690 | final long whichBatteryRealtime = computeBatteryRealtime(rawRealtime, which); |
| 3691 | final long totalRealtime = computeRealtime(rawRealtime, which); |
| 3692 | final long totalUptime = computeUptime(rawUptime, which); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3693 | final long whichBatteryScreenOffUptime = computeBatteryScreenOffUptime(rawUptime, which); |
| 3694 | final long whichBatteryScreenOffRealtime = computeBatteryScreenOffRealtime(rawRealtime, |
| 3695 | which); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 3696 | final long batteryTimeRemaining = computeBatteryTimeRemaining(rawRealtime); |
| 3697 | final long chargeTimeRemaining = computeChargeTimeRemaining(rawRealtime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3698 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3699 | final StringBuilder sb = new StringBuilder(128); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3700 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3701 | final SparseArray<? extends Uid> uidStats = getUidStats(); |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 3702 | final int NU = uidStats.size(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3703 | |
Adam Lesinski | f9b20a9 | 2016-06-17 17:30:01 -0700 | [diff] [blame] | 3704 | final int estimatedBatteryCapacity = getEstimatedBatteryCapacity(); |
| 3705 | if (estimatedBatteryCapacity > 0) { |
| 3706 | sb.setLength(0); |
| 3707 | sb.append(prefix); |
| 3708 | sb.append(" Estimated battery capacity: "); |
| 3709 | sb.append(BatteryStatsHelper.makemAh(estimatedBatteryCapacity)); |
| 3710 | sb.append(" mAh"); |
| 3711 | pw.println(sb.toString()); |
| 3712 | } |
| 3713 | |
Jocelyn Dang | c627d10 | 2017-04-14 13:15:14 -0700 | [diff] [blame] | 3714 | final int minLearnedBatteryCapacity = getMinLearnedBatteryCapacity(); |
| 3715 | if (minLearnedBatteryCapacity > 0) { |
| 3716 | sb.setLength(0); |
| 3717 | sb.append(prefix); |
| 3718 | sb.append(" Min learned battery capacity: "); |
| 3719 | sb.append(BatteryStatsHelper.makemAh(minLearnedBatteryCapacity / 1000)); |
| 3720 | sb.append(" mAh"); |
| 3721 | pw.println(sb.toString()); |
| 3722 | } |
| 3723 | final int maxLearnedBatteryCapacity = getMaxLearnedBatteryCapacity(); |
| 3724 | if (maxLearnedBatteryCapacity > 0) { |
| 3725 | sb.setLength(0); |
| 3726 | sb.append(prefix); |
| 3727 | sb.append(" Max learned battery capacity: "); |
| 3728 | sb.append(BatteryStatsHelper.makemAh(maxLearnedBatteryCapacity / 1000)); |
| 3729 | sb.append(" mAh"); |
| 3730 | pw.println(sb.toString()); |
| 3731 | } |
| 3732 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3733 | sb.setLength(0); |
| 3734 | sb.append(prefix); |
| 3735 | sb.append(" Time on battery: "); |
| 3736 | formatTimeMs(sb, whichBatteryRealtime / 1000); sb.append("("); |
| 3737 | sb.append(formatRatioLocked(whichBatteryRealtime, totalRealtime)); |
| 3738 | sb.append(") realtime, "); |
| 3739 | formatTimeMs(sb, whichBatteryUptime / 1000); |
| 3740 | sb.append("("); sb.append(formatRatioLocked(whichBatteryUptime, totalRealtime)); |
| 3741 | sb.append(") uptime"); |
| 3742 | pw.println(sb.toString()); |
| 3743 | sb.setLength(0); |
| 3744 | sb.append(prefix); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3745 | sb.append(" Time on battery screen off: "); |
| 3746 | formatTimeMs(sb, whichBatteryScreenOffRealtime / 1000); sb.append("("); |
| 3747 | sb.append(formatRatioLocked(whichBatteryScreenOffRealtime, totalRealtime)); |
| 3748 | sb.append(") realtime, "); |
| 3749 | formatTimeMs(sb, whichBatteryScreenOffUptime / 1000); |
| 3750 | sb.append("("); |
| 3751 | sb.append(formatRatioLocked(whichBatteryScreenOffUptime, totalRealtime)); |
| 3752 | sb.append(") uptime"); |
| 3753 | pw.println(sb.toString()); |
| 3754 | sb.setLength(0); |
| 3755 | sb.append(prefix); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3756 | sb.append(" Total run time: "); |
| 3757 | formatTimeMs(sb, totalRealtime / 1000); |
| 3758 | sb.append("realtime, "); |
| 3759 | formatTimeMs(sb, totalUptime / 1000); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 3760 | sb.append("uptime"); |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 3761 | pw.println(sb.toString()); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 3762 | if (batteryTimeRemaining >= 0) { |
| 3763 | sb.setLength(0); |
| 3764 | sb.append(prefix); |
| 3765 | sb.append(" Battery time remaining: "); |
| 3766 | formatTimeMs(sb, batteryTimeRemaining / 1000); |
| 3767 | pw.println(sb.toString()); |
| 3768 | } |
| 3769 | if (chargeTimeRemaining >= 0) { |
| 3770 | sb.setLength(0); |
| 3771 | sb.append(prefix); |
| 3772 | sb.append(" Charge time remaining: "); |
| 3773 | formatTimeMs(sb, chargeTimeRemaining / 1000); |
| 3774 | pw.println(sb.toString()); |
| 3775 | } |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 3776 | |
| 3777 | final LongCounter dischargeCounter = getDischargeCoulombCounter(); |
| 3778 | final long dischargeCount = dischargeCounter.getCountLocked(which); |
| 3779 | if (dischargeCount >= 0) { |
| 3780 | sb.setLength(0); |
| 3781 | sb.append(prefix); |
| 3782 | sb.append(" Discharge: "); |
| 3783 | sb.append(BatteryStatsHelper.makemAh(dischargeCount / 1000.0)); |
| 3784 | sb.append(" mAh"); |
| 3785 | pw.println(sb.toString()); |
| 3786 | } |
| 3787 | |
| 3788 | final LongCounter dischargeScreenOffCounter = getDischargeScreenOffCoulombCounter(); |
| 3789 | final long dischargeScreenOffCount = dischargeScreenOffCounter.getCountLocked(which); |
| 3790 | if (dischargeScreenOffCount >= 0) { |
| 3791 | sb.setLength(0); |
| 3792 | sb.append(prefix); |
| 3793 | sb.append(" Screen off discharge: "); |
| 3794 | sb.append(BatteryStatsHelper.makemAh(dischargeScreenOffCount / 1000.0)); |
| 3795 | sb.append(" mAh"); |
| 3796 | pw.println(sb.toString()); |
| 3797 | } |
| 3798 | |
| 3799 | final long dischargeScreenOnCount = dischargeCount - dischargeScreenOffCount; |
| 3800 | if (dischargeScreenOnCount >= 0) { |
| 3801 | sb.setLength(0); |
| 3802 | sb.append(prefix); |
| 3803 | sb.append(" Screen on discharge: "); |
| 3804 | sb.append(BatteryStatsHelper.makemAh(dischargeScreenOnCount / 1000.0)); |
| 3805 | sb.append(" mAh"); |
| 3806 | pw.println(sb.toString()); |
| 3807 | } |
| 3808 | |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 3809 | pw.print(" Start clock time: "); |
| 3810 | pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss", getStartClockTime()).toString()); |
| 3811 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3812 | final long screenOnTime = getScreenOnTime(rawRealtime, which); |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 3813 | final long interactiveTime = getInteractiveTime(rawRealtime, which); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3814 | final long powerSaveModeEnabledTime = getPowerSaveModeEnabledTime(rawRealtime, which); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3815 | final long deviceIdleModeLightTime = getDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT, |
| 3816 | rawRealtime, which); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 3817 | final long deviceIdleModeFullTime = getDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP, |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3818 | rawRealtime, which); |
| 3819 | final long deviceLightIdlingTime = getDeviceIdlingTime(DEVICE_IDLE_MODE_LIGHT, |
| 3820 | rawRealtime, which); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 3821 | final long deviceIdlingTime = getDeviceIdlingTime(DEVICE_IDLE_MODE_DEEP, |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3822 | rawRealtime, which); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3823 | final long phoneOnTime = getPhoneOnTime(rawRealtime, which); |
| 3824 | final long wifiRunningTime = getGlobalWifiRunningTime(rawRealtime, which); |
| 3825 | final long wifiOnTime = getWifiOnTime(rawRealtime, which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3826 | sb.setLength(0); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3827 | sb.append(prefix); |
| 3828 | sb.append(" Screen on: "); formatTimeMs(sb, screenOnTime / 1000); |
| 3829 | sb.append("("); sb.append(formatRatioLocked(screenOnTime, whichBatteryRealtime)); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 3830 | sb.append(") "); sb.append(getScreenOnCount(which)); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3831 | sb.append("x, Interactive: "); formatTimeMs(sb, interactiveTime / 1000); |
| 3832 | sb.append("("); sb.append(formatRatioLocked(interactiveTime, whichBatteryRealtime)); |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 3833 | sb.append(")"); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3834 | pw.println(sb.toString()); |
| 3835 | sb.setLength(0); |
| 3836 | sb.append(prefix); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 3837 | sb.append(" Screen brightnesses:"); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3838 | boolean didOne = false; |
| 3839 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3840 | final long time = getScreenBrightnessTime(i, rawRealtime, which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3841 | if (time == 0) { |
| 3842 | continue; |
| 3843 | } |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 3844 | sb.append("\n "); |
| 3845 | sb.append(prefix); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3846 | didOne = true; |
| 3847 | sb.append(SCREEN_BRIGHTNESS_NAMES[i]); |
| 3848 | sb.append(" "); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3849 | formatTimeMs(sb, time/1000); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3850 | sb.append("("); |
| 3851 | sb.append(formatRatioLocked(time, screenOnTime)); |
| 3852 | sb.append(")"); |
| 3853 | } |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 3854 | if (!didOne) sb.append(" (no activity)"); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3855 | pw.println(sb.toString()); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3856 | if (powerSaveModeEnabledTime != 0) { |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3857 | sb.setLength(0); |
| 3858 | sb.append(prefix); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3859 | sb.append(" Power save mode enabled: "); |
| 3860 | formatTimeMs(sb, powerSaveModeEnabledTime / 1000); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3861 | sb.append("("); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3862 | sb.append(formatRatioLocked(powerSaveModeEnabledTime, whichBatteryRealtime)); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3863 | sb.append(")"); |
| 3864 | pw.println(sb.toString()); |
| 3865 | } |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3866 | if (deviceLightIdlingTime != 0) { |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3867 | sb.setLength(0); |
| 3868 | sb.append(prefix); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3869 | sb.append(" Device light idling: "); |
| 3870 | formatTimeMs(sb, deviceLightIdlingTime / 1000); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 3871 | sb.append("("); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3872 | sb.append(formatRatioLocked(deviceLightIdlingTime, whichBatteryRealtime)); |
| 3873 | sb.append(") "); sb.append(getDeviceIdlingCount(DEVICE_IDLE_MODE_LIGHT, which)); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 3874 | sb.append("x"); |
| 3875 | pw.println(sb.toString()); |
| 3876 | } |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3877 | if (deviceIdleModeLightTime != 0) { |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 3878 | sb.setLength(0); |
| 3879 | sb.append(prefix); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3880 | sb.append(" Idle mode light time: "); |
| 3881 | formatTimeMs(sb, deviceIdleModeLightTime / 1000); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3882 | sb.append("("); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3883 | sb.append(formatRatioLocked(deviceIdleModeLightTime, whichBatteryRealtime)); |
| 3884 | sb.append(") "); |
| 3885 | sb.append(getDeviceIdleModeCount(DEVICE_IDLE_MODE_LIGHT, which)); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3886 | sb.append("x"); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3887 | sb.append(" -- longest "); |
| 3888 | formatTimeMs(sb, getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT)); |
| 3889 | pw.println(sb.toString()); |
| 3890 | } |
| 3891 | if (deviceIdlingTime != 0) { |
| 3892 | sb.setLength(0); |
| 3893 | sb.append(prefix); |
| 3894 | sb.append(" Device full idling: "); |
| 3895 | formatTimeMs(sb, deviceIdlingTime / 1000); |
| 3896 | sb.append("("); |
| 3897 | sb.append(formatRatioLocked(deviceIdlingTime, whichBatteryRealtime)); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 3898 | sb.append(") "); sb.append(getDeviceIdlingCount(DEVICE_IDLE_MODE_DEEP, which)); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3899 | sb.append("x"); |
| 3900 | pw.println(sb.toString()); |
| 3901 | } |
| 3902 | if (deviceIdleModeFullTime != 0) { |
| 3903 | sb.setLength(0); |
| 3904 | sb.append(prefix); |
| 3905 | sb.append(" Idle mode full time: "); |
| 3906 | formatTimeMs(sb, deviceIdleModeFullTime / 1000); |
| 3907 | sb.append("("); |
| 3908 | sb.append(formatRatioLocked(deviceIdleModeFullTime, whichBatteryRealtime)); |
| 3909 | sb.append(") "); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 3910 | sb.append(getDeviceIdleModeCount(DEVICE_IDLE_MODE_DEEP, which)); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3911 | sb.append("x"); |
| 3912 | sb.append(" -- longest "); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 3913 | formatTimeMs(sb, getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP)); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3914 | pw.println(sb.toString()); |
| 3915 | } |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3916 | if (phoneOnTime != 0) { |
| 3917 | sb.setLength(0); |
| 3918 | sb.append(prefix); |
| 3919 | sb.append(" Active phone call: "); formatTimeMs(sb, phoneOnTime / 1000); |
| 3920 | sb.append("("); sb.append(formatRatioLocked(phoneOnTime, whichBatteryRealtime)); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3921 | sb.append(") "); sb.append(getPhoneOnCount(which)); sb.append("x"); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3922 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3923 | final int connChanges = getNumConnectivityChange(which); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 3924 | if (connChanges != 0) { |
| 3925 | pw.print(prefix); |
| 3926 | pw.print(" Connectivity changes: "); pw.println(connChanges); |
| 3927 | } |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3928 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3929 | // Calculate wakelock times across all uids. |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 3930 | long fullWakeLockTimeTotalMicros = 0; |
| 3931 | long partialWakeLockTimeTotalMicros = 0; |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 3932 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3933 | final ArrayList<TimerEntry> timers = new ArrayList<>(); |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 3934 | |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 3935 | for (int iu = 0; iu < NU; iu++) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3936 | final Uid u = uidStats.valueAt(iu); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 3937 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3938 | final ArrayMap<String, ? extends BatteryStats.Uid.Wakelock> wakelocks |
| 3939 | = u.getWakelockStats(); |
| 3940 | for (int iw=wakelocks.size()-1; iw>=0; iw--) { |
| 3941 | final Uid.Wakelock wl = wakelocks.valueAt(iw); |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 3942 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3943 | final Timer fullWakeTimer = wl.getWakeTime(WAKE_TYPE_FULL); |
| 3944 | if (fullWakeTimer != null) { |
| 3945 | fullWakeLockTimeTotalMicros += fullWakeTimer.getTotalTimeLocked( |
| 3946 | rawRealtime, which); |
| 3947 | } |
| 3948 | |
| 3949 | final Timer partialWakeTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL); |
| 3950 | if (partialWakeTimer != null) { |
| 3951 | final long totalTimeMicros = partialWakeTimer.getTotalTimeLocked( |
| 3952 | rawRealtime, which); |
| 3953 | if (totalTimeMicros > 0) { |
| 3954 | if (reqUid < 0) { |
| 3955 | // Only show the ordered list of all wake |
| 3956 | // locks if the caller is not asking for data |
| 3957 | // about a specific uid. |
| 3958 | timers.add(new TimerEntry(wakelocks.keyAt(iw), u.getUid(), |
| 3959 | partialWakeTimer, totalTimeMicros)); |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 3960 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3961 | partialWakeLockTimeTotalMicros += totalTimeMicros; |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 3962 | } |
| 3963 | } |
| 3964 | } |
| 3965 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3966 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3967 | final long mobileRxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which); |
| 3968 | final long mobileTxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which); |
| 3969 | final long wifiRxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which); |
| 3970 | final long wifiTxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which); |
| 3971 | final long mobileRxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which); |
| 3972 | final long mobileTxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which); |
| 3973 | final long wifiRxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which); |
| 3974 | final long wifiTxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which); |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 3975 | final long btRxTotalBytes = getNetworkActivityBytes(NETWORK_BT_RX_DATA, which); |
| 3976 | final long btTxTotalBytes = getNetworkActivityBytes(NETWORK_BT_TX_DATA, which); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3977 | |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 3978 | if (fullWakeLockTimeTotalMicros != 0) { |
| 3979 | sb.setLength(0); |
| 3980 | sb.append(prefix); |
| 3981 | sb.append(" Total full wakelock time: "); formatTimeMsNoSpace(sb, |
| 3982 | (fullWakeLockTimeTotalMicros + 500) / 1000); |
| 3983 | pw.println(sb.toString()); |
| 3984 | } |
| 3985 | |
| 3986 | if (partialWakeLockTimeTotalMicros != 0) { |
| 3987 | sb.setLength(0); |
| 3988 | sb.append(prefix); |
| 3989 | sb.append(" Total partial wakelock time: "); formatTimeMsNoSpace(sb, |
| 3990 | (partialWakeLockTimeTotalMicros + 500) / 1000); |
| 3991 | pw.println(sb.toString()); |
| 3992 | } |
| 3993 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3994 | pw.print(prefix); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3995 | pw.print(" Mobile total received: "); pw.print(formatBytesLocked(mobileRxTotalBytes)); |
| 3996 | pw.print(", sent: "); pw.print(formatBytesLocked(mobileTxTotalBytes)); |
| 3997 | pw.print(" (packets received "); pw.print(mobileRxTotalPackets); |
| 3998 | pw.print(", sent "); pw.print(mobileTxTotalPackets); pw.println(")"); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3999 | sb.setLength(0); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4000 | sb.append(prefix); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 4001 | sb.append(" Phone signal levels:"); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4002 | didOne = false; |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 4003 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4004 | final long time = getPhoneSignalStrengthTime(i, rawRealtime, which); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4005 | if (time == 0) { |
| 4006 | continue; |
| 4007 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 4008 | sb.append("\n "); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 4009 | sb.append(prefix); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4010 | didOne = true; |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 4011 | sb.append(SignalStrength.SIGNAL_STRENGTH_NAMES[i]); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4012 | sb.append(" "); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4013 | formatTimeMs(sb, time/1000); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4014 | sb.append("("); |
| 4015 | sb.append(formatRatioLocked(time, whichBatteryRealtime)); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4016 | sb.append(") "); |
| 4017 | sb.append(getPhoneSignalStrengthCount(i, which)); |
| 4018 | sb.append("x"); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4019 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 4020 | if (!didOne) sb.append(" (no activity)"); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4021 | pw.println(sb.toString()); |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 4022 | |
| 4023 | sb.setLength(0); |
| 4024 | sb.append(prefix); |
| 4025 | sb.append(" Signal scanning time: "); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4026 | formatTimeMsNoSpace(sb, getPhoneSignalScanningTime(rawRealtime, which) / 1000); |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 4027 | pw.println(sb.toString()); |
| 4028 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4029 | sb.setLength(0); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4030 | sb.append(prefix); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 4031 | sb.append(" Radio types:"); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4032 | didOne = false; |
| 4033 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4034 | final long time = getPhoneDataConnectionTime(i, rawRealtime, which); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4035 | if (time == 0) { |
| 4036 | continue; |
| 4037 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 4038 | sb.append("\n "); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 4039 | sb.append(prefix); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4040 | didOne = true; |
| 4041 | sb.append(DATA_CONNECTION_NAMES[i]); |
| 4042 | sb.append(" "); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4043 | formatTimeMs(sb, time/1000); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4044 | sb.append("("); |
| 4045 | sb.append(formatRatioLocked(time, whichBatteryRealtime)); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4046 | sb.append(") "); |
| 4047 | sb.append(getPhoneDataConnectionCount(i, which)); |
| 4048 | sb.append("x"); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4049 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 4050 | if (!didOne) sb.append(" (no activity)"); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4051 | pw.println(sb.toString()); |
Amith Yamasani | 3f7e35c | 2009-07-13 16:02:45 -0700 | [diff] [blame] | 4052 | |
| 4053 | sb.setLength(0); |
| 4054 | sb.append(prefix); |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 4055 | sb.append(" Mobile radio active time: "); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4056 | final long mobileActiveTime = getMobileRadioActiveTime(rawRealtime, which); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4057 | formatTimeMs(sb, mobileActiveTime / 1000); |
| 4058 | sb.append("("); sb.append(formatRatioLocked(mobileActiveTime, whichBatteryRealtime)); |
| 4059 | sb.append(") "); sb.append(getMobileRadioActiveCount(which)); |
| 4060 | sb.append("x"); |
Amith Yamasani | 3f7e35c | 2009-07-13 16:02:45 -0700 | [diff] [blame] | 4061 | pw.println(sb.toString()); |
| 4062 | |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4063 | final long mobileActiveUnknownTime = getMobileRadioActiveUnknownTime(which); |
| 4064 | if (mobileActiveUnknownTime != 0) { |
| 4065 | sb.setLength(0); |
| 4066 | sb.append(prefix); |
| 4067 | sb.append(" Mobile radio active unknown time: "); |
| 4068 | formatTimeMs(sb, mobileActiveUnknownTime / 1000); |
| 4069 | sb.append("("); |
| 4070 | sb.append(formatRatioLocked(mobileActiveUnknownTime, whichBatteryRealtime)); |
| 4071 | sb.append(") "); sb.append(getMobileRadioActiveUnknownCount(which)); |
| 4072 | sb.append("x"); |
| 4073 | pw.println(sb.toString()); |
| 4074 | } |
| 4075 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 4076 | final long mobileActiveAdjustedTime = getMobileRadioActiveAdjustedTime(which); |
| 4077 | if (mobileActiveAdjustedTime != 0) { |
| 4078 | sb.setLength(0); |
| 4079 | sb.append(prefix); |
| 4080 | sb.append(" Mobile radio active adjusted time: "); |
| 4081 | formatTimeMs(sb, mobileActiveAdjustedTime / 1000); |
| 4082 | sb.append("("); |
| 4083 | sb.append(formatRatioLocked(mobileActiveAdjustedTime, whichBatteryRealtime)); |
| 4084 | sb.append(")"); |
| 4085 | pw.println(sb.toString()); |
| 4086 | } |
| 4087 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 4088 | printControllerActivity(pw, sb, prefix, "Radio", getModemControllerActivity(), which); |
| 4089 | |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 4090 | pw.print(prefix); |
| 4091 | pw.print(" Wi-Fi total received: "); pw.print(formatBytesLocked(wifiRxTotalBytes)); |
| 4092 | pw.print(", sent: "); pw.print(formatBytesLocked(wifiTxTotalBytes)); |
| 4093 | pw.print(" (packets received "); pw.print(wifiRxTotalPackets); |
| 4094 | pw.print(", sent "); pw.print(wifiTxTotalPackets); pw.println(")"); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4095 | sb.setLength(0); |
| 4096 | sb.append(prefix); |
| 4097 | sb.append(" Wifi on: "); formatTimeMs(sb, wifiOnTime / 1000); |
| 4098 | sb.append("("); sb.append(formatRatioLocked(wifiOnTime, whichBatteryRealtime)); |
| 4099 | sb.append("), Wifi running: "); formatTimeMs(sb, wifiRunningTime / 1000); |
| 4100 | sb.append("("); sb.append(formatRatioLocked(wifiRunningTime, whichBatteryRealtime)); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4101 | sb.append(")"); |
| 4102 | pw.println(sb.toString()); |
| 4103 | |
| 4104 | sb.setLength(0); |
| 4105 | sb.append(prefix); |
| 4106 | sb.append(" Wifi states:"); |
| 4107 | didOne = false; |
| 4108 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4109 | final long time = getWifiStateTime(i, rawRealtime, which); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4110 | if (time == 0) { |
| 4111 | continue; |
| 4112 | } |
| 4113 | sb.append("\n "); |
| 4114 | didOne = true; |
| 4115 | sb.append(WIFI_STATE_NAMES[i]); |
| 4116 | sb.append(" "); |
| 4117 | formatTimeMs(sb, time/1000); |
| 4118 | sb.append("("); |
| 4119 | sb.append(formatRatioLocked(time, whichBatteryRealtime)); |
| 4120 | sb.append(") "); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 4121 | sb.append(getWifiStateCount(i, which)); |
| 4122 | sb.append("x"); |
| 4123 | } |
| 4124 | if (!didOne) sb.append(" (no activity)"); |
| 4125 | pw.println(sb.toString()); |
| 4126 | |
| 4127 | sb.setLength(0); |
| 4128 | sb.append(prefix); |
| 4129 | sb.append(" Wifi supplicant states:"); |
| 4130 | didOne = false; |
| 4131 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
| 4132 | final long time = getWifiSupplStateTime(i, rawRealtime, which); |
| 4133 | if (time == 0) { |
| 4134 | continue; |
| 4135 | } |
| 4136 | sb.append("\n "); |
| 4137 | didOne = true; |
| 4138 | sb.append(WIFI_SUPPL_STATE_NAMES[i]); |
| 4139 | sb.append(" "); |
| 4140 | formatTimeMs(sb, time/1000); |
| 4141 | sb.append("("); |
| 4142 | sb.append(formatRatioLocked(time, whichBatteryRealtime)); |
| 4143 | sb.append(") "); |
| 4144 | sb.append(getWifiSupplStateCount(i, which)); |
| 4145 | sb.append("x"); |
| 4146 | } |
| 4147 | if (!didOne) sb.append(" (no activity)"); |
| 4148 | pw.println(sb.toString()); |
| 4149 | |
| 4150 | sb.setLength(0); |
| 4151 | sb.append(prefix); |
| 4152 | sb.append(" Wifi signal levels:"); |
| 4153 | didOne = false; |
| 4154 | for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 4155 | final long time = getWifiSignalStrengthTime(i, rawRealtime, which); |
| 4156 | if (time == 0) { |
| 4157 | continue; |
| 4158 | } |
| 4159 | sb.append("\n "); |
| 4160 | sb.append(prefix); |
| 4161 | didOne = true; |
| 4162 | sb.append("level("); |
| 4163 | sb.append(i); |
| 4164 | sb.append(") "); |
| 4165 | formatTimeMs(sb, time/1000); |
| 4166 | sb.append("("); |
| 4167 | sb.append(formatRatioLocked(time, whichBatteryRealtime)); |
| 4168 | sb.append(") "); |
| 4169 | sb.append(getWifiSignalStrengthCount(i, which)); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4170 | sb.append("x"); |
| 4171 | } |
| 4172 | if (!didOne) sb.append(" (no activity)"); |
| 4173 | pw.println(sb.toString()); |
| 4174 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 4175 | printControllerActivity(pw, sb, prefix, "WiFi", getWifiControllerActivity(), which); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 4176 | |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 4177 | pw.print(prefix); |
| 4178 | pw.print(" Bluetooth total received: "); pw.print(formatBytesLocked(btRxTotalBytes)); |
| 4179 | pw.print(", sent: "); pw.println(formatBytesLocked(btTxTotalBytes)); |
| 4180 | |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 4181 | final long bluetoothScanTimeMs = getBluetoothScanTime(rawRealtime, which) / 1000; |
| 4182 | sb.setLength(0); |
| 4183 | sb.append(prefix); |
| 4184 | sb.append(" Bluetooth scan time: "); formatTimeMs(sb, bluetoothScanTimeMs); |
| 4185 | pw.println(sb.toString()); |
| 4186 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 4187 | printControllerActivity(pw, sb, prefix, "Bluetooth", getBluetoothControllerActivity(), |
| 4188 | which); |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 4189 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4190 | pw.println(); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4191 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4192 | if (which == STATS_SINCE_UNPLUGGED) { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4193 | if (getIsOnBattery()) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4194 | pw.print(prefix); pw.println(" Device is currently unplugged"); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 4195 | pw.print(prefix); pw.print(" Discharge cycle start level: "); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4196 | pw.println(getDischargeStartLevel()); |
| 4197 | pw.print(prefix); pw.print(" Discharge cycle current level: "); |
| 4198 | pw.println(getDischargeCurrentLevel()); |
Dianne Hackborn | 99d0452 | 2010-08-20 13:43:00 -0700 | [diff] [blame] | 4199 | } else { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4200 | pw.print(prefix); pw.println(" Device is currently plugged into power"); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 4201 | pw.print(prefix); pw.print(" Last discharge cycle start level: "); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4202 | pw.println(getDischargeStartLevel()); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 4203 | pw.print(prefix); pw.print(" Last discharge cycle end level: "); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4204 | pw.println(getDischargeCurrentLevel()); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4205 | } |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 4206 | pw.print(prefix); pw.print(" Amount discharged while screen on: "); |
| 4207 | pw.println(getDischargeAmountScreenOn()); |
| 4208 | pw.print(prefix); pw.print(" Amount discharged while screen off: "); |
| 4209 | pw.println(getDischargeAmountScreenOff()); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4210 | pw.println(" "); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4211 | } else { |
| 4212 | pw.print(prefix); pw.println(" Device battery use since last full charge"); |
| 4213 | pw.print(prefix); pw.print(" Amount discharged (lower bound): "); |
| 4214 | pw.println(getLowDischargeAmountSinceCharge()); |
| 4215 | pw.print(prefix); pw.print(" Amount discharged (upper bound): "); |
| 4216 | pw.println(getHighDischargeAmountSinceCharge()); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 4217 | pw.print(prefix); pw.print(" Amount discharged while screen on: "); |
| 4218 | pw.println(getDischargeAmountScreenOnSinceCharge()); |
| 4219 | pw.print(prefix); pw.print(" Amount discharged while screen off: "); |
| 4220 | pw.println(getDischargeAmountScreenOffSinceCharge()); |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 4221 | pw.println(); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4222 | } |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 4223 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4224 | final BatteryStatsHelper helper = new BatteryStatsHelper(context, false, wifiOnly); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4225 | helper.create(this); |
| 4226 | helper.refreshStats(which, UserHandle.USER_ALL); |
| 4227 | List<BatterySipper> sippers = helper.getUsageList(); |
| 4228 | if (sippers != null && sippers.size() > 0) { |
| 4229 | pw.print(prefix); pw.println(" Estimated power use (mAh):"); |
| 4230 | pw.print(prefix); pw.print(" Capacity: "); |
| 4231 | printmAh(pw, helper.getPowerProfile().getBatteryCapacity()); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4232 | pw.print(", Computed drain: "); printmAh(pw, helper.getComputedPower()); |
Dianne Hackborn | 536456f | 2014-05-23 16:51:05 -0700 | [diff] [blame] | 4233 | pw.print(", actual drain: "); printmAh(pw, helper.getMinDrainedPower()); |
| 4234 | if (helper.getMinDrainedPower() != helper.getMaxDrainedPower()) { |
| 4235 | pw.print("-"); printmAh(pw, helper.getMaxDrainedPower()); |
| 4236 | } |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4237 | pw.println(); |
| 4238 | for (int i=0; i<sippers.size(); i++) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4239 | final BatterySipper bs = sippers.get(i); |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4240 | pw.print(prefix); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4241 | switch (bs.drainType) { |
| 4242 | case IDLE: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4243 | pw.print(" Idle: "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4244 | break; |
| 4245 | case CELL: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4246 | pw.print(" Cell standby: "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4247 | break; |
| 4248 | case PHONE: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4249 | pw.print(" Phone calls: "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4250 | break; |
| 4251 | case WIFI: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4252 | pw.print(" Wifi: "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4253 | break; |
| 4254 | case BLUETOOTH: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4255 | pw.print(" Bluetooth: "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4256 | break; |
| 4257 | case SCREEN: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4258 | pw.print(" Screen: "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4259 | break; |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 4260 | case FLASHLIGHT: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4261 | pw.print(" Flashlight: "); |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 4262 | break; |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4263 | case APP: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4264 | pw.print(" Uid "); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4265 | UserHandle.formatUid(pw, bs.uidObj.getUid()); |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4266 | pw.print(": "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4267 | break; |
| 4268 | case USER: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4269 | pw.print(" User "); pw.print(bs.userId); |
| 4270 | pw.print(": "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4271 | break; |
| 4272 | case UNACCOUNTED: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4273 | pw.print(" Unaccounted: "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4274 | break; |
| 4275 | case OVERCOUNTED: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4276 | pw.print(" Over-counted: "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4277 | break; |
Ruben Brunk | 5b1308f | 2015-06-03 18:49:27 -0700 | [diff] [blame] | 4278 | case CAMERA: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4279 | pw.print(" Camera: "); |
| 4280 | break; |
| 4281 | default: |
| 4282 | pw.print(" ???: "); |
Ruben Brunk | 5b1308f | 2015-06-03 18:49:27 -0700 | [diff] [blame] | 4283 | break; |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4284 | } |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4285 | printmAh(pw, bs.totalPowerMah); |
| 4286 | |
Adam Lesinski | 5712300 | 2015-06-12 16:12:07 -0700 | [diff] [blame] | 4287 | if (bs.usagePowerMah != bs.totalPowerMah) { |
| 4288 | // If the usage (generic power) isn't the whole amount, we list out |
| 4289 | // what components are involved in the calculation. |
| 4290 | |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4291 | pw.print(" ("); |
Adam Lesinski | 5712300 | 2015-06-12 16:12:07 -0700 | [diff] [blame] | 4292 | if (bs.usagePowerMah != 0) { |
| 4293 | pw.print(" usage="); |
| 4294 | printmAh(pw, bs.usagePowerMah); |
| 4295 | } |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4296 | if (bs.cpuPowerMah != 0) { |
| 4297 | pw.print(" cpu="); |
| 4298 | printmAh(pw, bs.cpuPowerMah); |
| 4299 | } |
| 4300 | if (bs.wakeLockPowerMah != 0) { |
| 4301 | pw.print(" wake="); |
| 4302 | printmAh(pw, bs.wakeLockPowerMah); |
| 4303 | } |
| 4304 | if (bs.mobileRadioPowerMah != 0) { |
| 4305 | pw.print(" radio="); |
| 4306 | printmAh(pw, bs.mobileRadioPowerMah); |
| 4307 | } |
| 4308 | if (bs.wifiPowerMah != 0) { |
| 4309 | pw.print(" wifi="); |
| 4310 | printmAh(pw, bs.wifiPowerMah); |
| 4311 | } |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 4312 | if (bs.bluetoothPowerMah != 0) { |
| 4313 | pw.print(" bt="); |
| 4314 | printmAh(pw, bs.bluetoothPowerMah); |
| 4315 | } |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4316 | if (bs.gpsPowerMah != 0) { |
| 4317 | pw.print(" gps="); |
| 4318 | printmAh(pw, bs.gpsPowerMah); |
| 4319 | } |
| 4320 | if (bs.sensorPowerMah != 0) { |
| 4321 | pw.print(" sensor="); |
| 4322 | printmAh(pw, bs.sensorPowerMah); |
| 4323 | } |
| 4324 | if (bs.cameraPowerMah != 0) { |
| 4325 | pw.print(" camera="); |
| 4326 | printmAh(pw, bs.cameraPowerMah); |
| 4327 | } |
| 4328 | if (bs.flashlightPowerMah != 0) { |
| 4329 | pw.print(" flash="); |
| 4330 | printmAh(pw, bs.flashlightPowerMah); |
| 4331 | } |
| 4332 | pw.print(" )"); |
| 4333 | } |
| 4334 | pw.println(); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4335 | } |
Dianne Hackborn | c46809e | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4336 | pw.println(); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4337 | } |
| 4338 | |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4339 | sippers = helper.getMobilemsppList(); |
| 4340 | if (sippers != null && sippers.size() > 0) { |
| 4341 | pw.print(prefix); pw.println(" Per-app mobile ms per packet:"); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 4342 | long totalTime = 0; |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4343 | for (int i=0; i<sippers.size(); i++) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4344 | final BatterySipper bs = sippers.get(i); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4345 | sb.setLength(0); |
| 4346 | sb.append(prefix); sb.append(" Uid "); |
| 4347 | UserHandle.formatUid(sb, bs.uidObj.getUid()); |
| 4348 | sb.append(": "); sb.append(BatteryStatsHelper.makemAh(bs.mobilemspp)); |
| 4349 | sb.append(" ("); sb.append(bs.mobileRxPackets+bs.mobileTxPackets); |
| 4350 | sb.append(" packets over "); formatTimeMsNoSpace(sb, bs.mobileActive); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 4351 | sb.append(") "); sb.append(bs.mobileActiveCount); sb.append("x"); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4352 | pw.println(sb.toString()); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 4353 | totalTime += bs.mobileActive; |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4354 | } |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 4355 | sb.setLength(0); |
| 4356 | sb.append(prefix); |
| 4357 | sb.append(" TOTAL TIME: "); |
| 4358 | formatTimeMs(sb, totalTime); |
| 4359 | sb.append("("); sb.append(formatRatioLocked(totalTime, whichBatteryRealtime)); |
| 4360 | sb.append(")"); |
| 4361 | pw.println(sb.toString()); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4362 | pw.println(); |
| 4363 | } |
| 4364 | |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 4365 | final Comparator<TimerEntry> timerComparator = new Comparator<TimerEntry>() { |
| 4366 | @Override |
| 4367 | public int compare(TimerEntry lhs, TimerEntry rhs) { |
| 4368 | long lhsTime = lhs.mTime; |
| 4369 | long rhsTime = rhs.mTime; |
| 4370 | if (lhsTime < rhsTime) { |
| 4371 | return 1; |
| 4372 | } |
| 4373 | if (lhsTime > rhsTime) { |
| 4374 | return -1; |
| 4375 | } |
| 4376 | return 0; |
| 4377 | } |
| 4378 | }; |
| 4379 | |
| 4380 | if (reqUid < 0) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4381 | final Map<String, ? extends BatteryStats.Timer> kernelWakelocks |
| 4382 | = getKernelWakelockStats(); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 4383 | if (kernelWakelocks.size() > 0) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4384 | final ArrayList<TimerEntry> ktimers = new ArrayList<>(); |
| 4385 | for (Map.Entry<String, ? extends BatteryStats.Timer> ent |
| 4386 | : kernelWakelocks.entrySet()) { |
| 4387 | final BatteryStats.Timer timer = ent.getValue(); |
| 4388 | final long totalTimeMillis = computeWakeLock(timer, rawRealtime, which); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 4389 | if (totalTimeMillis > 0) { |
| 4390 | ktimers.add(new TimerEntry(ent.getKey(), 0, timer, totalTimeMillis)); |
| 4391 | } |
| 4392 | } |
| 4393 | if (ktimers.size() > 0) { |
| 4394 | Collections.sort(ktimers, timerComparator); |
| 4395 | pw.print(prefix); pw.println(" All kernel wake locks:"); |
| 4396 | for (int i=0; i<ktimers.size(); i++) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4397 | final TimerEntry timer = ktimers.get(i); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 4398 | String linePrefix = ": "; |
| 4399 | sb.setLength(0); |
| 4400 | sb.append(prefix); |
| 4401 | sb.append(" Kernel Wake lock "); |
| 4402 | sb.append(timer.mName); |
| 4403 | linePrefix = printWakeLock(sb, timer.mTimer, rawRealtime, null, |
| 4404 | which, linePrefix); |
| 4405 | if (!linePrefix.equals(": ")) { |
| 4406 | sb.append(" realtime"); |
| 4407 | // Only print out wake locks that were held |
| 4408 | pw.println(sb.toString()); |
| 4409 | } |
| 4410 | } |
| 4411 | pw.println(); |
| 4412 | } |
| 4413 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 4414 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 4415 | if (timers.size() > 0) { |
| 4416 | Collections.sort(timers, timerComparator); |
| 4417 | pw.print(prefix); pw.println(" All partial wake locks:"); |
| 4418 | for (int i=0; i<timers.size(); i++) { |
| 4419 | TimerEntry timer = timers.get(i); |
| 4420 | sb.setLength(0); |
| 4421 | sb.append(" Wake lock "); |
| 4422 | UserHandle.formatUid(sb, timer.mId); |
| 4423 | sb.append(" "); |
| 4424 | sb.append(timer.mName); |
| 4425 | printWakeLock(sb, timer.mTimer, rawRealtime, null, which, ": "); |
| 4426 | sb.append(" realtime"); |
| 4427 | pw.println(sb.toString()); |
| 4428 | } |
| 4429 | timers.clear(); |
| 4430 | pw.println(); |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 4431 | } |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 4432 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4433 | final Map<String, ? extends Timer> wakeupReasons = getWakeupReasonStats(); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 4434 | if (wakeupReasons.size() > 0) { |
| 4435 | pw.print(prefix); pw.println(" All wakeup reasons:"); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4436 | final ArrayList<TimerEntry> reasons = new ArrayList<>(); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 4437 | for (Map.Entry<String, ? extends Timer> ent : wakeupReasons.entrySet()) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4438 | final Timer timer = ent.getValue(); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 4439 | reasons.add(new TimerEntry(ent.getKey(), 0, timer, |
| 4440 | timer.getCountLocked(which))); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 4441 | } |
| 4442 | Collections.sort(reasons, timerComparator); |
| 4443 | for (int i=0; i<reasons.size(); i++) { |
| 4444 | TimerEntry timer = reasons.get(i); |
| 4445 | String linePrefix = ": "; |
| 4446 | sb.setLength(0); |
| 4447 | sb.append(prefix); |
| 4448 | sb.append(" Wakeup reason "); |
| 4449 | sb.append(timer.mName); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 4450 | printWakeLock(sb, timer.mTimer, rawRealtime, null, which, ": "); |
| 4451 | sb.append(" realtime"); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 4452 | pw.println(sb.toString()); |
| 4453 | } |
| 4454 | pw.println(); |
| 4455 | } |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 4456 | } |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 4457 | |
James Carr | 2dd7e5e | 2016-07-20 18:48:39 -0700 | [diff] [blame] | 4458 | final LongSparseArray<? extends Timer> mMemoryStats = getKernelMemoryStats(); |
| 4459 | pw.println("Memory Stats"); |
| 4460 | for (int i = 0; i < mMemoryStats.size(); i++) { |
| 4461 | sb.setLength(0); |
| 4462 | sb.append("Bandwidth "); |
| 4463 | sb.append(mMemoryStats.keyAt(i)); |
| 4464 | sb.append(" Time "); |
| 4465 | sb.append(mMemoryStats.valueAt(i).getTotalTimeLocked(rawRealtime, which)); |
| 4466 | pw.println(sb.toString()); |
| 4467 | } |
| 4468 | |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 4469 | final long[] cpuFreqs = getCpuFreqs(); |
| 4470 | if (cpuFreqs != null) { |
| 4471 | sb.setLength(0); |
| 4472 | sb.append("CPU freqs:"); |
| 4473 | for (int i = 0; i < cpuFreqs.length; ++i) { |
| 4474 | sb.append(" " + cpuFreqs[i]); |
| 4475 | } |
| 4476 | pw.println(sb.toString()); |
| 4477 | } |
| 4478 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4479 | for (int iu=0; iu<NU; iu++) { |
| 4480 | final int uid = uidStats.keyAt(iu); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 4481 | if (reqUid >= 0 && uid != reqUid && uid != Process.SYSTEM_UID) { |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 4482 | continue; |
| 4483 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 4484 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4485 | final Uid u = uidStats.valueAt(iu); |
Dianne Hackborn | a4cc205 | 2013-07-08 17:31:25 -0700 | [diff] [blame] | 4486 | |
| 4487 | pw.print(prefix); |
| 4488 | pw.print(" "); |
| 4489 | UserHandle.formatUid(pw, uid); |
| 4490 | pw.println(":"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4491 | boolean uidActivity = false; |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4492 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4493 | final long mobileRxBytes = u.getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which); |
| 4494 | final long mobileTxBytes = u.getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which); |
| 4495 | final long wifiRxBytes = u.getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which); |
| 4496 | final long wifiTxBytes = u.getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which); |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 4497 | final long btRxBytes = u.getNetworkActivityBytes(NETWORK_BT_RX_DATA, which); |
| 4498 | final long btTxBytes = u.getNetworkActivityBytes(NETWORK_BT_TX_DATA, which); |
| 4499 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4500 | final long mobileRxPackets = u.getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which); |
| 4501 | final long mobileTxPackets = u.getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4502 | final long wifiRxPackets = u.getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which); |
| 4503 | final long wifiTxPackets = u.getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which); |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 4504 | |
| 4505 | final long uidMobileActiveTime = u.getMobileRadioActiveTime(which); |
| 4506 | final int uidMobileActiveCount = u.getMobileRadioActiveCount(which); |
| 4507 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4508 | final long fullWifiLockOnTime = u.getFullWifiLockTime(rawRealtime, which); |
| 4509 | final long wifiScanTime = u.getWifiScanTime(rawRealtime, which); |
| 4510 | final int wifiScanCount = u.getWifiScanCount(which); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 4511 | final int wifiScanCountBg = u.getWifiScanBackgroundCount(which); |
| 4512 | // 'actualTime' are unpooled and always since reset (regardless of 'which') |
| 4513 | final long wifiScanActualTime = u.getWifiScanActualTime(rawRealtime); |
| 4514 | final long wifiScanActualTimeBg = u.getWifiScanBackgroundTime(rawRealtime); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4515 | final long uidWifiRunningTime = u.getWifiRunningTime(rawRealtime, which); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 4516 | |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 4517 | final long mobileWakeup = u.getMobileRadioApWakeupCount(which); |
| 4518 | final long wifiWakeup = u.getWifiRadioApWakeupCount(which); |
| 4519 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4520 | if (mobileRxBytes > 0 || mobileTxBytes > 0 |
| 4521 | || mobileRxPackets > 0 || mobileTxPackets > 0) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 4522 | pw.print(prefix); pw.print(" Mobile network: "); |
| 4523 | pw.print(formatBytesLocked(mobileRxBytes)); pw.print(" received, "); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4524 | pw.print(formatBytesLocked(mobileTxBytes)); |
| 4525 | pw.print(" sent (packets "); pw.print(mobileRxPackets); |
| 4526 | pw.print(" received, "); pw.print(mobileTxPackets); pw.println(" sent)"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4527 | } |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4528 | if (uidMobileActiveTime > 0 || uidMobileActiveCount > 0) { |
| 4529 | sb.setLength(0); |
| 4530 | sb.append(prefix); sb.append(" Mobile radio active: "); |
| 4531 | formatTimeMs(sb, uidMobileActiveTime / 1000); |
| 4532 | sb.append("("); |
| 4533 | sb.append(formatRatioLocked(uidMobileActiveTime, mobileActiveTime)); |
| 4534 | sb.append(") "); sb.append(uidMobileActiveCount); sb.append("x"); |
| 4535 | long packets = mobileRxPackets + mobileTxPackets; |
| 4536 | if (packets == 0) { |
| 4537 | packets = 1; |
| 4538 | } |
| 4539 | sb.append(" @ "); |
| 4540 | sb.append(BatteryStatsHelper.makemAh(uidMobileActiveTime / 1000 / (double)packets)); |
| 4541 | sb.append(" mspp"); |
| 4542 | pw.println(sb.toString()); |
| 4543 | } |
| 4544 | |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 4545 | if (mobileWakeup > 0) { |
| 4546 | sb.setLength(0); |
| 4547 | sb.append(prefix); |
| 4548 | sb.append(" Mobile radio AP wakeups: "); |
| 4549 | sb.append(mobileWakeup); |
| 4550 | pw.println(sb.toString()); |
| 4551 | } |
| 4552 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 4553 | printControllerActivityIfInteresting(pw, sb, prefix + " ", "Modem", |
| 4554 | u.getModemControllerActivity(), which); |
| 4555 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4556 | if (wifiRxBytes > 0 || wifiTxBytes > 0 || wifiRxPackets > 0 || wifiTxPackets > 0) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 4557 | pw.print(prefix); pw.print(" Wi-Fi network: "); |
| 4558 | pw.print(formatBytesLocked(wifiRxBytes)); pw.print(" received, "); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4559 | pw.print(formatBytesLocked(wifiTxBytes)); |
| 4560 | pw.print(" sent (packets "); pw.print(wifiRxPackets); |
| 4561 | pw.print(" received, "); pw.print(wifiTxPackets); pw.println(" sent)"); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 4562 | } |
| 4563 | |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 4564 | if (fullWifiLockOnTime != 0 || wifiScanTime != 0 || wifiScanCount != 0 |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 4565 | || wifiScanCountBg != 0 || wifiScanActualTime != 0 || wifiScanActualTimeBg != 0 |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4566 | || uidWifiRunningTime != 0) { |
| 4567 | sb.setLength(0); |
| 4568 | sb.append(prefix); sb.append(" Wifi Running: "); |
| 4569 | formatTimeMs(sb, uidWifiRunningTime / 1000); |
| 4570 | sb.append("("); sb.append(formatRatioLocked(uidWifiRunningTime, |
| 4571 | whichBatteryRealtime)); sb.append(")\n"); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 4572 | sb.append(prefix); sb.append(" Full Wifi Lock: "); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4573 | formatTimeMs(sb, fullWifiLockOnTime / 1000); |
| 4574 | sb.append("("); sb.append(formatRatioLocked(fullWifiLockOnTime, |
| 4575 | whichBatteryRealtime)); sb.append(")\n"); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 4576 | sb.append(prefix); sb.append(" Wifi Scan (blamed): "); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4577 | formatTimeMs(sb, wifiScanTime / 1000); |
| 4578 | sb.append("("); sb.append(formatRatioLocked(wifiScanTime, |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 4579 | whichBatteryRealtime)); sb.append(") "); |
| 4580 | sb.append(wifiScanCount); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 4581 | sb.append("x\n"); |
| 4582 | // actual and background times are unpooled and since reset (regardless of 'which') |
| 4583 | sb.append(prefix); sb.append(" Wifi Scan (actual): "); |
| 4584 | formatTimeMs(sb, wifiScanActualTime / 1000); |
| 4585 | sb.append("("); sb.append(formatRatioLocked(wifiScanActualTime, |
| 4586 | computeBatteryRealtime(rawRealtime, STATS_SINCE_CHARGED))); |
| 4587 | sb.append(") "); |
| 4588 | sb.append(wifiScanCount); |
| 4589 | sb.append("x\n"); |
| 4590 | sb.append(prefix); sb.append(" Background Wifi Scan: "); |
| 4591 | formatTimeMs(sb, wifiScanActualTimeBg / 1000); |
| 4592 | sb.append("("); sb.append(formatRatioLocked(wifiScanActualTimeBg, |
| 4593 | computeBatteryRealtime(rawRealtime, STATS_SINCE_CHARGED))); |
| 4594 | sb.append(") "); |
| 4595 | sb.append(wifiScanCountBg); |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 4596 | sb.append("x"); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4597 | pw.println(sb.toString()); |
| 4598 | } |
| 4599 | |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 4600 | if (wifiWakeup > 0) { |
| 4601 | sb.setLength(0); |
| 4602 | sb.append(prefix); |
| 4603 | sb.append(" WiFi AP wakeups: "); |
| 4604 | sb.append(wifiWakeup); |
| 4605 | pw.println(sb.toString()); |
| 4606 | } |
| 4607 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 4608 | printControllerActivityIfInteresting(pw, sb, prefix + " ", "WiFi", |
| 4609 | u.getWifiControllerActivity(), which); |
Adam Lesinski | 049c88b | 2015-05-28 11:38:12 -0700 | [diff] [blame] | 4610 | |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 4611 | if (btRxBytes > 0 || btTxBytes > 0) { |
| 4612 | pw.print(prefix); pw.print(" Bluetooth network: "); |
| 4613 | pw.print(formatBytesLocked(btRxBytes)); pw.print(" received, "); |
| 4614 | pw.print(formatBytesLocked(btTxBytes)); |
| 4615 | pw.println(" sent"); |
| 4616 | } |
| 4617 | |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 4618 | final Timer bleTimer = u.getBluetoothScanTimer(); |
| 4619 | if (bleTimer != null) { |
| 4620 | // Convert from microseconds to milliseconds with rounding |
| 4621 | final long totalTimeMs = (bleTimer.getTotalTimeLocked(rawRealtime, which) + 500) |
| 4622 | / 1000; |
| 4623 | if (totalTimeMs != 0) { |
| 4624 | final int count = bleTimer.getCountLocked(which); |
| 4625 | final Timer bleTimerBg = u.getBluetoothScanBackgroundTimer(); |
| 4626 | final int countBg = bleTimerBg != null ? bleTimerBg.getCountLocked(which) : 0; |
| 4627 | final long rawRealtimeMs = (rawRealtime + 500) / 1000; |
| 4628 | // 'actualTime' are unpooled and always since reset (regardless of 'which') |
| 4629 | final long actualTimeMs = bleTimer.getTotalDurationMsLocked(rawRealtimeMs); |
| 4630 | final long actualTimeMsBg = bleTimerBg != null ? |
| 4631 | bleTimerBg.getTotalDurationMsLocked(rawRealtimeMs) : 0; |
Bookatz | 956f36bf | 2017-04-28 09:48:17 -0700 | [diff] [blame] | 4632 | final int resultCount = u.getBluetoothScanResultCounter() != null ? |
| 4633 | u.getBluetoothScanResultCounter().getCountLocked(which) : 0; |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 4634 | |
| 4635 | sb.setLength(0); |
| 4636 | sb.append(prefix); |
| 4637 | sb.append(" "); |
| 4638 | sb.append("Bluetooth Scan"); |
| 4639 | sb.append(": "); |
| 4640 | if (actualTimeMs != totalTimeMs) { |
| 4641 | formatTimeMs(sb, totalTimeMs); |
| 4642 | sb.append("blamed realtime, "); |
| 4643 | } |
| 4644 | formatTimeMs(sb, actualTimeMs); // since reset, regardless of 'which' |
| 4645 | sb.append("realtime ("); |
| 4646 | sb.append(count); |
| 4647 | sb.append(" times)"); |
| 4648 | if (bleTimer.isRunningLocked()) { |
| 4649 | sb.append(" (running)"); |
| 4650 | } |
| 4651 | if (actualTimeMsBg != 0 || countBg > 0) { |
| 4652 | sb.append(", "); |
| 4653 | formatTimeMs(sb, actualTimeMsBg); // since reset, regardless of 'which' |
| 4654 | sb.append("background ("); |
| 4655 | sb.append(countBg); |
| 4656 | sb.append(" times)"); |
| 4657 | } |
Bookatz | 956f36bf | 2017-04-28 09:48:17 -0700 | [diff] [blame] | 4658 | sb.append("; Results count "); |
| 4659 | sb.append(resultCount); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 4660 | pw.println(sb.toString()); |
| 4661 | uidActivity = true; |
| 4662 | } |
| 4663 | } |
| 4664 | |
| 4665 | |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 4666 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4667 | if (u.hasUserActivity()) { |
| 4668 | boolean hasData = false; |
Raph Levien | 4c7a4a7 | 2012-08-03 14:32:39 -0700 | [diff] [blame] | 4669 | for (int i=0; i<Uid.NUM_USER_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4670 | final int val = u.getUserActivityCount(i, which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4671 | if (val != 0) { |
| 4672 | if (!hasData) { |
| 4673 | sb.setLength(0); |
| 4674 | sb.append(" User activity: "); |
| 4675 | hasData = true; |
| 4676 | } else { |
| 4677 | sb.append(", "); |
| 4678 | } |
| 4679 | sb.append(val); |
| 4680 | sb.append(" "); |
| 4681 | sb.append(Uid.USER_ACTIVITY_TYPES[i]); |
| 4682 | } |
| 4683 | } |
| 4684 | if (hasData) { |
| 4685 | pw.println(sb.toString()); |
| 4686 | } |
| 4687 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4688 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4689 | final ArrayMap<String, ? extends BatteryStats.Uid.Wakelock> wakelocks |
| 4690 | = u.getWakelockStats(); |
| 4691 | long totalFullWakelock = 0, totalPartialWakelock = 0, totalWindowWakelock = 0; |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 4692 | long totalDrawWakelock = 0; |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4693 | int countWakelock = 0; |
| 4694 | for (int iw=wakelocks.size()-1; iw>=0; iw--) { |
| 4695 | final Uid.Wakelock wl = wakelocks.valueAt(iw); |
| 4696 | String linePrefix = ": "; |
| 4697 | sb.setLength(0); |
| 4698 | sb.append(prefix); |
| 4699 | sb.append(" Wake lock "); |
| 4700 | sb.append(wakelocks.keyAt(iw)); |
| 4701 | linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_FULL), rawRealtime, |
| 4702 | "full", which, linePrefix); |
Bookatz | 5b5ec32 | 2017-05-26 09:40:38 -0700 | [diff] [blame^] | 4703 | final Timer pTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL); |
| 4704 | linePrefix = printWakeLock(sb, pTimer, rawRealtime, |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4705 | "partial", which, linePrefix); |
Bookatz | 5b5ec32 | 2017-05-26 09:40:38 -0700 | [diff] [blame^] | 4706 | linePrefix = printWakeLock(sb, pTimer != null ? pTimer.getSubTimer() : null, |
| 4707 | rawRealtime, "background partial", which, linePrefix); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4708 | linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_WINDOW), rawRealtime, |
| 4709 | "window", which, linePrefix); |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 4710 | linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_DRAW), rawRealtime, |
| 4711 | "draw", which, linePrefix); |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 4712 | sb.append(" realtime"); |
| 4713 | pw.println(sb.toString()); |
| 4714 | uidActivity = true; |
| 4715 | countWakelock++; |
| 4716 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4717 | totalFullWakelock += computeWakeLock(wl.getWakeTime(WAKE_TYPE_FULL), |
| 4718 | rawRealtime, which); |
| 4719 | totalPartialWakelock += computeWakeLock(wl.getWakeTime(WAKE_TYPE_PARTIAL), |
| 4720 | rawRealtime, which); |
| 4721 | totalWindowWakelock += computeWakeLock(wl.getWakeTime(WAKE_TYPE_WINDOW), |
| 4722 | rawRealtime, which); |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 4723 | totalDrawWakelock += computeWakeLock(wl.getWakeTime(WAKE_TYPE_DRAW), |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 4724 | rawRealtime, which); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 4725 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4726 | if (countWakelock > 1) { |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 4727 | // get unpooled partial wakelock quantities (unlike totalPartialWakelock, which is |
| 4728 | // pooled and therefore just a lower bound) |
| 4729 | long actualTotalPartialWakelock = 0; |
| 4730 | long actualBgPartialWakelock = 0; |
| 4731 | if (u.getAggregatedPartialWakelockTimer() != null) { |
| 4732 | final Timer aggTimer = u.getAggregatedPartialWakelockTimer(); |
| 4733 | // Convert from microseconds to milliseconds with rounding |
| 4734 | actualTotalPartialWakelock = |
| 4735 | (aggTimer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000; |
| 4736 | final Timer bgAggTimer = aggTimer.getSubTimer(); |
| 4737 | actualBgPartialWakelock = bgAggTimer != null ? |
| 4738 | (bgAggTimer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000 : 0; |
| 4739 | } |
| 4740 | |
| 4741 | if (actualTotalPartialWakelock != 0 || actualBgPartialWakelock != 0 || |
| 4742 | totalFullWakelock != 0 || totalPartialWakelock != 0 || |
| 4743 | totalWindowWakelock != 0) { |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 4744 | sb.setLength(0); |
| 4745 | sb.append(prefix); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4746 | sb.append(" TOTAL wake: "); |
| 4747 | boolean needComma = false; |
| 4748 | if (totalFullWakelock != 0) { |
| 4749 | needComma = true; |
| 4750 | formatTimeMs(sb, totalFullWakelock); |
| 4751 | sb.append("full"); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 4752 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4753 | if (totalPartialWakelock != 0) { |
| 4754 | if (needComma) { |
| 4755 | sb.append(", "); |
| 4756 | } |
| 4757 | needComma = true; |
| 4758 | formatTimeMs(sb, totalPartialWakelock); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 4759 | sb.append("blamed partial"); |
| 4760 | } |
| 4761 | if (actualTotalPartialWakelock != 0) { |
| 4762 | if (needComma) { |
| 4763 | sb.append(", "); |
| 4764 | } |
| 4765 | needComma = true; |
| 4766 | formatTimeMs(sb, actualTotalPartialWakelock); |
| 4767 | sb.append("actual partial"); |
| 4768 | } |
| 4769 | if (actualBgPartialWakelock != 0) { |
| 4770 | if (needComma) { |
| 4771 | sb.append(", "); |
| 4772 | } |
| 4773 | needComma = true; |
| 4774 | formatTimeMs(sb, actualBgPartialWakelock); |
| 4775 | sb.append("actual background partial"); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4776 | } |
| 4777 | if (totalWindowWakelock != 0) { |
| 4778 | if (needComma) { |
| 4779 | sb.append(", "); |
| 4780 | } |
| 4781 | needComma = true; |
| 4782 | formatTimeMs(sb, totalWindowWakelock); |
| 4783 | sb.append("window"); |
| 4784 | } |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 4785 | if (totalDrawWakelock != 0) { |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 4786 | if (needComma) { |
| 4787 | sb.append(","); |
| 4788 | } |
| 4789 | needComma = true; |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 4790 | formatTimeMs(sb, totalDrawWakelock); |
| 4791 | sb.append("draw"); |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 4792 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4793 | sb.append(" realtime"); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 4794 | pw.println(sb.toString()); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 4795 | } |
| 4796 | } |
| 4797 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4798 | final ArrayMap<String, ? extends Timer> syncs = u.getSyncStats(); |
| 4799 | for (int isy=syncs.size()-1; isy>=0; isy--) { |
| 4800 | final Timer timer = syncs.valueAt(isy); |
| 4801 | // Convert from microseconds to milliseconds with rounding |
| 4802 | final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000; |
| 4803 | final int count = timer.getCountLocked(which); |
Bookatz | 2bffb5b | 2017-04-13 11:59:33 -0700 | [diff] [blame] | 4804 | final Timer bgTimer = timer.getSubTimer(); |
| 4805 | final long bgTime = bgTimer != null ? |
| 4806 | (bgTimer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000 : -1; |
| 4807 | final int bgCount = bgTimer != null ? bgTimer.getCountLocked(which) : -1; |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4808 | sb.setLength(0); |
| 4809 | sb.append(prefix); |
| 4810 | sb.append(" Sync "); |
| 4811 | sb.append(syncs.keyAt(isy)); |
| 4812 | sb.append(": "); |
| 4813 | if (totalTime != 0) { |
| 4814 | formatTimeMs(sb, totalTime); |
| 4815 | sb.append("realtime ("); |
| 4816 | sb.append(count); |
| 4817 | sb.append(" times)"); |
Bookatz | 2bffb5b | 2017-04-13 11:59:33 -0700 | [diff] [blame] | 4818 | if (bgTime > 0) { |
| 4819 | sb.append(", "); |
| 4820 | formatTimeMs(sb, bgTime); |
| 4821 | sb.append("background ("); |
| 4822 | sb.append(bgCount); |
| 4823 | sb.append(" times)"); |
| 4824 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4825 | } else { |
| 4826 | sb.append("(not used)"); |
| 4827 | } |
| 4828 | pw.println(sb.toString()); |
| 4829 | uidActivity = true; |
| 4830 | } |
| 4831 | |
| 4832 | final ArrayMap<String, ? extends Timer> jobs = u.getJobStats(); |
| 4833 | for (int ij=jobs.size()-1; ij>=0; ij--) { |
| 4834 | final Timer timer = jobs.valueAt(ij); |
| 4835 | // Convert from microseconds to milliseconds with rounding |
| 4836 | final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000; |
| 4837 | final int count = timer.getCountLocked(which); |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 4838 | final Timer bgTimer = timer.getSubTimer(); |
| 4839 | final long bgTime = bgTimer != null ? |
| 4840 | (bgTimer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000 : -1; |
| 4841 | final int bgCount = bgTimer != null ? bgTimer.getCountLocked(which) : -1; |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4842 | sb.setLength(0); |
| 4843 | sb.append(prefix); |
| 4844 | sb.append(" Job "); |
| 4845 | sb.append(jobs.keyAt(ij)); |
| 4846 | sb.append(": "); |
| 4847 | if (totalTime != 0) { |
| 4848 | formatTimeMs(sb, totalTime); |
| 4849 | sb.append("realtime ("); |
| 4850 | sb.append(count); |
| 4851 | sb.append(" times)"); |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 4852 | if (bgTime > 0) { |
| 4853 | sb.append(", "); |
| 4854 | formatTimeMs(sb, bgTime); |
| 4855 | sb.append("background ("); |
| 4856 | sb.append(bgCount); |
| 4857 | sb.append(" times)"); |
| 4858 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4859 | } else { |
| 4860 | sb.append("(not used)"); |
| 4861 | } |
| 4862 | pw.println(sb.toString()); |
| 4863 | uidActivity = true; |
| 4864 | } |
| 4865 | |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 4866 | uidActivity |= printTimer(pw, sb, u.getFlashlightTurnedOnTimer(), rawRealtime, which, |
| 4867 | prefix, "Flashlight"); |
| 4868 | uidActivity |= printTimer(pw, sb, u.getCameraTurnedOnTimer(), rawRealtime, which, |
| 4869 | prefix, "Camera"); |
| 4870 | uidActivity |= printTimer(pw, sb, u.getVideoTurnedOnTimer(), rawRealtime, which, |
| 4871 | prefix, "Video"); |
| 4872 | uidActivity |= printTimer(pw, sb, u.getAudioTurnedOnTimer(), rawRealtime, which, |
| 4873 | prefix, "Audio"); |
| 4874 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4875 | final SparseArray<? extends BatteryStats.Uid.Sensor> sensors = u.getSensorStats(); |
| 4876 | final int NSE = sensors.size(); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 4877 | for (int ise=0; ise<NSE; ise++) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4878 | final Uid.Sensor se = sensors.valueAt(ise); |
| 4879 | final int sensorNumber = sensors.keyAt(ise); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 4880 | sb.setLength(0); |
| 4881 | sb.append(prefix); |
| 4882 | sb.append(" Sensor "); |
| 4883 | int handle = se.getHandle(); |
| 4884 | if (handle == Uid.Sensor.GPS) { |
| 4885 | sb.append("GPS"); |
| 4886 | } else { |
| 4887 | sb.append(handle); |
| 4888 | } |
| 4889 | sb.append(": "); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4890 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4891 | final Timer timer = se.getSensorTime(); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 4892 | if (timer != null) { |
| 4893 | // Convert from microseconds to milliseconds with rounding |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 4894 | final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) |
| 4895 | / 1000; |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4896 | final int count = timer.getCountLocked(which); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 4897 | final Timer bgTimer = se.getSensorBackgroundTime(); |
| 4898 | final int bgCount = bgTimer != null ? bgTimer.getCountLocked(which) : 0; |
| 4899 | final long rawRealtimeMs = (rawRealtime + 500) / 1000; |
| 4900 | // 'actualTime' are unpooled and always since reset (regardless of 'which') |
| 4901 | final long actualTime = timer.getTotalDurationMsLocked(rawRealtimeMs); |
| 4902 | final long bgActualTime = bgTimer != null ? |
| 4903 | bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : 0; |
| 4904 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 4905 | //timer.logState(); |
| 4906 | if (totalTime != 0) { |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 4907 | if (actualTime != totalTime) { |
| 4908 | formatTimeMs(sb, totalTime); |
| 4909 | sb.append("blamed realtime, "); |
| 4910 | } |
| 4911 | |
| 4912 | formatTimeMs(sb, actualTime); // since reset, regardless of 'which' |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 4913 | sb.append("realtime ("); |
| 4914 | sb.append(count); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 4915 | sb.append(" times)"); |
| 4916 | |
| 4917 | if (bgActualTime != 0 || bgCount > 0) { |
Amith Yamasani | ab9ad19 | 2016-12-06 12:46:59 -0800 | [diff] [blame] | 4918 | sb.append(", "); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 4919 | formatTimeMs(sb, bgActualTime); // since reset, regardless of 'which' |
| 4920 | sb.append("background ("); |
Amith Yamasani | ab9ad19 | 2016-12-06 12:46:59 -0800 | [diff] [blame] | 4921 | sb.append(bgCount); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 4922 | sb.append(" times)"); |
Amith Yamasani | ab9ad19 | 2016-12-06 12:46:59 -0800 | [diff] [blame] | 4923 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4924 | } else { |
| 4925 | sb.append("(not used)"); |
| 4926 | } |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 4927 | } else { |
| 4928 | sb.append("(not used)"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4929 | } |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 4930 | |
| 4931 | pw.println(sb.toString()); |
| 4932 | uidActivity = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4933 | } |
| 4934 | |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 4935 | uidActivity |= printTimer(pw, sb, u.getVibratorOnTimer(), rawRealtime, which, prefix, |
| 4936 | "Vibrator"); |
| 4937 | uidActivity |= printTimer(pw, sb, u.getForegroundActivityTimer(), rawRealtime, which, |
| 4938 | prefix, "Foreground activities"); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 4939 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 4940 | long totalStateTime = 0; |
| 4941 | for (int ips=0; ips<Uid.NUM_PROCESS_STATE; ips++) { |
| 4942 | long time = u.getProcessStateTime(ips, rawRealtime, which); |
| 4943 | if (time > 0) { |
| 4944 | totalStateTime += time; |
| 4945 | sb.setLength(0); |
| 4946 | sb.append(prefix); |
| 4947 | sb.append(" "); |
| 4948 | sb.append(Uid.PROCESS_STATE_NAMES[ips]); |
| 4949 | sb.append(" for: "); |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 4950 | formatTimeMs(sb, (time + 500) / 1000); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 4951 | pw.println(sb.toString()); |
| 4952 | uidActivity = true; |
| 4953 | } |
| 4954 | } |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 4955 | if (totalStateTime > 0) { |
| 4956 | sb.setLength(0); |
| 4957 | sb.append(prefix); |
| 4958 | sb.append(" Total running: "); |
| 4959 | formatTimeMs(sb, (totalStateTime + 500) / 1000); |
| 4960 | pw.println(sb.toString()); |
| 4961 | } |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 4962 | |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 4963 | final long userCpuTimeUs = u.getUserCpuTimeUs(which); |
| 4964 | final long systemCpuTimeUs = u.getSystemCpuTimeUs(which); |
Adam Lesinski | d4abd1e | 2017-04-12 11:29:13 -0700 | [diff] [blame] | 4965 | if (userCpuTimeUs > 0 || systemCpuTimeUs > 0) { |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 4966 | sb.setLength(0); |
| 4967 | sb.append(prefix); |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 4968 | sb.append(" Total cpu time: u="); |
| 4969 | formatTimeMs(sb, userCpuTimeUs / 1000); |
| 4970 | sb.append("s="); |
| 4971 | formatTimeMs(sb, systemCpuTimeUs / 1000); |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 4972 | pw.println(sb.toString()); |
| 4973 | } |
| 4974 | |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 4975 | final long[] cpuFreqTimes = u.getCpuFreqTimes(which); |
| 4976 | if (cpuFreqTimes != null) { |
| 4977 | sb.setLength(0); |
| 4978 | sb.append(" Total cpu time per freq:"); |
| 4979 | for (int i = 0; i < cpuFreqTimes.length; ++i) { |
| 4980 | sb.append(" " + cpuFreqTimes[i]); |
| 4981 | } |
| 4982 | pw.println(sb.toString()); |
| 4983 | } |
| 4984 | final long[] screenOffCpuFreqTimes = u.getScreenOffCpuFreqTimes(which); |
| 4985 | if (screenOffCpuFreqTimes != null) { |
| 4986 | sb.setLength(0); |
| 4987 | sb.append(" Total screen-off cpu time per freq:"); |
| 4988 | for (int i = 0; i < screenOffCpuFreqTimes.length; ++i) { |
| 4989 | sb.append(" " + screenOffCpuFreqTimes[i]); |
| 4990 | } |
| 4991 | pw.println(sb.toString()); |
| 4992 | } |
| 4993 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4994 | final ArrayMap<String, ? extends BatteryStats.Uid.Proc> processStats |
| 4995 | = u.getProcessStats(); |
| 4996 | for (int ipr=processStats.size()-1; ipr>=0; ipr--) { |
| 4997 | final Uid.Proc ps = processStats.valueAt(ipr); |
| 4998 | long userTime; |
| 4999 | long systemTime; |
| 5000 | long foregroundTime; |
| 5001 | int starts; |
| 5002 | int numExcessive; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5003 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5004 | userTime = ps.getUserTime(which); |
| 5005 | systemTime = ps.getSystemTime(which); |
| 5006 | foregroundTime = ps.getForegroundTime(which); |
| 5007 | starts = ps.getStarts(which); |
| 5008 | final int numCrashes = ps.getNumCrashes(which); |
| 5009 | final int numAnrs = ps.getNumAnrs(which); |
| 5010 | numExcessive = which == STATS_SINCE_CHARGED |
| 5011 | ? ps.countExcessivePowers() : 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5012 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5013 | if (userTime != 0 || systemTime != 0 || foregroundTime != 0 || starts != 0 |
| 5014 | || numExcessive != 0 || numCrashes != 0 || numAnrs != 0) { |
| 5015 | sb.setLength(0); |
| 5016 | sb.append(prefix); sb.append(" Proc "); |
| 5017 | sb.append(processStats.keyAt(ipr)); sb.append(":\n"); |
| 5018 | sb.append(prefix); sb.append(" CPU: "); |
| 5019 | formatTimeMs(sb, userTime); sb.append("usr + "); |
| 5020 | formatTimeMs(sb, systemTime); sb.append("krn ; "); |
| 5021 | formatTimeMs(sb, foregroundTime); sb.append("fg"); |
| 5022 | if (starts != 0 || numCrashes != 0 || numAnrs != 0) { |
| 5023 | sb.append("\n"); sb.append(prefix); sb.append(" "); |
| 5024 | boolean hasOne = false; |
| 5025 | if (starts != 0) { |
| 5026 | hasOne = true; |
| 5027 | sb.append(starts); sb.append(" starts"); |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 5028 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5029 | if (numCrashes != 0) { |
| 5030 | if (hasOne) { |
| 5031 | sb.append(", "); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 5032 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5033 | hasOne = true; |
| 5034 | sb.append(numCrashes); sb.append(" crashes"); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 5035 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5036 | if (numAnrs != 0) { |
| 5037 | if (hasOne) { |
| 5038 | sb.append(", "); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5039 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5040 | sb.append(numAnrs); sb.append(" anrs"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5041 | } |
| 5042 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5043 | pw.println(sb.toString()); |
| 5044 | for (int e=0; e<numExcessive; e++) { |
| 5045 | Uid.Proc.ExcessivePower ew = ps.getExcessivePower(e); |
| 5046 | if (ew != null) { |
| 5047 | pw.print(prefix); pw.print(" * Killed for "); |
| 5048 | if (ew.type == Uid.Proc.ExcessivePower.TYPE_WAKE) { |
| 5049 | pw.print("wake lock"); |
| 5050 | } else if (ew.type == Uid.Proc.ExcessivePower.TYPE_CPU) { |
| 5051 | pw.print("cpu"); |
| 5052 | } else { |
| 5053 | pw.print("unknown"); |
| 5054 | } |
| 5055 | pw.print(" use: "); |
| 5056 | TimeUtils.formatDuration(ew.usedTime, pw); |
| 5057 | pw.print(" over "); |
| 5058 | TimeUtils.formatDuration(ew.overTime, pw); |
| 5059 | if (ew.overTime != 0) { |
| 5060 | pw.print(" ("); |
| 5061 | pw.print((ew.usedTime*100)/ew.overTime); |
| 5062 | pw.println("%)"); |
| 5063 | } |
| 5064 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5065 | } |
| 5066 | uidActivity = true; |
| 5067 | } |
| 5068 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5069 | |
| 5070 | final ArrayMap<String, ? extends BatteryStats.Uid.Pkg> packageStats |
| 5071 | = u.getPackageStats(); |
| 5072 | for (int ipkg=packageStats.size()-1; ipkg>=0; ipkg--) { |
| 5073 | pw.print(prefix); pw.print(" Apk "); pw.print(packageStats.keyAt(ipkg)); |
| 5074 | pw.println(":"); |
| 5075 | boolean apkActivity = false; |
| 5076 | final Uid.Pkg ps = packageStats.valueAt(ipkg); |
| 5077 | final ArrayMap<String, ? extends Counter> alarms = ps.getWakeupAlarmStats(); |
| 5078 | for (int iwa=alarms.size()-1; iwa>=0; iwa--) { |
| 5079 | pw.print(prefix); pw.print(" Wakeup alarm "); |
| 5080 | pw.print(alarms.keyAt(iwa)); pw.print(": "); |
| 5081 | pw.print(alarms.valueAt(iwa).getCountLocked(which)); |
| 5082 | pw.println(" times"); |
| 5083 | apkActivity = true; |
| 5084 | } |
| 5085 | final ArrayMap<String, ? extends Uid.Pkg.Serv> serviceStats = ps.getServiceStats(); |
| 5086 | for (int isvc=serviceStats.size()-1; isvc>=0; isvc--) { |
| 5087 | final BatteryStats.Uid.Pkg.Serv ss = serviceStats.valueAt(isvc); |
| 5088 | final long startTime = ss.getStartTime(batteryUptime, which); |
| 5089 | final int starts = ss.getStarts(which); |
| 5090 | final int launches = ss.getLaunches(which); |
| 5091 | if (startTime != 0 || starts != 0 || launches != 0) { |
| 5092 | sb.setLength(0); |
| 5093 | sb.append(prefix); sb.append(" Service "); |
| 5094 | sb.append(serviceStats.keyAt(isvc)); sb.append(":\n"); |
| 5095 | sb.append(prefix); sb.append(" Created for: "); |
| 5096 | formatTimeMs(sb, startTime / 1000); |
| 5097 | sb.append("uptime\n"); |
| 5098 | sb.append(prefix); sb.append(" Starts: "); |
| 5099 | sb.append(starts); |
| 5100 | sb.append(", launches: "); sb.append(launches); |
| 5101 | pw.println(sb.toString()); |
| 5102 | apkActivity = true; |
| 5103 | } |
| 5104 | } |
| 5105 | if (!apkActivity) { |
| 5106 | pw.print(prefix); pw.println(" (nothing executed)"); |
| 5107 | } |
| 5108 | uidActivity = true; |
| 5109 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5110 | if (!uidActivity) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 5111 | pw.print(prefix); pw.println(" (nothing executed)"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5112 | } |
| 5113 | } |
| 5114 | } |
| 5115 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 5116 | static void printBitDescriptions(PrintWriter pw, int oldval, int newval, HistoryTag wakelockTag, |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5117 | BitDescription[] descriptions, boolean longNames) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5118 | int diff = oldval ^ newval; |
| 5119 | if (diff == 0) return; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 5120 | boolean didWake = false; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5121 | for (int i=0; i<descriptions.length; i++) { |
| 5122 | BitDescription bd = descriptions[i]; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 5123 | if ((diff&bd.mask) != 0) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5124 | pw.print(longNames ? " " : ","); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5125 | if (bd.shift < 0) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 5126 | pw.print((newval&bd.mask) != 0 ? "+" : "-"); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5127 | pw.print(longNames ? bd.name : bd.shortName); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 5128 | if (bd.mask == HistoryItem.STATE_WAKE_LOCK_FLAG && wakelockTag != null) { |
| 5129 | didWake = true; |
| 5130 | pw.print("="); |
| 5131 | if (longNames) { |
| 5132 | UserHandle.formatUid(pw, wakelockTag.uid); |
| 5133 | pw.print(":\""); |
| 5134 | pw.print(wakelockTag.string); |
| 5135 | pw.print("\""); |
| 5136 | } else { |
| 5137 | pw.print(wakelockTag.poolIdx); |
| 5138 | } |
| 5139 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5140 | } else { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5141 | pw.print(longNames ? bd.name : bd.shortName); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5142 | pw.print("="); |
| 5143 | int val = (newval&bd.mask)>>bd.shift; |
| 5144 | if (bd.values != null && val >= 0 && val < bd.values.length) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5145 | pw.print(longNames? bd.values[val] : bd.shortValues[val]); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5146 | } else { |
| 5147 | pw.print(val); |
| 5148 | } |
| 5149 | } |
| 5150 | } |
| 5151 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 5152 | if (!didWake && wakelockTag != null) { |
Ashish Sharma | 81850c4 | 2014-05-05 13:57:07 -0700 | [diff] [blame] | 5153 | pw.print(longNames ? " wake_lock=" : ",w="); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 5154 | if (longNames) { |
| 5155 | UserHandle.formatUid(pw, wakelockTag.uid); |
| 5156 | pw.print(":\""); |
| 5157 | pw.print(wakelockTag.string); |
| 5158 | pw.print("\""); |
| 5159 | } else { |
| 5160 | pw.print(wakelockTag.poolIdx); |
| 5161 | } |
| 5162 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5163 | } |
| 5164 | |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5165 | public void prepareForDumpLocked() { |
| 5166 | } |
| 5167 | |
| 5168 | public static class HistoryPrinter { |
| 5169 | int oldState = 0; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 5170 | int oldState2 = 0; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5171 | int oldLevel = -1; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5172 | int oldStatus = -1; |
| 5173 | int oldHealth = -1; |
| 5174 | int oldPlug = -1; |
| 5175 | int oldTemp = -1; |
| 5176 | int oldVolt = -1; |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 5177 | int oldChargeMAh = -1; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5178 | long lastTime = -1; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5179 | |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 5180 | void reset() { |
| 5181 | oldState = oldState2 = 0; |
| 5182 | oldLevel = -1; |
| 5183 | oldStatus = -1; |
| 5184 | oldHealth = -1; |
| 5185 | oldPlug = -1; |
| 5186 | oldTemp = -1; |
| 5187 | oldVolt = -1; |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 5188 | oldChargeMAh = -1; |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 5189 | } |
| 5190 | |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 5191 | public void printNextItem(PrintWriter pw, HistoryItem rec, long baseTime, boolean checkin, |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 5192 | boolean verbose) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5193 | if (!checkin) { |
| 5194 | pw.print(" "); |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 5195 | TimeUtils.formatDuration(rec.time - baseTime, pw, TimeUtils.HUNDRED_DAY_FIELD_LEN); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 5196 | pw.print(" ("); |
| 5197 | pw.print(rec.numReadInts); |
| 5198 | pw.print(") "); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5199 | } else { |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 5200 | pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(','); |
| 5201 | pw.print(HISTORY_DATA); pw.print(','); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5202 | if (lastTime < 0) { |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 5203 | pw.print(rec.time - baseTime); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5204 | } else { |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 5205 | pw.print(rec.time - lastTime); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5206 | } |
| 5207 | lastTime = rec.time; |
| 5208 | } |
| 5209 | if (rec.cmd == HistoryItem.CMD_START) { |
| 5210 | if (checkin) { |
| 5211 | pw.print(":"); |
| 5212 | } |
| 5213 | pw.println("START"); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 5214 | reset(); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 5215 | } else if (rec.cmd == HistoryItem.CMD_CURRENT_TIME |
| 5216 | || rec.cmd == HistoryItem.CMD_RESET) { |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 5217 | if (checkin) { |
| 5218 | pw.print(":"); |
| 5219 | } |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 5220 | if (rec.cmd == HistoryItem.CMD_RESET) { |
| 5221 | pw.print("RESET:"); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 5222 | reset(); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 5223 | } |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 5224 | pw.print("TIME:"); |
| 5225 | if (checkin) { |
| 5226 | pw.println(rec.currentTime); |
| 5227 | } else { |
| 5228 | pw.print(" "); |
| 5229 | pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss", |
| 5230 | rec.currentTime).toString()); |
| 5231 | } |
Dianne Hackborn | 29cd7f1 | 2015-01-08 10:37:05 -0800 | [diff] [blame] | 5232 | } else if (rec.cmd == HistoryItem.CMD_SHUTDOWN) { |
| 5233 | if (checkin) { |
| 5234 | pw.print(":"); |
| 5235 | } |
| 5236 | pw.println("SHUTDOWN"); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5237 | } else if (rec.cmd == HistoryItem.CMD_OVERFLOW) { |
| 5238 | if (checkin) { |
| 5239 | pw.print(":"); |
| 5240 | } |
| 5241 | pw.println("*OVERFLOW*"); |
| 5242 | } else { |
| 5243 | if (!checkin) { |
| 5244 | if (rec.batteryLevel < 10) pw.print("00"); |
| 5245 | else if (rec.batteryLevel < 100) pw.print("0"); |
| 5246 | pw.print(rec.batteryLevel); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 5247 | if (verbose) { |
| 5248 | pw.print(" "); |
| 5249 | if (rec.states < 0) ; |
| 5250 | else if (rec.states < 0x10) pw.print("0000000"); |
| 5251 | else if (rec.states < 0x100) pw.print("000000"); |
| 5252 | else if (rec.states < 0x1000) pw.print("00000"); |
| 5253 | else if (rec.states < 0x10000) pw.print("0000"); |
| 5254 | else if (rec.states < 0x100000) pw.print("000"); |
| 5255 | else if (rec.states < 0x1000000) pw.print("00"); |
| 5256 | else if (rec.states < 0x10000000) pw.print("0"); |
| 5257 | pw.print(Integer.toHexString(rec.states)); |
| 5258 | } |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5259 | } else { |
| 5260 | if (oldLevel != rec.batteryLevel) { |
| 5261 | oldLevel = rec.batteryLevel; |
| 5262 | pw.print(",Bl="); pw.print(rec.batteryLevel); |
| 5263 | } |
| 5264 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5265 | if (oldStatus != rec.batteryStatus) { |
| 5266 | oldStatus = rec.batteryStatus; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5267 | pw.print(checkin ? ",Bs=" : " status="); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5268 | switch (oldStatus) { |
| 5269 | case BatteryManager.BATTERY_STATUS_UNKNOWN: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5270 | pw.print(checkin ? "?" : "unknown"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5271 | break; |
| 5272 | case BatteryManager.BATTERY_STATUS_CHARGING: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5273 | pw.print(checkin ? "c" : "charging"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5274 | break; |
| 5275 | case BatteryManager.BATTERY_STATUS_DISCHARGING: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5276 | pw.print(checkin ? "d" : "discharging"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5277 | break; |
| 5278 | case BatteryManager.BATTERY_STATUS_NOT_CHARGING: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5279 | pw.print(checkin ? "n" : "not-charging"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5280 | break; |
| 5281 | case BatteryManager.BATTERY_STATUS_FULL: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5282 | pw.print(checkin ? "f" : "full"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5283 | break; |
| 5284 | default: |
| 5285 | pw.print(oldStatus); |
| 5286 | break; |
| 5287 | } |
| 5288 | } |
| 5289 | if (oldHealth != rec.batteryHealth) { |
| 5290 | oldHealth = rec.batteryHealth; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5291 | pw.print(checkin ? ",Bh=" : " health="); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5292 | switch (oldHealth) { |
| 5293 | case BatteryManager.BATTERY_HEALTH_UNKNOWN: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5294 | pw.print(checkin ? "?" : "unknown"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5295 | break; |
| 5296 | case BatteryManager.BATTERY_HEALTH_GOOD: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5297 | pw.print(checkin ? "g" : "good"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5298 | break; |
| 5299 | case BatteryManager.BATTERY_HEALTH_OVERHEAT: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5300 | pw.print(checkin ? "h" : "overheat"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5301 | break; |
| 5302 | case BatteryManager.BATTERY_HEALTH_DEAD: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5303 | pw.print(checkin ? "d" : "dead"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5304 | break; |
| 5305 | case BatteryManager.BATTERY_HEALTH_OVER_VOLTAGE: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5306 | pw.print(checkin ? "v" : "over-voltage"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5307 | break; |
| 5308 | case BatteryManager.BATTERY_HEALTH_UNSPECIFIED_FAILURE: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5309 | pw.print(checkin ? "f" : "failure"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5310 | break; |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 5311 | case BatteryManager.BATTERY_HEALTH_COLD: |
| 5312 | pw.print(checkin ? "c" : "cold"); |
| 5313 | break; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5314 | default: |
| 5315 | pw.print(oldHealth); |
| 5316 | break; |
| 5317 | } |
| 5318 | } |
| 5319 | if (oldPlug != rec.batteryPlugType) { |
| 5320 | oldPlug = rec.batteryPlugType; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5321 | pw.print(checkin ? ",Bp=" : " plug="); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5322 | switch (oldPlug) { |
| 5323 | case 0: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5324 | pw.print(checkin ? "n" : "none"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5325 | break; |
| 5326 | case BatteryManager.BATTERY_PLUGGED_AC: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5327 | pw.print(checkin ? "a" : "ac"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5328 | break; |
| 5329 | case BatteryManager.BATTERY_PLUGGED_USB: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5330 | pw.print(checkin ? "u" : "usb"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5331 | break; |
Brian Muramatsu | 37a37f4 | 2012-08-14 15:21:02 -0700 | [diff] [blame] | 5332 | case BatteryManager.BATTERY_PLUGGED_WIRELESS: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5333 | pw.print(checkin ? "w" : "wireless"); |
Brian Muramatsu | 37a37f4 | 2012-08-14 15:21:02 -0700 | [diff] [blame] | 5334 | break; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5335 | default: |
| 5336 | pw.print(oldPlug); |
| 5337 | break; |
| 5338 | } |
| 5339 | } |
| 5340 | if (oldTemp != rec.batteryTemperature) { |
| 5341 | oldTemp = rec.batteryTemperature; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5342 | pw.print(checkin ? ",Bt=" : " temp="); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5343 | pw.print(oldTemp); |
| 5344 | } |
| 5345 | if (oldVolt != rec.batteryVoltage) { |
| 5346 | oldVolt = rec.batteryVoltage; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5347 | pw.print(checkin ? ",Bv=" : " volt="); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5348 | pw.print(oldVolt); |
| 5349 | } |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 5350 | final int chargeMAh = rec.batteryChargeUAh / 1000; |
| 5351 | if (oldChargeMAh != chargeMAh) { |
| 5352 | oldChargeMAh = chargeMAh; |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 5353 | pw.print(checkin ? ",Bcc=" : " charge="); |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 5354 | pw.print(oldChargeMAh); |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 5355 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 5356 | printBitDescriptions(pw, oldState, rec.states, rec.wakelockTag, |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5357 | HISTORY_STATE_DESCRIPTIONS, !checkin); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 5358 | printBitDescriptions(pw, oldState2, rec.states2, null, |
| 5359 | HISTORY_STATE2_DESCRIPTIONS, !checkin); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 5360 | if (rec.wakeReasonTag != null) { |
| 5361 | if (checkin) { |
Dianne Hackborn | d06dcfd | 2014-05-02 13:49:30 -0700 | [diff] [blame] | 5362 | pw.print(",wr="); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 5363 | pw.print(rec.wakeReasonTag.poolIdx); |
| 5364 | } else { |
| 5365 | pw.print(" wake_reason="); |
| 5366 | pw.print(rec.wakeReasonTag.uid); |
| 5367 | pw.print(":\""); |
| 5368 | pw.print(rec.wakeReasonTag.string); |
| 5369 | pw.print("\""); |
| 5370 | } |
| 5371 | } |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 5372 | if (rec.eventCode != HistoryItem.EVENT_NONE) { |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 5373 | pw.print(checkin ? "," : " "); |
| 5374 | if ((rec.eventCode&HistoryItem.EVENT_FLAG_START) != 0) { |
| 5375 | pw.print("+"); |
| 5376 | } else if ((rec.eventCode&HistoryItem.EVENT_FLAG_FINISH) != 0) { |
| 5377 | pw.print("-"); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 5378 | } |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 5379 | String[] eventNames = checkin ? HISTORY_EVENT_CHECKIN_NAMES |
| 5380 | : HISTORY_EVENT_NAMES; |
| 5381 | int idx = rec.eventCode & ~(HistoryItem.EVENT_FLAG_START |
| 5382 | | HistoryItem.EVENT_FLAG_FINISH); |
| 5383 | if (idx >= 0 && idx < eventNames.length) { |
| 5384 | pw.print(eventNames[idx]); |
| 5385 | } else { |
| 5386 | pw.print(checkin ? "Ev" : "event"); |
| 5387 | pw.print(idx); |
| 5388 | } |
| 5389 | pw.print("="); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 5390 | if (checkin) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 5391 | pw.print(rec.eventTag.poolIdx); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 5392 | } else { |
Adam Lesinski | 041d917 | 2016-12-12 12:03:56 -0800 | [diff] [blame] | 5393 | pw.append(HISTORY_EVENT_INT_FORMATTERS[idx] |
| 5394 | .applyAsString(rec.eventTag.uid)); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 5395 | pw.print(":\""); |
| 5396 | pw.print(rec.eventTag.string); |
| 5397 | pw.print("\""); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 5398 | } |
| 5399 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5400 | pw.println(); |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 5401 | if (rec.stepDetails != null) { |
| 5402 | if (!checkin) { |
| 5403 | pw.print(" Details: cpu="); |
| 5404 | pw.print(rec.stepDetails.userTime); |
| 5405 | pw.print("u+"); |
| 5406 | pw.print(rec.stepDetails.systemTime); |
| 5407 | pw.print("s"); |
| 5408 | if (rec.stepDetails.appCpuUid1 >= 0) { |
| 5409 | pw.print(" ("); |
| 5410 | printStepCpuUidDetails(pw, rec.stepDetails.appCpuUid1, |
| 5411 | rec.stepDetails.appCpuUTime1, rec.stepDetails.appCpuSTime1); |
| 5412 | if (rec.stepDetails.appCpuUid2 >= 0) { |
| 5413 | pw.print(", "); |
| 5414 | printStepCpuUidDetails(pw, rec.stepDetails.appCpuUid2, |
| 5415 | rec.stepDetails.appCpuUTime2, rec.stepDetails.appCpuSTime2); |
| 5416 | } |
| 5417 | if (rec.stepDetails.appCpuUid3 >= 0) { |
| 5418 | pw.print(", "); |
| 5419 | printStepCpuUidDetails(pw, rec.stepDetails.appCpuUid3, |
| 5420 | rec.stepDetails.appCpuUTime3, rec.stepDetails.appCpuSTime3); |
| 5421 | } |
| 5422 | pw.print(')'); |
| 5423 | } |
| 5424 | pw.println(); |
| 5425 | pw.print(" /proc/stat="); |
| 5426 | pw.print(rec.stepDetails.statUserTime); |
| 5427 | pw.print(" usr, "); |
| 5428 | pw.print(rec.stepDetails.statSystemTime); |
| 5429 | pw.print(" sys, "); |
| 5430 | pw.print(rec.stepDetails.statIOWaitTime); |
| 5431 | pw.print(" io, "); |
| 5432 | pw.print(rec.stepDetails.statIrqTime); |
| 5433 | pw.print(" irq, "); |
| 5434 | pw.print(rec.stepDetails.statSoftIrqTime); |
| 5435 | pw.print(" sirq, "); |
| 5436 | pw.print(rec.stepDetails.statIdlTime); |
| 5437 | pw.print(" idle"); |
| 5438 | int totalRun = rec.stepDetails.statUserTime + rec.stepDetails.statSystemTime |
| 5439 | + rec.stepDetails.statIOWaitTime + rec.stepDetails.statIrqTime |
| 5440 | + rec.stepDetails.statSoftIrqTime; |
| 5441 | int total = totalRun + rec.stepDetails.statIdlTime; |
| 5442 | if (total > 0) { |
| 5443 | pw.print(" ("); |
| 5444 | float perc = ((float)totalRun) / ((float)total) * 100; |
| 5445 | pw.print(String.format("%.1f%%", perc)); |
| 5446 | pw.print(" of "); |
| 5447 | StringBuilder sb = new StringBuilder(64); |
| 5448 | formatTimeMsNoSpace(sb, total*10); |
| 5449 | pw.print(sb); |
| 5450 | pw.print(")"); |
| 5451 | } |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 5452 | pw.print(", PlatformIdleStat "); |
| 5453 | pw.print(rec.stepDetails.statPlatformIdleState); |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 5454 | pw.println(); |
| 5455 | } else { |
| 5456 | pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(','); |
| 5457 | pw.print(HISTORY_DATA); pw.print(",0,Dcpu="); |
| 5458 | pw.print(rec.stepDetails.userTime); |
| 5459 | pw.print(":"); |
| 5460 | pw.print(rec.stepDetails.systemTime); |
| 5461 | if (rec.stepDetails.appCpuUid1 >= 0) { |
| 5462 | printStepCpuUidCheckinDetails(pw, rec.stepDetails.appCpuUid1, |
| 5463 | rec.stepDetails.appCpuUTime1, rec.stepDetails.appCpuSTime1); |
| 5464 | if (rec.stepDetails.appCpuUid2 >= 0) { |
| 5465 | printStepCpuUidCheckinDetails(pw, rec.stepDetails.appCpuUid2, |
| 5466 | rec.stepDetails.appCpuUTime2, rec.stepDetails.appCpuSTime2); |
| 5467 | } |
| 5468 | if (rec.stepDetails.appCpuUid3 >= 0) { |
| 5469 | printStepCpuUidCheckinDetails(pw, rec.stepDetails.appCpuUid3, |
| 5470 | rec.stepDetails.appCpuUTime3, rec.stepDetails.appCpuSTime3); |
| 5471 | } |
| 5472 | } |
| 5473 | pw.println(); |
| 5474 | pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(','); |
| 5475 | pw.print(HISTORY_DATA); pw.print(",0,Dpst="); |
| 5476 | pw.print(rec.stepDetails.statUserTime); |
| 5477 | pw.print(','); |
| 5478 | pw.print(rec.stepDetails.statSystemTime); |
| 5479 | pw.print(','); |
| 5480 | pw.print(rec.stepDetails.statIOWaitTime); |
| 5481 | pw.print(','); |
| 5482 | pw.print(rec.stepDetails.statIrqTime); |
| 5483 | pw.print(','); |
| 5484 | pw.print(rec.stepDetails.statSoftIrqTime); |
| 5485 | pw.print(','); |
| 5486 | pw.print(rec.stepDetails.statIdlTime); |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 5487 | pw.print(','); |
Adam Lesinski | 8568d8f | 2016-07-15 18:13:23 -0700 | [diff] [blame] | 5488 | if (rec.stepDetails.statPlatformIdleState != null) { |
| 5489 | pw.print(rec.stepDetails.statPlatformIdleState); |
| 5490 | } |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 5491 | pw.println(); |
| 5492 | } |
| 5493 | } |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 5494 | oldState = rec.states; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 5495 | oldState2 = rec.states2; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5496 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5497 | } |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 5498 | |
| 5499 | private void printStepCpuUidDetails(PrintWriter pw, int uid, int utime, int stime) { |
| 5500 | UserHandle.formatUid(pw, uid); |
| 5501 | pw.print("="); |
| 5502 | pw.print(utime); |
| 5503 | pw.print("u+"); |
| 5504 | pw.print(stime); |
| 5505 | pw.print("s"); |
| 5506 | } |
| 5507 | |
| 5508 | private void printStepCpuUidCheckinDetails(PrintWriter pw, int uid, int utime, int stime) { |
| 5509 | pw.print('/'); |
| 5510 | pw.print(uid); |
| 5511 | pw.print(":"); |
| 5512 | pw.print(utime); |
| 5513 | pw.print(":"); |
| 5514 | pw.print(stime); |
| 5515 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5516 | } |
| 5517 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 5518 | private void printSizeValue(PrintWriter pw, long size) { |
| 5519 | float result = size; |
| 5520 | String suffix = ""; |
| 5521 | if (result >= 10*1024) { |
| 5522 | suffix = "KB"; |
| 5523 | result = result / 1024; |
| 5524 | } |
| 5525 | if (result >= 10*1024) { |
| 5526 | suffix = "MB"; |
| 5527 | result = result / 1024; |
| 5528 | } |
| 5529 | if (result >= 10*1024) { |
| 5530 | suffix = "GB"; |
| 5531 | result = result / 1024; |
| 5532 | } |
| 5533 | if (result >= 10*1024) { |
| 5534 | suffix = "TB"; |
| 5535 | result = result / 1024; |
| 5536 | } |
| 5537 | if (result >= 10*1024) { |
| 5538 | suffix = "PB"; |
| 5539 | result = result / 1024; |
| 5540 | } |
| 5541 | pw.print((int)result); |
| 5542 | pw.print(suffix); |
| 5543 | } |
| 5544 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 5545 | private static boolean dumpTimeEstimate(PrintWriter pw, String label1, String label2, |
| 5546 | String label3, long estimatedTime) { |
| 5547 | if (estimatedTime < 0) { |
Dianne Hackborn | ad6a99b | 2014-11-18 10:11:10 -0800 | [diff] [blame] | 5548 | return false; |
| 5549 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 5550 | pw.print(label1); |
| 5551 | pw.print(label2); |
| 5552 | pw.print(label3); |
Dianne Hackborn | ad6a99b | 2014-11-18 10:11:10 -0800 | [diff] [blame] | 5553 | StringBuilder sb = new StringBuilder(64); |
| 5554 | formatTimeMs(sb, estimatedTime); |
| 5555 | pw.print(sb); |
| 5556 | pw.println(); |
Dianne Hackborn | ad6a99b | 2014-11-18 10:11:10 -0800 | [diff] [blame] | 5557 | return true; |
| 5558 | } |
| 5559 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 5560 | private static boolean dumpDurationSteps(PrintWriter pw, String prefix, String header, |
| 5561 | LevelStepTracker steps, boolean checkin) { |
| 5562 | if (steps == null) { |
| 5563 | return false; |
| 5564 | } |
| 5565 | int count = steps.mNumStepDurations; |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 5566 | if (count <= 0) { |
| 5567 | return false; |
| 5568 | } |
| 5569 | if (!checkin) { |
| 5570 | pw.println(header); |
| 5571 | } |
Kweku Adams | 030980a | 2015-04-01 16:07:48 -0700 | [diff] [blame] | 5572 | String[] lineArgs = new String[5]; |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 5573 | for (int i=0; i<count; i++) { |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 5574 | long duration = steps.getDurationAt(i); |
| 5575 | int level = steps.getLevelAt(i); |
| 5576 | long initMode = steps.getInitModeAt(i); |
| 5577 | long modMode = steps.getModModeAt(i); |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 5578 | if (checkin) { |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 5579 | lineArgs[0] = Long.toString(duration); |
| 5580 | lineArgs[1] = Integer.toString(level); |
| 5581 | if ((modMode&STEP_LEVEL_MODE_SCREEN_STATE) == 0) { |
| 5582 | switch ((int)(initMode&STEP_LEVEL_MODE_SCREEN_STATE) + 1) { |
| 5583 | case Display.STATE_OFF: lineArgs[2] = "s-"; break; |
| 5584 | case Display.STATE_ON: lineArgs[2] = "s+"; break; |
| 5585 | case Display.STATE_DOZE: lineArgs[2] = "sd"; break; |
| 5586 | case Display.STATE_DOZE_SUSPEND: lineArgs[2] = "sds"; break; |
Kweku Adams | 030980a | 2015-04-01 16:07:48 -0700 | [diff] [blame] | 5587 | default: lineArgs[2] = "?"; break; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 5588 | } |
| 5589 | } else { |
| 5590 | lineArgs[2] = ""; |
| 5591 | } |
| 5592 | if ((modMode&STEP_LEVEL_MODE_POWER_SAVE) == 0) { |
| 5593 | lineArgs[3] = (initMode&STEP_LEVEL_MODE_POWER_SAVE) != 0 ? "p+" : "p-"; |
| 5594 | } else { |
| 5595 | lineArgs[3] = ""; |
| 5596 | } |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 5597 | if ((modMode&STEP_LEVEL_MODE_DEVICE_IDLE) == 0) { |
Kweku Adams | 030980a | 2015-04-01 16:07:48 -0700 | [diff] [blame] | 5598 | lineArgs[4] = (initMode&STEP_LEVEL_MODE_DEVICE_IDLE) != 0 ? "i+" : "i-"; |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 5599 | } else { |
Kweku Adams | 030980a | 2015-04-01 16:07:48 -0700 | [diff] [blame] | 5600 | lineArgs[4] = ""; |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 5601 | } |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 5602 | dumpLine(pw, 0 /* uid */, "i" /* category */, header, (Object[])lineArgs); |
| 5603 | } else { |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 5604 | pw.print(prefix); |
| 5605 | pw.print("#"); pw.print(i); pw.print(": "); |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 5606 | TimeUtils.formatDuration(duration, pw); |
| 5607 | pw.print(" to "); pw.print(level); |
| 5608 | boolean haveModes = false; |
| 5609 | if ((modMode&STEP_LEVEL_MODE_SCREEN_STATE) == 0) { |
| 5610 | pw.print(" ("); |
| 5611 | switch ((int)(initMode&STEP_LEVEL_MODE_SCREEN_STATE) + 1) { |
| 5612 | case Display.STATE_OFF: pw.print("screen-off"); break; |
| 5613 | case Display.STATE_ON: pw.print("screen-on"); break; |
| 5614 | case Display.STATE_DOZE: pw.print("screen-doze"); break; |
| 5615 | case Display.STATE_DOZE_SUSPEND: pw.print("screen-doze-suspend"); break; |
Kweku Adams | 030980a | 2015-04-01 16:07:48 -0700 | [diff] [blame] | 5616 | default: pw.print("screen-?"); break; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 5617 | } |
| 5618 | haveModes = true; |
| 5619 | } |
| 5620 | if ((modMode&STEP_LEVEL_MODE_POWER_SAVE) == 0) { |
| 5621 | pw.print(haveModes ? ", " : " ("); |
| 5622 | pw.print((initMode&STEP_LEVEL_MODE_POWER_SAVE) != 0 |
| 5623 | ? "power-save-on" : "power-save-off"); |
| 5624 | haveModes = true; |
| 5625 | } |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 5626 | if ((modMode&STEP_LEVEL_MODE_DEVICE_IDLE) == 0) { |
| 5627 | pw.print(haveModes ? ", " : " ("); |
| 5628 | pw.print((initMode&STEP_LEVEL_MODE_DEVICE_IDLE) != 0 |
| 5629 | ? "device-idle-on" : "device-idle-off"); |
| 5630 | haveModes = true; |
| 5631 | } |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 5632 | if (haveModes) { |
| 5633 | pw.print(")"); |
| 5634 | } |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 5635 | pw.println(); |
| 5636 | } |
| 5637 | } |
| 5638 | return true; |
| 5639 | } |
| 5640 | |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 5641 | public static final int DUMP_CHARGED_ONLY = 1<<1; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 5642 | public static final int DUMP_DAILY_ONLY = 1<<2; |
| 5643 | public static final int DUMP_HISTORY_ONLY = 1<<3; |
| 5644 | public static final int DUMP_INCLUDE_HISTORY = 1<<4; |
| 5645 | public static final int DUMP_VERBOSE = 1<<5; |
| 5646 | public static final int DUMP_DEVICE_WIFI_ONLY = 1<<6; |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 5647 | |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 5648 | private void dumpHistoryLocked(PrintWriter pw, int flags, long histStart, boolean checkin) { |
| 5649 | final HistoryPrinter hprinter = new HistoryPrinter(); |
| 5650 | final HistoryItem rec = new HistoryItem(); |
| 5651 | long lastTime = -1; |
| 5652 | long baseTime = -1; |
| 5653 | boolean printed = false; |
| 5654 | HistoryEventTracker tracker = null; |
| 5655 | while (getNextHistoryLocked(rec)) { |
| 5656 | lastTime = rec.time; |
| 5657 | if (baseTime < 0) { |
| 5658 | baseTime = lastTime; |
| 5659 | } |
| 5660 | if (rec.time >= histStart) { |
| 5661 | if (histStart >= 0 && !printed) { |
| 5662 | if (rec.cmd == HistoryItem.CMD_CURRENT_TIME |
Ashish Sharma | 6020071 | 2014-05-23 18:22:20 -0700 | [diff] [blame] | 5663 | || rec.cmd == HistoryItem.CMD_RESET |
Dianne Hackborn | 29cd7f1 | 2015-01-08 10:37:05 -0800 | [diff] [blame] | 5664 | || rec.cmd == HistoryItem.CMD_START |
| 5665 | || rec.cmd == HistoryItem.CMD_SHUTDOWN) { |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 5666 | printed = true; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 5667 | hprinter.printNextItem(pw, rec, baseTime, checkin, |
| 5668 | (flags&DUMP_VERBOSE) != 0); |
| 5669 | rec.cmd = HistoryItem.CMD_UPDATE; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 5670 | } else if (rec.currentTime != 0) { |
| 5671 | printed = true; |
| 5672 | byte cmd = rec.cmd; |
| 5673 | rec.cmd = HistoryItem.CMD_CURRENT_TIME; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 5674 | hprinter.printNextItem(pw, rec, baseTime, checkin, |
| 5675 | (flags&DUMP_VERBOSE) != 0); |
| 5676 | rec.cmd = cmd; |
| 5677 | } |
| 5678 | if (tracker != null) { |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 5679 | if (rec.cmd != HistoryItem.CMD_UPDATE) { |
| 5680 | hprinter.printNextItem(pw, rec, baseTime, checkin, |
| 5681 | (flags&DUMP_VERBOSE) != 0); |
| 5682 | rec.cmd = HistoryItem.CMD_UPDATE; |
| 5683 | } |
| 5684 | int oldEventCode = rec.eventCode; |
| 5685 | HistoryTag oldEventTag = rec.eventTag; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 5686 | rec.eventTag = new HistoryTag(); |
| 5687 | for (int i=0; i<HistoryItem.EVENT_COUNT; i++) { |
| 5688 | HashMap<String, SparseIntArray> active |
| 5689 | = tracker.getStateForEvent(i); |
| 5690 | if (active == null) { |
| 5691 | continue; |
| 5692 | } |
| 5693 | for (HashMap.Entry<String, SparseIntArray> ent |
| 5694 | : active.entrySet()) { |
| 5695 | SparseIntArray uids = ent.getValue(); |
| 5696 | for (int j=0; j<uids.size(); j++) { |
| 5697 | rec.eventCode = i; |
| 5698 | rec.eventTag.string = ent.getKey(); |
| 5699 | rec.eventTag.uid = uids.keyAt(j); |
| 5700 | rec.eventTag.poolIdx = uids.valueAt(j); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 5701 | hprinter.printNextItem(pw, rec, baseTime, checkin, |
| 5702 | (flags&DUMP_VERBOSE) != 0); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 5703 | rec.wakeReasonTag = null; |
| 5704 | rec.wakelockTag = null; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 5705 | } |
| 5706 | } |
| 5707 | } |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 5708 | rec.eventCode = oldEventCode; |
| 5709 | rec.eventTag = oldEventTag; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 5710 | tracker = null; |
| 5711 | } |
| 5712 | } |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 5713 | hprinter.printNextItem(pw, rec, baseTime, checkin, |
| 5714 | (flags&DUMP_VERBOSE) != 0); |
Dianne Hackborn | 536456f | 2014-05-23 16:51:05 -0700 | [diff] [blame] | 5715 | } else if (false && rec.eventCode != HistoryItem.EVENT_NONE) { |
| 5716 | // This is an attempt to aggregate the previous state and generate |
| 5717 | //Â fake events to reflect that state at the point where we start |
| 5718 | // 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] | 5719 | if (tracker == null) { |
| 5720 | tracker = new HistoryEventTracker(); |
| 5721 | } |
| 5722 | tracker.updateState(rec.eventCode, rec.eventTag.string, |
| 5723 | rec.eventTag.uid, rec.eventTag.poolIdx); |
| 5724 | } |
| 5725 | } |
| 5726 | if (histStart >= 0) { |
Dianne Hackborn | fc06413 | 2014-06-02 12:42:12 -0700 | [diff] [blame] | 5727 | commitCurrentHistoryBatchLocked(); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 5728 | pw.print(checkin ? "NEXT: " : " NEXT: "); pw.println(lastTime+1); |
| 5729 | } |
| 5730 | } |
| 5731 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 5732 | private void dumpDailyLevelStepSummary(PrintWriter pw, String prefix, String label, |
| 5733 | LevelStepTracker steps, StringBuilder tmpSb, int[] tmpOutInt) { |
| 5734 | if (steps == null) { |
| 5735 | return; |
| 5736 | } |
| 5737 | long timeRemaining = steps.computeTimeEstimate(0, 0, tmpOutInt); |
| 5738 | if (timeRemaining >= 0) { |
| 5739 | pw.print(prefix); pw.print(label); pw.print(" total time: "); |
| 5740 | tmpSb.setLength(0); |
| 5741 | formatTimeMs(tmpSb, timeRemaining); |
| 5742 | pw.print(tmpSb); |
| 5743 | pw.print(" (from "); pw.print(tmpOutInt[0]); |
| 5744 | pw.println(" steps)"); |
| 5745 | } |
| 5746 | for (int i=0; i< STEP_LEVEL_MODES_OF_INTEREST.length; i++) { |
| 5747 | long estimatedTime = steps.computeTimeEstimate(STEP_LEVEL_MODES_OF_INTEREST[i], |
| 5748 | STEP_LEVEL_MODE_VALUES[i], tmpOutInt); |
| 5749 | if (estimatedTime > 0) { |
| 5750 | pw.print(prefix); pw.print(label); pw.print(" "); |
| 5751 | pw.print(STEP_LEVEL_MODE_LABELS[i]); |
| 5752 | pw.print(" time: "); |
| 5753 | tmpSb.setLength(0); |
| 5754 | formatTimeMs(tmpSb, estimatedTime); |
| 5755 | pw.print(tmpSb); |
| 5756 | pw.print(" (from "); pw.print(tmpOutInt[0]); |
| 5757 | pw.println(" steps)"); |
| 5758 | } |
| 5759 | } |
| 5760 | } |
| 5761 | |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 5762 | private void dumpDailyPackageChanges(PrintWriter pw, String prefix, |
| 5763 | ArrayList<PackageChange> changes) { |
| 5764 | if (changes == null) { |
| 5765 | return; |
| 5766 | } |
| 5767 | pw.print(prefix); pw.println("Package changes:"); |
| 5768 | for (int i=0; i<changes.size(); i++) { |
| 5769 | PackageChange pc = changes.get(i); |
| 5770 | if (pc.mUpdate) { |
| 5771 | pw.print(prefix); pw.print(" Update "); pw.print(pc.mPackageName); |
| 5772 | pw.print(" vers="); pw.println(pc.mVersionCode); |
| 5773 | } else { |
| 5774 | pw.print(prefix); pw.print(" Uninstall "); pw.println(pc.mPackageName); |
| 5775 | } |
| 5776 | } |
| 5777 | } |
| 5778 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5779 | /** |
| 5780 | * Dumps a human-readable summary of the battery statistics to the given PrintWriter. |
| 5781 | * |
| 5782 | * @param pw a Printer to receive the dump output. |
| 5783 | */ |
| 5784 | @SuppressWarnings("unused") |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 5785 | 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] | 5786 | prepareForDumpLocked(); |
| 5787 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 5788 | final boolean filtering = (flags |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5789 | & (DUMP_HISTORY_ONLY|DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) != 0; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5790 | |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 5791 | if ((flags&DUMP_HISTORY_ONLY) != 0 || !filtering) { |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 5792 | final long historyTotalSize = getHistoryTotalSize(); |
| 5793 | final long historyUsedSize = getHistoryUsedSize(); |
| 5794 | if (startIteratingHistoryLocked()) { |
| 5795 | try { |
| 5796 | pw.print("Battery History ("); |
| 5797 | pw.print((100*historyUsedSize)/historyTotalSize); |
| 5798 | pw.print("% used, "); |
| 5799 | printSizeValue(pw, historyUsedSize); |
| 5800 | pw.print(" used of "); |
| 5801 | printSizeValue(pw, historyTotalSize); |
| 5802 | pw.print(", "); |
| 5803 | pw.print(getHistoryStringPoolSize()); |
| 5804 | pw.print(" strings using "); |
| 5805 | printSizeValue(pw, getHistoryStringPoolBytes()); |
| 5806 | pw.println("):"); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 5807 | dumpHistoryLocked(pw, flags, histStart, false); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 5808 | pw.println(); |
| 5809 | } finally { |
| 5810 | finishIteratingHistoryLocked(); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 5811 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 5812 | } |
| 5813 | |
| 5814 | if (startIteratingOldHistoryLocked()) { |
| 5815 | try { |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 5816 | final HistoryItem rec = new HistoryItem(); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 5817 | pw.println("Old battery History:"); |
| 5818 | HistoryPrinter hprinter = new HistoryPrinter(); |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 5819 | long baseTime = -1; |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 5820 | while (getNextOldHistoryLocked(rec)) { |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 5821 | if (baseTime < 0) { |
| 5822 | baseTime = rec.time; |
| 5823 | } |
| 5824 | hprinter.printNextItem(pw, rec, baseTime, false, (flags&DUMP_VERBOSE) != 0); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 5825 | } |
| 5826 | pw.println(); |
| 5827 | } finally { |
| 5828 | finishIteratingOldHistoryLocked(); |
| 5829 | } |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 5830 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5831 | } |
| 5832 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5833 | if (filtering && (flags&(DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) == 0) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 5834 | return; |
| 5835 | } |
| 5836 | |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 5837 | if (!filtering) { |
| 5838 | SparseArray<? extends Uid> uidStats = getUidStats(); |
| 5839 | final int NU = uidStats.size(); |
| 5840 | boolean didPid = false; |
| 5841 | long nowRealtime = SystemClock.elapsedRealtime(); |
| 5842 | for (int i=0; i<NU; i++) { |
| 5843 | Uid uid = uidStats.valueAt(i); |
| 5844 | SparseArray<? extends Uid.Pid> pids = uid.getPidStats(); |
| 5845 | if (pids != null) { |
| 5846 | for (int j=0; j<pids.size(); j++) { |
| 5847 | Uid.Pid pid = pids.valueAt(j); |
| 5848 | if (!didPid) { |
| 5849 | pw.println("Per-PID Stats:"); |
| 5850 | didPid = true; |
| 5851 | } |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 5852 | long time = pid.mWakeSumMs + (pid.mWakeNesting > 0 |
| 5853 | ? (nowRealtime - pid.mWakeStartMs) : 0); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 5854 | pw.print(" PID "); pw.print(pids.keyAt(j)); |
| 5855 | pw.print(" wake time: "); |
| 5856 | TimeUtils.formatDuration(time, pw); |
| 5857 | pw.println(""); |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 5858 | } |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 5859 | } |
| 5860 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 5861 | if (didPid) { |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 5862 | pw.println(); |
| 5863 | } |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 5864 | } |
| 5865 | |
| 5866 | if (!filtering || (flags&DUMP_CHARGED_ONLY) != 0) { |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 5867 | if (dumpDurationSteps(pw, " ", "Discharge step durations:", |
| 5868 | getDischargeLevelStepTracker(), false)) { |
Kweku Adams | b0449e0 | 2016-10-12 14:18:27 -0700 | [diff] [blame] | 5869 | long timeRemaining = computeBatteryTimeRemaining( |
| 5870 | SystemClock.elapsedRealtime() * 1000); |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 5871 | if (timeRemaining >= 0) { |
| 5872 | pw.print(" Estimated discharge time remaining: "); |
| 5873 | TimeUtils.formatDuration(timeRemaining / 1000, pw); |
| 5874 | pw.println(); |
| 5875 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 5876 | final LevelStepTracker steps = getDischargeLevelStepTracker(); |
| 5877 | for (int i=0; i< STEP_LEVEL_MODES_OF_INTEREST.length; i++) { |
| 5878 | dumpTimeEstimate(pw, " Estimated ", STEP_LEVEL_MODE_LABELS[i], " time: ", |
| 5879 | steps.computeTimeEstimate(STEP_LEVEL_MODES_OF_INTEREST[i], |
| 5880 | STEP_LEVEL_MODE_VALUES[i], null)); |
| 5881 | } |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 5882 | pw.println(); |
| 5883 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 5884 | if (dumpDurationSteps(pw, " ", "Charge step durations:", |
| 5885 | getChargeLevelStepTracker(), false)) { |
Kweku Adams | b0449e0 | 2016-10-12 14:18:27 -0700 | [diff] [blame] | 5886 | long timeRemaining = computeChargeTimeRemaining( |
| 5887 | SystemClock.elapsedRealtime() * 1000); |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 5888 | if (timeRemaining >= 0) { |
| 5889 | pw.print(" Estimated charge time remaining: "); |
| 5890 | TimeUtils.formatDuration(timeRemaining / 1000, pw); |
| 5891 | pw.println(); |
| 5892 | } |
| 5893 | pw.println(); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 5894 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 5895 | } |
| 5896 | if (!filtering || (flags&(DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) != 0) { |
| 5897 | pw.println("Daily stats:"); |
| 5898 | pw.print(" Current start time: "); |
| 5899 | pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss", |
| 5900 | getCurrentDailyStartTime()).toString()); |
| 5901 | pw.print(" Next min deadline: "); |
| 5902 | pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss", |
| 5903 | getNextMinDailyDeadline()).toString()); |
| 5904 | pw.print(" Next max deadline: "); |
| 5905 | pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss", |
| 5906 | getNextMaxDailyDeadline()).toString()); |
| 5907 | StringBuilder sb = new StringBuilder(64); |
| 5908 | int[] outInt = new int[1]; |
| 5909 | LevelStepTracker dsteps = getDailyDischargeLevelStepTracker(); |
| 5910 | LevelStepTracker csteps = getDailyChargeLevelStepTracker(); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 5911 | ArrayList<PackageChange> pkgc = getDailyPackageChanges(); |
| 5912 | if (dsteps.mNumStepDurations > 0 || csteps.mNumStepDurations > 0 || pkgc != null) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5913 | if ((flags&DUMP_DAILY_ONLY) != 0 || !filtering) { |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 5914 | if (dumpDurationSteps(pw, " ", " Current daily discharge step durations:", |
| 5915 | dsteps, false)) { |
| 5916 | dumpDailyLevelStepSummary(pw, " ", "Discharge", dsteps, |
| 5917 | sb, outInt); |
| 5918 | } |
| 5919 | if (dumpDurationSteps(pw, " ", " Current daily charge step durations:", |
| 5920 | csteps, false)) { |
| 5921 | dumpDailyLevelStepSummary(pw, " ", "Charge", csteps, |
| 5922 | sb, outInt); |
| 5923 | } |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 5924 | dumpDailyPackageChanges(pw, " ", pkgc); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 5925 | } else { |
| 5926 | pw.println(" Current daily steps:"); |
| 5927 | dumpDailyLevelStepSummary(pw, " ", "Discharge", dsteps, |
| 5928 | sb, outInt); |
| 5929 | dumpDailyLevelStepSummary(pw, " ", "Charge", csteps, |
| 5930 | sb, outInt); |
| 5931 | } |
| 5932 | } |
| 5933 | DailyItem dit; |
| 5934 | int curIndex = 0; |
| 5935 | while ((dit=getDailyItemLocked(curIndex)) != null) { |
| 5936 | curIndex++; |
| 5937 | if ((flags&DUMP_DAILY_ONLY) != 0) { |
| 5938 | pw.println(); |
| 5939 | } |
| 5940 | pw.print(" Daily from "); |
| 5941 | pw.print(DateFormat.format("yyyy-MM-dd-HH-mm-ss", dit.mStartTime).toString()); |
| 5942 | pw.print(" to "); |
| 5943 | pw.print(DateFormat.format("yyyy-MM-dd-HH-mm-ss", dit.mEndTime).toString()); |
| 5944 | pw.println(":"); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5945 | if ((flags&DUMP_DAILY_ONLY) != 0 || !filtering) { |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 5946 | if (dumpDurationSteps(pw, " ", |
| 5947 | " Discharge step durations:", dit.mDischargeSteps, false)) { |
| 5948 | dumpDailyLevelStepSummary(pw, " ", "Discharge", dit.mDischargeSteps, |
| 5949 | sb, outInt); |
| 5950 | } |
| 5951 | if (dumpDurationSteps(pw, " ", |
| 5952 | " Charge step durations:", dit.mChargeSteps, false)) { |
| 5953 | dumpDailyLevelStepSummary(pw, " ", "Charge", dit.mChargeSteps, |
| 5954 | sb, outInt); |
| 5955 | } |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 5956 | dumpDailyPackageChanges(pw, " ", dit.mPackageChanges); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 5957 | } else { |
| 5958 | dumpDailyLevelStepSummary(pw, " ", "Discharge", dit.mDischargeSteps, |
| 5959 | sb, outInt); |
| 5960 | dumpDailyLevelStepSummary(pw, " ", "Charge", dit.mChargeSteps, |
| 5961 | sb, outInt); |
| 5962 | } |
| 5963 | } |
| 5964 | pw.println(); |
| 5965 | } |
| 5966 | if (!filtering || (flags&DUMP_CHARGED_ONLY) != 0) { |
Jeff Sharkey | ec43a6b | 2013-04-30 13:33:18 -0700 | [diff] [blame] | 5967 | pw.println("Statistics since last charge:"); |
| 5968 | pw.println(" System starts: " + getStartCount() |
| 5969 | + ", currently on battery: " + getIsOnBattery()); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 5970 | dumpLocked(context, pw, "", STATS_SINCE_CHARGED, reqUid, |
| 5971 | (flags&DUMP_DEVICE_WIFI_ONLY) != 0); |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 5972 | pw.println(); |
Jeff Sharkey | ec43a6b | 2013-04-30 13:33:18 -0700 | [diff] [blame] | 5973 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5974 | } |
| 5975 | |
| 5976 | @SuppressWarnings("unused") |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 5977 | public void dumpCheckinLocked(Context context, PrintWriter pw, |
| 5978 | List<ApplicationInfo> apps, int flags, long histStart) { |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5979 | prepareForDumpLocked(); |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 5980 | |
| 5981 | dumpLine(pw, 0 /* uid */, "i" /* category */, VERSION_DATA, |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 5982 | CHECKIN_VERSION, getParcelVersion(), getStartPlatformVersion(), |
| 5983 | getEndPlatformVersion()); |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 5984 | |
Dianne Hackborn | 13ac041 | 2013-06-25 19:34:49 -0700 | [diff] [blame] | 5985 | long now = getHistoryBaseTime() + SystemClock.elapsedRealtime(); |
| 5986 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 5987 | final boolean filtering = (flags & |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5988 | (DUMP_HISTORY_ONLY|DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) != 0; |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 5989 | |
| 5990 | if ((flags&DUMP_INCLUDE_HISTORY) != 0 || (flags&DUMP_HISTORY_ONLY) != 0) { |
Dianne Hackborn | 49021f5 | 2013-09-04 18:03:40 -0700 | [diff] [blame] | 5991 | if (startIteratingHistoryLocked()) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 5992 | try { |
| 5993 | for (int i=0; i<getHistoryStringPoolSize(); i++) { |
| 5994 | pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(','); |
| 5995 | pw.print(HISTORY_STRING_POOL); pw.print(','); |
| 5996 | pw.print(i); |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 5997 | pw.print(","); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 5998 | pw.print(getHistoryTagPoolUid(i)); |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 5999 | pw.print(",\""); |
| 6000 | String str = getHistoryTagPoolString(i); |
| 6001 | str = str.replace("\\", "\\\\"); |
| 6002 | str = str.replace("\"", "\\\""); |
| 6003 | pw.print(str); |
| 6004 | pw.print("\""); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 6005 | pw.println(); |
| 6006 | } |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 6007 | dumpHistoryLocked(pw, flags, histStart, true); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 6008 | } finally { |
| 6009 | finishIteratingHistoryLocked(); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 6010 | } |
Dianne Hackborn | 13ac041 | 2013-06-25 19:34:49 -0700 | [diff] [blame] | 6011 | } |
Dianne Hackborn | 13ac041 | 2013-06-25 19:34:49 -0700 | [diff] [blame] | 6012 | } |
| 6013 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 6014 | if (filtering && (flags&(DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) == 0) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 6015 | return; |
| 6016 | } |
| 6017 | |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 6018 | if (apps != null) { |
Dianne Hackborn | 9cfba35 | 2016-03-24 17:31:28 -0700 | [diff] [blame] | 6019 | SparseArray<Pair<ArrayList<String>, MutableBoolean>> uids = new SparseArray<>(); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 6020 | for (int i=0; i<apps.size(); i++) { |
| 6021 | ApplicationInfo ai = apps.get(i); |
Dianne Hackborn | 9cfba35 | 2016-03-24 17:31:28 -0700 | [diff] [blame] | 6022 | Pair<ArrayList<String>, MutableBoolean> pkgs = uids.get( |
| 6023 | UserHandle.getAppId(ai.uid)); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 6024 | if (pkgs == null) { |
Dianne Hackborn | 9cfba35 | 2016-03-24 17:31:28 -0700 | [diff] [blame] | 6025 | pkgs = new Pair<>(new ArrayList<String>(), new MutableBoolean(false)); |
| 6026 | uids.put(UserHandle.getAppId(ai.uid), pkgs); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 6027 | } |
Dianne Hackborn | 9cfba35 | 2016-03-24 17:31:28 -0700 | [diff] [blame] | 6028 | pkgs.first.add(ai.packageName); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 6029 | } |
| 6030 | SparseArray<? extends Uid> uidStats = getUidStats(); |
| 6031 | final int NU = uidStats.size(); |
| 6032 | String[] lineArgs = new String[2]; |
| 6033 | for (int i=0; i<NU; i++) { |
Dianne Hackborn | 9cfba35 | 2016-03-24 17:31:28 -0700 | [diff] [blame] | 6034 | int uid = UserHandle.getAppId(uidStats.keyAt(i)); |
| 6035 | Pair<ArrayList<String>, MutableBoolean> pkgs = uids.get(uid); |
| 6036 | if (pkgs != null && !pkgs.second.value) { |
| 6037 | pkgs.second.value = true; |
| 6038 | for (int j=0; j<pkgs.first.size(); j++) { |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 6039 | lineArgs[0] = Integer.toString(uid); |
Dianne Hackborn | 9cfba35 | 2016-03-24 17:31:28 -0700 | [diff] [blame] | 6040 | lineArgs[1] = pkgs.first.get(j); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 6041 | dumpLine(pw, 0 /* uid */, "i" /* category */, UID_DATA, |
| 6042 | (Object[])lineArgs); |
| 6043 | } |
| 6044 | } |
| 6045 | } |
| 6046 | } |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 6047 | if (!filtering || (flags&DUMP_CHARGED_ONLY) != 0) { |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6048 | dumpDurationSteps(pw, "", DISCHARGE_STEP_DATA, getDischargeLevelStepTracker(), true); |
Dianne Hackborn | d06dcfd | 2014-05-02 13:49:30 -0700 | [diff] [blame] | 6049 | String[] lineArgs = new String[1]; |
Kweku Adams | b0449e0 | 2016-10-12 14:18:27 -0700 | [diff] [blame] | 6050 | long timeRemaining = computeBatteryTimeRemaining(SystemClock.elapsedRealtime() * 1000); |
Dianne Hackborn | d06dcfd | 2014-05-02 13:49:30 -0700 | [diff] [blame] | 6051 | if (timeRemaining >= 0) { |
| 6052 | lineArgs[0] = Long.toString(timeRemaining); |
| 6053 | dumpLine(pw, 0 /* uid */, "i" /* category */, DISCHARGE_TIME_REMAIN_DATA, |
| 6054 | (Object[])lineArgs); |
| 6055 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 6056 | dumpDurationSteps(pw, "", CHARGE_STEP_DATA, getChargeLevelStepTracker(), true); |
Kweku Adams | b0449e0 | 2016-10-12 14:18:27 -0700 | [diff] [blame] | 6057 | timeRemaining = computeChargeTimeRemaining(SystemClock.elapsedRealtime() * 1000); |
Dianne Hackborn | d06dcfd | 2014-05-02 13:49:30 -0700 | [diff] [blame] | 6058 | if (timeRemaining >= 0) { |
| 6059 | lineArgs[0] = Long.toString(timeRemaining); |
| 6060 | dumpLine(pw, 0 /* uid */, "i" /* category */, CHARGE_TIME_REMAIN_DATA, |
| 6061 | (Object[])lineArgs); |
| 6062 | } |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 6063 | dumpCheckinLocked(context, pw, STATS_SINCE_CHARGED, -1, |
| 6064 | (flags&DUMP_DEVICE_WIFI_ONLY) != 0); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 6065 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6066 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6067 | } |