The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2006-2007 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 | |
| 17 | package com.android.internal.os; |
| 18 | |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 19 | import android.annotation.Nullable; |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 20 | import android.app.ActivityManager; |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 21 | import android.bluetooth.BluetoothActivityEnergyInfo; |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 22 | import android.bluetooth.UidTraffic; |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 23 | import android.content.Context; |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 24 | import android.content.Intent; |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 25 | import android.net.ConnectivityManager; |
| 26 | import android.net.NetworkStats; |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 27 | import android.net.wifi.WifiActivityEnergyInfo; |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 28 | import android.net.wifi.WifiManager; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 29 | import android.os.BatteryManager; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 30 | import android.os.BatteryStats; |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 31 | import android.os.Build; |
Dianne Hackborn | 8bdf593 | 2010-10-15 12:54:40 -0700 | [diff] [blame] | 32 | import android.os.FileUtils; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 33 | import android.os.Handler; |
Jeff Brown | 6f357d3 | 2014-01-15 20:40:55 -0800 | [diff] [blame] | 34 | import android.os.Looper; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 35 | import android.os.Message; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 36 | import android.os.Parcel; |
| 37 | import android.os.ParcelFormatException; |
| 38 | import android.os.Parcelable; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 39 | import android.os.Process; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 40 | import android.os.SystemClock; |
Jeff Sharkey | 418d12d | 2011-12-13 15:38:03 -0800 | [diff] [blame] | 41 | import android.os.SystemProperties; |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 42 | import android.os.WorkSource; |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 43 | import android.telephony.DataConnectionRealTimeInfo; |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 44 | import android.telephony.ModemActivityInfo; |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 45 | import android.telephony.ServiceState; |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 46 | import android.telephony.SignalStrength; |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 47 | import android.telephony.TelephonyManager; |
Jeff Sharkey | 9da2f1e | 2014-08-14 12:55:00 -0700 | [diff] [blame] | 48 | import android.text.TextUtils; |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 49 | import android.util.ArrayMap; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 50 | import android.util.Log; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 51 | import android.util.LogWriter; |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 52 | import android.util.MutableInt; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 53 | import android.util.PrintWriterPrinter; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 54 | import android.util.Printer; |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 55 | import android.util.Slog; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 56 | import android.util.SparseArray; |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 57 | import android.util.SparseIntArray; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 58 | import android.util.SparseLongArray; |
Dianne Hackborn | ae38445 | 2011-06-28 12:33:48 -0700 | [diff] [blame] | 59 | import android.util.TimeUtils; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 60 | import android.util.Xml; |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 61 | import android.view.Display; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 62 | |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 63 | import com.android.internal.net.NetworkStatsFactory; |
Dianne Hackborn | d0c5b9a | 2014-02-21 16:19:05 -0800 | [diff] [blame] | 64 | import com.android.internal.util.ArrayUtils; |
Dianne Hackborn | 8c84109 | 2013-06-24 13:46:13 -0700 | [diff] [blame] | 65 | import com.android.internal.util.FastPrintWriter; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 66 | import com.android.internal.util.FastXmlSerializer; |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 67 | import com.android.internal.util.JournaledFile; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 68 | import com.android.internal.util.XmlUtils; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 69 | import com.android.server.NetworkManagementSocketTagger; |
| 70 | import libcore.util.EmptyArray; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 71 | import org.xmlpull.v1.XmlPullParser; |
| 72 | import org.xmlpull.v1.XmlPullParserException; |
| 73 | import org.xmlpull.v1.XmlSerializer; |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 74 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 75 | import java.io.ByteArrayOutputStream; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 76 | import java.io.File; |
| 77 | import java.io.FileInputStream; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 78 | import java.io.FileNotFoundException; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 79 | import java.io.FileOutputStream; |
| 80 | import java.io.IOException; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 81 | import java.io.PrintWriter; |
Wojciech Staszkiewicz | 9e9e2e7 | 2015-05-08 14:58:46 +0100 | [diff] [blame] | 82 | import java.nio.charset.StandardCharsets; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 83 | import java.util.ArrayList; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 84 | import java.util.Calendar; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 85 | import java.util.HashMap; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 86 | import java.util.Iterator; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 87 | import java.util.Map; |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 88 | import java.util.concurrent.atomic.AtomicInteger; |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 89 | import java.util.concurrent.locks.ReentrantLock; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 90 | |
| 91 | /** |
| 92 | * All information we are collecting about things that can happen that impact |
| 93 | * battery life. All times are represented in microseconds except where indicated |
| 94 | * otherwise. |
| 95 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 96 | public class BatteryStatsImpl extends BatteryStats { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 97 | private static final String TAG = "BatteryStatsImpl"; |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 98 | private static final boolean DEBUG = false; |
Adam Lesinski | a7c90c8 | 2015-06-18 14:52:24 -0700 | [diff] [blame] | 99 | public static final boolean DEBUG_ENERGY = false; |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 100 | private static final boolean DEBUG_ENERGY_CPU = DEBUG_ENERGY; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 101 | private static final boolean DEBUG_HISTORY = false; |
Dianne Hackborn | e8c88e6 | 2011-08-17 19:09:09 -0700 | [diff] [blame] | 102 | private static final boolean USE_OLD_HISTORY = false; // for debugging. |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 103 | |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 104 | // TODO: remove "tcp" from network methods, since we measure total stats. |
| 105 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 106 | // In-memory Parcel magic number, used to detect attempts to unmarshall bad data |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 107 | private static final int MAGIC = 0xBA757475; // 'BATSTATS' |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 108 | |
| 109 | // Current on-disk Parcel version |
Phil Weaver | da80d67 | 2016-03-15 16:25:46 -0700 | [diff] [blame] | 110 | private static final int VERSION = 142 + (USE_OLD_HISTORY ? 1000 : 0); |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 111 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 112 | // Maximum number of items we will record in the history. |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 113 | private static final int MAX_HISTORY_ITEMS = 2000; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 114 | |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 115 | // No, really, THIS is the maximum number of items we will record in the history. |
| 116 | private static final int MAX_MAX_HISTORY_ITEMS = 3000; |
| 117 | |
Dianne Hackborn | 9e0f5d9 | 2010-02-22 15:05:42 -0800 | [diff] [blame] | 118 | // The maximum number of names wakelocks we will keep track of |
| 119 | // per uid; once the limit is reached, we batch the remaining wakelocks |
| 120 | // in to one common name. |
Dianne Hackborn | acc4a12 | 2014-08-18 16:33:44 -0700 | [diff] [blame] | 121 | private static final int MAX_WAKELOCKS_PER_UID = 100; |
Dianne Hackborn | c24ab86 | 2011-10-18 15:55:03 -0700 | [diff] [blame] | 122 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 123 | // Number of transmit power states the Wifi controller can be in. |
| 124 | private static final int NUM_WIFI_TX_LEVELS = 1; |
| 125 | |
| 126 | // Number of transmit power states the Bluetooth controller can be in. |
| 127 | private static final int NUM_BT_TX_LEVELS = 1; |
| 128 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 129 | protected Clocks mClocks; |
| 130 | |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 131 | private final JournaledFile mFile; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 132 | public final AtomicFile mCheckinFile; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 133 | public final AtomicFile mDailyFile; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 134 | |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 135 | static final int MSG_UPDATE_WAKELOCKS = 1; |
| 136 | static final int MSG_REPORT_POWER_CHANGE = 2; |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 137 | static final int MSG_REPORT_CHARGING = 3; |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 138 | static final long DELAY_UPDATE_WAKELOCKS = 5*1000; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 139 | |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 140 | private final KernelWakelockReader mKernelWakelockReader = new KernelWakelockReader(); |
| 141 | private final KernelWakelockStats mTmpWakelockStats = new KernelWakelockStats(); |
| 142 | |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 143 | private final KernelUidCpuTimeReader mKernelUidCpuTimeReader = new KernelUidCpuTimeReader(); |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 144 | private KernelCpuSpeedReader[] mKernelCpuSpeedReaders; |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 145 | |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 146 | public interface BatteryCallback { |
| 147 | public void batteryNeedsCpuUpdate(); |
| 148 | public void batteryPowerChanged(boolean onBattery); |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 149 | public void batterySendBroadcast(Intent intent); |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 150 | } |
| 151 | |
| 152 | final class MyHandler extends Handler { |
Jeff Brown | 6f357d3 | 2014-01-15 20:40:55 -0800 | [diff] [blame] | 153 | public MyHandler(Looper looper) { |
| 154 | super(looper, null, true); |
| 155 | } |
| 156 | |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 157 | @Override |
| 158 | public void handleMessage(Message msg) { |
| 159 | BatteryCallback cb = mCallback; |
| 160 | switch (msg.what) { |
| 161 | case MSG_UPDATE_WAKELOCKS: |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 162 | synchronized (BatteryStatsImpl.this) { |
| 163 | updateCpuTimeLocked(); |
| 164 | } |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 165 | if (cb != null) { |
| 166 | cb.batteryNeedsCpuUpdate(); |
| 167 | } |
| 168 | break; |
| 169 | case MSG_REPORT_POWER_CHANGE: |
| 170 | if (cb != null) { |
| 171 | cb.batteryPowerChanged(msg.arg1 != 0); |
| 172 | } |
| 173 | break; |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 174 | case MSG_REPORT_CHARGING: |
| 175 | if (cb != null) { |
| 176 | final String action; |
| 177 | synchronized (BatteryStatsImpl.this) { |
| 178 | action = mCharging ? BatteryManager.ACTION_CHARGING |
| 179 | : BatteryManager.ACTION_DISCHARGING; |
| 180 | } |
| 181 | Intent intent = new Intent(action); |
| 182 | intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT); |
| 183 | cb.batterySendBroadcast(intent); |
| 184 | } |
| 185 | break; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 186 | } |
| 187 | } |
| 188 | } |
| 189 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 190 | public interface Clocks { |
| 191 | public long elapsedRealtime(); |
| 192 | public long uptimeMillis(); |
| 193 | } |
| 194 | |
| 195 | public static class SystemClocks implements Clocks { |
| 196 | public long elapsedRealtime() { |
| 197 | return SystemClock.elapsedRealtime(); |
| 198 | } |
| 199 | |
| 200 | public long uptimeMillis() { |
| 201 | return SystemClock.uptimeMillis(); |
| 202 | } |
| 203 | } |
| 204 | |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 205 | public interface ExternalStatsSync { |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 206 | public static final int UPDATE_CPU = 0x01; |
| 207 | public static final int UPDATE_WIFI = 0x02; |
| 208 | public static final int UPDATE_RADIO = 0x04; |
| 209 | public static final int UPDATE_BT = 0x08; |
| 210 | public static final int UPDATE_ALL = UPDATE_CPU | UPDATE_WIFI | UPDATE_RADIO | UPDATE_BT; |
| 211 | |
| 212 | void scheduleSync(String reason, int flags); |
Adam Lesinski | 61db88f | 2015-07-01 15:05:07 -0700 | [diff] [blame] | 213 | void scheduleCpuSyncDueToRemovedUid(int uid); |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 214 | } |
| 215 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 216 | public final MyHandler mHandler; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 217 | private final ExternalStatsSync mExternalSync; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 218 | |
| 219 | private BatteryCallback mCallback; |
| 220 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 221 | /** |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 222 | * Mapping isolated uids to the actual owning app uid. |
| 223 | */ |
| 224 | final SparseIntArray mIsolatedUids = new SparseIntArray(); |
| 225 | |
| 226 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 227 | * The statistics we have collected organized by uids. |
| 228 | */ |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 229 | final SparseArray<BatteryStatsImpl.Uid> mUidStats = new SparseArray<>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 230 | |
| 231 | // A set of pools of currently active timers. When a timer is queried, we will divide the |
| 232 | // elapsed time by the number of active timers to arrive at that timer's share of the time. |
| 233 | // In order to do this, we must refresh each timer whenever the number of active timers |
| 234 | // changes. |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 235 | final ArrayList<StopwatchTimer> mPartialTimers = new ArrayList<>(); |
| 236 | final ArrayList<StopwatchTimer> mFullTimers = new ArrayList<>(); |
| 237 | final ArrayList<StopwatchTimer> mWindowTimers = new ArrayList<>(); |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 238 | final ArrayList<StopwatchTimer> mDrawTimers = new ArrayList<>(); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 239 | final SparseArray<ArrayList<StopwatchTimer>> mSensorTimers = new SparseArray<>(); |
| 240 | final ArrayList<StopwatchTimer> mWifiRunningTimers = new ArrayList<>(); |
| 241 | final ArrayList<StopwatchTimer> mFullWifiLockTimers = new ArrayList<>(); |
| 242 | final ArrayList<StopwatchTimer> mWifiMulticastTimers = new ArrayList<>(); |
| 243 | final ArrayList<StopwatchTimer> mWifiScanTimers = new ArrayList<>(); |
| 244 | final SparseArray<ArrayList<StopwatchTimer>> mWifiBatchedScanTimers = new SparseArray<>(); |
| 245 | final ArrayList<StopwatchTimer> mAudioTurnedOnTimers = new ArrayList<>(); |
| 246 | final ArrayList<StopwatchTimer> mVideoTurnedOnTimers = new ArrayList<>(); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 247 | final ArrayList<StopwatchTimer> mFlashlightTurnedOnTimers = new ArrayList<>(); |
| 248 | final ArrayList<StopwatchTimer> mCameraTurnedOnTimers = new ArrayList<>(); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 249 | final ArrayList<StopwatchTimer> mBluetoothScanOnTimers = new ArrayList<>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 250 | |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 251 | // Last partial timers we use for distributing CPU usage. |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 252 | final ArrayList<StopwatchTimer> mLastPartialTimers = new ArrayList<>(); |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 253 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 254 | // These are the objects that will want to do something when the device |
| 255 | // is unplugged from power. |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 256 | protected final TimeBase mOnBatteryTimeBase = new TimeBase(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 257 | |
| 258 | // These are the objects that will want to do something when the device |
| 259 | // is unplugged from power *and* the screen is off. |
| 260 | final TimeBase mOnBatteryScreenOffTimeBase = new TimeBase(); |
| 261 | |
| 262 | // Set to true when we want to distribute CPU across wakelocks for the next |
| 263 | // CPU update, even if we aren't currently running wake locks. |
| 264 | boolean mDistributeWakelockCpu; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 265 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 266 | boolean mShuttingDown; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 267 | |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 268 | final HistoryEventTracker mActiveEvents = new HistoryEventTracker(); |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 269 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 270 | long mHistoryBaseTime; |
| 271 | boolean mHaveBatteryLevel = false; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 272 | boolean mRecordingHistory = false; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 273 | int mNumHistoryItems; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 274 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 275 | static final int MAX_HISTORY_BUFFER = 256*1024; // 256KB |
| 276 | static final int MAX_MAX_HISTORY_BUFFER = 320*1024; // 320KB |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 277 | final Parcel mHistoryBuffer = Parcel.obtain(); |
| 278 | final HistoryItem mHistoryLastWritten = new HistoryItem(); |
| 279 | final HistoryItem mHistoryLastLastWritten = new HistoryItem(); |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 280 | final HistoryItem mHistoryReadTmp = new HistoryItem(); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 281 | final HistoryItem mHistoryAddTmp = new HistoryItem(); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 282 | final HashMap<HistoryTag, Integer> mHistoryTagPool = new HashMap<>(); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 283 | String[] mReadHistoryStrings; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 284 | int[] mReadHistoryUids; |
| 285 | int mReadHistoryChars; |
| 286 | int mNextHistoryTagIdx = 0; |
| 287 | int mNumHistoryTagChars = 0; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 288 | int mHistoryBufferLastPos = -1; |
| 289 | boolean mHistoryOverflow = false; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 290 | int mActiveHistoryStates = 0xffffffff; |
| 291 | int mActiveHistoryStates2 = 0xffffffff; |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 292 | long mLastHistoryElapsedRealtime = 0; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 293 | long mTrackRunningHistoryElapsedRealtime = 0; |
| 294 | long mTrackRunningHistoryUptime = 0; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 295 | |
| 296 | final HistoryItem mHistoryCur = new HistoryItem(); |
| 297 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 298 | HistoryItem mHistory; |
| 299 | HistoryItem mHistoryEnd; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 300 | HistoryItem mHistoryLastEnd; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 301 | HistoryItem mHistoryCache; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 302 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 303 | // Used by computeHistoryStepDetails |
| 304 | HistoryStepDetails mLastHistoryStepDetails = null; |
| 305 | byte mLastHistoryStepLevel = 0; |
| 306 | final HistoryStepDetails mCurHistoryStepDetails = new HistoryStepDetails(); |
| 307 | final HistoryStepDetails mReadHistoryStepDetails = new HistoryStepDetails(); |
| 308 | final HistoryStepDetails mTmpHistoryStepDetails = new HistoryStepDetails(); |
Adam Lesinski | 7b83b0c | 2015-06-05 12:59:36 -0700 | [diff] [blame] | 309 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 310 | /** |
Adam Lesinski | 7b83b0c | 2015-06-05 12:59:36 -0700 | [diff] [blame] | 311 | * Total time (in milliseconds) spent executing in user code. |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 312 | */ |
| 313 | long mLastStepCpuUserTime; |
| 314 | long mCurStepCpuUserTime; |
| 315 | /** |
Adam Lesinski | 7b83b0c | 2015-06-05 12:59:36 -0700 | [diff] [blame] | 316 | * Total time (in milliseconds) spent executing in kernel code. |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 317 | */ |
| 318 | long mLastStepCpuSystemTime; |
| 319 | long mCurStepCpuSystemTime; |
| 320 | /** |
Adam Lesinski | 7b83b0c | 2015-06-05 12:59:36 -0700 | [diff] [blame] | 321 | * Times from /proc/stat (but measured in milliseconds). |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 322 | */ |
| 323 | long mLastStepStatUserTime; |
| 324 | long mLastStepStatSystemTime; |
| 325 | long mLastStepStatIOWaitTime; |
| 326 | long mLastStepStatIrqTime; |
| 327 | long mLastStepStatSoftIrqTime; |
| 328 | long mLastStepStatIdleTime; |
| 329 | long mCurStepStatUserTime; |
| 330 | long mCurStepStatSystemTime; |
| 331 | long mCurStepStatIOWaitTime; |
| 332 | long mCurStepStatIrqTime; |
| 333 | long mCurStepStatSoftIrqTime; |
| 334 | long mCurStepStatIdleTime; |
| 335 | |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 336 | private HistoryItem mHistoryIterator; |
| 337 | private boolean mReadOverflow; |
| 338 | private boolean mIteratingHistory; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 339 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 340 | int mStartCount; |
| 341 | |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 342 | long mStartClockTime; |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 343 | String mStartPlatformVersion; |
| 344 | String mEndPlatformVersion; |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 345 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 346 | long mUptime; |
| 347 | long mUptimeStart; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 348 | long mRealtime; |
| 349 | long mRealtimeStart; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 350 | |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 351 | int mWakeLockNesting; |
| 352 | boolean mWakeLockImportant; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 353 | public boolean mRecordAllHistory; |
Dianne Hackborn | 9a75543 | 2014-05-15 17:05:22 -0700 | [diff] [blame] | 354 | boolean mNoAutoReset; |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 355 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 356 | int mScreenState = Display.STATE_UNKNOWN; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 357 | StopwatchTimer mScreenOnTimer; |
Amith Yamasani | 3718aaa | 2009-06-09 06:32:35 -0700 | [diff] [blame] | 358 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 359 | int mScreenBrightnessBin = -1; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 360 | final StopwatchTimer[] mScreenBrightnessTimer = new StopwatchTimer[NUM_SCREEN_BRIGHTNESS_BINS]; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 361 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 362 | boolean mInteractive; |
| 363 | StopwatchTimer mInteractiveTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 364 | |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 365 | boolean mPowerSaveModeEnabled; |
| 366 | StopwatchTimer mPowerSaveModeEnabledTimer; |
| 367 | |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 368 | boolean mDeviceIdling; |
| 369 | StopwatchTimer mDeviceIdlingTimer; |
| 370 | |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 371 | boolean mDeviceLightIdling; |
| 372 | StopwatchTimer mDeviceLightIdlingTimer; |
| 373 | |
| 374 | int mDeviceIdleMode; |
| 375 | long mLastIdleTimeStart; |
| 376 | long mLongestLightIdleTime; |
| 377 | long mLongestFullIdleTime; |
| 378 | StopwatchTimer mDeviceIdleModeLightTimer; |
| 379 | StopwatchTimer mDeviceIdleModeFullTimer; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 380 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 381 | boolean mPhoneOn; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 382 | StopwatchTimer mPhoneOnTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 383 | |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 384 | int mAudioOnNesting; |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 385 | StopwatchTimer mAudioOnTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 386 | |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 387 | int mVideoOnNesting; |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 388 | StopwatchTimer mVideoOnTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 389 | |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 390 | int mFlashlightOnNesting; |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 391 | StopwatchTimer mFlashlightOnTimer; |
| 392 | |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 393 | int mCameraOnNesting; |
| 394 | StopwatchTimer mCameraOnTimer; |
| 395 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 396 | int mPhoneSignalStrengthBin = -1; |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 397 | int mPhoneSignalStrengthBinRaw = -1; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 398 | final StopwatchTimer[] mPhoneSignalStrengthsTimer = |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 399 | new StopwatchTimer[SignalStrength.NUM_SIGNAL_STRENGTH_BINS]; |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 400 | |
| 401 | StopwatchTimer mPhoneSignalScanningTimer; |
| 402 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 403 | int mPhoneDataConnectionType = -1; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 404 | final StopwatchTimer[] mPhoneDataConnectionsTimer = |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 405 | new StopwatchTimer[NUM_DATA_CONNECTION_TYPES]; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 406 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 407 | final LongSamplingCounter[] mNetworkByteActivityCounters = |
| 408 | new LongSamplingCounter[NUM_NETWORK_ACTIVITY_TYPES]; |
| 409 | final LongSamplingCounter[] mNetworkPacketActivityCounters = |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 410 | new LongSamplingCounter[NUM_NETWORK_ACTIVITY_TYPES]; |
| 411 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 412 | /** |
| 413 | * The WiFi controller activity (time in tx, rx, idle, and power consumed) for the device. |
| 414 | */ |
| 415 | ControllerActivityCounterImpl mWifiActivity; |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 416 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 417 | /** |
| 418 | * The Bluetooth controller activity (time in tx, rx, idle, and power consumed) for the device. |
| 419 | */ |
| 420 | ControllerActivityCounterImpl mBluetoothActivity; |
| 421 | |
| 422 | /** |
| 423 | * The Modem controller activity (time in tx, rx, idle, and power consumed) for the device. |
| 424 | */ |
| 425 | ControllerActivityCounterImpl mModemActivity; |
| 426 | |
| 427 | /** |
| 428 | * Whether the device supports WiFi controller energy reporting. This is set to true on |
| 429 | * the first WiFi energy report. See {@link #mWifiActivity}. |
| 430 | */ |
| 431 | boolean mHasWifiReporting = false; |
| 432 | |
| 433 | /** |
| 434 | * Whether the device supports Bluetooth controller energy reporting. This is set to true on |
| 435 | * the first Bluetooth energy report. See {@link #mBluetoothActivity}. |
| 436 | */ |
| 437 | boolean mHasBluetoothReporting = false; |
| 438 | |
| 439 | /** |
| 440 | * Whether the device supports Modem controller energy reporting. This is set to true on |
| 441 | * the first Modem energy report. See {@link #mModemActivity}. |
| 442 | */ |
| 443 | boolean mHasModemReporting = false; |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 444 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 445 | boolean mWifiOn; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 446 | StopwatchTimer mWifiOnTimer; |
Eric Shienbrood | d4c5f89 | 2009-03-24 18:13:20 -0700 | [diff] [blame] | 447 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 448 | boolean mGlobalWifiRunning; |
| 449 | StopwatchTimer mGlobalWifiRunningTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 450 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 451 | int mWifiState = -1; |
| 452 | final StopwatchTimer[] mWifiStateTimer = new StopwatchTimer[NUM_WIFI_STATES]; |
| 453 | |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 454 | int mWifiSupplState = -1; |
| 455 | final StopwatchTimer[] mWifiSupplStateTimer = new StopwatchTimer[NUM_WIFI_SUPPL_STATES]; |
| 456 | |
| 457 | int mWifiSignalStrengthBin = -1; |
| 458 | final StopwatchTimer[] mWifiSignalStrengthsTimer = |
| 459 | new StopwatchTimer[NUM_WIFI_SIGNAL_STRENGTH_BINS]; |
| 460 | |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 461 | int mBluetoothScanNesting; |
| 462 | StopwatchTimer mBluetoothScanTimer; |
| 463 | |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 464 | int mMobileRadioPowerState = DataConnectionRealTimeInfo.DC_POWER_STATE_LOW; |
Dianne Hackborn | f7097a5 | 2014-05-13 09:56:14 -0700 | [diff] [blame] | 465 | long mMobileRadioActiveStartTime; |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 466 | StopwatchTimer mMobileRadioActiveTimer; |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 467 | StopwatchTimer mMobileRadioActivePerAppTimer; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 468 | LongSamplingCounter mMobileRadioActiveAdjustedTime; |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 469 | LongSamplingCounter mMobileRadioActiveUnknownTime; |
| 470 | LongSamplingCounter mMobileRadioActiveUnknownCount; |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 471 | |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 472 | int mWifiRadioPowerState = DataConnectionRealTimeInfo.DC_POWER_STATE_LOW; |
| 473 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 474 | /** |
| 475 | * These provide time bases that discount the time the device is plugged |
| 476 | * in to power. |
| 477 | */ |
| 478 | boolean mOnBattery; |
| 479 | boolean mOnBatteryInternal; |
Amith Yamasani | 3718aaa | 2009-06-09 06:32:35 -0700 | [diff] [blame] | 480 | |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 481 | /** |
| 482 | * External reporting of whether the device is actually charging. |
| 483 | */ |
| 484 | boolean mCharging = true; |
| 485 | int mLastChargingStateLevel; |
| 486 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 487 | /* |
| 488 | * These keep track of battery levels (1-100) at the last plug event and the last unplug event. |
| 489 | */ |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 490 | int mDischargeStartLevel; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 491 | int mDischargeUnplugLevel; |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 492 | int mDischargePlugLevel; |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 493 | int mDischargeCurrentLevel; |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 494 | int mCurrentBatteryLevel; |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 495 | int mLowDischargeAmountSinceCharge; |
| 496 | int mHighDischargeAmountSinceCharge; |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 497 | int mDischargeScreenOnUnplugLevel; |
| 498 | int mDischargeScreenOffUnplugLevel; |
| 499 | int mDischargeAmountScreenOn; |
| 500 | int mDischargeAmountScreenOnSinceCharge; |
| 501 | int mDischargeAmountScreenOff; |
| 502 | int mDischargeAmountScreenOffSinceCharge; |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 503 | |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 504 | static final int MAX_LEVEL_STEPS = 200; |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 505 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 506 | int mInitStepMode = 0; |
| 507 | int mCurStepMode = 0; |
| 508 | int mModStepMode = 0; |
| 509 | |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 510 | int mLastDischargeStepLevel; |
Dianne Hackborn | 2932513 | 2014-05-21 15:01:03 -0700 | [diff] [blame] | 511 | int mMinDischargeStepLevel; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 512 | final LevelStepTracker mDischargeStepTracker = new LevelStepTracker(MAX_LEVEL_STEPS); |
| 513 | final LevelStepTracker mDailyDischargeStepTracker = new LevelStepTracker(MAX_LEVEL_STEPS*2); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 514 | ArrayList<PackageChange> mDailyPackageChanges; |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 515 | |
| 516 | int mLastChargeStepLevel; |
Dianne Hackborn | 2932513 | 2014-05-21 15:01:03 -0700 | [diff] [blame] | 517 | int mMaxChargeStepLevel; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 518 | final LevelStepTracker mChargeStepTracker = new LevelStepTracker(MAX_LEVEL_STEPS); |
| 519 | final LevelStepTracker mDailyChargeStepTracker = new LevelStepTracker(MAX_LEVEL_STEPS*2); |
| 520 | |
| 521 | static final int MAX_DAILY_ITEMS = 10; |
| 522 | |
| 523 | long mDailyStartTime = 0; |
| 524 | long mNextMinDailyDeadline = 0; |
| 525 | long mNextMaxDailyDeadline = 0; |
| 526 | |
| 527 | final ArrayList<DailyItem> mDailyItems = new ArrayList<>(); |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 528 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 529 | long mLastWriteTime = 0; // Milliseconds |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 530 | |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 531 | private int mPhoneServiceState = -1; |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 532 | private int mPhoneServiceStateRaw = -1; |
| 533 | private int mPhoneSimStateRaw = -1; |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 534 | |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 535 | private int mNumConnectivityChange; |
| 536 | private int mLoadedNumConnectivityChange; |
| 537 | private int mUnpluggedNumConnectivityChange; |
| 538 | |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 539 | private final NetworkStats.Entry mTmpNetworkStatsEntry = new NetworkStats.Entry(); |
| 540 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 541 | private PowerProfile mPowerProfile; |
| 542 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 543 | /* |
| 544 | * Holds a SamplingTimer associated with each kernel wakelock name being tracked. |
| 545 | */ |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 546 | private final HashMap<String, SamplingTimer> mKernelWakelockStats = new HashMap<>(); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 547 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 548 | public Map<String, ? extends Timer> getKernelWakelockStats() { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 549 | return mKernelWakelockStats; |
| 550 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 551 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 552 | String mLastWakeupReason = null; |
| 553 | long mLastWakeupUptimeMs = 0; |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 554 | private final HashMap<String, SamplingTimer> mWakeupReasonStats = new HashMap<>(); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 555 | |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 556 | public Map<String, ? extends Timer> getWakeupReasonStats() { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 557 | return mWakeupReasonStats; |
| 558 | } |
| 559 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 560 | public BatteryStatsImpl() { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 561 | this(new SystemClocks()); |
| 562 | } |
| 563 | |
| 564 | public BatteryStatsImpl(Clocks clocks) { |
| 565 | init(clocks); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 566 | mFile = null; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 567 | mCheckinFile = null; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 568 | mDailyFile = null; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 569 | mHandler = null; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 570 | mExternalSync = null; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 571 | clearHistoryLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 572 | } |
| 573 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 574 | private void init(Clocks clocks) { |
| 575 | mClocks = clocks; |
| 576 | mMobileNetworkStats = new NetworkStats[] { |
| 577 | new NetworkStats(mClocks.elapsedRealtime(), 50), |
| 578 | new NetworkStats(mClocks.elapsedRealtime(), 50), |
| 579 | new NetworkStats(mClocks.elapsedRealtime(), 50) |
| 580 | }; |
| 581 | mWifiNetworkStats = new NetworkStats[] { |
| 582 | new NetworkStats(mClocks.elapsedRealtime(), 50), |
| 583 | new NetworkStats(mClocks.elapsedRealtime(), 50), |
| 584 | new NetworkStats(mClocks.elapsedRealtime(), 50) |
| 585 | }; |
| 586 | } |
| 587 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 588 | public static interface TimeBaseObs { |
| 589 | void onTimeStarted(long elapsedRealtime, long baseUptime, long baseRealtime); |
| 590 | void onTimeStopped(long elapsedRealtime, long baseUptime, long baseRealtime); |
| 591 | } |
| 592 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 593 | // methods are protected not private to be VisibleForTesting |
| 594 | public static class TimeBase { |
| 595 | protected final ArrayList<TimeBaseObs> mObservers = new ArrayList<>(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 596 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 597 | protected long mUptime; |
| 598 | protected long mRealtime; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 599 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 600 | protected boolean mRunning; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 601 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 602 | protected long mPastUptime; |
| 603 | protected long mUptimeStart; |
| 604 | protected long mPastRealtime; |
| 605 | protected long mRealtimeStart; |
| 606 | protected long mUnpluggedUptime; |
| 607 | protected long mUnpluggedRealtime; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 608 | |
| 609 | public void dump(PrintWriter pw, String prefix) { |
| 610 | StringBuilder sb = new StringBuilder(128); |
| 611 | pw.print(prefix); pw.print("mRunning="); pw.println(mRunning); |
| 612 | sb.setLength(0); |
| 613 | sb.append(prefix); |
| 614 | sb.append("mUptime="); |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 615 | formatTimeMs(sb, mUptime / 1000); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 616 | pw.println(sb.toString()); |
| 617 | sb.setLength(0); |
| 618 | sb.append(prefix); |
| 619 | sb.append("mRealtime="); |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 620 | formatTimeMs(sb, mRealtime / 1000); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 621 | pw.println(sb.toString()); |
| 622 | sb.setLength(0); |
| 623 | sb.append(prefix); |
| 624 | sb.append("mPastUptime="); |
| 625 | formatTimeMs(sb, mPastUptime / 1000); sb.append("mUptimeStart="); |
| 626 | formatTimeMs(sb, mUptimeStart / 1000); |
| 627 | sb.append("mUnpluggedUptime="); formatTimeMs(sb, mUnpluggedUptime / 1000); |
| 628 | pw.println(sb.toString()); |
| 629 | sb.setLength(0); |
| 630 | sb.append(prefix); |
| 631 | sb.append("mPastRealtime="); |
| 632 | formatTimeMs(sb, mPastRealtime / 1000); sb.append("mRealtimeStart="); |
| 633 | formatTimeMs(sb, mRealtimeStart / 1000); |
| 634 | sb.append("mUnpluggedRealtime="); formatTimeMs(sb, mUnpluggedRealtime / 1000); |
| 635 | pw.println(sb.toString()); |
| 636 | } |
| 637 | |
| 638 | public void add(TimeBaseObs observer) { |
| 639 | mObservers.add(observer); |
| 640 | } |
| 641 | |
| 642 | public void remove(TimeBaseObs observer) { |
| 643 | if (!mObservers.remove(observer)) { |
| 644 | Slog.wtf(TAG, "Removed unknown observer: " + observer); |
| 645 | } |
| 646 | } |
| 647 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 648 | public boolean hasObserver(TimeBaseObs observer) { |
| 649 | return mObservers.contains(observer); |
| 650 | } |
| 651 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 652 | public void init(long uptime, long realtime) { |
| 653 | mRealtime = 0; |
| 654 | mUptime = 0; |
| 655 | mPastUptime = 0; |
| 656 | mPastRealtime = 0; |
| 657 | mUptimeStart = uptime; |
| 658 | mRealtimeStart = realtime; |
| 659 | mUnpluggedUptime = getUptime(mUptimeStart); |
| 660 | mUnpluggedRealtime = getRealtime(mRealtimeStart); |
| 661 | } |
| 662 | |
| 663 | public void reset(long uptime, long realtime) { |
| 664 | if (!mRunning) { |
| 665 | mPastUptime = 0; |
| 666 | mPastRealtime = 0; |
| 667 | } else { |
| 668 | mUptimeStart = uptime; |
| 669 | mRealtimeStart = realtime; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 670 | // TODO: Since mUptimeStart was just reset and we are running, getUptime will |
| 671 | // just return mPastUptime. Also, are we sure we don't want to reset that? |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 672 | mUnpluggedUptime = getUptime(uptime); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 673 | // TODO: likewise. |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 674 | mUnpluggedRealtime = getRealtime(realtime); |
| 675 | } |
| 676 | } |
| 677 | |
| 678 | public long computeUptime(long curTime, int which) { |
| 679 | switch (which) { |
| 680 | case STATS_SINCE_CHARGED: |
| 681 | return mUptime + getUptime(curTime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 682 | case STATS_CURRENT: |
| 683 | return getUptime(curTime); |
| 684 | case STATS_SINCE_UNPLUGGED: |
| 685 | return getUptime(curTime) - mUnpluggedUptime; |
| 686 | } |
| 687 | return 0; |
| 688 | } |
| 689 | |
| 690 | public long computeRealtime(long curTime, int which) { |
| 691 | switch (which) { |
| 692 | case STATS_SINCE_CHARGED: |
| 693 | return mRealtime + getRealtime(curTime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 694 | case STATS_CURRENT: |
| 695 | return getRealtime(curTime); |
| 696 | case STATS_SINCE_UNPLUGGED: |
| 697 | return getRealtime(curTime) - mUnpluggedRealtime; |
| 698 | } |
| 699 | return 0; |
| 700 | } |
| 701 | |
| 702 | public long getUptime(long curTime) { |
| 703 | long time = mPastUptime; |
| 704 | if (mRunning) { |
| 705 | time += curTime - mUptimeStart; |
| 706 | } |
| 707 | return time; |
| 708 | } |
| 709 | |
| 710 | public long getRealtime(long curTime) { |
| 711 | long time = mPastRealtime; |
| 712 | if (mRunning) { |
| 713 | time += curTime - mRealtimeStart; |
| 714 | } |
| 715 | return time; |
| 716 | } |
| 717 | |
| 718 | public long getUptimeStart() { |
| 719 | return mUptimeStart; |
| 720 | } |
| 721 | |
| 722 | public long getRealtimeStart() { |
| 723 | return mRealtimeStart; |
| 724 | } |
| 725 | |
| 726 | public boolean isRunning() { |
| 727 | return mRunning; |
| 728 | } |
| 729 | |
| 730 | public boolean setRunning(boolean running, long uptime, long realtime) { |
| 731 | if (mRunning != running) { |
| 732 | mRunning = running; |
| 733 | if (running) { |
| 734 | mUptimeStart = uptime; |
| 735 | mRealtimeStart = realtime; |
| 736 | long batteryUptime = mUnpluggedUptime = getUptime(uptime); |
| 737 | long batteryRealtime = mUnpluggedRealtime = getRealtime(realtime); |
| 738 | |
| 739 | for (int i = mObservers.size() - 1; i >= 0; i--) { |
| 740 | mObservers.get(i).onTimeStarted(realtime, batteryUptime, batteryRealtime); |
| 741 | } |
| 742 | } else { |
| 743 | mPastUptime += uptime - mUptimeStart; |
| 744 | mPastRealtime += realtime - mRealtimeStart; |
| 745 | |
| 746 | long batteryUptime = getUptime(uptime); |
| 747 | long batteryRealtime = getRealtime(realtime); |
| 748 | |
| 749 | for (int i = mObservers.size() - 1; i >= 0; i--) { |
| 750 | mObservers.get(i).onTimeStopped(realtime, batteryUptime, batteryRealtime); |
| 751 | } |
| 752 | } |
| 753 | return true; |
| 754 | } |
| 755 | return false; |
| 756 | } |
| 757 | |
| 758 | public void readSummaryFromParcel(Parcel in) { |
| 759 | mUptime = in.readLong(); |
| 760 | mRealtime = in.readLong(); |
| 761 | } |
| 762 | |
| 763 | public void writeSummaryToParcel(Parcel out, long uptime, long realtime) { |
| 764 | out.writeLong(computeUptime(uptime, STATS_SINCE_CHARGED)); |
| 765 | out.writeLong(computeRealtime(realtime, STATS_SINCE_CHARGED)); |
| 766 | } |
| 767 | |
| 768 | public void readFromParcel(Parcel in) { |
| 769 | mRunning = false; |
| 770 | mUptime = in.readLong(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 771 | mPastUptime = in.readLong(); |
| 772 | mUptimeStart = in.readLong(); |
Dianne Hackborn | ef640cd | 2014-03-25 14:41:05 -0700 | [diff] [blame] | 773 | mRealtime = in.readLong(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 774 | mPastRealtime = in.readLong(); |
| 775 | mRealtimeStart = in.readLong(); |
| 776 | mUnpluggedUptime = in.readLong(); |
| 777 | mUnpluggedRealtime = in.readLong(); |
| 778 | } |
| 779 | |
| 780 | public void writeToParcel(Parcel out, long uptime, long realtime) { |
| 781 | final long runningUptime = getUptime(uptime); |
| 782 | final long runningRealtime = getRealtime(realtime); |
| 783 | out.writeLong(mUptime); |
| 784 | out.writeLong(runningUptime); |
| 785 | out.writeLong(mUptimeStart); |
Dianne Hackborn | ef640cd | 2014-03-25 14:41:05 -0700 | [diff] [blame] | 786 | out.writeLong(mRealtime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 787 | out.writeLong(runningRealtime); |
| 788 | out.writeLong(mRealtimeStart); |
| 789 | out.writeLong(mUnpluggedUptime); |
| 790 | out.writeLong(mUnpluggedRealtime); |
| 791 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 792 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 793 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 794 | /** |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 795 | * State for keeping track of counting information. |
| 796 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 797 | public static class Counter extends BatteryStats.Counter implements TimeBaseObs { |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 798 | final AtomicInteger mCount = new AtomicInteger(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 799 | final TimeBase mTimeBase; |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 800 | int mLoadedCount; |
| 801 | int mLastCount; |
| 802 | int mUnpluggedCount; |
| 803 | int mPluggedCount; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 804 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 805 | Counter(TimeBase timeBase, Parcel in) { |
| 806 | mTimeBase = timeBase; |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 807 | mPluggedCount = in.readInt(); |
| 808 | mCount.set(mPluggedCount); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 809 | mLoadedCount = in.readInt(); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 810 | mLastCount = 0; |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 811 | mUnpluggedCount = in.readInt(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 812 | timeBase.add(this); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 813 | } |
| 814 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 815 | Counter(TimeBase timeBase) { |
| 816 | mTimeBase = timeBase; |
| 817 | timeBase.add(this); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 818 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 819 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 820 | public void writeToParcel(Parcel out) { |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 821 | out.writeInt(mCount.get()); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 822 | out.writeInt(mLoadedCount); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 823 | out.writeInt(mUnpluggedCount); |
| 824 | } |
| 825 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 826 | public void onTimeStarted(long elapsedRealtime, long baseUptime, long baseRealtime) { |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 827 | mUnpluggedCount = mPluggedCount; |
| 828 | mCount.set(mPluggedCount); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 829 | } |
| 830 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 831 | public void onTimeStopped(long elapsedRealtime, long baseUptime, long baseRealtime) { |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 832 | mPluggedCount = mCount.get(); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 833 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 834 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 835 | /** |
| 836 | * Writes a possibly null Counter to a Parcel. |
| 837 | * |
| 838 | * @param out the Parcel to be written to. |
| 839 | * @param counter a Counter, or null. |
| 840 | */ |
| 841 | public static void writeCounterToParcel(Parcel out, Counter counter) { |
| 842 | if (counter == null) { |
| 843 | out.writeInt(0); // indicates null |
| 844 | return; |
| 845 | } |
| 846 | out.writeInt(1); // indicates non-null |
| 847 | |
| 848 | counter.writeToParcel(out); |
| 849 | } |
| 850 | |
| 851 | @Override |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 852 | public int getCountLocked(int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 853 | int val = mCount.get(); |
| 854 | if (which == STATS_SINCE_UNPLUGGED) { |
| 855 | val -= mUnpluggedCount; |
| 856 | } else if (which != STATS_SINCE_CHARGED) { |
| 857 | val -= mLoadedCount; |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 858 | } |
| 859 | |
| 860 | return val; |
| 861 | } |
| 862 | |
| 863 | public void logState(Printer pw, String prefix) { |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 864 | pw.println(prefix + "mCount=" + mCount.get() |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 865 | + " mLoadedCount=" + mLoadedCount + " mLastCount=" + mLastCount |
| 866 | + " mUnpluggedCount=" + mUnpluggedCount |
| 867 | + " mPluggedCount=" + mPluggedCount); |
| 868 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 869 | |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 870 | void stepAtomic() { |
| 871 | mCount.incrementAndGet(); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 872 | } |
| 873 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 874 | /** |
| 875 | * Clear state of this counter. |
| 876 | */ |
| 877 | void reset(boolean detachIfReset) { |
| 878 | mCount.set(0); |
| 879 | mLoadedCount = mLastCount = mPluggedCount = mUnpluggedCount = 0; |
| 880 | if (detachIfReset) { |
| 881 | detach(); |
| 882 | } |
| 883 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 884 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 885 | void detach() { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 886 | mTimeBase.remove(this); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 887 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 888 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 889 | void writeSummaryFromParcelLocked(Parcel out) { |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 890 | int count = mCount.get(); |
| 891 | out.writeInt(count); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 892 | } |
| 893 | |
| 894 | void readSummaryFromParcelLocked(Parcel in) { |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 895 | mLoadedCount = in.readInt(); |
| 896 | mCount.set(mLoadedCount); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 897 | mLastCount = 0; |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 898 | mUnpluggedCount = mPluggedCount = mLoadedCount; |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 899 | } |
| 900 | } |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 901 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 902 | public static class LongSamplingCounter extends LongCounter implements TimeBaseObs { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 903 | final TimeBase mTimeBase; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 904 | long mCount; |
| 905 | long mLoadedCount; |
| 906 | long mLastCount; |
| 907 | long mUnpluggedCount; |
| 908 | long mPluggedCount; |
| 909 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 910 | LongSamplingCounter(TimeBase timeBase, Parcel in) { |
| 911 | mTimeBase = timeBase; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 912 | mPluggedCount = in.readLong(); |
| 913 | mCount = mPluggedCount; |
| 914 | mLoadedCount = in.readLong(); |
| 915 | mLastCount = 0; |
| 916 | mUnpluggedCount = in.readLong(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 917 | timeBase.add(this); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 918 | } |
| 919 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 920 | LongSamplingCounter(TimeBase timeBase) { |
| 921 | mTimeBase = timeBase; |
| 922 | timeBase.add(this); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 923 | } |
| 924 | |
| 925 | public void writeToParcel(Parcel out) { |
| 926 | out.writeLong(mCount); |
| 927 | out.writeLong(mLoadedCount); |
| 928 | out.writeLong(mUnpluggedCount); |
| 929 | } |
| 930 | |
| 931 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 932 | public void onTimeStarted(long elapsedRealtime, long baseUptime, long baseRealtime) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 933 | mUnpluggedCount = mPluggedCount; |
| 934 | mCount = mPluggedCount; |
| 935 | } |
| 936 | |
| 937 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 938 | public void onTimeStopped(long elapsedRealtime, long baseUptime, long baseRealtime) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 939 | mPluggedCount = mCount; |
| 940 | } |
| 941 | |
| 942 | public long getCountLocked(int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 943 | long val = mCount; |
| 944 | if (which == STATS_SINCE_UNPLUGGED) { |
| 945 | val -= mUnpluggedCount; |
| 946 | } else if (which != STATS_SINCE_CHARGED) { |
| 947 | val -= mLoadedCount; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 948 | } |
| 949 | |
| 950 | return val; |
| 951 | } |
| 952 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 953 | @Override |
| 954 | public void logState(Printer pw, String prefix) { |
| 955 | pw.println(prefix + "mCount=" + mCount |
| 956 | + " mLoadedCount=" + mLoadedCount + " mLastCount=" + mLastCount |
| 957 | + " mUnpluggedCount=" + mUnpluggedCount |
| 958 | + " mPluggedCount=" + mPluggedCount); |
| 959 | } |
| 960 | |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 961 | void addCountLocked(long count) { |
| 962 | mCount += count; |
| 963 | } |
| 964 | |
| 965 | /** |
| 966 | * Clear state of this counter. |
| 967 | */ |
| 968 | void reset(boolean detachIfReset) { |
| 969 | mCount = 0; |
| 970 | mLoadedCount = mLastCount = mPluggedCount = mUnpluggedCount = 0; |
| 971 | if (detachIfReset) { |
| 972 | detach(); |
| 973 | } |
| 974 | } |
| 975 | |
| 976 | void detach() { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 977 | mTimeBase.remove(this); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 978 | } |
| 979 | |
| 980 | void writeSummaryFromParcelLocked(Parcel out) { |
| 981 | out.writeLong(mCount); |
| 982 | } |
| 983 | |
| 984 | void readSummaryFromParcelLocked(Parcel in) { |
| 985 | mLoadedCount = in.readLong(); |
| 986 | mCount = mLoadedCount; |
| 987 | mLastCount = 0; |
| 988 | mUnpluggedCount = mPluggedCount = mLoadedCount; |
| 989 | } |
| 990 | } |
| 991 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 992 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 993 | * State for keeping track of timing information. |
| 994 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 995 | public static abstract class Timer extends BatteryStats.Timer implements TimeBaseObs { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 996 | protected final Clocks mClocks; |
| 997 | protected final int mType; |
| 998 | protected final TimeBase mTimeBase; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 999 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1000 | protected int mCount; |
| 1001 | protected int mLoadedCount; |
| 1002 | protected int mLastCount; |
| 1003 | protected int mUnpluggedCount; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1004 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1005 | // Times are in microseconds for better accuracy when dividing by the |
| 1006 | // lock count, and are in "battery realtime" units. |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1007 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1008 | /** |
| 1009 | * The total time we have accumulated since the start of the original |
| 1010 | * boot, to the last time something interesting happened in the |
| 1011 | * current run. |
| 1012 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1013 | protected long mTotalTime; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1014 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1015 | /** |
| 1016 | * The total time we loaded for the previous runs. Subtract this from |
| 1017 | * mTotalTime to find the time for the current run of the system. |
| 1018 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1019 | protected long mLoadedTime; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1020 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1021 | /** |
| 1022 | * The run time of the last run of the system, as loaded from the |
| 1023 | * saved data. |
| 1024 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1025 | protected long mLastTime; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1026 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1027 | /** |
| 1028 | * The value of mTotalTime when unplug() was last called. Subtract |
| 1029 | * this from mTotalTime to find the time since the last unplug from |
| 1030 | * power. |
| 1031 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1032 | protected long mUnpluggedTime; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1033 | |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 1034 | /** |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 1035 | * The total time this timer has been running until the latest mark has been set. |
| 1036 | * Subtract this from mTotalTime to get the time spent running since the mark was set. |
| 1037 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1038 | protected long mTimeBeforeMark; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 1039 | |
| 1040 | /** |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 1041 | * Constructs from a parcel. |
| 1042 | * @param type |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1043 | * @param timeBase |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 1044 | * @param in |
| 1045 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1046 | public Timer(Clocks clocks, int type, TimeBase timeBase, Parcel in) { |
| 1047 | mClocks = clocks; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1048 | mType = type; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1049 | mTimeBase = timeBase; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1050 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1051 | mCount = in.readInt(); |
| 1052 | mLoadedCount = in.readInt(); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 1053 | mLastCount = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1054 | mUnpluggedCount = in.readInt(); |
| 1055 | mTotalTime = in.readLong(); |
| 1056 | mLoadedTime = in.readLong(); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 1057 | mLastTime = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1058 | mUnpluggedTime = in.readLong(); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 1059 | mTimeBeforeMark = in.readLong(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1060 | timeBase.add(this); |
Dianne Hackborn | 2932513 | 2014-05-21 15:01:03 -0700 | [diff] [blame] | 1061 | if (DEBUG) Log.i(TAG, "**** READ TIMER #" + mType + ": mTotalTime=" + mTotalTime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1062 | } |
| 1063 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1064 | public Timer(Clocks clocks, int type, TimeBase timeBase) { |
| 1065 | mClocks = clocks; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1066 | mType = type; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1067 | mTimeBase = timeBase; |
| 1068 | timeBase.add(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1069 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1070 | |
| 1071 | protected abstract long computeRunTimeLocked(long curBatteryRealtime); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1072 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1073 | protected abstract int computeCurrentCountLocked(); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1074 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1075 | /** |
| 1076 | * Clear state of this timer. Returns true if the timer is inactive |
| 1077 | * so can be completely dropped. |
| 1078 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1079 | public boolean reset(boolean detachIfReset) { |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 1080 | mTotalTime = mLoadedTime = mLastTime = mTimeBeforeMark = 0; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1081 | mCount = mLoadedCount = mLastCount = 0; |
| 1082 | if (detachIfReset) { |
| 1083 | detach(); |
| 1084 | } |
| 1085 | return true; |
| 1086 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1087 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1088 | public void detach() { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1089 | mTimeBase.remove(this); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1090 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1091 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1092 | public void writeToParcel(Parcel out, long elapsedRealtimeUs) { |
Dianne Hackborn | 2932513 | 2014-05-21 15:01:03 -0700 | [diff] [blame] | 1093 | if (DEBUG) Log.i(TAG, "**** WRITING TIMER #" + mType + ": mTotalTime=" |
| 1094 | + computeRunTimeLocked(mTimeBase.getRealtime(elapsedRealtimeUs))); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1095 | out.writeInt(mCount); |
| 1096 | out.writeInt(mLoadedCount); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1097 | out.writeInt(mUnpluggedCount); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1098 | out.writeLong(computeRunTimeLocked(mTimeBase.getRealtime(elapsedRealtimeUs))); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1099 | out.writeLong(mLoadedTime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1100 | out.writeLong(mUnpluggedTime); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 1101 | out.writeLong(mTimeBeforeMark); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1102 | } |
| 1103 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 1104 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1105 | public void onTimeStarted(long elapsedRealtime, long timeBaseUptime, long baseRealtime) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1106 | if (DEBUG && mType < 0) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1107 | Log.v(TAG, "unplug #" + mType + ": realtime=" + baseRealtime |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1108 | + " old mUnpluggedTime=" + mUnpluggedTime |
| 1109 | + " old mUnpluggedCount=" + mUnpluggedCount); |
| 1110 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1111 | mUnpluggedTime = computeRunTimeLocked(baseRealtime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1112 | mUnpluggedCount = mCount; |
| 1113 | if (DEBUG && mType < 0) { |
| 1114 | Log.v(TAG, "unplug #" + mType |
| 1115 | + ": new mUnpluggedTime=" + mUnpluggedTime |
| 1116 | + " new mUnpluggedCount=" + mUnpluggedCount); |
| 1117 | } |
| 1118 | } |
| 1119 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 1120 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1121 | public void onTimeStopped(long elapsedRealtime, long baseUptime, long baseRealtime) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1122 | if (DEBUG && mType < 0) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1123 | Log.v(TAG, "plug #" + mType + ": realtime=" + baseRealtime |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1124 | + " old mTotalTime=" + mTotalTime); |
| 1125 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1126 | mTotalTime = computeRunTimeLocked(baseRealtime); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1127 | mCount = computeCurrentCountLocked(); |
| 1128 | if (DEBUG && mType < 0) { |
| 1129 | Log.v(TAG, "plug #" + mType |
| 1130 | + ": new mTotalTime=" + mTotalTime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1131 | } |
| 1132 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1133 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1134 | /** |
| 1135 | * Writes a possibly null Timer to a Parcel. |
| 1136 | * |
| 1137 | * @param out the Parcel to be written to. |
| 1138 | * @param timer a Timer, or null. |
| 1139 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1140 | public static void writeTimerToParcel(Parcel out, Timer timer, long elapsedRealtimeUs) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1141 | if (timer == null) { |
| 1142 | out.writeInt(0); // indicates null |
| 1143 | return; |
| 1144 | } |
| 1145 | out.writeInt(1); // indicates non-null |
| 1146 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1147 | timer.writeToParcel(out, elapsedRealtimeUs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1148 | } |
| 1149 | |
| 1150 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1151 | public long getTotalTimeLocked(long elapsedRealtimeUs, int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 1152 | long val = computeRunTimeLocked(mTimeBase.getRealtime(elapsedRealtimeUs)); |
| 1153 | if (which == STATS_SINCE_UNPLUGGED) { |
| 1154 | val -= mUnpluggedTime; |
| 1155 | } else if (which != STATS_SINCE_CHARGED) { |
| 1156 | val -= mLoadedTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1157 | } |
| 1158 | |
| 1159 | return val; |
| 1160 | } |
| 1161 | |
| 1162 | @Override |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1163 | public int getCountLocked(int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 1164 | int val = computeCurrentCountLocked(); |
| 1165 | if (which == STATS_SINCE_UNPLUGGED) { |
| 1166 | val -= mUnpluggedCount; |
| 1167 | } else if (which != STATS_SINCE_CHARGED) { |
| 1168 | val -= mLoadedCount; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1169 | } |
| 1170 | |
| 1171 | return val; |
| 1172 | } |
| 1173 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 1174 | @Override |
| 1175 | public long getTimeSinceMarkLocked(long elapsedRealtimeUs) { |
| 1176 | long val = computeRunTimeLocked(mTimeBase.getRealtime(elapsedRealtimeUs)); |
| 1177 | return val - mTimeBeforeMark; |
| 1178 | } |
| 1179 | |
| 1180 | @Override |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 1181 | public void logState(Printer pw, String prefix) { |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 1182 | pw.println(prefix + "mCount=" + mCount |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1183 | + " mLoadedCount=" + mLoadedCount + " mLastCount=" + mLastCount |
| 1184 | + " mUnpluggedCount=" + mUnpluggedCount); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 1185 | pw.println(prefix + "mTotalTime=" + mTotalTime |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1186 | + " mLoadedTime=" + mLoadedTime); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 1187 | pw.println(prefix + "mLastTime=" + mLastTime |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1188 | + " mUnpluggedTime=" + mUnpluggedTime); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1189 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1190 | |
| 1191 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1192 | public void writeSummaryFromParcelLocked(Parcel out, long elapsedRealtimeUs) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1193 | long runTime = computeRunTimeLocked(mTimeBase.getRealtime(elapsedRealtimeUs)); |
| 1194 | out.writeLong(runTime); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1195 | out.writeInt(mCount); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1196 | } |
| 1197 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1198 | public void readSummaryFromParcelLocked(Parcel in) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1199 | // Multiply by 1000 for backwards compatibility |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1200 | mTotalTime = mLoadedTime = in.readLong(); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 1201 | mLastTime = 0; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1202 | mUnpluggedTime = mTotalTime; |
| 1203 | mCount = mLoadedCount = in.readInt(); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 1204 | mLastCount = 0; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1205 | mUnpluggedCount = mCount; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 1206 | |
| 1207 | // When reading the summary, we set the mark to be the latest information. |
| 1208 | mTimeBeforeMark = mTotalTime; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1209 | } |
| 1210 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1211 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1212 | public static class SamplingTimer extends Timer { |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1213 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1214 | /** |
| 1215 | * The most recent reported count from /proc/wakelocks. |
| 1216 | */ |
| 1217 | int mCurrentReportedCount; |
| 1218 | |
| 1219 | /** |
| 1220 | * The reported count from /proc/wakelocks when unplug() was last |
| 1221 | * called. |
| 1222 | */ |
| 1223 | int mUnpluggedReportedCount; |
| 1224 | |
| 1225 | /** |
| 1226 | * The most recent reported total_time from /proc/wakelocks. |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1227 | */ |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1228 | long mCurrentReportedTotalTime; |
| 1229 | |
| 1230 | |
| 1231 | /** |
| 1232 | * The reported total_time from /proc/wakelocks when unplug() was last |
| 1233 | * called. |
| 1234 | */ |
| 1235 | long mUnpluggedReportedTotalTime; |
| 1236 | |
| 1237 | /** |
| 1238 | * Whether we are currently in a discharge cycle. |
| 1239 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1240 | boolean mTimeBaseRunning; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1241 | |
| 1242 | /** |
| 1243 | * Whether we are currently recording reported values. |
| 1244 | */ |
| 1245 | boolean mTrackingReportedValues; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1246 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1247 | /* |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1248 | * A sequence counter, incremented once for each update of the stats. |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1249 | */ |
| 1250 | int mUpdateVersion; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1251 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1252 | SamplingTimer(Clocks clocks, TimeBase timeBase, Parcel in) { |
| 1253 | super(clocks, 0, timeBase, in); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1254 | mCurrentReportedCount = in.readInt(); |
| 1255 | mUnpluggedReportedCount = in.readInt(); |
| 1256 | mCurrentReportedTotalTime = in.readLong(); |
| 1257 | mUnpluggedReportedTotalTime = in.readLong(); |
| 1258 | mTrackingReportedValues = in.readInt() == 1; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1259 | mTimeBaseRunning = timeBase.isRunning(); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1260 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1261 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1262 | SamplingTimer(Clocks clocks, TimeBase timeBase, boolean trackReportedValues) { |
| 1263 | super(clocks, 0, timeBase); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1264 | mTrackingReportedValues = trackReportedValues; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1265 | mTimeBaseRunning = timeBase.isRunning(); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1266 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1267 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1268 | public void setStale() { |
| 1269 | mTrackingReportedValues = false; |
| 1270 | mUnpluggedReportedTotalTime = 0; |
| 1271 | mUnpluggedReportedCount = 0; |
| 1272 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1273 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1274 | public void setUpdateVersion(int version) { |
| 1275 | mUpdateVersion = version; |
| 1276 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1277 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1278 | public int getUpdateVersion() { |
| 1279 | return mUpdateVersion; |
| 1280 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1281 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1282 | public void updateCurrentReportedCount(int count) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1283 | if (mTimeBaseRunning && mUnpluggedReportedCount == 0) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1284 | // Updating the reported value for the first time. |
| 1285 | mUnpluggedReportedCount = count; |
| 1286 | // If we are receiving an update update mTrackingReportedValues; |
| 1287 | mTrackingReportedValues = true; |
| 1288 | } |
| 1289 | mCurrentReportedCount = count; |
| 1290 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1291 | |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 1292 | public void addCurrentReportedCount(int delta) { |
| 1293 | updateCurrentReportedCount(mCurrentReportedCount + delta); |
| 1294 | } |
| 1295 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1296 | public void updateCurrentReportedTotalTime(long totalTime) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1297 | if (mTimeBaseRunning && mUnpluggedReportedTotalTime == 0) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1298 | // Updating the reported value for the first time. |
| 1299 | mUnpluggedReportedTotalTime = totalTime; |
| 1300 | // If we are receiving an update update mTrackingReportedValues; |
| 1301 | mTrackingReportedValues = true; |
| 1302 | } |
| 1303 | mCurrentReportedTotalTime = totalTime; |
| 1304 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1305 | |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 1306 | public void addCurrentReportedTotalTime(long delta) { |
| 1307 | updateCurrentReportedTotalTime(mCurrentReportedTotalTime + delta); |
| 1308 | } |
| 1309 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1310 | public void onTimeStarted(long elapsedRealtime, long baseUptime, long baseRealtime) { |
| 1311 | super.onTimeStarted(elapsedRealtime, baseUptime, baseRealtime); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1312 | if (mTrackingReportedValues) { |
| 1313 | mUnpluggedReportedTotalTime = mCurrentReportedTotalTime; |
| 1314 | mUnpluggedReportedCount = mCurrentReportedCount; |
| 1315 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1316 | mTimeBaseRunning = true; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1317 | } |
| 1318 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1319 | public void onTimeStopped(long elapsedRealtime, long baseUptime, long baseRealtime) { |
| 1320 | super.onTimeStopped(elapsedRealtime, baseUptime, baseRealtime); |
| 1321 | mTimeBaseRunning = false; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1322 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1323 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1324 | public void logState(Printer pw, String prefix) { |
| 1325 | super.logState(pw, prefix); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1326 | pw.println(prefix + "mCurrentReportedCount=" + mCurrentReportedCount |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1327 | + " mUnpluggedReportedCount=" + mUnpluggedReportedCount |
| 1328 | + " mCurrentReportedTotalTime=" + mCurrentReportedTotalTime |
| 1329 | + " mUnpluggedReportedTotalTime=" + mUnpluggedReportedTotalTime); |
| 1330 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1331 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1332 | protected long computeRunTimeLocked(long curBatteryRealtime) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1333 | return mTotalTime + (mTimeBaseRunning && mTrackingReportedValues |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1334 | ? mCurrentReportedTotalTime - mUnpluggedReportedTotalTime : 0); |
| 1335 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1336 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1337 | protected int computeCurrentCountLocked() { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1338 | return mCount + (mTimeBaseRunning && mTrackingReportedValues |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1339 | ? mCurrentReportedCount - mUnpluggedReportedCount : 0); |
| 1340 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1341 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1342 | public void writeToParcel(Parcel out, long elapsedRealtimeUs) { |
| 1343 | super.writeToParcel(out, elapsedRealtimeUs); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1344 | out.writeInt(mCurrentReportedCount); |
| 1345 | out.writeInt(mUnpluggedReportedCount); |
| 1346 | out.writeLong(mCurrentReportedTotalTime); |
| 1347 | out.writeLong(mUnpluggedReportedTotalTime); |
| 1348 | out.writeInt(mTrackingReportedValues ? 1 : 0); |
| 1349 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1350 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1351 | public boolean reset(boolean detachIfReset) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1352 | super.reset(detachIfReset); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1353 | setStale(); |
| 1354 | return true; |
| 1355 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1356 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1357 | public void writeSummaryFromParcelLocked(Parcel out, long batteryRealtime) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1358 | super.writeSummaryFromParcelLocked(out, batteryRealtime); |
| 1359 | out.writeLong(mCurrentReportedTotalTime); |
| 1360 | out.writeInt(mCurrentReportedCount); |
| 1361 | out.writeInt(mTrackingReportedValues ? 1 : 0); |
| 1362 | } |
| 1363 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1364 | public void readSummaryFromParcelLocked(Parcel in) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1365 | super.readSummaryFromParcelLocked(in); |
| 1366 | mUnpluggedReportedTotalTime = mCurrentReportedTotalTime = in.readLong(); |
| 1367 | mUnpluggedReportedCount = mCurrentReportedCount = in.readInt(); |
| 1368 | mTrackingReportedValues = in.readInt() == 1; |
| 1369 | } |
| 1370 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1371 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1372 | /** |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1373 | * A timer that increments in batches. It does not run for durations, but just jumps |
| 1374 | * for a pre-determined amount. |
| 1375 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1376 | public static class BatchTimer extends Timer { |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1377 | final Uid mUid; |
| 1378 | |
| 1379 | /** |
| 1380 | * The last time at which we updated the timer. This is in elapsed realtime microseconds. |
| 1381 | */ |
| 1382 | long mLastAddedTime; |
| 1383 | |
| 1384 | /** |
| 1385 | * The last duration that we added to the timer. This is in microseconds. |
| 1386 | */ |
| 1387 | long mLastAddedDuration; |
| 1388 | |
| 1389 | /** |
| 1390 | * Whether we are currently in a discharge cycle. |
| 1391 | */ |
| 1392 | boolean mInDischarge; |
| 1393 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1394 | BatchTimer(Clocks clocks, Uid uid, int type, TimeBase timeBase, Parcel in) { |
| 1395 | super(clocks, type, timeBase, in); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1396 | mUid = uid; |
| 1397 | mLastAddedTime = in.readLong(); |
| 1398 | mLastAddedDuration = in.readLong(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1399 | mInDischarge = timeBase.isRunning(); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1400 | } |
| 1401 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1402 | BatchTimer(Clocks clocks, Uid uid, int type, TimeBase timeBase) { |
| 1403 | super(clocks, type, timeBase); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1404 | mUid = uid; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1405 | mInDischarge = timeBase.isRunning(); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1406 | } |
| 1407 | |
| 1408 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1409 | public void writeToParcel(Parcel out, long elapsedRealtimeUs) { |
| 1410 | super.writeToParcel(out, elapsedRealtimeUs); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1411 | out.writeLong(mLastAddedTime); |
| 1412 | out.writeLong(mLastAddedDuration); |
| 1413 | } |
| 1414 | |
| 1415 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1416 | public void onTimeStopped(long elapsedRealtime, long baseUptime, long baseRealtime) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1417 | recomputeLastDuration(mClocks.elapsedRealtime() * 1000, false); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1418 | mInDischarge = false; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1419 | super.onTimeStopped(elapsedRealtime, baseUptime, baseRealtime); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1420 | } |
| 1421 | |
| 1422 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1423 | public void onTimeStarted(long elapsedRealtime, long baseUptime, long baseRealtime) { |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1424 | recomputeLastDuration(elapsedRealtime, false); |
| 1425 | mInDischarge = true; |
| 1426 | // If we are still within the last added duration, then re-added whatever remains. |
| 1427 | if (mLastAddedTime == elapsedRealtime) { |
| 1428 | mTotalTime += mLastAddedDuration; |
| 1429 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1430 | super.onTimeStarted(elapsedRealtime, baseUptime, baseRealtime); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1431 | } |
| 1432 | |
| 1433 | @Override |
| 1434 | public void logState(Printer pw, String prefix) { |
| 1435 | super.logState(pw, prefix); |
| 1436 | pw.println(prefix + "mLastAddedTime=" + mLastAddedTime |
| 1437 | + " mLastAddedDuration=" + mLastAddedDuration); |
| 1438 | } |
| 1439 | |
| 1440 | private long computeOverage(long curTime) { |
| 1441 | if (mLastAddedTime > 0) { |
| 1442 | return mLastTime + mLastAddedDuration - curTime; |
| 1443 | } |
| 1444 | return 0; |
| 1445 | } |
| 1446 | |
| 1447 | private void recomputeLastDuration(long curTime, boolean abort) { |
| 1448 | final long overage = computeOverage(curTime); |
| 1449 | if (overage > 0) { |
| 1450 | // Aborting before the duration ran out -- roll back the remaining |
| 1451 | // duration. Only do this if currently discharging; otherwise we didn't |
| 1452 | // actually add the time. |
| 1453 | if (mInDischarge) { |
| 1454 | mTotalTime -= overage; |
| 1455 | } |
| 1456 | if (abort) { |
| 1457 | mLastAddedTime = 0; |
| 1458 | } else { |
| 1459 | mLastAddedTime = curTime; |
| 1460 | mLastAddedDuration -= overage; |
| 1461 | } |
| 1462 | } |
| 1463 | } |
| 1464 | |
| 1465 | public void addDuration(BatteryStatsImpl stats, long durationMillis) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1466 | final long now = mClocks.elapsedRealtime() * 1000; |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1467 | recomputeLastDuration(now, true); |
| 1468 | mLastAddedTime = now; |
| 1469 | mLastAddedDuration = durationMillis * 1000; |
| 1470 | if (mInDischarge) { |
| 1471 | mTotalTime += mLastAddedDuration; |
| 1472 | mCount++; |
| 1473 | } |
| 1474 | } |
| 1475 | |
| 1476 | public void abortLastDuration(BatteryStatsImpl stats) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1477 | final long now = mClocks.elapsedRealtime() * 1000; |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1478 | recomputeLastDuration(now, true); |
| 1479 | } |
| 1480 | |
| 1481 | @Override |
| 1482 | protected int computeCurrentCountLocked() { |
| 1483 | return mCount; |
| 1484 | } |
| 1485 | |
| 1486 | @Override |
| 1487 | protected long computeRunTimeLocked(long curBatteryRealtime) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1488 | final long overage = computeOverage(mClocks.elapsedRealtime() * 1000); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1489 | if (overage > 0) { |
| 1490 | return mTotalTime = overage; |
| 1491 | } |
| 1492 | return mTotalTime; |
| 1493 | } |
| 1494 | |
| 1495 | @Override |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1496 | public boolean reset(boolean detachIfReset) { |
| 1497 | final long now = mClocks.elapsedRealtime() * 1000; |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1498 | recomputeLastDuration(now, true); |
| 1499 | boolean stillActive = mLastAddedTime == now; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1500 | super.reset(!stillActive && detachIfReset); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1501 | return !stillActive; |
| 1502 | } |
| 1503 | } |
| 1504 | |
| 1505 | /** |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1506 | * State for keeping track of timing information. |
| 1507 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1508 | public static class StopwatchTimer extends Timer { |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 1509 | final Uid mUid; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1510 | final ArrayList<StopwatchTimer> mTimerPool; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 1511 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1512 | int mNesting; |
| 1513 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1514 | /** |
| 1515 | * The last time at which we updated the timer. If mNesting is > 0, |
| 1516 | * subtract this from the current battery time to find the amount of |
| 1517 | * time we have been running since we last computed an update. |
| 1518 | */ |
| 1519 | long mUpdateTime; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1520 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1521 | /** |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 1522 | * The total time at which the timer was acquired, to determine if it |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1523 | * was actually held for an interesting duration. |
| 1524 | */ |
| 1525 | long mAcquireTime; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1526 | |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 1527 | long mTimeout; |
| 1528 | |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 1529 | /** |
| 1530 | * For partial wake locks, keep track of whether we are in the list |
| 1531 | * to consume CPU cycles. |
| 1532 | */ |
| 1533 | boolean mInList; |
| 1534 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1535 | public StopwatchTimer(Clocks clocks, Uid uid, int type, ArrayList<StopwatchTimer> timerPool, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1536 | TimeBase timeBase, Parcel in) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1537 | super(clocks, type, timeBase, in); |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 1538 | mUid = uid; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1539 | mTimerPool = timerPool; |
| 1540 | mUpdateTime = in.readLong(); |
| 1541 | } |
| 1542 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1543 | public StopwatchTimer(Clocks clocks, Uid uid, int type, ArrayList<StopwatchTimer> timerPool, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1544 | TimeBase timeBase) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1545 | super(clocks, type, timeBase); |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 1546 | mUid = uid; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1547 | mTimerPool = timerPool; |
| 1548 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1549 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1550 | public void setTimeout(long timeout) { |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 1551 | mTimeout = timeout; |
| 1552 | } |
| 1553 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1554 | public void writeToParcel(Parcel out, long elapsedRealtimeUs) { |
| 1555 | super.writeToParcel(out, elapsedRealtimeUs); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1556 | out.writeLong(mUpdateTime); |
| 1557 | } |
| 1558 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1559 | public void onTimeStopped(long elapsedRealtime, long baseUptime, long baseRealtime) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1560 | if (mNesting > 0) { |
| 1561 | if (DEBUG && mType < 0) { |
| 1562 | Log.v(TAG, "old mUpdateTime=" + mUpdateTime); |
| 1563 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1564 | super.onTimeStopped(elapsedRealtime, baseUptime, baseRealtime); |
| 1565 | mUpdateTime = baseRealtime; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1566 | if (DEBUG && mType < 0) { |
| 1567 | Log.v(TAG, "new mUpdateTime=" + mUpdateTime); |
| 1568 | } |
| 1569 | } |
| 1570 | } |
| 1571 | |
| 1572 | public void logState(Printer pw, String prefix) { |
| 1573 | super.logState(pw, prefix); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 1574 | pw.println(prefix + "mNesting=" + mNesting + " mUpdateTime=" + mUpdateTime |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1575 | + " mAcquireTime=" + mAcquireTime); |
| 1576 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1577 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1578 | public void startRunningLocked(long elapsedRealtimeMs) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1579 | if (mNesting++ == 0) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1580 | final long batteryRealtime = mTimeBase.getRealtime(elapsedRealtimeMs * 1000); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 1581 | mUpdateTime = batteryRealtime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1582 | if (mTimerPool != null) { |
| 1583 | // Accumulate time to all currently active timers before adding |
| 1584 | // this new one to the pool. |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1585 | refreshTimersLocked(batteryRealtime, mTimerPool, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1586 | // Add this timer to the active pool |
| 1587 | mTimerPool.add(this); |
| 1588 | } |
| 1589 | // Increment the count |
| 1590 | mCount++; |
| 1591 | mAcquireTime = mTotalTime; |
| 1592 | if (DEBUG && mType < 0) { |
| 1593 | Log.v(TAG, "start #" + mType + ": mUpdateTime=" + mUpdateTime |
| 1594 | + " mTotalTime=" + mTotalTime + " mCount=" + mCount |
| 1595 | + " mAcquireTime=" + mAcquireTime); |
| 1596 | } |
| 1597 | } |
| 1598 | } |
| 1599 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1600 | public boolean isRunningLocked() { |
Amith Yamasani | 32dbefd | 2009-06-19 09:21:17 -0700 | [diff] [blame] | 1601 | return mNesting > 0; |
| 1602 | } |
| 1603 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1604 | public void stopRunningLocked(long elapsedRealtimeMs) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1605 | // Ignore attempt to stop a timer that isn't running |
| 1606 | if (mNesting == 0) { |
| 1607 | return; |
| 1608 | } |
| 1609 | if (--mNesting == 0) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1610 | final long batteryRealtime = mTimeBase.getRealtime(elapsedRealtimeMs * 1000); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1611 | if (mTimerPool != null) { |
| 1612 | // Accumulate time to all active counters, scaled by the total |
| 1613 | // active in the pool, before taking this one out of the pool. |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1614 | refreshTimersLocked(batteryRealtime, mTimerPool, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1615 | // Remove this timer from the active pool |
| 1616 | mTimerPool.remove(this); |
| 1617 | } else { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1618 | mNesting = 1; |
| 1619 | mTotalTime = computeRunTimeLocked(batteryRealtime); |
| 1620 | mNesting = 0; |
| 1621 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1622 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1623 | if (DEBUG && mType < 0) { |
| 1624 | Log.v(TAG, "stop #" + mType + ": mUpdateTime=" + mUpdateTime |
| 1625 | + " mTotalTime=" + mTotalTime + " mCount=" + mCount |
| 1626 | + " mAcquireTime=" + mAcquireTime); |
| 1627 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1628 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1629 | if (mTotalTime == mAcquireTime) { |
| 1630 | // If there was no change in the time, then discard this |
| 1631 | // count. A somewhat cheezy strategy, but hey. |
| 1632 | mCount--; |
| 1633 | } |
| 1634 | } |
| 1635 | } |
| 1636 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1637 | public void stopAllRunningLocked(long elapsedRealtimeMs) { |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 1638 | if (mNesting > 0) { |
| 1639 | mNesting = 1; |
| 1640 | stopRunningLocked(elapsedRealtimeMs); |
| 1641 | } |
| 1642 | } |
| 1643 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1644 | // Update the total time for all other running Timers with the same type as this Timer |
| 1645 | // due to a change in timer count |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1646 | private static long refreshTimersLocked(long batteryRealtime, |
| 1647 | final ArrayList<StopwatchTimer> pool, StopwatchTimer self) { |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 1648 | long selfTime = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1649 | final int N = pool.size(); |
| 1650 | for (int i=N-1; i>= 0; i--) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1651 | final StopwatchTimer t = pool.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1652 | long heldTime = batteryRealtime - t.mUpdateTime; |
| 1653 | if (heldTime > 0) { |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 1654 | final long myTime = heldTime / N; |
| 1655 | if (t == self) { |
| 1656 | selfTime = myTime; |
| 1657 | } |
| 1658 | t.mTotalTime += myTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1659 | } |
| 1660 | t.mUpdateTime = batteryRealtime; |
| 1661 | } |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 1662 | return selfTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1663 | } |
| 1664 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1665 | @Override |
| 1666 | protected long computeRunTimeLocked(long curBatteryRealtime) { |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 1667 | if (mTimeout > 0 && curBatteryRealtime > mUpdateTime + mTimeout) { |
| 1668 | curBatteryRealtime = mUpdateTime + mTimeout; |
| 1669 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1670 | return mTotalTime + (mNesting > 0 |
| 1671 | ? (curBatteryRealtime - mUpdateTime) |
| 1672 | / (mTimerPool != null ? mTimerPool.size() : 1) |
| 1673 | : 0); |
| 1674 | } |
| 1675 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1676 | @Override |
| 1677 | protected int computeCurrentCountLocked() { |
| 1678 | return mCount; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1679 | } |
| 1680 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 1681 | @Override |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1682 | public boolean reset(boolean detachIfReset) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1683 | boolean canDetach = mNesting <= 0; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1684 | super.reset(canDetach && detachIfReset); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 1685 | if (mNesting > 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1686 | mUpdateTime = mTimeBase.getRealtime(mClocks.elapsedRealtime() * 1000); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 1687 | } |
| 1688 | mAcquireTime = mTotalTime; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1689 | return canDetach; |
| 1690 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1691 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 1692 | @Override |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1693 | public void detach() { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1694 | super.detach(); |
| 1695 | if (mTimerPool != null) { |
| 1696 | mTimerPool.remove(this); |
| 1697 | } |
| 1698 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1699 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 1700 | @Override |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1701 | public void readSummaryFromParcelLocked(Parcel in) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1702 | super.readSummaryFromParcelLocked(in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1703 | mNesting = 0; |
| 1704 | } |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 1705 | |
| 1706 | /** |
| 1707 | * Set the mark so that we can query later for the total time the timer has |
| 1708 | * accumulated since this point. The timer can be running or not. |
| 1709 | * |
| 1710 | * @param elapsedRealtimeMs the current elapsed realtime in milliseconds. |
| 1711 | */ |
| 1712 | public void setMark(long elapsedRealtimeMs) { |
| 1713 | final long batteryRealtime = mTimeBase.getRealtime(elapsedRealtimeMs * 1000); |
| 1714 | if (mNesting > 0) { |
| 1715 | // We are running. |
| 1716 | if (mTimerPool != null) { |
| 1717 | refreshTimersLocked(batteryRealtime, mTimerPool, this); |
| 1718 | } else { |
| 1719 | mTotalTime += batteryRealtime - mUpdateTime; |
| 1720 | mUpdateTime = batteryRealtime; |
| 1721 | } |
| 1722 | } |
| 1723 | mTimeBeforeMark = mTotalTime; |
| 1724 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1725 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1726 | |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 1727 | public abstract class OverflowArrayMap<T> { |
| 1728 | private static final String OVERFLOW_NAME = "*overflow*"; |
| 1729 | |
| 1730 | final ArrayMap<String, T> mMap = new ArrayMap<>(); |
| 1731 | T mCurOverflow; |
| 1732 | ArrayMap<String, MutableInt> mActiveOverflow; |
| 1733 | |
| 1734 | public OverflowArrayMap() { |
| 1735 | } |
| 1736 | |
| 1737 | public ArrayMap<String, T> getMap() { |
| 1738 | return mMap; |
| 1739 | } |
| 1740 | |
| 1741 | public void clear() { |
| 1742 | mMap.clear(); |
| 1743 | mCurOverflow = null; |
| 1744 | mActiveOverflow = null; |
| 1745 | } |
| 1746 | |
| 1747 | public void add(String name, T obj) { |
Joe Onorato | 388fc33 | 2016-04-12 17:06:47 -0700 | [diff] [blame] | 1748 | if (name == null) { |
| 1749 | name = ""; |
| 1750 | } |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 1751 | mMap.put(name, obj); |
| 1752 | if (OVERFLOW_NAME.equals(name)) { |
| 1753 | mCurOverflow = obj; |
| 1754 | } |
| 1755 | } |
| 1756 | |
| 1757 | public void cleanup() { |
| 1758 | if (mActiveOverflow != null) { |
| 1759 | if (mActiveOverflow.size() == 0) { |
| 1760 | mActiveOverflow = null; |
| 1761 | } |
| 1762 | } |
| 1763 | if (mActiveOverflow == null) { |
| 1764 | // There is no currently active overflow, so we should no longer have |
| 1765 | // an overflow entry. |
| 1766 | if (mMap.containsKey(OVERFLOW_NAME)) { |
| 1767 | Slog.wtf(TAG, "Cleaning up with no active overflow, but have overflow entry " |
| 1768 | + mMap.get(OVERFLOW_NAME)); |
| 1769 | mMap.remove(OVERFLOW_NAME); |
| 1770 | } |
| 1771 | mCurOverflow = null; |
| 1772 | } else { |
| 1773 | // There is currently active overflow, so we should still have an overflow entry. |
| 1774 | if (mCurOverflow == null || !mMap.containsKey(OVERFLOW_NAME)) { |
| 1775 | Slog.wtf(TAG, "Cleaning up with active overflow, but no overflow entry: cur=" |
| 1776 | + mCurOverflow + " map=" + mMap.get(OVERFLOW_NAME)); |
| 1777 | } |
| 1778 | } |
| 1779 | } |
| 1780 | |
| 1781 | public T startObject(String name) { |
Joe Onorato | 388fc33 | 2016-04-12 17:06:47 -0700 | [diff] [blame] | 1782 | if (name == null) { |
| 1783 | name = ""; |
| 1784 | } |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 1785 | T obj = mMap.get(name); |
| 1786 | if (obj != null) { |
| 1787 | return obj; |
| 1788 | } |
| 1789 | |
| 1790 | // No object exists for the given name, but do we currently have it |
| 1791 | // running as part of the overflow? |
| 1792 | if (mActiveOverflow != null) { |
| 1793 | MutableInt over = mActiveOverflow.get(name); |
| 1794 | if (over != null) { |
| 1795 | // We are already actively counting this name in the overflow object. |
| 1796 | obj = mCurOverflow; |
| 1797 | if (obj == null) { |
| 1798 | // Shouldn't be here, but we'll try to recover. |
| 1799 | Slog.wtf(TAG, "Have active overflow " + name + " but null overflow"); |
| 1800 | obj = mCurOverflow = instantiateObject(); |
| 1801 | mMap.put(OVERFLOW_NAME, obj); |
| 1802 | } |
| 1803 | over.value++; |
| 1804 | return obj; |
| 1805 | } |
| 1806 | } |
| 1807 | |
| 1808 | // No object exists for given name nor in the overflow; we need to make |
| 1809 | // a new one. |
| 1810 | final int N = mMap.size(); |
| 1811 | if (N >= MAX_WAKELOCKS_PER_UID) { |
| 1812 | // Went over the limit on number of objects to track; this one goes |
| 1813 | // in to the overflow. |
| 1814 | obj = mCurOverflow; |
| 1815 | if (obj == null) { |
| 1816 | // Need to start overflow now... |
| 1817 | obj = mCurOverflow = instantiateObject(); |
| 1818 | mMap.put(OVERFLOW_NAME, obj); |
| 1819 | } |
| 1820 | if (mActiveOverflow == null) { |
| 1821 | mActiveOverflow = new ArrayMap<>(); |
| 1822 | } |
| 1823 | mActiveOverflow.put(name, new MutableInt(1)); |
| 1824 | return obj; |
| 1825 | } |
| 1826 | |
| 1827 | // Normal case where we just need to make a new object. |
| 1828 | obj = instantiateObject(); |
| 1829 | mMap.put(name, obj); |
| 1830 | return obj; |
| 1831 | } |
| 1832 | |
| 1833 | public T stopObject(String name) { |
Joe Onorato | 388fc33 | 2016-04-12 17:06:47 -0700 | [diff] [blame] | 1834 | if (name == null) { |
| 1835 | name = ""; |
| 1836 | } |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 1837 | T obj = mMap.get(name); |
| 1838 | if (obj != null) { |
| 1839 | return obj; |
| 1840 | } |
| 1841 | |
| 1842 | // No object exists for the given name, but do we currently have it |
| 1843 | // running as part of the overflow? |
| 1844 | if (mActiveOverflow != null) { |
| 1845 | MutableInt over = mActiveOverflow.get(name); |
| 1846 | if (over != null) { |
| 1847 | // We are already actively counting this name in the overflow object. |
| 1848 | obj = mCurOverflow; |
| 1849 | if (obj != null) { |
| 1850 | over.value--; |
| 1851 | if (over.value <= 0) { |
| 1852 | mActiveOverflow.remove(name); |
| 1853 | } |
| 1854 | return obj; |
| 1855 | } |
| 1856 | } |
| 1857 | } |
| 1858 | |
| 1859 | // Huh, they are stopping an active operation but we can't find one! |
| 1860 | // That's not good. |
| 1861 | Slog.wtf(TAG, "Unable to find object for " + name + " mapsize=" |
| 1862 | + mMap.size() + " activeoverflow=" + mActiveOverflow |
| 1863 | + " curoverflow=" + mCurOverflow); |
| 1864 | return null; |
| 1865 | } |
| 1866 | |
| 1867 | public abstract T instantiateObject(); |
| 1868 | } |
| 1869 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 1870 | public static class ControllerActivityCounterImpl extends ControllerActivityCounter |
| 1871 | implements Parcelable { |
| 1872 | private final LongSamplingCounter mIdleTimeMillis; |
| 1873 | private final LongSamplingCounter mRxTimeMillis; |
| 1874 | private final LongSamplingCounter[] mTxTimeMillis; |
| 1875 | private final LongSamplingCounter mPowerDrainMaMs; |
| 1876 | |
| 1877 | public ControllerActivityCounterImpl(TimeBase timeBase, int numTxStates) { |
| 1878 | mIdleTimeMillis = new LongSamplingCounter(timeBase); |
| 1879 | mRxTimeMillis = new LongSamplingCounter(timeBase); |
| 1880 | mTxTimeMillis = new LongSamplingCounter[numTxStates]; |
| 1881 | for (int i = 0; i < numTxStates; i++) { |
| 1882 | mTxTimeMillis[i] = new LongSamplingCounter(timeBase); |
| 1883 | } |
| 1884 | mPowerDrainMaMs = new LongSamplingCounter(timeBase); |
| 1885 | } |
| 1886 | |
| 1887 | public ControllerActivityCounterImpl(TimeBase timeBase, int numTxStates, Parcel in) { |
| 1888 | mIdleTimeMillis = new LongSamplingCounter(timeBase, in); |
| 1889 | mRxTimeMillis = new LongSamplingCounter(timeBase, in); |
| 1890 | final int recordedTxStates = in.readInt(); |
| 1891 | if (recordedTxStates != numTxStates) { |
| 1892 | throw new ParcelFormatException("inconsistent tx state lengths"); |
| 1893 | } |
| 1894 | |
| 1895 | mTxTimeMillis = new LongSamplingCounter[numTxStates]; |
| 1896 | for (int i = 0; i < numTxStates; i++) { |
| 1897 | mTxTimeMillis[i] = new LongSamplingCounter(timeBase, in); |
| 1898 | } |
| 1899 | mPowerDrainMaMs = new LongSamplingCounter(timeBase, in); |
| 1900 | } |
| 1901 | |
| 1902 | public void readSummaryFromParcel(Parcel in) { |
| 1903 | mIdleTimeMillis.readSummaryFromParcelLocked(in); |
| 1904 | mRxTimeMillis.readSummaryFromParcelLocked(in); |
| 1905 | final int recordedTxStates = in.readInt(); |
| 1906 | if (recordedTxStates != mTxTimeMillis.length) { |
| 1907 | throw new ParcelFormatException("inconsistent tx state lengths"); |
| 1908 | } |
| 1909 | for (LongSamplingCounter counter : mTxTimeMillis) { |
| 1910 | counter.readSummaryFromParcelLocked(in); |
| 1911 | } |
| 1912 | mPowerDrainMaMs.readSummaryFromParcelLocked(in); |
| 1913 | } |
| 1914 | |
| 1915 | @Override |
| 1916 | public int describeContents() { |
| 1917 | return 0; |
| 1918 | } |
| 1919 | |
| 1920 | public void writeSummaryToParcel(Parcel dest) { |
| 1921 | mIdleTimeMillis.writeSummaryFromParcelLocked(dest); |
| 1922 | mRxTimeMillis.writeSummaryFromParcelLocked(dest); |
| 1923 | dest.writeInt(mTxTimeMillis.length); |
| 1924 | for (LongSamplingCounter counter : mTxTimeMillis) { |
| 1925 | counter.writeSummaryFromParcelLocked(dest); |
| 1926 | } |
| 1927 | mPowerDrainMaMs.writeSummaryFromParcelLocked(dest); |
| 1928 | } |
| 1929 | |
| 1930 | @Override |
| 1931 | public void writeToParcel(Parcel dest, int flags) { |
| 1932 | mIdleTimeMillis.writeToParcel(dest); |
| 1933 | mRxTimeMillis.writeToParcel(dest); |
| 1934 | dest.writeInt(mTxTimeMillis.length); |
| 1935 | for (LongSamplingCounter counter : mTxTimeMillis) { |
| 1936 | counter.writeToParcel(dest); |
| 1937 | } |
| 1938 | mPowerDrainMaMs.writeToParcel(dest); |
| 1939 | } |
| 1940 | |
| 1941 | public void reset(boolean detachIfReset) { |
| 1942 | mIdleTimeMillis.reset(detachIfReset); |
| 1943 | mRxTimeMillis.reset(detachIfReset); |
| 1944 | for (LongSamplingCounter counter : mTxTimeMillis) { |
| 1945 | counter.reset(detachIfReset); |
| 1946 | } |
| 1947 | mPowerDrainMaMs.reset(detachIfReset); |
| 1948 | } |
| 1949 | |
| 1950 | public void detach() { |
| 1951 | mIdleTimeMillis.detach(); |
| 1952 | mRxTimeMillis.detach(); |
| 1953 | for (LongSamplingCounter counter : mTxTimeMillis) { |
| 1954 | counter.detach(); |
| 1955 | } |
| 1956 | mPowerDrainMaMs.detach(); |
| 1957 | } |
| 1958 | |
| 1959 | /** |
| 1960 | * @return a LongSamplingCounter, measuring time spent in the idle state in |
| 1961 | * milliseconds. |
| 1962 | */ |
| 1963 | @Override |
| 1964 | public LongSamplingCounter getIdleTimeCounter() { |
Roshan Pius | 8164330 | 2016-03-14 16:45:55 -0700 | [diff] [blame] | 1965 | return mIdleTimeMillis; |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 1966 | } |
| 1967 | |
| 1968 | /** |
| 1969 | * @return a LongSamplingCounter, measuring time spent in the receive state in |
| 1970 | * milliseconds. |
| 1971 | */ |
| 1972 | @Override |
| 1973 | public LongSamplingCounter getRxTimeCounter() { |
| 1974 | return mRxTimeMillis; |
| 1975 | } |
| 1976 | |
| 1977 | /** |
| 1978 | * @return a LongSamplingCounter[], measuring time spent in various transmit states in |
| 1979 | * milliseconds. |
| 1980 | */ |
| 1981 | @Override |
| 1982 | public LongSamplingCounter[] getTxTimeCounters() { |
| 1983 | return mTxTimeMillis; |
| 1984 | } |
| 1985 | |
| 1986 | /** |
| 1987 | * @return a LongSamplingCounter, measuring power use in milli-ampere milliseconds (mAmS). |
| 1988 | */ |
| 1989 | @Override |
| 1990 | public LongSamplingCounter getPowerCounter() { |
| 1991 | return mPowerDrainMaMs; |
| 1992 | } |
| 1993 | } |
| 1994 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1995 | /* |
| 1996 | * Get the wakeup reason counter, and create a new one if one |
| 1997 | * doesn't already exist. |
| 1998 | */ |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 1999 | public SamplingTimer getWakeupReasonTimerLocked(String name) { |
| 2000 | SamplingTimer timer = mWakeupReasonStats.get(name); |
| 2001 | if (timer == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 2002 | timer = new SamplingTimer(mClocks, mOnBatteryTimeBase, true); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 2003 | mWakeupReasonStats.put(name, timer); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2004 | } |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 2005 | return timer; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2006 | } |
| 2007 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2008 | /* |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2009 | * Get the KernelWakelockTimer associated with name, and create a new one if one |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2010 | * doesn't already exist. |
| 2011 | */ |
| 2012 | public SamplingTimer getKernelWakelockTimerLocked(String name) { |
| 2013 | SamplingTimer kwlt = mKernelWakelockStats.get(name); |
| 2014 | if (kwlt == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 2015 | kwlt = new SamplingTimer(mClocks, mOnBatteryScreenOffTimeBase, |
| 2016 | true /* track reported values */); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2017 | mKernelWakelockStats.put(name, kwlt); |
| 2018 | } |
| 2019 | return kwlt; |
| 2020 | } |
Amith Yamasani | 3718aaa | 2009-06-09 06:32:35 -0700 | [diff] [blame] | 2021 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2022 | private int writeHistoryTag(HistoryTag tag) { |
| 2023 | Integer idxObj = mHistoryTagPool.get(tag); |
| 2024 | int idx; |
| 2025 | if (idxObj != null) { |
| 2026 | idx = idxObj; |
| 2027 | } else { |
| 2028 | idx = mNextHistoryTagIdx; |
| 2029 | HistoryTag key = new HistoryTag(); |
| 2030 | key.setTo(tag); |
| 2031 | tag.poolIdx = idx; |
| 2032 | mHistoryTagPool.put(key, idx); |
| 2033 | mNextHistoryTagIdx++; |
| 2034 | mNumHistoryTagChars += key.string.length() + 1; |
| 2035 | } |
| 2036 | return idx; |
| 2037 | } |
| 2038 | |
| 2039 | private void readHistoryTag(int index, HistoryTag tag) { |
| 2040 | tag.string = mReadHistoryStrings[index]; |
| 2041 | tag.uid = mReadHistoryUids[index]; |
| 2042 | tag.poolIdx = index; |
| 2043 | } |
| 2044 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2045 | // Part of initial delta int that specifies the time delta. |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 2046 | static final int DELTA_TIME_MASK = 0x7ffff; |
| 2047 | static final int DELTA_TIME_LONG = 0x7ffff; // The delta is a following long |
| 2048 | static final int DELTA_TIME_INT = 0x7fffe; // The delta is a following int |
| 2049 | static final int DELTA_TIME_ABS = 0x7fffd; // Following is an entire abs update. |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2050 | // Flag in delta int: a new battery level int follows. |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 2051 | static final int DELTA_BATTERY_LEVEL_FLAG = 0x00080000; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2052 | // Flag in delta int: a new full state and battery status int follows. |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 2053 | static final int DELTA_STATE_FLAG = 0x00100000; |
| 2054 | // Flag in delta int: a new full state2 int follows. |
| 2055 | static final int DELTA_STATE2_FLAG = 0x00200000; |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 2056 | // Flag in delta int: contains a wakelock or wakeReason tag. |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 2057 | static final int DELTA_WAKELOCK_FLAG = 0x00400000; |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2058 | // Flag in delta int: contains an event description. |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 2059 | static final int DELTA_EVENT_FLAG = 0x00800000; |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2060 | // These upper bits are the frequently changing state bits. |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 2061 | static final int DELTA_STATE_MASK = 0xff000000; |
| 2062 | |
| 2063 | // These are the pieces of battery state that are packed in to the upper bits of |
| 2064 | // the state int that have been packed in to the first delta int. They must fit |
| 2065 | // in DELTA_STATE_MASK. |
| 2066 | static final int STATE_BATTERY_STATUS_MASK = 0x00000007; |
| 2067 | static final int STATE_BATTERY_STATUS_SHIFT = 29; |
| 2068 | static final int STATE_BATTERY_HEALTH_MASK = 0x00000007; |
| 2069 | static final int STATE_BATTERY_HEALTH_SHIFT = 26; |
| 2070 | static final int STATE_BATTERY_PLUG_MASK = 0x00000003; |
| 2071 | static final int STATE_BATTERY_PLUG_SHIFT = 24; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2072 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 2073 | // We use the low bit of the battery state int to indicate that we have full details |
| 2074 | // from a battery level change. |
| 2075 | static final int BATTERY_DELTA_LEVEL_FLAG = 0x00000001; |
| 2076 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2077 | public void writeHistoryDelta(Parcel dest, HistoryItem cur, HistoryItem last) { |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2078 | if (last == null || cur.cmd != HistoryItem.CMD_UPDATE) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2079 | dest.writeInt(DELTA_TIME_ABS); |
| 2080 | cur.writeToParcel(dest, 0); |
| 2081 | return; |
| 2082 | } |
| 2083 | |
| 2084 | final long deltaTime = cur.time - last.time; |
| 2085 | final int lastBatteryLevelInt = buildBatteryLevelInt(last); |
| 2086 | final int lastStateInt = buildStateInt(last); |
| 2087 | |
| 2088 | int deltaTimeToken; |
| 2089 | if (deltaTime < 0 || deltaTime > Integer.MAX_VALUE) { |
| 2090 | deltaTimeToken = DELTA_TIME_LONG; |
| 2091 | } else if (deltaTime >= DELTA_TIME_ABS) { |
| 2092 | deltaTimeToken = DELTA_TIME_INT; |
| 2093 | } else { |
| 2094 | deltaTimeToken = (int)deltaTime; |
| 2095 | } |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2096 | int firstToken = deltaTimeToken | (cur.states&DELTA_STATE_MASK); |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 2097 | final int includeStepDetails = mLastHistoryStepLevel > cur.batteryLevel |
| 2098 | ? BATTERY_DELTA_LEVEL_FLAG : 0; |
| 2099 | final boolean computeStepDetails = includeStepDetails != 0 |
| 2100 | || mLastHistoryStepDetails == null; |
| 2101 | final int batteryLevelInt = buildBatteryLevelInt(cur) | includeStepDetails; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2102 | final boolean batteryLevelIntChanged = batteryLevelInt != lastBatteryLevelInt; |
| 2103 | if (batteryLevelIntChanged) { |
| 2104 | firstToken |= DELTA_BATTERY_LEVEL_FLAG; |
| 2105 | } |
| 2106 | final int stateInt = buildStateInt(cur); |
| 2107 | final boolean stateIntChanged = stateInt != lastStateInt; |
| 2108 | if (stateIntChanged) { |
| 2109 | firstToken |= DELTA_STATE_FLAG; |
| 2110 | } |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2111 | final boolean state2IntChanged = cur.states2 != last.states2; |
| 2112 | if (state2IntChanged) { |
| 2113 | firstToken |= DELTA_STATE2_FLAG; |
| 2114 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 2115 | if (cur.wakelockTag != null || cur.wakeReasonTag != null) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2116 | firstToken |= DELTA_WAKELOCK_FLAG; |
| 2117 | } |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2118 | if (cur.eventCode != HistoryItem.EVENT_NONE) { |
| 2119 | firstToken |= DELTA_EVENT_FLAG; |
| 2120 | } |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2121 | dest.writeInt(firstToken); |
| 2122 | if (DEBUG) Slog.i(TAG, "WRITE DELTA: firstToken=0x" + Integer.toHexString(firstToken) |
| 2123 | + " deltaTime=" + deltaTime); |
| 2124 | |
| 2125 | if (deltaTimeToken >= DELTA_TIME_INT) { |
| 2126 | if (deltaTimeToken == DELTA_TIME_INT) { |
| 2127 | if (DEBUG) Slog.i(TAG, "WRITE DELTA: int deltaTime=" + (int)deltaTime); |
| 2128 | dest.writeInt((int)deltaTime); |
| 2129 | } else { |
| 2130 | if (DEBUG) Slog.i(TAG, "WRITE DELTA: long deltaTime=" + deltaTime); |
| 2131 | dest.writeLong(deltaTime); |
| 2132 | } |
| 2133 | } |
| 2134 | if (batteryLevelIntChanged) { |
| 2135 | dest.writeInt(batteryLevelInt); |
| 2136 | if (DEBUG) Slog.i(TAG, "WRITE DELTA: batteryToken=0x" |
| 2137 | + Integer.toHexString(batteryLevelInt) |
| 2138 | + " batteryLevel=" + cur.batteryLevel |
| 2139 | + " batteryTemp=" + cur.batteryTemperature |
| 2140 | + " batteryVolt=" + (int)cur.batteryVoltage); |
| 2141 | } |
| 2142 | if (stateIntChanged) { |
| 2143 | dest.writeInt(stateInt); |
| 2144 | if (DEBUG) Slog.i(TAG, "WRITE DELTA: stateToken=0x" |
| 2145 | + Integer.toHexString(stateInt) |
| 2146 | + " batteryStatus=" + cur.batteryStatus |
| 2147 | + " batteryHealth=" + cur.batteryHealth |
| 2148 | + " batteryPlugType=" + cur.batteryPlugType |
| 2149 | + " states=0x" + Integer.toHexString(cur.states)); |
| 2150 | } |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2151 | if (state2IntChanged) { |
| 2152 | dest.writeInt(cur.states2); |
| 2153 | if (DEBUG) Slog.i(TAG, "WRITE DELTA: states2=0x" |
| 2154 | + Integer.toHexString(cur.states2)); |
| 2155 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 2156 | if (cur.wakelockTag != null || cur.wakeReasonTag != null) { |
| 2157 | int wakeLockIndex; |
| 2158 | int wakeReasonIndex; |
| 2159 | if (cur.wakelockTag != null) { |
| 2160 | wakeLockIndex = writeHistoryTag(cur.wakelockTag); |
| 2161 | if (DEBUG) Slog.i(TAG, "WRITE DELTA: wakelockTag=#" + cur.wakelockTag.poolIdx |
| 2162 | + " " + cur.wakelockTag.uid + ":" + cur.wakelockTag.string); |
| 2163 | } else { |
| 2164 | wakeLockIndex = 0xffff; |
| 2165 | } |
| 2166 | if (cur.wakeReasonTag != null) { |
| 2167 | wakeReasonIndex = writeHistoryTag(cur.wakeReasonTag); |
| 2168 | if (DEBUG) Slog.i(TAG, "WRITE DELTA: wakeReasonTag=#" + cur.wakeReasonTag.poolIdx |
| 2169 | + " " + cur.wakeReasonTag.uid + ":" + cur.wakeReasonTag.string); |
| 2170 | } else { |
| 2171 | wakeReasonIndex = 0xffff; |
| 2172 | } |
| 2173 | dest.writeInt((wakeReasonIndex<<16) | wakeLockIndex); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2174 | } |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2175 | if (cur.eventCode != HistoryItem.EVENT_NONE) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2176 | int index = writeHistoryTag(cur.eventTag); |
| 2177 | int codeAndIndex = (cur.eventCode&0xffff) | (index<<16); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 2178 | dest.writeInt(codeAndIndex); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2179 | if (DEBUG) Slog.i(TAG, "WRITE DELTA: event=" + cur.eventCode + " tag=#" |
| 2180 | + cur.eventTag.poolIdx + " " + cur.eventTag.uid + ":" |
| 2181 | + cur.eventTag.string); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2182 | } |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 2183 | if (computeStepDetails) { |
| 2184 | computeHistoryStepDetails(mCurHistoryStepDetails, mLastHistoryStepDetails); |
| 2185 | if (includeStepDetails != 0) { |
| 2186 | mCurHistoryStepDetails.writeToParcel(dest); |
| 2187 | } |
| 2188 | cur.stepDetails = mCurHistoryStepDetails; |
| 2189 | mLastHistoryStepDetails = mCurHistoryStepDetails; |
| 2190 | } else { |
| 2191 | cur.stepDetails = null; |
| 2192 | } |
| 2193 | if (mLastHistoryStepLevel < cur.batteryLevel) { |
| 2194 | mLastHistoryStepDetails = null; |
| 2195 | } |
| 2196 | mLastHistoryStepLevel = cur.batteryLevel; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2197 | } |
| 2198 | |
| 2199 | private int buildBatteryLevelInt(HistoryItem h) { |
| 2200 | return ((((int)h.batteryLevel)<<25)&0xfe000000) |
Adam Lesinski | 3944c81 | 2015-11-13 15:54:59 -0800 | [diff] [blame] | 2201 | | ((((int)h.batteryTemperature)<<15)&0x01ff8000) |
| 2202 | | ((((int)h.batteryVoltage)<<1)&0x00007ffe); |
| 2203 | } |
| 2204 | |
| 2205 | private void readBatteryLevelInt(int batteryLevelInt, HistoryItem out) { |
| 2206 | out.batteryLevel = (byte)((batteryLevelInt & 0xfe000000) >>> 25); |
| 2207 | out.batteryTemperature = (short)((batteryLevelInt & 0x01ff8000) >>> 15); |
| 2208 | out.batteryVoltage = (char)((batteryLevelInt & 0x00007ffe) >>> 1); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2209 | } |
| 2210 | |
| 2211 | private int buildStateInt(HistoryItem h) { |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 2212 | int plugType = 0; |
| 2213 | if ((h.batteryPlugType&BatteryManager.BATTERY_PLUGGED_AC) != 0) { |
| 2214 | plugType = 1; |
| 2215 | } else if ((h.batteryPlugType&BatteryManager.BATTERY_PLUGGED_USB) != 0) { |
| 2216 | plugType = 2; |
| 2217 | } else if ((h.batteryPlugType&BatteryManager.BATTERY_PLUGGED_WIRELESS) != 0) { |
| 2218 | plugType = 3; |
| 2219 | } |
| 2220 | return ((h.batteryStatus&STATE_BATTERY_STATUS_MASK)<<STATE_BATTERY_STATUS_SHIFT) |
| 2221 | | ((h.batteryHealth&STATE_BATTERY_HEALTH_MASK)<<STATE_BATTERY_HEALTH_SHIFT) |
| 2222 | | ((plugType&STATE_BATTERY_PLUG_MASK)<<STATE_BATTERY_PLUG_SHIFT) |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2223 | | (h.states&(~DELTA_STATE_MASK)); |
| 2224 | } |
| 2225 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 2226 | private void computeHistoryStepDetails(final HistoryStepDetails out, |
| 2227 | final HistoryStepDetails last) { |
| 2228 | final HistoryStepDetails tmp = last != null ? mTmpHistoryStepDetails : out; |
| 2229 | |
| 2230 | // Perform a CPU update right after we do this collection, so we have started |
| 2231 | // collecting good data for the next step. |
| 2232 | requestImmediateCpuUpdate(); |
| 2233 | |
| 2234 | if (last == null) { |
| 2235 | // We are not generating a delta, so all we need to do is reset the stats |
| 2236 | // we will later be doing a delta from. |
| 2237 | final int NU = mUidStats.size(); |
| 2238 | for (int i=0; i<NU; i++) { |
| 2239 | final BatteryStatsImpl.Uid uid = mUidStats.valueAt(i); |
| 2240 | uid.mLastStepUserTime = uid.mCurStepUserTime; |
| 2241 | uid.mLastStepSystemTime = uid.mCurStepSystemTime; |
| 2242 | } |
| 2243 | mLastStepCpuUserTime = mCurStepCpuUserTime; |
| 2244 | mLastStepCpuSystemTime = mCurStepCpuSystemTime; |
| 2245 | mLastStepStatUserTime = mCurStepStatUserTime; |
| 2246 | mLastStepStatSystemTime = mCurStepStatSystemTime; |
| 2247 | mLastStepStatIOWaitTime = mCurStepStatIOWaitTime; |
| 2248 | mLastStepStatIrqTime = mCurStepStatIrqTime; |
| 2249 | mLastStepStatSoftIrqTime = mCurStepStatSoftIrqTime; |
| 2250 | mLastStepStatIdleTime = mCurStepStatIdleTime; |
| 2251 | tmp.clear(); |
| 2252 | return; |
| 2253 | } |
| 2254 | if (DEBUG) { |
| 2255 | Slog.d(TAG, "Step stats last: user=" + mLastStepCpuUserTime + " sys=" |
| 2256 | + mLastStepStatSystemTime + " io=" + mLastStepStatIOWaitTime |
| 2257 | + " irq=" + mLastStepStatIrqTime + " sirq=" |
| 2258 | + mLastStepStatSoftIrqTime + " idle=" + mLastStepStatIdleTime); |
| 2259 | Slog.d(TAG, "Step stats cur: user=" + mCurStepCpuUserTime + " sys=" |
| 2260 | + mCurStepStatSystemTime + " io=" + mCurStepStatIOWaitTime |
| 2261 | + " irq=" + mCurStepStatIrqTime + " sirq=" |
| 2262 | + mCurStepStatSoftIrqTime + " idle=" + mCurStepStatIdleTime); |
| 2263 | } |
| 2264 | out.userTime = (int)(mCurStepCpuUserTime - mLastStepCpuUserTime); |
| 2265 | out.systemTime = (int)(mCurStepCpuSystemTime - mLastStepCpuSystemTime); |
| 2266 | out.statUserTime = (int)(mCurStepStatUserTime - mLastStepStatUserTime); |
| 2267 | out.statSystemTime = (int)(mCurStepStatSystemTime - mLastStepStatSystemTime); |
| 2268 | out.statIOWaitTime = (int)(mCurStepStatIOWaitTime - mLastStepStatIOWaitTime); |
| 2269 | out.statIrqTime = (int)(mCurStepStatIrqTime - mLastStepStatIrqTime); |
| 2270 | out.statSoftIrqTime = (int)(mCurStepStatSoftIrqTime - mLastStepStatSoftIrqTime); |
| 2271 | out.statIdlTime = (int)(mCurStepStatIdleTime - mLastStepStatIdleTime); |
| 2272 | out.appCpuUid1 = out.appCpuUid2 = out.appCpuUid3 = -1; |
| 2273 | out.appCpuUTime1 = out.appCpuUTime2 = out.appCpuUTime3 = 0; |
| 2274 | out.appCpuSTime1 = out.appCpuSTime2 = out.appCpuSTime3 = 0; |
| 2275 | final int NU = mUidStats.size(); |
| 2276 | for (int i=0; i<NU; i++) { |
| 2277 | final BatteryStatsImpl.Uid uid = mUidStats.valueAt(i); |
| 2278 | final int totalUTime = (int)(uid.mCurStepUserTime - uid.mLastStepUserTime); |
| 2279 | final int totalSTime = (int)(uid.mCurStepSystemTime - uid.mLastStepSystemTime); |
| 2280 | final int totalTime = totalUTime + totalSTime; |
| 2281 | uid.mLastStepUserTime = uid.mCurStepUserTime; |
| 2282 | uid.mLastStepSystemTime = uid.mCurStepSystemTime; |
| 2283 | if (totalTime <= (out.appCpuUTime3+out.appCpuSTime3)) { |
| 2284 | continue; |
| 2285 | } |
| 2286 | if (totalTime <= (out.appCpuUTime2+out.appCpuSTime2)) { |
| 2287 | out.appCpuUid3 = uid.mUid; |
| 2288 | out.appCpuUTime3 = totalUTime; |
| 2289 | out.appCpuSTime3 = totalSTime; |
| 2290 | } else { |
| 2291 | out.appCpuUid3 = out.appCpuUid2; |
| 2292 | out.appCpuUTime3 = out.appCpuUTime2; |
| 2293 | out.appCpuSTime3 = out.appCpuSTime2; |
| 2294 | if (totalTime <= (out.appCpuUTime1+out.appCpuSTime1)) { |
| 2295 | out.appCpuUid2 = uid.mUid; |
| 2296 | out.appCpuUTime2 = totalUTime; |
| 2297 | out.appCpuSTime2 = totalSTime; |
| 2298 | } else { |
| 2299 | out.appCpuUid2 = out.appCpuUid1; |
| 2300 | out.appCpuUTime2 = out.appCpuUTime1; |
| 2301 | out.appCpuSTime2 = out.appCpuSTime1; |
| 2302 | out.appCpuUid1 = uid.mUid; |
| 2303 | out.appCpuUTime1 = totalUTime; |
| 2304 | out.appCpuSTime1 = totalSTime; |
| 2305 | } |
| 2306 | } |
| 2307 | } |
| 2308 | mLastStepCpuUserTime = mCurStepCpuUserTime; |
| 2309 | mLastStepCpuSystemTime = mCurStepCpuSystemTime; |
| 2310 | mLastStepStatUserTime = mCurStepStatUserTime; |
| 2311 | mLastStepStatSystemTime = mCurStepStatSystemTime; |
| 2312 | mLastStepStatIOWaitTime = mCurStepStatIOWaitTime; |
| 2313 | mLastStepStatIrqTime = mCurStepStatIrqTime; |
| 2314 | mLastStepStatSoftIrqTime = mCurStepStatSoftIrqTime; |
| 2315 | mLastStepStatIdleTime = mCurStepStatIdleTime; |
| 2316 | } |
| 2317 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2318 | public void readHistoryDelta(Parcel src, HistoryItem cur) { |
| 2319 | int firstToken = src.readInt(); |
| 2320 | int deltaTimeToken = firstToken&DELTA_TIME_MASK; |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2321 | cur.cmd = HistoryItem.CMD_UPDATE; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2322 | cur.numReadInts = 1; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2323 | if (DEBUG) Slog.i(TAG, "READ DELTA: firstToken=0x" + Integer.toHexString(firstToken) |
| 2324 | + " deltaTimeToken=" + deltaTimeToken); |
| 2325 | |
| 2326 | if (deltaTimeToken < DELTA_TIME_ABS) { |
| 2327 | cur.time += deltaTimeToken; |
| 2328 | } else if (deltaTimeToken == DELTA_TIME_ABS) { |
| 2329 | cur.time = src.readLong(); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2330 | cur.numReadInts += 2; |
| 2331 | if (DEBUG) Slog.i(TAG, "READ DELTA: ABS time=" + cur.time); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2332 | cur.readFromParcel(src); |
| 2333 | return; |
| 2334 | } else if (deltaTimeToken == DELTA_TIME_INT) { |
| 2335 | int delta = src.readInt(); |
| 2336 | cur.time += delta; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2337 | cur.numReadInts += 1; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2338 | if (DEBUG) Slog.i(TAG, "READ DELTA: time delta=" + delta + " new time=" + cur.time); |
| 2339 | } else { |
| 2340 | long delta = src.readLong(); |
| 2341 | if (DEBUG) Slog.i(TAG, "READ DELTA: time delta=" + delta + " new time=" + cur.time); |
| 2342 | cur.time += delta; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2343 | cur.numReadInts += 2; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2344 | } |
| 2345 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 2346 | final int batteryLevelInt; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2347 | if ((firstToken&DELTA_BATTERY_LEVEL_FLAG) != 0) { |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 2348 | batteryLevelInt = src.readInt(); |
Adam Lesinski | 3944c81 | 2015-11-13 15:54:59 -0800 | [diff] [blame] | 2349 | readBatteryLevelInt(batteryLevelInt, cur); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2350 | cur.numReadInts += 1; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2351 | if (DEBUG) Slog.i(TAG, "READ DELTA: batteryToken=0x" |
| 2352 | + Integer.toHexString(batteryLevelInt) |
| 2353 | + " batteryLevel=" + cur.batteryLevel |
| 2354 | + " batteryTemp=" + cur.batteryTemperature |
| 2355 | + " batteryVolt=" + (int)cur.batteryVoltage); |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 2356 | } else { |
| 2357 | batteryLevelInt = 0; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2358 | } |
| 2359 | |
| 2360 | if ((firstToken&DELTA_STATE_FLAG) != 0) { |
| 2361 | int stateInt = src.readInt(); |
| 2362 | cur.states = (firstToken&DELTA_STATE_MASK) | (stateInt&(~DELTA_STATE_MASK)); |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 2363 | cur.batteryStatus = (byte)((stateInt>>STATE_BATTERY_STATUS_SHIFT) |
| 2364 | & STATE_BATTERY_STATUS_MASK); |
| 2365 | cur.batteryHealth = (byte)((stateInt>>STATE_BATTERY_HEALTH_SHIFT) |
| 2366 | & STATE_BATTERY_HEALTH_MASK); |
| 2367 | cur.batteryPlugType = (byte)((stateInt>>STATE_BATTERY_PLUG_SHIFT) |
| 2368 | & STATE_BATTERY_PLUG_MASK); |
| 2369 | switch (cur.batteryPlugType) { |
| 2370 | case 1: |
| 2371 | cur.batteryPlugType = BatteryManager.BATTERY_PLUGGED_AC; |
| 2372 | break; |
| 2373 | case 2: |
| 2374 | cur.batteryPlugType = BatteryManager.BATTERY_PLUGGED_USB; |
| 2375 | break; |
| 2376 | case 3: |
| 2377 | cur.batteryPlugType = BatteryManager.BATTERY_PLUGGED_WIRELESS; |
| 2378 | break; |
| 2379 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2380 | cur.numReadInts += 1; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2381 | if (DEBUG) Slog.i(TAG, "READ DELTA: stateToken=0x" |
| 2382 | + Integer.toHexString(stateInt) |
| 2383 | + " batteryStatus=" + cur.batteryStatus |
| 2384 | + " batteryHealth=" + cur.batteryHealth |
| 2385 | + " batteryPlugType=" + cur.batteryPlugType |
| 2386 | + " states=0x" + Integer.toHexString(cur.states)); |
| 2387 | } else { |
| 2388 | cur.states = (firstToken&DELTA_STATE_MASK) | (cur.states&(~DELTA_STATE_MASK)); |
| 2389 | } |
| 2390 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2391 | if ((firstToken&DELTA_STATE2_FLAG) != 0) { |
| 2392 | cur.states2 = src.readInt(); |
| 2393 | if (DEBUG) Slog.i(TAG, "READ DELTA: states2=0x" |
| 2394 | + Integer.toHexString(cur.states2)); |
| 2395 | } |
| 2396 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2397 | if ((firstToken&DELTA_WAKELOCK_FLAG) != 0) { |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 2398 | int indexes = src.readInt(); |
| 2399 | int wakeLockIndex = indexes&0xffff; |
| 2400 | int wakeReasonIndex = (indexes>>16)&0xffff; |
| 2401 | if (wakeLockIndex != 0xffff) { |
| 2402 | cur.wakelockTag = cur.localWakelockTag; |
| 2403 | readHistoryTag(wakeLockIndex, cur.wakelockTag); |
| 2404 | if (DEBUG) Slog.i(TAG, "READ DELTA: wakelockTag=#" + cur.wakelockTag.poolIdx |
| 2405 | + " " + cur.wakelockTag.uid + ":" + cur.wakelockTag.string); |
| 2406 | } else { |
| 2407 | cur.wakelockTag = null; |
| 2408 | } |
| 2409 | if (wakeReasonIndex != 0xffff) { |
| 2410 | cur.wakeReasonTag = cur.localWakeReasonTag; |
| 2411 | readHistoryTag(wakeReasonIndex, cur.wakeReasonTag); |
| 2412 | if (DEBUG) Slog.i(TAG, "READ DELTA: wakeReasonTag=#" + cur.wakeReasonTag.poolIdx |
| 2413 | + " " + cur.wakeReasonTag.uid + ":" + cur.wakeReasonTag.string); |
| 2414 | } else { |
| 2415 | cur.wakeReasonTag = null; |
| 2416 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2417 | cur.numReadInts += 1; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2418 | } else { |
| 2419 | cur.wakelockTag = null; |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 2420 | cur.wakeReasonTag = null; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2421 | } |
| 2422 | |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2423 | if ((firstToken&DELTA_EVENT_FLAG) != 0) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2424 | cur.eventTag = cur.localEventTag; |
| 2425 | final int codeAndIndex = src.readInt(); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 2426 | cur.eventCode = (codeAndIndex&0xffff); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2427 | final int index = ((codeAndIndex>>16)&0xffff); |
| 2428 | readHistoryTag(index, cur.eventTag); |
| 2429 | cur.numReadInts += 1; |
| 2430 | if (DEBUG) Slog.i(TAG, "READ DELTA: event=" + cur.eventCode + " tag=#" |
| 2431 | + cur.eventTag.poolIdx + " " + cur.eventTag.uid + ":" |
| 2432 | + cur.eventTag.string); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2433 | } else { |
| 2434 | cur.eventCode = HistoryItem.EVENT_NONE; |
| 2435 | } |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 2436 | |
| 2437 | if ((batteryLevelInt&BATTERY_DELTA_LEVEL_FLAG) != 0) { |
| 2438 | cur.stepDetails = mReadHistoryStepDetails; |
| 2439 | cur.stepDetails.readFromParcel(src); |
| 2440 | } else { |
| 2441 | cur.stepDetails = null; |
| 2442 | } |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2443 | } |
| 2444 | |
Dianne Hackborn | fc06413 | 2014-06-02 12:42:12 -0700 | [diff] [blame] | 2445 | @Override |
| 2446 | public void commitCurrentHistoryBatchLocked() { |
| 2447 | mHistoryLastWritten.cmd = HistoryItem.CMD_NULL; |
| 2448 | } |
| 2449 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2450 | void addHistoryBufferLocked(long elapsedRealtimeMs, long uptimeMs, HistoryItem cur) { |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2451 | if (!mHaveBatteryLevel || !mRecordingHistory) { |
| 2452 | return; |
| 2453 | } |
| 2454 | |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2455 | final long timeDiff = (mHistoryBaseTime+elapsedRealtimeMs) - mHistoryLastWritten.time; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 2456 | final int diffStates = mHistoryLastWritten.states^(cur.states&mActiveHistoryStates); |
| 2457 | final int diffStates2 = mHistoryLastWritten.states2^(cur.states2&mActiveHistoryStates2); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2458 | final int lastDiffStates = mHistoryLastWritten.states^mHistoryLastLastWritten.states; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2459 | final int lastDiffStates2 = mHistoryLastWritten.states2^mHistoryLastLastWritten.states2; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2460 | if (DEBUG) Slog.i(TAG, "ADD: tdelta=" + timeDiff + " diff=" |
| 2461 | + Integer.toHexString(diffStates) + " lastDiff=" |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2462 | + Integer.toHexString(lastDiffStates) + " diff2=" |
| 2463 | + Integer.toHexString(diffStates2) + " lastDiff2=" |
| 2464 | + Integer.toHexString(lastDiffStates2)); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2465 | if (mHistoryBufferLastPos >= 0 && mHistoryLastWritten.cmd == HistoryItem.CMD_UPDATE |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2466 | && timeDiff < 1000 && (diffStates&lastDiffStates) == 0 |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2467 | && (diffStates2&lastDiffStates2) == 0 |
| 2468 | && (mHistoryLastWritten.wakelockTag == null || cur.wakelockTag == null) |
| 2469 | && (mHistoryLastWritten.wakeReasonTag == null || cur.wakeReasonTag == null) |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 2470 | && mHistoryLastWritten.stepDetails == null |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2471 | && (mHistoryLastWritten.eventCode == HistoryItem.EVENT_NONE |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2472 | || cur.eventCode == HistoryItem.EVENT_NONE) |
| 2473 | && mHistoryLastWritten.batteryLevel == cur.batteryLevel |
| 2474 | && mHistoryLastWritten.batteryStatus == cur.batteryStatus |
| 2475 | && mHistoryLastWritten.batteryHealth == cur.batteryHealth |
| 2476 | && mHistoryLastWritten.batteryPlugType == cur.batteryPlugType |
| 2477 | && mHistoryLastWritten.batteryTemperature == cur.batteryTemperature |
| 2478 | && mHistoryLastWritten.batteryVoltage == cur.batteryVoltage) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2479 | // We can merge this new change in with the last one. Merging is |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2480 | // allowed as long as only the states have changed, and within those states |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2481 | // as long as no bit has changed both between now and the last entry, as |
| 2482 | // well as the last entry and the one before it (so we capture any toggles). |
| 2483 | if (DEBUG) Slog.i(TAG, "ADD: rewinding back to " + mHistoryBufferLastPos); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2484 | mHistoryBuffer.setDataSize(mHistoryBufferLastPos); |
| 2485 | mHistoryBuffer.setDataPosition(mHistoryBufferLastPos); |
| 2486 | mHistoryBufferLastPos = -1; |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2487 | elapsedRealtimeMs = mHistoryLastWritten.time - mHistoryBaseTime; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2488 | // If the last written history had a wakelock tag, we need to retain it. |
| 2489 | // Note that the condition above made sure that we aren't in a case where |
| 2490 | // both it and the current history item have a wakelock tag. |
| 2491 | if (mHistoryLastWritten.wakelockTag != null) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2492 | cur.wakelockTag = cur.localWakelockTag; |
| 2493 | cur.wakelockTag.setTo(mHistoryLastWritten.wakelockTag); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2494 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 2495 | // If the last written history had a wake reason tag, we need to retain it. |
| 2496 | // Note that the condition above made sure that we aren't in a case where |
| 2497 | // both it and the current history item have a wakelock tag. |
| 2498 | if (mHistoryLastWritten.wakeReasonTag != null) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2499 | cur.wakeReasonTag = cur.localWakeReasonTag; |
| 2500 | cur.wakeReasonTag.setTo(mHistoryLastWritten.wakeReasonTag); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 2501 | } |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2502 | // If the last written history had an event, we need to retain it. |
| 2503 | // Note that the condition above made sure that we aren't in a case where |
| 2504 | // both it and the current history item have an event. |
| 2505 | if (mHistoryLastWritten.eventCode != HistoryItem.EVENT_NONE) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2506 | cur.eventCode = mHistoryLastWritten.eventCode; |
| 2507 | cur.eventTag = cur.localEventTag; |
| 2508 | cur.eventTag.setTo(mHistoryLastWritten.eventTag); |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2509 | } |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 2510 | mHistoryLastWritten.setTo(mHistoryLastLastWritten); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2511 | } |
| 2512 | |
| 2513 | final int dataSize = mHistoryBuffer.dataSize(); |
| 2514 | if (dataSize >= MAX_HISTORY_BUFFER) { |
| 2515 | if (!mHistoryOverflow) { |
| 2516 | mHistoryOverflow = true; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2517 | addHistoryBufferLocked(elapsedRealtimeMs, uptimeMs, HistoryItem.CMD_UPDATE, cur); |
| 2518 | addHistoryBufferLocked(elapsedRealtimeMs, uptimeMs, HistoryItem.CMD_OVERFLOW, cur); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2519 | return; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2520 | } |
| 2521 | |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 2522 | // After overflow, we allow various bit-wise states to settle to 0. |
| 2523 | boolean writeAnyway = false; |
| 2524 | final int curStates = cur.states & HistoryItem.SETTLE_TO_ZERO_STATES |
| 2525 | & mActiveHistoryStates; |
| 2526 | if (mHistoryLastWritten.states != curStates) { |
| 2527 | // mActiveHistoryStates keeps track of which bits in .states are now being |
| 2528 | // forced to 0. |
| 2529 | int old = mActiveHistoryStates; |
| 2530 | mActiveHistoryStates &= curStates | ~HistoryItem.SETTLE_TO_ZERO_STATES; |
| 2531 | writeAnyway |= old != mActiveHistoryStates; |
| 2532 | } |
| 2533 | final int curStates2 = cur.states2 & HistoryItem.SETTLE_TO_ZERO_STATES2 |
| 2534 | & mActiveHistoryStates2; |
| 2535 | if (mHistoryLastWritten.states2 != curStates2) { |
| 2536 | // mActiveHistoryStates2 keeps track of which bits in .states2 are now being |
| 2537 | // forced to 0. |
| 2538 | int old = mActiveHistoryStates2; |
| 2539 | mActiveHistoryStates2 &= curStates2 | ~HistoryItem.SETTLE_TO_ZERO_STATES2; |
| 2540 | writeAnyway |= old != mActiveHistoryStates2; |
| 2541 | } |
| 2542 | |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2543 | // Once we've reached the maximum number of items, we only |
| 2544 | // record changes to the battery level and the most interesting states. |
| 2545 | // Once we've reached the maximum maximum number of items, we only |
| 2546 | // record changes to the battery level. |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 2547 | if (!writeAnyway && mHistoryLastWritten.batteryLevel == cur.batteryLevel && |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2548 | (dataSize >= MAX_MAX_HISTORY_BUFFER |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2549 | || ((mHistoryLastWritten.states^cur.states) |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 2550 | & HistoryItem.MOST_INTERESTING_STATES) == 0 |
| 2551 | || ((mHistoryLastWritten.states2^cur.states2) |
| 2552 | & HistoryItem.MOST_INTERESTING_STATES2) == 0)) { |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2553 | return; |
| 2554 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2555 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2556 | addHistoryBufferLocked(elapsedRealtimeMs, uptimeMs, HistoryItem.CMD_UPDATE, cur); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2557 | return; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2558 | } |
| 2559 | |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 2560 | if (dataSize == 0) { |
| 2561 | // The history is currently empty; we need it to start with a time stamp. |
| 2562 | cur.currentTime = System.currentTimeMillis(); |
| 2563 | addHistoryBufferLocked(elapsedRealtimeMs, uptimeMs, HistoryItem.CMD_RESET, cur); |
| 2564 | } |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2565 | addHistoryBufferLocked(elapsedRealtimeMs, uptimeMs, HistoryItem.CMD_UPDATE, cur); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2566 | } |
| 2567 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2568 | private void addHistoryBufferLocked(long elapsedRealtimeMs, long uptimeMs, byte cmd, |
| 2569 | HistoryItem cur) { |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2570 | if (mIteratingHistory) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2571 | throw new IllegalStateException("Can't do this while iterating history!"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2572 | } |
| 2573 | mHistoryBufferLastPos = mHistoryBuffer.dataPosition(); |
| 2574 | mHistoryLastLastWritten.setTo(mHistoryLastWritten); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2575 | mHistoryLastWritten.setTo(mHistoryBaseTime + elapsedRealtimeMs, cmd, cur); |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 2576 | mHistoryLastWritten.states &= mActiveHistoryStates; |
| 2577 | mHistoryLastWritten.states2 &= mActiveHistoryStates2; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2578 | writeHistoryDelta(mHistoryBuffer, mHistoryLastWritten, mHistoryLastLastWritten); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2579 | mLastHistoryElapsedRealtime = elapsedRealtimeMs; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2580 | cur.wakelockTag = null; |
| 2581 | cur.wakeReasonTag = null; |
| 2582 | cur.eventCode = HistoryItem.EVENT_NONE; |
| 2583 | cur.eventTag = null; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2584 | if (DEBUG_HISTORY) Slog.i(TAG, "Writing history buffer: was " + mHistoryBufferLastPos |
| 2585 | + " now " + mHistoryBuffer.dataPosition() |
| 2586 | + " size is now " + mHistoryBuffer.dataSize()); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2587 | } |
| 2588 | |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 2589 | int mChangedStates = 0; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2590 | int mChangedStates2 = 0; |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 2591 | |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2592 | void addHistoryRecordLocked(long elapsedRealtimeMs, long uptimeMs) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2593 | if (mTrackRunningHistoryElapsedRealtime != 0) { |
| 2594 | final long diffElapsed = elapsedRealtimeMs - mTrackRunningHistoryElapsedRealtime; |
| 2595 | final long diffUptime = uptimeMs - mTrackRunningHistoryUptime; |
| 2596 | if (diffUptime < (diffElapsed-20)) { |
| 2597 | final long wakeElapsedTime = elapsedRealtimeMs - (diffElapsed - diffUptime); |
| 2598 | mHistoryAddTmp.setTo(mHistoryLastWritten); |
| 2599 | mHistoryAddTmp.wakelockTag = null; |
| 2600 | mHistoryAddTmp.wakeReasonTag = null; |
| 2601 | mHistoryAddTmp.eventCode = HistoryItem.EVENT_NONE; |
| 2602 | mHistoryAddTmp.states &= ~HistoryItem.STATE_CPU_RUNNING_FLAG; |
| 2603 | addHistoryRecordInnerLocked(wakeElapsedTime, uptimeMs, mHistoryAddTmp); |
| 2604 | } |
| 2605 | } |
| 2606 | mHistoryCur.states |= HistoryItem.STATE_CPU_RUNNING_FLAG; |
| 2607 | mTrackRunningHistoryElapsedRealtime = elapsedRealtimeMs; |
| 2608 | mTrackRunningHistoryUptime = uptimeMs; |
| 2609 | addHistoryRecordInnerLocked(elapsedRealtimeMs, uptimeMs, mHistoryCur); |
| 2610 | } |
| 2611 | |
| 2612 | void addHistoryRecordInnerLocked(long elapsedRealtimeMs, long uptimeMs, HistoryItem cur) { |
| 2613 | addHistoryBufferLocked(elapsedRealtimeMs, uptimeMs, cur); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2614 | |
Dianne Hackborn | e8c88e6 | 2011-08-17 19:09:09 -0700 | [diff] [blame] | 2615 | if (!USE_OLD_HISTORY) { |
| 2616 | return; |
| 2617 | } |
| 2618 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2619 | if (!mHaveBatteryLevel || !mRecordingHistory) { |
| 2620 | return; |
| 2621 | } |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2622 | |
| 2623 | // If the current time is basically the same as the last time, |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 2624 | // and no states have since the last recorded entry changed and |
| 2625 | // are now resetting back to their original value, then just collapse |
| 2626 | // into one record. |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2627 | if (mHistoryEnd != null && mHistoryEnd.cmd == HistoryItem.CMD_UPDATE |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2628 | && (mHistoryBaseTime+elapsedRealtimeMs) < (mHistoryEnd.time+1000) |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 2629 | && ((mHistoryEnd.states^cur.states)&mChangedStates&mActiveHistoryStates) == 0 |
| 2630 | && ((mHistoryEnd.states2^cur.states2)&mChangedStates2&mActiveHistoryStates2) == 0) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2631 | // If the current is the same as the one before, then we no |
| 2632 | // longer need the entry. |
| 2633 | if (mHistoryLastEnd != null && mHistoryLastEnd.cmd == HistoryItem.CMD_UPDATE |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2634 | && (mHistoryBaseTime+elapsedRealtimeMs) < (mHistoryEnd.time+500) |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2635 | && mHistoryLastEnd.sameNonEvent(cur)) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2636 | mHistoryLastEnd.next = null; |
| 2637 | mHistoryEnd.next = mHistoryCache; |
| 2638 | mHistoryCache = mHistoryEnd; |
| 2639 | mHistoryEnd = mHistoryLastEnd; |
| 2640 | mHistoryLastEnd = null; |
| 2641 | } else { |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 2642 | mChangedStates |= mHistoryEnd.states^(cur.states&mActiveHistoryStates); |
| 2643 | mChangedStates2 |= mHistoryEnd.states^(cur.states2&mActiveHistoryStates2); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2644 | mHistoryEnd.setTo(mHistoryEnd.time, HistoryItem.CMD_UPDATE, cur); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2645 | } |
| 2646 | return; |
| 2647 | } |
| 2648 | |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 2649 | mChangedStates = 0; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2650 | mChangedStates2 = 0; |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 2651 | |
| 2652 | if (mNumHistoryItems == MAX_HISTORY_ITEMS |
| 2653 | || mNumHistoryItems == MAX_MAX_HISTORY_ITEMS) { |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2654 | addHistoryRecordLocked(elapsedRealtimeMs, HistoryItem.CMD_OVERFLOW); |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 2655 | } |
| 2656 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2657 | if (mNumHistoryItems >= MAX_HISTORY_ITEMS) { |
| 2658 | // Once we've reached the maximum number of items, we only |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 2659 | // record changes to the battery level and the most interesting states. |
| 2660 | // Once we've reached the maximum maximum number of items, we only |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2661 | // record changes to the battery level. |
| 2662 | if (mHistoryEnd != null && mHistoryEnd.batteryLevel |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2663 | == cur.batteryLevel && |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 2664 | (mNumHistoryItems >= MAX_MAX_HISTORY_ITEMS |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 2665 | || ((mHistoryEnd.states^(cur.states&mActiveHistoryStates)) |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 2666 | & HistoryItem.MOST_INTERESTING_STATES) == 0)) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2667 | return; |
| 2668 | } |
| 2669 | } |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2670 | |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2671 | addHistoryRecordLocked(elapsedRealtimeMs, HistoryItem.CMD_UPDATE); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2672 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2673 | |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 2674 | public void addHistoryEventLocked(long elapsedRealtimeMs, long uptimeMs, int code, |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2675 | String name, int uid) { |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2676 | mHistoryCur.eventCode = code; |
| 2677 | mHistoryCur.eventTag = mHistoryCur.localEventTag; |
| 2678 | mHistoryCur.eventTag.string = name; |
| 2679 | mHistoryCur.eventTag.uid = uid; |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 2680 | addHistoryRecordLocked(elapsedRealtimeMs, uptimeMs); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 2681 | } |
| 2682 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2683 | void addHistoryRecordLocked(long elapsedRealtimeMs, long uptimeMs, byte cmd, HistoryItem cur) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2684 | HistoryItem rec = mHistoryCache; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 2685 | if (rec != null) { |
| 2686 | mHistoryCache = rec.next; |
| 2687 | } else { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2688 | rec = new HistoryItem(); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 2689 | } |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2690 | rec.setTo(mHistoryBaseTime + elapsedRealtimeMs, cmd, cur); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2691 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2692 | addHistoryRecordLocked(rec); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 2693 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2694 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2695 | void addHistoryRecordLocked(HistoryItem rec) { |
| 2696 | mNumHistoryItems++; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 2697 | rec.next = null; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2698 | mHistoryLastEnd = mHistoryEnd; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 2699 | if (mHistoryEnd != null) { |
| 2700 | mHistoryEnd.next = rec; |
| 2701 | mHistoryEnd = rec; |
| 2702 | } else { |
| 2703 | mHistory = mHistoryEnd = rec; |
| 2704 | } |
| 2705 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2706 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2707 | void clearHistoryLocked() { |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2708 | if (DEBUG_HISTORY) Slog.i(TAG, "********** CLEARING HISTORY!"); |
Dianne Hackborn | e8c88e6 | 2011-08-17 19:09:09 -0700 | [diff] [blame] | 2709 | if (USE_OLD_HISTORY) { |
| 2710 | if (mHistory != null) { |
| 2711 | mHistoryEnd.next = mHistoryCache; |
| 2712 | mHistoryCache = mHistory; |
| 2713 | mHistory = mHistoryLastEnd = mHistoryEnd = null; |
| 2714 | } |
| 2715 | mNumHistoryItems = 0; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 2716 | } |
Dianne Hackborn | e8c88e6 | 2011-08-17 19:09:09 -0700 | [diff] [blame] | 2717 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2718 | mHistoryBaseTime = 0; |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2719 | mLastHistoryElapsedRealtime = 0; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2720 | mTrackRunningHistoryElapsedRealtime = 0; |
| 2721 | mTrackRunningHistoryUptime = 0; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2722 | |
| 2723 | mHistoryBuffer.setDataSize(0); |
| 2724 | mHistoryBuffer.setDataPosition(0); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2725 | mHistoryBuffer.setDataCapacity(MAX_HISTORY_BUFFER / 2); |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2726 | mHistoryLastLastWritten.clear(); |
| 2727 | mHistoryLastWritten.clear(); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2728 | mHistoryTagPool.clear(); |
| 2729 | mNextHistoryTagIdx = 0; |
| 2730 | mNumHistoryTagChars = 0; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2731 | mHistoryBufferLastPos = -1; |
| 2732 | mHistoryOverflow = false; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 2733 | mActiveHistoryStates = 0xffffffff; |
| 2734 | mActiveHistoryStates2 = 0xffffffff; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 2735 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2736 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2737 | public void updateTimeBasesLocked(boolean unplugged, boolean screenOff, long uptime, |
| 2738 | long realtime) { |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 2739 | mOnBatteryTimeBase.setRunning(unplugged, uptime, realtime); |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 2740 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2741 | boolean unpluggedScreenOff = unplugged && screenOff; |
| 2742 | if (unpluggedScreenOff != mOnBatteryScreenOffTimeBase.isRunning()) { |
| 2743 | updateKernelWakelocksLocked(); |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 2744 | if (DEBUG_ENERGY_CPU) { |
| 2745 | Slog.d(TAG, "Updating cpu time because screen is now " + |
| 2746 | (unpluggedScreenOff ? "off" : "on")); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2747 | } |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 2748 | updateCpuTimeLocked(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2749 | mOnBatteryScreenOffTimeBase.setRunning(unpluggedScreenOff, uptime, realtime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2750 | } |
| 2751 | } |
Amith Yamasani | 3718aaa | 2009-06-09 06:32:35 -0700 | [diff] [blame] | 2752 | |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 2753 | public void addIsolatedUidLocked(int isolatedUid, int appUid) { |
| 2754 | mIsolatedUids.put(isolatedUid, appUid); |
| 2755 | } |
| 2756 | |
Adam Lesinski | 61db88f | 2015-07-01 15:05:07 -0700 | [diff] [blame] | 2757 | /** |
| 2758 | * Schedules a read of the latest cpu times before removing the isolated UID. |
| 2759 | * @see #removeIsolatedUidLocked(int) |
| 2760 | */ |
| 2761 | public void scheduleRemoveIsolatedUidLocked(int isolatedUid, int appUid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 2762 | int curUid = mIsolatedUids.get(isolatedUid, -1); |
| 2763 | if (curUid == appUid) { |
Adam Lesinski | 61db88f | 2015-07-01 15:05:07 -0700 | [diff] [blame] | 2764 | if (mExternalSync != null) { |
| 2765 | mExternalSync.scheduleCpuSyncDueToRemovedUid(isolatedUid); |
| 2766 | } |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 2767 | } |
| 2768 | } |
| 2769 | |
Adam Lesinski | 61db88f | 2015-07-01 15:05:07 -0700 | [diff] [blame] | 2770 | /** |
| 2771 | * This should only be called after the cpu times have been read. |
| 2772 | * @see #scheduleRemoveIsolatedUidLocked(int, int) |
| 2773 | */ |
| 2774 | public void removeIsolatedUidLocked(int isolatedUid) { |
| 2775 | mIsolatedUids.delete(isolatedUid); |
| 2776 | mKernelUidCpuTimeReader.removeUid(isolatedUid); |
| 2777 | } |
| 2778 | |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 2779 | public int mapUid(int uid) { |
| 2780 | int isolated = mIsolatedUids.get(uid, -1); |
| 2781 | return isolated > 0 ? isolated : uid; |
| 2782 | } |
| 2783 | |
| 2784 | public void noteEventLocked(int code, String name, int uid) { |
| 2785 | uid = mapUid(uid); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 2786 | if (!mActiveEvents.updateState(code, name, uid, 0)) { |
| 2787 | return; |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 2788 | } |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 2789 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 2790 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2791 | addHistoryEventLocked(elapsedRealtime, uptime, code, name, uid); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 2792 | } |
| 2793 | |
Dianne Hackborn | d48954f | 2015-07-22 17:20:33 -0700 | [diff] [blame] | 2794 | boolean ensureStartClockTime(final long currentTime) { |
| 2795 | final long ABOUT_ONE_YEAR = 365*24*60*60*1000L; |
| 2796 | if (currentTime > ABOUT_ONE_YEAR && mStartClockTime < (currentTime-ABOUT_ONE_YEAR)) { |
| 2797 | // If the start clock time has changed by more than a year, then presumably |
| 2798 | // the previous time was completely bogus. So we are going to figure out a |
| 2799 | // new time based on how much time has elapsed since we started counting. |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 2800 | mStartClockTime = currentTime - (mClocks.elapsedRealtime()-(mRealtimeStart/1000)); |
Dianne Hackborn | d48954f | 2015-07-22 17:20:33 -0700 | [diff] [blame] | 2801 | return true; |
| 2802 | } |
| 2803 | return false; |
| 2804 | } |
| 2805 | |
Dianne Hackborn | 7d9eefd | 2014-08-27 18:30:31 -0700 | [diff] [blame] | 2806 | public void noteCurrentTimeChangedLocked() { |
| 2807 | final long currentTime = System.currentTimeMillis(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 2808 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 2809 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 7d9eefd | 2014-08-27 18:30:31 -0700 | [diff] [blame] | 2810 | recordCurrentTimeChangeLocked(currentTime, elapsedRealtime, uptime); |
Dianne Hackborn | d48954f | 2015-07-22 17:20:33 -0700 | [diff] [blame] | 2811 | ensureStartClockTime(currentTime); |
Dianne Hackborn | 7d9eefd | 2014-08-27 18:30:31 -0700 | [diff] [blame] | 2812 | } |
| 2813 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 2814 | public void noteProcessStartLocked(String name, int uid) { |
| 2815 | uid = mapUid(uid); |
| 2816 | if (isOnBattery()) { |
| 2817 | Uid u = getUidStatsLocked(uid); |
| 2818 | u.getProcessStatsLocked(name).incStartsLocked(); |
| 2819 | } |
| 2820 | if (!mActiveEvents.updateState(HistoryItem.EVENT_PROC_START, name, uid, 0)) { |
| 2821 | return; |
| 2822 | } |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 2823 | if (!mRecordAllHistory) { |
| 2824 | return; |
| 2825 | } |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 2826 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 2827 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 2828 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_PROC_START, name, uid); |
| 2829 | } |
| 2830 | |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 2831 | public void noteProcessCrashLocked(String name, int uid) { |
| 2832 | uid = mapUid(uid); |
| 2833 | if (isOnBattery()) { |
| 2834 | Uid u = getUidStatsLocked(uid); |
| 2835 | u.getProcessStatsLocked(name).incNumCrashesLocked(); |
| 2836 | } |
| 2837 | } |
| 2838 | |
| 2839 | public void noteProcessAnrLocked(String name, int uid) { |
| 2840 | uid = mapUid(uid); |
| 2841 | if (isOnBattery()) { |
| 2842 | Uid u = getUidStatsLocked(uid); |
| 2843 | u.getProcessStatsLocked(name).incNumAnrsLocked(); |
| 2844 | } |
| 2845 | } |
| 2846 | |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 2847 | public void noteUidProcessStateLocked(int uid, int state) { |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 2848 | uid = mapUid(uid); |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 2849 | getUidStatsLocked(uid).updateUidProcessStateLocked(state); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 2850 | } |
| 2851 | |
| 2852 | public void noteProcessFinishLocked(String name, int uid) { |
| 2853 | uid = mapUid(uid); |
| 2854 | if (!mActiveEvents.updateState(HistoryItem.EVENT_PROC_FINISH, name, uid, 0)) { |
| 2855 | return; |
| 2856 | } |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 2857 | if (!mRecordAllHistory) { |
| 2858 | return; |
| 2859 | } |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 2860 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 2861 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 2862 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_PROC_FINISH, name, uid); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 2863 | } |
| 2864 | |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 2865 | public void noteSyncStartLocked(String name, int uid) { |
| 2866 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 2867 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 2868 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 2869 | getUidStatsLocked(uid).noteStartSyncLocked(name, elapsedRealtime); |
| 2870 | if (!mActiveEvents.updateState(HistoryItem.EVENT_SYNC_START, name, uid, 0)) { |
| 2871 | return; |
| 2872 | } |
| 2873 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_SYNC_START, name, uid); |
| 2874 | } |
| 2875 | |
| 2876 | public void noteSyncFinishLocked(String name, int uid) { |
| 2877 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 2878 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 2879 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 2880 | getUidStatsLocked(uid).noteStopSyncLocked(name, elapsedRealtime); |
| 2881 | if (!mActiveEvents.updateState(HistoryItem.EVENT_SYNC_FINISH, name, uid, 0)) { |
| 2882 | return; |
| 2883 | } |
| 2884 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_SYNC_FINISH, name, uid); |
| 2885 | } |
| 2886 | |
| 2887 | public void noteJobStartLocked(String name, int uid) { |
| 2888 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 2889 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 2890 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 2891 | getUidStatsLocked(uid).noteStartJobLocked(name, elapsedRealtime); |
| 2892 | if (!mActiveEvents.updateState(HistoryItem.EVENT_JOB_START, name, uid, 0)) { |
| 2893 | return; |
| 2894 | } |
| 2895 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_JOB_START, name, uid); |
| 2896 | } |
| 2897 | |
| 2898 | public void noteJobFinishLocked(String name, int uid) { |
| 2899 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 2900 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 2901 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 2902 | getUidStatsLocked(uid).noteStopJobLocked(name, elapsedRealtime); |
| 2903 | if (!mActiveEvents.updateState(HistoryItem.EVENT_JOB_FINISH, name, uid, 0)) { |
| 2904 | return; |
| 2905 | } |
| 2906 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_JOB_FINISH, name, uid); |
| 2907 | } |
| 2908 | |
Dianne Hackborn | 1e38382 | 2015-04-10 14:02:33 -0700 | [diff] [blame] | 2909 | public void noteAlarmStartLocked(String name, int uid) { |
| 2910 | if (!mRecordAllHistory) { |
| 2911 | return; |
| 2912 | } |
| 2913 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 2914 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 2915 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 1e38382 | 2015-04-10 14:02:33 -0700 | [diff] [blame] | 2916 | if (!mActiveEvents.updateState(HistoryItem.EVENT_ALARM_START, name, uid, 0)) { |
| 2917 | return; |
| 2918 | } |
| 2919 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_ALARM_START, name, uid); |
| 2920 | } |
| 2921 | |
| 2922 | public void noteAlarmFinishLocked(String name, int uid) { |
| 2923 | if (!mRecordAllHistory) { |
| 2924 | return; |
| 2925 | } |
| 2926 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 2927 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 2928 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 1e38382 | 2015-04-10 14:02:33 -0700 | [diff] [blame] | 2929 | if (!mActiveEvents.updateState(HistoryItem.EVENT_ALARM_FINISH, name, uid, 0)) { |
| 2930 | return; |
| 2931 | } |
| 2932 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_ALARM_FINISH, name, uid); |
| 2933 | } |
| 2934 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2935 | private void requestWakelockCpuUpdate() { |
| 2936 | if (!mHandler.hasMessages(MSG_UPDATE_WAKELOCKS)) { |
| 2937 | Message m = mHandler.obtainMessage(MSG_UPDATE_WAKELOCKS); |
| 2938 | mHandler.sendMessageDelayed(m, DELAY_UPDATE_WAKELOCKS); |
| 2939 | } |
| 2940 | } |
| 2941 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 2942 | private void requestImmediateCpuUpdate() { |
| 2943 | mHandler.removeMessages(MSG_UPDATE_WAKELOCKS); |
| 2944 | mHandler.sendEmptyMessage(MSG_UPDATE_WAKELOCKS); |
| 2945 | } |
| 2946 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 2947 | public void setRecordAllHistoryLocked(boolean enabled) { |
| 2948 | mRecordAllHistory = enabled; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 2949 | if (!enabled) { |
| 2950 | // Clear out any existing state. |
| 2951 | mActiveEvents.removeEvents(HistoryItem.EVENT_WAKE_LOCK); |
Dianne Hackborn | 1e38382 | 2015-04-10 14:02:33 -0700 | [diff] [blame] | 2952 | mActiveEvents.removeEvents(HistoryItem.EVENT_ALARM); |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 2953 | // Record the currently running processes as stopping, now that we are no |
| 2954 | // longer tracking them. |
| 2955 | HashMap<String, SparseIntArray> active = mActiveEvents.getStateForEvent( |
| 2956 | HistoryItem.EVENT_PROC); |
| 2957 | if (active != null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 2958 | long mSecRealtime = mClocks.elapsedRealtime(); |
| 2959 | final long mSecUptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 2960 | for (HashMap.Entry<String, SparseIntArray> ent : active.entrySet()) { |
| 2961 | SparseIntArray uids = ent.getValue(); |
| 2962 | for (int j=0; j<uids.size(); j++) { |
| 2963 | addHistoryEventLocked(mSecRealtime, mSecUptime, |
| 2964 | HistoryItem.EVENT_PROC_FINISH, ent.getKey(), uids.keyAt(j)); |
| 2965 | } |
| 2966 | } |
| 2967 | } |
| 2968 | } else { |
| 2969 | // Record the currently running processes as starting, now that we are tracking them. |
| 2970 | HashMap<String, SparseIntArray> active = mActiveEvents.getStateForEvent( |
| 2971 | HistoryItem.EVENT_PROC); |
| 2972 | if (active != null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 2973 | long mSecRealtime = mClocks.elapsedRealtime(); |
| 2974 | final long mSecUptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 2975 | for (HashMap.Entry<String, SparseIntArray> ent : active.entrySet()) { |
| 2976 | SparseIntArray uids = ent.getValue(); |
| 2977 | for (int j=0; j<uids.size(); j++) { |
| 2978 | addHistoryEventLocked(mSecRealtime, mSecUptime, |
| 2979 | HistoryItem.EVENT_PROC_START, ent.getKey(), uids.keyAt(j)); |
| 2980 | } |
| 2981 | } |
| 2982 | } |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 2983 | } |
| 2984 | } |
| 2985 | |
Dianne Hackborn | 9a75543 | 2014-05-15 17:05:22 -0700 | [diff] [blame] | 2986 | public void setNoAutoReset(boolean enabled) { |
| 2987 | mNoAutoReset = enabled; |
| 2988 | } |
| 2989 | |
| 2990 | private String mInitialAcquireWakeName; |
| 2991 | private int mInitialAcquireWakeUid = -1; |
| 2992 | |
Dianne Hackborn | a1f1a3c | 2014-02-24 18:12:28 -0800 | [diff] [blame] | 2993 | public void noteStartWakeLocked(int uid, int pid, String name, String historyName, int type, |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2994 | boolean unimportantForLogging, long elapsedRealtime, long uptime) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 2995 | uid = mapUid(uid); |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 2996 | if (type == WAKE_TYPE_PARTIAL) { |
| 2997 | // Only care about partial wake locks, since full wake locks |
| 2998 | // will be canceled when the user puts the screen to sleep. |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2999 | aggregateLastWakeupUptimeLocked(uptime); |
Dianne Hackborn | fc06413 | 2014-06-02 12:42:12 -0700 | [diff] [blame] | 3000 | if (historyName == null) { |
| 3001 | historyName = name; |
| 3002 | } |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 3003 | if (mRecordAllHistory) { |
Dianne Hackborn | fc06413 | 2014-06-02 12:42:12 -0700 | [diff] [blame] | 3004 | if (mActiveEvents.updateState(HistoryItem.EVENT_WAKE_LOCK_START, historyName, |
| 3005 | uid, 0)) { |
Dianne Hackborn | 536456f | 2014-05-23 16:51:05 -0700 | [diff] [blame] | 3006 | addHistoryEventLocked(elapsedRealtime, uptime, |
Dianne Hackborn | fc06413 | 2014-06-02 12:42:12 -0700 | [diff] [blame] | 3007 | HistoryItem.EVENT_WAKE_LOCK_START, historyName, uid); |
Dianne Hackborn | 536456f | 2014-05-23 16:51:05 -0700 | [diff] [blame] | 3008 | } |
| 3009 | } |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 3010 | if (mWakeLockNesting == 0) { |
| 3011 | mHistoryCur.states |= HistoryItem.STATE_WAKE_LOCK_FLAG; |
| 3012 | if (DEBUG_HISTORY) Slog.v(TAG, "Start wake lock to: " |
| 3013 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3014 | mHistoryCur.wakelockTag = mHistoryCur.localWakelockTag; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3015 | mHistoryCur.wakelockTag.string = mInitialAcquireWakeName = historyName; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 3016 | mHistoryCur.wakelockTag.uid = mInitialAcquireWakeUid = uid; |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 3017 | mWakeLockImportant = !unimportantForLogging; |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3018 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | fc06413 | 2014-06-02 12:42:12 -0700 | [diff] [blame] | 3019 | } else if (!mWakeLockImportant && !unimportantForLogging |
| 3020 | && mHistoryLastWritten.cmd == HistoryItem.CMD_UPDATE) { |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 3021 | if (mHistoryLastWritten.wakelockTag != null) { |
| 3022 | // We'll try to update the last tag. |
| 3023 | mHistoryLastWritten.wakelockTag = null; |
| 3024 | mHistoryCur.wakelockTag = mHistoryCur.localWakelockTag; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3025 | mHistoryCur.wakelockTag.string = mInitialAcquireWakeName = historyName; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 3026 | mHistoryCur.wakelockTag.uid = mInitialAcquireWakeUid = uid; |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3027 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 3028 | } |
| 3029 | mWakeLockImportant = true; |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 3030 | } |
| 3031 | mWakeLockNesting++; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3032 | } |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3033 | if (uid >= 0) { |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 3034 | if (mOnBatteryScreenOffTimeBase.isRunning()) { |
| 3035 | // We only update the cpu time when a wake lock is acquired if the screen is off. |
| 3036 | // If the screen is on, we don't distribute the power amongst partial wakelocks. |
| 3037 | if (DEBUG_ENERGY_CPU) { |
| 3038 | Slog.d(TAG, "Updating cpu time because of +wake_lock"); |
| 3039 | } |
| 3040 | requestWakelockCpuUpdate(); |
| 3041 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3042 | getUidStatsLocked(uid).noteStartWakeLocked(pid, name, type, elapsedRealtime); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3043 | } |
| 3044 | } |
| 3045 | |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3046 | public void noteStopWakeLocked(int uid, int pid, String name, String historyName, int type, |
| 3047 | long elapsedRealtime, long uptime) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3048 | uid = mapUid(uid); |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 3049 | if (type == WAKE_TYPE_PARTIAL) { |
| 3050 | mWakeLockNesting--; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 3051 | if (mRecordAllHistory) { |
Dianne Hackborn | fc06413 | 2014-06-02 12:42:12 -0700 | [diff] [blame] | 3052 | if (historyName == null) { |
| 3053 | historyName = name; |
| 3054 | } |
| 3055 | if (mActiveEvents.updateState(HistoryItem.EVENT_WAKE_LOCK_FINISH, historyName, |
| 3056 | uid, 0)) { |
Dianne Hackborn | 536456f | 2014-05-23 16:51:05 -0700 | [diff] [blame] | 3057 | addHistoryEventLocked(elapsedRealtime, uptime, |
Dianne Hackborn | fc06413 | 2014-06-02 12:42:12 -0700 | [diff] [blame] | 3058 | HistoryItem.EVENT_WAKE_LOCK_FINISH, historyName, uid); |
Dianne Hackborn | 536456f | 2014-05-23 16:51:05 -0700 | [diff] [blame] | 3059 | } |
| 3060 | } |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 3061 | if (mWakeLockNesting == 0) { |
| 3062 | mHistoryCur.states &= ~HistoryItem.STATE_WAKE_LOCK_FLAG; |
| 3063 | if (DEBUG_HISTORY) Slog.v(TAG, "Stop wake lock to: " |
| 3064 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 3065 | mInitialAcquireWakeName = null; |
| 3066 | mInitialAcquireWakeUid = -1; |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3067 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 3068 | } |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3069 | } |
| 3070 | if (uid >= 0) { |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 3071 | if (mOnBatteryScreenOffTimeBase.isRunning()) { |
| 3072 | if (DEBUG_ENERGY_CPU) { |
| 3073 | Slog.d(TAG, "Updating cpu time because of -wake_lock"); |
| 3074 | } |
| 3075 | requestWakelockCpuUpdate(); |
| 3076 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3077 | getUidStatsLocked(uid).noteStopWakeLocked(pid, name, type, elapsedRealtime); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3078 | } |
| 3079 | } |
| 3080 | |
Dianne Hackborn | a1f1a3c | 2014-02-24 18:12:28 -0800 | [diff] [blame] | 3081 | public void noteStartWakeFromSourceLocked(WorkSource ws, int pid, String name, |
| 3082 | String historyName, int type, boolean unimportantForLogging) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3083 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3084 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 3085 | final int N = ws.size(); |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 3086 | for (int i=0; i<N; i++) { |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 3087 | noteStartWakeLocked(ws.get(i), pid, name, historyName, type, unimportantForLogging, |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3088 | elapsedRealtime, uptime); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 3089 | } |
| 3090 | } |
| 3091 | |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3092 | public void noteChangeWakelockFromSourceLocked(WorkSource ws, int pid, String name, |
| 3093 | String historyName, int type, WorkSource newWs, int newPid, String newName, |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 3094 | String newHistoryName, int newType, boolean newUnimportantForLogging) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3095 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3096 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 3097 | // For correct semantics, we start the need worksources first, so that we won't |
| 3098 | // make inappropriate history items as if all wake locks went away and new ones |
| 3099 | // appeared. This is okay because tracking of wake locks allows nesting. |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3100 | final int NN = newWs.size(); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 3101 | for (int i=0; i<NN; i++) { |
| 3102 | noteStartWakeLocked(newWs.get(i), newPid, newName, newHistoryName, newType, |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3103 | newUnimportantForLogging, elapsedRealtime, uptime); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 3104 | } |
| 3105 | final int NO = ws.size(); |
| 3106 | for (int i=0; i<NO; i++) { |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3107 | noteStopWakeLocked(ws.get(i), pid, name, historyName, type, elapsedRealtime, uptime); |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 3108 | } |
| 3109 | } |
| 3110 | |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3111 | public void noteStopWakeFromSourceLocked(WorkSource ws, int pid, String name, |
| 3112 | String historyName, int type) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3113 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3114 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 3115 | final int N = ws.size(); |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 3116 | for (int i=0; i<N; i++) { |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3117 | noteStopWakeLocked(ws.get(i), pid, name, historyName, type, elapsedRealtime, uptime); |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 3118 | } |
| 3119 | } |
| 3120 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3121 | void aggregateLastWakeupUptimeLocked(long uptimeMs) { |
| 3122 | if (mLastWakeupReason != null) { |
| 3123 | long deltaUptime = uptimeMs - mLastWakeupUptimeMs; |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 3124 | SamplingTimer timer = getWakeupReasonTimerLocked(mLastWakeupReason); |
| 3125 | timer.addCurrentReportedCount(1); |
| 3126 | timer.addCurrentReportedTotalTime(deltaUptime * 1000); // time is in microseconds |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3127 | mLastWakeupReason = null; |
| 3128 | } |
| 3129 | } |
| 3130 | |
| 3131 | public void noteWakeupReasonLocked(String reason) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3132 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3133 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 3134 | if (DEBUG_HISTORY) Slog.v(TAG, "Wakeup reason \"" + reason +"\": " |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 3135 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3136 | aggregateLastWakeupUptimeLocked(uptime); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 3137 | mHistoryCur.wakeReasonTag = mHistoryCur.localWakeReasonTag; |
| 3138 | mHistoryCur.wakeReasonTag.string = reason; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3139 | mHistoryCur.wakeReasonTag.uid = 0; |
| 3140 | mLastWakeupReason = reason; |
| 3141 | mLastWakeupUptimeMs = uptime; |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3142 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 3143 | } |
| 3144 | |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 3145 | public boolean startAddingCpuLocked() { |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 3146 | mHandler.removeMessages(MSG_UPDATE_WAKELOCKS); |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 3147 | return mOnBatteryInternal; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 3148 | } |
| 3149 | |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 3150 | public void finishAddingCpuLocked(int totalUTime, int totalSTime, int statUserTime, |
| 3151 | int statSystemTime, int statIOWaitTime, int statIrqTime, |
| 3152 | int statSoftIrqTime, int statIdleTime) { |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 3153 | if (DEBUG) Slog.d(TAG, "Adding cpu: tuser=" + totalUTime + " tsys=" + totalSTime |
| 3154 | + " user=" + statUserTime + " sys=" + statSystemTime |
| 3155 | + " io=" + statIOWaitTime + " irq=" + statIrqTime |
| 3156 | + " sirq=" + statSoftIrqTime + " idle=" + statIdleTime); |
| 3157 | mCurStepCpuUserTime += totalUTime; |
| 3158 | mCurStepCpuSystemTime += totalSTime; |
| 3159 | mCurStepStatUserTime += statUserTime; |
| 3160 | mCurStepStatSystemTime += statSystemTime; |
| 3161 | mCurStepStatIOWaitTime += statIOWaitTime; |
| 3162 | mCurStepStatIrqTime += statIrqTime; |
| 3163 | mCurStepStatSoftIrqTime += statSoftIrqTime; |
| 3164 | mCurStepStatIdleTime += statIdleTime; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 3165 | } |
| 3166 | |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3167 | public void noteProcessDiedLocked(int uid, int pid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3168 | uid = mapUid(uid); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3169 | Uid u = mUidStats.get(uid); |
| 3170 | if (u != null) { |
| 3171 | u.mPids.remove(pid); |
| 3172 | } |
| 3173 | } |
| 3174 | |
| 3175 | public long getProcessWakeTime(int uid, int pid, long realtime) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3176 | uid = mapUid(uid); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3177 | Uid u = mUidStats.get(uid); |
| 3178 | if (u != null) { |
| 3179 | Uid.Pid p = u.mPids.get(pid); |
| 3180 | if (p != null) { |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 3181 | return p.mWakeSumMs + (p.mWakeNesting > 0 ? (realtime - p.mWakeStartMs) : 0); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3182 | } |
| 3183 | } |
| 3184 | return 0; |
| 3185 | } |
| 3186 | |
| 3187 | public void reportExcessiveWakeLocked(int uid, String proc, long overTime, long usedTime) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3188 | uid = mapUid(uid); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3189 | Uid u = mUidStats.get(uid); |
| 3190 | if (u != null) { |
| 3191 | u.reportExcessiveWakeLocked(proc, overTime, usedTime); |
| 3192 | } |
| 3193 | } |
| 3194 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 3195 | public void reportExcessiveCpuLocked(int uid, String proc, long overTime, long usedTime) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3196 | uid = mapUid(uid); |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 3197 | Uid u = mUidStats.get(uid); |
| 3198 | if (u != null) { |
| 3199 | u.reportExcessiveCpuLocked(proc, overTime, usedTime); |
| 3200 | } |
| 3201 | } |
| 3202 | |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3203 | int mSensorNesting; |
| 3204 | |
| 3205 | public void noteStartSensorLocked(int uid, int sensor) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3206 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3207 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3208 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3209 | if (mSensorNesting == 0) { |
| 3210 | mHistoryCur.states |= HistoryItem.STATE_SENSOR_ON_FLAG; |
| 3211 | if (DEBUG_HISTORY) Slog.v(TAG, "Start sensor to: " |
| 3212 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3213 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3214 | } |
| 3215 | mSensorNesting++; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3216 | getUidStatsLocked(uid).noteStartSensor(sensor, elapsedRealtime); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3217 | } |
| 3218 | |
| 3219 | public void noteStopSensorLocked(int uid, int sensor) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3220 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3221 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3222 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3223 | mSensorNesting--; |
| 3224 | if (mSensorNesting == 0) { |
| 3225 | mHistoryCur.states &= ~HistoryItem.STATE_SENSOR_ON_FLAG; |
| 3226 | if (DEBUG_HISTORY) Slog.v(TAG, "Stop sensor to: " |
| 3227 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3228 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3229 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3230 | getUidStatsLocked(uid).noteStopSensor(sensor, elapsedRealtime); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3231 | } |
| 3232 | |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3233 | int mGpsNesting; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3234 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3235 | public void noteStartGpsLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3236 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3237 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3238 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3239 | if (mGpsNesting == 0) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3240 | mHistoryCur.states |= HistoryItem.STATE_GPS_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3241 | if (DEBUG_HISTORY) Slog.v(TAG, "Start GPS to: " |
| 3242 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3243 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3244 | } |
| 3245 | mGpsNesting++; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3246 | getUidStatsLocked(uid).noteStartGps(elapsedRealtime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3247 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3248 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3249 | public void noteStopGpsLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3250 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3251 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3252 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3253 | mGpsNesting--; |
| 3254 | if (mGpsNesting == 0) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3255 | mHistoryCur.states &= ~HistoryItem.STATE_GPS_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3256 | if (DEBUG_HISTORY) Slog.v(TAG, "Stop GPS to: " |
| 3257 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3258 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3259 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3260 | getUidStatsLocked(uid).noteStopGps(elapsedRealtime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3261 | } |
Amith Yamasani | 3718aaa | 2009-06-09 06:32:35 -0700 | [diff] [blame] | 3262 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 3263 | public void noteScreenStateLocked(int state) { |
| 3264 | if (mScreenState != state) { |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 3265 | recordDailyStatsIfNeededLocked(true); |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 3266 | final int oldState = mScreenState; |
| 3267 | mScreenState = state; |
| 3268 | if (DEBUG) Slog.v(TAG, "Screen state: oldState=" + Display.stateToString(oldState) |
| 3269 | + ", newState=" + Display.stateToString(state)); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3270 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 3271 | if (state != Display.STATE_UNKNOWN) { |
| 3272 | int stepState = state-1; |
| 3273 | if (stepState < 4) { |
| 3274 | mModStepMode |= (mCurStepMode&STEP_LEVEL_MODE_SCREEN_STATE) ^ stepState; |
| 3275 | mCurStepMode = (mCurStepMode&~STEP_LEVEL_MODE_SCREEN_STATE) | stepState; |
| 3276 | } else { |
| 3277 | Slog.wtf(TAG, "Unexpected screen state: " + state); |
| 3278 | } |
| 3279 | } |
| 3280 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 3281 | if (state == Display.STATE_ON) { |
| 3282 | // Screen turning on. |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3283 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3284 | final long uptime = mClocks.uptimeMillis(); |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 3285 | mHistoryCur.states |= HistoryItem.STATE_SCREEN_ON_FLAG; |
| 3286 | if (DEBUG_HISTORY) Slog.v(TAG, "Screen on to: " |
| 3287 | + Integer.toHexString(mHistoryCur.states)); |
| 3288 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 3289 | mScreenOnTimer.startRunningLocked(elapsedRealtime); |
| 3290 | if (mScreenBrightnessBin >= 0) { |
| 3291 | mScreenBrightnessTimer[mScreenBrightnessBin].startRunningLocked(elapsedRealtime); |
| 3292 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3293 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 3294 | updateTimeBasesLocked(mOnBatteryTimeBase.isRunning(), false, |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3295 | mClocks.uptimeMillis() * 1000, elapsedRealtime * 1000); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 3296 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 3297 | // Fake a wake lock, so we consider the device waked as long |
| 3298 | // as the screen is on. |
| 3299 | noteStartWakeLocked(-1, -1, "screen", null, WAKE_TYPE_PARTIAL, false, |
| 3300 | elapsedRealtime, uptime); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3301 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 3302 | // Update discharge amounts. |
| 3303 | if (mOnBatteryInternal) { |
| 3304 | updateDischargeScreenLevelsLocked(false, true); |
| 3305 | } |
| 3306 | } else if (oldState == Display.STATE_ON) { |
| 3307 | // Screen turning off or dozing. |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3308 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3309 | final long uptime = mClocks.uptimeMillis(); |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 3310 | mHistoryCur.states &= ~HistoryItem.STATE_SCREEN_ON_FLAG; |
| 3311 | if (DEBUG_HISTORY) Slog.v(TAG, "Screen off to: " |
| 3312 | + Integer.toHexString(mHistoryCur.states)); |
| 3313 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 3314 | mScreenOnTimer.stopRunningLocked(elapsedRealtime); |
| 3315 | if (mScreenBrightnessBin >= 0) { |
| 3316 | mScreenBrightnessTimer[mScreenBrightnessBin].stopRunningLocked(elapsedRealtime); |
| 3317 | } |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3318 | |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3319 | noteStopWakeLocked(-1, -1, "screen", "screen", WAKE_TYPE_PARTIAL, |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 3320 | elapsedRealtime, uptime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3321 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 3322 | updateTimeBasesLocked(mOnBatteryTimeBase.isRunning(), true, |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3323 | mClocks.uptimeMillis() * 1000, elapsedRealtime * 1000); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3324 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 3325 | // Update discharge amounts. |
| 3326 | if (mOnBatteryInternal) { |
| 3327 | updateDischargeScreenLevelsLocked(true, false); |
| 3328 | } |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 3329 | } |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3330 | } |
| 3331 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3332 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3333 | public void noteScreenBrightnessLocked(int brightness) { |
| 3334 | // Bin the brightness. |
| 3335 | int bin = brightness / (256/NUM_SCREEN_BRIGHTNESS_BINS); |
| 3336 | if (bin < 0) bin = 0; |
| 3337 | else if (bin >= NUM_SCREEN_BRIGHTNESS_BINS) bin = NUM_SCREEN_BRIGHTNESS_BINS-1; |
| 3338 | if (mScreenBrightnessBin != bin) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3339 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3340 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3341 | mHistoryCur.states = (mHistoryCur.states&~HistoryItem.STATE_BRIGHTNESS_MASK) |
| 3342 | | (bin << HistoryItem.STATE_BRIGHTNESS_SHIFT); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3343 | if (DEBUG_HISTORY) Slog.v(TAG, "Screen brightness " + bin + " to: " |
| 3344 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3345 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 3346 | if (mScreenState == Display.STATE_ON) { |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3347 | if (mScreenBrightnessBin >= 0) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3348 | mScreenBrightnessTimer[mScreenBrightnessBin].stopRunningLocked(elapsedRealtime); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3349 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3350 | mScreenBrightnessTimer[bin].startRunningLocked(elapsedRealtime); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3351 | } |
| 3352 | mScreenBrightnessBin = bin; |
| 3353 | } |
| 3354 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3355 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3356 | public void noteUserActivityLocked(int uid, int event) { |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 3357 | if (mOnBatteryInternal) { |
| 3358 | uid = mapUid(uid); |
| 3359 | getUidStatsLocked(uid).noteUserActivityLocked(event); |
| 3360 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3361 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3362 | |
Dianne Hackborn | 280a64e | 2015-07-13 14:48:08 -0700 | [diff] [blame] | 3363 | public void noteWakeUpLocked(String reason, int reasonUid) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3364 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3365 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 280a64e | 2015-07-13 14:48:08 -0700 | [diff] [blame] | 3366 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_SCREEN_WAKE_UP, |
| 3367 | reason, reasonUid); |
| 3368 | } |
| 3369 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 3370 | public void noteInteractiveLocked(boolean interactive) { |
| 3371 | if (mInteractive != interactive) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3372 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 3373 | mInteractive = interactive; |
| 3374 | if (DEBUG) Slog.v(TAG, "Interactive: " + interactive); |
| 3375 | if (interactive) { |
| 3376 | mInteractiveTimer.startRunningLocked(elapsedRealtime); |
| 3377 | } else { |
| 3378 | mInteractiveTimer.stopRunningLocked(elapsedRealtime); |
| 3379 | } |
| 3380 | } |
| 3381 | } |
| 3382 | |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 3383 | public void noteConnectivityChangedLocked(int type, String extra) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3384 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3385 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 3386 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_CONNECTIVITY_CHANGED, |
| 3387 | extra, type); |
| 3388 | mNumConnectivityChange++; |
| 3389 | } |
| 3390 | |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 3391 | public void noteMobileRadioPowerState(int powerState, long timestampNs) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3392 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3393 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 3394 | if (mMobileRadioPowerState != powerState) { |
| 3395 | long realElapsedRealtimeMs; |
| 3396 | final boolean active = |
| 3397 | powerState == DataConnectionRealTimeInfo.DC_POWER_STATE_MEDIUM |
| 3398 | || powerState == DataConnectionRealTimeInfo.DC_POWER_STATE_HIGH; |
| 3399 | if (active) { |
Adam Lesinski | 9acfd81 | 2016-04-19 18:29:50 -0700 | [diff] [blame^] | 3400 | mMobileRadioActiveStartTime = realElapsedRealtimeMs = timestampNs / (1000 * 1000); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 3401 | mHistoryCur.states |= HistoryItem.STATE_MOBILE_RADIO_ACTIVE_FLAG; |
| 3402 | } else { |
| 3403 | realElapsedRealtimeMs = timestampNs / (1000*1000); |
Dianne Hackborn | f7097a5 | 2014-05-13 09:56:14 -0700 | [diff] [blame] | 3404 | long lastUpdateTimeMs = mMobileRadioActiveStartTime; |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 3405 | if (realElapsedRealtimeMs < lastUpdateTimeMs) { |
| 3406 | Slog.wtf(TAG, "Data connection inactive timestamp " + realElapsedRealtimeMs |
| 3407 | + " is before start time " + lastUpdateTimeMs); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3408 | realElapsedRealtimeMs = elapsedRealtime; |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 3409 | } else if (realElapsedRealtimeMs < elapsedRealtime) { |
| 3410 | mMobileRadioActiveAdjustedTime.addCountLocked(elapsedRealtime |
| 3411 | - realElapsedRealtimeMs); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3412 | } |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 3413 | mHistoryCur.states &= ~HistoryItem.STATE_MOBILE_RADIO_ACTIVE_FLAG; |
| 3414 | } |
| 3415 | if (DEBUG_HISTORY) Slog.v(TAG, "Mobile network active " + active + " to: " |
| 3416 | + Integer.toHexString(mHistoryCur.states)); |
| 3417 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 3418 | mMobileRadioPowerState = powerState; |
| 3419 | if (active) { |
| 3420 | mMobileRadioActiveTimer.startRunningLocked(elapsedRealtime); |
| 3421 | mMobileRadioActivePerAppTimer.startRunningLocked(elapsedRealtime); |
| 3422 | } else { |
| 3423 | mMobileRadioActiveTimer.stopRunningLocked(realElapsedRealtimeMs); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3424 | updateMobileRadioStateLocked(realElapsedRealtimeMs, null); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 3425 | mMobileRadioActivePerAppTimer.stopRunningLocked(realElapsedRealtimeMs); |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 3426 | } |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 3427 | } |
| 3428 | } |
| 3429 | |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3430 | public void notePowerSaveMode(boolean enabled) { |
| 3431 | if (mPowerSaveModeEnabled != enabled) { |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 3432 | int stepState = enabled ? STEP_LEVEL_MODE_POWER_SAVE : 0; |
| 3433 | mModStepMode |= (mCurStepMode&STEP_LEVEL_MODE_POWER_SAVE) ^ stepState; |
| 3434 | mCurStepMode = (mCurStepMode&~STEP_LEVEL_MODE_POWER_SAVE) | stepState; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3435 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3436 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3437 | mPowerSaveModeEnabled = enabled; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3438 | if (enabled) { |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3439 | mHistoryCur.states2 |= HistoryItem.STATE2_POWER_SAVE_FLAG; |
| 3440 | if (DEBUG_HISTORY) Slog.v(TAG, "Power save mode enabled to: " |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3441 | + Integer.toHexString(mHistoryCur.states2)); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3442 | mPowerSaveModeEnabledTimer.startRunningLocked(elapsedRealtime); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3443 | } else { |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3444 | mHistoryCur.states2 &= ~HistoryItem.STATE2_POWER_SAVE_FLAG; |
| 3445 | if (DEBUG_HISTORY) Slog.v(TAG, "Power save mode disabled to: " |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3446 | + Integer.toHexString(mHistoryCur.states2)); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3447 | mPowerSaveModeEnabledTimer.stopRunningLocked(elapsedRealtime); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3448 | } |
| 3449 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 3450 | } |
| 3451 | } |
| 3452 | |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3453 | public void noteDeviceIdleModeLocked(int mode, String activeReason, int activeUid) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3454 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3455 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 3456 | boolean nowIdling = mode == DEVICE_IDLE_MODE_DEEP; |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3457 | if (mDeviceIdling && !nowIdling && activeReason == null) { |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 3458 | // We don't go out of general idling mode until explicitly taken out of |
| 3459 | // device idle through going active or significant motion. |
| 3460 | nowIdling = true; |
| 3461 | } |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3462 | boolean nowLightIdling = mode == DEVICE_IDLE_MODE_LIGHT; |
| 3463 | if (mDeviceLightIdling && !nowLightIdling && !nowIdling && activeReason == null) { |
| 3464 | // We don't go out of general light idling mode until explicitly taken out of |
| 3465 | // device idle through going active or significant motion. |
| 3466 | nowLightIdling = true; |
| 3467 | } |
| 3468 | if (activeReason != null && (mDeviceIdling || mDeviceLightIdling)) { |
| 3469 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_ACTIVE, |
| 3470 | activeReason, activeUid); |
| 3471 | } |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 3472 | if (mDeviceIdling != nowIdling) { |
| 3473 | mDeviceIdling = nowIdling; |
| 3474 | int stepState = nowIdling ? STEP_LEVEL_MODE_DEVICE_IDLE : 0; |
| 3475 | mModStepMode |= (mCurStepMode&STEP_LEVEL_MODE_DEVICE_IDLE) ^ stepState; |
| 3476 | mCurStepMode = (mCurStepMode&~STEP_LEVEL_MODE_DEVICE_IDLE) | stepState; |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3477 | if (nowIdling) { |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 3478 | mDeviceIdlingTimer.startRunningLocked(elapsedRealtime); |
| 3479 | } else { |
| 3480 | mDeviceIdlingTimer.stopRunningLocked(elapsedRealtime); |
| 3481 | } |
| 3482 | } |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3483 | if (mDeviceLightIdling != nowLightIdling) { |
| 3484 | mDeviceLightIdling = nowLightIdling; |
| 3485 | if (nowLightIdling) { |
| 3486 | mDeviceLightIdlingTimer.startRunningLocked(elapsedRealtime); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3487 | } else { |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3488 | mDeviceLightIdlingTimer.stopRunningLocked(elapsedRealtime); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3489 | } |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3490 | } |
| 3491 | if (mDeviceIdleMode != mode) { |
| 3492 | mHistoryCur.states2 = (mHistoryCur.states2 & ~HistoryItem.STATE2_DEVICE_IDLE_MASK) |
| 3493 | | (mode << HistoryItem.STATE2_DEVICE_IDLE_SHIFT); |
| 3494 | if (DEBUG_HISTORY) Slog.v(TAG, "Device idle mode changed to: " |
| 3495 | + Integer.toHexString(mHistoryCur.states2)); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3496 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3497 | long lastDuration = elapsedRealtime - mLastIdleTimeStart; |
| 3498 | mLastIdleTimeStart = elapsedRealtime; |
| 3499 | if (mDeviceIdleMode == DEVICE_IDLE_MODE_LIGHT) { |
| 3500 | if (lastDuration > mLongestLightIdleTime) { |
| 3501 | mLongestLightIdleTime = lastDuration; |
| 3502 | } |
| 3503 | mDeviceIdleModeLightTimer.stopRunningLocked(elapsedRealtime); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 3504 | } else if (mDeviceIdleMode == DEVICE_IDLE_MODE_DEEP) { |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3505 | if (lastDuration > mLongestFullIdleTime) { |
| 3506 | mLongestFullIdleTime = lastDuration; |
| 3507 | } |
| 3508 | mDeviceIdleModeFullTimer.stopRunningLocked(elapsedRealtime); |
| 3509 | } |
| 3510 | if (mode == DEVICE_IDLE_MODE_LIGHT) { |
| 3511 | mDeviceIdleModeLightTimer.startRunningLocked(elapsedRealtime); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 3512 | } else if (mode == DEVICE_IDLE_MODE_DEEP) { |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3513 | mDeviceIdleModeFullTimer.startRunningLocked(elapsedRealtime); |
| 3514 | } |
| 3515 | mDeviceIdleMode = mode; |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3516 | } |
| 3517 | } |
| 3518 | |
| 3519 | public void notePackageInstalledLocked(String pkgName, int versionCode) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3520 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3521 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3522 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_PACKAGE_INSTALLED, |
| 3523 | pkgName, versionCode); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 3524 | PackageChange pc = new PackageChange(); |
| 3525 | pc.mPackageName = pkgName; |
| 3526 | pc.mUpdate = true; |
| 3527 | pc.mVersionCode = versionCode; |
| 3528 | addPackageChange(pc); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3529 | } |
| 3530 | |
| 3531 | public void notePackageUninstalledLocked(String pkgName) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3532 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3533 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3534 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_PACKAGE_UNINSTALLED, |
| 3535 | pkgName, 0); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 3536 | PackageChange pc = new PackageChange(); |
| 3537 | pc.mPackageName = pkgName; |
| 3538 | pc.mUpdate = true; |
| 3539 | addPackageChange(pc); |
| 3540 | } |
| 3541 | |
| 3542 | private void addPackageChange(PackageChange pc) { |
| 3543 | if (mDailyPackageChanges == null) { |
| 3544 | mDailyPackageChanges = new ArrayList<>(); |
| 3545 | } |
| 3546 | mDailyPackageChanges.add(pc); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3547 | } |
| 3548 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3549 | public void notePhoneOnLocked() { |
| 3550 | if (!mPhoneOn) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3551 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3552 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 3553 | mHistoryCur.states2 |= HistoryItem.STATE2_PHONE_IN_CALL_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3554 | if (DEBUG_HISTORY) Slog.v(TAG, "Phone on to: " |
| 3555 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3556 | addHistoryRecordLocked(elapsedRealtime, uptime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3557 | mPhoneOn = true; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3558 | mPhoneOnTimer.startRunningLocked(elapsedRealtime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3559 | } |
| 3560 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3561 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3562 | public void notePhoneOffLocked() { |
| 3563 | if (mPhoneOn) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3564 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3565 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 3566 | mHistoryCur.states2 &= ~HistoryItem.STATE2_PHONE_IN_CALL_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3567 | if (DEBUG_HISTORY) Slog.v(TAG, "Phone off to: " |
| 3568 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3569 | addHistoryRecordLocked(elapsedRealtime, uptime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3570 | mPhoneOn = false; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3571 | mPhoneOnTimer.stopRunningLocked(elapsedRealtime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3572 | } |
| 3573 | } |
Amith Yamasani | 32dbefd | 2009-06-19 09:21:17 -0700 | [diff] [blame] | 3574 | |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 3575 | void stopAllPhoneSignalStrengthTimersLocked(int except) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3576 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 3577 | for (int i = 0; i < SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 3578 | if (i == except) { |
| 3579 | continue; |
| 3580 | } |
| 3581 | while (mPhoneSignalStrengthsTimer[i].isRunningLocked()) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3582 | mPhoneSignalStrengthsTimer[i].stopRunningLocked(elapsedRealtime); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 3583 | } |
| 3584 | } |
| 3585 | } |
| 3586 | |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3587 | private int fixPhoneServiceState(int state, int signalBin) { |
| 3588 | if (mPhoneSimStateRaw == TelephonyManager.SIM_STATE_ABSENT) { |
| 3589 | // In this case we will always be STATE_OUT_OF_SERVICE, so need |
| 3590 | // to infer that we are scanning from other data. |
| 3591 | if (state == ServiceState.STATE_OUT_OF_SERVICE |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 3592 | && signalBin > SignalStrength.SIGNAL_STRENGTH_NONE_OR_UNKNOWN) { |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3593 | state = ServiceState.STATE_IN_SERVICE; |
| 3594 | } |
| 3595 | } |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 3596 | |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3597 | return state; |
| 3598 | } |
| 3599 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3600 | private void updateAllPhoneStateLocked(int state, int simState, int strengthBin) { |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3601 | boolean scanning = false; |
| 3602 | boolean newHistory = false; |
| 3603 | |
| 3604 | mPhoneServiceStateRaw = state; |
| 3605 | mPhoneSimStateRaw = simState; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3606 | mPhoneSignalStrengthBinRaw = strengthBin; |
| 3607 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3608 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3609 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3610 | |
| 3611 | if (simState == TelephonyManager.SIM_STATE_ABSENT) { |
| 3612 | // In this case we will always be STATE_OUT_OF_SERVICE, so need |
| 3613 | // to infer that we are scanning from other data. |
| 3614 | if (state == ServiceState.STATE_OUT_OF_SERVICE |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3615 | && strengthBin > SignalStrength.SIGNAL_STRENGTH_NONE_OR_UNKNOWN) { |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3616 | state = ServiceState.STATE_IN_SERVICE; |
| 3617 | } |
| 3618 | } |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 3619 | |
| 3620 | // If the phone is powered off, stop all timers. |
| 3621 | if (state == ServiceState.STATE_POWER_OFF) { |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3622 | strengthBin = -1; |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 3623 | |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3624 | // If we are in service, make sure the correct signal string timer is running. |
| 3625 | } else if (state == ServiceState.STATE_IN_SERVICE) { |
| 3626 | // Bin will be changed below. |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 3627 | |
| 3628 | // If we're out of service, we are in the lowest signal strength |
| 3629 | // bin and have the scanning bit set. |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 3630 | } else if (state == ServiceState.STATE_OUT_OF_SERVICE) { |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 3631 | scanning = true; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3632 | strengthBin = SignalStrength.SIGNAL_STRENGTH_NONE_OR_UNKNOWN; |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 3633 | if (!mPhoneSignalScanningTimer.isRunningLocked()) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3634 | mHistoryCur.states |= HistoryItem.STATE_PHONE_SCANNING_FLAG; |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3635 | newHistory = true; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3636 | if (DEBUG_HISTORY) Slog.v(TAG, "Phone started scanning to: " |
| 3637 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3638 | mPhoneSignalScanningTimer.startRunningLocked(elapsedRealtime); |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 3639 | } |
| 3640 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3641 | |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 3642 | if (!scanning) { |
| 3643 | // If we are no longer scanning, then stop the scanning timer. |
| 3644 | if (mPhoneSignalScanningTimer.isRunningLocked()) { |
| 3645 | mHistoryCur.states &= ~HistoryItem.STATE_PHONE_SCANNING_FLAG; |
| 3646 | if (DEBUG_HISTORY) Slog.v(TAG, "Phone stopped scanning to: " |
| 3647 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3648 | newHistory = true; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3649 | mPhoneSignalScanningTimer.stopRunningLocked(elapsedRealtime); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 3650 | } |
| 3651 | } |
| 3652 | |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3653 | if (mPhoneServiceState != state) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3654 | mHistoryCur.states = (mHistoryCur.states&~HistoryItem.STATE_PHONE_STATE_MASK) |
| 3655 | | (state << HistoryItem.STATE_PHONE_STATE_SHIFT); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3656 | if (DEBUG_HISTORY) Slog.v(TAG, "Phone state " + state + " to: " |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3657 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3658 | newHistory = true; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3659 | mPhoneServiceState = state; |
| 3660 | } |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3661 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3662 | if (mPhoneSignalStrengthBin != strengthBin) { |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3663 | if (mPhoneSignalStrengthBin >= 0) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3664 | mPhoneSignalStrengthsTimer[mPhoneSignalStrengthBin].stopRunningLocked( |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3665 | elapsedRealtime); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3666 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3667 | if (strengthBin >= 0) { |
| 3668 | if (!mPhoneSignalStrengthsTimer[strengthBin].isRunningLocked()) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3669 | mPhoneSignalStrengthsTimer[strengthBin].startRunningLocked(elapsedRealtime); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3670 | } |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 3671 | mHistoryCur.states = (mHistoryCur.states&~HistoryItem.STATE_PHONE_SIGNAL_STRENGTH_MASK) |
| 3672 | | (strengthBin << HistoryItem.STATE_PHONE_SIGNAL_STRENGTH_SHIFT); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3673 | if (DEBUG_HISTORY) Slog.v(TAG, "Signal strength " + strengthBin + " to: " |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3674 | + Integer.toHexString(mHistoryCur.states)); |
| 3675 | newHistory = true; |
| 3676 | } else { |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 3677 | stopAllPhoneSignalStrengthTimersLocked(-1); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3678 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3679 | mPhoneSignalStrengthBin = strengthBin; |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3680 | } |
| 3681 | |
| 3682 | if (newHistory) { |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3683 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3684 | } |
| 3685 | } |
| 3686 | |
| 3687 | /** |
| 3688 | * Telephony stack updates the phone state. |
| 3689 | * @param state phone state from ServiceState.getState() |
| 3690 | */ |
| 3691 | public void notePhoneStateLocked(int state, int simState) { |
| 3692 | updateAllPhoneStateLocked(state, simState, mPhoneSignalStrengthBinRaw); |
Amith Yamasani | 32dbefd | 2009-06-19 09:21:17 -0700 | [diff] [blame] | 3693 | } |
| 3694 | |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 3695 | public void notePhoneSignalStrengthLocked(SignalStrength signalStrength) { |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3696 | // Bin the strength. |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 3697 | int bin = signalStrength.getLevel(); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3698 | updateAllPhoneStateLocked(mPhoneServiceStateRaw, mPhoneSimStateRaw, bin); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3699 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3700 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3701 | public void notePhoneDataConnectionStateLocked(int dataType, boolean hasData) { |
| 3702 | int bin = DATA_CONNECTION_NONE; |
| 3703 | if (hasData) { |
| 3704 | switch (dataType) { |
| 3705 | case TelephonyManager.NETWORK_TYPE_EDGE: |
| 3706 | bin = DATA_CONNECTION_EDGE; |
| 3707 | break; |
| 3708 | case TelephonyManager.NETWORK_TYPE_GPRS: |
| 3709 | bin = DATA_CONNECTION_GPRS; |
| 3710 | break; |
| 3711 | case TelephonyManager.NETWORK_TYPE_UMTS: |
| 3712 | bin = DATA_CONNECTION_UMTS; |
| 3713 | break; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3714 | case TelephonyManager.NETWORK_TYPE_CDMA: |
| 3715 | bin = DATA_CONNECTION_CDMA; |
| 3716 | break; |
| 3717 | case TelephonyManager.NETWORK_TYPE_EVDO_0: |
| 3718 | bin = DATA_CONNECTION_EVDO_0; |
| 3719 | break; |
| 3720 | case TelephonyManager.NETWORK_TYPE_EVDO_A: |
| 3721 | bin = DATA_CONNECTION_EVDO_A; |
| 3722 | break; |
| 3723 | case TelephonyManager.NETWORK_TYPE_1xRTT: |
| 3724 | bin = DATA_CONNECTION_1xRTT; |
| 3725 | break; |
| 3726 | case TelephonyManager.NETWORK_TYPE_HSDPA: |
| 3727 | bin = DATA_CONNECTION_HSDPA; |
| 3728 | break; |
| 3729 | case TelephonyManager.NETWORK_TYPE_HSUPA: |
| 3730 | bin = DATA_CONNECTION_HSUPA; |
| 3731 | break; |
| 3732 | case TelephonyManager.NETWORK_TYPE_HSPA: |
| 3733 | bin = DATA_CONNECTION_HSPA; |
| 3734 | break; |
| 3735 | case TelephonyManager.NETWORK_TYPE_IDEN: |
| 3736 | bin = DATA_CONNECTION_IDEN; |
| 3737 | break; |
| 3738 | case TelephonyManager.NETWORK_TYPE_EVDO_B: |
| 3739 | bin = DATA_CONNECTION_EVDO_B; |
| 3740 | break; |
Robert Greenwalt | 962a990 | 2010-11-02 11:10:25 -0700 | [diff] [blame] | 3741 | case TelephonyManager.NETWORK_TYPE_LTE: |
| 3742 | bin = DATA_CONNECTION_LTE; |
| 3743 | break; |
| 3744 | case TelephonyManager.NETWORK_TYPE_EHRPD: |
| 3745 | bin = DATA_CONNECTION_EHRPD; |
| 3746 | break; |
Patrick Tjin | b71703c | 2013-11-06 09:27:03 -0800 | [diff] [blame] | 3747 | case TelephonyManager.NETWORK_TYPE_HSPAP: |
| 3748 | bin = DATA_CONNECTION_HSPAP; |
| 3749 | break; |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3750 | default: |
| 3751 | bin = DATA_CONNECTION_OTHER; |
| 3752 | break; |
| 3753 | } |
| 3754 | } |
Amith Yamasani | 3718aaa | 2009-06-09 06:32:35 -0700 | [diff] [blame] | 3755 | if (DEBUG) Log.i(TAG, "Phone Data Connection -> " + dataType + " = " + hasData); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3756 | if (mPhoneDataConnectionType != bin) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3757 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3758 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3759 | mHistoryCur.states = (mHistoryCur.states&~HistoryItem.STATE_DATA_CONNECTION_MASK) |
| 3760 | | (bin << HistoryItem.STATE_DATA_CONNECTION_SHIFT); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3761 | if (DEBUG_HISTORY) Slog.v(TAG, "Data connection " + bin + " to: " |
| 3762 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3763 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3764 | if (mPhoneDataConnectionType >= 0) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3765 | mPhoneDataConnectionsTimer[mPhoneDataConnectionType].stopRunningLocked( |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3766 | elapsedRealtime); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3767 | } |
| 3768 | mPhoneDataConnectionType = bin; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3769 | mPhoneDataConnectionsTimer[bin].startRunningLocked(elapsedRealtime); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3770 | } |
| 3771 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3772 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 3773 | public void noteWifiOnLocked() { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3774 | if (!mWifiOn) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3775 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3776 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 3777 | mHistoryCur.states2 |= HistoryItem.STATE2_WIFI_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3778 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI on to: " |
| 3779 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3780 | addHistoryRecordLocked(elapsedRealtime, uptime); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3781 | mWifiOn = true; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3782 | mWifiOnTimer.startRunningLocked(elapsedRealtime); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 3783 | scheduleSyncExternalStatsLocked("wifi-off", ExternalStatsSync.UPDATE_WIFI); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3784 | } |
| 3785 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3786 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 3787 | public void noteWifiOffLocked() { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3788 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3789 | final long uptime = mClocks.uptimeMillis(); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3790 | if (mWifiOn) { |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 3791 | mHistoryCur.states2 &= ~HistoryItem.STATE2_WIFI_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3792 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI off to: " |
| 3793 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3794 | addHistoryRecordLocked(elapsedRealtime, uptime); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3795 | mWifiOn = false; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3796 | mWifiOnTimer.stopRunningLocked(elapsedRealtime); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 3797 | scheduleSyncExternalStatsLocked("wifi-on", ExternalStatsSync.UPDATE_WIFI); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3798 | } |
| 3799 | } |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 3800 | |
| 3801 | public void noteAudioOnLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3802 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3803 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3804 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 3805 | if (mAudioOnNesting == 0) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3806 | mHistoryCur.states |= HistoryItem.STATE_AUDIO_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3807 | if (DEBUG_HISTORY) Slog.v(TAG, "Audio on to: " |
| 3808 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3809 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3810 | mAudioOnTimer.startRunningLocked(elapsedRealtime); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 3811 | } |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 3812 | mAudioOnNesting++; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3813 | getUidStatsLocked(uid).noteAudioTurnedOnLocked(elapsedRealtime); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 3814 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3815 | |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 3816 | public void noteAudioOffLocked(int uid) { |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 3817 | if (mAudioOnNesting == 0) { |
| 3818 | return; |
| 3819 | } |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3820 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3821 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3822 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 3823 | if (--mAudioOnNesting == 0) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3824 | mHistoryCur.states &= ~HistoryItem.STATE_AUDIO_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3825 | if (DEBUG_HISTORY) Slog.v(TAG, "Audio off to: " |
| 3826 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3827 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3828 | mAudioOnTimer.stopRunningLocked(elapsedRealtime); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 3829 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3830 | getUidStatsLocked(uid).noteAudioTurnedOffLocked(elapsedRealtime); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 3831 | } |
| 3832 | |
| 3833 | public void noteVideoOnLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3834 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3835 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3836 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 3837 | if (mVideoOnNesting == 0) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3838 | mHistoryCur.states2 |= HistoryItem.STATE2_VIDEO_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3839 | if (DEBUG_HISTORY) Slog.v(TAG, "Video on to: " |
| 3840 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3841 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3842 | mVideoOnTimer.startRunningLocked(elapsedRealtime); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 3843 | } |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 3844 | mVideoOnNesting++; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3845 | getUidStatsLocked(uid).noteVideoTurnedOnLocked(elapsedRealtime); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 3846 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3847 | |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 3848 | public void noteVideoOffLocked(int uid) { |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 3849 | if (mVideoOnNesting == 0) { |
| 3850 | return; |
| 3851 | } |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3852 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3853 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3854 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 3855 | if (--mVideoOnNesting == 0) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3856 | mHistoryCur.states2 &= ~HistoryItem.STATE2_VIDEO_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3857 | if (DEBUG_HISTORY) Slog.v(TAG, "Video off to: " |
| 3858 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3859 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3860 | mVideoOnTimer.stopRunningLocked(elapsedRealtime); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 3861 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3862 | getUidStatsLocked(uid).noteVideoTurnedOffLocked(elapsedRealtime); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 3863 | } |
| 3864 | |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 3865 | public void noteResetAudioLocked() { |
| 3866 | if (mAudioOnNesting > 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3867 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3868 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 3869 | mAudioOnNesting = 0; |
| 3870 | mHistoryCur.states &= ~HistoryItem.STATE_AUDIO_ON_FLAG; |
| 3871 | if (DEBUG_HISTORY) Slog.v(TAG, "Audio off to: " |
| 3872 | + Integer.toHexString(mHistoryCur.states)); |
| 3873 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 3874 | mAudioOnTimer.stopAllRunningLocked(elapsedRealtime); |
| 3875 | for (int i=0; i<mUidStats.size(); i++) { |
| 3876 | BatteryStatsImpl.Uid uid = mUidStats.valueAt(i); |
| 3877 | uid.noteResetAudioLocked(elapsedRealtime); |
| 3878 | } |
| 3879 | } |
| 3880 | } |
| 3881 | |
| 3882 | public void noteResetVideoLocked() { |
| 3883 | if (mVideoOnNesting > 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3884 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3885 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 3886 | mAudioOnNesting = 0; |
| 3887 | mHistoryCur.states2 &= ~HistoryItem.STATE2_VIDEO_ON_FLAG; |
| 3888 | if (DEBUG_HISTORY) Slog.v(TAG, "Video off to: " |
| 3889 | + Integer.toHexString(mHistoryCur.states)); |
| 3890 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 3891 | mVideoOnTimer.stopAllRunningLocked(elapsedRealtime); |
| 3892 | for (int i=0; i<mUidStats.size(); i++) { |
| 3893 | BatteryStatsImpl.Uid uid = mUidStats.valueAt(i); |
| 3894 | uid.noteResetVideoLocked(elapsedRealtime); |
| 3895 | } |
| 3896 | } |
| 3897 | } |
| 3898 | |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 3899 | public void noteActivityResumedLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3900 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3901 | getUidStatsLocked(uid).noteActivityResumedLocked(mClocks.elapsedRealtime()); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 3902 | } |
| 3903 | |
| 3904 | public void noteActivityPausedLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3905 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3906 | getUidStatsLocked(uid).noteActivityPausedLocked(mClocks.elapsedRealtime()); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 3907 | } |
| 3908 | |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 3909 | public void noteVibratorOnLocked(int uid, long durationMillis) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3910 | uid = mapUid(uid); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 3911 | getUidStatsLocked(uid).noteVibratorOnLocked(durationMillis); |
| 3912 | } |
| 3913 | |
| 3914 | public void noteVibratorOffLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3915 | uid = mapUid(uid); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 3916 | getUidStatsLocked(uid).noteVibratorOffLocked(); |
| 3917 | } |
| 3918 | |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 3919 | public void noteFlashlightOnLocked(int uid) { |
| 3920 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3921 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3922 | final long uptime = mClocks.uptimeMillis(); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 3923 | if (mFlashlightOnNesting++ == 0) { |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 3924 | mHistoryCur.states2 |= HistoryItem.STATE2_FLASHLIGHT_FLAG; |
| 3925 | if (DEBUG_HISTORY) Slog.v(TAG, "Flashlight on to: " |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 3926 | + Integer.toHexString(mHistoryCur.states2)); |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 3927 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 3928 | mFlashlightOnTimer.startRunningLocked(elapsedRealtime); |
| 3929 | } |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 3930 | getUidStatsLocked(uid).noteFlashlightTurnedOnLocked(elapsedRealtime); |
| 3931 | } |
| 3932 | |
| 3933 | public void noteFlashlightOffLocked(int uid) { |
| 3934 | if (mFlashlightOnNesting == 0) { |
| 3935 | return; |
| 3936 | } |
| 3937 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3938 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3939 | final long uptime = mClocks.uptimeMillis(); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 3940 | if (--mFlashlightOnNesting == 0) { |
| 3941 | mHistoryCur.states2 &= ~HistoryItem.STATE2_FLASHLIGHT_FLAG; |
| 3942 | if (DEBUG_HISTORY) Slog.v(TAG, "Flashlight off to: " |
| 3943 | + Integer.toHexString(mHistoryCur.states2)); |
| 3944 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 3945 | mFlashlightOnTimer.stopRunningLocked(elapsedRealtime); |
| 3946 | } |
| 3947 | getUidStatsLocked(uid).noteFlashlightTurnedOffLocked(elapsedRealtime); |
| 3948 | } |
| 3949 | |
| 3950 | public void noteCameraOnLocked(int uid) { |
| 3951 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3952 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3953 | final long uptime = mClocks.uptimeMillis(); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 3954 | if (mCameraOnNesting++ == 0) { |
| 3955 | mHistoryCur.states2 |= HistoryItem.STATE2_CAMERA_FLAG; |
| 3956 | if (DEBUG_HISTORY) Slog.v(TAG, "Camera on to: " |
| 3957 | + Integer.toHexString(mHistoryCur.states2)); |
| 3958 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 3959 | mCameraOnTimer.startRunningLocked(elapsedRealtime); |
| 3960 | } |
| 3961 | getUidStatsLocked(uid).noteCameraTurnedOnLocked(elapsedRealtime); |
| 3962 | } |
| 3963 | |
| 3964 | public void noteCameraOffLocked(int uid) { |
| 3965 | if (mCameraOnNesting == 0) { |
| 3966 | return; |
| 3967 | } |
| 3968 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3969 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3970 | final long uptime = mClocks.uptimeMillis(); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 3971 | if (--mCameraOnNesting == 0) { |
| 3972 | mHistoryCur.states2 &= ~HistoryItem.STATE2_CAMERA_FLAG; |
| 3973 | if (DEBUG_HISTORY) Slog.v(TAG, "Camera off to: " |
| 3974 | + Integer.toHexString(mHistoryCur.states2)); |
| 3975 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 3976 | mCameraOnTimer.stopRunningLocked(elapsedRealtime); |
| 3977 | } |
| 3978 | getUidStatsLocked(uid).noteCameraTurnedOffLocked(elapsedRealtime); |
| 3979 | } |
| 3980 | |
| 3981 | public void noteResetCameraLocked() { |
| 3982 | if (mCameraOnNesting > 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3983 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3984 | final long uptime = mClocks.uptimeMillis(); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 3985 | mCameraOnNesting = 0; |
| 3986 | mHistoryCur.states2 &= ~HistoryItem.STATE2_CAMERA_FLAG; |
| 3987 | if (DEBUG_HISTORY) Slog.v(TAG, "Camera off to: " |
| 3988 | + Integer.toHexString(mHistoryCur.states2)); |
| 3989 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 3990 | mCameraOnTimer.stopAllRunningLocked(elapsedRealtime); |
| 3991 | for (int i=0; i<mUidStats.size(); i++) { |
| 3992 | BatteryStatsImpl.Uid uid = mUidStats.valueAt(i); |
| 3993 | uid.noteResetCameraLocked(elapsedRealtime); |
| 3994 | } |
| 3995 | } |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 3996 | } |
| 3997 | |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 3998 | public void noteResetFlashlightLocked() { |
| 3999 | if (mFlashlightOnNesting > 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4000 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4001 | final long uptime = mClocks.uptimeMillis(); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 4002 | mFlashlightOnNesting = 0; |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 4003 | mHistoryCur.states2 &= ~HistoryItem.STATE2_FLASHLIGHT_FLAG; |
| 4004 | if (DEBUG_HISTORY) Slog.v(TAG, "Flashlight off to: " |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 4005 | + Integer.toHexString(mHistoryCur.states2)); |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 4006 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 4007 | mFlashlightOnTimer.stopAllRunningLocked(elapsedRealtime); |
| 4008 | for (int i=0; i<mUidStats.size(); i++) { |
| 4009 | BatteryStatsImpl.Uid uid = mUidStats.valueAt(i); |
| 4010 | uid.noteResetFlashlightLocked(elapsedRealtime); |
| 4011 | } |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 4012 | } |
| 4013 | } |
| 4014 | |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 4015 | private void noteBluetoothScanStartedLocked(int uid) { |
| 4016 | uid = mapUid(uid); |
| 4017 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 4018 | final long uptime = SystemClock.uptimeMillis(); |
| 4019 | if (mBluetoothScanNesting == 0) { |
| 4020 | mHistoryCur.states2 |= HistoryItem.STATE2_BLUETOOTH_SCAN_FLAG; |
| 4021 | if (DEBUG_HISTORY) Slog.v(TAG, "BLE scan started for: " |
| 4022 | + Integer.toHexString(mHistoryCur.states2)); |
| 4023 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Adam Lesinski | d9b99be | 2016-03-30 16:58:51 -0700 | [diff] [blame] | 4024 | mBluetoothScanTimer.startRunningLocked(elapsedRealtime); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 4025 | } |
| 4026 | mBluetoothScanNesting++; |
| 4027 | getUidStatsLocked(uid).noteBluetoothScanStartedLocked(elapsedRealtime); |
| 4028 | } |
| 4029 | |
| 4030 | public void noteBluetoothScanStartedFromSourceLocked(WorkSource ws) { |
| 4031 | final int N = ws.size(); |
| 4032 | for (int i = 0; i < N; i++) { |
| 4033 | noteBluetoothScanStartedLocked(ws.get(i)); |
| 4034 | } |
| 4035 | } |
| 4036 | |
| 4037 | private void noteBluetoothScanStoppedLocked(int uid) { |
| 4038 | uid = mapUid(uid); |
| 4039 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 4040 | final long uptime = SystemClock.uptimeMillis(); |
| 4041 | mBluetoothScanNesting--; |
| 4042 | if (mBluetoothScanNesting == 0) { |
| 4043 | mHistoryCur.states2 &= ~HistoryItem.STATE2_BLUETOOTH_SCAN_FLAG; |
| 4044 | if (DEBUG_HISTORY) Slog.v(TAG, "BLE scan stopped for: " |
| 4045 | + Integer.toHexString(mHistoryCur.states2)); |
| 4046 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Adam Lesinski | d9b99be | 2016-03-30 16:58:51 -0700 | [diff] [blame] | 4047 | mBluetoothScanTimer.stopRunningLocked(elapsedRealtime); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 4048 | } |
| 4049 | getUidStatsLocked(uid).noteBluetoothScanStoppedLocked(elapsedRealtime); |
| 4050 | } |
| 4051 | |
| 4052 | public void noteBluetoothScanStoppedFromSourceLocked(WorkSource ws) { |
| 4053 | final int N = ws.size(); |
| 4054 | for (int i = 0; i < N; i++) { |
| 4055 | noteBluetoothScanStoppedLocked(ws.get(i)); |
| 4056 | } |
| 4057 | } |
| 4058 | |
| 4059 | public void noteResetBluetoothScanLocked() { |
| 4060 | if (mBluetoothScanNesting > 0) { |
| 4061 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 4062 | final long uptime = SystemClock.uptimeMillis(); |
| 4063 | mBluetoothScanNesting = 0; |
| 4064 | mHistoryCur.states2 &= ~HistoryItem.STATE2_BLUETOOTH_SCAN_FLAG; |
| 4065 | if (DEBUG_HISTORY) Slog.v(TAG, "BLE can stopped for: " |
| 4066 | + Integer.toHexString(mHistoryCur.states2)); |
| 4067 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 4068 | mBluetoothScanTimer.stopAllRunningLocked(elapsedRealtime); |
| 4069 | for (int i=0; i<mUidStats.size(); i++) { |
| 4070 | BatteryStatsImpl.Uid uid = mUidStats.valueAt(i); |
| 4071 | uid.noteResetBluetoothScanLocked(elapsedRealtime); |
| 4072 | } |
| 4073 | } |
| 4074 | } |
| 4075 | |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 4076 | public void noteWifiRadioPowerState(int powerState, long timestampNs) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4077 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4078 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 4079 | if (mWifiRadioPowerState != powerState) { |
| 4080 | final boolean active = |
| 4081 | powerState == DataConnectionRealTimeInfo.DC_POWER_STATE_MEDIUM |
| 4082 | || powerState == DataConnectionRealTimeInfo.DC_POWER_STATE_HIGH; |
| 4083 | if (active) { |
| 4084 | mHistoryCur.states |= HistoryItem.STATE_WIFI_RADIO_ACTIVE_FLAG; |
| 4085 | } else { |
| 4086 | mHistoryCur.states &= ~HistoryItem.STATE_WIFI_RADIO_ACTIVE_FLAG; |
| 4087 | } |
| 4088 | if (DEBUG_HISTORY) Slog.v(TAG, "Wifi network active " + active + " to: " |
| 4089 | + Integer.toHexString(mHistoryCur.states)); |
| 4090 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 4091 | mWifiRadioPowerState = powerState; |
| 4092 | } |
| 4093 | } |
| 4094 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 4095 | public void noteWifiRunningLocked(WorkSource ws) { |
| 4096 | if (!mGlobalWifiRunning) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4097 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4098 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 4099 | mHistoryCur.states2 |= HistoryItem.STATE2_WIFI_RUNNING_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4100 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI running to: " |
| 4101 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 4102 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 4103 | mGlobalWifiRunning = true; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4104 | mGlobalWifiRunningTimer.startRunningLocked(elapsedRealtime); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 4105 | int N = ws.size(); |
| 4106 | for (int i=0; i<N; i++) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4107 | int uid = mapUid(ws.get(i)); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4108 | getUidStatsLocked(uid).noteWifiRunningLocked(elapsedRealtime); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 4109 | } |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 4110 | scheduleSyncExternalStatsLocked("wifi-running", ExternalStatsSync.UPDATE_WIFI); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 4111 | } else { |
| 4112 | Log.w(TAG, "noteWifiRunningLocked -- called while WIFI running"); |
Eric Shienbrood | d4c5f89 | 2009-03-24 18:13:20 -0700 | [diff] [blame] | 4113 | } |
| 4114 | } |
| 4115 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 4116 | public void noteWifiRunningChangedLocked(WorkSource oldWs, WorkSource newWs) { |
| 4117 | if (mGlobalWifiRunning) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4118 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 4119 | int N = oldWs.size(); |
| 4120 | for (int i=0; i<N; i++) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4121 | int uid = mapUid(oldWs.get(i)); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4122 | getUidStatsLocked(uid).noteWifiStoppedLocked(elapsedRealtime); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 4123 | } |
| 4124 | N = newWs.size(); |
| 4125 | for (int i=0; i<N; i++) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4126 | int uid = mapUid(newWs.get(i)); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4127 | getUidStatsLocked(uid).noteWifiRunningLocked(elapsedRealtime); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 4128 | } |
| 4129 | } else { |
| 4130 | Log.w(TAG, "noteWifiRunningChangedLocked -- called while WIFI not running"); |
| 4131 | } |
| 4132 | } |
| 4133 | |
| 4134 | public void noteWifiStoppedLocked(WorkSource ws) { |
| 4135 | if (mGlobalWifiRunning) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4136 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4137 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 4138 | mHistoryCur.states2 &= ~HistoryItem.STATE2_WIFI_RUNNING_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4139 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI stopped to: " |
| 4140 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 4141 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 4142 | mGlobalWifiRunning = false; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4143 | mGlobalWifiRunningTimer.stopRunningLocked(elapsedRealtime); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 4144 | int N = ws.size(); |
| 4145 | for (int i=0; i<N; i++) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4146 | int uid = mapUid(ws.get(i)); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4147 | getUidStatsLocked(uid).noteWifiStoppedLocked(elapsedRealtime); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 4148 | } |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 4149 | scheduleSyncExternalStatsLocked("wifi-stopped", ExternalStatsSync.UPDATE_WIFI); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 4150 | } else { |
| 4151 | Log.w(TAG, "noteWifiStoppedLocked -- called while WIFI not running"); |
Eric Shienbrood | d4c5f89 | 2009-03-24 18:13:20 -0700 | [diff] [blame] | 4152 | } |
| 4153 | } |
| 4154 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4155 | public void noteWifiStateLocked(int wifiState, String accessPoint) { |
| 4156 | if (DEBUG) Log.i(TAG, "WiFi state -> " + wifiState); |
| 4157 | if (mWifiState != wifiState) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4158 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4159 | if (mWifiState >= 0) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4160 | mWifiStateTimer[mWifiState].stopRunningLocked(elapsedRealtime); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4161 | } |
| 4162 | mWifiState = wifiState; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4163 | mWifiStateTimer[wifiState].startRunningLocked(elapsedRealtime); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 4164 | scheduleSyncExternalStatsLocked("wifi-state", ExternalStatsSync.UPDATE_WIFI); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4165 | } |
| 4166 | } |
| 4167 | |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 4168 | public void noteWifiSupplicantStateChangedLocked(int supplState, boolean failedAuth) { |
| 4169 | if (DEBUG) Log.i(TAG, "WiFi suppl state -> " + supplState); |
| 4170 | if (mWifiSupplState != supplState) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4171 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4172 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 4173 | if (mWifiSupplState >= 0) { |
| 4174 | mWifiSupplStateTimer[mWifiSupplState].stopRunningLocked(elapsedRealtime); |
| 4175 | } |
| 4176 | mWifiSupplState = supplState; |
| 4177 | mWifiSupplStateTimer[supplState].startRunningLocked(elapsedRealtime); |
| 4178 | mHistoryCur.states2 = |
| 4179 | (mHistoryCur.states2&~HistoryItem.STATE2_WIFI_SUPPL_STATE_MASK) |
| 4180 | | (supplState << HistoryItem.STATE2_WIFI_SUPPL_STATE_SHIFT); |
| 4181 | if (DEBUG_HISTORY) Slog.v(TAG, "Wifi suppl state " + supplState + " to: " |
| 4182 | + Integer.toHexString(mHistoryCur.states2)); |
| 4183 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 4184 | } |
| 4185 | } |
| 4186 | |
| 4187 | void stopAllWifiSignalStrengthTimersLocked(int except) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4188 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 4189 | for (int i = 0; i < NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 4190 | if (i == except) { |
| 4191 | continue; |
| 4192 | } |
| 4193 | while (mWifiSignalStrengthsTimer[i].isRunningLocked()) { |
| 4194 | mWifiSignalStrengthsTimer[i].stopRunningLocked(elapsedRealtime); |
| 4195 | } |
| 4196 | } |
| 4197 | } |
| 4198 | |
| 4199 | public void noteWifiRssiChangedLocked(int newRssi) { |
| 4200 | int strengthBin = WifiManager.calculateSignalLevel(newRssi, NUM_WIFI_SIGNAL_STRENGTH_BINS); |
| 4201 | if (DEBUG) Log.i(TAG, "WiFi rssi -> " + newRssi + " bin=" + strengthBin); |
| 4202 | if (mWifiSignalStrengthBin != strengthBin) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4203 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4204 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 4205 | if (mWifiSignalStrengthBin >= 0) { |
| 4206 | mWifiSignalStrengthsTimer[mWifiSignalStrengthBin].stopRunningLocked( |
| 4207 | elapsedRealtime); |
| 4208 | } |
| 4209 | if (strengthBin >= 0) { |
| 4210 | if (!mWifiSignalStrengthsTimer[strengthBin].isRunningLocked()) { |
| 4211 | mWifiSignalStrengthsTimer[strengthBin].startRunningLocked(elapsedRealtime); |
| 4212 | } |
| 4213 | mHistoryCur.states2 = |
| 4214 | (mHistoryCur.states2&~HistoryItem.STATE2_WIFI_SIGNAL_STRENGTH_MASK) |
| 4215 | | (strengthBin << HistoryItem.STATE2_WIFI_SIGNAL_STRENGTH_SHIFT); |
| 4216 | if (DEBUG_HISTORY) Slog.v(TAG, "Wifi signal strength " + strengthBin + " to: " |
| 4217 | + Integer.toHexString(mHistoryCur.states2)); |
| 4218 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 4219 | } else { |
| 4220 | stopAllWifiSignalStrengthTimersLocked(-1); |
| 4221 | } |
| 4222 | mWifiSignalStrengthBin = strengthBin; |
| 4223 | } |
| 4224 | } |
| 4225 | |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4226 | int mWifiFullLockNesting = 0; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4227 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4228 | public void noteFullWifiLockAcquiredLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4229 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4230 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4231 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4232 | if (mWifiFullLockNesting == 0) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4233 | mHistoryCur.states |= HistoryItem.STATE_WIFI_FULL_LOCK_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4234 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI full lock on to: " |
| 4235 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 4236 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4237 | } |
| 4238 | mWifiFullLockNesting++; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4239 | getUidStatsLocked(uid).noteFullWifiLockAcquiredLocked(elapsedRealtime); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4240 | } |
| 4241 | |
| 4242 | public void noteFullWifiLockReleasedLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4243 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4244 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4245 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4246 | mWifiFullLockNesting--; |
| 4247 | if (mWifiFullLockNesting == 0) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4248 | mHistoryCur.states &= ~HistoryItem.STATE_WIFI_FULL_LOCK_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4249 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI full lock off to: " |
| 4250 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 4251 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4252 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4253 | getUidStatsLocked(uid).noteFullWifiLockReleasedLocked(elapsedRealtime); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4254 | } |
| 4255 | |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 4256 | int mWifiScanNesting = 0; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4257 | |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 4258 | public void noteWifiScanStartedLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4259 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4260 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4261 | final long uptime = mClocks.uptimeMillis(); |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 4262 | if (mWifiScanNesting == 0) { |
| 4263 | mHistoryCur.states |= HistoryItem.STATE_WIFI_SCAN_FLAG; |
| 4264 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI scan started for: " |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4265 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 4266 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4267 | } |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 4268 | mWifiScanNesting++; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4269 | getUidStatsLocked(uid).noteWifiScanStartedLocked(elapsedRealtime); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4270 | } |
| 4271 | |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 4272 | public void noteWifiScanStoppedLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4273 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4274 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4275 | final long uptime = mClocks.uptimeMillis(); |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 4276 | mWifiScanNesting--; |
| 4277 | if (mWifiScanNesting == 0) { |
| 4278 | mHistoryCur.states &= ~HistoryItem.STATE_WIFI_SCAN_FLAG; |
| 4279 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI scan stopped for: " |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4280 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 4281 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4282 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4283 | getUidStatsLocked(uid).noteWifiScanStoppedLocked(elapsedRealtime); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4284 | } |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 4285 | |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 4286 | public void noteWifiBatchedScanStartedLocked(int uid, int csph) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4287 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4288 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4289 | getUidStatsLocked(uid).noteWifiBatchedScanStartedLocked(csph, elapsedRealtime); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 4290 | } |
| 4291 | |
| 4292 | public void noteWifiBatchedScanStoppedLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4293 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4294 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4295 | getUidStatsLocked(uid).noteWifiBatchedScanStoppedLocked(elapsedRealtime); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 4296 | } |
| 4297 | |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4298 | int mWifiMulticastNesting = 0; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4299 | |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 4300 | public void noteWifiMulticastEnabledLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4301 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4302 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4303 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4304 | if (mWifiMulticastNesting == 0) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4305 | mHistoryCur.states |= HistoryItem.STATE_WIFI_MULTICAST_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4306 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI multicast on to: " |
| 4307 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 4308 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4309 | } |
| 4310 | mWifiMulticastNesting++; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4311 | getUidStatsLocked(uid).noteWifiMulticastEnabledLocked(elapsedRealtime); |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 4312 | } |
| 4313 | |
| 4314 | public void noteWifiMulticastDisabledLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4315 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4316 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4317 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4318 | mWifiMulticastNesting--; |
| 4319 | if (mWifiMulticastNesting == 0) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4320 | mHistoryCur.states &= ~HistoryItem.STATE_WIFI_MULTICAST_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4321 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI multicast off to: " |
| 4322 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 4323 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4324 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4325 | getUidStatsLocked(uid).noteWifiMulticastDisabledLocked(elapsedRealtime); |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 4326 | } |
| 4327 | |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 4328 | public void noteFullWifiLockAcquiredFromSourceLocked(WorkSource ws) { |
| 4329 | int N = ws.size(); |
| 4330 | for (int i=0; i<N; i++) { |
| 4331 | noteFullWifiLockAcquiredLocked(ws.get(i)); |
| 4332 | } |
| 4333 | } |
| 4334 | |
| 4335 | public void noteFullWifiLockReleasedFromSourceLocked(WorkSource ws) { |
| 4336 | int N = ws.size(); |
| 4337 | for (int i=0; i<N; i++) { |
| 4338 | noteFullWifiLockReleasedLocked(ws.get(i)); |
| 4339 | } |
| 4340 | } |
| 4341 | |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 4342 | public void noteWifiScanStartedFromSourceLocked(WorkSource ws) { |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 4343 | int N = ws.size(); |
| 4344 | for (int i=0; i<N; i++) { |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 4345 | noteWifiScanStartedLocked(ws.get(i)); |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 4346 | } |
| 4347 | } |
| 4348 | |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 4349 | public void noteWifiScanStoppedFromSourceLocked(WorkSource ws) { |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 4350 | int N = ws.size(); |
| 4351 | for (int i=0; i<N; i++) { |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 4352 | noteWifiScanStoppedLocked(ws.get(i)); |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 4353 | } |
| 4354 | } |
| 4355 | |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 4356 | public void noteWifiBatchedScanStartedFromSourceLocked(WorkSource ws, int csph) { |
| 4357 | int N = ws.size(); |
| 4358 | for (int i=0; i<N; i++) { |
| 4359 | noteWifiBatchedScanStartedLocked(ws.get(i), csph); |
| 4360 | } |
| 4361 | } |
| 4362 | |
| 4363 | public void noteWifiBatchedScanStoppedFromSourceLocked(WorkSource ws) { |
| 4364 | int N = ws.size(); |
| 4365 | for (int i=0; i<N; i++) { |
| 4366 | noteWifiBatchedScanStoppedLocked(ws.get(i)); |
| 4367 | } |
| 4368 | } |
| 4369 | |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 4370 | public void noteWifiMulticastEnabledFromSourceLocked(WorkSource ws) { |
| 4371 | int N = ws.size(); |
| 4372 | for (int i=0; i<N; i++) { |
| 4373 | noteWifiMulticastEnabledLocked(ws.get(i)); |
| 4374 | } |
| 4375 | } |
| 4376 | |
| 4377 | public void noteWifiMulticastDisabledFromSourceLocked(WorkSource ws) { |
| 4378 | int N = ws.size(); |
| 4379 | for (int i=0; i<N; i++) { |
| 4380 | noteWifiMulticastDisabledLocked(ws.get(i)); |
| 4381 | } |
| 4382 | } |
| 4383 | |
Dianne Hackborn | d0c5b9a | 2014-02-21 16:19:05 -0800 | [diff] [blame] | 4384 | private static String[] includeInStringArray(String[] array, String str) { |
| 4385 | if (ArrayUtils.indexOf(array, str) >= 0) { |
| 4386 | return array; |
| 4387 | } |
| 4388 | String[] newArray = new String[array.length+1]; |
| 4389 | System.arraycopy(array, 0, newArray, 0, array.length); |
| 4390 | newArray[array.length] = str; |
| 4391 | return newArray; |
| 4392 | } |
| 4393 | |
| 4394 | private static String[] excludeFromStringArray(String[] array, String str) { |
| 4395 | int index = ArrayUtils.indexOf(array, str); |
| 4396 | if (index >= 0) { |
| 4397 | String[] newArray = new String[array.length-1]; |
| 4398 | if (index > 0) { |
| 4399 | System.arraycopy(array, 0, newArray, 0, index); |
| 4400 | } |
| 4401 | if (index < array.length-1) { |
| 4402 | System.arraycopy(array, index+1, newArray, index, array.length-index-1); |
| 4403 | } |
| 4404 | return newArray; |
| 4405 | } |
| 4406 | return array; |
| 4407 | } |
| 4408 | |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 4409 | public void noteNetworkInterfaceTypeLocked(String iface, int networkType) { |
Jeff Sharkey | 9da2f1e | 2014-08-14 12:55:00 -0700 | [diff] [blame] | 4410 | if (TextUtils.isEmpty(iface)) return; |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 4411 | if (ConnectivityManager.isNetworkTypeMobile(networkType)) { |
Dianne Hackborn | d0c5b9a | 2014-02-21 16:19:05 -0800 | [diff] [blame] | 4412 | mMobileIfaces = includeInStringArray(mMobileIfaces, iface); |
| 4413 | if (DEBUG) Slog.d(TAG, "Note mobile iface " + iface + ": " + mMobileIfaces); |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 4414 | } else { |
Dianne Hackborn | d0c5b9a | 2014-02-21 16:19:05 -0800 | [diff] [blame] | 4415 | mMobileIfaces = excludeFromStringArray(mMobileIfaces, iface); |
| 4416 | if (DEBUG) Slog.d(TAG, "Note non-mobile iface " + iface + ": " + mMobileIfaces); |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 4417 | } |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 4418 | if (ConnectivityManager.isNetworkTypeWifi(networkType)) { |
Dianne Hackborn | d0c5b9a | 2014-02-21 16:19:05 -0800 | [diff] [blame] | 4419 | mWifiIfaces = includeInStringArray(mWifiIfaces, iface); |
| 4420 | if (DEBUG) Slog.d(TAG, "Note wifi iface " + iface + ": " + mWifiIfaces); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 4421 | } else { |
Dianne Hackborn | d0c5b9a | 2014-02-21 16:19:05 -0800 | [diff] [blame] | 4422 | mWifiIfaces = excludeFromStringArray(mWifiIfaces, iface); |
| 4423 | if (DEBUG) Slog.d(TAG, "Note non-wifi iface " + iface + ": " + mWifiIfaces); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 4424 | } |
| 4425 | } |
| 4426 | |
| 4427 | public void noteNetworkStatsEnabledLocked() { |
| 4428 | // During device boot, qtaguid isn't enabled until after the inital |
| 4429 | // loading of battery stats. Now that they're enabled, take our initial |
| 4430 | // snapshot for future delta calculation. |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4431 | updateMobileRadioStateLocked(mClocks.elapsedRealtime(), null); |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 4432 | updateWifiStateLocked(null); |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 4433 | } |
| 4434 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4435 | @Override public long getScreenOnTime(long elapsedRealtimeUs, int which) { |
| 4436 | return mScreenOnTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4437 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4438 | |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 4439 | @Override public int getScreenOnCount(int which) { |
| 4440 | return mScreenOnTimer.getCountLocked(which); |
| 4441 | } |
| 4442 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4443 | @Override public long getScreenBrightnessTime(int brightnessBin, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4444 | long elapsedRealtimeUs, int which) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 4445 | return mScreenBrightnessTimer[brightnessBin].getTotalTimeLocked( |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4446 | elapsedRealtimeUs, which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4447 | } |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 4448 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 4449 | @Override public long getInteractiveTime(long elapsedRealtimeUs, int which) { |
| 4450 | return mInteractiveTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4451 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4452 | |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4453 | @Override public long getPowerSaveModeEnabledTime(long elapsedRealtimeUs, int which) { |
| 4454 | return mPowerSaveModeEnabledTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 4455 | } |
| 4456 | |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4457 | @Override public int getPowerSaveModeEnabledCount(int which) { |
| 4458 | return mPowerSaveModeEnabledTimer.getCountLocked(which); |
| 4459 | } |
| 4460 | |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4461 | @Override public long getDeviceIdleModeTime(int mode, long elapsedRealtimeUs, |
| 4462 | int which) { |
| 4463 | switch (mode) { |
| 4464 | case DEVICE_IDLE_MODE_LIGHT: |
| 4465 | return mDeviceIdleModeLightTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 4466 | case DEVICE_IDLE_MODE_DEEP: |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4467 | return mDeviceIdleModeFullTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
| 4468 | } |
| 4469 | return 0; |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4470 | } |
| 4471 | |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4472 | @Override public int getDeviceIdleModeCount(int mode, int which) { |
| 4473 | switch (mode) { |
| 4474 | case DEVICE_IDLE_MODE_LIGHT: |
| 4475 | return mDeviceIdleModeLightTimer.getCountLocked(which); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 4476 | case DEVICE_IDLE_MODE_DEEP: |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4477 | return mDeviceIdleModeFullTimer.getCountLocked(which); |
| 4478 | } |
| 4479 | return 0; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 4480 | } |
| 4481 | |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4482 | @Override public long getLongestDeviceIdleModeTime(int mode) { |
| 4483 | switch (mode) { |
| 4484 | case DEVICE_IDLE_MODE_LIGHT: |
| 4485 | return mLongestLightIdleTime; |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 4486 | case DEVICE_IDLE_MODE_DEEP: |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4487 | return mLongestFullIdleTime; |
| 4488 | } |
| 4489 | return 0; |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 4490 | } |
| 4491 | |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4492 | @Override public long getDeviceIdlingTime(int mode, long elapsedRealtimeUs, int which) { |
| 4493 | switch (mode) { |
| 4494 | case DEVICE_IDLE_MODE_LIGHT: |
| 4495 | return mDeviceLightIdlingTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 4496 | case DEVICE_IDLE_MODE_DEEP: |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4497 | return mDeviceIdlingTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
| 4498 | } |
| 4499 | return 0; |
| 4500 | } |
| 4501 | |
| 4502 | @Override public int getDeviceIdlingCount(int mode, int which) { |
| 4503 | switch (mode) { |
| 4504 | case DEVICE_IDLE_MODE_LIGHT: |
| 4505 | return mDeviceLightIdlingTimer.getCountLocked(which); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 4506 | case DEVICE_IDLE_MODE_DEEP: |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4507 | return mDeviceIdlingTimer.getCountLocked(which); |
| 4508 | } |
| 4509 | return 0; |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 4510 | } |
| 4511 | |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 4512 | @Override public int getNumConnectivityChange(int which) { |
| 4513 | int val = mNumConnectivityChange; |
| 4514 | if (which == STATS_CURRENT) { |
| 4515 | val -= mLoadedNumConnectivityChange; |
| 4516 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 4517 | val -= mUnpluggedNumConnectivityChange; |
| 4518 | } |
| 4519 | return val; |
| 4520 | } |
| 4521 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4522 | @Override public long getPhoneOnTime(long elapsedRealtimeUs, int which) { |
| 4523 | return mPhoneOnTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4524 | } |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 4525 | |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 4526 | @Override public int getPhoneOnCount(int which) { |
| 4527 | return mPhoneOnTimer.getCountLocked(which); |
| 4528 | } |
| 4529 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4530 | @Override public long getPhoneSignalStrengthTime(int strengthBin, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4531 | long elapsedRealtimeUs, int which) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 4532 | return mPhoneSignalStrengthsTimer[strengthBin].getTotalTimeLocked( |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4533 | elapsedRealtimeUs, which); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4534 | } |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 4535 | |
| 4536 | @Override public long getPhoneSignalScanningTime( |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4537 | long elapsedRealtimeUs, int which) { |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 4538 | return mPhoneSignalScanningTimer.getTotalTimeLocked( |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4539 | elapsedRealtimeUs, which); |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 4540 | } |
| 4541 | |
Catherine Liu | fb90081 | 2012-07-17 14:12:56 -0500 | [diff] [blame] | 4542 | @Override public int getPhoneSignalStrengthCount(int strengthBin, int which) { |
| 4543 | return mPhoneSignalStrengthsTimer[strengthBin].getCountLocked(which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4544 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4545 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4546 | @Override public long getPhoneDataConnectionTime(int dataType, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4547 | long elapsedRealtimeUs, int which) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 4548 | return mPhoneDataConnectionsTimer[dataType].getTotalTimeLocked( |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4549 | elapsedRealtimeUs, which); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4550 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4551 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4552 | @Override public int getPhoneDataConnectionCount(int dataType, int which) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 4553 | return mPhoneDataConnectionsTimer[dataType].getCountLocked(which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4554 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4555 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4556 | @Override public long getMobileRadioActiveTime(long elapsedRealtimeUs, int which) { |
| 4557 | return mMobileRadioActiveTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 4558 | } |
| 4559 | |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4560 | @Override public int getMobileRadioActiveCount(int which) { |
| 4561 | return mMobileRadioActiveTimer.getCountLocked(which); |
| 4562 | } |
| 4563 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 4564 | @Override public long getMobileRadioActiveAdjustedTime(int which) { |
| 4565 | return mMobileRadioActiveAdjustedTime.getCountLocked(which); |
| 4566 | } |
| 4567 | |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4568 | @Override public long getMobileRadioActiveUnknownTime(int which) { |
| 4569 | return mMobileRadioActiveUnknownTime.getCountLocked(which); |
| 4570 | } |
| 4571 | |
| 4572 | @Override public int getMobileRadioActiveUnknownCount(int which) { |
| 4573 | return (int)mMobileRadioActiveUnknownCount.getCountLocked(which); |
| 4574 | } |
| 4575 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4576 | @Override public long getWifiOnTime(long elapsedRealtimeUs, int which) { |
| 4577 | return mWifiOnTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4578 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4579 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4580 | @Override public long getGlobalWifiRunningTime(long elapsedRealtimeUs, int which) { |
| 4581 | return mGlobalWifiRunningTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Eric Shienbrood | d4c5f89 | 2009-03-24 18:13:20 -0700 | [diff] [blame] | 4582 | } |
| 4583 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4584 | @Override public long getWifiStateTime(int wifiState, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4585 | long elapsedRealtimeUs, int which) { |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4586 | return mWifiStateTimer[wifiState].getTotalTimeLocked( |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4587 | elapsedRealtimeUs, which); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4588 | } |
| 4589 | |
| 4590 | @Override public int getWifiStateCount(int wifiState, int which) { |
| 4591 | return mWifiStateTimer[wifiState].getCountLocked(which); |
| 4592 | } |
| 4593 | |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 4594 | @Override public long getWifiSupplStateTime(int state, |
| 4595 | long elapsedRealtimeUs, int which) { |
| 4596 | return mWifiSupplStateTimer[state].getTotalTimeLocked( |
| 4597 | elapsedRealtimeUs, which); |
| 4598 | } |
| 4599 | |
| 4600 | @Override public int getWifiSupplStateCount(int state, int which) { |
| 4601 | return mWifiSupplStateTimer[state].getCountLocked(which); |
| 4602 | } |
| 4603 | |
| 4604 | @Override public long getWifiSignalStrengthTime(int strengthBin, |
| 4605 | long elapsedRealtimeUs, int which) { |
| 4606 | return mWifiSignalStrengthsTimer[strengthBin].getTotalTimeLocked( |
| 4607 | elapsedRealtimeUs, which); |
| 4608 | } |
| 4609 | |
| 4610 | @Override public int getWifiSignalStrengthCount(int strengthBin, int which) { |
| 4611 | return mWifiSignalStrengthsTimer[strengthBin].getCountLocked(which); |
| 4612 | } |
| 4613 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 4614 | @Override |
| 4615 | public ControllerActivityCounter getBluetoothControllerActivity() { |
| 4616 | return mBluetoothActivity; |
Adam Lesinski | 1739076 | 2015-04-10 13:17:47 -0700 | [diff] [blame] | 4617 | } |
| 4618 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 4619 | @Override |
| 4620 | public ControllerActivityCounter getWifiControllerActivity() { |
| 4621 | return mWifiActivity; |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 4622 | } |
| 4623 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 4624 | @Override |
| 4625 | public ControllerActivityCounter getModemControllerActivity() { |
| 4626 | return mModemActivity; |
Adam Lesinski | 1739076 | 2015-04-10 13:17:47 -0700 | [diff] [blame] | 4627 | } |
| 4628 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 4629 | @Override |
| 4630 | public boolean hasBluetoothActivityReporting() { |
| 4631 | return mHasBluetoothReporting; |
| 4632 | } |
| 4633 | |
| 4634 | @Override |
| 4635 | public boolean hasWifiActivityReporting() { |
| 4636 | return mHasWifiReporting; |
| 4637 | } |
| 4638 | |
| 4639 | @Override |
| 4640 | public boolean hasModemActivityReporting() { |
| 4641 | return mHasModemReporting; |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 4642 | } |
| 4643 | |
Ruben Brunk | 5b1308f | 2015-06-03 18:49:27 -0700 | [diff] [blame] | 4644 | @Override |
| 4645 | public long getFlashlightOnTime(long elapsedRealtimeUs, int which) { |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 4646 | return mFlashlightOnTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
| 4647 | } |
| 4648 | |
Ruben Brunk | 5b1308f | 2015-06-03 18:49:27 -0700 | [diff] [blame] | 4649 | @Override |
| 4650 | public long getFlashlightOnCount(int which) { |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 4651 | return mFlashlightOnTimer.getCountLocked(which); |
| 4652 | } |
| 4653 | |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 4654 | @Override |
Ruben Brunk | 5b1308f | 2015-06-03 18:49:27 -0700 | [diff] [blame] | 4655 | public long getCameraOnTime(long elapsedRealtimeUs, int which) { |
| 4656 | return mCameraOnTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
| 4657 | } |
| 4658 | |
| 4659 | @Override |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 4660 | public long getBluetoothScanTime(long elapsedRealtimeUs, int which) { |
| 4661 | return mBluetoothScanTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
| 4662 | } |
| 4663 | |
| 4664 | @Override |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4665 | public long getNetworkActivityBytes(int type, int which) { |
| 4666 | if (type >= 0 && type < mNetworkByteActivityCounters.length) { |
| 4667 | return mNetworkByteActivityCounters[type].getCountLocked(which); |
| 4668 | } else { |
| 4669 | return 0; |
| 4670 | } |
| 4671 | } |
| 4672 | |
| 4673 | @Override |
| 4674 | public long getNetworkActivityPackets(int type, int which) { |
| 4675 | if (type >= 0 && type < mNetworkPacketActivityCounters.length) { |
| 4676 | return mNetworkPacketActivityCounters[type].getCountLocked(which); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 4677 | } else { |
| 4678 | return 0; |
| 4679 | } |
| 4680 | } |
| 4681 | |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 4682 | @Override public long getStartClockTime() { |
Dianne Hackborn | d48954f | 2015-07-22 17:20:33 -0700 | [diff] [blame] | 4683 | final long currentTime = System.currentTimeMillis(); |
| 4684 | if (ensureStartClockTime(currentTime)) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4685 | recordCurrentTimeChangeLocked(currentTime, mClocks.elapsedRealtime(), |
| 4686 | mClocks.uptimeMillis()); |
Dianne Hackborn | 7d9eefd | 2014-08-27 18:30:31 -0700 | [diff] [blame] | 4687 | } |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 4688 | return mStartClockTime; |
| 4689 | } |
| 4690 | |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 4691 | @Override public String getStartPlatformVersion() { |
| 4692 | return mStartPlatformVersion; |
| 4693 | } |
| 4694 | |
| 4695 | @Override public String getEndPlatformVersion() { |
| 4696 | return mEndPlatformVersion; |
| 4697 | } |
| 4698 | |
| 4699 | @Override public int getParcelVersion() { |
| 4700 | return VERSION; |
| 4701 | } |
| 4702 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4703 | @Override public boolean getIsOnBattery() { |
| 4704 | return mOnBattery; |
| 4705 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4706 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4707 | @Override public SparseArray<? extends BatteryStats.Uid> getUidStats() { |
| 4708 | return mUidStats; |
| 4709 | } |
| 4710 | |
| 4711 | /** |
| 4712 | * The statistics associated with a particular uid. |
| 4713 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4714 | public static class Uid extends BatteryStats.Uid { |
| 4715 | /** |
| 4716 | * BatteryStatsImpl that we are associated with. |
| 4717 | */ |
| 4718 | protected BatteryStatsImpl mBsi; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4719 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4720 | final int mUid; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4721 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 4722 | boolean mWifiRunning; |
| 4723 | StopwatchTimer mWifiRunningTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4724 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4725 | boolean mFullWifiLockOut; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 4726 | StopwatchTimer mFullWifiLockTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4727 | |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 4728 | boolean mWifiScanStarted; |
| 4729 | StopwatchTimer mWifiScanTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4730 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 4731 | static final int NO_BATCHED_SCAN_STARTED = -1; |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 4732 | int mWifiBatchedScanBinStarted = NO_BATCHED_SCAN_STARTED; |
| 4733 | StopwatchTimer[] mWifiBatchedScanTimer; |
| 4734 | |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 4735 | boolean mWifiMulticastEnabled; |
| 4736 | StopwatchTimer mWifiMulticastTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4737 | |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 4738 | StopwatchTimer mAudioTurnedOnTimer; |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 4739 | StopwatchTimer mVideoTurnedOnTimer; |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 4740 | StopwatchTimer mFlashlightTurnedOnTimer; |
| 4741 | StopwatchTimer mCameraTurnedOnTimer; |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 4742 | StopwatchTimer mForegroundActivityTimer; |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 4743 | StopwatchTimer mBluetoothScanTimer; |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 4744 | |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 4745 | int mProcessState = ActivityManager.PROCESS_STATE_NONEXISTENT; |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 4746 | StopwatchTimer[] mProcessStateTimer; |
| 4747 | |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 4748 | BatchTimer mVibratorOnTimer; |
| 4749 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4750 | Counter[] mUserActivityCounters; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4751 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4752 | LongSamplingCounter[] mNetworkByteActivityCounters; |
| 4753 | LongSamplingCounter[] mNetworkPacketActivityCounters; |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4754 | LongSamplingCounter mMobileRadioActiveTime; |
| 4755 | LongSamplingCounter mMobileRadioActiveCount; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 4756 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4757 | /** |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 4758 | * The amount of time this uid has kept the WiFi controller in idle, tx, and rx mode. |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 4759 | * Can be null if the UID has had no such activity. |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 4760 | */ |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 4761 | private ControllerActivityCounterImpl mWifiControllerActivity; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 4762 | |
| 4763 | /** |
| 4764 | * The amount of time this uid has kept the Bluetooth controller in idle, tx, and rx mode. |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 4765 | * Can be null if the UID has had no such activity. |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 4766 | */ |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 4767 | private ControllerActivityCounterImpl mBluetoothControllerActivity; |
| 4768 | |
| 4769 | /** |
| 4770 | * The amount of time this uid has kept the Modem controller in idle, tx, and rx mode. |
| 4771 | * Can be null if the UID has had no such activity. |
| 4772 | */ |
| 4773 | private ControllerActivityCounterImpl mModemControllerActivity; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 4774 | |
| 4775 | /** |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 4776 | * The CPU times we had at the last history details update. |
| 4777 | */ |
| 4778 | long mLastStepUserTime; |
| 4779 | long mLastStepSystemTime; |
| 4780 | long mCurStepUserTime; |
| 4781 | long mCurStepSystemTime; |
| 4782 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4783 | LongSamplingCounter mUserCpuTime; |
| 4784 | LongSamplingCounter mSystemCpuTime; |
| 4785 | LongSamplingCounter mCpuPower; |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 4786 | LongSamplingCounter[][] mCpuClusterSpeed; |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 4787 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 4788 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4789 | * The statistics we have collected for this uid's wake locks. |
| 4790 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4791 | final OverflowArrayMap<Wakelock> mWakelockStats; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4792 | |
| 4793 | /** |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 4794 | * The statistics we have collected for this uid's syncs. |
| 4795 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4796 | final OverflowArrayMap<StopwatchTimer> mSyncStats; |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 4797 | |
| 4798 | /** |
| 4799 | * The statistics we have collected for this uid's jobs. |
| 4800 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4801 | final OverflowArrayMap<StopwatchTimer> mJobStats; |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 4802 | |
| 4803 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4804 | * The statistics we have collected for this uid's sensor activations. |
| 4805 | */ |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 4806 | final SparseArray<Sensor> mSensorStats = new SparseArray<>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4807 | |
| 4808 | /** |
| 4809 | * The statistics we have collected for this uid's processes. |
| 4810 | */ |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 4811 | final ArrayMap<String, Proc> mProcessStats = new ArrayMap<>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4812 | |
| 4813 | /** |
| 4814 | * The statistics we have collected for this uid's processes. |
| 4815 | */ |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 4816 | final ArrayMap<String, Pkg> mPackageStats = new ArrayMap<>(); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4817 | |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4818 | /** |
| 4819 | * The transient wake stats we have collected for this uid's pids. |
| 4820 | */ |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 4821 | final SparseArray<Pid> mPids = new SparseArray<>(); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4822 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4823 | public Uid(BatteryStatsImpl bsi, int uid) { |
| 4824 | mBsi = bsi; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4825 | mUid = uid; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4826 | |
| 4827 | mUserCpuTime = new LongSamplingCounter(mBsi.mOnBatteryTimeBase); |
| 4828 | mSystemCpuTime = new LongSamplingCounter(mBsi.mOnBatteryTimeBase); |
| 4829 | mCpuPower = new LongSamplingCounter(mBsi.mOnBatteryTimeBase); |
| 4830 | |
| 4831 | mWakelockStats = mBsi.new OverflowArrayMap<Wakelock>() { |
| 4832 | @Override public Wakelock instantiateObject() { |
| 4833 | return new Wakelock(mBsi, Uid.this); |
| 4834 | } |
| 4835 | }; |
| 4836 | mSyncStats = mBsi.new OverflowArrayMap<StopwatchTimer>() { |
| 4837 | @Override public StopwatchTimer instantiateObject() { |
| 4838 | return new StopwatchTimer(mBsi.mClocks, Uid.this, SYNC, null, |
| 4839 | mBsi.mOnBatteryTimeBase); |
| 4840 | } |
| 4841 | }; |
| 4842 | mJobStats = mBsi.new OverflowArrayMap<StopwatchTimer>() { |
| 4843 | @Override public StopwatchTimer instantiateObject() { |
| 4844 | return new StopwatchTimer(mBsi.mClocks, Uid.this, JOB, null, |
| 4845 | mBsi.mOnBatteryTimeBase); |
| 4846 | } |
| 4847 | }; |
| 4848 | |
| 4849 | mWifiRunningTimer = new StopwatchTimer(mBsi.mClocks, this, WIFI_RUNNING, |
| 4850 | mBsi.mWifiRunningTimers, mBsi.mOnBatteryTimeBase); |
| 4851 | mFullWifiLockTimer = new StopwatchTimer(mBsi.mClocks, this, FULL_WIFI_LOCK, |
| 4852 | mBsi.mFullWifiLockTimers, mBsi.mOnBatteryTimeBase); |
| 4853 | mWifiScanTimer = new StopwatchTimer(mBsi.mClocks, this, WIFI_SCAN, |
| 4854 | mBsi.mWifiScanTimers, mBsi.mOnBatteryTimeBase); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 4855 | mWifiBatchedScanTimer = new StopwatchTimer[NUM_WIFI_BATCHED_SCAN_BINS]; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4856 | mWifiMulticastTimer = new StopwatchTimer(mBsi.mClocks, this, WIFI_MULTICAST_ENABLED, |
| 4857 | mBsi.mWifiMulticastTimers, mBsi.mOnBatteryTimeBase); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 4858 | mProcessStateTimer = new StopwatchTimer[NUM_PROCESS_STATE]; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4859 | } |
| 4860 | |
| 4861 | @Override |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4862 | public ArrayMap<String, ? extends BatteryStats.Uid.Wakelock> getWakelockStats() { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 4863 | return mWakelockStats.getMap(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4864 | } |
| 4865 | |
| 4866 | @Override |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4867 | public ArrayMap<String, ? extends BatteryStats.Timer> getSyncStats() { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 4868 | return mSyncStats.getMap(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 4869 | } |
| 4870 | |
| 4871 | @Override |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4872 | public ArrayMap<String, ? extends BatteryStats.Timer> getJobStats() { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 4873 | return mJobStats.getMap(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 4874 | } |
| 4875 | |
| 4876 | @Override |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 4877 | public SparseArray<? extends BatteryStats.Uid.Sensor> getSensorStats() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4878 | return mSensorStats; |
| 4879 | } |
| 4880 | |
| 4881 | @Override |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4882 | public ArrayMap<String, ? extends BatteryStats.Uid.Proc> getProcessStats() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4883 | return mProcessStats; |
| 4884 | } |
| 4885 | |
| 4886 | @Override |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 4887 | public ArrayMap<String, ? extends BatteryStats.Uid.Pkg> getPackageStats() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4888 | return mPackageStats; |
| 4889 | } |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 4890 | |
| 4891 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4892 | public int getUid() { |
| 4893 | return mUid; |
| 4894 | } |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 4895 | |
| 4896 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4897 | public void noteWifiRunningLocked(long elapsedRealtimeMs) { |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 4898 | if (!mWifiRunning) { |
| 4899 | mWifiRunning = true; |
| 4900 | if (mWifiRunningTimer == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4901 | mWifiRunningTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, WIFI_RUNNING, |
| 4902 | mBsi.mWifiRunningTimers, mBsi.mOnBatteryTimeBase); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4903 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4904 | mWifiRunningTimer.startRunningLocked(elapsedRealtimeMs); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4905 | } |
| 4906 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4907 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4908 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4909 | public void noteWifiStoppedLocked(long elapsedRealtimeMs) { |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 4910 | if (mWifiRunning) { |
| 4911 | mWifiRunning = false; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4912 | mWifiRunningTimer.stopRunningLocked(elapsedRealtimeMs); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4913 | } |
| 4914 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4915 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4916 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4917 | public void noteFullWifiLockAcquiredLocked(long elapsedRealtimeMs) { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4918 | if (!mFullWifiLockOut) { |
| 4919 | mFullWifiLockOut = true; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4920 | if (mFullWifiLockTimer == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4921 | mFullWifiLockTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, FULL_WIFI_LOCK, |
| 4922 | mBsi.mFullWifiLockTimers, mBsi.mOnBatteryTimeBase); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4923 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4924 | mFullWifiLockTimer.startRunningLocked(elapsedRealtimeMs); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4925 | } |
| 4926 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4927 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4928 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4929 | public void noteFullWifiLockReleasedLocked(long elapsedRealtimeMs) { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4930 | if (mFullWifiLockOut) { |
| 4931 | mFullWifiLockOut = false; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4932 | mFullWifiLockTimer.stopRunningLocked(elapsedRealtimeMs); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4933 | } |
| 4934 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4935 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4936 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4937 | public void noteWifiScanStartedLocked(long elapsedRealtimeMs) { |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 4938 | if (!mWifiScanStarted) { |
| 4939 | mWifiScanStarted = true; |
| 4940 | if (mWifiScanTimer == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4941 | mWifiScanTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, WIFI_SCAN, |
| 4942 | mBsi.mWifiScanTimers, mBsi.mOnBatteryTimeBase); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4943 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4944 | mWifiScanTimer.startRunningLocked(elapsedRealtimeMs); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4945 | } |
| 4946 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4947 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4948 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4949 | public void noteWifiScanStoppedLocked(long elapsedRealtimeMs) { |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 4950 | if (mWifiScanStarted) { |
| 4951 | mWifiScanStarted = false; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4952 | mWifiScanTimer.stopRunningLocked(elapsedRealtimeMs); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4953 | } |
| 4954 | } |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 4955 | |
| 4956 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4957 | public void noteWifiBatchedScanStartedLocked(int csph, long elapsedRealtimeMs) { |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 4958 | int bin = 0; |
Navtej Singh Mann | 3c0ce5c | 2015-06-11 16:53:11 -0700 | [diff] [blame] | 4959 | while (csph > 8 && bin < NUM_WIFI_BATCHED_SCAN_BINS-1) { |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 4960 | csph = csph >> 3; |
| 4961 | bin++; |
| 4962 | } |
| 4963 | |
| 4964 | if (mWifiBatchedScanBinStarted == bin) return; |
| 4965 | |
| 4966 | if (mWifiBatchedScanBinStarted != NO_BATCHED_SCAN_STARTED) { |
| 4967 | mWifiBatchedScanTimer[mWifiBatchedScanBinStarted]. |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4968 | stopRunningLocked(elapsedRealtimeMs); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 4969 | } |
| 4970 | mWifiBatchedScanBinStarted = bin; |
| 4971 | if (mWifiBatchedScanTimer[bin] == null) { |
| 4972 | makeWifiBatchedScanBin(bin, null); |
| 4973 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4974 | mWifiBatchedScanTimer[bin].startRunningLocked(elapsedRealtimeMs); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 4975 | } |
| 4976 | |
| 4977 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4978 | public void noteWifiBatchedScanStoppedLocked(long elapsedRealtimeMs) { |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 4979 | if (mWifiBatchedScanBinStarted != NO_BATCHED_SCAN_STARTED) { |
| 4980 | mWifiBatchedScanTimer[mWifiBatchedScanBinStarted]. |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4981 | stopRunningLocked(elapsedRealtimeMs); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 4982 | mWifiBatchedScanBinStarted = NO_BATCHED_SCAN_STARTED; |
| 4983 | } |
| 4984 | } |
| 4985 | |
| 4986 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4987 | public void noteWifiMulticastEnabledLocked(long elapsedRealtimeMs) { |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 4988 | if (!mWifiMulticastEnabled) { |
| 4989 | mWifiMulticastEnabled = true; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4990 | if (mWifiMulticastTimer == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4991 | mWifiMulticastTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, |
| 4992 | WIFI_MULTICAST_ENABLED, mBsi.mWifiMulticastTimers, mBsi.mOnBatteryTimeBase); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4993 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4994 | mWifiMulticastTimer.startRunningLocked(elapsedRealtimeMs); |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 4995 | } |
| 4996 | } |
| 4997 | |
| 4998 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4999 | public void noteWifiMulticastDisabledLocked(long elapsedRealtimeMs) { |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 5000 | if (mWifiMulticastEnabled) { |
| 5001 | mWifiMulticastEnabled = false; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5002 | mWifiMulticastTimer.stopRunningLocked(elapsedRealtimeMs); |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 5003 | } |
| 5004 | } |
| 5005 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 5006 | @Override |
| 5007 | public ControllerActivityCounter getWifiControllerActivity() { |
| 5008 | return mWifiControllerActivity; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 5009 | } |
| 5010 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 5011 | @Override |
| 5012 | public ControllerActivityCounter getBluetoothControllerActivity() { |
| 5013 | return mBluetoothControllerActivity; |
| 5014 | } |
| 5015 | |
| 5016 | @Override |
| 5017 | public ControllerActivityCounter getModemControllerActivity() { |
| 5018 | return mModemControllerActivity; |
| 5019 | } |
| 5020 | |
| 5021 | public ControllerActivityCounterImpl getOrCreateWifiControllerActivityLocked() { |
| 5022 | if (mWifiControllerActivity == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5023 | mWifiControllerActivity = new ControllerActivityCounterImpl(mBsi.mOnBatteryTimeBase, |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 5024 | NUM_BT_TX_LEVELS); |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 5025 | } |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 5026 | return mWifiControllerActivity; |
| 5027 | } |
| 5028 | |
| 5029 | public ControllerActivityCounterImpl getOrCreateBluetoothControllerActivityLocked() { |
| 5030 | if (mBluetoothControllerActivity == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5031 | mBluetoothControllerActivity = new ControllerActivityCounterImpl(mBsi.mOnBatteryTimeBase, |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 5032 | NUM_BT_TX_LEVELS); |
| 5033 | } |
| 5034 | return mBluetoothControllerActivity; |
| 5035 | } |
| 5036 | |
| 5037 | public ControllerActivityCounterImpl getOrCreateModemControllerActivityLocked() { |
| 5038 | if (mModemControllerActivity == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5039 | mModemControllerActivity = new ControllerActivityCounterImpl(mBsi.mOnBatteryTimeBase, |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 5040 | ModemActivityInfo.TX_POWER_LEVELS); |
| 5041 | } |
| 5042 | return mModemControllerActivity; |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 5043 | } |
| 5044 | |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 5045 | public StopwatchTimer createAudioTurnedOnTimerLocked() { |
| 5046 | if (mAudioTurnedOnTimer == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5047 | mAudioTurnedOnTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, AUDIO_TURNED_ON, |
| 5048 | mBsi.mAudioTurnedOnTimers, mBsi.mOnBatteryTimeBase); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 5049 | } |
| 5050 | return mAudioTurnedOnTimer; |
| 5051 | } |
| 5052 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5053 | public void noteAudioTurnedOnLocked(long elapsedRealtimeMs) { |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 5054 | createAudioTurnedOnTimerLocked().startRunningLocked(elapsedRealtimeMs); |
| 5055 | } |
| 5056 | |
| 5057 | public void noteAudioTurnedOffLocked(long elapsedRealtimeMs) { |
| 5058 | if (mAudioTurnedOnTimer != null) { |
| 5059 | mAudioTurnedOnTimer.stopRunningLocked(elapsedRealtimeMs); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5060 | } |
| 5061 | } |
| 5062 | |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 5063 | public void noteResetAudioLocked(long elapsedRealtimeMs) { |
| 5064 | if (mAudioTurnedOnTimer != null) { |
| 5065 | mAudioTurnedOnTimer.stopAllRunningLocked(elapsedRealtimeMs); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5066 | } |
| 5067 | } |
| 5068 | |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 5069 | public StopwatchTimer createVideoTurnedOnTimerLocked() { |
| 5070 | if (mVideoTurnedOnTimer == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5071 | mVideoTurnedOnTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, VIDEO_TURNED_ON, |
| 5072 | mBsi.mVideoTurnedOnTimers, mBsi.mOnBatteryTimeBase); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 5073 | } |
| 5074 | return mVideoTurnedOnTimer; |
| 5075 | } |
| 5076 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5077 | public void noteVideoTurnedOnLocked(long elapsedRealtimeMs) { |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 5078 | createVideoTurnedOnTimerLocked().startRunningLocked(elapsedRealtimeMs); |
| 5079 | } |
| 5080 | |
| 5081 | public void noteVideoTurnedOffLocked(long elapsedRealtimeMs) { |
| 5082 | if (mVideoTurnedOnTimer != null) { |
| 5083 | mVideoTurnedOnTimer.stopRunningLocked(elapsedRealtimeMs); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5084 | } |
| 5085 | } |
| 5086 | |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 5087 | public void noteResetVideoLocked(long elapsedRealtimeMs) { |
| 5088 | if (mVideoTurnedOnTimer != null) { |
| 5089 | mVideoTurnedOnTimer.stopAllRunningLocked(elapsedRealtimeMs); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 5090 | } |
| 5091 | } |
| 5092 | |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 5093 | public StopwatchTimer createFlashlightTurnedOnTimerLocked() { |
| 5094 | if (mFlashlightTurnedOnTimer == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5095 | mFlashlightTurnedOnTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, |
| 5096 | FLASHLIGHT_TURNED_ON, mBsi.mFlashlightTurnedOnTimers, mBsi.mOnBatteryTimeBase); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 5097 | } |
| 5098 | return mFlashlightTurnedOnTimer; |
| 5099 | } |
| 5100 | |
| 5101 | public void noteFlashlightTurnedOnLocked(long elapsedRealtimeMs) { |
| 5102 | createFlashlightTurnedOnTimerLocked().startRunningLocked(elapsedRealtimeMs); |
| 5103 | } |
| 5104 | |
| 5105 | public void noteFlashlightTurnedOffLocked(long elapsedRealtimeMs) { |
| 5106 | if (mFlashlightTurnedOnTimer != null) { |
| 5107 | mFlashlightTurnedOnTimer.stopRunningLocked(elapsedRealtimeMs); |
| 5108 | } |
| 5109 | } |
| 5110 | |
| 5111 | public void noteResetFlashlightLocked(long elapsedRealtimeMs) { |
| 5112 | if (mFlashlightTurnedOnTimer != null) { |
| 5113 | mFlashlightTurnedOnTimer.stopAllRunningLocked(elapsedRealtimeMs); |
| 5114 | } |
| 5115 | } |
| 5116 | |
| 5117 | public StopwatchTimer createCameraTurnedOnTimerLocked() { |
| 5118 | if (mCameraTurnedOnTimer == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5119 | mCameraTurnedOnTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, CAMERA_TURNED_ON, |
| 5120 | mBsi.mCameraTurnedOnTimers, mBsi.mOnBatteryTimeBase); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 5121 | } |
| 5122 | return mCameraTurnedOnTimer; |
| 5123 | } |
| 5124 | |
| 5125 | public void noteCameraTurnedOnLocked(long elapsedRealtimeMs) { |
| 5126 | createCameraTurnedOnTimerLocked().startRunningLocked(elapsedRealtimeMs); |
| 5127 | } |
| 5128 | |
| 5129 | public void noteCameraTurnedOffLocked(long elapsedRealtimeMs) { |
| 5130 | if (mCameraTurnedOnTimer != null) { |
| 5131 | mCameraTurnedOnTimer.stopRunningLocked(elapsedRealtimeMs); |
| 5132 | } |
| 5133 | } |
| 5134 | |
| 5135 | public void noteResetCameraLocked(long elapsedRealtimeMs) { |
| 5136 | if (mCameraTurnedOnTimer != null) { |
| 5137 | mCameraTurnedOnTimer.stopAllRunningLocked(elapsedRealtimeMs); |
| 5138 | } |
| 5139 | } |
| 5140 | |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 5141 | public StopwatchTimer createForegroundActivityTimerLocked() { |
| 5142 | if (mForegroundActivityTimer == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5143 | mForegroundActivityTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, |
| 5144 | FOREGROUND_ACTIVITY, null, mBsi.mOnBatteryTimeBase); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 5145 | } |
| 5146 | return mForegroundActivityTimer; |
| 5147 | } |
| 5148 | |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 5149 | public StopwatchTimer createBluetoothScanTimerLocked() { |
| 5150 | if (mBluetoothScanTimer == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5151 | mBluetoothScanTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, BLUETOOTH_SCAN_ON, |
| 5152 | mBsi.mBluetoothScanOnTimers, mBsi.mOnBatteryTimeBase); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 5153 | } |
| 5154 | return mBluetoothScanTimer; |
| 5155 | } |
| 5156 | |
| 5157 | public void noteBluetoothScanStartedLocked(long elapsedRealtimeMs) { |
| 5158 | createBluetoothScanTimerLocked().startRunningLocked(elapsedRealtimeMs); |
| 5159 | } |
| 5160 | |
| 5161 | public void noteBluetoothScanStoppedLocked(long elapsedRealtimeMs) { |
| 5162 | if (mBluetoothScanTimer != null) { |
| 5163 | mBluetoothScanTimer.stopRunningLocked(elapsedRealtimeMs); |
| 5164 | } |
| 5165 | } |
| 5166 | |
| 5167 | public void noteResetBluetoothScanLocked(long elapsedRealtimeMs) { |
| 5168 | if (mBluetoothScanTimer != null) { |
| 5169 | mBluetoothScanTimer.stopAllRunningLocked(elapsedRealtimeMs); |
| 5170 | } |
| 5171 | } |
| 5172 | |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 5173 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5174 | public void noteActivityResumedLocked(long elapsedRealtimeMs) { |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 5175 | // We always start, since we want multiple foreground PIDs to nest |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5176 | createForegroundActivityTimerLocked().startRunningLocked(elapsedRealtimeMs); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 5177 | } |
| 5178 | |
| 5179 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5180 | public void noteActivityPausedLocked(long elapsedRealtimeMs) { |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 5181 | if (mForegroundActivityTimer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5182 | mForegroundActivityTimer.stopRunningLocked(elapsedRealtimeMs); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 5183 | } |
| 5184 | } |
| 5185 | |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 5186 | public BatchTimer createVibratorOnTimerLocked() { |
| 5187 | if (mVibratorOnTimer == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5188 | mVibratorOnTimer = new BatchTimer(mBsi.mClocks, Uid.this, VIBRATOR_ON, |
| 5189 | mBsi.mOnBatteryTimeBase); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 5190 | } |
| 5191 | return mVibratorOnTimer; |
| 5192 | } |
| 5193 | |
| 5194 | public void noteVibratorOnLocked(long durationMillis) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5195 | createVibratorOnTimerLocked().addDuration(mBsi, durationMillis); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 5196 | } |
| 5197 | |
| 5198 | public void noteVibratorOffLocked() { |
| 5199 | if (mVibratorOnTimer != null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5200 | mVibratorOnTimer.abortLastDuration(mBsi); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5201 | } |
| 5202 | } |
| 5203 | |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5204 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5205 | public long getWifiRunningTime(long elapsedRealtimeUs, int which) { |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 5206 | if (mWifiRunningTimer == null) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5207 | return 0; |
| 5208 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5209 | return mWifiRunningTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 5210 | } |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 5211 | |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5212 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5213 | public long getFullWifiLockTime(long elapsedRealtimeUs, int which) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5214 | if (mFullWifiLockTimer == null) { |
| 5215 | return 0; |
| 5216 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5217 | return mFullWifiLockTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 5218 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5219 | |
| 5220 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5221 | public long getWifiScanTime(long elapsedRealtimeUs, int which) { |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 5222 | if (mWifiScanTimer == null) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5223 | return 0; |
| 5224 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5225 | return mWifiScanTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 5226 | } |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 5227 | |
| 5228 | @Override |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 5229 | public int getWifiScanCount(int which) { |
| 5230 | if (mWifiScanTimer == null) { |
| 5231 | return 0; |
| 5232 | } |
| 5233 | return mWifiScanTimer.getCountLocked(which); |
| 5234 | } |
| 5235 | |
| 5236 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5237 | public long getWifiBatchedScanTime(int csphBin, long elapsedRealtimeUs, int which) { |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 5238 | if (csphBin < 0 || csphBin >= NUM_WIFI_BATCHED_SCAN_BINS) return 0; |
| 5239 | if (mWifiBatchedScanTimer[csphBin] == null) { |
| 5240 | return 0; |
| 5241 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5242 | return mWifiBatchedScanTimer[csphBin].getTotalTimeLocked(elapsedRealtimeUs, which); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 5243 | } |
| 5244 | |
| 5245 | @Override |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 5246 | public int getWifiBatchedScanCount(int csphBin, int which) { |
| 5247 | if (csphBin < 0 || csphBin >= NUM_WIFI_BATCHED_SCAN_BINS) return 0; |
| 5248 | if (mWifiBatchedScanTimer[csphBin] == null) { |
| 5249 | return 0; |
| 5250 | } |
| 5251 | return mWifiBatchedScanTimer[csphBin].getCountLocked(which); |
| 5252 | } |
| 5253 | |
| 5254 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5255 | public long getWifiMulticastTime(long elapsedRealtimeUs, int which) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5256 | if (mWifiMulticastTimer == null) { |
| 5257 | return 0; |
| 5258 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5259 | return mWifiMulticastTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 5260 | } |
| 5261 | |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5262 | @Override |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 5263 | public Timer getAudioTurnedOnTimer() { |
| 5264 | return mAudioTurnedOnTimer; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5265 | } |
| 5266 | |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5267 | @Override |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 5268 | public Timer getVideoTurnedOnTimer() { |
| 5269 | return mVideoTurnedOnTimer; |
| 5270 | } |
| 5271 | |
| 5272 | @Override |
| 5273 | public Timer getFlashlightTurnedOnTimer() { |
| 5274 | return mFlashlightTurnedOnTimer; |
| 5275 | } |
| 5276 | |
| 5277 | @Override |
| 5278 | public Timer getCameraTurnedOnTimer() { |
| 5279 | return mCameraTurnedOnTimer; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5280 | } |
| 5281 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 5282 | @Override |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 5283 | public Timer getForegroundActivityTimer() { |
| 5284 | return mForegroundActivityTimer; |
| 5285 | } |
| 5286 | |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 5287 | @Override |
| 5288 | public Timer getBluetoothScanTimer() { |
| 5289 | return mBluetoothScanTimer; |
| 5290 | } |
| 5291 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5292 | void makeProcessState(int i, Parcel in) { |
| 5293 | if (i < 0 || i >= NUM_PROCESS_STATE) return; |
| 5294 | |
| 5295 | if (in == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5296 | mProcessStateTimer[i] = new StopwatchTimer(mBsi.mClocks, this, PROCESS_STATE, null, |
| 5297 | mBsi.mOnBatteryTimeBase); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5298 | } else { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5299 | mProcessStateTimer[i] = new StopwatchTimer(mBsi.mClocks, this, PROCESS_STATE, null, |
| 5300 | mBsi.mOnBatteryTimeBase, in); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5301 | } |
| 5302 | } |
| 5303 | |
| 5304 | @Override |
| 5305 | public long getProcessStateTime(int state, long elapsedRealtimeUs, int which) { |
| 5306 | if (state < 0 || state >= NUM_PROCESS_STATE) return 0; |
| 5307 | if (mProcessStateTimer[state] == null) { |
| 5308 | return 0; |
| 5309 | } |
| 5310 | return mProcessStateTimer[state].getTotalTimeLocked(elapsedRealtimeUs, which); |
| 5311 | } |
| 5312 | |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 5313 | @Override |
Joe Onorato | 713fec8 | 2016-03-04 10:34:02 -0800 | [diff] [blame] | 5314 | public Timer getProcessStateTimer(int state) { |
| 5315 | if (state < 0 || state >= NUM_PROCESS_STATE) return null; |
| 5316 | return mProcessStateTimer[state]; |
| 5317 | } |
| 5318 | |
| 5319 | @Override |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 5320 | public Timer getVibratorOnTimer() { |
| 5321 | return mVibratorOnTimer; |
| 5322 | } |
| 5323 | |
| 5324 | @Override |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 5325 | public void noteUserActivityLocked(int type) { |
| 5326 | if (mUserActivityCounters == null) { |
| 5327 | initUserActivityLocked(); |
| 5328 | } |
Jeff Brown | df693de | 2012-07-27 12:03:38 -0700 | [diff] [blame] | 5329 | if (type >= 0 && type < NUM_USER_ACTIVITY_TYPES) { |
| 5330 | mUserActivityCounters[type].stepAtomic(); |
| 5331 | } else { |
| 5332 | Slog.w(TAG, "Unknown user activity type " + type + " was specified.", |
| 5333 | new Throwable()); |
| 5334 | } |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 5335 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5336 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 5337 | @Override |
| 5338 | public boolean hasUserActivity() { |
| 5339 | return mUserActivityCounters != null; |
| 5340 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5341 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 5342 | @Override |
| 5343 | public int getUserActivityCount(int type, int which) { |
| 5344 | if (mUserActivityCounters == null) { |
| 5345 | return 0; |
| 5346 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 5347 | return mUserActivityCounters[type].getCountLocked(which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 5348 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5349 | |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 5350 | void makeWifiBatchedScanBin(int i, Parcel in) { |
| 5351 | if (i < 0 || i >= NUM_WIFI_BATCHED_SCAN_BINS) return; |
| 5352 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5353 | ArrayList<StopwatchTimer> collected = mBsi.mWifiBatchedScanTimers.get(i); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 5354 | if (collected == null) { |
| 5355 | collected = new ArrayList<StopwatchTimer>(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5356 | mBsi.mWifiBatchedScanTimers.put(i, collected); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 5357 | } |
| 5358 | if (in == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5359 | mWifiBatchedScanTimer[i] = new StopwatchTimer(mBsi.mClocks, this, WIFI_BATCHED_SCAN, |
| 5360 | collected, mBsi.mOnBatteryTimeBase); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 5361 | } else { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5362 | mWifiBatchedScanTimer[i] = new StopwatchTimer(mBsi.mClocks, this, WIFI_BATCHED_SCAN, |
| 5363 | collected, mBsi.mOnBatteryTimeBase, in); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 5364 | } |
| 5365 | } |
| 5366 | |
| 5367 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 5368 | void initUserActivityLocked() { |
| 5369 | mUserActivityCounters = new Counter[NUM_USER_ACTIVITY_TYPES]; |
| 5370 | for (int i=0; i<NUM_USER_ACTIVITY_TYPES; i++) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5371 | mUserActivityCounters[i] = new Counter(mBsi.mOnBatteryTimeBase); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 5372 | } |
| 5373 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5374 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5375 | void noteNetworkActivityLocked(int type, long deltaBytes, long deltaPackets) { |
| 5376 | if (mNetworkByteActivityCounters == null) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5377 | initNetworkActivityLocked(); |
| 5378 | } |
| 5379 | if (type >= 0 && type < NUM_NETWORK_ACTIVITY_TYPES) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5380 | mNetworkByteActivityCounters[type].addCountLocked(deltaBytes); |
| 5381 | mNetworkPacketActivityCounters[type].addCountLocked(deltaPackets); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5382 | } else { |
| 5383 | Slog.w(TAG, "Unknown network activity type " + type + " was specified.", |
| 5384 | new Throwable()); |
| 5385 | } |
| 5386 | } |
| 5387 | |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 5388 | void noteMobileRadioActiveTimeLocked(long batteryUptime) { |
| 5389 | if (mNetworkByteActivityCounters == null) { |
| 5390 | initNetworkActivityLocked(); |
| 5391 | } |
| 5392 | mMobileRadioActiveTime.addCountLocked(batteryUptime); |
| 5393 | mMobileRadioActiveCount.addCountLocked(1); |
| 5394 | } |
| 5395 | |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5396 | @Override |
| 5397 | public boolean hasNetworkActivity() { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5398 | return mNetworkByteActivityCounters != null; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5399 | } |
| 5400 | |
| 5401 | @Override |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5402 | public long getNetworkActivityBytes(int type, int which) { |
| 5403 | if (mNetworkByteActivityCounters != null && type >= 0 |
| 5404 | && type < mNetworkByteActivityCounters.length) { |
| 5405 | return mNetworkByteActivityCounters[type].getCountLocked(which); |
| 5406 | } else { |
| 5407 | return 0; |
| 5408 | } |
| 5409 | } |
| 5410 | |
| 5411 | @Override |
| 5412 | public long getNetworkActivityPackets(int type, int which) { |
| 5413 | if (mNetworkPacketActivityCounters != null && type >= 0 |
| 5414 | && type < mNetworkPacketActivityCounters.length) { |
| 5415 | return mNetworkPacketActivityCounters[type].getCountLocked(which); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5416 | } else { |
| 5417 | return 0; |
| 5418 | } |
| 5419 | } |
| 5420 | |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 5421 | @Override |
| 5422 | public long getMobileRadioActiveTime(int which) { |
| 5423 | return mMobileRadioActiveTime != null |
| 5424 | ? mMobileRadioActiveTime.getCountLocked(which) : 0; |
| 5425 | } |
| 5426 | |
| 5427 | @Override |
| 5428 | public int getMobileRadioActiveCount(int which) { |
| 5429 | return mMobileRadioActiveCount != null |
| 5430 | ? (int)mMobileRadioActiveCount.getCountLocked(which) : 0; |
| 5431 | } |
| 5432 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 5433 | @Override |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 5434 | public long getUserCpuTimeUs(int which) { |
| 5435 | return mUserCpuTime.getCountLocked(which); |
| 5436 | } |
| 5437 | |
| 5438 | @Override |
| 5439 | public long getSystemCpuTimeUs(int which) { |
| 5440 | return mSystemCpuTime.getCountLocked(which); |
| 5441 | } |
| 5442 | |
| 5443 | @Override |
Adam Lesinski | a7a4ccc | 2015-06-26 17:43:04 -0700 | [diff] [blame] | 5444 | public long getCpuPowerMaUs(int which) { |
| 5445 | return mCpuPower.getCountLocked(which); |
| 5446 | } |
| 5447 | |
| 5448 | @Override |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 5449 | public long getTimeAtCpuSpeed(int cluster, int step, int which) { |
| 5450 | if (mCpuClusterSpeed != null) { |
| 5451 | if (cluster >= 0 && cluster < mCpuClusterSpeed.length) { |
| 5452 | final LongSamplingCounter[] cpuSpeeds = mCpuClusterSpeed[cluster]; |
| 5453 | if (cpuSpeeds != null) { |
| 5454 | if (step >= 0 && step < cpuSpeeds.length) { |
| 5455 | final LongSamplingCounter c = cpuSpeeds[step]; |
| 5456 | if (c != null) { |
| 5457 | return c.getCountLocked(which); |
| 5458 | } |
| 5459 | } |
| 5460 | } |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 5461 | } |
| 5462 | } |
| 5463 | return 0; |
| 5464 | } |
| 5465 | |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5466 | void initNetworkActivityLocked() { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5467 | mNetworkByteActivityCounters = new LongSamplingCounter[NUM_NETWORK_ACTIVITY_TYPES]; |
| 5468 | mNetworkPacketActivityCounters = new LongSamplingCounter[NUM_NETWORK_ACTIVITY_TYPES]; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5469 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5470 | mNetworkByteActivityCounters[i] = new LongSamplingCounter(mBsi.mOnBatteryTimeBase); |
| 5471 | mNetworkPacketActivityCounters[i] = new LongSamplingCounter(mBsi.mOnBatteryTimeBase); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5472 | } |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5473 | mMobileRadioActiveTime = new LongSamplingCounter(mBsi.mOnBatteryTimeBase); |
| 5474 | mMobileRadioActiveCount = new LongSamplingCounter(mBsi.mOnBatteryTimeBase); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5475 | } |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 5476 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5477 | /** |
| 5478 | * Clear all stats for this uid. Returns true if the uid is completely |
| 5479 | * inactive so can be dropped. |
| 5480 | */ |
| 5481 | boolean reset() { |
| 5482 | boolean active = false; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5483 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 5484 | if (mWifiRunningTimer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5485 | active |= !mWifiRunningTimer.reset(false); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 5486 | active |= mWifiRunning; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5487 | } |
| 5488 | if (mFullWifiLockTimer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5489 | active |= !mFullWifiLockTimer.reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5490 | active |= mFullWifiLockOut; |
| 5491 | } |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 5492 | if (mWifiScanTimer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5493 | active |= !mWifiScanTimer.reset(false); |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 5494 | active |= mWifiScanStarted; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5495 | } |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 5496 | if (mWifiBatchedScanTimer != null) { |
| 5497 | for (int i = 0; i < NUM_WIFI_BATCHED_SCAN_BINS; i++) { |
| 5498 | if (mWifiBatchedScanTimer[i] != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5499 | active |= !mWifiBatchedScanTimer[i].reset(false); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 5500 | } |
| 5501 | } |
| 5502 | active |= (mWifiBatchedScanBinStarted != NO_BATCHED_SCAN_STARTED); |
| 5503 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5504 | if (mWifiMulticastTimer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5505 | active |= !mWifiMulticastTimer.reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5506 | active |= mWifiMulticastEnabled; |
| 5507 | } |
| 5508 | if (mAudioTurnedOnTimer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5509 | active |= !mAudioTurnedOnTimer.reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5510 | } |
| 5511 | if (mVideoTurnedOnTimer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5512 | active |= !mVideoTurnedOnTimer.reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5513 | } |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 5514 | if (mFlashlightTurnedOnTimer != null) { |
| 5515 | active |= !mFlashlightTurnedOnTimer.reset(false); |
| 5516 | } |
| 5517 | if (mCameraTurnedOnTimer != null) { |
| 5518 | active |= !mCameraTurnedOnTimer.reset(false); |
| 5519 | } |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 5520 | if (mForegroundActivityTimer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5521 | active |= !mForegroundActivityTimer.reset(false); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 5522 | } |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 5523 | if (mBluetoothScanTimer != null) { |
| 5524 | active |= !mBluetoothScanTimer.reset(false); |
| 5525 | } |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5526 | if (mProcessStateTimer != null) { |
| 5527 | for (int i = 0; i < NUM_PROCESS_STATE; i++) { |
| 5528 | if (mProcessStateTimer[i] != null) { |
| 5529 | active |= !mProcessStateTimer[i].reset(false); |
| 5530 | } |
| 5531 | } |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 5532 | active |= (mProcessState != ActivityManager.PROCESS_STATE_NONEXISTENT); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5533 | } |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 5534 | if (mVibratorOnTimer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5535 | if (mVibratorOnTimer.reset(false)) { |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 5536 | mVibratorOnTimer.detach(); |
| 5537 | mVibratorOnTimer = null; |
| 5538 | } else { |
| 5539 | active = true; |
| 5540 | } |
| 5541 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5542 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5543 | if (mUserActivityCounters != null) { |
| 5544 | for (int i=0; i<NUM_USER_ACTIVITY_TYPES; i++) { |
| 5545 | mUserActivityCounters[i].reset(false); |
| 5546 | } |
| 5547 | } |
| 5548 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5549 | if (mNetworkByteActivityCounters != null) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5550 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5551 | mNetworkByteActivityCounters[i].reset(false); |
| 5552 | mNetworkPacketActivityCounters[i].reset(false); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5553 | } |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 5554 | mMobileRadioActiveTime.reset(false); |
| 5555 | mMobileRadioActiveCount.reset(false); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5556 | } |
| 5557 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 5558 | if (mWifiControllerActivity != null) { |
| 5559 | mWifiControllerActivity.reset(false); |
| 5560 | } |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 5561 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5562 | if (mBsi.mBluetoothActivity != null) { |
| 5563 | mBsi.mBluetoothActivity.reset(false); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 5564 | } |
| 5565 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5566 | if (mBsi.mModemActivity != null) { |
| 5567 | mBsi.mModemActivity.reset(false); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 5568 | } |
| 5569 | |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 5570 | mUserCpuTime.reset(false); |
| 5571 | mSystemCpuTime.reset(false); |
Adam Lesinski | a7a4ccc | 2015-06-26 17:43:04 -0700 | [diff] [blame] | 5572 | mCpuPower.reset(false); |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 5573 | |
| 5574 | if (mCpuClusterSpeed != null) { |
| 5575 | for (LongSamplingCounter[] speeds : mCpuClusterSpeed) { |
| 5576 | if (speeds != null) { |
| 5577 | for (LongSamplingCounter speed : speeds) { |
| 5578 | if (speed != null) { |
| 5579 | speed.reset(false); |
| 5580 | } |
| 5581 | } |
| 5582 | } |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 5583 | } |
| 5584 | } |
| 5585 | |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 5586 | final ArrayMap<String, Wakelock> wakeStats = mWakelockStats.getMap(); |
| 5587 | for (int iw=wakeStats.size()-1; iw>=0; iw--) { |
| 5588 | Wakelock wl = wakeStats.valueAt(iw); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5589 | if (wl.reset()) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 5590 | wakeStats.removeAt(iw); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5591 | } else { |
| 5592 | active = true; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5593 | } |
| 5594 | } |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 5595 | mWakelockStats.cleanup(); |
| 5596 | final ArrayMap<String, StopwatchTimer> syncStats = mSyncStats.getMap(); |
| 5597 | for (int is=syncStats.size()-1; is>=0; is--) { |
| 5598 | StopwatchTimer timer = syncStats.valueAt(is); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 5599 | if (timer.reset(false)) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 5600 | syncStats.removeAt(is); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 5601 | timer.detach(); |
| 5602 | } else { |
| 5603 | active = true; |
| 5604 | } |
| 5605 | } |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 5606 | mSyncStats.cleanup(); |
| 5607 | final ArrayMap<String, StopwatchTimer> jobStats = mJobStats.getMap(); |
| 5608 | for (int ij=jobStats.size()-1; ij>=0; ij--) { |
| 5609 | StopwatchTimer timer = jobStats.valueAt(ij); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 5610 | if (timer.reset(false)) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 5611 | jobStats.removeAt(ij); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 5612 | timer.detach(); |
| 5613 | } else { |
| 5614 | active = true; |
| 5615 | } |
| 5616 | } |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 5617 | mJobStats.cleanup(); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5618 | for (int ise=mSensorStats.size()-1; ise>=0; ise--) { |
| 5619 | Sensor s = mSensorStats.valueAt(ise); |
| 5620 | if (s.reset()) { |
| 5621 | mSensorStats.removeAt(ise); |
| 5622 | } else { |
| 5623 | active = true; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5624 | } |
| 5625 | } |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5626 | for (int ip=mProcessStats.size()-1; ip>=0; ip--) { |
| 5627 | Proc proc = mProcessStats.valueAt(ip); |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 5628 | proc.detach(); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5629 | } |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 5630 | mProcessStats.clear(); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 5631 | if (mPids.size() > 0) { |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 5632 | for (int i=mPids.size()-1; i>=0; i--) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 5633 | Pid pid = mPids.valueAt(i); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 5634 | if (pid.mWakeNesting > 0) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 5635 | active = true; |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 5636 | } else { |
| 5637 | mPids.removeAt(i); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 5638 | } |
| 5639 | } |
| 5640 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5641 | if (mPackageStats.size() > 0) { |
| 5642 | Iterator<Map.Entry<String, Pkg>> it = mPackageStats.entrySet().iterator(); |
| 5643 | while (it.hasNext()) { |
| 5644 | Map.Entry<String, Pkg> pkgEntry = it.next(); |
| 5645 | Pkg p = pkgEntry.getValue(); |
| 5646 | p.detach(); |
| 5647 | if (p.mServiceStats.size() > 0) { |
| 5648 | Iterator<Map.Entry<String, Pkg.Serv>> it2 |
| 5649 | = p.mServiceStats.entrySet().iterator(); |
| 5650 | while (it2.hasNext()) { |
| 5651 | Map.Entry<String, Pkg.Serv> servEntry = it2.next(); |
| 5652 | servEntry.getValue().detach(); |
| 5653 | } |
| 5654 | } |
| 5655 | } |
| 5656 | mPackageStats.clear(); |
| 5657 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5658 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 5659 | mLastStepUserTime = mLastStepSystemTime = 0; |
| 5660 | mCurStepUserTime = mCurStepSystemTime = 0; |
| 5661 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5662 | if (!active) { |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 5663 | if (mWifiRunningTimer != null) { |
| 5664 | mWifiRunningTimer.detach(); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5665 | } |
| 5666 | if (mFullWifiLockTimer != null) { |
| 5667 | mFullWifiLockTimer.detach(); |
| 5668 | } |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 5669 | if (mWifiScanTimer != null) { |
| 5670 | mWifiScanTimer.detach(); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5671 | } |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 5672 | for (int i = 0; i < NUM_WIFI_BATCHED_SCAN_BINS; i++) { |
| 5673 | if (mWifiBatchedScanTimer[i] != null) { |
| 5674 | mWifiBatchedScanTimer[i].detach(); |
| 5675 | } |
| 5676 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5677 | if (mWifiMulticastTimer != null) { |
| 5678 | mWifiMulticastTimer.detach(); |
| 5679 | } |
| 5680 | if (mAudioTurnedOnTimer != null) { |
| 5681 | mAudioTurnedOnTimer.detach(); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 5682 | mAudioTurnedOnTimer = null; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5683 | } |
| 5684 | if (mVideoTurnedOnTimer != null) { |
| 5685 | mVideoTurnedOnTimer.detach(); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 5686 | mVideoTurnedOnTimer = null; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5687 | } |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 5688 | if (mFlashlightTurnedOnTimer != null) { |
| 5689 | mFlashlightTurnedOnTimer.detach(); |
| 5690 | mFlashlightTurnedOnTimer = null; |
| 5691 | } |
| 5692 | if (mCameraTurnedOnTimer != null) { |
| 5693 | mCameraTurnedOnTimer.detach(); |
| 5694 | mCameraTurnedOnTimer = null; |
| 5695 | } |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 5696 | if (mForegroundActivityTimer != null) { |
| 5697 | mForegroundActivityTimer.detach(); |
| 5698 | mForegroundActivityTimer = null; |
| 5699 | } |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 5700 | if (mBluetoothScanTimer != null) { |
| 5701 | mBluetoothScanTimer.detach(); |
| 5702 | mBluetoothScanTimer = null; |
| 5703 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5704 | if (mUserActivityCounters != null) { |
| 5705 | for (int i=0; i<NUM_USER_ACTIVITY_TYPES; i++) { |
| 5706 | mUserActivityCounters[i].detach(); |
| 5707 | } |
| 5708 | } |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5709 | if (mNetworkByteActivityCounters != null) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5710 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5711 | mNetworkByteActivityCounters[i].detach(); |
| 5712 | mNetworkPacketActivityCounters[i].detach(); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5713 | } |
| 5714 | } |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 5715 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 5716 | if (mWifiControllerActivity != null) { |
| 5717 | mWifiControllerActivity.detach(); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 5718 | } |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 5719 | |
| 5720 | if (mBluetoothControllerActivity != null) { |
| 5721 | mBluetoothControllerActivity.detach(); |
| 5722 | } |
| 5723 | |
| 5724 | if (mModemControllerActivity != null) { |
| 5725 | mModemControllerActivity.detach(); |
| 5726 | } |
| 5727 | |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 5728 | mPids.clear(); |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 5729 | |
| 5730 | mUserCpuTime.detach(); |
| 5731 | mSystemCpuTime.detach(); |
Adam Lesinski | a7a4ccc | 2015-06-26 17:43:04 -0700 | [diff] [blame] | 5732 | mCpuPower.detach(); |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 5733 | |
| 5734 | if (mCpuClusterSpeed != null) { |
| 5735 | for (LongSamplingCounter[] cpuSpeeds : mCpuClusterSpeed) { |
| 5736 | if (cpuSpeeds != null) { |
| 5737 | for (LongSamplingCounter c : cpuSpeeds) { |
| 5738 | if (c != null) { |
| 5739 | c.detach(); |
| 5740 | } |
| 5741 | } |
| 5742 | } |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 5743 | } |
| 5744 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5745 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5746 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5747 | return !active; |
| 5748 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5749 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5750 | void writeToParcelLocked(Parcel out, long elapsedRealtimeUs) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 5751 | final ArrayMap<String, Wakelock> wakeStats = mWakelockStats.getMap(); |
| 5752 | int NW = wakeStats.size(); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5753 | out.writeInt(NW); |
| 5754 | for (int iw=0; iw<NW; iw++) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 5755 | out.writeString(wakeStats.keyAt(iw)); |
| 5756 | Uid.Wakelock wakelock = wakeStats.valueAt(iw); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5757 | wakelock.writeToParcelLocked(out, elapsedRealtimeUs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5758 | } |
| 5759 | |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 5760 | final ArrayMap<String, StopwatchTimer> syncStats = mSyncStats.getMap(); |
| 5761 | int NS = syncStats.size(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 5762 | out.writeInt(NS); |
| 5763 | for (int is=0; is<NS; is++) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 5764 | out.writeString(syncStats.keyAt(is)); |
| 5765 | StopwatchTimer timer = syncStats.valueAt(is); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 5766 | Timer.writeTimerToParcel(out, timer, elapsedRealtimeUs); |
| 5767 | } |
| 5768 | |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 5769 | final ArrayMap<String, StopwatchTimer> jobStats = mJobStats.getMap(); |
| 5770 | int NJ = jobStats.size(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 5771 | out.writeInt(NJ); |
| 5772 | for (int ij=0; ij<NJ; ij++) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 5773 | out.writeString(jobStats.keyAt(ij)); |
| 5774 | StopwatchTimer timer = jobStats.valueAt(ij); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 5775 | Timer.writeTimerToParcel(out, timer, elapsedRealtimeUs); |
| 5776 | } |
| 5777 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5778 | int NSE = mSensorStats.size(); |
| 5779 | out.writeInt(NSE); |
| 5780 | for (int ise=0; ise<NSE; ise++) { |
| 5781 | out.writeInt(mSensorStats.keyAt(ise)); |
| 5782 | Uid.Sensor sensor = mSensorStats.valueAt(ise); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5783 | sensor.writeToParcelLocked(out, elapsedRealtimeUs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5784 | } |
| 5785 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5786 | int NP = mProcessStats.size(); |
| 5787 | out.writeInt(NP); |
| 5788 | for (int ip=0; ip<NP; ip++) { |
| 5789 | out.writeString(mProcessStats.keyAt(ip)); |
| 5790 | Uid.Proc proc = mProcessStats.valueAt(ip); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5791 | proc.writeToParcelLocked(out); |
| 5792 | } |
| 5793 | |
| 5794 | out.writeInt(mPackageStats.size()); |
| 5795 | for (Map.Entry<String, Uid.Pkg> pkgEntry : mPackageStats.entrySet()) { |
| 5796 | out.writeString(pkgEntry.getKey()); |
| 5797 | Uid.Pkg pkg = pkgEntry.getValue(); |
| 5798 | pkg.writeToParcelLocked(out); |
| 5799 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5800 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 5801 | if (mWifiRunningTimer != null) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5802 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5803 | mWifiRunningTimer.writeToParcel(out, elapsedRealtimeUs); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 5804 | } else { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5805 | out.writeInt(0); |
| 5806 | } |
| 5807 | if (mFullWifiLockTimer != null) { |
| 5808 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5809 | mFullWifiLockTimer.writeToParcel(out, elapsedRealtimeUs); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5810 | } else { |
| 5811 | out.writeInt(0); |
| 5812 | } |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 5813 | if (mWifiScanTimer != null) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5814 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5815 | mWifiScanTimer.writeToParcel(out, elapsedRealtimeUs); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5816 | } else { |
| 5817 | out.writeInt(0); |
| 5818 | } |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 5819 | for (int i = 0; i < NUM_WIFI_BATCHED_SCAN_BINS; i++) { |
| 5820 | if (mWifiBatchedScanTimer[i] != null) { |
| 5821 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5822 | mWifiBatchedScanTimer[i].writeToParcel(out, elapsedRealtimeUs); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 5823 | } else { |
| 5824 | out.writeInt(0); |
| 5825 | } |
| 5826 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5827 | if (mWifiMulticastTimer != null) { |
| 5828 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5829 | mWifiMulticastTimer.writeToParcel(out, elapsedRealtimeUs); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5830 | } else { |
| 5831 | out.writeInt(0); |
| 5832 | } |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 5833 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5834 | if (mAudioTurnedOnTimer != null) { |
| 5835 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5836 | mAudioTurnedOnTimer.writeToParcel(out, elapsedRealtimeUs); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5837 | } else { |
| 5838 | out.writeInt(0); |
| 5839 | } |
| 5840 | if (mVideoTurnedOnTimer != null) { |
| 5841 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5842 | mVideoTurnedOnTimer.writeToParcel(out, elapsedRealtimeUs); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5843 | } else { |
| 5844 | out.writeInt(0); |
| 5845 | } |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 5846 | if (mFlashlightTurnedOnTimer != null) { |
| 5847 | out.writeInt(1); |
| 5848 | mFlashlightTurnedOnTimer.writeToParcel(out, elapsedRealtimeUs); |
| 5849 | } else { |
| 5850 | out.writeInt(0); |
| 5851 | } |
| 5852 | if (mCameraTurnedOnTimer != null) { |
| 5853 | out.writeInt(1); |
| 5854 | mCameraTurnedOnTimer.writeToParcel(out, elapsedRealtimeUs); |
| 5855 | } else { |
| 5856 | out.writeInt(0); |
| 5857 | } |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 5858 | if (mForegroundActivityTimer != null) { |
| 5859 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5860 | mForegroundActivityTimer.writeToParcel(out, elapsedRealtimeUs); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 5861 | } else { |
| 5862 | out.writeInt(0); |
| 5863 | } |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 5864 | if (mBluetoothScanTimer != null) { |
| 5865 | out.writeInt(1); |
| 5866 | mBluetoothScanTimer.writeToParcel(out, elapsedRealtimeUs); |
| 5867 | } else { |
| 5868 | out.writeInt(0); |
| 5869 | } |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5870 | for (int i = 0; i < NUM_PROCESS_STATE; i++) { |
| 5871 | if (mProcessStateTimer[i] != null) { |
| 5872 | out.writeInt(1); |
| 5873 | mProcessStateTimer[i].writeToParcel(out, elapsedRealtimeUs); |
| 5874 | } else { |
| 5875 | out.writeInt(0); |
| 5876 | } |
| 5877 | } |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 5878 | if (mVibratorOnTimer != null) { |
| 5879 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5880 | mVibratorOnTimer.writeToParcel(out, elapsedRealtimeUs); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 5881 | } else { |
| 5882 | out.writeInt(0); |
| 5883 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5884 | if (mUserActivityCounters != null) { |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 5885 | out.writeInt(1); |
| 5886 | for (int i=0; i<NUM_USER_ACTIVITY_TYPES; i++) { |
| 5887 | mUserActivityCounters[i].writeToParcel(out); |
| 5888 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5889 | } else { |
| 5890 | out.writeInt(0); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 5891 | } |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5892 | if (mNetworkByteActivityCounters != null) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5893 | out.writeInt(1); |
| 5894 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5895 | mNetworkByteActivityCounters[i].writeToParcel(out); |
| 5896 | mNetworkPacketActivityCounters[i].writeToParcel(out); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5897 | } |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 5898 | mMobileRadioActiveTime.writeToParcel(out); |
| 5899 | mMobileRadioActiveCount.writeToParcel(out); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5900 | } else { |
| 5901 | out.writeInt(0); |
| 5902 | } |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 5903 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 5904 | if (mWifiControllerActivity != null) { |
| 5905 | out.writeInt(1); |
| 5906 | mWifiControllerActivity.writeToParcel(out, 0); |
| 5907 | } else { |
| 5908 | out.writeInt(0); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 5909 | } |
| 5910 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 5911 | if (mBluetoothControllerActivity != null) { |
| 5912 | out.writeInt(1); |
| 5913 | mBluetoothControllerActivity.writeToParcel(out, 0); |
| 5914 | } else { |
| 5915 | out.writeInt(0); |
| 5916 | } |
| 5917 | |
| 5918 | if (mModemControllerActivity != null) { |
| 5919 | out.writeInt(1); |
| 5920 | mModemControllerActivity.writeToParcel(out, 0); |
| 5921 | } else { |
| 5922 | out.writeInt(0); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 5923 | } |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 5924 | |
| 5925 | mUserCpuTime.writeToParcel(out); |
| 5926 | mSystemCpuTime.writeToParcel(out); |
Adam Lesinski | a7a4ccc | 2015-06-26 17:43:04 -0700 | [diff] [blame] | 5927 | mCpuPower.writeToParcel(out); |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 5928 | |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 5929 | if (mCpuClusterSpeed != null) { |
| 5930 | out.writeInt(1); |
| 5931 | out.writeInt(mCpuClusterSpeed.length); |
| 5932 | for (LongSamplingCounter[] cpuSpeeds : mCpuClusterSpeed) { |
| 5933 | if (cpuSpeeds != null) { |
| 5934 | out.writeInt(1); |
| 5935 | out.writeInt(cpuSpeeds.length); |
| 5936 | for (LongSamplingCounter c : cpuSpeeds) { |
| 5937 | if (c != null) { |
| 5938 | out.writeInt(1); |
| 5939 | c.writeToParcel(out); |
| 5940 | } else { |
| 5941 | out.writeInt(0); |
| 5942 | } |
| 5943 | } |
| 5944 | } else { |
| 5945 | out.writeInt(0); |
| 5946 | } |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 5947 | } |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 5948 | } else { |
| 5949 | out.writeInt(0); |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 5950 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5951 | } |
| 5952 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5953 | void readFromParcelLocked(TimeBase timeBase, TimeBase screenOffTimeBase, Parcel in) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5954 | int numWakelocks = in.readInt(); |
| 5955 | mWakelockStats.clear(); |
| 5956 | for (int j = 0; j < numWakelocks; j++) { |
| 5957 | String wakelockName = in.readString(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5958 | Uid.Wakelock wakelock = new Wakelock(mBsi, this); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5959 | wakelock.readFromParcelLocked(timeBase, screenOffTimeBase, in); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 5960 | mWakelockStats.add(wakelockName, wakelock); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5961 | } |
| 5962 | |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 5963 | int numSyncs = in.readInt(); |
| 5964 | mSyncStats.clear(); |
| 5965 | for (int j = 0; j < numSyncs; j++) { |
| 5966 | String syncName = in.readString(); |
| 5967 | if (in.readInt() != 0) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 5968 | mSyncStats.add(syncName, |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5969 | new StopwatchTimer(mBsi.mClocks, Uid.this, SYNC, null, timeBase, in)); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 5970 | } |
| 5971 | } |
| 5972 | |
| 5973 | int numJobs = in.readInt(); |
| 5974 | mJobStats.clear(); |
| 5975 | for (int j = 0; j < numJobs; j++) { |
| 5976 | String jobName = in.readString(); |
| 5977 | if (in.readInt() != 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5978 | mJobStats.add(jobName, new StopwatchTimer(mBsi.mClocks, Uid.this, JOB, null, |
| 5979 | timeBase, in)); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 5980 | } |
| 5981 | } |
| 5982 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5983 | int numSensors = in.readInt(); |
| 5984 | mSensorStats.clear(); |
| 5985 | for (int k = 0; k < numSensors; k++) { |
| 5986 | int sensorNumber = in.readInt(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5987 | Uid.Sensor sensor = new Sensor(mBsi, this, sensorNumber); |
| 5988 | sensor.readFromParcelLocked(mBsi.mOnBatteryTimeBase, in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5989 | mSensorStats.put(sensorNumber, sensor); |
| 5990 | } |
| 5991 | |
| 5992 | int numProcs = in.readInt(); |
| 5993 | mProcessStats.clear(); |
| 5994 | for (int k = 0; k < numProcs; k++) { |
| 5995 | String processName = in.readString(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5996 | Uid.Proc proc = new Proc(mBsi, processName); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5997 | proc.readFromParcelLocked(in); |
| 5998 | mProcessStats.put(processName, proc); |
| 5999 | } |
| 6000 | |
| 6001 | int numPkgs = in.readInt(); |
| 6002 | mPackageStats.clear(); |
| 6003 | for (int l = 0; l < numPkgs; l++) { |
| 6004 | String packageName = in.readString(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6005 | Uid.Pkg pkg = new Pkg(mBsi); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6006 | pkg.readFromParcelLocked(in); |
| 6007 | mPackageStats.put(packageName, pkg); |
| 6008 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6009 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 6010 | mWifiRunning = false; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6011 | if (in.readInt() != 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6012 | mWifiRunningTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, WIFI_RUNNING, |
| 6013 | mBsi.mWifiRunningTimers, mBsi.mOnBatteryTimeBase, in); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 6014 | } else { |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 6015 | mWifiRunningTimer = null; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6016 | } |
| 6017 | mFullWifiLockOut = false; |
| 6018 | if (in.readInt() != 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6019 | mFullWifiLockTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, FULL_WIFI_LOCK, |
| 6020 | mBsi.mFullWifiLockTimers, mBsi.mOnBatteryTimeBase, in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6021 | } else { |
| 6022 | mFullWifiLockTimer = null; |
| 6023 | } |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 6024 | mWifiScanStarted = false; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6025 | if (in.readInt() != 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6026 | mWifiScanTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, WIFI_SCAN, |
| 6027 | mBsi.mWifiScanTimers, mBsi.mOnBatteryTimeBase, in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6028 | } else { |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 6029 | mWifiScanTimer = null; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6030 | } |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 6031 | mWifiBatchedScanBinStarted = NO_BATCHED_SCAN_STARTED; |
| 6032 | for (int i = 0; i < NUM_WIFI_BATCHED_SCAN_BINS; i++) { |
| 6033 | if (in.readInt() != 0) { |
| 6034 | makeWifiBatchedScanBin(i, in); |
| 6035 | } else { |
| 6036 | mWifiBatchedScanTimer[i] = null; |
| 6037 | } |
| 6038 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6039 | mWifiMulticastEnabled = false; |
| 6040 | if (in.readInt() != 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6041 | mWifiMulticastTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, WIFI_MULTICAST_ENABLED, |
| 6042 | mBsi.mWifiMulticastTimers, mBsi.mOnBatteryTimeBase, in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6043 | } else { |
| 6044 | mWifiMulticastTimer = null; |
| 6045 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6046 | if (in.readInt() != 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6047 | mAudioTurnedOnTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, AUDIO_TURNED_ON, |
| 6048 | mBsi.mAudioTurnedOnTimers, mBsi.mOnBatteryTimeBase, in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6049 | } else { |
| 6050 | mAudioTurnedOnTimer = null; |
| 6051 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6052 | if (in.readInt() != 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6053 | mVideoTurnedOnTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, VIDEO_TURNED_ON, |
| 6054 | mBsi.mVideoTurnedOnTimers, mBsi.mOnBatteryTimeBase, in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6055 | } else { |
| 6056 | mVideoTurnedOnTimer = null; |
| 6057 | } |
| 6058 | if (in.readInt() != 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6059 | mFlashlightTurnedOnTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, |
| 6060 | FLASHLIGHT_TURNED_ON, mBsi.mFlashlightTurnedOnTimers, mBsi.mOnBatteryTimeBase, in); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 6061 | } else { |
| 6062 | mFlashlightTurnedOnTimer = null; |
| 6063 | } |
| 6064 | if (in.readInt() != 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6065 | mCameraTurnedOnTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, CAMERA_TURNED_ON, |
| 6066 | mBsi.mCameraTurnedOnTimers, mBsi.mOnBatteryTimeBase, in); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 6067 | } else { |
| 6068 | mCameraTurnedOnTimer = null; |
| 6069 | } |
| 6070 | if (in.readInt() != 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6071 | mForegroundActivityTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, |
| 6072 | FOREGROUND_ACTIVITY, null, mBsi.mOnBatteryTimeBase, in); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 6073 | } else { |
| 6074 | mForegroundActivityTimer = null; |
| 6075 | } |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 6076 | if (in.readInt() != 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6077 | mBluetoothScanTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, BLUETOOTH_SCAN_ON, |
| 6078 | mBsi.mBluetoothScanOnTimers, mBsi.mOnBatteryTimeBase, in); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 6079 | } else { |
| 6080 | mBluetoothScanTimer = null; |
| 6081 | } |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 6082 | mProcessState = ActivityManager.PROCESS_STATE_NONEXISTENT; |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 6083 | for (int i = 0; i < NUM_PROCESS_STATE; i++) { |
| 6084 | if (in.readInt() != 0) { |
| 6085 | makeProcessState(i, in); |
| 6086 | } else { |
| 6087 | mProcessStateTimer[i] = null; |
| 6088 | } |
| 6089 | } |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 6090 | if (in.readInt() != 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6091 | mVibratorOnTimer = new BatchTimer(mBsi.mClocks, Uid.this, VIBRATOR_ON, |
| 6092 | mBsi.mOnBatteryTimeBase, in); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 6093 | } else { |
| 6094 | mVibratorOnTimer = null; |
| 6095 | } |
| 6096 | if (in.readInt() != 0) { |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 6097 | mUserActivityCounters = new Counter[NUM_USER_ACTIVITY_TYPES]; |
| 6098 | for (int i=0; i<NUM_USER_ACTIVITY_TYPES; i++) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6099 | mUserActivityCounters[i] = new Counter(mBsi.mOnBatteryTimeBase, in); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 6100 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6101 | } else { |
| 6102 | mUserActivityCounters = null; |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 6103 | } |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 6104 | if (in.readInt() != 0) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6105 | mNetworkByteActivityCounters = new LongSamplingCounter[NUM_NETWORK_ACTIVITY_TYPES]; |
| 6106 | mNetworkPacketActivityCounters |
| 6107 | = new LongSamplingCounter[NUM_NETWORK_ACTIVITY_TYPES]; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 6108 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6109 | mNetworkByteActivityCounters[i] |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6110 | = new LongSamplingCounter(mBsi.mOnBatteryTimeBase, in); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6111 | mNetworkPacketActivityCounters[i] |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6112 | = new LongSamplingCounter(mBsi.mOnBatteryTimeBase, in); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 6113 | } |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6114 | mMobileRadioActiveTime = new LongSamplingCounter(mBsi.mOnBatteryTimeBase, in); |
| 6115 | mMobileRadioActiveCount = new LongSamplingCounter(mBsi.mOnBatteryTimeBase, in); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 6116 | } else { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6117 | mNetworkByteActivityCounters = null; |
| 6118 | mNetworkPacketActivityCounters = null; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 6119 | } |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 6120 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 6121 | if (in.readInt() != 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6122 | mWifiControllerActivity = new ControllerActivityCounterImpl(mBsi.mOnBatteryTimeBase, |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 6123 | NUM_WIFI_TX_LEVELS, in); |
| 6124 | } else { |
| 6125 | mWifiControllerActivity = null; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 6126 | } |
| 6127 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 6128 | if (in.readInt() != 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6129 | mBluetoothControllerActivity = new ControllerActivityCounterImpl(mBsi.mOnBatteryTimeBase, |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 6130 | NUM_BT_TX_LEVELS, in); |
| 6131 | } else { |
| 6132 | mBluetoothControllerActivity = null; |
| 6133 | } |
| 6134 | |
| 6135 | if (in.readInt() != 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6136 | mModemControllerActivity = new ControllerActivityCounterImpl(mBsi.mOnBatteryTimeBase, |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 6137 | ModemActivityInfo.TX_POWER_LEVELS, in); |
| 6138 | } else { |
| 6139 | mModemControllerActivity = null; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 6140 | } |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 6141 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6142 | mUserCpuTime = new LongSamplingCounter(mBsi.mOnBatteryTimeBase, in); |
| 6143 | mSystemCpuTime = new LongSamplingCounter(mBsi.mOnBatteryTimeBase, in); |
| 6144 | mCpuPower = new LongSamplingCounter(mBsi.mOnBatteryTimeBase, in); |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 6145 | |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 6146 | if (in.readInt() != 0) { |
| 6147 | int numCpuClusters = in.readInt(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6148 | if (mBsi.mPowerProfile != null && mBsi.mPowerProfile.getNumCpuClusters() != numCpuClusters) { |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 6149 | throw new ParcelFormatException("Incompatible number of cpu clusters"); |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 6150 | } |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 6151 | |
| 6152 | mCpuClusterSpeed = new LongSamplingCounter[numCpuClusters][]; |
| 6153 | for (int cluster = 0; cluster < numCpuClusters; cluster++) { |
| 6154 | if (in.readInt() != 0) { |
| 6155 | int numSpeeds = in.readInt(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6156 | if (mBsi.mPowerProfile != null && |
| 6157 | mBsi.mPowerProfile.getNumSpeedStepsInCpuCluster(cluster) != numSpeeds) { |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 6158 | throw new ParcelFormatException("Incompatible number of cpu speeds"); |
| 6159 | } |
| 6160 | |
| 6161 | final LongSamplingCounter[] cpuSpeeds = new LongSamplingCounter[numSpeeds]; |
| 6162 | mCpuClusterSpeed[cluster] = cpuSpeeds; |
| 6163 | for (int speed = 0; speed < numSpeeds; speed++) { |
| 6164 | if (in.readInt() != 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6165 | cpuSpeeds[speed] = new LongSamplingCounter(mBsi.mOnBatteryTimeBase, in); |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 6166 | } |
| 6167 | } |
Adam Lesinski | a57a540 | 2015-09-28 10:21:33 -0700 | [diff] [blame] | 6168 | } else { |
| 6169 | mCpuClusterSpeed[cluster] = null; |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 6170 | } |
| 6171 | } |
| 6172 | } else { |
| 6173 | mCpuClusterSpeed = null; |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 6174 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6175 | } |
| 6176 | |
| 6177 | /** |
| 6178 | * The statistics associated with a particular wake lock. |
| 6179 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6180 | public static class Wakelock extends BatteryStats.Uid.Wakelock { |
| 6181 | /** |
| 6182 | * BatteryStatsImpl that we are associated with. |
| 6183 | */ |
| 6184 | protected BatteryStatsImpl mBsi; |
| 6185 | |
| 6186 | /** |
| 6187 | * BatteryStatsImpl that we are associated with. |
| 6188 | */ |
| 6189 | protected Uid mUid; |
| 6190 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6191 | /** |
| 6192 | * How long (in ms) this uid has been keeping the device partially awake. |
| 6193 | */ |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 6194 | StopwatchTimer mTimerPartial; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6195 | |
| 6196 | /** |
| 6197 | * How long (in ms) this uid has been keeping the device fully awake. |
| 6198 | */ |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 6199 | StopwatchTimer mTimerFull; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6200 | |
| 6201 | /** |
| 6202 | * How long (in ms) this uid has had a window keeping the device awake. |
| 6203 | */ |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 6204 | StopwatchTimer mTimerWindow; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6205 | |
| 6206 | /** |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 6207 | * How long (in ms) this uid has had a draw wake lock. |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 6208 | */ |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 6209 | StopwatchTimer mTimerDraw; |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 6210 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6211 | public Wakelock(BatteryStatsImpl bsi, Uid uid) { |
| 6212 | mBsi = bsi; |
| 6213 | mUid = uid; |
| 6214 | } |
| 6215 | |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 6216 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6217 | * Reads a possibly null Timer from a Parcel. The timer is associated with the |
| 6218 | * proper timer pool from the given BatteryStatsImpl object. |
| 6219 | * |
| 6220 | * @param in the Parcel to be read from. |
| 6221 | * return a new Timer, or null. |
| 6222 | */ |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 6223 | private StopwatchTimer readTimerFromParcel(int type, ArrayList<StopwatchTimer> pool, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6224 | TimeBase timeBase, Parcel in) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6225 | if (in.readInt() == 0) { |
| 6226 | return null; |
| 6227 | } |
| 6228 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6229 | return new StopwatchTimer(mBsi.mClocks, mUid, type, pool, timeBase, in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6230 | } |
| 6231 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6232 | boolean reset() { |
| 6233 | boolean wlactive = false; |
| 6234 | if (mTimerFull != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6235 | wlactive |= !mTimerFull.reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6236 | } |
| 6237 | if (mTimerPartial != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6238 | wlactive |= !mTimerPartial.reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6239 | } |
| 6240 | if (mTimerWindow != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6241 | wlactive |= !mTimerWindow.reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6242 | } |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 6243 | if (mTimerDraw != null) { |
| 6244 | wlactive |= !mTimerDraw.reset(false); |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 6245 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6246 | if (!wlactive) { |
| 6247 | if (mTimerFull != null) { |
| 6248 | mTimerFull.detach(); |
| 6249 | mTimerFull = null; |
| 6250 | } |
| 6251 | if (mTimerPartial != null) { |
| 6252 | mTimerPartial.detach(); |
| 6253 | mTimerPartial = null; |
| 6254 | } |
| 6255 | if (mTimerWindow != null) { |
| 6256 | mTimerWindow.detach(); |
| 6257 | mTimerWindow = null; |
| 6258 | } |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 6259 | if (mTimerDraw != null) { |
| 6260 | mTimerDraw.detach(); |
| 6261 | mTimerDraw = null; |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 6262 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6263 | } |
| 6264 | return !wlactive; |
| 6265 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6266 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6267 | void readFromParcelLocked(TimeBase timeBase, TimeBase screenOffTimeBase, Parcel in) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6268 | mTimerPartial = readTimerFromParcel(WAKE_TYPE_PARTIAL, |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6269 | mBsi.mPartialTimers, screenOffTimeBase, in); |
| 6270 | mTimerFull = readTimerFromParcel(WAKE_TYPE_FULL, mBsi.mFullTimers, timeBase, in); |
| 6271 | mTimerWindow = readTimerFromParcel(WAKE_TYPE_WINDOW, mBsi.mWindowTimers, timeBase, in); |
| 6272 | mTimerDraw = readTimerFromParcel(WAKE_TYPE_DRAW, mBsi.mDrawTimers, timeBase, in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6273 | } |
| 6274 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6275 | void writeToParcelLocked(Parcel out, long elapsedRealtimeUs) { |
| 6276 | Timer.writeTimerToParcel(out, mTimerPartial, elapsedRealtimeUs); |
| 6277 | Timer.writeTimerToParcel(out, mTimerFull, elapsedRealtimeUs); |
| 6278 | Timer.writeTimerToParcel(out, mTimerWindow, elapsedRealtimeUs); |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 6279 | Timer.writeTimerToParcel(out, mTimerDraw, elapsedRealtimeUs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6280 | } |
| 6281 | |
| 6282 | @Override |
| 6283 | public Timer getWakeTime(int type) { |
| 6284 | switch (type) { |
| 6285 | case WAKE_TYPE_FULL: return mTimerFull; |
| 6286 | case WAKE_TYPE_PARTIAL: return mTimerPartial; |
| 6287 | case WAKE_TYPE_WINDOW: return mTimerWindow; |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 6288 | case WAKE_TYPE_DRAW: return mTimerDraw; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6289 | default: throw new IllegalArgumentException("type = " + type); |
| 6290 | } |
| 6291 | } |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 6292 | |
| 6293 | public StopwatchTimer getStopwatchTimer(int type) { |
| 6294 | StopwatchTimer t; |
| 6295 | switch (type) { |
| 6296 | case WAKE_TYPE_PARTIAL: |
| 6297 | t = mTimerPartial; |
| 6298 | if (t == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6299 | t = new StopwatchTimer(mBsi.mClocks, mUid, WAKE_TYPE_PARTIAL, |
| 6300 | mBsi.mPartialTimers, mBsi.mOnBatteryScreenOffTimeBase); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 6301 | mTimerPartial = t; |
| 6302 | } |
| 6303 | return t; |
| 6304 | case WAKE_TYPE_FULL: |
| 6305 | t = mTimerFull; |
| 6306 | if (t == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6307 | t = new StopwatchTimer(mBsi.mClocks, mUid, WAKE_TYPE_FULL, |
| 6308 | mBsi.mFullTimers, mBsi.mOnBatteryTimeBase); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 6309 | mTimerFull = t; |
| 6310 | } |
| 6311 | return t; |
| 6312 | case WAKE_TYPE_WINDOW: |
| 6313 | t = mTimerWindow; |
| 6314 | if (t == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6315 | t = new StopwatchTimer(mBsi.mClocks, mUid, WAKE_TYPE_WINDOW, |
| 6316 | mBsi.mWindowTimers, mBsi.mOnBatteryTimeBase); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 6317 | mTimerWindow = t; |
| 6318 | } |
| 6319 | return t; |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 6320 | case WAKE_TYPE_DRAW: |
| 6321 | t = mTimerDraw; |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 6322 | if (t == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6323 | t = new StopwatchTimer(mBsi.mClocks, mUid, WAKE_TYPE_DRAW, |
| 6324 | mBsi.mDrawTimers, mBsi.mOnBatteryTimeBase); |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 6325 | mTimerDraw = t; |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 6326 | } |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 6327 | return t; |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 6328 | default: |
| 6329 | throw new IllegalArgumentException("type=" + type); |
| 6330 | } |
| 6331 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6332 | } |
| 6333 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6334 | public static class Sensor extends BatteryStats.Uid.Sensor { |
| 6335 | /** |
| 6336 | * BatteryStatsImpl that we are associated with. |
| 6337 | */ |
| 6338 | protected BatteryStatsImpl mBsi; |
| 6339 | |
| 6340 | /** |
| 6341 | * BatteryStatsImpl that we are associated with. |
| 6342 | */ |
| 6343 | protected Uid mUid; |
| 6344 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6345 | final int mHandle; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 6346 | StopwatchTimer mTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6347 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6348 | public Sensor(BatteryStatsImpl bsi, Uid uid, int handle) { |
| 6349 | mBsi = bsi; |
| 6350 | mUid = uid; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6351 | mHandle = handle; |
| 6352 | } |
| 6353 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6354 | private StopwatchTimer readTimerFromParcel(TimeBase timeBase, Parcel in) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6355 | if (in.readInt() == 0) { |
| 6356 | return null; |
| 6357 | } |
| 6358 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6359 | ArrayList<StopwatchTimer> pool = mBsi.mSensorTimers.get(mHandle); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6360 | if (pool == null) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 6361 | pool = new ArrayList<StopwatchTimer>(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6362 | mBsi.mSensorTimers.put(mHandle, pool); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6363 | } |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6364 | return new StopwatchTimer(mBsi.mClocks, mUid, 0, pool, timeBase, in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6365 | } |
| 6366 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6367 | boolean reset() { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6368 | if (mTimer.reset(true)) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6369 | mTimer = null; |
| 6370 | return true; |
| 6371 | } |
| 6372 | return false; |
| 6373 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6374 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6375 | void readFromParcelLocked(TimeBase timeBase, Parcel in) { |
| 6376 | mTimer = readTimerFromParcel(timeBase, in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6377 | } |
| 6378 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6379 | void writeToParcelLocked(Parcel out, long elapsedRealtimeUs) { |
| 6380 | Timer.writeTimerToParcel(out, mTimer, elapsedRealtimeUs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6381 | } |
| 6382 | |
| 6383 | @Override |
| 6384 | public Timer getSensorTime() { |
| 6385 | return mTimer; |
| 6386 | } |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 6387 | |
| 6388 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6389 | public int getHandle() { |
| 6390 | return mHandle; |
| 6391 | } |
| 6392 | } |
| 6393 | |
| 6394 | /** |
| 6395 | * The statistics associated with a particular process. |
| 6396 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6397 | public static class Proc extends BatteryStats.Uid.Proc implements TimeBaseObs { |
| 6398 | /** |
| 6399 | * BatteryStatsImpl that we are associated with. |
| 6400 | */ |
| 6401 | protected BatteryStatsImpl mBsi; |
| 6402 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6403 | /** |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 6404 | * The name of this process. |
| 6405 | */ |
| 6406 | final String mName; |
| 6407 | |
| 6408 | /** |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 6409 | * Remains true until removed from the stats. |
| 6410 | */ |
| 6411 | boolean mActive = true; |
| 6412 | |
| 6413 | /** |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 6414 | * Total time (in ms) spent executing in user code. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6415 | */ |
| 6416 | long mUserTime; |
| 6417 | |
| 6418 | /** |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 6419 | * Total time (in ms) spent executing in kernel code. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6420 | */ |
| 6421 | long mSystemTime; |
| 6422 | |
| 6423 | /** |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 6424 | * Amount of time (in ms) the process was running in the foreground. |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 6425 | */ |
| 6426 | long mForegroundTime; |
| 6427 | |
| 6428 | /** |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 6429 | * Number of times the process has been started. |
| 6430 | */ |
| 6431 | int mStarts; |
| 6432 | |
| 6433 | /** |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 6434 | * Number of times the process has crashed. |
| 6435 | */ |
| 6436 | int mNumCrashes; |
| 6437 | |
| 6438 | /** |
| 6439 | * Number of times the process has had an ANR. |
| 6440 | */ |
| 6441 | int mNumAnrs; |
| 6442 | |
| 6443 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6444 | * The amount of user time loaded from a previous save. |
| 6445 | */ |
| 6446 | long mLoadedUserTime; |
| 6447 | |
| 6448 | /** |
| 6449 | * The amount of system time loaded from a previous save. |
| 6450 | */ |
| 6451 | long mLoadedSystemTime; |
| 6452 | |
| 6453 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 6454 | * The amount of foreground time loaded from a previous save. |
| 6455 | */ |
| 6456 | long mLoadedForegroundTime; |
| 6457 | |
| 6458 | /** |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 6459 | * The number of times the process has started from a previous save. |
| 6460 | */ |
| 6461 | int mLoadedStarts; |
| 6462 | |
| 6463 | /** |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 6464 | * Number of times the process has crashed from a previous save. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6465 | */ |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 6466 | int mLoadedNumCrashes; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6467 | |
| 6468 | /** |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 6469 | * Number of times the process has had an ANR from a previous save. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6470 | */ |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 6471 | int mLoadedNumAnrs; |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 6472 | |
| 6473 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6474 | * The amount of user time when last unplugged. |
| 6475 | */ |
| 6476 | long mUnpluggedUserTime; |
| 6477 | |
| 6478 | /** |
| 6479 | * The amount of system time when last unplugged. |
| 6480 | */ |
| 6481 | long mUnpluggedSystemTime; |
| 6482 | |
| 6483 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 6484 | * The amount of foreground time since unplugged. |
| 6485 | */ |
| 6486 | long mUnpluggedForegroundTime; |
| 6487 | |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 6488 | /** |
| 6489 | * The number of times the process has started before unplugged. |
| 6490 | */ |
| 6491 | int mUnpluggedStarts; |
| 6492 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 6493 | /** |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 6494 | * Number of times the process has crashed before unplugged. |
| 6495 | */ |
| 6496 | int mUnpluggedNumCrashes; |
| 6497 | |
| 6498 | /** |
| 6499 | * Number of times the process has had an ANR before unplugged. |
| 6500 | */ |
| 6501 | int mUnpluggedNumAnrs; |
| 6502 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 6503 | ArrayList<ExcessivePower> mExcessivePower; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 6504 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6505 | public Proc(BatteryStatsImpl bsi, String name) { |
| 6506 | mBsi = bsi; |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 6507 | mName = name; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6508 | mBsi.mOnBatteryTimeBase.add(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6509 | } |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 6510 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6511 | public void onTimeStarted(long elapsedRealtime, long baseUptime, long baseRealtime) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6512 | mUnpluggedUserTime = mUserTime; |
| 6513 | mUnpluggedSystemTime = mSystemTime; |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 6514 | mUnpluggedForegroundTime = mForegroundTime; |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 6515 | mUnpluggedStarts = mStarts; |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 6516 | mUnpluggedNumCrashes = mNumCrashes; |
| 6517 | mUnpluggedNumAnrs = mNumAnrs; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6518 | } |
| 6519 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6520 | public void onTimeStopped(long elapsedRealtime, long baseUptime, long baseRealtime) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6521 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6522 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6523 | void detach() { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 6524 | mActive = false; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6525 | mBsi.mOnBatteryTimeBase.remove(this); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6526 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6527 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 6528 | public int countExcessivePowers() { |
| 6529 | return mExcessivePower != null ? mExcessivePower.size() : 0; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 6530 | } |
| 6531 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 6532 | public ExcessivePower getExcessivePower(int i) { |
| 6533 | if (mExcessivePower != null) { |
| 6534 | return mExcessivePower.get(i); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 6535 | } |
| 6536 | return null; |
| 6537 | } |
| 6538 | |
| 6539 | public void addExcessiveWake(long overTime, long usedTime) { |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 6540 | if (mExcessivePower == null) { |
| 6541 | mExcessivePower = new ArrayList<ExcessivePower>(); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 6542 | } |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 6543 | ExcessivePower ew = new ExcessivePower(); |
| 6544 | ew.type = ExcessivePower.TYPE_WAKE; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 6545 | ew.overTime = overTime; |
| 6546 | ew.usedTime = usedTime; |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 6547 | mExcessivePower.add(ew); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 6548 | } |
| 6549 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 6550 | public void addExcessiveCpu(long overTime, long usedTime) { |
| 6551 | if (mExcessivePower == null) { |
| 6552 | mExcessivePower = new ArrayList<ExcessivePower>(); |
| 6553 | } |
| 6554 | ExcessivePower ew = new ExcessivePower(); |
| 6555 | ew.type = ExcessivePower.TYPE_CPU; |
| 6556 | ew.overTime = overTime; |
| 6557 | ew.usedTime = usedTime; |
| 6558 | mExcessivePower.add(ew); |
| 6559 | } |
| 6560 | |
| 6561 | void writeExcessivePowerToParcelLocked(Parcel out) { |
| 6562 | if (mExcessivePower == null) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 6563 | out.writeInt(0); |
| 6564 | return; |
| 6565 | } |
| 6566 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 6567 | final int N = mExcessivePower.size(); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 6568 | out.writeInt(N); |
| 6569 | for (int i=0; i<N; i++) { |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 6570 | ExcessivePower ew = mExcessivePower.get(i); |
| 6571 | out.writeInt(ew.type); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 6572 | out.writeLong(ew.overTime); |
| 6573 | out.writeLong(ew.usedTime); |
| 6574 | } |
| 6575 | } |
| 6576 | |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 6577 | void readExcessivePowerFromParcelLocked(Parcel in) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 6578 | final int N = in.readInt(); |
| 6579 | if (N == 0) { |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 6580 | mExcessivePower = null; |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 6581 | return; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 6582 | } |
| 6583 | |
Dianne Hackborn | 7b9c56f | 2010-12-07 11:14:53 -0800 | [diff] [blame] | 6584 | if (N > 10000) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 6585 | throw new ParcelFormatException( |
| 6586 | "File corrupt: too many excessive power entries " + N); |
Dianne Hackborn | 7b9c56f | 2010-12-07 11:14:53 -0800 | [diff] [blame] | 6587 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 6588 | |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 6589 | mExcessivePower = new ArrayList<>(); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 6590 | for (int i=0; i<N; i++) { |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 6591 | ExcessivePower ew = new ExcessivePower(); |
| 6592 | ew.type = in.readInt(); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 6593 | ew.overTime = in.readLong(); |
| 6594 | ew.usedTime = in.readLong(); |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 6595 | mExcessivePower.add(ew); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 6596 | } |
| 6597 | } |
| 6598 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6599 | void writeToParcelLocked(Parcel out) { |
| 6600 | out.writeLong(mUserTime); |
| 6601 | out.writeLong(mSystemTime); |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 6602 | out.writeLong(mForegroundTime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6603 | out.writeInt(mStarts); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 6604 | out.writeInt(mNumCrashes); |
| 6605 | out.writeInt(mNumAnrs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6606 | out.writeLong(mLoadedUserTime); |
| 6607 | out.writeLong(mLoadedSystemTime); |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 6608 | out.writeLong(mLoadedForegroundTime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6609 | out.writeInt(mLoadedStarts); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 6610 | out.writeInt(mLoadedNumCrashes); |
| 6611 | out.writeInt(mLoadedNumAnrs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6612 | out.writeLong(mUnpluggedUserTime); |
| 6613 | out.writeLong(mUnpluggedSystemTime); |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 6614 | out.writeLong(mUnpluggedForegroundTime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6615 | out.writeInt(mUnpluggedStarts); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 6616 | out.writeInt(mUnpluggedNumCrashes); |
| 6617 | out.writeInt(mUnpluggedNumAnrs); |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 6618 | writeExcessivePowerToParcelLocked(out); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6619 | } |
| 6620 | |
| 6621 | void readFromParcelLocked(Parcel in) { |
| 6622 | mUserTime = in.readLong(); |
| 6623 | mSystemTime = in.readLong(); |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 6624 | mForegroundTime = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6625 | mStarts = in.readInt(); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 6626 | mNumCrashes = in.readInt(); |
| 6627 | mNumAnrs = in.readInt(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6628 | mLoadedUserTime = in.readLong(); |
| 6629 | mLoadedSystemTime = in.readLong(); |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 6630 | mLoadedForegroundTime = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6631 | mLoadedStarts = in.readInt(); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 6632 | mLoadedNumCrashes = in.readInt(); |
| 6633 | mLoadedNumAnrs = in.readInt(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6634 | mUnpluggedUserTime = in.readLong(); |
| 6635 | mUnpluggedSystemTime = in.readLong(); |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 6636 | mUnpluggedForegroundTime = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6637 | mUnpluggedStarts = in.readInt(); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 6638 | mUnpluggedNumCrashes = in.readInt(); |
| 6639 | mUnpluggedNumAnrs = in.readInt(); |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 6640 | readExcessivePowerFromParcelLocked(in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6641 | } |
| 6642 | |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 6643 | public void addCpuTimeLocked(int utime, int stime) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6644 | mUserTime += utime; |
| 6645 | mSystemTime += stime; |
| 6646 | } |
| 6647 | |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 6648 | public void addForegroundTimeLocked(long ttime) { |
| 6649 | mForegroundTime += ttime; |
| 6650 | } |
| 6651 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6652 | public void incStartsLocked() { |
| 6653 | mStarts++; |
| 6654 | } |
| 6655 | |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 6656 | public void incNumCrashesLocked() { |
| 6657 | mNumCrashes++; |
| 6658 | } |
| 6659 | |
| 6660 | public void incNumAnrsLocked() { |
| 6661 | mNumAnrs++; |
| 6662 | } |
| 6663 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6664 | @Override |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 6665 | public boolean isActive() { |
| 6666 | return mActive; |
| 6667 | } |
| 6668 | |
| 6669 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6670 | public long getUserTime(int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 6671 | long val = mUserTime; |
| 6672 | if (which == STATS_CURRENT) { |
| 6673 | val -= mLoadedUserTime; |
| 6674 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 6675 | val -= mUnpluggedUserTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6676 | } |
| 6677 | return val; |
| 6678 | } |
| 6679 | |
| 6680 | @Override |
| 6681 | public long getSystemTime(int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 6682 | long val = mSystemTime; |
| 6683 | if (which == STATS_CURRENT) { |
| 6684 | val -= mLoadedSystemTime; |
| 6685 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 6686 | val -= mUnpluggedSystemTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6687 | } |
| 6688 | return val; |
| 6689 | } |
| 6690 | |
| 6691 | @Override |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 6692 | public long getForegroundTime(int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 6693 | long val = mForegroundTime; |
| 6694 | if (which == STATS_CURRENT) { |
| 6695 | val -= mLoadedForegroundTime; |
| 6696 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 6697 | val -= mUnpluggedForegroundTime; |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 6698 | } |
| 6699 | return val; |
| 6700 | } |
| 6701 | |
| 6702 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6703 | public int getStarts(int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 6704 | int val = mStarts; |
| 6705 | if (which == STATS_CURRENT) { |
| 6706 | val -= mLoadedStarts; |
| 6707 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 6708 | val -= mUnpluggedStarts; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6709 | } |
| 6710 | return val; |
| 6711 | } |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 6712 | |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 6713 | @Override |
| 6714 | public int getNumCrashes(int which) { |
| 6715 | int val = mNumCrashes; |
| 6716 | if (which == STATS_CURRENT) { |
| 6717 | val -= mLoadedNumCrashes; |
| 6718 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 6719 | val -= mUnpluggedNumCrashes; |
| 6720 | } |
| 6721 | return val; |
| 6722 | } |
| 6723 | |
| 6724 | @Override |
| 6725 | public int getNumAnrs(int which) { |
| 6726 | int val = mNumAnrs; |
| 6727 | if (which == STATS_CURRENT) { |
| 6728 | val -= mLoadedNumAnrs; |
| 6729 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 6730 | val -= mUnpluggedNumAnrs; |
| 6731 | } |
| 6732 | return val; |
| 6733 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6734 | } |
| 6735 | |
| 6736 | /** |
| 6737 | * The statistics associated with a particular package. |
| 6738 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6739 | public static class Pkg extends BatteryStats.Uid.Pkg implements TimeBaseObs { |
| 6740 | /** |
| 6741 | * BatteryStatsImpl that we are associated with. |
| 6742 | */ |
| 6743 | protected BatteryStatsImpl mBsi; |
| 6744 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6745 | /** |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 6746 | * Number of times wakeup alarms have occurred for this app. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6747 | */ |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 6748 | ArrayMap<String, Counter> mWakeupAlarms = new ArrayMap<>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6749 | |
| 6750 | /** |
| 6751 | * The statics we have collected for this package's services. |
| 6752 | */ |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 6753 | final ArrayMap<String, Serv> mServiceStats = new ArrayMap<>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6754 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6755 | public Pkg(BatteryStatsImpl bsi) { |
| 6756 | mBsi = bsi; |
| 6757 | mBsi.mOnBatteryScreenOffTimeBase.add(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6758 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6759 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6760 | public void onTimeStarted(long elapsedRealtime, long baseUptime, long baseRealtime) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6761 | } |
| 6762 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6763 | public void onTimeStopped(long elapsedRealtime, long baseUptime, long baseRealtime) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6764 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6765 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6766 | void detach() { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6767 | mBsi.mOnBatteryScreenOffTimeBase.remove(this); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6768 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6769 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6770 | void readFromParcelLocked(Parcel in) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 6771 | int numWA = in.readInt(); |
| 6772 | mWakeupAlarms.clear(); |
| 6773 | for (int i=0; i<numWA; i++) { |
| 6774 | String tag = in.readString(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6775 | mWakeupAlarms.put(tag, new Counter(mBsi.mOnBatteryTimeBase, in)); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 6776 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6777 | |
| 6778 | int numServs = in.readInt(); |
| 6779 | mServiceStats.clear(); |
| 6780 | for (int m = 0; m < numServs; m++) { |
| 6781 | String serviceName = in.readString(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6782 | Uid.Pkg.Serv serv = new Serv(mBsi); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6783 | mServiceStats.put(serviceName, serv); |
| 6784 | |
| 6785 | serv.readFromParcelLocked(in); |
| 6786 | } |
| 6787 | } |
| 6788 | |
| 6789 | void writeToParcelLocked(Parcel out) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 6790 | int numWA = mWakeupAlarms.size(); |
| 6791 | out.writeInt(numWA); |
| 6792 | for (int i=0; i<numWA; i++) { |
| 6793 | out.writeString(mWakeupAlarms.keyAt(i)); |
| 6794 | mWakeupAlarms.valueAt(i).writeToParcel(out); |
| 6795 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6796 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 6797 | final int NS = mServiceStats.size(); |
| 6798 | out.writeInt(NS); |
| 6799 | for (int i=0; i<NS; i++) { |
| 6800 | out.writeString(mServiceStats.keyAt(i)); |
| 6801 | Uid.Pkg.Serv serv = mServiceStats.valueAt(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6802 | serv.writeToParcelLocked(out); |
| 6803 | } |
| 6804 | } |
| 6805 | |
| 6806 | @Override |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 6807 | public ArrayMap<String, ? extends BatteryStats.Counter> getWakeupAlarmStats() { |
| 6808 | return mWakeupAlarms; |
| 6809 | } |
| 6810 | |
| 6811 | public void noteWakeupAlarmLocked(String tag) { |
| 6812 | Counter c = mWakeupAlarms.get(tag); |
| 6813 | if (c == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6814 | c = new Counter(mBsi.mOnBatteryTimeBase); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 6815 | mWakeupAlarms.put(tag, c); |
| 6816 | } |
| 6817 | c.stepAtomic(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6818 | } |
| 6819 | |
| 6820 | @Override |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 6821 | public ArrayMap<String, ? extends BatteryStats.Uid.Pkg.Serv> getServiceStats() { |
| 6822 | return mServiceStats; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6823 | } |
| 6824 | |
| 6825 | /** |
| 6826 | * The statistics associated with a particular service. |
| 6827 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6828 | public static class Serv extends BatteryStats.Uid.Pkg.Serv implements TimeBaseObs { |
| 6829 | /** |
| 6830 | * BatteryStatsImpl that we are associated with. |
| 6831 | */ |
| 6832 | protected BatteryStatsImpl mBsi; |
| 6833 | |
| 6834 | /** |
| 6835 | * The android package in which this service resides. |
| 6836 | */ |
| 6837 | protected Pkg mPkg; |
| 6838 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6839 | /** |
| 6840 | * Total time (ms in battery uptime) the service has been left started. |
| 6841 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6842 | protected long mStartTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6843 | |
| 6844 | /** |
| 6845 | * If service has been started and not yet stopped, this is |
| 6846 | * when it was started. |
| 6847 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6848 | protected long mRunningSince; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6849 | |
| 6850 | /** |
| 6851 | * True if we are currently running. |
| 6852 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6853 | protected boolean mRunning; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6854 | |
| 6855 | /** |
| 6856 | * Total number of times startService() has been called. |
| 6857 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6858 | protected int mStarts; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6859 | |
| 6860 | /** |
| 6861 | * Total time (ms in battery uptime) the service has been left launched. |
| 6862 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6863 | protected long mLaunchedTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6864 | |
| 6865 | /** |
| 6866 | * If service has been launched and not yet exited, this is |
| 6867 | * when it was launched (ms in battery uptime). |
| 6868 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6869 | protected long mLaunchedSince; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6870 | |
| 6871 | /** |
| 6872 | * True if we are currently launched. |
| 6873 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6874 | protected boolean mLaunched; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6875 | |
| 6876 | /** |
| 6877 | * Total number times the service has been launched. |
| 6878 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6879 | protected int mLaunches; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6880 | |
| 6881 | /** |
| 6882 | * The amount of time spent started loaded from a previous save |
| 6883 | * (ms in battery uptime). |
| 6884 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6885 | protected long mLoadedStartTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6886 | |
| 6887 | /** |
| 6888 | * The number of starts loaded from a previous save. |
| 6889 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6890 | protected int mLoadedStarts; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6891 | |
| 6892 | /** |
| 6893 | * The number of launches loaded from a previous save. |
| 6894 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6895 | protected int mLoadedLaunches; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6896 | |
| 6897 | /** |
| 6898 | * The amount of time spent started as of the last run (ms |
| 6899 | * in battery uptime). |
| 6900 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6901 | protected long mLastStartTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6902 | |
| 6903 | /** |
| 6904 | * The number of starts as of the last run. |
| 6905 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6906 | protected int mLastStarts; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6907 | |
| 6908 | /** |
| 6909 | * The number of launches as of the last run. |
| 6910 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6911 | protected int mLastLaunches; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6912 | |
| 6913 | /** |
| 6914 | * The amount of time spent started when last unplugged (ms |
| 6915 | * in battery uptime). |
| 6916 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6917 | protected long mUnpluggedStartTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6918 | |
| 6919 | /** |
| 6920 | * The number of starts when last unplugged. |
| 6921 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6922 | protected int mUnpluggedStarts; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6923 | |
| 6924 | /** |
| 6925 | * The number of launches when last unplugged. |
| 6926 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6927 | protected int mUnpluggedLaunches; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6928 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6929 | /** |
| 6930 | * Construct a Serv. Also adds it to the on-battery time base as a listener. |
| 6931 | */ |
| 6932 | public Serv(BatteryStatsImpl bsi) { |
| 6933 | mBsi = bsi; |
| 6934 | mBsi.mOnBatteryTimeBase.add(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6935 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6936 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6937 | public void onTimeStarted(long elapsedRealtime, long baseUptime, |
| 6938 | long baseRealtime) { |
| 6939 | mUnpluggedStartTime = getStartTimeToNowLocked(baseUptime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6940 | mUnpluggedStarts = mStarts; |
| 6941 | mUnpluggedLaunches = mLaunches; |
| 6942 | } |
| 6943 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6944 | public void onTimeStopped(long elapsedRealtime, long baseUptime, |
| 6945 | long baseRealtime) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6946 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6947 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6948 | /** |
| 6949 | * Remove this Serv as a listener from the time base. |
| 6950 | */ |
| 6951 | public void detach() { |
| 6952 | mBsi.mOnBatteryTimeBase.remove(this); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6953 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6954 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6955 | public void readFromParcelLocked(Parcel in) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6956 | mStartTime = in.readLong(); |
| 6957 | mRunningSince = in.readLong(); |
| 6958 | mRunning = in.readInt() != 0; |
| 6959 | mStarts = in.readInt(); |
| 6960 | mLaunchedTime = in.readLong(); |
| 6961 | mLaunchedSince = in.readLong(); |
| 6962 | mLaunched = in.readInt() != 0; |
| 6963 | mLaunches = in.readInt(); |
| 6964 | mLoadedStartTime = in.readLong(); |
| 6965 | mLoadedStarts = in.readInt(); |
| 6966 | mLoadedLaunches = in.readInt(); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 6967 | mLastStartTime = 0; |
| 6968 | mLastStarts = 0; |
| 6969 | mLastLaunches = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6970 | mUnpluggedStartTime = in.readLong(); |
| 6971 | mUnpluggedStarts = in.readInt(); |
| 6972 | mUnpluggedLaunches = in.readInt(); |
| 6973 | } |
| 6974 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6975 | public void writeToParcelLocked(Parcel out) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6976 | out.writeLong(mStartTime); |
| 6977 | out.writeLong(mRunningSince); |
| 6978 | out.writeInt(mRunning ? 1 : 0); |
| 6979 | out.writeInt(mStarts); |
| 6980 | out.writeLong(mLaunchedTime); |
| 6981 | out.writeLong(mLaunchedSince); |
| 6982 | out.writeInt(mLaunched ? 1 : 0); |
| 6983 | out.writeInt(mLaunches); |
| 6984 | out.writeLong(mLoadedStartTime); |
| 6985 | out.writeInt(mLoadedStarts); |
| 6986 | out.writeInt(mLoadedLaunches); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6987 | out.writeLong(mUnpluggedStartTime); |
| 6988 | out.writeInt(mUnpluggedStarts); |
| 6989 | out.writeInt(mUnpluggedLaunches); |
| 6990 | } |
| 6991 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6992 | public long getLaunchTimeToNowLocked(long batteryUptime) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6993 | if (!mLaunched) return mLaunchedTime; |
| 6994 | return mLaunchedTime + batteryUptime - mLaunchedSince; |
| 6995 | } |
| 6996 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6997 | public long getStartTimeToNowLocked(long batteryUptime) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6998 | if (!mRunning) return mStartTime; |
| 6999 | return mStartTime + batteryUptime - mRunningSince; |
| 7000 | } |
| 7001 | |
| 7002 | public void startLaunchedLocked() { |
| 7003 | if (!mLaunched) { |
| 7004 | mLaunches++; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7005 | mLaunchedSince = mBsi.getBatteryUptimeLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7006 | mLaunched = true; |
| 7007 | } |
| 7008 | } |
| 7009 | |
| 7010 | public void stopLaunchedLocked() { |
| 7011 | if (mLaunched) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7012 | long time = mBsi.getBatteryUptimeLocked() - mLaunchedSince; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7013 | if (time > 0) { |
| 7014 | mLaunchedTime += time; |
| 7015 | } else { |
| 7016 | mLaunches--; |
| 7017 | } |
| 7018 | mLaunched = false; |
| 7019 | } |
| 7020 | } |
| 7021 | |
| 7022 | public void startRunningLocked() { |
| 7023 | if (!mRunning) { |
| 7024 | mStarts++; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7025 | mRunningSince = mBsi.getBatteryUptimeLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7026 | mRunning = true; |
| 7027 | } |
| 7028 | } |
| 7029 | |
| 7030 | public void stopRunningLocked() { |
| 7031 | if (mRunning) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7032 | long time = mBsi.getBatteryUptimeLocked() - mRunningSince; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7033 | if (time > 0) { |
| 7034 | mStartTime += time; |
| 7035 | } else { |
| 7036 | mStarts--; |
| 7037 | } |
| 7038 | mRunning = false; |
| 7039 | } |
| 7040 | } |
| 7041 | |
| 7042 | public BatteryStatsImpl getBatteryStats() { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7043 | return mBsi; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7044 | } |
| 7045 | |
| 7046 | @Override |
| 7047 | public int getLaunches(int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 7048 | int val = mLaunches; |
| 7049 | if (which == STATS_CURRENT) { |
| 7050 | val -= mLoadedLaunches; |
| 7051 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 7052 | val -= mUnpluggedLaunches; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7053 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7054 | return val; |
| 7055 | } |
| 7056 | |
| 7057 | @Override |
| 7058 | public long getStartTime(long now, int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 7059 | long val = getStartTimeToNowLocked(now); |
| 7060 | if (which == STATS_CURRENT) { |
| 7061 | val -= mLoadedStartTime; |
| 7062 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 7063 | val -= mUnpluggedStartTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7064 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7065 | return val; |
| 7066 | } |
| 7067 | |
| 7068 | @Override |
| 7069 | public int getStarts(int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 7070 | int val = mStarts; |
| 7071 | if (which == STATS_CURRENT) { |
| 7072 | val -= mLoadedStarts; |
| 7073 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 7074 | val -= mUnpluggedStarts; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7075 | } |
| 7076 | |
| 7077 | return val; |
| 7078 | } |
| 7079 | } |
| 7080 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7081 | final Serv newServiceStatsLocked() { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7082 | return new Serv(mBsi); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7083 | } |
| 7084 | } |
| 7085 | |
| 7086 | /** |
| 7087 | * Retrieve the statistics object for a particular process, creating |
| 7088 | * if needed. |
| 7089 | */ |
| 7090 | public Proc getProcessStatsLocked(String name) { |
| 7091 | Proc ps = mProcessStats.get(name); |
| 7092 | if (ps == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7093 | ps = new Proc(mBsi, name); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7094 | mProcessStats.put(name, ps); |
| 7095 | } |
| 7096 | |
| 7097 | return ps; |
| 7098 | } |
| 7099 | |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 7100 | public void updateUidProcessStateLocked(int procState) { |
| 7101 | int uidRunningState; |
| 7102 | if (procState == ActivityManager.PROCESS_STATE_NONEXISTENT) { |
| 7103 | uidRunningState = ActivityManager.PROCESS_STATE_NONEXISTENT; |
| 7104 | } else if (procState == ActivityManager.PROCESS_STATE_TOP) { |
| 7105 | uidRunningState = PROCESS_STATE_TOP; |
| 7106 | } else if (procState <= ActivityManager.PROCESS_STATE_FOREGROUND_SERVICE) { |
| 7107 | // Persistent and other foreground states go here. |
| 7108 | uidRunningState = PROCESS_STATE_FOREGROUND_SERVICE; |
| 7109 | } else if (procState <= ActivityManager.PROCESS_STATE_TOP_SLEEPING) { |
| 7110 | uidRunningState = PROCESS_STATE_TOP_SLEEPING; |
| 7111 | } else if (procState <= ActivityManager.PROCESS_STATE_IMPORTANT_FOREGROUND) { |
| 7112 | // Persistent and other foreground states go here. |
| 7113 | uidRunningState = PROCESS_STATE_FOREGROUND; |
| 7114 | } else if (procState <= ActivityManager.PROCESS_STATE_RECEIVER) { |
| 7115 | uidRunningState = PROCESS_STATE_BACKGROUND; |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 7116 | } else { |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 7117 | uidRunningState = PROCESS_STATE_CACHED; |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 7118 | } |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 7119 | |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 7120 | if (mProcessState == uidRunningState) return; |
| 7121 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7122 | final long elapsedRealtime = mBsi.mClocks.elapsedRealtime(); |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 7123 | |
| 7124 | if (mProcessState != ActivityManager.PROCESS_STATE_NONEXISTENT) { |
| 7125 | mProcessStateTimer[mProcessState].stopRunningLocked(elapsedRealtime); |
| 7126 | } |
| 7127 | mProcessState = uidRunningState; |
| 7128 | if (uidRunningState != ActivityManager.PROCESS_STATE_NONEXISTENT) { |
| 7129 | if (mProcessStateTimer[uidRunningState] == null) { |
| 7130 | makeProcessState(uidRunningState, null); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 7131 | } |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 7132 | mProcessStateTimer[uidRunningState].startRunningLocked(elapsedRealtime); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 7133 | } |
| 7134 | } |
| 7135 | |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 7136 | public SparseArray<? extends Pid> getPidStats() { |
| 7137 | return mPids; |
| 7138 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7139 | |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 7140 | public Pid getPidStatsLocked(int pid) { |
| 7141 | Pid p = mPids.get(pid); |
| 7142 | if (p == null) { |
| 7143 | p = new Pid(); |
| 7144 | mPids.put(pid, p); |
| 7145 | } |
| 7146 | return p; |
| 7147 | } |
| 7148 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7149 | /** |
| 7150 | * Retrieve the statistics object for a particular service, creating |
| 7151 | * if needed. |
| 7152 | */ |
| 7153 | public Pkg getPackageStatsLocked(String name) { |
| 7154 | Pkg ps = mPackageStats.get(name); |
| 7155 | if (ps == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7156 | ps = new Pkg(mBsi); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7157 | mPackageStats.put(name, ps); |
| 7158 | } |
| 7159 | |
| 7160 | return ps; |
| 7161 | } |
| 7162 | |
| 7163 | /** |
| 7164 | * Retrieve the statistics object for a particular service, creating |
| 7165 | * if needed. |
| 7166 | */ |
| 7167 | public Pkg.Serv getServiceStatsLocked(String pkg, String serv) { |
| 7168 | Pkg ps = getPackageStatsLocked(pkg); |
| 7169 | Pkg.Serv ss = ps.mServiceStats.get(serv); |
| 7170 | if (ss == null) { |
| 7171 | ss = ps.newServiceStatsLocked(); |
| 7172 | ps.mServiceStats.put(serv, ss); |
| 7173 | } |
| 7174 | |
| 7175 | return ss; |
| 7176 | } |
| 7177 | |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 7178 | public void readSyncSummaryFromParcelLocked(String name, Parcel in) { |
| 7179 | StopwatchTimer timer = mSyncStats.instantiateObject(); |
| 7180 | timer.readSummaryFromParcelLocked(in); |
| 7181 | mSyncStats.add(name, timer); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 7182 | } |
| 7183 | |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 7184 | public void readJobSummaryFromParcelLocked(String name, Parcel in) { |
| 7185 | StopwatchTimer timer = mJobStats.instantiateObject(); |
| 7186 | timer.readSummaryFromParcelLocked(in); |
| 7187 | mJobStats.add(name, timer); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 7188 | } |
| 7189 | |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 7190 | public void readWakeSummaryFromParcelLocked(String wlName, Parcel in) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7191 | Wakelock wl = new Wakelock(mBsi, this); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 7192 | mWakelockStats.add(wlName, wl); |
| 7193 | if (in.readInt() != 0) { |
| 7194 | wl.getStopwatchTimer(WAKE_TYPE_FULL).readSummaryFromParcelLocked(in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7195 | } |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 7196 | if (in.readInt() != 0) { |
| 7197 | wl.getStopwatchTimer(WAKE_TYPE_PARTIAL).readSummaryFromParcelLocked(in); |
| 7198 | } |
| 7199 | if (in.readInt() != 0) { |
| 7200 | wl.getStopwatchTimer(WAKE_TYPE_WINDOW).readSummaryFromParcelLocked(in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7201 | } |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 7202 | if (in.readInt() != 0) { |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 7203 | wl.getStopwatchTimer(WAKE_TYPE_DRAW).readSummaryFromParcelLocked(in); |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 7204 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7205 | } |
| 7206 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 7207 | public StopwatchTimer getSensorTimerLocked(int sensor, boolean create) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7208 | Sensor se = mSensorStats.get(sensor); |
| 7209 | if (se == null) { |
| 7210 | if (!create) { |
| 7211 | return null; |
| 7212 | } |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7213 | se = new Sensor(mBsi, this, sensor); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7214 | mSensorStats.put(sensor, se); |
| 7215 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 7216 | StopwatchTimer t = se.mTimer; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7217 | if (t != null) { |
| 7218 | return t; |
| 7219 | } |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7220 | ArrayList<StopwatchTimer> timers = mBsi.mSensorTimers.get(sensor); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7221 | if (timers == null) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 7222 | timers = new ArrayList<StopwatchTimer>(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7223 | mBsi.mSensorTimers.put(sensor, timers); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7224 | } |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7225 | t = new StopwatchTimer(mBsi.mClocks, this, BatteryStats.SENSOR, timers, |
| 7226 | mBsi.mOnBatteryTimeBase); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7227 | se.mTimer = t; |
| 7228 | return t; |
| 7229 | } |
| 7230 | |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 7231 | public void noteStartSyncLocked(String name, long elapsedRealtimeMs) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 7232 | StopwatchTimer t = mSyncStats.startObject(name); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 7233 | if (t != null) { |
| 7234 | t.startRunningLocked(elapsedRealtimeMs); |
| 7235 | } |
| 7236 | } |
| 7237 | |
| 7238 | public void noteStopSyncLocked(String name, long elapsedRealtimeMs) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 7239 | StopwatchTimer t = mSyncStats.stopObject(name); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 7240 | if (t != null) { |
| 7241 | t.stopRunningLocked(elapsedRealtimeMs); |
| 7242 | } |
| 7243 | } |
| 7244 | |
| 7245 | public void noteStartJobLocked(String name, long elapsedRealtimeMs) { |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 7246 | StopwatchTimer t = mJobStats.startObject(name); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 7247 | if (t != null) { |
| 7248 | t.startRunningLocked(elapsedRealtimeMs); |
| 7249 | } |
| 7250 | } |
| 7251 | |
| 7252 | public void noteStopJobLocked(String name, long elapsedRealtimeMs) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 7253 | StopwatchTimer t = mJobStats.stopObject(name); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 7254 | if (t != null) { |
| 7255 | t.stopRunningLocked(elapsedRealtimeMs); |
| 7256 | } |
| 7257 | } |
| 7258 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7259 | public void noteStartWakeLocked(int pid, String name, int type, long elapsedRealtimeMs) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 7260 | Wakelock wl = mWakelockStats.startObject(name); |
| 7261 | if (wl != null) { |
| 7262 | wl.getStopwatchTimer(type).startRunningLocked(elapsedRealtimeMs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7263 | } |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 7264 | if (pid >= 0 && type == WAKE_TYPE_PARTIAL) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 7265 | Pid p = getPidStatsLocked(pid); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 7266 | if (p.mWakeNesting++ == 0) { |
| 7267 | p.mWakeStartMs = elapsedRealtimeMs; |
Dianne Hackborn | b8071d79 | 2010-09-09 16:45:15 -0700 | [diff] [blame] | 7268 | } |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 7269 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7270 | } |
| 7271 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7272 | public void noteStopWakeLocked(int pid, String name, int type, long elapsedRealtimeMs) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 7273 | Wakelock wl = mWakelockStats.stopObject(name); |
| 7274 | if (wl != null) { |
| 7275 | wl.getStopwatchTimer(type).stopRunningLocked(elapsedRealtimeMs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7276 | } |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 7277 | if (pid >= 0 && type == WAKE_TYPE_PARTIAL) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 7278 | Pid p = mPids.get(pid); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 7279 | if (p != null && p.mWakeNesting > 0) { |
| 7280 | if (p.mWakeNesting-- == 1) { |
| 7281 | p.mWakeSumMs += elapsedRealtimeMs - p.mWakeStartMs; |
| 7282 | p.mWakeStartMs = 0; |
| 7283 | } |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 7284 | } |
| 7285 | } |
| 7286 | } |
| 7287 | |
| 7288 | public void reportExcessiveWakeLocked(String proc, long overTime, long usedTime) { |
| 7289 | Proc p = getProcessStatsLocked(proc); |
| 7290 | if (p != null) { |
| 7291 | p.addExcessiveWake(overTime, usedTime); |
| 7292 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7293 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7294 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 7295 | public void reportExcessiveCpuLocked(String proc, long overTime, long usedTime) { |
| 7296 | Proc p = getProcessStatsLocked(proc); |
| 7297 | if (p != null) { |
| 7298 | p.addExcessiveCpu(overTime, usedTime); |
| 7299 | } |
| 7300 | } |
| 7301 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7302 | public void noteStartSensor(int sensor, long elapsedRealtimeMs) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 7303 | StopwatchTimer t = getSensorTimerLocked(sensor, true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7304 | if (t != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7305 | t.startRunningLocked(elapsedRealtimeMs); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7306 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7307 | } |
| 7308 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7309 | public void noteStopSensor(int sensor, long elapsedRealtimeMs) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7310 | // Don't create a timer if one doesn't already exist |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 7311 | StopwatchTimer t = getSensorTimerLocked(sensor, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7312 | if (t != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7313 | t.stopRunningLocked(elapsedRealtimeMs); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7314 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7315 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7316 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7317 | public void noteStartGps(long elapsedRealtimeMs) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 7318 | StopwatchTimer t = getSensorTimerLocked(Sensor.GPS, true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7319 | if (t != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7320 | t.startRunningLocked(elapsedRealtimeMs); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7321 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7322 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7323 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7324 | public void noteStopGps(long elapsedRealtimeMs) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 7325 | StopwatchTimer t = getSensorTimerLocked(Sensor.GPS, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7326 | if (t != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7327 | t.stopRunningLocked(elapsedRealtimeMs); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 7328 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7329 | } |
| 7330 | |
| 7331 | public BatteryStatsImpl getBatteryStats() { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7332 | return mBsi; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7333 | } |
| 7334 | } |
| 7335 | |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 7336 | public BatteryStatsImpl(File systemDir, Handler handler, ExternalStatsSync externalSync) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7337 | this(new SystemClocks(), systemDir, handler, externalSync); |
| 7338 | } |
| 7339 | |
| 7340 | public BatteryStatsImpl(Clocks clocks, File systemDir, Handler handler, |
| 7341 | ExternalStatsSync externalSync) { |
| 7342 | init(clocks); |
| 7343 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 7344 | if (systemDir != null) { |
| 7345 | mFile = new JournaledFile(new File(systemDir, "batterystats.bin"), |
| 7346 | new File(systemDir, "batterystats.bin.tmp")); |
| 7347 | } else { |
| 7348 | mFile = null; |
| 7349 | } |
| 7350 | mCheckinFile = new AtomicFile(new File(systemDir, "batterystats-checkin.bin")); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 7351 | mDailyFile = new AtomicFile(new File(systemDir, "batterystats-daily.xml")); |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 7352 | mExternalSync = externalSync; |
Jeff Brown | 6f357d3 | 2014-01-15 20:40:55 -0800 | [diff] [blame] | 7353 | mHandler = new MyHandler(handler.getLooper()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7354 | mStartCount++; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7355 | mScreenOnTimer = new StopwatchTimer(mClocks, null, -1, null, mOnBatteryTimeBase); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 7356 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7357 | mScreenBrightnessTimer[i] = new StopwatchTimer(mClocks, null, -100-i, null, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7358 | mOnBatteryTimeBase); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 7359 | } |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7360 | mInteractiveTimer = new StopwatchTimer(mClocks, null, -10, null, mOnBatteryTimeBase); |
| 7361 | mPowerSaveModeEnabledTimer = new StopwatchTimer(mClocks, null, -2, null, |
| 7362 | mOnBatteryTimeBase); |
| 7363 | mDeviceIdleModeLightTimer = new StopwatchTimer(mClocks, null, -11, null, |
| 7364 | mOnBatteryTimeBase); |
| 7365 | mDeviceIdleModeFullTimer = new StopwatchTimer(mClocks, null, -14, null, mOnBatteryTimeBase); |
| 7366 | mDeviceLightIdlingTimer = new StopwatchTimer(mClocks, null, -15, null, mOnBatteryTimeBase); |
| 7367 | mDeviceIdlingTimer = new StopwatchTimer(mClocks, null, -12, null, mOnBatteryTimeBase); |
| 7368 | mPhoneOnTimer = new StopwatchTimer(mClocks, null, -3, null, mOnBatteryTimeBase); |
| 7369 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
| 7370 | mPhoneSignalStrengthsTimer[i] = new StopwatchTimer(mClocks, null, -200-i, null, |
| 7371 | mOnBatteryTimeBase); |
| 7372 | } |
| 7373 | mPhoneSignalScanningTimer = new StopwatchTimer(mClocks, null, -200+1, null, |
| 7374 | mOnBatteryTimeBase); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 7375 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7376 | mPhoneDataConnectionsTimer[i] = new StopwatchTimer(mClocks, null, -300-i, null, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7377 | mOnBatteryTimeBase); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 7378 | } |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 7379 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7380 | mNetworkByteActivityCounters[i] = new LongSamplingCounter(mOnBatteryTimeBase); |
| 7381 | mNetworkPacketActivityCounters[i] = new LongSamplingCounter(mOnBatteryTimeBase); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 7382 | } |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 7383 | mWifiActivity = new ControllerActivityCounterImpl(mOnBatteryTimeBase, NUM_WIFI_TX_LEVELS); |
| 7384 | mBluetoothActivity = new ControllerActivityCounterImpl(mOnBatteryTimeBase, |
| 7385 | NUM_BT_TX_LEVELS); |
| 7386 | mModemActivity = new ControllerActivityCounterImpl(mOnBatteryTimeBase, |
| 7387 | ModemActivityInfo.TX_POWER_LEVELS); |
| 7388 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7389 | mMobileRadioActiveTimer = new StopwatchTimer(mClocks, null, -400, null, mOnBatteryTimeBase); |
| 7390 | mMobileRadioActivePerAppTimer = new StopwatchTimer(mClocks, null, -401, null, |
| 7391 | mOnBatteryTimeBase); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 7392 | mMobileRadioActiveAdjustedTime = new LongSamplingCounter(mOnBatteryTimeBase); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7393 | mMobileRadioActiveUnknownTime = new LongSamplingCounter(mOnBatteryTimeBase); |
| 7394 | mMobileRadioActiveUnknownCount = new LongSamplingCounter(mOnBatteryTimeBase); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7395 | mWifiOnTimer = new StopwatchTimer(mClocks, null, -4, null, mOnBatteryTimeBase); |
| 7396 | mGlobalWifiRunningTimer = new StopwatchTimer(mClocks, null, -5, null, mOnBatteryTimeBase); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 7397 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7398 | mWifiStateTimer[i] = new StopwatchTimer(mClocks, null, -600-i, null, |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 7399 | mOnBatteryTimeBase); |
| 7400 | } |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7401 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
| 7402 | mWifiSupplStateTimer[i] = new StopwatchTimer(mClocks, null, -700-i, null, |
| 7403 | mOnBatteryTimeBase); |
| 7404 | } |
| 7405 | for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 7406 | mWifiSignalStrengthsTimer[i] = new StopwatchTimer(mClocks, null, -800-i, null, |
| 7407 | mOnBatteryTimeBase); |
| 7408 | } |
| 7409 | mAudioOnTimer = new StopwatchTimer(mClocks, null, -7, null, mOnBatteryTimeBase); |
| 7410 | mVideoOnTimer = new StopwatchTimer(mClocks, null, -8, null, mOnBatteryTimeBase); |
| 7411 | mFlashlightOnTimer = new StopwatchTimer(mClocks, null, -9, null, mOnBatteryTimeBase); |
| 7412 | mCameraOnTimer = new StopwatchTimer(mClocks, null, -13, null, mOnBatteryTimeBase); |
| 7413 | mBluetoothScanTimer = new StopwatchTimer(mClocks, null, -14, null, mOnBatteryTimeBase); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7414 | mOnBattery = mOnBatteryInternal = false; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7415 | long uptime = mClocks.uptimeMillis() * 1000; |
| 7416 | long realtime = mClocks.elapsedRealtime() * 1000; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7417 | initTimes(uptime, realtime); |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 7418 | mStartPlatformVersion = mEndPlatformVersion = Build.ID; |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 7419 | mDischargeStartLevel = 0; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7420 | mDischargeUnplugLevel = 0; |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 7421 | mDischargePlugLevel = -1; |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 7422 | mDischargeCurrentLevel = 0; |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 7423 | mCurrentBatteryLevel = 0; |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 7424 | initDischarge(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 7425 | clearHistoryLocked(); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 7426 | updateDailyDeadlineLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7427 | } |
| 7428 | |
| 7429 | public BatteryStatsImpl(Parcel p) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7430 | this(new SystemClocks(), p); |
| 7431 | } |
| 7432 | |
| 7433 | public BatteryStatsImpl(Clocks clocks, Parcel p) { |
| 7434 | init(clocks); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 7435 | mFile = null; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 7436 | mCheckinFile = null; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 7437 | mDailyFile = null; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 7438 | mHandler = null; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 7439 | mExternalSync = null; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 7440 | clearHistoryLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7441 | readFromParcel(p); |
| 7442 | } |
| 7443 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 7444 | public void setPowerProfile(PowerProfile profile) { |
| 7445 | synchronized (this) { |
| 7446 | mPowerProfile = profile; |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 7447 | |
| 7448 | // We need to initialize the KernelCpuSpeedReaders to read from |
| 7449 | // the first cpu of each core. Once we have the PowerProfile, we have access to this |
| 7450 | // information. |
| 7451 | final int numClusters = mPowerProfile.getNumCpuClusters(); |
| 7452 | mKernelCpuSpeedReaders = new KernelCpuSpeedReader[numClusters]; |
| 7453 | int firstCpuOfCluster = 0; |
| 7454 | for (int i = 0; i < numClusters; i++) { |
| 7455 | final int numSpeedSteps = mPowerProfile.getNumSpeedStepsInCpuCluster(i); |
| 7456 | mKernelCpuSpeedReaders[i] = new KernelCpuSpeedReader(firstCpuOfCluster, |
| 7457 | numSpeedSteps); |
| 7458 | firstCpuOfCluster += mPowerProfile.getNumCoresInCpuCluster(i); |
| 7459 | } |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 7460 | } |
| 7461 | } |
| 7462 | |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 7463 | public void setCallback(BatteryCallback cb) { |
| 7464 | mCallback = cb; |
| 7465 | } |
| 7466 | |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 7467 | public void setRadioScanningTimeout(long timeout) { |
| 7468 | if (mPhoneSignalScanningTimer != null) { |
| 7469 | mPhoneSignalScanningTimer.setTimeout(timeout); |
| 7470 | } |
| 7471 | } |
| 7472 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 7473 | public void updateDailyDeadlineLocked() { |
| 7474 | // Get the current time. |
| 7475 | long currentTime = mDailyStartTime = System.currentTimeMillis(); |
| 7476 | Calendar calDeadline = Calendar.getInstance(); |
| 7477 | calDeadline.setTimeInMillis(currentTime); |
| 7478 | |
| 7479 | // Move time up to the next day, ranging from 1am to 3pm. |
| 7480 | calDeadline.set(Calendar.DAY_OF_YEAR, calDeadline.get(Calendar.DAY_OF_YEAR) + 1); |
| 7481 | calDeadline.set(Calendar.MILLISECOND, 0); |
| 7482 | calDeadline.set(Calendar.SECOND, 0); |
| 7483 | calDeadline.set(Calendar.MINUTE, 0); |
| 7484 | calDeadline.set(Calendar.HOUR_OF_DAY, 1); |
| 7485 | mNextMinDailyDeadline = calDeadline.getTimeInMillis(); |
| 7486 | calDeadline.set(Calendar.HOUR_OF_DAY, 3); |
| 7487 | mNextMaxDailyDeadline = calDeadline.getTimeInMillis(); |
| 7488 | } |
| 7489 | |
| 7490 | public void recordDailyStatsIfNeededLocked(boolean settled) { |
| 7491 | long currentTime = System.currentTimeMillis(); |
| 7492 | if (currentTime >= mNextMaxDailyDeadline) { |
| 7493 | recordDailyStatsLocked(); |
| 7494 | } else if (settled && currentTime >= mNextMinDailyDeadline) { |
| 7495 | recordDailyStatsLocked(); |
| 7496 | } else if (currentTime < (mDailyStartTime-(1000*60*60*24))) { |
| 7497 | recordDailyStatsLocked(); |
| 7498 | } |
| 7499 | } |
| 7500 | |
| 7501 | public void recordDailyStatsLocked() { |
| 7502 | DailyItem item = new DailyItem(); |
| 7503 | item.mStartTime = mDailyStartTime; |
| 7504 | item.mEndTime = System.currentTimeMillis(); |
| 7505 | boolean hasData = false; |
| 7506 | if (mDailyDischargeStepTracker.mNumStepDurations > 0) { |
| 7507 | hasData = true; |
| 7508 | item.mDischargeSteps = new LevelStepTracker( |
| 7509 | mDailyDischargeStepTracker.mNumStepDurations, |
| 7510 | mDailyDischargeStepTracker.mStepDurations); |
| 7511 | } |
| 7512 | if (mDailyChargeStepTracker.mNumStepDurations > 0) { |
| 7513 | hasData = true; |
| 7514 | item.mChargeSteps = new LevelStepTracker( |
| 7515 | mDailyChargeStepTracker.mNumStepDurations, |
| 7516 | mDailyChargeStepTracker.mStepDurations); |
| 7517 | } |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 7518 | if (mDailyPackageChanges != null) { |
| 7519 | hasData = true; |
| 7520 | item.mPackageChanges = mDailyPackageChanges; |
| 7521 | mDailyPackageChanges = null; |
| 7522 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 7523 | mDailyDischargeStepTracker.init(); |
| 7524 | mDailyChargeStepTracker.init(); |
| 7525 | updateDailyDeadlineLocked(); |
| 7526 | |
| 7527 | if (hasData) { |
| 7528 | mDailyItems.add(item); |
| 7529 | while (mDailyItems.size() > MAX_DAILY_ITEMS) { |
| 7530 | mDailyItems.remove(0); |
| 7531 | } |
| 7532 | final ByteArrayOutputStream memStream = new ByteArrayOutputStream(); |
| 7533 | try { |
| 7534 | XmlSerializer out = new FastXmlSerializer(); |
Wojciech Staszkiewicz | 9e9e2e7 | 2015-05-08 14:58:46 +0100 | [diff] [blame] | 7535 | out.setOutput(memStream, StandardCharsets.UTF_8.name()); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 7536 | writeDailyItemsLocked(out); |
| 7537 | BackgroundThread.getHandler().post(new Runnable() { |
| 7538 | @Override |
| 7539 | public void run() { |
| 7540 | synchronized (mCheckinFile) { |
| 7541 | FileOutputStream stream = null; |
| 7542 | try { |
| 7543 | stream = mDailyFile.startWrite(); |
| 7544 | memStream.writeTo(stream); |
| 7545 | stream.flush(); |
| 7546 | FileUtils.sync(stream); |
| 7547 | stream.close(); |
| 7548 | mDailyFile.finishWrite(stream); |
| 7549 | } catch (IOException e) { |
| 7550 | Slog.w("BatteryStats", |
| 7551 | "Error writing battery daily items", e); |
| 7552 | mDailyFile.failWrite(stream); |
| 7553 | } |
| 7554 | } |
| 7555 | } |
| 7556 | }); |
| 7557 | } catch (IOException e) { |
| 7558 | } |
| 7559 | } |
| 7560 | } |
| 7561 | |
| 7562 | private void writeDailyItemsLocked(XmlSerializer out) throws IOException { |
| 7563 | StringBuilder sb = new StringBuilder(64); |
| 7564 | out.startDocument(null, true); |
| 7565 | out.startTag(null, "daily-items"); |
| 7566 | for (int i=0; i<mDailyItems.size(); i++) { |
| 7567 | final DailyItem dit = mDailyItems.get(i); |
| 7568 | out.startTag(null, "item"); |
| 7569 | out.attribute(null, "start", Long.toString(dit.mStartTime)); |
| 7570 | out.attribute(null, "end", Long.toString(dit.mEndTime)); |
| 7571 | writeDailyLevelSteps(out, "dis", dit.mDischargeSteps, sb); |
| 7572 | writeDailyLevelSteps(out, "chg", dit.mChargeSteps, sb); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 7573 | if (dit.mPackageChanges != null) { |
| 7574 | for (int j=0; j<dit.mPackageChanges.size(); j++) { |
| 7575 | PackageChange pc = dit.mPackageChanges.get(j); |
| 7576 | if (pc.mUpdate) { |
| 7577 | out.startTag(null, "upd"); |
| 7578 | out.attribute(null, "pkg", pc.mPackageName); |
| 7579 | out.attribute(null, "ver", Integer.toString(pc.mVersionCode)); |
| 7580 | out.endTag(null, "upd"); |
| 7581 | } else { |
| 7582 | out.startTag(null, "rem"); |
| 7583 | out.attribute(null, "pkg", pc.mPackageName); |
| 7584 | out.endTag(null, "rem"); |
| 7585 | } |
| 7586 | } |
| 7587 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 7588 | out.endTag(null, "item"); |
| 7589 | } |
| 7590 | out.endTag(null, "daily-items"); |
| 7591 | out.endDocument(); |
| 7592 | } |
| 7593 | |
| 7594 | private void writeDailyLevelSteps(XmlSerializer out, String tag, LevelStepTracker steps, |
| 7595 | StringBuilder tmpBuilder) throws IOException { |
| 7596 | if (steps != null) { |
| 7597 | out.startTag(null, tag); |
| 7598 | out.attribute(null, "n", Integer.toString(steps.mNumStepDurations)); |
| 7599 | for (int i=0; i<steps.mNumStepDurations; i++) { |
| 7600 | out.startTag(null, "s"); |
| 7601 | tmpBuilder.setLength(0); |
| 7602 | steps.encodeEntryAt(i, tmpBuilder); |
| 7603 | out.attribute(null, "v", tmpBuilder.toString()); |
| 7604 | out.endTag(null, "s"); |
| 7605 | } |
| 7606 | out.endTag(null, tag); |
| 7607 | } |
| 7608 | } |
| 7609 | |
| 7610 | public void readDailyStatsLocked() { |
| 7611 | Slog.d(TAG, "Reading daily items from " + mDailyFile.getBaseFile()); |
| 7612 | mDailyItems.clear(); |
| 7613 | FileInputStream stream; |
| 7614 | try { |
| 7615 | stream = mDailyFile.openRead(); |
| 7616 | } catch (FileNotFoundException e) { |
| 7617 | return; |
| 7618 | } |
| 7619 | try { |
| 7620 | XmlPullParser parser = Xml.newPullParser(); |
Wojciech Staszkiewicz | 9e9e2e7 | 2015-05-08 14:58:46 +0100 | [diff] [blame] | 7621 | parser.setInput(stream, StandardCharsets.UTF_8.name()); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 7622 | readDailyItemsLocked(parser); |
| 7623 | } catch (XmlPullParserException e) { |
| 7624 | } finally { |
| 7625 | try { |
| 7626 | stream.close(); |
| 7627 | } catch (IOException e) { |
| 7628 | } |
| 7629 | } |
| 7630 | } |
| 7631 | |
| 7632 | private void readDailyItemsLocked(XmlPullParser parser) { |
| 7633 | try { |
| 7634 | int type; |
| 7635 | while ((type = parser.next()) != XmlPullParser.START_TAG |
| 7636 | && type != XmlPullParser.END_DOCUMENT) { |
| 7637 | ; |
| 7638 | } |
| 7639 | |
| 7640 | if (type != XmlPullParser.START_TAG) { |
| 7641 | throw new IllegalStateException("no start tag found"); |
| 7642 | } |
| 7643 | |
| 7644 | int outerDepth = parser.getDepth(); |
| 7645 | while ((type = parser.next()) != XmlPullParser.END_DOCUMENT |
| 7646 | && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) { |
| 7647 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 7648 | continue; |
| 7649 | } |
| 7650 | |
| 7651 | String tagName = parser.getName(); |
| 7652 | if (tagName.equals("item")) { |
| 7653 | readDailyItemTagLocked(parser); |
| 7654 | } else { |
| 7655 | Slog.w(TAG, "Unknown element under <daily-items>: " |
| 7656 | + parser.getName()); |
| 7657 | XmlUtils.skipCurrentTag(parser); |
| 7658 | } |
| 7659 | } |
| 7660 | |
| 7661 | } catch (IllegalStateException e) { |
| 7662 | Slog.w(TAG, "Failed parsing daily " + e); |
| 7663 | } catch (NullPointerException e) { |
| 7664 | Slog.w(TAG, "Failed parsing daily " + e); |
| 7665 | } catch (NumberFormatException e) { |
| 7666 | Slog.w(TAG, "Failed parsing daily " + e); |
| 7667 | } catch (XmlPullParserException e) { |
| 7668 | Slog.w(TAG, "Failed parsing daily " + e); |
| 7669 | } catch (IOException e) { |
| 7670 | Slog.w(TAG, "Failed parsing daily " + e); |
| 7671 | } catch (IndexOutOfBoundsException e) { |
| 7672 | Slog.w(TAG, "Failed parsing daily " + e); |
| 7673 | } |
| 7674 | } |
| 7675 | |
| 7676 | void readDailyItemTagLocked(XmlPullParser parser) throws NumberFormatException, |
| 7677 | XmlPullParserException, IOException { |
| 7678 | DailyItem dit = new DailyItem(); |
| 7679 | String attr = parser.getAttributeValue(null, "start"); |
| 7680 | if (attr != null) { |
| 7681 | dit.mStartTime = Long.parseLong(attr); |
| 7682 | } |
| 7683 | attr = parser.getAttributeValue(null, "end"); |
| 7684 | if (attr != null) { |
| 7685 | dit.mEndTime = Long.parseLong(attr); |
| 7686 | } |
| 7687 | int outerDepth = parser.getDepth(); |
| 7688 | int type; |
| 7689 | while ((type = parser.next()) != XmlPullParser.END_DOCUMENT |
| 7690 | && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) { |
| 7691 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 7692 | continue; |
| 7693 | } |
| 7694 | |
| 7695 | String tagName = parser.getName(); |
| 7696 | if (tagName.equals("dis")) { |
| 7697 | readDailyItemTagDetailsLocked(parser, dit, false, "dis"); |
| 7698 | } else if (tagName.equals("chg")) { |
| 7699 | readDailyItemTagDetailsLocked(parser, dit, true, "chg"); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 7700 | } else if (tagName.equals("upd")) { |
| 7701 | if (dit.mPackageChanges == null) { |
| 7702 | dit.mPackageChanges = new ArrayList<>(); |
| 7703 | } |
| 7704 | PackageChange pc = new PackageChange(); |
| 7705 | pc.mUpdate = true; |
| 7706 | pc.mPackageName = parser.getAttributeValue(null, "pkg"); |
| 7707 | String verStr = parser.getAttributeValue(null, "ver"); |
| 7708 | pc.mVersionCode = verStr != null ? Integer.parseInt(verStr) : 0; |
| 7709 | dit.mPackageChanges.add(pc); |
| 7710 | XmlUtils.skipCurrentTag(parser); |
| 7711 | } else if (tagName.equals("rem")) { |
| 7712 | if (dit.mPackageChanges == null) { |
| 7713 | dit.mPackageChanges = new ArrayList<>(); |
| 7714 | } |
| 7715 | PackageChange pc = new PackageChange(); |
| 7716 | pc.mUpdate = false; |
| 7717 | pc.mPackageName = parser.getAttributeValue(null, "pkg"); |
| 7718 | dit.mPackageChanges.add(pc); |
| 7719 | XmlUtils.skipCurrentTag(parser); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 7720 | } else { |
| 7721 | Slog.w(TAG, "Unknown element under <item>: " |
| 7722 | + parser.getName()); |
| 7723 | XmlUtils.skipCurrentTag(parser); |
| 7724 | } |
| 7725 | } |
| 7726 | mDailyItems.add(dit); |
| 7727 | } |
| 7728 | |
| 7729 | void readDailyItemTagDetailsLocked(XmlPullParser parser, DailyItem dit, boolean isCharge, |
| 7730 | String tag) |
| 7731 | throws NumberFormatException, XmlPullParserException, IOException { |
| 7732 | final String numAttr = parser.getAttributeValue(null, "n"); |
| 7733 | if (numAttr == null) { |
| 7734 | Slog.w(TAG, "Missing 'n' attribute at " + parser.getPositionDescription()); |
| 7735 | XmlUtils.skipCurrentTag(parser); |
| 7736 | return; |
| 7737 | } |
| 7738 | final int num = Integer.parseInt(numAttr); |
| 7739 | LevelStepTracker steps = new LevelStepTracker(num); |
| 7740 | if (isCharge) { |
| 7741 | dit.mChargeSteps = steps; |
| 7742 | } else { |
| 7743 | dit.mDischargeSteps = steps; |
| 7744 | } |
| 7745 | int i = 0; |
| 7746 | int outerDepth = parser.getDepth(); |
| 7747 | int type; |
| 7748 | while ((type = parser.next()) != XmlPullParser.END_DOCUMENT |
| 7749 | && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) { |
| 7750 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 7751 | continue; |
| 7752 | } |
| 7753 | |
| 7754 | String tagName = parser.getName(); |
| 7755 | if ("s".equals(tagName)) { |
| 7756 | if (i < num) { |
| 7757 | String valueAttr = parser.getAttributeValue(null, "v"); |
| 7758 | if (valueAttr != null) { |
| 7759 | steps.decodeEntryAt(i, valueAttr); |
| 7760 | i++; |
| 7761 | } |
| 7762 | } |
| 7763 | } else { |
| 7764 | Slog.w(TAG, "Unknown element under <" + tag + ">: " |
| 7765 | + parser.getName()); |
| 7766 | XmlUtils.skipCurrentTag(parser); |
| 7767 | } |
| 7768 | } |
| 7769 | steps.mNumStepDurations = i; |
| 7770 | } |
| 7771 | |
| 7772 | @Override |
| 7773 | public DailyItem getDailyItemLocked(int daysAgo) { |
| 7774 | int index = mDailyItems.size()-1-daysAgo; |
| 7775 | return index >= 0 ? mDailyItems.get(index) : null; |
| 7776 | } |
| 7777 | |
| 7778 | @Override |
| 7779 | public long getCurrentDailyStartTime() { |
| 7780 | return mDailyStartTime; |
| 7781 | } |
| 7782 | |
| 7783 | @Override |
| 7784 | public long getNextMinDailyDeadline() { |
| 7785 | return mNextMinDailyDeadline; |
| 7786 | } |
| 7787 | |
| 7788 | @Override |
| 7789 | public long getNextMaxDailyDeadline() { |
| 7790 | return mNextMaxDailyDeadline; |
| 7791 | } |
| 7792 | |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 7793 | @Override |
| 7794 | public boolean startIteratingOldHistoryLocked() { |
| 7795 | if (DEBUG_HISTORY) Slog.i(TAG, "ITERATING: buff size=" + mHistoryBuffer.dataSize() |
| 7796 | + " pos=" + mHistoryBuffer.dataPosition()); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 7797 | if ((mHistoryIterator = mHistory) == null) { |
| 7798 | return false; |
| 7799 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 7800 | mHistoryBuffer.setDataPosition(0); |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 7801 | mHistoryReadTmp.clear(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 7802 | mReadOverflow = false; |
| 7803 | mIteratingHistory = true; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 7804 | return true; |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 7805 | } |
| 7806 | |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 7807 | @Override |
| 7808 | public boolean getNextOldHistoryLocked(HistoryItem out) { |
| 7809 | boolean end = mHistoryBuffer.dataPosition() >= mHistoryBuffer.dataSize(); |
| 7810 | if (!end) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 7811 | readHistoryDelta(mHistoryBuffer, mHistoryReadTmp); |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 7812 | mReadOverflow |= mHistoryReadTmp.cmd == HistoryItem.CMD_OVERFLOW; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 7813 | } |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 7814 | HistoryItem cur = mHistoryIterator; |
| 7815 | if (cur == null) { |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 7816 | if (!mReadOverflow && !end) { |
| 7817 | Slog.w(TAG, "Old history ends before new history!"); |
| 7818 | } |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 7819 | return false; |
| 7820 | } |
| 7821 | out.setTo(cur); |
| 7822 | mHistoryIterator = cur.next; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 7823 | if (!mReadOverflow) { |
| 7824 | if (end) { |
| 7825 | Slog.w(TAG, "New history ends before old history!"); |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 7826 | } else if (!out.same(mHistoryReadTmp)) { |
Dianne Hackborn | 8c84109 | 2013-06-24 13:46:13 -0700 | [diff] [blame] | 7827 | PrintWriter pw = new FastPrintWriter(new LogWriter(android.util.Log.WARN, TAG)); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 7828 | pw.println("Histories differ!"); |
| 7829 | pw.println("Old history:"); |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 7830 | (new HistoryPrinter()).printNextItem(pw, out, 0, false, true); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 7831 | pw.println("New history:"); |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 7832 | (new HistoryPrinter()).printNextItem(pw, mHistoryReadTmp, 0, false, |
| 7833 | true); |
Dianne Hackborn | 8c84109 | 2013-06-24 13:46:13 -0700 | [diff] [blame] | 7834 | pw.flush(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 7835 | } |
| 7836 | } |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 7837 | return true; |
| 7838 | } |
| 7839 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7840 | @Override |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 7841 | public void finishIteratingOldHistoryLocked() { |
| 7842 | mIteratingHistory = false; |
| 7843 | mHistoryBuffer.setDataPosition(mHistoryBuffer.dataSize()); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 7844 | mHistoryIterator = null; |
| 7845 | } |
| 7846 | |
| 7847 | public int getHistoryTotalSize() { |
| 7848 | return MAX_HISTORY_BUFFER; |
| 7849 | } |
| 7850 | |
| 7851 | public int getHistoryUsedSize() { |
| 7852 | return mHistoryBuffer.dataSize(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 7853 | } |
| 7854 | |
| 7855 | @Override |
| 7856 | public boolean startIteratingHistoryLocked() { |
| 7857 | if (DEBUG_HISTORY) Slog.i(TAG, "ITERATING: buff size=" + mHistoryBuffer.dataSize() |
| 7858 | + " pos=" + mHistoryBuffer.dataPosition()); |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 7859 | if (mHistoryBuffer.dataSize() <= 0) { |
| 7860 | return false; |
| 7861 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 7862 | mHistoryBuffer.setDataPosition(0); |
| 7863 | mReadOverflow = false; |
| 7864 | mIteratingHistory = true; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 7865 | mReadHistoryStrings = new String[mHistoryTagPool.size()]; |
| 7866 | mReadHistoryUids = new int[mHistoryTagPool.size()]; |
| 7867 | mReadHistoryChars = 0; |
| 7868 | for (HashMap.Entry<HistoryTag, Integer> ent : mHistoryTagPool.entrySet()) { |
| 7869 | final HistoryTag tag = ent.getKey(); |
| 7870 | final int idx = ent.getValue(); |
| 7871 | mReadHistoryStrings[idx] = tag.string; |
| 7872 | mReadHistoryUids[idx] = tag.uid; |
| 7873 | mReadHistoryChars += tag.string.length() + 1; |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 7874 | } |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 7875 | return true; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 7876 | } |
| 7877 | |
| 7878 | @Override |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 7879 | public int getHistoryStringPoolSize() { |
| 7880 | return mReadHistoryStrings.length; |
| 7881 | } |
| 7882 | |
| 7883 | @Override |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 7884 | public int getHistoryStringPoolBytes() { |
| 7885 | // Each entry is a fixed 12 bytes: 4 for index, 4 for uid, 4 for string size |
| 7886 | // Each string character is 2 bytes. |
| 7887 | return (mReadHistoryStrings.length * 12) + (mReadHistoryChars * 2); |
| 7888 | } |
| 7889 | |
| 7890 | @Override |
| 7891 | public String getHistoryTagPoolString(int index) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 7892 | return mReadHistoryStrings[index]; |
| 7893 | } |
| 7894 | |
| 7895 | @Override |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 7896 | public int getHistoryTagPoolUid(int index) { |
| 7897 | return mReadHistoryUids[index]; |
| 7898 | } |
| 7899 | |
| 7900 | @Override |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 7901 | public boolean getNextHistoryLocked(HistoryItem out) { |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 7902 | final int pos = mHistoryBuffer.dataPosition(); |
| 7903 | if (pos == 0) { |
| 7904 | out.clear(); |
| 7905 | } |
| 7906 | boolean end = pos >= mHistoryBuffer.dataSize(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 7907 | if (end) { |
| 7908 | return false; |
| 7909 | } |
| 7910 | |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 7911 | final long lastRealtime = out.time; |
| 7912 | final long lastWalltime = out.currentTime; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 7913 | readHistoryDelta(mHistoryBuffer, out); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 7914 | if (out.cmd != HistoryItem.CMD_CURRENT_TIME |
| 7915 | && out.cmd != HistoryItem.CMD_RESET && lastWalltime != 0) { |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 7916 | out.currentTime = lastWalltime + (out.time - lastRealtime); |
| 7917 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 7918 | return true; |
| 7919 | } |
| 7920 | |
| 7921 | @Override |
| 7922 | public void finishIteratingHistoryLocked() { |
| 7923 | mIteratingHistory = false; |
| 7924 | mHistoryBuffer.setDataPosition(mHistoryBuffer.dataSize()); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 7925 | mReadHistoryStrings = null; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 7926 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7927 | |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 7928 | @Override |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 7929 | public long getHistoryBaseTime() { |
| 7930 | return mHistoryBaseTime; |
| 7931 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7932 | |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 7933 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7934 | public int getStartCount() { |
| 7935 | return mStartCount; |
| 7936 | } |
| 7937 | |
| 7938 | public boolean isOnBattery() { |
| 7939 | return mOnBattery; |
| 7940 | } |
| 7941 | |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 7942 | public boolean isCharging() { |
| 7943 | return mCharging; |
| 7944 | } |
| 7945 | |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 7946 | public boolean isScreenOn() { |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 7947 | return mScreenState == Display.STATE_ON; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 7948 | } |
| 7949 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7950 | void initTimes(long uptime, long realtime) { |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 7951 | mStartClockTime = System.currentTimeMillis(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7952 | mOnBatteryTimeBase.init(uptime, realtime); |
| 7953 | mOnBatteryScreenOffTimeBase.init(uptime, realtime); |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 7954 | mRealtime = 0; |
| 7955 | mUptime = 0; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7956 | mRealtimeStart = realtime; |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 7957 | mUptimeStart = uptime; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7958 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7959 | |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 7960 | void initDischarge() { |
| 7961 | mLowDischargeAmountSinceCharge = 0; |
| 7962 | mHighDischargeAmountSinceCharge = 0; |
| 7963 | mDischargeAmountScreenOn = 0; |
| 7964 | mDischargeAmountScreenOnSinceCharge = 0; |
| 7965 | mDischargeAmountScreenOff = 0; |
| 7966 | mDischargeAmountScreenOffSinceCharge = 0; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 7967 | mDischargeStepTracker.init(); |
| 7968 | mChargeStepTracker.init(); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 7969 | } |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 7970 | |
| 7971 | public void resetAllStatsCmdLocked() { |
| 7972 | resetAllStatsLocked(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7973 | final long mSecUptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 7974 | long uptime = mSecUptime * 1000; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7975 | long mSecRealtime = mClocks.elapsedRealtime(); |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 7976 | long realtime = mSecRealtime * 1000; |
| 7977 | mDischargeStartLevel = mHistoryCur.batteryLevel; |
| 7978 | pullPendingStateUpdatesLocked(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 7979 | addHistoryRecordLocked(mSecRealtime, mSecUptime); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 7980 | mDischargeCurrentLevel = mDischargeUnplugLevel = mDischargePlugLevel |
| 7981 | = mCurrentBatteryLevel = mHistoryCur.batteryLevel; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7982 | mOnBatteryTimeBase.reset(uptime, realtime); |
| 7983 | mOnBatteryScreenOffTimeBase.reset(uptime, realtime); |
| 7984 | if ((mHistoryCur.states&HistoryItem.STATE_BATTERY_PLUGGED_FLAG) == 0) { |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 7985 | if (mScreenState == Display.STATE_ON) { |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 7986 | mDischargeScreenOnUnplugLevel = mHistoryCur.batteryLevel; |
| 7987 | mDischargeScreenOffUnplugLevel = 0; |
| 7988 | } else { |
| 7989 | mDischargeScreenOnUnplugLevel = 0; |
| 7990 | mDischargeScreenOffUnplugLevel = mHistoryCur.batteryLevel; |
| 7991 | } |
| 7992 | mDischargeAmountScreenOn = 0; |
| 7993 | mDischargeAmountScreenOff = 0; |
| 7994 | } |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 7995 | initActiveHistoryEventsLocked(mSecRealtime, mSecUptime); |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 7996 | } |
| 7997 | |
| 7998 | private void resetAllStatsLocked() { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7999 | mStartCount = 0; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8000 | initTimes(mClocks.uptimeMillis() * 1000, mClocks.elapsedRealtime() * 1000); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8001 | mScreenOnTimer.reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8002 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8003 | mScreenBrightnessTimer[i].reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8004 | } |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 8005 | mInteractiveTimer.reset(false); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 8006 | mPowerSaveModeEnabledTimer.reset(false); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 8007 | mLongestLightIdleTime = 0; |
| 8008 | mLongestFullIdleTime = 0; |
| 8009 | mDeviceIdleModeLightTimer.reset(false); |
| 8010 | mDeviceIdleModeFullTimer.reset(false); |
| 8011 | mDeviceLightIdlingTimer.reset(false); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 8012 | mDeviceIdlingTimer.reset(false); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8013 | mPhoneOnTimer.reset(false); |
| 8014 | mAudioOnTimer.reset(false); |
| 8015 | mVideoOnTimer.reset(false); |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 8016 | mFlashlightOnTimer.reset(false); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 8017 | mCameraOnTimer.reset(false); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 8018 | mBluetoothScanTimer.reset(false); |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 8019 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8020 | mPhoneSignalStrengthsTimer[i].reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8021 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8022 | mPhoneSignalScanningTimer.reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8023 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8024 | mPhoneDataConnectionsTimer[i].reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8025 | } |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 8026 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 8027 | mNetworkByteActivityCounters[i].reset(false); |
| 8028 | mNetworkPacketActivityCounters[i].reset(false); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 8029 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8030 | mMobileRadioActiveTimer.reset(false); |
| 8031 | mMobileRadioActivePerAppTimer.reset(false); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 8032 | mMobileRadioActiveAdjustedTime.reset(false); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 8033 | mMobileRadioActiveUnknownTime.reset(false); |
| 8034 | mMobileRadioActiveUnknownCount.reset(false); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8035 | mWifiOnTimer.reset(false); |
| 8036 | mGlobalWifiRunningTimer.reset(false); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 8037 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8038 | mWifiStateTimer[i].reset(false); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 8039 | } |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 8040 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
| 8041 | mWifiSupplStateTimer[i].reset(false); |
| 8042 | } |
| 8043 | for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 8044 | mWifiSignalStrengthsTimer[i].reset(false); |
| 8045 | } |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 8046 | mWifiActivity.reset(false); |
| 8047 | mBluetoothActivity.reset(false); |
| 8048 | mModemActivity.reset(false); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 8049 | mNumConnectivityChange = mLoadedNumConnectivityChange = mUnpluggedNumConnectivityChange = 0; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 8050 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8051 | for (int i=0; i<mUidStats.size(); i++) { |
| 8052 | if (mUidStats.valueAt(i).reset()) { |
| 8053 | mUidStats.remove(mUidStats.keyAt(i)); |
| 8054 | i--; |
| 8055 | } |
| 8056 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 8057 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8058 | if (mKernelWakelockStats.size() > 0) { |
| 8059 | for (SamplingTimer timer : mKernelWakelockStats.values()) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8060 | mOnBatteryScreenOffTimeBase.remove(timer); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8061 | } |
| 8062 | mKernelWakelockStats.clear(); |
| 8063 | } |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 8064 | |
| 8065 | if (mWakeupReasonStats.size() > 0) { |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 8066 | for (SamplingTimer timer : mWakeupReasonStats.values()) { |
| 8067 | mOnBatteryTimeBase.remove(timer); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 8068 | } |
| 8069 | mWakeupReasonStats.clear(); |
| 8070 | } |
| 8071 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 8072 | mLastHistoryStepDetails = null; |
| 8073 | mLastStepCpuUserTime = mLastStepCpuSystemTime = 0; |
| 8074 | mCurStepCpuUserTime = mCurStepCpuSystemTime = 0; |
| 8075 | mLastStepCpuUserTime = mCurStepCpuUserTime = 0; |
| 8076 | mLastStepCpuSystemTime = mCurStepCpuSystemTime = 0; |
| 8077 | mLastStepStatUserTime = mCurStepStatUserTime = 0; |
| 8078 | mLastStepStatSystemTime = mCurStepStatSystemTime = 0; |
| 8079 | mLastStepStatIOWaitTime = mCurStepStatIOWaitTime = 0; |
| 8080 | mLastStepStatIrqTime = mCurStepStatIrqTime = 0; |
| 8081 | mLastStepStatSoftIrqTime = mCurStepStatSoftIrqTime = 0; |
| 8082 | mLastStepStatIdleTime = mCurStepStatIdleTime = 0; |
| 8083 | |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 8084 | initDischarge(); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 8085 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8086 | clearHistoryLocked(); |
| 8087 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 8088 | |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 8089 | private void initActiveHistoryEventsLocked(long elapsedRealtimeMs, long uptimeMs) { |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 8090 | for (int i=0; i<HistoryItem.EVENT_COUNT; i++) { |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 8091 | if (!mRecordAllHistory && i == HistoryItem.EVENT_PROC) { |
| 8092 | // Not recording process starts/stops. |
| 8093 | continue; |
| 8094 | } |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 8095 | HashMap<String, SparseIntArray> active = mActiveEvents.getStateForEvent(i); |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 8096 | if (active == null) { |
| 8097 | continue; |
| 8098 | } |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 8099 | for (HashMap.Entry<String, SparseIntArray> ent : active.entrySet()) { |
| 8100 | SparseIntArray uids = ent.getValue(); |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 8101 | for (int j=0; j<uids.size(); j++) { |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 8102 | addHistoryEventLocked(elapsedRealtimeMs, uptimeMs, i, ent.getKey(), |
| 8103 | uids.keyAt(j)); |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 8104 | } |
| 8105 | } |
| 8106 | } |
| 8107 | } |
| 8108 | |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 8109 | void updateDischargeScreenLevelsLocked(boolean oldScreenOn, boolean newScreenOn) { |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 8110 | if (oldScreenOn) { |
| 8111 | int diff = mDischargeScreenOnUnplugLevel - mDischargeCurrentLevel; |
| 8112 | if (diff > 0) { |
| 8113 | mDischargeAmountScreenOn += diff; |
| 8114 | mDischargeAmountScreenOnSinceCharge += diff; |
| 8115 | } |
| 8116 | } else { |
| 8117 | int diff = mDischargeScreenOffUnplugLevel - mDischargeCurrentLevel; |
| 8118 | if (diff > 0) { |
| 8119 | mDischargeAmountScreenOff += diff; |
| 8120 | mDischargeAmountScreenOffSinceCharge += diff; |
| 8121 | } |
| 8122 | } |
| 8123 | if (newScreenOn) { |
| 8124 | mDischargeScreenOnUnplugLevel = mDischargeCurrentLevel; |
| 8125 | mDischargeScreenOffUnplugLevel = 0; |
| 8126 | } else { |
| 8127 | mDischargeScreenOnUnplugLevel = 0; |
| 8128 | mDischargeScreenOffUnplugLevel = mDischargeCurrentLevel; |
| 8129 | } |
| 8130 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8131 | |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 8132 | public void pullPendingStateUpdatesLocked() { |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 8133 | if (mOnBatteryInternal) { |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 8134 | final boolean screenOn = mScreenState == Display.STATE_ON; |
| 8135 | updateDischargeScreenLevelsLocked(screenOn, screenOn); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 8136 | } |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 8137 | } |
| 8138 | |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8139 | private String[] mMobileIfaces = EmptyArray.STRING; |
| 8140 | private String[] mWifiIfaces = EmptyArray.STRING; |
| 8141 | |
| 8142 | private final NetworkStatsFactory mNetworkStatsFactory = new NetworkStatsFactory(); |
| 8143 | |
| 8144 | private static final int NETWORK_STATS_LAST = 0; |
| 8145 | private static final int NETWORK_STATS_NEXT = 1; |
| 8146 | private static final int NETWORK_STATS_DELTA = 2; |
| 8147 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8148 | private NetworkStats[] mMobileNetworkStats; |
| 8149 | private NetworkStats[] mWifiNetworkStats; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8150 | |
| 8151 | /** |
| 8152 | * Retrieves the delta of network stats for the given network ifaces. Uses networkStatsBuffer |
| 8153 | * as a buffer of NetworkStats objects to cycle through when computing deltas. |
| 8154 | */ |
| 8155 | private NetworkStats getNetworkStatsDeltaLocked(String[] ifaces, |
| 8156 | NetworkStats[] networkStatsBuffer) |
| 8157 | throws IOException { |
| 8158 | if (!SystemProperties.getBoolean(NetworkManagementSocketTagger.PROP_QTAGUID_ENABLED, |
| 8159 | false)) { |
| 8160 | return null; |
| 8161 | } |
| 8162 | |
| 8163 | final NetworkStats stats = mNetworkStatsFactory.readNetworkStatsDetail(NetworkStats.UID_ALL, |
| 8164 | ifaces, NetworkStats.TAG_NONE, networkStatsBuffer[NETWORK_STATS_NEXT]); |
| 8165 | networkStatsBuffer[NETWORK_STATS_DELTA] = NetworkStats.subtract(stats, |
| 8166 | networkStatsBuffer[NETWORK_STATS_LAST], null, null, |
| 8167 | networkStatsBuffer[NETWORK_STATS_DELTA]); |
| 8168 | networkStatsBuffer[NETWORK_STATS_NEXT] = networkStatsBuffer[NETWORK_STATS_LAST]; |
| 8169 | networkStatsBuffer[NETWORK_STATS_LAST] = stats; |
| 8170 | return networkStatsBuffer[NETWORK_STATS_DELTA]; |
| 8171 | } |
| 8172 | |
| 8173 | /** |
| 8174 | * Distribute WiFi energy info and network traffic to apps. |
| 8175 | * @param info The energy information from the WiFi controller. |
| 8176 | */ |
| 8177 | public void updateWifiStateLocked(@Nullable final WifiActivityEnergyInfo info) { |
Adam Lesinski | a7c90c8 | 2015-06-18 14:52:24 -0700 | [diff] [blame] | 8178 | if (DEBUG_ENERGY) { |
| 8179 | Slog.d(TAG, "Updating wifi stats"); |
| 8180 | } |
| 8181 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8182 | final long elapsedRealtimeMs = mClocks.elapsedRealtime(); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 8183 | NetworkStats delta = null; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8184 | try { |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 8185 | if (!ArrayUtils.isEmpty(mWifiIfaces)) { |
| 8186 | delta = getNetworkStatsDeltaLocked(mWifiIfaces, mWifiNetworkStats); |
| 8187 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8188 | } catch (IOException e) { |
| 8189 | Slog.wtf(TAG, "Failed to get wifi network stats", e); |
| 8190 | return; |
| 8191 | } |
| 8192 | |
| 8193 | if (!mOnBatteryInternal) { |
| 8194 | return; |
| 8195 | } |
| 8196 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 8197 | SparseLongArray rxPackets = new SparseLongArray(); |
| 8198 | SparseLongArray txPackets = new SparseLongArray(); |
| 8199 | long totalTxPackets = 0; |
| 8200 | long totalRxPackets = 0; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8201 | if (delta != null) { |
| 8202 | final int size = delta.size(); |
| 8203 | for (int i = 0; i < size; i++) { |
| 8204 | final NetworkStats.Entry entry = delta.getValues(i, mTmpNetworkStatsEntry); |
| 8205 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 8206 | if (DEBUG_ENERGY) { |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8207 | Slog.d(TAG, "Wifi uid " + entry.uid + ": delta rx=" + entry.rxBytes |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 8208 | + " tx=" + entry.txBytes + " rxPackets=" + entry.rxPackets |
| 8209 | + " txPackets=" + entry.txPackets); |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8210 | } |
| 8211 | |
Adam Lesinski | 6cca414 | 2016-02-25 18:23:02 -0800 | [diff] [blame] | 8212 | if (entry.rxBytes == 0 && entry.txBytes == 0) { |
| 8213 | // Skip the lookup below since there is no work to do. |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8214 | continue; |
| 8215 | } |
| 8216 | |
| 8217 | final Uid u = getUidStatsLocked(mapUid(entry.uid)); |
Adam Lesinski | ba88e68 | 2015-12-08 12:06:55 -0800 | [diff] [blame] | 8218 | if (entry.rxBytes != 0) { |
| 8219 | u.noteNetworkActivityLocked(NETWORK_WIFI_RX_DATA, entry.rxBytes, |
| 8220 | entry.rxPackets); |
| 8221 | mNetworkByteActivityCounters[NETWORK_WIFI_RX_DATA].addCountLocked( |
| 8222 | entry.rxBytes); |
| 8223 | mNetworkPacketActivityCounters[NETWORK_WIFI_RX_DATA].addCountLocked( |
| 8224 | entry.rxPackets); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 8225 | |
Adam Lesinski | ba88e68 | 2015-12-08 12:06:55 -0800 | [diff] [blame] | 8226 | rxPackets.put(u.getUid(), entry.rxPackets); |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8227 | |
Adam Lesinski | ba88e68 | 2015-12-08 12:06:55 -0800 | [diff] [blame] | 8228 | // Sum the total number of packets so that the Rx Power can |
| 8229 | // be evenly distributed amongst the apps. |
| 8230 | totalRxPackets += entry.rxPackets; |
| 8231 | } |
| 8232 | |
| 8233 | if (entry.txBytes != 0) { |
| 8234 | u.noteNetworkActivityLocked(NETWORK_WIFI_TX_DATA, entry.txBytes, |
| 8235 | entry.txPackets); |
| 8236 | mNetworkByteActivityCounters[NETWORK_WIFI_TX_DATA].addCountLocked( |
| 8237 | entry.txBytes); |
| 8238 | mNetworkPacketActivityCounters[NETWORK_WIFI_TX_DATA].addCountLocked( |
| 8239 | entry.txPackets); |
| 8240 | |
| 8241 | txPackets.put(u.getUid(), entry.txPackets); |
| 8242 | |
| 8243 | // Sum the total number of packets so that the Tx Power can |
| 8244 | // be evenly distributed amongst the apps. |
| 8245 | totalTxPackets += entry.txPackets; |
| 8246 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8247 | } |
| 8248 | } |
| 8249 | |
| 8250 | if (info != null) { |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 8251 | mHasWifiReporting = true; |
Adam Lesinski | 1739076 | 2015-04-10 13:17:47 -0700 | [diff] [blame] | 8252 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 8253 | // Measured in mAms |
| 8254 | final long txTimeMs = info.getControllerTxTimeMillis(); |
| 8255 | final long rxTimeMs = info.getControllerRxTimeMillis(); |
| 8256 | final long idleTimeMs = info.getControllerIdleTimeMillis(); |
| 8257 | final long totalTimeMs = txTimeMs + rxTimeMs + idleTimeMs; |
| 8258 | |
| 8259 | long leftOverRxTimeMs = rxTimeMs; |
Mitchell Wills | f901649 | 2015-07-29 17:47:44 -0700 | [diff] [blame] | 8260 | long leftOverTxTimeMs = txTimeMs; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 8261 | |
| 8262 | if (DEBUG_ENERGY) { |
| 8263 | Slog.d(TAG, "------ BEGIN WiFi power blaming ------"); |
| 8264 | Slog.d(TAG, " Tx Time: " + txTimeMs + " ms"); |
| 8265 | Slog.d(TAG, " Rx Time: " + rxTimeMs + " ms"); |
| 8266 | Slog.d(TAG, " Idle Time: " + idleTimeMs + " ms"); |
| 8267 | Slog.d(TAG, " Total Time: " + totalTimeMs + " ms"); |
| 8268 | } |
| 8269 | |
| 8270 | long totalWifiLockTimeMs = 0; |
| 8271 | long totalScanTimeMs = 0; |
| 8272 | |
| 8273 | // On the first pass, collect some totals so that we can normalize power |
| 8274 | // calculations if we need to. |
| 8275 | final int uidStatsSize = mUidStats.size(); |
| 8276 | for (int i = 0; i < uidStatsSize; i++) { |
| 8277 | final Uid uid = mUidStats.valueAt(i); |
| 8278 | |
| 8279 | // Sum the total scan power for all apps. |
| 8280 | totalScanTimeMs += uid.mWifiScanTimer.getTimeSinceMarkLocked( |
| 8281 | elapsedRealtimeMs * 1000) / 1000; |
| 8282 | |
| 8283 | // Sum the total time holding wifi lock for all apps. |
| 8284 | totalWifiLockTimeMs += uid.mFullWifiLockTimer.getTimeSinceMarkLocked( |
| 8285 | elapsedRealtimeMs * 1000) / 1000; |
| 8286 | } |
| 8287 | |
| 8288 | if (DEBUG_ENERGY && totalScanTimeMs > rxTimeMs) { |
| 8289 | Slog.d(TAG, " !Estimated scan time > Actual rx time (" + totalScanTimeMs + " ms > " |
| 8290 | + rxTimeMs + " ms). Normalizing scan time."); |
| 8291 | } |
Mitchell Wills | f901649 | 2015-07-29 17:47:44 -0700 | [diff] [blame] | 8292 | if (DEBUG_ENERGY && totalScanTimeMs > txTimeMs) { |
| 8293 | Slog.d(TAG, " !Estimated scan time > Actual tx time (" + totalScanTimeMs + " ms > " |
| 8294 | + txTimeMs + " ms). Normalizing scan time."); |
| 8295 | } |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 8296 | |
| 8297 | // Actually assign and distribute power usage to apps. |
| 8298 | for (int i = 0; i < uidStatsSize; i++) { |
| 8299 | final Uid uid = mUidStats.valueAt(i); |
| 8300 | |
| 8301 | long scanTimeSinceMarkMs = uid.mWifiScanTimer.getTimeSinceMarkLocked( |
| 8302 | elapsedRealtimeMs * 1000) / 1000; |
| 8303 | if (scanTimeSinceMarkMs > 0) { |
| 8304 | // Set the new mark so that next time we get new data since this point. |
| 8305 | uid.mWifiScanTimer.setMark(elapsedRealtimeMs); |
| 8306 | |
Mitchell Wills | f901649 | 2015-07-29 17:47:44 -0700 | [diff] [blame] | 8307 | long scanRxTimeSinceMarkMs = scanTimeSinceMarkMs; |
| 8308 | long scanTxTimeSinceMarkMs = scanTimeSinceMarkMs; |
| 8309 | |
| 8310 | // Our total scan time is more than the reported Tx/Rx time. |
| 8311 | // This is possible because the cost of a scan is approximate. |
| 8312 | // Let's normalize the result so that we evenly blame each app |
| 8313 | // scanning. |
| 8314 | // |
| 8315 | // This means that we may have apps that transmitted/received packets not be |
| 8316 | // blamed for this, but this is fine as scans are relatively more expensive. |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 8317 | if (totalScanTimeMs > rxTimeMs) { |
Mitchell Wills | f901649 | 2015-07-29 17:47:44 -0700 | [diff] [blame] | 8318 | scanRxTimeSinceMarkMs = (rxTimeMs * scanRxTimeSinceMarkMs) / |
| 8319 | totalScanTimeMs; |
| 8320 | } |
| 8321 | if (totalScanTimeMs > txTimeMs) { |
| 8322 | scanTxTimeSinceMarkMs = (txTimeMs * scanTxTimeSinceMarkMs) / |
| 8323 | totalScanTimeMs; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 8324 | } |
| 8325 | |
| 8326 | if (DEBUG_ENERGY) { |
Mitchell Wills | f901649 | 2015-07-29 17:47:44 -0700 | [diff] [blame] | 8327 | Slog.d(TAG, " ScanTime for UID " + uid.getUid() + ": Rx:" |
| 8328 | + scanRxTimeSinceMarkMs + " ms Tx:" |
| 8329 | + scanTxTimeSinceMarkMs + " ms)"); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 8330 | } |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 8331 | |
| 8332 | ControllerActivityCounterImpl activityCounter = |
| 8333 | uid.getOrCreateWifiControllerActivityLocked(); |
| 8334 | activityCounter.getRxTimeCounter().addCountLocked(scanRxTimeSinceMarkMs); |
| 8335 | activityCounter.getTxTimeCounters()[0].addCountLocked(scanTxTimeSinceMarkMs); |
Mitchell Wills | f901649 | 2015-07-29 17:47:44 -0700 | [diff] [blame] | 8336 | leftOverRxTimeMs -= scanRxTimeSinceMarkMs; |
| 8337 | leftOverTxTimeMs -= scanTxTimeSinceMarkMs; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 8338 | } |
| 8339 | |
| 8340 | // Distribute evenly the power consumed while Idle to each app holding a WiFi |
| 8341 | // lock. |
| 8342 | final long wifiLockTimeSinceMarkMs = uid.mFullWifiLockTimer.getTimeSinceMarkLocked( |
| 8343 | elapsedRealtimeMs * 1000) / 1000; |
| 8344 | if (wifiLockTimeSinceMarkMs > 0) { |
| 8345 | // Set the new mark so that next time we get new data since this point. |
| 8346 | uid.mFullWifiLockTimer.setMark(elapsedRealtimeMs); |
| 8347 | |
| 8348 | final long myIdleTimeMs = (wifiLockTimeSinceMarkMs * idleTimeMs) |
| 8349 | / totalWifiLockTimeMs; |
| 8350 | if (DEBUG_ENERGY) { |
| 8351 | Slog.d(TAG, " IdleTime for UID " + uid.getUid() + ": " |
| 8352 | + myIdleTimeMs + " ms"); |
| 8353 | } |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 8354 | uid.getOrCreateWifiControllerActivityLocked().getIdleTimeCounter() |
| 8355 | .addCountLocked(myIdleTimeMs); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 8356 | } |
| 8357 | } |
| 8358 | |
| 8359 | if (DEBUG_ENERGY) { |
| 8360 | Slog.d(TAG, " New RxPower: " + leftOverRxTimeMs + " ms"); |
Mitchell Wills | f901649 | 2015-07-29 17:47:44 -0700 | [diff] [blame] | 8361 | Slog.d(TAG, " New TxPower: " + leftOverTxTimeMs + " ms"); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 8362 | } |
| 8363 | |
Mitchell Wills | f901649 | 2015-07-29 17:47:44 -0700 | [diff] [blame] | 8364 | // Distribute the remaining Tx power appropriately between all apps that transmitted |
| 8365 | // packets. |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 8366 | for (int i = 0; i < txPackets.size(); i++) { |
| 8367 | final Uid uid = getUidStatsLocked(txPackets.keyAt(i)); |
Mitchell Wills | f901649 | 2015-07-29 17:47:44 -0700 | [diff] [blame] | 8368 | final long myTxTimeMs = (txPackets.valueAt(i) * leftOverTxTimeMs) / totalTxPackets; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 8369 | if (DEBUG_ENERGY) { |
| 8370 | Slog.d(TAG, " TxTime for UID " + uid.getUid() + ": " + myTxTimeMs + " ms"); |
| 8371 | } |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 8372 | uid.getOrCreateWifiControllerActivityLocked().getTxTimeCounters()[0] |
| 8373 | .addCountLocked(myTxTimeMs); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 8374 | } |
| 8375 | |
| 8376 | // Distribute the remaining Rx power appropriately between all apps that received |
| 8377 | // packets. |
| 8378 | for (int i = 0; i < rxPackets.size(); i++) { |
| 8379 | final Uid uid = getUidStatsLocked(rxPackets.keyAt(i)); |
| 8380 | final long myRxTimeMs = (rxPackets.valueAt(i) * leftOverRxTimeMs) / totalRxPackets; |
| 8381 | if (DEBUG_ENERGY) { |
| 8382 | Slog.d(TAG, " RxTime for UID " + uid.getUid() + ": " + myRxTimeMs + " ms"); |
| 8383 | } |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 8384 | uid.getOrCreateWifiControllerActivityLocked().getRxTimeCounter() |
| 8385 | .addCountLocked(myRxTimeMs); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 8386 | } |
| 8387 | |
| 8388 | // Any left over power use will be picked up by the WiFi category in BatteryStatsHelper. |
| 8389 | |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8390 | // Update WiFi controller stats. |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 8391 | mWifiActivity.getRxTimeCounter().addCountLocked(info.getControllerRxTimeMillis()); |
| 8392 | mWifiActivity.getTxTimeCounters()[0].addCountLocked(info.getControllerTxTimeMillis()); |
| 8393 | mWifiActivity.getIdleTimeCounter().addCountLocked(info.getControllerIdleTimeMillis()); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 8394 | |
Adam Lesinski | 8576cf9 | 2015-06-09 12:48:25 -0700 | [diff] [blame] | 8395 | // POWER_WIFI_CONTROLLER_OPERATING_VOLTAGE is measured in mV, so convert to V. |
| 8396 | final double opVolt = mPowerProfile.getAveragePower( |
| 8397 | PowerProfile.POWER_WIFI_CONTROLLER_OPERATING_VOLTAGE) / 1000.0; |
| 8398 | if (opVolt != 0) { |
| 8399 | // We store the power drain as mAms. |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 8400 | mWifiActivity.getPowerCounter().addCountLocked( |
Adam Lesinski | 8576cf9 | 2015-06-09 12:48:25 -0700 | [diff] [blame] | 8401 | (long)(info.getControllerEnergyUsed() / opVolt)); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 8402 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8403 | } |
| 8404 | } |
| 8405 | |
| 8406 | /** |
| 8407 | * Distribute Cell radio energy info and network traffic to apps. |
| 8408 | */ |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 8409 | public void updateMobileRadioStateLocked(final long elapsedRealtimeMs, |
| 8410 | final ModemActivityInfo activityInfo) { |
Adam Lesinski | a7c90c8 | 2015-06-18 14:52:24 -0700 | [diff] [blame] | 8411 | if (DEBUG_ENERGY) { |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 8412 | Slog.d(TAG, "Updating mobile radio stats with " + activityInfo); |
Adam Lesinski | a7c90c8 | 2015-06-18 14:52:24 -0700 | [diff] [blame] | 8413 | } |
| 8414 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 8415 | NetworkStats delta = null; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8416 | try { |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 8417 | if (!ArrayUtils.isEmpty(mMobileIfaces)) { |
| 8418 | delta = getNetworkStatsDeltaLocked(mMobileIfaces, mMobileNetworkStats); |
| 8419 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8420 | } catch (IOException e) { |
| 8421 | Slog.wtf(TAG, "Failed to get mobile network stats", e); |
| 8422 | return; |
| 8423 | } |
| 8424 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 8425 | if (!mOnBatteryInternal) { |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8426 | return; |
| 8427 | } |
| 8428 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 8429 | long radioTime = mMobileRadioActivePerAppTimer.getTimeSinceMarkLocked( |
| 8430 | elapsedRealtimeMs * 1000); |
| 8431 | mMobileRadioActivePerAppTimer.setMark(elapsedRealtimeMs); |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8432 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 8433 | long totalRxPackets = 0; |
| 8434 | long totalTxPackets = 0; |
| 8435 | if (delta != null) { |
| 8436 | final int size = delta.size(); |
| 8437 | for (int i = 0; i < size; i++) { |
| 8438 | final NetworkStats.Entry entry = delta.getValues(i, mTmpNetworkStatsEntry); |
Adam Lesinski | a426817 | 2016-01-29 12:13:54 -0800 | [diff] [blame] | 8439 | if (entry.rxPackets == 0 && entry.txPackets == 0) { |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 8440 | continue; |
| 8441 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8442 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 8443 | if (DEBUG_ENERGY) { |
| 8444 | Slog.d(TAG, "Mobile uid " + entry.uid + ": delta rx=" + entry.rxBytes |
| 8445 | + " tx=" + entry.txBytes + " rxPackets=" + entry.rxPackets |
| 8446 | + " txPackets=" + entry.txPackets); |
| 8447 | } |
| 8448 | |
| 8449 | totalRxPackets += entry.rxPackets; |
| 8450 | totalTxPackets += entry.txPackets; |
| 8451 | |
| 8452 | final Uid u = getUidStatsLocked(mapUid(entry.uid)); |
| 8453 | u.noteNetworkActivityLocked(NETWORK_MOBILE_RX_DATA, entry.rxBytes, entry.rxPackets); |
| 8454 | u.noteNetworkActivityLocked(NETWORK_MOBILE_TX_DATA, entry.txBytes, entry.txPackets); |
| 8455 | |
| 8456 | mNetworkByteActivityCounters[NETWORK_MOBILE_RX_DATA].addCountLocked( |
| 8457 | entry.rxBytes); |
| 8458 | mNetworkByteActivityCounters[NETWORK_MOBILE_TX_DATA].addCountLocked( |
| 8459 | entry.txBytes); |
| 8460 | mNetworkPacketActivityCounters[NETWORK_MOBILE_RX_DATA].addCountLocked( |
| 8461 | entry.rxPackets); |
| 8462 | mNetworkPacketActivityCounters[NETWORK_MOBILE_TX_DATA].addCountLocked( |
| 8463 | entry.txPackets); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 8464 | } |
| 8465 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 8466 | // Now distribute proportional blame to the apps that did networking. |
| 8467 | long totalPackets = totalRxPackets + totalTxPackets; |
| 8468 | if (totalPackets > 0) { |
| 8469 | for (int i = 0; i < size; i++) { |
| 8470 | final NetworkStats.Entry entry = delta.getValues(i, mTmpNetworkStatsEntry); |
| 8471 | if (entry.rxPackets == 0 && entry.txPackets == 0) { |
| 8472 | continue; |
| 8473 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8474 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 8475 | final Uid u = getUidStatsLocked(mapUid(entry.uid)); |
| 8476 | |
| 8477 | // Distribute total radio active time in to this app. |
| 8478 | final long appPackets = entry.rxPackets + entry.txPackets; |
| 8479 | final long appRadioTime = (radioTime * appPackets) / totalPackets; |
| 8480 | u.noteMobileRadioActiveTimeLocked(appRadioTime); |
| 8481 | |
| 8482 | // Remove this app from the totals, so that we don't lose any time |
| 8483 | // due to rounding. |
| 8484 | radioTime -= appRadioTime; |
| 8485 | totalPackets -= appPackets; |
| 8486 | |
| 8487 | if (activityInfo != null) { |
| 8488 | ControllerActivityCounterImpl activityCounter = |
| 8489 | u.getOrCreateModemControllerActivityLocked(); |
Adam Lesinski | a426817 | 2016-01-29 12:13:54 -0800 | [diff] [blame] | 8490 | if (totalRxPackets > 0 && entry.rxPackets > 0) { |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 8491 | final long rxMs = (entry.rxPackets * activityInfo.getRxTimeMillis()) |
| 8492 | / totalRxPackets; |
| 8493 | activityCounter.getRxTimeCounter().addCountLocked(rxMs); |
| 8494 | } |
| 8495 | |
Adam Lesinski | a426817 | 2016-01-29 12:13:54 -0800 | [diff] [blame] | 8496 | if (totalTxPackets > 0 && entry.txPackets > 0) { |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 8497 | for (int lvl = 0; lvl < ModemActivityInfo.TX_POWER_LEVELS; lvl++) { |
| 8498 | long txMs = entry.txPackets * activityInfo.getTxTimeMillis()[lvl]; |
| 8499 | txMs /= totalTxPackets; |
| 8500 | activityCounter.getTxTimeCounters()[lvl].addCountLocked(txMs); |
| 8501 | } |
| 8502 | } |
| 8503 | } |
| 8504 | } |
| 8505 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8506 | |
| 8507 | if (radioTime > 0) { |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 8508 | // Whoops, there is some radio time we can't blame on an app! |
| 8509 | mMobileRadioActiveUnknownTime.addCountLocked(radioTime); |
| 8510 | mMobileRadioActiveUnknownCount.addCountLocked(1); |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8511 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8512 | } |
| 8513 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 8514 | if (activityInfo != null) { |
| 8515 | mHasModemReporting = true; |
| 8516 | mModemActivity.getIdleTimeCounter().addCountLocked(activityInfo.getIdleTimeMillis()); |
| 8517 | mModemActivity.getRxTimeCounter().addCountLocked(activityInfo.getRxTimeMillis()); |
| 8518 | for (int lvl = 0; lvl < ModemActivityInfo.TX_POWER_LEVELS; lvl++) { |
| 8519 | mModemActivity.getTxTimeCounters()[lvl] |
| 8520 | .addCountLocked(activityInfo.getTxTimeMillis()[lvl]); |
| 8521 | } |
| 8522 | |
| 8523 | // POWER_MODEM_CONTROLLER_OPERATING_VOLTAGE is measured in mV, so convert to V. |
| 8524 | final double opVolt = mPowerProfile.getAveragePower( |
| 8525 | PowerProfile.POWER_MODEM_CONTROLLER_OPERATING_VOLTAGE) / 1000.0; |
| 8526 | if (opVolt != 0) { |
| 8527 | // We store the power drain as mAms. |
| 8528 | mModemActivity.getPowerCounter().addCountLocked( |
| 8529 | (long) (activityInfo.getEnergyUsed() / opVolt)); |
| 8530 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8531 | } |
| 8532 | } |
| 8533 | |
| 8534 | /** |
| 8535 | * Distribute Bluetooth energy info and network traffic to apps. |
| 8536 | * @param info The energy information from the bluetooth controller. |
| 8537 | */ |
| 8538 | public void updateBluetoothStateLocked(@Nullable final BluetoothActivityEnergyInfo info) { |
Adam Lesinski | a7c90c8 | 2015-06-18 14:52:24 -0700 | [diff] [blame] | 8539 | if (DEBUG_ENERGY) { |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 8540 | Slog.d(TAG, "Updating bluetooth stats: " + info); |
Adam Lesinski | a7c90c8 | 2015-06-18 14:52:24 -0700 | [diff] [blame] | 8541 | } |
| 8542 | |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 8543 | if (info == null || !mOnBatteryInternal) { |
| 8544 | return; |
| 8545 | } |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 8546 | |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 8547 | mHasBluetoothReporting = true; |
| 8548 | |
| 8549 | final long elapsedRealtimeMs = SystemClock.elapsedRealtime(); |
| 8550 | final long rxTimeMs = info.getControllerRxTimeMillis(); |
| 8551 | final long txTimeMs = info.getControllerTxTimeMillis(); |
| 8552 | |
| 8553 | if (DEBUG_ENERGY) { |
| 8554 | Slog.d(TAG, "------ BEGIN BLE power blaming ------"); |
| 8555 | Slog.d(TAG, " Tx Time: " + txTimeMs + " ms"); |
| 8556 | Slog.d(TAG, " Rx Time: " + rxTimeMs + " ms"); |
| 8557 | Slog.d(TAG, " Idle Time: " + info.getControllerIdleTimeMillis() + " ms"); |
| 8558 | } |
| 8559 | |
| 8560 | long totalScanTimeMs = 0; |
| 8561 | |
| 8562 | final int uidCount = mUidStats.size(); |
| 8563 | for (int i = 0; i < uidCount; i++) { |
| 8564 | final Uid u = mUidStats.valueAt(i); |
| 8565 | if (u.mBluetoothScanTimer == null) { |
| 8566 | continue; |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 8567 | } |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 8568 | |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 8569 | totalScanTimeMs += u.mBluetoothScanTimer.getTimeSinceMarkLocked( |
| 8570 | elapsedRealtimeMs * 1000) / 1000; |
| 8571 | } |
| 8572 | |
| 8573 | final boolean normalizeScanRxTime = (totalScanTimeMs > rxTimeMs); |
| 8574 | final boolean normalizeScanTxTime = (totalScanTimeMs > txTimeMs); |
| 8575 | |
| 8576 | if (DEBUG_ENERGY) { |
| 8577 | Slog.d(TAG, "Normalizing scan power for RX=" + normalizeScanRxTime |
| 8578 | + " TX=" + normalizeScanTxTime); |
| 8579 | } |
| 8580 | |
| 8581 | long leftOverRxTimeMs = rxTimeMs; |
| 8582 | long leftOverTxTimeMs = txTimeMs; |
| 8583 | |
| 8584 | for (int i = 0; i < uidCount; i++) { |
| 8585 | final Uid u = mUidStats.valueAt(i); |
| 8586 | if (u.mBluetoothScanTimer == null) { |
| 8587 | continue; |
| 8588 | } |
| 8589 | |
| 8590 | long scanTimeSinceMarkMs = u.mBluetoothScanTimer.getTimeSinceMarkLocked( |
| 8591 | elapsedRealtimeMs * 1000) / 1000; |
| 8592 | if (scanTimeSinceMarkMs > 0) { |
| 8593 | // Set the new mark so that next time we get new data since this point. |
| 8594 | u.mBluetoothScanTimer.setMark(elapsedRealtimeMs); |
| 8595 | |
| 8596 | long scanTimeRxSinceMarkMs = scanTimeSinceMarkMs; |
| 8597 | long scanTimeTxSinceMarkMs = scanTimeSinceMarkMs; |
| 8598 | |
| 8599 | if (normalizeScanRxTime) { |
| 8600 | // Scan time is longer than the total rx time in the controller, |
| 8601 | // so distribute the scan time proportionately. This means regular traffic |
| 8602 | // will not blamed, but scans are more expensive anyways. |
| 8603 | scanTimeRxSinceMarkMs = (rxTimeMs * scanTimeRxSinceMarkMs) / totalScanTimeMs; |
| 8604 | } |
| 8605 | |
| 8606 | if (normalizeScanTxTime) { |
| 8607 | // Scan time is longer than the total tx time in the controller, |
| 8608 | // so distribute the scan time proportionately. This means regular traffic |
| 8609 | // will not blamed, but scans are more expensive anyways. |
| 8610 | scanTimeTxSinceMarkMs = (txTimeMs * scanTimeTxSinceMarkMs) / totalScanTimeMs; |
| 8611 | } |
| 8612 | |
| 8613 | final ControllerActivityCounterImpl counter = |
| 8614 | u.getOrCreateBluetoothControllerActivityLocked(); |
| 8615 | counter.getRxTimeCounter().addCountLocked(scanTimeRxSinceMarkMs); |
| 8616 | counter.getTxTimeCounters()[0].addCountLocked(scanTimeTxSinceMarkMs); |
| 8617 | |
| 8618 | leftOverRxTimeMs -= scanTimeRxSinceMarkMs; |
| 8619 | leftOverTxTimeMs -= scanTimeTxSinceMarkMs; |
| 8620 | } |
| 8621 | } |
| 8622 | |
| 8623 | if (DEBUG_ENERGY) { |
| 8624 | Slog.d(TAG, "Left over time for traffic RX=" + leftOverRxTimeMs |
| 8625 | + " TX=" + leftOverTxTimeMs); |
| 8626 | } |
| 8627 | |
| 8628 | // |
| 8629 | // Now distribute blame to apps that did bluetooth traffic. |
| 8630 | // |
| 8631 | |
| 8632 | long totalTxBytes = 0; |
| 8633 | long totalRxBytes = 0; |
| 8634 | |
| 8635 | final UidTraffic[] uidTraffic = info.getUidTraffic(); |
| 8636 | final int numUids = uidTraffic != null ? uidTraffic.length : 0; |
| 8637 | for (int i = 0; i < numUids; i++) { |
| 8638 | final UidTraffic traffic = uidTraffic[i]; |
| 8639 | |
| 8640 | // Add to the global counters. |
| 8641 | mNetworkByteActivityCounters[NETWORK_BT_RX_DATA].addCountLocked( |
| 8642 | traffic.getRxBytes()); |
| 8643 | mNetworkByteActivityCounters[NETWORK_BT_TX_DATA].addCountLocked( |
| 8644 | traffic.getTxBytes()); |
| 8645 | |
| 8646 | // Add to the UID counters. |
| 8647 | final Uid u = getUidStatsLocked(mapUid(traffic.getUid())); |
| 8648 | u.noteNetworkActivityLocked(NETWORK_BT_RX_DATA, traffic.getRxBytes(), 0); |
| 8649 | u.noteNetworkActivityLocked(NETWORK_BT_TX_DATA, traffic.getTxBytes(), 0); |
| 8650 | |
| 8651 | // Calculate the total traffic. |
| 8652 | totalTxBytes += traffic.getTxBytes(); |
| 8653 | totalRxBytes += traffic.getRxBytes(); |
| 8654 | } |
| 8655 | |
| 8656 | if ((totalTxBytes != 0 || totalRxBytes != 0) && |
| 8657 | (leftOverRxTimeMs != 0 || leftOverTxTimeMs != 0)) { |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 8658 | for (int i = 0; i < numUids; i++) { |
| 8659 | final UidTraffic traffic = uidTraffic[i]; |
| 8660 | |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 8661 | final Uid u = getUidStatsLocked(mapUid(traffic.getUid())); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 8662 | final ControllerActivityCounterImpl counter = |
| 8663 | u.getOrCreateBluetoothControllerActivityLocked(); |
| 8664 | |
| 8665 | if (totalRxBytes > 0 && traffic.getRxBytes() > 0) { |
| 8666 | final long timeRxMs = (leftOverRxTimeMs * traffic.getRxBytes()) / totalRxBytes; |
| 8667 | |
| 8668 | if (DEBUG_ENERGY) { |
| 8669 | Slog.d(TAG, "UID=" + traffic.getUid() + " rx_bytes=" + traffic.getRxBytes() |
| 8670 | + " rx_time=" + timeRxMs); |
| 8671 | } |
| 8672 | counter.getRxTimeCounter().addCountLocked(timeRxMs); |
| 8673 | leftOverRxTimeMs -= timeRxMs; |
| 8674 | } |
| 8675 | |
| 8676 | if (totalTxBytes > 0 && traffic.getTxBytes() > 0) { |
| 8677 | final long timeTxMs = (leftOverTxTimeMs * traffic.getTxBytes()) / totalTxBytes; |
| 8678 | |
| 8679 | if (DEBUG_ENERGY) { |
| 8680 | Slog.d(TAG, "UID=" + traffic.getUid() + " tx_bytes=" + traffic.getTxBytes() |
| 8681 | + " tx_time=" + timeTxMs); |
| 8682 | } |
| 8683 | |
| 8684 | counter.getTxTimeCounters()[0].addCountLocked(timeTxMs); |
| 8685 | leftOverTxTimeMs -= timeTxMs; |
| 8686 | } |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 8687 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8688 | } |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 8689 | |
| 8690 | mBluetoothActivity.getRxTimeCounter().addCountLocked( |
| 8691 | info.getControllerRxTimeMillis()); |
| 8692 | mBluetoothActivity.getTxTimeCounters()[0].addCountLocked( |
| 8693 | info.getControllerTxTimeMillis()); |
| 8694 | mBluetoothActivity.getIdleTimeCounter().addCountLocked( |
| 8695 | info.getControllerIdleTimeMillis()); |
| 8696 | |
| 8697 | // POWER_BLUETOOTH_CONTROLLER_OPERATING_VOLTAGE is measured in mV, so convert to V. |
| 8698 | final double opVolt = mPowerProfile.getAveragePower( |
| 8699 | PowerProfile.POWER_BLUETOOTH_CONTROLLER_OPERATING_VOLTAGE) / 1000.0; |
| 8700 | if (opVolt != 0) { |
| 8701 | // We store the power drain as mAms. |
| 8702 | mBluetoothActivity.getPowerCounter().addCountLocked( |
| 8703 | (long) (info.getControllerEnergyUsed() / opVolt)); |
| 8704 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8705 | } |
| 8706 | |
| 8707 | /** |
| 8708 | * Read and distribute kernel wake lock use across apps. |
| 8709 | */ |
| 8710 | public void updateKernelWakelocksLocked() { |
| 8711 | final KernelWakelockStats wakelockStats = mKernelWakelockReader.readKernelWakelockStats( |
| 8712 | mTmpWakelockStats); |
| 8713 | if (wakelockStats == null) { |
| 8714 | // Not crashing might make board bringup easier. |
| 8715 | Slog.w(TAG, "Couldn't get kernel wake lock stats"); |
| 8716 | return; |
| 8717 | } |
| 8718 | |
Adam Lesinski | fbabe7d | 2015-08-03 14:37:38 -0700 | [diff] [blame] | 8719 | // Record whether we've seen a non-zero time (for debugging b/22716723). |
| 8720 | boolean seenNonZeroTime = false; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8721 | for (Map.Entry<String, KernelWakelockStats.Entry> ent : wakelockStats.entrySet()) { |
| 8722 | String name = ent.getKey(); |
| 8723 | KernelWakelockStats.Entry kws = ent.getValue(); |
| 8724 | |
| 8725 | SamplingTimer kwlt = mKernelWakelockStats.get(name); |
| 8726 | if (kwlt == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8727 | kwlt = new SamplingTimer(mClocks, mOnBatteryScreenOffTimeBase, |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8728 | true /* track reported val */); |
| 8729 | mKernelWakelockStats.put(name, kwlt); |
| 8730 | } |
| 8731 | kwlt.updateCurrentReportedCount(kws.mCount); |
| 8732 | kwlt.updateCurrentReportedTotalTime(kws.mTotalTime); |
| 8733 | kwlt.setUpdateVersion(kws.mVersion); |
Adam Lesinski | fbabe7d | 2015-08-03 14:37:38 -0700 | [diff] [blame] | 8734 | |
| 8735 | if (kws.mVersion != wakelockStats.kernelWakelockVersion) |
| 8736 | seenNonZeroTime |= kws.mTotalTime > 0; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8737 | } |
| 8738 | |
Adam Lesinski | fbabe7d | 2015-08-03 14:37:38 -0700 | [diff] [blame] | 8739 | int numWakelocksSetStale = 0; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8740 | if (wakelockStats.size() != mKernelWakelockStats.size()) { |
| 8741 | // Set timers to stale if they didn't appear in /proc/wakelocks this time. |
| 8742 | for (Map.Entry<String, SamplingTimer> ent : mKernelWakelockStats.entrySet()) { |
| 8743 | SamplingTimer st = ent.getValue(); |
| 8744 | if (st.getUpdateVersion() != wakelockStats.kernelWakelockVersion) { |
| 8745 | st.setStale(); |
Adam Lesinski | fbabe7d | 2015-08-03 14:37:38 -0700 | [diff] [blame] | 8746 | numWakelocksSetStale++; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8747 | } |
| 8748 | } |
| 8749 | } |
Adam Lesinski | fbabe7d | 2015-08-03 14:37:38 -0700 | [diff] [blame] | 8750 | |
| 8751 | if (!seenNonZeroTime) { |
| 8752 | Slog.wtf(TAG, "All kernel wakelocks had time of zero"); |
| 8753 | } |
| 8754 | |
| 8755 | if (numWakelocksSetStale == mKernelWakelockStats.size()) { |
| 8756 | Slog.wtf(TAG, "All kernel wakelocks were set stale. new version=" + |
| 8757 | wakelockStats.kernelWakelockVersion); |
| 8758 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8759 | } |
| 8760 | |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 8761 | // We use an anonymous class to access these variables, |
| 8762 | // so they can't live on the stack or they'd have to be |
| 8763 | // final MutableLong objects (more allocations). |
| 8764 | // Used in updateCpuTimeLocked(). |
| 8765 | long mTempTotalCpuUserTimeUs; |
| 8766 | long mTempTotalCpuSystemTimeUs; |
| 8767 | |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 8768 | /** |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 8769 | * Read and distribute CPU usage across apps. If their are partial wakelocks being held |
| 8770 | * and we are on battery with screen off, we give more of the cpu time to those apps holding |
| 8771 | * wakelocks. If the screen is on, we just assign the actual cpu time an app used. |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 8772 | */ |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 8773 | public void updateCpuTimeLocked() { |
Adam Lesinski | 52290c9c | 2015-09-21 16:54:52 -0700 | [diff] [blame] | 8774 | if (mPowerProfile == null) { |
| 8775 | return; |
| 8776 | } |
| 8777 | |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 8778 | if (DEBUG_ENERGY_CPU) { |
| 8779 | Slog.d(TAG, "!Cpu updating!"); |
| 8780 | } |
| 8781 | |
| 8782 | // Holding a wakelock costs more than just using the cpu. |
| 8783 | // Currently, we assign only half the cpu time to an app that is running but |
| 8784 | // not holding a wakelock. The apps holding wakelocks get the rest of the blame. |
| 8785 | // If no app is holding a wakelock, then the distribution is normal. |
| 8786 | final int wakelockWeight = 50; |
| 8787 | |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 8788 | // Read the time spent for each cluster at various cpu frequencies. |
| 8789 | final long[][] clusterSpeeds = new long[mKernelCpuSpeedReaders.length][]; |
| 8790 | for (int cluster = 0; cluster < mKernelCpuSpeedReaders.length; cluster++) { |
| 8791 | clusterSpeeds[cluster] = mKernelCpuSpeedReaders[cluster].readDelta(); |
| 8792 | } |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 8793 | |
| 8794 | int numWakelocks = 0; |
| 8795 | |
| 8796 | // Calculate how many wakelocks we have to distribute amongst. The system is excluded. |
| 8797 | // Only distribute cpu power to wakelocks if the screen is off and we're on battery. |
| 8798 | final int numPartialTimers = mPartialTimers.size(); |
| 8799 | if (mOnBatteryScreenOffTimeBase.isRunning()) { |
| 8800 | for (int i = 0; i < numPartialTimers; i++) { |
| 8801 | final StopwatchTimer timer = mPartialTimers.get(i); |
| 8802 | if (timer.mInList && timer.mUid != null && timer.mUid.mUid != Process.SYSTEM_UID) { |
| 8803 | // Since the collection and blaming of wakelocks can be scheduled to run after |
| 8804 | // some delay, the mPartialTimers list may have new entries. We can't blame |
| 8805 | // the newly added timer for past cpu time, so we only consider timers that |
| 8806 | // were present for one round of collection. Once a timer has gone through |
| 8807 | // a round of collection, its mInList field is set to true. |
| 8808 | numWakelocks++; |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 8809 | } |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 8810 | } |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 8811 | } |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 8812 | |
| 8813 | final int numWakelocksF = numWakelocks; |
| 8814 | mTempTotalCpuUserTimeUs = 0; |
| 8815 | mTempTotalCpuSystemTimeUs = 0; |
| 8816 | |
| 8817 | // Read the CPU data for each UID. This will internally generate a snapshot so next time |
| 8818 | // we read, we get a delta. If we are to distribute the cpu time, then do so. Otherwise |
| 8819 | // we just ignore the data. |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8820 | final long startTimeMs = mClocks.elapsedRealtime(); |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 8821 | mKernelUidCpuTimeReader.readDelta(!mOnBatteryInternal ? null : |
| 8822 | new KernelUidCpuTimeReader.Callback() { |
| 8823 | @Override |
Adam Lesinski | a7a4ccc | 2015-06-26 17:43:04 -0700 | [diff] [blame] | 8824 | public void onUidCpuTime(int uid, long userTimeUs, long systemTimeUs, |
| 8825 | long powerMaUs) { |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 8826 | final Uid u = getUidStatsLocked(mapUid(uid)); |
| 8827 | |
| 8828 | // Accumulate the total system and user time. |
| 8829 | mTempTotalCpuUserTimeUs += userTimeUs; |
| 8830 | mTempTotalCpuSystemTimeUs += systemTimeUs; |
| 8831 | |
| 8832 | StringBuilder sb = null; |
| 8833 | if (DEBUG_ENERGY_CPU) { |
| 8834 | sb = new StringBuilder(); |
| 8835 | sb.append(" got time for uid=").append(u.mUid).append(": u="); |
| 8836 | TimeUtils.formatDuration(userTimeUs / 1000, sb); |
| 8837 | sb.append(" s="); |
| 8838 | TimeUtils.formatDuration(systemTimeUs / 1000, sb); |
Adam Lesinski | a7a4ccc | 2015-06-26 17:43:04 -0700 | [diff] [blame] | 8839 | sb.append(" p=").append(powerMaUs / 1000).append("mAms\n"); |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 8840 | } |
| 8841 | |
| 8842 | if (numWakelocksF > 0) { |
| 8843 | // We have wakelocks being held, so only give a portion of the |
| 8844 | // time to the process. The rest will be distributed among wakelock |
| 8845 | // holders. |
| 8846 | userTimeUs = (userTimeUs * wakelockWeight) / 100; |
| 8847 | systemTimeUs = (systemTimeUs * wakelockWeight) / 100; |
| 8848 | } |
| 8849 | |
| 8850 | if (sb != null) { |
| 8851 | sb.append(" adding to uid=").append(u.mUid).append(": u="); |
| 8852 | TimeUtils.formatDuration(userTimeUs / 1000, sb); |
| 8853 | sb.append(" s="); |
| 8854 | TimeUtils.formatDuration(systemTimeUs / 1000, sb); |
Adam Lesinski | a7a4ccc | 2015-06-26 17:43:04 -0700 | [diff] [blame] | 8855 | sb.append(" p=").append(powerMaUs / 1000).append("mAms"); |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 8856 | Slog.d(TAG, sb.toString()); |
| 8857 | } |
| 8858 | |
| 8859 | u.mUserCpuTime.addCountLocked(userTimeUs); |
| 8860 | u.mSystemCpuTime.addCountLocked(systemTimeUs); |
Adam Lesinski | a7a4ccc | 2015-06-26 17:43:04 -0700 | [diff] [blame] | 8861 | u.mCpuPower.addCountLocked(powerMaUs); |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 8862 | |
| 8863 | // Add the cpu speeds to this UID. These are used as a ratio |
| 8864 | // for computing the power this UID used. |
Adam Lesinski | 52290c9c | 2015-09-21 16:54:52 -0700 | [diff] [blame] | 8865 | final int numClusters = mPowerProfile.getNumCpuClusters(); |
| 8866 | if (u.mCpuClusterSpeed == null || u.mCpuClusterSpeed.length != |
| 8867 | numClusters) { |
| 8868 | u.mCpuClusterSpeed = new LongSamplingCounter[numClusters][]; |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 8869 | } |
| 8870 | |
| 8871 | for (int cluster = 0; cluster < clusterSpeeds.length; cluster++) { |
Adam Lesinski | 52290c9c | 2015-09-21 16:54:52 -0700 | [diff] [blame] | 8872 | final int speedsInCluster = mPowerProfile.getNumSpeedStepsInCpuCluster( |
| 8873 | cluster); |
| 8874 | if (u.mCpuClusterSpeed[cluster] == null || speedsInCluster != |
| 8875 | u.mCpuClusterSpeed[cluster].length) { |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 8876 | u.mCpuClusterSpeed[cluster] = |
Adam Lesinski | 52290c9c | 2015-09-21 16:54:52 -0700 | [diff] [blame] | 8877 | new LongSamplingCounter[speedsInCluster]; |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 8878 | } |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 8879 | |
| 8880 | final LongSamplingCounter[] cpuSpeeds = u.mCpuClusterSpeed[cluster]; |
| 8881 | for (int speed = 0; speed < clusterSpeeds[cluster].length; speed++) { |
| 8882 | if (cpuSpeeds[speed] == null) { |
| 8883 | cpuSpeeds[speed] = new LongSamplingCounter(mOnBatteryTimeBase); |
| 8884 | } |
| 8885 | cpuSpeeds[speed].addCountLocked(clusterSpeeds[cluster][speed]); |
| 8886 | } |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 8887 | } |
| 8888 | } |
| 8889 | }); |
| 8890 | |
| 8891 | if (DEBUG_ENERGY_CPU) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8892 | Slog.d(TAG, "Reading cpu stats took " + (mClocks.elapsedRealtime() - startTimeMs) + |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 8893 | " ms"); |
| 8894 | } |
| 8895 | |
| 8896 | if (mOnBatteryInternal && numWakelocks > 0) { |
| 8897 | // Distribute a portion of the total cpu time to wakelock holders. |
| 8898 | mTempTotalCpuUserTimeUs = (mTempTotalCpuUserTimeUs * (100 - wakelockWeight)) / 100; |
| 8899 | mTempTotalCpuSystemTimeUs = |
| 8900 | (mTempTotalCpuSystemTimeUs * (100 - wakelockWeight)) / 100; |
| 8901 | |
| 8902 | for (int i = 0; i < numPartialTimers; i++) { |
| 8903 | final StopwatchTimer timer = mPartialTimers.get(i); |
| 8904 | |
| 8905 | // The system does not share any blame, as it is usually holding the wakelock |
| 8906 | // on behalf of an app. |
| 8907 | if (timer.mInList && timer.mUid != null && timer.mUid.mUid != Process.SYSTEM_UID) { |
| 8908 | int userTimeUs = (int) (mTempTotalCpuUserTimeUs / numWakelocks); |
| 8909 | int systemTimeUs = (int) (mTempTotalCpuSystemTimeUs / numWakelocks); |
| 8910 | |
| 8911 | if (DEBUG_ENERGY_CPU) { |
| 8912 | StringBuilder sb = new StringBuilder(); |
| 8913 | sb.append(" Distributing wakelock uid=").append(timer.mUid.mUid) |
| 8914 | .append(": u="); |
| 8915 | TimeUtils.formatDuration(userTimeUs / 1000, sb); |
| 8916 | sb.append(" s="); |
| 8917 | TimeUtils.formatDuration(systemTimeUs / 1000, sb); |
| 8918 | Slog.d(TAG, sb.toString()); |
| 8919 | } |
| 8920 | |
| 8921 | timer.mUid.mUserCpuTime.addCountLocked(userTimeUs); |
| 8922 | timer.mUid.mSystemCpuTime.addCountLocked(systemTimeUs); |
| 8923 | |
| 8924 | final Uid.Proc proc = timer.mUid.getProcessStatsLocked("*wakelock*"); |
Adam Lesinski | 062e66c | 2015-07-14 12:02:44 -0700 | [diff] [blame] | 8925 | proc.addCpuTimeLocked(userTimeUs / 1000, systemTimeUs / 1000); |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 8926 | |
| 8927 | mTempTotalCpuUserTimeUs -= userTimeUs; |
| 8928 | mTempTotalCpuSystemTimeUs -= systemTimeUs; |
| 8929 | numWakelocks--; |
| 8930 | } |
| 8931 | } |
| 8932 | |
| 8933 | if (mTempTotalCpuUserTimeUs > 0 || mTempTotalCpuSystemTimeUs > 0) { |
| 8934 | // Anything left over is given to the system. |
| 8935 | if (DEBUG_ENERGY_CPU) { |
| 8936 | StringBuilder sb = new StringBuilder(); |
| 8937 | sb.append(" Distributing lost time to system: u="); |
| 8938 | TimeUtils.formatDuration(mTempTotalCpuUserTimeUs / 1000, sb); |
| 8939 | sb.append(" s="); |
| 8940 | TimeUtils.formatDuration(mTempTotalCpuSystemTimeUs / 1000, sb); |
| 8941 | Slog.d(TAG, sb.toString()); |
| 8942 | } |
| 8943 | |
| 8944 | final Uid u = getUidStatsLocked(Process.SYSTEM_UID); |
| 8945 | u.mUserCpuTime.addCountLocked(mTempTotalCpuUserTimeUs); |
| 8946 | u.mSystemCpuTime.addCountLocked(mTempTotalCpuSystemTimeUs); |
| 8947 | |
| 8948 | final Uid.Proc proc = u.getProcessStatsLocked("*lost*"); |
Adam Lesinski | 062e66c | 2015-07-14 12:02:44 -0700 | [diff] [blame] | 8949 | proc.addCpuTimeLocked((int) mTempTotalCpuUserTimeUs / 1000, |
| 8950 | (int) mTempTotalCpuSystemTimeUs / 1000); |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 8951 | } |
| 8952 | } |
| 8953 | |
| 8954 | // See if there is a difference in wakelocks between this collection and the last |
| 8955 | // collection. |
| 8956 | if (ArrayUtils.referenceEquals(mPartialTimers, mLastPartialTimers)) { |
| 8957 | // No difference, so each timer is now considered for the next collection. |
| 8958 | for (int i = 0; i < numPartialTimers; i++) { |
| 8959 | mPartialTimers.get(i).mInList = true; |
| 8960 | } |
| 8961 | } else { |
| 8962 | // The lists are different, meaning we added (or removed a timer) since the last |
| 8963 | // collection. |
| 8964 | final int numLastPartialTimers = mLastPartialTimers.size(); |
| 8965 | for (int i = 0; i < numLastPartialTimers; i++) { |
| 8966 | mLastPartialTimers.get(i).mInList = false; |
| 8967 | } |
| 8968 | mLastPartialTimers.clear(); |
| 8969 | |
| 8970 | // Mark the current timers as gone through a collection. |
| 8971 | for (int i = 0; i < numPartialTimers; i++) { |
| 8972 | final StopwatchTimer timer = mPartialTimers.get(i); |
| 8973 | timer.mInList = true; |
| 8974 | mLastPartialTimers.add(timer); |
| 8975 | } |
| 8976 | } |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 8977 | } |
| 8978 | |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 8979 | boolean setChargingLocked(boolean charging) { |
| 8980 | if (mCharging != charging) { |
| 8981 | mCharging = charging; |
| 8982 | if (charging) { |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 8983 | mHistoryCur.states2 |= HistoryItem.STATE2_CHARGING_FLAG; |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 8984 | } else { |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 8985 | mHistoryCur.states2 &= ~HistoryItem.STATE2_CHARGING_FLAG; |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 8986 | } |
| 8987 | mHandler.sendEmptyMessage(MSG_REPORT_CHARGING); |
| 8988 | return true; |
| 8989 | } |
| 8990 | return false; |
| 8991 | } |
| 8992 | |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 8993 | void setOnBatteryLocked(final long mSecRealtime, final long mSecUptime, final boolean onBattery, |
| 8994 | final int oldStatus, final int level) { |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 8995 | boolean doWrite = false; |
| 8996 | Message m = mHandler.obtainMessage(MSG_REPORT_POWER_CHANGE); |
| 8997 | m.arg1 = onBattery ? 1 : 0; |
| 8998 | mHandler.sendMessage(m); |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 8999 | |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 9000 | final long uptime = mSecUptime * 1000; |
| 9001 | final long realtime = mSecRealtime * 1000; |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 9002 | final boolean screenOn = mScreenState == Display.STATE_ON; |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 9003 | if (onBattery) { |
| 9004 | // We will reset our status if we are unplugging after the |
| 9005 | // battery was last full, or the level is at 100, or |
| 9006 | // we have gone through a significant charge (from a very low |
| 9007 | // level to a now very high level). |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 9008 | boolean reset = false; |
Dianne Hackborn | 9a75543 | 2014-05-15 17:05:22 -0700 | [diff] [blame] | 9009 | if (!mNoAutoReset && (oldStatus == BatteryManager.BATTERY_STATUS_FULL |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 9010 | || level >= 90 |
Dianne Hackborn | fb3809c | 2014-09-29 18:31:22 -0700 | [diff] [blame] | 9011 | || (mDischargeCurrentLevel < 20 && level >= 80) |
| 9012 | || (getHighDischargeAmountSinceCharge() >= 200 |
| 9013 | && mHistoryBuffer.dataSize() >= MAX_HISTORY_BUFFER))) { |
Dianne Hackborn | 73d6a82 | 2014-09-29 10:52:47 -0700 | [diff] [blame] | 9014 | Slog.i(TAG, "Resetting battery stats: level=" + level + " status=" + oldStatus |
Dianne Hackborn | fb3809c | 2014-09-29 18:31:22 -0700 | [diff] [blame] | 9015 | + " dischargeLevel=" + mDischargeCurrentLevel |
Dianne Hackborn | 73d6a82 | 2014-09-29 10:52:47 -0700 | [diff] [blame] | 9016 | + " lowAmount=" + getLowDischargeAmountSinceCharge() |
| 9017 | + " highAmount=" + getHighDischargeAmountSinceCharge()); |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 9018 | // Before we write, collect a snapshot of the final aggregated |
| 9019 | // stats to be reported in the next checkin. Only do this if we have |
| 9020 | // a sufficient amount of data to make it interesting. |
| 9021 | if (getLowDischargeAmountSinceCharge() >= 20) { |
| 9022 | final Parcel parcel = Parcel.obtain(); |
| 9023 | writeSummaryToParcel(parcel, true); |
| 9024 | BackgroundThread.getHandler().post(new Runnable() { |
| 9025 | @Override public void run() { |
| 9026 | synchronized (mCheckinFile) { |
| 9027 | FileOutputStream stream = null; |
| 9028 | try { |
| 9029 | stream = mCheckinFile.startWrite(); |
| 9030 | stream.write(parcel.marshall()); |
| 9031 | stream.flush(); |
| 9032 | FileUtils.sync(stream); |
| 9033 | stream.close(); |
| 9034 | mCheckinFile.finishWrite(stream); |
| 9035 | } catch (IOException e) { |
| 9036 | Slog.w("BatteryStats", |
| 9037 | "Error writing checkin battery statistics", e); |
| 9038 | mCheckinFile.failWrite(stream); |
| 9039 | } finally { |
| 9040 | parcel.recycle(); |
| 9041 | } |
| 9042 | } |
| 9043 | } |
| 9044 | }); |
| 9045 | } |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 9046 | doWrite = true; |
| 9047 | resetAllStatsLocked(); |
| 9048 | mDischargeStartLevel = level; |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 9049 | reset = true; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 9050 | mDischargeStepTracker.init(); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9051 | } |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 9052 | if (mCharging) { |
| 9053 | setChargingLocked(false); |
| 9054 | } |
| 9055 | mLastChargingStateLevel = level; |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 9056 | mOnBattery = mOnBatteryInternal = true; |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 9057 | mLastDischargeStepLevel = level; |
Dianne Hackborn | 2932513 | 2014-05-21 15:01:03 -0700 | [diff] [blame] | 9058 | mMinDischargeStepLevel = level; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 9059 | mDischargeStepTracker.clearTime(); |
| 9060 | mDailyDischargeStepTracker.clearTime(); |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 9061 | mInitStepMode = mCurStepMode; |
| 9062 | mModStepMode = 0; |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 9063 | pullPendingStateUpdatesLocked(); |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 9064 | mHistoryCur.batteryLevel = (byte)level; |
| 9065 | mHistoryCur.states &= ~HistoryItem.STATE_BATTERY_PLUGGED_FLAG; |
| 9066 | if (DEBUG_HISTORY) Slog.v(TAG, "Battery unplugged to: " |
| 9067 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 9068 | if (reset) { |
| 9069 | mRecordingHistory = true; |
| 9070 | startRecordingHistory(mSecRealtime, mSecUptime, reset); |
| 9071 | } |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 9072 | addHistoryRecordLocked(mSecRealtime, mSecUptime); |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 9073 | mDischargeCurrentLevel = mDischargeUnplugLevel = level; |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 9074 | if (screenOn) { |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 9075 | mDischargeScreenOnUnplugLevel = level; |
| 9076 | mDischargeScreenOffUnplugLevel = 0; |
| 9077 | } else { |
| 9078 | mDischargeScreenOnUnplugLevel = 0; |
| 9079 | mDischargeScreenOffUnplugLevel = level; |
| 9080 | } |
| 9081 | mDischargeAmountScreenOn = 0; |
| 9082 | mDischargeAmountScreenOff = 0; |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 9083 | updateTimeBasesLocked(true, !screenOn, uptime, realtime); |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 9084 | } else { |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 9085 | mLastChargingStateLevel = level; |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 9086 | mOnBattery = mOnBatteryInternal = false; |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 9087 | pullPendingStateUpdatesLocked(); |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 9088 | mHistoryCur.batteryLevel = (byte)level; |
| 9089 | mHistoryCur.states |= HistoryItem.STATE_BATTERY_PLUGGED_FLAG; |
| 9090 | if (DEBUG_HISTORY) Slog.v(TAG, "Battery plugged to: " |
| 9091 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 9092 | addHistoryRecordLocked(mSecRealtime, mSecUptime); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 9093 | mDischargeCurrentLevel = mDischargePlugLevel = level; |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 9094 | if (level < mDischargeUnplugLevel) { |
| 9095 | mLowDischargeAmountSinceCharge += mDischargeUnplugLevel-level-1; |
| 9096 | mHighDischargeAmountSinceCharge += mDischargeUnplugLevel-level; |
| 9097 | } |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 9098 | updateDischargeScreenLevelsLocked(screenOn, screenOn); |
| 9099 | updateTimeBasesLocked(false, !screenOn, uptime, realtime); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 9100 | mChargeStepTracker.init(); |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 9101 | mLastChargeStepLevel = level; |
Dianne Hackborn | 2932513 | 2014-05-21 15:01:03 -0700 | [diff] [blame] | 9102 | mMaxChargeStepLevel = level; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 9103 | mInitStepMode = mCurStepMode; |
| 9104 | mModStepMode = 0; |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 9105 | } |
| 9106 | if (doWrite || (mLastWriteTime + (60 * 1000)) < mSecRealtime) { |
| 9107 | if (mFile != null) { |
| 9108 | writeAsyncLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9109 | } |
| 9110 | } |
| 9111 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 9112 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 9113 | private void startRecordingHistory(final long elapsedRealtimeMs, final long uptimeMs, |
| 9114 | boolean reset) { |
| 9115 | mRecordingHistory = true; |
| 9116 | mHistoryCur.currentTime = System.currentTimeMillis(); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 9117 | addHistoryBufferLocked(elapsedRealtimeMs, uptimeMs, |
| 9118 | reset ? HistoryItem.CMD_RESET : HistoryItem.CMD_CURRENT_TIME, |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 9119 | mHistoryCur); |
| 9120 | mHistoryCur.currentTime = 0; |
| 9121 | if (reset) { |
| 9122 | initActiveHistoryEventsLocked(elapsedRealtimeMs, uptimeMs); |
| 9123 | } |
| 9124 | } |
| 9125 | |
Dianne Hackborn | 7d9eefd | 2014-08-27 18:30:31 -0700 | [diff] [blame] | 9126 | private void recordCurrentTimeChangeLocked(final long currentTime, final long elapsedRealtimeMs, |
| 9127 | final long uptimeMs) { |
| 9128 | if (mRecordingHistory) { |
| 9129 | mHistoryCur.currentTime = currentTime; |
| 9130 | addHistoryBufferLocked(elapsedRealtimeMs, uptimeMs, HistoryItem.CMD_CURRENT_TIME, |
| 9131 | mHistoryCur); |
| 9132 | mHistoryCur.currentTime = 0; |
| 9133 | } |
| 9134 | } |
| 9135 | |
Dianne Hackborn | 29cd7f1 | 2015-01-08 10:37:05 -0800 | [diff] [blame] | 9136 | private void recordShutdownLocked(final long elapsedRealtimeMs, final long uptimeMs) { |
| 9137 | if (mRecordingHistory) { |
| 9138 | mHistoryCur.currentTime = System.currentTimeMillis(); |
Dianne Hackborn | 29cd7f1 | 2015-01-08 10:37:05 -0800 | [diff] [blame] | 9139 | addHistoryBufferLocked(elapsedRealtimeMs, uptimeMs, HistoryItem.CMD_SHUTDOWN, |
| 9140 | mHistoryCur); |
| 9141 | mHistoryCur.currentTime = 0; |
| 9142 | } |
| 9143 | } |
| 9144 | |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 9145 | private void scheduleSyncExternalStatsLocked(String reason, int updateFlags) { |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 9146 | if (mExternalSync != null) { |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 9147 | mExternalSync.scheduleSync(reason, updateFlags); |
Adam Lesinski | a7c90c8 | 2015-06-18 14:52:24 -0700 | [diff] [blame] | 9148 | } |
| 9149 | } |
| 9150 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9151 | // This should probably be exposed in the API, though it's not critical |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 9152 | public static final int BATTERY_PLUGGED_NONE = 0; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 9153 | |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 9154 | public void setBatteryStateLocked(int status, int health, int plugType, int level, |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9155 | int temp, int volt) { |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 9156 | final boolean onBattery = plugType == BATTERY_PLUGGED_NONE; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9157 | final long uptime = mClocks.uptimeMillis(); |
| 9158 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 9159 | if (!mHaveBatteryLevel) { |
| 9160 | mHaveBatteryLevel = true; |
| 9161 | // We start out assuming that the device is plugged in (not |
| 9162 | // on battery). If our first report is now that we are indeed |
| 9163 | // plugged in, then twiddle our state to correctly reflect that |
| 9164 | // since we won't be going through the full setOnBattery(). |
| 9165 | if (onBattery == mOnBattery) { |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 9166 | if (onBattery) { |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 9167 | mHistoryCur.states &= ~HistoryItem.STATE_BATTERY_PLUGGED_FLAG; |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 9168 | } else { |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 9169 | mHistoryCur.states |= HistoryItem.STATE_BATTERY_PLUGGED_FLAG; |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 9170 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9171 | } |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 9172 | // Always start out assuming charging, that will be updated later. |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 9173 | mHistoryCur.states2 |= HistoryItem.STATE2_CHARGING_FLAG; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 9174 | mHistoryCur.batteryStatus = (byte)status; |
| 9175 | mHistoryCur.batteryLevel = (byte)level; |
| 9176 | mMaxChargeStepLevel = mMinDischargeStepLevel = |
| 9177 | mLastChargeStepLevel = mLastDischargeStepLevel = level; |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 9178 | mLastChargingStateLevel = level; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 9179 | } else if (mCurrentBatteryLevel != level || mOnBattery != onBattery) { |
| 9180 | recordDailyStatsIfNeededLocked(level >= 100 && onBattery); |
| 9181 | } |
| 9182 | int oldStatus = mHistoryCur.batteryStatus; |
| 9183 | if (onBattery) { |
| 9184 | mDischargeCurrentLevel = level; |
| 9185 | if (!mRecordingHistory) { |
| 9186 | mRecordingHistory = true; |
| 9187 | startRecordingHistory(elapsedRealtime, uptime, true); |
| 9188 | } |
| 9189 | } else if (level < 96) { |
| 9190 | if (!mRecordingHistory) { |
| 9191 | mRecordingHistory = true; |
| 9192 | startRecordingHistory(elapsedRealtime, uptime, true); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9193 | } |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 9194 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 9195 | mCurrentBatteryLevel = level; |
| 9196 | if (mDischargePlugLevel < 0) { |
| 9197 | mDischargePlugLevel = level; |
Marco Nelissen | d859331 | 2009-04-30 14:45:06 -0700 | [diff] [blame] | 9198 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 9199 | if (onBattery != mOnBattery) { |
| 9200 | mHistoryCur.batteryLevel = (byte)level; |
| 9201 | mHistoryCur.batteryStatus = (byte)status; |
| 9202 | mHistoryCur.batteryHealth = (byte)health; |
| 9203 | mHistoryCur.batteryPlugType = (byte)plugType; |
| 9204 | mHistoryCur.batteryTemperature = (short)temp; |
| 9205 | mHistoryCur.batteryVoltage = (char)volt; |
| 9206 | setOnBatteryLocked(elapsedRealtime, uptime, onBattery, oldStatus, level); |
| 9207 | } else { |
| 9208 | boolean changed = false; |
| 9209 | if (mHistoryCur.batteryLevel != level) { |
| 9210 | mHistoryCur.batteryLevel = (byte)level; |
| 9211 | changed = true; |
Marco Nelissen | d859331 | 2009-04-30 14:45:06 -0700 | [diff] [blame] | 9212 | |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 9213 | // TODO(adamlesinski): Schedule the creation of a HistoryStepDetails record |
| 9214 | // which will pull external stats. |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 9215 | scheduleSyncExternalStatsLocked("battery-level", ExternalStatsSync.UPDATE_ALL); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 9216 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 9217 | if (mHistoryCur.batteryStatus != status) { |
| 9218 | mHistoryCur.batteryStatus = (byte)status; |
| 9219 | changed = true; |
| 9220 | } |
| 9221 | if (mHistoryCur.batteryHealth != health) { |
| 9222 | mHistoryCur.batteryHealth = (byte)health; |
| 9223 | changed = true; |
| 9224 | } |
| 9225 | if (mHistoryCur.batteryPlugType != plugType) { |
| 9226 | mHistoryCur.batteryPlugType = (byte)plugType; |
| 9227 | changed = true; |
| 9228 | } |
| 9229 | if (temp >= (mHistoryCur.batteryTemperature+10) |
| 9230 | || temp <= (mHistoryCur.batteryTemperature-10)) { |
| 9231 | mHistoryCur.batteryTemperature = (short)temp; |
| 9232 | changed = true; |
| 9233 | } |
| 9234 | if (volt > (mHistoryCur.batteryVoltage+20) |
| 9235 | || volt < (mHistoryCur.batteryVoltage-20)) { |
| 9236 | mHistoryCur.batteryVoltage = (char)volt; |
| 9237 | changed = true; |
| 9238 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 9239 | long modeBits = (((long)mInitStepMode) << STEP_LEVEL_INITIAL_MODE_SHIFT) |
| 9240 | | (((long)mModStepMode) << STEP_LEVEL_MODIFIED_MODE_SHIFT) |
| 9241 | | (((long)(level&0xff)) << STEP_LEVEL_LEVEL_SHIFT); |
| 9242 | if (onBattery) { |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 9243 | changed |= setChargingLocked(false); |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 9244 | if (mLastDischargeStepLevel != level && mMinDischargeStepLevel > level) { |
| 9245 | mDischargeStepTracker.addLevelSteps(mLastDischargeStepLevel - level, |
| 9246 | modeBits, elapsedRealtime); |
| 9247 | mDailyDischargeStepTracker.addLevelSteps(mLastDischargeStepLevel - level, |
| 9248 | modeBits, elapsedRealtime); |
| 9249 | mLastDischargeStepLevel = level; |
| 9250 | mMinDischargeStepLevel = level; |
| 9251 | mInitStepMode = mCurStepMode; |
| 9252 | mModStepMode = 0; |
| 9253 | } |
| 9254 | } else { |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 9255 | if (level >= 90) { |
| 9256 | // If the battery level is at least 90%, always consider the device to be |
| 9257 | // charging even if it happens to go down a level. |
| 9258 | changed |= setChargingLocked(true); |
| 9259 | mLastChargeStepLevel = level; |
| 9260 | } if (!mCharging) { |
| 9261 | if (mLastChargeStepLevel < level) { |
| 9262 | // We have not reporting that we are charging, but the level has now |
| 9263 | // gone up, so consider the state to be charging. |
| 9264 | changed |= setChargingLocked(true); |
| 9265 | mLastChargeStepLevel = level; |
| 9266 | } |
| 9267 | } else { |
| 9268 | if (mLastChargeStepLevel > level) { |
| 9269 | // We had reported that the device was charging, but here we are with |
| 9270 | // power connected and the level going down. Looks like the current |
| 9271 | // power supplied isn't enough, so consider the device to now be |
| 9272 | // discharging. |
| 9273 | changed |= setChargingLocked(false); |
| 9274 | mLastChargeStepLevel = level; |
| 9275 | } |
| 9276 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 9277 | if (mLastChargeStepLevel != level && mMaxChargeStepLevel < level) { |
| 9278 | mChargeStepTracker.addLevelSteps(level - mLastChargeStepLevel, |
| 9279 | modeBits, elapsedRealtime); |
| 9280 | mDailyChargeStepTracker.addLevelSteps(level - mLastChargeStepLevel, |
| 9281 | modeBits, elapsedRealtime); |
| 9282 | mLastChargeStepLevel = level; |
| 9283 | mMaxChargeStepLevel = level; |
| 9284 | mInitStepMode = mCurStepMode; |
| 9285 | mModStepMode = 0; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 9286 | } |
| 9287 | } |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 9288 | if (changed) { |
| 9289 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 9290 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 9291 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 9292 | if (!onBattery && status == BatteryManager.BATTERY_STATUS_FULL) { |
| 9293 | // We don't record history while we are plugged in and fully charged. |
| 9294 | // The next time we are unplugged, history will be cleared. |
| 9295 | mRecordingHistory = DEBUG; |
Dianne Hackborn | d0c5b9a | 2014-02-21 16:19:05 -0800 | [diff] [blame] | 9296 | } |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 9297 | } |
| 9298 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9299 | public long getAwakeTimeBattery() { |
| 9300 | return computeBatteryUptime(getBatteryUptimeLocked(), STATS_CURRENT); |
| 9301 | } |
| 9302 | |
| 9303 | public long getAwakeTimePlugged() { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9304 | return (mClocks.uptimeMillis() * 1000) - getAwakeTimeBattery(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9305 | } |
| 9306 | |
| 9307 | @Override |
| 9308 | public long computeUptime(long curTime, int which) { |
| 9309 | switch (which) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9310 | case STATS_SINCE_CHARGED: return mUptime + (curTime-mUptimeStart); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9311 | case STATS_CURRENT: return (curTime-mUptimeStart); |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 9312 | case STATS_SINCE_UNPLUGGED: return (curTime-mOnBatteryTimeBase.getUptimeStart()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9313 | } |
| 9314 | return 0; |
| 9315 | } |
| 9316 | |
| 9317 | @Override |
| 9318 | public long computeRealtime(long curTime, int which) { |
| 9319 | switch (which) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9320 | case STATS_SINCE_CHARGED: return mRealtime + (curTime-mRealtimeStart); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9321 | case STATS_CURRENT: return (curTime-mRealtimeStart); |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 9322 | case STATS_SINCE_UNPLUGGED: return (curTime-mOnBatteryTimeBase.getRealtimeStart()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9323 | } |
| 9324 | return 0; |
| 9325 | } |
| 9326 | |
| 9327 | @Override |
| 9328 | public long computeBatteryUptime(long curTime, int which) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9329 | return mOnBatteryTimeBase.computeUptime(curTime, which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9330 | } |
| 9331 | |
| 9332 | @Override |
| 9333 | public long computeBatteryRealtime(long curTime, int which) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9334 | return mOnBatteryTimeBase.computeRealtime(curTime, which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9335 | } |
| 9336 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9337 | @Override |
| 9338 | public long computeBatteryScreenOffUptime(long curTime, int which) { |
| 9339 | return mOnBatteryScreenOffTimeBase.computeUptime(curTime, which); |
| 9340 | } |
| 9341 | |
| 9342 | @Override |
| 9343 | public long computeBatteryScreenOffRealtime(long curTime, int which) { |
| 9344 | return mOnBatteryScreenOffTimeBase.computeRealtime(curTime, which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9345 | } |
| 9346 | |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 9347 | private long computeTimePerLevel(long[] steps, int numSteps) { |
| 9348 | // For now we'll do a simple average across all steps. |
| 9349 | if (numSteps <= 0) { |
| 9350 | return -1; |
| 9351 | } |
| 9352 | long total = 0; |
| 9353 | for (int i=0; i<numSteps; i++) { |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 9354 | total += steps[i] & STEP_LEVEL_TIME_MASK; |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 9355 | } |
| 9356 | return total / numSteps; |
| 9357 | /* |
| 9358 | long[] buckets = new long[numSteps]; |
| 9359 | int numBuckets = 0; |
| 9360 | int numToAverage = 4; |
| 9361 | int i = 0; |
| 9362 | while (i < numSteps) { |
| 9363 | long totalTime = 0; |
| 9364 | int num = 0; |
| 9365 | for (int j=0; j<numToAverage && (i+j)<numSteps; j++) { |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 9366 | totalTime += steps[i+j] & STEP_LEVEL_TIME_MASK; |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 9367 | num++; |
| 9368 | } |
| 9369 | buckets[numBuckets] = totalTime / num; |
| 9370 | numBuckets++; |
| 9371 | numToAverage *= 2; |
| 9372 | i += num; |
| 9373 | } |
| 9374 | if (numBuckets < 1) { |
| 9375 | return -1; |
| 9376 | } |
| 9377 | long averageTime = buckets[numBuckets-1]; |
| 9378 | for (i=numBuckets-2; i>=0; i--) { |
| 9379 | averageTime = (averageTime + buckets[i]) / 2; |
| 9380 | } |
| 9381 | return averageTime; |
| 9382 | */ |
| 9383 | } |
| 9384 | |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 9385 | @Override |
| 9386 | public long computeBatteryTimeRemaining(long curTime) { |
| 9387 | if (!mOnBattery) { |
| 9388 | return -1; |
| 9389 | } |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 9390 | /* Simple implementation just looks at the average discharge per level across the |
| 9391 | entire sample period. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 9392 | int discharge = (getLowDischargeAmountSinceCharge()+getHighDischargeAmountSinceCharge())/2; |
| 9393 | if (discharge < 2) { |
| 9394 | return -1; |
| 9395 | } |
| 9396 | long duration = computeBatteryRealtime(curTime, STATS_SINCE_CHARGED); |
| 9397 | if (duration < 1000*1000) { |
| 9398 | return -1; |
| 9399 | } |
| 9400 | long usPerLevel = duration/discharge; |
| 9401 | return usPerLevel * mCurrentBatteryLevel; |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 9402 | */ |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 9403 | if (mDischargeStepTracker.mNumStepDurations < 1) { |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 9404 | return -1; |
| 9405 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 9406 | long msPerLevel = mDischargeStepTracker.computeTimePerLevel(); |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 9407 | if (msPerLevel <= 0) { |
| 9408 | return -1; |
| 9409 | } |
| 9410 | return (msPerLevel * mCurrentBatteryLevel) * 1000; |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 9411 | } |
| 9412 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 9413 | @Override |
| 9414 | public LevelStepTracker getDischargeLevelStepTracker() { |
| 9415 | return mDischargeStepTracker; |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 9416 | } |
| 9417 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 9418 | @Override |
| 9419 | public LevelStepTracker getDailyDischargeLevelStepTracker() { |
| 9420 | return mDailyDischargeStepTracker; |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 9421 | } |
| 9422 | |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 9423 | @Override |
| 9424 | public long computeChargeTimeRemaining(long curTime) { |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 9425 | if (mOnBattery) { |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 9426 | // Not yet working. |
| 9427 | return -1; |
| 9428 | } |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 9429 | /* Broken |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 9430 | int curLevel = mCurrentBatteryLevel; |
| 9431 | int plugLevel = mDischargePlugLevel; |
| 9432 | if (plugLevel < 0 || curLevel < (plugLevel+1)) { |
| 9433 | return -1; |
| 9434 | } |
| 9435 | long duration = computeBatteryRealtime(curTime, STATS_SINCE_UNPLUGGED); |
| 9436 | if (duration < 1000*1000) { |
| 9437 | return -1; |
| 9438 | } |
| 9439 | long usPerLevel = duration/(curLevel-plugLevel); |
| 9440 | return usPerLevel * (100-curLevel); |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 9441 | */ |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 9442 | if (mChargeStepTracker.mNumStepDurations < 1) { |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 9443 | return -1; |
| 9444 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 9445 | long msPerLevel = mChargeStepTracker.computeTimePerLevel(); |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 9446 | if (msPerLevel <= 0) { |
| 9447 | return -1; |
| 9448 | } |
| 9449 | return (msPerLevel * (100-mCurrentBatteryLevel)) * 1000; |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 9450 | } |
| 9451 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 9452 | @Override |
| 9453 | public LevelStepTracker getChargeLevelStepTracker() { |
| 9454 | return mChargeStepTracker; |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 9455 | } |
| 9456 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 9457 | @Override |
| 9458 | public LevelStepTracker getDailyChargeLevelStepTracker() { |
| 9459 | return mDailyChargeStepTracker; |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 9460 | } |
| 9461 | |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 9462 | @Override |
| 9463 | public ArrayList<PackageChange> getDailyPackageChanges() { |
| 9464 | return mDailyPackageChanges; |
| 9465 | } |
| 9466 | |
Joe Onorato | e1acd63 | 2016-02-23 13:25:10 -0800 | [diff] [blame] | 9467 | protected long getBatteryUptimeLocked() { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9468 | return mOnBatteryTimeBase.getUptime(mClocks.uptimeMillis() * 1000); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9469 | } |
| 9470 | |
| 9471 | @Override |
| 9472 | public long getBatteryUptime(long curTime) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9473 | return mOnBatteryTimeBase.getUptime(curTime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9474 | } |
| 9475 | |
| 9476 | @Override |
| 9477 | public long getBatteryRealtime(long curTime) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9478 | return mOnBatteryTimeBase.getRealtime(curTime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9479 | } |
Amith Yamasani | 3718aaa | 2009-06-09 06:32:35 -0700 | [diff] [blame] | 9480 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 9481 | @Override |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 9482 | public int getDischargeStartLevel() { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 9483 | synchronized(this) { |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 9484 | return getDischargeStartLevelLocked(); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 9485 | } |
| 9486 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 9487 | |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 9488 | public int getDischargeStartLevelLocked() { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9489 | return mDischargeUnplugLevel; |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 9490 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 9491 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 9492 | @Override |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 9493 | public int getDischargeCurrentLevel() { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 9494 | synchronized(this) { |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 9495 | return getDischargeCurrentLevelLocked(); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 9496 | } |
| 9497 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 9498 | |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 9499 | public int getDischargeCurrentLevelLocked() { |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 9500 | return mDischargeCurrentLevel; |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 9501 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9502 | |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 9503 | @Override |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 9504 | public int getLowDischargeAmountSinceCharge() { |
| 9505 | synchronized(this) { |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 9506 | int val = mLowDischargeAmountSinceCharge; |
| 9507 | if (mOnBattery && mDischargeCurrentLevel < mDischargeUnplugLevel) { |
| 9508 | val += mDischargeUnplugLevel-mDischargeCurrentLevel-1; |
| 9509 | } |
| 9510 | return val; |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 9511 | } |
| 9512 | } |
| 9513 | |
| 9514 | @Override |
| 9515 | public int getHighDischargeAmountSinceCharge() { |
| 9516 | synchronized(this) { |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 9517 | int val = mHighDischargeAmountSinceCharge; |
| 9518 | if (mOnBattery && mDischargeCurrentLevel < mDischargeUnplugLevel) { |
| 9519 | val += mDischargeUnplugLevel-mDischargeCurrentLevel; |
| 9520 | } |
| 9521 | return val; |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 9522 | } |
| 9523 | } |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 9524 | |
| 9525 | @Override |
| 9526 | public int getDischargeAmount(int which) { |
| 9527 | int dischargeAmount = which == STATS_SINCE_CHARGED |
| 9528 | ? getHighDischargeAmountSinceCharge() |
| 9529 | : (getDischargeStartLevel() - getDischargeCurrentLevel()); |
| 9530 | if (dischargeAmount < 0) { |
| 9531 | dischargeAmount = 0; |
| 9532 | } |
| 9533 | return dischargeAmount; |
| 9534 | } |
| 9535 | |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 9536 | public int getDischargeAmountScreenOn() { |
| 9537 | synchronized(this) { |
| 9538 | int val = mDischargeAmountScreenOn; |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 9539 | if (mOnBattery && mScreenState == Display.STATE_ON |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 9540 | && mDischargeCurrentLevel < mDischargeScreenOnUnplugLevel) { |
| 9541 | val += mDischargeScreenOnUnplugLevel-mDischargeCurrentLevel; |
| 9542 | } |
| 9543 | return val; |
| 9544 | } |
| 9545 | } |
| 9546 | |
| 9547 | public int getDischargeAmountScreenOnSinceCharge() { |
| 9548 | synchronized(this) { |
| 9549 | int val = mDischargeAmountScreenOnSinceCharge; |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 9550 | if (mOnBattery && mScreenState == Display.STATE_ON |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 9551 | && mDischargeCurrentLevel < mDischargeScreenOnUnplugLevel) { |
| 9552 | val += mDischargeScreenOnUnplugLevel-mDischargeCurrentLevel; |
| 9553 | } |
| 9554 | return val; |
| 9555 | } |
| 9556 | } |
| 9557 | |
| 9558 | public int getDischargeAmountScreenOff() { |
| 9559 | synchronized(this) { |
| 9560 | int val = mDischargeAmountScreenOff; |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 9561 | if (mOnBattery && mScreenState != Display.STATE_ON |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 9562 | && mDischargeCurrentLevel < mDischargeScreenOffUnplugLevel) { |
| 9563 | val += mDischargeScreenOffUnplugLevel-mDischargeCurrentLevel; |
| 9564 | } |
| 9565 | return val; |
| 9566 | } |
| 9567 | } |
| 9568 | |
| 9569 | public int getDischargeAmountScreenOffSinceCharge() { |
| 9570 | synchronized(this) { |
| 9571 | int val = mDischargeAmountScreenOffSinceCharge; |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 9572 | if (mOnBattery && mScreenState != Display.STATE_ON |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 9573 | && mDischargeCurrentLevel < mDischargeScreenOffUnplugLevel) { |
| 9574 | val += mDischargeScreenOffUnplugLevel-mDischargeCurrentLevel; |
| 9575 | } |
| 9576 | return val; |
| 9577 | } |
| 9578 | } |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 9579 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9580 | /** |
| 9581 | * Retrieve the statistics object for a particular uid, creating if needed. |
| 9582 | */ |
| 9583 | public Uid getUidStatsLocked(int uid) { |
| 9584 | Uid u = mUidStats.get(uid); |
| 9585 | if (u == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9586 | u = new Uid(this, uid); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9587 | mUidStats.put(uid, u); |
| 9588 | } |
| 9589 | return u; |
| 9590 | } |
| 9591 | |
| 9592 | /** |
| 9593 | * Remove the statistics object for a particular uid. |
| 9594 | */ |
| 9595 | public void removeUidStatsLocked(int uid) { |
Adam Lesinski | b83ffee | 2015-05-12 14:43:47 -0700 | [diff] [blame] | 9596 | mKernelUidCpuTimeReader.removeUid(uid); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9597 | mUidStats.remove(uid); |
| 9598 | } |
Amith Yamasani | 32dbefd | 2009-06-19 09:21:17 -0700 | [diff] [blame] | 9599 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9600 | /** |
| 9601 | * Retrieve the statistics object for a particular process, creating |
| 9602 | * if needed. |
| 9603 | */ |
| 9604 | public Uid.Proc getProcessStatsLocked(int uid, String name) { |
Dianne Hackborn | bbb7472 | 2014-03-13 09:50:24 -0700 | [diff] [blame] | 9605 | uid = mapUid(uid); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9606 | Uid u = getUidStatsLocked(uid); |
| 9607 | return u.getProcessStatsLocked(name); |
| 9608 | } |
| 9609 | |
| 9610 | /** |
| 9611 | * Retrieve the statistics object for a particular process, creating |
| 9612 | * if needed. |
| 9613 | */ |
| 9614 | public Uid.Pkg getPackageStatsLocked(int uid, String pkg) { |
Dianne Hackborn | bbb7472 | 2014-03-13 09:50:24 -0700 | [diff] [blame] | 9615 | uid = mapUid(uid); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9616 | Uid u = getUidStatsLocked(uid); |
| 9617 | return u.getPackageStatsLocked(pkg); |
| 9618 | } |
| 9619 | |
| 9620 | /** |
| 9621 | * Retrieve the statistics object for a particular service, creating |
| 9622 | * if needed. |
| 9623 | */ |
| 9624 | public Uid.Pkg.Serv getServiceStatsLocked(int uid, String pkg, String name) { |
Dianne Hackborn | bbb7472 | 2014-03-13 09:50:24 -0700 | [diff] [blame] | 9625 | uid = mapUid(uid); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9626 | Uid u = getUidStatsLocked(uid); |
| 9627 | return u.getServiceStatsLocked(pkg, name); |
| 9628 | } |
| 9629 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9630 | public void shutdownLocked() { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9631 | recordShutdownLocked(mClocks.elapsedRealtime(), mClocks.uptimeMillis()); |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 9632 | writeSyncLocked(); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9633 | mShuttingDown = true; |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 9634 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 9635 | |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 9636 | Parcel mPendingWrite = null; |
| 9637 | final ReentrantLock mWriteLock = new ReentrantLock(); |
| 9638 | |
| 9639 | public void writeAsyncLocked() { |
| 9640 | writeLocked(false); |
| 9641 | } |
| 9642 | |
| 9643 | public void writeSyncLocked() { |
| 9644 | writeLocked(true); |
| 9645 | } |
| 9646 | |
| 9647 | void writeLocked(boolean sync) { |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 9648 | if (mFile == null) { |
| 9649 | Slog.w("BatteryStats", "writeLocked: no file associated with this instance"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9650 | return; |
| 9651 | } |
| 9652 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9653 | if (mShuttingDown) { |
| 9654 | return; |
| 9655 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 9656 | |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 9657 | Parcel out = Parcel.obtain(); |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 9658 | writeSummaryToParcel(out, true); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9659 | mLastWriteTime = mClocks.elapsedRealtime(); |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 9660 | |
| 9661 | if (mPendingWrite != null) { |
| 9662 | mPendingWrite.recycle(); |
| 9663 | } |
| 9664 | mPendingWrite = out; |
| 9665 | |
| 9666 | if (sync) { |
| 9667 | commitPendingDataToDisk(); |
| 9668 | } else { |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 9669 | BackgroundThread.getHandler().post(new Runnable() { |
| 9670 | @Override public void run() { |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 9671 | commitPendingDataToDisk(); |
| 9672 | } |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 9673 | }); |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 9674 | } |
| 9675 | } |
| 9676 | |
| 9677 | public void commitPendingDataToDisk() { |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 9678 | final Parcel next; |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 9679 | synchronized (this) { |
| 9680 | next = mPendingWrite; |
| 9681 | mPendingWrite = null; |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 9682 | if (next == null) { |
| 9683 | return; |
| 9684 | } |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 9685 | |
| 9686 | mWriteLock.lock(); |
| 9687 | } |
| 9688 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9689 | try { |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 9690 | FileOutputStream stream = new FileOutputStream(mFile.chooseForWrite()); |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 9691 | stream.write(next.marshall()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9692 | stream.flush(); |
Dianne Hackborn | 8bdf593 | 2010-10-15 12:54:40 -0700 | [diff] [blame] | 9693 | FileUtils.sync(stream); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9694 | stream.close(); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 9695 | mFile.commit(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9696 | } catch (IOException e) { |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 9697 | Slog.w("BatteryStats", "Error writing battery statistics", e); |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 9698 | mFile.rollback(); |
| 9699 | } finally { |
| 9700 | next.recycle(); |
| 9701 | mWriteLock.unlock(); |
Suchi Amalapurapu | 8550f25 | 2009-09-29 15:20:32 -0700 | [diff] [blame] | 9702 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9703 | } |
| 9704 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9705 | public void readLocked() { |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 9706 | if (mDailyFile != null) { |
| 9707 | readDailyStatsLocked(); |
| 9708 | } |
| 9709 | |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 9710 | if (mFile == null) { |
| 9711 | Slog.w("BatteryStats", "readLocked: no file associated with this instance"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9712 | return; |
| 9713 | } |
| 9714 | |
| 9715 | mUidStats.clear(); |
| 9716 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9717 | try { |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 9718 | File file = mFile.chooseForRead(); |
| 9719 | if (!file.exists()) { |
| 9720 | return; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9721 | } |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 9722 | FileInputStream stream = new FileInputStream(file); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9723 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 9724 | byte[] raw = BatteryStatsHelper.readFully(stream); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9725 | Parcel in = Parcel.obtain(); |
| 9726 | in.unmarshall(raw, 0, raw.length); |
| 9727 | in.setDataPosition(0); |
| 9728 | stream.close(); |
| 9729 | |
| 9730 | readSummaryFromParcel(in); |
Dianne Hackborn | 00e2521 | 2014-02-19 10:49:24 -0800 | [diff] [blame] | 9731 | } catch(Exception e) { |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 9732 | Slog.e("BatteryStats", "Error reading battery statistics", e); |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 9733 | resetAllStatsLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9734 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 9735 | |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 9736 | mEndPlatformVersion = Build.ID; |
| 9737 | |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 9738 | if (mHistoryBuffer.dataPosition() > 0) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 9739 | mRecordingHistory = true; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9740 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 9741 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 9742 | if (USE_OLD_HISTORY) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 9743 | addHistoryRecordLocked(elapsedRealtime, uptime, HistoryItem.CMD_START, mHistoryCur); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 9744 | } |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 9745 | addHistoryBufferLocked(elapsedRealtime, uptime, HistoryItem.CMD_START, mHistoryCur); |
| 9746 | startRecordingHistory(elapsedRealtime, uptime, false); |
Dianne Hackborn | e8c88e6 | 2011-08-17 19:09:09 -0700 | [diff] [blame] | 9747 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 9748 | |
| 9749 | recordDailyStatsIfNeededLocked(false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9750 | } |
| 9751 | |
| 9752 | public int describeContents() { |
| 9753 | return 0; |
| 9754 | } |
| 9755 | |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 9756 | void readHistory(Parcel in, boolean andOldHistory) throws ParcelFormatException { |
Dianne Hackborn | ae38445 | 2011-06-28 12:33:48 -0700 | [diff] [blame] | 9757 | final long historyBaseTime = in.readLong(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 9758 | |
| 9759 | mHistoryBuffer.setDataSize(0); |
| 9760 | mHistoryBuffer.setDataPosition(0); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 9761 | mHistoryTagPool.clear(); |
| 9762 | mNextHistoryTagIdx = 0; |
| 9763 | mNumHistoryTagChars = 0; |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 9764 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 9765 | int numTags = in.readInt(); |
| 9766 | for (int i=0; i<numTags; i++) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 9767 | int idx = in.readInt(); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 9768 | String str = in.readString(); |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 9769 | if (str == null) { |
| 9770 | throw new ParcelFormatException("null history tag string"); |
| 9771 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 9772 | int uid = in.readInt(); |
| 9773 | HistoryTag tag = new HistoryTag(); |
| 9774 | tag.string = str; |
| 9775 | tag.uid = uid; |
| 9776 | tag.poolIdx = idx; |
| 9777 | mHistoryTagPool.put(tag, idx); |
| 9778 | if (idx >= mNextHistoryTagIdx) { |
| 9779 | mNextHistoryTagIdx = idx+1; |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 9780 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 9781 | mNumHistoryTagChars += tag.string.length() + 1; |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 9782 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 9783 | |
| 9784 | int bufSize = in.readInt(); |
| 9785 | int curPos = in.dataPosition(); |
| 9786 | if (bufSize >= (MAX_MAX_HISTORY_BUFFER*3)) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 9787 | throw new ParcelFormatException("File corrupt: history data buffer too large " + |
| 9788 | bufSize); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 9789 | } else if ((bufSize&~3) != bufSize) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 9790 | throw new ParcelFormatException("File corrupt: history data buffer not aligned " + |
| 9791 | bufSize); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 9792 | } else { |
| 9793 | if (DEBUG_HISTORY) Slog.i(TAG, "***************** READING NEW HISTORY: " + bufSize |
| 9794 | + " bytes at " + curPos); |
| 9795 | mHistoryBuffer.appendFrom(in, curPos, bufSize); |
| 9796 | in.setDataPosition(curPos + bufSize); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 9797 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 9798 | |
Dianne Hackborn | ae38445 | 2011-06-28 12:33:48 -0700 | [diff] [blame] | 9799 | if (andOldHistory) { |
| 9800 | readOldHistory(in); |
| 9801 | } |
| 9802 | |
| 9803 | if (DEBUG_HISTORY) { |
| 9804 | StringBuilder sb = new StringBuilder(128); |
| 9805 | sb.append("****************** OLD mHistoryBaseTime: "); |
| 9806 | TimeUtils.formatDuration(mHistoryBaseTime, sb); |
| 9807 | Slog.i(TAG, sb.toString()); |
| 9808 | } |
| 9809 | mHistoryBaseTime = historyBaseTime; |
| 9810 | if (DEBUG_HISTORY) { |
| 9811 | StringBuilder sb = new StringBuilder(128); |
| 9812 | sb.append("****************** NEW mHistoryBaseTime: "); |
| 9813 | TimeUtils.formatDuration(mHistoryBaseTime, sb); |
| 9814 | Slog.i(TAG, sb.toString()); |
| 9815 | } |
| 9816 | |
| 9817 | // We are just arbitrarily going to insert 1 minute from the sample of |
| 9818 | // the last run until samples in this run. |
| 9819 | if (mHistoryBaseTime > 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9820 | long oldnow = mClocks.elapsedRealtime(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 9821 | mHistoryBaseTime = mHistoryBaseTime - oldnow + 1; |
Dianne Hackborn | ae38445 | 2011-06-28 12:33:48 -0700 | [diff] [blame] | 9822 | if (DEBUG_HISTORY) { |
| 9823 | StringBuilder sb = new StringBuilder(128); |
| 9824 | sb.append("****************** ADJUSTED mHistoryBaseTime: "); |
| 9825 | TimeUtils.formatDuration(mHistoryBaseTime, sb); |
| 9826 | Slog.i(TAG, sb.toString()); |
| 9827 | } |
Dianne Hackborn | 1e4b9f3 | 2010-06-23 14:10:57 -0700 | [diff] [blame] | 9828 | } |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 9829 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 9830 | |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 9831 | void readOldHistory(Parcel in) { |
Dianne Hackborn | e8c88e6 | 2011-08-17 19:09:09 -0700 | [diff] [blame] | 9832 | if (!USE_OLD_HISTORY) { |
| 9833 | return; |
| 9834 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 9835 | mHistory = mHistoryEnd = mHistoryCache = null; |
| 9836 | long time; |
Conley Owens | 5e3357f | 2011-05-02 09:59:30 -0700 | [diff] [blame] | 9837 | while (in.dataAvail() > 0 && (time=in.readLong()) >= 0) { |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 9838 | HistoryItem rec = new HistoryItem(time, in); |
| 9839 | addHistoryRecordLocked(rec); |
| 9840 | } |
| 9841 | } |
| 9842 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 9843 | void writeHistory(Parcel out, boolean inclData, boolean andOldHistory) { |
Dianne Hackborn | ae38445 | 2011-06-28 12:33:48 -0700 | [diff] [blame] | 9844 | if (DEBUG_HISTORY) { |
| 9845 | StringBuilder sb = new StringBuilder(128); |
| 9846 | sb.append("****************** WRITING mHistoryBaseTime: "); |
| 9847 | TimeUtils.formatDuration(mHistoryBaseTime, sb); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 9848 | sb.append(" mLastHistoryElapsedRealtime: "); |
| 9849 | TimeUtils.formatDuration(mLastHistoryElapsedRealtime, sb); |
Dianne Hackborn | ae38445 | 2011-06-28 12:33:48 -0700 | [diff] [blame] | 9850 | Slog.i(TAG, sb.toString()); |
| 9851 | } |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 9852 | out.writeLong(mHistoryBaseTime + mLastHistoryElapsedRealtime); |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 9853 | if (!inclData) { |
| 9854 | out.writeInt(0); |
| 9855 | out.writeInt(0); |
| 9856 | return; |
| 9857 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 9858 | out.writeInt(mHistoryTagPool.size()); |
| 9859 | for (HashMap.Entry<HistoryTag, Integer> ent : mHistoryTagPool.entrySet()) { |
| 9860 | HistoryTag tag = ent.getKey(); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 9861 | out.writeInt(ent.getValue()); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 9862 | out.writeString(tag.string); |
| 9863 | out.writeInt(tag.uid); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 9864 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 9865 | out.writeInt(mHistoryBuffer.dataSize()); |
| 9866 | if (DEBUG_HISTORY) Slog.i(TAG, "***************** WRITING HISTORY: " |
| 9867 | + mHistoryBuffer.dataSize() + " bytes at " + out.dataPosition()); |
| 9868 | out.appendFrom(mHistoryBuffer, 0, mHistoryBuffer.dataSize()); |
Dianne Hackborn | ae38445 | 2011-06-28 12:33:48 -0700 | [diff] [blame] | 9869 | |
| 9870 | if (andOldHistory) { |
| 9871 | writeOldHistory(out); |
| 9872 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 9873 | } |
| 9874 | |
| 9875 | void writeOldHistory(Parcel out) { |
Dianne Hackborn | e8c88e6 | 2011-08-17 19:09:09 -0700 | [diff] [blame] | 9876 | if (!USE_OLD_HISTORY) { |
| 9877 | return; |
| 9878 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9879 | HistoryItem rec = mHistory; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 9880 | while (rec != null) { |
| 9881 | if (rec.time >= 0) rec.writeToParcel(out, 0); |
| 9882 | rec = rec.next; |
| 9883 | } |
| 9884 | out.writeLong(-1); |
| 9885 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 9886 | |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 9887 | public void readSummaryFromParcel(Parcel in) throws ParcelFormatException { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9888 | final int version = in.readInt(); |
| 9889 | if (version != VERSION) { |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 9890 | Slog.w("BatteryStats", "readFromParcel: version got " + version |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9891 | + ", expected " + VERSION + "; erasing old stats"); |
| 9892 | return; |
| 9893 | } |
| 9894 | |
Dianne Hackborn | ae38445 | 2011-06-28 12:33:48 -0700 | [diff] [blame] | 9895 | readHistory(in, true); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 9896 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9897 | mStartCount = in.readInt(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9898 | mUptime = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9899 | mRealtime = in.readLong(); |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 9900 | mStartClockTime = in.readLong(); |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 9901 | mStartPlatformVersion = in.readString(); |
| 9902 | mEndPlatformVersion = in.readString(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9903 | mOnBatteryTimeBase.readSummaryFromParcel(in); |
| 9904 | mOnBatteryScreenOffTimeBase.readSummaryFromParcel(in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9905 | mDischargeUnplugLevel = in.readInt(); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 9906 | mDischargePlugLevel = in.readInt(); |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 9907 | mDischargeCurrentLevel = in.readInt(); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 9908 | mCurrentBatteryLevel = in.readInt(); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 9909 | mLowDischargeAmountSinceCharge = in.readInt(); |
| 9910 | mHighDischargeAmountSinceCharge = in.readInt(); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 9911 | mDischargeAmountScreenOnSinceCharge = in.readInt(); |
| 9912 | mDischargeAmountScreenOffSinceCharge = in.readInt(); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 9913 | mDischargeStepTracker.readFromParcel(in); |
| 9914 | mChargeStepTracker.readFromParcel(in); |
| 9915 | mDailyDischargeStepTracker.readFromParcel(in); |
| 9916 | mDailyChargeStepTracker.readFromParcel(in); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 9917 | int NPKG = in.readInt(); |
| 9918 | if (NPKG > 0) { |
| 9919 | mDailyPackageChanges = new ArrayList<>(NPKG); |
| 9920 | while (NPKG > 0) { |
| 9921 | NPKG--; |
| 9922 | PackageChange pc = new PackageChange(); |
| 9923 | pc.mPackageName = in.readString(); |
| 9924 | pc.mUpdate = in.readInt() != 0; |
| 9925 | pc.mVersionCode = in.readInt(); |
| 9926 | mDailyPackageChanges.add(pc); |
| 9927 | } |
| 9928 | } else { |
| 9929 | mDailyPackageChanges = null; |
| 9930 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 9931 | mDailyStartTime = in.readLong(); |
| 9932 | mNextMinDailyDeadline = in.readLong(); |
| 9933 | mNextMaxDailyDeadline = in.readLong(); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 9934 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9935 | mStartCount++; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 9936 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 9937 | mScreenState = Display.STATE_UNKNOWN; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9938 | mScreenOnTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 9939 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
| 9940 | mScreenBrightnessTimer[i].readSummaryFromParcelLocked(in); |
| 9941 | } |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 9942 | mInteractive = false; |
| 9943 | mInteractiveTimer.readSummaryFromParcelLocked(in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9944 | mPhoneOn = false; |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 9945 | mPowerSaveModeEnabledTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 9946 | mLongestLightIdleTime = in.readLong(); |
| 9947 | mLongestFullIdleTime = in.readLong(); |
| 9948 | mDeviceIdleModeLightTimer.readSummaryFromParcelLocked(in); |
| 9949 | mDeviceIdleModeFullTimer.readSummaryFromParcelLocked(in); |
| 9950 | mDeviceLightIdlingTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 9951 | mDeviceIdlingTimer.readSummaryFromParcelLocked(in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9952 | mPhoneOnTimer.readSummaryFromParcelLocked(in); |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 9953 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 9954 | mPhoneSignalStrengthsTimer[i].readSummaryFromParcelLocked(in); |
| 9955 | } |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 9956 | mPhoneSignalScanningTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 9957 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
| 9958 | mPhoneDataConnectionsTimer[i].readSummaryFromParcelLocked(in); |
| 9959 | } |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 9960 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 9961 | mNetworkByteActivityCounters[i].readSummaryFromParcelLocked(in); |
| 9962 | mNetworkPacketActivityCounters[i].readSummaryFromParcelLocked(in); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 9963 | } |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 9964 | mMobileRadioPowerState = DataConnectionRealTimeInfo.DC_POWER_STATE_LOW; |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 9965 | mMobileRadioActiveTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 9966 | mMobileRadioActivePerAppTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 9967 | mMobileRadioActiveAdjustedTime.readSummaryFromParcelLocked(in); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 9968 | mMobileRadioActiveUnknownTime.readSummaryFromParcelLocked(in); |
| 9969 | mMobileRadioActiveUnknownCount.readSummaryFromParcelLocked(in); |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 9970 | mWifiRadioPowerState = DataConnectionRealTimeInfo.DC_POWER_STATE_LOW; |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 9971 | mWifiOn = false; |
| 9972 | mWifiOnTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 9973 | mGlobalWifiRunning = false; |
| 9974 | mGlobalWifiRunningTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 9975 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
| 9976 | mWifiStateTimer[i].readSummaryFromParcelLocked(in); |
| 9977 | } |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 9978 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
| 9979 | mWifiSupplStateTimer[i].readSummaryFromParcelLocked(in); |
| 9980 | } |
| 9981 | for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 9982 | mWifiSignalStrengthsTimer[i].readSummaryFromParcelLocked(in); |
| 9983 | } |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 9984 | mWifiActivity.readSummaryFromParcel(in); |
| 9985 | mBluetoothActivity.readSummaryFromParcel(in); |
| 9986 | mModemActivity.readSummaryFromParcel(in); |
| 9987 | mHasWifiReporting = in.readInt() != 0; |
| 9988 | mHasBluetoothReporting = in.readInt() != 0; |
| 9989 | mHasModemReporting = in.readInt() != 0; |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 9990 | |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 9991 | mNumConnectivityChange = mLoadedNumConnectivityChange = in.readInt(); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 9992 | mFlashlightOnNesting = 0; |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 9993 | mFlashlightOnTimer.readSummaryFromParcelLocked(in); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 9994 | mCameraOnNesting = 0; |
| 9995 | mCameraOnTimer.readSummaryFromParcelLocked(in); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 9996 | mBluetoothScanNesting = 0; |
| 9997 | mBluetoothScanTimer.readSummaryFromParcelLocked(in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9998 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 9999 | int NKW = in.readInt(); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 10000 | if (NKW > 10000) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 10001 | throw new ParcelFormatException("File corrupt: too many kernel wake locks " + NKW); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 10002 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 10003 | for (int ikw = 0; ikw < NKW; ikw++) { |
| 10004 | if (in.readInt() != 0) { |
| 10005 | String kwltName = in.readString(); |
| 10006 | getKernelWakelockTimerLocked(kwltName).readSummaryFromParcelLocked(in); |
| 10007 | } |
| 10008 | } |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 10009 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 10010 | int NWR = in.readInt(); |
| 10011 | if (NWR > 10000) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 10012 | throw new ParcelFormatException("File corrupt: too many wakeup reasons " + NWR); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 10013 | } |
| 10014 | for (int iwr = 0; iwr < NWR; iwr++) { |
| 10015 | if (in.readInt() != 0) { |
| 10016 | String reasonName = in.readString(); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 10017 | getWakeupReasonTimerLocked(reasonName).readSummaryFromParcelLocked(in); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 10018 | } |
| 10019 | } |
| 10020 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10021 | final int NU = in.readInt(); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 10022 | if (NU > 10000) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 10023 | throw new ParcelFormatException("File corrupt: too many uids " + NU); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 10024 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10025 | for (int iu = 0; iu < NU; iu++) { |
| 10026 | int uid = in.readInt(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 10027 | Uid u = new Uid(this, uid); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10028 | mUidStats.put(uid, u); |
| 10029 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 10030 | u.mWifiRunning = false; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10031 | if (in.readInt() != 0) { |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 10032 | u.mWifiRunningTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10033 | } |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 10034 | u.mFullWifiLockOut = false; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10035 | if (in.readInt() != 0) { |
| 10036 | u.mFullWifiLockTimer.readSummaryFromParcelLocked(in); |
| 10037 | } |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 10038 | u.mWifiScanStarted = false; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10039 | if (in.readInt() != 0) { |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 10040 | u.mWifiScanTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10041 | } |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 10042 | u.mWifiBatchedScanBinStarted = Uid.NO_BATCHED_SCAN_STARTED; |
| 10043 | for (int i = 0; i < Uid.NUM_WIFI_BATCHED_SCAN_BINS; i++) { |
| 10044 | if (in.readInt() != 0) { |
| 10045 | u.makeWifiBatchedScanBin(i, null); |
| 10046 | u.mWifiBatchedScanTimer[i].readSummaryFromParcelLocked(in); |
| 10047 | } |
| 10048 | } |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 10049 | u.mWifiMulticastEnabled = false; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10050 | if (in.readInt() != 0) { |
| 10051 | u.mWifiMulticastTimer.readSummaryFromParcelLocked(in); |
| 10052 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10053 | if (in.readInt() != 0) { |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 10054 | u.createAudioTurnedOnTimerLocked().readSummaryFromParcelLocked(in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10055 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10056 | if (in.readInt() != 0) { |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 10057 | u.createVideoTurnedOnTimerLocked().readSummaryFromParcelLocked(in); |
| 10058 | } |
| 10059 | if (in.readInt() != 0) { |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 10060 | u.createFlashlightTurnedOnTimerLocked().readSummaryFromParcelLocked(in); |
| 10061 | } |
| 10062 | if (in.readInt() != 0) { |
| 10063 | u.createCameraTurnedOnTimerLocked().readSummaryFromParcelLocked(in); |
| 10064 | } |
| 10065 | if (in.readInt() != 0) { |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 10066 | u.createForegroundActivityTimerLocked().readSummaryFromParcelLocked(in); |
| 10067 | } |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 10068 | if (in.readInt() != 0) { |
| 10069 | u.createBluetoothScanTimerLocked().readSummaryFromParcelLocked(in); |
| 10070 | } |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 10071 | u.mProcessState = ActivityManager.PROCESS_STATE_NONEXISTENT; |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 10072 | for (int i = 0; i < Uid.NUM_PROCESS_STATE; i++) { |
| 10073 | if (in.readInt() != 0) { |
| 10074 | u.makeProcessState(i, null); |
| 10075 | u.mProcessStateTimer[i].readSummaryFromParcelLocked(in); |
| 10076 | } |
| 10077 | } |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 10078 | if (in.readInt() != 0) { |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 10079 | u.createVibratorOnTimerLocked().readSummaryFromParcelLocked(in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10080 | } |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 10081 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 10082 | if (in.readInt() != 0) { |
| 10083 | if (u.mUserActivityCounters == null) { |
| 10084 | u.initUserActivityLocked(); |
| 10085 | } |
| 10086 | for (int i=0; i<Uid.NUM_USER_ACTIVITY_TYPES; i++) { |
| 10087 | u.mUserActivityCounters[i].readSummaryFromParcelLocked(in); |
| 10088 | } |
| 10089 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 10090 | |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 10091 | if (in.readInt() != 0) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 10092 | if (u.mNetworkByteActivityCounters == null) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 10093 | u.initNetworkActivityLocked(); |
| 10094 | } |
| 10095 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 10096 | u.mNetworkByteActivityCounters[i].readSummaryFromParcelLocked(in); |
| 10097 | u.mNetworkPacketActivityCounters[i].readSummaryFromParcelLocked(in); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 10098 | } |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 10099 | u.mMobileRadioActiveTime.readSummaryFromParcelLocked(in); |
| 10100 | u.mMobileRadioActiveCount.readSummaryFromParcelLocked(in); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 10101 | } |
| 10102 | |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 10103 | u.mUserCpuTime.readSummaryFromParcelLocked(in); |
| 10104 | u.mSystemCpuTime.readSummaryFromParcelLocked(in); |
Adam Lesinski | a7a4ccc | 2015-06-26 17:43:04 -0700 | [diff] [blame] | 10105 | u.mCpuPower.readSummaryFromParcelLocked(in); |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 10106 | |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 10107 | if (in.readInt() != 0) { |
| 10108 | final int numClusters = in.readInt(); |
| 10109 | if (mPowerProfile != null && mPowerProfile.getNumCpuClusters() != numClusters) { |
| 10110 | throw new ParcelFormatException("Incompatible cpu cluster arrangement"); |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 10111 | } |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 10112 | |
| 10113 | u.mCpuClusterSpeed = new LongSamplingCounter[numClusters][]; |
| 10114 | for (int cluster = 0; cluster < numClusters; cluster++) { |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 10115 | if (in.readInt() != 0) { |
Adam Lesinski | a57a540 | 2015-09-28 10:21:33 -0700 | [diff] [blame] | 10116 | final int NSB = in.readInt(); |
| 10117 | if (mPowerProfile != null && |
| 10118 | mPowerProfile.getNumSpeedStepsInCpuCluster(cluster) != NSB) { |
| 10119 | throw new ParcelFormatException("File corrupt: too many speed bins " + |
| 10120 | NSB); |
| 10121 | } |
| 10122 | |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 10123 | u.mCpuClusterSpeed[cluster] = new LongSamplingCounter[NSB]; |
| 10124 | for (int speed = 0; speed < NSB; speed++) { |
| 10125 | if (in.readInt() != 0) { |
| 10126 | u.mCpuClusterSpeed[cluster][speed] = new LongSamplingCounter( |
| 10127 | mOnBatteryTimeBase); |
| 10128 | u.mCpuClusterSpeed[cluster][speed].readSummaryFromParcelLocked(in); |
| 10129 | } |
| 10130 | } |
Adam Lesinski | a57a540 | 2015-09-28 10:21:33 -0700 | [diff] [blame] | 10131 | } else { |
| 10132 | u.mCpuClusterSpeed[cluster] = null; |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 10133 | } |
| 10134 | } |
| 10135 | } else { |
| 10136 | u.mCpuClusterSpeed = null; |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 10137 | } |
| 10138 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10139 | int NW = in.readInt(); |
Dianne Hackborn | 7b9c56f | 2010-12-07 11:14:53 -0800 | [diff] [blame] | 10140 | if (NW > 100) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 10141 | throw new ParcelFormatException("File corrupt: too many wake locks " + NW); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 10142 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10143 | for (int iw = 0; iw < NW; iw++) { |
| 10144 | String wlName = in.readString(); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 10145 | u.readWakeSummaryFromParcelLocked(wlName, in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10146 | } |
| 10147 | |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 10148 | int NS = in.readInt(); |
| 10149 | if (NS > 100) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 10150 | throw new ParcelFormatException("File corrupt: too many syncs " + NS); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 10151 | } |
| 10152 | for (int is = 0; is < NS; is++) { |
| 10153 | String name = in.readString(); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 10154 | u.readSyncSummaryFromParcelLocked(name, in); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 10155 | } |
| 10156 | |
| 10157 | int NJ = in.readInt(); |
| 10158 | if (NJ > 100) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 10159 | throw new ParcelFormatException("File corrupt: too many job timers " + NJ); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 10160 | } |
| 10161 | for (int ij = 0; ij < NJ; ij++) { |
| 10162 | String name = in.readString(); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 10163 | u.readJobSummaryFromParcelLocked(name, in); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 10164 | } |
| 10165 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10166 | int NP = in.readInt(); |
Dianne Hackborn | 7b9c56f | 2010-12-07 11:14:53 -0800 | [diff] [blame] | 10167 | if (NP > 1000) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 10168 | throw new ParcelFormatException("File corrupt: too many sensors " + NP); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 10169 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10170 | for (int is = 0; is < NP; is++) { |
| 10171 | int seNumber = in.readInt(); |
| 10172 | if (in.readInt() != 0) { |
| 10173 | u.getSensorTimerLocked(seNumber, true) |
| 10174 | .readSummaryFromParcelLocked(in); |
| 10175 | } |
| 10176 | } |
| 10177 | |
| 10178 | NP = in.readInt(); |
Dianne Hackborn | 7b9c56f | 2010-12-07 11:14:53 -0800 | [diff] [blame] | 10179 | if (NP > 1000) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 10180 | throw new ParcelFormatException("File corrupt: too many processes " + NP); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 10181 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10182 | for (int ip = 0; ip < NP; ip++) { |
| 10183 | String procName = in.readString(); |
| 10184 | Uid.Proc p = u.getProcessStatsLocked(procName); |
| 10185 | p.mUserTime = p.mLoadedUserTime = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10186 | p.mSystemTime = p.mLoadedSystemTime = in.readLong(); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 10187 | p.mForegroundTime = p.mLoadedForegroundTime = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10188 | p.mStarts = p.mLoadedStarts = in.readInt(); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 10189 | p.mNumCrashes = p.mLoadedNumCrashes = in.readInt(); |
| 10190 | p.mNumAnrs = p.mLoadedNumAnrs = in.readInt(); |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 10191 | p.readExcessivePowerFromParcelLocked(in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10192 | } |
| 10193 | |
| 10194 | NP = in.readInt(); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 10195 | if (NP > 10000) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 10196 | throw new ParcelFormatException("File corrupt: too many packages " + NP); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 10197 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10198 | for (int ip = 0; ip < NP; ip++) { |
| 10199 | String pkgName = in.readString(); |
| 10200 | Uid.Pkg p = u.getPackageStatsLocked(pkgName); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 10201 | final int NWA = in.readInt(); |
| 10202 | if (NWA > 1000) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 10203 | throw new ParcelFormatException("File corrupt: too many wakeup alarms " + NWA); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 10204 | } |
| 10205 | p.mWakeupAlarms.clear(); |
| 10206 | for (int iwa=0; iwa<NWA; iwa++) { |
| 10207 | String tag = in.readString(); |
| 10208 | Counter c = new Counter(mOnBatteryTimeBase); |
| 10209 | c.readSummaryFromParcelLocked(in); |
| 10210 | p.mWakeupAlarms.put(tag, c); |
| 10211 | } |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 10212 | NS = in.readInt(); |
Dianne Hackborn | 7b9c56f | 2010-12-07 11:14:53 -0800 | [diff] [blame] | 10213 | if (NS > 1000) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 10214 | throw new ParcelFormatException("File corrupt: too many services " + NS); |
Dianne Hackborn | 7b9c56f | 2010-12-07 11:14:53 -0800 | [diff] [blame] | 10215 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10216 | for (int is = 0; is < NS; is++) { |
| 10217 | String servName = in.readString(); |
| 10218 | Uid.Pkg.Serv s = u.getServiceStatsLocked(pkgName, servName); |
| 10219 | s.mStartTime = s.mLoadedStartTime = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10220 | s.mStarts = s.mLoadedStarts = in.readInt(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10221 | s.mLaunches = s.mLoadedLaunches = in.readInt(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10222 | } |
| 10223 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10224 | } |
| 10225 | } |
| 10226 | |
| 10227 | /** |
| 10228 | * Writes a summary of the statistics to a Parcel, in a format suitable to be written to |
| 10229 | * disk. This format does not allow a lossless round-trip. |
| 10230 | * |
| 10231 | * @param out the Parcel to be written to. |
| 10232 | */ |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 10233 | public void writeSummaryToParcel(Parcel out, boolean inclHistory) { |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 10234 | pullPendingStateUpdatesLocked(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 10235 | |
Dianne Hackborn | 7d9eefd | 2014-08-27 18:30:31 -0700 | [diff] [blame] | 10236 | // Pull the clock time. This may update the time and make a new history entry |
| 10237 | // if we had originally pulled a time before the RTC was set. |
| 10238 | long startClockTime = getStartClockTime(); |
| 10239 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 10240 | final long NOW_SYS = mClocks.uptimeMillis() * 1000; |
| 10241 | final long NOWREAL_SYS = mClocks.elapsedRealtime() * 1000; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10242 | |
| 10243 | out.writeInt(VERSION); |
| 10244 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 10245 | writeHistory(out, inclHistory, true); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 10246 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10247 | out.writeInt(mStartCount); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10248 | out.writeLong(computeUptime(NOW_SYS, STATS_SINCE_CHARGED)); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10249 | out.writeLong(computeRealtime(NOWREAL_SYS, STATS_SINCE_CHARGED)); |
Dianne Hackborn | 7d9eefd | 2014-08-27 18:30:31 -0700 | [diff] [blame] | 10250 | out.writeLong(startClockTime); |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 10251 | out.writeString(mStartPlatformVersion); |
| 10252 | out.writeString(mEndPlatformVersion); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10253 | mOnBatteryTimeBase.writeSummaryToParcel(out, NOW_SYS, NOWREAL_SYS); |
| 10254 | mOnBatteryScreenOffTimeBase.writeSummaryToParcel(out, NOW_SYS, NOWREAL_SYS); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10255 | out.writeInt(mDischargeUnplugLevel); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 10256 | out.writeInt(mDischargePlugLevel); |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 10257 | out.writeInt(mDischargeCurrentLevel); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 10258 | out.writeInt(mCurrentBatteryLevel); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 10259 | out.writeInt(getLowDischargeAmountSinceCharge()); |
| 10260 | out.writeInt(getHighDischargeAmountSinceCharge()); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 10261 | out.writeInt(getDischargeAmountScreenOnSinceCharge()); |
| 10262 | out.writeInt(getDischargeAmountScreenOffSinceCharge()); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 10263 | mDischargeStepTracker.writeToParcel(out); |
| 10264 | mChargeStepTracker.writeToParcel(out); |
| 10265 | mDailyDischargeStepTracker.writeToParcel(out); |
| 10266 | mDailyChargeStepTracker.writeToParcel(out); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 10267 | if (mDailyPackageChanges != null) { |
| 10268 | final int NPKG = mDailyPackageChanges.size(); |
| 10269 | out.writeInt(NPKG); |
| 10270 | for (int i=0; i<NPKG; i++) { |
| 10271 | PackageChange pc = mDailyPackageChanges.get(i); |
| 10272 | out.writeString(pc.mPackageName); |
| 10273 | out.writeInt(pc.mUpdate ? 1 : 0); |
| 10274 | out.writeInt(pc.mVersionCode); |
| 10275 | } |
| 10276 | } else { |
| 10277 | out.writeInt(0); |
| 10278 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 10279 | out.writeLong(mDailyStartTime); |
| 10280 | out.writeLong(mNextMinDailyDeadline); |
| 10281 | out.writeLong(mNextMaxDailyDeadline); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10282 | |
| 10283 | mScreenOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 10284 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10285 | mScreenBrightnessTimer[i].writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 10286 | } |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 10287 | mInteractiveTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 10288 | mPowerSaveModeEnabledTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 10289 | out.writeLong(mLongestLightIdleTime); |
| 10290 | out.writeLong(mLongestFullIdleTime); |
| 10291 | mDeviceIdleModeLightTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 10292 | mDeviceIdleModeFullTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 10293 | mDeviceLightIdlingTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 10294 | mDeviceIdlingTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10295 | mPhoneOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 10296 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10297 | mPhoneSignalStrengthsTimer[i].writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 10298 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10299 | mPhoneSignalScanningTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 10300 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10301 | mPhoneDataConnectionsTimer[i].writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 10302 | } |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 10303 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 10304 | mNetworkByteActivityCounters[i].writeSummaryFromParcelLocked(out); |
| 10305 | mNetworkPacketActivityCounters[i].writeSummaryFromParcelLocked(out); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 10306 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10307 | mMobileRadioActiveTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 10308 | mMobileRadioActivePerAppTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 10309 | mMobileRadioActiveAdjustedTime.writeSummaryFromParcelLocked(out); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 10310 | mMobileRadioActiveUnknownTime.writeSummaryFromParcelLocked(out); |
| 10311 | mMobileRadioActiveUnknownCount.writeSummaryFromParcelLocked(out); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10312 | mWifiOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 10313 | mGlobalWifiRunningTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 10314 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10315 | mWifiStateTimer[i].writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 10316 | } |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 10317 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
| 10318 | mWifiSupplStateTimer[i].writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 10319 | } |
| 10320 | for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 10321 | mWifiSignalStrengthsTimer[i].writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 10322 | } |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 10323 | mWifiActivity.writeSummaryToParcel(out); |
| 10324 | mBluetoothActivity.writeSummaryToParcel(out); |
| 10325 | mModemActivity.writeSummaryToParcel(out); |
| 10326 | out.writeInt(mHasWifiReporting ? 1 : 0); |
| 10327 | out.writeInt(mHasBluetoothReporting ? 1 : 0); |
| 10328 | out.writeInt(mHasModemReporting ? 1 : 0); |
| 10329 | |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 10330 | out.writeInt(mNumConnectivityChange); |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 10331 | mFlashlightOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 10332 | mCameraOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 10333 | mBluetoothScanTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10334 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 10335 | out.writeInt(mKernelWakelockStats.size()); |
| 10336 | for (Map.Entry<String, SamplingTimer> ent : mKernelWakelockStats.entrySet()) { |
| 10337 | Timer kwlt = ent.getValue(); |
| 10338 | if (kwlt != null) { |
| 10339 | out.writeInt(1); |
| 10340 | out.writeString(ent.getKey()); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 10341 | kwlt.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 10342 | } else { |
| 10343 | out.writeInt(0); |
| 10344 | } |
| 10345 | } |
| 10346 | |
| 10347 | out.writeInt(mWakeupReasonStats.size()); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 10348 | for (Map.Entry<String, SamplingTimer> ent : mWakeupReasonStats.entrySet()) { |
| 10349 | SamplingTimer timer = ent.getValue(); |
| 10350 | if (timer != null) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 10351 | out.writeInt(1); |
| 10352 | out.writeString(ent.getKey()); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 10353 | timer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 10354 | } else { |
| 10355 | out.writeInt(0); |
| 10356 | } |
| 10357 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 10358 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10359 | final int NU = mUidStats.size(); |
| 10360 | out.writeInt(NU); |
| 10361 | for (int iu = 0; iu < NU; iu++) { |
| 10362 | out.writeInt(mUidStats.keyAt(iu)); |
| 10363 | Uid u = mUidStats.valueAt(iu); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 10364 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 10365 | if (u.mWifiRunningTimer != null) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10366 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10367 | u.mWifiRunningTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10368 | } else { |
| 10369 | out.writeInt(0); |
| 10370 | } |
| 10371 | if (u.mFullWifiLockTimer != null) { |
| 10372 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10373 | u.mFullWifiLockTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10374 | } else { |
| 10375 | out.writeInt(0); |
| 10376 | } |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 10377 | if (u.mWifiScanTimer != null) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10378 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10379 | u.mWifiScanTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10380 | } else { |
| 10381 | out.writeInt(0); |
| 10382 | } |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 10383 | for (int i = 0; i < Uid.NUM_WIFI_BATCHED_SCAN_BINS; i++) { |
| 10384 | if (u.mWifiBatchedScanTimer[i] != null) { |
| 10385 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10386 | u.mWifiBatchedScanTimer[i].writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 10387 | } else { |
| 10388 | out.writeInt(0); |
| 10389 | } |
| 10390 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10391 | if (u.mWifiMulticastTimer != null) { |
| 10392 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10393 | u.mWifiMulticastTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10394 | } else { |
| 10395 | out.writeInt(0); |
| 10396 | } |
| 10397 | if (u.mAudioTurnedOnTimer != null) { |
| 10398 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10399 | u.mAudioTurnedOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10400 | } else { |
| 10401 | out.writeInt(0); |
| 10402 | } |
| 10403 | if (u.mVideoTurnedOnTimer != null) { |
| 10404 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10405 | u.mVideoTurnedOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10406 | } else { |
| 10407 | out.writeInt(0); |
| 10408 | } |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 10409 | if (u.mFlashlightTurnedOnTimer != null) { |
| 10410 | out.writeInt(1); |
| 10411 | u.mFlashlightTurnedOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 10412 | } else { |
| 10413 | out.writeInt(0); |
| 10414 | } |
| 10415 | if (u.mCameraTurnedOnTimer != null) { |
| 10416 | out.writeInt(1); |
| 10417 | u.mCameraTurnedOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 10418 | } else { |
| 10419 | out.writeInt(0); |
| 10420 | } |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 10421 | if (u.mForegroundActivityTimer != null) { |
| 10422 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10423 | u.mForegroundActivityTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 10424 | } else { |
| 10425 | out.writeInt(0); |
| 10426 | } |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 10427 | if (u.mBluetoothScanTimer != null) { |
| 10428 | out.writeInt(1); |
| 10429 | u.mBluetoothScanTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 10430 | } else { |
| 10431 | out.writeInt(0); |
| 10432 | } |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 10433 | for (int i = 0; i < Uid.NUM_PROCESS_STATE; i++) { |
| 10434 | if (u.mProcessStateTimer[i] != null) { |
| 10435 | out.writeInt(1); |
| 10436 | u.mProcessStateTimer[i].writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 10437 | } else { |
| 10438 | out.writeInt(0); |
| 10439 | } |
| 10440 | } |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 10441 | if (u.mVibratorOnTimer != null) { |
| 10442 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10443 | u.mVibratorOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 10444 | } else { |
| 10445 | out.writeInt(0); |
| 10446 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10447 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 10448 | if (u.mUserActivityCounters == null) { |
| 10449 | out.writeInt(0); |
| 10450 | } else { |
| 10451 | out.writeInt(1); |
| 10452 | for (int i=0; i<Uid.NUM_USER_ACTIVITY_TYPES; i++) { |
| 10453 | u.mUserActivityCounters[i].writeSummaryFromParcelLocked(out); |
| 10454 | } |
| 10455 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 10456 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 10457 | if (u.mNetworkByteActivityCounters == null) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 10458 | out.writeInt(0); |
| 10459 | } else { |
| 10460 | out.writeInt(1); |
| 10461 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 10462 | u.mNetworkByteActivityCounters[i].writeSummaryFromParcelLocked(out); |
| 10463 | u.mNetworkPacketActivityCounters[i].writeSummaryFromParcelLocked(out); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 10464 | } |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 10465 | u.mMobileRadioActiveTime.writeSummaryFromParcelLocked(out); |
| 10466 | u.mMobileRadioActiveCount.writeSummaryFromParcelLocked(out); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 10467 | } |
| 10468 | |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 10469 | u.mUserCpuTime.writeSummaryFromParcelLocked(out); |
| 10470 | u.mSystemCpuTime.writeSummaryFromParcelLocked(out); |
Adam Lesinski | a7a4ccc | 2015-06-26 17:43:04 -0700 | [diff] [blame] | 10471 | u.mCpuPower.writeSummaryFromParcelLocked(out); |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 10472 | |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 10473 | if (u.mCpuClusterSpeed != null) { |
| 10474 | out.writeInt(1); |
| 10475 | out.writeInt(u.mCpuClusterSpeed.length); |
| 10476 | for (LongSamplingCounter[] cpuSpeeds : u.mCpuClusterSpeed) { |
| 10477 | if (cpuSpeeds != null) { |
| 10478 | out.writeInt(1); |
| 10479 | out.writeInt(cpuSpeeds.length); |
| 10480 | for (LongSamplingCounter c : cpuSpeeds) { |
| 10481 | if (c != null) { |
| 10482 | out.writeInt(1); |
| 10483 | c.writeSummaryFromParcelLocked(out); |
| 10484 | } else { |
| 10485 | out.writeInt(0); |
| 10486 | } |
| 10487 | } |
| 10488 | } else { |
| 10489 | out.writeInt(0); |
| 10490 | } |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 10491 | } |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 10492 | } else { |
| 10493 | out.writeInt(0); |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 10494 | } |
| 10495 | |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 10496 | final ArrayMap<String, Uid.Wakelock> wakeStats = u.mWakelockStats.getMap(); |
| 10497 | int NW = wakeStats.size(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10498 | out.writeInt(NW); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 10499 | for (int iw=0; iw<NW; iw++) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 10500 | out.writeString(wakeStats.keyAt(iw)); |
| 10501 | Uid.Wakelock wl = wakeStats.valueAt(iw); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 10502 | if (wl.mTimerFull != null) { |
| 10503 | out.writeInt(1); |
| 10504 | wl.mTimerFull.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 10505 | } else { |
| 10506 | out.writeInt(0); |
| 10507 | } |
| 10508 | if (wl.mTimerPartial != null) { |
| 10509 | out.writeInt(1); |
| 10510 | wl.mTimerPartial.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 10511 | } else { |
| 10512 | out.writeInt(0); |
| 10513 | } |
| 10514 | if (wl.mTimerWindow != null) { |
| 10515 | out.writeInt(1); |
| 10516 | wl.mTimerWindow.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 10517 | } else { |
| 10518 | out.writeInt(0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10519 | } |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 10520 | if (wl.mTimerDraw != null) { |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 10521 | out.writeInt(1); |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 10522 | wl.mTimerDraw.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 10523 | } else { |
| 10524 | out.writeInt(0); |
| 10525 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10526 | } |
| 10527 | |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 10528 | final ArrayMap<String, StopwatchTimer> syncStats = u.mSyncStats.getMap(); |
| 10529 | int NS = syncStats.size(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 10530 | out.writeInt(NS); |
| 10531 | for (int is=0; is<NS; is++) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 10532 | out.writeString(syncStats.keyAt(is)); |
| 10533 | syncStats.valueAt(is).writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 10534 | } |
| 10535 | |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 10536 | final ArrayMap<String, StopwatchTimer> jobStats = u.mJobStats.getMap(); |
| 10537 | int NJ = jobStats.size(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 10538 | out.writeInt(NJ); |
| 10539 | for (int ij=0; ij<NJ; ij++) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 10540 | out.writeString(jobStats.keyAt(ij)); |
| 10541 | jobStats.valueAt(ij).writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 10542 | } |
| 10543 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10544 | int NSE = u.mSensorStats.size(); |
| 10545 | out.writeInt(NSE); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 10546 | for (int ise=0; ise<NSE; ise++) { |
| 10547 | out.writeInt(u.mSensorStats.keyAt(ise)); |
| 10548 | Uid.Sensor se = u.mSensorStats.valueAt(ise); |
| 10549 | if (se.mTimer != null) { |
| 10550 | out.writeInt(1); |
| 10551 | se.mTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 10552 | } else { |
| 10553 | out.writeInt(0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10554 | } |
| 10555 | } |
| 10556 | |
| 10557 | int NP = u.mProcessStats.size(); |
| 10558 | out.writeInt(NP); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 10559 | for (int ip=0; ip<NP; ip++) { |
| 10560 | out.writeString(u.mProcessStats.keyAt(ip)); |
| 10561 | Uid.Proc ps = u.mProcessStats.valueAt(ip); |
| 10562 | out.writeLong(ps.mUserTime); |
| 10563 | out.writeLong(ps.mSystemTime); |
| 10564 | out.writeLong(ps.mForegroundTime); |
| 10565 | out.writeInt(ps.mStarts); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 10566 | out.writeInt(ps.mNumCrashes); |
| 10567 | out.writeInt(ps.mNumAnrs); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 10568 | ps.writeExcessivePowerToParcelLocked(out); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10569 | } |
| 10570 | |
| 10571 | NP = u.mPackageStats.size(); |
| 10572 | out.writeInt(NP); |
| 10573 | if (NP > 0) { |
| 10574 | for (Map.Entry<String, BatteryStatsImpl.Uid.Pkg> ent |
| 10575 | : u.mPackageStats.entrySet()) { |
| 10576 | out.writeString(ent.getKey()); |
| 10577 | Uid.Pkg ps = ent.getValue(); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 10578 | final int NWA = ps.mWakeupAlarms.size(); |
| 10579 | out.writeInt(NWA); |
| 10580 | for (int iwa=0; iwa<NWA; iwa++) { |
| 10581 | out.writeString(ps.mWakeupAlarms.keyAt(iwa)); |
| 10582 | ps.mWakeupAlarms.valueAt(iwa).writeSummaryFromParcelLocked(out); |
| 10583 | } |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 10584 | NS = ps.mServiceStats.size(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10585 | out.writeInt(NS); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 10586 | for (int is=0; is<NS; is++) { |
| 10587 | out.writeString(ps.mServiceStats.keyAt(is)); |
| 10588 | BatteryStatsImpl.Uid.Pkg.Serv ss = ps.mServiceStats.valueAt(is); |
| 10589 | long time = ss.getStartTimeToNowLocked( |
| 10590 | mOnBatteryTimeBase.getUptime(NOW_SYS)); |
| 10591 | out.writeLong(time); |
| 10592 | out.writeInt(ss.mStarts); |
| 10593 | out.writeInt(ss.mLaunches); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10594 | } |
| 10595 | } |
| 10596 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10597 | } |
| 10598 | } |
| 10599 | |
| 10600 | public void readFromParcel(Parcel in) { |
| 10601 | readFromParcelLocked(in); |
| 10602 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 10603 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10604 | void readFromParcelLocked(Parcel in) { |
| 10605 | int magic = in.readInt(); |
| 10606 | if (magic != MAGIC) { |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 10607 | throw new ParcelFormatException("Bad magic number: #" + Integer.toHexString(magic)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10608 | } |
| 10609 | |
Dianne Hackborn | ae38445 | 2011-06-28 12:33:48 -0700 | [diff] [blame] | 10610 | readHistory(in, false); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 10611 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10612 | mStartCount = in.readInt(); |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 10613 | mStartClockTime = in.readLong(); |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 10614 | mStartPlatformVersion = in.readString(); |
| 10615 | mEndPlatformVersion = in.readString(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10616 | mUptime = in.readLong(); |
| 10617 | mUptimeStart = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10618 | mRealtime = in.readLong(); |
| 10619 | mRealtimeStart = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10620 | mOnBattery = in.readInt() != 0; |
| 10621 | mOnBatteryInternal = false; // we are no longer really running. |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10622 | mOnBatteryTimeBase.readFromParcel(in); |
| 10623 | mOnBatteryScreenOffTimeBase.readFromParcel(in); |
| 10624 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 10625 | mScreenState = Display.STATE_UNKNOWN; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 10626 | mScreenOnTimer = new StopwatchTimer(mClocks, null, -1, null, mOnBatteryTimeBase, in); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10627 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 10628 | mScreenBrightnessTimer[i] = new StopwatchTimer(mClocks, null, -100-i, null, |
| 10629 | mOnBatteryTimeBase, in); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10630 | } |
Dianne Hackborn | 2932513 | 2014-05-21 15:01:03 -0700 | [diff] [blame] | 10631 | mInteractive = false; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 10632 | mInteractiveTimer = new StopwatchTimer(mClocks, null, -10, null, mOnBatteryTimeBase, in); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10633 | mPhoneOn = false; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 10634 | mPowerSaveModeEnabledTimer = new StopwatchTimer(mClocks, null, -2, null, |
| 10635 | mOnBatteryTimeBase, in); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 10636 | mLongestLightIdleTime = in.readLong(); |
| 10637 | mLongestFullIdleTime = in.readLong(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 10638 | mDeviceIdleModeLightTimer = new StopwatchTimer(mClocks, null, -14, null, |
| 10639 | mOnBatteryTimeBase, in); |
| 10640 | mDeviceIdleModeFullTimer = new StopwatchTimer(mClocks, null, -11, null, |
| 10641 | mOnBatteryTimeBase, in); |
| 10642 | mDeviceLightIdlingTimer = new StopwatchTimer(mClocks, null, -15, null, |
| 10643 | mOnBatteryTimeBase, in); |
| 10644 | mDeviceIdlingTimer = new StopwatchTimer(mClocks, null, -12, null, mOnBatteryTimeBase, in); |
| 10645 | mPhoneOnTimer = new StopwatchTimer(mClocks, null, -3, null, mOnBatteryTimeBase, in); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10646 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 10647 | mPhoneSignalStrengthsTimer[i] = new StopwatchTimer(mClocks, null, -200-i, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10648 | null, mOnBatteryTimeBase, in); |
| 10649 | } |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 10650 | mPhoneSignalScanningTimer = new StopwatchTimer(mClocks, null, -200+1, null, |
| 10651 | mOnBatteryTimeBase, in); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10652 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 10653 | mPhoneDataConnectionsTimer[i] = new StopwatchTimer(mClocks, null, -300-i, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10654 | null, mOnBatteryTimeBase, in); |
| 10655 | } |
| 10656 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
| 10657 | mNetworkByteActivityCounters[i] = new LongSamplingCounter(mOnBatteryTimeBase, in); |
| 10658 | mNetworkPacketActivityCounters[i] = new LongSamplingCounter(mOnBatteryTimeBase, in); |
| 10659 | } |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 10660 | mMobileRadioPowerState = DataConnectionRealTimeInfo.DC_POWER_STATE_LOW; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 10661 | mMobileRadioActiveTimer = new StopwatchTimer(mClocks, null, -400, null, |
| 10662 | mOnBatteryTimeBase, in); |
| 10663 | mMobileRadioActivePerAppTimer = new StopwatchTimer(mClocks, null, -401, null, |
| 10664 | mOnBatteryTimeBase, in); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 10665 | mMobileRadioActiveAdjustedTime = new LongSamplingCounter(mOnBatteryTimeBase, in); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10666 | mMobileRadioActiveUnknownTime = new LongSamplingCounter(mOnBatteryTimeBase, in); |
| 10667 | mMobileRadioActiveUnknownCount = new LongSamplingCounter(mOnBatteryTimeBase, in); |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 10668 | mWifiRadioPowerState = DataConnectionRealTimeInfo.DC_POWER_STATE_LOW; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10669 | mWifiOn = false; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 10670 | mWifiOnTimer = new StopwatchTimer(mClocks, null, -4, null, mOnBatteryTimeBase, in); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10671 | mGlobalWifiRunning = false; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 10672 | mGlobalWifiRunningTimer = new StopwatchTimer(mClocks, null, -5, null, |
| 10673 | mOnBatteryTimeBase, in); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10674 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 10675 | mWifiStateTimer[i] = new StopwatchTimer(mClocks, null, -600-i, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10676 | null, mOnBatteryTimeBase, in); |
| 10677 | } |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 10678 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 10679 | mWifiSupplStateTimer[i] = new StopwatchTimer(mClocks, null, -700-i, |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 10680 | null, mOnBatteryTimeBase, in); |
| 10681 | } |
| 10682 | for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 10683 | mWifiSignalStrengthsTimer[i] = new StopwatchTimer(mClocks, null, -800-i, |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 10684 | null, mOnBatteryTimeBase, in); |
| 10685 | } |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 10686 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 10687 | mWifiActivity = new ControllerActivityCounterImpl(mOnBatteryTimeBase, |
| 10688 | NUM_WIFI_TX_LEVELS, in); |
| 10689 | mBluetoothActivity = new ControllerActivityCounterImpl(mOnBatteryTimeBase, |
| 10690 | NUM_BT_TX_LEVELS, in); |
| 10691 | mModemActivity = new ControllerActivityCounterImpl(mOnBatteryTimeBase, |
| 10692 | ModemActivityInfo.TX_POWER_LEVELS, in); |
| 10693 | mHasWifiReporting = in.readInt() != 0; |
| 10694 | mHasBluetoothReporting = in.readInt() != 0; |
| 10695 | mHasModemReporting = in.readInt() != 0; |
| 10696 | |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 10697 | mNumConnectivityChange = in.readInt(); |
| 10698 | mLoadedNumConnectivityChange = in.readInt(); |
| 10699 | mUnpluggedNumConnectivityChange = in.readInt(); |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 10700 | mAudioOnNesting = 0; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 10701 | mAudioOnTimer = new StopwatchTimer(mClocks, null, -7, null, mOnBatteryTimeBase); |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 10702 | mVideoOnNesting = 0; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 10703 | mVideoOnTimer = new StopwatchTimer(mClocks, null, -8, null, mOnBatteryTimeBase); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 10704 | mFlashlightOnNesting = 0; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 10705 | mFlashlightOnTimer = new StopwatchTimer(mClocks, null, -9, null, mOnBatteryTimeBase, in); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 10706 | mCameraOnNesting = 0; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 10707 | mCameraOnTimer = new StopwatchTimer(mClocks, null, -13, null, mOnBatteryTimeBase, in); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 10708 | mBluetoothScanNesting = 0; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 10709 | mBluetoothScanTimer = new StopwatchTimer(mClocks, null, -14, null, mOnBatteryTimeBase, in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10710 | mDischargeUnplugLevel = in.readInt(); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 10711 | mDischargePlugLevel = in.readInt(); |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 10712 | mDischargeCurrentLevel = in.readInt(); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 10713 | mCurrentBatteryLevel = in.readInt(); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 10714 | mLowDischargeAmountSinceCharge = in.readInt(); |
| 10715 | mHighDischargeAmountSinceCharge = in.readInt(); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 10716 | mDischargeAmountScreenOn = in.readInt(); |
| 10717 | mDischargeAmountScreenOnSinceCharge = in.readInt(); |
| 10718 | mDischargeAmountScreenOff = in.readInt(); |
| 10719 | mDischargeAmountScreenOffSinceCharge = in.readInt(); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 10720 | mDischargeStepTracker.readFromParcel(in); |
| 10721 | mChargeStepTracker.readFromParcel(in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10722 | mLastWriteTime = in.readLong(); |
| 10723 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 10724 | mKernelWakelockStats.clear(); |
| 10725 | int NKW = in.readInt(); |
| 10726 | for (int ikw = 0; ikw < NKW; ikw++) { |
| 10727 | if (in.readInt() != 0) { |
| 10728 | String wakelockName = in.readString(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 10729 | SamplingTimer kwlt = new SamplingTimer(mClocks, mOnBatteryScreenOffTimeBase, in); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 10730 | mKernelWakelockStats.put(wakelockName, kwlt); |
| 10731 | } |
| 10732 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 10733 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 10734 | mWakeupReasonStats.clear(); |
| 10735 | int NWR = in.readInt(); |
| 10736 | for (int iwr = 0; iwr < NWR; iwr++) { |
| 10737 | if (in.readInt() != 0) { |
| 10738 | String reasonName = in.readString(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 10739 | SamplingTimer timer = new SamplingTimer(mClocks, mOnBatteryTimeBase, in); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 10740 | mWakeupReasonStats.put(reasonName, timer); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 10741 | } |
| 10742 | } |
| 10743 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10744 | mPartialTimers.clear(); |
| 10745 | mFullTimers.clear(); |
| 10746 | mWindowTimers.clear(); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 10747 | mWifiRunningTimers.clear(); |
| 10748 | mFullWifiLockTimers.clear(); |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 10749 | mWifiScanTimers.clear(); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 10750 | mWifiBatchedScanTimers.clear(); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 10751 | mWifiMulticastTimers.clear(); |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 10752 | mAudioTurnedOnTimers.clear(); |
| 10753 | mVideoTurnedOnTimers.clear(); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 10754 | mFlashlightTurnedOnTimers.clear(); |
| 10755 | mCameraTurnedOnTimers.clear(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10756 | |
| 10757 | int numUids = in.readInt(); |
| 10758 | mUidStats.clear(); |
| 10759 | for (int i = 0; i < numUids; i++) { |
| 10760 | int uid = in.readInt(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 10761 | Uid u = new Uid(this, uid); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10762 | u.readFromParcelLocked(mOnBatteryTimeBase, mOnBatteryScreenOffTimeBase, in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10763 | mUidStats.append(uid, u); |
| 10764 | } |
| 10765 | } |
| 10766 | |
| 10767 | public void writeToParcel(Parcel out, int flags) { |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 10768 | writeToParcelLocked(out, true, flags); |
| 10769 | } |
| 10770 | |
| 10771 | public void writeToParcelWithoutUids(Parcel out, int flags) { |
| 10772 | writeToParcelLocked(out, false, flags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10773 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 10774 | |
| 10775 | @SuppressWarnings("unused") |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 10776 | void writeToParcelLocked(Parcel out, boolean inclUids, int flags) { |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 10777 | // Need to update with current kernel wake lock counts. |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 10778 | pullPendingStateUpdatesLocked(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 10779 | |
Dianne Hackborn | 7d9eefd | 2014-08-27 18:30:31 -0700 | [diff] [blame] | 10780 | // Pull the clock time. This may update the time and make a new history entry |
| 10781 | // if we had originally pulled a time before the RTC was set. |
| 10782 | long startClockTime = getStartClockTime(); |
| 10783 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 10784 | final long uSecUptime = mClocks.uptimeMillis() * 1000; |
| 10785 | final long uSecRealtime = mClocks.elapsedRealtime() * 1000; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10786 | final long batteryRealtime = mOnBatteryTimeBase.getRealtime(uSecRealtime); |
| 10787 | final long batteryScreenOffRealtime = mOnBatteryScreenOffTimeBase.getRealtime(uSecRealtime); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 10788 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10789 | out.writeInt(MAGIC); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 10790 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 10791 | writeHistory(out, true, false); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 10792 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10793 | out.writeInt(mStartCount); |
Dianne Hackborn | 7d9eefd | 2014-08-27 18:30:31 -0700 | [diff] [blame] | 10794 | out.writeLong(startClockTime); |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 10795 | out.writeString(mStartPlatformVersion); |
| 10796 | out.writeString(mEndPlatformVersion); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10797 | out.writeLong(mUptime); |
| 10798 | out.writeLong(mUptimeStart); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10799 | out.writeLong(mRealtime); |
| 10800 | out.writeLong(mRealtimeStart); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10801 | out.writeInt(mOnBattery ? 1 : 0); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10802 | mOnBatteryTimeBase.writeToParcel(out, uSecUptime, uSecRealtime); |
| 10803 | mOnBatteryScreenOffTimeBase.writeToParcel(out, uSecUptime, uSecRealtime); |
| 10804 | |
| 10805 | mScreenOnTimer.writeToParcel(out, uSecRealtime); |
| 10806 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
| 10807 | mScreenBrightnessTimer[i].writeToParcel(out, uSecRealtime); |
| 10808 | } |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 10809 | mInteractiveTimer.writeToParcel(out, uSecRealtime); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 10810 | mPowerSaveModeEnabledTimer.writeToParcel(out, uSecRealtime); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 10811 | out.writeLong(mLongestLightIdleTime); |
| 10812 | out.writeLong(mLongestFullIdleTime); |
| 10813 | mDeviceIdleModeLightTimer.writeToParcel(out, uSecRealtime); |
| 10814 | mDeviceIdleModeFullTimer.writeToParcel(out, uSecRealtime); |
| 10815 | mDeviceLightIdlingTimer.writeToParcel(out, uSecRealtime); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 10816 | mDeviceIdlingTimer.writeToParcel(out, uSecRealtime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10817 | mPhoneOnTimer.writeToParcel(out, uSecRealtime); |
| 10818 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
| 10819 | mPhoneSignalStrengthsTimer[i].writeToParcel(out, uSecRealtime); |
| 10820 | } |
| 10821 | mPhoneSignalScanningTimer.writeToParcel(out, uSecRealtime); |
| 10822 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
| 10823 | mPhoneDataConnectionsTimer[i].writeToParcel(out, uSecRealtime); |
| 10824 | } |
| 10825 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
| 10826 | mNetworkByteActivityCounters[i].writeToParcel(out); |
| 10827 | mNetworkPacketActivityCounters[i].writeToParcel(out); |
| 10828 | } |
| 10829 | mMobileRadioActiveTimer.writeToParcel(out, uSecRealtime); |
| 10830 | mMobileRadioActivePerAppTimer.writeToParcel(out, uSecRealtime); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 10831 | mMobileRadioActiveAdjustedTime.writeToParcel(out); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10832 | mMobileRadioActiveUnknownTime.writeToParcel(out); |
| 10833 | mMobileRadioActiveUnknownCount.writeToParcel(out); |
| 10834 | mWifiOnTimer.writeToParcel(out, uSecRealtime); |
| 10835 | mGlobalWifiRunningTimer.writeToParcel(out, uSecRealtime); |
| 10836 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
| 10837 | mWifiStateTimer[i].writeToParcel(out, uSecRealtime); |
| 10838 | } |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 10839 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
| 10840 | mWifiSupplStateTimer[i].writeToParcel(out, uSecRealtime); |
| 10841 | } |
| 10842 | for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 10843 | mWifiSignalStrengthsTimer[i].writeToParcel(out, uSecRealtime); |
| 10844 | } |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 10845 | mWifiActivity.writeToParcel(out, 0); |
| 10846 | mBluetoothActivity.writeToParcel(out, 0); |
| 10847 | mModemActivity.writeToParcel(out, 0); |
| 10848 | out.writeInt(mHasWifiReporting ? 1 : 0); |
| 10849 | out.writeInt(mHasBluetoothReporting ? 1 : 0); |
| 10850 | out.writeInt(mHasModemReporting ? 1 : 0); |
| 10851 | |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 10852 | out.writeInt(mNumConnectivityChange); |
| 10853 | out.writeInt(mLoadedNumConnectivityChange); |
| 10854 | out.writeInt(mUnpluggedNumConnectivityChange); |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 10855 | mFlashlightOnTimer.writeToParcel(out, uSecRealtime); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 10856 | mCameraOnTimer.writeToParcel(out, uSecRealtime); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 10857 | mBluetoothScanTimer.writeToParcel(out, uSecRealtime); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10858 | out.writeInt(mDischargeUnplugLevel); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 10859 | out.writeInt(mDischargePlugLevel); |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 10860 | out.writeInt(mDischargeCurrentLevel); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 10861 | out.writeInt(mCurrentBatteryLevel); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 10862 | out.writeInt(mLowDischargeAmountSinceCharge); |
| 10863 | out.writeInt(mHighDischargeAmountSinceCharge); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 10864 | out.writeInt(mDischargeAmountScreenOn); |
| 10865 | out.writeInt(mDischargeAmountScreenOnSinceCharge); |
| 10866 | out.writeInt(mDischargeAmountScreenOff); |
| 10867 | out.writeInt(mDischargeAmountScreenOffSinceCharge); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 10868 | mDischargeStepTracker.writeToParcel(out); |
| 10869 | mChargeStepTracker.writeToParcel(out); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10870 | out.writeLong(mLastWriteTime); |
| 10871 | |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 10872 | if (inclUids) { |
| 10873 | out.writeInt(mKernelWakelockStats.size()); |
| 10874 | for (Map.Entry<String, SamplingTimer> ent : mKernelWakelockStats.entrySet()) { |
| 10875 | SamplingTimer kwlt = ent.getValue(); |
| 10876 | if (kwlt != null) { |
| 10877 | out.writeInt(1); |
| 10878 | out.writeString(ent.getKey()); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 10879 | kwlt.writeToParcel(out, uSecRealtime); |
| 10880 | } else { |
| 10881 | out.writeInt(0); |
| 10882 | } |
| 10883 | } |
| 10884 | out.writeInt(mWakeupReasonStats.size()); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 10885 | for (Map.Entry<String, SamplingTimer> ent : mWakeupReasonStats.entrySet()) { |
| 10886 | SamplingTimer timer = ent.getValue(); |
| 10887 | if (timer != null) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 10888 | out.writeInt(1); |
| 10889 | out.writeString(ent.getKey()); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 10890 | timer.writeToParcel(out, uSecRealtime); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 10891 | } else { |
| 10892 | out.writeInt(0); |
| 10893 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 10894 | } |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 10895 | } else { |
| 10896 | out.writeInt(0); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 10897 | } |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 10898 | |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 10899 | if (inclUids) { |
| 10900 | int size = mUidStats.size(); |
| 10901 | out.writeInt(size); |
| 10902 | for (int i = 0; i < size; i++) { |
| 10903 | out.writeInt(mUidStats.keyAt(i)); |
| 10904 | Uid uid = mUidStats.valueAt(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10905 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10906 | uid.writeToParcelLocked(out, uSecRealtime); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 10907 | } |
| 10908 | } else { |
| 10909 | out.writeInt(0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10910 | } |
| 10911 | } |
| 10912 | |
| 10913 | public static final Parcelable.Creator<BatteryStatsImpl> CREATOR = |
| 10914 | new Parcelable.Creator<BatteryStatsImpl>() { |
| 10915 | public BatteryStatsImpl createFromParcel(Parcel in) { |
| 10916 | return new BatteryStatsImpl(in); |
| 10917 | } |
| 10918 | |
| 10919 | public BatteryStatsImpl[] newArray(int size) { |
| 10920 | return new BatteryStatsImpl[size]; |
| 10921 | } |
| 10922 | }; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 10923 | |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 10924 | public void prepareForDumpLocked() { |
| 10925 | // Need to retrieve current kernel wake lock stats before printing. |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 10926 | pullPendingStateUpdatesLocked(); |
Dianne Hackborn | 7d9eefd | 2014-08-27 18:30:31 -0700 | [diff] [blame] | 10927 | |
| 10928 | // Pull the clock time. This may update the time and make a new history entry |
| 10929 | // if we had originally pulled a time before the RTC was set. |
| 10930 | getStartClockTime(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 10931 | } |
| 10932 | |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 10933 | public void dumpLocked(Context context, PrintWriter pw, int flags, int reqUid, long histStart) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10934 | if (DEBUG) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10935 | pw.println("mOnBatteryTimeBase:"); |
| 10936 | mOnBatteryTimeBase.dump(pw, " "); |
| 10937 | pw.println("mOnBatteryScreenOffTimeBase:"); |
| 10938 | mOnBatteryScreenOffTimeBase.dump(pw, " "); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10939 | Printer pr = new PrintWriterPrinter(pw); |
| 10940 | pr.println("*** Screen timer:"); |
| 10941 | mScreenOnTimer.logState(pr, " "); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 10942 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10943 | pr.println("*** Screen brightness #" + i + ":"); |
| 10944 | mScreenBrightnessTimer[i].logState(pr, " "); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 10945 | } |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 10946 | pr.println("*** Interactive timer:"); |
| 10947 | mInteractiveTimer.logState(pr, " "); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 10948 | pr.println("*** Power save mode timer:"); |
| 10949 | mPowerSaveModeEnabledTimer.logState(pr, " "); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 10950 | pr.println("*** Device idle mode light timer:"); |
| 10951 | mDeviceIdleModeLightTimer.logState(pr, " "); |
| 10952 | pr.println("*** Device idle mode full timer:"); |
| 10953 | mDeviceIdleModeFullTimer.logState(pr, " "); |
| 10954 | pr.println("*** Device light idling timer:"); |
| 10955 | mDeviceLightIdlingTimer.logState(pr, " "); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 10956 | pr.println("*** Device idling timer:"); |
| 10957 | mDeviceIdlingTimer.logState(pr, " "); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10958 | pr.println("*** Phone timer:"); |
| 10959 | mPhoneOnTimer.logState(pr, " "); |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 10960 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 10961 | pr.println("*** Phone signal strength #" + i + ":"); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10962 | mPhoneSignalStrengthsTimer[i].logState(pr, " "); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 10963 | } |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 10964 | pr.println("*** Signal scanning :"); |
| 10965 | mPhoneSignalScanningTimer.logState(pr, " "); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 10966 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10967 | pr.println("*** Data connection type #" + i + ":"); |
| 10968 | mPhoneDataConnectionsTimer[i].logState(pr, " "); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 10969 | } |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 10970 | pr.println("*** mMobileRadioPowerState=" + mMobileRadioPowerState); |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 10971 | pr.println("*** Mobile network active timer:"); |
| 10972 | mMobileRadioActiveTimer.logState(pr, " "); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 10973 | pr.println("*** Mobile network active adjusted timer:"); |
| 10974 | mMobileRadioActiveAdjustedTime.logState(pr, " "); |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 10975 | pr.println("*** mWifiRadioPowerState=" + mWifiRadioPowerState); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10976 | pr.println("*** Wifi timer:"); |
| 10977 | mWifiOnTimer.logState(pr, " "); |
| 10978 | pr.println("*** WifiRunning timer:"); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 10979 | mGlobalWifiRunningTimer.logState(pr, " "); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 10980 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
| 10981 | pr.println("*** Wifi state #" + i + ":"); |
| 10982 | mWifiStateTimer[i].logState(pr, " "); |
| 10983 | } |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 10984 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
| 10985 | pr.println("*** Wifi suppl state #" + i + ":"); |
| 10986 | mWifiSupplStateTimer[i].logState(pr, " "); |
| 10987 | } |
| 10988 | for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 10989 | pr.println("*** Wifi signal strength #" + i + ":"); |
| 10990 | mWifiSignalStrengthsTimer[i].logState(pr, " "); |
| 10991 | } |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 10992 | pr.println("*** Flashlight timer:"); |
| 10993 | mFlashlightOnTimer.logState(pr, " "); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 10994 | pr.println("*** Camera timer:"); |
| 10995 | mCameraOnTimer.logState(pr, " "); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10996 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 10997 | super.dumpLocked(context, pw, flags, reqUid, histStart); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10998 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10999 | } |