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; |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 33 | import android.util.Log; |
James Carr | 2dd7e5e | 2016-07-20 18:48:39 -0700 | [diff] [blame] | 34 | import android.util.LongSparseArray; |
Dianne Hackborn | 9cfba35 | 2016-03-24 17:31:28 -0700 | [diff] [blame] | 35 | import android.util.MutableBoolean; |
| 36 | import android.util.Pair; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 37 | import android.util.Printer; |
| 38 | import android.util.SparseArray; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 39 | import android.util.SparseIntArray; |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 40 | import android.util.TimeUtils; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 41 | import android.view.Display; |
Amith Yamasani | ab9ad19 | 2016-12-06 12:46:59 -0800 | [diff] [blame^] | 42 | |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 43 | import com.android.internal.os.BatterySipper; |
| 44 | import com.android.internal.os.BatteryStatsHelper; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 45 | |
| 46 | /** |
| 47 | * A class providing access to battery usage statistics, including information on |
| 48 | * wakelocks, processes, packages, and services. All times are represented in microseconds |
| 49 | * except where indicated otherwise. |
| 50 | * @hide |
| 51 | */ |
| 52 | public abstract class BatteryStats implements Parcelable { |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 53 | private static final String TAG = "BatteryStats"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 54 | |
| 55 | private static final boolean LOCAL_LOGV = false; |
Dianne Hackborn | 91268cf | 2013-06-13 19:06:50 -0700 | [diff] [blame] | 56 | |
| 57 | /** @hide */ |
| 58 | public static final String SERVICE_NAME = "batterystats"; |
| 59 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 60 | /** |
| 61 | * A constant indicating a partial wake lock timer. |
| 62 | */ |
| 63 | public static final int WAKE_TYPE_PARTIAL = 0; |
| 64 | |
| 65 | /** |
| 66 | * A constant indicating a full wake lock timer. |
| 67 | */ |
| 68 | public static final int WAKE_TYPE_FULL = 1; |
| 69 | |
| 70 | /** |
| 71 | * A constant indicating a window wake lock timer. |
| 72 | */ |
| 73 | public static final int WAKE_TYPE_WINDOW = 2; |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 74 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 75 | /** |
| 76 | * A constant indicating a sensor timer. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 77 | */ |
| 78 | public static final int SENSOR = 3; |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 79 | |
| 80 | /** |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 81 | * A constant indicating a a wifi running timer |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 82 | */ |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 83 | public static final int WIFI_RUNNING = 4; |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 84 | |
| 85 | /** |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 86 | * A constant indicating a full wifi lock timer |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 87 | */ |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 88 | public static final int FULL_WIFI_LOCK = 5; |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 89 | |
| 90 | /** |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 91 | * A constant indicating a wifi scan |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 92 | */ |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 93 | public static final int WIFI_SCAN = 6; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 94 | |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 95 | /** |
| 96 | * A constant indicating a wifi multicast timer |
| 97 | */ |
| 98 | public static final int WIFI_MULTICAST_ENABLED = 7; |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 99 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 100 | /** |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 101 | * A constant indicating a video turn on timer |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 102 | */ |
| 103 | public static final int VIDEO_TURNED_ON = 8; |
| 104 | |
| 105 | /** |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 106 | * A constant indicating a vibrator on timer |
| 107 | */ |
| 108 | public static final int VIBRATOR_ON = 9; |
| 109 | |
| 110 | /** |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 111 | * A constant indicating a foreground activity timer |
| 112 | */ |
| 113 | public static final int FOREGROUND_ACTIVITY = 10; |
| 114 | |
| 115 | /** |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 116 | * A constant indicating a wifi batched scan is active |
| 117 | */ |
| 118 | public static final int WIFI_BATCHED_SCAN = 11; |
| 119 | |
| 120 | /** |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 121 | * A constant indicating a process state timer |
| 122 | */ |
| 123 | public static final int PROCESS_STATE = 12; |
| 124 | |
| 125 | /** |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 126 | * A constant indicating a sync timer |
| 127 | */ |
| 128 | public static final int SYNC = 13; |
| 129 | |
| 130 | /** |
| 131 | * A constant indicating a job timer |
| 132 | */ |
| 133 | public static final int JOB = 14; |
| 134 | |
| 135 | /** |
Kweku Adams | d537987 | 2014-11-24 17:34:05 -0800 | [diff] [blame] | 136 | * A constant indicating an audio turn on timer |
| 137 | */ |
| 138 | public static final int AUDIO_TURNED_ON = 15; |
| 139 | |
| 140 | /** |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 141 | * A constant indicating a flashlight turn on timer |
| 142 | */ |
| 143 | public static final int FLASHLIGHT_TURNED_ON = 16; |
| 144 | |
| 145 | /** |
| 146 | * A constant indicating a camera turn on timer |
| 147 | */ |
| 148 | public static final int CAMERA_TURNED_ON = 17; |
| 149 | |
| 150 | /** |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 151 | * A constant indicating a draw wake lock timer. |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 152 | */ |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 153 | public static final int WAKE_TYPE_DRAW = 18; |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 154 | |
| 155 | /** |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 156 | * A constant indicating a bluetooth scan timer. |
| 157 | */ |
| 158 | public static final int BLUETOOTH_SCAN_ON = 19; |
| 159 | |
| 160 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 161 | * Include all of the data in the stats, including previously saved data. |
| 162 | */ |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 163 | public static final int STATS_SINCE_CHARGED = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 164 | |
| 165 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 166 | * Include only the current run in the stats. |
| 167 | */ |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 168 | public static final int STATS_CURRENT = 1; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 169 | |
| 170 | /** |
| 171 | * Include only the run since the last time the device was unplugged in the stats. |
| 172 | */ |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 173 | public static final int STATS_SINCE_UNPLUGGED = 2; |
Evan Millar | e84de8d | 2009-04-02 22:16:12 -0700 | [diff] [blame] | 174 | |
| 175 | // NOTE: Update this list if you add/change any stats above. |
| 176 | // These characters are supposed to represent "total", "last", "current", |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 177 | // and "unplugged". They were shortened for efficiency sake. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 178 | private static final String[] STAT_NAMES = { "l", "c", "u" }; |
| 179 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 180 | /** |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 181 | * Current version of checkin data format. |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 182 | * |
| 183 | * New in version 19: |
| 184 | * - Wakelock data (wl) gets current and max times. |
Amith Yamasani | ab9ad19 | 2016-12-06 12:46:59 -0800 | [diff] [blame^] | 185 | * New in version 20: |
| 186 | * - Sensor gets a background counter. |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 187 | */ |
Kweku Adams | 47db5a8 | 2016-12-09 19:04:50 -0800 | [diff] [blame] | 188 | static final String CHECKIN_VERSION = "20"; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 189 | |
| 190 | /** |
| 191 | * 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] | 192 | */ |
Ashish Sharma | 213bb2f | 2014-07-07 17:14:52 -0700 | [diff] [blame] | 193 | private static final int BATTERY_STATS_CHECKIN_VERSION = 9; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 194 | |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 195 | private static final long BYTES_PER_KB = 1024; |
| 196 | private static final long BYTES_PER_MB = 1048576; // 1024^2 |
| 197 | private static final long BYTES_PER_GB = 1073741824; //1024^3 |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 198 | |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 199 | private static final String VERSION_DATA = "vers"; |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 200 | private static final String UID_DATA = "uid"; |
Joe Onorato | 1476d32 | 2016-05-05 14:46:15 -0700 | [diff] [blame] | 201 | private static final String WAKEUP_ALARM_DATA = "wua"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 202 | private static final String APK_DATA = "apk"; |
Evan Millar | e84de8d | 2009-04-02 22:16:12 -0700 | [diff] [blame] | 203 | private static final String PROCESS_DATA = "pr"; |
Adam Lesinski | a7a4ccc | 2015-06-26 17:43:04 -0700 | [diff] [blame] | 204 | private static final String CPU_DATA = "cpu"; |
Evan Millar | e84de8d | 2009-04-02 22:16:12 -0700 | [diff] [blame] | 205 | private static final String SENSOR_DATA = "sr"; |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 206 | private static final String VIBRATOR_DATA = "vib"; |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 207 | private static final String FOREGROUND_DATA = "fg"; |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 208 | private static final String STATE_TIME_DATA = "st"; |
Evan Millar | e84de8d | 2009-04-02 22:16:12 -0700 | [diff] [blame] | 209 | private static final String WAKELOCK_DATA = "wl"; |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 210 | private static final String SYNC_DATA = "sy"; |
| 211 | private static final String JOB_DATA = "jb"; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 212 | private static final String KERNEL_WAKELOCK_DATA = "kwl"; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 213 | private static final String WAKEUP_REASON_DATA = "wr"; |
Evan Millar | e84de8d | 2009-04-02 22:16:12 -0700 | [diff] [blame] | 214 | private static final String NETWORK_DATA = "nt"; |
| 215 | private static final String USER_ACTIVITY_DATA = "ua"; |
| 216 | private static final String BATTERY_DATA = "bt"; |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 217 | private static final String BATTERY_DISCHARGE_DATA = "dc"; |
Evan Millar | e84de8d | 2009-04-02 22:16:12 -0700 | [diff] [blame] | 218 | private static final String BATTERY_LEVEL_DATA = "lv"; |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 219 | private static final String GLOBAL_WIFI_DATA = "gwfl"; |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 220 | private static final String WIFI_DATA = "wfl"; |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 221 | private static final String GLOBAL_WIFI_CONTROLLER_DATA = "gwfcd"; |
| 222 | private static final String WIFI_CONTROLLER_DATA = "wfcd"; |
| 223 | private static final String GLOBAL_BLUETOOTH_CONTROLLER_DATA = "gble"; |
| 224 | private static final String BLUETOOTH_CONTROLLER_DATA = "ble"; |
Adam Lesinski | d9b99be | 2016-03-30 16:58:51 -0700 | [diff] [blame] | 225 | private static final String BLUETOOTH_MISC_DATA = "blem"; |
Evan Millar | e84de8d | 2009-04-02 22:16:12 -0700 | [diff] [blame] | 226 | private static final String MISC_DATA = "m"; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 227 | private static final String GLOBAL_NETWORK_DATA = "gn"; |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 228 | private static final String GLOBAL_MODEM_CONTROLLER_DATA = "gmcd"; |
| 229 | private static final String MODEM_CONTROLLER_DATA = "mcd"; |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 230 | private static final String HISTORY_STRING_POOL = "hsp"; |
Dianne Hackborn | 8a0de58 | 2013-08-07 15:22:07 -0700 | [diff] [blame] | 231 | private static final String HISTORY_DATA = "h"; |
Evan Millar | e84de8d | 2009-04-02 22:16:12 -0700 | [diff] [blame] | 232 | private static final String SCREEN_BRIGHTNESS_DATA = "br"; |
| 233 | private static final String SIGNAL_STRENGTH_TIME_DATA = "sgt"; |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 234 | private static final String SIGNAL_SCANNING_TIME_DATA = "sst"; |
Evan Millar | e84de8d | 2009-04-02 22:16:12 -0700 | [diff] [blame] | 235 | private static final String SIGNAL_STRENGTH_COUNT_DATA = "sgc"; |
| 236 | private static final String DATA_CONNECTION_TIME_DATA = "dct"; |
| 237 | private static final String DATA_CONNECTION_COUNT_DATA = "dcc"; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 238 | private static final String WIFI_STATE_TIME_DATA = "wst"; |
| 239 | private static final String WIFI_STATE_COUNT_DATA = "wsc"; |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 240 | private static final String WIFI_SUPPL_STATE_TIME_DATA = "wsst"; |
| 241 | private static final String WIFI_SUPPL_STATE_COUNT_DATA = "wssc"; |
| 242 | private static final String WIFI_SIGNAL_STRENGTH_TIME_DATA = "wsgt"; |
| 243 | private static final String WIFI_SIGNAL_STRENGTH_COUNT_DATA = "wsgc"; |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 244 | private static final String POWER_USE_SUMMARY_DATA = "pws"; |
| 245 | private static final String POWER_USE_ITEM_DATA = "pwi"; |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 246 | private static final String DISCHARGE_STEP_DATA = "dsd"; |
| 247 | private static final String CHARGE_STEP_DATA = "csd"; |
Dianne Hackborn | d06dcfd | 2014-05-02 13:49:30 -0700 | [diff] [blame] | 248 | private static final String DISCHARGE_TIME_REMAIN_DATA = "dtr"; |
| 249 | private static final String CHARGE_TIME_REMAIN_DATA = "ctr"; |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 250 | private static final String FLASHLIGHT_DATA = "fla"; |
| 251 | private static final String CAMERA_DATA = "cam"; |
| 252 | private static final String VIDEO_DATA = "vid"; |
| 253 | private static final String AUDIO_DATA = "aud"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 254 | |
Adam Lesinski | 010bf37 | 2016-04-11 12:18:18 -0700 | [diff] [blame] | 255 | public static final String RESULT_RECEIVER_CONTROLLER_KEY = "controller_activity"; |
| 256 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 257 | private final StringBuilder mFormatBuilder = new StringBuilder(32); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 258 | private final Formatter mFormatter = new Formatter(mFormatBuilder); |
| 259 | |
| 260 | /** |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 261 | * State for keeping track of counting information. |
| 262 | */ |
| 263 | public static abstract class Counter { |
| 264 | |
| 265 | /** |
| 266 | * Returns the count associated with this Counter for the |
| 267 | * selected type of statistics. |
| 268 | * |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 269 | * @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] | 270 | */ |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 271 | public abstract int getCountLocked(int which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 272 | |
| 273 | /** |
| 274 | * Temporary for debugging. |
| 275 | */ |
| 276 | public abstract void logState(Printer pw, String prefix); |
| 277 | } |
| 278 | |
| 279 | /** |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 280 | * State for keeping track of long counting information. |
| 281 | */ |
| 282 | public static abstract class LongCounter { |
| 283 | |
| 284 | /** |
| 285 | * Returns the count associated with this Counter for the |
| 286 | * selected type of statistics. |
| 287 | * |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 288 | * @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] | 289 | */ |
| 290 | public abstract long getCountLocked(int which); |
| 291 | |
| 292 | /** |
| 293 | * Temporary for debugging. |
| 294 | */ |
| 295 | public abstract void logState(Printer pw, String prefix); |
| 296 | } |
| 297 | |
| 298 | /** |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 299 | * Container class that aggregates counters for transmit, receive, and idle state of a |
| 300 | * radio controller. |
| 301 | */ |
| 302 | public static abstract class ControllerActivityCounter { |
| 303 | /** |
| 304 | * @return a non-null {@link LongCounter} representing time spent (milliseconds) in the |
| 305 | * idle state. |
| 306 | */ |
| 307 | public abstract LongCounter getIdleTimeCounter(); |
| 308 | |
| 309 | /** |
| 310 | * @return a non-null {@link LongCounter} representing time spent (milliseconds) in the |
| 311 | * receive state. |
| 312 | */ |
| 313 | public abstract LongCounter getRxTimeCounter(); |
| 314 | |
| 315 | /** |
| 316 | * An array of {@link LongCounter}, representing various transmit levels, where each level |
| 317 | * may draw a different amount of power. The levels themselves are controller-specific. |
| 318 | * @return non-null array of {@link LongCounter}s representing time spent (milliseconds) in |
| 319 | * various transmit level states. |
| 320 | */ |
| 321 | public abstract LongCounter[] getTxTimeCounters(); |
| 322 | |
| 323 | /** |
| 324 | * @return a non-null {@link LongCounter} representing the power consumed by the controller |
| 325 | * in all states, measured in milli-ampere-milliseconds (mAms). The counter may always |
| 326 | * yield a value of 0 if the device doesn't support power calculations. |
| 327 | */ |
| 328 | public abstract LongCounter getPowerCounter(); |
| 329 | } |
| 330 | |
| 331 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 332 | * State for keeping track of timing information. |
| 333 | */ |
| 334 | public static abstract class Timer { |
| 335 | |
| 336 | /** |
| 337 | * Returns the count associated with this Timer for the |
| 338 | * selected type of statistics. |
| 339 | * |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 340 | * @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] | 341 | */ |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 342 | public abstract int getCountLocked(int which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 343 | |
| 344 | /** |
| 345 | * Returns the total time in microseconds associated with this Timer for the |
| 346 | * selected type of statistics. |
| 347 | * |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 348 | * @param elapsedRealtimeUs current elapsed realtime of system in microseconds |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 349 | * @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] | 350 | * @return a time in microseconds |
| 351 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 352 | public abstract long getTotalTimeLocked(long elapsedRealtimeUs, int which); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 353 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 354 | /** |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 355 | * Returns the total time in microseconds associated with this Timer since the |
| 356 | * 'mark' was last set. |
| 357 | * |
| 358 | * @param elapsedRealtimeUs current elapsed realtime of system in microseconds |
| 359 | * @return a time in microseconds |
| 360 | */ |
| 361 | public abstract long getTimeSinceMarkLocked(long elapsedRealtimeUs); |
| 362 | |
| 363 | /** |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 364 | * Returns the max duration if it is being tracked. |
| 365 | * Not all Timer subclasses track the max duration and the current duration. |
| 366 | |
| 367 | */ |
| 368 | public long getMaxDurationMsLocked(long elapsedRealtimeMs) { |
| 369 | return -1; |
| 370 | } |
| 371 | |
| 372 | /** |
| 373 | * Returns the current time the timer has been active, if it is being tracked. |
| 374 | * Not all Timer subclasses track the max duration and the current duration. |
| 375 | */ |
| 376 | public long getCurrentDurationMsLocked(long elapsedRealtimeMs) { |
| 377 | return -1; |
| 378 | } |
| 379 | |
| 380 | /** |
| 381 | * Returns whether the timer is currently running. Some types of timers |
| 382 | * (e.g. BatchTimers) don't know whether the event is currently active, |
| 383 | * and report false. |
| 384 | */ |
| 385 | public boolean isRunningLocked() { |
| 386 | return false; |
| 387 | } |
| 388 | |
| 389 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 390 | * Temporary for debugging. |
| 391 | */ |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 392 | public abstract void logState(Printer pw, String prefix); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 393 | } |
| 394 | |
| 395 | /** |
| 396 | * The statistics associated with a particular uid. |
| 397 | */ |
| 398 | public static abstract class Uid { |
| 399 | |
| 400 | /** |
| 401 | * Returns a mapping containing wakelock statistics. |
| 402 | * |
| 403 | * @return a Map from Strings to Uid.Wakelock objects. |
| 404 | */ |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 405 | public abstract ArrayMap<String, ? extends Wakelock> getWakelockStats(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 406 | |
| 407 | /** |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 408 | * Returns a mapping containing sync statistics. |
| 409 | * |
| 410 | * @return a Map from Strings to Timer objects. |
| 411 | */ |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 412 | public abstract ArrayMap<String, ? extends Timer> getSyncStats(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 413 | |
| 414 | /** |
| 415 | * Returns a mapping containing scheduled job statistics. |
| 416 | * |
| 417 | * @return a Map from Strings to Timer objects. |
| 418 | */ |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 419 | public abstract ArrayMap<String, ? extends Timer> getJobStats(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 420 | |
| 421 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 422 | * The statistics associated with a particular wake lock. |
| 423 | */ |
| 424 | public static abstract class Wakelock { |
| 425 | public abstract Timer getWakeTime(int type); |
| 426 | } |
| 427 | |
| 428 | /** |
| 429 | * Returns a mapping containing sensor statistics. |
| 430 | * |
| 431 | * @return a Map from Integer sensor ids to Uid.Sensor objects. |
| 432 | */ |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 433 | public abstract SparseArray<? extends Sensor> getSensorStats(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 434 | |
| 435 | /** |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 436 | * Returns a mapping containing active process data. |
| 437 | */ |
| 438 | public abstract SparseArray<? extends Pid> getPidStats(); |
| 439 | |
| 440 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 441 | * Returns a mapping containing process statistics. |
| 442 | * |
| 443 | * @return a Map from Strings to Uid.Proc objects. |
| 444 | */ |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 445 | public abstract ArrayMap<String, ? extends Proc> getProcessStats(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 446 | |
| 447 | /** |
| 448 | * Returns a mapping containing package statistics. |
| 449 | * |
| 450 | * @return a Map from Strings to Uid.Pkg objects. |
| 451 | */ |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 452 | public abstract ArrayMap<String, ? extends Pkg> getPackageStats(); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 453 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 454 | public abstract ControllerActivityCounter getWifiControllerActivity(); |
| 455 | public abstract ControllerActivityCounter getBluetoothControllerActivity(); |
| 456 | public abstract ControllerActivityCounter getModemControllerActivity(); |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 457 | |
| 458 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 459 | * {@hide} |
| 460 | */ |
| 461 | public abstract int getUid(); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 462 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 463 | public abstract void noteWifiRunningLocked(long elapsedRealtime); |
| 464 | public abstract void noteWifiStoppedLocked(long elapsedRealtime); |
| 465 | public abstract void noteFullWifiLockAcquiredLocked(long elapsedRealtime); |
| 466 | public abstract void noteFullWifiLockReleasedLocked(long elapsedRealtime); |
| 467 | public abstract void noteWifiScanStartedLocked(long elapsedRealtime); |
| 468 | public abstract void noteWifiScanStoppedLocked(long elapsedRealtime); |
| 469 | public abstract void noteWifiBatchedScanStartedLocked(int csph, long elapsedRealtime); |
| 470 | public abstract void noteWifiBatchedScanStoppedLocked(long elapsedRealtime); |
| 471 | public abstract void noteWifiMulticastEnabledLocked(long elapsedRealtime); |
| 472 | public abstract void noteWifiMulticastDisabledLocked(long elapsedRealtime); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 473 | public abstract void noteActivityResumedLocked(long elapsedRealtime); |
| 474 | public abstract void noteActivityPausedLocked(long elapsedRealtime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 475 | public abstract long getWifiRunningTime(long elapsedRealtimeUs, int which); |
| 476 | public abstract long getFullWifiLockTime(long elapsedRealtimeUs, int which); |
| 477 | public abstract long getWifiScanTime(long elapsedRealtimeUs, int which); |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 478 | public abstract int getWifiScanCount(int which); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 479 | public abstract long getWifiBatchedScanTime(int csphBin, long elapsedRealtimeUs, int which); |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 480 | public abstract int getWifiBatchedScanCount(int csphBin, int which); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 481 | public abstract long getWifiMulticastTime(long elapsedRealtimeUs, int which); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 482 | public abstract Timer getAudioTurnedOnTimer(); |
| 483 | public abstract Timer getVideoTurnedOnTimer(); |
| 484 | public abstract Timer getFlashlightTurnedOnTimer(); |
| 485 | public abstract Timer getCameraTurnedOnTimer(); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 486 | public abstract Timer getForegroundActivityTimer(); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 487 | public abstract Timer getBluetoothScanTimer(); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 488 | |
Dianne Hackborn | a0200e3 | 2016-03-30 18:01:41 -0700 | [diff] [blame] | 489 | // Note: the following times are disjoint. They can be added together to find the |
| 490 | // total time a uid has had any processes running at all. |
| 491 | |
| 492 | /** |
| 493 | * Time this uid has any processes in the top state (or above such as persistent). |
| 494 | */ |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 495 | public static final int PROCESS_STATE_TOP = 0; |
Dianne Hackborn | a0200e3 | 2016-03-30 18:01:41 -0700 | [diff] [blame] | 496 | /** |
| 497 | * Time this uid has any process with a started out bound foreground service, but |
| 498 | * none in the "top" state. |
| 499 | */ |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 500 | public static final int PROCESS_STATE_FOREGROUND_SERVICE = 1; |
Dianne Hackborn | a0200e3 | 2016-03-30 18:01:41 -0700 | [diff] [blame] | 501 | /** |
| 502 | * Time this uid has any process that is top while the device is sleeping, but none |
| 503 | * in the "foreground service" or better state. |
| 504 | */ |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 505 | public static final int PROCESS_STATE_TOP_SLEEPING = 2; |
Dianne Hackborn | a0200e3 | 2016-03-30 18:01:41 -0700 | [diff] [blame] | 506 | /** |
| 507 | * Time this uid has any process in an active foreground state, but none in the |
| 508 | * "top sleeping" or better state. |
| 509 | */ |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 510 | public static final int PROCESS_STATE_FOREGROUND = 3; |
Dianne Hackborn | a0200e3 | 2016-03-30 18:01:41 -0700 | [diff] [blame] | 511 | /** |
| 512 | * Time this uid has any process in an active background state, but none in the |
| 513 | * "foreground" or better state. |
| 514 | */ |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 515 | public static final int PROCESS_STATE_BACKGROUND = 4; |
Dianne Hackborn | a0200e3 | 2016-03-30 18:01:41 -0700 | [diff] [blame] | 516 | /** |
| 517 | * Time this uid has any processes that are sitting around cached, not in one of the |
| 518 | * other active states. |
| 519 | */ |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 520 | public static final int PROCESS_STATE_CACHED = 5; |
Dianne Hackborn | a0200e3 | 2016-03-30 18:01:41 -0700 | [diff] [blame] | 521 | /** |
| 522 | * Total number of process states we track. |
| 523 | */ |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 524 | public static final int NUM_PROCESS_STATE = 6; |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 525 | |
| 526 | static final String[] PROCESS_STATE_NAMES = { |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 527 | "Top", "Fg Service", "Top Sleeping", "Foreground", "Background", "Cached" |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 528 | }; |
| 529 | |
| 530 | public abstract long getProcessStateTime(int state, long elapsedRealtimeUs, int which); |
Joe Onorato | 713fec8 | 2016-03-04 10:34:02 -0800 | [diff] [blame] | 531 | public abstract Timer getProcessStateTimer(int state); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 532 | |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 533 | public abstract Timer getVibratorOnTimer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 534 | |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 535 | public static final int NUM_WIFI_BATCHED_SCAN_BINS = 5; |
| 536 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 537 | /** |
Jeff Brown | df693de | 2012-07-27 12:03:38 -0700 | [diff] [blame] | 538 | * Note that these must match the constants in android.os.PowerManager. |
| 539 | * Also, if the user activity types change, the BatteryStatsImpl.VERSION must |
| 540 | * also be bumped. |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 541 | */ |
| 542 | static final String[] USER_ACTIVITY_TYPES = { |
Phil Weaver | da80d67 | 2016-03-15 16:25:46 -0700 | [diff] [blame] | 543 | "other", "button", "touch", "accessibility" |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 544 | }; |
| 545 | |
Phil Weaver | da80d67 | 2016-03-15 16:25:46 -0700 | [diff] [blame] | 546 | public static final int NUM_USER_ACTIVITY_TYPES = 4; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 547 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 548 | public abstract void noteUserActivityLocked(int type); |
| 549 | public abstract boolean hasUserActivity(); |
| 550 | public abstract int getUserActivityCount(int type, int which); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 551 | |
| 552 | public abstract boolean hasNetworkActivity(); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 553 | public abstract long getNetworkActivityBytes(int type, int which); |
| 554 | public abstract long getNetworkActivityPackets(int type, int which); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 555 | public abstract long getMobileRadioActiveTime(int which); |
| 556 | public abstract int getMobileRadioActiveCount(int which); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 557 | |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 558 | /** |
| 559 | * Get the total cpu time (in microseconds) this UID had processes executing in userspace. |
| 560 | */ |
| 561 | public abstract long getUserCpuTimeUs(int which); |
| 562 | |
| 563 | /** |
| 564 | * Get the total cpu time (in microseconds) this UID had processes executing kernel syscalls. |
| 565 | */ |
| 566 | public abstract long getSystemCpuTimeUs(int which); |
| 567 | |
| 568 | /** |
Adam Lesinski | a7a4ccc | 2015-06-26 17:43:04 -0700 | [diff] [blame] | 569 | * Get the total cpu power consumed (in milli-ampere-microseconds). |
| 570 | */ |
| 571 | public abstract long getCpuPowerMaUs(int which); |
| 572 | |
| 573 | /** |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 574 | * Returns the approximate cpu time (in milliseconds) spent at a certain CPU speed for a |
| 575 | * given CPU cluster. |
| 576 | * @param cluster the index of the CPU cluster. |
Adam Lesinski | a7a4ccc | 2015-06-26 17:43:04 -0700 | [diff] [blame] | 577 | * @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] | 578 | * @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] | 579 | * @see com.android.internal.os.PowerProfile#getNumCpuClusters() |
| 580 | * @see com.android.internal.os.PowerProfile#getNumSpeedStepsInCpuCluster(int) |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 581 | */ |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 582 | public abstract long getTimeAtCpuSpeed(int cluster, int step, int which); |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 583 | |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 584 | /** |
| 585 | * Returns the number of times this UID woke up the Application Processor to |
| 586 | * process a mobile radio packet. |
| 587 | * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT. |
| 588 | */ |
| 589 | public abstract long getMobileRadioApWakeupCount(int which); |
| 590 | |
| 591 | /** |
| 592 | * Returns the number of times this UID woke up the Application Processor to |
| 593 | * process a WiFi packet. |
| 594 | * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT. |
| 595 | */ |
| 596 | public abstract long getWifiRadioApWakeupCount(int which); |
| 597 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 598 | public static abstract class Sensor { |
Mathias Agopian | 7f84c06 | 2013-02-04 19:22:47 -0800 | [diff] [blame] | 599 | /* |
| 600 | * FIXME: it's not correct to use this magic value because it |
| 601 | * could clash with a sensor handle (which are defined by |
| 602 | * the sensor HAL, and therefore out of our control |
| 603 | */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 604 | // Magic sensor number for the GPS. |
| 605 | public static final int GPS = -10000; |
Amith Yamasani | ab9ad19 | 2016-12-06 12:46:59 -0800 | [diff] [blame^] | 606 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 607 | public abstract int getHandle(); |
Amith Yamasani | ab9ad19 | 2016-12-06 12:46:59 -0800 | [diff] [blame^] | 608 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 609 | public abstract Timer getSensorTime(); |
Amith Yamasani | ab9ad19 | 2016-12-06 12:46:59 -0800 | [diff] [blame^] | 610 | |
| 611 | /** Returns a counter for usage count when in the background. */ |
| 612 | public abstract Counter getSensorBgCount(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 613 | } |
| 614 | |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 615 | public class Pid { |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 616 | public int mWakeNesting; |
| 617 | public long mWakeSumMs; |
| 618 | public long mWakeStartMs; |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 619 | } |
| 620 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 621 | /** |
| 622 | * The statistics associated with a particular process. |
| 623 | */ |
| 624 | public static abstract class Proc { |
| 625 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 626 | public static class ExcessivePower { |
| 627 | public static final int TYPE_WAKE = 1; |
| 628 | public static final int TYPE_CPU = 2; |
| 629 | |
| 630 | public int type; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 631 | public long overTime; |
| 632 | public long usedTime; |
| 633 | } |
| 634 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 635 | /** |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 636 | * Returns true if this process is still active in the battery stats. |
| 637 | */ |
| 638 | public abstract boolean isActive(); |
| 639 | |
| 640 | /** |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 641 | * 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] | 642 | * |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 643 | * @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] | 644 | */ |
| 645 | public abstract long getUserTime(int which); |
| 646 | |
| 647 | /** |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 648 | * 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] | 649 | * |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 650 | * @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] | 651 | */ |
| 652 | public abstract long getSystemTime(int which); |
| 653 | |
| 654 | /** |
| 655 | * Returns the number of times the process has been started. |
| 656 | * |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 657 | * @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] | 658 | */ |
| 659 | public abstract int getStarts(int which); |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 660 | |
| 661 | /** |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 662 | * Returns the number of times the process has crashed. |
| 663 | * |
| 664 | * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT. |
| 665 | */ |
| 666 | public abstract int getNumCrashes(int which); |
| 667 | |
| 668 | /** |
| 669 | * Returns the number of times the process has ANRed. |
| 670 | * |
| 671 | * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT. |
| 672 | */ |
| 673 | public abstract int getNumAnrs(int which); |
| 674 | |
| 675 | /** |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 676 | * 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] | 677 | * @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] | 678 | * @return foreground cpu time in microseconds |
| 679 | */ |
| 680 | public abstract long getForegroundTime(int which); |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 681 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 682 | public abstract int countExcessivePowers(); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 683 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 684 | public abstract ExcessivePower getExcessivePower(int i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 685 | } |
| 686 | |
| 687 | /** |
| 688 | * The statistics associated with a particular package. |
| 689 | */ |
| 690 | public static abstract class Pkg { |
| 691 | |
| 692 | /** |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 693 | * Returns information about all wakeup alarms that have been triggered for this |
| 694 | * package. The mapping keys are tag names for the alarms, the counter contains |
| 695 | * 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] | 696 | */ |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 697 | public abstract ArrayMap<String, ? extends Counter> getWakeupAlarmStats(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 698 | |
| 699 | /** |
| 700 | * Returns a mapping containing service statistics. |
| 701 | */ |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 702 | public abstract ArrayMap<String, ? extends Serv> getServiceStats(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 703 | |
| 704 | /** |
| 705 | * The statistics associated with a particular service. |
| 706 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 707 | public static abstract class Serv { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 708 | |
| 709 | /** |
| 710 | * Returns the amount of time spent started. |
| 711 | * |
| 712 | * @param batteryUptime elapsed uptime on battery in microseconds. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 713 | * @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] | 714 | * @return |
| 715 | */ |
| 716 | public abstract long getStartTime(long batteryUptime, int which); |
| 717 | |
| 718 | /** |
| 719 | * Returns the total number of times startService() has been called. |
| 720 | * |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 721 | * @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] | 722 | */ |
| 723 | public abstract int getStarts(int which); |
| 724 | |
| 725 | /** |
| 726 | * Returns the total number times the service has been launched. |
| 727 | * |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 728 | * @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] | 729 | */ |
| 730 | public abstract int getLaunches(int which); |
| 731 | } |
| 732 | } |
| 733 | } |
| 734 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 735 | public static final class LevelStepTracker { |
| 736 | public long mLastStepTime = -1; |
| 737 | public int mNumStepDurations; |
| 738 | public final long[] mStepDurations; |
| 739 | |
| 740 | public LevelStepTracker(int maxLevelSteps) { |
| 741 | mStepDurations = new long[maxLevelSteps]; |
| 742 | } |
| 743 | |
| 744 | public LevelStepTracker(int numSteps, long[] steps) { |
| 745 | mNumStepDurations = numSteps; |
| 746 | mStepDurations = new long[numSteps]; |
| 747 | System.arraycopy(steps, 0, mStepDurations, 0, numSteps); |
| 748 | } |
| 749 | |
| 750 | public long getDurationAt(int index) { |
| 751 | return mStepDurations[index] & STEP_LEVEL_TIME_MASK; |
| 752 | } |
| 753 | |
| 754 | public int getLevelAt(int index) { |
| 755 | return (int)((mStepDurations[index] & STEP_LEVEL_LEVEL_MASK) |
| 756 | >> STEP_LEVEL_LEVEL_SHIFT); |
| 757 | } |
| 758 | |
| 759 | public int getInitModeAt(int index) { |
| 760 | return (int)((mStepDurations[index] & STEP_LEVEL_INITIAL_MODE_MASK) |
| 761 | >> STEP_LEVEL_INITIAL_MODE_SHIFT); |
| 762 | } |
| 763 | |
| 764 | public int getModModeAt(int index) { |
| 765 | return (int)((mStepDurations[index] & STEP_LEVEL_MODIFIED_MODE_MASK) |
| 766 | >> STEP_LEVEL_MODIFIED_MODE_SHIFT); |
| 767 | } |
| 768 | |
| 769 | private void appendHex(long val, int topOffset, StringBuilder out) { |
| 770 | boolean hasData = false; |
| 771 | while (topOffset >= 0) { |
| 772 | int digit = (int)( (val>>topOffset) & 0xf ); |
| 773 | topOffset -= 4; |
| 774 | if (!hasData && digit == 0) { |
| 775 | continue; |
| 776 | } |
| 777 | hasData = true; |
| 778 | if (digit >= 0 && digit <= 9) { |
| 779 | out.append((char)('0' + digit)); |
| 780 | } else { |
| 781 | out.append((char)('a' + digit - 10)); |
| 782 | } |
| 783 | } |
| 784 | } |
| 785 | |
| 786 | public void encodeEntryAt(int index, StringBuilder out) { |
| 787 | long item = mStepDurations[index]; |
| 788 | long duration = item & STEP_LEVEL_TIME_MASK; |
| 789 | int level = (int)((item & STEP_LEVEL_LEVEL_MASK) |
| 790 | >> STEP_LEVEL_LEVEL_SHIFT); |
| 791 | int initMode = (int)((item & STEP_LEVEL_INITIAL_MODE_MASK) |
| 792 | >> STEP_LEVEL_INITIAL_MODE_SHIFT); |
| 793 | int modMode = (int)((item & STEP_LEVEL_MODIFIED_MODE_MASK) |
| 794 | >> STEP_LEVEL_MODIFIED_MODE_SHIFT); |
| 795 | switch ((initMode&STEP_LEVEL_MODE_SCREEN_STATE) + 1) { |
| 796 | case Display.STATE_OFF: out.append('f'); break; |
| 797 | case Display.STATE_ON: out.append('o'); break; |
| 798 | case Display.STATE_DOZE: out.append('d'); break; |
| 799 | case Display.STATE_DOZE_SUSPEND: out.append('z'); break; |
| 800 | } |
| 801 | if ((initMode&STEP_LEVEL_MODE_POWER_SAVE) != 0) { |
| 802 | out.append('p'); |
| 803 | } |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 804 | if ((initMode&STEP_LEVEL_MODE_DEVICE_IDLE) != 0) { |
| 805 | out.append('i'); |
| 806 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 807 | switch ((modMode&STEP_LEVEL_MODE_SCREEN_STATE) + 1) { |
| 808 | case Display.STATE_OFF: out.append('F'); break; |
| 809 | case Display.STATE_ON: out.append('O'); break; |
| 810 | case Display.STATE_DOZE: out.append('D'); break; |
| 811 | case Display.STATE_DOZE_SUSPEND: out.append('Z'); break; |
| 812 | } |
| 813 | if ((modMode&STEP_LEVEL_MODE_POWER_SAVE) != 0) { |
| 814 | out.append('P'); |
| 815 | } |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 816 | if ((modMode&STEP_LEVEL_MODE_DEVICE_IDLE) != 0) { |
| 817 | out.append('I'); |
| 818 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 819 | out.append('-'); |
| 820 | appendHex(level, 4, out); |
| 821 | out.append('-'); |
| 822 | appendHex(duration, STEP_LEVEL_LEVEL_SHIFT-4, out); |
| 823 | } |
| 824 | |
| 825 | public void decodeEntryAt(int index, String value) { |
| 826 | final int N = value.length(); |
| 827 | int i = 0; |
| 828 | char c; |
| 829 | long out = 0; |
| 830 | while (i < N && (c=value.charAt(i)) != '-') { |
| 831 | i++; |
| 832 | switch (c) { |
Dianne Hackborn | 8cfb58b | 2015-03-04 13:28:36 -0800 | [diff] [blame] | 833 | 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] | 834 | break; |
Dianne Hackborn | 8cfb58b | 2015-03-04 13:28:36 -0800 | [diff] [blame] | 835 | 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] | 836 | break; |
Dianne Hackborn | 8cfb58b | 2015-03-04 13:28:36 -0800 | [diff] [blame] | 837 | 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] | 838 | break; |
Dianne Hackborn | 8cfb58b | 2015-03-04 13:28:36 -0800 | [diff] [blame] | 839 | case 'z': out |= (((long)Display.STATE_DOZE_SUSPEND-1) |
| 840 | << STEP_LEVEL_INITIAL_MODE_SHIFT); |
| 841 | break; |
| 842 | case 'p': out |= (((long)STEP_LEVEL_MODE_POWER_SAVE) |
| 843 | << STEP_LEVEL_INITIAL_MODE_SHIFT); |
| 844 | break; |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 845 | case 'i': out |= (((long)STEP_LEVEL_MODE_DEVICE_IDLE) |
| 846 | << STEP_LEVEL_INITIAL_MODE_SHIFT); |
| 847 | break; |
Dianne Hackborn | 8cfb58b | 2015-03-04 13:28:36 -0800 | [diff] [blame] | 848 | case 'F': out |= (((long)Display.STATE_OFF-1)<<STEP_LEVEL_MODIFIED_MODE_SHIFT); |
| 849 | break; |
| 850 | case 'O': out |= (((long)Display.STATE_ON-1)<<STEP_LEVEL_MODIFIED_MODE_SHIFT); |
| 851 | break; |
| 852 | case 'D': out |= (((long)Display.STATE_DOZE-1)<<STEP_LEVEL_MODIFIED_MODE_SHIFT); |
| 853 | break; |
| 854 | case 'Z': out |= (((long)Display.STATE_DOZE_SUSPEND-1) |
| 855 | << STEP_LEVEL_MODIFIED_MODE_SHIFT); |
| 856 | break; |
| 857 | case 'P': out |= (((long)STEP_LEVEL_MODE_POWER_SAVE) |
| 858 | << STEP_LEVEL_MODIFIED_MODE_SHIFT); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 859 | break; |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 860 | case 'I': out |= (((long)STEP_LEVEL_MODE_DEVICE_IDLE) |
| 861 | << STEP_LEVEL_MODIFIED_MODE_SHIFT); |
| 862 | break; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 863 | } |
| 864 | } |
| 865 | i++; |
Dianne Hackborn | 8cfb58b | 2015-03-04 13:28:36 -0800 | [diff] [blame] | 866 | long level = 0; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 867 | while (i < N && (c=value.charAt(i)) != '-') { |
| 868 | i++; |
| 869 | level <<= 4; |
| 870 | if (c >= '0' && c <= '9') { |
| 871 | level += c - '0'; |
| 872 | } else if (c >= 'a' && c <= 'f') { |
| 873 | level += c - 'a' + 10; |
| 874 | } else if (c >= 'A' && c <= 'F') { |
| 875 | level += c - 'A' + 10; |
| 876 | } |
| 877 | } |
Dianne Hackborn | 8cfb58b | 2015-03-04 13:28:36 -0800 | [diff] [blame] | 878 | i++; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 879 | out |= (level << STEP_LEVEL_LEVEL_SHIFT) & STEP_LEVEL_LEVEL_MASK; |
| 880 | long duration = 0; |
| 881 | while (i < N && (c=value.charAt(i)) != '-') { |
| 882 | i++; |
| 883 | duration <<= 4; |
| 884 | if (c >= '0' && c <= '9') { |
| 885 | duration += c - '0'; |
| 886 | } else if (c >= 'a' && c <= 'f') { |
| 887 | duration += c - 'a' + 10; |
| 888 | } else if (c >= 'A' && c <= 'F') { |
| 889 | duration += c - 'A' + 10; |
| 890 | } |
| 891 | } |
| 892 | mStepDurations[index] = out | (duration & STEP_LEVEL_TIME_MASK); |
| 893 | } |
| 894 | |
| 895 | public void init() { |
| 896 | mLastStepTime = -1; |
| 897 | mNumStepDurations = 0; |
| 898 | } |
| 899 | |
| 900 | public void clearTime() { |
| 901 | mLastStepTime = -1; |
| 902 | } |
| 903 | |
| 904 | public long computeTimePerLevel() { |
| 905 | final long[] steps = mStepDurations; |
| 906 | final int numSteps = mNumStepDurations; |
| 907 | |
| 908 | // For now we'll do a simple average across all steps. |
| 909 | if (numSteps <= 0) { |
| 910 | return -1; |
| 911 | } |
| 912 | long total = 0; |
| 913 | for (int i=0; i<numSteps; i++) { |
| 914 | total += steps[i] & STEP_LEVEL_TIME_MASK; |
| 915 | } |
| 916 | return total / numSteps; |
| 917 | /* |
| 918 | long[] buckets = new long[numSteps]; |
| 919 | int numBuckets = 0; |
| 920 | int numToAverage = 4; |
| 921 | int i = 0; |
| 922 | while (i < numSteps) { |
| 923 | long totalTime = 0; |
| 924 | int num = 0; |
| 925 | for (int j=0; j<numToAverage && (i+j)<numSteps; j++) { |
| 926 | totalTime += steps[i+j] & STEP_LEVEL_TIME_MASK; |
| 927 | num++; |
| 928 | } |
| 929 | buckets[numBuckets] = totalTime / num; |
| 930 | numBuckets++; |
| 931 | numToAverage *= 2; |
| 932 | i += num; |
| 933 | } |
| 934 | if (numBuckets < 1) { |
| 935 | return -1; |
| 936 | } |
| 937 | long averageTime = buckets[numBuckets-1]; |
| 938 | for (i=numBuckets-2; i>=0; i--) { |
| 939 | averageTime = (averageTime + buckets[i]) / 2; |
| 940 | } |
| 941 | return averageTime; |
| 942 | */ |
| 943 | } |
| 944 | |
| 945 | public long computeTimeEstimate(long modesOfInterest, long modeValues, |
| 946 | int[] outNumOfInterest) { |
| 947 | final long[] steps = mStepDurations; |
| 948 | final int count = mNumStepDurations; |
| 949 | if (count <= 0) { |
| 950 | return -1; |
| 951 | } |
| 952 | long total = 0; |
| 953 | int numOfInterest = 0; |
| 954 | for (int i=0; i<count; i++) { |
| 955 | long initMode = (steps[i] & STEP_LEVEL_INITIAL_MODE_MASK) |
| 956 | >> STEP_LEVEL_INITIAL_MODE_SHIFT; |
| 957 | long modMode = (steps[i] & STEP_LEVEL_MODIFIED_MODE_MASK) |
| 958 | >> STEP_LEVEL_MODIFIED_MODE_SHIFT; |
| 959 | // If the modes of interest didn't change during this step period... |
| 960 | if ((modMode&modesOfInterest) == 0) { |
| 961 | // And the mode values during this period match those we are measuring... |
| 962 | if ((initMode&modesOfInterest) == modeValues) { |
| 963 | // Then this can be used to estimate the total time! |
| 964 | numOfInterest++; |
| 965 | total += steps[i] & STEP_LEVEL_TIME_MASK; |
| 966 | } |
| 967 | } |
| 968 | } |
| 969 | if (numOfInterest <= 0) { |
| 970 | return -1; |
| 971 | } |
| 972 | |
| 973 | if (outNumOfInterest != null) { |
| 974 | outNumOfInterest[0] = numOfInterest; |
| 975 | } |
| 976 | |
| 977 | // The estimated time is the average time we spend in each level, multipled |
| 978 | // by 100 -- the total number of battery levels |
| 979 | return (total / numOfInterest) * 100; |
| 980 | } |
| 981 | |
| 982 | public void addLevelSteps(int numStepLevels, long modeBits, long elapsedRealtime) { |
| 983 | int stepCount = mNumStepDurations; |
| 984 | final long lastStepTime = mLastStepTime; |
| 985 | if (lastStepTime >= 0 && numStepLevels > 0) { |
| 986 | final long[] steps = mStepDurations; |
| 987 | long duration = elapsedRealtime - lastStepTime; |
| 988 | for (int i=0; i<numStepLevels; i++) { |
| 989 | System.arraycopy(steps, 0, steps, 1, steps.length-1); |
| 990 | long thisDuration = duration / (numStepLevels-i); |
| 991 | duration -= thisDuration; |
| 992 | if (thisDuration > STEP_LEVEL_TIME_MASK) { |
| 993 | thisDuration = STEP_LEVEL_TIME_MASK; |
| 994 | } |
| 995 | steps[0] = thisDuration | modeBits; |
| 996 | } |
| 997 | stepCount += numStepLevels; |
| 998 | if (stepCount > steps.length) { |
| 999 | stepCount = steps.length; |
| 1000 | } |
| 1001 | } |
| 1002 | mNumStepDurations = stepCount; |
| 1003 | mLastStepTime = elapsedRealtime; |
| 1004 | } |
| 1005 | |
| 1006 | public void readFromParcel(Parcel in) { |
| 1007 | final int N = in.readInt(); |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 1008 | if (N > mStepDurations.length) { |
| 1009 | throw new ParcelFormatException("more step durations than available: " + N); |
| 1010 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 1011 | mNumStepDurations = N; |
| 1012 | for (int i=0; i<N; i++) { |
| 1013 | mStepDurations[i] = in.readLong(); |
| 1014 | } |
| 1015 | } |
| 1016 | |
| 1017 | public void writeToParcel(Parcel out) { |
| 1018 | final int N = mNumStepDurations; |
| 1019 | out.writeInt(N); |
| 1020 | for (int i=0; i<N; i++) { |
| 1021 | out.writeLong(mStepDurations[i]); |
| 1022 | } |
| 1023 | } |
| 1024 | } |
| 1025 | |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 1026 | public static final class PackageChange { |
| 1027 | public String mPackageName; |
| 1028 | public boolean mUpdate; |
| 1029 | public int mVersionCode; |
| 1030 | } |
| 1031 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 1032 | public static final class DailyItem { |
| 1033 | public long mStartTime; |
| 1034 | public long mEndTime; |
| 1035 | public LevelStepTracker mDischargeSteps; |
| 1036 | public LevelStepTracker mChargeSteps; |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 1037 | public ArrayList<PackageChange> mPackageChanges; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 1038 | } |
| 1039 | |
| 1040 | public abstract DailyItem getDailyItemLocked(int daysAgo); |
| 1041 | |
| 1042 | public abstract long getCurrentDailyStartTime(); |
| 1043 | |
| 1044 | public abstract long getNextMinDailyDeadline(); |
| 1045 | |
| 1046 | public abstract long getNextMaxDailyDeadline(); |
| 1047 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1048 | public final static class HistoryTag { |
| 1049 | public String string; |
| 1050 | public int uid; |
| 1051 | |
| 1052 | public int poolIdx; |
| 1053 | |
| 1054 | public void setTo(HistoryTag o) { |
| 1055 | string = o.string; |
| 1056 | uid = o.uid; |
| 1057 | poolIdx = o.poolIdx; |
| 1058 | } |
| 1059 | |
| 1060 | public void setTo(String _string, int _uid) { |
| 1061 | string = _string; |
| 1062 | uid = _uid; |
| 1063 | poolIdx = -1; |
| 1064 | } |
| 1065 | |
| 1066 | public void writeToParcel(Parcel dest, int flags) { |
| 1067 | dest.writeString(string); |
| 1068 | dest.writeInt(uid); |
| 1069 | } |
| 1070 | |
| 1071 | public void readFromParcel(Parcel src) { |
| 1072 | string = src.readString(); |
| 1073 | uid = src.readInt(); |
| 1074 | poolIdx = -1; |
| 1075 | } |
| 1076 | |
| 1077 | @Override |
| 1078 | public boolean equals(Object o) { |
| 1079 | if (this == o) return true; |
| 1080 | if (o == null || getClass() != o.getClass()) return false; |
| 1081 | |
| 1082 | HistoryTag that = (HistoryTag) o; |
| 1083 | |
| 1084 | if (uid != that.uid) return false; |
| 1085 | if (!string.equals(that.string)) return false; |
| 1086 | |
| 1087 | return true; |
| 1088 | } |
| 1089 | |
| 1090 | @Override |
| 1091 | public int hashCode() { |
| 1092 | int result = string.hashCode(); |
| 1093 | result = 31 * result + uid; |
| 1094 | return result; |
| 1095 | } |
| 1096 | } |
| 1097 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 1098 | /** |
| 1099 | * Optional detailed information that can go into a history step. This is typically |
| 1100 | * generated each time the battery level changes. |
| 1101 | */ |
| 1102 | public final static class HistoryStepDetails { |
| 1103 | // Time (in 1/100 second) spent in user space and the kernel since the last step. |
| 1104 | public int userTime; |
| 1105 | public int systemTime; |
| 1106 | |
| 1107 | // Top three apps using CPU in the last step, with times in 1/100 second. |
| 1108 | public int appCpuUid1; |
| 1109 | public int appCpuUTime1; |
| 1110 | public int appCpuSTime1; |
| 1111 | public int appCpuUid2; |
| 1112 | public int appCpuUTime2; |
| 1113 | public int appCpuSTime2; |
| 1114 | public int appCpuUid3; |
| 1115 | public int appCpuUTime3; |
| 1116 | public int appCpuSTime3; |
| 1117 | |
| 1118 | // Information from /proc/stat |
| 1119 | public int statUserTime; |
| 1120 | public int statSystemTime; |
| 1121 | public int statIOWaitTime; |
| 1122 | public int statIrqTime; |
| 1123 | public int statSoftIrqTime; |
| 1124 | public int statIdlTime; |
| 1125 | |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 1126 | // Platform-level low power state stats |
| 1127 | public String statPlatformIdleState; |
| 1128 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 1129 | public HistoryStepDetails() { |
| 1130 | clear(); |
| 1131 | } |
| 1132 | |
| 1133 | public void clear() { |
| 1134 | userTime = systemTime = 0; |
| 1135 | appCpuUid1 = appCpuUid2 = appCpuUid3 = -1; |
| 1136 | appCpuUTime1 = appCpuSTime1 = appCpuUTime2 = appCpuSTime2 |
| 1137 | = appCpuUTime3 = appCpuSTime3 = 0; |
| 1138 | } |
| 1139 | |
| 1140 | public void writeToParcel(Parcel out) { |
| 1141 | out.writeInt(userTime); |
| 1142 | out.writeInt(systemTime); |
| 1143 | out.writeInt(appCpuUid1); |
| 1144 | out.writeInt(appCpuUTime1); |
| 1145 | out.writeInt(appCpuSTime1); |
| 1146 | out.writeInt(appCpuUid2); |
| 1147 | out.writeInt(appCpuUTime2); |
| 1148 | out.writeInt(appCpuSTime2); |
| 1149 | out.writeInt(appCpuUid3); |
| 1150 | out.writeInt(appCpuUTime3); |
| 1151 | out.writeInt(appCpuSTime3); |
| 1152 | out.writeInt(statUserTime); |
| 1153 | out.writeInt(statSystemTime); |
| 1154 | out.writeInt(statIOWaitTime); |
| 1155 | out.writeInt(statIrqTime); |
| 1156 | out.writeInt(statSoftIrqTime); |
| 1157 | out.writeInt(statIdlTime); |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 1158 | out.writeString(statPlatformIdleState); |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 1159 | } |
| 1160 | |
| 1161 | public void readFromParcel(Parcel in) { |
| 1162 | userTime = in.readInt(); |
| 1163 | systemTime = in.readInt(); |
| 1164 | appCpuUid1 = in.readInt(); |
| 1165 | appCpuUTime1 = in.readInt(); |
| 1166 | appCpuSTime1 = in.readInt(); |
| 1167 | appCpuUid2 = in.readInt(); |
| 1168 | appCpuUTime2 = in.readInt(); |
| 1169 | appCpuSTime2 = in.readInt(); |
| 1170 | appCpuUid3 = in.readInt(); |
| 1171 | appCpuUTime3 = in.readInt(); |
| 1172 | appCpuSTime3 = in.readInt(); |
| 1173 | statUserTime = in.readInt(); |
| 1174 | statSystemTime = in.readInt(); |
| 1175 | statIOWaitTime = in.readInt(); |
| 1176 | statIrqTime = in.readInt(); |
| 1177 | statSoftIrqTime = in.readInt(); |
| 1178 | statIdlTime = in.readInt(); |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 1179 | statPlatformIdleState = in.readString(); |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 1180 | } |
| 1181 | } |
| 1182 | |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 1183 | public final static class HistoryItem implements Parcelable { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1184 | public HistoryItem next; |
Dianne Hackborn | 9a75543 | 2014-05-15 17:05:22 -0700 | [diff] [blame] | 1185 | |
| 1186 | // The time of this event in milliseconds, as per SystemClock.elapsedRealtime(). |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1187 | public long time; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1188 | |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 1189 | 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] | 1190 | public static final byte CMD_NULL = -1; |
| 1191 | public static final byte CMD_START = 4; |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1192 | public static final byte CMD_CURRENT_TIME = 5; |
| 1193 | public static final byte CMD_OVERFLOW = 6; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 1194 | public static final byte CMD_RESET = 7; |
Dianne Hackborn | 29cd7f1 | 2015-01-08 10:37:05 -0800 | [diff] [blame] | 1195 | public static final byte CMD_SHUTDOWN = 8; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1196 | |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 1197 | public byte cmd = CMD_NULL; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1198 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1199 | /** |
| 1200 | * Return whether the command code is a delta data update. |
| 1201 | */ |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1202 | public boolean isDeltaData() { |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 1203 | return cmd == CMD_UPDATE; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1204 | } |
| 1205 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1206 | public byte batteryLevel; |
| 1207 | public byte batteryStatus; |
| 1208 | public byte batteryHealth; |
| 1209 | public byte batteryPlugType; |
| 1210 | |
Sungmin Choi | c7e9e8b | 2013-01-16 12:57:36 +0900 | [diff] [blame] | 1211 | public short batteryTemperature; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1212 | public char batteryVoltage; |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 1213 | |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 1214 | // The charge of the battery in micro-Ampere-hours. |
| 1215 | public int batteryChargeUAh; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1216 | |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 1217 | // Constants from SCREEN_BRIGHTNESS_* |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1218 | public static final int STATE_BRIGHTNESS_SHIFT = 0; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1219 | public static final int STATE_BRIGHTNESS_MASK = 0x7; |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 1220 | // Constants from SIGNAL_STRENGTH_* |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 1221 | public static final int STATE_PHONE_SIGNAL_STRENGTH_SHIFT = 3; |
| 1222 | 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] | 1223 | // Constants from ServiceState.STATE_* |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1224 | public static final int STATE_PHONE_STATE_SHIFT = 6; |
| 1225 | 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] | 1226 | // Constants from DATA_CONNECTION_* |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1227 | public static final int STATE_DATA_CONNECTION_SHIFT = 9; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1228 | 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] | 1229 | |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 1230 | // These states always appear directly in the first int token |
| 1231 | // of a delta change; they should be ones that change relatively |
| 1232 | // frequently. |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1233 | public static final int STATE_CPU_RUNNING_FLAG = 1<<31; |
| 1234 | public static final int STATE_WAKE_LOCK_FLAG = 1<<30; |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 1235 | public static final int STATE_GPS_ON_FLAG = 1<<29; |
| 1236 | public static final int STATE_WIFI_FULL_LOCK_FLAG = 1<<28; |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 1237 | public static final int STATE_WIFI_SCAN_FLAG = 1<<27; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 1238 | public static final int STATE_WIFI_RADIO_ACTIVE_FLAG = 1<<26; |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 1239 | public static final int STATE_MOBILE_RADIO_ACTIVE_FLAG = 1<<25; |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 1240 | // Do not use, this is used for coulomb delta count. |
| 1241 | private static final int STATE_RESERVED_0 = 1<<24; |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 1242 | // These are on the lower bits used for the command; if they change |
| 1243 | // we need to write another int of data. |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1244 | public static final int STATE_SENSOR_ON_FLAG = 1<<23; |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 1245 | public static final int STATE_AUDIO_ON_FLAG = 1<<22; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1246 | public static final int STATE_PHONE_SCANNING_FLAG = 1<<21; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 1247 | public static final int STATE_SCREEN_ON_FLAG = 1<<20; // consider moving to states2 |
| 1248 | public static final int STATE_BATTERY_PLUGGED_FLAG = 1<<19; // consider moving to states2 |
| 1249 | // empty slot |
| 1250 | // empty slot |
| 1251 | public static final int STATE_WIFI_MULTICAST_ON_FLAG = 1<<16; |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 1252 | |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 1253 | public static final int MOST_INTERESTING_STATES = |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 1254 | STATE_BATTERY_PLUGGED_FLAG | STATE_SCREEN_ON_FLAG; |
| 1255 | |
| 1256 | public static final int SETTLE_TO_ZERO_STATES = 0xffff0000 & ~MOST_INTERESTING_STATES; |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 1257 | |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1258 | public int states; |
| 1259 | |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 1260 | // Constants from WIFI_SUPPL_STATE_* |
| 1261 | public static final int STATE2_WIFI_SUPPL_STATE_SHIFT = 0; |
| 1262 | public static final int STATE2_WIFI_SUPPL_STATE_MASK = 0xf; |
| 1263 | // Values for NUM_WIFI_SIGNAL_STRENGTH_BINS |
| 1264 | public static final int STATE2_WIFI_SIGNAL_STRENGTH_SHIFT = 4; |
| 1265 | public static final int STATE2_WIFI_SIGNAL_STRENGTH_MASK = |
| 1266 | 0x7 << STATE2_WIFI_SIGNAL_STRENGTH_SHIFT; |
| 1267 | |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 1268 | public static final int STATE2_POWER_SAVE_FLAG = 1<<31; |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 1269 | public static final int STATE2_VIDEO_ON_FLAG = 1<<30; |
| 1270 | public static final int STATE2_WIFI_RUNNING_FLAG = 1<<29; |
| 1271 | public static final int STATE2_WIFI_ON_FLAG = 1<<28; |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 1272 | public static final int STATE2_FLASHLIGHT_FLAG = 1<<27; |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 1273 | public static final int STATE2_DEVICE_IDLE_SHIFT = 25; |
| 1274 | public static final int STATE2_DEVICE_IDLE_MASK = 0x3 << STATE2_DEVICE_IDLE_SHIFT; |
| 1275 | public static final int STATE2_CHARGING_FLAG = 1<<24; |
| 1276 | public static final int STATE2_PHONE_IN_CALL_FLAG = 1<<23; |
| 1277 | public static final int STATE2_BLUETOOTH_ON_FLAG = 1<<22; |
| 1278 | public static final int STATE2_CAMERA_FLAG = 1<<21; |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 1279 | public static final int STATE2_BLUETOOTH_SCAN_FLAG = 1 << 20; |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 1280 | |
| 1281 | public static final int MOST_INTERESTING_STATES2 = |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 1282 | STATE2_POWER_SAVE_FLAG | STATE2_WIFI_ON_FLAG | STATE2_DEVICE_IDLE_MASK |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 1283 | | STATE2_CHARGING_FLAG | STATE2_PHONE_IN_CALL_FLAG | STATE2_BLUETOOTH_ON_FLAG; |
| 1284 | |
| 1285 | public static final int SETTLE_TO_ZERO_STATES2 = 0xffff0000 & ~MOST_INTERESTING_STATES2; |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 1286 | |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 1287 | public int states2; |
| 1288 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1289 | // The wake lock that was acquired at this point. |
| 1290 | public HistoryTag wakelockTag; |
| 1291 | |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1292 | // Kernel wakeup reason at this point. |
| 1293 | public HistoryTag wakeReasonTag; |
| 1294 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 1295 | // Non-null when there is more detailed information at this step. |
| 1296 | public HistoryStepDetails stepDetails; |
| 1297 | |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 1298 | public static final int EVENT_FLAG_START = 0x8000; |
| 1299 | public static final int EVENT_FLAG_FINISH = 0x4000; |
| 1300 | |
| 1301 | // No event in this item. |
| 1302 | public static final int EVENT_NONE = 0x0000; |
| 1303 | // Event is about a process that is running. |
| 1304 | public static final int EVENT_PROC = 0x0001; |
| 1305 | // Event is about an application package that is in the foreground. |
| 1306 | public static final int EVENT_FOREGROUND = 0x0002; |
| 1307 | // Event is about an application package that is at the top of the screen. |
| 1308 | public static final int EVENT_TOP = 0x0003; |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 1309 | // Event is about active sync operations. |
Dianne Hackborn | a1f1a3c | 2014-02-24 18:12:28 -0800 | [diff] [blame] | 1310 | public static final int EVENT_SYNC = 0x0004; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 1311 | // Events for all additional wake locks aquired/release within a wake block. |
| 1312 | // These are not generated by default. |
| 1313 | public static final int EVENT_WAKE_LOCK = 0x0005; |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 1314 | // Event is about an application executing a scheduled job. |
| 1315 | public static final int EVENT_JOB = 0x0006; |
| 1316 | // Events for users running. |
| 1317 | public static final int EVENT_USER_RUNNING = 0x0007; |
| 1318 | // Events for foreground user. |
| 1319 | public static final int EVENT_USER_FOREGROUND = 0x0008; |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 1320 | // Event for connectivity changed. |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 1321 | public static final int EVENT_CONNECTIVITY_CHANGED = 0x0009; |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 1322 | // Event for becoming active taking us out of idle mode. |
Dianne Hackborn | b6683c4 | 2015-06-18 17:40:33 -0700 | [diff] [blame] | 1323 | public static final int EVENT_ACTIVE = 0x000a; |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 1324 | // Event for a package being installed. |
Dianne Hackborn | b6683c4 | 2015-06-18 17:40:33 -0700 | [diff] [blame] | 1325 | public static final int EVENT_PACKAGE_INSTALLED = 0x000b; |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 1326 | // Event for a package being uninstalled. |
Dianne Hackborn | b6683c4 | 2015-06-18 17:40:33 -0700 | [diff] [blame] | 1327 | public static final int EVENT_PACKAGE_UNINSTALLED = 0x000c; |
Dianne Hackborn | 1e38382 | 2015-04-10 14:02:33 -0700 | [diff] [blame] | 1328 | // Event for a package being uninstalled. |
Dianne Hackborn | b6683c4 | 2015-06-18 17:40:33 -0700 | [diff] [blame] | 1329 | public static final int EVENT_ALARM = 0x000d; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 1330 | // Record that we have decided we need to collect new stats data. |
Dianne Hackborn | b6683c4 | 2015-06-18 17:40:33 -0700 | [diff] [blame] | 1331 | public static final int EVENT_COLLECT_EXTERNAL_STATS = 0x000e; |
Amith Yamasani | 6776849 | 2015-06-09 12:23:58 -0700 | [diff] [blame] | 1332 | // 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] | 1333 | public static final int EVENT_PACKAGE_INACTIVE = 0x000f; |
Amith Yamasani | 6776849 | 2015-06-09 12:23:58 -0700 | [diff] [blame] | 1334 | // Event for a package becoming active due to an interaction. |
Dianne Hackborn | b6683c4 | 2015-06-18 17:40:33 -0700 | [diff] [blame] | 1335 | public static final int EVENT_PACKAGE_ACTIVE = 0x0010; |
Dianne Hackborn | fd854ee | 2015-07-13 18:00:37 -0700 | [diff] [blame] | 1336 | // Event for a package being on the temporary whitelist. |
| 1337 | public static final int EVENT_TEMP_WHITELIST = 0x0011; |
Dianne Hackborn | 280a64e | 2015-07-13 14:48:08 -0700 | [diff] [blame] | 1338 | // Event for the screen waking up. |
| 1339 | public static final int EVENT_SCREEN_WAKE_UP = 0x0012; |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 1340 | // Event for the UID that woke up the application processor. |
| 1341 | // Used for wakeups coming from WiFi, modem, etc. |
| 1342 | public static final int EVENT_WAKEUP_AP = 0x0013; |
Dianne Hackborn | d0db6f0 | 2016-07-18 14:14:20 -0700 | [diff] [blame] | 1343 | // Event for reporting that a specific partial wake lock has been held for a long duration. |
| 1344 | public static final int EVENT_LONG_WAKE_LOCK = 0x0014; |
Amith Yamasani | 6776849 | 2015-06-09 12:23:58 -0700 | [diff] [blame] | 1345 | |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 1346 | // Number of event types. |
Dianne Hackborn | d0db6f0 | 2016-07-18 14:14:20 -0700 | [diff] [blame] | 1347 | public static final int EVENT_COUNT = 0x0015; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 1348 | // Mask to extract out only the type part of the event. |
| 1349 | 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] | 1350 | |
| 1351 | public static final int EVENT_PROC_START = EVENT_PROC | EVENT_FLAG_START; |
| 1352 | public static final int EVENT_PROC_FINISH = EVENT_PROC | EVENT_FLAG_FINISH; |
| 1353 | public static final int EVENT_FOREGROUND_START = EVENT_FOREGROUND | EVENT_FLAG_START; |
| 1354 | public static final int EVENT_FOREGROUND_FINISH = EVENT_FOREGROUND | EVENT_FLAG_FINISH; |
| 1355 | public static final int EVENT_TOP_START = EVENT_TOP | EVENT_FLAG_START; |
| 1356 | public static final int EVENT_TOP_FINISH = EVENT_TOP | EVENT_FLAG_FINISH; |
Dianne Hackborn | a1f1a3c | 2014-02-24 18:12:28 -0800 | [diff] [blame] | 1357 | public static final int EVENT_SYNC_START = EVENT_SYNC | EVENT_FLAG_START; |
| 1358 | public static final int EVENT_SYNC_FINISH = EVENT_SYNC | EVENT_FLAG_FINISH; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 1359 | public static final int EVENT_WAKE_LOCK_START = EVENT_WAKE_LOCK | EVENT_FLAG_START; |
| 1360 | 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] | 1361 | public static final int EVENT_JOB_START = EVENT_JOB | EVENT_FLAG_START; |
| 1362 | public static final int EVENT_JOB_FINISH = EVENT_JOB | EVENT_FLAG_FINISH; |
| 1363 | public static final int EVENT_USER_RUNNING_START = EVENT_USER_RUNNING | EVENT_FLAG_START; |
| 1364 | public static final int EVENT_USER_RUNNING_FINISH = EVENT_USER_RUNNING | EVENT_FLAG_FINISH; |
| 1365 | public static final int EVENT_USER_FOREGROUND_START = |
| 1366 | EVENT_USER_FOREGROUND | EVENT_FLAG_START; |
| 1367 | public static final int EVENT_USER_FOREGROUND_FINISH = |
| 1368 | EVENT_USER_FOREGROUND | EVENT_FLAG_FINISH; |
Dianne Hackborn | 1e38382 | 2015-04-10 14:02:33 -0700 | [diff] [blame] | 1369 | public static final int EVENT_ALARM_START = EVENT_ALARM | EVENT_FLAG_START; |
| 1370 | public static final int EVENT_ALARM_FINISH = EVENT_ALARM | EVENT_FLAG_FINISH; |
Dianne Hackborn | fd854ee | 2015-07-13 18:00:37 -0700 | [diff] [blame] | 1371 | public static final int EVENT_TEMP_WHITELIST_START = |
| 1372 | EVENT_TEMP_WHITELIST | EVENT_FLAG_START; |
| 1373 | public static final int EVENT_TEMP_WHITELIST_FINISH = |
| 1374 | EVENT_TEMP_WHITELIST | EVENT_FLAG_FINISH; |
Dianne Hackborn | d0db6f0 | 2016-07-18 14:14:20 -0700 | [diff] [blame] | 1375 | public static final int EVENT_LONG_WAKE_LOCK_START = |
| 1376 | EVENT_LONG_WAKE_LOCK | EVENT_FLAG_START; |
| 1377 | public static final int EVENT_LONG_WAKE_LOCK_FINISH = |
| 1378 | EVENT_LONG_WAKE_LOCK | EVENT_FLAG_FINISH; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1379 | |
| 1380 | // For CMD_EVENT. |
| 1381 | public int eventCode; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1382 | public HistoryTag eventTag; |
| 1383 | |
Dianne Hackborn | 9a75543 | 2014-05-15 17:05:22 -0700 | [diff] [blame] | 1384 | // 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] | 1385 | public long currentTime; |
| 1386 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1387 | // Meta-data when reading. |
| 1388 | public int numReadInts; |
| 1389 | |
| 1390 | // Pre-allocated objects. |
| 1391 | public final HistoryTag localWakelockTag = new HistoryTag(); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1392 | public final HistoryTag localWakeReasonTag = new HistoryTag(); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1393 | public final HistoryTag localEventTag = new HistoryTag(); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1394 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1395 | public HistoryItem() { |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1396 | } |
| 1397 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1398 | public HistoryItem(long time, Parcel src) { |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1399 | this.time = time; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1400 | numReadInts = 2; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 1401 | readFromParcel(src); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1402 | } |
| 1403 | |
| 1404 | public int describeContents() { |
| 1405 | return 0; |
| 1406 | } |
| 1407 | |
| 1408 | public void writeToParcel(Parcel dest, int flags) { |
| 1409 | dest.writeLong(time); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1410 | int bat = (((int)cmd)&0xff) |
| 1411 | | ((((int)batteryLevel)<<8)&0xff00) |
| 1412 | | ((((int)batteryStatus)<<16)&0xf0000) |
| 1413 | | ((((int)batteryHealth)<<20)&0xf00000) |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1414 | | ((((int)batteryPlugType)<<24)&0xf000000) |
| 1415 | | (wakelockTag != null ? 0x10000000 : 0) |
| 1416 | | (wakeReasonTag != null ? 0x20000000 : 0) |
| 1417 | | (eventCode != EVENT_NONE ? 0x40000000 : 0); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1418 | dest.writeInt(bat); |
| 1419 | bat = (((int)batteryTemperature)&0xffff) |
| 1420 | | ((((int)batteryVoltage)<<16)&0xffff0000); |
| 1421 | dest.writeInt(bat); |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 1422 | dest.writeInt(batteryChargeUAh); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1423 | dest.writeInt(states); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1424 | dest.writeInt(states2); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1425 | if (wakelockTag != null) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1426 | wakelockTag.writeToParcel(dest, flags); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1427 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1428 | if (wakeReasonTag != null) { |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1429 | wakeReasonTag.writeToParcel(dest, flags); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1430 | } |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 1431 | if (eventCode != EVENT_NONE) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1432 | dest.writeInt(eventCode); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1433 | eventTag.writeToParcel(dest, flags); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1434 | } |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 1435 | if (cmd == CMD_CURRENT_TIME || cmd == CMD_RESET) { |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1436 | dest.writeLong(currentTime); |
| 1437 | } |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1438 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 1439 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1440 | public void readFromParcel(Parcel src) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1441 | int start = src.dataPosition(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 1442 | int bat = src.readInt(); |
| 1443 | cmd = (byte)(bat&0xff); |
| 1444 | batteryLevel = (byte)((bat>>8)&0xff); |
| 1445 | batteryStatus = (byte)((bat>>16)&0xf); |
| 1446 | batteryHealth = (byte)((bat>>20)&0xf); |
| 1447 | batteryPlugType = (byte)((bat>>24)&0xf); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1448 | int bat2 = src.readInt(); |
| 1449 | batteryTemperature = (short)(bat2&0xffff); |
| 1450 | batteryVoltage = (char)((bat2>>16)&0xffff); |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 1451 | batteryChargeUAh = src.readInt(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 1452 | states = src.readInt(); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1453 | states2 = src.readInt(); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1454 | if ((bat&0x10000000) != 0) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1455 | wakelockTag = localWakelockTag; |
| 1456 | wakelockTag.readFromParcel(src); |
| 1457 | } else { |
| 1458 | wakelockTag = null; |
| 1459 | } |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1460 | if ((bat&0x20000000) != 0) { |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1461 | wakeReasonTag = localWakeReasonTag; |
| 1462 | wakeReasonTag.readFromParcel(src); |
| 1463 | } else { |
| 1464 | wakeReasonTag = null; |
| 1465 | } |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1466 | if ((bat&0x40000000) != 0) { |
| 1467 | eventCode = src.readInt(); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1468 | eventTag = localEventTag; |
| 1469 | eventTag.readFromParcel(src); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1470 | } else { |
| 1471 | eventCode = EVENT_NONE; |
| 1472 | eventTag = null; |
| 1473 | } |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 1474 | if (cmd == CMD_CURRENT_TIME || cmd == CMD_RESET) { |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1475 | currentTime = src.readLong(); |
| 1476 | } else { |
| 1477 | currentTime = 0; |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 1478 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1479 | numReadInts += (src.dataPosition()-start)/4; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 1480 | } |
| 1481 | |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 1482 | public void clear() { |
| 1483 | time = 0; |
| 1484 | cmd = CMD_NULL; |
| 1485 | batteryLevel = 0; |
| 1486 | batteryStatus = 0; |
| 1487 | batteryHealth = 0; |
| 1488 | batteryPlugType = 0; |
| 1489 | batteryTemperature = 0; |
| 1490 | batteryVoltage = 0; |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 1491 | batteryChargeUAh = 0; |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 1492 | states = 0; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1493 | states2 = 0; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1494 | wakelockTag = null; |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1495 | wakeReasonTag = null; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1496 | eventCode = EVENT_NONE; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1497 | eventTag = null; |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 1498 | } |
| 1499 | |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 1500 | public void setTo(HistoryItem o) { |
| 1501 | time = o.time; |
| 1502 | cmd = o.cmd; |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 1503 | setToCommon(o); |
| 1504 | } |
| 1505 | |
| 1506 | public void setTo(long time, byte cmd, HistoryItem o) { |
| 1507 | this.time = time; |
| 1508 | this.cmd = cmd; |
| 1509 | setToCommon(o); |
| 1510 | } |
| 1511 | |
| 1512 | private void setToCommon(HistoryItem o) { |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 1513 | batteryLevel = o.batteryLevel; |
| 1514 | batteryStatus = o.batteryStatus; |
| 1515 | batteryHealth = o.batteryHealth; |
| 1516 | batteryPlugType = o.batteryPlugType; |
| 1517 | batteryTemperature = o.batteryTemperature; |
| 1518 | batteryVoltage = o.batteryVoltage; |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 1519 | batteryChargeUAh = o.batteryChargeUAh; |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 1520 | states = o.states; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1521 | states2 = o.states2; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1522 | if (o.wakelockTag != null) { |
| 1523 | wakelockTag = localWakelockTag; |
| 1524 | wakelockTag.setTo(o.wakelockTag); |
| 1525 | } else { |
| 1526 | wakelockTag = null; |
| 1527 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1528 | if (o.wakeReasonTag != null) { |
| 1529 | wakeReasonTag = localWakeReasonTag; |
| 1530 | wakeReasonTag.setTo(o.wakeReasonTag); |
| 1531 | } else { |
| 1532 | wakeReasonTag = null; |
| 1533 | } |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1534 | eventCode = o.eventCode; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1535 | if (o.eventTag != null) { |
| 1536 | eventTag = localEventTag; |
| 1537 | eventTag.setTo(o.eventTag); |
| 1538 | } else { |
| 1539 | eventTag = null; |
| 1540 | } |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1541 | currentTime = o.currentTime; |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 1542 | } |
| 1543 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1544 | public boolean sameNonEvent(HistoryItem o) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 1545 | return batteryLevel == o.batteryLevel |
| 1546 | && batteryStatus == o.batteryStatus |
| 1547 | && batteryHealth == o.batteryHealth |
| 1548 | && batteryPlugType == o.batteryPlugType |
| 1549 | && batteryTemperature == o.batteryTemperature |
| 1550 | && batteryVoltage == o.batteryVoltage |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 1551 | && batteryChargeUAh == o.batteryChargeUAh |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1552 | && states == o.states |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1553 | && states2 == o.states2 |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 1554 | && currentTime == o.currentTime; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 1555 | } |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1556 | |
| 1557 | public boolean same(HistoryItem o) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1558 | if (!sameNonEvent(o) || eventCode != o.eventCode) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1559 | return false; |
| 1560 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1561 | if (wakelockTag != o.wakelockTag) { |
| 1562 | if (wakelockTag == null || o.wakelockTag == null) { |
| 1563 | return false; |
| 1564 | } |
| 1565 | if (!wakelockTag.equals(o.wakelockTag)) { |
| 1566 | return false; |
| 1567 | } |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1568 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 1569 | if (wakeReasonTag != o.wakeReasonTag) { |
| 1570 | if (wakeReasonTag == null || o.wakeReasonTag == null) { |
| 1571 | return false; |
| 1572 | } |
| 1573 | if (!wakeReasonTag.equals(o.wakeReasonTag)) { |
| 1574 | return false; |
| 1575 | } |
| 1576 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1577 | if (eventTag != o.eventTag) { |
| 1578 | if (eventTag == null || o.eventTag == null) { |
| 1579 | return false; |
| 1580 | } |
| 1581 | if (!eventTag.equals(o.eventTag)) { |
| 1582 | return false; |
| 1583 | } |
| 1584 | } |
| 1585 | return true; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1586 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1587 | } |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 1588 | |
| 1589 | public final static class HistoryEventTracker { |
| 1590 | private final HashMap<String, SparseIntArray>[] mActiveEvents |
| 1591 | = (HashMap<String, SparseIntArray>[]) new HashMap[HistoryItem.EVENT_COUNT]; |
| 1592 | |
| 1593 | public boolean updateState(int code, String name, int uid, int poolIdx) { |
| 1594 | if ((code&HistoryItem.EVENT_FLAG_START) != 0) { |
| 1595 | int idx = code&HistoryItem.EVENT_TYPE_MASK; |
| 1596 | HashMap<String, SparseIntArray> active = mActiveEvents[idx]; |
| 1597 | if (active == null) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 1598 | active = new HashMap<>(); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 1599 | mActiveEvents[idx] = active; |
| 1600 | } |
| 1601 | SparseIntArray uids = active.get(name); |
| 1602 | if (uids == null) { |
| 1603 | uids = new SparseIntArray(); |
| 1604 | active.put(name, uids); |
| 1605 | } |
| 1606 | if (uids.indexOfKey(uid) >= 0) { |
| 1607 | // Already set, nothing to do! |
| 1608 | return false; |
| 1609 | } |
| 1610 | uids.put(uid, poolIdx); |
| 1611 | } else if ((code&HistoryItem.EVENT_FLAG_FINISH) != 0) { |
| 1612 | int idx = code&HistoryItem.EVENT_TYPE_MASK; |
| 1613 | HashMap<String, SparseIntArray> active = mActiveEvents[idx]; |
| 1614 | if (active == null) { |
| 1615 | // not currently active, nothing to do. |
| 1616 | return false; |
| 1617 | } |
| 1618 | SparseIntArray uids = active.get(name); |
| 1619 | if (uids == null) { |
| 1620 | // not currently active, nothing to do. |
| 1621 | return false; |
| 1622 | } |
| 1623 | idx = uids.indexOfKey(uid); |
| 1624 | if (idx < 0) { |
| 1625 | // not currently active, nothing to do. |
| 1626 | return false; |
| 1627 | } |
| 1628 | uids.removeAt(idx); |
| 1629 | if (uids.size() <= 0) { |
| 1630 | active.remove(name); |
| 1631 | } |
| 1632 | } |
| 1633 | return true; |
| 1634 | } |
| 1635 | |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 1636 | public void removeEvents(int code) { |
| 1637 | int idx = code&HistoryItem.EVENT_TYPE_MASK; |
| 1638 | mActiveEvents[idx] = null; |
| 1639 | } |
| 1640 | |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 1641 | public HashMap<String, SparseIntArray> getStateForEvent(int code) { |
| 1642 | return mActiveEvents[code]; |
| 1643 | } |
| 1644 | } |
| 1645 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1646 | public static final class BitDescription { |
| 1647 | public final int mask; |
| 1648 | public final int shift; |
| 1649 | public final String name; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1650 | public final String shortName; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1651 | public final String[] values; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1652 | public final String[] shortValues; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1653 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1654 | public BitDescription(int mask, String name, String shortName) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1655 | this.mask = mask; |
| 1656 | this.shift = -1; |
| 1657 | this.name = name; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1658 | this.shortName = shortName; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1659 | this.values = null; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1660 | this.shortValues = null; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1661 | } |
| 1662 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1663 | public BitDescription(int mask, int shift, String name, String shortName, |
| 1664 | String[] values, String[] shortValues) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1665 | this.mask = mask; |
| 1666 | this.shift = shift; |
| 1667 | this.name = name; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1668 | this.shortName = shortName; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1669 | this.values = values; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1670 | this.shortValues = shortValues; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1671 | } |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 1672 | } |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 1673 | |
Dianne Hackborn | fc06413 | 2014-06-02 12:42:12 -0700 | [diff] [blame] | 1674 | /** |
| 1675 | * Don't allow any more batching in to the current history event. This |
| 1676 | * is called when printing partial histories, so to ensure that the next |
| 1677 | * history event will go in to a new batch after what was printed in the |
| 1678 | * last partial history. |
| 1679 | */ |
| 1680 | public abstract void commitCurrentHistoryBatchLocked(); |
| 1681 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1682 | public abstract int getHistoryTotalSize(); |
| 1683 | |
| 1684 | public abstract int getHistoryUsedSize(); |
| 1685 | |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 1686 | public abstract boolean startIteratingHistoryLocked(); |
| 1687 | |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 1688 | public abstract int getHistoryStringPoolSize(); |
| 1689 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 1690 | public abstract int getHistoryStringPoolBytes(); |
| 1691 | |
| 1692 | public abstract String getHistoryTagPoolString(int index); |
| 1693 | |
| 1694 | public abstract int getHistoryTagPoolUid(int index); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 1695 | |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 1696 | public abstract boolean getNextHistoryLocked(HistoryItem out); |
| 1697 | |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 1698 | public abstract void finishIteratingHistoryLocked(); |
| 1699 | |
| 1700 | public abstract boolean startIteratingOldHistoryLocked(); |
| 1701 | |
| 1702 | public abstract boolean getNextOldHistoryLocked(HistoryItem out); |
| 1703 | |
| 1704 | public abstract void finishIteratingOldHistoryLocked(); |
| 1705 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1706 | /** |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 1707 | * Return the base time offset for the battery history. |
| 1708 | */ |
| 1709 | public abstract long getHistoryBaseTime(); |
| 1710 | |
| 1711 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1712 | * Returns the number of times the device has been started. |
| 1713 | */ |
| 1714 | public abstract int getStartCount(); |
| 1715 | |
| 1716 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 1717 | * 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] | 1718 | * running on battery. |
| 1719 | * |
| 1720 | * {@hide} |
| 1721 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1722 | public abstract long getScreenOnTime(long elapsedRealtimeUs, int which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1723 | |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 1724 | /** |
| 1725 | * Returns the number of times the screen was turned on. |
| 1726 | * |
| 1727 | * {@hide} |
| 1728 | */ |
| 1729 | public abstract int getScreenOnCount(int which); |
| 1730 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 1731 | public abstract long getInteractiveTime(long elapsedRealtimeUs, int which); |
| 1732 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1733 | public static final int SCREEN_BRIGHTNESS_DARK = 0; |
| 1734 | public static final int SCREEN_BRIGHTNESS_DIM = 1; |
| 1735 | public static final int SCREEN_BRIGHTNESS_MEDIUM = 2; |
| 1736 | public static final int SCREEN_BRIGHTNESS_LIGHT = 3; |
| 1737 | public static final int SCREEN_BRIGHTNESS_BRIGHT = 4; |
| 1738 | |
| 1739 | static final String[] SCREEN_BRIGHTNESS_NAMES = { |
| 1740 | "dark", "dim", "medium", "light", "bright" |
| 1741 | }; |
| 1742 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1743 | static final String[] SCREEN_BRIGHTNESS_SHORT_NAMES = { |
| 1744 | "0", "1", "2", "3", "4" |
| 1745 | }; |
| 1746 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1747 | public static final int NUM_SCREEN_BRIGHTNESS_BINS = 5; |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 1748 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1749 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 1750 | * Returns the time in microseconds that the screen has been on with |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1751 | * the given brightness |
| 1752 | * |
| 1753 | * {@hide} |
| 1754 | */ |
| 1755 | public abstract long getScreenBrightnessTime(int brightnessBin, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1756 | long elapsedRealtimeUs, int which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1757 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1758 | /** |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 1759 | * 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] | 1760 | * running on battery. |
| 1761 | * |
| 1762 | * {@hide} |
| 1763 | */ |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 1764 | public abstract long getPowerSaveModeEnabledTime(long elapsedRealtimeUs, int which); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 1765 | |
| 1766 | /** |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 1767 | * Returns the number of times that power save mode was enabled. |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 1768 | * |
| 1769 | * {@hide} |
| 1770 | */ |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 1771 | public abstract int getPowerSaveModeEnabledCount(int which); |
| 1772 | |
| 1773 | /** |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 1774 | * Constant for device idle mode: not active. |
| 1775 | */ |
| 1776 | public static final int DEVICE_IDLE_MODE_OFF = 0; |
| 1777 | |
| 1778 | /** |
| 1779 | * Constant for device idle mode: active in lightweight mode. |
| 1780 | */ |
| 1781 | public static final int DEVICE_IDLE_MODE_LIGHT = 1; |
| 1782 | |
| 1783 | /** |
| 1784 | * Constant for device idle mode: active in full mode. |
| 1785 | */ |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 1786 | public static final int DEVICE_IDLE_MODE_DEEP = 2; |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 1787 | |
| 1788 | /** |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 1789 | * Returns the time in microseconds that device has been in idle mode while |
| 1790 | * running on battery. |
| 1791 | * |
| 1792 | * {@hide} |
| 1793 | */ |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 1794 | public abstract long getDeviceIdleModeTime(int mode, long elapsedRealtimeUs, int which); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 1795 | |
| 1796 | /** |
| 1797 | * Returns the number of times that the devie has gone in to idle mode. |
| 1798 | * |
| 1799 | * {@hide} |
| 1800 | */ |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 1801 | public abstract int getDeviceIdleModeCount(int mode, int which); |
| 1802 | |
| 1803 | /** |
| 1804 | * Return the longest duration we spent in a particular device idle mode (fully in the |
| 1805 | * mode, not in idle maintenance etc). |
| 1806 | */ |
| 1807 | public abstract long getLongestDeviceIdleModeTime(int mode); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 1808 | |
| 1809 | /** |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 1810 | * 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] | 1811 | * battery. This is broader than {@link #getDeviceIdleModeTime} -- it |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 1812 | * counts all of the time that we consider the device to be idle, whether or not |
| 1813 | * it is currently in the actual device idle mode. |
| 1814 | * |
| 1815 | * {@hide} |
| 1816 | */ |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 1817 | public abstract long getDeviceIdlingTime(int mode, long elapsedRealtimeUs, int which); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 1818 | |
| 1819 | /** |
| 1820 | * Returns the number of times that the devie has started idling. |
| 1821 | * |
| 1822 | * {@hide} |
| 1823 | */ |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 1824 | public abstract int getDeviceIdlingCount(int mode, int which); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 1825 | |
| 1826 | /** |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 1827 | * Returns the number of times that connectivity state changed. |
| 1828 | * |
| 1829 | * {@hide} |
| 1830 | */ |
| 1831 | public abstract int getNumConnectivityChange(int which); |
| 1832 | |
| 1833 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 1834 | * 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] | 1835 | * running on battery. |
| 1836 | * |
| 1837 | * {@hide} |
| 1838 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1839 | public abstract long getPhoneOnTime(long elapsedRealtimeUs, int which); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 1840 | |
| 1841 | /** |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 1842 | * Returns the number of times a phone call was activated. |
| 1843 | * |
| 1844 | * {@hide} |
| 1845 | */ |
| 1846 | public abstract int getPhoneOnCount(int which); |
| 1847 | |
| 1848 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 1849 | * Returns the time in microseconds that the phone has been running with |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 1850 | * the given signal strength. |
| 1851 | * |
| 1852 | * {@hide} |
| 1853 | */ |
| 1854 | public abstract long getPhoneSignalStrengthTime(int strengthBin, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1855 | long elapsedRealtimeUs, int which); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 1856 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1857 | /** |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 1858 | * Returns the time in microseconds that the phone has been trying to |
| 1859 | * acquire a signal. |
| 1860 | * |
| 1861 | * {@hide} |
| 1862 | */ |
| 1863 | public abstract long getPhoneSignalScanningTime( |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1864 | long elapsedRealtimeUs, int which); |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 1865 | |
| 1866 | /** |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1867 | * Returns the number of times the phone has entered the given signal strength. |
| 1868 | * |
| 1869 | * {@hide} |
| 1870 | */ |
| 1871 | public abstract int getPhoneSignalStrengthCount(int strengthBin, int which); |
| 1872 | |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 1873 | /** |
| 1874 | * Returns the time in microseconds that the mobile network has been active |
| 1875 | * (in a high power state). |
| 1876 | * |
| 1877 | * {@hide} |
| 1878 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1879 | public abstract long getMobileRadioActiveTime(long elapsedRealtimeUs, int which); |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 1880 | |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 1881 | /** |
| 1882 | * Returns the number of times that the mobile network has transitioned to the |
| 1883 | * active state. |
| 1884 | * |
| 1885 | * {@hide} |
| 1886 | */ |
| 1887 | public abstract int getMobileRadioActiveCount(int which); |
| 1888 | |
| 1889 | /** |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1890 | * Returns the time in microseconds that is the difference between the mobile radio |
| 1891 | * time we saw based on the elapsed timestamp when going down vs. the given time stamp |
| 1892 | * from the radio. |
| 1893 | * |
| 1894 | * {@hide} |
| 1895 | */ |
| 1896 | public abstract long getMobileRadioActiveAdjustedTime(int which); |
| 1897 | |
| 1898 | /** |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 1899 | * Returns the time in microseconds that the mobile network has been active |
| 1900 | * (in a high power state) but not being able to blame on an app. |
| 1901 | * |
| 1902 | * {@hide} |
| 1903 | */ |
| 1904 | public abstract long getMobileRadioActiveUnknownTime(int which); |
| 1905 | |
| 1906 | /** |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 1907 | * 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] | 1908 | * |
| 1909 | * {@hide} |
| 1910 | */ |
| 1911 | public abstract int getMobileRadioActiveUnknownCount(int which); |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 1912 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 1913 | public static final int DATA_CONNECTION_NONE = 0; |
| 1914 | public static final int DATA_CONNECTION_GPRS = 1; |
| 1915 | public static final int DATA_CONNECTION_EDGE = 2; |
| 1916 | public static final int DATA_CONNECTION_UMTS = 3; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1917 | public static final int DATA_CONNECTION_CDMA = 4; |
| 1918 | public static final int DATA_CONNECTION_EVDO_0 = 5; |
| 1919 | public static final int DATA_CONNECTION_EVDO_A = 6; |
| 1920 | public static final int DATA_CONNECTION_1xRTT = 7; |
| 1921 | public static final int DATA_CONNECTION_HSDPA = 8; |
| 1922 | public static final int DATA_CONNECTION_HSUPA = 9; |
| 1923 | public static final int DATA_CONNECTION_HSPA = 10; |
| 1924 | public static final int DATA_CONNECTION_IDEN = 11; |
| 1925 | public static final int DATA_CONNECTION_EVDO_B = 12; |
Robert Greenwalt | 962a990 | 2010-11-02 11:10:25 -0700 | [diff] [blame] | 1926 | public static final int DATA_CONNECTION_LTE = 13; |
| 1927 | public static final int DATA_CONNECTION_EHRPD = 14; |
Patrick Tjin | b71703c | 2013-11-06 09:27:03 -0800 | [diff] [blame] | 1928 | public static final int DATA_CONNECTION_HSPAP = 15; |
| 1929 | public static final int DATA_CONNECTION_OTHER = 16; |
Robert Greenwalt | 962a990 | 2010-11-02 11:10:25 -0700 | [diff] [blame] | 1930 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 1931 | static final String[] DATA_CONNECTION_NAMES = { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1932 | "none", "gprs", "edge", "umts", "cdma", "evdo_0", "evdo_A", |
Robert Greenwalt | 962a990 | 2010-11-02 11:10:25 -0700 | [diff] [blame] | 1933 | "1xrtt", "hsdpa", "hsupa", "hspa", "iden", "evdo_b", "lte", |
Patrick Tjin | b71703c | 2013-11-06 09:27:03 -0800 | [diff] [blame] | 1934 | "ehrpd", "hspap", "other" |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 1935 | }; |
| 1936 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1937 | public static final int NUM_DATA_CONNECTION_TYPES = DATA_CONNECTION_OTHER+1; |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 1938 | |
| 1939 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 1940 | * Returns the time in microseconds that the phone has been running with |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 1941 | * the given data connection. |
| 1942 | * |
| 1943 | * {@hide} |
| 1944 | */ |
| 1945 | public abstract long getPhoneDataConnectionTime(int dataType, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1946 | long elapsedRealtimeUs, int which); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 1947 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 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 data |
| 1950 | * connection type. |
| 1951 | * |
| 1952 | * {@hide} |
| 1953 | */ |
| 1954 | public abstract int getPhoneDataConnectionCount(int dataType, int which); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1955 | |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 1956 | public static final int WIFI_SUPPL_STATE_INVALID = 0; |
| 1957 | public static final int WIFI_SUPPL_STATE_DISCONNECTED = 1; |
| 1958 | public static final int WIFI_SUPPL_STATE_INTERFACE_DISABLED = 2; |
| 1959 | public static final int WIFI_SUPPL_STATE_INACTIVE = 3; |
| 1960 | public static final int WIFI_SUPPL_STATE_SCANNING = 4; |
| 1961 | public static final int WIFI_SUPPL_STATE_AUTHENTICATING = 5; |
| 1962 | public static final int WIFI_SUPPL_STATE_ASSOCIATING = 6; |
| 1963 | public static final int WIFI_SUPPL_STATE_ASSOCIATED = 7; |
| 1964 | public static final int WIFI_SUPPL_STATE_FOUR_WAY_HANDSHAKE = 8; |
| 1965 | public static final int WIFI_SUPPL_STATE_GROUP_HANDSHAKE = 9; |
| 1966 | public static final int WIFI_SUPPL_STATE_COMPLETED = 10; |
| 1967 | public static final int WIFI_SUPPL_STATE_DORMANT = 11; |
| 1968 | public static final int WIFI_SUPPL_STATE_UNINITIALIZED = 12; |
| 1969 | |
| 1970 | public static final int NUM_WIFI_SUPPL_STATES = WIFI_SUPPL_STATE_UNINITIALIZED+1; |
| 1971 | |
| 1972 | static final String[] WIFI_SUPPL_STATE_NAMES = { |
| 1973 | "invalid", "disconn", "disabled", "inactive", "scanning", |
| 1974 | "authenticating", "associating", "associated", "4-way-handshake", |
| 1975 | "group-handshake", "completed", "dormant", "uninit" |
| 1976 | }; |
| 1977 | |
| 1978 | static final String[] WIFI_SUPPL_STATE_SHORT_NAMES = { |
| 1979 | "inv", "dsc", "dis", "inact", "scan", |
| 1980 | "auth", "ascing", "asced", "4-way", |
| 1981 | "group", "compl", "dorm", "uninit" |
| 1982 | }; |
| 1983 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1984 | public static final BitDescription[] HISTORY_STATE_DESCRIPTIONS |
| 1985 | = new BitDescription[] { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1986 | new BitDescription(HistoryItem.STATE_CPU_RUNNING_FLAG, "running", "r"), |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 1987 | new BitDescription(HistoryItem.STATE_WAKE_LOCK_FLAG, "wake_lock", "w"), |
| 1988 | new BitDescription(HistoryItem.STATE_SENSOR_ON_FLAG, "sensor", "s"), |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1989 | new BitDescription(HistoryItem.STATE_GPS_ON_FLAG, "gps", "g"), |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1990 | new BitDescription(HistoryItem.STATE_WIFI_FULL_LOCK_FLAG, "wifi_full_lock", "Wl"), |
| 1991 | new BitDescription(HistoryItem.STATE_WIFI_SCAN_FLAG, "wifi_scan", "Ws"), |
| 1992 | new BitDescription(HistoryItem.STATE_WIFI_MULTICAST_ON_FLAG, "wifi_multicast", "Wm"), |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 1993 | new BitDescription(HistoryItem.STATE_WIFI_RADIO_ACTIVE_FLAG, "wifi_radio", "Wr"), |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 1994 | new BitDescription(HistoryItem.STATE_MOBILE_RADIO_ACTIVE_FLAG, "mobile_radio", "Pr"), |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 1995 | new BitDescription(HistoryItem.STATE_PHONE_SCANNING_FLAG, "phone_scanning", "Psc"), |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 1996 | new BitDescription(HistoryItem.STATE_AUDIO_ON_FLAG, "audio", "a"), |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 1997 | new BitDescription(HistoryItem.STATE_SCREEN_ON_FLAG, "screen", "S"), |
| 1998 | new BitDescription(HistoryItem.STATE_BATTERY_PLUGGED_FLAG, "plugged", "BP"), |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 1999 | new BitDescription(HistoryItem.STATE_DATA_CONNECTION_MASK, |
| 2000 | HistoryItem.STATE_DATA_CONNECTION_SHIFT, "data_conn", "Pcn", |
| 2001 | DATA_CONNECTION_NAMES, DATA_CONNECTION_NAMES), |
| 2002 | new BitDescription(HistoryItem.STATE_PHONE_STATE_MASK, |
| 2003 | HistoryItem.STATE_PHONE_STATE_SHIFT, "phone_state", "Pst", |
| 2004 | new String[] {"in", "out", "emergency", "off"}, |
| 2005 | new String[] {"in", "out", "em", "off"}), |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 2006 | new BitDescription(HistoryItem.STATE_PHONE_SIGNAL_STRENGTH_MASK, |
| 2007 | HistoryItem.STATE_PHONE_SIGNAL_STRENGTH_SHIFT, "phone_signal_strength", "Pss", |
| 2008 | SignalStrength.SIGNAL_STRENGTH_NAMES, |
| 2009 | new String[] { "0", "1", "2", "3", "4" }), |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2010 | new BitDescription(HistoryItem.STATE_BRIGHTNESS_MASK, |
| 2011 | HistoryItem.STATE_BRIGHTNESS_SHIFT, "brightness", "Sb", |
| 2012 | SCREEN_BRIGHTNESS_NAMES, SCREEN_BRIGHTNESS_SHORT_NAMES), |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2013 | }; |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2014 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2015 | public static final BitDescription[] HISTORY_STATE2_DESCRIPTIONS |
| 2016 | = new BitDescription[] { |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 2017 | new BitDescription(HistoryItem.STATE2_POWER_SAVE_FLAG, "power_save", "ps"), |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 2018 | new BitDescription(HistoryItem.STATE2_VIDEO_ON_FLAG, "video", "v"), |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 2019 | new BitDescription(HistoryItem.STATE2_WIFI_RUNNING_FLAG, "wifi_running", "Ww"), |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 2020 | new BitDescription(HistoryItem.STATE2_WIFI_ON_FLAG, "wifi", "W"), |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 2021 | new BitDescription(HistoryItem.STATE2_FLASHLIGHT_FLAG, "flashlight", "fl"), |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 2022 | new BitDescription(HistoryItem.STATE2_DEVICE_IDLE_MASK, |
| 2023 | HistoryItem.STATE2_DEVICE_IDLE_SHIFT, "device_idle", "di", |
| 2024 | new String[] { "off", "light", "full", "???" }, |
| 2025 | new String[] { "off", "light", "full", "???" }), |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 2026 | new BitDescription(HistoryItem.STATE2_CHARGING_FLAG, "charging", "ch"), |
| 2027 | new BitDescription(HistoryItem.STATE2_PHONE_IN_CALL_FLAG, "phone_in_call", "Pcl"), |
| 2028 | new BitDescription(HistoryItem.STATE2_BLUETOOTH_ON_FLAG, "bluetooth", "b"), |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 2029 | new BitDescription(HistoryItem.STATE2_WIFI_SIGNAL_STRENGTH_MASK, |
| 2030 | HistoryItem.STATE2_WIFI_SIGNAL_STRENGTH_SHIFT, "wifi_signal_strength", "Wss", |
| 2031 | new String[] { "0", "1", "2", "3", "4" }, |
| 2032 | new String[] { "0", "1", "2", "3", "4" }), |
| 2033 | new BitDescription(HistoryItem.STATE2_WIFI_SUPPL_STATE_MASK, |
| 2034 | HistoryItem.STATE2_WIFI_SUPPL_STATE_SHIFT, "wifi_suppl", "Wsp", |
| 2035 | WIFI_SUPPL_STATE_NAMES, WIFI_SUPPL_STATE_SHORT_NAMES), |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 2036 | new BitDescription(HistoryItem.STATE2_CAMERA_FLAG, "camera", "ca"), |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 2037 | new BitDescription(HistoryItem.STATE2_BLUETOOTH_SCAN_FLAG, "ble_scan", "bles"), |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2038 | }; |
| 2039 | |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 2040 | public static final String[] HISTORY_EVENT_NAMES = new String[] { |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 2041 | "null", "proc", "fg", "top", "sync", "wake_lock_in", "job", "user", "userfg", "conn", |
Dianne Hackborn | 280a64e | 2015-07-13 14:48:08 -0700 | [diff] [blame] | 2042 | "active", "pkginst", "pkgunin", "alarm", "stats", "inactive", "active", "tmpwhitelist", |
Dianne Hackborn | d0db6f0 | 2016-07-18 14:14:20 -0700 | [diff] [blame] | 2043 | "screenwake", "wakeupap", "longwake" |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 2044 | }; |
| 2045 | |
| 2046 | public static final String[] HISTORY_EVENT_CHECKIN_NAMES = new String[] { |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 2047 | "Enl", "Epr", "Efg", "Etp", "Esy", "Ewl", "Ejb", "Eur", "Euf", "Ecn", |
Dianne Hackborn | 280a64e | 2015-07-13 14:48:08 -0700 | [diff] [blame] | 2048 | "Eac", "Epi", "Epu", "Eal", "Est", "Eai", "Eaa", "Etw", |
Dianne Hackborn | d0db6f0 | 2016-07-18 14:14:20 -0700 | [diff] [blame] | 2049 | "Esw", "Ewa", "Elw" |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 2050 | }; |
| 2051 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2052 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 2053 | * 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] | 2054 | * running on battery. |
| 2055 | * |
| 2056 | * {@hide} |
| 2057 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2058 | public abstract long getWifiOnTime(long elapsedRealtimeUs, int which); |
Eric Shienbrood | d4c5f89 | 2009-03-24 18:13:20 -0700 | [diff] [blame] | 2059 | |
| 2060 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 2061 | * 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] | 2062 | * been in the running state while the device was running on battery. |
| 2063 | * |
| 2064 | * {@hide} |
| 2065 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2066 | public abstract long getGlobalWifiRunningTime(long elapsedRealtimeUs, int which); |
Eric Shienbrood | d4c5f89 | 2009-03-24 18:13:20 -0700 | [diff] [blame] | 2067 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 2068 | public static final int WIFI_STATE_OFF = 0; |
| 2069 | public static final int WIFI_STATE_OFF_SCANNING = 1; |
| 2070 | public static final int WIFI_STATE_ON_NO_NETWORKS = 2; |
| 2071 | public static final int WIFI_STATE_ON_DISCONNECTED = 3; |
| 2072 | public static final int WIFI_STATE_ON_CONNECTED_STA = 4; |
| 2073 | public static final int WIFI_STATE_ON_CONNECTED_P2P = 5; |
| 2074 | public static final int WIFI_STATE_ON_CONNECTED_STA_P2P = 6; |
| 2075 | public static final int WIFI_STATE_SOFT_AP = 7; |
| 2076 | |
| 2077 | static final String[] WIFI_STATE_NAMES = { |
| 2078 | "off", "scanning", "no_net", "disconn", |
| 2079 | "sta", "p2p", "sta_p2p", "soft_ap" |
| 2080 | }; |
| 2081 | |
| 2082 | public static final int NUM_WIFI_STATES = WIFI_STATE_SOFT_AP+1; |
| 2083 | |
| 2084 | /** |
| 2085 | * Returns the time in microseconds that WiFi has been running in the given state. |
| 2086 | * |
| 2087 | * {@hide} |
| 2088 | */ |
| 2089 | public abstract long getWifiStateTime(int wifiState, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2090 | long elapsedRealtimeUs, int which); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 2091 | |
| 2092 | /** |
| 2093 | * Returns the number of times that WiFi has entered the given state. |
| 2094 | * |
| 2095 | * {@hide} |
| 2096 | */ |
| 2097 | public abstract int getWifiStateCount(int wifiState, int which); |
| 2098 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2099 | /** |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 2100 | * Returns the time in microseconds that the wifi supplicant has been |
| 2101 | * in a given state. |
| 2102 | * |
| 2103 | * {@hide} |
| 2104 | */ |
| 2105 | public abstract long getWifiSupplStateTime(int state, long elapsedRealtimeUs, int which); |
| 2106 | |
| 2107 | /** |
| 2108 | * Returns the number of times that the wifi supplicant has transitioned |
| 2109 | * to a given state. |
| 2110 | * |
| 2111 | * {@hide} |
| 2112 | */ |
| 2113 | public abstract int getWifiSupplStateCount(int state, int which); |
| 2114 | |
| 2115 | public static final int NUM_WIFI_SIGNAL_STRENGTH_BINS = 5; |
| 2116 | |
| 2117 | /** |
| 2118 | * Returns the time in microseconds that WIFI has been running with |
| 2119 | * the given signal strength. |
| 2120 | * |
| 2121 | * {@hide} |
| 2122 | */ |
| 2123 | public abstract long getWifiSignalStrengthTime(int strengthBin, |
| 2124 | long elapsedRealtimeUs, int which); |
| 2125 | |
| 2126 | /** |
| 2127 | * Returns the number of times WIFI has entered the given signal strength. |
| 2128 | * |
| 2129 | * {@hide} |
| 2130 | */ |
| 2131 | public abstract int getWifiSignalStrengthCount(int strengthBin, int which); |
| 2132 | |
| 2133 | /** |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 2134 | * Returns the time in microseconds that the flashlight has been on while the device was |
| 2135 | * running on battery. |
| 2136 | * |
| 2137 | * {@hide} |
| 2138 | */ |
| 2139 | public abstract long getFlashlightOnTime(long elapsedRealtimeUs, int which); |
| 2140 | |
| 2141 | /** |
| 2142 | * Returns the number of times that the flashlight has been turned on while the device was |
| 2143 | * running on battery. |
| 2144 | * |
| 2145 | * {@hide} |
| 2146 | */ |
| 2147 | public abstract long getFlashlightOnCount(int which); |
| 2148 | |
Ruben Brunk | 5b1308f | 2015-06-03 18:49:27 -0700 | [diff] [blame] | 2149 | /** |
| 2150 | * Returns the time in microseconds that the camera has been on while the device was |
| 2151 | * running on battery. |
| 2152 | * |
| 2153 | * {@hide} |
| 2154 | */ |
| 2155 | public abstract long getCameraOnTime(long elapsedRealtimeUs, int which); |
| 2156 | |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 2157 | /** |
| 2158 | * Returns the time in microseconds that bluetooth scans were running while the device was |
| 2159 | * on battery. |
| 2160 | * |
| 2161 | * {@hide} |
| 2162 | */ |
| 2163 | public abstract long getBluetoothScanTime(long elapsedRealtimeUs, int which); |
Ruben Brunk | 5b1308f | 2015-06-03 18:49:27 -0700 | [diff] [blame] | 2164 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2165 | public static final int NETWORK_MOBILE_RX_DATA = 0; |
| 2166 | public static final int NETWORK_MOBILE_TX_DATA = 1; |
| 2167 | public static final int NETWORK_WIFI_RX_DATA = 2; |
| 2168 | public static final int NETWORK_WIFI_TX_DATA = 3; |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 2169 | public static final int NETWORK_BT_RX_DATA = 4; |
| 2170 | public static final int NETWORK_BT_TX_DATA = 5; |
| 2171 | public static final int NUM_NETWORK_ACTIVITY_TYPES = NETWORK_BT_TX_DATA + 1; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 2172 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2173 | public abstract long getNetworkActivityBytes(int type, int which); |
| 2174 | public abstract long getNetworkActivityPackets(int type, int which); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 2175 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 2176 | /** |
Adam Lesinski | 1739076 | 2015-04-10 13:17:47 -0700 | [diff] [blame] | 2177 | * Returns true if the BatteryStats object has detailed WiFi power reports. |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 2178 | * When true, calling {@link #getWifiControllerActivity()} will yield the |
Adam Lesinski | 1739076 | 2015-04-10 13:17:47 -0700 | [diff] [blame] | 2179 | * actual power data. |
| 2180 | */ |
| 2181 | public abstract boolean hasWifiActivityReporting(); |
| 2182 | |
| 2183 | /** |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 2184 | * Returns a {@link ControllerActivityCounter} which is an aggregate of the times spent |
| 2185 | * in various radio controller states, such as transmit, receive, and idle. |
| 2186 | * @return non-null {@link ControllerActivityCounter} |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 2187 | */ |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 2188 | public abstract ControllerActivityCounter getWifiControllerActivity(); |
| 2189 | |
| 2190 | /** |
| 2191 | * Returns true if the BatteryStats object has detailed bluetooth power reports. |
| 2192 | * When true, calling {@link #getBluetoothControllerActivity()} will yield the |
| 2193 | * actual power data. |
| 2194 | */ |
| 2195 | public abstract boolean hasBluetoothActivityReporting(); |
| 2196 | |
| 2197 | /** |
| 2198 | * Returns a {@link ControllerActivityCounter} which is an aggregate of the times spent |
| 2199 | * in various radio controller states, such as transmit, receive, and idle. |
| 2200 | * @return non-null {@link ControllerActivityCounter} |
| 2201 | */ |
| 2202 | public abstract ControllerActivityCounter getBluetoothControllerActivity(); |
| 2203 | |
| 2204 | /** |
| 2205 | * Returns true if the BatteryStats object has detailed modem power reports. |
| 2206 | * When true, calling {@link #getModemControllerActivity()} will yield the |
| 2207 | * actual power data. |
| 2208 | */ |
| 2209 | public abstract boolean hasModemActivityReporting(); |
| 2210 | |
| 2211 | /** |
| 2212 | * Returns a {@link ControllerActivityCounter} which is an aggregate of the times spent |
| 2213 | * in various radio controller states, such as transmit, receive, and idle. |
| 2214 | * @return non-null {@link ControllerActivityCounter} |
| 2215 | */ |
| 2216 | public abstract ControllerActivityCounter getModemControllerActivity(); |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 2217 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2218 | /** |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 2219 | * Return the wall clock time when battery stats data collection started. |
| 2220 | */ |
| 2221 | public abstract long getStartClockTime(); |
| 2222 | |
| 2223 | /** |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 2224 | * Return platform version tag that we were running in when the battery stats started. |
| 2225 | */ |
| 2226 | public abstract String getStartPlatformVersion(); |
| 2227 | |
| 2228 | /** |
| 2229 | * Return platform version tag that we were running in when the battery stats ended. |
| 2230 | */ |
| 2231 | public abstract String getEndPlatformVersion(); |
| 2232 | |
| 2233 | /** |
| 2234 | * Return the internal version code of the parcelled format. |
| 2235 | */ |
| 2236 | public abstract int getParcelVersion(); |
| 2237 | |
| 2238 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2239 | * Return whether we are currently running on battery. |
| 2240 | */ |
| 2241 | public abstract boolean getIsOnBattery(); |
| 2242 | |
| 2243 | /** |
| 2244 | * Returns a SparseArray containing the statistics for each uid. |
| 2245 | */ |
| 2246 | public abstract SparseArray<? extends Uid> getUidStats(); |
| 2247 | |
| 2248 | /** |
| 2249 | * Returns the current battery uptime in microseconds. |
| 2250 | * |
| 2251 | * @param curTime the amount of elapsed realtime in microseconds. |
| 2252 | */ |
| 2253 | public abstract long getBatteryUptime(long curTime); |
| 2254 | |
| 2255 | /** |
| 2256 | * Returns the current battery realtime in microseconds. |
| 2257 | * |
| 2258 | * @param curTime the amount of elapsed realtime in microseconds. |
| 2259 | */ |
| 2260 | public abstract long getBatteryRealtime(long curTime); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2261 | |
| 2262 | /** |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 2263 | * Returns the battery percentage level at the last time the device was unplugged from power, or |
| 2264 | * the last time it booted on battery power. |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2265 | */ |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 2266 | public abstract int getDischargeStartLevel(); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2267 | |
| 2268 | /** |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 2269 | * Returns the current battery percentage level if we are in a discharge cycle, otherwise |
| 2270 | * returns the level at the last plug event. |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2271 | */ |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 2272 | public abstract int getDischargeCurrentLevel(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2273 | |
| 2274 | /** |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 2275 | * Get the amount the battery has discharged since the stats were |
| 2276 | * last reset after charging, as a lower-end approximation. |
| 2277 | */ |
| 2278 | public abstract int getLowDischargeAmountSinceCharge(); |
| 2279 | |
| 2280 | /** |
| 2281 | * Get the amount the battery has discharged since the stats were |
| 2282 | * last reset after charging, as an upper-end approximation. |
| 2283 | */ |
| 2284 | public abstract int getHighDischargeAmountSinceCharge(); |
| 2285 | |
| 2286 | /** |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2287 | * Retrieve the discharge amount over the selected discharge period <var>which</var>. |
| 2288 | */ |
| 2289 | public abstract int getDischargeAmount(int which); |
| 2290 | |
| 2291 | /** |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 2292 | * Get the amount the battery has discharged while the screen was on, |
| 2293 | * since the last time power was unplugged. |
| 2294 | */ |
| 2295 | public abstract int getDischargeAmountScreenOn(); |
| 2296 | |
| 2297 | /** |
| 2298 | * Get the amount the battery has discharged while the screen was on, |
| 2299 | * since the last time the device was charged. |
| 2300 | */ |
| 2301 | public abstract int getDischargeAmountScreenOnSinceCharge(); |
| 2302 | |
| 2303 | /** |
| 2304 | * Get the amount the battery has discharged while the screen was off, |
| 2305 | * since the last time power was unplugged. |
| 2306 | */ |
| 2307 | public abstract int getDischargeAmountScreenOff(); |
| 2308 | |
| 2309 | /** |
| 2310 | * Get the amount the battery has discharged while the screen was off, |
| 2311 | * since the last time the device was charged. |
| 2312 | */ |
| 2313 | public abstract int getDischargeAmountScreenOffSinceCharge(); |
| 2314 | |
| 2315 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2316 | * Returns the total, last, or current battery uptime in microseconds. |
| 2317 | * |
| 2318 | * @param curTime the elapsed realtime in microseconds. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2319 | * @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] | 2320 | */ |
| 2321 | public abstract long computeBatteryUptime(long curTime, int which); |
| 2322 | |
| 2323 | /** |
| 2324 | * Returns the total, last, or current battery realtime in microseconds. |
| 2325 | * |
| 2326 | * @param curTime the current elapsed realtime in microseconds. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2327 | * @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] | 2328 | */ |
| 2329 | public abstract long computeBatteryRealtime(long curTime, int which); |
| 2330 | |
| 2331 | /** |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2332 | * Returns the total, last, or current battery screen off uptime in microseconds. |
| 2333 | * |
| 2334 | * @param curTime the elapsed realtime in microseconds. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2335 | * @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] | 2336 | */ |
| 2337 | public abstract long computeBatteryScreenOffUptime(long curTime, int which); |
| 2338 | |
| 2339 | /** |
| 2340 | * Returns the total, last, or current battery screen off realtime in microseconds. |
| 2341 | * |
| 2342 | * @param curTime the current elapsed realtime in microseconds. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2343 | * @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] | 2344 | */ |
| 2345 | public abstract long computeBatteryScreenOffRealtime(long curTime, int which); |
| 2346 | |
| 2347 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2348 | * Returns the total, last, or current uptime in microseconds. |
| 2349 | * |
| 2350 | * @param curTime the current elapsed realtime in microseconds. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2351 | * @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] | 2352 | */ |
| 2353 | public abstract long computeUptime(long curTime, int which); |
| 2354 | |
| 2355 | /** |
| 2356 | * Returns the total, last, or current realtime in microseconds. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2357 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2358 | * @param curTime the current elapsed realtime in microseconds. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2359 | * @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] | 2360 | */ |
| 2361 | public abstract long computeRealtime(long curTime, int which); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2362 | |
| 2363 | /** |
| 2364 | * Compute an approximation for how much run time (in microseconds) is remaining on |
| 2365 | * the battery. Returns -1 if no time can be computed: either there is not |
| 2366 | * enough current data to make a decision, or the battery is currently |
| 2367 | * charging. |
| 2368 | * |
| 2369 | * @param curTime The current elepsed realtime in microseconds. |
| 2370 | */ |
| 2371 | public abstract long computeBatteryTimeRemaining(long curTime); |
| 2372 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 2373 | // The part of a step duration that is the actual time. |
| 2374 | public static final long STEP_LEVEL_TIME_MASK = 0x000000ffffffffffL; |
| 2375 | |
| 2376 | // Bits in a step duration that are the new battery level we are at. |
| 2377 | public static final long STEP_LEVEL_LEVEL_MASK = 0x0000ff0000000000L; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2378 | public static final int STEP_LEVEL_LEVEL_SHIFT = 40; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 2379 | |
| 2380 | // Bits in a step duration that are the initial mode we were in at that step. |
| 2381 | public static final long STEP_LEVEL_INITIAL_MODE_MASK = 0x00ff000000000000L; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2382 | public static final int STEP_LEVEL_INITIAL_MODE_SHIFT = 48; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 2383 | |
| 2384 | // Bits in a step duration that indicate which modes changed during that step. |
| 2385 | public static final long STEP_LEVEL_MODIFIED_MODE_MASK = 0xff00000000000000L; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2386 | public static final int STEP_LEVEL_MODIFIED_MODE_SHIFT = 56; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 2387 | |
| 2388 | // Step duration mode: the screen is on, off, dozed, etc; value is Display.STATE_* - 1. |
| 2389 | public static final int STEP_LEVEL_MODE_SCREEN_STATE = 0x03; |
| 2390 | |
| 2391 | // Step duration mode: power save is on. |
| 2392 | public static final int STEP_LEVEL_MODE_POWER_SAVE = 0x04; |
| 2393 | |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2394 | // Step duration mode: device is currently in idle mode. |
| 2395 | public static final int STEP_LEVEL_MODE_DEVICE_IDLE = 0x08; |
| 2396 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2397 | public static final int[] STEP_LEVEL_MODES_OF_INTEREST = new int[] { |
| 2398 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE, |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2399 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE|STEP_LEVEL_MODE_DEVICE_IDLE, |
| 2400 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_DEVICE_IDLE, |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2401 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE, |
| 2402 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE, |
| 2403 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE, |
| 2404 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE, |
| 2405 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE, |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2406 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE|STEP_LEVEL_MODE_DEVICE_IDLE, |
| 2407 | STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_DEVICE_IDLE, |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2408 | }; |
| 2409 | public static final int[] STEP_LEVEL_MODE_VALUES = new int[] { |
| 2410 | (Display.STATE_OFF-1), |
| 2411 | (Display.STATE_OFF-1)|STEP_LEVEL_MODE_POWER_SAVE, |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2412 | (Display.STATE_OFF-1)|STEP_LEVEL_MODE_DEVICE_IDLE, |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2413 | (Display.STATE_ON-1), |
| 2414 | (Display.STATE_ON-1)|STEP_LEVEL_MODE_POWER_SAVE, |
| 2415 | (Display.STATE_DOZE-1), |
| 2416 | (Display.STATE_DOZE-1)|STEP_LEVEL_MODE_POWER_SAVE, |
| 2417 | (Display.STATE_DOZE_SUSPEND-1), |
| 2418 | (Display.STATE_DOZE_SUSPEND-1)|STEP_LEVEL_MODE_POWER_SAVE, |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2419 | (Display.STATE_DOZE_SUSPEND-1)|STEP_LEVEL_MODE_DEVICE_IDLE, |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2420 | }; |
| 2421 | public static final String[] STEP_LEVEL_MODE_LABELS = new String[] { |
| 2422 | "screen off", |
| 2423 | "screen off power save", |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2424 | "screen off device idle", |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2425 | "screen on", |
| 2426 | "screen on power save", |
| 2427 | "screen doze", |
| 2428 | "screen doze power save", |
| 2429 | "screen doze-suspend", |
| 2430 | "screen doze-suspend power save", |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2431 | "screen doze-suspend device idle", |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2432 | }; |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 2433 | |
| 2434 | /** |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 2435 | * Return the counter keeping track of the amount of battery discharge while the screen was off, |
| 2436 | * measured in micro-Ampere-hours. This will be non-zero only if the device's battery has |
| 2437 | * a coulomb counter. |
| 2438 | */ |
| 2439 | public abstract LongCounter getDischargeScreenOffCoulombCounter(); |
| 2440 | |
| 2441 | /** |
| 2442 | * Return the counter keeping track of the amount of battery discharge measured in |
| 2443 | * micro-Ampere-hours. This will be non-zero only if the device's battery has |
| 2444 | * a coulomb counter. |
| 2445 | */ |
| 2446 | public abstract LongCounter getDischargeCoulombCounter(); |
| 2447 | |
| 2448 | /** |
Adam Lesinski | f9b20a9 | 2016-06-17 17:30:01 -0700 | [diff] [blame] | 2449 | * Returns the estimated real battery capacity, which may be less than the capacity |
| 2450 | * declared by the PowerProfile. |
| 2451 | * @return The estimated battery capacity in mAh. |
| 2452 | */ |
| 2453 | public abstract int getEstimatedBatteryCapacity(); |
| 2454 | |
| 2455 | /** |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2456 | * Return the array of discharge step durations. |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 2457 | */ |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2458 | public abstract LevelStepTracker getDischargeLevelStepTracker(); |
| 2459 | |
| 2460 | /** |
| 2461 | * Return the array of daily discharge step durations. |
| 2462 | */ |
| 2463 | public abstract LevelStepTracker getDailyDischargeLevelStepTracker(); |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 2464 | |
| 2465 | /** |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2466 | * Compute an approximation for how much time (in microseconds) remains until the battery |
| 2467 | * is fully charged. Returns -1 if no time can be computed: either there is not |
| 2468 | * enough current data to make a decision, or the battery is currently |
| 2469 | * discharging. |
| 2470 | * |
| 2471 | * @param curTime The current elepsed realtime in microseconds. |
| 2472 | */ |
| 2473 | public abstract long computeChargeTimeRemaining(long curTime); |
| 2474 | |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 2475 | /** |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2476 | * Return the array of charge step durations. |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 2477 | */ |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2478 | public abstract LevelStepTracker getChargeLevelStepTracker(); |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 2479 | |
| 2480 | /** |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2481 | * Return the array of daily charge step durations. |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 2482 | */ |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 2483 | public abstract LevelStepTracker getDailyChargeLevelStepTracker(); |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 2484 | |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 2485 | public abstract ArrayList<PackageChange> getDailyPackageChanges(); |
| 2486 | |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 2487 | public abstract Map<String, ? extends Timer> getWakeupReasonStats(); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2488 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2489 | public abstract Map<String, ? extends Timer> getKernelWakelockStats(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2490 | |
James Carr | 2dd7e5e | 2016-07-20 18:48:39 -0700 | [diff] [blame] | 2491 | public abstract LongSparseArray<? extends Timer> getKernelMemoryStats(); |
| 2492 | |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 2493 | public abstract void writeToParcelWithoutUids(Parcel out, int flags); |
| 2494 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 2495 | private final static void formatTimeRaw(StringBuilder out, long seconds) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2496 | long days = seconds / (60 * 60 * 24); |
| 2497 | if (days != 0) { |
| 2498 | out.append(days); |
| 2499 | out.append("d "); |
| 2500 | } |
| 2501 | long used = days * 60 * 60 * 24; |
| 2502 | |
| 2503 | long hours = (seconds - used) / (60 * 60); |
| 2504 | if (hours != 0 || used != 0) { |
| 2505 | out.append(hours); |
| 2506 | out.append("h "); |
| 2507 | } |
| 2508 | used += hours * 60 * 60; |
| 2509 | |
| 2510 | long mins = (seconds-used) / 60; |
| 2511 | if (mins != 0 || used != 0) { |
| 2512 | out.append(mins); |
| 2513 | out.append("m "); |
| 2514 | } |
| 2515 | used += mins * 60; |
| 2516 | |
| 2517 | if (seconds != 0 || used != 0) { |
| 2518 | out.append(seconds-used); |
| 2519 | out.append("s "); |
| 2520 | } |
| 2521 | } |
| 2522 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2523 | public final static void formatTimeMs(StringBuilder sb, long time) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2524 | long sec = time / 1000; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 2525 | formatTimeRaw(sb, sec); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2526 | sb.append(time - (sec * 1000)); |
| 2527 | sb.append("ms "); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2528 | } |
| 2529 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2530 | public final static void formatTimeMsNoSpace(StringBuilder sb, long time) { |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 2531 | long sec = time / 1000; |
| 2532 | formatTimeRaw(sb, sec); |
| 2533 | sb.append(time - (sec * 1000)); |
| 2534 | sb.append("ms"); |
| 2535 | } |
| 2536 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2537 | public final String formatRatioLocked(long num, long den) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2538 | if (den == 0L) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2539 | return "--%"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2540 | } |
| 2541 | float perc = ((float)num) / ((float)den) * 100; |
| 2542 | mFormatBuilder.setLength(0); |
| 2543 | mFormatter.format("%.1f%%", perc); |
| 2544 | return mFormatBuilder.toString(); |
| 2545 | } |
| 2546 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2547 | final String formatBytesLocked(long bytes) { |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 2548 | mFormatBuilder.setLength(0); |
| 2549 | |
| 2550 | if (bytes < BYTES_PER_KB) { |
| 2551 | return bytes + "B"; |
| 2552 | } else if (bytes < BYTES_PER_MB) { |
| 2553 | mFormatter.format("%.2fKB", bytes / (double) BYTES_PER_KB); |
| 2554 | return mFormatBuilder.toString(); |
| 2555 | } else if (bytes < BYTES_PER_GB){ |
| 2556 | mFormatter.format("%.2fMB", bytes / (double) BYTES_PER_MB); |
| 2557 | return mFormatBuilder.toString(); |
| 2558 | } else { |
| 2559 | mFormatter.format("%.2fGB", bytes / (double) BYTES_PER_GB); |
| 2560 | return mFormatBuilder.toString(); |
| 2561 | } |
| 2562 | } |
| 2563 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2564 | private static long computeWakeLock(Timer timer, long elapsedRealtimeUs, int which) { |
Dianne Hackborn | c24ab86 | 2011-10-18 15:55:03 -0700 | [diff] [blame] | 2565 | if (timer != null) { |
| 2566 | // Convert from microseconds to milliseconds with rounding |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2567 | long totalTimeMicros = timer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Dianne Hackborn | c24ab86 | 2011-10-18 15:55:03 -0700 | [diff] [blame] | 2568 | long totalTimeMillis = (totalTimeMicros + 500) / 1000; |
| 2569 | return totalTimeMillis; |
| 2570 | } |
| 2571 | return 0; |
| 2572 | } |
| 2573 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2574 | /** |
| 2575 | * |
| 2576 | * @param sb a StringBuilder object. |
| 2577 | * @param timer a Timer object contining the wakelock times. |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2578 | * @param elapsedRealtimeUs the current on-battery time in microseconds. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2579 | * @param name the name of the wakelock. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2580 | * @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] | 2581 | * @param linePrefix a String to be prepended to each line of output. |
| 2582 | * @return the line prefix |
| 2583 | */ |
| 2584 | private static final String printWakeLock(StringBuilder sb, Timer timer, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2585 | long elapsedRealtimeUs, String name, int which, String linePrefix) { |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 2586 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2587 | if (timer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2588 | long totalTimeMillis = computeWakeLock(timer, elapsedRealtimeUs, which); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 2589 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2590 | int count = timer.getCountLocked(which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2591 | if (totalTimeMillis != 0) { |
| 2592 | sb.append(linePrefix); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 2593 | formatTimeMs(sb, totalTimeMillis); |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 2594 | if (name != null) { |
| 2595 | sb.append(name); |
| 2596 | sb.append(' '); |
| 2597 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2598 | sb.append('('); |
| 2599 | sb.append(count); |
| 2600 | sb.append(" times)"); |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2601 | final long maxDurationMs = timer.getMaxDurationMsLocked(elapsedRealtimeUs/1000); |
| 2602 | if (maxDurationMs >= 0) { |
| 2603 | sb.append(" max="); |
| 2604 | sb.append(maxDurationMs); |
| 2605 | } |
| 2606 | if (timer.isRunningLocked()) { |
| 2607 | final long currentMs = timer.getCurrentDurationMsLocked(elapsedRealtimeUs/1000); |
| 2608 | if (currentMs >= 0) { |
| 2609 | sb.append(" (running for "); |
| 2610 | sb.append(currentMs); |
| 2611 | sb.append("ms)"); |
| 2612 | } else { |
| 2613 | sb.append(" (running)"); |
| 2614 | } |
| 2615 | } |
| 2616 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2617 | return ", "; |
| 2618 | } |
| 2619 | } |
| 2620 | return linePrefix; |
| 2621 | } |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 2622 | |
| 2623 | /** |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2624 | * 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] | 2625 | * |
| 2626 | * @param pw a PrintWriter object to print to. |
| 2627 | * @param sb a StringBuilder object. |
| 2628 | * @param timer a Timer object contining the wakelock times. |
| 2629 | * @param rawRealtime the current on-battery time in microseconds. |
| 2630 | * @param which which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT. |
| 2631 | * @param prefix a String to be prepended to each line of output. |
| 2632 | * @param type the name of the timer. |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2633 | * @return true if anything was printed. |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 2634 | */ |
| 2635 | private static final boolean printTimer(PrintWriter pw, StringBuilder sb, Timer timer, |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2636 | long rawRealtimeUs, int which, String prefix, String type) { |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 2637 | if (timer != null) { |
| 2638 | // Convert from microseconds to milliseconds with rounding |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2639 | final long totalTimeMs = (timer.getTotalTimeLocked( |
| 2640 | rawRealtimeUs, which) + 500) / 1000; |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 2641 | final int count = timer.getCountLocked(which); |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2642 | if (totalTimeMs != 0) { |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 2643 | sb.setLength(0); |
| 2644 | sb.append(prefix); |
| 2645 | sb.append(" "); |
| 2646 | sb.append(type); |
| 2647 | sb.append(": "); |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2648 | formatTimeMs(sb, totalTimeMs); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 2649 | sb.append("realtime ("); |
| 2650 | sb.append(count); |
| 2651 | sb.append(" times)"); |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2652 | final long maxDurationMs = timer.getMaxDurationMsLocked(rawRealtimeUs/1000); |
| 2653 | if (maxDurationMs >= 0) { |
| 2654 | sb.append(" max="); |
| 2655 | sb.append(maxDurationMs); |
| 2656 | } |
| 2657 | if (timer.isRunningLocked()) { |
| 2658 | final long currentMs = timer.getCurrentDurationMsLocked(rawRealtimeUs/1000); |
| 2659 | if (currentMs >= 0) { |
| 2660 | sb.append(" (running for "); |
| 2661 | sb.append(currentMs); |
| 2662 | sb.append("ms)"); |
| 2663 | } else { |
| 2664 | sb.append(" (running)"); |
| 2665 | } |
| 2666 | } |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 2667 | pw.println(sb.toString()); |
| 2668 | return true; |
| 2669 | } |
| 2670 | } |
| 2671 | return false; |
| 2672 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2673 | |
| 2674 | /** |
| 2675 | * Checkin version of wakelock printer. Prints simple comma-separated list. |
| 2676 | * |
| 2677 | * @param sb a StringBuilder object. |
| 2678 | * @param timer a Timer object contining the wakelock times. |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2679 | * @param elapsedRealtimeUs the current time in microseconds. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2680 | * @param name the name of the wakelock. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 2681 | * @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] | 2682 | * @param linePrefix a String to be prepended to each line of output. |
| 2683 | * @return the line prefix |
| 2684 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2685 | private static final String printWakeLockCheckin(StringBuilder sb, Timer timer, |
| 2686 | long elapsedRealtimeUs, String name, int which, String linePrefix) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2687 | long totalTimeMicros = 0; |
| 2688 | int count = 0; |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2689 | long max = -1; |
| 2690 | long current = -1; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2691 | if (timer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2692 | totalTimeMicros = timer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2693 | count = timer.getCountLocked(which); |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2694 | current = timer.getCurrentDurationMsLocked(elapsedRealtimeUs/1000); |
| 2695 | max = timer.getMaxDurationMsLocked(elapsedRealtimeUs/1000); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2696 | } |
| 2697 | sb.append(linePrefix); |
| 2698 | sb.append((totalTimeMicros + 500) / 1000); // microseconds to milliseconds with rounding |
| 2699 | sb.append(','); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2700 | sb.append(name != null ? name + "," : ""); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2701 | sb.append(count); |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 2702 | sb.append(','); |
| 2703 | sb.append(current); |
| 2704 | sb.append(','); |
| 2705 | sb.append(max); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2706 | return ","; |
| 2707 | } |
| 2708 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 2709 | private static final void dumpLineHeader(PrintWriter pw, int uid, String category, |
| 2710 | String type) { |
| 2711 | pw.print(BATTERY_STATS_CHECKIN_VERSION); |
| 2712 | pw.print(','); |
| 2713 | pw.print(uid); |
| 2714 | pw.print(','); |
| 2715 | pw.print(category); |
| 2716 | pw.print(','); |
| 2717 | pw.print(type); |
| 2718 | } |
| 2719 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2720 | /** |
| 2721 | * Dump a comma-separated line of values for terse checkin mode. |
| 2722 | * |
| 2723 | * @param pw the PageWriter to dump log to |
| 2724 | * @param category category of data (e.g. "total", "last", "unplugged", "current" ) |
| 2725 | * @param type type of data (e.g. "wakelock", "sensor", "process", "apk" , "process", "network") |
| 2726 | * @param args type-dependent data arguments |
| 2727 | */ |
| 2728 | private static final void dumpLine(PrintWriter pw, int uid, String category, String type, |
| 2729 | Object... args ) { |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 2730 | dumpLineHeader(pw, uid, category, type); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 2731 | for (Object arg : args) { |
Dianne Hackborn | 13ac041 | 2013-06-25 19:34:49 -0700 | [diff] [blame] | 2732 | pw.print(','); |
| 2733 | pw.print(arg); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2734 | } |
Dianne Hackborn | 13ac041 | 2013-06-25 19:34:49 -0700 | [diff] [blame] | 2735 | pw.println(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2736 | } |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 2737 | |
| 2738 | /** |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 2739 | * Dump a given timer stat for terse checkin mode. |
| 2740 | * |
| 2741 | * @param pw the PageWriter to dump log to |
| 2742 | * @param uid the UID to log |
| 2743 | * @param category category of data (e.g. "total", "last", "unplugged", "current" ) |
| 2744 | * @param type type of data (e.g. "wakelock", "sensor", "process", "apk" , "process", "network") |
| 2745 | * @param timer a {@link Timer} to dump stats for |
| 2746 | * @param rawRealtime the current elapsed realtime of the system in microseconds |
| 2747 | * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT |
| 2748 | */ |
| 2749 | private static final void dumpTimer(PrintWriter pw, int uid, String category, String type, |
| 2750 | Timer timer, long rawRealtime, int which) { |
| 2751 | if (timer != null) { |
| 2752 | // Convert from microseconds to milliseconds with rounding |
| 2753 | final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) |
| 2754 | / 1000; |
| 2755 | final int count = timer.getCountLocked(which); |
| 2756 | if (totalTime != 0) { |
| 2757 | dumpLine(pw, uid, category, type, totalTime, count); |
| 2758 | } |
| 2759 | } |
| 2760 | } |
| 2761 | |
| 2762 | /** |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 2763 | * Checks if the ControllerActivityCounter has any data worth dumping. |
| 2764 | */ |
| 2765 | private static boolean controllerActivityHasData(ControllerActivityCounter counter, int which) { |
| 2766 | if (counter == null) { |
| 2767 | return false; |
| 2768 | } |
| 2769 | |
| 2770 | if (counter.getIdleTimeCounter().getCountLocked(which) != 0 |
| 2771 | || counter.getRxTimeCounter().getCountLocked(which) != 0 |
| 2772 | || counter.getPowerCounter().getCountLocked(which) != 0) { |
| 2773 | return true; |
| 2774 | } |
| 2775 | |
| 2776 | for (LongCounter c : counter.getTxTimeCounters()) { |
| 2777 | if (c.getCountLocked(which) != 0) { |
| 2778 | return true; |
| 2779 | } |
| 2780 | } |
| 2781 | return false; |
| 2782 | } |
| 2783 | |
| 2784 | /** |
| 2785 | * Dumps the ControllerActivityCounter if it has any data worth dumping. |
| 2786 | * The order of the arguments in the final check in line is: |
| 2787 | * |
| 2788 | * idle, rx, power, tx... |
| 2789 | * |
| 2790 | * where tx... is one or more transmit level times. |
| 2791 | */ |
| 2792 | private static final void dumpControllerActivityLine(PrintWriter pw, int uid, String category, |
| 2793 | String type, |
| 2794 | ControllerActivityCounter counter, |
| 2795 | int which) { |
| 2796 | if (!controllerActivityHasData(counter, which)) { |
| 2797 | return; |
| 2798 | } |
| 2799 | |
| 2800 | dumpLineHeader(pw, uid, category, type); |
| 2801 | pw.print(","); |
| 2802 | pw.print(counter.getIdleTimeCounter().getCountLocked(which)); |
| 2803 | pw.print(","); |
| 2804 | pw.print(counter.getRxTimeCounter().getCountLocked(which)); |
| 2805 | pw.print(","); |
| 2806 | pw.print(counter.getPowerCounter().getCountLocked(which) / (1000 * 60 * 60)); |
| 2807 | for (LongCounter c : counter.getTxTimeCounters()) { |
| 2808 | pw.print(","); |
| 2809 | pw.print(c.getCountLocked(which)); |
| 2810 | } |
| 2811 | pw.println(); |
| 2812 | } |
| 2813 | |
| 2814 | private final void printControllerActivityIfInteresting(PrintWriter pw, StringBuilder sb, |
| 2815 | String prefix, String controllerName, |
| 2816 | ControllerActivityCounter counter, |
| 2817 | int which) { |
| 2818 | if (controllerActivityHasData(counter, which)) { |
| 2819 | printControllerActivity(pw, sb, prefix, controllerName, counter, which); |
| 2820 | } |
| 2821 | } |
| 2822 | |
| 2823 | private final void printControllerActivity(PrintWriter pw, StringBuilder sb, String prefix, |
| 2824 | String controllerName, |
| 2825 | ControllerActivityCounter counter, int which) { |
| 2826 | final long idleTimeMs = counter.getIdleTimeCounter().getCountLocked(which); |
| 2827 | final long rxTimeMs = counter.getRxTimeCounter().getCountLocked(which); |
| 2828 | final long powerDrainMaMs = counter.getPowerCounter().getCountLocked(which); |
| 2829 | long totalTxTimeMs = 0; |
| 2830 | for (LongCounter txState : counter.getTxTimeCounters()) { |
| 2831 | totalTxTimeMs += txState.getCountLocked(which); |
| 2832 | } |
| 2833 | |
| 2834 | final long totalTimeMs = idleTimeMs + rxTimeMs + totalTxTimeMs; |
| 2835 | |
| 2836 | sb.setLength(0); |
| 2837 | sb.append(prefix); |
| 2838 | sb.append(" "); |
| 2839 | sb.append(controllerName); |
| 2840 | sb.append(" Idle time: "); |
| 2841 | formatTimeMs(sb, idleTimeMs); |
| 2842 | sb.append("("); |
| 2843 | sb.append(formatRatioLocked(idleTimeMs, totalTimeMs)); |
| 2844 | sb.append(")"); |
| 2845 | pw.println(sb.toString()); |
| 2846 | |
| 2847 | sb.setLength(0); |
| 2848 | sb.append(prefix); |
| 2849 | sb.append(" "); |
| 2850 | sb.append(controllerName); |
| 2851 | sb.append(" Rx time: "); |
| 2852 | formatTimeMs(sb, rxTimeMs); |
| 2853 | sb.append("("); |
| 2854 | sb.append(formatRatioLocked(rxTimeMs, totalTimeMs)); |
| 2855 | sb.append(")"); |
| 2856 | pw.println(sb.toString()); |
| 2857 | |
| 2858 | sb.setLength(0); |
| 2859 | sb.append(prefix); |
| 2860 | sb.append(" "); |
| 2861 | sb.append(controllerName); |
| 2862 | sb.append(" Tx time: "); |
| 2863 | formatTimeMs(sb, totalTxTimeMs); |
| 2864 | sb.append("("); |
| 2865 | sb.append(formatRatioLocked(totalTxTimeMs, totalTimeMs)); |
| 2866 | sb.append(")"); |
| 2867 | pw.println(sb.toString()); |
| 2868 | |
| 2869 | final int numTxLvls = counter.getTxTimeCounters().length; |
| 2870 | if (numTxLvls > 1) { |
| 2871 | for (int lvl = 0; lvl < numTxLvls; lvl++) { |
| 2872 | final long txLvlTimeMs = counter.getTxTimeCounters()[lvl].getCountLocked(which); |
| 2873 | sb.setLength(0); |
| 2874 | sb.append(prefix); |
| 2875 | sb.append(" ["); |
| 2876 | sb.append(lvl); |
| 2877 | sb.append("] "); |
| 2878 | formatTimeMs(sb, txLvlTimeMs); |
| 2879 | sb.append("("); |
| 2880 | sb.append(formatRatioLocked(txLvlTimeMs, totalTxTimeMs)); |
| 2881 | sb.append(")"); |
| 2882 | pw.println(sb.toString()); |
| 2883 | } |
| 2884 | } |
| 2885 | |
| 2886 | sb.setLength(0); |
| 2887 | sb.append(prefix); |
| 2888 | sb.append(" "); |
| 2889 | sb.append(controllerName); |
| 2890 | sb.append(" Power drain: ").append( |
| 2891 | BatteryStatsHelper.makemAh(powerDrainMaMs / (double) (1000*60*60))); |
| 2892 | sb.append("mAh"); |
| 2893 | pw.println(sb.toString()); |
| 2894 | } |
| 2895 | |
| 2896 | /** |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 2897 | * Temporary for settings. |
| 2898 | */ |
| 2899 | public final void dumpCheckinLocked(Context context, PrintWriter pw, int which, int reqUid) { |
| 2900 | dumpCheckinLocked(context, pw, which, reqUid, BatteryStatsHelper.checkWifiOnly(context)); |
| 2901 | } |
| 2902 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2903 | /** |
| 2904 | * Checkin server version of dump to produce more compact, computer-readable log. |
| 2905 | * |
| 2906 | * NOTE: all times are expressed in 'ms'. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2907 | */ |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 2908 | public final void dumpCheckinLocked(Context context, PrintWriter pw, int which, int reqUid, |
| 2909 | boolean wifiOnly) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2910 | final long rawUptime = SystemClock.uptimeMillis() * 1000; |
| 2911 | final long rawRealtime = SystemClock.elapsedRealtime() * 1000; |
| 2912 | final long batteryUptime = getBatteryUptime(rawUptime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2913 | final long whichBatteryUptime = computeBatteryUptime(rawUptime, which); |
| 2914 | final long whichBatteryRealtime = computeBatteryRealtime(rawRealtime, which); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2915 | final long whichBatteryScreenOffUptime = computeBatteryScreenOffUptime(rawUptime, which); |
| 2916 | final long whichBatteryScreenOffRealtime = computeBatteryScreenOffRealtime(rawRealtime, |
| 2917 | which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2918 | final long totalRealtime = computeRealtime(rawRealtime, which); |
| 2919 | final long totalUptime = computeUptime(rawUptime, which); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2920 | final long screenOnTime = getScreenOnTime(rawRealtime, which); |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 2921 | final long interactiveTime = getInteractiveTime(rawRealtime, which); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 2922 | final long powerSaveModeEnabledTime = getPowerSaveModeEnabledTime(rawRealtime, which); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 2923 | final long deviceIdleModeLightTime = getDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT, |
| 2924 | rawRealtime, which); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 2925 | final long deviceIdleModeFullTime = getDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP, |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 2926 | rawRealtime, which); |
| 2927 | final long deviceLightIdlingTime = getDeviceIdlingTime(DEVICE_IDLE_MODE_LIGHT, |
| 2928 | rawRealtime, which); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 2929 | final long deviceIdlingTime = getDeviceIdlingTime(DEVICE_IDLE_MODE_DEEP, |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 2930 | rawRealtime, which); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 2931 | final int connChanges = getNumConnectivityChange(which); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2932 | final long phoneOnTime = getPhoneOnTime(rawRealtime, which); |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 2933 | final long dischargeCount = getDischargeCoulombCounter().getCountLocked(which); |
| 2934 | final long dischargeScreenOffCount = getDischargeScreenOffCoulombCounter() |
| 2935 | .getCountLocked(which); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 2936 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 2937 | final StringBuilder sb = new StringBuilder(128); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2938 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 2939 | final SparseArray<? extends Uid> uidStats = getUidStats(); |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 2940 | final int NU = uidStats.size(); |
| 2941 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 2942 | final String category = STAT_NAMES[which]; |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 2943 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2944 | // Dump "battery" stat |
| 2945 | dumpLine(pw, 0 /* uid */, category, BATTERY_DATA, |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2946 | which == STATS_SINCE_CHARGED ? getStartCount() : "N/A", |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 2947 | whichBatteryRealtime / 1000, whichBatteryUptime / 1000, |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 2948 | totalRealtime / 1000, totalUptime / 1000, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2949 | getStartClockTime(), |
Adam Lesinski | f9b20a9 | 2016-06-17 17:30:01 -0700 | [diff] [blame] | 2950 | whichBatteryScreenOffRealtime / 1000, whichBatteryScreenOffUptime / 1000, |
| 2951 | getEstimatedBatteryCapacity()); |
Adam Lesinski | 67c134f | 2016-06-10 15:15:08 -0700 | [diff] [blame] | 2952 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2953 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2954 | // Calculate wakelock times across all uids. |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 2955 | long fullWakeLockTimeTotal = 0; |
| 2956 | long partialWakeLockTimeTotal = 0; |
| 2957 | |
| 2958 | for (int iu = 0; iu < NU; iu++) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 2959 | final Uid u = uidStats.valueAt(iu); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 2960 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 2961 | final ArrayMap<String, ? extends BatteryStats.Uid.Wakelock> wakelocks |
| 2962 | = u.getWakelockStats(); |
| 2963 | for (int iw=wakelocks.size()-1; iw>=0; iw--) { |
| 2964 | final Uid.Wakelock wl = wakelocks.valueAt(iw); |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 2965 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 2966 | final Timer fullWakeTimer = wl.getWakeTime(WAKE_TYPE_FULL); |
| 2967 | if (fullWakeTimer != null) { |
| 2968 | fullWakeLockTimeTotal += fullWakeTimer.getTotalTimeLocked(rawRealtime, |
| 2969 | which); |
| 2970 | } |
| 2971 | |
| 2972 | final Timer partialWakeTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL); |
| 2973 | if (partialWakeTimer != null) { |
| 2974 | partialWakeLockTimeTotal += partialWakeTimer.getTotalTimeLocked( |
| 2975 | rawRealtime, which); |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 2976 | } |
| 2977 | } |
| 2978 | } |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 2979 | |
| 2980 | // Dump network stats |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 2981 | final long mobileRxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which); |
| 2982 | final long mobileTxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which); |
| 2983 | final long wifiRxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which); |
| 2984 | final long wifiTxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which); |
| 2985 | final long mobileRxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which); |
| 2986 | final long mobileTxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which); |
| 2987 | final long wifiRxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which); |
| 2988 | final long wifiTxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 2989 | final long btRxTotalBytes = getNetworkActivityBytes(NETWORK_BT_RX_DATA, which); |
| 2990 | final long btTxTotalBytes = getNetworkActivityBytes(NETWORK_BT_TX_DATA, which); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2991 | dumpLine(pw, 0 /* uid */, category, GLOBAL_NETWORK_DATA, |
| 2992 | mobileRxTotalBytes, mobileTxTotalBytes, wifiRxTotalBytes, wifiTxTotalBytes, |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 2993 | mobileRxTotalPackets, mobileTxTotalPackets, wifiRxTotalPackets, wifiTxTotalPackets, |
| 2994 | btRxTotalBytes, btTxTotalBytes); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2995 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 2996 | // Dump Modem controller stats |
| 2997 | dumpControllerActivityLine(pw, 0 /* uid */, category, GLOBAL_MODEM_CONTROLLER_DATA, |
| 2998 | getModemControllerActivity(), which); |
| 2999 | |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 3000 | // Dump Wifi controller stats |
| 3001 | final long wifiOnTime = getWifiOnTime(rawRealtime, which); |
| 3002 | final long wifiRunningTime = getGlobalWifiRunningTime(rawRealtime, which); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3003 | dumpLine(pw, 0 /* uid */, category, GLOBAL_WIFI_DATA, wifiOnTime / 1000, |
Adam Lesinski | 2208e74 | 2016-02-19 12:53:31 -0800 | [diff] [blame] | 3004 | wifiRunningTime / 1000, /* legacy fields follow, keep at 0 */ 0, 0, 0); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3005 | |
| 3006 | dumpControllerActivityLine(pw, 0 /* uid */, category, GLOBAL_WIFI_CONTROLLER_DATA, |
| 3007 | getWifiControllerActivity(), which); |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 3008 | |
| 3009 | // Dump Bluetooth controller stats |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3010 | dumpControllerActivityLine(pw, 0 /* uid */, category, GLOBAL_BLUETOOTH_CONTROLLER_DATA, |
| 3011 | getBluetoothControllerActivity(), which); |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 3012 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3013 | // Dump misc stats |
| 3014 | dumpLine(pw, 0 /* uid */, category, MISC_DATA, |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 3015 | screenOnTime / 1000, phoneOnTime / 1000, |
Ashish Sharma | 213bb2f | 2014-07-07 17:14:52 -0700 | [diff] [blame] | 3016 | fullWakeLockTimeTotal / 1000, partialWakeLockTimeTotal / 1000, |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 3017 | getMobileRadioActiveTime(rawRealtime, which) / 1000, |
Ashish Sharma | 213bb2f | 2014-07-07 17:14:52 -0700 | [diff] [blame] | 3018 | getMobileRadioActiveAdjustedTime(which) / 1000, interactiveTime / 1000, |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3019 | powerSaveModeEnabledTime / 1000, connChanges, deviceIdleModeFullTime / 1000, |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 3020 | getDeviceIdleModeCount(DEVICE_IDLE_MODE_DEEP, which), deviceIdlingTime / 1000, |
| 3021 | getDeviceIdlingCount(DEVICE_IDLE_MODE_DEEP, which), |
Adam Lesinski | 782327b | 2015-07-30 16:36:29 -0700 | [diff] [blame] | 3022 | getMobileRadioActiveCount(which), |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3023 | getMobileRadioActiveUnknownTime(which) / 1000, deviceIdleModeLightTime / 1000, |
| 3024 | getDeviceIdleModeCount(DEVICE_IDLE_MODE_LIGHT, which), deviceLightIdlingTime / 1000, |
| 3025 | getDeviceIdlingCount(DEVICE_IDLE_MODE_LIGHT, which), |
| 3026 | getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT), |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 3027 | getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP)); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3028 | |
| 3029 | // Dump screen brightness stats |
| 3030 | Object[] args = new Object[NUM_SCREEN_BRIGHTNESS_BINS]; |
| 3031 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3032 | args[i] = getScreenBrightnessTime(i, rawRealtime, which) / 1000; |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3033 | } |
| 3034 | dumpLine(pw, 0 /* uid */, category, SCREEN_BRIGHTNESS_DATA, args); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3035 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3036 | // Dump signal strength stats |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 3037 | args = new Object[SignalStrength.NUM_SIGNAL_STRENGTH_BINS]; |
| 3038 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3039 | args[i] = getPhoneSignalStrengthTime(i, rawRealtime, which) / 1000; |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3040 | } |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3041 | dumpLine(pw, 0 /* uid */, category, SIGNAL_STRENGTH_TIME_DATA, args); |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 3042 | dumpLine(pw, 0 /* uid */, category, SIGNAL_SCANNING_TIME_DATA, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3043 | getPhoneSignalScanningTime(rawRealtime, which) / 1000); |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 3044 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3045 | args[i] = getPhoneSignalStrengthCount(i, which); |
| 3046 | } |
| 3047 | dumpLine(pw, 0 /* uid */, category, SIGNAL_STRENGTH_COUNT_DATA, args); |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 3048 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3049 | // Dump network type stats |
| 3050 | args = new Object[NUM_DATA_CONNECTION_TYPES]; |
| 3051 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3052 | args[i] = getPhoneDataConnectionTime(i, rawRealtime, which) / 1000; |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3053 | } |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3054 | dumpLine(pw, 0 /* uid */, category, DATA_CONNECTION_TIME_DATA, args); |
| 3055 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
| 3056 | args[i] = getPhoneDataConnectionCount(i, which); |
| 3057 | } |
| 3058 | dumpLine(pw, 0 /* uid */, category, DATA_CONNECTION_COUNT_DATA, args); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3059 | |
| 3060 | // Dump wifi state stats |
| 3061 | args = new Object[NUM_WIFI_STATES]; |
| 3062 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3063 | args[i] = getWifiStateTime(i, rawRealtime, which) / 1000; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3064 | } |
| 3065 | dumpLine(pw, 0 /* uid */, category, WIFI_STATE_TIME_DATA, args); |
| 3066 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
| 3067 | args[i] = getWifiStateCount(i, which); |
| 3068 | } |
| 3069 | dumpLine(pw, 0 /* uid */, category, WIFI_STATE_COUNT_DATA, args); |
| 3070 | |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 3071 | // Dump wifi suppl state stats |
| 3072 | args = new Object[NUM_WIFI_SUPPL_STATES]; |
| 3073 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
| 3074 | args[i] = getWifiSupplStateTime(i, rawRealtime, which) / 1000; |
| 3075 | } |
| 3076 | dumpLine(pw, 0 /* uid */, category, WIFI_SUPPL_STATE_TIME_DATA, args); |
| 3077 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
| 3078 | args[i] = getWifiSupplStateCount(i, which); |
| 3079 | } |
| 3080 | dumpLine(pw, 0 /* uid */, category, WIFI_SUPPL_STATE_COUNT_DATA, args); |
| 3081 | |
| 3082 | // Dump wifi signal strength stats |
| 3083 | args = new Object[NUM_WIFI_SIGNAL_STRENGTH_BINS]; |
| 3084 | for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 3085 | args[i] = getWifiSignalStrengthTime(i, rawRealtime, which) / 1000; |
| 3086 | } |
| 3087 | dumpLine(pw, 0 /* uid */, category, WIFI_SIGNAL_STRENGTH_TIME_DATA, args); |
| 3088 | for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 3089 | args[i] = getWifiSignalStrengthCount(i, which); |
| 3090 | } |
| 3091 | dumpLine(pw, 0 /* uid */, category, WIFI_SIGNAL_STRENGTH_COUNT_DATA, args); |
| 3092 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3093 | if (which == STATS_SINCE_UNPLUGGED) { |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 3094 | dumpLine(pw, 0 /* uid */, category, BATTERY_LEVEL_DATA, getDischargeStartLevel(), |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 3095 | getDischargeCurrentLevel()); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3096 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3097 | |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 3098 | if (which == STATS_SINCE_UNPLUGGED) { |
| 3099 | dumpLine(pw, 0 /* uid */, category, BATTERY_DISCHARGE_DATA, |
| 3100 | getDischargeStartLevel()-getDischargeCurrentLevel(), |
| 3101 | getDischargeStartLevel()-getDischargeCurrentLevel(), |
Adam Lesinski | 67c134f | 2016-06-10 15:15:08 -0700 | [diff] [blame] | 3102 | getDischargeAmountScreenOn(), getDischargeAmountScreenOff(), |
| 3103 | dischargeCount / 1000, dischargeScreenOffCount / 1000); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 3104 | } else { |
| 3105 | dumpLine(pw, 0 /* uid */, category, BATTERY_DISCHARGE_DATA, |
| 3106 | getLowDischargeAmountSinceCharge(), getHighDischargeAmountSinceCharge(), |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 3107 | getDischargeAmountScreenOnSinceCharge(), |
Adam Lesinski | 67c134f | 2016-06-10 15:15:08 -0700 | [diff] [blame] | 3108 | getDischargeAmountScreenOffSinceCharge(), |
| 3109 | dischargeCount / 1000, dischargeScreenOffCount / 1000); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 3110 | } |
| 3111 | |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 3112 | if (reqUid < 0) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3113 | final Map<String, ? extends Timer> kernelWakelocks = getKernelWakelockStats(); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 3114 | if (kernelWakelocks.size() > 0) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3115 | for (Map.Entry<String, ? extends Timer> ent : kernelWakelocks.entrySet()) { |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 3116 | sb.setLength(0); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3117 | printWakeLockCheckin(sb, ent.getValue(), rawRealtime, null, which, ""); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3118 | dumpLine(pw, 0 /* uid */, category, KERNEL_WAKELOCK_DATA, ent.getKey(), |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 3119 | sb.toString()); |
| 3120 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 3121 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3122 | final Map<String, ? extends Timer> wakeupReasons = getWakeupReasonStats(); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3123 | if (wakeupReasons.size() > 0) { |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 3124 | for (Map.Entry<String, ? extends Timer> ent : wakeupReasons.entrySet()) { |
| 3125 | // Not doing the regular wake lock formatting to remain compatible |
| 3126 | // with the old checkin format. |
| 3127 | long totalTimeMicros = ent.getValue().getTotalTimeLocked(rawRealtime, which); |
| 3128 | int count = ent.getValue().getCountLocked(which); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3129 | dumpLine(pw, 0 /* uid */, category, WAKEUP_REASON_DATA, |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 3130 | "\"" + ent.getKey() + "\"", (totalTimeMicros + 500) / 1000, count); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3131 | } |
| 3132 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 3133 | } |
| 3134 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3135 | final BatteryStatsHelper helper = new BatteryStatsHelper(context, false, wifiOnly); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3136 | helper.create(this); |
| 3137 | helper.refreshStats(which, UserHandle.USER_ALL); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3138 | final List<BatterySipper> sippers = helper.getUsageList(); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3139 | if (sippers != null && sippers.size() > 0) { |
| 3140 | dumpLine(pw, 0 /* uid */, category, POWER_USE_SUMMARY_DATA, |
| 3141 | BatteryStatsHelper.makemAh(helper.getPowerProfile().getBatteryCapacity()), |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3142 | BatteryStatsHelper.makemAh(helper.getComputedPower()), |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3143 | BatteryStatsHelper.makemAh(helper.getMinDrainedPower()), |
| 3144 | BatteryStatsHelper.makemAh(helper.getMaxDrainedPower())); |
| 3145 | for (int i=0; i<sippers.size(); i++) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3146 | final BatterySipper bs = sippers.get(i); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3147 | int uid = 0; |
| 3148 | String label; |
| 3149 | switch (bs.drainType) { |
| 3150 | case IDLE: |
| 3151 | label="idle"; |
| 3152 | break; |
| 3153 | case CELL: |
| 3154 | label="cell"; |
| 3155 | break; |
| 3156 | case PHONE: |
| 3157 | label="phone"; |
| 3158 | break; |
| 3159 | case WIFI: |
| 3160 | label="wifi"; |
| 3161 | break; |
| 3162 | case BLUETOOTH: |
| 3163 | label="blue"; |
| 3164 | break; |
| 3165 | case SCREEN: |
| 3166 | label="scrn"; |
| 3167 | break; |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 3168 | case FLASHLIGHT: |
| 3169 | label="flashlight"; |
| 3170 | break; |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3171 | case APP: |
| 3172 | uid = bs.uidObj.getUid(); |
| 3173 | label = "uid"; |
| 3174 | break; |
| 3175 | case USER: |
| 3176 | uid = UserHandle.getUid(bs.userId, 0); |
| 3177 | label = "user"; |
| 3178 | break; |
| 3179 | case UNACCOUNTED: |
| 3180 | label = "unacc"; |
| 3181 | break; |
| 3182 | case OVERCOUNTED: |
| 3183 | label = "over"; |
| 3184 | break; |
Ruben Brunk | 5b1308f | 2015-06-03 18:49:27 -0700 | [diff] [blame] | 3185 | case CAMERA: |
| 3186 | label = "camera"; |
| 3187 | break; |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3188 | default: |
| 3189 | label = "???"; |
| 3190 | } |
| 3191 | dumpLine(pw, uid, category, POWER_USE_ITEM_DATA, label, |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 3192 | BatteryStatsHelper.makemAh(bs.totalPowerMah)); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3193 | } |
| 3194 | } |
| 3195 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3196 | for (int iu = 0; iu < NU; iu++) { |
| 3197 | final int uid = uidStats.keyAt(iu); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 3198 | if (reqUid >= 0 && uid != reqUid) { |
| 3199 | continue; |
| 3200 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3201 | final Uid u = uidStats.valueAt(iu); |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 3202 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3203 | // Dump Network stats per uid, if any |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3204 | final long mobileBytesRx = u.getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which); |
| 3205 | final long mobileBytesTx = u.getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which); |
| 3206 | final long wifiBytesRx = u.getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which); |
| 3207 | final long wifiBytesTx = u.getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which); |
| 3208 | final long mobilePacketsRx = u.getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which); |
| 3209 | final long mobilePacketsTx = u.getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which); |
| 3210 | final long mobileActiveTime = u.getMobileRadioActiveTime(which); |
| 3211 | final int mobileActiveCount = u.getMobileRadioActiveCount(which); |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 3212 | final long mobileWakeup = u.getMobileRadioApWakeupCount(which); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3213 | final long wifiPacketsRx = u.getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which); |
| 3214 | final long wifiPacketsTx = u.getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which); |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 3215 | final long wifiWakeup = u.getWifiRadioApWakeupCount(which); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 3216 | final long btBytesRx = u.getNetworkActivityBytes(NETWORK_BT_RX_DATA, which); |
| 3217 | final long btBytesTx = u.getNetworkActivityBytes(NETWORK_BT_TX_DATA, which); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3218 | if (mobileBytesRx > 0 || mobileBytesTx > 0 || wifiBytesRx > 0 || wifiBytesTx > 0 |
| 3219 | || mobilePacketsRx > 0 || mobilePacketsTx > 0 || wifiPacketsRx > 0 |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 3220 | || wifiPacketsTx > 0 || mobileActiveTime > 0 || mobileActiveCount > 0 |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 3221 | || btBytesRx > 0 || btBytesTx > 0 || mobileWakeup > 0 || wifiWakeup > 0) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3222 | dumpLine(pw, uid, category, NETWORK_DATA, mobileBytesRx, mobileBytesTx, |
| 3223 | wifiBytesRx, wifiBytesTx, |
| 3224 | mobilePacketsRx, mobilePacketsTx, |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 3225 | wifiPacketsRx, wifiPacketsTx, |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 3226 | mobileActiveTime, mobileActiveCount, |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 3227 | btBytesRx, btBytesTx, mobileWakeup, wifiWakeup); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 3228 | } |
| 3229 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3230 | // Dump modem controller data, per UID. |
| 3231 | dumpControllerActivityLine(pw, uid, category, MODEM_CONTROLLER_DATA, |
| 3232 | u.getModemControllerActivity(), which); |
| 3233 | |
| 3234 | // Dump Wifi controller data, per UID. |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 3235 | final long fullWifiLockOnTime = u.getFullWifiLockTime(rawRealtime, which); |
| 3236 | final long wifiScanTime = u.getWifiScanTime(rawRealtime, which); |
| 3237 | final int wifiScanCount = u.getWifiScanCount(which); |
| 3238 | final long uidWifiRunningTime = u.getWifiRunningTime(rawRealtime, which); |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 3239 | if (fullWifiLockOnTime != 0 || wifiScanTime != 0 || wifiScanCount != 0 |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3240 | || uidWifiRunningTime != 0) { |
| 3241 | dumpLine(pw, uid, category, WIFI_DATA, fullWifiLockOnTime, wifiScanTime, |
| 3242 | uidWifiRunningTime, wifiScanCount, |
Kweku Adams | 5b2747e | 2016-04-25 10:44:05 -0700 | [diff] [blame] | 3243 | /* legacy fields follow, keep at 0 */ 0, 0, 0); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3244 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3245 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3246 | dumpControllerActivityLine(pw, uid, category, WIFI_CONTROLLER_DATA, |
| 3247 | u.getWifiControllerActivity(), which); |
| 3248 | |
Adam Lesinski | ba9d893 | 2016-04-12 12:06:03 -0700 | [diff] [blame] | 3249 | dumpTimer(pw, uid, category, BLUETOOTH_MISC_DATA, u.getBluetoothScanTimer(), |
Adam Lesinski | d9b99be | 2016-03-30 16:58:51 -0700 | [diff] [blame] | 3250 | rawRealtime, which); |
Adam Lesinski | d9b99be | 2016-03-30 16:58:51 -0700 | [diff] [blame] | 3251 | |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 3252 | dumpControllerActivityLine(pw, uid, category, BLUETOOTH_CONTROLLER_DATA, |
| 3253 | u.getBluetoothControllerActivity(), which); |
| 3254 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3255 | if (u.hasUserActivity()) { |
| 3256 | args = new Object[Uid.NUM_USER_ACTIVITY_TYPES]; |
| 3257 | boolean hasData = false; |
| 3258 | for (int i=0; i<Uid.NUM_USER_ACTIVITY_TYPES; i++) { |
| 3259 | int val = u.getUserActivityCount(i, which); |
| 3260 | args[i] = val; |
| 3261 | if (val != 0) hasData = true; |
| 3262 | } |
| 3263 | if (hasData) { |
Ashish Sharma | cba1215 | 2014-07-07 17:14:52 -0700 | [diff] [blame] | 3264 | dumpLine(pw, uid /* uid */, category, USER_ACTIVITY_DATA, args); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3265 | } |
| 3266 | } |
| 3267 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3268 | final ArrayMap<String, ? extends Uid.Wakelock> wakelocks = u.getWakelockStats(); |
| 3269 | for (int iw=wakelocks.size()-1; iw>=0; iw--) { |
| 3270 | final Uid.Wakelock wl = wakelocks.valueAt(iw); |
| 3271 | String linePrefix = ""; |
| 3272 | sb.setLength(0); |
| 3273 | linePrefix = printWakeLockCheckin(sb, wl.getWakeTime(WAKE_TYPE_FULL), |
| 3274 | rawRealtime, "f", which, linePrefix); |
| 3275 | linePrefix = printWakeLockCheckin(sb, wl.getWakeTime(WAKE_TYPE_PARTIAL), |
| 3276 | rawRealtime, "p", which, linePrefix); |
| 3277 | linePrefix = printWakeLockCheckin(sb, wl.getWakeTime(WAKE_TYPE_WINDOW), |
| 3278 | rawRealtime, "w", which, linePrefix); |
| 3279 | |
| 3280 | // Only log if we had at lease one wakelock... |
| 3281 | if (sb.length() > 0) { |
| 3282 | String name = wakelocks.keyAt(iw); |
| 3283 | if (name.indexOf(',') >= 0) { |
| 3284 | name = name.replace(',', '_'); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3285 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3286 | dumpLine(pw, uid, category, WAKELOCK_DATA, name, sb.toString()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3287 | } |
| 3288 | } |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 3289 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3290 | final ArrayMap<String, ? extends Timer> syncs = u.getSyncStats(); |
| 3291 | for (int isy=syncs.size()-1; isy>=0; isy--) { |
| 3292 | final Timer timer = syncs.valueAt(isy); |
| 3293 | // Convert from microseconds to milliseconds with rounding |
| 3294 | final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000; |
| 3295 | final int count = timer.getCountLocked(which); |
| 3296 | if (totalTime != 0) { |
| 3297 | dumpLine(pw, uid, category, SYNC_DATA, syncs.keyAt(isy), totalTime, count); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 3298 | } |
| 3299 | } |
| 3300 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3301 | final ArrayMap<String, ? extends Timer> jobs = u.getJobStats(); |
| 3302 | for (int ij=jobs.size()-1; ij>=0; ij--) { |
| 3303 | final Timer timer = jobs.valueAt(ij); |
| 3304 | // Convert from microseconds to milliseconds with rounding |
| 3305 | final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000; |
| 3306 | final int count = timer.getCountLocked(which); |
| 3307 | if (totalTime != 0) { |
| 3308 | dumpLine(pw, uid, category, JOB_DATA, jobs.keyAt(ij), totalTime, count); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 3309 | } |
| 3310 | } |
| 3311 | |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 3312 | dumpTimer(pw, uid, category, FLASHLIGHT_DATA, u.getFlashlightTurnedOnTimer(), |
| 3313 | rawRealtime, which); |
| 3314 | dumpTimer(pw, uid, category, CAMERA_DATA, u.getCameraTurnedOnTimer(), |
| 3315 | rawRealtime, which); |
| 3316 | dumpTimer(pw, uid, category, VIDEO_DATA, u.getVideoTurnedOnTimer(), |
| 3317 | rawRealtime, which); |
| 3318 | dumpTimer(pw, uid, category, AUDIO_DATA, u.getAudioTurnedOnTimer(), |
| 3319 | rawRealtime, which); |
| 3320 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3321 | final SparseArray<? extends BatteryStats.Uid.Sensor> sensors = u.getSensorStats(); |
| 3322 | final int NSE = sensors.size(); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 3323 | for (int ise=0; ise<NSE; ise++) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3324 | final Uid.Sensor se = sensors.valueAt(ise); |
| 3325 | final int sensorNumber = sensors.keyAt(ise); |
| 3326 | final Timer timer = se.getSensorTime(); |
Amith Yamasani | ab9ad19 | 2016-12-06 12:46:59 -0800 | [diff] [blame^] | 3327 | final Counter bgCounter = se.getSensorBgCount(); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 3328 | if (timer != null) { |
| 3329 | // Convert from microseconds to milliseconds with rounding |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3330 | final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) |
| 3331 | / 1000; |
| 3332 | final int count = timer.getCountLocked(which); |
Amith Yamasani | ab9ad19 | 2016-12-06 12:46:59 -0800 | [diff] [blame^] | 3333 | final int bgCount = bgCounter != null ? bgCounter.getCountLocked(which) : 0; |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 3334 | if (totalTime != 0) { |
Amith Yamasani | ab9ad19 | 2016-12-06 12:46:59 -0800 | [diff] [blame^] | 3335 | dumpLine(pw, uid, category, SENSOR_DATA, sensorNumber, totalTime, count, |
| 3336 | bgCount); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 3337 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3338 | } |
| 3339 | } |
| 3340 | |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 3341 | dumpTimer(pw, uid, category, VIBRATOR_DATA, u.getVibratorOnTimer(), |
| 3342 | rawRealtime, which); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 3343 | |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 3344 | dumpTimer(pw, uid, category, FOREGROUND_DATA, u.getForegroundActivityTimer(), |
| 3345 | rawRealtime, which); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 3346 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3347 | final Object[] stateTimes = new Object[Uid.NUM_PROCESS_STATE]; |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 3348 | long totalStateTime = 0; |
| 3349 | for (int ips=0; ips<Uid.NUM_PROCESS_STATE; ips++) { |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 3350 | final long time = u.getProcessStateTime(ips, rawRealtime, which); |
| 3351 | totalStateTime += time; |
| 3352 | stateTimes[ips] = (time + 500) / 1000; |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 3353 | } |
| 3354 | if (totalStateTime > 0) { |
| 3355 | dumpLine(pw, uid, category, STATE_TIME_DATA, stateTimes); |
| 3356 | } |
| 3357 | |
Adam Lesinski | a7a4ccc | 2015-06-26 17:43:04 -0700 | [diff] [blame] | 3358 | final long userCpuTimeUs = u.getUserCpuTimeUs(which); |
| 3359 | final long systemCpuTimeUs = u.getSystemCpuTimeUs(which); |
| 3360 | final long powerCpuMaUs = u.getCpuPowerMaUs(which); |
| 3361 | if (userCpuTimeUs > 0 || systemCpuTimeUs > 0 || powerCpuMaUs > 0) { |
| 3362 | dumpLine(pw, uid, category, CPU_DATA, userCpuTimeUs / 1000, systemCpuTimeUs / 1000, |
| 3363 | powerCpuMaUs / 1000); |
| 3364 | } |
| 3365 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3366 | final ArrayMap<String, ? extends BatteryStats.Uid.Proc> processStats |
| 3367 | = u.getProcessStats(); |
| 3368 | for (int ipr=processStats.size()-1; ipr>=0; ipr--) { |
| 3369 | final Uid.Proc ps = processStats.valueAt(ipr); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 3370 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3371 | final long userMillis = ps.getUserTime(which); |
| 3372 | final long systemMillis = ps.getSystemTime(which); |
| 3373 | final long foregroundMillis = ps.getForegroundTime(which); |
| 3374 | final int starts = ps.getStarts(which); |
| 3375 | final int numCrashes = ps.getNumCrashes(which); |
| 3376 | final int numAnrs = ps.getNumAnrs(which); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 3377 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3378 | if (userMillis != 0 || systemMillis != 0 || foregroundMillis != 0 |
| 3379 | || starts != 0 || numAnrs != 0 || numCrashes != 0) { |
| 3380 | dumpLine(pw, uid, category, PROCESS_DATA, processStats.keyAt(ipr), userMillis, |
| 3381 | systemMillis, foregroundMillis, starts, numAnrs, numCrashes); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3382 | } |
| 3383 | } |
| 3384 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3385 | final ArrayMap<String, ? extends BatteryStats.Uid.Pkg> packageStats |
| 3386 | = u.getPackageStats(); |
| 3387 | for (int ipkg=packageStats.size()-1; ipkg>=0; ipkg--) { |
| 3388 | final Uid.Pkg ps = packageStats.valueAt(ipkg); |
| 3389 | int wakeups = 0; |
| 3390 | final ArrayMap<String, ? extends Counter> alarms = ps.getWakeupAlarmStats(); |
| 3391 | for (int iwa=alarms.size()-1; iwa>=0; iwa--) { |
Joe Onorato | 1476d32 | 2016-05-05 14:46:15 -0700 | [diff] [blame] | 3392 | int count = alarms.valueAt(iwa).getCountLocked(which); |
| 3393 | wakeups += count; |
| 3394 | String name = alarms.keyAt(iwa).replace(',', '_'); |
| 3395 | dumpLine(pw, uid, category, WAKEUP_ALARM_DATA, name, count); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3396 | } |
| 3397 | final ArrayMap<String, ? extends Uid.Pkg.Serv> serviceStats = ps.getServiceStats(); |
| 3398 | for (int isvc=serviceStats.size()-1; isvc>=0; isvc--) { |
| 3399 | final BatteryStats.Uid.Pkg.Serv ss = serviceStats.valueAt(isvc); |
| 3400 | final long startTime = ss.getStartTime(batteryUptime, which); |
| 3401 | final int starts = ss.getStarts(which); |
| 3402 | final int launches = ss.getLaunches(which); |
| 3403 | if (startTime != 0 || starts != 0 || launches != 0) { |
| 3404 | dumpLine(pw, uid, category, APK_DATA, |
| 3405 | wakeups, // wakeup alarms |
| 3406 | packageStats.keyAt(ipkg), // Apk |
| 3407 | serviceStats.keyAt(isvc), // service |
| 3408 | startTime / 1000, // time spent started, in ms |
| 3409 | starts, |
| 3410 | launches); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3411 | } |
| 3412 | } |
| 3413 | } |
| 3414 | } |
| 3415 | } |
| 3416 | |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 3417 | static final class TimerEntry { |
| 3418 | final String mName; |
| 3419 | final int mId; |
| 3420 | final BatteryStats.Timer mTimer; |
| 3421 | final long mTime; |
| 3422 | TimerEntry(String name, int id, BatteryStats.Timer timer, long time) { |
| 3423 | mName = name; |
| 3424 | mId = id; |
| 3425 | mTimer = timer; |
| 3426 | mTime = time; |
| 3427 | } |
| 3428 | } |
| 3429 | |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3430 | private void printmAh(PrintWriter printer, double power) { |
| 3431 | printer.print(BatteryStatsHelper.makemAh(power)); |
| 3432 | } |
| 3433 | |
Adam Lesinski | a7a4ccc | 2015-06-26 17:43:04 -0700 | [diff] [blame] | 3434 | private void printmAh(StringBuilder sb, double power) { |
| 3435 | sb.append(BatteryStatsHelper.makemAh(power)); |
| 3436 | } |
| 3437 | |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 3438 | /** |
| 3439 | * Temporary for settings. |
| 3440 | */ |
| 3441 | public final void dumpLocked(Context context, PrintWriter pw, String prefix, int which, |
| 3442 | int reqUid) { |
| 3443 | dumpLocked(context, pw, prefix, which, reqUid, BatteryStatsHelper.checkWifiOnly(context)); |
| 3444 | } |
| 3445 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3446 | @SuppressWarnings("unused") |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3447 | 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] | 3448 | int reqUid, boolean wifiOnly) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3449 | final long rawUptime = SystemClock.uptimeMillis() * 1000; |
| 3450 | final long rawRealtime = SystemClock.elapsedRealtime() * 1000; |
| 3451 | final long batteryUptime = getBatteryUptime(rawUptime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3452 | |
| 3453 | final long whichBatteryUptime = computeBatteryUptime(rawUptime, which); |
| 3454 | final long whichBatteryRealtime = computeBatteryRealtime(rawRealtime, which); |
| 3455 | final long totalRealtime = computeRealtime(rawRealtime, which); |
| 3456 | final long totalUptime = computeUptime(rawUptime, which); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3457 | final long whichBatteryScreenOffUptime = computeBatteryScreenOffUptime(rawUptime, which); |
| 3458 | final long whichBatteryScreenOffRealtime = computeBatteryScreenOffRealtime(rawRealtime, |
| 3459 | which); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 3460 | final long batteryTimeRemaining = computeBatteryTimeRemaining(rawRealtime); |
| 3461 | final long chargeTimeRemaining = computeChargeTimeRemaining(rawRealtime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3462 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3463 | final StringBuilder sb = new StringBuilder(128); |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 3464 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3465 | final SparseArray<? extends Uid> uidStats = getUidStats(); |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 3466 | final int NU = uidStats.size(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3467 | |
Adam Lesinski | f9b20a9 | 2016-06-17 17:30:01 -0700 | [diff] [blame] | 3468 | final int estimatedBatteryCapacity = getEstimatedBatteryCapacity(); |
| 3469 | if (estimatedBatteryCapacity > 0) { |
| 3470 | sb.setLength(0); |
| 3471 | sb.append(prefix); |
| 3472 | sb.append(" Estimated battery capacity: "); |
| 3473 | sb.append(BatteryStatsHelper.makemAh(estimatedBatteryCapacity)); |
| 3474 | sb.append(" mAh"); |
| 3475 | pw.println(sb.toString()); |
| 3476 | } |
| 3477 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3478 | sb.setLength(0); |
| 3479 | sb.append(prefix); |
| 3480 | sb.append(" Time on battery: "); |
| 3481 | formatTimeMs(sb, whichBatteryRealtime / 1000); sb.append("("); |
| 3482 | sb.append(formatRatioLocked(whichBatteryRealtime, totalRealtime)); |
| 3483 | sb.append(") realtime, "); |
| 3484 | formatTimeMs(sb, whichBatteryUptime / 1000); |
| 3485 | sb.append("("); sb.append(formatRatioLocked(whichBatteryUptime, totalRealtime)); |
| 3486 | sb.append(") uptime"); |
| 3487 | pw.println(sb.toString()); |
| 3488 | sb.setLength(0); |
| 3489 | sb.append(prefix); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3490 | sb.append(" Time on battery screen off: "); |
| 3491 | formatTimeMs(sb, whichBatteryScreenOffRealtime / 1000); sb.append("("); |
| 3492 | sb.append(formatRatioLocked(whichBatteryScreenOffRealtime, totalRealtime)); |
| 3493 | sb.append(") realtime, "); |
| 3494 | formatTimeMs(sb, whichBatteryScreenOffUptime / 1000); |
| 3495 | sb.append("("); |
| 3496 | sb.append(formatRatioLocked(whichBatteryScreenOffUptime, totalRealtime)); |
| 3497 | sb.append(") uptime"); |
| 3498 | pw.println(sb.toString()); |
| 3499 | sb.setLength(0); |
| 3500 | sb.append(prefix); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3501 | sb.append(" Total run time: "); |
| 3502 | formatTimeMs(sb, totalRealtime / 1000); |
| 3503 | sb.append("realtime, "); |
| 3504 | formatTimeMs(sb, totalUptime / 1000); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 3505 | sb.append("uptime"); |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 3506 | pw.println(sb.toString()); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 3507 | if (batteryTimeRemaining >= 0) { |
| 3508 | sb.setLength(0); |
| 3509 | sb.append(prefix); |
| 3510 | sb.append(" Battery time remaining: "); |
| 3511 | formatTimeMs(sb, batteryTimeRemaining / 1000); |
| 3512 | pw.println(sb.toString()); |
| 3513 | } |
| 3514 | if (chargeTimeRemaining >= 0) { |
| 3515 | sb.setLength(0); |
| 3516 | sb.append(prefix); |
| 3517 | sb.append(" Charge time remaining: "); |
| 3518 | formatTimeMs(sb, chargeTimeRemaining / 1000); |
| 3519 | pw.println(sb.toString()); |
| 3520 | } |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 3521 | |
| 3522 | final LongCounter dischargeCounter = getDischargeCoulombCounter(); |
| 3523 | final long dischargeCount = dischargeCounter.getCountLocked(which); |
| 3524 | if (dischargeCount >= 0) { |
| 3525 | sb.setLength(0); |
| 3526 | sb.append(prefix); |
| 3527 | sb.append(" Discharge: "); |
| 3528 | sb.append(BatteryStatsHelper.makemAh(dischargeCount / 1000.0)); |
| 3529 | sb.append(" mAh"); |
| 3530 | pw.println(sb.toString()); |
| 3531 | } |
| 3532 | |
| 3533 | final LongCounter dischargeScreenOffCounter = getDischargeScreenOffCoulombCounter(); |
| 3534 | final long dischargeScreenOffCount = dischargeScreenOffCounter.getCountLocked(which); |
| 3535 | if (dischargeScreenOffCount >= 0) { |
| 3536 | sb.setLength(0); |
| 3537 | sb.append(prefix); |
| 3538 | sb.append(" Screen off discharge: "); |
| 3539 | sb.append(BatteryStatsHelper.makemAh(dischargeScreenOffCount / 1000.0)); |
| 3540 | sb.append(" mAh"); |
| 3541 | pw.println(sb.toString()); |
| 3542 | } |
| 3543 | |
| 3544 | final long dischargeScreenOnCount = dischargeCount - dischargeScreenOffCount; |
| 3545 | if (dischargeScreenOnCount >= 0) { |
| 3546 | sb.setLength(0); |
| 3547 | sb.append(prefix); |
| 3548 | sb.append(" Screen on discharge: "); |
| 3549 | sb.append(BatteryStatsHelper.makemAh(dischargeScreenOnCount / 1000.0)); |
| 3550 | sb.append(" mAh"); |
| 3551 | pw.println(sb.toString()); |
| 3552 | } |
| 3553 | |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 3554 | pw.print(" Start clock time: "); |
| 3555 | pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss", getStartClockTime()).toString()); |
| 3556 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3557 | final long screenOnTime = getScreenOnTime(rawRealtime, which); |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 3558 | final long interactiveTime = getInteractiveTime(rawRealtime, which); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3559 | final long powerSaveModeEnabledTime = getPowerSaveModeEnabledTime(rawRealtime, which); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3560 | final long deviceIdleModeLightTime = getDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT, |
| 3561 | rawRealtime, which); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 3562 | final long deviceIdleModeFullTime = getDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP, |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3563 | rawRealtime, which); |
| 3564 | final long deviceLightIdlingTime = getDeviceIdlingTime(DEVICE_IDLE_MODE_LIGHT, |
| 3565 | rawRealtime, which); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 3566 | final long deviceIdlingTime = getDeviceIdlingTime(DEVICE_IDLE_MODE_DEEP, |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3567 | rawRealtime, which); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3568 | final long phoneOnTime = getPhoneOnTime(rawRealtime, which); |
| 3569 | final long wifiRunningTime = getGlobalWifiRunningTime(rawRealtime, which); |
| 3570 | final long wifiOnTime = getWifiOnTime(rawRealtime, which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3571 | sb.setLength(0); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3572 | sb.append(prefix); |
| 3573 | sb.append(" Screen on: "); formatTimeMs(sb, screenOnTime / 1000); |
| 3574 | sb.append("("); sb.append(formatRatioLocked(screenOnTime, whichBatteryRealtime)); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 3575 | sb.append(") "); sb.append(getScreenOnCount(which)); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3576 | sb.append("x, Interactive: "); formatTimeMs(sb, interactiveTime / 1000); |
| 3577 | sb.append("("); sb.append(formatRatioLocked(interactiveTime, whichBatteryRealtime)); |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 3578 | sb.append(")"); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3579 | pw.println(sb.toString()); |
| 3580 | sb.setLength(0); |
| 3581 | sb.append(prefix); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 3582 | sb.append(" Screen brightnesses:"); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3583 | boolean didOne = false; |
| 3584 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3585 | final long time = getScreenBrightnessTime(i, rawRealtime, which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3586 | if (time == 0) { |
| 3587 | continue; |
| 3588 | } |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 3589 | sb.append("\n "); |
| 3590 | sb.append(prefix); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3591 | didOne = true; |
| 3592 | sb.append(SCREEN_BRIGHTNESS_NAMES[i]); |
| 3593 | sb.append(" "); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3594 | formatTimeMs(sb, time/1000); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3595 | sb.append("("); |
| 3596 | sb.append(formatRatioLocked(time, screenOnTime)); |
| 3597 | sb.append(")"); |
| 3598 | } |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 3599 | if (!didOne) sb.append(" (no activity)"); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3600 | pw.println(sb.toString()); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3601 | if (powerSaveModeEnabledTime != 0) { |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3602 | sb.setLength(0); |
| 3603 | sb.append(prefix); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3604 | sb.append(" Power save mode enabled: "); |
| 3605 | formatTimeMs(sb, powerSaveModeEnabledTime / 1000); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3606 | sb.append("("); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3607 | sb.append(formatRatioLocked(powerSaveModeEnabledTime, whichBatteryRealtime)); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3608 | sb.append(")"); |
| 3609 | pw.println(sb.toString()); |
| 3610 | } |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3611 | if (deviceLightIdlingTime != 0) { |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3612 | sb.setLength(0); |
| 3613 | sb.append(prefix); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3614 | sb.append(" Device light idling: "); |
| 3615 | formatTimeMs(sb, deviceLightIdlingTime / 1000); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 3616 | sb.append("("); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3617 | sb.append(formatRatioLocked(deviceLightIdlingTime, whichBatteryRealtime)); |
| 3618 | sb.append(") "); sb.append(getDeviceIdlingCount(DEVICE_IDLE_MODE_LIGHT, which)); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 3619 | sb.append("x"); |
| 3620 | pw.println(sb.toString()); |
| 3621 | } |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3622 | if (deviceIdleModeLightTime != 0) { |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 3623 | sb.setLength(0); |
| 3624 | sb.append(prefix); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3625 | sb.append(" Idle mode light time: "); |
| 3626 | formatTimeMs(sb, deviceIdleModeLightTime / 1000); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3627 | sb.append("("); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3628 | sb.append(formatRatioLocked(deviceIdleModeLightTime, whichBatteryRealtime)); |
| 3629 | sb.append(") "); |
| 3630 | sb.append(getDeviceIdleModeCount(DEVICE_IDLE_MODE_LIGHT, which)); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3631 | sb.append("x"); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3632 | sb.append(" -- longest "); |
| 3633 | formatTimeMs(sb, getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT)); |
| 3634 | pw.println(sb.toString()); |
| 3635 | } |
| 3636 | if (deviceIdlingTime != 0) { |
| 3637 | sb.setLength(0); |
| 3638 | sb.append(prefix); |
| 3639 | sb.append(" Device full idling: "); |
| 3640 | formatTimeMs(sb, deviceIdlingTime / 1000); |
| 3641 | sb.append("("); |
| 3642 | sb.append(formatRatioLocked(deviceIdlingTime, whichBatteryRealtime)); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 3643 | sb.append(") "); sb.append(getDeviceIdlingCount(DEVICE_IDLE_MODE_DEEP, which)); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3644 | sb.append("x"); |
| 3645 | pw.println(sb.toString()); |
| 3646 | } |
| 3647 | if (deviceIdleModeFullTime != 0) { |
| 3648 | sb.setLength(0); |
| 3649 | sb.append(prefix); |
| 3650 | sb.append(" Idle mode full time: "); |
| 3651 | formatTimeMs(sb, deviceIdleModeFullTime / 1000); |
| 3652 | sb.append("("); |
| 3653 | sb.append(formatRatioLocked(deviceIdleModeFullTime, whichBatteryRealtime)); |
| 3654 | sb.append(") "); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 3655 | sb.append(getDeviceIdleModeCount(DEVICE_IDLE_MODE_DEEP, which)); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3656 | sb.append("x"); |
| 3657 | sb.append(" -- longest "); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 3658 | formatTimeMs(sb, getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP)); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3659 | pw.println(sb.toString()); |
| 3660 | } |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3661 | if (phoneOnTime != 0) { |
| 3662 | sb.setLength(0); |
| 3663 | sb.append(prefix); |
| 3664 | sb.append(" Active phone call: "); formatTimeMs(sb, phoneOnTime / 1000); |
| 3665 | sb.append("("); sb.append(formatRatioLocked(phoneOnTime, whichBatteryRealtime)); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3666 | sb.append(") "); sb.append(getPhoneOnCount(which)); sb.append("x"); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3667 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3668 | final int connChanges = getNumConnectivityChange(which); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 3669 | if (connChanges != 0) { |
| 3670 | pw.print(prefix); |
| 3671 | pw.print(" Connectivity changes: "); pw.println(connChanges); |
| 3672 | } |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3673 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3674 | // Calculate wakelock times across all uids. |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 3675 | long fullWakeLockTimeTotalMicros = 0; |
| 3676 | long partialWakeLockTimeTotalMicros = 0; |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 3677 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3678 | final ArrayList<TimerEntry> timers = new ArrayList<>(); |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 3679 | |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 3680 | for (int iu = 0; iu < NU; iu++) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3681 | final Uid u = uidStats.valueAt(iu); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 3682 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3683 | final ArrayMap<String, ? extends BatteryStats.Uid.Wakelock> wakelocks |
| 3684 | = u.getWakelockStats(); |
| 3685 | for (int iw=wakelocks.size()-1; iw>=0; iw--) { |
| 3686 | final Uid.Wakelock wl = wakelocks.valueAt(iw); |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 3687 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3688 | final Timer fullWakeTimer = wl.getWakeTime(WAKE_TYPE_FULL); |
| 3689 | if (fullWakeTimer != null) { |
| 3690 | fullWakeLockTimeTotalMicros += fullWakeTimer.getTotalTimeLocked( |
| 3691 | rawRealtime, which); |
| 3692 | } |
| 3693 | |
| 3694 | final Timer partialWakeTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL); |
| 3695 | if (partialWakeTimer != null) { |
| 3696 | final long totalTimeMicros = partialWakeTimer.getTotalTimeLocked( |
| 3697 | rawRealtime, which); |
| 3698 | if (totalTimeMicros > 0) { |
| 3699 | if (reqUid < 0) { |
| 3700 | // Only show the ordered list of all wake |
| 3701 | // locks if the caller is not asking for data |
| 3702 | // about a specific uid. |
| 3703 | timers.add(new TimerEntry(wakelocks.keyAt(iw), u.getUid(), |
| 3704 | partialWakeTimer, totalTimeMicros)); |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 3705 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3706 | partialWakeLockTimeTotalMicros += totalTimeMicros; |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 3707 | } |
| 3708 | } |
| 3709 | } |
| 3710 | } |
| 3711 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3712 | final long mobileRxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which); |
| 3713 | final long mobileTxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which); |
| 3714 | final long wifiRxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which); |
| 3715 | final long wifiTxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which); |
| 3716 | final long mobileRxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which); |
| 3717 | final long mobileTxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which); |
| 3718 | final long wifiRxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which); |
| 3719 | final long wifiTxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which); |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 3720 | final long btRxTotalBytes = getNetworkActivityBytes(NETWORK_BT_RX_DATA, which); |
| 3721 | final long btTxTotalBytes = getNetworkActivityBytes(NETWORK_BT_TX_DATA, which); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3722 | |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 3723 | if (fullWakeLockTimeTotalMicros != 0) { |
| 3724 | sb.setLength(0); |
| 3725 | sb.append(prefix); |
| 3726 | sb.append(" Total full wakelock time: "); formatTimeMsNoSpace(sb, |
| 3727 | (fullWakeLockTimeTotalMicros + 500) / 1000); |
| 3728 | pw.println(sb.toString()); |
| 3729 | } |
| 3730 | |
| 3731 | if (partialWakeLockTimeTotalMicros != 0) { |
| 3732 | sb.setLength(0); |
| 3733 | sb.append(prefix); |
| 3734 | sb.append(" Total partial wakelock time: "); formatTimeMsNoSpace(sb, |
| 3735 | (partialWakeLockTimeTotalMicros + 500) / 1000); |
| 3736 | pw.println(sb.toString()); |
| 3737 | } |
| 3738 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3739 | pw.print(prefix); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3740 | pw.print(" Mobile total received: "); pw.print(formatBytesLocked(mobileRxTotalBytes)); |
| 3741 | pw.print(", sent: "); pw.print(formatBytesLocked(mobileTxTotalBytes)); |
| 3742 | pw.print(" (packets received "); pw.print(mobileRxTotalPackets); |
| 3743 | pw.print(", sent "); pw.print(mobileTxTotalPackets); pw.println(")"); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3744 | sb.setLength(0); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3745 | sb.append(prefix); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 3746 | sb.append(" Phone signal levels:"); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3747 | didOne = false; |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 3748 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3749 | final long time = getPhoneSignalStrengthTime(i, rawRealtime, which); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3750 | if (time == 0) { |
| 3751 | continue; |
| 3752 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3753 | sb.append("\n "); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 3754 | sb.append(prefix); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3755 | didOne = true; |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 3756 | sb.append(SignalStrength.SIGNAL_STRENGTH_NAMES[i]); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3757 | sb.append(" "); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3758 | formatTimeMs(sb, time/1000); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3759 | sb.append("("); |
| 3760 | sb.append(formatRatioLocked(time, whichBatteryRealtime)); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3761 | sb.append(") "); |
| 3762 | sb.append(getPhoneSignalStrengthCount(i, which)); |
| 3763 | sb.append("x"); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3764 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3765 | if (!didOne) sb.append(" (no activity)"); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3766 | pw.println(sb.toString()); |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 3767 | |
| 3768 | sb.setLength(0); |
| 3769 | sb.append(prefix); |
| 3770 | sb.append(" Signal scanning time: "); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3771 | formatTimeMsNoSpace(sb, getPhoneSignalScanningTime(rawRealtime, which) / 1000); |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 3772 | pw.println(sb.toString()); |
| 3773 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3774 | sb.setLength(0); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3775 | sb.append(prefix); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3776 | sb.append(" Radio types:"); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3777 | didOne = false; |
| 3778 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3779 | final long time = getPhoneDataConnectionTime(i, rawRealtime, which); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3780 | if (time == 0) { |
| 3781 | continue; |
| 3782 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3783 | sb.append("\n "); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 3784 | sb.append(prefix); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3785 | didOne = true; |
| 3786 | sb.append(DATA_CONNECTION_NAMES[i]); |
| 3787 | sb.append(" "); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3788 | formatTimeMs(sb, time/1000); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3789 | sb.append("("); |
| 3790 | sb.append(formatRatioLocked(time, whichBatteryRealtime)); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3791 | sb.append(") "); |
| 3792 | sb.append(getPhoneDataConnectionCount(i, which)); |
| 3793 | sb.append("x"); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3794 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3795 | if (!didOne) sb.append(" (no activity)"); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3796 | pw.println(sb.toString()); |
Amith Yamasani | 3f7e35c | 2009-07-13 16:02:45 -0700 | [diff] [blame] | 3797 | |
| 3798 | sb.setLength(0); |
| 3799 | sb.append(prefix); |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 3800 | sb.append(" Mobile radio active time: "); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3801 | final long mobileActiveTime = getMobileRadioActiveTime(rawRealtime, which); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 3802 | formatTimeMs(sb, mobileActiveTime / 1000); |
| 3803 | sb.append("("); sb.append(formatRatioLocked(mobileActiveTime, whichBatteryRealtime)); |
| 3804 | sb.append(") "); sb.append(getMobileRadioActiveCount(which)); |
| 3805 | sb.append("x"); |
Amith Yamasani | 3f7e35c | 2009-07-13 16:02:45 -0700 | [diff] [blame] | 3806 | pw.println(sb.toString()); |
| 3807 | |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 3808 | final long mobileActiveUnknownTime = getMobileRadioActiveUnknownTime(which); |
| 3809 | if (mobileActiveUnknownTime != 0) { |
| 3810 | sb.setLength(0); |
| 3811 | sb.append(prefix); |
| 3812 | sb.append(" Mobile radio active unknown time: "); |
| 3813 | formatTimeMs(sb, mobileActiveUnknownTime / 1000); |
| 3814 | sb.append("("); |
| 3815 | sb.append(formatRatioLocked(mobileActiveUnknownTime, whichBatteryRealtime)); |
| 3816 | sb.append(") "); sb.append(getMobileRadioActiveUnknownCount(which)); |
| 3817 | sb.append("x"); |
| 3818 | pw.println(sb.toString()); |
| 3819 | } |
| 3820 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3821 | final long mobileActiveAdjustedTime = getMobileRadioActiveAdjustedTime(which); |
| 3822 | if (mobileActiveAdjustedTime != 0) { |
| 3823 | sb.setLength(0); |
| 3824 | sb.append(prefix); |
| 3825 | sb.append(" Mobile radio active adjusted time: "); |
| 3826 | formatTimeMs(sb, mobileActiveAdjustedTime / 1000); |
| 3827 | sb.append("("); |
| 3828 | sb.append(formatRatioLocked(mobileActiveAdjustedTime, whichBatteryRealtime)); |
| 3829 | sb.append(")"); |
| 3830 | pw.println(sb.toString()); |
| 3831 | } |
| 3832 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3833 | printControllerActivity(pw, sb, prefix, "Radio", getModemControllerActivity(), which); |
| 3834 | |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 3835 | pw.print(prefix); |
| 3836 | pw.print(" Wi-Fi total received: "); pw.print(formatBytesLocked(wifiRxTotalBytes)); |
| 3837 | pw.print(", sent: "); pw.print(formatBytesLocked(wifiTxTotalBytes)); |
| 3838 | pw.print(" (packets received "); pw.print(wifiRxTotalPackets); |
| 3839 | pw.print(", sent "); pw.print(wifiTxTotalPackets); pw.println(")"); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3840 | sb.setLength(0); |
| 3841 | sb.append(prefix); |
| 3842 | sb.append(" Wifi on: "); formatTimeMs(sb, wifiOnTime / 1000); |
| 3843 | sb.append("("); sb.append(formatRatioLocked(wifiOnTime, whichBatteryRealtime)); |
| 3844 | sb.append("), Wifi running: "); formatTimeMs(sb, wifiRunningTime / 1000); |
| 3845 | sb.append("("); sb.append(formatRatioLocked(wifiRunningTime, whichBatteryRealtime)); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3846 | sb.append(")"); |
| 3847 | pw.println(sb.toString()); |
| 3848 | |
| 3849 | sb.setLength(0); |
| 3850 | sb.append(prefix); |
| 3851 | sb.append(" Wifi states:"); |
| 3852 | didOne = false; |
| 3853 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3854 | final long time = getWifiStateTime(i, rawRealtime, which); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3855 | if (time == 0) { |
| 3856 | continue; |
| 3857 | } |
| 3858 | sb.append("\n "); |
| 3859 | didOne = true; |
| 3860 | sb.append(WIFI_STATE_NAMES[i]); |
| 3861 | sb.append(" "); |
| 3862 | formatTimeMs(sb, time/1000); |
| 3863 | sb.append("("); |
| 3864 | sb.append(formatRatioLocked(time, whichBatteryRealtime)); |
| 3865 | sb.append(") "); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 3866 | sb.append(getWifiStateCount(i, which)); |
| 3867 | sb.append("x"); |
| 3868 | } |
| 3869 | if (!didOne) sb.append(" (no activity)"); |
| 3870 | pw.println(sb.toString()); |
| 3871 | |
| 3872 | sb.setLength(0); |
| 3873 | sb.append(prefix); |
| 3874 | sb.append(" Wifi supplicant states:"); |
| 3875 | didOne = false; |
| 3876 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
| 3877 | final long time = getWifiSupplStateTime(i, rawRealtime, which); |
| 3878 | if (time == 0) { |
| 3879 | continue; |
| 3880 | } |
| 3881 | sb.append("\n "); |
| 3882 | didOne = true; |
| 3883 | sb.append(WIFI_SUPPL_STATE_NAMES[i]); |
| 3884 | sb.append(" "); |
| 3885 | formatTimeMs(sb, time/1000); |
| 3886 | sb.append("("); |
| 3887 | sb.append(formatRatioLocked(time, whichBatteryRealtime)); |
| 3888 | sb.append(") "); |
| 3889 | sb.append(getWifiSupplStateCount(i, which)); |
| 3890 | sb.append("x"); |
| 3891 | } |
| 3892 | if (!didOne) sb.append(" (no activity)"); |
| 3893 | pw.println(sb.toString()); |
| 3894 | |
| 3895 | sb.setLength(0); |
| 3896 | sb.append(prefix); |
| 3897 | sb.append(" Wifi signal levels:"); |
| 3898 | didOne = false; |
| 3899 | for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 3900 | final long time = getWifiSignalStrengthTime(i, rawRealtime, which); |
| 3901 | if (time == 0) { |
| 3902 | continue; |
| 3903 | } |
| 3904 | sb.append("\n "); |
| 3905 | sb.append(prefix); |
| 3906 | didOne = true; |
| 3907 | sb.append("level("); |
| 3908 | sb.append(i); |
| 3909 | sb.append(") "); |
| 3910 | formatTimeMs(sb, time/1000); |
| 3911 | sb.append("("); |
| 3912 | sb.append(formatRatioLocked(time, whichBatteryRealtime)); |
| 3913 | sb.append(") "); |
| 3914 | sb.append(getWifiSignalStrengthCount(i, which)); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3915 | sb.append("x"); |
| 3916 | } |
| 3917 | if (!didOne) sb.append(" (no activity)"); |
| 3918 | pw.println(sb.toString()); |
| 3919 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3920 | printControllerActivity(pw, sb, prefix, "WiFi", getWifiControllerActivity(), which); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 3921 | |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 3922 | pw.print(prefix); |
| 3923 | pw.print(" Bluetooth total received: "); pw.print(formatBytesLocked(btRxTotalBytes)); |
| 3924 | pw.print(", sent: "); pw.println(formatBytesLocked(btTxTotalBytes)); |
| 3925 | |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 3926 | final long bluetoothScanTimeMs = getBluetoothScanTime(rawRealtime, which) / 1000; |
| 3927 | sb.setLength(0); |
| 3928 | sb.append(prefix); |
| 3929 | sb.append(" Bluetooth scan time: "); formatTimeMs(sb, bluetoothScanTimeMs); |
| 3930 | pw.println(sb.toString()); |
| 3931 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3932 | printControllerActivity(pw, sb, prefix, "Bluetooth", getBluetoothControllerActivity(), |
| 3933 | which); |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 3934 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3935 | pw.println(); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3936 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3937 | if (which == STATS_SINCE_UNPLUGGED) { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3938 | if (getIsOnBattery()) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3939 | pw.print(prefix); pw.println(" Device is currently unplugged"); |
| 3940 | pw.print(prefix); pw.print(" Discharge cycle start level: "); |
| 3941 | pw.println(getDischargeStartLevel()); |
| 3942 | pw.print(prefix); pw.print(" Discharge cycle current level: "); |
| 3943 | pw.println(getDischargeCurrentLevel()); |
Dianne Hackborn | 99d0452 | 2010-08-20 13:43:00 -0700 | [diff] [blame] | 3944 | } else { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 3945 | pw.print(prefix); pw.println(" Device is currently plugged into power"); |
| 3946 | pw.print(prefix); pw.print(" Last discharge cycle start level: "); |
| 3947 | pw.println(getDischargeStartLevel()); |
| 3948 | pw.print(prefix); pw.print(" Last discharge cycle end level: "); |
| 3949 | pw.println(getDischargeCurrentLevel()); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3950 | } |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 3951 | pw.print(prefix); pw.print(" Amount discharged while screen on: "); |
| 3952 | pw.println(getDischargeAmountScreenOn()); |
| 3953 | pw.print(prefix); pw.print(" Amount discharged while screen off: "); |
| 3954 | pw.println(getDischargeAmountScreenOff()); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3955 | pw.println(" "); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3956 | } else { |
| 3957 | pw.print(prefix); pw.println(" Device battery use since last full charge"); |
| 3958 | pw.print(prefix); pw.print(" Amount discharged (lower bound): "); |
| 3959 | pw.println(getLowDischargeAmountSinceCharge()); |
| 3960 | pw.print(prefix); pw.print(" Amount discharged (upper bound): "); |
| 3961 | pw.println(getHighDischargeAmountSinceCharge()); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 3962 | pw.print(prefix); pw.print(" Amount discharged while screen on: "); |
| 3963 | pw.println(getDischargeAmountScreenOnSinceCharge()); |
| 3964 | pw.print(prefix); pw.print(" Amount discharged while screen off: "); |
| 3965 | pw.println(getDischargeAmountScreenOffSinceCharge()); |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 3966 | pw.println(); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3967 | } |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 3968 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3969 | final BatteryStatsHelper helper = new BatteryStatsHelper(context, false, wifiOnly); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3970 | helper.create(this); |
| 3971 | helper.refreshStats(which, UserHandle.USER_ALL); |
| 3972 | List<BatterySipper> sippers = helper.getUsageList(); |
| 3973 | if (sippers != null && sippers.size() > 0) { |
| 3974 | pw.print(prefix); pw.println(" Estimated power use (mAh):"); |
| 3975 | pw.print(prefix); pw.print(" Capacity: "); |
| 3976 | printmAh(pw, helper.getPowerProfile().getBatteryCapacity()); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3977 | pw.print(", Computed drain: "); printmAh(pw, helper.getComputedPower()); |
Dianne Hackborn | 536456f | 2014-05-23 16:51:05 -0700 | [diff] [blame] | 3978 | pw.print(", actual drain: "); printmAh(pw, helper.getMinDrainedPower()); |
| 3979 | if (helper.getMinDrainedPower() != helper.getMaxDrainedPower()) { |
| 3980 | pw.print("-"); printmAh(pw, helper.getMaxDrainedPower()); |
| 3981 | } |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3982 | pw.println(); |
| 3983 | for (int i=0; i<sippers.size(); i++) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 3984 | final BatterySipper bs = sippers.get(i); |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 3985 | pw.print(prefix); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3986 | switch (bs.drainType) { |
| 3987 | case IDLE: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 3988 | pw.print(" Idle: "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3989 | break; |
| 3990 | case CELL: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 3991 | pw.print(" Cell standby: "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3992 | break; |
| 3993 | case PHONE: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 3994 | pw.print(" Phone calls: "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3995 | break; |
| 3996 | case WIFI: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 3997 | pw.print(" Wifi: "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 3998 | break; |
| 3999 | case BLUETOOTH: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4000 | pw.print(" Bluetooth: "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4001 | break; |
| 4002 | case SCREEN: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4003 | pw.print(" Screen: "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4004 | break; |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 4005 | case FLASHLIGHT: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4006 | pw.print(" Flashlight: "); |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 4007 | break; |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4008 | case APP: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4009 | pw.print(" Uid "); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4010 | UserHandle.formatUid(pw, bs.uidObj.getUid()); |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4011 | pw.print(": "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4012 | break; |
| 4013 | case USER: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4014 | pw.print(" User "); pw.print(bs.userId); |
| 4015 | pw.print(": "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4016 | break; |
| 4017 | case UNACCOUNTED: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4018 | pw.print(" Unaccounted: "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4019 | break; |
| 4020 | case OVERCOUNTED: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4021 | pw.print(" Over-counted: "); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4022 | break; |
Ruben Brunk | 5b1308f | 2015-06-03 18:49:27 -0700 | [diff] [blame] | 4023 | case CAMERA: |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4024 | pw.print(" Camera: "); |
| 4025 | break; |
| 4026 | default: |
| 4027 | pw.print(" ???: "); |
Ruben Brunk | 5b1308f | 2015-06-03 18:49:27 -0700 | [diff] [blame] | 4028 | break; |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4029 | } |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4030 | printmAh(pw, bs.totalPowerMah); |
| 4031 | |
Adam Lesinski | 5712300 | 2015-06-12 16:12:07 -0700 | [diff] [blame] | 4032 | if (bs.usagePowerMah != bs.totalPowerMah) { |
| 4033 | // If the usage (generic power) isn't the whole amount, we list out |
| 4034 | // what components are involved in the calculation. |
| 4035 | |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4036 | pw.print(" ("); |
Adam Lesinski | 5712300 | 2015-06-12 16:12:07 -0700 | [diff] [blame] | 4037 | if (bs.usagePowerMah != 0) { |
| 4038 | pw.print(" usage="); |
| 4039 | printmAh(pw, bs.usagePowerMah); |
| 4040 | } |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4041 | if (bs.cpuPowerMah != 0) { |
| 4042 | pw.print(" cpu="); |
| 4043 | printmAh(pw, bs.cpuPowerMah); |
| 4044 | } |
| 4045 | if (bs.wakeLockPowerMah != 0) { |
| 4046 | pw.print(" wake="); |
| 4047 | printmAh(pw, bs.wakeLockPowerMah); |
| 4048 | } |
| 4049 | if (bs.mobileRadioPowerMah != 0) { |
| 4050 | pw.print(" radio="); |
| 4051 | printmAh(pw, bs.mobileRadioPowerMah); |
| 4052 | } |
| 4053 | if (bs.wifiPowerMah != 0) { |
| 4054 | pw.print(" wifi="); |
| 4055 | printmAh(pw, bs.wifiPowerMah); |
| 4056 | } |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 4057 | if (bs.bluetoothPowerMah != 0) { |
| 4058 | pw.print(" bt="); |
| 4059 | printmAh(pw, bs.bluetoothPowerMah); |
| 4060 | } |
Adam Lesinski | 628ef9c | 2015-06-10 13:08:57 -0700 | [diff] [blame] | 4061 | if (bs.gpsPowerMah != 0) { |
| 4062 | pw.print(" gps="); |
| 4063 | printmAh(pw, bs.gpsPowerMah); |
| 4064 | } |
| 4065 | if (bs.sensorPowerMah != 0) { |
| 4066 | pw.print(" sensor="); |
| 4067 | printmAh(pw, bs.sensorPowerMah); |
| 4068 | } |
| 4069 | if (bs.cameraPowerMah != 0) { |
| 4070 | pw.print(" camera="); |
| 4071 | printmAh(pw, bs.cameraPowerMah); |
| 4072 | } |
| 4073 | if (bs.flashlightPowerMah != 0) { |
| 4074 | pw.print(" flash="); |
| 4075 | printmAh(pw, bs.flashlightPowerMah); |
| 4076 | } |
| 4077 | pw.print(" )"); |
| 4078 | } |
| 4079 | pw.println(); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4080 | } |
Dianne Hackborn | c46809e | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4081 | pw.println(); |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 4082 | } |
| 4083 | |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4084 | sippers = helper.getMobilemsppList(); |
| 4085 | if (sippers != null && sippers.size() > 0) { |
| 4086 | pw.print(prefix); pw.println(" Per-app mobile ms per packet:"); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 4087 | long totalTime = 0; |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4088 | for (int i=0; i<sippers.size(); i++) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4089 | final BatterySipper bs = sippers.get(i); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4090 | sb.setLength(0); |
| 4091 | sb.append(prefix); sb.append(" Uid "); |
| 4092 | UserHandle.formatUid(sb, bs.uidObj.getUid()); |
| 4093 | sb.append(": "); sb.append(BatteryStatsHelper.makemAh(bs.mobilemspp)); |
| 4094 | sb.append(" ("); sb.append(bs.mobileRxPackets+bs.mobileTxPackets); |
| 4095 | sb.append(" packets over "); formatTimeMsNoSpace(sb, bs.mobileActive); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 4096 | sb.append(") "); sb.append(bs.mobileActiveCount); sb.append("x"); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4097 | pw.println(sb.toString()); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 4098 | totalTime += bs.mobileActive; |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4099 | } |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 4100 | sb.setLength(0); |
| 4101 | sb.append(prefix); |
| 4102 | sb.append(" TOTAL TIME: "); |
| 4103 | formatTimeMs(sb, totalTime); |
| 4104 | sb.append("("); sb.append(formatRatioLocked(totalTime, whichBatteryRealtime)); |
| 4105 | sb.append(")"); |
| 4106 | pw.println(sb.toString()); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4107 | pw.println(); |
| 4108 | } |
| 4109 | |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 4110 | final Comparator<TimerEntry> timerComparator = new Comparator<TimerEntry>() { |
| 4111 | @Override |
| 4112 | public int compare(TimerEntry lhs, TimerEntry rhs) { |
| 4113 | long lhsTime = lhs.mTime; |
| 4114 | long rhsTime = rhs.mTime; |
| 4115 | if (lhsTime < rhsTime) { |
| 4116 | return 1; |
| 4117 | } |
| 4118 | if (lhsTime > rhsTime) { |
| 4119 | return -1; |
| 4120 | } |
| 4121 | return 0; |
| 4122 | } |
| 4123 | }; |
| 4124 | |
| 4125 | if (reqUid < 0) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4126 | final Map<String, ? extends BatteryStats.Timer> kernelWakelocks |
| 4127 | = getKernelWakelockStats(); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 4128 | if (kernelWakelocks.size() > 0) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4129 | final ArrayList<TimerEntry> ktimers = new ArrayList<>(); |
| 4130 | for (Map.Entry<String, ? extends BatteryStats.Timer> ent |
| 4131 | : kernelWakelocks.entrySet()) { |
| 4132 | final BatteryStats.Timer timer = ent.getValue(); |
| 4133 | final long totalTimeMillis = computeWakeLock(timer, rawRealtime, which); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 4134 | if (totalTimeMillis > 0) { |
| 4135 | ktimers.add(new TimerEntry(ent.getKey(), 0, timer, totalTimeMillis)); |
| 4136 | } |
| 4137 | } |
| 4138 | if (ktimers.size() > 0) { |
| 4139 | Collections.sort(ktimers, timerComparator); |
| 4140 | pw.print(prefix); pw.println(" All kernel wake locks:"); |
| 4141 | for (int i=0; i<ktimers.size(); i++) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4142 | final TimerEntry timer = ktimers.get(i); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 4143 | String linePrefix = ": "; |
| 4144 | sb.setLength(0); |
| 4145 | sb.append(prefix); |
| 4146 | sb.append(" Kernel Wake lock "); |
| 4147 | sb.append(timer.mName); |
| 4148 | linePrefix = printWakeLock(sb, timer.mTimer, rawRealtime, null, |
| 4149 | which, linePrefix); |
| 4150 | if (!linePrefix.equals(": ")) { |
| 4151 | sb.append(" realtime"); |
| 4152 | // Only print out wake locks that were held |
| 4153 | pw.println(sb.toString()); |
| 4154 | } |
| 4155 | } |
| 4156 | pw.println(); |
| 4157 | } |
| 4158 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 4159 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 4160 | if (timers.size() > 0) { |
| 4161 | Collections.sort(timers, timerComparator); |
| 4162 | pw.print(prefix); pw.println(" All partial wake locks:"); |
| 4163 | for (int i=0; i<timers.size(); i++) { |
| 4164 | TimerEntry timer = timers.get(i); |
| 4165 | sb.setLength(0); |
| 4166 | sb.append(" Wake lock "); |
| 4167 | UserHandle.formatUid(sb, timer.mId); |
| 4168 | sb.append(" "); |
| 4169 | sb.append(timer.mName); |
| 4170 | printWakeLock(sb, timer.mTimer, rawRealtime, null, which, ": "); |
| 4171 | sb.append(" realtime"); |
| 4172 | pw.println(sb.toString()); |
| 4173 | } |
| 4174 | timers.clear(); |
| 4175 | pw.println(); |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 4176 | } |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 4177 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4178 | final Map<String, ? extends Timer> wakeupReasons = getWakeupReasonStats(); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 4179 | if (wakeupReasons.size() > 0) { |
| 4180 | pw.print(prefix); pw.println(" All wakeup reasons:"); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4181 | final ArrayList<TimerEntry> reasons = new ArrayList<>(); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 4182 | for (Map.Entry<String, ? extends Timer> ent : wakeupReasons.entrySet()) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4183 | final Timer timer = ent.getValue(); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 4184 | reasons.add(new TimerEntry(ent.getKey(), 0, timer, |
| 4185 | timer.getCountLocked(which))); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 4186 | } |
| 4187 | Collections.sort(reasons, timerComparator); |
| 4188 | for (int i=0; i<reasons.size(); i++) { |
| 4189 | TimerEntry timer = reasons.get(i); |
| 4190 | String linePrefix = ": "; |
| 4191 | sb.setLength(0); |
| 4192 | sb.append(prefix); |
| 4193 | sb.append(" Wakeup reason "); |
| 4194 | sb.append(timer.mName); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 4195 | printWakeLock(sb, timer.mTimer, rawRealtime, null, which, ": "); |
| 4196 | sb.append(" realtime"); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 4197 | pw.println(sb.toString()); |
| 4198 | } |
| 4199 | pw.println(); |
| 4200 | } |
Dianne Hackborn | 8103890 | 2012-11-26 17:04:09 -0800 | [diff] [blame] | 4201 | } |
Evan Millar | 22ac043 | 2009-03-31 11:33:18 -0700 | [diff] [blame] | 4202 | |
James Carr | 2dd7e5e | 2016-07-20 18:48:39 -0700 | [diff] [blame] | 4203 | final LongSparseArray<? extends Timer> mMemoryStats = getKernelMemoryStats(); |
| 4204 | pw.println("Memory Stats"); |
| 4205 | for (int i = 0; i < mMemoryStats.size(); i++) { |
| 4206 | sb.setLength(0); |
| 4207 | sb.append("Bandwidth "); |
| 4208 | sb.append(mMemoryStats.keyAt(i)); |
| 4209 | sb.append(" Time "); |
| 4210 | sb.append(mMemoryStats.valueAt(i).getTotalTimeLocked(rawRealtime, which)); |
| 4211 | pw.println(sb.toString()); |
| 4212 | } |
| 4213 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4214 | for (int iu=0; iu<NU; iu++) { |
| 4215 | final int uid = uidStats.keyAt(iu); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 4216 | if (reqUid >= 0 && uid != reqUid && uid != Process.SYSTEM_UID) { |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 4217 | continue; |
| 4218 | } |
| 4219 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4220 | final Uid u = uidStats.valueAt(iu); |
Dianne Hackborn | a4cc205 | 2013-07-08 17:31:25 -0700 | [diff] [blame] | 4221 | |
| 4222 | pw.print(prefix); |
| 4223 | pw.print(" "); |
| 4224 | UserHandle.formatUid(pw, uid); |
| 4225 | pw.println(":"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4226 | boolean uidActivity = false; |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4227 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4228 | final long mobileRxBytes = u.getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which); |
| 4229 | final long mobileTxBytes = u.getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which); |
| 4230 | final long wifiRxBytes = u.getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which); |
| 4231 | final long wifiTxBytes = u.getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which); |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 4232 | final long btRxBytes = u.getNetworkActivityBytes(NETWORK_BT_RX_DATA, which); |
| 4233 | final long btTxBytes = u.getNetworkActivityBytes(NETWORK_BT_TX_DATA, which); |
| 4234 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4235 | final long mobileRxPackets = u.getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which); |
| 4236 | final long mobileTxPackets = u.getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4237 | final long wifiRxPackets = u.getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which); |
| 4238 | final long wifiTxPackets = u.getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which); |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 4239 | |
| 4240 | final long uidMobileActiveTime = u.getMobileRadioActiveTime(which); |
| 4241 | final int uidMobileActiveCount = u.getMobileRadioActiveCount(which); |
| 4242 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4243 | final long fullWifiLockOnTime = u.getFullWifiLockTime(rawRealtime, which); |
| 4244 | final long wifiScanTime = u.getWifiScanTime(rawRealtime, which); |
| 4245 | final int wifiScanCount = u.getWifiScanCount(which); |
| 4246 | final long uidWifiRunningTime = u.getWifiRunningTime(rawRealtime, which); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 4247 | |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 4248 | final long mobileWakeup = u.getMobileRadioApWakeupCount(which); |
| 4249 | final long wifiWakeup = u.getWifiRadioApWakeupCount(which); |
| 4250 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4251 | if (mobileRxBytes > 0 || mobileTxBytes > 0 |
| 4252 | || mobileRxPackets > 0 || mobileTxPackets > 0) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 4253 | pw.print(prefix); pw.print(" Mobile network: "); |
| 4254 | pw.print(formatBytesLocked(mobileRxBytes)); pw.print(" received, "); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4255 | pw.print(formatBytesLocked(mobileTxBytes)); |
| 4256 | pw.print(" sent (packets "); pw.print(mobileRxPackets); |
| 4257 | pw.print(" received, "); pw.print(mobileTxPackets); pw.println(" sent)"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4258 | } |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4259 | if (uidMobileActiveTime > 0 || uidMobileActiveCount > 0) { |
| 4260 | sb.setLength(0); |
| 4261 | sb.append(prefix); sb.append(" Mobile radio active: "); |
| 4262 | formatTimeMs(sb, uidMobileActiveTime / 1000); |
| 4263 | sb.append("("); |
| 4264 | sb.append(formatRatioLocked(uidMobileActiveTime, mobileActiveTime)); |
| 4265 | sb.append(") "); sb.append(uidMobileActiveCount); sb.append("x"); |
| 4266 | long packets = mobileRxPackets + mobileTxPackets; |
| 4267 | if (packets == 0) { |
| 4268 | packets = 1; |
| 4269 | } |
| 4270 | sb.append(" @ "); |
| 4271 | sb.append(BatteryStatsHelper.makemAh(uidMobileActiveTime / 1000 / (double)packets)); |
| 4272 | sb.append(" mspp"); |
| 4273 | pw.println(sb.toString()); |
| 4274 | } |
| 4275 | |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 4276 | if (mobileWakeup > 0) { |
| 4277 | sb.setLength(0); |
| 4278 | sb.append(prefix); |
| 4279 | sb.append(" Mobile radio AP wakeups: "); |
| 4280 | sb.append(mobileWakeup); |
| 4281 | pw.println(sb.toString()); |
| 4282 | } |
| 4283 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 4284 | printControllerActivityIfInteresting(pw, sb, prefix + " ", "Modem", |
| 4285 | u.getModemControllerActivity(), which); |
| 4286 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4287 | if (wifiRxBytes > 0 || wifiTxBytes > 0 || wifiRxPackets > 0 || wifiTxPackets > 0) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 4288 | pw.print(prefix); pw.print(" Wi-Fi network: "); |
| 4289 | pw.print(formatBytesLocked(wifiRxBytes)); pw.print(" received, "); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4290 | pw.print(formatBytesLocked(wifiTxBytes)); |
| 4291 | pw.print(" sent (packets "); pw.print(wifiRxPackets); |
| 4292 | pw.print(" received, "); pw.print(wifiTxPackets); pw.println(" sent)"); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 4293 | } |
| 4294 | |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 4295 | if (fullWifiLockOnTime != 0 || wifiScanTime != 0 || wifiScanCount != 0 |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4296 | || uidWifiRunningTime != 0) { |
| 4297 | sb.setLength(0); |
| 4298 | sb.append(prefix); sb.append(" Wifi Running: "); |
| 4299 | formatTimeMs(sb, uidWifiRunningTime / 1000); |
| 4300 | sb.append("("); sb.append(formatRatioLocked(uidWifiRunningTime, |
| 4301 | whichBatteryRealtime)); sb.append(")\n"); |
| 4302 | sb.append(prefix); sb.append(" Full Wifi Lock: "); |
| 4303 | formatTimeMs(sb, fullWifiLockOnTime / 1000); |
| 4304 | sb.append("("); sb.append(formatRatioLocked(fullWifiLockOnTime, |
| 4305 | whichBatteryRealtime)); sb.append(")\n"); |
| 4306 | sb.append(prefix); sb.append(" Wifi Scan: "); |
| 4307 | formatTimeMs(sb, wifiScanTime / 1000); |
| 4308 | sb.append("("); sb.append(formatRatioLocked(wifiScanTime, |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 4309 | whichBatteryRealtime)); sb.append(") "); |
| 4310 | sb.append(wifiScanCount); |
| 4311 | sb.append("x"); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4312 | pw.println(sb.toString()); |
| 4313 | } |
| 4314 | |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 4315 | if (wifiWakeup > 0) { |
| 4316 | sb.setLength(0); |
| 4317 | sb.append(prefix); |
| 4318 | sb.append(" WiFi AP wakeups: "); |
| 4319 | sb.append(wifiWakeup); |
| 4320 | pw.println(sb.toString()); |
| 4321 | } |
| 4322 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 4323 | printControllerActivityIfInteresting(pw, sb, prefix + " ", "WiFi", |
| 4324 | u.getWifiControllerActivity(), which); |
Adam Lesinski | 049c88b | 2015-05-28 11:38:12 -0700 | [diff] [blame] | 4325 | |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 4326 | if (btRxBytes > 0 || btTxBytes > 0) { |
| 4327 | pw.print(prefix); pw.print(" Bluetooth network: "); |
| 4328 | pw.print(formatBytesLocked(btRxBytes)); pw.print(" received, "); |
| 4329 | pw.print(formatBytesLocked(btTxBytes)); |
| 4330 | pw.println(" sent"); |
| 4331 | } |
| 4332 | |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 4333 | uidActivity |= printTimer(pw, sb, u.getBluetoothScanTimer(), rawRealtime, which, prefix, |
| 4334 | "Bluetooth Scan"); |
| 4335 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4336 | if (u.hasUserActivity()) { |
| 4337 | boolean hasData = false; |
Raph Levien | 4c7a4a7 | 2012-08-03 14:32:39 -0700 | [diff] [blame] | 4338 | for (int i=0; i<Uid.NUM_USER_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4339 | final int val = u.getUserActivityCount(i, which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4340 | if (val != 0) { |
| 4341 | if (!hasData) { |
| 4342 | sb.setLength(0); |
| 4343 | sb.append(" User activity: "); |
| 4344 | hasData = true; |
| 4345 | } else { |
| 4346 | sb.append(", "); |
| 4347 | } |
| 4348 | sb.append(val); |
| 4349 | sb.append(" "); |
| 4350 | sb.append(Uid.USER_ACTIVITY_TYPES[i]); |
| 4351 | } |
| 4352 | } |
| 4353 | if (hasData) { |
| 4354 | pw.println(sb.toString()); |
| 4355 | } |
| 4356 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4357 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4358 | final ArrayMap<String, ? extends BatteryStats.Uid.Wakelock> wakelocks |
| 4359 | = u.getWakelockStats(); |
| 4360 | long totalFullWakelock = 0, totalPartialWakelock = 0, totalWindowWakelock = 0; |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 4361 | long totalDrawWakelock = 0; |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4362 | int countWakelock = 0; |
| 4363 | for (int iw=wakelocks.size()-1; iw>=0; iw--) { |
| 4364 | final Uid.Wakelock wl = wakelocks.valueAt(iw); |
| 4365 | String linePrefix = ": "; |
| 4366 | sb.setLength(0); |
| 4367 | sb.append(prefix); |
| 4368 | sb.append(" Wake lock "); |
| 4369 | sb.append(wakelocks.keyAt(iw)); |
| 4370 | linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_FULL), rawRealtime, |
| 4371 | "full", which, linePrefix); |
| 4372 | linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_PARTIAL), rawRealtime, |
| 4373 | "partial", which, linePrefix); |
| 4374 | linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_WINDOW), rawRealtime, |
| 4375 | "window", which, linePrefix); |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 4376 | linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_DRAW), rawRealtime, |
| 4377 | "draw", which, linePrefix); |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 4378 | sb.append(" realtime"); |
| 4379 | pw.println(sb.toString()); |
| 4380 | uidActivity = true; |
| 4381 | countWakelock++; |
| 4382 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4383 | totalFullWakelock += computeWakeLock(wl.getWakeTime(WAKE_TYPE_FULL), |
| 4384 | rawRealtime, which); |
| 4385 | totalPartialWakelock += computeWakeLock(wl.getWakeTime(WAKE_TYPE_PARTIAL), |
| 4386 | rawRealtime, which); |
| 4387 | totalWindowWakelock += computeWakeLock(wl.getWakeTime(WAKE_TYPE_WINDOW), |
| 4388 | rawRealtime, which); |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 4389 | totalDrawWakelock += computeWakeLock(wl.getWakeTime(WAKE_TYPE_DRAW), |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 4390 | rawRealtime, which); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 4391 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4392 | if (countWakelock > 1) { |
| 4393 | if (totalFullWakelock != 0 || totalPartialWakelock != 0 |
| 4394 | || totalWindowWakelock != 0) { |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 4395 | sb.setLength(0); |
| 4396 | sb.append(prefix); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4397 | sb.append(" TOTAL wake: "); |
| 4398 | boolean needComma = false; |
| 4399 | if (totalFullWakelock != 0) { |
| 4400 | needComma = true; |
| 4401 | formatTimeMs(sb, totalFullWakelock); |
| 4402 | sb.append("full"); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 4403 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4404 | if (totalPartialWakelock != 0) { |
| 4405 | if (needComma) { |
| 4406 | sb.append(", "); |
| 4407 | } |
| 4408 | needComma = true; |
| 4409 | formatTimeMs(sb, totalPartialWakelock); |
| 4410 | sb.append("partial"); |
| 4411 | } |
| 4412 | if (totalWindowWakelock != 0) { |
| 4413 | if (needComma) { |
| 4414 | sb.append(", "); |
| 4415 | } |
| 4416 | needComma = true; |
| 4417 | formatTimeMs(sb, totalWindowWakelock); |
| 4418 | sb.append("window"); |
| 4419 | } |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 4420 | if (totalDrawWakelock != 0) { |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 4421 | if (needComma) { |
| 4422 | sb.append(","); |
| 4423 | } |
| 4424 | needComma = true; |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 4425 | formatTimeMs(sb, totalDrawWakelock); |
| 4426 | sb.append("draw"); |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 4427 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4428 | sb.append(" realtime"); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 4429 | pw.println(sb.toString()); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 4430 | } |
| 4431 | } |
| 4432 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4433 | final ArrayMap<String, ? extends Timer> syncs = u.getSyncStats(); |
| 4434 | for (int isy=syncs.size()-1; isy>=0; isy--) { |
| 4435 | final Timer timer = syncs.valueAt(isy); |
| 4436 | // Convert from microseconds to milliseconds with rounding |
| 4437 | final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000; |
| 4438 | final int count = timer.getCountLocked(which); |
| 4439 | sb.setLength(0); |
| 4440 | sb.append(prefix); |
| 4441 | sb.append(" Sync "); |
| 4442 | sb.append(syncs.keyAt(isy)); |
| 4443 | sb.append(": "); |
| 4444 | if (totalTime != 0) { |
| 4445 | formatTimeMs(sb, totalTime); |
| 4446 | sb.append("realtime ("); |
| 4447 | sb.append(count); |
| 4448 | sb.append(" times)"); |
| 4449 | } else { |
| 4450 | sb.append("(not used)"); |
| 4451 | } |
| 4452 | pw.println(sb.toString()); |
| 4453 | uidActivity = true; |
| 4454 | } |
| 4455 | |
| 4456 | final ArrayMap<String, ? extends Timer> jobs = u.getJobStats(); |
| 4457 | for (int ij=jobs.size()-1; ij>=0; ij--) { |
| 4458 | final Timer timer = jobs.valueAt(ij); |
| 4459 | // Convert from microseconds to milliseconds with rounding |
| 4460 | final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000; |
| 4461 | final int count = timer.getCountLocked(which); |
| 4462 | sb.setLength(0); |
| 4463 | sb.append(prefix); |
| 4464 | sb.append(" Job "); |
| 4465 | sb.append(jobs.keyAt(ij)); |
| 4466 | sb.append(": "); |
| 4467 | if (totalTime != 0) { |
| 4468 | formatTimeMs(sb, totalTime); |
| 4469 | sb.append("realtime ("); |
| 4470 | sb.append(count); |
| 4471 | sb.append(" times)"); |
| 4472 | } else { |
| 4473 | sb.append("(not used)"); |
| 4474 | } |
| 4475 | pw.println(sb.toString()); |
| 4476 | uidActivity = true; |
| 4477 | } |
| 4478 | |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 4479 | uidActivity |= printTimer(pw, sb, u.getFlashlightTurnedOnTimer(), rawRealtime, which, |
| 4480 | prefix, "Flashlight"); |
| 4481 | uidActivity |= printTimer(pw, sb, u.getCameraTurnedOnTimer(), rawRealtime, which, |
| 4482 | prefix, "Camera"); |
| 4483 | uidActivity |= printTimer(pw, sb, u.getVideoTurnedOnTimer(), rawRealtime, which, |
| 4484 | prefix, "Video"); |
| 4485 | uidActivity |= printTimer(pw, sb, u.getAudioTurnedOnTimer(), rawRealtime, which, |
| 4486 | prefix, "Audio"); |
| 4487 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4488 | final SparseArray<? extends BatteryStats.Uid.Sensor> sensors = u.getSensorStats(); |
| 4489 | final int NSE = sensors.size(); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 4490 | for (int ise=0; ise<NSE; ise++) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4491 | final Uid.Sensor se = sensors.valueAt(ise); |
| 4492 | final int sensorNumber = sensors.keyAt(ise); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 4493 | sb.setLength(0); |
| 4494 | sb.append(prefix); |
| 4495 | sb.append(" Sensor "); |
| 4496 | int handle = se.getHandle(); |
| 4497 | if (handle == Uid.Sensor.GPS) { |
| 4498 | sb.append("GPS"); |
| 4499 | } else { |
| 4500 | sb.append(handle); |
| 4501 | } |
| 4502 | sb.append(": "); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4503 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4504 | final Timer timer = se.getSensorTime(); |
Amith Yamasani | ab9ad19 | 2016-12-06 12:46:59 -0800 | [diff] [blame^] | 4505 | final Counter bgCounter = se.getSensorBgCount(); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 4506 | if (timer != null) { |
| 4507 | // Convert from microseconds to milliseconds with rounding |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4508 | final long totalTime = (timer.getTotalTimeLocked( |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 4509 | rawRealtime, which) + 500) / 1000; |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4510 | final int count = timer.getCountLocked(which); |
Amith Yamasani | ab9ad19 | 2016-12-06 12:46:59 -0800 | [diff] [blame^] | 4511 | final int bgCount = bgCounter != null ? bgCounter.getCountLocked(which) : 0; |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 4512 | //timer.logState(); |
| 4513 | if (totalTime != 0) { |
| 4514 | formatTimeMs(sb, totalTime); |
| 4515 | sb.append("realtime ("); |
| 4516 | sb.append(count); |
Amith Yamasani | ab9ad19 | 2016-12-06 12:46:59 -0800 | [diff] [blame^] | 4517 | sb.append(" times"); |
| 4518 | if (bgCount > 0) { |
| 4519 | sb.append(", "); |
| 4520 | sb.append(bgCount); |
| 4521 | sb.append(" bg"); |
| 4522 | } |
| 4523 | sb.append(")"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4524 | } else { |
| 4525 | sb.append("(not used)"); |
| 4526 | } |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 4527 | } else { |
| 4528 | sb.append("(not used)"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4529 | } |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 4530 | |
| 4531 | pw.println(sb.toString()); |
| 4532 | uidActivity = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4533 | } |
| 4534 | |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 4535 | uidActivity |= printTimer(pw, sb, u.getVibratorOnTimer(), rawRealtime, which, prefix, |
| 4536 | "Vibrator"); |
| 4537 | uidActivity |= printTimer(pw, sb, u.getForegroundActivityTimer(), rawRealtime, which, |
| 4538 | prefix, "Foreground activities"); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 4539 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 4540 | long totalStateTime = 0; |
| 4541 | for (int ips=0; ips<Uid.NUM_PROCESS_STATE; ips++) { |
| 4542 | long time = u.getProcessStateTime(ips, rawRealtime, which); |
| 4543 | if (time > 0) { |
| 4544 | totalStateTime += time; |
| 4545 | sb.setLength(0); |
| 4546 | sb.append(prefix); |
| 4547 | sb.append(" "); |
| 4548 | sb.append(Uid.PROCESS_STATE_NAMES[ips]); |
| 4549 | sb.append(" for: "); |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 4550 | formatTimeMs(sb, (time + 500) / 1000); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 4551 | pw.println(sb.toString()); |
| 4552 | uidActivity = true; |
| 4553 | } |
| 4554 | } |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 4555 | if (totalStateTime > 0) { |
| 4556 | sb.setLength(0); |
| 4557 | sb.append(prefix); |
| 4558 | sb.append(" Total running: "); |
| 4559 | formatTimeMs(sb, (totalStateTime + 500) / 1000); |
| 4560 | pw.println(sb.toString()); |
| 4561 | } |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 4562 | |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 4563 | final long userCpuTimeUs = u.getUserCpuTimeUs(which); |
| 4564 | final long systemCpuTimeUs = u.getSystemCpuTimeUs(which); |
Adam Lesinski | a7a4ccc | 2015-06-26 17:43:04 -0700 | [diff] [blame] | 4565 | final long powerCpuMaUs = u.getCpuPowerMaUs(which); |
| 4566 | if (userCpuTimeUs > 0 || systemCpuTimeUs > 0 || powerCpuMaUs > 0) { |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 4567 | sb.setLength(0); |
| 4568 | sb.append(prefix); |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 4569 | sb.append(" Total cpu time: u="); |
| 4570 | formatTimeMs(sb, userCpuTimeUs / 1000); |
| 4571 | sb.append("s="); |
| 4572 | formatTimeMs(sb, systemCpuTimeUs / 1000); |
Adam Lesinski | a7a4ccc | 2015-06-26 17:43:04 -0700 | [diff] [blame] | 4573 | sb.append("p="); |
| 4574 | printmAh(sb, powerCpuMaUs / (1000.0 * 1000.0 * 60.0 * 60.0)); |
| 4575 | sb.append("mAh"); |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 4576 | pw.println(sb.toString()); |
| 4577 | } |
| 4578 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4579 | final ArrayMap<String, ? extends BatteryStats.Uid.Proc> processStats |
| 4580 | = u.getProcessStats(); |
| 4581 | for (int ipr=processStats.size()-1; ipr>=0; ipr--) { |
| 4582 | final Uid.Proc ps = processStats.valueAt(ipr); |
| 4583 | long userTime; |
| 4584 | long systemTime; |
| 4585 | long foregroundTime; |
| 4586 | int starts; |
| 4587 | int numExcessive; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4588 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4589 | userTime = ps.getUserTime(which); |
| 4590 | systemTime = ps.getSystemTime(which); |
| 4591 | foregroundTime = ps.getForegroundTime(which); |
| 4592 | starts = ps.getStarts(which); |
| 4593 | final int numCrashes = ps.getNumCrashes(which); |
| 4594 | final int numAnrs = ps.getNumAnrs(which); |
| 4595 | numExcessive = which == STATS_SINCE_CHARGED |
| 4596 | ? ps.countExcessivePowers() : 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4597 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4598 | if (userTime != 0 || systemTime != 0 || foregroundTime != 0 || starts != 0 |
| 4599 | || numExcessive != 0 || numCrashes != 0 || numAnrs != 0) { |
| 4600 | sb.setLength(0); |
| 4601 | sb.append(prefix); sb.append(" Proc "); |
| 4602 | sb.append(processStats.keyAt(ipr)); sb.append(":\n"); |
| 4603 | sb.append(prefix); sb.append(" CPU: "); |
| 4604 | formatTimeMs(sb, userTime); sb.append("usr + "); |
| 4605 | formatTimeMs(sb, systemTime); sb.append("krn ; "); |
| 4606 | formatTimeMs(sb, foregroundTime); sb.append("fg"); |
| 4607 | if (starts != 0 || numCrashes != 0 || numAnrs != 0) { |
| 4608 | sb.append("\n"); sb.append(prefix); sb.append(" "); |
| 4609 | boolean hasOne = false; |
| 4610 | if (starts != 0) { |
| 4611 | hasOne = true; |
| 4612 | sb.append(starts); sb.append(" starts"); |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 4613 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4614 | if (numCrashes != 0) { |
| 4615 | if (hasOne) { |
| 4616 | sb.append(", "); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4617 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4618 | hasOne = true; |
| 4619 | sb.append(numCrashes); sb.append(" crashes"); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4620 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4621 | if (numAnrs != 0) { |
| 4622 | if (hasOne) { |
| 4623 | sb.append(", "); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4624 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4625 | sb.append(numAnrs); sb.append(" anrs"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4626 | } |
| 4627 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4628 | pw.println(sb.toString()); |
| 4629 | for (int e=0; e<numExcessive; e++) { |
| 4630 | Uid.Proc.ExcessivePower ew = ps.getExcessivePower(e); |
| 4631 | if (ew != null) { |
| 4632 | pw.print(prefix); pw.print(" * Killed for "); |
| 4633 | if (ew.type == Uid.Proc.ExcessivePower.TYPE_WAKE) { |
| 4634 | pw.print("wake lock"); |
| 4635 | } else if (ew.type == Uid.Proc.ExcessivePower.TYPE_CPU) { |
| 4636 | pw.print("cpu"); |
| 4637 | } else { |
| 4638 | pw.print("unknown"); |
| 4639 | } |
| 4640 | pw.print(" use: "); |
| 4641 | TimeUtils.formatDuration(ew.usedTime, pw); |
| 4642 | pw.print(" over "); |
| 4643 | TimeUtils.formatDuration(ew.overTime, pw); |
| 4644 | if (ew.overTime != 0) { |
| 4645 | pw.print(" ("); |
| 4646 | pw.print((ew.usedTime*100)/ew.overTime); |
| 4647 | pw.println("%)"); |
| 4648 | } |
| 4649 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4650 | } |
| 4651 | uidActivity = true; |
| 4652 | } |
| 4653 | } |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4654 | |
| 4655 | final ArrayMap<String, ? extends BatteryStats.Uid.Pkg> packageStats |
| 4656 | = u.getPackageStats(); |
| 4657 | for (int ipkg=packageStats.size()-1; ipkg>=0; ipkg--) { |
| 4658 | pw.print(prefix); pw.print(" Apk "); pw.print(packageStats.keyAt(ipkg)); |
| 4659 | pw.println(":"); |
| 4660 | boolean apkActivity = false; |
| 4661 | final Uid.Pkg ps = packageStats.valueAt(ipkg); |
| 4662 | final ArrayMap<String, ? extends Counter> alarms = ps.getWakeupAlarmStats(); |
| 4663 | for (int iwa=alarms.size()-1; iwa>=0; iwa--) { |
| 4664 | pw.print(prefix); pw.print(" Wakeup alarm "); |
| 4665 | pw.print(alarms.keyAt(iwa)); pw.print(": "); |
| 4666 | pw.print(alarms.valueAt(iwa).getCountLocked(which)); |
| 4667 | pw.println(" times"); |
| 4668 | apkActivity = true; |
| 4669 | } |
| 4670 | final ArrayMap<String, ? extends Uid.Pkg.Serv> serviceStats = ps.getServiceStats(); |
| 4671 | for (int isvc=serviceStats.size()-1; isvc>=0; isvc--) { |
| 4672 | final BatteryStats.Uid.Pkg.Serv ss = serviceStats.valueAt(isvc); |
| 4673 | final long startTime = ss.getStartTime(batteryUptime, which); |
| 4674 | final int starts = ss.getStarts(which); |
| 4675 | final int launches = ss.getLaunches(which); |
| 4676 | if (startTime != 0 || starts != 0 || launches != 0) { |
| 4677 | sb.setLength(0); |
| 4678 | sb.append(prefix); sb.append(" Service "); |
| 4679 | sb.append(serviceStats.keyAt(isvc)); sb.append(":\n"); |
| 4680 | sb.append(prefix); sb.append(" Created for: "); |
| 4681 | formatTimeMs(sb, startTime / 1000); |
| 4682 | sb.append("uptime\n"); |
| 4683 | sb.append(prefix); sb.append(" Starts: "); |
| 4684 | sb.append(starts); |
| 4685 | sb.append(", launches: "); sb.append(launches); |
| 4686 | pw.println(sb.toString()); |
| 4687 | apkActivity = true; |
| 4688 | } |
| 4689 | } |
| 4690 | if (!apkActivity) { |
| 4691 | pw.print(prefix); pw.println(" (nothing executed)"); |
| 4692 | } |
| 4693 | uidActivity = true; |
| 4694 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4695 | if (!uidActivity) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4696 | pw.print(prefix); pw.println(" (nothing executed)"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4697 | } |
| 4698 | } |
| 4699 | } |
| 4700 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 4701 | static void printBitDescriptions(PrintWriter pw, int oldval, int newval, HistoryTag wakelockTag, |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4702 | BitDescription[] descriptions, boolean longNames) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4703 | int diff = oldval ^ newval; |
| 4704 | if (diff == 0) return; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 4705 | boolean didWake = false; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4706 | for (int i=0; i<descriptions.length; i++) { |
| 4707 | BitDescription bd = descriptions[i]; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 4708 | if ((diff&bd.mask) != 0) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4709 | pw.print(longNames ? " " : ","); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4710 | if (bd.shift < 0) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 4711 | pw.print((newval&bd.mask) != 0 ? "+" : "-"); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4712 | pw.print(longNames ? bd.name : bd.shortName); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 4713 | if (bd.mask == HistoryItem.STATE_WAKE_LOCK_FLAG && wakelockTag != null) { |
| 4714 | didWake = true; |
| 4715 | pw.print("="); |
| 4716 | if (longNames) { |
| 4717 | UserHandle.formatUid(pw, wakelockTag.uid); |
| 4718 | pw.print(":\""); |
| 4719 | pw.print(wakelockTag.string); |
| 4720 | pw.print("\""); |
| 4721 | } else { |
| 4722 | pw.print(wakelockTag.poolIdx); |
| 4723 | } |
| 4724 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4725 | } else { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4726 | pw.print(longNames ? bd.name : bd.shortName); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4727 | pw.print("="); |
| 4728 | int val = (newval&bd.mask)>>bd.shift; |
| 4729 | if (bd.values != null && val >= 0 && val < bd.values.length) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4730 | pw.print(longNames? bd.values[val] : bd.shortValues[val]); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4731 | } else { |
| 4732 | pw.print(val); |
| 4733 | } |
| 4734 | } |
| 4735 | } |
| 4736 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 4737 | if (!didWake && wakelockTag != null) { |
Ashish Sharma | 81850c4 | 2014-05-05 13:57:07 -0700 | [diff] [blame] | 4738 | pw.print(longNames ? " wake_lock=" : ",w="); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 4739 | if (longNames) { |
| 4740 | UserHandle.formatUid(pw, wakelockTag.uid); |
| 4741 | pw.print(":\""); |
| 4742 | pw.print(wakelockTag.string); |
| 4743 | pw.print("\""); |
| 4744 | } else { |
| 4745 | pw.print(wakelockTag.poolIdx); |
| 4746 | } |
| 4747 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4748 | } |
| 4749 | |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 4750 | public void prepareForDumpLocked() { |
| 4751 | } |
| 4752 | |
| 4753 | public static class HistoryPrinter { |
| 4754 | int oldState = 0; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 4755 | int oldState2 = 0; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4756 | int oldLevel = -1; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 4757 | int oldStatus = -1; |
| 4758 | int oldHealth = -1; |
| 4759 | int oldPlug = -1; |
| 4760 | int oldTemp = -1; |
| 4761 | int oldVolt = -1; |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 4762 | int oldChargeMAh = -1; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4763 | long lastTime = -1; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 4764 | |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 4765 | void reset() { |
| 4766 | oldState = oldState2 = 0; |
| 4767 | oldLevel = -1; |
| 4768 | oldStatus = -1; |
| 4769 | oldHealth = -1; |
| 4770 | oldPlug = -1; |
| 4771 | oldTemp = -1; |
| 4772 | oldVolt = -1; |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 4773 | oldChargeMAh = -1; |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 4774 | } |
| 4775 | |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 4776 | public void printNextItem(PrintWriter pw, HistoryItem rec, long baseTime, boolean checkin, |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 4777 | boolean verbose) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4778 | if (!checkin) { |
| 4779 | pw.print(" "); |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 4780 | TimeUtils.formatDuration(rec.time - baseTime, pw, TimeUtils.HUNDRED_DAY_FIELD_LEN); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 4781 | pw.print(" ("); |
| 4782 | pw.print(rec.numReadInts); |
| 4783 | pw.print(") "); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4784 | } else { |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 4785 | pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(','); |
| 4786 | pw.print(HISTORY_DATA); pw.print(','); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4787 | if (lastTime < 0) { |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 4788 | pw.print(rec.time - baseTime); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4789 | } else { |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 4790 | pw.print(rec.time - lastTime); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4791 | } |
| 4792 | lastTime = rec.time; |
| 4793 | } |
| 4794 | if (rec.cmd == HistoryItem.CMD_START) { |
| 4795 | if (checkin) { |
| 4796 | pw.print(":"); |
| 4797 | } |
| 4798 | pw.println("START"); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 4799 | reset(); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 4800 | } else if (rec.cmd == HistoryItem.CMD_CURRENT_TIME |
| 4801 | || rec.cmd == HistoryItem.CMD_RESET) { |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 4802 | if (checkin) { |
| 4803 | pw.print(":"); |
| 4804 | } |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 4805 | if (rec.cmd == HistoryItem.CMD_RESET) { |
| 4806 | pw.print("RESET:"); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 4807 | reset(); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 4808 | } |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 4809 | pw.print("TIME:"); |
| 4810 | if (checkin) { |
| 4811 | pw.println(rec.currentTime); |
| 4812 | } else { |
| 4813 | pw.print(" "); |
| 4814 | pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss", |
| 4815 | rec.currentTime).toString()); |
| 4816 | } |
Dianne Hackborn | 29cd7f1 | 2015-01-08 10:37:05 -0800 | [diff] [blame] | 4817 | } else if (rec.cmd == HistoryItem.CMD_SHUTDOWN) { |
| 4818 | if (checkin) { |
| 4819 | pw.print(":"); |
| 4820 | } |
| 4821 | pw.println("SHUTDOWN"); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4822 | } else if (rec.cmd == HistoryItem.CMD_OVERFLOW) { |
| 4823 | if (checkin) { |
| 4824 | pw.print(":"); |
| 4825 | } |
| 4826 | pw.println("*OVERFLOW*"); |
| 4827 | } else { |
| 4828 | if (!checkin) { |
| 4829 | if (rec.batteryLevel < 10) pw.print("00"); |
| 4830 | else if (rec.batteryLevel < 100) pw.print("0"); |
| 4831 | pw.print(rec.batteryLevel); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 4832 | if (verbose) { |
| 4833 | pw.print(" "); |
| 4834 | if (rec.states < 0) ; |
| 4835 | else if (rec.states < 0x10) pw.print("0000000"); |
| 4836 | else if (rec.states < 0x100) pw.print("000000"); |
| 4837 | else if (rec.states < 0x1000) pw.print("00000"); |
| 4838 | else if (rec.states < 0x10000) pw.print("0000"); |
| 4839 | else if (rec.states < 0x100000) pw.print("000"); |
| 4840 | else if (rec.states < 0x1000000) pw.print("00"); |
| 4841 | else if (rec.states < 0x10000000) pw.print("0"); |
| 4842 | pw.print(Integer.toHexString(rec.states)); |
| 4843 | } |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4844 | } else { |
| 4845 | if (oldLevel != rec.batteryLevel) { |
| 4846 | oldLevel = rec.batteryLevel; |
| 4847 | pw.print(",Bl="); pw.print(rec.batteryLevel); |
| 4848 | } |
| 4849 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 4850 | if (oldStatus != rec.batteryStatus) { |
| 4851 | oldStatus = rec.batteryStatus; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4852 | pw.print(checkin ? ",Bs=" : " status="); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 4853 | switch (oldStatus) { |
| 4854 | case BatteryManager.BATTERY_STATUS_UNKNOWN: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4855 | pw.print(checkin ? "?" : "unknown"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 4856 | break; |
| 4857 | case BatteryManager.BATTERY_STATUS_CHARGING: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4858 | pw.print(checkin ? "c" : "charging"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 4859 | break; |
| 4860 | case BatteryManager.BATTERY_STATUS_DISCHARGING: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4861 | pw.print(checkin ? "d" : "discharging"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 4862 | break; |
| 4863 | case BatteryManager.BATTERY_STATUS_NOT_CHARGING: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4864 | pw.print(checkin ? "n" : "not-charging"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 4865 | break; |
| 4866 | case BatteryManager.BATTERY_STATUS_FULL: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4867 | pw.print(checkin ? "f" : "full"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 4868 | break; |
| 4869 | default: |
| 4870 | pw.print(oldStatus); |
| 4871 | break; |
| 4872 | } |
| 4873 | } |
| 4874 | if (oldHealth != rec.batteryHealth) { |
| 4875 | oldHealth = rec.batteryHealth; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4876 | pw.print(checkin ? ",Bh=" : " health="); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 4877 | switch (oldHealth) { |
| 4878 | case BatteryManager.BATTERY_HEALTH_UNKNOWN: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4879 | pw.print(checkin ? "?" : "unknown"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 4880 | break; |
| 4881 | case BatteryManager.BATTERY_HEALTH_GOOD: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4882 | pw.print(checkin ? "g" : "good"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 4883 | break; |
| 4884 | case BatteryManager.BATTERY_HEALTH_OVERHEAT: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4885 | pw.print(checkin ? "h" : "overheat"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 4886 | break; |
| 4887 | case BatteryManager.BATTERY_HEALTH_DEAD: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4888 | pw.print(checkin ? "d" : "dead"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 4889 | break; |
| 4890 | case BatteryManager.BATTERY_HEALTH_OVER_VOLTAGE: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4891 | pw.print(checkin ? "v" : "over-voltage"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 4892 | break; |
| 4893 | case BatteryManager.BATTERY_HEALTH_UNSPECIFIED_FAILURE: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4894 | pw.print(checkin ? "f" : "failure"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 4895 | break; |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 4896 | case BatteryManager.BATTERY_HEALTH_COLD: |
| 4897 | pw.print(checkin ? "c" : "cold"); |
| 4898 | break; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 4899 | default: |
| 4900 | pw.print(oldHealth); |
| 4901 | break; |
| 4902 | } |
| 4903 | } |
| 4904 | if (oldPlug != rec.batteryPlugType) { |
| 4905 | oldPlug = rec.batteryPlugType; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4906 | pw.print(checkin ? ",Bp=" : " plug="); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 4907 | switch (oldPlug) { |
| 4908 | case 0: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4909 | pw.print(checkin ? "n" : "none"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 4910 | break; |
| 4911 | case BatteryManager.BATTERY_PLUGGED_AC: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4912 | pw.print(checkin ? "a" : "ac"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 4913 | break; |
| 4914 | case BatteryManager.BATTERY_PLUGGED_USB: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4915 | pw.print(checkin ? "u" : "usb"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 4916 | break; |
Brian Muramatsu | 37a37f4 | 2012-08-14 15:21:02 -0700 | [diff] [blame] | 4917 | case BatteryManager.BATTERY_PLUGGED_WIRELESS: |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4918 | pw.print(checkin ? "w" : "wireless"); |
Brian Muramatsu | 37a37f4 | 2012-08-14 15:21:02 -0700 | [diff] [blame] | 4919 | break; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 4920 | default: |
| 4921 | pw.print(oldPlug); |
| 4922 | break; |
| 4923 | } |
| 4924 | } |
| 4925 | if (oldTemp != rec.batteryTemperature) { |
| 4926 | oldTemp = rec.batteryTemperature; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4927 | pw.print(checkin ? ",Bt=" : " temp="); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 4928 | pw.print(oldTemp); |
| 4929 | } |
| 4930 | if (oldVolt != rec.batteryVoltage) { |
| 4931 | oldVolt = rec.batteryVoltage; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4932 | pw.print(checkin ? ",Bv=" : " volt="); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 4933 | pw.print(oldVolt); |
| 4934 | } |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 4935 | final int chargeMAh = rec.batteryChargeUAh / 1000; |
| 4936 | if (oldChargeMAh != chargeMAh) { |
| 4937 | oldChargeMAh = chargeMAh; |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 4938 | pw.print(checkin ? ",Bcc=" : " charge="); |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 4939 | pw.print(oldChargeMAh); |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 4940 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 4941 | printBitDescriptions(pw, oldState, rec.states, rec.wakelockTag, |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4942 | HISTORY_STATE_DESCRIPTIONS, !checkin); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 4943 | printBitDescriptions(pw, oldState2, rec.states2, null, |
| 4944 | HISTORY_STATE2_DESCRIPTIONS, !checkin); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 4945 | if (rec.wakeReasonTag != null) { |
| 4946 | if (checkin) { |
Dianne Hackborn | d06dcfd | 2014-05-02 13:49:30 -0700 | [diff] [blame] | 4947 | pw.print(",wr="); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 4948 | pw.print(rec.wakeReasonTag.poolIdx); |
| 4949 | } else { |
| 4950 | pw.print(" wake_reason="); |
| 4951 | pw.print(rec.wakeReasonTag.uid); |
| 4952 | pw.print(":\""); |
| 4953 | pw.print(rec.wakeReasonTag.string); |
| 4954 | pw.print("\""); |
| 4955 | } |
| 4956 | } |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4957 | if (rec.eventCode != HistoryItem.EVENT_NONE) { |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 4958 | pw.print(checkin ? "," : " "); |
| 4959 | if ((rec.eventCode&HistoryItem.EVENT_FLAG_START) != 0) { |
| 4960 | pw.print("+"); |
| 4961 | } else if ((rec.eventCode&HistoryItem.EVENT_FLAG_FINISH) != 0) { |
| 4962 | pw.print("-"); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4963 | } |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 4964 | String[] eventNames = checkin ? HISTORY_EVENT_CHECKIN_NAMES |
| 4965 | : HISTORY_EVENT_NAMES; |
| 4966 | int idx = rec.eventCode & ~(HistoryItem.EVENT_FLAG_START |
| 4967 | | HistoryItem.EVENT_FLAG_FINISH); |
| 4968 | if (idx >= 0 && idx < eventNames.length) { |
| 4969 | pw.print(eventNames[idx]); |
| 4970 | } else { |
| 4971 | pw.print(checkin ? "Ev" : "event"); |
| 4972 | pw.print(idx); |
| 4973 | } |
| 4974 | pw.print("="); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4975 | if (checkin) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 4976 | pw.print(rec.eventTag.poolIdx); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4977 | } else { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 4978 | UserHandle.formatUid(pw, rec.eventTag.uid); |
| 4979 | pw.print(":\""); |
| 4980 | pw.print(rec.eventTag.string); |
| 4981 | pw.print("\""); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4982 | } |
| 4983 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 4984 | pw.println(); |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 4985 | if (rec.stepDetails != null) { |
| 4986 | if (!checkin) { |
| 4987 | pw.print(" Details: cpu="); |
| 4988 | pw.print(rec.stepDetails.userTime); |
| 4989 | pw.print("u+"); |
| 4990 | pw.print(rec.stepDetails.systemTime); |
| 4991 | pw.print("s"); |
| 4992 | if (rec.stepDetails.appCpuUid1 >= 0) { |
| 4993 | pw.print(" ("); |
| 4994 | printStepCpuUidDetails(pw, rec.stepDetails.appCpuUid1, |
| 4995 | rec.stepDetails.appCpuUTime1, rec.stepDetails.appCpuSTime1); |
| 4996 | if (rec.stepDetails.appCpuUid2 >= 0) { |
| 4997 | pw.print(", "); |
| 4998 | printStepCpuUidDetails(pw, rec.stepDetails.appCpuUid2, |
| 4999 | rec.stepDetails.appCpuUTime2, rec.stepDetails.appCpuSTime2); |
| 5000 | } |
| 5001 | if (rec.stepDetails.appCpuUid3 >= 0) { |
| 5002 | pw.print(", "); |
| 5003 | printStepCpuUidDetails(pw, rec.stepDetails.appCpuUid3, |
| 5004 | rec.stepDetails.appCpuUTime3, rec.stepDetails.appCpuSTime3); |
| 5005 | } |
| 5006 | pw.print(')'); |
| 5007 | } |
| 5008 | pw.println(); |
| 5009 | pw.print(" /proc/stat="); |
| 5010 | pw.print(rec.stepDetails.statUserTime); |
| 5011 | pw.print(" usr, "); |
| 5012 | pw.print(rec.stepDetails.statSystemTime); |
| 5013 | pw.print(" sys, "); |
| 5014 | pw.print(rec.stepDetails.statIOWaitTime); |
| 5015 | pw.print(" io, "); |
| 5016 | pw.print(rec.stepDetails.statIrqTime); |
| 5017 | pw.print(" irq, "); |
| 5018 | pw.print(rec.stepDetails.statSoftIrqTime); |
| 5019 | pw.print(" sirq, "); |
| 5020 | pw.print(rec.stepDetails.statIdlTime); |
| 5021 | pw.print(" idle"); |
| 5022 | int totalRun = rec.stepDetails.statUserTime + rec.stepDetails.statSystemTime |
| 5023 | + rec.stepDetails.statIOWaitTime + rec.stepDetails.statIrqTime |
| 5024 | + rec.stepDetails.statSoftIrqTime; |
| 5025 | int total = totalRun + rec.stepDetails.statIdlTime; |
| 5026 | if (total > 0) { |
| 5027 | pw.print(" ("); |
| 5028 | float perc = ((float)totalRun) / ((float)total) * 100; |
| 5029 | pw.print(String.format("%.1f%%", perc)); |
| 5030 | pw.print(" of "); |
| 5031 | StringBuilder sb = new StringBuilder(64); |
| 5032 | formatTimeMsNoSpace(sb, total*10); |
| 5033 | pw.print(sb); |
| 5034 | pw.print(")"); |
| 5035 | } |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 5036 | pw.print(", PlatformIdleStat "); |
| 5037 | pw.print(rec.stepDetails.statPlatformIdleState); |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 5038 | pw.println(); |
| 5039 | } else { |
| 5040 | pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(','); |
| 5041 | pw.print(HISTORY_DATA); pw.print(",0,Dcpu="); |
| 5042 | pw.print(rec.stepDetails.userTime); |
| 5043 | pw.print(":"); |
| 5044 | pw.print(rec.stepDetails.systemTime); |
| 5045 | if (rec.stepDetails.appCpuUid1 >= 0) { |
| 5046 | printStepCpuUidCheckinDetails(pw, rec.stepDetails.appCpuUid1, |
| 5047 | rec.stepDetails.appCpuUTime1, rec.stepDetails.appCpuSTime1); |
| 5048 | if (rec.stepDetails.appCpuUid2 >= 0) { |
| 5049 | printStepCpuUidCheckinDetails(pw, rec.stepDetails.appCpuUid2, |
| 5050 | rec.stepDetails.appCpuUTime2, rec.stepDetails.appCpuSTime2); |
| 5051 | } |
| 5052 | if (rec.stepDetails.appCpuUid3 >= 0) { |
| 5053 | printStepCpuUidCheckinDetails(pw, rec.stepDetails.appCpuUid3, |
| 5054 | rec.stepDetails.appCpuUTime3, rec.stepDetails.appCpuSTime3); |
| 5055 | } |
| 5056 | } |
| 5057 | pw.println(); |
| 5058 | pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(','); |
| 5059 | pw.print(HISTORY_DATA); pw.print(",0,Dpst="); |
| 5060 | pw.print(rec.stepDetails.statUserTime); |
| 5061 | pw.print(','); |
| 5062 | pw.print(rec.stepDetails.statSystemTime); |
| 5063 | pw.print(','); |
| 5064 | pw.print(rec.stepDetails.statIOWaitTime); |
| 5065 | pw.print(','); |
| 5066 | pw.print(rec.stepDetails.statIrqTime); |
| 5067 | pw.print(','); |
| 5068 | pw.print(rec.stepDetails.statSoftIrqTime); |
| 5069 | pw.print(','); |
| 5070 | pw.print(rec.stepDetails.statIdlTime); |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 5071 | pw.print(','); |
Adam Lesinski | 8568d8f | 2016-07-15 18:13:23 -0700 | [diff] [blame] | 5072 | if (rec.stepDetails.statPlatformIdleState != null) { |
| 5073 | pw.print(rec.stepDetails.statPlatformIdleState); |
| 5074 | } |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 5075 | pw.println(); |
| 5076 | } |
| 5077 | } |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 5078 | oldState = rec.states; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 5079 | oldState2 = rec.states2; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5080 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5081 | } |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 5082 | |
| 5083 | private void printStepCpuUidDetails(PrintWriter pw, int uid, int utime, int stime) { |
| 5084 | UserHandle.formatUid(pw, uid); |
| 5085 | pw.print("="); |
| 5086 | pw.print(utime); |
| 5087 | pw.print("u+"); |
| 5088 | pw.print(stime); |
| 5089 | pw.print("s"); |
| 5090 | } |
| 5091 | |
| 5092 | private void printStepCpuUidCheckinDetails(PrintWriter pw, int uid, int utime, int stime) { |
| 5093 | pw.print('/'); |
| 5094 | pw.print(uid); |
| 5095 | pw.print(":"); |
| 5096 | pw.print(utime); |
| 5097 | pw.print(":"); |
| 5098 | pw.print(stime); |
| 5099 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5100 | } |
| 5101 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 5102 | private void printSizeValue(PrintWriter pw, long size) { |
| 5103 | float result = size; |
| 5104 | String suffix = ""; |
| 5105 | if (result >= 10*1024) { |
| 5106 | suffix = "KB"; |
| 5107 | result = result / 1024; |
| 5108 | } |
| 5109 | if (result >= 10*1024) { |
| 5110 | suffix = "MB"; |
| 5111 | result = result / 1024; |
| 5112 | } |
| 5113 | if (result >= 10*1024) { |
| 5114 | suffix = "GB"; |
| 5115 | result = result / 1024; |
| 5116 | } |
| 5117 | if (result >= 10*1024) { |
| 5118 | suffix = "TB"; |
| 5119 | result = result / 1024; |
| 5120 | } |
| 5121 | if (result >= 10*1024) { |
| 5122 | suffix = "PB"; |
| 5123 | result = result / 1024; |
| 5124 | } |
| 5125 | pw.print((int)result); |
| 5126 | pw.print(suffix); |
| 5127 | } |
| 5128 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 5129 | private static boolean dumpTimeEstimate(PrintWriter pw, String label1, String label2, |
| 5130 | String label3, long estimatedTime) { |
| 5131 | if (estimatedTime < 0) { |
Dianne Hackborn | ad6a99b | 2014-11-18 10:11:10 -0800 | [diff] [blame] | 5132 | return false; |
| 5133 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 5134 | pw.print(label1); |
| 5135 | pw.print(label2); |
| 5136 | pw.print(label3); |
Dianne Hackborn | ad6a99b | 2014-11-18 10:11:10 -0800 | [diff] [blame] | 5137 | StringBuilder sb = new StringBuilder(64); |
| 5138 | formatTimeMs(sb, estimatedTime); |
| 5139 | pw.print(sb); |
| 5140 | pw.println(); |
Dianne Hackborn | ad6a99b | 2014-11-18 10:11:10 -0800 | [diff] [blame] | 5141 | return true; |
| 5142 | } |
| 5143 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 5144 | private static boolean dumpDurationSteps(PrintWriter pw, String prefix, String header, |
| 5145 | LevelStepTracker steps, boolean checkin) { |
| 5146 | if (steps == null) { |
| 5147 | return false; |
| 5148 | } |
| 5149 | int count = steps.mNumStepDurations; |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 5150 | if (count <= 0) { |
| 5151 | return false; |
| 5152 | } |
| 5153 | if (!checkin) { |
| 5154 | pw.println(header); |
| 5155 | } |
Kweku Adams | 030980a | 2015-04-01 16:07:48 -0700 | [diff] [blame] | 5156 | String[] lineArgs = new String[5]; |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 5157 | for (int i=0; i<count; i++) { |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 5158 | long duration = steps.getDurationAt(i); |
| 5159 | int level = steps.getLevelAt(i); |
| 5160 | long initMode = steps.getInitModeAt(i); |
| 5161 | long modMode = steps.getModModeAt(i); |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 5162 | if (checkin) { |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 5163 | lineArgs[0] = Long.toString(duration); |
| 5164 | lineArgs[1] = Integer.toString(level); |
| 5165 | if ((modMode&STEP_LEVEL_MODE_SCREEN_STATE) == 0) { |
| 5166 | switch ((int)(initMode&STEP_LEVEL_MODE_SCREEN_STATE) + 1) { |
| 5167 | case Display.STATE_OFF: lineArgs[2] = "s-"; break; |
| 5168 | case Display.STATE_ON: lineArgs[2] = "s+"; break; |
| 5169 | case Display.STATE_DOZE: lineArgs[2] = "sd"; break; |
| 5170 | case Display.STATE_DOZE_SUSPEND: lineArgs[2] = "sds"; break; |
Kweku Adams | 030980a | 2015-04-01 16:07:48 -0700 | [diff] [blame] | 5171 | default: lineArgs[2] = "?"; break; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 5172 | } |
| 5173 | } else { |
| 5174 | lineArgs[2] = ""; |
| 5175 | } |
| 5176 | if ((modMode&STEP_LEVEL_MODE_POWER_SAVE) == 0) { |
| 5177 | lineArgs[3] = (initMode&STEP_LEVEL_MODE_POWER_SAVE) != 0 ? "p+" : "p-"; |
| 5178 | } else { |
| 5179 | lineArgs[3] = ""; |
| 5180 | } |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 5181 | if ((modMode&STEP_LEVEL_MODE_DEVICE_IDLE) == 0) { |
Kweku Adams | 030980a | 2015-04-01 16:07:48 -0700 | [diff] [blame] | 5182 | lineArgs[4] = (initMode&STEP_LEVEL_MODE_DEVICE_IDLE) != 0 ? "i+" : "i-"; |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 5183 | } else { |
Kweku Adams | 030980a | 2015-04-01 16:07:48 -0700 | [diff] [blame] | 5184 | lineArgs[4] = ""; |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 5185 | } |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 5186 | dumpLine(pw, 0 /* uid */, "i" /* category */, header, (Object[])lineArgs); |
| 5187 | } else { |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 5188 | pw.print(prefix); |
| 5189 | pw.print("#"); pw.print(i); pw.print(": "); |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 5190 | TimeUtils.formatDuration(duration, pw); |
| 5191 | pw.print(" to "); pw.print(level); |
| 5192 | boolean haveModes = false; |
| 5193 | if ((modMode&STEP_LEVEL_MODE_SCREEN_STATE) == 0) { |
| 5194 | pw.print(" ("); |
| 5195 | switch ((int)(initMode&STEP_LEVEL_MODE_SCREEN_STATE) + 1) { |
| 5196 | case Display.STATE_OFF: pw.print("screen-off"); break; |
| 5197 | case Display.STATE_ON: pw.print("screen-on"); break; |
| 5198 | case Display.STATE_DOZE: pw.print("screen-doze"); break; |
| 5199 | case Display.STATE_DOZE_SUSPEND: pw.print("screen-doze-suspend"); break; |
Kweku Adams | 030980a | 2015-04-01 16:07:48 -0700 | [diff] [blame] | 5200 | default: pw.print("screen-?"); break; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 5201 | } |
| 5202 | haveModes = true; |
| 5203 | } |
| 5204 | if ((modMode&STEP_LEVEL_MODE_POWER_SAVE) == 0) { |
| 5205 | pw.print(haveModes ? ", " : " ("); |
| 5206 | pw.print((initMode&STEP_LEVEL_MODE_POWER_SAVE) != 0 |
| 5207 | ? "power-save-on" : "power-save-off"); |
| 5208 | haveModes = true; |
| 5209 | } |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 5210 | if ((modMode&STEP_LEVEL_MODE_DEVICE_IDLE) == 0) { |
| 5211 | pw.print(haveModes ? ", " : " ("); |
| 5212 | pw.print((initMode&STEP_LEVEL_MODE_DEVICE_IDLE) != 0 |
| 5213 | ? "device-idle-on" : "device-idle-off"); |
| 5214 | haveModes = true; |
| 5215 | } |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 5216 | if (haveModes) { |
| 5217 | pw.print(")"); |
| 5218 | } |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 5219 | pw.println(); |
| 5220 | } |
| 5221 | } |
| 5222 | return true; |
| 5223 | } |
| 5224 | |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 5225 | public static final int DUMP_CHARGED_ONLY = 1<<1; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 5226 | public static final int DUMP_DAILY_ONLY = 1<<2; |
| 5227 | public static final int DUMP_HISTORY_ONLY = 1<<3; |
| 5228 | public static final int DUMP_INCLUDE_HISTORY = 1<<4; |
| 5229 | public static final int DUMP_VERBOSE = 1<<5; |
| 5230 | public static final int DUMP_DEVICE_WIFI_ONLY = 1<<6; |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 5231 | |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 5232 | private void dumpHistoryLocked(PrintWriter pw, int flags, long histStart, boolean checkin) { |
| 5233 | final HistoryPrinter hprinter = new HistoryPrinter(); |
| 5234 | final HistoryItem rec = new HistoryItem(); |
| 5235 | long lastTime = -1; |
| 5236 | long baseTime = -1; |
| 5237 | boolean printed = false; |
| 5238 | HistoryEventTracker tracker = null; |
| 5239 | while (getNextHistoryLocked(rec)) { |
| 5240 | lastTime = rec.time; |
| 5241 | if (baseTime < 0) { |
| 5242 | baseTime = lastTime; |
| 5243 | } |
| 5244 | if (rec.time >= histStart) { |
| 5245 | if (histStart >= 0 && !printed) { |
| 5246 | if (rec.cmd == HistoryItem.CMD_CURRENT_TIME |
Ashish Sharma | 6020071 | 2014-05-23 18:22:20 -0700 | [diff] [blame] | 5247 | || rec.cmd == HistoryItem.CMD_RESET |
Dianne Hackborn | 29cd7f1 | 2015-01-08 10:37:05 -0800 | [diff] [blame] | 5248 | || rec.cmd == HistoryItem.CMD_START |
| 5249 | || rec.cmd == HistoryItem.CMD_SHUTDOWN) { |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 5250 | printed = true; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 5251 | hprinter.printNextItem(pw, rec, baseTime, checkin, |
| 5252 | (flags&DUMP_VERBOSE) != 0); |
| 5253 | rec.cmd = HistoryItem.CMD_UPDATE; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 5254 | } else if (rec.currentTime != 0) { |
| 5255 | printed = true; |
| 5256 | byte cmd = rec.cmd; |
| 5257 | rec.cmd = HistoryItem.CMD_CURRENT_TIME; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 5258 | hprinter.printNextItem(pw, rec, baseTime, checkin, |
| 5259 | (flags&DUMP_VERBOSE) != 0); |
| 5260 | rec.cmd = cmd; |
| 5261 | } |
| 5262 | if (tracker != null) { |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 5263 | if (rec.cmd != HistoryItem.CMD_UPDATE) { |
| 5264 | hprinter.printNextItem(pw, rec, baseTime, checkin, |
| 5265 | (flags&DUMP_VERBOSE) != 0); |
| 5266 | rec.cmd = HistoryItem.CMD_UPDATE; |
| 5267 | } |
| 5268 | int oldEventCode = rec.eventCode; |
| 5269 | HistoryTag oldEventTag = rec.eventTag; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 5270 | rec.eventTag = new HistoryTag(); |
| 5271 | for (int i=0; i<HistoryItem.EVENT_COUNT; i++) { |
| 5272 | HashMap<String, SparseIntArray> active |
| 5273 | = tracker.getStateForEvent(i); |
| 5274 | if (active == null) { |
| 5275 | continue; |
| 5276 | } |
| 5277 | for (HashMap.Entry<String, SparseIntArray> ent |
| 5278 | : active.entrySet()) { |
| 5279 | SparseIntArray uids = ent.getValue(); |
| 5280 | for (int j=0; j<uids.size(); j++) { |
| 5281 | rec.eventCode = i; |
| 5282 | rec.eventTag.string = ent.getKey(); |
| 5283 | rec.eventTag.uid = uids.keyAt(j); |
| 5284 | rec.eventTag.poolIdx = uids.valueAt(j); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 5285 | hprinter.printNextItem(pw, rec, baseTime, checkin, |
| 5286 | (flags&DUMP_VERBOSE) != 0); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 5287 | rec.wakeReasonTag = null; |
| 5288 | rec.wakelockTag = null; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 5289 | } |
| 5290 | } |
| 5291 | } |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 5292 | rec.eventCode = oldEventCode; |
| 5293 | rec.eventTag = oldEventTag; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 5294 | tracker = null; |
| 5295 | } |
| 5296 | } |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 5297 | hprinter.printNextItem(pw, rec, baseTime, checkin, |
| 5298 | (flags&DUMP_VERBOSE) != 0); |
Dianne Hackborn | 536456f | 2014-05-23 16:51:05 -0700 | [diff] [blame] | 5299 | } else if (false && rec.eventCode != HistoryItem.EVENT_NONE) { |
| 5300 | // This is an attempt to aggregate the previous state and generate |
| 5301 | //Â fake events to reflect that state at the point where we start |
| 5302 | // 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] | 5303 | if (tracker == null) { |
| 5304 | tracker = new HistoryEventTracker(); |
| 5305 | } |
| 5306 | tracker.updateState(rec.eventCode, rec.eventTag.string, |
| 5307 | rec.eventTag.uid, rec.eventTag.poolIdx); |
| 5308 | } |
| 5309 | } |
| 5310 | if (histStart >= 0) { |
Dianne Hackborn | fc06413 | 2014-06-02 12:42:12 -0700 | [diff] [blame] | 5311 | commitCurrentHistoryBatchLocked(); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 5312 | pw.print(checkin ? "NEXT: " : " NEXT: "); pw.println(lastTime+1); |
| 5313 | } |
| 5314 | } |
| 5315 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 5316 | private void dumpDailyLevelStepSummary(PrintWriter pw, String prefix, String label, |
| 5317 | LevelStepTracker steps, StringBuilder tmpSb, int[] tmpOutInt) { |
| 5318 | if (steps == null) { |
| 5319 | return; |
| 5320 | } |
| 5321 | long timeRemaining = steps.computeTimeEstimate(0, 0, tmpOutInt); |
| 5322 | if (timeRemaining >= 0) { |
| 5323 | pw.print(prefix); pw.print(label); pw.print(" total time: "); |
| 5324 | tmpSb.setLength(0); |
| 5325 | formatTimeMs(tmpSb, timeRemaining); |
| 5326 | pw.print(tmpSb); |
| 5327 | pw.print(" (from "); pw.print(tmpOutInt[0]); |
| 5328 | pw.println(" steps)"); |
| 5329 | } |
| 5330 | for (int i=0; i< STEP_LEVEL_MODES_OF_INTEREST.length; i++) { |
| 5331 | long estimatedTime = steps.computeTimeEstimate(STEP_LEVEL_MODES_OF_INTEREST[i], |
| 5332 | STEP_LEVEL_MODE_VALUES[i], tmpOutInt); |
| 5333 | if (estimatedTime > 0) { |
| 5334 | pw.print(prefix); pw.print(label); pw.print(" "); |
| 5335 | pw.print(STEP_LEVEL_MODE_LABELS[i]); |
| 5336 | pw.print(" time: "); |
| 5337 | tmpSb.setLength(0); |
| 5338 | formatTimeMs(tmpSb, estimatedTime); |
| 5339 | pw.print(tmpSb); |
| 5340 | pw.print(" (from "); pw.print(tmpOutInt[0]); |
| 5341 | pw.println(" steps)"); |
| 5342 | } |
| 5343 | } |
| 5344 | } |
| 5345 | |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 5346 | private void dumpDailyPackageChanges(PrintWriter pw, String prefix, |
| 5347 | ArrayList<PackageChange> changes) { |
| 5348 | if (changes == null) { |
| 5349 | return; |
| 5350 | } |
| 5351 | pw.print(prefix); pw.println("Package changes:"); |
| 5352 | for (int i=0; i<changes.size(); i++) { |
| 5353 | PackageChange pc = changes.get(i); |
| 5354 | if (pc.mUpdate) { |
| 5355 | pw.print(prefix); pw.print(" Update "); pw.print(pc.mPackageName); |
| 5356 | pw.print(" vers="); pw.println(pc.mVersionCode); |
| 5357 | } else { |
| 5358 | pw.print(prefix); pw.print(" Uninstall "); pw.println(pc.mPackageName); |
| 5359 | } |
| 5360 | } |
| 5361 | } |
| 5362 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5363 | /** |
| 5364 | * Dumps a human-readable summary of the battery statistics to the given PrintWriter. |
| 5365 | * |
| 5366 | * @param pw a Printer to receive the dump output. |
| 5367 | */ |
| 5368 | @SuppressWarnings("unused") |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 5369 | 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] | 5370 | prepareForDumpLocked(); |
| 5371 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 5372 | final boolean filtering = (flags |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5373 | & (DUMP_HISTORY_ONLY|DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) != 0; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5374 | |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 5375 | if ((flags&DUMP_HISTORY_ONLY) != 0 || !filtering) { |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 5376 | final long historyTotalSize = getHistoryTotalSize(); |
| 5377 | final long historyUsedSize = getHistoryUsedSize(); |
| 5378 | if (startIteratingHistoryLocked()) { |
| 5379 | try { |
| 5380 | pw.print("Battery History ("); |
| 5381 | pw.print((100*historyUsedSize)/historyTotalSize); |
| 5382 | pw.print("% used, "); |
| 5383 | printSizeValue(pw, historyUsedSize); |
| 5384 | pw.print(" used of "); |
| 5385 | printSizeValue(pw, historyTotalSize); |
| 5386 | pw.print(", "); |
| 5387 | pw.print(getHistoryStringPoolSize()); |
| 5388 | pw.print(" strings using "); |
| 5389 | printSizeValue(pw, getHistoryStringPoolBytes()); |
| 5390 | pw.println("):"); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 5391 | dumpHistoryLocked(pw, flags, histStart, false); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 5392 | pw.println(); |
| 5393 | } finally { |
| 5394 | finishIteratingHistoryLocked(); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 5395 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 5396 | } |
| 5397 | |
| 5398 | if (startIteratingOldHistoryLocked()) { |
| 5399 | try { |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 5400 | final HistoryItem rec = new HistoryItem(); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 5401 | pw.println("Old battery History:"); |
| 5402 | HistoryPrinter hprinter = new HistoryPrinter(); |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 5403 | long baseTime = -1; |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 5404 | while (getNextOldHistoryLocked(rec)) { |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 5405 | if (baseTime < 0) { |
| 5406 | baseTime = rec.time; |
| 5407 | } |
| 5408 | hprinter.printNextItem(pw, rec, baseTime, false, (flags&DUMP_VERBOSE) != 0); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 5409 | } |
| 5410 | pw.println(); |
| 5411 | } finally { |
| 5412 | finishIteratingOldHistoryLocked(); |
| 5413 | } |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 5414 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5415 | } |
| 5416 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5417 | if (filtering && (flags&(DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) == 0) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 5418 | return; |
| 5419 | } |
| 5420 | |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 5421 | if (!filtering) { |
| 5422 | SparseArray<? extends Uid> uidStats = getUidStats(); |
| 5423 | final int NU = uidStats.size(); |
| 5424 | boolean didPid = false; |
| 5425 | long nowRealtime = SystemClock.elapsedRealtime(); |
| 5426 | for (int i=0; i<NU; i++) { |
| 5427 | Uid uid = uidStats.valueAt(i); |
| 5428 | SparseArray<? extends Uid.Pid> pids = uid.getPidStats(); |
| 5429 | if (pids != null) { |
| 5430 | for (int j=0; j<pids.size(); j++) { |
| 5431 | Uid.Pid pid = pids.valueAt(j); |
| 5432 | if (!didPid) { |
| 5433 | pw.println("Per-PID Stats:"); |
| 5434 | didPid = true; |
| 5435 | } |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 5436 | long time = pid.mWakeSumMs + (pid.mWakeNesting > 0 |
| 5437 | ? (nowRealtime - pid.mWakeStartMs) : 0); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 5438 | pw.print(" PID "); pw.print(pids.keyAt(j)); |
| 5439 | pw.print(" wake time: "); |
| 5440 | TimeUtils.formatDuration(time, pw); |
| 5441 | pw.println(""); |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 5442 | } |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 5443 | } |
| 5444 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 5445 | if (didPid) { |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 5446 | pw.println(); |
| 5447 | } |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 5448 | } |
| 5449 | |
| 5450 | if (!filtering || (flags&DUMP_CHARGED_ONLY) != 0) { |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 5451 | if (dumpDurationSteps(pw, " ", "Discharge step durations:", |
| 5452 | getDischargeLevelStepTracker(), false)) { |
Kweku Adams | b0449e0 | 2016-10-12 14:18:27 -0700 | [diff] [blame] | 5453 | long timeRemaining = computeBatteryTimeRemaining( |
| 5454 | SystemClock.elapsedRealtime() * 1000); |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 5455 | if (timeRemaining >= 0) { |
| 5456 | pw.print(" Estimated discharge time remaining: "); |
| 5457 | TimeUtils.formatDuration(timeRemaining / 1000, pw); |
| 5458 | pw.println(); |
| 5459 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 5460 | final LevelStepTracker steps = getDischargeLevelStepTracker(); |
| 5461 | for (int i=0; i< STEP_LEVEL_MODES_OF_INTEREST.length; i++) { |
| 5462 | dumpTimeEstimate(pw, " Estimated ", STEP_LEVEL_MODE_LABELS[i], " time: ", |
| 5463 | steps.computeTimeEstimate(STEP_LEVEL_MODES_OF_INTEREST[i], |
| 5464 | STEP_LEVEL_MODE_VALUES[i], null)); |
| 5465 | } |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 5466 | pw.println(); |
| 5467 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 5468 | if (dumpDurationSteps(pw, " ", "Charge step durations:", |
| 5469 | getChargeLevelStepTracker(), false)) { |
Kweku Adams | b0449e0 | 2016-10-12 14:18:27 -0700 | [diff] [blame] | 5470 | long timeRemaining = computeChargeTimeRemaining( |
| 5471 | SystemClock.elapsedRealtime() * 1000); |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 5472 | if (timeRemaining >= 0) { |
| 5473 | pw.print(" Estimated charge time remaining: "); |
| 5474 | TimeUtils.formatDuration(timeRemaining / 1000, pw); |
| 5475 | pw.println(); |
| 5476 | } |
| 5477 | pw.println(); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 5478 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 5479 | } |
| 5480 | if (!filtering || (flags&(DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) != 0) { |
| 5481 | pw.println("Daily stats:"); |
| 5482 | pw.print(" Current start time: "); |
| 5483 | pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss", |
| 5484 | getCurrentDailyStartTime()).toString()); |
| 5485 | pw.print(" Next min deadline: "); |
| 5486 | pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss", |
| 5487 | getNextMinDailyDeadline()).toString()); |
| 5488 | pw.print(" Next max deadline: "); |
| 5489 | pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss", |
| 5490 | getNextMaxDailyDeadline()).toString()); |
| 5491 | StringBuilder sb = new StringBuilder(64); |
| 5492 | int[] outInt = new int[1]; |
| 5493 | LevelStepTracker dsteps = getDailyDischargeLevelStepTracker(); |
| 5494 | LevelStepTracker csteps = getDailyChargeLevelStepTracker(); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 5495 | ArrayList<PackageChange> pkgc = getDailyPackageChanges(); |
| 5496 | if (dsteps.mNumStepDurations > 0 || csteps.mNumStepDurations > 0 || pkgc != null) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5497 | if ((flags&DUMP_DAILY_ONLY) != 0 || !filtering) { |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 5498 | if (dumpDurationSteps(pw, " ", " Current daily discharge step durations:", |
| 5499 | dsteps, false)) { |
| 5500 | dumpDailyLevelStepSummary(pw, " ", "Discharge", dsteps, |
| 5501 | sb, outInt); |
| 5502 | } |
| 5503 | if (dumpDurationSteps(pw, " ", " Current daily charge step durations:", |
| 5504 | csteps, false)) { |
| 5505 | dumpDailyLevelStepSummary(pw, " ", "Charge", csteps, |
| 5506 | sb, outInt); |
| 5507 | } |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 5508 | dumpDailyPackageChanges(pw, " ", pkgc); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 5509 | } else { |
| 5510 | pw.println(" Current daily steps:"); |
| 5511 | dumpDailyLevelStepSummary(pw, " ", "Discharge", dsteps, |
| 5512 | sb, outInt); |
| 5513 | dumpDailyLevelStepSummary(pw, " ", "Charge", csteps, |
| 5514 | sb, outInt); |
| 5515 | } |
| 5516 | } |
| 5517 | DailyItem dit; |
| 5518 | int curIndex = 0; |
| 5519 | while ((dit=getDailyItemLocked(curIndex)) != null) { |
| 5520 | curIndex++; |
| 5521 | if ((flags&DUMP_DAILY_ONLY) != 0) { |
| 5522 | pw.println(); |
| 5523 | } |
| 5524 | pw.print(" Daily from "); |
| 5525 | pw.print(DateFormat.format("yyyy-MM-dd-HH-mm-ss", dit.mStartTime).toString()); |
| 5526 | pw.print(" to "); |
| 5527 | pw.print(DateFormat.format("yyyy-MM-dd-HH-mm-ss", dit.mEndTime).toString()); |
| 5528 | pw.println(":"); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5529 | if ((flags&DUMP_DAILY_ONLY) != 0 || !filtering) { |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 5530 | if (dumpDurationSteps(pw, " ", |
| 5531 | " Discharge step durations:", dit.mDischargeSteps, false)) { |
| 5532 | dumpDailyLevelStepSummary(pw, " ", "Discharge", dit.mDischargeSteps, |
| 5533 | sb, outInt); |
| 5534 | } |
| 5535 | if (dumpDurationSteps(pw, " ", |
| 5536 | " Charge step durations:", dit.mChargeSteps, false)) { |
| 5537 | dumpDailyLevelStepSummary(pw, " ", "Charge", dit.mChargeSteps, |
| 5538 | sb, outInt); |
| 5539 | } |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 5540 | dumpDailyPackageChanges(pw, " ", dit.mPackageChanges); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 5541 | } else { |
| 5542 | dumpDailyLevelStepSummary(pw, " ", "Discharge", dit.mDischargeSteps, |
| 5543 | sb, outInt); |
| 5544 | dumpDailyLevelStepSummary(pw, " ", "Charge", dit.mChargeSteps, |
| 5545 | sb, outInt); |
| 5546 | } |
| 5547 | } |
| 5548 | pw.println(); |
| 5549 | } |
| 5550 | if (!filtering || (flags&DUMP_CHARGED_ONLY) != 0) { |
Jeff Sharkey | ec43a6b | 2013-04-30 13:33:18 -0700 | [diff] [blame] | 5551 | pw.println("Statistics since last charge:"); |
| 5552 | pw.println(" System starts: " + getStartCount() |
| 5553 | + ", currently on battery: " + getIsOnBattery()); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 5554 | dumpLocked(context, pw, "", STATS_SINCE_CHARGED, reqUid, |
| 5555 | (flags&DUMP_DEVICE_WIFI_ONLY) != 0); |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 5556 | pw.println(); |
Jeff Sharkey | ec43a6b | 2013-04-30 13:33:18 -0700 | [diff] [blame] | 5557 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5558 | } |
| 5559 | |
| 5560 | @SuppressWarnings("unused") |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 5561 | public void dumpCheckinLocked(Context context, PrintWriter pw, |
| 5562 | List<ApplicationInfo> apps, int flags, long histStart) { |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 5563 | prepareForDumpLocked(); |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 5564 | |
| 5565 | dumpLine(pw, 0 /* uid */, "i" /* category */, VERSION_DATA, |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 5566 | CHECKIN_VERSION, getParcelVersion(), getStartPlatformVersion(), |
| 5567 | getEndPlatformVersion()); |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 5568 | |
Dianne Hackborn | 13ac041 | 2013-06-25 19:34:49 -0700 | [diff] [blame] | 5569 | long now = getHistoryBaseTime() + SystemClock.elapsedRealtime(); |
| 5570 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 5571 | final boolean filtering = (flags & |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5572 | (DUMP_HISTORY_ONLY|DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) != 0; |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 5573 | |
| 5574 | if ((flags&DUMP_INCLUDE_HISTORY) != 0 || (flags&DUMP_HISTORY_ONLY) != 0) { |
Dianne Hackborn | 49021f5 | 2013-09-04 18:03:40 -0700 | [diff] [blame] | 5575 | if (startIteratingHistoryLocked()) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 5576 | try { |
| 5577 | for (int i=0; i<getHistoryStringPoolSize(); i++) { |
| 5578 | pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(','); |
| 5579 | pw.print(HISTORY_STRING_POOL); pw.print(','); |
| 5580 | pw.print(i); |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 5581 | pw.print(","); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 5582 | pw.print(getHistoryTagPoolUid(i)); |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 5583 | pw.print(",\""); |
| 5584 | String str = getHistoryTagPoolString(i); |
| 5585 | str = str.replace("\\", "\\\\"); |
| 5586 | str = str.replace("\"", "\\\""); |
| 5587 | pw.print(str); |
| 5588 | pw.print("\""); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 5589 | pw.println(); |
| 5590 | } |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 5591 | dumpHistoryLocked(pw, flags, histStart, true); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 5592 | } finally { |
| 5593 | finishIteratingHistoryLocked(); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 5594 | } |
Dianne Hackborn | 13ac041 | 2013-06-25 19:34:49 -0700 | [diff] [blame] | 5595 | } |
Dianne Hackborn | 13ac041 | 2013-06-25 19:34:49 -0700 | [diff] [blame] | 5596 | } |
| 5597 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5598 | if (filtering && (flags&(DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) == 0) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 5599 | return; |
| 5600 | } |
| 5601 | |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 5602 | if (apps != null) { |
Dianne Hackborn | 9cfba35 | 2016-03-24 17:31:28 -0700 | [diff] [blame] | 5603 | SparseArray<Pair<ArrayList<String>, MutableBoolean>> uids = new SparseArray<>(); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 5604 | for (int i=0; i<apps.size(); i++) { |
| 5605 | ApplicationInfo ai = apps.get(i); |
Dianne Hackborn | 9cfba35 | 2016-03-24 17:31:28 -0700 | [diff] [blame] | 5606 | Pair<ArrayList<String>, MutableBoolean> pkgs = uids.get( |
| 5607 | UserHandle.getAppId(ai.uid)); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 5608 | if (pkgs == null) { |
Dianne Hackborn | 9cfba35 | 2016-03-24 17:31:28 -0700 | [diff] [blame] | 5609 | pkgs = new Pair<>(new ArrayList<String>(), new MutableBoolean(false)); |
| 5610 | uids.put(UserHandle.getAppId(ai.uid), pkgs); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 5611 | } |
Dianne Hackborn | 9cfba35 | 2016-03-24 17:31:28 -0700 | [diff] [blame] | 5612 | pkgs.first.add(ai.packageName); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 5613 | } |
| 5614 | SparseArray<? extends Uid> uidStats = getUidStats(); |
| 5615 | final int NU = uidStats.size(); |
| 5616 | String[] lineArgs = new String[2]; |
| 5617 | for (int i=0; i<NU; i++) { |
Dianne Hackborn | 9cfba35 | 2016-03-24 17:31:28 -0700 | [diff] [blame] | 5618 | int uid = UserHandle.getAppId(uidStats.keyAt(i)); |
| 5619 | Pair<ArrayList<String>, MutableBoolean> pkgs = uids.get(uid); |
| 5620 | if (pkgs != null && !pkgs.second.value) { |
| 5621 | pkgs.second.value = true; |
| 5622 | for (int j=0; j<pkgs.first.size(); j++) { |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 5623 | lineArgs[0] = Integer.toString(uid); |
Dianne Hackborn | 9cfba35 | 2016-03-24 17:31:28 -0700 | [diff] [blame] | 5624 | lineArgs[1] = pkgs.first.get(j); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 5625 | dumpLine(pw, 0 /* uid */, "i" /* category */, UID_DATA, |
| 5626 | (Object[])lineArgs); |
| 5627 | } |
| 5628 | } |
| 5629 | } |
| 5630 | } |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 5631 | if (!filtering || (flags&DUMP_CHARGED_ONLY) != 0) { |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 5632 | dumpDurationSteps(pw, "", DISCHARGE_STEP_DATA, getDischargeLevelStepTracker(), true); |
Dianne Hackborn | d06dcfd | 2014-05-02 13:49:30 -0700 | [diff] [blame] | 5633 | String[] lineArgs = new String[1]; |
Kweku Adams | b0449e0 | 2016-10-12 14:18:27 -0700 | [diff] [blame] | 5634 | long timeRemaining = computeBatteryTimeRemaining(SystemClock.elapsedRealtime() * 1000); |
Dianne Hackborn | d06dcfd | 2014-05-02 13:49:30 -0700 | [diff] [blame] | 5635 | if (timeRemaining >= 0) { |
| 5636 | lineArgs[0] = Long.toString(timeRemaining); |
| 5637 | dumpLine(pw, 0 /* uid */, "i" /* category */, DISCHARGE_TIME_REMAIN_DATA, |
| 5638 | (Object[])lineArgs); |
| 5639 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 5640 | dumpDurationSteps(pw, "", CHARGE_STEP_DATA, getChargeLevelStepTracker(), true); |
Kweku Adams | b0449e0 | 2016-10-12 14:18:27 -0700 | [diff] [blame] | 5641 | timeRemaining = computeChargeTimeRemaining(SystemClock.elapsedRealtime() * 1000); |
Dianne Hackborn | d06dcfd | 2014-05-02 13:49:30 -0700 | [diff] [blame] | 5642 | if (timeRemaining >= 0) { |
| 5643 | lineArgs[0] = Long.toString(timeRemaining); |
| 5644 | dumpLine(pw, 0 /* uid */, "i" /* category */, CHARGE_TIME_REMAIN_DATA, |
| 5645 | (Object[])lineArgs); |
| 5646 | } |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 5647 | dumpCheckinLocked(context, pw, STATS_SINCE_CHARGED, -1, |
| 5648 | (flags&DUMP_DEVICE_WIFI_ONLY) != 0); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 5649 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5650 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5651 | } |