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; |
James Carr | 3a22605 | 2016-07-01 14:49:52 -0700 | [diff] [blame] | 52 | import android.util.LongSparseArray; |
| 53 | import android.util.LongSparseLongArray; |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 54 | import android.util.MutableInt; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 55 | import android.util.PrintWriterPrinter; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 56 | import android.util.Printer; |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 57 | import android.util.Slog; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 58 | import android.util.SparseArray; |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 59 | import android.util.SparseIntArray; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 60 | import android.util.SparseLongArray; |
Dianne Hackborn | ae38445 | 2011-06-28 12:33:48 -0700 | [diff] [blame] | 61 | import android.util.TimeUtils; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 62 | import android.util.Xml; |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 63 | import android.view.Display; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 64 | |
Adam Lesinski | 98f0d46 | 2016-04-19 16:46:20 -0700 | [diff] [blame] | 65 | import com.android.internal.annotations.VisibleForTesting; |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 66 | import com.android.internal.net.NetworkStatsFactory; |
Dianne Hackborn | d0c5b9a | 2014-02-21 16:19:05 -0800 | [diff] [blame] | 67 | import com.android.internal.util.ArrayUtils; |
Dianne Hackborn | 8c84109 | 2013-06-24 13:46:13 -0700 | [diff] [blame] | 68 | import com.android.internal.util.FastPrintWriter; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 69 | import com.android.internal.util.FastXmlSerializer; |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 70 | import com.android.internal.util.JournaledFile; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 71 | import com.android.internal.util.XmlUtils; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 72 | import com.android.server.NetworkManagementSocketTagger; |
| 73 | import libcore.util.EmptyArray; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 74 | import org.xmlpull.v1.XmlPullParser; |
| 75 | import org.xmlpull.v1.XmlPullParserException; |
| 76 | import org.xmlpull.v1.XmlSerializer; |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 77 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 78 | import java.io.ByteArrayOutputStream; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 79 | import java.io.File; |
| 80 | import java.io.FileInputStream; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 81 | import java.io.FileNotFoundException; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 82 | import java.io.FileOutputStream; |
| 83 | import java.io.IOException; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 84 | import java.io.PrintWriter; |
Wojciech Staszkiewicz | 9e9e2e7 | 2015-05-08 14:58:46 +0100 | [diff] [blame] | 85 | import java.nio.charset.StandardCharsets; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 86 | import java.util.ArrayList; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 87 | import java.util.Calendar; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 88 | import java.util.HashMap; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 89 | import java.util.Iterator; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 90 | import java.util.Map; |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 91 | import java.util.concurrent.atomic.AtomicInteger; |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 92 | import java.util.concurrent.locks.ReentrantLock; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 93 | |
| 94 | /** |
| 95 | * All information we are collecting about things that can happen that impact |
| 96 | * battery life. All times are represented in microseconds except where indicated |
| 97 | * otherwise. |
| 98 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 99 | public class BatteryStatsImpl extends BatteryStats { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 100 | private static final String TAG = "BatteryStatsImpl"; |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 101 | private static final boolean DEBUG = false; |
Adam Lesinski | a7c90c8 | 2015-06-18 14:52:24 -0700 | [diff] [blame] | 102 | public static final boolean DEBUG_ENERGY = false; |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 103 | private static final boolean DEBUG_ENERGY_CPU = DEBUG_ENERGY; |
James Carr | 3a22605 | 2016-07-01 14:49:52 -0700 | [diff] [blame] | 104 | private static final boolean DEBUG_MEMORY = false; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 105 | private static final boolean DEBUG_HISTORY = false; |
Dianne Hackborn | e8c88e6 | 2011-08-17 19:09:09 -0700 | [diff] [blame] | 106 | private static final boolean USE_OLD_HISTORY = false; // for debugging. |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 107 | |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 108 | // TODO: remove "tcp" from network methods, since we measure total stats. |
| 109 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 110 | // 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] | 111 | private static final int MAGIC = 0xBA757475; // 'BATSTATS' |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 112 | |
| 113 | // Current on-disk Parcel version |
Kweku Adams | 47db5a8 | 2016-12-09 19:04:50 -0800 | [diff] [blame] | 114 | private static final int VERSION = 151 + (USE_OLD_HISTORY ? 1000 : 0); |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 115 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 116 | // Maximum number of items we will record in the history. |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 117 | private static final int MAX_HISTORY_ITEMS = 2000; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 118 | |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 119 | // No, really, THIS is the maximum number of items we will record in the history. |
| 120 | private static final int MAX_MAX_HISTORY_ITEMS = 3000; |
| 121 | |
Dianne Hackborn | 9e0f5d9 | 2010-02-22 15:05:42 -0800 | [diff] [blame] | 122 | // The maximum number of names wakelocks we will keep track of |
| 123 | // per uid; once the limit is reached, we batch the remaining wakelocks |
| 124 | // in to one common name. |
Dianne Hackborn | acc4a12 | 2014-08-18 16:33:44 -0700 | [diff] [blame] | 125 | private static final int MAX_WAKELOCKS_PER_UID = 100; |
Dianne Hackborn | c24ab86 | 2011-10-18 15:55:03 -0700 | [diff] [blame] | 126 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 127 | // Number of transmit power states the Wifi controller can be in. |
| 128 | private static final int NUM_WIFI_TX_LEVELS = 1; |
| 129 | |
| 130 | // Number of transmit power states the Bluetooth controller can be in. |
| 131 | private static final int NUM_BT_TX_LEVELS = 1; |
| 132 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 133 | protected Clocks mClocks; |
| 134 | |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 135 | private final JournaledFile mFile; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 136 | public final AtomicFile mCheckinFile; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 137 | public final AtomicFile mDailyFile; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 138 | |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 139 | static final int MSG_UPDATE_WAKELOCKS = 1; |
| 140 | static final int MSG_REPORT_POWER_CHANGE = 2; |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 141 | static final int MSG_REPORT_CHARGING = 3; |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 142 | static final long DELAY_UPDATE_WAKELOCKS = 5*1000; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 143 | |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 144 | private final KernelWakelockReader mKernelWakelockReader = new KernelWakelockReader(); |
| 145 | private final KernelWakelockStats mTmpWakelockStats = new KernelWakelockStats(); |
| 146 | |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 147 | private final KernelUidCpuTimeReader mKernelUidCpuTimeReader = new KernelUidCpuTimeReader(); |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 148 | private KernelCpuSpeedReader[] mKernelCpuSpeedReaders; |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 149 | |
James Carr | 3a22605 | 2016-07-01 14:49:52 -0700 | [diff] [blame] | 150 | private final KernelMemoryBandwidthStats mKernelMemoryBandwidthStats |
| 151 | = new KernelMemoryBandwidthStats(); |
| 152 | private final LongSparseArray<SamplingTimer> mKernelMemoryStats = new LongSparseArray<>(); |
| 153 | public LongSparseArray<SamplingTimer> getKernelMemoryStats() { |
| 154 | return mKernelMemoryStats; |
| 155 | } |
| 156 | |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 157 | public interface BatteryCallback { |
| 158 | public void batteryNeedsCpuUpdate(); |
| 159 | public void batteryPowerChanged(boolean onBattery); |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 160 | public void batterySendBroadcast(Intent intent); |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 161 | } |
| 162 | |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 163 | public interface PlatformIdleStateCallback { |
| 164 | public String getPlatformLowPowerStats(); |
| 165 | } |
| 166 | |
| 167 | private final PlatformIdleStateCallback mPlatformIdleStateCallback; |
| 168 | |
| 169 | |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 170 | final class MyHandler extends Handler { |
Jeff Brown | 6f357d3 | 2014-01-15 20:40:55 -0800 | [diff] [blame] | 171 | public MyHandler(Looper looper) { |
| 172 | super(looper, null, true); |
| 173 | } |
| 174 | |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 175 | @Override |
| 176 | public void handleMessage(Message msg) { |
| 177 | BatteryCallback cb = mCallback; |
| 178 | switch (msg.what) { |
| 179 | case MSG_UPDATE_WAKELOCKS: |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 180 | synchronized (BatteryStatsImpl.this) { |
| 181 | updateCpuTimeLocked(); |
| 182 | } |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 183 | if (cb != null) { |
| 184 | cb.batteryNeedsCpuUpdate(); |
| 185 | } |
| 186 | break; |
| 187 | case MSG_REPORT_POWER_CHANGE: |
| 188 | if (cb != null) { |
| 189 | cb.batteryPowerChanged(msg.arg1 != 0); |
| 190 | } |
| 191 | break; |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 192 | case MSG_REPORT_CHARGING: |
| 193 | if (cb != null) { |
| 194 | final String action; |
| 195 | synchronized (BatteryStatsImpl.this) { |
| 196 | action = mCharging ? BatteryManager.ACTION_CHARGING |
| 197 | : BatteryManager.ACTION_DISCHARGING; |
| 198 | } |
| 199 | Intent intent = new Intent(action); |
| 200 | intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT); |
| 201 | cb.batterySendBroadcast(intent); |
| 202 | } |
| 203 | break; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 204 | } |
| 205 | } |
| 206 | } |
| 207 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 208 | public interface Clocks { |
| 209 | public long elapsedRealtime(); |
| 210 | public long uptimeMillis(); |
| 211 | } |
| 212 | |
| 213 | public static class SystemClocks implements Clocks { |
| 214 | public long elapsedRealtime() { |
| 215 | return SystemClock.elapsedRealtime(); |
| 216 | } |
| 217 | |
| 218 | public long uptimeMillis() { |
| 219 | return SystemClock.uptimeMillis(); |
| 220 | } |
| 221 | } |
| 222 | |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 223 | public interface ExternalStatsSync { |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 224 | public static final int UPDATE_CPU = 0x01; |
| 225 | public static final int UPDATE_WIFI = 0x02; |
| 226 | public static final int UPDATE_RADIO = 0x04; |
| 227 | public static final int UPDATE_BT = 0x08; |
| 228 | public static final int UPDATE_ALL = UPDATE_CPU | UPDATE_WIFI | UPDATE_RADIO | UPDATE_BT; |
| 229 | |
| 230 | void scheduleSync(String reason, int flags); |
Adam Lesinski | 61db88f | 2015-07-01 15:05:07 -0700 | [diff] [blame] | 231 | void scheduleCpuSyncDueToRemovedUid(int uid); |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 232 | } |
| 233 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 234 | public final MyHandler mHandler; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 235 | private final ExternalStatsSync mExternalSync; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 236 | |
| 237 | private BatteryCallback mCallback; |
| 238 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 239 | /** |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 240 | * Mapping isolated uids to the actual owning app uid. |
| 241 | */ |
| 242 | final SparseIntArray mIsolatedUids = new SparseIntArray(); |
| 243 | |
| 244 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 245 | * The statistics we have collected organized by uids. |
| 246 | */ |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 247 | final SparseArray<BatteryStatsImpl.Uid> mUidStats = new SparseArray<>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 248 | |
| 249 | // A set of pools of currently active timers. When a timer is queried, we will divide the |
| 250 | // elapsed time by the number of active timers to arrive at that timer's share of the time. |
| 251 | // In order to do this, we must refresh each timer whenever the number of active timers |
| 252 | // changes. |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 253 | final ArrayList<StopwatchTimer> mPartialTimers = new ArrayList<>(); |
| 254 | final ArrayList<StopwatchTimer> mFullTimers = new ArrayList<>(); |
| 255 | final ArrayList<StopwatchTimer> mWindowTimers = new ArrayList<>(); |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 256 | final ArrayList<StopwatchTimer> mDrawTimers = new ArrayList<>(); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 257 | final SparseArray<ArrayList<StopwatchTimer>> mSensorTimers = new SparseArray<>(); |
| 258 | final ArrayList<StopwatchTimer> mWifiRunningTimers = new ArrayList<>(); |
| 259 | final ArrayList<StopwatchTimer> mFullWifiLockTimers = new ArrayList<>(); |
| 260 | final ArrayList<StopwatchTimer> mWifiMulticastTimers = new ArrayList<>(); |
| 261 | final ArrayList<StopwatchTimer> mWifiScanTimers = new ArrayList<>(); |
| 262 | final SparseArray<ArrayList<StopwatchTimer>> mWifiBatchedScanTimers = new SparseArray<>(); |
| 263 | final ArrayList<StopwatchTimer> mAudioTurnedOnTimers = new ArrayList<>(); |
| 264 | final ArrayList<StopwatchTimer> mVideoTurnedOnTimers = new ArrayList<>(); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 265 | final ArrayList<StopwatchTimer> mFlashlightTurnedOnTimers = new ArrayList<>(); |
| 266 | final ArrayList<StopwatchTimer> mCameraTurnedOnTimers = new ArrayList<>(); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 267 | final ArrayList<StopwatchTimer> mBluetoothScanOnTimers = new ArrayList<>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 268 | |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 269 | // Last partial timers we use for distributing CPU usage. |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 270 | final ArrayList<StopwatchTimer> mLastPartialTimers = new ArrayList<>(); |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 271 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 272 | // These are the objects that will want to do something when the device |
| 273 | // is unplugged from power. |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 274 | protected final TimeBase mOnBatteryTimeBase = new TimeBase(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 275 | |
| 276 | // These are the objects that will want to do something when the device |
| 277 | // is unplugged from power *and* the screen is off. |
| 278 | final TimeBase mOnBatteryScreenOffTimeBase = new TimeBase(); |
| 279 | |
| 280 | // Set to true when we want to distribute CPU across wakelocks for the next |
| 281 | // CPU update, even if we aren't currently running wake locks. |
| 282 | boolean mDistributeWakelockCpu; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 283 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 284 | boolean mShuttingDown; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 285 | |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 286 | final HistoryEventTracker mActiveEvents = new HistoryEventTracker(); |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 287 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 288 | long mHistoryBaseTime; |
| 289 | boolean mHaveBatteryLevel = false; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 290 | boolean mRecordingHistory = false; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 291 | int mNumHistoryItems; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 292 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 293 | static final int MAX_HISTORY_BUFFER = 256*1024; // 256KB |
| 294 | static final int MAX_MAX_HISTORY_BUFFER = 320*1024; // 320KB |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 295 | final Parcel mHistoryBuffer = Parcel.obtain(); |
| 296 | final HistoryItem mHistoryLastWritten = new HistoryItem(); |
| 297 | final HistoryItem mHistoryLastLastWritten = new HistoryItem(); |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 298 | final HistoryItem mHistoryReadTmp = new HistoryItem(); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 299 | final HistoryItem mHistoryAddTmp = new HistoryItem(); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 300 | final HashMap<HistoryTag, Integer> mHistoryTagPool = new HashMap<>(); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 301 | String[] mReadHistoryStrings; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 302 | int[] mReadHistoryUids; |
| 303 | int mReadHistoryChars; |
| 304 | int mNextHistoryTagIdx = 0; |
| 305 | int mNumHistoryTagChars = 0; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 306 | int mHistoryBufferLastPos = -1; |
| 307 | boolean mHistoryOverflow = false; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 308 | int mActiveHistoryStates = 0xffffffff; |
| 309 | int mActiveHistoryStates2 = 0xffffffff; |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 310 | long mLastHistoryElapsedRealtime = 0; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 311 | long mTrackRunningHistoryElapsedRealtime = 0; |
| 312 | long mTrackRunningHistoryUptime = 0; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 313 | |
| 314 | final HistoryItem mHistoryCur = new HistoryItem(); |
| 315 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 316 | HistoryItem mHistory; |
| 317 | HistoryItem mHistoryEnd; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 318 | HistoryItem mHistoryLastEnd; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 319 | HistoryItem mHistoryCache; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 320 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 321 | // Used by computeHistoryStepDetails |
| 322 | HistoryStepDetails mLastHistoryStepDetails = null; |
| 323 | byte mLastHistoryStepLevel = 0; |
| 324 | final HistoryStepDetails mCurHistoryStepDetails = new HistoryStepDetails(); |
| 325 | final HistoryStepDetails mReadHistoryStepDetails = new HistoryStepDetails(); |
| 326 | final HistoryStepDetails mTmpHistoryStepDetails = new HistoryStepDetails(); |
Adam Lesinski | 7b83b0c | 2015-06-05 12:59:36 -0700 | [diff] [blame] | 327 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 328 | /** |
Adam Lesinski | 7b83b0c | 2015-06-05 12:59:36 -0700 | [diff] [blame] | 329 | * Total time (in milliseconds) spent executing in user code. |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 330 | */ |
| 331 | long mLastStepCpuUserTime; |
| 332 | long mCurStepCpuUserTime; |
| 333 | /** |
Adam Lesinski | 7b83b0c | 2015-06-05 12:59:36 -0700 | [diff] [blame] | 334 | * Total time (in milliseconds) spent executing in kernel code. |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 335 | */ |
| 336 | long mLastStepCpuSystemTime; |
| 337 | long mCurStepCpuSystemTime; |
| 338 | /** |
Adam Lesinski | 7b83b0c | 2015-06-05 12:59:36 -0700 | [diff] [blame] | 339 | * Times from /proc/stat (but measured in milliseconds). |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 340 | */ |
| 341 | long mLastStepStatUserTime; |
| 342 | long mLastStepStatSystemTime; |
| 343 | long mLastStepStatIOWaitTime; |
| 344 | long mLastStepStatIrqTime; |
| 345 | long mLastStepStatSoftIrqTime; |
| 346 | long mLastStepStatIdleTime; |
| 347 | long mCurStepStatUserTime; |
| 348 | long mCurStepStatSystemTime; |
| 349 | long mCurStepStatIOWaitTime; |
| 350 | long mCurStepStatIrqTime; |
| 351 | long mCurStepStatSoftIrqTime; |
| 352 | long mCurStepStatIdleTime; |
| 353 | |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 354 | private HistoryItem mHistoryIterator; |
| 355 | private boolean mReadOverflow; |
| 356 | private boolean mIteratingHistory; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 357 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 358 | int mStartCount; |
| 359 | |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 360 | long mStartClockTime; |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 361 | String mStartPlatformVersion; |
| 362 | String mEndPlatformVersion; |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 363 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 364 | long mUptime; |
| 365 | long mUptimeStart; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 366 | long mRealtime; |
| 367 | long mRealtimeStart; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 368 | |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 369 | int mWakeLockNesting; |
| 370 | boolean mWakeLockImportant; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 371 | public boolean mRecordAllHistory; |
Dianne Hackborn | 9a75543 | 2014-05-15 17:05:22 -0700 | [diff] [blame] | 372 | boolean mNoAutoReset; |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 373 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 374 | int mScreenState = Display.STATE_UNKNOWN; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 375 | StopwatchTimer mScreenOnTimer; |
Amith Yamasani | 3718aaa | 2009-06-09 06:32:35 -0700 | [diff] [blame] | 376 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 377 | int mScreenBrightnessBin = -1; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 378 | final StopwatchTimer[] mScreenBrightnessTimer = new StopwatchTimer[NUM_SCREEN_BRIGHTNESS_BINS]; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 379 | |
Amith Yamasani | 674c9bb | 2017-02-01 09:45:17 -0800 | [diff] [blame] | 380 | boolean mPretendScreenOff; |
| 381 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 382 | boolean mInteractive; |
| 383 | StopwatchTimer mInteractiveTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 384 | |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 385 | boolean mPowerSaveModeEnabled; |
| 386 | StopwatchTimer mPowerSaveModeEnabledTimer; |
| 387 | |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 388 | boolean mDeviceIdling; |
| 389 | StopwatchTimer mDeviceIdlingTimer; |
| 390 | |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 391 | boolean mDeviceLightIdling; |
| 392 | StopwatchTimer mDeviceLightIdlingTimer; |
| 393 | |
| 394 | int mDeviceIdleMode; |
| 395 | long mLastIdleTimeStart; |
| 396 | long mLongestLightIdleTime; |
| 397 | long mLongestFullIdleTime; |
| 398 | StopwatchTimer mDeviceIdleModeLightTimer; |
| 399 | StopwatchTimer mDeviceIdleModeFullTimer; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 400 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 401 | boolean mPhoneOn; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 402 | StopwatchTimer mPhoneOnTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 403 | |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 404 | int mAudioOnNesting; |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 405 | StopwatchTimer mAudioOnTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 406 | |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 407 | int mVideoOnNesting; |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 408 | StopwatchTimer mVideoOnTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 409 | |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 410 | int mFlashlightOnNesting; |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 411 | StopwatchTimer mFlashlightOnTimer; |
| 412 | |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 413 | int mCameraOnNesting; |
| 414 | StopwatchTimer mCameraOnTimer; |
| 415 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 416 | int mPhoneSignalStrengthBin = -1; |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 417 | int mPhoneSignalStrengthBinRaw = -1; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 418 | final StopwatchTimer[] mPhoneSignalStrengthsTimer = |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 419 | new StopwatchTimer[SignalStrength.NUM_SIGNAL_STRENGTH_BINS]; |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 420 | |
| 421 | StopwatchTimer mPhoneSignalScanningTimer; |
| 422 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 423 | int mPhoneDataConnectionType = -1; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 424 | final StopwatchTimer[] mPhoneDataConnectionsTimer = |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 425 | new StopwatchTimer[NUM_DATA_CONNECTION_TYPES]; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 426 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 427 | final LongSamplingCounter[] mNetworkByteActivityCounters = |
| 428 | new LongSamplingCounter[NUM_NETWORK_ACTIVITY_TYPES]; |
| 429 | final LongSamplingCounter[] mNetworkPacketActivityCounters = |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 430 | new LongSamplingCounter[NUM_NETWORK_ACTIVITY_TYPES]; |
| 431 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 432 | /** |
| 433 | * The WiFi controller activity (time in tx, rx, idle, and power consumed) for the device. |
| 434 | */ |
| 435 | ControllerActivityCounterImpl mWifiActivity; |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 436 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 437 | /** |
| 438 | * The Bluetooth controller activity (time in tx, rx, idle, and power consumed) for the device. |
| 439 | */ |
| 440 | ControllerActivityCounterImpl mBluetoothActivity; |
| 441 | |
| 442 | /** |
| 443 | * The Modem controller activity (time in tx, rx, idle, and power consumed) for the device. |
| 444 | */ |
| 445 | ControllerActivityCounterImpl mModemActivity; |
| 446 | |
| 447 | /** |
| 448 | * Whether the device supports WiFi controller energy reporting. This is set to true on |
| 449 | * the first WiFi energy report. See {@link #mWifiActivity}. |
| 450 | */ |
| 451 | boolean mHasWifiReporting = false; |
| 452 | |
| 453 | /** |
| 454 | * Whether the device supports Bluetooth controller energy reporting. This is set to true on |
| 455 | * the first Bluetooth energy report. See {@link #mBluetoothActivity}. |
| 456 | */ |
| 457 | boolean mHasBluetoothReporting = false; |
| 458 | |
| 459 | /** |
| 460 | * Whether the device supports Modem controller energy reporting. This is set to true on |
| 461 | * the first Modem energy report. See {@link #mModemActivity}. |
| 462 | */ |
| 463 | boolean mHasModemReporting = false; |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 464 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 465 | boolean mWifiOn; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 466 | StopwatchTimer mWifiOnTimer; |
Eric Shienbrood | d4c5f89 | 2009-03-24 18:13:20 -0700 | [diff] [blame] | 467 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 468 | boolean mGlobalWifiRunning; |
| 469 | StopwatchTimer mGlobalWifiRunningTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 470 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 471 | int mWifiState = -1; |
| 472 | final StopwatchTimer[] mWifiStateTimer = new StopwatchTimer[NUM_WIFI_STATES]; |
| 473 | |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 474 | int mWifiSupplState = -1; |
| 475 | final StopwatchTimer[] mWifiSupplStateTimer = new StopwatchTimer[NUM_WIFI_SUPPL_STATES]; |
| 476 | |
| 477 | int mWifiSignalStrengthBin = -1; |
| 478 | final StopwatchTimer[] mWifiSignalStrengthsTimer = |
| 479 | new StopwatchTimer[NUM_WIFI_SIGNAL_STRENGTH_BINS]; |
| 480 | |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 481 | int mBluetoothScanNesting; |
| 482 | StopwatchTimer mBluetoothScanTimer; |
| 483 | |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 484 | int mMobileRadioPowerState = DataConnectionRealTimeInfo.DC_POWER_STATE_LOW; |
Dianne Hackborn | f7097a5 | 2014-05-13 09:56:14 -0700 | [diff] [blame] | 485 | long mMobileRadioActiveStartTime; |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 486 | StopwatchTimer mMobileRadioActiveTimer; |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 487 | StopwatchTimer mMobileRadioActivePerAppTimer; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 488 | LongSamplingCounter mMobileRadioActiveAdjustedTime; |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 489 | LongSamplingCounter mMobileRadioActiveUnknownTime; |
| 490 | LongSamplingCounter mMobileRadioActiveUnknownCount; |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 491 | |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 492 | int mWifiRadioPowerState = DataConnectionRealTimeInfo.DC_POWER_STATE_LOW; |
| 493 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 494 | /** |
| 495 | * These provide time bases that discount the time the device is plugged |
| 496 | * in to power. |
| 497 | */ |
| 498 | boolean mOnBattery; |
| 499 | boolean mOnBatteryInternal; |
Amith Yamasani | 3718aaa | 2009-06-09 06:32:35 -0700 | [diff] [blame] | 500 | |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 501 | /** |
| 502 | * External reporting of whether the device is actually charging. |
| 503 | */ |
| 504 | boolean mCharging = true; |
| 505 | int mLastChargingStateLevel; |
| 506 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 507 | /* |
| 508 | * These keep track of battery levels (1-100) at the last plug event and the last unplug event. |
| 509 | */ |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 510 | int mDischargeStartLevel; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 511 | int mDischargeUnplugLevel; |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 512 | int mDischargePlugLevel; |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 513 | int mDischargeCurrentLevel; |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 514 | int mCurrentBatteryLevel; |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 515 | int mLowDischargeAmountSinceCharge; |
| 516 | int mHighDischargeAmountSinceCharge; |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 517 | int mDischargeScreenOnUnplugLevel; |
| 518 | int mDischargeScreenOffUnplugLevel; |
| 519 | int mDischargeAmountScreenOn; |
| 520 | int mDischargeAmountScreenOnSinceCharge; |
| 521 | int mDischargeAmountScreenOff; |
| 522 | int mDischargeAmountScreenOffSinceCharge; |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 523 | |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 524 | private LongSamplingCounter mDischargeScreenOffCounter; |
| 525 | private LongSamplingCounter mDischargeCounter; |
| 526 | |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 527 | static final int MAX_LEVEL_STEPS = 200; |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 528 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 529 | int mInitStepMode = 0; |
| 530 | int mCurStepMode = 0; |
| 531 | int mModStepMode = 0; |
| 532 | |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 533 | int mLastDischargeStepLevel; |
Dianne Hackborn | 2932513 | 2014-05-21 15:01:03 -0700 | [diff] [blame] | 534 | int mMinDischargeStepLevel; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 535 | final LevelStepTracker mDischargeStepTracker = new LevelStepTracker(MAX_LEVEL_STEPS); |
| 536 | final LevelStepTracker mDailyDischargeStepTracker = new LevelStepTracker(MAX_LEVEL_STEPS*2); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 537 | ArrayList<PackageChange> mDailyPackageChanges; |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 538 | |
| 539 | int mLastChargeStepLevel; |
Dianne Hackborn | 2932513 | 2014-05-21 15:01:03 -0700 | [diff] [blame] | 540 | int mMaxChargeStepLevel; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 541 | final LevelStepTracker mChargeStepTracker = new LevelStepTracker(MAX_LEVEL_STEPS); |
| 542 | final LevelStepTracker mDailyChargeStepTracker = new LevelStepTracker(MAX_LEVEL_STEPS*2); |
| 543 | |
| 544 | static final int MAX_DAILY_ITEMS = 10; |
| 545 | |
| 546 | long mDailyStartTime = 0; |
| 547 | long mNextMinDailyDeadline = 0; |
| 548 | long mNextMaxDailyDeadline = 0; |
| 549 | |
| 550 | final ArrayList<DailyItem> mDailyItems = new ArrayList<>(); |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 551 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 552 | long mLastWriteTime = 0; // Milliseconds |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 553 | |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 554 | private int mPhoneServiceState = -1; |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 555 | private int mPhoneServiceStateRaw = -1; |
| 556 | private int mPhoneSimStateRaw = -1; |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 557 | |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 558 | private int mNumConnectivityChange; |
| 559 | private int mLoadedNumConnectivityChange; |
| 560 | private int mUnpluggedNumConnectivityChange; |
| 561 | |
Adam Lesinski | f9b20a9 | 2016-06-17 17:30:01 -0700 | [diff] [blame] | 562 | private int mEstimatedBatteryCapacity = -1; |
| 563 | |
Adam Lesinski | 041d917 | 2016-12-12 12:03:56 -0800 | [diff] [blame] | 564 | // Last learned capacity reported by BatteryService in |
| 565 | // setBatteryState(). |
| 566 | private int mLastChargeFullUAh = 0; |
| 567 | |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 568 | private final NetworkStats.Entry mTmpNetworkStatsEntry = new NetworkStats.Entry(); |
| 569 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 570 | private PowerProfile mPowerProfile; |
| 571 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 572 | /* |
| 573 | * Holds a SamplingTimer associated with each kernel wakelock name being tracked. |
| 574 | */ |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 575 | private final HashMap<String, SamplingTimer> mKernelWakelockStats = new HashMap<>(); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 576 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 577 | public Map<String, ? extends Timer> getKernelWakelockStats() { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 578 | return mKernelWakelockStats; |
| 579 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 580 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 581 | String mLastWakeupReason = null; |
| 582 | long mLastWakeupUptimeMs = 0; |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 583 | private final HashMap<String, SamplingTimer> mWakeupReasonStats = new HashMap<>(); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 584 | |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 585 | public Map<String, ? extends Timer> getWakeupReasonStats() { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 586 | return mWakeupReasonStats; |
| 587 | } |
| 588 | |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 589 | @Override |
| 590 | public LongCounter getDischargeScreenOffCoulombCounter() { |
| 591 | return mDischargeScreenOffCounter; |
| 592 | } |
| 593 | |
| 594 | @Override |
| 595 | public LongCounter getDischargeCoulombCounter() { |
| 596 | return mDischargeCounter; |
| 597 | } |
| 598 | |
Adam Lesinski | f9b20a9 | 2016-06-17 17:30:01 -0700 | [diff] [blame] | 599 | @Override |
| 600 | public int getEstimatedBatteryCapacity() { |
| 601 | return mEstimatedBatteryCapacity; |
| 602 | } |
| 603 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 604 | public BatteryStatsImpl() { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 605 | this(new SystemClocks()); |
| 606 | } |
| 607 | |
| 608 | public BatteryStatsImpl(Clocks clocks) { |
| 609 | init(clocks); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 610 | mFile = null; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 611 | mCheckinFile = null; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 612 | mDailyFile = null; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 613 | mHandler = null; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 614 | mExternalSync = null; |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 615 | mPlatformIdleStateCallback = null; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 616 | clearHistoryLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 617 | } |
| 618 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 619 | private void init(Clocks clocks) { |
| 620 | mClocks = clocks; |
| 621 | mMobileNetworkStats = new NetworkStats[] { |
| 622 | new NetworkStats(mClocks.elapsedRealtime(), 50), |
| 623 | new NetworkStats(mClocks.elapsedRealtime(), 50), |
| 624 | new NetworkStats(mClocks.elapsedRealtime(), 50) |
| 625 | }; |
| 626 | mWifiNetworkStats = new NetworkStats[] { |
| 627 | new NetworkStats(mClocks.elapsedRealtime(), 50), |
| 628 | new NetworkStats(mClocks.elapsedRealtime(), 50), |
| 629 | new NetworkStats(mClocks.elapsedRealtime(), 50) |
| 630 | }; |
| 631 | } |
| 632 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 633 | public static interface TimeBaseObs { |
| 634 | void onTimeStarted(long elapsedRealtime, long baseUptime, long baseRealtime); |
| 635 | void onTimeStopped(long elapsedRealtime, long baseUptime, long baseRealtime); |
| 636 | } |
| 637 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 638 | // methods are protected not private to be VisibleForTesting |
| 639 | public static class TimeBase { |
| 640 | protected final ArrayList<TimeBaseObs> mObservers = new ArrayList<>(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 641 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 642 | protected long mUptime; |
| 643 | protected long mRealtime; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 644 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 645 | protected boolean mRunning; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 646 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 647 | protected long mPastUptime; |
| 648 | protected long mUptimeStart; |
| 649 | protected long mPastRealtime; |
| 650 | protected long mRealtimeStart; |
| 651 | protected long mUnpluggedUptime; |
| 652 | protected long mUnpluggedRealtime; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 653 | |
| 654 | public void dump(PrintWriter pw, String prefix) { |
| 655 | StringBuilder sb = new StringBuilder(128); |
| 656 | pw.print(prefix); pw.print("mRunning="); pw.println(mRunning); |
| 657 | sb.setLength(0); |
| 658 | sb.append(prefix); |
| 659 | sb.append("mUptime="); |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 660 | formatTimeMs(sb, mUptime / 1000); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 661 | pw.println(sb.toString()); |
| 662 | sb.setLength(0); |
| 663 | sb.append(prefix); |
| 664 | sb.append("mRealtime="); |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 665 | formatTimeMs(sb, mRealtime / 1000); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 666 | pw.println(sb.toString()); |
| 667 | sb.setLength(0); |
| 668 | sb.append(prefix); |
| 669 | sb.append("mPastUptime="); |
| 670 | formatTimeMs(sb, mPastUptime / 1000); sb.append("mUptimeStart="); |
| 671 | formatTimeMs(sb, mUptimeStart / 1000); |
| 672 | sb.append("mUnpluggedUptime="); formatTimeMs(sb, mUnpluggedUptime / 1000); |
| 673 | pw.println(sb.toString()); |
| 674 | sb.setLength(0); |
| 675 | sb.append(prefix); |
| 676 | sb.append("mPastRealtime="); |
| 677 | formatTimeMs(sb, mPastRealtime / 1000); sb.append("mRealtimeStart="); |
| 678 | formatTimeMs(sb, mRealtimeStart / 1000); |
| 679 | sb.append("mUnpluggedRealtime="); formatTimeMs(sb, mUnpluggedRealtime / 1000); |
| 680 | pw.println(sb.toString()); |
| 681 | } |
| 682 | |
| 683 | public void add(TimeBaseObs observer) { |
| 684 | mObservers.add(observer); |
| 685 | } |
| 686 | |
| 687 | public void remove(TimeBaseObs observer) { |
| 688 | if (!mObservers.remove(observer)) { |
| 689 | Slog.wtf(TAG, "Removed unknown observer: " + observer); |
| 690 | } |
| 691 | } |
| 692 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 693 | public boolean hasObserver(TimeBaseObs observer) { |
| 694 | return mObservers.contains(observer); |
| 695 | } |
| 696 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 697 | public void init(long uptime, long realtime) { |
| 698 | mRealtime = 0; |
| 699 | mUptime = 0; |
| 700 | mPastUptime = 0; |
| 701 | mPastRealtime = 0; |
| 702 | mUptimeStart = uptime; |
| 703 | mRealtimeStart = realtime; |
| 704 | mUnpluggedUptime = getUptime(mUptimeStart); |
| 705 | mUnpluggedRealtime = getRealtime(mRealtimeStart); |
| 706 | } |
| 707 | |
| 708 | public void reset(long uptime, long realtime) { |
| 709 | if (!mRunning) { |
| 710 | mPastUptime = 0; |
| 711 | mPastRealtime = 0; |
| 712 | } else { |
| 713 | mUptimeStart = uptime; |
| 714 | mRealtimeStart = realtime; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 715 | // TODO: Since mUptimeStart was just reset and we are running, getUptime will |
| 716 | // 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] | 717 | mUnpluggedUptime = getUptime(uptime); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 718 | // TODO: likewise. |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 719 | mUnpluggedRealtime = getRealtime(realtime); |
| 720 | } |
| 721 | } |
| 722 | |
| 723 | public long computeUptime(long curTime, int which) { |
| 724 | switch (which) { |
| 725 | case STATS_SINCE_CHARGED: |
| 726 | return mUptime + getUptime(curTime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 727 | case STATS_CURRENT: |
| 728 | return getUptime(curTime); |
| 729 | case STATS_SINCE_UNPLUGGED: |
| 730 | return getUptime(curTime) - mUnpluggedUptime; |
| 731 | } |
| 732 | return 0; |
| 733 | } |
| 734 | |
| 735 | public long computeRealtime(long curTime, int which) { |
| 736 | switch (which) { |
| 737 | case STATS_SINCE_CHARGED: |
| 738 | return mRealtime + getRealtime(curTime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 739 | case STATS_CURRENT: |
| 740 | return getRealtime(curTime); |
| 741 | case STATS_SINCE_UNPLUGGED: |
| 742 | return getRealtime(curTime) - mUnpluggedRealtime; |
| 743 | } |
| 744 | return 0; |
| 745 | } |
| 746 | |
| 747 | public long getUptime(long curTime) { |
| 748 | long time = mPastUptime; |
| 749 | if (mRunning) { |
| 750 | time += curTime - mUptimeStart; |
| 751 | } |
| 752 | return time; |
| 753 | } |
| 754 | |
| 755 | public long getRealtime(long curTime) { |
| 756 | long time = mPastRealtime; |
| 757 | if (mRunning) { |
| 758 | time += curTime - mRealtimeStart; |
| 759 | } |
| 760 | return time; |
| 761 | } |
| 762 | |
| 763 | public long getUptimeStart() { |
| 764 | return mUptimeStart; |
| 765 | } |
| 766 | |
| 767 | public long getRealtimeStart() { |
| 768 | return mRealtimeStart; |
| 769 | } |
| 770 | |
| 771 | public boolean isRunning() { |
| 772 | return mRunning; |
| 773 | } |
| 774 | |
| 775 | public boolean setRunning(boolean running, long uptime, long realtime) { |
| 776 | if (mRunning != running) { |
| 777 | mRunning = running; |
| 778 | if (running) { |
| 779 | mUptimeStart = uptime; |
| 780 | mRealtimeStart = realtime; |
| 781 | long batteryUptime = mUnpluggedUptime = getUptime(uptime); |
| 782 | long batteryRealtime = mUnpluggedRealtime = getRealtime(realtime); |
| 783 | |
| 784 | for (int i = mObservers.size() - 1; i >= 0; i--) { |
| 785 | mObservers.get(i).onTimeStarted(realtime, batteryUptime, batteryRealtime); |
| 786 | } |
| 787 | } else { |
| 788 | mPastUptime += uptime - mUptimeStart; |
| 789 | mPastRealtime += realtime - mRealtimeStart; |
| 790 | |
| 791 | long batteryUptime = getUptime(uptime); |
| 792 | long batteryRealtime = getRealtime(realtime); |
| 793 | |
| 794 | for (int i = mObservers.size() - 1; i >= 0; i--) { |
| 795 | mObservers.get(i).onTimeStopped(realtime, batteryUptime, batteryRealtime); |
| 796 | } |
| 797 | } |
| 798 | return true; |
| 799 | } |
| 800 | return false; |
| 801 | } |
| 802 | |
| 803 | public void readSummaryFromParcel(Parcel in) { |
| 804 | mUptime = in.readLong(); |
| 805 | mRealtime = in.readLong(); |
| 806 | } |
| 807 | |
| 808 | public void writeSummaryToParcel(Parcel out, long uptime, long realtime) { |
| 809 | out.writeLong(computeUptime(uptime, STATS_SINCE_CHARGED)); |
| 810 | out.writeLong(computeRealtime(realtime, STATS_SINCE_CHARGED)); |
| 811 | } |
| 812 | |
| 813 | public void readFromParcel(Parcel in) { |
| 814 | mRunning = false; |
| 815 | mUptime = in.readLong(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 816 | mPastUptime = in.readLong(); |
| 817 | mUptimeStart = in.readLong(); |
Dianne Hackborn | ef640cd | 2014-03-25 14:41:05 -0700 | [diff] [blame] | 818 | mRealtime = in.readLong(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 819 | mPastRealtime = in.readLong(); |
| 820 | mRealtimeStart = in.readLong(); |
| 821 | mUnpluggedUptime = in.readLong(); |
| 822 | mUnpluggedRealtime = in.readLong(); |
| 823 | } |
| 824 | |
| 825 | public void writeToParcel(Parcel out, long uptime, long realtime) { |
| 826 | final long runningUptime = getUptime(uptime); |
| 827 | final long runningRealtime = getRealtime(realtime); |
| 828 | out.writeLong(mUptime); |
| 829 | out.writeLong(runningUptime); |
| 830 | out.writeLong(mUptimeStart); |
Dianne Hackborn | ef640cd | 2014-03-25 14:41:05 -0700 | [diff] [blame] | 831 | out.writeLong(mRealtime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 832 | out.writeLong(runningRealtime); |
| 833 | out.writeLong(mRealtimeStart); |
| 834 | out.writeLong(mUnpluggedUptime); |
| 835 | out.writeLong(mUnpluggedRealtime); |
| 836 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 837 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 838 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 839 | /** |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 840 | * State for keeping track of counting information. |
| 841 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 842 | public static class Counter extends BatteryStats.Counter implements TimeBaseObs { |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 843 | final AtomicInteger mCount = new AtomicInteger(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 844 | final TimeBase mTimeBase; |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 845 | int mLoadedCount; |
| 846 | int mLastCount; |
| 847 | int mUnpluggedCount; |
| 848 | int mPluggedCount; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 849 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 850 | Counter(TimeBase timeBase, Parcel in) { |
| 851 | mTimeBase = timeBase; |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 852 | mPluggedCount = in.readInt(); |
| 853 | mCount.set(mPluggedCount); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 854 | mLoadedCount = in.readInt(); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 855 | mLastCount = 0; |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 856 | mUnpluggedCount = in.readInt(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 857 | timeBase.add(this); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 858 | } |
| 859 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 860 | Counter(TimeBase timeBase) { |
| 861 | mTimeBase = timeBase; |
| 862 | timeBase.add(this); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 863 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 864 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 865 | public void writeToParcel(Parcel out) { |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 866 | out.writeInt(mCount.get()); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 867 | out.writeInt(mLoadedCount); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 868 | out.writeInt(mUnpluggedCount); |
| 869 | } |
| 870 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 871 | public void onTimeStarted(long elapsedRealtime, long baseUptime, long baseRealtime) { |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 872 | mUnpluggedCount = mPluggedCount; |
| 873 | mCount.set(mPluggedCount); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 874 | } |
| 875 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 876 | public void onTimeStopped(long elapsedRealtime, long baseUptime, long baseRealtime) { |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 877 | mPluggedCount = mCount.get(); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 878 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 879 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 880 | /** |
| 881 | * Writes a possibly null Counter to a Parcel. |
| 882 | * |
| 883 | * @param out the Parcel to be written to. |
| 884 | * @param counter a Counter, or null. |
| 885 | */ |
| 886 | public static void writeCounterToParcel(Parcel out, Counter counter) { |
| 887 | if (counter == null) { |
| 888 | out.writeInt(0); // indicates null |
| 889 | return; |
| 890 | } |
| 891 | out.writeInt(1); // indicates non-null |
| 892 | |
| 893 | counter.writeToParcel(out); |
| 894 | } |
| 895 | |
| 896 | @Override |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 897 | public int getCountLocked(int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 898 | int val = mCount.get(); |
| 899 | if (which == STATS_SINCE_UNPLUGGED) { |
| 900 | val -= mUnpluggedCount; |
| 901 | } else if (which != STATS_SINCE_CHARGED) { |
| 902 | val -= mLoadedCount; |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 903 | } |
| 904 | |
| 905 | return val; |
| 906 | } |
| 907 | |
| 908 | public void logState(Printer pw, String prefix) { |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 909 | pw.println(prefix + "mCount=" + mCount.get() |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 910 | + " mLoadedCount=" + mLoadedCount + " mLastCount=" + mLastCount |
| 911 | + " mUnpluggedCount=" + mUnpluggedCount |
| 912 | + " mPluggedCount=" + mPluggedCount); |
| 913 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 914 | |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 915 | void stepAtomic() { |
| 916 | mCount.incrementAndGet(); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 917 | } |
| 918 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 919 | /** |
| 920 | * Clear state of this counter. |
| 921 | */ |
| 922 | void reset(boolean detachIfReset) { |
| 923 | mCount.set(0); |
| 924 | mLoadedCount = mLastCount = mPluggedCount = mUnpluggedCount = 0; |
| 925 | if (detachIfReset) { |
| 926 | detach(); |
| 927 | } |
| 928 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 929 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 930 | void detach() { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 931 | mTimeBase.remove(this); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 932 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 933 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 934 | void writeSummaryFromParcelLocked(Parcel out) { |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 935 | int count = mCount.get(); |
| 936 | out.writeInt(count); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 937 | } |
| 938 | |
| 939 | void readSummaryFromParcelLocked(Parcel in) { |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 940 | mLoadedCount = in.readInt(); |
| 941 | mCount.set(mLoadedCount); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 942 | mLastCount = 0; |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 943 | mUnpluggedCount = mPluggedCount = mLoadedCount; |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 944 | } |
| 945 | } |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 946 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 947 | public static class LongSamplingCounter extends LongCounter implements TimeBaseObs { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 948 | final TimeBase mTimeBase; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 949 | long mCount; |
| 950 | long mLoadedCount; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 951 | long mUnpluggedCount; |
| 952 | long mPluggedCount; |
| 953 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 954 | LongSamplingCounter(TimeBase timeBase, Parcel in) { |
| 955 | mTimeBase = timeBase; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 956 | mPluggedCount = in.readLong(); |
| 957 | mCount = mPluggedCount; |
| 958 | mLoadedCount = in.readLong(); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 959 | mUnpluggedCount = in.readLong(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 960 | timeBase.add(this); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 961 | } |
| 962 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 963 | LongSamplingCounter(TimeBase timeBase) { |
| 964 | mTimeBase = timeBase; |
| 965 | timeBase.add(this); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 966 | } |
| 967 | |
| 968 | public void writeToParcel(Parcel out) { |
| 969 | out.writeLong(mCount); |
| 970 | out.writeLong(mLoadedCount); |
| 971 | out.writeLong(mUnpluggedCount); |
| 972 | } |
| 973 | |
| 974 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 975 | public void onTimeStarted(long elapsedRealtime, long baseUptime, long baseRealtime) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 976 | mUnpluggedCount = mPluggedCount; |
| 977 | mCount = mPluggedCount; |
| 978 | } |
| 979 | |
| 980 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 981 | public void onTimeStopped(long elapsedRealtime, long baseUptime, long baseRealtime) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 982 | mPluggedCount = mCount; |
| 983 | } |
| 984 | |
| 985 | public long getCountLocked(int which) { |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 986 | long val = mTimeBase.isRunning() ? mCount : mPluggedCount; |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 987 | if (which == STATS_SINCE_UNPLUGGED) { |
| 988 | val -= mUnpluggedCount; |
| 989 | } else if (which != STATS_SINCE_CHARGED) { |
| 990 | val -= mLoadedCount; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 991 | } |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 992 | return val; |
| 993 | } |
| 994 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 995 | @Override |
| 996 | public void logState(Printer pw, String prefix) { |
| 997 | pw.println(prefix + "mCount=" + mCount |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 998 | + " mLoadedCount=" + mLoadedCount |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 999 | + " mUnpluggedCount=" + mUnpluggedCount |
| 1000 | + " mPluggedCount=" + mPluggedCount); |
| 1001 | } |
| 1002 | |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 1003 | void addCountLocked(long count) { |
| 1004 | mCount += count; |
| 1005 | } |
| 1006 | |
| 1007 | /** |
| 1008 | * Clear state of this counter. |
| 1009 | */ |
| 1010 | void reset(boolean detachIfReset) { |
| 1011 | mCount = 0; |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 1012 | mLoadedCount = mPluggedCount = mUnpluggedCount = 0; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 1013 | if (detachIfReset) { |
| 1014 | detach(); |
| 1015 | } |
| 1016 | } |
| 1017 | |
| 1018 | void detach() { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1019 | mTimeBase.remove(this); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 1020 | } |
| 1021 | |
| 1022 | void writeSummaryFromParcelLocked(Parcel out) { |
| 1023 | out.writeLong(mCount); |
| 1024 | } |
| 1025 | |
| 1026 | void readSummaryFromParcelLocked(Parcel in) { |
| 1027 | mLoadedCount = in.readLong(); |
| 1028 | mCount = mLoadedCount; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 1029 | mUnpluggedCount = mPluggedCount = mLoadedCount; |
| 1030 | } |
| 1031 | } |
| 1032 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1033 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1034 | * State for keeping track of timing information. |
| 1035 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1036 | public static abstract class Timer extends BatteryStats.Timer implements TimeBaseObs { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1037 | protected final Clocks mClocks; |
| 1038 | protected final int mType; |
| 1039 | protected final TimeBase mTimeBase; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1040 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1041 | protected int mCount; |
| 1042 | protected int mLoadedCount; |
| 1043 | protected int mLastCount; |
| 1044 | protected int mUnpluggedCount; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1045 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1046 | // Times are in microseconds for better accuracy when dividing by the |
| 1047 | // lock count, and are in "battery realtime" units. |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1048 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1049 | /** |
| 1050 | * The total time we have accumulated since the start of the original |
| 1051 | * boot, to the last time something interesting happened in the |
| 1052 | * current run. |
| 1053 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1054 | protected long mTotalTime; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1055 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1056 | /** |
| 1057 | * The total time we loaded for the previous runs. Subtract this from |
| 1058 | * mTotalTime to find the time for the current run of the system. |
| 1059 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1060 | protected long mLoadedTime; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1061 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1062 | /** |
| 1063 | * The run time of the last run of the system, as loaded from the |
| 1064 | * saved data. |
| 1065 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1066 | protected long mLastTime; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1067 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1068 | /** |
| 1069 | * The value of mTotalTime when unplug() was last called. Subtract |
| 1070 | * this from mTotalTime to find the time since the last unplug from |
| 1071 | * power. |
| 1072 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1073 | protected long mUnpluggedTime; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1074 | |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 1075 | /** |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 1076 | * The total time this timer has been running until the latest mark has been set. |
| 1077 | * Subtract this from mTotalTime to get the time spent running since the mark was set. |
| 1078 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1079 | protected long mTimeBeforeMark; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 1080 | |
| 1081 | /** |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 1082 | * Constructs from a parcel. |
| 1083 | * @param type |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1084 | * @param timeBase |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 1085 | * @param in |
| 1086 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1087 | public Timer(Clocks clocks, int type, TimeBase timeBase, Parcel in) { |
| 1088 | mClocks = clocks; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1089 | mType = type; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1090 | mTimeBase = timeBase; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1091 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1092 | mCount = in.readInt(); |
| 1093 | mLoadedCount = in.readInt(); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 1094 | mLastCount = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1095 | mUnpluggedCount = in.readInt(); |
| 1096 | mTotalTime = in.readLong(); |
| 1097 | mLoadedTime = in.readLong(); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 1098 | mLastTime = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1099 | mUnpluggedTime = in.readLong(); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 1100 | mTimeBeforeMark = in.readLong(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1101 | timeBase.add(this); |
Dianne Hackborn | 2932513 | 2014-05-21 15:01:03 -0700 | [diff] [blame] | 1102 | 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] | 1103 | } |
| 1104 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1105 | public Timer(Clocks clocks, int type, TimeBase timeBase) { |
| 1106 | mClocks = clocks; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1107 | mType = type; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1108 | mTimeBase = timeBase; |
| 1109 | timeBase.add(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1110 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1111 | |
| 1112 | protected abstract long computeRunTimeLocked(long curBatteryRealtime); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1113 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1114 | protected abstract int computeCurrentCountLocked(); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1115 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1116 | /** |
| 1117 | * Clear state of this timer. Returns true if the timer is inactive |
| 1118 | * so can be completely dropped. |
| 1119 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1120 | public boolean reset(boolean detachIfReset) { |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 1121 | mTotalTime = mLoadedTime = mLastTime = mTimeBeforeMark = 0; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1122 | mCount = mLoadedCount = mLastCount = 0; |
| 1123 | if (detachIfReset) { |
| 1124 | detach(); |
| 1125 | } |
| 1126 | return true; |
| 1127 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1128 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1129 | public void detach() { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1130 | mTimeBase.remove(this); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1131 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1132 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1133 | public void writeToParcel(Parcel out, long elapsedRealtimeUs) { |
Dianne Hackborn | 2932513 | 2014-05-21 15:01:03 -0700 | [diff] [blame] | 1134 | if (DEBUG) Log.i(TAG, "**** WRITING TIMER #" + mType + ": mTotalTime=" |
| 1135 | + computeRunTimeLocked(mTimeBase.getRealtime(elapsedRealtimeUs))); |
Adam Lesinski | 98f0d46 | 2016-04-19 16:46:20 -0700 | [diff] [blame] | 1136 | out.writeInt(computeCurrentCountLocked()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1137 | out.writeInt(mLoadedCount); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1138 | out.writeInt(mUnpluggedCount); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1139 | out.writeLong(computeRunTimeLocked(mTimeBase.getRealtime(elapsedRealtimeUs))); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1140 | out.writeLong(mLoadedTime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1141 | out.writeLong(mUnpluggedTime); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 1142 | out.writeLong(mTimeBeforeMark); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1143 | } |
| 1144 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 1145 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1146 | public void onTimeStarted(long elapsedRealtime, long timeBaseUptime, long baseRealtime) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1147 | if (DEBUG && mType < 0) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1148 | Log.v(TAG, "unplug #" + mType + ": realtime=" + baseRealtime |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1149 | + " old mUnpluggedTime=" + mUnpluggedTime |
| 1150 | + " old mUnpluggedCount=" + mUnpluggedCount); |
| 1151 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1152 | mUnpluggedTime = computeRunTimeLocked(baseRealtime); |
Adam Lesinski | 98f0d46 | 2016-04-19 16:46:20 -0700 | [diff] [blame] | 1153 | mUnpluggedCount = computeCurrentCountLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1154 | if (DEBUG && mType < 0) { |
| 1155 | Log.v(TAG, "unplug #" + mType |
| 1156 | + ": new mUnpluggedTime=" + mUnpluggedTime |
| 1157 | + " new mUnpluggedCount=" + mUnpluggedCount); |
| 1158 | } |
| 1159 | } |
| 1160 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 1161 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1162 | public void onTimeStopped(long elapsedRealtime, long baseUptime, long baseRealtime) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1163 | if (DEBUG && mType < 0) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1164 | Log.v(TAG, "plug #" + mType + ": realtime=" + baseRealtime |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1165 | + " old mTotalTime=" + mTotalTime); |
| 1166 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1167 | mTotalTime = computeRunTimeLocked(baseRealtime); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1168 | mCount = computeCurrentCountLocked(); |
| 1169 | if (DEBUG && mType < 0) { |
| 1170 | Log.v(TAG, "plug #" + mType |
| 1171 | + ": new mTotalTime=" + mTotalTime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1172 | } |
| 1173 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1174 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1175 | /** |
| 1176 | * Writes a possibly null Timer to a Parcel. |
| 1177 | * |
| 1178 | * @param out the Parcel to be written to. |
| 1179 | * @param timer a Timer, or null. |
| 1180 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1181 | 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] | 1182 | if (timer == null) { |
| 1183 | out.writeInt(0); // indicates null |
| 1184 | return; |
| 1185 | } |
| 1186 | out.writeInt(1); // indicates non-null |
| 1187 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1188 | timer.writeToParcel(out, elapsedRealtimeUs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1189 | } |
| 1190 | |
| 1191 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1192 | public long getTotalTimeLocked(long elapsedRealtimeUs, int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 1193 | long val = computeRunTimeLocked(mTimeBase.getRealtime(elapsedRealtimeUs)); |
| 1194 | if (which == STATS_SINCE_UNPLUGGED) { |
| 1195 | val -= mUnpluggedTime; |
| 1196 | } else if (which != STATS_SINCE_CHARGED) { |
| 1197 | val -= mLoadedTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1198 | } |
| 1199 | |
| 1200 | return val; |
| 1201 | } |
| 1202 | |
| 1203 | @Override |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1204 | public int getCountLocked(int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 1205 | int val = computeCurrentCountLocked(); |
| 1206 | if (which == STATS_SINCE_UNPLUGGED) { |
| 1207 | val -= mUnpluggedCount; |
| 1208 | } else if (which != STATS_SINCE_CHARGED) { |
| 1209 | val -= mLoadedCount; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1210 | } |
| 1211 | |
| 1212 | return val; |
| 1213 | } |
| 1214 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 1215 | @Override |
| 1216 | public long getTimeSinceMarkLocked(long elapsedRealtimeUs) { |
| 1217 | long val = computeRunTimeLocked(mTimeBase.getRealtime(elapsedRealtimeUs)); |
| 1218 | return val - mTimeBeforeMark; |
| 1219 | } |
| 1220 | |
| 1221 | @Override |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 1222 | public void logState(Printer pw, String prefix) { |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 1223 | pw.println(prefix + "mCount=" + mCount |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1224 | + " mLoadedCount=" + mLoadedCount + " mLastCount=" + mLastCount |
| 1225 | + " mUnpluggedCount=" + mUnpluggedCount); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 1226 | pw.println(prefix + "mTotalTime=" + mTotalTime |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1227 | + " mLoadedTime=" + mLoadedTime); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 1228 | pw.println(prefix + "mLastTime=" + mLastTime |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1229 | + " mUnpluggedTime=" + mUnpluggedTime); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1230 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1231 | |
| 1232 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1233 | public void writeSummaryFromParcelLocked(Parcel out, long elapsedRealtimeUs) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1234 | long runTime = computeRunTimeLocked(mTimeBase.getRealtime(elapsedRealtimeUs)); |
| 1235 | out.writeLong(runTime); |
Adam Lesinski | 98f0d46 | 2016-04-19 16:46:20 -0700 | [diff] [blame] | 1236 | out.writeInt(computeCurrentCountLocked()); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1237 | } |
| 1238 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1239 | public void readSummaryFromParcelLocked(Parcel in) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1240 | // Multiply by 1000 for backwards compatibility |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1241 | mTotalTime = mLoadedTime = in.readLong(); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 1242 | mLastTime = 0; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1243 | mUnpluggedTime = mTotalTime; |
| 1244 | mCount = mLoadedCount = in.readInt(); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 1245 | mLastCount = 0; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1246 | mUnpluggedCount = mCount; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 1247 | |
| 1248 | // When reading the summary, we set the mark to be the latest information. |
| 1249 | mTimeBeforeMark = mTotalTime; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1250 | } |
| 1251 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1252 | |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 1253 | /** |
| 1254 | * A counter meant to accept monotonically increasing values to its {@link #update(long, int)} |
| 1255 | * method. The state of the timer according to its {@link TimeBase} will determine how much |
| 1256 | * of the value is recorded. |
| 1257 | * |
| 1258 | * If the value being recorded resets, {@link #endSample()} can be called in order to |
| 1259 | * account for the change. If the value passed in to {@link #update(long, int)} decreased |
| 1260 | * between calls, the {@link #endSample()} is automatically called and the new value is |
| 1261 | * expected to increase monotonically from that point on. |
| 1262 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1263 | public static class SamplingTimer extends Timer { |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1264 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1265 | /** |
| 1266 | * The most recent reported count from /proc/wakelocks. |
| 1267 | */ |
| 1268 | int mCurrentReportedCount; |
| 1269 | |
| 1270 | /** |
| 1271 | * The reported count from /proc/wakelocks when unplug() was last |
| 1272 | * called. |
| 1273 | */ |
| 1274 | int mUnpluggedReportedCount; |
| 1275 | |
| 1276 | /** |
| 1277 | * The most recent reported total_time from /proc/wakelocks. |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1278 | */ |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1279 | long mCurrentReportedTotalTime; |
| 1280 | |
| 1281 | |
| 1282 | /** |
| 1283 | * The reported total_time from /proc/wakelocks when unplug() was last |
| 1284 | * called. |
| 1285 | */ |
| 1286 | long mUnpluggedReportedTotalTime; |
| 1287 | |
| 1288 | /** |
| 1289 | * Whether we are currently in a discharge cycle. |
| 1290 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1291 | boolean mTimeBaseRunning; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1292 | |
| 1293 | /** |
| 1294 | * Whether we are currently recording reported values. |
| 1295 | */ |
| 1296 | boolean mTrackingReportedValues; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1297 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1298 | /* |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1299 | * A sequence counter, incremented once for each update of the stats. |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1300 | */ |
| 1301 | int mUpdateVersion; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1302 | |
Adam Lesinski | 98f0d46 | 2016-04-19 16:46:20 -0700 | [diff] [blame] | 1303 | @VisibleForTesting |
| 1304 | public SamplingTimer(Clocks clocks, TimeBase timeBase, Parcel in) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1305 | super(clocks, 0, timeBase, in); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1306 | mCurrentReportedCount = in.readInt(); |
| 1307 | mUnpluggedReportedCount = in.readInt(); |
| 1308 | mCurrentReportedTotalTime = in.readLong(); |
| 1309 | mUnpluggedReportedTotalTime = in.readLong(); |
| 1310 | mTrackingReportedValues = in.readInt() == 1; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1311 | mTimeBaseRunning = timeBase.isRunning(); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1312 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1313 | |
Adam Lesinski | 98f0d46 | 2016-04-19 16:46:20 -0700 | [diff] [blame] | 1314 | @VisibleForTesting |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 1315 | public SamplingTimer(Clocks clocks, TimeBase timeBase) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1316 | super(clocks, 0, timeBase); |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 1317 | mTrackingReportedValues = false; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1318 | mTimeBaseRunning = timeBase.isRunning(); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1319 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1320 | |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 1321 | /** |
| 1322 | * Ends the current sample, allowing subsequent values to {@link #update(long, int)} to |
| 1323 | * be less than the values used for a previous invocation. |
| 1324 | */ |
| 1325 | public void endSample() { |
| 1326 | mTotalTime = computeRunTimeLocked(0 /* unused by us */); |
| 1327 | mCount = computeCurrentCountLocked(); |
| 1328 | mUnpluggedReportedTotalTime = mCurrentReportedTotalTime = 0; |
| 1329 | mUnpluggedReportedCount = mCurrentReportedCount = 0; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 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 | public void setUpdateVersion(int version) { |
| 1333 | mUpdateVersion = version; |
| 1334 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1335 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1336 | public int getUpdateVersion() { |
| 1337 | return mUpdateVersion; |
| 1338 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1339 | |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 1340 | /** |
| 1341 | * Updates the current recorded values. These are meant to be monotonically increasing |
| 1342 | * and cumulative. If you are dealing with deltas, use {@link #add(long, int)}. |
| 1343 | * |
| 1344 | * If the values being recorded have been reset, the monotonically increasing requirement |
| 1345 | * will be broken. In this case, {@link #endSample()} is automatically called and |
| 1346 | * the total value of totalTime and count are recorded, starting a new monotonically |
| 1347 | * increasing sample. |
| 1348 | * |
| 1349 | * @param totalTime total time of sample in microseconds. |
| 1350 | * @param count total number of times the event being sampled occurred. |
| 1351 | */ |
| 1352 | public void update(long totalTime, int count) { |
| 1353 | if (mTimeBaseRunning && !mTrackingReportedValues) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1354 | // Updating the reported value for the first time. |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 1355 | mUnpluggedReportedTotalTime = totalTime; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1356 | mUnpluggedReportedCount = count; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1357 | } |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 1358 | |
| 1359 | mTrackingReportedValues = true; |
| 1360 | |
| 1361 | if (totalTime < mCurrentReportedTotalTime || count < mCurrentReportedCount) { |
| 1362 | endSample(); |
| 1363 | } |
| 1364 | |
| 1365 | mCurrentReportedTotalTime = totalTime; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1366 | mCurrentReportedCount = count; |
| 1367 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1368 | |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 1369 | /** |
| 1370 | * Adds deltaTime and deltaCount to the current sample. |
| 1371 | * |
| 1372 | * @param deltaTime additional time recorded since the last sampled event, in microseconds. |
| 1373 | * @param deltaCount additional number of times the event being sampled occurred. |
| 1374 | */ |
| 1375 | public void add(long deltaTime, int deltaCount) { |
| 1376 | update(mCurrentReportedTotalTime + deltaTime, mCurrentReportedCount + deltaCount); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 1377 | } |
| 1378 | |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 1379 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1380 | public void onTimeStarted(long elapsedRealtime, long baseUptime, long baseRealtime) { |
| 1381 | super.onTimeStarted(elapsedRealtime, baseUptime, baseRealtime); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1382 | if (mTrackingReportedValues) { |
| 1383 | mUnpluggedReportedTotalTime = mCurrentReportedTotalTime; |
| 1384 | mUnpluggedReportedCount = mCurrentReportedCount; |
| 1385 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1386 | mTimeBaseRunning = true; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1387 | } |
| 1388 | |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 1389 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1390 | public void onTimeStopped(long elapsedRealtime, long baseUptime, long baseRealtime) { |
| 1391 | super.onTimeStopped(elapsedRealtime, baseUptime, baseRealtime); |
| 1392 | mTimeBaseRunning = false; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1393 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1394 | |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 1395 | @Override |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1396 | public void logState(Printer pw, String prefix) { |
| 1397 | super.logState(pw, prefix); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1398 | pw.println(prefix + "mCurrentReportedCount=" + mCurrentReportedCount |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1399 | + " mUnpluggedReportedCount=" + mUnpluggedReportedCount |
| 1400 | + " mCurrentReportedTotalTime=" + mCurrentReportedTotalTime |
| 1401 | + " mUnpluggedReportedTotalTime=" + mUnpluggedReportedTotalTime); |
| 1402 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1403 | |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 1404 | @Override |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1405 | protected long computeRunTimeLocked(long curBatteryRealtime) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1406 | return mTotalTime + (mTimeBaseRunning && mTrackingReportedValues |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1407 | ? mCurrentReportedTotalTime - mUnpluggedReportedTotalTime : 0); |
| 1408 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1409 | |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 1410 | @Override |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1411 | protected int computeCurrentCountLocked() { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1412 | return mCount + (mTimeBaseRunning && mTrackingReportedValues |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1413 | ? mCurrentReportedCount - mUnpluggedReportedCount : 0); |
| 1414 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1415 | |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 1416 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1417 | public void writeToParcel(Parcel out, long elapsedRealtimeUs) { |
| 1418 | super.writeToParcel(out, elapsedRealtimeUs); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1419 | out.writeInt(mCurrentReportedCount); |
| 1420 | out.writeInt(mUnpluggedReportedCount); |
| 1421 | out.writeLong(mCurrentReportedTotalTime); |
| 1422 | out.writeLong(mUnpluggedReportedTotalTime); |
| 1423 | out.writeInt(mTrackingReportedValues ? 1 : 0); |
| 1424 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1425 | |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 1426 | @Override |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1427 | public boolean reset(boolean detachIfReset) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1428 | super.reset(detachIfReset); |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 1429 | mTrackingReportedValues = false; |
| 1430 | mUnpluggedReportedTotalTime = 0; |
| 1431 | mUnpluggedReportedCount = 0; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1432 | return true; |
| 1433 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1434 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1435 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1436 | /** |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1437 | * A timer that increments in batches. It does not run for durations, but just jumps |
| 1438 | * for a pre-determined amount. |
| 1439 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1440 | public static class BatchTimer extends Timer { |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1441 | final Uid mUid; |
| 1442 | |
| 1443 | /** |
| 1444 | * The last time at which we updated the timer. This is in elapsed realtime microseconds. |
| 1445 | */ |
| 1446 | long mLastAddedTime; |
| 1447 | |
| 1448 | /** |
| 1449 | * The last duration that we added to the timer. This is in microseconds. |
| 1450 | */ |
| 1451 | long mLastAddedDuration; |
| 1452 | |
| 1453 | /** |
| 1454 | * Whether we are currently in a discharge cycle. |
| 1455 | */ |
| 1456 | boolean mInDischarge; |
| 1457 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1458 | BatchTimer(Clocks clocks, Uid uid, int type, TimeBase timeBase, Parcel in) { |
| 1459 | super(clocks, type, timeBase, in); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1460 | mUid = uid; |
| 1461 | mLastAddedTime = in.readLong(); |
| 1462 | mLastAddedDuration = in.readLong(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1463 | mInDischarge = timeBase.isRunning(); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1464 | } |
| 1465 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1466 | BatchTimer(Clocks clocks, Uid uid, int type, TimeBase timeBase) { |
| 1467 | super(clocks, type, timeBase); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1468 | mUid = uid; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1469 | mInDischarge = timeBase.isRunning(); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1470 | } |
| 1471 | |
| 1472 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1473 | public void writeToParcel(Parcel out, long elapsedRealtimeUs) { |
| 1474 | super.writeToParcel(out, elapsedRealtimeUs); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1475 | out.writeLong(mLastAddedTime); |
| 1476 | out.writeLong(mLastAddedDuration); |
| 1477 | } |
| 1478 | |
| 1479 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1480 | public void onTimeStopped(long elapsedRealtime, long baseUptime, long baseRealtime) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1481 | recomputeLastDuration(mClocks.elapsedRealtime() * 1000, false); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1482 | mInDischarge = false; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1483 | super.onTimeStopped(elapsedRealtime, baseUptime, baseRealtime); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1484 | } |
| 1485 | |
| 1486 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1487 | public void onTimeStarted(long elapsedRealtime, long baseUptime, long baseRealtime) { |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1488 | recomputeLastDuration(elapsedRealtime, false); |
| 1489 | mInDischarge = true; |
| 1490 | // If we are still within the last added duration, then re-added whatever remains. |
| 1491 | if (mLastAddedTime == elapsedRealtime) { |
| 1492 | mTotalTime += mLastAddedDuration; |
| 1493 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1494 | super.onTimeStarted(elapsedRealtime, baseUptime, baseRealtime); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1495 | } |
| 1496 | |
| 1497 | @Override |
| 1498 | public void logState(Printer pw, String prefix) { |
| 1499 | super.logState(pw, prefix); |
| 1500 | pw.println(prefix + "mLastAddedTime=" + mLastAddedTime |
| 1501 | + " mLastAddedDuration=" + mLastAddedDuration); |
| 1502 | } |
| 1503 | |
| 1504 | private long computeOverage(long curTime) { |
| 1505 | if (mLastAddedTime > 0) { |
| 1506 | return mLastTime + mLastAddedDuration - curTime; |
| 1507 | } |
| 1508 | return 0; |
| 1509 | } |
| 1510 | |
| 1511 | private void recomputeLastDuration(long curTime, boolean abort) { |
| 1512 | final long overage = computeOverage(curTime); |
| 1513 | if (overage > 0) { |
| 1514 | // Aborting before the duration ran out -- roll back the remaining |
| 1515 | // duration. Only do this if currently discharging; otherwise we didn't |
| 1516 | // actually add the time. |
| 1517 | if (mInDischarge) { |
| 1518 | mTotalTime -= overage; |
| 1519 | } |
| 1520 | if (abort) { |
| 1521 | mLastAddedTime = 0; |
| 1522 | } else { |
| 1523 | mLastAddedTime = curTime; |
| 1524 | mLastAddedDuration -= overage; |
| 1525 | } |
| 1526 | } |
| 1527 | } |
| 1528 | |
| 1529 | public void addDuration(BatteryStatsImpl stats, long durationMillis) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1530 | final long now = mClocks.elapsedRealtime() * 1000; |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1531 | recomputeLastDuration(now, true); |
| 1532 | mLastAddedTime = now; |
| 1533 | mLastAddedDuration = durationMillis * 1000; |
| 1534 | if (mInDischarge) { |
| 1535 | mTotalTime += mLastAddedDuration; |
| 1536 | mCount++; |
| 1537 | } |
| 1538 | } |
| 1539 | |
| 1540 | public void abortLastDuration(BatteryStatsImpl stats) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1541 | final long now = mClocks.elapsedRealtime() * 1000; |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1542 | recomputeLastDuration(now, true); |
| 1543 | } |
| 1544 | |
| 1545 | @Override |
| 1546 | protected int computeCurrentCountLocked() { |
| 1547 | return mCount; |
| 1548 | } |
| 1549 | |
| 1550 | @Override |
| 1551 | protected long computeRunTimeLocked(long curBatteryRealtime) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1552 | final long overage = computeOverage(mClocks.elapsedRealtime() * 1000); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1553 | if (overage > 0) { |
| 1554 | return mTotalTime = overage; |
| 1555 | } |
| 1556 | return mTotalTime; |
| 1557 | } |
| 1558 | |
| 1559 | @Override |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1560 | public boolean reset(boolean detachIfReset) { |
| 1561 | final long now = mClocks.elapsedRealtime() * 1000; |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1562 | recomputeLastDuration(now, true); |
| 1563 | boolean stillActive = mLastAddedTime == now; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1564 | super.reset(!stillActive && detachIfReset); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1565 | return !stillActive; |
| 1566 | } |
| 1567 | } |
| 1568 | |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 1569 | |
| 1570 | /** |
| 1571 | * A StopwatchTimer that also tracks the total and max individual |
| 1572 | * time spent active according to the given timebase. Whereas |
| 1573 | * StopwatchTimer apportions the time amongst all in the pool, |
| 1574 | * the total and max durations are not apportioned. |
| 1575 | */ |
| 1576 | public static class DurationTimer extends StopwatchTimer { |
| 1577 | /** |
| 1578 | * The time (in ms) that the timer was last acquired or the time base |
| 1579 | * last (re-)started. Increasing the nesting depth does not reset this time. |
| 1580 | * |
| 1581 | * -1 if the timer is currently not running or the time base is not running. |
| 1582 | * |
| 1583 | * If written to a parcel, the start time is reset, as is mNesting in the base class |
| 1584 | * StopwatchTimer. |
| 1585 | */ |
| 1586 | long mStartTimeMs = -1; |
| 1587 | |
| 1588 | /** |
| 1589 | * The longest time period (in ms) that the timer has been active. |
| 1590 | */ |
| 1591 | long mMaxDurationMs; |
| 1592 | |
| 1593 | /** |
| 1594 | * The total time (in ms) that that the timer has been active since reset(). |
| 1595 | */ |
| 1596 | long mCurrentDurationMs; |
| 1597 | |
| 1598 | public DurationTimer(Clocks clocks, Uid uid, int type, ArrayList<StopwatchTimer> timerPool, |
| 1599 | TimeBase timeBase, Parcel in) { |
| 1600 | super(clocks, uid, type, timerPool, timeBase, in); |
| 1601 | mMaxDurationMs = in.readLong(); |
| 1602 | } |
| 1603 | |
| 1604 | public DurationTimer(Clocks clocks, Uid uid, int type, ArrayList<StopwatchTimer> timerPool, |
| 1605 | TimeBase timeBase) { |
| 1606 | super(clocks, uid, type, timerPool, timeBase); |
| 1607 | } |
| 1608 | |
| 1609 | @Override |
| 1610 | public void writeToParcel(Parcel out, long elapsedRealtimeUs) { |
| 1611 | super.writeToParcel(out, elapsedRealtimeUs); |
Kweku Adams | 47db5a8 | 2016-12-09 19:04:50 -0800 | [diff] [blame] | 1612 | out.writeLong(getMaxDurationMsLocked(elapsedRealtimeUs / 1000)); |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 1613 | } |
| 1614 | |
| 1615 | /** |
| 1616 | * Write the summary to the parcel. |
| 1617 | * |
| 1618 | * Since the time base is probably meaningless after we come back, reading |
| 1619 | * from this will have the effect of stopping the timer. So here all we write |
| 1620 | * is the max duration. |
| 1621 | */ |
| 1622 | @Override |
| 1623 | public void writeSummaryFromParcelLocked(Parcel out, long elapsedRealtimeUs) { |
| 1624 | super.writeSummaryFromParcelLocked(out, elapsedRealtimeUs); |
Kweku Adams | 47db5a8 | 2016-12-09 19:04:50 -0800 | [diff] [blame] | 1625 | out.writeLong(getMaxDurationMsLocked(elapsedRealtimeUs / 1000)); |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 1626 | } |
| 1627 | |
| 1628 | /** |
| 1629 | * Read the summary parcel. |
| 1630 | * |
| 1631 | * Has the side effect of stopping the timer. |
| 1632 | */ |
| 1633 | @Override |
| 1634 | public void readSummaryFromParcelLocked(Parcel in) { |
| 1635 | super.readSummaryFromParcelLocked(in); |
| 1636 | mMaxDurationMs = in.readLong(); |
| 1637 | mStartTimeMs = -1; |
| 1638 | mCurrentDurationMs = 0; |
| 1639 | } |
| 1640 | |
| 1641 | /** |
| 1642 | * The TimeBase time started (again). |
| 1643 | * |
| 1644 | * If the timer is also running, store the start time. |
| 1645 | */ |
| 1646 | public void onTimeStarted(long elapsedRealtimeUs, long baseUptime, long baseRealtime) { |
| 1647 | super.onTimeStarted(elapsedRealtimeUs, baseUptime, baseRealtime); |
| 1648 | if (mNesting > 0) { |
Kweku Adams | 47db5a8 | 2016-12-09 19:04:50 -0800 | [diff] [blame] | 1649 | mStartTimeMs = baseRealtime / 1000; |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 1650 | } |
| 1651 | } |
| 1652 | |
| 1653 | /** |
| 1654 | * The TimeBase stopped running. |
| 1655 | * |
| 1656 | * If the timer is running, add the duration into mCurrentDurationMs. |
| 1657 | */ |
| 1658 | @Override |
Kweku Adams | 47db5a8 | 2016-12-09 19:04:50 -0800 | [diff] [blame] | 1659 | public void onTimeStopped(long elapsedRealtimeUs, long baseUptime, long baseRealtimeUs) { |
| 1660 | super.onTimeStopped(elapsedRealtimeUs, baseUptime, baseRealtimeUs); |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 1661 | if (mNesting > 0) { |
Kweku Adams | 47db5a8 | 2016-12-09 19:04:50 -0800 | [diff] [blame] | 1662 | // baseRealtimeUs has already been converted to the timebase's realtime. |
| 1663 | mCurrentDurationMs += (baseRealtimeUs / 1000) - mStartTimeMs; |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 1664 | } |
| 1665 | mStartTimeMs = -1; |
| 1666 | } |
| 1667 | |
| 1668 | @Override |
| 1669 | public void logState(Printer pw, String prefix) { |
| 1670 | super.logState(pw, prefix); |
| 1671 | } |
| 1672 | |
| 1673 | @Override |
| 1674 | public void startRunningLocked(long elapsedRealtimeMs) { |
| 1675 | super.startRunningLocked(elapsedRealtimeMs); |
| 1676 | if (mNesting == 1 && mTimeBase.isRunning()) { |
| 1677 | // Just started |
Kweku Adams | 47db5a8 | 2016-12-09 19:04:50 -0800 | [diff] [blame] | 1678 | mStartTimeMs = mTimeBase.getRealtime(elapsedRealtimeMs * 1000) / 1000; |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 1679 | } |
| 1680 | } |
| 1681 | |
| 1682 | /** |
| 1683 | * Decrements the mNesting ref-count on this timer. |
| 1684 | * |
| 1685 | * If it actually stopped (mNesting went to 0), then possibly update |
| 1686 | * mMaxDuration if the current duration was the longest ever. |
| 1687 | */ |
| 1688 | @Override |
| 1689 | public void stopRunningLocked(long elapsedRealtimeMs) { |
Kweku Adams | 47db5a8 | 2016-12-09 19:04:50 -0800 | [diff] [blame] | 1690 | if (mNesting == 1) { |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 1691 | final long durationMs = getCurrentDurationMsLocked(elapsedRealtimeMs); |
| 1692 | if (durationMs > mMaxDurationMs) { |
| 1693 | mMaxDurationMs = durationMs; |
| 1694 | } |
| 1695 | mStartTimeMs = -1; |
| 1696 | mCurrentDurationMs = 0; |
| 1697 | } |
Kweku Adams | 47db5a8 | 2016-12-09 19:04:50 -0800 | [diff] [blame] | 1698 | // super method decrements mNesting, which getCurrentDurationMsLocked relies on, |
| 1699 | // so call super.stopRunningLocked after calling getCurrentDurationMsLocked. |
| 1700 | super.stopRunningLocked(elapsedRealtimeMs); |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 1701 | } |
| 1702 | |
| 1703 | @Override |
| 1704 | public boolean reset(boolean detachIfReset) { |
| 1705 | boolean result = super.reset(detachIfReset); |
| 1706 | mMaxDurationMs = 0; |
| 1707 | mCurrentDurationMs = 0; |
| 1708 | if (mNesting > 0) { |
| 1709 | mStartTimeMs = mTimeBase.getRealtime(mClocks.elapsedRealtime()*1000) / 1000; |
| 1710 | } else { |
| 1711 | mStartTimeMs = -1; |
| 1712 | } |
| 1713 | return result; |
| 1714 | } |
| 1715 | |
| 1716 | /** |
| 1717 | * Returns the max duration that this timer has ever seen. |
| 1718 | * |
| 1719 | * Note that this time is NOT split between the timers in the timer group that |
| 1720 | * this timer is attached to. It is the TOTAL time. |
| 1721 | */ |
| 1722 | @Override |
| 1723 | public long getMaxDurationMsLocked(long elapsedRealtimeMs) { |
| 1724 | if (mNesting > 0) { |
| 1725 | final long durationMs = getCurrentDurationMsLocked(elapsedRealtimeMs); |
| 1726 | if (durationMs > mMaxDurationMs) { |
| 1727 | return durationMs; |
| 1728 | } |
| 1729 | } |
| 1730 | return mMaxDurationMs; |
| 1731 | } |
| 1732 | |
| 1733 | /** |
| 1734 | * Returns the time since the timer was started. |
| 1735 | * |
| 1736 | * Note that this time is NOT split between the timers in the timer group that |
| 1737 | * this timer is attached to. It is the TOTAL time. |
| 1738 | */ |
| 1739 | @Override |
| 1740 | public long getCurrentDurationMsLocked(long elapsedRealtimeMs) { |
| 1741 | long durationMs = mCurrentDurationMs; |
Kweku Adams | 47db5a8 | 2016-12-09 19:04:50 -0800 | [diff] [blame] | 1742 | if (mNesting > 0 && mTimeBase.isRunning()) { |
| 1743 | durationMs += (mTimeBase.getRealtime(elapsedRealtimeMs*1000)/1000) |
| 1744 | - mStartTimeMs; |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 1745 | } |
| 1746 | return durationMs; |
| 1747 | } |
| 1748 | } |
| 1749 | |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1750 | /** |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1751 | * State for keeping track of timing information. |
| 1752 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1753 | public static class StopwatchTimer extends Timer { |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 1754 | final Uid mUid; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1755 | final ArrayList<StopwatchTimer> mTimerPool; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 1756 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1757 | int mNesting; |
| 1758 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1759 | /** |
| 1760 | * The last time at which we updated the timer. If mNesting is > 0, |
| 1761 | * subtract this from the current battery time to find the amount of |
| 1762 | * time we have been running since we last computed an update. |
| 1763 | */ |
| 1764 | long mUpdateTime; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1765 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1766 | /** |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 1767 | * 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] | 1768 | * was actually held for an interesting duration. |
| 1769 | */ |
| 1770 | long mAcquireTime; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1771 | |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 1772 | long mTimeout; |
| 1773 | |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 1774 | /** |
| 1775 | * For partial wake locks, keep track of whether we are in the list |
| 1776 | * to consume CPU cycles. |
| 1777 | */ |
| 1778 | boolean mInList; |
| 1779 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1780 | public StopwatchTimer(Clocks clocks, Uid uid, int type, ArrayList<StopwatchTimer> timerPool, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1781 | TimeBase timeBase, Parcel in) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1782 | super(clocks, type, timeBase, in); |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 1783 | mUid = uid; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1784 | mTimerPool = timerPool; |
| 1785 | mUpdateTime = in.readLong(); |
| 1786 | } |
| 1787 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1788 | public StopwatchTimer(Clocks clocks, Uid uid, int type, ArrayList<StopwatchTimer> timerPool, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1789 | TimeBase timeBase) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1790 | super(clocks, type, timeBase); |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 1791 | mUid = uid; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1792 | mTimerPool = timerPool; |
| 1793 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1794 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1795 | public void setTimeout(long timeout) { |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 1796 | mTimeout = timeout; |
| 1797 | } |
| 1798 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1799 | public void writeToParcel(Parcel out, long elapsedRealtimeUs) { |
| 1800 | super.writeToParcel(out, elapsedRealtimeUs); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1801 | out.writeLong(mUpdateTime); |
| 1802 | } |
| 1803 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1804 | public void onTimeStopped(long elapsedRealtime, long baseUptime, long baseRealtime) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1805 | if (mNesting > 0) { |
| 1806 | if (DEBUG && mType < 0) { |
| 1807 | Log.v(TAG, "old mUpdateTime=" + mUpdateTime); |
| 1808 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1809 | super.onTimeStopped(elapsedRealtime, baseUptime, baseRealtime); |
| 1810 | mUpdateTime = baseRealtime; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1811 | if (DEBUG && mType < 0) { |
| 1812 | Log.v(TAG, "new mUpdateTime=" + mUpdateTime); |
| 1813 | } |
| 1814 | } |
| 1815 | } |
| 1816 | |
| 1817 | public void logState(Printer pw, String prefix) { |
| 1818 | super.logState(pw, prefix); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 1819 | pw.println(prefix + "mNesting=" + mNesting + " mUpdateTime=" + mUpdateTime |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1820 | + " mAcquireTime=" + mAcquireTime); |
| 1821 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1822 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1823 | public void startRunningLocked(long elapsedRealtimeMs) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1824 | if (mNesting++ == 0) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1825 | final long batteryRealtime = mTimeBase.getRealtime(elapsedRealtimeMs * 1000); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 1826 | mUpdateTime = batteryRealtime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1827 | if (mTimerPool != null) { |
| 1828 | // Accumulate time to all currently active timers before adding |
| 1829 | // this new one to the pool. |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1830 | refreshTimersLocked(batteryRealtime, mTimerPool, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1831 | // Add this timer to the active pool |
| 1832 | mTimerPool.add(this); |
| 1833 | } |
| 1834 | // Increment the count |
| 1835 | mCount++; |
| 1836 | mAcquireTime = mTotalTime; |
| 1837 | if (DEBUG && mType < 0) { |
| 1838 | Log.v(TAG, "start #" + mType + ": mUpdateTime=" + mUpdateTime |
| 1839 | + " mTotalTime=" + mTotalTime + " mCount=" + mCount |
| 1840 | + " mAcquireTime=" + mAcquireTime); |
| 1841 | } |
| 1842 | } |
| 1843 | } |
| 1844 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1845 | public boolean isRunningLocked() { |
Amith Yamasani | 32dbefd | 2009-06-19 09:21:17 -0700 | [diff] [blame] | 1846 | return mNesting > 0; |
| 1847 | } |
| 1848 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1849 | public void stopRunningLocked(long elapsedRealtimeMs) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1850 | // Ignore attempt to stop a timer that isn't running |
| 1851 | if (mNesting == 0) { |
| 1852 | return; |
| 1853 | } |
| 1854 | if (--mNesting == 0) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1855 | final long batteryRealtime = mTimeBase.getRealtime(elapsedRealtimeMs * 1000); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1856 | if (mTimerPool != null) { |
| 1857 | // Accumulate time to all active counters, scaled by the total |
| 1858 | // active in the pool, before taking this one out of the pool. |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1859 | refreshTimersLocked(batteryRealtime, mTimerPool, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1860 | // Remove this timer from the active pool |
| 1861 | mTimerPool.remove(this); |
| 1862 | } else { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1863 | mNesting = 1; |
| 1864 | mTotalTime = computeRunTimeLocked(batteryRealtime); |
| 1865 | mNesting = 0; |
| 1866 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1867 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1868 | if (DEBUG && mType < 0) { |
| 1869 | Log.v(TAG, "stop #" + mType + ": mUpdateTime=" + mUpdateTime |
| 1870 | + " mTotalTime=" + mTotalTime + " mCount=" + mCount |
| 1871 | + " mAcquireTime=" + mAcquireTime); |
| 1872 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1873 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1874 | if (mTotalTime == mAcquireTime) { |
| 1875 | // If there was no change in the time, then discard this |
| 1876 | // count. A somewhat cheezy strategy, but hey. |
| 1877 | mCount--; |
| 1878 | } |
| 1879 | } |
| 1880 | } |
| 1881 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1882 | public void stopAllRunningLocked(long elapsedRealtimeMs) { |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 1883 | if (mNesting > 0) { |
| 1884 | mNesting = 1; |
| 1885 | stopRunningLocked(elapsedRealtimeMs); |
| 1886 | } |
| 1887 | } |
| 1888 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1889 | // Update the total time for all other running Timers with the same type as this Timer |
| 1890 | // due to a change in timer count |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1891 | private static long refreshTimersLocked(long batteryRealtime, |
| 1892 | final ArrayList<StopwatchTimer> pool, StopwatchTimer self) { |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 1893 | long selfTime = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1894 | final int N = pool.size(); |
| 1895 | for (int i=N-1; i>= 0; i--) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1896 | final StopwatchTimer t = pool.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1897 | long heldTime = batteryRealtime - t.mUpdateTime; |
| 1898 | if (heldTime > 0) { |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 1899 | final long myTime = heldTime / N; |
| 1900 | if (t == self) { |
| 1901 | selfTime = myTime; |
| 1902 | } |
| 1903 | t.mTotalTime += myTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1904 | } |
| 1905 | t.mUpdateTime = batteryRealtime; |
| 1906 | } |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 1907 | return selfTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1908 | } |
| 1909 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1910 | @Override |
| 1911 | protected long computeRunTimeLocked(long curBatteryRealtime) { |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 1912 | if (mTimeout > 0 && curBatteryRealtime > mUpdateTime + mTimeout) { |
| 1913 | curBatteryRealtime = mUpdateTime + mTimeout; |
| 1914 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1915 | return mTotalTime + (mNesting > 0 |
| 1916 | ? (curBatteryRealtime - mUpdateTime) |
| 1917 | / (mTimerPool != null ? mTimerPool.size() : 1) |
| 1918 | : 0); |
| 1919 | } |
| 1920 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1921 | @Override |
| 1922 | protected int computeCurrentCountLocked() { |
| 1923 | return mCount; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1924 | } |
| 1925 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 1926 | @Override |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1927 | public boolean reset(boolean detachIfReset) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1928 | boolean canDetach = mNesting <= 0; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1929 | super.reset(canDetach && detachIfReset); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 1930 | if (mNesting > 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1931 | mUpdateTime = mTimeBase.getRealtime(mClocks.elapsedRealtime() * 1000); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 1932 | } |
| 1933 | mAcquireTime = mTotalTime; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1934 | return canDetach; |
| 1935 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1936 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 1937 | @Override |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1938 | public void detach() { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1939 | super.detach(); |
| 1940 | if (mTimerPool != null) { |
| 1941 | mTimerPool.remove(this); |
| 1942 | } |
| 1943 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1944 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 1945 | @Override |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1946 | public void readSummaryFromParcelLocked(Parcel in) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1947 | super.readSummaryFromParcelLocked(in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1948 | mNesting = 0; |
| 1949 | } |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 1950 | |
| 1951 | /** |
| 1952 | * Set the mark so that we can query later for the total time the timer has |
| 1953 | * accumulated since this point. The timer can be running or not. |
| 1954 | * |
| 1955 | * @param elapsedRealtimeMs the current elapsed realtime in milliseconds. |
| 1956 | */ |
| 1957 | public void setMark(long elapsedRealtimeMs) { |
| 1958 | final long batteryRealtime = mTimeBase.getRealtime(elapsedRealtimeMs * 1000); |
| 1959 | if (mNesting > 0) { |
| 1960 | // We are running. |
| 1961 | if (mTimerPool != null) { |
| 1962 | refreshTimersLocked(batteryRealtime, mTimerPool, this); |
| 1963 | } else { |
| 1964 | mTotalTime += batteryRealtime - mUpdateTime; |
| 1965 | mUpdateTime = batteryRealtime; |
| 1966 | } |
| 1967 | } |
| 1968 | mTimeBeforeMark = mTotalTime; |
| 1969 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1970 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1971 | |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 1972 | public abstract class OverflowArrayMap<T> { |
| 1973 | private static final String OVERFLOW_NAME = "*overflow*"; |
| 1974 | |
Dianne Hackborn | 657153b | 2016-07-29 14:54:14 -0700 | [diff] [blame] | 1975 | final int mUid; |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 1976 | final ArrayMap<String, T> mMap = new ArrayMap<>(); |
| 1977 | T mCurOverflow; |
| 1978 | ArrayMap<String, MutableInt> mActiveOverflow; |
Dianne Hackborn | 657153b | 2016-07-29 14:54:14 -0700 | [diff] [blame] | 1979 | long mLastOverflowTime; |
| 1980 | long mLastOverflowFinishTime; |
| 1981 | long mLastClearTime; |
| 1982 | long mLastCleanupTime; |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 1983 | |
Dianne Hackborn | 657153b | 2016-07-29 14:54:14 -0700 | [diff] [blame] | 1984 | public OverflowArrayMap(int uid) { |
| 1985 | mUid = uid; |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 1986 | } |
| 1987 | |
| 1988 | public ArrayMap<String, T> getMap() { |
| 1989 | return mMap; |
| 1990 | } |
| 1991 | |
| 1992 | public void clear() { |
Dianne Hackborn | 657153b | 2016-07-29 14:54:14 -0700 | [diff] [blame] | 1993 | mLastClearTime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 1994 | mMap.clear(); |
| 1995 | mCurOverflow = null; |
| 1996 | mActiveOverflow = null; |
| 1997 | } |
| 1998 | |
| 1999 | public void add(String name, T obj) { |
Joe Onorato | 388fc33 | 2016-04-12 17:06:47 -0700 | [diff] [blame] | 2000 | if (name == null) { |
| 2001 | name = ""; |
| 2002 | } |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 2003 | mMap.put(name, obj); |
| 2004 | if (OVERFLOW_NAME.equals(name)) { |
| 2005 | mCurOverflow = obj; |
| 2006 | } |
| 2007 | } |
| 2008 | |
| 2009 | public void cleanup() { |
Dianne Hackborn | 657153b | 2016-07-29 14:54:14 -0700 | [diff] [blame] | 2010 | mLastCleanupTime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 2011 | if (mActiveOverflow != null) { |
| 2012 | if (mActiveOverflow.size() == 0) { |
| 2013 | mActiveOverflow = null; |
| 2014 | } |
| 2015 | } |
| 2016 | if (mActiveOverflow == null) { |
| 2017 | // There is no currently active overflow, so we should no longer have |
| 2018 | // an overflow entry. |
| 2019 | if (mMap.containsKey(OVERFLOW_NAME)) { |
| 2020 | Slog.wtf(TAG, "Cleaning up with no active overflow, but have overflow entry " |
| 2021 | + mMap.get(OVERFLOW_NAME)); |
| 2022 | mMap.remove(OVERFLOW_NAME); |
| 2023 | } |
| 2024 | mCurOverflow = null; |
| 2025 | } else { |
| 2026 | // There is currently active overflow, so we should still have an overflow entry. |
| 2027 | if (mCurOverflow == null || !mMap.containsKey(OVERFLOW_NAME)) { |
| 2028 | Slog.wtf(TAG, "Cleaning up with active overflow, but no overflow entry: cur=" |
| 2029 | + mCurOverflow + " map=" + mMap.get(OVERFLOW_NAME)); |
| 2030 | } |
| 2031 | } |
| 2032 | } |
| 2033 | |
| 2034 | public T startObject(String name) { |
Joe Onorato | 388fc33 | 2016-04-12 17:06:47 -0700 | [diff] [blame] | 2035 | if (name == null) { |
| 2036 | name = ""; |
| 2037 | } |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 2038 | T obj = mMap.get(name); |
| 2039 | if (obj != null) { |
| 2040 | return obj; |
| 2041 | } |
| 2042 | |
| 2043 | // No object exists for the given name, but do we currently have it |
| 2044 | // running as part of the overflow? |
| 2045 | if (mActiveOverflow != null) { |
| 2046 | MutableInt over = mActiveOverflow.get(name); |
| 2047 | if (over != null) { |
| 2048 | // We are already actively counting this name in the overflow object. |
| 2049 | obj = mCurOverflow; |
| 2050 | if (obj == null) { |
| 2051 | // Shouldn't be here, but we'll try to recover. |
| 2052 | Slog.wtf(TAG, "Have active overflow " + name + " but null overflow"); |
| 2053 | obj = mCurOverflow = instantiateObject(); |
| 2054 | mMap.put(OVERFLOW_NAME, obj); |
| 2055 | } |
| 2056 | over.value++; |
| 2057 | return obj; |
| 2058 | } |
| 2059 | } |
| 2060 | |
| 2061 | // No object exists for given name nor in the overflow; we need to make |
| 2062 | // a new one. |
| 2063 | final int N = mMap.size(); |
| 2064 | if (N >= MAX_WAKELOCKS_PER_UID) { |
| 2065 | // Went over the limit on number of objects to track; this one goes |
| 2066 | // in to the overflow. |
| 2067 | obj = mCurOverflow; |
| 2068 | if (obj == null) { |
| 2069 | // Need to start overflow now... |
| 2070 | obj = mCurOverflow = instantiateObject(); |
| 2071 | mMap.put(OVERFLOW_NAME, obj); |
| 2072 | } |
| 2073 | if (mActiveOverflow == null) { |
| 2074 | mActiveOverflow = new ArrayMap<>(); |
| 2075 | } |
| 2076 | mActiveOverflow.put(name, new MutableInt(1)); |
Dianne Hackborn | 657153b | 2016-07-29 14:54:14 -0700 | [diff] [blame] | 2077 | mLastOverflowTime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 2078 | return obj; |
| 2079 | } |
| 2080 | |
| 2081 | // Normal case where we just need to make a new object. |
| 2082 | obj = instantiateObject(); |
| 2083 | mMap.put(name, obj); |
| 2084 | return obj; |
| 2085 | } |
| 2086 | |
| 2087 | public T stopObject(String name) { |
Joe Onorato | 388fc33 | 2016-04-12 17:06:47 -0700 | [diff] [blame] | 2088 | if (name == null) { |
| 2089 | name = ""; |
| 2090 | } |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 2091 | T obj = mMap.get(name); |
| 2092 | if (obj != null) { |
| 2093 | return obj; |
| 2094 | } |
| 2095 | |
| 2096 | // No object exists for the given name, but do we currently have it |
| 2097 | // running as part of the overflow? |
| 2098 | if (mActiveOverflow != null) { |
| 2099 | MutableInt over = mActiveOverflow.get(name); |
| 2100 | if (over != null) { |
| 2101 | // We are already actively counting this name in the overflow object. |
| 2102 | obj = mCurOverflow; |
| 2103 | if (obj != null) { |
| 2104 | over.value--; |
| 2105 | if (over.value <= 0) { |
| 2106 | mActiveOverflow.remove(name); |
Dianne Hackborn | 657153b | 2016-07-29 14:54:14 -0700 | [diff] [blame] | 2107 | mLastOverflowFinishTime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 2108 | } |
| 2109 | return obj; |
| 2110 | } |
| 2111 | } |
| 2112 | } |
| 2113 | |
| 2114 | // Huh, they are stopping an active operation but we can't find one! |
| 2115 | // That's not good. |
Dianne Hackborn | 657153b | 2016-07-29 14:54:14 -0700 | [diff] [blame] | 2116 | StringBuilder sb = new StringBuilder(); |
| 2117 | sb.append("Unable to find object for "); |
| 2118 | sb.append(name); |
| 2119 | sb.append(" in uid "); |
| 2120 | sb.append(mUid); |
| 2121 | sb.append(" mapsize="); |
| 2122 | sb.append(mMap.size()); |
| 2123 | sb.append(" activeoverflow="); |
| 2124 | sb.append(mActiveOverflow); |
| 2125 | sb.append(" curoverflow="); |
| 2126 | sb.append(mCurOverflow); |
| 2127 | long now = SystemClock.elapsedRealtime(); |
| 2128 | if (mLastOverflowTime != 0) { |
| 2129 | sb.append(" lastOverflowTime="); |
| 2130 | TimeUtils.formatDuration(mLastOverflowTime-now, sb); |
| 2131 | } |
| 2132 | if (mLastOverflowFinishTime != 0) { |
| 2133 | sb.append(" lastOverflowFinishTime="); |
| 2134 | TimeUtils.formatDuration(mLastOverflowFinishTime-now, sb); |
| 2135 | } |
| 2136 | if (mLastClearTime != 0) { |
| 2137 | sb.append(" lastClearTime="); |
| 2138 | TimeUtils.formatDuration(mLastClearTime-now, sb); |
| 2139 | } |
| 2140 | if (mLastCleanupTime != 0) { |
| 2141 | sb.append(" lastCleanupTime="); |
| 2142 | TimeUtils.formatDuration(mLastCleanupTime-now, sb); |
| 2143 | } |
| 2144 | Slog.wtf(TAG, sb.toString()); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 2145 | return null; |
| 2146 | } |
| 2147 | |
| 2148 | public abstract T instantiateObject(); |
| 2149 | } |
| 2150 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 2151 | public static class ControllerActivityCounterImpl extends ControllerActivityCounter |
| 2152 | implements Parcelable { |
| 2153 | private final LongSamplingCounter mIdleTimeMillis; |
| 2154 | private final LongSamplingCounter mRxTimeMillis; |
| 2155 | private final LongSamplingCounter[] mTxTimeMillis; |
| 2156 | private final LongSamplingCounter mPowerDrainMaMs; |
| 2157 | |
| 2158 | public ControllerActivityCounterImpl(TimeBase timeBase, int numTxStates) { |
| 2159 | mIdleTimeMillis = new LongSamplingCounter(timeBase); |
| 2160 | mRxTimeMillis = new LongSamplingCounter(timeBase); |
| 2161 | mTxTimeMillis = new LongSamplingCounter[numTxStates]; |
| 2162 | for (int i = 0; i < numTxStates; i++) { |
| 2163 | mTxTimeMillis[i] = new LongSamplingCounter(timeBase); |
| 2164 | } |
| 2165 | mPowerDrainMaMs = new LongSamplingCounter(timeBase); |
| 2166 | } |
| 2167 | |
| 2168 | public ControllerActivityCounterImpl(TimeBase timeBase, int numTxStates, Parcel in) { |
| 2169 | mIdleTimeMillis = new LongSamplingCounter(timeBase, in); |
| 2170 | mRxTimeMillis = new LongSamplingCounter(timeBase, in); |
| 2171 | final int recordedTxStates = in.readInt(); |
| 2172 | if (recordedTxStates != numTxStates) { |
| 2173 | throw new ParcelFormatException("inconsistent tx state lengths"); |
| 2174 | } |
| 2175 | |
| 2176 | mTxTimeMillis = new LongSamplingCounter[numTxStates]; |
| 2177 | for (int i = 0; i < numTxStates; i++) { |
| 2178 | mTxTimeMillis[i] = new LongSamplingCounter(timeBase, in); |
| 2179 | } |
| 2180 | mPowerDrainMaMs = new LongSamplingCounter(timeBase, in); |
| 2181 | } |
| 2182 | |
| 2183 | public void readSummaryFromParcel(Parcel in) { |
| 2184 | mIdleTimeMillis.readSummaryFromParcelLocked(in); |
| 2185 | mRxTimeMillis.readSummaryFromParcelLocked(in); |
| 2186 | final int recordedTxStates = in.readInt(); |
| 2187 | if (recordedTxStates != mTxTimeMillis.length) { |
| 2188 | throw new ParcelFormatException("inconsistent tx state lengths"); |
| 2189 | } |
| 2190 | for (LongSamplingCounter counter : mTxTimeMillis) { |
| 2191 | counter.readSummaryFromParcelLocked(in); |
| 2192 | } |
| 2193 | mPowerDrainMaMs.readSummaryFromParcelLocked(in); |
| 2194 | } |
| 2195 | |
| 2196 | @Override |
| 2197 | public int describeContents() { |
| 2198 | return 0; |
| 2199 | } |
| 2200 | |
| 2201 | public void writeSummaryToParcel(Parcel dest) { |
| 2202 | mIdleTimeMillis.writeSummaryFromParcelLocked(dest); |
| 2203 | mRxTimeMillis.writeSummaryFromParcelLocked(dest); |
| 2204 | dest.writeInt(mTxTimeMillis.length); |
| 2205 | for (LongSamplingCounter counter : mTxTimeMillis) { |
| 2206 | counter.writeSummaryFromParcelLocked(dest); |
| 2207 | } |
| 2208 | mPowerDrainMaMs.writeSummaryFromParcelLocked(dest); |
| 2209 | } |
| 2210 | |
| 2211 | @Override |
| 2212 | public void writeToParcel(Parcel dest, int flags) { |
| 2213 | mIdleTimeMillis.writeToParcel(dest); |
| 2214 | mRxTimeMillis.writeToParcel(dest); |
| 2215 | dest.writeInt(mTxTimeMillis.length); |
| 2216 | for (LongSamplingCounter counter : mTxTimeMillis) { |
| 2217 | counter.writeToParcel(dest); |
| 2218 | } |
| 2219 | mPowerDrainMaMs.writeToParcel(dest); |
| 2220 | } |
| 2221 | |
| 2222 | public void reset(boolean detachIfReset) { |
| 2223 | mIdleTimeMillis.reset(detachIfReset); |
| 2224 | mRxTimeMillis.reset(detachIfReset); |
| 2225 | for (LongSamplingCounter counter : mTxTimeMillis) { |
| 2226 | counter.reset(detachIfReset); |
| 2227 | } |
| 2228 | mPowerDrainMaMs.reset(detachIfReset); |
| 2229 | } |
| 2230 | |
| 2231 | public void detach() { |
| 2232 | mIdleTimeMillis.detach(); |
| 2233 | mRxTimeMillis.detach(); |
| 2234 | for (LongSamplingCounter counter : mTxTimeMillis) { |
| 2235 | counter.detach(); |
| 2236 | } |
| 2237 | mPowerDrainMaMs.detach(); |
| 2238 | } |
| 2239 | |
| 2240 | /** |
| 2241 | * @return a LongSamplingCounter, measuring time spent in the idle state in |
| 2242 | * milliseconds. |
| 2243 | */ |
| 2244 | @Override |
| 2245 | public LongSamplingCounter getIdleTimeCounter() { |
Roshan Pius | 8164330 | 2016-03-14 16:45:55 -0700 | [diff] [blame] | 2246 | return mIdleTimeMillis; |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 2247 | } |
| 2248 | |
| 2249 | /** |
| 2250 | * @return a LongSamplingCounter, measuring time spent in the receive state in |
| 2251 | * milliseconds. |
| 2252 | */ |
| 2253 | @Override |
| 2254 | public LongSamplingCounter getRxTimeCounter() { |
| 2255 | return mRxTimeMillis; |
| 2256 | } |
| 2257 | |
| 2258 | /** |
| 2259 | * @return a LongSamplingCounter[], measuring time spent in various transmit states in |
| 2260 | * milliseconds. |
| 2261 | */ |
| 2262 | @Override |
| 2263 | public LongSamplingCounter[] getTxTimeCounters() { |
| 2264 | return mTxTimeMillis; |
| 2265 | } |
| 2266 | |
| 2267 | /** |
| 2268 | * @return a LongSamplingCounter, measuring power use in milli-ampere milliseconds (mAmS). |
| 2269 | */ |
| 2270 | @Override |
| 2271 | public LongSamplingCounter getPowerCounter() { |
| 2272 | return mPowerDrainMaMs; |
| 2273 | } |
| 2274 | } |
| 2275 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2276 | /* |
| 2277 | * Get the wakeup reason counter, and create a new one if one |
| 2278 | * doesn't already exist. |
| 2279 | */ |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 2280 | public SamplingTimer getWakeupReasonTimerLocked(String name) { |
| 2281 | SamplingTimer timer = mWakeupReasonStats.get(name); |
| 2282 | if (timer == null) { |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 2283 | timer = new SamplingTimer(mClocks, mOnBatteryTimeBase); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 2284 | mWakeupReasonStats.put(name, timer); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2285 | } |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 2286 | return timer; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2287 | } |
| 2288 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2289 | /* |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2290 | * 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] | 2291 | * doesn't already exist. |
| 2292 | */ |
| 2293 | public SamplingTimer getKernelWakelockTimerLocked(String name) { |
| 2294 | SamplingTimer kwlt = mKernelWakelockStats.get(name); |
| 2295 | if (kwlt == null) { |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 2296 | kwlt = new SamplingTimer(mClocks, mOnBatteryScreenOffTimeBase); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2297 | mKernelWakelockStats.put(name, kwlt); |
| 2298 | } |
| 2299 | return kwlt; |
| 2300 | } |
Amith Yamasani | 3718aaa | 2009-06-09 06:32:35 -0700 | [diff] [blame] | 2301 | |
James Carr | 3a22605 | 2016-07-01 14:49:52 -0700 | [diff] [blame] | 2302 | public SamplingTimer getKernelMemoryTimerLocked(long bucket) { |
| 2303 | SamplingTimer kmt = mKernelMemoryStats.get(bucket); |
| 2304 | if (kmt == null) { |
| 2305 | kmt = new SamplingTimer(mClocks, mOnBatteryTimeBase); |
| 2306 | mKernelMemoryStats.put(bucket, kmt); |
| 2307 | } |
| 2308 | return kmt; |
| 2309 | } |
| 2310 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2311 | private int writeHistoryTag(HistoryTag tag) { |
| 2312 | Integer idxObj = mHistoryTagPool.get(tag); |
| 2313 | int idx; |
| 2314 | if (idxObj != null) { |
| 2315 | idx = idxObj; |
| 2316 | } else { |
| 2317 | idx = mNextHistoryTagIdx; |
| 2318 | HistoryTag key = new HistoryTag(); |
| 2319 | key.setTo(tag); |
| 2320 | tag.poolIdx = idx; |
| 2321 | mHistoryTagPool.put(key, idx); |
| 2322 | mNextHistoryTagIdx++; |
| 2323 | mNumHistoryTagChars += key.string.length() + 1; |
| 2324 | } |
| 2325 | return idx; |
| 2326 | } |
| 2327 | |
| 2328 | private void readHistoryTag(int index, HistoryTag tag) { |
| 2329 | tag.string = mReadHistoryStrings[index]; |
| 2330 | tag.uid = mReadHistoryUids[index]; |
| 2331 | tag.poolIdx = index; |
| 2332 | } |
| 2333 | |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 2334 | /* |
| 2335 | The history delta format uses flags to denote further data in subsequent ints in the parcel. |
| 2336 | |
| 2337 | There is always the first token, which may contain the delta time, or an indicator of |
| 2338 | the length of the time (int or long) following this token. |
| 2339 | |
| 2340 | First token: always present, |
| 2341 | 31 23 15 7 0 |
| 2342 | â–ˆM|L|K|J|I|H|G|Fâ–ˆE|D|C|B|A|T|T|Tâ–ˆT|T|T|T|T|T|T|Tâ–ˆT|T|T|T|T|T|T|Tâ–ˆ |
| 2343 | |
| 2344 | T: the delta time if it is <= 0x7fffd. Otherwise 0x7fffe indicates an int immediately |
| 2345 | follows containing the time, and 0x7ffff indicates a long immediately follows with the |
| 2346 | delta time. |
| 2347 | A: battery level changed and an int follows with battery data. |
| 2348 | B: state changed and an int follows with state change data. |
| 2349 | C: state2 has changed and an int follows with state2 change data. |
| 2350 | D: wakelock/wakereason has changed and an wakelock/wakereason struct follows. |
| 2351 | E: event data has changed and an event struct follows. |
| 2352 | F: battery charge in coulombs has changed and an int with the charge follows. |
| 2353 | G: state flag denoting that the mobile radio was active. |
| 2354 | H: state flag denoting that the wifi radio was active. |
| 2355 | I: state flag denoting that a wifi scan occurred. |
| 2356 | J: state flag denoting that a wifi full lock was held. |
| 2357 | K: state flag denoting that the gps was on. |
| 2358 | L: state flag denoting that a wakelock was held. |
| 2359 | M: state flag denoting that the cpu was running. |
| 2360 | |
| 2361 | Time int/long: if T in the first token is 0x7ffff or 0x7fffe, then an int or long follows |
| 2362 | with the time delta. |
| 2363 | |
| 2364 | Battery level int: if A in the first token is set, |
| 2365 | 31 23 15 7 0 |
| 2366 | â–ˆL|L|L|L|L|L|L|Tâ–ˆT|T|T|T|T|T|T|Tâ–ˆT|V|V|V|V|V|V|Vâ–ˆV|V|V|V|V|V|V|Dâ–ˆ |
| 2367 | |
| 2368 | D: indicates that extra history details follow. |
| 2369 | V: the battery voltage. |
| 2370 | T: the battery temperature. |
| 2371 | L: the battery level (out of 100). |
| 2372 | |
| 2373 | State change int: if B in the first token is set, |
| 2374 | 31 23 15 7 0 |
| 2375 | â–ˆS|S|S|H|H|H|P|Pâ–ˆF|E|D|C|B| | |Aâ–ˆ | | | | | | | â–ˆ | | | | | | | â–ˆ |
| 2376 | |
| 2377 | A: wifi multicast was on. |
| 2378 | B: battery was plugged in. |
| 2379 | C: screen was on. |
| 2380 | D: phone was scanning for signal. |
| 2381 | E: audio was on. |
| 2382 | F: a sensor was active. |
| 2383 | |
| 2384 | State2 change int: if C in the first token is set, |
| 2385 | 31 23 15 7 0 |
| 2386 | â–ˆM|L|K|J|I|H|H|Gâ–ˆF|E|D|C| | | | â–ˆ | | | | | | | â–ˆ |B|B|B|A|A|A|Aâ–ˆ |
| 2387 | |
| 2388 | A: 4 bits indicating the wifi supplicant state: {@link BatteryStats#WIFI_SUPPL_STATE_NAMES}. |
| 2389 | B: 3 bits indicating the wifi signal strength: 0, 1, 2, 3, 4. |
| 2390 | C: a bluetooth scan was active. |
| 2391 | D: the camera was active. |
| 2392 | E: bluetooth was on. |
| 2393 | F: a phone call was active. |
| 2394 | G: the device was charging. |
| 2395 | H: 2 bits indicating the device-idle (doze) state: off, light, full |
| 2396 | I: the flashlight was on. |
| 2397 | J: wifi was on. |
| 2398 | K: wifi was running. |
| 2399 | L: video was playing. |
| 2400 | M: power save mode was on. |
| 2401 | |
| 2402 | Wakelock/wakereason struct: if D in the first token is set, |
| 2403 | TODO(adamlesinski): describe wakelock/wakereason struct. |
| 2404 | |
| 2405 | Event struct: if E in the first token is set, |
| 2406 | TODO(adamlesinski): describe the event struct. |
| 2407 | |
| 2408 | History step details struct: if D in the battery level int is set, |
| 2409 | TODO(adamlesinski): describe the history step details struct. |
| 2410 | |
| 2411 | Battery charge int: if F in the first token is set, an int representing the battery charge |
| 2412 | in coulombs follows. |
| 2413 | */ |
| 2414 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2415 | // Part of initial delta int that specifies the time delta. |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 2416 | static final int DELTA_TIME_MASK = 0x7ffff; |
| 2417 | static final int DELTA_TIME_LONG = 0x7ffff; // The delta is a following long |
| 2418 | static final int DELTA_TIME_INT = 0x7fffe; // The delta is a following int |
| 2419 | 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] | 2420 | // Flag in delta int: a new battery level int follows. |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 2421 | static final int DELTA_BATTERY_LEVEL_FLAG = 0x00080000; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2422 | // Flag in delta int: a new full state and battery status int follows. |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 2423 | static final int DELTA_STATE_FLAG = 0x00100000; |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 2424 | // Flag in delta int: a new full state2 int follows. |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 2425 | static final int DELTA_STATE2_FLAG = 0x00200000; |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 2426 | // Flag in delta int: contains a wakelock or wakeReason tag. |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 2427 | static final int DELTA_WAKELOCK_FLAG = 0x00400000; |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2428 | // Flag in delta int: contains an event description. |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 2429 | static final int DELTA_EVENT_FLAG = 0x00800000; |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 2430 | // Flag in delta int: contains the battery charge count in uAh. |
| 2431 | static final int DELTA_BATTERY_CHARGE_FLAG = 0x01000000; |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2432 | // These upper bits are the frequently changing state bits. |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 2433 | static final int DELTA_STATE_MASK = 0xfe000000; |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 2434 | |
| 2435 | // These are the pieces of battery state that are packed in to the upper bits of |
| 2436 | // the state int that have been packed in to the first delta int. They must fit |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 2437 | // in STATE_BATTERY_MASK. |
| 2438 | static final int STATE_BATTERY_MASK = 0xff000000; |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 2439 | static final int STATE_BATTERY_STATUS_MASK = 0x00000007; |
| 2440 | static final int STATE_BATTERY_STATUS_SHIFT = 29; |
| 2441 | static final int STATE_BATTERY_HEALTH_MASK = 0x00000007; |
| 2442 | static final int STATE_BATTERY_HEALTH_SHIFT = 26; |
| 2443 | static final int STATE_BATTERY_PLUG_MASK = 0x00000003; |
| 2444 | static final int STATE_BATTERY_PLUG_SHIFT = 24; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2445 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 2446 | // We use the low bit of the battery state int to indicate that we have full details |
| 2447 | // from a battery level change. |
| 2448 | static final int BATTERY_DELTA_LEVEL_FLAG = 0x00000001; |
| 2449 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2450 | public void writeHistoryDelta(Parcel dest, HistoryItem cur, HistoryItem last) { |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2451 | if (last == null || cur.cmd != HistoryItem.CMD_UPDATE) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2452 | dest.writeInt(DELTA_TIME_ABS); |
| 2453 | cur.writeToParcel(dest, 0); |
| 2454 | return; |
| 2455 | } |
| 2456 | |
| 2457 | final long deltaTime = cur.time - last.time; |
| 2458 | final int lastBatteryLevelInt = buildBatteryLevelInt(last); |
| 2459 | final int lastStateInt = buildStateInt(last); |
| 2460 | |
| 2461 | int deltaTimeToken; |
| 2462 | if (deltaTime < 0 || deltaTime > Integer.MAX_VALUE) { |
| 2463 | deltaTimeToken = DELTA_TIME_LONG; |
| 2464 | } else if (deltaTime >= DELTA_TIME_ABS) { |
| 2465 | deltaTimeToken = DELTA_TIME_INT; |
| 2466 | } else { |
| 2467 | deltaTimeToken = (int)deltaTime; |
| 2468 | } |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2469 | int firstToken = deltaTimeToken | (cur.states&DELTA_STATE_MASK); |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 2470 | final int includeStepDetails = mLastHistoryStepLevel > cur.batteryLevel |
| 2471 | ? BATTERY_DELTA_LEVEL_FLAG : 0; |
| 2472 | final boolean computeStepDetails = includeStepDetails != 0 |
| 2473 | || mLastHistoryStepDetails == null; |
| 2474 | final int batteryLevelInt = buildBatteryLevelInt(cur) | includeStepDetails; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2475 | final boolean batteryLevelIntChanged = batteryLevelInt != lastBatteryLevelInt; |
| 2476 | if (batteryLevelIntChanged) { |
| 2477 | firstToken |= DELTA_BATTERY_LEVEL_FLAG; |
| 2478 | } |
| 2479 | final int stateInt = buildStateInt(cur); |
| 2480 | final boolean stateIntChanged = stateInt != lastStateInt; |
| 2481 | if (stateIntChanged) { |
| 2482 | firstToken |= DELTA_STATE_FLAG; |
| 2483 | } |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2484 | final boolean state2IntChanged = cur.states2 != last.states2; |
| 2485 | if (state2IntChanged) { |
| 2486 | firstToken |= DELTA_STATE2_FLAG; |
| 2487 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 2488 | if (cur.wakelockTag != null || cur.wakeReasonTag != null) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2489 | firstToken |= DELTA_WAKELOCK_FLAG; |
| 2490 | } |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2491 | if (cur.eventCode != HistoryItem.EVENT_NONE) { |
| 2492 | firstToken |= DELTA_EVENT_FLAG; |
| 2493 | } |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 2494 | |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 2495 | final boolean batteryChargeChanged = cur.batteryChargeUAh != last.batteryChargeUAh; |
| 2496 | if (batteryChargeChanged) { |
| 2497 | firstToken |= DELTA_BATTERY_CHARGE_FLAG; |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 2498 | } |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2499 | dest.writeInt(firstToken); |
| 2500 | if (DEBUG) Slog.i(TAG, "WRITE DELTA: firstToken=0x" + Integer.toHexString(firstToken) |
| 2501 | + " deltaTime=" + deltaTime); |
| 2502 | |
| 2503 | if (deltaTimeToken >= DELTA_TIME_INT) { |
| 2504 | if (deltaTimeToken == DELTA_TIME_INT) { |
| 2505 | if (DEBUG) Slog.i(TAG, "WRITE DELTA: int deltaTime=" + (int)deltaTime); |
| 2506 | dest.writeInt((int)deltaTime); |
| 2507 | } else { |
| 2508 | if (DEBUG) Slog.i(TAG, "WRITE DELTA: long deltaTime=" + deltaTime); |
| 2509 | dest.writeLong(deltaTime); |
| 2510 | } |
| 2511 | } |
| 2512 | if (batteryLevelIntChanged) { |
| 2513 | dest.writeInt(batteryLevelInt); |
| 2514 | if (DEBUG) Slog.i(TAG, "WRITE DELTA: batteryToken=0x" |
| 2515 | + Integer.toHexString(batteryLevelInt) |
| 2516 | + " batteryLevel=" + cur.batteryLevel |
| 2517 | + " batteryTemp=" + cur.batteryTemperature |
| 2518 | + " batteryVolt=" + (int)cur.batteryVoltage); |
| 2519 | } |
| 2520 | if (stateIntChanged) { |
| 2521 | dest.writeInt(stateInt); |
| 2522 | if (DEBUG) Slog.i(TAG, "WRITE DELTA: stateToken=0x" |
| 2523 | + Integer.toHexString(stateInt) |
| 2524 | + " batteryStatus=" + cur.batteryStatus |
| 2525 | + " batteryHealth=" + cur.batteryHealth |
| 2526 | + " batteryPlugType=" + cur.batteryPlugType |
| 2527 | + " states=0x" + Integer.toHexString(cur.states)); |
| 2528 | } |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2529 | if (state2IntChanged) { |
| 2530 | dest.writeInt(cur.states2); |
| 2531 | if (DEBUG) Slog.i(TAG, "WRITE DELTA: states2=0x" |
| 2532 | + Integer.toHexString(cur.states2)); |
| 2533 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 2534 | if (cur.wakelockTag != null || cur.wakeReasonTag != null) { |
| 2535 | int wakeLockIndex; |
| 2536 | int wakeReasonIndex; |
| 2537 | if (cur.wakelockTag != null) { |
| 2538 | wakeLockIndex = writeHistoryTag(cur.wakelockTag); |
| 2539 | if (DEBUG) Slog.i(TAG, "WRITE DELTA: wakelockTag=#" + cur.wakelockTag.poolIdx |
| 2540 | + " " + cur.wakelockTag.uid + ":" + cur.wakelockTag.string); |
| 2541 | } else { |
| 2542 | wakeLockIndex = 0xffff; |
| 2543 | } |
| 2544 | if (cur.wakeReasonTag != null) { |
| 2545 | wakeReasonIndex = writeHistoryTag(cur.wakeReasonTag); |
| 2546 | if (DEBUG) Slog.i(TAG, "WRITE DELTA: wakeReasonTag=#" + cur.wakeReasonTag.poolIdx |
| 2547 | + " " + cur.wakeReasonTag.uid + ":" + cur.wakeReasonTag.string); |
| 2548 | } else { |
| 2549 | wakeReasonIndex = 0xffff; |
| 2550 | } |
| 2551 | dest.writeInt((wakeReasonIndex<<16) | wakeLockIndex); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2552 | } |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2553 | if (cur.eventCode != HistoryItem.EVENT_NONE) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2554 | int index = writeHistoryTag(cur.eventTag); |
| 2555 | int codeAndIndex = (cur.eventCode&0xffff) | (index<<16); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 2556 | dest.writeInt(codeAndIndex); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2557 | if (DEBUG) Slog.i(TAG, "WRITE DELTA: event=" + cur.eventCode + " tag=#" |
| 2558 | + cur.eventTag.poolIdx + " " + cur.eventTag.uid + ":" |
| 2559 | + cur.eventTag.string); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2560 | } |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 2561 | if (computeStepDetails) { |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 2562 | if (mPlatformIdleStateCallback != null) { |
| 2563 | mCurHistoryStepDetails.statPlatformIdleState = |
| 2564 | mPlatformIdleStateCallback.getPlatformLowPowerStats(); |
| 2565 | if (DEBUG) Slog.i(TAG, "WRITE PlatformIdleState:" + |
| 2566 | mCurHistoryStepDetails.statPlatformIdleState); |
| 2567 | } |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 2568 | computeHistoryStepDetails(mCurHistoryStepDetails, mLastHistoryStepDetails); |
| 2569 | if (includeStepDetails != 0) { |
| 2570 | mCurHistoryStepDetails.writeToParcel(dest); |
| 2571 | } |
| 2572 | cur.stepDetails = mCurHistoryStepDetails; |
| 2573 | mLastHistoryStepDetails = mCurHistoryStepDetails; |
| 2574 | } else { |
| 2575 | cur.stepDetails = null; |
| 2576 | } |
| 2577 | if (mLastHistoryStepLevel < cur.batteryLevel) { |
| 2578 | mLastHistoryStepDetails = null; |
| 2579 | } |
| 2580 | mLastHistoryStepLevel = cur.batteryLevel; |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 2581 | |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 2582 | if (batteryChargeChanged) { |
| 2583 | if (DEBUG) Slog.i(TAG, "WRITE DELTA: batteryChargeUAh=" + cur.batteryChargeUAh); |
| 2584 | dest.writeInt(cur.batteryChargeUAh); |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 2585 | } |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2586 | } |
| 2587 | |
| 2588 | private int buildBatteryLevelInt(HistoryItem h) { |
| 2589 | return ((((int)h.batteryLevel)<<25)&0xfe000000) |
Adam Lesinski | 3944c81 | 2015-11-13 15:54:59 -0800 | [diff] [blame] | 2590 | | ((((int)h.batteryTemperature)<<15)&0x01ff8000) |
| 2591 | | ((((int)h.batteryVoltage)<<1)&0x00007ffe); |
| 2592 | } |
| 2593 | |
| 2594 | private void readBatteryLevelInt(int batteryLevelInt, HistoryItem out) { |
| 2595 | out.batteryLevel = (byte)((batteryLevelInt & 0xfe000000) >>> 25); |
| 2596 | out.batteryTemperature = (short)((batteryLevelInt & 0x01ff8000) >>> 15); |
| 2597 | out.batteryVoltage = (char)((batteryLevelInt & 0x00007ffe) >>> 1); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2598 | } |
| 2599 | |
| 2600 | private int buildStateInt(HistoryItem h) { |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 2601 | int plugType = 0; |
| 2602 | if ((h.batteryPlugType&BatteryManager.BATTERY_PLUGGED_AC) != 0) { |
| 2603 | plugType = 1; |
| 2604 | } else if ((h.batteryPlugType&BatteryManager.BATTERY_PLUGGED_USB) != 0) { |
| 2605 | plugType = 2; |
| 2606 | } else if ((h.batteryPlugType&BatteryManager.BATTERY_PLUGGED_WIRELESS) != 0) { |
| 2607 | plugType = 3; |
| 2608 | } |
| 2609 | return ((h.batteryStatus&STATE_BATTERY_STATUS_MASK)<<STATE_BATTERY_STATUS_SHIFT) |
| 2610 | | ((h.batteryHealth&STATE_BATTERY_HEALTH_MASK)<<STATE_BATTERY_HEALTH_SHIFT) |
| 2611 | | ((plugType&STATE_BATTERY_PLUG_MASK)<<STATE_BATTERY_PLUG_SHIFT) |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 2612 | | (h.states&(~STATE_BATTERY_MASK)); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2613 | } |
| 2614 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 2615 | private void computeHistoryStepDetails(final HistoryStepDetails out, |
| 2616 | final HistoryStepDetails last) { |
| 2617 | final HistoryStepDetails tmp = last != null ? mTmpHistoryStepDetails : out; |
| 2618 | |
| 2619 | // Perform a CPU update right after we do this collection, so we have started |
| 2620 | // collecting good data for the next step. |
| 2621 | requestImmediateCpuUpdate(); |
| 2622 | |
| 2623 | if (last == null) { |
| 2624 | // We are not generating a delta, so all we need to do is reset the stats |
| 2625 | // we will later be doing a delta from. |
| 2626 | final int NU = mUidStats.size(); |
| 2627 | for (int i=0; i<NU; i++) { |
| 2628 | final BatteryStatsImpl.Uid uid = mUidStats.valueAt(i); |
| 2629 | uid.mLastStepUserTime = uid.mCurStepUserTime; |
| 2630 | uid.mLastStepSystemTime = uid.mCurStepSystemTime; |
| 2631 | } |
| 2632 | mLastStepCpuUserTime = mCurStepCpuUserTime; |
| 2633 | mLastStepCpuSystemTime = mCurStepCpuSystemTime; |
| 2634 | mLastStepStatUserTime = mCurStepStatUserTime; |
| 2635 | mLastStepStatSystemTime = mCurStepStatSystemTime; |
| 2636 | mLastStepStatIOWaitTime = mCurStepStatIOWaitTime; |
| 2637 | mLastStepStatIrqTime = mCurStepStatIrqTime; |
| 2638 | mLastStepStatSoftIrqTime = mCurStepStatSoftIrqTime; |
| 2639 | mLastStepStatIdleTime = mCurStepStatIdleTime; |
| 2640 | tmp.clear(); |
| 2641 | return; |
| 2642 | } |
| 2643 | if (DEBUG) { |
| 2644 | Slog.d(TAG, "Step stats last: user=" + mLastStepCpuUserTime + " sys=" |
| 2645 | + mLastStepStatSystemTime + " io=" + mLastStepStatIOWaitTime |
| 2646 | + " irq=" + mLastStepStatIrqTime + " sirq=" |
| 2647 | + mLastStepStatSoftIrqTime + " idle=" + mLastStepStatIdleTime); |
| 2648 | Slog.d(TAG, "Step stats cur: user=" + mCurStepCpuUserTime + " sys=" |
| 2649 | + mCurStepStatSystemTime + " io=" + mCurStepStatIOWaitTime |
| 2650 | + " irq=" + mCurStepStatIrqTime + " sirq=" |
| 2651 | + mCurStepStatSoftIrqTime + " idle=" + mCurStepStatIdleTime); |
| 2652 | } |
| 2653 | out.userTime = (int)(mCurStepCpuUserTime - mLastStepCpuUserTime); |
| 2654 | out.systemTime = (int)(mCurStepCpuSystemTime - mLastStepCpuSystemTime); |
| 2655 | out.statUserTime = (int)(mCurStepStatUserTime - mLastStepStatUserTime); |
| 2656 | out.statSystemTime = (int)(mCurStepStatSystemTime - mLastStepStatSystemTime); |
| 2657 | out.statIOWaitTime = (int)(mCurStepStatIOWaitTime - mLastStepStatIOWaitTime); |
| 2658 | out.statIrqTime = (int)(mCurStepStatIrqTime - mLastStepStatIrqTime); |
| 2659 | out.statSoftIrqTime = (int)(mCurStepStatSoftIrqTime - mLastStepStatSoftIrqTime); |
| 2660 | out.statIdlTime = (int)(mCurStepStatIdleTime - mLastStepStatIdleTime); |
| 2661 | out.appCpuUid1 = out.appCpuUid2 = out.appCpuUid3 = -1; |
| 2662 | out.appCpuUTime1 = out.appCpuUTime2 = out.appCpuUTime3 = 0; |
| 2663 | out.appCpuSTime1 = out.appCpuSTime2 = out.appCpuSTime3 = 0; |
| 2664 | final int NU = mUidStats.size(); |
| 2665 | for (int i=0; i<NU; i++) { |
| 2666 | final BatteryStatsImpl.Uid uid = mUidStats.valueAt(i); |
| 2667 | final int totalUTime = (int)(uid.mCurStepUserTime - uid.mLastStepUserTime); |
| 2668 | final int totalSTime = (int)(uid.mCurStepSystemTime - uid.mLastStepSystemTime); |
| 2669 | final int totalTime = totalUTime + totalSTime; |
| 2670 | uid.mLastStepUserTime = uid.mCurStepUserTime; |
| 2671 | uid.mLastStepSystemTime = uid.mCurStepSystemTime; |
| 2672 | if (totalTime <= (out.appCpuUTime3+out.appCpuSTime3)) { |
| 2673 | continue; |
| 2674 | } |
| 2675 | if (totalTime <= (out.appCpuUTime2+out.appCpuSTime2)) { |
| 2676 | out.appCpuUid3 = uid.mUid; |
| 2677 | out.appCpuUTime3 = totalUTime; |
| 2678 | out.appCpuSTime3 = totalSTime; |
| 2679 | } else { |
| 2680 | out.appCpuUid3 = out.appCpuUid2; |
| 2681 | out.appCpuUTime3 = out.appCpuUTime2; |
| 2682 | out.appCpuSTime3 = out.appCpuSTime2; |
| 2683 | if (totalTime <= (out.appCpuUTime1+out.appCpuSTime1)) { |
| 2684 | out.appCpuUid2 = uid.mUid; |
| 2685 | out.appCpuUTime2 = totalUTime; |
| 2686 | out.appCpuSTime2 = totalSTime; |
| 2687 | } else { |
| 2688 | out.appCpuUid2 = out.appCpuUid1; |
| 2689 | out.appCpuUTime2 = out.appCpuUTime1; |
| 2690 | out.appCpuSTime2 = out.appCpuSTime1; |
| 2691 | out.appCpuUid1 = uid.mUid; |
| 2692 | out.appCpuUTime1 = totalUTime; |
| 2693 | out.appCpuSTime1 = totalSTime; |
| 2694 | } |
| 2695 | } |
| 2696 | } |
| 2697 | mLastStepCpuUserTime = mCurStepCpuUserTime; |
| 2698 | mLastStepCpuSystemTime = mCurStepCpuSystemTime; |
| 2699 | mLastStepStatUserTime = mCurStepStatUserTime; |
| 2700 | mLastStepStatSystemTime = mCurStepStatSystemTime; |
| 2701 | mLastStepStatIOWaitTime = mCurStepStatIOWaitTime; |
| 2702 | mLastStepStatIrqTime = mCurStepStatIrqTime; |
| 2703 | mLastStepStatSoftIrqTime = mCurStepStatSoftIrqTime; |
| 2704 | mLastStepStatIdleTime = mCurStepStatIdleTime; |
| 2705 | } |
| 2706 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2707 | public void readHistoryDelta(Parcel src, HistoryItem cur) { |
| 2708 | int firstToken = src.readInt(); |
| 2709 | int deltaTimeToken = firstToken&DELTA_TIME_MASK; |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2710 | cur.cmd = HistoryItem.CMD_UPDATE; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2711 | cur.numReadInts = 1; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2712 | if (DEBUG) Slog.i(TAG, "READ DELTA: firstToken=0x" + Integer.toHexString(firstToken) |
| 2713 | + " deltaTimeToken=" + deltaTimeToken); |
| 2714 | |
| 2715 | if (deltaTimeToken < DELTA_TIME_ABS) { |
| 2716 | cur.time += deltaTimeToken; |
| 2717 | } else if (deltaTimeToken == DELTA_TIME_ABS) { |
| 2718 | cur.time = src.readLong(); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2719 | cur.numReadInts += 2; |
| 2720 | if (DEBUG) Slog.i(TAG, "READ DELTA: ABS time=" + cur.time); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2721 | cur.readFromParcel(src); |
| 2722 | return; |
| 2723 | } else if (deltaTimeToken == DELTA_TIME_INT) { |
| 2724 | int delta = src.readInt(); |
| 2725 | cur.time += delta; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2726 | cur.numReadInts += 1; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2727 | if (DEBUG) Slog.i(TAG, "READ DELTA: time delta=" + delta + " new time=" + cur.time); |
| 2728 | } else { |
| 2729 | long delta = src.readLong(); |
| 2730 | if (DEBUG) Slog.i(TAG, "READ DELTA: time delta=" + delta + " new time=" + cur.time); |
| 2731 | cur.time += delta; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2732 | cur.numReadInts += 2; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2733 | } |
| 2734 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 2735 | final int batteryLevelInt; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2736 | if ((firstToken&DELTA_BATTERY_LEVEL_FLAG) != 0) { |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 2737 | batteryLevelInt = src.readInt(); |
Adam Lesinski | 3944c81 | 2015-11-13 15:54:59 -0800 | [diff] [blame] | 2738 | readBatteryLevelInt(batteryLevelInt, cur); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2739 | cur.numReadInts += 1; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2740 | if (DEBUG) Slog.i(TAG, "READ DELTA: batteryToken=0x" |
| 2741 | + Integer.toHexString(batteryLevelInt) |
| 2742 | + " batteryLevel=" + cur.batteryLevel |
| 2743 | + " batteryTemp=" + cur.batteryTemperature |
| 2744 | + " batteryVolt=" + (int)cur.batteryVoltage); |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 2745 | } else { |
| 2746 | batteryLevelInt = 0; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2747 | } |
| 2748 | |
| 2749 | if ((firstToken&DELTA_STATE_FLAG) != 0) { |
| 2750 | int stateInt = src.readInt(); |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 2751 | cur.states = (firstToken&DELTA_STATE_MASK) | (stateInt&(~STATE_BATTERY_MASK)); |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 2752 | cur.batteryStatus = (byte)((stateInt>>STATE_BATTERY_STATUS_SHIFT) |
| 2753 | & STATE_BATTERY_STATUS_MASK); |
| 2754 | cur.batteryHealth = (byte)((stateInt>>STATE_BATTERY_HEALTH_SHIFT) |
| 2755 | & STATE_BATTERY_HEALTH_MASK); |
| 2756 | cur.batteryPlugType = (byte)((stateInt>>STATE_BATTERY_PLUG_SHIFT) |
| 2757 | & STATE_BATTERY_PLUG_MASK); |
| 2758 | switch (cur.batteryPlugType) { |
| 2759 | case 1: |
| 2760 | cur.batteryPlugType = BatteryManager.BATTERY_PLUGGED_AC; |
| 2761 | break; |
| 2762 | case 2: |
| 2763 | cur.batteryPlugType = BatteryManager.BATTERY_PLUGGED_USB; |
| 2764 | break; |
| 2765 | case 3: |
| 2766 | cur.batteryPlugType = BatteryManager.BATTERY_PLUGGED_WIRELESS; |
| 2767 | break; |
| 2768 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2769 | cur.numReadInts += 1; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2770 | if (DEBUG) Slog.i(TAG, "READ DELTA: stateToken=0x" |
| 2771 | + Integer.toHexString(stateInt) |
| 2772 | + " batteryStatus=" + cur.batteryStatus |
| 2773 | + " batteryHealth=" + cur.batteryHealth |
| 2774 | + " batteryPlugType=" + cur.batteryPlugType |
| 2775 | + " states=0x" + Integer.toHexString(cur.states)); |
| 2776 | } else { |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 2777 | cur.states = (firstToken&DELTA_STATE_MASK) | (cur.states&(~STATE_BATTERY_MASK)); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2778 | } |
| 2779 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2780 | if ((firstToken&DELTA_STATE2_FLAG) != 0) { |
| 2781 | cur.states2 = src.readInt(); |
| 2782 | if (DEBUG) Slog.i(TAG, "READ DELTA: states2=0x" |
| 2783 | + Integer.toHexString(cur.states2)); |
| 2784 | } |
| 2785 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2786 | if ((firstToken&DELTA_WAKELOCK_FLAG) != 0) { |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 2787 | int indexes = src.readInt(); |
| 2788 | int wakeLockIndex = indexes&0xffff; |
| 2789 | int wakeReasonIndex = (indexes>>16)&0xffff; |
| 2790 | if (wakeLockIndex != 0xffff) { |
| 2791 | cur.wakelockTag = cur.localWakelockTag; |
| 2792 | readHistoryTag(wakeLockIndex, cur.wakelockTag); |
| 2793 | if (DEBUG) Slog.i(TAG, "READ DELTA: wakelockTag=#" + cur.wakelockTag.poolIdx |
| 2794 | + " " + cur.wakelockTag.uid + ":" + cur.wakelockTag.string); |
| 2795 | } else { |
| 2796 | cur.wakelockTag = null; |
| 2797 | } |
| 2798 | if (wakeReasonIndex != 0xffff) { |
| 2799 | cur.wakeReasonTag = cur.localWakeReasonTag; |
| 2800 | readHistoryTag(wakeReasonIndex, cur.wakeReasonTag); |
| 2801 | if (DEBUG) Slog.i(TAG, "READ DELTA: wakeReasonTag=#" + cur.wakeReasonTag.poolIdx |
| 2802 | + " " + cur.wakeReasonTag.uid + ":" + cur.wakeReasonTag.string); |
| 2803 | } else { |
| 2804 | cur.wakeReasonTag = null; |
| 2805 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2806 | cur.numReadInts += 1; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2807 | } else { |
| 2808 | cur.wakelockTag = null; |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 2809 | cur.wakeReasonTag = null; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2810 | } |
| 2811 | |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2812 | if ((firstToken&DELTA_EVENT_FLAG) != 0) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2813 | cur.eventTag = cur.localEventTag; |
| 2814 | final int codeAndIndex = src.readInt(); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 2815 | cur.eventCode = (codeAndIndex&0xffff); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2816 | final int index = ((codeAndIndex>>16)&0xffff); |
| 2817 | readHistoryTag(index, cur.eventTag); |
| 2818 | cur.numReadInts += 1; |
| 2819 | if (DEBUG) Slog.i(TAG, "READ DELTA: event=" + cur.eventCode + " tag=#" |
| 2820 | + cur.eventTag.poolIdx + " " + cur.eventTag.uid + ":" |
| 2821 | + cur.eventTag.string); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2822 | } else { |
| 2823 | cur.eventCode = HistoryItem.EVENT_NONE; |
| 2824 | } |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 2825 | |
| 2826 | if ((batteryLevelInt&BATTERY_DELTA_LEVEL_FLAG) != 0) { |
| 2827 | cur.stepDetails = mReadHistoryStepDetails; |
| 2828 | cur.stepDetails.readFromParcel(src); |
| 2829 | } else { |
| 2830 | cur.stepDetails = null; |
| 2831 | } |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 2832 | |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 2833 | if ((firstToken&DELTA_BATTERY_CHARGE_FLAG) != 0) { |
| 2834 | cur.batteryChargeUAh = src.readInt(); |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 2835 | } |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2836 | } |
| 2837 | |
Dianne Hackborn | fc06413 | 2014-06-02 12:42:12 -0700 | [diff] [blame] | 2838 | @Override |
| 2839 | public void commitCurrentHistoryBatchLocked() { |
| 2840 | mHistoryLastWritten.cmd = HistoryItem.CMD_NULL; |
| 2841 | } |
| 2842 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2843 | void addHistoryBufferLocked(long elapsedRealtimeMs, long uptimeMs, HistoryItem cur) { |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2844 | if (!mHaveBatteryLevel || !mRecordingHistory) { |
| 2845 | return; |
| 2846 | } |
| 2847 | |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2848 | final long timeDiff = (mHistoryBaseTime+elapsedRealtimeMs) - mHistoryLastWritten.time; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 2849 | final int diffStates = mHistoryLastWritten.states^(cur.states&mActiveHistoryStates); |
| 2850 | final int diffStates2 = mHistoryLastWritten.states2^(cur.states2&mActiveHistoryStates2); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2851 | final int lastDiffStates = mHistoryLastWritten.states^mHistoryLastLastWritten.states; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2852 | final int lastDiffStates2 = mHistoryLastWritten.states2^mHistoryLastLastWritten.states2; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2853 | if (DEBUG) Slog.i(TAG, "ADD: tdelta=" + timeDiff + " diff=" |
| 2854 | + Integer.toHexString(diffStates) + " lastDiff=" |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2855 | + Integer.toHexString(lastDiffStates) + " diff2=" |
| 2856 | + Integer.toHexString(diffStates2) + " lastDiff2=" |
| 2857 | + Integer.toHexString(lastDiffStates2)); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2858 | if (mHistoryBufferLastPos >= 0 && mHistoryLastWritten.cmd == HistoryItem.CMD_UPDATE |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2859 | && timeDiff < 1000 && (diffStates&lastDiffStates) == 0 |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2860 | && (diffStates2&lastDiffStates2) == 0 |
| 2861 | && (mHistoryLastWritten.wakelockTag == null || cur.wakelockTag == null) |
| 2862 | && (mHistoryLastWritten.wakeReasonTag == null || cur.wakeReasonTag == null) |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 2863 | && mHistoryLastWritten.stepDetails == null |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2864 | && (mHistoryLastWritten.eventCode == HistoryItem.EVENT_NONE |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2865 | || cur.eventCode == HistoryItem.EVENT_NONE) |
| 2866 | && mHistoryLastWritten.batteryLevel == cur.batteryLevel |
| 2867 | && mHistoryLastWritten.batteryStatus == cur.batteryStatus |
| 2868 | && mHistoryLastWritten.batteryHealth == cur.batteryHealth |
| 2869 | && mHistoryLastWritten.batteryPlugType == cur.batteryPlugType |
| 2870 | && mHistoryLastWritten.batteryTemperature == cur.batteryTemperature |
| 2871 | && mHistoryLastWritten.batteryVoltage == cur.batteryVoltage) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2872 | // 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] | 2873 | // 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] | 2874 | // as long as no bit has changed both between now and the last entry, as |
| 2875 | // well as the last entry and the one before it (so we capture any toggles). |
| 2876 | if (DEBUG) Slog.i(TAG, "ADD: rewinding back to " + mHistoryBufferLastPos); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2877 | mHistoryBuffer.setDataSize(mHistoryBufferLastPos); |
| 2878 | mHistoryBuffer.setDataPosition(mHistoryBufferLastPos); |
| 2879 | mHistoryBufferLastPos = -1; |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2880 | elapsedRealtimeMs = mHistoryLastWritten.time - mHistoryBaseTime; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2881 | // If the last written history had a wakelock tag, we need to retain it. |
| 2882 | // Note that the condition above made sure that we aren't in a case where |
| 2883 | // both it and the current history item have a wakelock tag. |
| 2884 | if (mHistoryLastWritten.wakelockTag != null) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2885 | cur.wakelockTag = cur.localWakelockTag; |
| 2886 | cur.wakelockTag.setTo(mHistoryLastWritten.wakelockTag); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2887 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 2888 | // If the last written history had a wake reason tag, we need to retain it. |
| 2889 | // Note that the condition above made sure that we aren't in a case where |
| 2890 | // both it and the current history item have a wakelock tag. |
| 2891 | if (mHistoryLastWritten.wakeReasonTag != null) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2892 | cur.wakeReasonTag = cur.localWakeReasonTag; |
| 2893 | cur.wakeReasonTag.setTo(mHistoryLastWritten.wakeReasonTag); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 2894 | } |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2895 | // If the last written history had an event, we need to retain it. |
| 2896 | // Note that the condition above made sure that we aren't in a case where |
| 2897 | // both it and the current history item have an event. |
| 2898 | if (mHistoryLastWritten.eventCode != HistoryItem.EVENT_NONE) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2899 | cur.eventCode = mHistoryLastWritten.eventCode; |
| 2900 | cur.eventTag = cur.localEventTag; |
| 2901 | cur.eventTag.setTo(mHistoryLastWritten.eventTag); |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2902 | } |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 2903 | mHistoryLastWritten.setTo(mHistoryLastLastWritten); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2904 | } |
| 2905 | |
Adam Lesinski | 4548978 | 2016-12-15 23:45:17 -0800 | [diff] [blame] | 2906 | boolean recordResetDueToOverflow = false; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2907 | final int dataSize = mHistoryBuffer.dataSize(); |
Adam Lesinski | 4548978 | 2016-12-15 23:45:17 -0800 | [diff] [blame] | 2908 | if (dataSize >= MAX_MAX_HISTORY_BUFFER*3) { |
| 2909 | // Clients can't deal with history buffers this large. This only |
| 2910 | // really happens when the device is on charger and interacted with |
| 2911 | // for long periods of time, like in retail mode. Since the device is |
| 2912 | // most likely charged, when unplugged, stats would have reset anyways. |
| 2913 | // Reset the stats and mark that we overflowed. |
| 2914 | // b/32540341 |
| 2915 | resetAllStatsLocked(); |
| 2916 | |
| 2917 | // Mark that we want to set *OVERFLOW* event and the RESET:START |
| 2918 | // events. |
| 2919 | recordResetDueToOverflow = true; |
| 2920 | |
| 2921 | } else if (dataSize >= MAX_HISTORY_BUFFER) { |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2922 | if (!mHistoryOverflow) { |
| 2923 | mHistoryOverflow = true; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2924 | addHistoryBufferLocked(elapsedRealtimeMs, uptimeMs, HistoryItem.CMD_UPDATE, cur); |
| 2925 | addHistoryBufferLocked(elapsedRealtimeMs, uptimeMs, HistoryItem.CMD_OVERFLOW, cur); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2926 | return; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2927 | } |
| 2928 | |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 2929 | // After overflow, we allow various bit-wise states to settle to 0. |
| 2930 | boolean writeAnyway = false; |
| 2931 | final int curStates = cur.states & HistoryItem.SETTLE_TO_ZERO_STATES |
| 2932 | & mActiveHistoryStates; |
| 2933 | if (mHistoryLastWritten.states != curStates) { |
| 2934 | // mActiveHistoryStates keeps track of which bits in .states are now being |
| 2935 | // forced to 0. |
| 2936 | int old = mActiveHistoryStates; |
| 2937 | mActiveHistoryStates &= curStates | ~HistoryItem.SETTLE_TO_ZERO_STATES; |
| 2938 | writeAnyway |= old != mActiveHistoryStates; |
| 2939 | } |
| 2940 | final int curStates2 = cur.states2 & HistoryItem.SETTLE_TO_ZERO_STATES2 |
| 2941 | & mActiveHistoryStates2; |
| 2942 | if (mHistoryLastWritten.states2 != curStates2) { |
| 2943 | // mActiveHistoryStates2 keeps track of which bits in .states2 are now being |
| 2944 | // forced to 0. |
| 2945 | int old = mActiveHistoryStates2; |
| 2946 | mActiveHistoryStates2 &= curStates2 | ~HistoryItem.SETTLE_TO_ZERO_STATES2; |
| 2947 | writeAnyway |= old != mActiveHistoryStates2; |
| 2948 | } |
| 2949 | |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2950 | // Once we've reached the maximum number of items, we only |
| 2951 | // record changes to the battery level and the most interesting states. |
| 2952 | // Once we've reached the maximum maximum number of items, we only |
| 2953 | // record changes to the battery level. |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 2954 | if (!writeAnyway && mHistoryLastWritten.batteryLevel == cur.batteryLevel && |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2955 | (dataSize >= MAX_MAX_HISTORY_BUFFER |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2956 | || ((mHistoryLastWritten.states^cur.states) |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 2957 | & HistoryItem.MOST_INTERESTING_STATES) == 0 |
| 2958 | || ((mHistoryLastWritten.states2^cur.states2) |
| 2959 | & HistoryItem.MOST_INTERESTING_STATES2) == 0)) { |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2960 | return; |
| 2961 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2962 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2963 | addHistoryBufferLocked(elapsedRealtimeMs, uptimeMs, HistoryItem.CMD_UPDATE, cur); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2964 | return; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2965 | } |
| 2966 | |
Adam Lesinski | 4548978 | 2016-12-15 23:45:17 -0800 | [diff] [blame] | 2967 | if (dataSize == 0 || recordResetDueToOverflow) { |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 2968 | // The history is currently empty; we need it to start with a time stamp. |
| 2969 | cur.currentTime = System.currentTimeMillis(); |
Adam Lesinski | 4548978 | 2016-12-15 23:45:17 -0800 | [diff] [blame] | 2970 | if (recordResetDueToOverflow) { |
| 2971 | addHistoryBufferLocked(elapsedRealtimeMs, uptimeMs, HistoryItem.CMD_OVERFLOW, cur); |
| 2972 | } |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 2973 | addHistoryBufferLocked(elapsedRealtimeMs, uptimeMs, HistoryItem.CMD_RESET, cur); |
| 2974 | } |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2975 | addHistoryBufferLocked(elapsedRealtimeMs, uptimeMs, HistoryItem.CMD_UPDATE, cur); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2976 | } |
| 2977 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2978 | private void addHistoryBufferLocked(long elapsedRealtimeMs, long uptimeMs, byte cmd, |
| 2979 | HistoryItem cur) { |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2980 | if (mIteratingHistory) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2981 | throw new IllegalStateException("Can't do this while iterating history!"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2982 | } |
| 2983 | mHistoryBufferLastPos = mHistoryBuffer.dataPosition(); |
| 2984 | mHistoryLastLastWritten.setTo(mHistoryLastWritten); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2985 | mHistoryLastWritten.setTo(mHistoryBaseTime + elapsedRealtimeMs, cmd, cur); |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 2986 | mHistoryLastWritten.states &= mActiveHistoryStates; |
| 2987 | mHistoryLastWritten.states2 &= mActiveHistoryStates2; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2988 | writeHistoryDelta(mHistoryBuffer, mHistoryLastWritten, mHistoryLastLastWritten); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2989 | mLastHistoryElapsedRealtime = elapsedRealtimeMs; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2990 | cur.wakelockTag = null; |
| 2991 | cur.wakeReasonTag = null; |
| 2992 | cur.eventCode = HistoryItem.EVENT_NONE; |
| 2993 | cur.eventTag = null; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2994 | if (DEBUG_HISTORY) Slog.i(TAG, "Writing history buffer: was " + mHistoryBufferLastPos |
| 2995 | + " now " + mHistoryBuffer.dataPosition() |
| 2996 | + " size is now " + mHistoryBuffer.dataSize()); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2997 | } |
| 2998 | |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 2999 | int mChangedStates = 0; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3000 | int mChangedStates2 = 0; |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 3001 | |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3002 | void addHistoryRecordLocked(long elapsedRealtimeMs, long uptimeMs) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3003 | if (mTrackRunningHistoryElapsedRealtime != 0) { |
| 3004 | final long diffElapsed = elapsedRealtimeMs - mTrackRunningHistoryElapsedRealtime; |
| 3005 | final long diffUptime = uptimeMs - mTrackRunningHistoryUptime; |
| 3006 | if (diffUptime < (diffElapsed-20)) { |
| 3007 | final long wakeElapsedTime = elapsedRealtimeMs - (diffElapsed - diffUptime); |
| 3008 | mHistoryAddTmp.setTo(mHistoryLastWritten); |
| 3009 | mHistoryAddTmp.wakelockTag = null; |
| 3010 | mHistoryAddTmp.wakeReasonTag = null; |
| 3011 | mHistoryAddTmp.eventCode = HistoryItem.EVENT_NONE; |
| 3012 | mHistoryAddTmp.states &= ~HistoryItem.STATE_CPU_RUNNING_FLAG; |
| 3013 | addHistoryRecordInnerLocked(wakeElapsedTime, uptimeMs, mHistoryAddTmp); |
| 3014 | } |
| 3015 | } |
| 3016 | mHistoryCur.states |= HistoryItem.STATE_CPU_RUNNING_FLAG; |
| 3017 | mTrackRunningHistoryElapsedRealtime = elapsedRealtimeMs; |
| 3018 | mTrackRunningHistoryUptime = uptimeMs; |
| 3019 | addHistoryRecordInnerLocked(elapsedRealtimeMs, uptimeMs, mHistoryCur); |
| 3020 | } |
| 3021 | |
| 3022 | void addHistoryRecordInnerLocked(long elapsedRealtimeMs, long uptimeMs, HistoryItem cur) { |
| 3023 | addHistoryBufferLocked(elapsedRealtimeMs, uptimeMs, cur); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 3024 | |
Dianne Hackborn | e8c88e6 | 2011-08-17 19:09:09 -0700 | [diff] [blame] | 3025 | if (!USE_OLD_HISTORY) { |
| 3026 | return; |
| 3027 | } |
| 3028 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3029 | if (!mHaveBatteryLevel || !mRecordingHistory) { |
| 3030 | return; |
| 3031 | } |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3032 | |
| 3033 | // If the current time is basically the same as the last time, |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 3034 | // and no states have since the last recorded entry changed and |
| 3035 | // are now resetting back to their original value, then just collapse |
| 3036 | // into one record. |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3037 | if (mHistoryEnd != null && mHistoryEnd.cmd == HistoryItem.CMD_UPDATE |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3038 | && (mHistoryBaseTime+elapsedRealtimeMs) < (mHistoryEnd.time+1000) |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 3039 | && ((mHistoryEnd.states^cur.states)&mChangedStates&mActiveHistoryStates) == 0 |
| 3040 | && ((mHistoryEnd.states2^cur.states2)&mChangedStates2&mActiveHistoryStates2) == 0) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3041 | // If the current is the same as the one before, then we no |
| 3042 | // longer need the entry. |
| 3043 | if (mHistoryLastEnd != null && mHistoryLastEnd.cmd == HistoryItem.CMD_UPDATE |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3044 | && (mHistoryBaseTime+elapsedRealtimeMs) < (mHistoryEnd.time+500) |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3045 | && mHistoryLastEnd.sameNonEvent(cur)) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3046 | mHistoryLastEnd.next = null; |
| 3047 | mHistoryEnd.next = mHistoryCache; |
| 3048 | mHistoryCache = mHistoryEnd; |
| 3049 | mHistoryEnd = mHistoryLastEnd; |
| 3050 | mHistoryLastEnd = null; |
| 3051 | } else { |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 3052 | mChangedStates |= mHistoryEnd.states^(cur.states&mActiveHistoryStates); |
| 3053 | mChangedStates2 |= mHistoryEnd.states^(cur.states2&mActiveHistoryStates2); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3054 | mHistoryEnd.setTo(mHistoryEnd.time, HistoryItem.CMD_UPDATE, cur); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3055 | } |
| 3056 | return; |
| 3057 | } |
| 3058 | |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 3059 | mChangedStates = 0; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3060 | mChangedStates2 = 0; |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 3061 | |
| 3062 | if (mNumHistoryItems == MAX_HISTORY_ITEMS |
| 3063 | || mNumHistoryItems == MAX_MAX_HISTORY_ITEMS) { |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3064 | addHistoryRecordLocked(elapsedRealtimeMs, HistoryItem.CMD_OVERFLOW); |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 3065 | } |
| 3066 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3067 | if (mNumHistoryItems >= MAX_HISTORY_ITEMS) { |
| 3068 | // Once we've reached the maximum number of items, we only |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 3069 | // record changes to the battery level and the most interesting states. |
| 3070 | // Once we've reached the maximum maximum number of items, we only |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3071 | // record changes to the battery level. |
| 3072 | if (mHistoryEnd != null && mHistoryEnd.batteryLevel |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3073 | == cur.batteryLevel && |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 3074 | (mNumHistoryItems >= MAX_MAX_HISTORY_ITEMS |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 3075 | || ((mHistoryEnd.states^(cur.states&mActiveHistoryStates)) |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 3076 | & HistoryItem.MOST_INTERESTING_STATES) == 0)) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3077 | return; |
| 3078 | } |
| 3079 | } |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3080 | |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3081 | addHistoryRecordLocked(elapsedRealtimeMs, HistoryItem.CMD_UPDATE); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3082 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3083 | |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 3084 | public void addHistoryEventLocked(long elapsedRealtimeMs, long uptimeMs, int code, |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3085 | String name, int uid) { |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 3086 | mHistoryCur.eventCode = code; |
| 3087 | mHistoryCur.eventTag = mHistoryCur.localEventTag; |
| 3088 | mHistoryCur.eventTag.string = name; |
| 3089 | mHistoryCur.eventTag.uid = uid; |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 3090 | addHistoryRecordLocked(elapsedRealtimeMs, uptimeMs); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3091 | } |
| 3092 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3093 | void addHistoryRecordLocked(long elapsedRealtimeMs, long uptimeMs, byte cmd, HistoryItem cur) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3094 | HistoryItem rec = mHistoryCache; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3095 | if (rec != null) { |
| 3096 | mHistoryCache = rec.next; |
| 3097 | } else { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3098 | rec = new HistoryItem(); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3099 | } |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3100 | rec.setTo(mHistoryBaseTime + elapsedRealtimeMs, cmd, cur); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3101 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3102 | addHistoryRecordLocked(rec); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3103 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3104 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3105 | void addHistoryRecordLocked(HistoryItem rec) { |
| 3106 | mNumHistoryItems++; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3107 | rec.next = null; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3108 | mHistoryLastEnd = mHistoryEnd; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3109 | if (mHistoryEnd != null) { |
| 3110 | mHistoryEnd.next = rec; |
| 3111 | mHistoryEnd = rec; |
| 3112 | } else { |
| 3113 | mHistory = mHistoryEnd = rec; |
| 3114 | } |
| 3115 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3116 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3117 | void clearHistoryLocked() { |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 3118 | if (DEBUG_HISTORY) Slog.i(TAG, "********** CLEARING HISTORY!"); |
Dianne Hackborn | e8c88e6 | 2011-08-17 19:09:09 -0700 | [diff] [blame] | 3119 | if (USE_OLD_HISTORY) { |
| 3120 | if (mHistory != null) { |
| 3121 | mHistoryEnd.next = mHistoryCache; |
| 3122 | mHistoryCache = mHistory; |
| 3123 | mHistory = mHistoryLastEnd = mHistoryEnd = null; |
| 3124 | } |
| 3125 | mNumHistoryItems = 0; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3126 | } |
Dianne Hackborn | e8c88e6 | 2011-08-17 19:09:09 -0700 | [diff] [blame] | 3127 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3128 | mHistoryBaseTime = 0; |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3129 | mLastHistoryElapsedRealtime = 0; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3130 | mTrackRunningHistoryElapsedRealtime = 0; |
| 3131 | mTrackRunningHistoryUptime = 0; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 3132 | |
| 3133 | mHistoryBuffer.setDataSize(0); |
| 3134 | mHistoryBuffer.setDataPosition(0); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3135 | mHistoryBuffer.setDataCapacity(MAX_HISTORY_BUFFER / 2); |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 3136 | mHistoryLastLastWritten.clear(); |
| 3137 | mHistoryLastWritten.clear(); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3138 | mHistoryTagPool.clear(); |
| 3139 | mNextHistoryTagIdx = 0; |
| 3140 | mNumHistoryTagChars = 0; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 3141 | mHistoryBufferLastPos = -1; |
| 3142 | mHistoryOverflow = false; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 3143 | mActiveHistoryStates = 0xffffffff; |
| 3144 | mActiveHistoryStates2 = 0xffffffff; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3145 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3146 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3147 | public void updateTimeBasesLocked(boolean unplugged, boolean screenOff, long uptime, |
| 3148 | long realtime) { |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 3149 | mOnBatteryTimeBase.setRunning(unplugged, uptime, realtime); |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 3150 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3151 | boolean unpluggedScreenOff = unplugged && screenOff; |
| 3152 | if (unpluggedScreenOff != mOnBatteryScreenOffTimeBase.isRunning()) { |
| 3153 | updateKernelWakelocksLocked(); |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 3154 | if (DEBUG_ENERGY_CPU) { |
| 3155 | Slog.d(TAG, "Updating cpu time because screen is now " + |
| 3156 | (unpluggedScreenOff ? "off" : "on")); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3157 | } |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 3158 | updateCpuTimeLocked(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3159 | mOnBatteryScreenOffTimeBase.setRunning(unpluggedScreenOff, uptime, realtime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3160 | } |
| 3161 | } |
Amith Yamasani | 3718aaa | 2009-06-09 06:32:35 -0700 | [diff] [blame] | 3162 | |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3163 | public void addIsolatedUidLocked(int isolatedUid, int appUid) { |
| 3164 | mIsolatedUids.put(isolatedUid, appUid); |
| 3165 | } |
| 3166 | |
Adam Lesinski | 61db88f | 2015-07-01 15:05:07 -0700 | [diff] [blame] | 3167 | /** |
| 3168 | * Schedules a read of the latest cpu times before removing the isolated UID. |
| 3169 | * @see #removeIsolatedUidLocked(int) |
| 3170 | */ |
| 3171 | public void scheduleRemoveIsolatedUidLocked(int isolatedUid, int appUid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3172 | int curUid = mIsolatedUids.get(isolatedUid, -1); |
| 3173 | if (curUid == appUid) { |
Adam Lesinski | 61db88f | 2015-07-01 15:05:07 -0700 | [diff] [blame] | 3174 | if (mExternalSync != null) { |
| 3175 | mExternalSync.scheduleCpuSyncDueToRemovedUid(isolatedUid); |
| 3176 | } |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3177 | } |
| 3178 | } |
| 3179 | |
Adam Lesinski | 61db88f | 2015-07-01 15:05:07 -0700 | [diff] [blame] | 3180 | /** |
| 3181 | * This should only be called after the cpu times have been read. |
| 3182 | * @see #scheduleRemoveIsolatedUidLocked(int, int) |
| 3183 | */ |
| 3184 | public void removeIsolatedUidLocked(int isolatedUid) { |
| 3185 | mIsolatedUids.delete(isolatedUid); |
| 3186 | mKernelUidCpuTimeReader.removeUid(isolatedUid); |
| 3187 | } |
| 3188 | |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3189 | public int mapUid(int uid) { |
| 3190 | int isolated = mIsolatedUids.get(uid, -1); |
| 3191 | return isolated > 0 ? isolated : uid; |
| 3192 | } |
| 3193 | |
| 3194 | public void noteEventLocked(int code, String name, int uid) { |
| 3195 | uid = mapUid(uid); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 3196 | if (!mActiveEvents.updateState(code, name, uid, 0)) { |
| 3197 | return; |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 3198 | } |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3199 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3200 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3201 | addHistoryEventLocked(elapsedRealtime, uptime, code, name, uid); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3202 | } |
| 3203 | |
Dianne Hackborn | d48954f | 2015-07-22 17:20:33 -0700 | [diff] [blame] | 3204 | boolean ensureStartClockTime(final long currentTime) { |
| 3205 | final long ABOUT_ONE_YEAR = 365*24*60*60*1000L; |
| 3206 | if (currentTime > ABOUT_ONE_YEAR && mStartClockTime < (currentTime-ABOUT_ONE_YEAR)) { |
| 3207 | // If the start clock time has changed by more than a year, then presumably |
| 3208 | // the previous time was completely bogus. So we are going to figure out a |
| 3209 | // 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] | 3210 | mStartClockTime = currentTime - (mClocks.elapsedRealtime()-(mRealtimeStart/1000)); |
Dianne Hackborn | d48954f | 2015-07-22 17:20:33 -0700 | [diff] [blame] | 3211 | return true; |
| 3212 | } |
| 3213 | return false; |
| 3214 | } |
| 3215 | |
Dianne Hackborn | 7d9eefd | 2014-08-27 18:30:31 -0700 | [diff] [blame] | 3216 | public void noteCurrentTimeChangedLocked() { |
| 3217 | final long currentTime = System.currentTimeMillis(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3218 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3219 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 7d9eefd | 2014-08-27 18:30:31 -0700 | [diff] [blame] | 3220 | recordCurrentTimeChangeLocked(currentTime, elapsedRealtime, uptime); |
Dianne Hackborn | d48954f | 2015-07-22 17:20:33 -0700 | [diff] [blame] | 3221 | ensureStartClockTime(currentTime); |
Dianne Hackborn | 7d9eefd | 2014-08-27 18:30:31 -0700 | [diff] [blame] | 3222 | } |
| 3223 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 3224 | public void noteProcessStartLocked(String name, int uid) { |
| 3225 | uid = mapUid(uid); |
| 3226 | if (isOnBattery()) { |
| 3227 | Uid u = getUidStatsLocked(uid); |
| 3228 | u.getProcessStatsLocked(name).incStartsLocked(); |
| 3229 | } |
| 3230 | if (!mActiveEvents.updateState(HistoryItem.EVENT_PROC_START, name, uid, 0)) { |
| 3231 | return; |
| 3232 | } |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 3233 | if (!mRecordAllHistory) { |
| 3234 | return; |
| 3235 | } |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3236 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3237 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 3238 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_PROC_START, name, uid); |
| 3239 | } |
| 3240 | |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 3241 | public void noteProcessCrashLocked(String name, int uid) { |
| 3242 | uid = mapUid(uid); |
| 3243 | if (isOnBattery()) { |
| 3244 | Uid u = getUidStatsLocked(uid); |
| 3245 | u.getProcessStatsLocked(name).incNumCrashesLocked(); |
| 3246 | } |
| 3247 | } |
| 3248 | |
| 3249 | public void noteProcessAnrLocked(String name, int uid) { |
| 3250 | uid = mapUid(uid); |
| 3251 | if (isOnBattery()) { |
| 3252 | Uid u = getUidStatsLocked(uid); |
| 3253 | u.getProcessStatsLocked(name).incNumAnrsLocked(); |
| 3254 | } |
| 3255 | } |
| 3256 | |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 3257 | public void noteUidProcessStateLocked(int uid, int state) { |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 3258 | uid = mapUid(uid); |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 3259 | getUidStatsLocked(uid).updateUidProcessStateLocked(state); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 3260 | } |
| 3261 | |
| 3262 | public void noteProcessFinishLocked(String name, int uid) { |
| 3263 | uid = mapUid(uid); |
| 3264 | if (!mActiveEvents.updateState(HistoryItem.EVENT_PROC_FINISH, name, uid, 0)) { |
| 3265 | return; |
| 3266 | } |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 3267 | if (!mRecordAllHistory) { |
| 3268 | return; |
| 3269 | } |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3270 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3271 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 3272 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_PROC_FINISH, name, uid); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 3273 | } |
| 3274 | |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 3275 | public void noteSyncStartLocked(String name, int uid) { |
| 3276 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3277 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3278 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 3279 | getUidStatsLocked(uid).noteStartSyncLocked(name, elapsedRealtime); |
| 3280 | if (!mActiveEvents.updateState(HistoryItem.EVENT_SYNC_START, name, uid, 0)) { |
| 3281 | return; |
| 3282 | } |
| 3283 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_SYNC_START, name, uid); |
| 3284 | } |
| 3285 | |
| 3286 | public void noteSyncFinishLocked(String name, int uid) { |
| 3287 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3288 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3289 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 3290 | getUidStatsLocked(uid).noteStopSyncLocked(name, elapsedRealtime); |
| 3291 | if (!mActiveEvents.updateState(HistoryItem.EVENT_SYNC_FINISH, name, uid, 0)) { |
| 3292 | return; |
| 3293 | } |
| 3294 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_SYNC_FINISH, name, uid); |
| 3295 | } |
| 3296 | |
| 3297 | public void noteJobStartLocked(String name, int uid) { |
| 3298 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3299 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3300 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 3301 | getUidStatsLocked(uid).noteStartJobLocked(name, elapsedRealtime); |
| 3302 | if (!mActiveEvents.updateState(HistoryItem.EVENT_JOB_START, name, uid, 0)) { |
| 3303 | return; |
| 3304 | } |
| 3305 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_JOB_START, name, uid); |
| 3306 | } |
| 3307 | |
| 3308 | public void noteJobFinishLocked(String name, int uid) { |
| 3309 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3310 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3311 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 3312 | getUidStatsLocked(uid).noteStopJobLocked(name, elapsedRealtime); |
| 3313 | if (!mActiveEvents.updateState(HistoryItem.EVENT_JOB_FINISH, name, uid, 0)) { |
| 3314 | return; |
| 3315 | } |
| 3316 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_JOB_FINISH, name, uid); |
| 3317 | } |
| 3318 | |
Dianne Hackborn | 1e38382 | 2015-04-10 14:02:33 -0700 | [diff] [blame] | 3319 | public void noteAlarmStartLocked(String name, int uid) { |
| 3320 | if (!mRecordAllHistory) { |
| 3321 | return; |
| 3322 | } |
| 3323 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3324 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3325 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 1e38382 | 2015-04-10 14:02:33 -0700 | [diff] [blame] | 3326 | if (!mActiveEvents.updateState(HistoryItem.EVENT_ALARM_START, name, uid, 0)) { |
| 3327 | return; |
| 3328 | } |
| 3329 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_ALARM_START, name, uid); |
| 3330 | } |
| 3331 | |
| 3332 | public void noteAlarmFinishLocked(String name, int uid) { |
| 3333 | if (!mRecordAllHistory) { |
| 3334 | return; |
| 3335 | } |
| 3336 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3337 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3338 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 1e38382 | 2015-04-10 14:02:33 -0700 | [diff] [blame] | 3339 | if (!mActiveEvents.updateState(HistoryItem.EVENT_ALARM_FINISH, name, uid, 0)) { |
| 3340 | return; |
| 3341 | } |
| 3342 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_ALARM_FINISH, name, uid); |
| 3343 | } |
| 3344 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3345 | private void requestWakelockCpuUpdate() { |
| 3346 | if (!mHandler.hasMessages(MSG_UPDATE_WAKELOCKS)) { |
| 3347 | Message m = mHandler.obtainMessage(MSG_UPDATE_WAKELOCKS); |
| 3348 | mHandler.sendMessageDelayed(m, DELAY_UPDATE_WAKELOCKS); |
| 3349 | } |
| 3350 | } |
| 3351 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 3352 | private void requestImmediateCpuUpdate() { |
| 3353 | mHandler.removeMessages(MSG_UPDATE_WAKELOCKS); |
| 3354 | mHandler.sendEmptyMessage(MSG_UPDATE_WAKELOCKS); |
| 3355 | } |
| 3356 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 3357 | public void setRecordAllHistoryLocked(boolean enabled) { |
| 3358 | mRecordAllHistory = enabled; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3359 | if (!enabled) { |
| 3360 | // Clear out any existing state. |
| 3361 | mActiveEvents.removeEvents(HistoryItem.EVENT_WAKE_LOCK); |
Dianne Hackborn | 1e38382 | 2015-04-10 14:02:33 -0700 | [diff] [blame] | 3362 | mActiveEvents.removeEvents(HistoryItem.EVENT_ALARM); |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 3363 | // Record the currently running processes as stopping, now that we are no |
| 3364 | // longer tracking them. |
| 3365 | HashMap<String, SparseIntArray> active = mActiveEvents.getStateForEvent( |
| 3366 | HistoryItem.EVENT_PROC); |
| 3367 | if (active != null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3368 | long mSecRealtime = mClocks.elapsedRealtime(); |
| 3369 | final long mSecUptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 3370 | for (HashMap.Entry<String, SparseIntArray> ent : active.entrySet()) { |
| 3371 | SparseIntArray uids = ent.getValue(); |
| 3372 | for (int j=0; j<uids.size(); j++) { |
| 3373 | addHistoryEventLocked(mSecRealtime, mSecUptime, |
| 3374 | HistoryItem.EVENT_PROC_FINISH, ent.getKey(), uids.keyAt(j)); |
| 3375 | } |
| 3376 | } |
| 3377 | } |
| 3378 | } else { |
| 3379 | // Record the currently running processes as starting, now that we are tracking them. |
| 3380 | HashMap<String, SparseIntArray> active = mActiveEvents.getStateForEvent( |
| 3381 | HistoryItem.EVENT_PROC); |
| 3382 | if (active != null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3383 | long mSecRealtime = mClocks.elapsedRealtime(); |
| 3384 | final long mSecUptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 3385 | for (HashMap.Entry<String, SparseIntArray> ent : active.entrySet()) { |
| 3386 | SparseIntArray uids = ent.getValue(); |
| 3387 | for (int j=0; j<uids.size(); j++) { |
| 3388 | addHistoryEventLocked(mSecRealtime, mSecUptime, |
| 3389 | HistoryItem.EVENT_PROC_START, ent.getKey(), uids.keyAt(j)); |
| 3390 | } |
| 3391 | } |
| 3392 | } |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3393 | } |
| 3394 | } |
| 3395 | |
Dianne Hackborn | 9a75543 | 2014-05-15 17:05:22 -0700 | [diff] [blame] | 3396 | public void setNoAutoReset(boolean enabled) { |
| 3397 | mNoAutoReset = enabled; |
| 3398 | } |
| 3399 | |
Amith Yamasani | 674c9bb | 2017-02-01 09:45:17 -0800 | [diff] [blame] | 3400 | public void setPretendScreenOff(boolean pretendScreenOff) { |
| 3401 | mPretendScreenOff = pretendScreenOff; |
| 3402 | noteScreenStateLocked(pretendScreenOff ? Display.STATE_OFF : Display.STATE_ON); |
| 3403 | } |
| 3404 | |
Dianne Hackborn | 9a75543 | 2014-05-15 17:05:22 -0700 | [diff] [blame] | 3405 | private String mInitialAcquireWakeName; |
| 3406 | private int mInitialAcquireWakeUid = -1; |
| 3407 | |
Dianne Hackborn | a1f1a3c | 2014-02-24 18:12:28 -0800 | [diff] [blame] | 3408 | 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] | 3409 | boolean unimportantForLogging, long elapsedRealtime, long uptime) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3410 | uid = mapUid(uid); |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 3411 | if (type == WAKE_TYPE_PARTIAL) { |
| 3412 | // Only care about partial wake locks, since full wake locks |
| 3413 | // will be canceled when the user puts the screen to sleep. |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3414 | aggregateLastWakeupUptimeLocked(uptime); |
Dianne Hackborn | fc06413 | 2014-06-02 12:42:12 -0700 | [diff] [blame] | 3415 | if (historyName == null) { |
| 3416 | historyName = name; |
| 3417 | } |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 3418 | if (mRecordAllHistory) { |
Dianne Hackborn | fc06413 | 2014-06-02 12:42:12 -0700 | [diff] [blame] | 3419 | if (mActiveEvents.updateState(HistoryItem.EVENT_WAKE_LOCK_START, historyName, |
| 3420 | uid, 0)) { |
Dianne Hackborn | 536456f | 2014-05-23 16:51:05 -0700 | [diff] [blame] | 3421 | addHistoryEventLocked(elapsedRealtime, uptime, |
Dianne Hackborn | fc06413 | 2014-06-02 12:42:12 -0700 | [diff] [blame] | 3422 | HistoryItem.EVENT_WAKE_LOCK_START, historyName, uid); |
Dianne Hackborn | 536456f | 2014-05-23 16:51:05 -0700 | [diff] [blame] | 3423 | } |
| 3424 | } |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 3425 | if (mWakeLockNesting == 0) { |
| 3426 | mHistoryCur.states |= HistoryItem.STATE_WAKE_LOCK_FLAG; |
| 3427 | if (DEBUG_HISTORY) Slog.v(TAG, "Start wake lock to: " |
| 3428 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3429 | mHistoryCur.wakelockTag = mHistoryCur.localWakelockTag; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3430 | mHistoryCur.wakelockTag.string = mInitialAcquireWakeName = historyName; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 3431 | mHistoryCur.wakelockTag.uid = mInitialAcquireWakeUid = uid; |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 3432 | mWakeLockImportant = !unimportantForLogging; |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3433 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | fc06413 | 2014-06-02 12:42:12 -0700 | [diff] [blame] | 3434 | } else if (!mWakeLockImportant && !unimportantForLogging |
| 3435 | && mHistoryLastWritten.cmd == HistoryItem.CMD_UPDATE) { |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 3436 | if (mHistoryLastWritten.wakelockTag != null) { |
| 3437 | // We'll try to update the last tag. |
| 3438 | mHistoryLastWritten.wakelockTag = null; |
| 3439 | mHistoryCur.wakelockTag = mHistoryCur.localWakelockTag; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3440 | mHistoryCur.wakelockTag.string = mInitialAcquireWakeName = historyName; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 3441 | mHistoryCur.wakelockTag.uid = mInitialAcquireWakeUid = uid; |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3442 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 3443 | } |
| 3444 | mWakeLockImportant = true; |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 3445 | } |
| 3446 | mWakeLockNesting++; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3447 | } |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3448 | if (uid >= 0) { |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 3449 | if (mOnBatteryScreenOffTimeBase.isRunning()) { |
| 3450 | // We only update the cpu time when a wake lock is acquired if the screen is off. |
| 3451 | // If the screen is on, we don't distribute the power amongst partial wakelocks. |
| 3452 | if (DEBUG_ENERGY_CPU) { |
| 3453 | Slog.d(TAG, "Updating cpu time because of +wake_lock"); |
| 3454 | } |
| 3455 | requestWakelockCpuUpdate(); |
| 3456 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3457 | getUidStatsLocked(uid).noteStartWakeLocked(pid, name, type, elapsedRealtime); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3458 | } |
| 3459 | } |
| 3460 | |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3461 | public void noteStopWakeLocked(int uid, int pid, String name, String historyName, int type, |
| 3462 | long elapsedRealtime, long uptime) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3463 | uid = mapUid(uid); |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 3464 | if (type == WAKE_TYPE_PARTIAL) { |
| 3465 | mWakeLockNesting--; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 3466 | if (mRecordAllHistory) { |
Dianne Hackborn | fc06413 | 2014-06-02 12:42:12 -0700 | [diff] [blame] | 3467 | if (historyName == null) { |
| 3468 | historyName = name; |
| 3469 | } |
| 3470 | if (mActiveEvents.updateState(HistoryItem.EVENT_WAKE_LOCK_FINISH, historyName, |
| 3471 | uid, 0)) { |
Dianne Hackborn | 536456f | 2014-05-23 16:51:05 -0700 | [diff] [blame] | 3472 | addHistoryEventLocked(elapsedRealtime, uptime, |
Dianne Hackborn | fc06413 | 2014-06-02 12:42:12 -0700 | [diff] [blame] | 3473 | HistoryItem.EVENT_WAKE_LOCK_FINISH, historyName, uid); |
Dianne Hackborn | 536456f | 2014-05-23 16:51:05 -0700 | [diff] [blame] | 3474 | } |
| 3475 | } |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 3476 | if (mWakeLockNesting == 0) { |
| 3477 | mHistoryCur.states &= ~HistoryItem.STATE_WAKE_LOCK_FLAG; |
| 3478 | if (DEBUG_HISTORY) Slog.v(TAG, "Stop wake lock to: " |
| 3479 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 3480 | mInitialAcquireWakeName = null; |
| 3481 | mInitialAcquireWakeUid = -1; |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3482 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 3483 | } |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3484 | } |
| 3485 | if (uid >= 0) { |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 3486 | if (mOnBatteryScreenOffTimeBase.isRunning()) { |
| 3487 | if (DEBUG_ENERGY_CPU) { |
| 3488 | Slog.d(TAG, "Updating cpu time because of -wake_lock"); |
| 3489 | } |
| 3490 | requestWakelockCpuUpdate(); |
| 3491 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3492 | getUidStatsLocked(uid).noteStopWakeLocked(pid, name, type, elapsedRealtime); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3493 | } |
| 3494 | } |
| 3495 | |
Dianne Hackborn | a1f1a3c | 2014-02-24 18:12:28 -0800 | [diff] [blame] | 3496 | public void noteStartWakeFromSourceLocked(WorkSource ws, int pid, String name, |
| 3497 | String historyName, int type, boolean unimportantForLogging) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3498 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3499 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 3500 | final int N = ws.size(); |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 3501 | for (int i=0; i<N; i++) { |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 3502 | noteStartWakeLocked(ws.get(i), pid, name, historyName, type, unimportantForLogging, |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3503 | elapsedRealtime, uptime); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 3504 | } |
| 3505 | } |
| 3506 | |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3507 | public void noteChangeWakelockFromSourceLocked(WorkSource ws, int pid, String name, |
| 3508 | String historyName, int type, WorkSource newWs, int newPid, String newName, |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 3509 | String newHistoryName, int newType, boolean newUnimportantForLogging) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3510 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3511 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 3512 | // For correct semantics, we start the need worksources first, so that we won't |
| 3513 | // make inappropriate history items as if all wake locks went away and new ones |
| 3514 | // appeared. This is okay because tracking of wake locks allows nesting. |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3515 | final int NN = newWs.size(); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 3516 | for (int i=0; i<NN; i++) { |
| 3517 | noteStartWakeLocked(newWs.get(i), newPid, newName, newHistoryName, newType, |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3518 | newUnimportantForLogging, elapsedRealtime, uptime); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 3519 | } |
| 3520 | final int NO = ws.size(); |
| 3521 | for (int i=0; i<NO; i++) { |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3522 | noteStopWakeLocked(ws.get(i), pid, name, historyName, type, elapsedRealtime, uptime); |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 3523 | } |
| 3524 | } |
| 3525 | |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3526 | public void noteStopWakeFromSourceLocked(WorkSource ws, int pid, String name, |
| 3527 | String historyName, int type) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3528 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3529 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 3530 | final int N = ws.size(); |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 3531 | for (int i=0; i<N; i++) { |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3532 | noteStopWakeLocked(ws.get(i), pid, name, historyName, type, elapsedRealtime, uptime); |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 3533 | } |
| 3534 | } |
| 3535 | |
Dianne Hackborn | d0db6f0 | 2016-07-18 14:14:20 -0700 | [diff] [blame] | 3536 | public void noteLongPartialWakelockStart(String name, String historyName, int uid) { |
| 3537 | uid = mapUid(uid); |
| 3538 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3539 | final long uptime = mClocks.uptimeMillis(); |
| 3540 | if (historyName == null) { |
| 3541 | historyName = name; |
| 3542 | } |
| 3543 | if (!mActiveEvents.updateState(HistoryItem.EVENT_LONG_WAKE_LOCK_START, historyName, uid, |
| 3544 | 0)) { |
| 3545 | return; |
| 3546 | } |
| 3547 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_LONG_WAKE_LOCK_START, |
| 3548 | historyName, uid); |
| 3549 | } |
| 3550 | |
| 3551 | public void noteLongPartialWakelockFinish(String name, String historyName, int uid) { |
| 3552 | uid = mapUid(uid); |
| 3553 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3554 | final long uptime = mClocks.uptimeMillis(); |
| 3555 | if (historyName == null) { |
| 3556 | historyName = name; |
| 3557 | } |
| 3558 | if (!mActiveEvents.updateState(HistoryItem.EVENT_LONG_WAKE_LOCK_FINISH, historyName, uid, |
| 3559 | 0)) { |
| 3560 | return; |
| 3561 | } |
| 3562 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_LONG_WAKE_LOCK_FINISH, |
| 3563 | historyName, uid); |
| 3564 | } |
| 3565 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3566 | void aggregateLastWakeupUptimeLocked(long uptimeMs) { |
| 3567 | if (mLastWakeupReason != null) { |
| 3568 | long deltaUptime = uptimeMs - mLastWakeupUptimeMs; |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 3569 | SamplingTimer timer = getWakeupReasonTimerLocked(mLastWakeupReason); |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 3570 | timer.add(deltaUptime * 1000, 1); // time in in microseconds |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3571 | mLastWakeupReason = null; |
| 3572 | } |
| 3573 | } |
| 3574 | |
| 3575 | public void noteWakeupReasonLocked(String reason) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3576 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3577 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 3578 | if (DEBUG_HISTORY) Slog.v(TAG, "Wakeup reason \"" + reason +"\": " |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 3579 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3580 | aggregateLastWakeupUptimeLocked(uptime); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 3581 | mHistoryCur.wakeReasonTag = mHistoryCur.localWakeReasonTag; |
| 3582 | mHistoryCur.wakeReasonTag.string = reason; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3583 | mHistoryCur.wakeReasonTag.uid = 0; |
| 3584 | mLastWakeupReason = reason; |
| 3585 | mLastWakeupUptimeMs = uptime; |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3586 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 3587 | } |
| 3588 | |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 3589 | public boolean startAddingCpuLocked() { |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 3590 | mHandler.removeMessages(MSG_UPDATE_WAKELOCKS); |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 3591 | return mOnBatteryInternal; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 3592 | } |
| 3593 | |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 3594 | public void finishAddingCpuLocked(int totalUTime, int totalSTime, int statUserTime, |
| 3595 | int statSystemTime, int statIOWaitTime, int statIrqTime, |
| 3596 | int statSoftIrqTime, int statIdleTime) { |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 3597 | if (DEBUG) Slog.d(TAG, "Adding cpu: tuser=" + totalUTime + " tsys=" + totalSTime |
| 3598 | + " user=" + statUserTime + " sys=" + statSystemTime |
| 3599 | + " io=" + statIOWaitTime + " irq=" + statIrqTime |
| 3600 | + " sirq=" + statSoftIrqTime + " idle=" + statIdleTime); |
| 3601 | mCurStepCpuUserTime += totalUTime; |
| 3602 | mCurStepCpuSystemTime += totalSTime; |
| 3603 | mCurStepStatUserTime += statUserTime; |
| 3604 | mCurStepStatSystemTime += statSystemTime; |
| 3605 | mCurStepStatIOWaitTime += statIOWaitTime; |
| 3606 | mCurStepStatIrqTime += statIrqTime; |
| 3607 | mCurStepStatSoftIrqTime += statSoftIrqTime; |
| 3608 | mCurStepStatIdleTime += statIdleTime; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 3609 | } |
| 3610 | |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3611 | public void noteProcessDiedLocked(int uid, int pid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3612 | uid = mapUid(uid); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3613 | Uid u = mUidStats.get(uid); |
| 3614 | if (u != null) { |
| 3615 | u.mPids.remove(pid); |
| 3616 | } |
| 3617 | } |
| 3618 | |
| 3619 | public long getProcessWakeTime(int uid, int pid, long realtime) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3620 | uid = mapUid(uid); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3621 | Uid u = mUidStats.get(uid); |
| 3622 | if (u != null) { |
| 3623 | Uid.Pid p = u.mPids.get(pid); |
| 3624 | if (p != null) { |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 3625 | return p.mWakeSumMs + (p.mWakeNesting > 0 ? (realtime - p.mWakeStartMs) : 0); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3626 | } |
| 3627 | } |
| 3628 | return 0; |
| 3629 | } |
| 3630 | |
| 3631 | public void reportExcessiveWakeLocked(int uid, String proc, long overTime, long usedTime) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3632 | uid = mapUid(uid); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3633 | Uid u = mUidStats.get(uid); |
| 3634 | if (u != null) { |
| 3635 | u.reportExcessiveWakeLocked(proc, overTime, usedTime); |
| 3636 | } |
| 3637 | } |
| 3638 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 3639 | public void reportExcessiveCpuLocked(int uid, String proc, long overTime, long usedTime) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3640 | uid = mapUid(uid); |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 3641 | Uid u = mUidStats.get(uid); |
| 3642 | if (u != null) { |
| 3643 | u.reportExcessiveCpuLocked(proc, overTime, usedTime); |
| 3644 | } |
| 3645 | } |
| 3646 | |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3647 | int mSensorNesting; |
| 3648 | |
| 3649 | public void noteStartSensorLocked(int uid, int sensor) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3650 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3651 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3652 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3653 | if (mSensorNesting == 0) { |
| 3654 | mHistoryCur.states |= HistoryItem.STATE_SENSOR_ON_FLAG; |
| 3655 | if (DEBUG_HISTORY) Slog.v(TAG, "Start sensor to: " |
| 3656 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3657 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3658 | } |
| 3659 | mSensorNesting++; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3660 | getUidStatsLocked(uid).noteStartSensor(sensor, elapsedRealtime); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3661 | } |
| 3662 | |
| 3663 | public void noteStopSensorLocked(int uid, int sensor) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3664 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3665 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3666 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3667 | mSensorNesting--; |
| 3668 | if (mSensorNesting == 0) { |
| 3669 | mHistoryCur.states &= ~HistoryItem.STATE_SENSOR_ON_FLAG; |
| 3670 | if (DEBUG_HISTORY) Slog.v(TAG, "Stop sensor to: " |
| 3671 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3672 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3673 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3674 | getUidStatsLocked(uid).noteStopSensor(sensor, elapsedRealtime); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3675 | } |
| 3676 | |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3677 | int mGpsNesting; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3678 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3679 | public void noteStartGpsLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3680 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3681 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3682 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3683 | if (mGpsNesting == 0) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3684 | mHistoryCur.states |= HistoryItem.STATE_GPS_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3685 | if (DEBUG_HISTORY) Slog.v(TAG, "Start GPS to: " |
| 3686 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3687 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3688 | } |
| 3689 | mGpsNesting++; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3690 | getUidStatsLocked(uid).noteStartGps(elapsedRealtime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3691 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3692 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3693 | public void noteStopGpsLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3694 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3695 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3696 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3697 | mGpsNesting--; |
| 3698 | if (mGpsNesting == 0) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3699 | mHistoryCur.states &= ~HistoryItem.STATE_GPS_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3700 | if (DEBUG_HISTORY) Slog.v(TAG, "Stop GPS to: " |
| 3701 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3702 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3703 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3704 | getUidStatsLocked(uid).noteStopGps(elapsedRealtime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3705 | } |
Amith Yamasani | 3718aaa | 2009-06-09 06:32:35 -0700 | [diff] [blame] | 3706 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 3707 | public void noteScreenStateLocked(int state) { |
Amith Yamasani | 674c9bb | 2017-02-01 09:45:17 -0800 | [diff] [blame] | 3708 | state = mPretendScreenOff ? Display.STATE_OFF : state; |
Santos Cordon | e94f050 | 2017-02-24 12:31:20 -0800 | [diff] [blame] | 3709 | |
| 3710 | // Battery stats relies on there being 4 states. To accommodate this, new states beyond the |
| 3711 | // original 4 are mapped to one of the originals. |
| 3712 | if (state > MAX_TRACKED_SCREEN_STATE) { |
| 3713 | switch (state) { |
| 3714 | case Display.STATE_VR: |
| 3715 | state = Display.STATE_ON; |
| 3716 | break; |
| 3717 | default: |
| 3718 | Slog.wtf(TAG, "Unknown screen state (not mapped): " + state); |
| 3719 | break; |
| 3720 | } |
| 3721 | } |
| 3722 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 3723 | if (mScreenState != state) { |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 3724 | recordDailyStatsIfNeededLocked(true); |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 3725 | final int oldState = mScreenState; |
| 3726 | mScreenState = state; |
| 3727 | if (DEBUG) Slog.v(TAG, "Screen state: oldState=" + Display.stateToString(oldState) |
| 3728 | + ", newState=" + Display.stateToString(state)); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3729 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 3730 | if (state != Display.STATE_UNKNOWN) { |
| 3731 | int stepState = state-1; |
Santos Cordon | e94f050 | 2017-02-24 12:31:20 -0800 | [diff] [blame] | 3732 | if ((stepState & STEP_LEVEL_MODE_SCREEN_STATE) == stepState) { |
| 3733 | mModStepMode |= (mCurStepMode & STEP_LEVEL_MODE_SCREEN_STATE) ^ stepState; |
| 3734 | mCurStepMode = (mCurStepMode & ~STEP_LEVEL_MODE_SCREEN_STATE) | stepState; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 3735 | } else { |
| 3736 | Slog.wtf(TAG, "Unexpected screen state: " + state); |
| 3737 | } |
| 3738 | } |
| 3739 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 3740 | if (state == Display.STATE_ON) { |
| 3741 | // Screen turning on. |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3742 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3743 | final long uptime = mClocks.uptimeMillis(); |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 3744 | mHistoryCur.states |= HistoryItem.STATE_SCREEN_ON_FLAG; |
| 3745 | if (DEBUG_HISTORY) Slog.v(TAG, "Screen on to: " |
| 3746 | + Integer.toHexString(mHistoryCur.states)); |
| 3747 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 3748 | mScreenOnTimer.startRunningLocked(elapsedRealtime); |
| 3749 | if (mScreenBrightnessBin >= 0) { |
| 3750 | mScreenBrightnessTimer[mScreenBrightnessBin].startRunningLocked(elapsedRealtime); |
| 3751 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3752 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 3753 | updateTimeBasesLocked(mOnBatteryTimeBase.isRunning(), false, |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3754 | mClocks.uptimeMillis() * 1000, elapsedRealtime * 1000); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 3755 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 3756 | // Fake a wake lock, so we consider the device waked as long |
| 3757 | // as the screen is on. |
| 3758 | noteStartWakeLocked(-1, -1, "screen", null, WAKE_TYPE_PARTIAL, false, |
| 3759 | elapsedRealtime, uptime); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3760 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 3761 | // Update discharge amounts. |
| 3762 | if (mOnBatteryInternal) { |
| 3763 | updateDischargeScreenLevelsLocked(false, true); |
| 3764 | } |
| 3765 | } else if (oldState == Display.STATE_ON) { |
| 3766 | // Screen turning off or dozing. |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3767 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3768 | final long uptime = mClocks.uptimeMillis(); |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 3769 | mHistoryCur.states &= ~HistoryItem.STATE_SCREEN_ON_FLAG; |
| 3770 | if (DEBUG_HISTORY) Slog.v(TAG, "Screen off to: " |
| 3771 | + Integer.toHexString(mHistoryCur.states)); |
| 3772 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 3773 | mScreenOnTimer.stopRunningLocked(elapsedRealtime); |
| 3774 | if (mScreenBrightnessBin >= 0) { |
| 3775 | mScreenBrightnessTimer[mScreenBrightnessBin].stopRunningLocked(elapsedRealtime); |
| 3776 | } |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3777 | |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3778 | noteStopWakeLocked(-1, -1, "screen", "screen", WAKE_TYPE_PARTIAL, |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 3779 | elapsedRealtime, uptime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3780 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 3781 | updateTimeBasesLocked(mOnBatteryTimeBase.isRunning(), true, |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3782 | mClocks.uptimeMillis() * 1000, elapsedRealtime * 1000); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3783 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 3784 | // Update discharge amounts. |
| 3785 | if (mOnBatteryInternal) { |
| 3786 | updateDischargeScreenLevelsLocked(true, false); |
| 3787 | } |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 3788 | } |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3789 | } |
| 3790 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3791 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3792 | public void noteScreenBrightnessLocked(int brightness) { |
| 3793 | // Bin the brightness. |
| 3794 | int bin = brightness / (256/NUM_SCREEN_BRIGHTNESS_BINS); |
| 3795 | if (bin < 0) bin = 0; |
| 3796 | else if (bin >= NUM_SCREEN_BRIGHTNESS_BINS) bin = NUM_SCREEN_BRIGHTNESS_BINS-1; |
| 3797 | if (mScreenBrightnessBin != bin) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3798 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3799 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3800 | mHistoryCur.states = (mHistoryCur.states&~HistoryItem.STATE_BRIGHTNESS_MASK) |
| 3801 | | (bin << HistoryItem.STATE_BRIGHTNESS_SHIFT); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3802 | if (DEBUG_HISTORY) Slog.v(TAG, "Screen brightness " + bin + " to: " |
| 3803 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3804 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 3805 | if (mScreenState == Display.STATE_ON) { |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3806 | if (mScreenBrightnessBin >= 0) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3807 | mScreenBrightnessTimer[mScreenBrightnessBin].stopRunningLocked(elapsedRealtime); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3808 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3809 | mScreenBrightnessTimer[bin].startRunningLocked(elapsedRealtime); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3810 | } |
| 3811 | mScreenBrightnessBin = bin; |
| 3812 | } |
| 3813 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3814 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3815 | public void noteUserActivityLocked(int uid, int event) { |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 3816 | if (mOnBatteryInternal) { |
| 3817 | uid = mapUid(uid); |
| 3818 | getUidStatsLocked(uid).noteUserActivityLocked(event); |
| 3819 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3820 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3821 | |
Dianne Hackborn | 280a64e | 2015-07-13 14:48:08 -0700 | [diff] [blame] | 3822 | public void noteWakeUpLocked(String reason, int reasonUid) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3823 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3824 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 280a64e | 2015-07-13 14:48:08 -0700 | [diff] [blame] | 3825 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_SCREEN_WAKE_UP, |
| 3826 | reason, reasonUid); |
| 3827 | } |
| 3828 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 3829 | public void noteInteractiveLocked(boolean interactive) { |
| 3830 | if (mInteractive != interactive) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3831 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 3832 | mInteractive = interactive; |
| 3833 | if (DEBUG) Slog.v(TAG, "Interactive: " + interactive); |
| 3834 | if (interactive) { |
| 3835 | mInteractiveTimer.startRunningLocked(elapsedRealtime); |
| 3836 | } else { |
| 3837 | mInteractiveTimer.stopRunningLocked(elapsedRealtime); |
| 3838 | } |
| 3839 | } |
| 3840 | } |
| 3841 | |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 3842 | public void noteConnectivityChangedLocked(int type, String extra) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3843 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3844 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 3845 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_CONNECTIVITY_CHANGED, |
| 3846 | extra, type); |
| 3847 | mNumConnectivityChange++; |
| 3848 | } |
| 3849 | |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 3850 | private void noteMobileRadioApWakeupLocked(final long elapsedRealtimeMillis, |
| 3851 | final long uptimeMillis, int uid) { |
| 3852 | uid = mapUid(uid); |
| 3853 | addHistoryEventLocked(elapsedRealtimeMillis, uptimeMillis, HistoryItem.EVENT_WAKEUP_AP, "", |
| 3854 | uid); |
| 3855 | getUidStatsLocked(uid).noteMobileRadioApWakeupLocked(); |
| 3856 | } |
| 3857 | |
Ruchi Kandoi | fa97fcf | 2016-05-13 15:10:39 -0700 | [diff] [blame] | 3858 | public void noteMobileRadioPowerState(int powerState, long timestampNs, int uid) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3859 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3860 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 3861 | if (mMobileRadioPowerState != powerState) { |
| 3862 | long realElapsedRealtimeMs; |
| 3863 | final boolean active = |
| 3864 | powerState == DataConnectionRealTimeInfo.DC_POWER_STATE_MEDIUM |
| 3865 | || powerState == DataConnectionRealTimeInfo.DC_POWER_STATE_HIGH; |
| 3866 | if (active) { |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 3867 | if (uid > 0) { |
| 3868 | noteMobileRadioApWakeupLocked(elapsedRealtime, uptime, uid); |
| 3869 | } |
| 3870 | |
Adam Lesinski | 9acfd81 | 2016-04-19 18:29:50 -0700 | [diff] [blame] | 3871 | mMobileRadioActiveStartTime = realElapsedRealtimeMs = timestampNs / (1000 * 1000); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 3872 | mHistoryCur.states |= HistoryItem.STATE_MOBILE_RADIO_ACTIVE_FLAG; |
| 3873 | } else { |
| 3874 | realElapsedRealtimeMs = timestampNs / (1000*1000); |
Dianne Hackborn | f7097a5 | 2014-05-13 09:56:14 -0700 | [diff] [blame] | 3875 | long lastUpdateTimeMs = mMobileRadioActiveStartTime; |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 3876 | if (realElapsedRealtimeMs < lastUpdateTimeMs) { |
| 3877 | Slog.wtf(TAG, "Data connection inactive timestamp " + realElapsedRealtimeMs |
| 3878 | + " is before start time " + lastUpdateTimeMs); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3879 | realElapsedRealtimeMs = elapsedRealtime; |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 3880 | } else if (realElapsedRealtimeMs < elapsedRealtime) { |
| 3881 | mMobileRadioActiveAdjustedTime.addCountLocked(elapsedRealtime |
| 3882 | - realElapsedRealtimeMs); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3883 | } |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 3884 | mHistoryCur.states &= ~HistoryItem.STATE_MOBILE_RADIO_ACTIVE_FLAG; |
| 3885 | } |
| 3886 | if (DEBUG_HISTORY) Slog.v(TAG, "Mobile network active " + active + " to: " |
| 3887 | + Integer.toHexString(mHistoryCur.states)); |
| 3888 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 3889 | mMobileRadioPowerState = powerState; |
| 3890 | if (active) { |
| 3891 | mMobileRadioActiveTimer.startRunningLocked(elapsedRealtime); |
| 3892 | mMobileRadioActivePerAppTimer.startRunningLocked(elapsedRealtime); |
| 3893 | } else { |
| 3894 | mMobileRadioActiveTimer.stopRunningLocked(realElapsedRealtimeMs); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3895 | updateMobileRadioStateLocked(realElapsedRealtimeMs, null); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 3896 | mMobileRadioActivePerAppTimer.stopRunningLocked(realElapsedRealtimeMs); |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 3897 | } |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 3898 | } |
| 3899 | } |
| 3900 | |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3901 | public void notePowerSaveMode(boolean enabled) { |
| 3902 | if (mPowerSaveModeEnabled != enabled) { |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 3903 | int stepState = enabled ? STEP_LEVEL_MODE_POWER_SAVE : 0; |
| 3904 | mModStepMode |= (mCurStepMode&STEP_LEVEL_MODE_POWER_SAVE) ^ stepState; |
| 3905 | mCurStepMode = (mCurStepMode&~STEP_LEVEL_MODE_POWER_SAVE) | stepState; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3906 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3907 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3908 | mPowerSaveModeEnabled = enabled; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3909 | if (enabled) { |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3910 | mHistoryCur.states2 |= HistoryItem.STATE2_POWER_SAVE_FLAG; |
| 3911 | if (DEBUG_HISTORY) Slog.v(TAG, "Power save mode enabled to: " |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3912 | + Integer.toHexString(mHistoryCur.states2)); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3913 | mPowerSaveModeEnabledTimer.startRunningLocked(elapsedRealtime); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3914 | } else { |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3915 | mHistoryCur.states2 &= ~HistoryItem.STATE2_POWER_SAVE_FLAG; |
| 3916 | if (DEBUG_HISTORY) Slog.v(TAG, "Power save mode disabled to: " |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3917 | + Integer.toHexString(mHistoryCur.states2)); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3918 | mPowerSaveModeEnabledTimer.stopRunningLocked(elapsedRealtime); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3919 | } |
| 3920 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 3921 | } |
| 3922 | } |
| 3923 | |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3924 | public void noteDeviceIdleModeLocked(int mode, String activeReason, int activeUid) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3925 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3926 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 3927 | boolean nowIdling = mode == DEVICE_IDLE_MODE_DEEP; |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3928 | if (mDeviceIdling && !nowIdling && activeReason == null) { |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 3929 | // We don't go out of general idling mode until explicitly taken out of |
| 3930 | // device idle through going active or significant motion. |
| 3931 | nowIdling = true; |
| 3932 | } |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3933 | boolean nowLightIdling = mode == DEVICE_IDLE_MODE_LIGHT; |
| 3934 | if (mDeviceLightIdling && !nowLightIdling && !nowIdling && activeReason == null) { |
| 3935 | // We don't go out of general light idling mode until explicitly taken out of |
| 3936 | // device idle through going active or significant motion. |
| 3937 | nowLightIdling = true; |
| 3938 | } |
| 3939 | if (activeReason != null && (mDeviceIdling || mDeviceLightIdling)) { |
| 3940 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_ACTIVE, |
| 3941 | activeReason, activeUid); |
| 3942 | } |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 3943 | if (mDeviceIdling != nowIdling) { |
| 3944 | mDeviceIdling = nowIdling; |
| 3945 | int stepState = nowIdling ? STEP_LEVEL_MODE_DEVICE_IDLE : 0; |
| 3946 | mModStepMode |= (mCurStepMode&STEP_LEVEL_MODE_DEVICE_IDLE) ^ stepState; |
| 3947 | mCurStepMode = (mCurStepMode&~STEP_LEVEL_MODE_DEVICE_IDLE) | stepState; |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3948 | if (nowIdling) { |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 3949 | mDeviceIdlingTimer.startRunningLocked(elapsedRealtime); |
| 3950 | } else { |
| 3951 | mDeviceIdlingTimer.stopRunningLocked(elapsedRealtime); |
| 3952 | } |
| 3953 | } |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3954 | if (mDeviceLightIdling != nowLightIdling) { |
| 3955 | mDeviceLightIdling = nowLightIdling; |
| 3956 | if (nowLightIdling) { |
| 3957 | mDeviceLightIdlingTimer.startRunningLocked(elapsedRealtime); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3958 | } else { |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3959 | mDeviceLightIdlingTimer.stopRunningLocked(elapsedRealtime); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3960 | } |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3961 | } |
| 3962 | if (mDeviceIdleMode != mode) { |
| 3963 | mHistoryCur.states2 = (mHistoryCur.states2 & ~HistoryItem.STATE2_DEVICE_IDLE_MASK) |
| 3964 | | (mode << HistoryItem.STATE2_DEVICE_IDLE_SHIFT); |
| 3965 | if (DEBUG_HISTORY) Slog.v(TAG, "Device idle mode changed to: " |
| 3966 | + Integer.toHexString(mHistoryCur.states2)); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3967 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3968 | long lastDuration = elapsedRealtime - mLastIdleTimeStart; |
| 3969 | mLastIdleTimeStart = elapsedRealtime; |
| 3970 | if (mDeviceIdleMode == DEVICE_IDLE_MODE_LIGHT) { |
| 3971 | if (lastDuration > mLongestLightIdleTime) { |
| 3972 | mLongestLightIdleTime = lastDuration; |
| 3973 | } |
| 3974 | mDeviceIdleModeLightTimer.stopRunningLocked(elapsedRealtime); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 3975 | } else if (mDeviceIdleMode == DEVICE_IDLE_MODE_DEEP) { |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3976 | if (lastDuration > mLongestFullIdleTime) { |
| 3977 | mLongestFullIdleTime = lastDuration; |
| 3978 | } |
| 3979 | mDeviceIdleModeFullTimer.stopRunningLocked(elapsedRealtime); |
| 3980 | } |
| 3981 | if (mode == DEVICE_IDLE_MODE_LIGHT) { |
| 3982 | mDeviceIdleModeLightTimer.startRunningLocked(elapsedRealtime); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 3983 | } else if (mode == DEVICE_IDLE_MODE_DEEP) { |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3984 | mDeviceIdleModeFullTimer.startRunningLocked(elapsedRealtime); |
| 3985 | } |
| 3986 | mDeviceIdleMode = mode; |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3987 | } |
| 3988 | } |
| 3989 | |
| 3990 | public void notePackageInstalledLocked(String pkgName, int versionCode) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3991 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3992 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3993 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_PACKAGE_INSTALLED, |
| 3994 | pkgName, versionCode); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 3995 | PackageChange pc = new PackageChange(); |
| 3996 | pc.mPackageName = pkgName; |
| 3997 | pc.mUpdate = true; |
| 3998 | pc.mVersionCode = versionCode; |
| 3999 | addPackageChange(pc); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4000 | } |
| 4001 | |
| 4002 | public void notePackageUninstalledLocked(String pkgName) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4003 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4004 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4005 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_PACKAGE_UNINSTALLED, |
| 4006 | pkgName, 0); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 4007 | PackageChange pc = new PackageChange(); |
| 4008 | pc.mPackageName = pkgName; |
| 4009 | pc.mUpdate = true; |
| 4010 | addPackageChange(pc); |
| 4011 | } |
| 4012 | |
| 4013 | private void addPackageChange(PackageChange pc) { |
| 4014 | if (mDailyPackageChanges == null) { |
| 4015 | mDailyPackageChanges = new ArrayList<>(); |
| 4016 | } |
| 4017 | mDailyPackageChanges.add(pc); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4018 | } |
| 4019 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4020 | public void notePhoneOnLocked() { |
| 4021 | if (!mPhoneOn) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4022 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4023 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 4024 | mHistoryCur.states2 |= HistoryItem.STATE2_PHONE_IN_CALL_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4025 | if (DEBUG_HISTORY) Slog.v(TAG, "Phone on to: " |
| 4026 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 4027 | addHistoryRecordLocked(elapsedRealtime, uptime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4028 | mPhoneOn = true; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4029 | mPhoneOnTimer.startRunningLocked(elapsedRealtime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4030 | } |
| 4031 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4032 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4033 | public void notePhoneOffLocked() { |
| 4034 | if (mPhoneOn) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4035 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4036 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 4037 | mHistoryCur.states2 &= ~HistoryItem.STATE2_PHONE_IN_CALL_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4038 | if (DEBUG_HISTORY) Slog.v(TAG, "Phone off to: " |
| 4039 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 4040 | addHistoryRecordLocked(elapsedRealtime, uptime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4041 | mPhoneOn = false; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4042 | mPhoneOnTimer.stopRunningLocked(elapsedRealtime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4043 | } |
| 4044 | } |
Amith Yamasani | 32dbefd | 2009-06-19 09:21:17 -0700 | [diff] [blame] | 4045 | |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 4046 | void stopAllPhoneSignalStrengthTimersLocked(int except) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4047 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 4048 | for (int i = 0; i < SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 4049 | if (i == except) { |
| 4050 | continue; |
| 4051 | } |
| 4052 | while (mPhoneSignalStrengthsTimer[i].isRunningLocked()) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4053 | mPhoneSignalStrengthsTimer[i].stopRunningLocked(elapsedRealtime); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 4054 | } |
| 4055 | } |
| 4056 | } |
| 4057 | |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 4058 | private int fixPhoneServiceState(int state, int signalBin) { |
| 4059 | if (mPhoneSimStateRaw == TelephonyManager.SIM_STATE_ABSENT) { |
| 4060 | // In this case we will always be STATE_OUT_OF_SERVICE, so need |
| 4061 | // to infer that we are scanning from other data. |
| 4062 | if (state == ServiceState.STATE_OUT_OF_SERVICE |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 4063 | && signalBin > SignalStrength.SIGNAL_STRENGTH_NONE_OR_UNKNOWN) { |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 4064 | state = ServiceState.STATE_IN_SERVICE; |
| 4065 | } |
| 4066 | } |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 4067 | |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 4068 | return state; |
| 4069 | } |
| 4070 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4071 | private void updateAllPhoneStateLocked(int state, int simState, int strengthBin) { |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 4072 | boolean scanning = false; |
| 4073 | boolean newHistory = false; |
| 4074 | |
| 4075 | mPhoneServiceStateRaw = state; |
| 4076 | mPhoneSimStateRaw = simState; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4077 | mPhoneSignalStrengthBinRaw = strengthBin; |
| 4078 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4079 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4080 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 4081 | |
| 4082 | if (simState == TelephonyManager.SIM_STATE_ABSENT) { |
| 4083 | // In this case we will always be STATE_OUT_OF_SERVICE, so need |
| 4084 | // to infer that we are scanning from other data. |
| 4085 | if (state == ServiceState.STATE_OUT_OF_SERVICE |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4086 | && strengthBin > SignalStrength.SIGNAL_STRENGTH_NONE_OR_UNKNOWN) { |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 4087 | state = ServiceState.STATE_IN_SERVICE; |
| 4088 | } |
| 4089 | } |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 4090 | |
| 4091 | // If the phone is powered off, stop all timers. |
| 4092 | if (state == ServiceState.STATE_POWER_OFF) { |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4093 | strengthBin = -1; |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 4094 | |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 4095 | // If we are in service, make sure the correct signal string timer is running. |
| 4096 | } else if (state == ServiceState.STATE_IN_SERVICE) { |
| 4097 | // Bin will be changed below. |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 4098 | |
| 4099 | // If we're out of service, we are in the lowest signal strength |
| 4100 | // bin and have the scanning bit set. |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 4101 | } else if (state == ServiceState.STATE_OUT_OF_SERVICE) { |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 4102 | scanning = true; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4103 | strengthBin = SignalStrength.SIGNAL_STRENGTH_NONE_OR_UNKNOWN; |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 4104 | if (!mPhoneSignalScanningTimer.isRunningLocked()) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4105 | mHistoryCur.states |= HistoryItem.STATE_PHONE_SCANNING_FLAG; |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 4106 | newHistory = true; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4107 | if (DEBUG_HISTORY) Slog.v(TAG, "Phone started scanning to: " |
| 4108 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4109 | mPhoneSignalScanningTimer.startRunningLocked(elapsedRealtime); |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 4110 | } |
| 4111 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4112 | |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 4113 | if (!scanning) { |
| 4114 | // If we are no longer scanning, then stop the scanning timer. |
| 4115 | if (mPhoneSignalScanningTimer.isRunningLocked()) { |
| 4116 | mHistoryCur.states &= ~HistoryItem.STATE_PHONE_SCANNING_FLAG; |
| 4117 | if (DEBUG_HISTORY) Slog.v(TAG, "Phone stopped scanning to: " |
| 4118 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 4119 | newHistory = true; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4120 | mPhoneSignalScanningTimer.stopRunningLocked(elapsedRealtime); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 4121 | } |
| 4122 | } |
| 4123 | |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4124 | if (mPhoneServiceState != state) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4125 | mHistoryCur.states = (mHistoryCur.states&~HistoryItem.STATE_PHONE_STATE_MASK) |
| 4126 | | (state << HistoryItem.STATE_PHONE_STATE_SHIFT); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 4127 | if (DEBUG_HISTORY) Slog.v(TAG, "Phone state " + state + " to: " |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4128 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 4129 | newHistory = true; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4130 | mPhoneServiceState = state; |
| 4131 | } |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 4132 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4133 | if (mPhoneSignalStrengthBin != strengthBin) { |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 4134 | if (mPhoneSignalStrengthBin >= 0) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4135 | mPhoneSignalStrengthsTimer[mPhoneSignalStrengthBin].stopRunningLocked( |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4136 | elapsedRealtime); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 4137 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4138 | if (strengthBin >= 0) { |
| 4139 | if (!mPhoneSignalStrengthsTimer[strengthBin].isRunningLocked()) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4140 | mPhoneSignalStrengthsTimer[strengthBin].startRunningLocked(elapsedRealtime); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 4141 | } |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 4142 | mHistoryCur.states = (mHistoryCur.states&~HistoryItem.STATE_PHONE_SIGNAL_STRENGTH_MASK) |
| 4143 | | (strengthBin << HistoryItem.STATE_PHONE_SIGNAL_STRENGTH_SHIFT); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4144 | if (DEBUG_HISTORY) Slog.v(TAG, "Signal strength " + strengthBin + " to: " |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 4145 | + Integer.toHexString(mHistoryCur.states)); |
| 4146 | newHistory = true; |
| 4147 | } else { |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 4148 | stopAllPhoneSignalStrengthTimersLocked(-1); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 4149 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4150 | mPhoneSignalStrengthBin = strengthBin; |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 4151 | } |
| 4152 | |
| 4153 | if (newHistory) { |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 4154 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 4155 | } |
| 4156 | } |
| 4157 | |
| 4158 | /** |
| 4159 | * Telephony stack updates the phone state. |
| 4160 | * @param state phone state from ServiceState.getState() |
| 4161 | */ |
| 4162 | public void notePhoneStateLocked(int state, int simState) { |
| 4163 | updateAllPhoneStateLocked(state, simState, mPhoneSignalStrengthBinRaw); |
Amith Yamasani | 32dbefd | 2009-06-19 09:21:17 -0700 | [diff] [blame] | 4164 | } |
| 4165 | |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 4166 | public void notePhoneSignalStrengthLocked(SignalStrength signalStrength) { |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4167 | // Bin the strength. |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 4168 | int bin = signalStrength.getLevel(); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 4169 | updateAllPhoneStateLocked(mPhoneServiceStateRaw, mPhoneSimStateRaw, bin); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4170 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4171 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4172 | public void notePhoneDataConnectionStateLocked(int dataType, boolean hasData) { |
| 4173 | int bin = DATA_CONNECTION_NONE; |
| 4174 | if (hasData) { |
| 4175 | switch (dataType) { |
| 4176 | case TelephonyManager.NETWORK_TYPE_EDGE: |
| 4177 | bin = DATA_CONNECTION_EDGE; |
| 4178 | break; |
| 4179 | case TelephonyManager.NETWORK_TYPE_GPRS: |
| 4180 | bin = DATA_CONNECTION_GPRS; |
| 4181 | break; |
| 4182 | case TelephonyManager.NETWORK_TYPE_UMTS: |
| 4183 | bin = DATA_CONNECTION_UMTS; |
| 4184 | break; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4185 | case TelephonyManager.NETWORK_TYPE_CDMA: |
| 4186 | bin = DATA_CONNECTION_CDMA; |
| 4187 | break; |
| 4188 | case TelephonyManager.NETWORK_TYPE_EVDO_0: |
| 4189 | bin = DATA_CONNECTION_EVDO_0; |
| 4190 | break; |
| 4191 | case TelephonyManager.NETWORK_TYPE_EVDO_A: |
| 4192 | bin = DATA_CONNECTION_EVDO_A; |
| 4193 | break; |
| 4194 | case TelephonyManager.NETWORK_TYPE_1xRTT: |
| 4195 | bin = DATA_CONNECTION_1xRTT; |
| 4196 | break; |
| 4197 | case TelephonyManager.NETWORK_TYPE_HSDPA: |
| 4198 | bin = DATA_CONNECTION_HSDPA; |
| 4199 | break; |
| 4200 | case TelephonyManager.NETWORK_TYPE_HSUPA: |
| 4201 | bin = DATA_CONNECTION_HSUPA; |
| 4202 | break; |
| 4203 | case TelephonyManager.NETWORK_TYPE_HSPA: |
| 4204 | bin = DATA_CONNECTION_HSPA; |
| 4205 | break; |
| 4206 | case TelephonyManager.NETWORK_TYPE_IDEN: |
| 4207 | bin = DATA_CONNECTION_IDEN; |
| 4208 | break; |
| 4209 | case TelephonyManager.NETWORK_TYPE_EVDO_B: |
| 4210 | bin = DATA_CONNECTION_EVDO_B; |
| 4211 | break; |
Robert Greenwalt | 962a990 | 2010-11-02 11:10:25 -0700 | [diff] [blame] | 4212 | case TelephonyManager.NETWORK_TYPE_LTE: |
| 4213 | bin = DATA_CONNECTION_LTE; |
| 4214 | break; |
| 4215 | case TelephonyManager.NETWORK_TYPE_EHRPD: |
| 4216 | bin = DATA_CONNECTION_EHRPD; |
| 4217 | break; |
Patrick Tjin | b71703c | 2013-11-06 09:27:03 -0800 | [diff] [blame] | 4218 | case TelephonyManager.NETWORK_TYPE_HSPAP: |
| 4219 | bin = DATA_CONNECTION_HSPAP; |
| 4220 | break; |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4221 | default: |
| 4222 | bin = DATA_CONNECTION_OTHER; |
| 4223 | break; |
| 4224 | } |
| 4225 | } |
Amith Yamasani | 3718aaa | 2009-06-09 06:32:35 -0700 | [diff] [blame] | 4226 | if (DEBUG) Log.i(TAG, "Phone Data Connection -> " + dataType + " = " + hasData); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4227 | if (mPhoneDataConnectionType != bin) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4228 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4229 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4230 | mHistoryCur.states = (mHistoryCur.states&~HistoryItem.STATE_DATA_CONNECTION_MASK) |
| 4231 | | (bin << HistoryItem.STATE_DATA_CONNECTION_SHIFT); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4232 | if (DEBUG_HISTORY) Slog.v(TAG, "Data connection " + bin + " to: " |
| 4233 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 4234 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4235 | if (mPhoneDataConnectionType >= 0) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4236 | mPhoneDataConnectionsTimer[mPhoneDataConnectionType].stopRunningLocked( |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4237 | elapsedRealtime); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4238 | } |
| 4239 | mPhoneDataConnectionType = bin; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4240 | mPhoneDataConnectionsTimer[bin].startRunningLocked(elapsedRealtime); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4241 | } |
| 4242 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4243 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 4244 | public void noteWifiOnLocked() { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4245 | if (!mWifiOn) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4246 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4247 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 4248 | mHistoryCur.states2 |= HistoryItem.STATE2_WIFI_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4249 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI on to: " |
| 4250 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 4251 | addHistoryRecordLocked(elapsedRealtime, uptime); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4252 | mWifiOn = true; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4253 | mWifiOnTimer.startRunningLocked(elapsedRealtime); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 4254 | scheduleSyncExternalStatsLocked("wifi-off", ExternalStatsSync.UPDATE_WIFI); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4255 | } |
| 4256 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4257 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 4258 | public void noteWifiOffLocked() { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4259 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4260 | final long uptime = mClocks.uptimeMillis(); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4261 | if (mWifiOn) { |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 4262 | mHistoryCur.states2 &= ~HistoryItem.STATE2_WIFI_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4263 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI off to: " |
| 4264 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 4265 | addHistoryRecordLocked(elapsedRealtime, uptime); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4266 | mWifiOn = false; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4267 | mWifiOnTimer.stopRunningLocked(elapsedRealtime); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 4268 | scheduleSyncExternalStatsLocked("wifi-on", ExternalStatsSync.UPDATE_WIFI); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4269 | } |
| 4270 | } |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 4271 | |
| 4272 | public void noteAudioOnLocked(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(); |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 4276 | if (mAudioOnNesting == 0) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4277 | mHistoryCur.states |= HistoryItem.STATE_AUDIO_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4278 | if (DEBUG_HISTORY) Slog.v(TAG, "Audio on to: " |
| 4279 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 4280 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4281 | mAudioOnTimer.startRunningLocked(elapsedRealtime); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 4282 | } |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 4283 | mAudioOnNesting++; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4284 | getUidStatsLocked(uid).noteAudioTurnedOnLocked(elapsedRealtime); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 4285 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4286 | |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 4287 | public void noteAudioOffLocked(int uid) { |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 4288 | if (mAudioOnNesting == 0) { |
| 4289 | return; |
| 4290 | } |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4291 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4292 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4293 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 4294 | if (--mAudioOnNesting == 0) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4295 | mHistoryCur.states &= ~HistoryItem.STATE_AUDIO_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4296 | if (DEBUG_HISTORY) Slog.v(TAG, "Audio off to: " |
| 4297 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 4298 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4299 | mAudioOnTimer.stopRunningLocked(elapsedRealtime); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 4300 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4301 | getUidStatsLocked(uid).noteAudioTurnedOffLocked(elapsedRealtime); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 4302 | } |
| 4303 | |
| 4304 | public void noteVideoOnLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4305 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4306 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4307 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 4308 | if (mVideoOnNesting == 0) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 4309 | mHistoryCur.states2 |= HistoryItem.STATE2_VIDEO_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4310 | if (DEBUG_HISTORY) Slog.v(TAG, "Video on to: " |
| 4311 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 4312 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4313 | mVideoOnTimer.startRunningLocked(elapsedRealtime); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 4314 | } |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 4315 | mVideoOnNesting++; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4316 | getUidStatsLocked(uid).noteVideoTurnedOnLocked(elapsedRealtime); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 4317 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4318 | |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 4319 | public void noteVideoOffLocked(int uid) { |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 4320 | if (mVideoOnNesting == 0) { |
| 4321 | return; |
| 4322 | } |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4323 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4324 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4325 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 4326 | if (--mVideoOnNesting == 0) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 4327 | mHistoryCur.states2 &= ~HistoryItem.STATE2_VIDEO_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4328 | if (DEBUG_HISTORY) Slog.v(TAG, "Video off to: " |
| 4329 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 4330 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4331 | mVideoOnTimer.stopRunningLocked(elapsedRealtime); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 4332 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4333 | getUidStatsLocked(uid).noteVideoTurnedOffLocked(elapsedRealtime); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 4334 | } |
| 4335 | |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 4336 | public void noteResetAudioLocked() { |
| 4337 | if (mAudioOnNesting > 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4338 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4339 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 4340 | mAudioOnNesting = 0; |
| 4341 | mHistoryCur.states &= ~HistoryItem.STATE_AUDIO_ON_FLAG; |
| 4342 | if (DEBUG_HISTORY) Slog.v(TAG, "Audio off to: " |
| 4343 | + Integer.toHexString(mHistoryCur.states)); |
| 4344 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 4345 | mAudioOnTimer.stopAllRunningLocked(elapsedRealtime); |
| 4346 | for (int i=0; i<mUidStats.size(); i++) { |
| 4347 | BatteryStatsImpl.Uid uid = mUidStats.valueAt(i); |
| 4348 | uid.noteResetAudioLocked(elapsedRealtime); |
| 4349 | } |
| 4350 | } |
| 4351 | } |
| 4352 | |
| 4353 | public void noteResetVideoLocked() { |
| 4354 | if (mVideoOnNesting > 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4355 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4356 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 4357 | mAudioOnNesting = 0; |
| 4358 | mHistoryCur.states2 &= ~HistoryItem.STATE2_VIDEO_ON_FLAG; |
| 4359 | if (DEBUG_HISTORY) Slog.v(TAG, "Video off to: " |
| 4360 | + Integer.toHexString(mHistoryCur.states)); |
| 4361 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 4362 | mVideoOnTimer.stopAllRunningLocked(elapsedRealtime); |
| 4363 | for (int i=0; i<mUidStats.size(); i++) { |
| 4364 | BatteryStatsImpl.Uid uid = mUidStats.valueAt(i); |
| 4365 | uid.noteResetVideoLocked(elapsedRealtime); |
| 4366 | } |
| 4367 | } |
| 4368 | } |
| 4369 | |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 4370 | public void noteActivityResumedLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4371 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4372 | getUidStatsLocked(uid).noteActivityResumedLocked(mClocks.elapsedRealtime()); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 4373 | } |
| 4374 | |
| 4375 | public void noteActivityPausedLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4376 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4377 | getUidStatsLocked(uid).noteActivityPausedLocked(mClocks.elapsedRealtime()); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 4378 | } |
| 4379 | |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 4380 | public void noteVibratorOnLocked(int uid, long durationMillis) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4381 | uid = mapUid(uid); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 4382 | getUidStatsLocked(uid).noteVibratorOnLocked(durationMillis); |
| 4383 | } |
| 4384 | |
| 4385 | public void noteVibratorOffLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4386 | uid = mapUid(uid); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 4387 | getUidStatsLocked(uid).noteVibratorOffLocked(); |
| 4388 | } |
| 4389 | |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 4390 | public void noteFlashlightOnLocked(int uid) { |
| 4391 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4392 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4393 | final long uptime = mClocks.uptimeMillis(); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 4394 | if (mFlashlightOnNesting++ == 0) { |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 4395 | mHistoryCur.states2 |= HistoryItem.STATE2_FLASHLIGHT_FLAG; |
| 4396 | if (DEBUG_HISTORY) Slog.v(TAG, "Flashlight on to: " |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 4397 | + Integer.toHexString(mHistoryCur.states2)); |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 4398 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 4399 | mFlashlightOnTimer.startRunningLocked(elapsedRealtime); |
| 4400 | } |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 4401 | getUidStatsLocked(uid).noteFlashlightTurnedOnLocked(elapsedRealtime); |
| 4402 | } |
| 4403 | |
| 4404 | public void noteFlashlightOffLocked(int uid) { |
| 4405 | if (mFlashlightOnNesting == 0) { |
| 4406 | return; |
| 4407 | } |
| 4408 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4409 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4410 | final long uptime = mClocks.uptimeMillis(); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 4411 | if (--mFlashlightOnNesting == 0) { |
| 4412 | mHistoryCur.states2 &= ~HistoryItem.STATE2_FLASHLIGHT_FLAG; |
| 4413 | if (DEBUG_HISTORY) Slog.v(TAG, "Flashlight off to: " |
| 4414 | + Integer.toHexString(mHistoryCur.states2)); |
| 4415 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 4416 | mFlashlightOnTimer.stopRunningLocked(elapsedRealtime); |
| 4417 | } |
| 4418 | getUidStatsLocked(uid).noteFlashlightTurnedOffLocked(elapsedRealtime); |
| 4419 | } |
| 4420 | |
| 4421 | public void noteCameraOnLocked(int uid) { |
| 4422 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4423 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4424 | final long uptime = mClocks.uptimeMillis(); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 4425 | if (mCameraOnNesting++ == 0) { |
| 4426 | mHistoryCur.states2 |= HistoryItem.STATE2_CAMERA_FLAG; |
| 4427 | if (DEBUG_HISTORY) Slog.v(TAG, "Camera on to: " |
| 4428 | + Integer.toHexString(mHistoryCur.states2)); |
| 4429 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 4430 | mCameraOnTimer.startRunningLocked(elapsedRealtime); |
| 4431 | } |
| 4432 | getUidStatsLocked(uid).noteCameraTurnedOnLocked(elapsedRealtime); |
| 4433 | } |
| 4434 | |
| 4435 | public void noteCameraOffLocked(int uid) { |
| 4436 | if (mCameraOnNesting == 0) { |
| 4437 | return; |
| 4438 | } |
| 4439 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4440 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4441 | final long uptime = mClocks.uptimeMillis(); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 4442 | if (--mCameraOnNesting == 0) { |
| 4443 | mHistoryCur.states2 &= ~HistoryItem.STATE2_CAMERA_FLAG; |
| 4444 | if (DEBUG_HISTORY) Slog.v(TAG, "Camera off to: " |
| 4445 | + Integer.toHexString(mHistoryCur.states2)); |
| 4446 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 4447 | mCameraOnTimer.stopRunningLocked(elapsedRealtime); |
| 4448 | } |
| 4449 | getUidStatsLocked(uid).noteCameraTurnedOffLocked(elapsedRealtime); |
| 4450 | } |
| 4451 | |
| 4452 | public void noteResetCameraLocked() { |
| 4453 | if (mCameraOnNesting > 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4454 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4455 | final long uptime = mClocks.uptimeMillis(); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 4456 | mCameraOnNesting = 0; |
| 4457 | mHistoryCur.states2 &= ~HistoryItem.STATE2_CAMERA_FLAG; |
| 4458 | if (DEBUG_HISTORY) Slog.v(TAG, "Camera off to: " |
| 4459 | + Integer.toHexString(mHistoryCur.states2)); |
| 4460 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 4461 | mCameraOnTimer.stopAllRunningLocked(elapsedRealtime); |
| 4462 | for (int i=0; i<mUidStats.size(); i++) { |
| 4463 | BatteryStatsImpl.Uid uid = mUidStats.valueAt(i); |
| 4464 | uid.noteResetCameraLocked(elapsedRealtime); |
| 4465 | } |
| 4466 | } |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 4467 | } |
| 4468 | |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 4469 | public void noteResetFlashlightLocked() { |
| 4470 | if (mFlashlightOnNesting > 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4471 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4472 | final long uptime = mClocks.uptimeMillis(); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 4473 | mFlashlightOnNesting = 0; |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 4474 | mHistoryCur.states2 &= ~HistoryItem.STATE2_FLASHLIGHT_FLAG; |
| 4475 | if (DEBUG_HISTORY) Slog.v(TAG, "Flashlight off to: " |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 4476 | + Integer.toHexString(mHistoryCur.states2)); |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 4477 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 4478 | mFlashlightOnTimer.stopAllRunningLocked(elapsedRealtime); |
| 4479 | for (int i=0; i<mUidStats.size(); i++) { |
| 4480 | BatteryStatsImpl.Uid uid = mUidStats.valueAt(i); |
| 4481 | uid.noteResetFlashlightLocked(elapsedRealtime); |
| 4482 | } |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 4483 | } |
| 4484 | } |
| 4485 | |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 4486 | private void noteBluetoothScanStartedLocked(int uid) { |
| 4487 | uid = mapUid(uid); |
| 4488 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 4489 | final long uptime = SystemClock.uptimeMillis(); |
| 4490 | if (mBluetoothScanNesting == 0) { |
| 4491 | mHistoryCur.states2 |= HistoryItem.STATE2_BLUETOOTH_SCAN_FLAG; |
| 4492 | if (DEBUG_HISTORY) Slog.v(TAG, "BLE scan started for: " |
| 4493 | + Integer.toHexString(mHistoryCur.states2)); |
| 4494 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Adam Lesinski | d9b99be | 2016-03-30 16:58:51 -0700 | [diff] [blame] | 4495 | mBluetoothScanTimer.startRunningLocked(elapsedRealtime); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 4496 | } |
| 4497 | mBluetoothScanNesting++; |
| 4498 | getUidStatsLocked(uid).noteBluetoothScanStartedLocked(elapsedRealtime); |
| 4499 | } |
| 4500 | |
| 4501 | public void noteBluetoothScanStartedFromSourceLocked(WorkSource ws) { |
| 4502 | final int N = ws.size(); |
| 4503 | for (int i = 0; i < N; i++) { |
| 4504 | noteBluetoothScanStartedLocked(ws.get(i)); |
| 4505 | } |
| 4506 | } |
| 4507 | |
| 4508 | private void noteBluetoothScanStoppedLocked(int uid) { |
| 4509 | uid = mapUid(uid); |
| 4510 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 4511 | final long uptime = SystemClock.uptimeMillis(); |
| 4512 | mBluetoothScanNesting--; |
| 4513 | if (mBluetoothScanNesting == 0) { |
| 4514 | mHistoryCur.states2 &= ~HistoryItem.STATE2_BLUETOOTH_SCAN_FLAG; |
| 4515 | if (DEBUG_HISTORY) Slog.v(TAG, "BLE scan stopped for: " |
| 4516 | + Integer.toHexString(mHistoryCur.states2)); |
| 4517 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Adam Lesinski | d9b99be | 2016-03-30 16:58:51 -0700 | [diff] [blame] | 4518 | mBluetoothScanTimer.stopRunningLocked(elapsedRealtime); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 4519 | } |
| 4520 | getUidStatsLocked(uid).noteBluetoothScanStoppedLocked(elapsedRealtime); |
| 4521 | } |
| 4522 | |
| 4523 | public void noteBluetoothScanStoppedFromSourceLocked(WorkSource ws) { |
| 4524 | final int N = ws.size(); |
| 4525 | for (int i = 0; i < N; i++) { |
| 4526 | noteBluetoothScanStoppedLocked(ws.get(i)); |
| 4527 | } |
| 4528 | } |
| 4529 | |
| 4530 | public void noteResetBluetoothScanLocked() { |
| 4531 | if (mBluetoothScanNesting > 0) { |
| 4532 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 4533 | final long uptime = SystemClock.uptimeMillis(); |
| 4534 | mBluetoothScanNesting = 0; |
| 4535 | mHistoryCur.states2 &= ~HistoryItem.STATE2_BLUETOOTH_SCAN_FLAG; |
| 4536 | if (DEBUG_HISTORY) Slog.v(TAG, "BLE can stopped for: " |
| 4537 | + Integer.toHexString(mHistoryCur.states2)); |
| 4538 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 4539 | mBluetoothScanTimer.stopAllRunningLocked(elapsedRealtime); |
| 4540 | for (int i=0; i<mUidStats.size(); i++) { |
| 4541 | BatteryStatsImpl.Uid uid = mUidStats.valueAt(i); |
| 4542 | uid.noteResetBluetoothScanLocked(elapsedRealtime); |
| 4543 | } |
| 4544 | } |
| 4545 | } |
| 4546 | |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 4547 | private void noteWifiRadioApWakeupLocked(final long elapsedRealtimeMillis, |
| 4548 | final long uptimeMillis, int uid) { |
| 4549 | uid = mapUid(uid); |
| 4550 | addHistoryEventLocked(elapsedRealtimeMillis, uptimeMillis, HistoryItem.EVENT_WAKEUP_AP, "", |
| 4551 | uid); |
| 4552 | getUidStatsLocked(uid).noteWifiRadioApWakeupLocked(); |
| 4553 | } |
| 4554 | |
| 4555 | public void noteWifiRadioPowerState(int powerState, long timestampNs, int uid) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4556 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4557 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 4558 | if (mWifiRadioPowerState != powerState) { |
| 4559 | final boolean active = |
| 4560 | powerState == DataConnectionRealTimeInfo.DC_POWER_STATE_MEDIUM |
| 4561 | || powerState == DataConnectionRealTimeInfo.DC_POWER_STATE_HIGH; |
| 4562 | if (active) { |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 4563 | if (uid > 0) { |
| 4564 | noteWifiRadioApWakeupLocked(elapsedRealtime, uptime, uid); |
| 4565 | } |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 4566 | mHistoryCur.states |= HistoryItem.STATE_WIFI_RADIO_ACTIVE_FLAG; |
| 4567 | } else { |
| 4568 | mHistoryCur.states &= ~HistoryItem.STATE_WIFI_RADIO_ACTIVE_FLAG; |
| 4569 | } |
| 4570 | if (DEBUG_HISTORY) Slog.v(TAG, "Wifi network active " + active + " to: " |
| 4571 | + Integer.toHexString(mHistoryCur.states)); |
| 4572 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 4573 | mWifiRadioPowerState = powerState; |
| 4574 | } |
| 4575 | } |
| 4576 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 4577 | public void noteWifiRunningLocked(WorkSource ws) { |
| 4578 | if (!mGlobalWifiRunning) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4579 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4580 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 4581 | mHistoryCur.states2 |= HistoryItem.STATE2_WIFI_RUNNING_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4582 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI running to: " |
| 4583 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 4584 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 4585 | mGlobalWifiRunning = true; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4586 | mGlobalWifiRunningTimer.startRunningLocked(elapsedRealtime); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 4587 | int N = ws.size(); |
| 4588 | for (int i=0; i<N; i++) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4589 | int uid = mapUid(ws.get(i)); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4590 | getUidStatsLocked(uid).noteWifiRunningLocked(elapsedRealtime); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 4591 | } |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 4592 | scheduleSyncExternalStatsLocked("wifi-running", ExternalStatsSync.UPDATE_WIFI); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 4593 | } else { |
| 4594 | Log.w(TAG, "noteWifiRunningLocked -- called while WIFI running"); |
Eric Shienbrood | d4c5f89 | 2009-03-24 18:13:20 -0700 | [diff] [blame] | 4595 | } |
| 4596 | } |
| 4597 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 4598 | public void noteWifiRunningChangedLocked(WorkSource oldWs, WorkSource newWs) { |
| 4599 | if (mGlobalWifiRunning) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4600 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 4601 | int N = oldWs.size(); |
| 4602 | for (int i=0; i<N; i++) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4603 | int uid = mapUid(oldWs.get(i)); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4604 | getUidStatsLocked(uid).noteWifiStoppedLocked(elapsedRealtime); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 4605 | } |
| 4606 | N = newWs.size(); |
| 4607 | for (int i=0; i<N; i++) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4608 | int uid = mapUid(newWs.get(i)); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4609 | getUidStatsLocked(uid).noteWifiRunningLocked(elapsedRealtime); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 4610 | } |
| 4611 | } else { |
| 4612 | Log.w(TAG, "noteWifiRunningChangedLocked -- called while WIFI not running"); |
| 4613 | } |
| 4614 | } |
| 4615 | |
| 4616 | public void noteWifiStoppedLocked(WorkSource ws) { |
| 4617 | if (mGlobalWifiRunning) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4618 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4619 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 4620 | mHistoryCur.states2 &= ~HistoryItem.STATE2_WIFI_RUNNING_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4621 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI stopped to: " |
| 4622 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 4623 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 4624 | mGlobalWifiRunning = false; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4625 | mGlobalWifiRunningTimer.stopRunningLocked(elapsedRealtime); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 4626 | int N = ws.size(); |
| 4627 | for (int i=0; i<N; i++) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4628 | int uid = mapUid(ws.get(i)); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4629 | getUidStatsLocked(uid).noteWifiStoppedLocked(elapsedRealtime); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 4630 | } |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 4631 | scheduleSyncExternalStatsLocked("wifi-stopped", ExternalStatsSync.UPDATE_WIFI); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 4632 | } else { |
| 4633 | Log.w(TAG, "noteWifiStoppedLocked -- called while WIFI not running"); |
Eric Shienbrood | d4c5f89 | 2009-03-24 18:13:20 -0700 | [diff] [blame] | 4634 | } |
| 4635 | } |
| 4636 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4637 | public void noteWifiStateLocked(int wifiState, String accessPoint) { |
| 4638 | if (DEBUG) Log.i(TAG, "WiFi state -> " + wifiState); |
| 4639 | if (mWifiState != wifiState) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4640 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4641 | if (mWifiState >= 0) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4642 | mWifiStateTimer[mWifiState].stopRunningLocked(elapsedRealtime); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4643 | } |
| 4644 | mWifiState = wifiState; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4645 | mWifiStateTimer[wifiState].startRunningLocked(elapsedRealtime); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 4646 | scheduleSyncExternalStatsLocked("wifi-state", ExternalStatsSync.UPDATE_WIFI); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4647 | } |
| 4648 | } |
| 4649 | |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 4650 | public void noteWifiSupplicantStateChangedLocked(int supplState, boolean failedAuth) { |
| 4651 | if (DEBUG) Log.i(TAG, "WiFi suppl state -> " + supplState); |
| 4652 | if (mWifiSupplState != supplState) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4653 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4654 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 4655 | if (mWifiSupplState >= 0) { |
| 4656 | mWifiSupplStateTimer[mWifiSupplState].stopRunningLocked(elapsedRealtime); |
| 4657 | } |
| 4658 | mWifiSupplState = supplState; |
| 4659 | mWifiSupplStateTimer[supplState].startRunningLocked(elapsedRealtime); |
| 4660 | mHistoryCur.states2 = |
| 4661 | (mHistoryCur.states2&~HistoryItem.STATE2_WIFI_SUPPL_STATE_MASK) |
| 4662 | | (supplState << HistoryItem.STATE2_WIFI_SUPPL_STATE_SHIFT); |
| 4663 | if (DEBUG_HISTORY) Slog.v(TAG, "Wifi suppl state " + supplState + " to: " |
| 4664 | + Integer.toHexString(mHistoryCur.states2)); |
| 4665 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 4666 | } |
| 4667 | } |
| 4668 | |
| 4669 | void stopAllWifiSignalStrengthTimersLocked(int except) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4670 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 4671 | for (int i = 0; i < NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 4672 | if (i == except) { |
| 4673 | continue; |
| 4674 | } |
| 4675 | while (mWifiSignalStrengthsTimer[i].isRunningLocked()) { |
| 4676 | mWifiSignalStrengthsTimer[i].stopRunningLocked(elapsedRealtime); |
| 4677 | } |
| 4678 | } |
| 4679 | } |
| 4680 | |
| 4681 | public void noteWifiRssiChangedLocked(int newRssi) { |
| 4682 | int strengthBin = WifiManager.calculateSignalLevel(newRssi, NUM_WIFI_SIGNAL_STRENGTH_BINS); |
| 4683 | if (DEBUG) Log.i(TAG, "WiFi rssi -> " + newRssi + " bin=" + strengthBin); |
| 4684 | if (mWifiSignalStrengthBin != strengthBin) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4685 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4686 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 4687 | if (mWifiSignalStrengthBin >= 0) { |
| 4688 | mWifiSignalStrengthsTimer[mWifiSignalStrengthBin].stopRunningLocked( |
| 4689 | elapsedRealtime); |
| 4690 | } |
| 4691 | if (strengthBin >= 0) { |
| 4692 | if (!mWifiSignalStrengthsTimer[strengthBin].isRunningLocked()) { |
| 4693 | mWifiSignalStrengthsTimer[strengthBin].startRunningLocked(elapsedRealtime); |
| 4694 | } |
| 4695 | mHistoryCur.states2 = |
| 4696 | (mHistoryCur.states2&~HistoryItem.STATE2_WIFI_SIGNAL_STRENGTH_MASK) |
| 4697 | | (strengthBin << HistoryItem.STATE2_WIFI_SIGNAL_STRENGTH_SHIFT); |
| 4698 | if (DEBUG_HISTORY) Slog.v(TAG, "Wifi signal strength " + strengthBin + " to: " |
| 4699 | + Integer.toHexString(mHistoryCur.states2)); |
| 4700 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 4701 | } else { |
| 4702 | stopAllWifiSignalStrengthTimersLocked(-1); |
| 4703 | } |
| 4704 | mWifiSignalStrengthBin = strengthBin; |
| 4705 | } |
| 4706 | } |
| 4707 | |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4708 | int mWifiFullLockNesting = 0; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4709 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4710 | public void noteFullWifiLockAcquiredLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4711 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4712 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4713 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4714 | if (mWifiFullLockNesting == 0) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4715 | mHistoryCur.states |= HistoryItem.STATE_WIFI_FULL_LOCK_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4716 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI full lock on to: " |
| 4717 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 4718 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4719 | } |
| 4720 | mWifiFullLockNesting++; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4721 | getUidStatsLocked(uid).noteFullWifiLockAcquiredLocked(elapsedRealtime); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4722 | } |
| 4723 | |
| 4724 | public void noteFullWifiLockReleasedLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4725 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4726 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4727 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4728 | mWifiFullLockNesting--; |
| 4729 | if (mWifiFullLockNesting == 0) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4730 | mHistoryCur.states &= ~HistoryItem.STATE_WIFI_FULL_LOCK_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4731 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI full lock off to: " |
| 4732 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 4733 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4734 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4735 | getUidStatsLocked(uid).noteFullWifiLockReleasedLocked(elapsedRealtime); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4736 | } |
| 4737 | |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 4738 | int mWifiScanNesting = 0; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4739 | |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 4740 | public void noteWifiScanStartedLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4741 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4742 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4743 | final long uptime = mClocks.uptimeMillis(); |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 4744 | if (mWifiScanNesting == 0) { |
| 4745 | mHistoryCur.states |= HistoryItem.STATE_WIFI_SCAN_FLAG; |
| 4746 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI scan started for: " |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4747 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 4748 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4749 | } |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 4750 | mWifiScanNesting++; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4751 | getUidStatsLocked(uid).noteWifiScanStartedLocked(elapsedRealtime); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4752 | } |
| 4753 | |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 4754 | public void noteWifiScanStoppedLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4755 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4756 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4757 | final long uptime = mClocks.uptimeMillis(); |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 4758 | mWifiScanNesting--; |
| 4759 | if (mWifiScanNesting == 0) { |
| 4760 | mHistoryCur.states &= ~HistoryItem.STATE_WIFI_SCAN_FLAG; |
| 4761 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI scan stopped for: " |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4762 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 4763 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4764 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4765 | getUidStatsLocked(uid).noteWifiScanStoppedLocked(elapsedRealtime); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4766 | } |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 4767 | |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 4768 | public void noteWifiBatchedScanStartedLocked(int uid, int csph) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4769 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4770 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4771 | getUidStatsLocked(uid).noteWifiBatchedScanStartedLocked(csph, elapsedRealtime); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 4772 | } |
| 4773 | |
| 4774 | public void noteWifiBatchedScanStoppedLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4775 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4776 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4777 | getUidStatsLocked(uid).noteWifiBatchedScanStoppedLocked(elapsedRealtime); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 4778 | } |
| 4779 | |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4780 | int mWifiMulticastNesting = 0; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4781 | |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 4782 | public void noteWifiMulticastEnabledLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4783 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4784 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4785 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4786 | if (mWifiMulticastNesting == 0) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4787 | mHistoryCur.states |= HistoryItem.STATE_WIFI_MULTICAST_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4788 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI multicast on to: " |
| 4789 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 4790 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4791 | } |
| 4792 | mWifiMulticastNesting++; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4793 | getUidStatsLocked(uid).noteWifiMulticastEnabledLocked(elapsedRealtime); |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 4794 | } |
| 4795 | |
| 4796 | public void noteWifiMulticastDisabledLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4797 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4798 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4799 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4800 | mWifiMulticastNesting--; |
| 4801 | if (mWifiMulticastNesting == 0) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4802 | mHistoryCur.states &= ~HistoryItem.STATE_WIFI_MULTICAST_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4803 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI multicast off to: " |
| 4804 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 4805 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4806 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4807 | getUidStatsLocked(uid).noteWifiMulticastDisabledLocked(elapsedRealtime); |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 4808 | } |
| 4809 | |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 4810 | public void noteFullWifiLockAcquiredFromSourceLocked(WorkSource ws) { |
| 4811 | int N = ws.size(); |
| 4812 | for (int i=0; i<N; i++) { |
| 4813 | noteFullWifiLockAcquiredLocked(ws.get(i)); |
| 4814 | } |
| 4815 | } |
| 4816 | |
| 4817 | public void noteFullWifiLockReleasedFromSourceLocked(WorkSource ws) { |
| 4818 | int N = ws.size(); |
| 4819 | for (int i=0; i<N; i++) { |
| 4820 | noteFullWifiLockReleasedLocked(ws.get(i)); |
| 4821 | } |
| 4822 | } |
| 4823 | |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 4824 | public void noteWifiScanStartedFromSourceLocked(WorkSource ws) { |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 4825 | int N = ws.size(); |
| 4826 | for (int i=0; i<N; i++) { |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 4827 | noteWifiScanStartedLocked(ws.get(i)); |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 4828 | } |
| 4829 | } |
| 4830 | |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 4831 | public void noteWifiScanStoppedFromSourceLocked(WorkSource ws) { |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 4832 | int N = ws.size(); |
| 4833 | for (int i=0; i<N; i++) { |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 4834 | noteWifiScanStoppedLocked(ws.get(i)); |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 4835 | } |
| 4836 | } |
| 4837 | |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 4838 | public void noteWifiBatchedScanStartedFromSourceLocked(WorkSource ws, int csph) { |
| 4839 | int N = ws.size(); |
| 4840 | for (int i=0; i<N; i++) { |
| 4841 | noteWifiBatchedScanStartedLocked(ws.get(i), csph); |
| 4842 | } |
| 4843 | } |
| 4844 | |
| 4845 | public void noteWifiBatchedScanStoppedFromSourceLocked(WorkSource ws) { |
| 4846 | int N = ws.size(); |
| 4847 | for (int i=0; i<N; i++) { |
| 4848 | noteWifiBatchedScanStoppedLocked(ws.get(i)); |
| 4849 | } |
| 4850 | } |
| 4851 | |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 4852 | public void noteWifiMulticastEnabledFromSourceLocked(WorkSource ws) { |
| 4853 | int N = ws.size(); |
| 4854 | for (int i=0; i<N; i++) { |
| 4855 | noteWifiMulticastEnabledLocked(ws.get(i)); |
| 4856 | } |
| 4857 | } |
| 4858 | |
| 4859 | public void noteWifiMulticastDisabledFromSourceLocked(WorkSource ws) { |
| 4860 | int N = ws.size(); |
| 4861 | for (int i=0; i<N; i++) { |
| 4862 | noteWifiMulticastDisabledLocked(ws.get(i)); |
| 4863 | } |
| 4864 | } |
| 4865 | |
Dianne Hackborn | d0c5b9a | 2014-02-21 16:19:05 -0800 | [diff] [blame] | 4866 | private static String[] includeInStringArray(String[] array, String str) { |
| 4867 | if (ArrayUtils.indexOf(array, str) >= 0) { |
| 4868 | return array; |
| 4869 | } |
| 4870 | String[] newArray = new String[array.length+1]; |
| 4871 | System.arraycopy(array, 0, newArray, 0, array.length); |
| 4872 | newArray[array.length] = str; |
| 4873 | return newArray; |
| 4874 | } |
| 4875 | |
| 4876 | private static String[] excludeFromStringArray(String[] array, String str) { |
| 4877 | int index = ArrayUtils.indexOf(array, str); |
| 4878 | if (index >= 0) { |
| 4879 | String[] newArray = new String[array.length-1]; |
| 4880 | if (index > 0) { |
| 4881 | System.arraycopy(array, 0, newArray, 0, index); |
| 4882 | } |
| 4883 | if (index < array.length-1) { |
| 4884 | System.arraycopy(array, index+1, newArray, index, array.length-index-1); |
| 4885 | } |
| 4886 | return newArray; |
| 4887 | } |
| 4888 | return array; |
| 4889 | } |
| 4890 | |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 4891 | public void noteNetworkInterfaceTypeLocked(String iface, int networkType) { |
Jeff Sharkey | 9da2f1e | 2014-08-14 12:55:00 -0700 | [diff] [blame] | 4892 | if (TextUtils.isEmpty(iface)) return; |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 4893 | if (ConnectivityManager.isNetworkTypeMobile(networkType)) { |
Dianne Hackborn | d0c5b9a | 2014-02-21 16:19:05 -0800 | [diff] [blame] | 4894 | mMobileIfaces = includeInStringArray(mMobileIfaces, iface); |
| 4895 | if (DEBUG) Slog.d(TAG, "Note mobile iface " + iface + ": " + mMobileIfaces); |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 4896 | } else { |
Dianne Hackborn | d0c5b9a | 2014-02-21 16:19:05 -0800 | [diff] [blame] | 4897 | mMobileIfaces = excludeFromStringArray(mMobileIfaces, iface); |
| 4898 | if (DEBUG) Slog.d(TAG, "Note non-mobile iface " + iface + ": " + mMobileIfaces); |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 4899 | } |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 4900 | if (ConnectivityManager.isNetworkTypeWifi(networkType)) { |
Dianne Hackborn | d0c5b9a | 2014-02-21 16:19:05 -0800 | [diff] [blame] | 4901 | mWifiIfaces = includeInStringArray(mWifiIfaces, iface); |
| 4902 | if (DEBUG) Slog.d(TAG, "Note wifi iface " + iface + ": " + mWifiIfaces); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 4903 | } else { |
Dianne Hackborn | d0c5b9a | 2014-02-21 16:19:05 -0800 | [diff] [blame] | 4904 | mWifiIfaces = excludeFromStringArray(mWifiIfaces, iface); |
| 4905 | if (DEBUG) Slog.d(TAG, "Note non-wifi iface " + iface + ": " + mWifiIfaces); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 4906 | } |
| 4907 | } |
| 4908 | |
| 4909 | public void noteNetworkStatsEnabledLocked() { |
| 4910 | // During device boot, qtaguid isn't enabled until after the inital |
| 4911 | // loading of battery stats. Now that they're enabled, take our initial |
| 4912 | // snapshot for future delta calculation. |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4913 | updateMobileRadioStateLocked(mClocks.elapsedRealtime(), null); |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 4914 | updateWifiStateLocked(null); |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 4915 | } |
| 4916 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4917 | @Override public long getScreenOnTime(long elapsedRealtimeUs, int which) { |
| 4918 | return mScreenOnTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4919 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4920 | |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 4921 | @Override public int getScreenOnCount(int which) { |
| 4922 | return mScreenOnTimer.getCountLocked(which); |
| 4923 | } |
| 4924 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4925 | @Override public long getScreenBrightnessTime(int brightnessBin, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4926 | long elapsedRealtimeUs, int which) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 4927 | return mScreenBrightnessTimer[brightnessBin].getTotalTimeLocked( |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4928 | elapsedRealtimeUs, which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4929 | } |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 4930 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 4931 | @Override public long getInteractiveTime(long elapsedRealtimeUs, int which) { |
| 4932 | return mInteractiveTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4933 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4934 | |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4935 | @Override public long getPowerSaveModeEnabledTime(long elapsedRealtimeUs, int which) { |
| 4936 | return mPowerSaveModeEnabledTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 4937 | } |
| 4938 | |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4939 | @Override public int getPowerSaveModeEnabledCount(int which) { |
| 4940 | return mPowerSaveModeEnabledTimer.getCountLocked(which); |
| 4941 | } |
| 4942 | |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4943 | @Override public long getDeviceIdleModeTime(int mode, long elapsedRealtimeUs, |
| 4944 | int which) { |
| 4945 | switch (mode) { |
| 4946 | case DEVICE_IDLE_MODE_LIGHT: |
| 4947 | return mDeviceIdleModeLightTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 4948 | case DEVICE_IDLE_MODE_DEEP: |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4949 | return mDeviceIdleModeFullTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
| 4950 | } |
| 4951 | return 0; |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4952 | } |
| 4953 | |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4954 | @Override public int getDeviceIdleModeCount(int mode, int which) { |
| 4955 | switch (mode) { |
| 4956 | case DEVICE_IDLE_MODE_LIGHT: |
| 4957 | return mDeviceIdleModeLightTimer.getCountLocked(which); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 4958 | case DEVICE_IDLE_MODE_DEEP: |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4959 | return mDeviceIdleModeFullTimer.getCountLocked(which); |
| 4960 | } |
| 4961 | return 0; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 4962 | } |
| 4963 | |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4964 | @Override public long getLongestDeviceIdleModeTime(int mode) { |
| 4965 | switch (mode) { |
| 4966 | case DEVICE_IDLE_MODE_LIGHT: |
| 4967 | return mLongestLightIdleTime; |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 4968 | case DEVICE_IDLE_MODE_DEEP: |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4969 | return mLongestFullIdleTime; |
| 4970 | } |
| 4971 | return 0; |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 4972 | } |
| 4973 | |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4974 | @Override public long getDeviceIdlingTime(int mode, long elapsedRealtimeUs, int which) { |
| 4975 | switch (mode) { |
| 4976 | case DEVICE_IDLE_MODE_LIGHT: |
| 4977 | return mDeviceLightIdlingTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 4978 | case DEVICE_IDLE_MODE_DEEP: |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4979 | return mDeviceIdlingTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
| 4980 | } |
| 4981 | return 0; |
| 4982 | } |
| 4983 | |
| 4984 | @Override public int getDeviceIdlingCount(int mode, int which) { |
| 4985 | switch (mode) { |
| 4986 | case DEVICE_IDLE_MODE_LIGHT: |
| 4987 | return mDeviceLightIdlingTimer.getCountLocked(which); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 4988 | case DEVICE_IDLE_MODE_DEEP: |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4989 | return mDeviceIdlingTimer.getCountLocked(which); |
| 4990 | } |
| 4991 | return 0; |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 4992 | } |
| 4993 | |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 4994 | @Override public int getNumConnectivityChange(int which) { |
| 4995 | int val = mNumConnectivityChange; |
| 4996 | if (which == STATS_CURRENT) { |
| 4997 | val -= mLoadedNumConnectivityChange; |
| 4998 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 4999 | val -= mUnpluggedNumConnectivityChange; |
| 5000 | } |
| 5001 | return val; |
| 5002 | } |
| 5003 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5004 | @Override public long getPhoneOnTime(long elapsedRealtimeUs, int which) { |
| 5005 | return mPhoneOnTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5006 | } |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 5007 | |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 5008 | @Override public int getPhoneOnCount(int which) { |
| 5009 | return mPhoneOnTimer.getCountLocked(which); |
| 5010 | } |
| 5011 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 5012 | @Override public long getPhoneSignalStrengthTime(int strengthBin, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5013 | long elapsedRealtimeUs, int which) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 5014 | return mPhoneSignalStrengthsTimer[strengthBin].getTotalTimeLocked( |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5015 | elapsedRealtimeUs, which); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 5016 | } |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 5017 | |
| 5018 | @Override public long getPhoneSignalScanningTime( |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5019 | long elapsedRealtimeUs, int which) { |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 5020 | return mPhoneSignalScanningTimer.getTotalTimeLocked( |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5021 | elapsedRealtimeUs, which); |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 5022 | } |
| 5023 | |
Catherine Liu | fb90081 | 2012-07-17 14:12:56 -0500 | [diff] [blame] | 5024 | @Override public int getPhoneSignalStrengthCount(int strengthBin, int which) { |
| 5025 | return mPhoneSignalStrengthsTimer[strengthBin].getCountLocked(which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 5026 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5027 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 5028 | @Override public long getPhoneDataConnectionTime(int dataType, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5029 | long elapsedRealtimeUs, int which) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 5030 | return mPhoneDataConnectionsTimer[dataType].getTotalTimeLocked( |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5031 | elapsedRealtimeUs, which); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 5032 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5033 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 5034 | @Override public int getPhoneDataConnectionCount(int dataType, int which) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 5035 | return mPhoneDataConnectionsTimer[dataType].getCountLocked(which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 5036 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5037 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5038 | @Override public long getMobileRadioActiveTime(long elapsedRealtimeUs, int which) { |
| 5039 | return mMobileRadioActiveTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 5040 | } |
| 5041 | |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 5042 | @Override public int getMobileRadioActiveCount(int which) { |
| 5043 | return mMobileRadioActiveTimer.getCountLocked(which); |
| 5044 | } |
| 5045 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 5046 | @Override public long getMobileRadioActiveAdjustedTime(int which) { |
| 5047 | return mMobileRadioActiveAdjustedTime.getCountLocked(which); |
| 5048 | } |
| 5049 | |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 5050 | @Override public long getMobileRadioActiveUnknownTime(int which) { |
| 5051 | return mMobileRadioActiveUnknownTime.getCountLocked(which); |
| 5052 | } |
| 5053 | |
| 5054 | @Override public int getMobileRadioActiveUnknownCount(int which) { |
| 5055 | return (int)mMobileRadioActiveUnknownCount.getCountLocked(which); |
| 5056 | } |
| 5057 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5058 | @Override public long getWifiOnTime(long elapsedRealtimeUs, int which) { |
| 5059 | return mWifiOnTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 5060 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5061 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5062 | @Override public long getGlobalWifiRunningTime(long elapsedRealtimeUs, int which) { |
| 5063 | return mGlobalWifiRunningTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Eric Shienbrood | d4c5f89 | 2009-03-24 18:13:20 -0700 | [diff] [blame] | 5064 | } |
| 5065 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 5066 | @Override public long getWifiStateTime(int wifiState, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5067 | long elapsedRealtimeUs, int which) { |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 5068 | return mWifiStateTimer[wifiState].getTotalTimeLocked( |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5069 | elapsedRealtimeUs, which); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 5070 | } |
| 5071 | |
| 5072 | @Override public int getWifiStateCount(int wifiState, int which) { |
| 5073 | return mWifiStateTimer[wifiState].getCountLocked(which); |
| 5074 | } |
| 5075 | |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 5076 | @Override public long getWifiSupplStateTime(int state, |
| 5077 | long elapsedRealtimeUs, int which) { |
| 5078 | return mWifiSupplStateTimer[state].getTotalTimeLocked( |
| 5079 | elapsedRealtimeUs, which); |
| 5080 | } |
| 5081 | |
| 5082 | @Override public int getWifiSupplStateCount(int state, int which) { |
| 5083 | return mWifiSupplStateTimer[state].getCountLocked(which); |
| 5084 | } |
| 5085 | |
| 5086 | @Override public long getWifiSignalStrengthTime(int strengthBin, |
| 5087 | long elapsedRealtimeUs, int which) { |
| 5088 | return mWifiSignalStrengthsTimer[strengthBin].getTotalTimeLocked( |
| 5089 | elapsedRealtimeUs, which); |
| 5090 | } |
| 5091 | |
| 5092 | @Override public int getWifiSignalStrengthCount(int strengthBin, int which) { |
| 5093 | return mWifiSignalStrengthsTimer[strengthBin].getCountLocked(which); |
| 5094 | } |
| 5095 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 5096 | @Override |
| 5097 | public ControllerActivityCounter getBluetoothControllerActivity() { |
| 5098 | return mBluetoothActivity; |
Adam Lesinski | 1739076 | 2015-04-10 13:17:47 -0700 | [diff] [blame] | 5099 | } |
| 5100 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 5101 | @Override |
| 5102 | public ControllerActivityCounter getWifiControllerActivity() { |
| 5103 | return mWifiActivity; |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 5104 | } |
| 5105 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 5106 | @Override |
| 5107 | public ControllerActivityCounter getModemControllerActivity() { |
| 5108 | return mModemActivity; |
Adam Lesinski | 1739076 | 2015-04-10 13:17:47 -0700 | [diff] [blame] | 5109 | } |
| 5110 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 5111 | @Override |
| 5112 | public boolean hasBluetoothActivityReporting() { |
| 5113 | return mHasBluetoothReporting; |
| 5114 | } |
| 5115 | |
| 5116 | @Override |
| 5117 | public boolean hasWifiActivityReporting() { |
| 5118 | return mHasWifiReporting; |
| 5119 | } |
| 5120 | |
| 5121 | @Override |
| 5122 | public boolean hasModemActivityReporting() { |
| 5123 | return mHasModemReporting; |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 5124 | } |
| 5125 | |
Ruben Brunk | 5b1308f | 2015-06-03 18:49:27 -0700 | [diff] [blame] | 5126 | @Override |
| 5127 | public long getFlashlightOnTime(long elapsedRealtimeUs, int which) { |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 5128 | return mFlashlightOnTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
| 5129 | } |
| 5130 | |
Ruben Brunk | 5b1308f | 2015-06-03 18:49:27 -0700 | [diff] [blame] | 5131 | @Override |
| 5132 | public long getFlashlightOnCount(int which) { |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 5133 | return mFlashlightOnTimer.getCountLocked(which); |
| 5134 | } |
| 5135 | |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5136 | @Override |
Ruben Brunk | 5b1308f | 2015-06-03 18:49:27 -0700 | [diff] [blame] | 5137 | public long getCameraOnTime(long elapsedRealtimeUs, int which) { |
| 5138 | return mCameraOnTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
| 5139 | } |
| 5140 | |
| 5141 | @Override |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 5142 | public long getBluetoothScanTime(long elapsedRealtimeUs, int which) { |
| 5143 | return mBluetoothScanTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
| 5144 | } |
| 5145 | |
| 5146 | @Override |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5147 | public long getNetworkActivityBytes(int type, int which) { |
| 5148 | if (type >= 0 && type < mNetworkByteActivityCounters.length) { |
| 5149 | return mNetworkByteActivityCounters[type].getCountLocked(which); |
| 5150 | } else { |
| 5151 | return 0; |
| 5152 | } |
| 5153 | } |
| 5154 | |
| 5155 | @Override |
| 5156 | public long getNetworkActivityPackets(int type, int which) { |
| 5157 | if (type >= 0 && type < mNetworkPacketActivityCounters.length) { |
| 5158 | return mNetworkPacketActivityCounters[type].getCountLocked(which); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5159 | } else { |
| 5160 | return 0; |
| 5161 | } |
| 5162 | } |
| 5163 | |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 5164 | @Override public long getStartClockTime() { |
Dianne Hackborn | d48954f | 2015-07-22 17:20:33 -0700 | [diff] [blame] | 5165 | final long currentTime = System.currentTimeMillis(); |
| 5166 | if (ensureStartClockTime(currentTime)) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5167 | recordCurrentTimeChangeLocked(currentTime, mClocks.elapsedRealtime(), |
| 5168 | mClocks.uptimeMillis()); |
Dianne Hackborn | 7d9eefd | 2014-08-27 18:30:31 -0700 | [diff] [blame] | 5169 | } |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 5170 | return mStartClockTime; |
| 5171 | } |
| 5172 | |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 5173 | @Override public String getStartPlatformVersion() { |
| 5174 | return mStartPlatformVersion; |
| 5175 | } |
| 5176 | |
| 5177 | @Override public String getEndPlatformVersion() { |
| 5178 | return mEndPlatformVersion; |
| 5179 | } |
| 5180 | |
| 5181 | @Override public int getParcelVersion() { |
| 5182 | return VERSION; |
| 5183 | } |
| 5184 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5185 | @Override public boolean getIsOnBattery() { |
| 5186 | return mOnBattery; |
| 5187 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5188 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5189 | @Override public SparseArray<? extends BatteryStats.Uid> getUidStats() { |
| 5190 | return mUidStats; |
| 5191 | } |
| 5192 | |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 5193 | private static void detachTimerIfNotNull(BatteryStatsImpl.Timer timer) { |
| 5194 | if (timer != null) { |
| 5195 | timer.detach(); |
| 5196 | } |
| 5197 | } |
| 5198 | |
| 5199 | private static boolean resetTimerIfNotNull(BatteryStatsImpl.Timer timer, |
| 5200 | boolean detachIfReset) { |
| 5201 | if (timer != null) { |
| 5202 | return timer.reset(detachIfReset); |
| 5203 | } |
| 5204 | return true; |
| 5205 | } |
| 5206 | |
| 5207 | private static void detachLongCounterIfNotNull(LongSamplingCounter counter) { |
| 5208 | if (counter != null) { |
| 5209 | counter.detach(); |
| 5210 | } |
| 5211 | } |
| 5212 | |
| 5213 | private static void resetLongCounterIfNotNull(LongSamplingCounter counter, |
| 5214 | boolean detachIfReset) { |
| 5215 | if (counter != null) { |
| 5216 | counter.reset(detachIfReset); |
| 5217 | } |
| 5218 | } |
| 5219 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5220 | /** |
| 5221 | * The statistics associated with a particular uid. |
| 5222 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5223 | public static class Uid extends BatteryStats.Uid { |
| 5224 | /** |
| 5225 | * BatteryStatsImpl that we are associated with. |
| 5226 | */ |
| 5227 | protected BatteryStatsImpl mBsi; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5228 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5229 | final int mUid; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5230 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 5231 | boolean mWifiRunning; |
| 5232 | StopwatchTimer mWifiRunningTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5233 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 5234 | boolean mFullWifiLockOut; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 5235 | StopwatchTimer mFullWifiLockTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5236 | |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 5237 | boolean mWifiScanStarted; |
| 5238 | StopwatchTimer mWifiScanTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5239 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5240 | static final int NO_BATCHED_SCAN_STARTED = -1; |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 5241 | int mWifiBatchedScanBinStarted = NO_BATCHED_SCAN_STARTED; |
| 5242 | StopwatchTimer[] mWifiBatchedScanTimer; |
| 5243 | |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 5244 | boolean mWifiMulticastEnabled; |
| 5245 | StopwatchTimer mWifiMulticastTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5246 | |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 5247 | StopwatchTimer mAudioTurnedOnTimer; |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 5248 | StopwatchTimer mVideoTurnedOnTimer; |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 5249 | StopwatchTimer mFlashlightTurnedOnTimer; |
| 5250 | StopwatchTimer mCameraTurnedOnTimer; |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 5251 | StopwatchTimer mForegroundActivityTimer; |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 5252 | StopwatchTimer mBluetoothScanTimer; |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 5253 | |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 5254 | int mProcessState = ActivityManager.PROCESS_STATE_NONEXISTENT; |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5255 | StopwatchTimer[] mProcessStateTimer; |
| 5256 | |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 5257 | BatchTimer mVibratorOnTimer; |
| 5258 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 5259 | Counter[] mUserActivityCounters; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5260 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5261 | LongSamplingCounter[] mNetworkByteActivityCounters; |
| 5262 | LongSamplingCounter[] mNetworkPacketActivityCounters; |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 5263 | LongSamplingCounter mMobileRadioActiveTime; |
| 5264 | LongSamplingCounter mMobileRadioActiveCount; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5265 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5266 | /** |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 5267 | * How many times this UID woke up the Application Processor due to a Mobile radio packet. |
| 5268 | */ |
| 5269 | private LongSamplingCounter mMobileRadioApWakeupCount; |
| 5270 | |
| 5271 | /** |
| 5272 | * How many times this UID woke up the Application Processor due to a Wifi packet. |
| 5273 | */ |
| 5274 | private LongSamplingCounter mWifiRadioApWakeupCount; |
| 5275 | |
| 5276 | /** |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 5277 | * 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] | 5278 | * Can be null if the UID has had no such activity. |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 5279 | */ |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 5280 | private ControllerActivityCounterImpl mWifiControllerActivity; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 5281 | |
| 5282 | /** |
| 5283 | * 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] | 5284 | * Can be null if the UID has had no such activity. |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 5285 | */ |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 5286 | private ControllerActivityCounterImpl mBluetoothControllerActivity; |
| 5287 | |
| 5288 | /** |
| 5289 | * The amount of time this uid has kept the Modem controller in idle, tx, and rx mode. |
| 5290 | * Can be null if the UID has had no such activity. |
| 5291 | */ |
| 5292 | private ControllerActivityCounterImpl mModemControllerActivity; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 5293 | |
| 5294 | /** |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 5295 | * The CPU times we had at the last history details update. |
| 5296 | */ |
| 5297 | long mLastStepUserTime; |
| 5298 | long mLastStepSystemTime; |
| 5299 | long mCurStepUserTime; |
| 5300 | long mCurStepSystemTime; |
| 5301 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5302 | LongSamplingCounter mUserCpuTime; |
| 5303 | LongSamplingCounter mSystemCpuTime; |
| 5304 | LongSamplingCounter mCpuPower; |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 5305 | LongSamplingCounter[][] mCpuClusterSpeed; |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 5306 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 5307 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5308 | * The statistics we have collected for this uid's wake locks. |
| 5309 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5310 | final OverflowArrayMap<Wakelock> mWakelockStats; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5311 | |
| 5312 | /** |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 5313 | * The statistics we have collected for this uid's syncs. |
| 5314 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5315 | final OverflowArrayMap<StopwatchTimer> mSyncStats; |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 5316 | |
| 5317 | /** |
| 5318 | * The statistics we have collected for this uid's jobs. |
| 5319 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5320 | final OverflowArrayMap<StopwatchTimer> mJobStats; |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 5321 | |
| 5322 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5323 | * The statistics we have collected for this uid's sensor activations. |
| 5324 | */ |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 5325 | final SparseArray<Sensor> mSensorStats = new SparseArray<>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5326 | |
| 5327 | /** |
| 5328 | * The statistics we have collected for this uid's processes. |
| 5329 | */ |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 5330 | final ArrayMap<String, Proc> mProcessStats = new ArrayMap<>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5331 | |
| 5332 | /** |
| 5333 | * The statistics we have collected for this uid's processes. |
| 5334 | */ |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 5335 | final ArrayMap<String, Pkg> mPackageStats = new ArrayMap<>(); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5336 | |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 5337 | /** |
| 5338 | * The transient wake stats we have collected for this uid's pids. |
| 5339 | */ |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 5340 | final SparseArray<Pid> mPids = new SparseArray<>(); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 5341 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5342 | public Uid(BatteryStatsImpl bsi, int uid) { |
| 5343 | mBsi = bsi; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5344 | mUid = uid; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5345 | |
| 5346 | mUserCpuTime = new LongSamplingCounter(mBsi.mOnBatteryTimeBase); |
| 5347 | mSystemCpuTime = new LongSamplingCounter(mBsi.mOnBatteryTimeBase); |
| 5348 | mCpuPower = new LongSamplingCounter(mBsi.mOnBatteryTimeBase); |
| 5349 | |
Dianne Hackborn | 657153b | 2016-07-29 14:54:14 -0700 | [diff] [blame] | 5350 | mWakelockStats = mBsi.new OverflowArrayMap<Wakelock>(uid) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5351 | @Override public Wakelock instantiateObject() { |
| 5352 | return new Wakelock(mBsi, Uid.this); |
| 5353 | } |
| 5354 | }; |
Dianne Hackborn | 657153b | 2016-07-29 14:54:14 -0700 | [diff] [blame] | 5355 | mSyncStats = mBsi.new OverflowArrayMap<StopwatchTimer>(uid) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5356 | @Override public StopwatchTimer instantiateObject() { |
| 5357 | return new StopwatchTimer(mBsi.mClocks, Uid.this, SYNC, null, |
| 5358 | mBsi.mOnBatteryTimeBase); |
| 5359 | } |
| 5360 | }; |
Dianne Hackborn | 657153b | 2016-07-29 14:54:14 -0700 | [diff] [blame] | 5361 | mJobStats = mBsi.new OverflowArrayMap<StopwatchTimer>(uid) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5362 | @Override public StopwatchTimer instantiateObject() { |
| 5363 | return new StopwatchTimer(mBsi.mClocks, Uid.this, JOB, null, |
| 5364 | mBsi.mOnBatteryTimeBase); |
| 5365 | } |
| 5366 | }; |
| 5367 | |
| 5368 | mWifiRunningTimer = new StopwatchTimer(mBsi.mClocks, this, WIFI_RUNNING, |
| 5369 | mBsi.mWifiRunningTimers, mBsi.mOnBatteryTimeBase); |
| 5370 | mFullWifiLockTimer = new StopwatchTimer(mBsi.mClocks, this, FULL_WIFI_LOCK, |
| 5371 | mBsi.mFullWifiLockTimers, mBsi.mOnBatteryTimeBase); |
| 5372 | mWifiScanTimer = new StopwatchTimer(mBsi.mClocks, this, WIFI_SCAN, |
| 5373 | mBsi.mWifiScanTimers, mBsi.mOnBatteryTimeBase); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 5374 | mWifiBatchedScanTimer = new StopwatchTimer[NUM_WIFI_BATCHED_SCAN_BINS]; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5375 | mWifiMulticastTimer = new StopwatchTimer(mBsi.mClocks, this, WIFI_MULTICAST_ENABLED, |
| 5376 | mBsi.mWifiMulticastTimers, mBsi.mOnBatteryTimeBase); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5377 | mProcessStateTimer = new StopwatchTimer[NUM_PROCESS_STATE]; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5378 | } |
| 5379 | |
| 5380 | @Override |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5381 | public ArrayMap<String, ? extends BatteryStats.Uid.Wakelock> getWakelockStats() { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 5382 | return mWakelockStats.getMap(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5383 | } |
| 5384 | |
| 5385 | @Override |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5386 | public ArrayMap<String, ? extends BatteryStats.Timer> getSyncStats() { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 5387 | return mSyncStats.getMap(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 5388 | } |
| 5389 | |
| 5390 | @Override |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5391 | public ArrayMap<String, ? extends BatteryStats.Timer> getJobStats() { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 5392 | return mJobStats.getMap(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 5393 | } |
| 5394 | |
| 5395 | @Override |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5396 | public SparseArray<? extends BatteryStats.Uid.Sensor> getSensorStats() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5397 | return mSensorStats; |
| 5398 | } |
| 5399 | |
| 5400 | @Override |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5401 | public ArrayMap<String, ? extends BatteryStats.Uid.Proc> getProcessStats() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5402 | return mProcessStats; |
| 5403 | } |
| 5404 | |
| 5405 | @Override |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5406 | public ArrayMap<String, ? extends BatteryStats.Uid.Pkg> getPackageStats() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5407 | return mPackageStats; |
| 5408 | } |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 5409 | |
| 5410 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5411 | public int getUid() { |
| 5412 | return mUid; |
| 5413 | } |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 5414 | |
| 5415 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5416 | public void noteWifiRunningLocked(long elapsedRealtimeMs) { |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 5417 | if (!mWifiRunning) { |
| 5418 | mWifiRunning = true; |
| 5419 | if (mWifiRunningTimer == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5420 | mWifiRunningTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, WIFI_RUNNING, |
| 5421 | mBsi.mWifiRunningTimers, mBsi.mOnBatteryTimeBase); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5422 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5423 | mWifiRunningTimer.startRunningLocked(elapsedRealtimeMs); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 5424 | } |
| 5425 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5426 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 5427 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5428 | public void noteWifiStoppedLocked(long elapsedRealtimeMs) { |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 5429 | if (mWifiRunning) { |
| 5430 | mWifiRunning = false; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5431 | mWifiRunningTimer.stopRunningLocked(elapsedRealtimeMs); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 5432 | } |
| 5433 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5434 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 5435 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5436 | public void noteFullWifiLockAcquiredLocked(long elapsedRealtimeMs) { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 5437 | if (!mFullWifiLockOut) { |
| 5438 | mFullWifiLockOut = true; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5439 | if (mFullWifiLockTimer == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5440 | mFullWifiLockTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, FULL_WIFI_LOCK, |
| 5441 | mBsi.mFullWifiLockTimers, mBsi.mOnBatteryTimeBase); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5442 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5443 | mFullWifiLockTimer.startRunningLocked(elapsedRealtimeMs); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 5444 | } |
| 5445 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5446 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 5447 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5448 | public void noteFullWifiLockReleasedLocked(long elapsedRealtimeMs) { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 5449 | if (mFullWifiLockOut) { |
| 5450 | mFullWifiLockOut = false; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5451 | mFullWifiLockTimer.stopRunningLocked(elapsedRealtimeMs); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 5452 | } |
| 5453 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5454 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 5455 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5456 | public void noteWifiScanStartedLocked(long elapsedRealtimeMs) { |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 5457 | if (!mWifiScanStarted) { |
| 5458 | mWifiScanStarted = true; |
| 5459 | if (mWifiScanTimer == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5460 | mWifiScanTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, WIFI_SCAN, |
| 5461 | mBsi.mWifiScanTimers, mBsi.mOnBatteryTimeBase); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5462 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5463 | mWifiScanTimer.startRunningLocked(elapsedRealtimeMs); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 5464 | } |
| 5465 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5466 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 5467 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5468 | public void noteWifiScanStoppedLocked(long elapsedRealtimeMs) { |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 5469 | if (mWifiScanStarted) { |
| 5470 | mWifiScanStarted = false; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5471 | mWifiScanTimer.stopRunningLocked(elapsedRealtimeMs); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 5472 | } |
| 5473 | } |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 5474 | |
| 5475 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5476 | public void noteWifiBatchedScanStartedLocked(int csph, long elapsedRealtimeMs) { |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 5477 | int bin = 0; |
Navtej Singh Mann | 3c0ce5c | 2015-06-11 16:53:11 -0700 | [diff] [blame] | 5478 | while (csph > 8 && bin < NUM_WIFI_BATCHED_SCAN_BINS-1) { |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 5479 | csph = csph >> 3; |
| 5480 | bin++; |
| 5481 | } |
| 5482 | |
| 5483 | if (mWifiBatchedScanBinStarted == bin) return; |
| 5484 | |
| 5485 | if (mWifiBatchedScanBinStarted != NO_BATCHED_SCAN_STARTED) { |
| 5486 | mWifiBatchedScanTimer[mWifiBatchedScanBinStarted]. |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5487 | stopRunningLocked(elapsedRealtimeMs); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 5488 | } |
| 5489 | mWifiBatchedScanBinStarted = bin; |
| 5490 | if (mWifiBatchedScanTimer[bin] == null) { |
| 5491 | makeWifiBatchedScanBin(bin, null); |
| 5492 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5493 | mWifiBatchedScanTimer[bin].startRunningLocked(elapsedRealtimeMs); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 5494 | } |
| 5495 | |
| 5496 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5497 | public void noteWifiBatchedScanStoppedLocked(long elapsedRealtimeMs) { |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 5498 | if (mWifiBatchedScanBinStarted != NO_BATCHED_SCAN_STARTED) { |
| 5499 | mWifiBatchedScanTimer[mWifiBatchedScanBinStarted]. |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5500 | stopRunningLocked(elapsedRealtimeMs); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 5501 | mWifiBatchedScanBinStarted = NO_BATCHED_SCAN_STARTED; |
| 5502 | } |
| 5503 | } |
| 5504 | |
| 5505 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5506 | public void noteWifiMulticastEnabledLocked(long elapsedRealtimeMs) { |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 5507 | if (!mWifiMulticastEnabled) { |
| 5508 | mWifiMulticastEnabled = true; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5509 | if (mWifiMulticastTimer == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5510 | mWifiMulticastTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, |
| 5511 | WIFI_MULTICAST_ENABLED, mBsi.mWifiMulticastTimers, mBsi.mOnBatteryTimeBase); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5512 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5513 | mWifiMulticastTimer.startRunningLocked(elapsedRealtimeMs); |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 5514 | } |
| 5515 | } |
| 5516 | |
| 5517 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5518 | public void noteWifiMulticastDisabledLocked(long elapsedRealtimeMs) { |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 5519 | if (mWifiMulticastEnabled) { |
| 5520 | mWifiMulticastEnabled = false; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5521 | mWifiMulticastTimer.stopRunningLocked(elapsedRealtimeMs); |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 5522 | } |
| 5523 | } |
| 5524 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 5525 | @Override |
| 5526 | public ControllerActivityCounter getWifiControllerActivity() { |
| 5527 | return mWifiControllerActivity; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 5528 | } |
| 5529 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 5530 | @Override |
| 5531 | public ControllerActivityCounter getBluetoothControllerActivity() { |
| 5532 | return mBluetoothControllerActivity; |
| 5533 | } |
| 5534 | |
| 5535 | @Override |
| 5536 | public ControllerActivityCounter getModemControllerActivity() { |
| 5537 | return mModemControllerActivity; |
| 5538 | } |
| 5539 | |
| 5540 | public ControllerActivityCounterImpl getOrCreateWifiControllerActivityLocked() { |
| 5541 | if (mWifiControllerActivity == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5542 | mWifiControllerActivity = new ControllerActivityCounterImpl(mBsi.mOnBatteryTimeBase, |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 5543 | NUM_BT_TX_LEVELS); |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 5544 | } |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 5545 | return mWifiControllerActivity; |
| 5546 | } |
| 5547 | |
| 5548 | public ControllerActivityCounterImpl getOrCreateBluetoothControllerActivityLocked() { |
| 5549 | if (mBluetoothControllerActivity == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5550 | mBluetoothControllerActivity = new ControllerActivityCounterImpl(mBsi.mOnBatteryTimeBase, |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 5551 | NUM_BT_TX_LEVELS); |
| 5552 | } |
| 5553 | return mBluetoothControllerActivity; |
| 5554 | } |
| 5555 | |
| 5556 | public ControllerActivityCounterImpl getOrCreateModemControllerActivityLocked() { |
| 5557 | if (mModemControllerActivity == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5558 | mModemControllerActivity = new ControllerActivityCounterImpl(mBsi.mOnBatteryTimeBase, |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 5559 | ModemActivityInfo.TX_POWER_LEVELS); |
| 5560 | } |
| 5561 | return mModemControllerActivity; |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 5562 | } |
| 5563 | |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 5564 | public StopwatchTimer createAudioTurnedOnTimerLocked() { |
| 5565 | if (mAudioTurnedOnTimer == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5566 | mAudioTurnedOnTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, AUDIO_TURNED_ON, |
| 5567 | mBsi.mAudioTurnedOnTimers, mBsi.mOnBatteryTimeBase); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 5568 | } |
| 5569 | return mAudioTurnedOnTimer; |
| 5570 | } |
| 5571 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5572 | public void noteAudioTurnedOnLocked(long elapsedRealtimeMs) { |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 5573 | createAudioTurnedOnTimerLocked().startRunningLocked(elapsedRealtimeMs); |
| 5574 | } |
| 5575 | |
| 5576 | public void noteAudioTurnedOffLocked(long elapsedRealtimeMs) { |
| 5577 | if (mAudioTurnedOnTimer != null) { |
| 5578 | mAudioTurnedOnTimer.stopRunningLocked(elapsedRealtimeMs); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5579 | } |
| 5580 | } |
| 5581 | |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 5582 | public void noteResetAudioLocked(long elapsedRealtimeMs) { |
| 5583 | if (mAudioTurnedOnTimer != null) { |
| 5584 | mAudioTurnedOnTimer.stopAllRunningLocked(elapsedRealtimeMs); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5585 | } |
| 5586 | } |
| 5587 | |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 5588 | public StopwatchTimer createVideoTurnedOnTimerLocked() { |
| 5589 | if (mVideoTurnedOnTimer == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5590 | mVideoTurnedOnTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, VIDEO_TURNED_ON, |
| 5591 | mBsi.mVideoTurnedOnTimers, mBsi.mOnBatteryTimeBase); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 5592 | } |
| 5593 | return mVideoTurnedOnTimer; |
| 5594 | } |
| 5595 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5596 | public void noteVideoTurnedOnLocked(long elapsedRealtimeMs) { |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 5597 | createVideoTurnedOnTimerLocked().startRunningLocked(elapsedRealtimeMs); |
| 5598 | } |
| 5599 | |
| 5600 | public void noteVideoTurnedOffLocked(long elapsedRealtimeMs) { |
| 5601 | if (mVideoTurnedOnTimer != null) { |
| 5602 | mVideoTurnedOnTimer.stopRunningLocked(elapsedRealtimeMs); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5603 | } |
| 5604 | } |
| 5605 | |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 5606 | public void noteResetVideoLocked(long elapsedRealtimeMs) { |
| 5607 | if (mVideoTurnedOnTimer != null) { |
| 5608 | mVideoTurnedOnTimer.stopAllRunningLocked(elapsedRealtimeMs); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 5609 | } |
| 5610 | } |
| 5611 | |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 5612 | public StopwatchTimer createFlashlightTurnedOnTimerLocked() { |
| 5613 | if (mFlashlightTurnedOnTimer == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5614 | mFlashlightTurnedOnTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, |
| 5615 | FLASHLIGHT_TURNED_ON, mBsi.mFlashlightTurnedOnTimers, mBsi.mOnBatteryTimeBase); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 5616 | } |
| 5617 | return mFlashlightTurnedOnTimer; |
| 5618 | } |
| 5619 | |
| 5620 | public void noteFlashlightTurnedOnLocked(long elapsedRealtimeMs) { |
| 5621 | createFlashlightTurnedOnTimerLocked().startRunningLocked(elapsedRealtimeMs); |
| 5622 | } |
| 5623 | |
| 5624 | public void noteFlashlightTurnedOffLocked(long elapsedRealtimeMs) { |
| 5625 | if (mFlashlightTurnedOnTimer != null) { |
| 5626 | mFlashlightTurnedOnTimer.stopRunningLocked(elapsedRealtimeMs); |
| 5627 | } |
| 5628 | } |
| 5629 | |
| 5630 | public void noteResetFlashlightLocked(long elapsedRealtimeMs) { |
| 5631 | if (mFlashlightTurnedOnTimer != null) { |
| 5632 | mFlashlightTurnedOnTimer.stopAllRunningLocked(elapsedRealtimeMs); |
| 5633 | } |
| 5634 | } |
| 5635 | |
| 5636 | public StopwatchTimer createCameraTurnedOnTimerLocked() { |
| 5637 | if (mCameraTurnedOnTimer == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5638 | mCameraTurnedOnTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, CAMERA_TURNED_ON, |
| 5639 | mBsi.mCameraTurnedOnTimers, mBsi.mOnBatteryTimeBase); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 5640 | } |
| 5641 | return mCameraTurnedOnTimer; |
| 5642 | } |
| 5643 | |
| 5644 | public void noteCameraTurnedOnLocked(long elapsedRealtimeMs) { |
| 5645 | createCameraTurnedOnTimerLocked().startRunningLocked(elapsedRealtimeMs); |
| 5646 | } |
| 5647 | |
| 5648 | public void noteCameraTurnedOffLocked(long elapsedRealtimeMs) { |
| 5649 | if (mCameraTurnedOnTimer != null) { |
| 5650 | mCameraTurnedOnTimer.stopRunningLocked(elapsedRealtimeMs); |
| 5651 | } |
| 5652 | } |
| 5653 | |
| 5654 | public void noteResetCameraLocked(long elapsedRealtimeMs) { |
| 5655 | if (mCameraTurnedOnTimer != null) { |
| 5656 | mCameraTurnedOnTimer.stopAllRunningLocked(elapsedRealtimeMs); |
| 5657 | } |
| 5658 | } |
| 5659 | |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 5660 | public StopwatchTimer createForegroundActivityTimerLocked() { |
| 5661 | if (mForegroundActivityTimer == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5662 | mForegroundActivityTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, |
| 5663 | FOREGROUND_ACTIVITY, null, mBsi.mOnBatteryTimeBase); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 5664 | } |
| 5665 | return mForegroundActivityTimer; |
| 5666 | } |
| 5667 | |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 5668 | public StopwatchTimer createBluetoothScanTimerLocked() { |
| 5669 | if (mBluetoothScanTimer == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5670 | mBluetoothScanTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, BLUETOOTH_SCAN_ON, |
| 5671 | mBsi.mBluetoothScanOnTimers, mBsi.mOnBatteryTimeBase); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 5672 | } |
| 5673 | return mBluetoothScanTimer; |
| 5674 | } |
| 5675 | |
| 5676 | public void noteBluetoothScanStartedLocked(long elapsedRealtimeMs) { |
| 5677 | createBluetoothScanTimerLocked().startRunningLocked(elapsedRealtimeMs); |
| 5678 | } |
| 5679 | |
| 5680 | public void noteBluetoothScanStoppedLocked(long elapsedRealtimeMs) { |
| 5681 | if (mBluetoothScanTimer != null) { |
| 5682 | mBluetoothScanTimer.stopRunningLocked(elapsedRealtimeMs); |
| 5683 | } |
| 5684 | } |
| 5685 | |
| 5686 | public void noteResetBluetoothScanLocked(long elapsedRealtimeMs) { |
| 5687 | if (mBluetoothScanTimer != null) { |
| 5688 | mBluetoothScanTimer.stopAllRunningLocked(elapsedRealtimeMs); |
| 5689 | } |
| 5690 | } |
| 5691 | |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 5692 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5693 | public void noteActivityResumedLocked(long elapsedRealtimeMs) { |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 5694 | // We always start, since we want multiple foreground PIDs to nest |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5695 | createForegroundActivityTimerLocked().startRunningLocked(elapsedRealtimeMs); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 5696 | } |
| 5697 | |
| 5698 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5699 | public void noteActivityPausedLocked(long elapsedRealtimeMs) { |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 5700 | if (mForegroundActivityTimer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5701 | mForegroundActivityTimer.stopRunningLocked(elapsedRealtimeMs); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 5702 | } |
| 5703 | } |
| 5704 | |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 5705 | public BatchTimer createVibratorOnTimerLocked() { |
| 5706 | if (mVibratorOnTimer == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5707 | mVibratorOnTimer = new BatchTimer(mBsi.mClocks, Uid.this, VIBRATOR_ON, |
| 5708 | mBsi.mOnBatteryTimeBase); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 5709 | } |
| 5710 | return mVibratorOnTimer; |
| 5711 | } |
| 5712 | |
| 5713 | public void noteVibratorOnLocked(long durationMillis) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5714 | createVibratorOnTimerLocked().addDuration(mBsi, durationMillis); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 5715 | } |
| 5716 | |
| 5717 | public void noteVibratorOffLocked() { |
| 5718 | if (mVibratorOnTimer != null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5719 | mVibratorOnTimer.abortLastDuration(mBsi); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5720 | } |
| 5721 | } |
| 5722 | |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5723 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5724 | public long getWifiRunningTime(long elapsedRealtimeUs, int which) { |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 5725 | if (mWifiRunningTimer == null) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5726 | return 0; |
| 5727 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5728 | return mWifiRunningTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 5729 | } |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 5730 | |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5731 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5732 | public long getFullWifiLockTime(long elapsedRealtimeUs, int which) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5733 | if (mFullWifiLockTimer == null) { |
| 5734 | return 0; |
| 5735 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5736 | return mFullWifiLockTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 5737 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5738 | |
| 5739 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5740 | public long getWifiScanTime(long elapsedRealtimeUs, int which) { |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 5741 | if (mWifiScanTimer == null) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5742 | return 0; |
| 5743 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5744 | return mWifiScanTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 5745 | } |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 5746 | |
| 5747 | @Override |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 5748 | public int getWifiScanCount(int which) { |
| 5749 | if (mWifiScanTimer == null) { |
| 5750 | return 0; |
| 5751 | } |
| 5752 | return mWifiScanTimer.getCountLocked(which); |
| 5753 | } |
| 5754 | |
| 5755 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5756 | public long getWifiBatchedScanTime(int csphBin, long elapsedRealtimeUs, int which) { |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 5757 | if (csphBin < 0 || csphBin >= NUM_WIFI_BATCHED_SCAN_BINS) return 0; |
| 5758 | if (mWifiBatchedScanTimer[csphBin] == null) { |
| 5759 | return 0; |
| 5760 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5761 | return mWifiBatchedScanTimer[csphBin].getTotalTimeLocked(elapsedRealtimeUs, which); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 5762 | } |
| 5763 | |
| 5764 | @Override |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 5765 | public int getWifiBatchedScanCount(int csphBin, int which) { |
| 5766 | if (csphBin < 0 || csphBin >= NUM_WIFI_BATCHED_SCAN_BINS) return 0; |
| 5767 | if (mWifiBatchedScanTimer[csphBin] == null) { |
| 5768 | return 0; |
| 5769 | } |
| 5770 | return mWifiBatchedScanTimer[csphBin].getCountLocked(which); |
| 5771 | } |
| 5772 | |
| 5773 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5774 | public long getWifiMulticastTime(long elapsedRealtimeUs, int which) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5775 | if (mWifiMulticastTimer == null) { |
| 5776 | return 0; |
| 5777 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5778 | return mWifiMulticastTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 5779 | } |
| 5780 | |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5781 | @Override |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 5782 | public Timer getAudioTurnedOnTimer() { |
| 5783 | return mAudioTurnedOnTimer; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5784 | } |
| 5785 | |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5786 | @Override |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 5787 | public Timer getVideoTurnedOnTimer() { |
| 5788 | return mVideoTurnedOnTimer; |
| 5789 | } |
| 5790 | |
| 5791 | @Override |
| 5792 | public Timer getFlashlightTurnedOnTimer() { |
| 5793 | return mFlashlightTurnedOnTimer; |
| 5794 | } |
| 5795 | |
| 5796 | @Override |
| 5797 | public Timer getCameraTurnedOnTimer() { |
| 5798 | return mCameraTurnedOnTimer; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5799 | } |
| 5800 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 5801 | @Override |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 5802 | public Timer getForegroundActivityTimer() { |
| 5803 | return mForegroundActivityTimer; |
| 5804 | } |
| 5805 | |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 5806 | @Override |
| 5807 | public Timer getBluetoothScanTimer() { |
| 5808 | return mBluetoothScanTimer; |
| 5809 | } |
| 5810 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5811 | void makeProcessState(int i, Parcel in) { |
| 5812 | if (i < 0 || i >= NUM_PROCESS_STATE) return; |
| 5813 | |
| 5814 | if (in == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5815 | mProcessStateTimer[i] = new StopwatchTimer(mBsi.mClocks, this, PROCESS_STATE, null, |
| 5816 | mBsi.mOnBatteryTimeBase); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5817 | } else { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5818 | mProcessStateTimer[i] = new StopwatchTimer(mBsi.mClocks, this, PROCESS_STATE, null, |
| 5819 | mBsi.mOnBatteryTimeBase, in); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5820 | } |
| 5821 | } |
| 5822 | |
| 5823 | @Override |
| 5824 | public long getProcessStateTime(int state, long elapsedRealtimeUs, int which) { |
| 5825 | if (state < 0 || state >= NUM_PROCESS_STATE) return 0; |
| 5826 | if (mProcessStateTimer[state] == null) { |
| 5827 | return 0; |
| 5828 | } |
| 5829 | return mProcessStateTimer[state].getTotalTimeLocked(elapsedRealtimeUs, which); |
| 5830 | } |
| 5831 | |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 5832 | @Override |
Joe Onorato | 713fec8 | 2016-03-04 10:34:02 -0800 | [diff] [blame] | 5833 | public Timer getProcessStateTimer(int state) { |
| 5834 | if (state < 0 || state >= NUM_PROCESS_STATE) return null; |
| 5835 | return mProcessStateTimer[state]; |
| 5836 | } |
| 5837 | |
| 5838 | @Override |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 5839 | public Timer getVibratorOnTimer() { |
| 5840 | return mVibratorOnTimer; |
| 5841 | } |
| 5842 | |
| 5843 | @Override |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 5844 | public void noteUserActivityLocked(int type) { |
| 5845 | if (mUserActivityCounters == null) { |
| 5846 | initUserActivityLocked(); |
| 5847 | } |
Jeff Brown | df693de | 2012-07-27 12:03:38 -0700 | [diff] [blame] | 5848 | if (type >= 0 && type < NUM_USER_ACTIVITY_TYPES) { |
| 5849 | mUserActivityCounters[type].stepAtomic(); |
| 5850 | } else { |
| 5851 | Slog.w(TAG, "Unknown user activity type " + type + " was specified.", |
| 5852 | new Throwable()); |
| 5853 | } |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 5854 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5855 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 5856 | @Override |
| 5857 | public boolean hasUserActivity() { |
| 5858 | return mUserActivityCounters != null; |
| 5859 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5860 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 5861 | @Override |
| 5862 | public int getUserActivityCount(int type, int which) { |
| 5863 | if (mUserActivityCounters == null) { |
| 5864 | return 0; |
| 5865 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 5866 | return mUserActivityCounters[type].getCountLocked(which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 5867 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5868 | |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 5869 | void makeWifiBatchedScanBin(int i, Parcel in) { |
| 5870 | if (i < 0 || i >= NUM_WIFI_BATCHED_SCAN_BINS) return; |
| 5871 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5872 | ArrayList<StopwatchTimer> collected = mBsi.mWifiBatchedScanTimers.get(i); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 5873 | if (collected == null) { |
| 5874 | collected = new ArrayList<StopwatchTimer>(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5875 | mBsi.mWifiBatchedScanTimers.put(i, collected); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 5876 | } |
| 5877 | if (in == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5878 | mWifiBatchedScanTimer[i] = new StopwatchTimer(mBsi.mClocks, this, WIFI_BATCHED_SCAN, |
| 5879 | collected, mBsi.mOnBatteryTimeBase); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 5880 | } else { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5881 | mWifiBatchedScanTimer[i] = new StopwatchTimer(mBsi.mClocks, this, WIFI_BATCHED_SCAN, |
| 5882 | collected, mBsi.mOnBatteryTimeBase, in); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 5883 | } |
| 5884 | } |
| 5885 | |
| 5886 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 5887 | void initUserActivityLocked() { |
| 5888 | mUserActivityCounters = new Counter[NUM_USER_ACTIVITY_TYPES]; |
| 5889 | for (int i=0; i<NUM_USER_ACTIVITY_TYPES; i++) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5890 | mUserActivityCounters[i] = new Counter(mBsi.mOnBatteryTimeBase); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 5891 | } |
| 5892 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5893 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5894 | void noteNetworkActivityLocked(int type, long deltaBytes, long deltaPackets) { |
| 5895 | if (mNetworkByteActivityCounters == null) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5896 | initNetworkActivityLocked(); |
| 5897 | } |
| 5898 | if (type >= 0 && type < NUM_NETWORK_ACTIVITY_TYPES) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5899 | mNetworkByteActivityCounters[type].addCountLocked(deltaBytes); |
| 5900 | mNetworkPacketActivityCounters[type].addCountLocked(deltaPackets); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5901 | } else { |
| 5902 | Slog.w(TAG, "Unknown network activity type " + type + " was specified.", |
| 5903 | new Throwable()); |
| 5904 | } |
| 5905 | } |
| 5906 | |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 5907 | void noteMobileRadioActiveTimeLocked(long batteryUptime) { |
| 5908 | if (mNetworkByteActivityCounters == null) { |
| 5909 | initNetworkActivityLocked(); |
| 5910 | } |
| 5911 | mMobileRadioActiveTime.addCountLocked(batteryUptime); |
| 5912 | mMobileRadioActiveCount.addCountLocked(1); |
| 5913 | } |
| 5914 | |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5915 | @Override |
| 5916 | public boolean hasNetworkActivity() { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5917 | return mNetworkByteActivityCounters != null; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5918 | } |
| 5919 | |
| 5920 | @Override |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5921 | public long getNetworkActivityBytes(int type, int which) { |
| 5922 | if (mNetworkByteActivityCounters != null && type >= 0 |
| 5923 | && type < mNetworkByteActivityCounters.length) { |
| 5924 | return mNetworkByteActivityCounters[type].getCountLocked(which); |
| 5925 | } else { |
| 5926 | return 0; |
| 5927 | } |
| 5928 | } |
| 5929 | |
| 5930 | @Override |
| 5931 | public long getNetworkActivityPackets(int type, int which) { |
| 5932 | if (mNetworkPacketActivityCounters != null && type >= 0 |
| 5933 | && type < mNetworkPacketActivityCounters.length) { |
| 5934 | return mNetworkPacketActivityCounters[type].getCountLocked(which); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5935 | } else { |
| 5936 | return 0; |
| 5937 | } |
| 5938 | } |
| 5939 | |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 5940 | @Override |
| 5941 | public long getMobileRadioActiveTime(int which) { |
| 5942 | return mMobileRadioActiveTime != null |
| 5943 | ? mMobileRadioActiveTime.getCountLocked(which) : 0; |
| 5944 | } |
| 5945 | |
| 5946 | @Override |
| 5947 | public int getMobileRadioActiveCount(int which) { |
| 5948 | return mMobileRadioActiveCount != null |
| 5949 | ? (int)mMobileRadioActiveCount.getCountLocked(which) : 0; |
| 5950 | } |
| 5951 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 5952 | @Override |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 5953 | public long getUserCpuTimeUs(int which) { |
| 5954 | return mUserCpuTime.getCountLocked(which); |
| 5955 | } |
| 5956 | |
| 5957 | @Override |
| 5958 | public long getSystemCpuTimeUs(int which) { |
| 5959 | return mSystemCpuTime.getCountLocked(which); |
| 5960 | } |
| 5961 | |
| 5962 | @Override |
Adam Lesinski | a7a4ccc | 2015-06-26 17:43:04 -0700 | [diff] [blame] | 5963 | public long getCpuPowerMaUs(int which) { |
| 5964 | return mCpuPower.getCountLocked(which); |
| 5965 | } |
| 5966 | |
| 5967 | @Override |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 5968 | public long getTimeAtCpuSpeed(int cluster, int step, int which) { |
| 5969 | if (mCpuClusterSpeed != null) { |
| 5970 | if (cluster >= 0 && cluster < mCpuClusterSpeed.length) { |
| 5971 | final LongSamplingCounter[] cpuSpeeds = mCpuClusterSpeed[cluster]; |
| 5972 | if (cpuSpeeds != null) { |
| 5973 | if (step >= 0 && step < cpuSpeeds.length) { |
| 5974 | final LongSamplingCounter c = cpuSpeeds[step]; |
| 5975 | if (c != null) { |
| 5976 | return c.getCountLocked(which); |
| 5977 | } |
| 5978 | } |
| 5979 | } |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 5980 | } |
| 5981 | } |
| 5982 | return 0; |
| 5983 | } |
| 5984 | |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 5985 | public void noteMobileRadioApWakeupLocked() { |
| 5986 | if (mMobileRadioApWakeupCount == null) { |
| 5987 | mMobileRadioApWakeupCount = new LongSamplingCounter(mBsi.mOnBatteryTimeBase); |
| 5988 | } |
| 5989 | mMobileRadioApWakeupCount.addCountLocked(1); |
| 5990 | } |
| 5991 | |
| 5992 | @Override |
| 5993 | public long getMobileRadioApWakeupCount(int which) { |
| 5994 | if (mMobileRadioApWakeupCount != null) { |
| 5995 | return mMobileRadioApWakeupCount.getCountLocked(which); |
| 5996 | } |
| 5997 | return 0; |
| 5998 | } |
| 5999 | |
| 6000 | public void noteWifiRadioApWakeupLocked() { |
| 6001 | if (mWifiRadioApWakeupCount == null) { |
| 6002 | mWifiRadioApWakeupCount = new LongSamplingCounter(mBsi.mOnBatteryTimeBase); |
| 6003 | } |
| 6004 | mWifiRadioApWakeupCount.addCountLocked(1); |
| 6005 | } |
| 6006 | |
| 6007 | @Override |
| 6008 | public long getWifiRadioApWakeupCount(int which) { |
| 6009 | if (mWifiRadioApWakeupCount != null) { |
| 6010 | return mWifiRadioApWakeupCount.getCountLocked(which); |
| 6011 | } |
| 6012 | return 0; |
| 6013 | } |
| 6014 | |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 6015 | void initNetworkActivityLocked() { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6016 | mNetworkByteActivityCounters = new LongSamplingCounter[NUM_NETWORK_ACTIVITY_TYPES]; |
| 6017 | mNetworkPacketActivityCounters = new LongSamplingCounter[NUM_NETWORK_ACTIVITY_TYPES]; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 6018 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6019 | mNetworkByteActivityCounters[i] = new LongSamplingCounter(mBsi.mOnBatteryTimeBase); |
| 6020 | mNetworkPacketActivityCounters[i] = new LongSamplingCounter(mBsi.mOnBatteryTimeBase); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 6021 | } |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6022 | mMobileRadioActiveTime = new LongSamplingCounter(mBsi.mOnBatteryTimeBase); |
| 6023 | mMobileRadioActiveCount = new LongSamplingCounter(mBsi.mOnBatteryTimeBase); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6024 | } |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 6025 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6026 | /** |
| 6027 | * Clear all stats for this uid. Returns true if the uid is completely |
| 6028 | * inactive so can be dropped. |
| 6029 | */ |
Adam Lesinski | 5f212c8 | 2017-03-13 12:25:13 -0700 | [diff] [blame^] | 6030 | @VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE) |
| 6031 | public boolean reset() { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6032 | boolean active = false; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6033 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 6034 | if (mWifiRunningTimer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6035 | active |= !mWifiRunningTimer.reset(false); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 6036 | active |= mWifiRunning; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6037 | } |
| 6038 | if (mFullWifiLockTimer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6039 | active |= !mFullWifiLockTimer.reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6040 | active |= mFullWifiLockOut; |
| 6041 | } |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 6042 | if (mWifiScanTimer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6043 | active |= !mWifiScanTimer.reset(false); |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 6044 | active |= mWifiScanStarted; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6045 | } |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 6046 | if (mWifiBatchedScanTimer != null) { |
| 6047 | for (int i = 0; i < NUM_WIFI_BATCHED_SCAN_BINS; i++) { |
| 6048 | if (mWifiBatchedScanTimer[i] != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6049 | active |= !mWifiBatchedScanTimer[i].reset(false); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 6050 | } |
| 6051 | } |
| 6052 | active |= (mWifiBatchedScanBinStarted != NO_BATCHED_SCAN_STARTED); |
| 6053 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6054 | if (mWifiMulticastTimer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6055 | active |= !mWifiMulticastTimer.reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6056 | active |= mWifiMulticastEnabled; |
| 6057 | } |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 6058 | |
| 6059 | active |= !resetTimerIfNotNull(mAudioTurnedOnTimer, false); |
| 6060 | active |= !resetTimerIfNotNull(mVideoTurnedOnTimer, false); |
| 6061 | active |= !resetTimerIfNotNull(mFlashlightTurnedOnTimer, false); |
| 6062 | active |= !resetTimerIfNotNull(mCameraTurnedOnTimer, false); |
| 6063 | active |= !resetTimerIfNotNull(mForegroundActivityTimer, false); |
| 6064 | active |= !resetTimerIfNotNull(mBluetoothScanTimer, false); |
| 6065 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 6066 | if (mProcessStateTimer != null) { |
| 6067 | for (int i = 0; i < NUM_PROCESS_STATE; i++) { |
| 6068 | if (mProcessStateTimer[i] != null) { |
| 6069 | active |= !mProcessStateTimer[i].reset(false); |
| 6070 | } |
| 6071 | } |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 6072 | active |= (mProcessState != ActivityManager.PROCESS_STATE_NONEXISTENT); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 6073 | } |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 6074 | if (mVibratorOnTimer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6075 | if (mVibratorOnTimer.reset(false)) { |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 6076 | mVibratorOnTimer.detach(); |
| 6077 | mVibratorOnTimer = null; |
| 6078 | } else { |
| 6079 | active = true; |
| 6080 | } |
| 6081 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6082 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6083 | if (mUserActivityCounters != null) { |
| 6084 | for (int i=0; i<NUM_USER_ACTIVITY_TYPES; i++) { |
| 6085 | mUserActivityCounters[i].reset(false); |
| 6086 | } |
| 6087 | } |
| 6088 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6089 | if (mNetworkByteActivityCounters != null) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 6090 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6091 | mNetworkByteActivityCounters[i].reset(false); |
| 6092 | mNetworkPacketActivityCounters[i].reset(false); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 6093 | } |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 6094 | mMobileRadioActiveTime.reset(false); |
| 6095 | mMobileRadioActiveCount.reset(false); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 6096 | } |
| 6097 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 6098 | if (mWifiControllerActivity != null) { |
| 6099 | mWifiControllerActivity.reset(false); |
| 6100 | } |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 6101 | |
Adam Lesinski | 1a2b39e | 2016-04-29 17:56:58 -0700 | [diff] [blame] | 6102 | if (mBluetoothControllerActivity != null) { |
| 6103 | mBluetoothControllerActivity.reset(false); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 6104 | } |
| 6105 | |
Adam Lesinski | 1a2b39e | 2016-04-29 17:56:58 -0700 | [diff] [blame] | 6106 | if (mModemControllerActivity != null) { |
| 6107 | mModemControllerActivity.reset(false); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 6108 | } |
| 6109 | |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 6110 | mUserCpuTime.reset(false); |
| 6111 | mSystemCpuTime.reset(false); |
Adam Lesinski | a7a4ccc | 2015-06-26 17:43:04 -0700 | [diff] [blame] | 6112 | mCpuPower.reset(false); |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 6113 | |
| 6114 | if (mCpuClusterSpeed != null) { |
| 6115 | for (LongSamplingCounter[] speeds : mCpuClusterSpeed) { |
| 6116 | if (speeds != null) { |
| 6117 | for (LongSamplingCounter speed : speeds) { |
| 6118 | if (speed != null) { |
| 6119 | speed.reset(false); |
| 6120 | } |
| 6121 | } |
| 6122 | } |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 6123 | } |
| 6124 | } |
| 6125 | |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 6126 | resetLongCounterIfNotNull(mMobileRadioApWakeupCount, false); |
| 6127 | resetLongCounterIfNotNull(mWifiRadioApWakeupCount, false); |
| 6128 | |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 6129 | final ArrayMap<String, Wakelock> wakeStats = mWakelockStats.getMap(); |
| 6130 | for (int iw=wakeStats.size()-1; iw>=0; iw--) { |
| 6131 | Wakelock wl = wakeStats.valueAt(iw); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 6132 | if (wl.reset()) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 6133 | wakeStats.removeAt(iw); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 6134 | } else { |
| 6135 | active = true; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6136 | } |
| 6137 | } |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 6138 | mWakelockStats.cleanup(); |
| 6139 | final ArrayMap<String, StopwatchTimer> syncStats = mSyncStats.getMap(); |
| 6140 | for (int is=syncStats.size()-1; is>=0; is--) { |
| 6141 | StopwatchTimer timer = syncStats.valueAt(is); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 6142 | if (timer.reset(false)) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 6143 | syncStats.removeAt(is); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 6144 | timer.detach(); |
| 6145 | } else { |
| 6146 | active = true; |
| 6147 | } |
| 6148 | } |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 6149 | mSyncStats.cleanup(); |
| 6150 | final ArrayMap<String, StopwatchTimer> jobStats = mJobStats.getMap(); |
| 6151 | for (int ij=jobStats.size()-1; ij>=0; ij--) { |
| 6152 | StopwatchTimer timer = jobStats.valueAt(ij); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 6153 | if (timer.reset(false)) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 6154 | jobStats.removeAt(ij); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 6155 | timer.detach(); |
| 6156 | } else { |
| 6157 | active = true; |
| 6158 | } |
| 6159 | } |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 6160 | mJobStats.cleanup(); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 6161 | for (int ise=mSensorStats.size()-1; ise>=0; ise--) { |
| 6162 | Sensor s = mSensorStats.valueAt(ise); |
| 6163 | if (s.reset()) { |
| 6164 | mSensorStats.removeAt(ise); |
| 6165 | } else { |
| 6166 | active = true; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6167 | } |
| 6168 | } |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 6169 | for (int ip=mProcessStats.size()-1; ip>=0; ip--) { |
| 6170 | Proc proc = mProcessStats.valueAt(ip); |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 6171 | proc.detach(); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6172 | } |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 6173 | mProcessStats.clear(); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 6174 | if (mPids.size() > 0) { |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 6175 | for (int i=mPids.size()-1; i>=0; i--) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 6176 | Pid pid = mPids.valueAt(i); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 6177 | if (pid.mWakeNesting > 0) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 6178 | active = true; |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 6179 | } else { |
| 6180 | mPids.removeAt(i); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 6181 | } |
| 6182 | } |
| 6183 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6184 | if (mPackageStats.size() > 0) { |
| 6185 | Iterator<Map.Entry<String, Pkg>> it = mPackageStats.entrySet().iterator(); |
| 6186 | while (it.hasNext()) { |
| 6187 | Map.Entry<String, Pkg> pkgEntry = it.next(); |
| 6188 | Pkg p = pkgEntry.getValue(); |
| 6189 | p.detach(); |
| 6190 | if (p.mServiceStats.size() > 0) { |
| 6191 | Iterator<Map.Entry<String, Pkg.Serv>> it2 |
| 6192 | = p.mServiceStats.entrySet().iterator(); |
| 6193 | while (it2.hasNext()) { |
| 6194 | Map.Entry<String, Pkg.Serv> servEntry = it2.next(); |
| 6195 | servEntry.getValue().detach(); |
| 6196 | } |
| 6197 | } |
| 6198 | } |
| 6199 | mPackageStats.clear(); |
| 6200 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6201 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 6202 | mLastStepUserTime = mLastStepSystemTime = 0; |
| 6203 | mCurStepUserTime = mCurStepSystemTime = 0; |
| 6204 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6205 | if (!active) { |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 6206 | if (mWifiRunningTimer != null) { |
| 6207 | mWifiRunningTimer.detach(); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6208 | } |
| 6209 | if (mFullWifiLockTimer != null) { |
| 6210 | mFullWifiLockTimer.detach(); |
| 6211 | } |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 6212 | if (mWifiScanTimer != null) { |
| 6213 | mWifiScanTimer.detach(); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6214 | } |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 6215 | for (int i = 0; i < NUM_WIFI_BATCHED_SCAN_BINS; i++) { |
| 6216 | if (mWifiBatchedScanTimer[i] != null) { |
| 6217 | mWifiBatchedScanTimer[i].detach(); |
| 6218 | } |
| 6219 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6220 | if (mWifiMulticastTimer != null) { |
| 6221 | mWifiMulticastTimer.detach(); |
| 6222 | } |
| 6223 | if (mAudioTurnedOnTimer != null) { |
| 6224 | mAudioTurnedOnTimer.detach(); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 6225 | mAudioTurnedOnTimer = null; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6226 | } |
| 6227 | if (mVideoTurnedOnTimer != null) { |
| 6228 | mVideoTurnedOnTimer.detach(); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 6229 | mVideoTurnedOnTimer = null; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6230 | } |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 6231 | if (mFlashlightTurnedOnTimer != null) { |
| 6232 | mFlashlightTurnedOnTimer.detach(); |
| 6233 | mFlashlightTurnedOnTimer = null; |
| 6234 | } |
| 6235 | if (mCameraTurnedOnTimer != null) { |
| 6236 | mCameraTurnedOnTimer.detach(); |
| 6237 | mCameraTurnedOnTimer = null; |
| 6238 | } |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 6239 | if (mForegroundActivityTimer != null) { |
| 6240 | mForegroundActivityTimer.detach(); |
| 6241 | mForegroundActivityTimer = null; |
| 6242 | } |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 6243 | if (mBluetoothScanTimer != null) { |
| 6244 | mBluetoothScanTimer.detach(); |
| 6245 | mBluetoothScanTimer = null; |
| 6246 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6247 | if (mUserActivityCounters != null) { |
| 6248 | for (int i=0; i<NUM_USER_ACTIVITY_TYPES; i++) { |
| 6249 | mUserActivityCounters[i].detach(); |
| 6250 | } |
| 6251 | } |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6252 | if (mNetworkByteActivityCounters != null) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 6253 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6254 | mNetworkByteActivityCounters[i].detach(); |
| 6255 | mNetworkPacketActivityCounters[i].detach(); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 6256 | } |
| 6257 | } |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 6258 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 6259 | if (mWifiControllerActivity != null) { |
| 6260 | mWifiControllerActivity.detach(); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 6261 | } |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 6262 | |
| 6263 | if (mBluetoothControllerActivity != null) { |
| 6264 | mBluetoothControllerActivity.detach(); |
| 6265 | } |
| 6266 | |
| 6267 | if (mModemControllerActivity != null) { |
| 6268 | mModemControllerActivity.detach(); |
| 6269 | } |
| 6270 | |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 6271 | mPids.clear(); |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 6272 | |
| 6273 | mUserCpuTime.detach(); |
| 6274 | mSystemCpuTime.detach(); |
Adam Lesinski | a7a4ccc | 2015-06-26 17:43:04 -0700 | [diff] [blame] | 6275 | mCpuPower.detach(); |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 6276 | |
| 6277 | if (mCpuClusterSpeed != null) { |
| 6278 | for (LongSamplingCounter[] cpuSpeeds : mCpuClusterSpeed) { |
| 6279 | if (cpuSpeeds != null) { |
| 6280 | for (LongSamplingCounter c : cpuSpeeds) { |
| 6281 | if (c != null) { |
| 6282 | c.detach(); |
| 6283 | } |
| 6284 | } |
| 6285 | } |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 6286 | } |
| 6287 | } |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 6288 | |
| 6289 | detachLongCounterIfNotNull(mMobileRadioApWakeupCount); |
| 6290 | detachLongCounterIfNotNull(mWifiRadioApWakeupCount); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6291 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6292 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6293 | return !active; |
| 6294 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6295 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6296 | void writeToParcelLocked(Parcel out, long elapsedRealtimeUs) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 6297 | final ArrayMap<String, Wakelock> wakeStats = mWakelockStats.getMap(); |
| 6298 | int NW = wakeStats.size(); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 6299 | out.writeInt(NW); |
| 6300 | for (int iw=0; iw<NW; iw++) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 6301 | out.writeString(wakeStats.keyAt(iw)); |
| 6302 | Uid.Wakelock wakelock = wakeStats.valueAt(iw); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6303 | wakelock.writeToParcelLocked(out, elapsedRealtimeUs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6304 | } |
| 6305 | |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 6306 | final ArrayMap<String, StopwatchTimer> syncStats = mSyncStats.getMap(); |
| 6307 | int NS = syncStats.size(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 6308 | out.writeInt(NS); |
| 6309 | for (int is=0; is<NS; is++) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 6310 | out.writeString(syncStats.keyAt(is)); |
| 6311 | StopwatchTimer timer = syncStats.valueAt(is); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 6312 | Timer.writeTimerToParcel(out, timer, elapsedRealtimeUs); |
| 6313 | } |
| 6314 | |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 6315 | final ArrayMap<String, StopwatchTimer> jobStats = mJobStats.getMap(); |
| 6316 | int NJ = jobStats.size(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 6317 | out.writeInt(NJ); |
| 6318 | for (int ij=0; ij<NJ; ij++) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 6319 | out.writeString(jobStats.keyAt(ij)); |
| 6320 | StopwatchTimer timer = jobStats.valueAt(ij); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 6321 | Timer.writeTimerToParcel(out, timer, elapsedRealtimeUs); |
| 6322 | } |
| 6323 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 6324 | int NSE = mSensorStats.size(); |
| 6325 | out.writeInt(NSE); |
| 6326 | for (int ise=0; ise<NSE; ise++) { |
| 6327 | out.writeInt(mSensorStats.keyAt(ise)); |
| 6328 | Uid.Sensor sensor = mSensorStats.valueAt(ise); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6329 | sensor.writeToParcelLocked(out, elapsedRealtimeUs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6330 | } |
| 6331 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 6332 | int NP = mProcessStats.size(); |
| 6333 | out.writeInt(NP); |
| 6334 | for (int ip=0; ip<NP; ip++) { |
| 6335 | out.writeString(mProcessStats.keyAt(ip)); |
| 6336 | Uid.Proc proc = mProcessStats.valueAt(ip); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6337 | proc.writeToParcelLocked(out); |
| 6338 | } |
| 6339 | |
| 6340 | out.writeInt(mPackageStats.size()); |
| 6341 | for (Map.Entry<String, Uid.Pkg> pkgEntry : mPackageStats.entrySet()) { |
| 6342 | out.writeString(pkgEntry.getKey()); |
| 6343 | Uid.Pkg pkg = pkgEntry.getValue(); |
| 6344 | pkg.writeToParcelLocked(out); |
| 6345 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6346 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 6347 | if (mWifiRunningTimer != null) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6348 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6349 | mWifiRunningTimer.writeToParcel(out, elapsedRealtimeUs); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 6350 | } else { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6351 | out.writeInt(0); |
| 6352 | } |
| 6353 | if (mFullWifiLockTimer != null) { |
| 6354 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6355 | mFullWifiLockTimer.writeToParcel(out, elapsedRealtimeUs); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6356 | } else { |
| 6357 | out.writeInt(0); |
| 6358 | } |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 6359 | if (mWifiScanTimer != null) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6360 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6361 | mWifiScanTimer.writeToParcel(out, elapsedRealtimeUs); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6362 | } else { |
| 6363 | out.writeInt(0); |
| 6364 | } |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 6365 | for (int i = 0; i < NUM_WIFI_BATCHED_SCAN_BINS; i++) { |
| 6366 | if (mWifiBatchedScanTimer[i] != null) { |
| 6367 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6368 | mWifiBatchedScanTimer[i].writeToParcel(out, elapsedRealtimeUs); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 6369 | } else { |
| 6370 | out.writeInt(0); |
| 6371 | } |
| 6372 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6373 | if (mWifiMulticastTimer != null) { |
| 6374 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6375 | mWifiMulticastTimer.writeToParcel(out, elapsedRealtimeUs); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6376 | } else { |
| 6377 | out.writeInt(0); |
| 6378 | } |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 6379 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6380 | if (mAudioTurnedOnTimer != null) { |
| 6381 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6382 | mAudioTurnedOnTimer.writeToParcel(out, elapsedRealtimeUs); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6383 | } else { |
| 6384 | out.writeInt(0); |
| 6385 | } |
| 6386 | if (mVideoTurnedOnTimer != null) { |
| 6387 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6388 | mVideoTurnedOnTimer.writeToParcel(out, elapsedRealtimeUs); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6389 | } else { |
| 6390 | out.writeInt(0); |
| 6391 | } |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 6392 | if (mFlashlightTurnedOnTimer != null) { |
| 6393 | out.writeInt(1); |
| 6394 | mFlashlightTurnedOnTimer.writeToParcel(out, elapsedRealtimeUs); |
| 6395 | } else { |
| 6396 | out.writeInt(0); |
| 6397 | } |
| 6398 | if (mCameraTurnedOnTimer != null) { |
| 6399 | out.writeInt(1); |
| 6400 | mCameraTurnedOnTimer.writeToParcel(out, elapsedRealtimeUs); |
| 6401 | } else { |
| 6402 | out.writeInt(0); |
| 6403 | } |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 6404 | if (mForegroundActivityTimer != null) { |
| 6405 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6406 | mForegroundActivityTimer.writeToParcel(out, elapsedRealtimeUs); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 6407 | } else { |
| 6408 | out.writeInt(0); |
| 6409 | } |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 6410 | if (mBluetoothScanTimer != null) { |
| 6411 | out.writeInt(1); |
| 6412 | mBluetoothScanTimer.writeToParcel(out, elapsedRealtimeUs); |
| 6413 | } else { |
| 6414 | out.writeInt(0); |
| 6415 | } |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 6416 | for (int i = 0; i < NUM_PROCESS_STATE; i++) { |
| 6417 | if (mProcessStateTimer[i] != null) { |
| 6418 | out.writeInt(1); |
| 6419 | mProcessStateTimer[i].writeToParcel(out, elapsedRealtimeUs); |
| 6420 | } else { |
| 6421 | out.writeInt(0); |
| 6422 | } |
| 6423 | } |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 6424 | if (mVibratorOnTimer != null) { |
| 6425 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6426 | mVibratorOnTimer.writeToParcel(out, elapsedRealtimeUs); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 6427 | } else { |
| 6428 | out.writeInt(0); |
| 6429 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6430 | if (mUserActivityCounters != null) { |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 6431 | out.writeInt(1); |
| 6432 | for (int i=0; i<NUM_USER_ACTIVITY_TYPES; i++) { |
| 6433 | mUserActivityCounters[i].writeToParcel(out); |
| 6434 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6435 | } else { |
| 6436 | out.writeInt(0); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 6437 | } |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6438 | if (mNetworkByteActivityCounters != null) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 6439 | out.writeInt(1); |
| 6440 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6441 | mNetworkByteActivityCounters[i].writeToParcel(out); |
| 6442 | mNetworkPacketActivityCounters[i].writeToParcel(out); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 6443 | } |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 6444 | mMobileRadioActiveTime.writeToParcel(out); |
| 6445 | mMobileRadioActiveCount.writeToParcel(out); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 6446 | } else { |
| 6447 | out.writeInt(0); |
| 6448 | } |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 6449 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 6450 | if (mWifiControllerActivity != null) { |
| 6451 | out.writeInt(1); |
| 6452 | mWifiControllerActivity.writeToParcel(out, 0); |
| 6453 | } else { |
| 6454 | out.writeInt(0); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 6455 | } |
| 6456 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 6457 | if (mBluetoothControllerActivity != null) { |
| 6458 | out.writeInt(1); |
| 6459 | mBluetoothControllerActivity.writeToParcel(out, 0); |
| 6460 | } else { |
| 6461 | out.writeInt(0); |
| 6462 | } |
| 6463 | |
| 6464 | if (mModemControllerActivity != null) { |
| 6465 | out.writeInt(1); |
| 6466 | mModemControllerActivity.writeToParcel(out, 0); |
| 6467 | } else { |
| 6468 | out.writeInt(0); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 6469 | } |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 6470 | |
| 6471 | mUserCpuTime.writeToParcel(out); |
| 6472 | mSystemCpuTime.writeToParcel(out); |
Adam Lesinski | a7a4ccc | 2015-06-26 17:43:04 -0700 | [diff] [blame] | 6473 | mCpuPower.writeToParcel(out); |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 6474 | |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 6475 | if (mCpuClusterSpeed != null) { |
| 6476 | out.writeInt(1); |
| 6477 | out.writeInt(mCpuClusterSpeed.length); |
| 6478 | for (LongSamplingCounter[] cpuSpeeds : mCpuClusterSpeed) { |
| 6479 | if (cpuSpeeds != null) { |
| 6480 | out.writeInt(1); |
| 6481 | out.writeInt(cpuSpeeds.length); |
| 6482 | for (LongSamplingCounter c : cpuSpeeds) { |
| 6483 | if (c != null) { |
| 6484 | out.writeInt(1); |
| 6485 | c.writeToParcel(out); |
| 6486 | } else { |
| 6487 | out.writeInt(0); |
| 6488 | } |
| 6489 | } |
| 6490 | } else { |
| 6491 | out.writeInt(0); |
| 6492 | } |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 6493 | } |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 6494 | } else { |
| 6495 | out.writeInt(0); |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 6496 | } |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 6497 | |
| 6498 | if (mMobileRadioApWakeupCount != null) { |
| 6499 | out.writeInt(1); |
| 6500 | mMobileRadioApWakeupCount.writeToParcel(out); |
| 6501 | } else { |
| 6502 | out.writeInt(0); |
| 6503 | } |
| 6504 | |
| 6505 | if (mWifiRadioApWakeupCount != null) { |
| 6506 | out.writeInt(1); |
| 6507 | mWifiRadioApWakeupCount.writeToParcel(out); |
| 6508 | } else { |
| 6509 | out.writeInt(0); |
| 6510 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6511 | } |
| 6512 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6513 | void readFromParcelLocked(TimeBase timeBase, TimeBase screenOffTimeBase, Parcel in) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6514 | int numWakelocks = in.readInt(); |
| 6515 | mWakelockStats.clear(); |
| 6516 | for (int j = 0; j < numWakelocks; j++) { |
| 6517 | String wakelockName = in.readString(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6518 | Uid.Wakelock wakelock = new Wakelock(mBsi, this); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6519 | wakelock.readFromParcelLocked(timeBase, screenOffTimeBase, in); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 6520 | mWakelockStats.add(wakelockName, wakelock); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6521 | } |
| 6522 | |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 6523 | int numSyncs = in.readInt(); |
| 6524 | mSyncStats.clear(); |
| 6525 | for (int j = 0; j < numSyncs; j++) { |
| 6526 | String syncName = in.readString(); |
| 6527 | if (in.readInt() != 0) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 6528 | mSyncStats.add(syncName, |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6529 | new StopwatchTimer(mBsi.mClocks, Uid.this, SYNC, null, timeBase, in)); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 6530 | } |
| 6531 | } |
| 6532 | |
| 6533 | int numJobs = in.readInt(); |
| 6534 | mJobStats.clear(); |
| 6535 | for (int j = 0; j < numJobs; j++) { |
| 6536 | String jobName = in.readString(); |
| 6537 | if (in.readInt() != 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6538 | mJobStats.add(jobName, new StopwatchTimer(mBsi.mClocks, Uid.this, JOB, null, |
| 6539 | timeBase, in)); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 6540 | } |
| 6541 | } |
| 6542 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6543 | int numSensors = in.readInt(); |
| 6544 | mSensorStats.clear(); |
| 6545 | for (int k = 0; k < numSensors; k++) { |
| 6546 | int sensorNumber = in.readInt(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6547 | Uid.Sensor sensor = new Sensor(mBsi, this, sensorNumber); |
| 6548 | sensor.readFromParcelLocked(mBsi.mOnBatteryTimeBase, in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6549 | mSensorStats.put(sensorNumber, sensor); |
| 6550 | } |
| 6551 | |
| 6552 | int numProcs = in.readInt(); |
| 6553 | mProcessStats.clear(); |
| 6554 | for (int k = 0; k < numProcs; k++) { |
| 6555 | String processName = in.readString(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6556 | Uid.Proc proc = new Proc(mBsi, processName); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6557 | proc.readFromParcelLocked(in); |
| 6558 | mProcessStats.put(processName, proc); |
| 6559 | } |
| 6560 | |
| 6561 | int numPkgs = in.readInt(); |
| 6562 | mPackageStats.clear(); |
| 6563 | for (int l = 0; l < numPkgs; l++) { |
| 6564 | String packageName = in.readString(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6565 | Uid.Pkg pkg = new Pkg(mBsi); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6566 | pkg.readFromParcelLocked(in); |
| 6567 | mPackageStats.put(packageName, pkg); |
| 6568 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6569 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 6570 | mWifiRunning = false; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6571 | if (in.readInt() != 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6572 | mWifiRunningTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, WIFI_RUNNING, |
| 6573 | mBsi.mWifiRunningTimers, mBsi.mOnBatteryTimeBase, in); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 6574 | } else { |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 6575 | mWifiRunningTimer = null; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6576 | } |
| 6577 | mFullWifiLockOut = false; |
| 6578 | if (in.readInt() != 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6579 | mFullWifiLockTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, FULL_WIFI_LOCK, |
| 6580 | mBsi.mFullWifiLockTimers, mBsi.mOnBatteryTimeBase, in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6581 | } else { |
| 6582 | mFullWifiLockTimer = null; |
| 6583 | } |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 6584 | mWifiScanStarted = false; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6585 | if (in.readInt() != 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6586 | mWifiScanTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, WIFI_SCAN, |
| 6587 | mBsi.mWifiScanTimers, mBsi.mOnBatteryTimeBase, in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6588 | } else { |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 6589 | mWifiScanTimer = null; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6590 | } |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 6591 | mWifiBatchedScanBinStarted = NO_BATCHED_SCAN_STARTED; |
| 6592 | for (int i = 0; i < NUM_WIFI_BATCHED_SCAN_BINS; i++) { |
| 6593 | if (in.readInt() != 0) { |
| 6594 | makeWifiBatchedScanBin(i, in); |
| 6595 | } else { |
| 6596 | mWifiBatchedScanTimer[i] = null; |
| 6597 | } |
| 6598 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6599 | mWifiMulticastEnabled = false; |
| 6600 | if (in.readInt() != 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6601 | mWifiMulticastTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, WIFI_MULTICAST_ENABLED, |
| 6602 | mBsi.mWifiMulticastTimers, mBsi.mOnBatteryTimeBase, in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6603 | } else { |
| 6604 | mWifiMulticastTimer = null; |
| 6605 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6606 | if (in.readInt() != 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6607 | mAudioTurnedOnTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, AUDIO_TURNED_ON, |
| 6608 | mBsi.mAudioTurnedOnTimers, mBsi.mOnBatteryTimeBase, in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6609 | } else { |
| 6610 | mAudioTurnedOnTimer = null; |
| 6611 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6612 | if (in.readInt() != 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6613 | mVideoTurnedOnTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, VIDEO_TURNED_ON, |
| 6614 | mBsi.mVideoTurnedOnTimers, mBsi.mOnBatteryTimeBase, in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6615 | } else { |
| 6616 | mVideoTurnedOnTimer = null; |
| 6617 | } |
| 6618 | if (in.readInt() != 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6619 | mFlashlightTurnedOnTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, |
| 6620 | FLASHLIGHT_TURNED_ON, mBsi.mFlashlightTurnedOnTimers, mBsi.mOnBatteryTimeBase, in); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 6621 | } else { |
| 6622 | mFlashlightTurnedOnTimer = null; |
| 6623 | } |
| 6624 | if (in.readInt() != 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6625 | mCameraTurnedOnTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, CAMERA_TURNED_ON, |
| 6626 | mBsi.mCameraTurnedOnTimers, mBsi.mOnBatteryTimeBase, in); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 6627 | } else { |
| 6628 | mCameraTurnedOnTimer = null; |
| 6629 | } |
| 6630 | if (in.readInt() != 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6631 | mForegroundActivityTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, |
| 6632 | FOREGROUND_ACTIVITY, null, mBsi.mOnBatteryTimeBase, in); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 6633 | } else { |
| 6634 | mForegroundActivityTimer = null; |
| 6635 | } |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 6636 | if (in.readInt() != 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6637 | mBluetoothScanTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, BLUETOOTH_SCAN_ON, |
| 6638 | mBsi.mBluetoothScanOnTimers, mBsi.mOnBatteryTimeBase, in); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 6639 | } else { |
| 6640 | mBluetoothScanTimer = null; |
| 6641 | } |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 6642 | mProcessState = ActivityManager.PROCESS_STATE_NONEXISTENT; |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 6643 | for (int i = 0; i < NUM_PROCESS_STATE; i++) { |
| 6644 | if (in.readInt() != 0) { |
| 6645 | makeProcessState(i, in); |
| 6646 | } else { |
| 6647 | mProcessStateTimer[i] = null; |
| 6648 | } |
| 6649 | } |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 6650 | if (in.readInt() != 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6651 | mVibratorOnTimer = new BatchTimer(mBsi.mClocks, Uid.this, VIBRATOR_ON, |
| 6652 | mBsi.mOnBatteryTimeBase, in); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 6653 | } else { |
| 6654 | mVibratorOnTimer = null; |
| 6655 | } |
| 6656 | if (in.readInt() != 0) { |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 6657 | mUserActivityCounters = new Counter[NUM_USER_ACTIVITY_TYPES]; |
| 6658 | for (int i=0; i<NUM_USER_ACTIVITY_TYPES; i++) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6659 | mUserActivityCounters[i] = new Counter(mBsi.mOnBatteryTimeBase, in); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 6660 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6661 | } else { |
| 6662 | mUserActivityCounters = null; |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 6663 | } |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 6664 | if (in.readInt() != 0) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6665 | mNetworkByteActivityCounters = new LongSamplingCounter[NUM_NETWORK_ACTIVITY_TYPES]; |
| 6666 | mNetworkPacketActivityCounters |
| 6667 | = new LongSamplingCounter[NUM_NETWORK_ACTIVITY_TYPES]; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 6668 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6669 | mNetworkByteActivityCounters[i] |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6670 | = new LongSamplingCounter(mBsi.mOnBatteryTimeBase, in); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6671 | mNetworkPacketActivityCounters[i] |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6672 | = new LongSamplingCounter(mBsi.mOnBatteryTimeBase, in); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 6673 | } |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6674 | mMobileRadioActiveTime = new LongSamplingCounter(mBsi.mOnBatteryTimeBase, in); |
| 6675 | mMobileRadioActiveCount = new LongSamplingCounter(mBsi.mOnBatteryTimeBase, in); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 6676 | } else { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6677 | mNetworkByteActivityCounters = null; |
| 6678 | mNetworkPacketActivityCounters = null; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 6679 | } |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 6680 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 6681 | if (in.readInt() != 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6682 | mWifiControllerActivity = new ControllerActivityCounterImpl(mBsi.mOnBatteryTimeBase, |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 6683 | NUM_WIFI_TX_LEVELS, in); |
| 6684 | } else { |
| 6685 | mWifiControllerActivity = null; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 6686 | } |
| 6687 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 6688 | if (in.readInt() != 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6689 | mBluetoothControllerActivity = new ControllerActivityCounterImpl(mBsi.mOnBatteryTimeBase, |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 6690 | NUM_BT_TX_LEVELS, in); |
| 6691 | } else { |
| 6692 | mBluetoothControllerActivity = null; |
| 6693 | } |
| 6694 | |
| 6695 | if (in.readInt() != 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6696 | mModemControllerActivity = new ControllerActivityCounterImpl(mBsi.mOnBatteryTimeBase, |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 6697 | ModemActivityInfo.TX_POWER_LEVELS, in); |
| 6698 | } else { |
| 6699 | mModemControllerActivity = null; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 6700 | } |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 6701 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6702 | mUserCpuTime = new LongSamplingCounter(mBsi.mOnBatteryTimeBase, in); |
| 6703 | mSystemCpuTime = new LongSamplingCounter(mBsi.mOnBatteryTimeBase, in); |
| 6704 | mCpuPower = new LongSamplingCounter(mBsi.mOnBatteryTimeBase, in); |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 6705 | |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 6706 | if (in.readInt() != 0) { |
| 6707 | int numCpuClusters = in.readInt(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6708 | if (mBsi.mPowerProfile != null && mBsi.mPowerProfile.getNumCpuClusters() != numCpuClusters) { |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 6709 | throw new ParcelFormatException("Incompatible number of cpu clusters"); |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 6710 | } |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 6711 | |
| 6712 | mCpuClusterSpeed = new LongSamplingCounter[numCpuClusters][]; |
| 6713 | for (int cluster = 0; cluster < numCpuClusters; cluster++) { |
| 6714 | if (in.readInt() != 0) { |
| 6715 | int numSpeeds = in.readInt(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6716 | if (mBsi.mPowerProfile != null && |
| 6717 | mBsi.mPowerProfile.getNumSpeedStepsInCpuCluster(cluster) != numSpeeds) { |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 6718 | throw new ParcelFormatException("Incompatible number of cpu speeds"); |
| 6719 | } |
| 6720 | |
| 6721 | final LongSamplingCounter[] cpuSpeeds = new LongSamplingCounter[numSpeeds]; |
| 6722 | mCpuClusterSpeed[cluster] = cpuSpeeds; |
| 6723 | for (int speed = 0; speed < numSpeeds; speed++) { |
| 6724 | if (in.readInt() != 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6725 | cpuSpeeds[speed] = new LongSamplingCounter(mBsi.mOnBatteryTimeBase, in); |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 6726 | } |
| 6727 | } |
Adam Lesinski | a57a540 | 2015-09-28 10:21:33 -0700 | [diff] [blame] | 6728 | } else { |
| 6729 | mCpuClusterSpeed[cluster] = null; |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 6730 | } |
| 6731 | } |
| 6732 | } else { |
| 6733 | mCpuClusterSpeed = null; |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 6734 | } |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 6735 | |
| 6736 | if (in.readInt() != 0) { |
| 6737 | mMobileRadioApWakeupCount = new LongSamplingCounter(mBsi.mOnBatteryTimeBase, in); |
| 6738 | } else { |
| 6739 | mMobileRadioApWakeupCount = null; |
| 6740 | } |
| 6741 | |
| 6742 | if (in.readInt() != 0) { |
| 6743 | mWifiRadioApWakeupCount = new LongSamplingCounter(mBsi.mOnBatteryTimeBase, in); |
| 6744 | } else { |
| 6745 | mWifiRadioApWakeupCount = null; |
| 6746 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6747 | } |
| 6748 | |
| 6749 | /** |
| 6750 | * The statistics associated with a particular wake lock. |
| 6751 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6752 | public static class Wakelock extends BatteryStats.Uid.Wakelock { |
| 6753 | /** |
| 6754 | * BatteryStatsImpl that we are associated with. |
| 6755 | */ |
| 6756 | protected BatteryStatsImpl mBsi; |
| 6757 | |
| 6758 | /** |
| 6759 | * BatteryStatsImpl that we are associated with. |
| 6760 | */ |
| 6761 | protected Uid mUid; |
| 6762 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6763 | /** |
| 6764 | * How long (in ms) this uid has been keeping the device partially awake. |
| 6765 | */ |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 6766 | DurationTimer mTimerPartial; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6767 | |
| 6768 | /** |
| 6769 | * How long (in ms) this uid has been keeping the device fully awake. |
| 6770 | */ |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 6771 | StopwatchTimer mTimerFull; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6772 | |
| 6773 | /** |
| 6774 | * How long (in ms) this uid has had a window keeping the device awake. |
| 6775 | */ |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 6776 | StopwatchTimer mTimerWindow; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6777 | |
| 6778 | /** |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 6779 | * How long (in ms) this uid has had a draw wake lock. |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 6780 | */ |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 6781 | StopwatchTimer mTimerDraw; |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 6782 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6783 | public Wakelock(BatteryStatsImpl bsi, Uid uid) { |
| 6784 | mBsi = bsi; |
| 6785 | mUid = uid; |
| 6786 | } |
| 6787 | |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 6788 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6789 | * Reads a possibly null Timer from a Parcel. The timer is associated with the |
| 6790 | * proper timer pool from the given BatteryStatsImpl object. |
| 6791 | * |
| 6792 | * @param in the Parcel to be read from. |
| 6793 | * return a new Timer, or null. |
| 6794 | */ |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 6795 | private StopwatchTimer readStopwatchTimerFromParcel(int type, |
| 6796 | ArrayList<StopwatchTimer> pool, TimeBase timeBase, Parcel in) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6797 | if (in.readInt() == 0) { |
| 6798 | return null; |
| 6799 | } |
| 6800 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6801 | 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] | 6802 | } |
| 6803 | |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 6804 | /** |
| 6805 | * Reads a possibly null Timer from a Parcel. The timer is associated with the |
| 6806 | * proper timer pool from the given BatteryStatsImpl object. |
| 6807 | * |
| 6808 | * @param in the Parcel to be read from. |
| 6809 | * return a new Timer, or null. |
| 6810 | */ |
| 6811 | private DurationTimer readDurationTimerFromParcel(int type, |
| 6812 | ArrayList<StopwatchTimer> pool, TimeBase timeBase, Parcel in) { |
| 6813 | if (in.readInt() == 0) { |
| 6814 | return null; |
| 6815 | } |
| 6816 | |
| 6817 | return new DurationTimer(mBsi.mClocks, mUid, type, pool, timeBase, in); |
| 6818 | } |
| 6819 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6820 | boolean reset() { |
| 6821 | boolean wlactive = false; |
| 6822 | if (mTimerFull != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6823 | wlactive |= !mTimerFull.reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6824 | } |
| 6825 | if (mTimerPartial != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6826 | wlactive |= !mTimerPartial.reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6827 | } |
| 6828 | if (mTimerWindow != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6829 | wlactive |= !mTimerWindow.reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6830 | } |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 6831 | if (mTimerDraw != null) { |
| 6832 | wlactive |= !mTimerDraw.reset(false); |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 6833 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6834 | if (!wlactive) { |
| 6835 | if (mTimerFull != null) { |
| 6836 | mTimerFull.detach(); |
| 6837 | mTimerFull = null; |
| 6838 | } |
| 6839 | if (mTimerPartial != null) { |
| 6840 | mTimerPartial.detach(); |
| 6841 | mTimerPartial = null; |
| 6842 | } |
| 6843 | if (mTimerWindow != null) { |
| 6844 | mTimerWindow.detach(); |
| 6845 | mTimerWindow = null; |
| 6846 | } |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 6847 | if (mTimerDraw != null) { |
| 6848 | mTimerDraw.detach(); |
| 6849 | mTimerDraw = null; |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 6850 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6851 | } |
| 6852 | return !wlactive; |
| 6853 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6854 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6855 | void readFromParcelLocked(TimeBase timeBase, TimeBase screenOffTimeBase, Parcel in) { |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 6856 | mTimerPartial = readDurationTimerFromParcel(WAKE_TYPE_PARTIAL, |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6857 | mBsi.mPartialTimers, screenOffTimeBase, in); |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 6858 | mTimerFull = readStopwatchTimerFromParcel(WAKE_TYPE_FULL, |
| 6859 | mBsi.mFullTimers, timeBase, in); |
| 6860 | mTimerWindow = readStopwatchTimerFromParcel(WAKE_TYPE_WINDOW, |
| 6861 | mBsi.mWindowTimers, timeBase, in); |
| 6862 | mTimerDraw = readStopwatchTimerFromParcel(WAKE_TYPE_DRAW, |
| 6863 | mBsi.mDrawTimers, timeBase, in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6864 | } |
| 6865 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6866 | void writeToParcelLocked(Parcel out, long elapsedRealtimeUs) { |
| 6867 | Timer.writeTimerToParcel(out, mTimerPartial, elapsedRealtimeUs); |
| 6868 | Timer.writeTimerToParcel(out, mTimerFull, elapsedRealtimeUs); |
| 6869 | Timer.writeTimerToParcel(out, mTimerWindow, elapsedRealtimeUs); |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 6870 | Timer.writeTimerToParcel(out, mTimerDraw, elapsedRealtimeUs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6871 | } |
| 6872 | |
| 6873 | @Override |
| 6874 | public Timer getWakeTime(int type) { |
| 6875 | switch (type) { |
| 6876 | case WAKE_TYPE_FULL: return mTimerFull; |
| 6877 | case WAKE_TYPE_PARTIAL: return mTimerPartial; |
| 6878 | case WAKE_TYPE_WINDOW: return mTimerWindow; |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 6879 | case WAKE_TYPE_DRAW: return mTimerDraw; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6880 | default: throw new IllegalArgumentException("type = " + type); |
| 6881 | } |
| 6882 | } |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 6883 | |
| 6884 | public StopwatchTimer getStopwatchTimer(int type) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 6885 | switch (type) { |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 6886 | case WAKE_TYPE_PARTIAL: { |
| 6887 | DurationTimer t = mTimerPartial; |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 6888 | if (t == null) { |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 6889 | t = new DurationTimer(mBsi.mClocks, mUid, WAKE_TYPE_PARTIAL, |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6890 | mBsi.mPartialTimers, mBsi.mOnBatteryScreenOffTimeBase); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 6891 | mTimerPartial = t; |
| 6892 | } |
| 6893 | return t; |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 6894 | } |
| 6895 | case WAKE_TYPE_FULL: { |
| 6896 | StopwatchTimer t = mTimerFull; |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 6897 | if (t == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6898 | t = new StopwatchTimer(mBsi.mClocks, mUid, WAKE_TYPE_FULL, |
| 6899 | mBsi.mFullTimers, mBsi.mOnBatteryTimeBase); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 6900 | mTimerFull = t; |
| 6901 | } |
| 6902 | return t; |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 6903 | } |
| 6904 | case WAKE_TYPE_WINDOW: { |
| 6905 | StopwatchTimer t = mTimerWindow; |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 6906 | if (t == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6907 | t = new StopwatchTimer(mBsi.mClocks, mUid, WAKE_TYPE_WINDOW, |
| 6908 | mBsi.mWindowTimers, mBsi.mOnBatteryTimeBase); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 6909 | mTimerWindow = t; |
| 6910 | } |
| 6911 | return t; |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 6912 | } |
| 6913 | case WAKE_TYPE_DRAW: { |
| 6914 | StopwatchTimer t = mTimerDraw; |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 6915 | if (t == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6916 | t = new StopwatchTimer(mBsi.mClocks, mUid, WAKE_TYPE_DRAW, |
| 6917 | mBsi.mDrawTimers, mBsi.mOnBatteryTimeBase); |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 6918 | mTimerDraw = t; |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 6919 | } |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 6920 | return t; |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 6921 | } |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 6922 | default: |
| 6923 | throw new IllegalArgumentException("type=" + type); |
| 6924 | } |
| 6925 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6926 | } |
| 6927 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6928 | public static class Sensor extends BatteryStats.Uid.Sensor { |
| 6929 | /** |
| 6930 | * BatteryStatsImpl that we are associated with. |
| 6931 | */ |
| 6932 | protected BatteryStatsImpl mBsi; |
| 6933 | |
| 6934 | /** |
| 6935 | * BatteryStatsImpl that we are associated with. |
| 6936 | */ |
| 6937 | protected Uid mUid; |
| 6938 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6939 | final int mHandle; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 6940 | StopwatchTimer mTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6941 | |
Amith Yamasani | ab9ad19 | 2016-12-06 12:46:59 -0800 | [diff] [blame] | 6942 | Counter mBgCounter; |
| 6943 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6944 | public Sensor(BatteryStatsImpl bsi, Uid uid, int handle) { |
| 6945 | mBsi = bsi; |
| 6946 | mUid = uid; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6947 | mHandle = handle; |
| 6948 | } |
| 6949 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6950 | private StopwatchTimer readTimerFromParcel(TimeBase timeBase, Parcel in) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6951 | if (in.readInt() == 0) { |
| 6952 | return null; |
| 6953 | } |
| 6954 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6955 | ArrayList<StopwatchTimer> pool = mBsi.mSensorTimers.get(mHandle); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6956 | if (pool == null) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 6957 | pool = new ArrayList<StopwatchTimer>(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6958 | mBsi.mSensorTimers.put(mHandle, pool); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6959 | } |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6960 | 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] | 6961 | } |
| 6962 | |
Amith Yamasani | ab9ad19 | 2016-12-06 12:46:59 -0800 | [diff] [blame] | 6963 | private Counter readCounterFromParcel(TimeBase timeBase, Parcel in) { |
| 6964 | if (in.readInt() == 0) { |
| 6965 | return null; |
| 6966 | } |
| 6967 | return new Counter(timeBase, in); |
| 6968 | } |
| 6969 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6970 | boolean reset() { |
Amith Yamasani | ab9ad19 | 2016-12-06 12:46:59 -0800 | [diff] [blame] | 6971 | if (mBgCounter != null) { |
Adam Lesinski | 5f212c8 | 2017-03-13 12:25:13 -0700 | [diff] [blame^] | 6972 | mBgCounter.reset(true /*detachIfReset*/); |
| 6973 | // If we detach, we must null the mBgCounter reference so that it |
| 6974 | // can be recreated and attached. |
| 6975 | mBgCounter = null; |
Amith Yamasani | ab9ad19 | 2016-12-06 12:46:59 -0800 | [diff] [blame] | 6976 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6977 | if (mTimer.reset(true)) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6978 | mTimer = null; |
| 6979 | return true; |
| 6980 | } |
| 6981 | return false; |
| 6982 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6983 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6984 | void readFromParcelLocked(TimeBase timeBase, Parcel in) { |
| 6985 | mTimer = readTimerFromParcel(timeBase, in); |
Amith Yamasani | ab9ad19 | 2016-12-06 12:46:59 -0800 | [diff] [blame] | 6986 | mBgCounter = readCounterFromParcel(timeBase, in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6987 | } |
| 6988 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6989 | void writeToParcelLocked(Parcel out, long elapsedRealtimeUs) { |
| 6990 | Timer.writeTimerToParcel(out, mTimer, elapsedRealtimeUs); |
Amith Yamasani | ab9ad19 | 2016-12-06 12:46:59 -0800 | [diff] [blame] | 6991 | Counter.writeCounterToParcel(out, mBgCounter); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6992 | } |
| 6993 | |
| 6994 | @Override |
| 6995 | public Timer getSensorTime() { |
| 6996 | return mTimer; |
| 6997 | } |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 6998 | |
| 6999 | @Override |
Amith Yamasani | ab9ad19 | 2016-12-06 12:46:59 -0800 | [diff] [blame] | 7000 | public Counter getSensorBgCount() { |
| 7001 | return mBgCounter; |
| 7002 | } |
| 7003 | |
| 7004 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7005 | public int getHandle() { |
| 7006 | return mHandle; |
| 7007 | } |
| 7008 | } |
| 7009 | |
| 7010 | /** |
| 7011 | * The statistics associated with a particular process. |
| 7012 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7013 | public static class Proc extends BatteryStats.Uid.Proc implements TimeBaseObs { |
| 7014 | /** |
| 7015 | * BatteryStatsImpl that we are associated with. |
| 7016 | */ |
| 7017 | protected BatteryStatsImpl mBsi; |
| 7018 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7019 | /** |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 7020 | * The name of this process. |
| 7021 | */ |
| 7022 | final String mName; |
| 7023 | |
| 7024 | /** |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 7025 | * Remains true until removed from the stats. |
| 7026 | */ |
| 7027 | boolean mActive = true; |
| 7028 | |
| 7029 | /** |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 7030 | * Total time (in ms) spent executing in user code. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7031 | */ |
| 7032 | long mUserTime; |
| 7033 | |
| 7034 | /** |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 7035 | * Total time (in ms) spent executing in kernel code. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7036 | */ |
| 7037 | long mSystemTime; |
| 7038 | |
| 7039 | /** |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 7040 | * Amount of time (in ms) the process was running in the foreground. |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 7041 | */ |
| 7042 | long mForegroundTime; |
| 7043 | |
| 7044 | /** |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 7045 | * Number of times the process has been started. |
| 7046 | */ |
| 7047 | int mStarts; |
| 7048 | |
| 7049 | /** |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 7050 | * Number of times the process has crashed. |
| 7051 | */ |
| 7052 | int mNumCrashes; |
| 7053 | |
| 7054 | /** |
| 7055 | * Number of times the process has had an ANR. |
| 7056 | */ |
| 7057 | int mNumAnrs; |
| 7058 | |
| 7059 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7060 | * The amount of user time loaded from a previous save. |
| 7061 | */ |
| 7062 | long mLoadedUserTime; |
| 7063 | |
| 7064 | /** |
| 7065 | * The amount of system time loaded from a previous save. |
| 7066 | */ |
| 7067 | long mLoadedSystemTime; |
| 7068 | |
| 7069 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 7070 | * The amount of foreground time loaded from a previous save. |
| 7071 | */ |
| 7072 | long mLoadedForegroundTime; |
| 7073 | |
| 7074 | /** |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 7075 | * The number of times the process has started from a previous save. |
| 7076 | */ |
| 7077 | int mLoadedStarts; |
| 7078 | |
| 7079 | /** |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 7080 | * 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] | 7081 | */ |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 7082 | int mLoadedNumCrashes; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7083 | |
| 7084 | /** |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 7085 | * 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] | 7086 | */ |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 7087 | int mLoadedNumAnrs; |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 7088 | |
| 7089 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7090 | * The amount of user time when last unplugged. |
| 7091 | */ |
| 7092 | long mUnpluggedUserTime; |
| 7093 | |
| 7094 | /** |
| 7095 | * The amount of system time when last unplugged. |
| 7096 | */ |
| 7097 | long mUnpluggedSystemTime; |
| 7098 | |
| 7099 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 7100 | * The amount of foreground time since unplugged. |
| 7101 | */ |
| 7102 | long mUnpluggedForegroundTime; |
| 7103 | |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 7104 | /** |
| 7105 | * The number of times the process has started before unplugged. |
| 7106 | */ |
| 7107 | int mUnpluggedStarts; |
| 7108 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 7109 | /** |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 7110 | * Number of times the process has crashed before unplugged. |
| 7111 | */ |
| 7112 | int mUnpluggedNumCrashes; |
| 7113 | |
| 7114 | /** |
| 7115 | * Number of times the process has had an ANR before unplugged. |
| 7116 | */ |
| 7117 | int mUnpluggedNumAnrs; |
| 7118 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 7119 | ArrayList<ExcessivePower> mExcessivePower; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 7120 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7121 | public Proc(BatteryStatsImpl bsi, String name) { |
| 7122 | mBsi = bsi; |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 7123 | mName = name; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7124 | mBsi.mOnBatteryTimeBase.add(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7125 | } |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 7126 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7127 | public void onTimeStarted(long elapsedRealtime, long baseUptime, long baseRealtime) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7128 | mUnpluggedUserTime = mUserTime; |
| 7129 | mUnpluggedSystemTime = mSystemTime; |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 7130 | mUnpluggedForegroundTime = mForegroundTime; |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 7131 | mUnpluggedStarts = mStarts; |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 7132 | mUnpluggedNumCrashes = mNumCrashes; |
| 7133 | mUnpluggedNumAnrs = mNumAnrs; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7134 | } |
| 7135 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7136 | public void onTimeStopped(long elapsedRealtime, long baseUptime, long baseRealtime) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7137 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7138 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7139 | void detach() { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 7140 | mActive = false; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7141 | mBsi.mOnBatteryTimeBase.remove(this); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7142 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7143 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 7144 | public int countExcessivePowers() { |
| 7145 | return mExcessivePower != null ? mExcessivePower.size() : 0; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 7146 | } |
| 7147 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 7148 | public ExcessivePower getExcessivePower(int i) { |
| 7149 | if (mExcessivePower != null) { |
| 7150 | return mExcessivePower.get(i); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 7151 | } |
| 7152 | return null; |
| 7153 | } |
| 7154 | |
| 7155 | public void addExcessiveWake(long overTime, long usedTime) { |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 7156 | if (mExcessivePower == null) { |
| 7157 | mExcessivePower = new ArrayList<ExcessivePower>(); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 7158 | } |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 7159 | ExcessivePower ew = new ExcessivePower(); |
| 7160 | ew.type = ExcessivePower.TYPE_WAKE; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 7161 | ew.overTime = overTime; |
| 7162 | ew.usedTime = usedTime; |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 7163 | mExcessivePower.add(ew); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 7164 | } |
| 7165 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 7166 | public void addExcessiveCpu(long overTime, long usedTime) { |
| 7167 | if (mExcessivePower == null) { |
| 7168 | mExcessivePower = new ArrayList<ExcessivePower>(); |
| 7169 | } |
| 7170 | ExcessivePower ew = new ExcessivePower(); |
| 7171 | ew.type = ExcessivePower.TYPE_CPU; |
| 7172 | ew.overTime = overTime; |
| 7173 | ew.usedTime = usedTime; |
| 7174 | mExcessivePower.add(ew); |
| 7175 | } |
| 7176 | |
| 7177 | void writeExcessivePowerToParcelLocked(Parcel out) { |
| 7178 | if (mExcessivePower == null) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 7179 | out.writeInt(0); |
| 7180 | return; |
| 7181 | } |
| 7182 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 7183 | final int N = mExcessivePower.size(); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 7184 | out.writeInt(N); |
| 7185 | for (int i=0; i<N; i++) { |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 7186 | ExcessivePower ew = mExcessivePower.get(i); |
| 7187 | out.writeInt(ew.type); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 7188 | out.writeLong(ew.overTime); |
| 7189 | out.writeLong(ew.usedTime); |
| 7190 | } |
| 7191 | } |
| 7192 | |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 7193 | void readExcessivePowerFromParcelLocked(Parcel in) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 7194 | final int N = in.readInt(); |
| 7195 | if (N == 0) { |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 7196 | mExcessivePower = null; |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 7197 | return; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 7198 | } |
| 7199 | |
Dianne Hackborn | 7b9c56f | 2010-12-07 11:14:53 -0800 | [diff] [blame] | 7200 | if (N > 10000) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 7201 | throw new ParcelFormatException( |
| 7202 | "File corrupt: too many excessive power entries " + N); |
Dianne Hackborn | 7b9c56f | 2010-12-07 11:14:53 -0800 | [diff] [blame] | 7203 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 7204 | |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 7205 | mExcessivePower = new ArrayList<>(); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 7206 | for (int i=0; i<N; i++) { |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 7207 | ExcessivePower ew = new ExcessivePower(); |
| 7208 | ew.type = in.readInt(); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 7209 | ew.overTime = in.readLong(); |
| 7210 | ew.usedTime = in.readLong(); |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 7211 | mExcessivePower.add(ew); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 7212 | } |
| 7213 | } |
| 7214 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7215 | void writeToParcelLocked(Parcel out) { |
| 7216 | out.writeLong(mUserTime); |
| 7217 | out.writeLong(mSystemTime); |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 7218 | out.writeLong(mForegroundTime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7219 | out.writeInt(mStarts); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 7220 | out.writeInt(mNumCrashes); |
| 7221 | out.writeInt(mNumAnrs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7222 | out.writeLong(mLoadedUserTime); |
| 7223 | out.writeLong(mLoadedSystemTime); |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 7224 | out.writeLong(mLoadedForegroundTime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7225 | out.writeInt(mLoadedStarts); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 7226 | out.writeInt(mLoadedNumCrashes); |
| 7227 | out.writeInt(mLoadedNumAnrs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7228 | out.writeLong(mUnpluggedUserTime); |
| 7229 | out.writeLong(mUnpluggedSystemTime); |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 7230 | out.writeLong(mUnpluggedForegroundTime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7231 | out.writeInt(mUnpluggedStarts); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 7232 | out.writeInt(mUnpluggedNumCrashes); |
| 7233 | out.writeInt(mUnpluggedNumAnrs); |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 7234 | writeExcessivePowerToParcelLocked(out); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7235 | } |
| 7236 | |
| 7237 | void readFromParcelLocked(Parcel in) { |
| 7238 | mUserTime = in.readLong(); |
| 7239 | mSystemTime = in.readLong(); |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 7240 | mForegroundTime = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7241 | mStarts = in.readInt(); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 7242 | mNumCrashes = in.readInt(); |
| 7243 | mNumAnrs = in.readInt(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7244 | mLoadedUserTime = in.readLong(); |
| 7245 | mLoadedSystemTime = in.readLong(); |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 7246 | mLoadedForegroundTime = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7247 | mLoadedStarts = in.readInt(); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 7248 | mLoadedNumCrashes = in.readInt(); |
| 7249 | mLoadedNumAnrs = in.readInt(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7250 | mUnpluggedUserTime = in.readLong(); |
| 7251 | mUnpluggedSystemTime = in.readLong(); |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 7252 | mUnpluggedForegroundTime = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7253 | mUnpluggedStarts = in.readInt(); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 7254 | mUnpluggedNumCrashes = in.readInt(); |
| 7255 | mUnpluggedNumAnrs = in.readInt(); |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 7256 | readExcessivePowerFromParcelLocked(in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7257 | } |
| 7258 | |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 7259 | public void addCpuTimeLocked(int utime, int stime) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7260 | mUserTime += utime; |
| 7261 | mSystemTime += stime; |
| 7262 | } |
| 7263 | |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 7264 | public void addForegroundTimeLocked(long ttime) { |
| 7265 | mForegroundTime += ttime; |
| 7266 | } |
| 7267 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7268 | public void incStartsLocked() { |
| 7269 | mStarts++; |
| 7270 | } |
| 7271 | |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 7272 | public void incNumCrashesLocked() { |
| 7273 | mNumCrashes++; |
| 7274 | } |
| 7275 | |
| 7276 | public void incNumAnrsLocked() { |
| 7277 | mNumAnrs++; |
| 7278 | } |
| 7279 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7280 | @Override |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 7281 | public boolean isActive() { |
| 7282 | return mActive; |
| 7283 | } |
| 7284 | |
| 7285 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7286 | public long getUserTime(int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 7287 | long val = mUserTime; |
| 7288 | if (which == STATS_CURRENT) { |
| 7289 | val -= mLoadedUserTime; |
| 7290 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 7291 | val -= mUnpluggedUserTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7292 | } |
| 7293 | return val; |
| 7294 | } |
| 7295 | |
| 7296 | @Override |
| 7297 | public long getSystemTime(int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 7298 | long val = mSystemTime; |
| 7299 | if (which == STATS_CURRENT) { |
| 7300 | val -= mLoadedSystemTime; |
| 7301 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 7302 | val -= mUnpluggedSystemTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7303 | } |
| 7304 | return val; |
| 7305 | } |
| 7306 | |
| 7307 | @Override |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 7308 | public long getForegroundTime(int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 7309 | long val = mForegroundTime; |
| 7310 | if (which == STATS_CURRENT) { |
| 7311 | val -= mLoadedForegroundTime; |
| 7312 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 7313 | val -= mUnpluggedForegroundTime; |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 7314 | } |
| 7315 | return val; |
| 7316 | } |
| 7317 | |
| 7318 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7319 | public int getStarts(int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 7320 | int val = mStarts; |
| 7321 | if (which == STATS_CURRENT) { |
| 7322 | val -= mLoadedStarts; |
| 7323 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 7324 | val -= mUnpluggedStarts; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7325 | } |
| 7326 | return val; |
| 7327 | } |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 7328 | |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 7329 | @Override |
| 7330 | public int getNumCrashes(int which) { |
| 7331 | int val = mNumCrashes; |
| 7332 | if (which == STATS_CURRENT) { |
| 7333 | val -= mLoadedNumCrashes; |
| 7334 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 7335 | val -= mUnpluggedNumCrashes; |
| 7336 | } |
| 7337 | return val; |
| 7338 | } |
| 7339 | |
| 7340 | @Override |
| 7341 | public int getNumAnrs(int which) { |
| 7342 | int val = mNumAnrs; |
| 7343 | if (which == STATS_CURRENT) { |
| 7344 | val -= mLoadedNumAnrs; |
| 7345 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 7346 | val -= mUnpluggedNumAnrs; |
| 7347 | } |
| 7348 | return val; |
| 7349 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7350 | } |
| 7351 | |
| 7352 | /** |
| 7353 | * The statistics associated with a particular package. |
| 7354 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7355 | public static class Pkg extends BatteryStats.Uid.Pkg implements TimeBaseObs { |
| 7356 | /** |
| 7357 | * BatteryStatsImpl that we are associated with. |
| 7358 | */ |
| 7359 | protected BatteryStatsImpl mBsi; |
| 7360 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7361 | /** |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 7362 | * 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] | 7363 | */ |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 7364 | ArrayMap<String, Counter> mWakeupAlarms = new ArrayMap<>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7365 | |
| 7366 | /** |
| 7367 | * The statics we have collected for this package's services. |
| 7368 | */ |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 7369 | final ArrayMap<String, Serv> mServiceStats = new ArrayMap<>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7370 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7371 | public Pkg(BatteryStatsImpl bsi) { |
| 7372 | mBsi = bsi; |
| 7373 | mBsi.mOnBatteryScreenOffTimeBase.add(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7374 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7375 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7376 | public void onTimeStarted(long elapsedRealtime, long baseUptime, long baseRealtime) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7377 | } |
| 7378 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7379 | public void onTimeStopped(long elapsedRealtime, long baseUptime, long baseRealtime) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7380 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7381 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7382 | void detach() { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7383 | mBsi.mOnBatteryScreenOffTimeBase.remove(this); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7384 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7385 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7386 | void readFromParcelLocked(Parcel in) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 7387 | int numWA = in.readInt(); |
| 7388 | mWakeupAlarms.clear(); |
| 7389 | for (int i=0; i<numWA; i++) { |
| 7390 | String tag = in.readString(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7391 | mWakeupAlarms.put(tag, new Counter(mBsi.mOnBatteryTimeBase, in)); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 7392 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7393 | |
| 7394 | int numServs = in.readInt(); |
| 7395 | mServiceStats.clear(); |
| 7396 | for (int m = 0; m < numServs; m++) { |
| 7397 | String serviceName = in.readString(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7398 | Uid.Pkg.Serv serv = new Serv(mBsi); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7399 | mServiceStats.put(serviceName, serv); |
| 7400 | |
| 7401 | serv.readFromParcelLocked(in); |
| 7402 | } |
| 7403 | } |
| 7404 | |
| 7405 | void writeToParcelLocked(Parcel out) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 7406 | int numWA = mWakeupAlarms.size(); |
| 7407 | out.writeInt(numWA); |
| 7408 | for (int i=0; i<numWA; i++) { |
| 7409 | out.writeString(mWakeupAlarms.keyAt(i)); |
| 7410 | mWakeupAlarms.valueAt(i).writeToParcel(out); |
| 7411 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7412 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 7413 | final int NS = mServiceStats.size(); |
| 7414 | out.writeInt(NS); |
| 7415 | for (int i=0; i<NS; i++) { |
| 7416 | out.writeString(mServiceStats.keyAt(i)); |
| 7417 | Uid.Pkg.Serv serv = mServiceStats.valueAt(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7418 | serv.writeToParcelLocked(out); |
| 7419 | } |
| 7420 | } |
| 7421 | |
| 7422 | @Override |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 7423 | public ArrayMap<String, ? extends BatteryStats.Counter> getWakeupAlarmStats() { |
| 7424 | return mWakeupAlarms; |
| 7425 | } |
| 7426 | |
| 7427 | public void noteWakeupAlarmLocked(String tag) { |
| 7428 | Counter c = mWakeupAlarms.get(tag); |
| 7429 | if (c == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7430 | c = new Counter(mBsi.mOnBatteryTimeBase); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 7431 | mWakeupAlarms.put(tag, c); |
| 7432 | } |
| 7433 | c.stepAtomic(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7434 | } |
| 7435 | |
| 7436 | @Override |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 7437 | public ArrayMap<String, ? extends BatteryStats.Uid.Pkg.Serv> getServiceStats() { |
| 7438 | return mServiceStats; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7439 | } |
| 7440 | |
| 7441 | /** |
| 7442 | * The statistics associated with a particular service. |
| 7443 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7444 | public static class Serv extends BatteryStats.Uid.Pkg.Serv implements TimeBaseObs { |
| 7445 | /** |
| 7446 | * BatteryStatsImpl that we are associated with. |
| 7447 | */ |
| 7448 | protected BatteryStatsImpl mBsi; |
| 7449 | |
| 7450 | /** |
| 7451 | * The android package in which this service resides. |
| 7452 | */ |
| 7453 | protected Pkg mPkg; |
| 7454 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7455 | /** |
| 7456 | * Total time (ms in battery uptime) the service has been left started. |
| 7457 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7458 | protected long mStartTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7459 | |
| 7460 | /** |
| 7461 | * If service has been started and not yet stopped, this is |
| 7462 | * when it was started. |
| 7463 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7464 | protected long mRunningSince; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7465 | |
| 7466 | /** |
| 7467 | * True if we are currently running. |
| 7468 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7469 | protected boolean mRunning; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7470 | |
| 7471 | /** |
| 7472 | * Total number of times startService() has been called. |
| 7473 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7474 | protected int mStarts; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7475 | |
| 7476 | /** |
| 7477 | * Total time (ms in battery uptime) the service has been left launched. |
| 7478 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7479 | protected long mLaunchedTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7480 | |
| 7481 | /** |
| 7482 | * If service has been launched and not yet exited, this is |
| 7483 | * when it was launched (ms in battery uptime). |
| 7484 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7485 | protected long mLaunchedSince; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7486 | |
| 7487 | /** |
| 7488 | * True if we are currently launched. |
| 7489 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7490 | protected boolean mLaunched; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7491 | |
| 7492 | /** |
| 7493 | * Total number times the service has been launched. |
| 7494 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7495 | protected int mLaunches; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7496 | |
| 7497 | /** |
| 7498 | * The amount of time spent started loaded from a previous save |
| 7499 | * (ms in battery uptime). |
| 7500 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7501 | protected long mLoadedStartTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7502 | |
| 7503 | /** |
| 7504 | * The number of starts loaded from a previous save. |
| 7505 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7506 | protected int mLoadedStarts; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7507 | |
| 7508 | /** |
| 7509 | * The number of launches loaded from a previous save. |
| 7510 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7511 | protected int mLoadedLaunches; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7512 | |
| 7513 | /** |
| 7514 | * The amount of time spent started as of the last run (ms |
| 7515 | * in battery uptime). |
| 7516 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7517 | protected long mLastStartTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7518 | |
| 7519 | /** |
| 7520 | * The number of starts as of the last run. |
| 7521 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7522 | protected int mLastStarts; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7523 | |
| 7524 | /** |
| 7525 | * The number of launches as of the last run. |
| 7526 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7527 | protected int mLastLaunches; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7528 | |
| 7529 | /** |
| 7530 | * The amount of time spent started when last unplugged (ms |
| 7531 | * in battery uptime). |
| 7532 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7533 | protected long mUnpluggedStartTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7534 | |
| 7535 | /** |
| 7536 | * The number of starts when last unplugged. |
| 7537 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7538 | protected int mUnpluggedStarts; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7539 | |
| 7540 | /** |
| 7541 | * The number of launches when last unplugged. |
| 7542 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7543 | protected int mUnpluggedLaunches; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7544 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7545 | /** |
| 7546 | * Construct a Serv. Also adds it to the on-battery time base as a listener. |
| 7547 | */ |
| 7548 | public Serv(BatteryStatsImpl bsi) { |
| 7549 | mBsi = bsi; |
| 7550 | mBsi.mOnBatteryTimeBase.add(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7551 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7552 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7553 | public void onTimeStarted(long elapsedRealtime, long baseUptime, |
| 7554 | long baseRealtime) { |
| 7555 | mUnpluggedStartTime = getStartTimeToNowLocked(baseUptime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7556 | mUnpluggedStarts = mStarts; |
| 7557 | mUnpluggedLaunches = mLaunches; |
| 7558 | } |
| 7559 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7560 | public void onTimeStopped(long elapsedRealtime, long baseUptime, |
| 7561 | long baseRealtime) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7562 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7563 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7564 | /** |
| 7565 | * Remove this Serv as a listener from the time base. |
| 7566 | */ |
| 7567 | public void detach() { |
| 7568 | mBsi.mOnBatteryTimeBase.remove(this); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7569 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7570 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7571 | public void readFromParcelLocked(Parcel in) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7572 | mStartTime = in.readLong(); |
| 7573 | mRunningSince = in.readLong(); |
| 7574 | mRunning = in.readInt() != 0; |
| 7575 | mStarts = in.readInt(); |
| 7576 | mLaunchedTime = in.readLong(); |
| 7577 | mLaunchedSince = in.readLong(); |
| 7578 | mLaunched = in.readInt() != 0; |
| 7579 | mLaunches = in.readInt(); |
| 7580 | mLoadedStartTime = in.readLong(); |
| 7581 | mLoadedStarts = in.readInt(); |
| 7582 | mLoadedLaunches = in.readInt(); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 7583 | mLastStartTime = 0; |
| 7584 | mLastStarts = 0; |
| 7585 | mLastLaunches = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7586 | mUnpluggedStartTime = in.readLong(); |
| 7587 | mUnpluggedStarts = in.readInt(); |
| 7588 | mUnpluggedLaunches = in.readInt(); |
| 7589 | } |
| 7590 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7591 | public void writeToParcelLocked(Parcel out) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7592 | out.writeLong(mStartTime); |
| 7593 | out.writeLong(mRunningSince); |
| 7594 | out.writeInt(mRunning ? 1 : 0); |
| 7595 | out.writeInt(mStarts); |
| 7596 | out.writeLong(mLaunchedTime); |
| 7597 | out.writeLong(mLaunchedSince); |
| 7598 | out.writeInt(mLaunched ? 1 : 0); |
| 7599 | out.writeInt(mLaunches); |
| 7600 | out.writeLong(mLoadedStartTime); |
| 7601 | out.writeInt(mLoadedStarts); |
| 7602 | out.writeInt(mLoadedLaunches); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7603 | out.writeLong(mUnpluggedStartTime); |
| 7604 | out.writeInt(mUnpluggedStarts); |
| 7605 | out.writeInt(mUnpluggedLaunches); |
| 7606 | } |
| 7607 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7608 | public long getLaunchTimeToNowLocked(long batteryUptime) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7609 | if (!mLaunched) return mLaunchedTime; |
| 7610 | return mLaunchedTime + batteryUptime - mLaunchedSince; |
| 7611 | } |
| 7612 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7613 | public long getStartTimeToNowLocked(long batteryUptime) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7614 | if (!mRunning) return mStartTime; |
| 7615 | return mStartTime + batteryUptime - mRunningSince; |
| 7616 | } |
| 7617 | |
| 7618 | public void startLaunchedLocked() { |
| 7619 | if (!mLaunched) { |
| 7620 | mLaunches++; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7621 | mLaunchedSince = mBsi.getBatteryUptimeLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7622 | mLaunched = true; |
| 7623 | } |
| 7624 | } |
| 7625 | |
| 7626 | public void stopLaunchedLocked() { |
| 7627 | if (mLaunched) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7628 | long time = mBsi.getBatteryUptimeLocked() - mLaunchedSince; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7629 | if (time > 0) { |
| 7630 | mLaunchedTime += time; |
| 7631 | } else { |
| 7632 | mLaunches--; |
| 7633 | } |
| 7634 | mLaunched = false; |
| 7635 | } |
| 7636 | } |
| 7637 | |
| 7638 | public void startRunningLocked() { |
| 7639 | if (!mRunning) { |
| 7640 | mStarts++; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7641 | mRunningSince = mBsi.getBatteryUptimeLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7642 | mRunning = true; |
| 7643 | } |
| 7644 | } |
| 7645 | |
| 7646 | public void stopRunningLocked() { |
| 7647 | if (mRunning) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7648 | long time = mBsi.getBatteryUptimeLocked() - mRunningSince; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7649 | if (time > 0) { |
| 7650 | mStartTime += time; |
| 7651 | } else { |
| 7652 | mStarts--; |
| 7653 | } |
| 7654 | mRunning = false; |
| 7655 | } |
| 7656 | } |
| 7657 | |
| 7658 | public BatteryStatsImpl getBatteryStats() { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7659 | return mBsi; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7660 | } |
| 7661 | |
| 7662 | @Override |
| 7663 | public int getLaunches(int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 7664 | int val = mLaunches; |
| 7665 | if (which == STATS_CURRENT) { |
| 7666 | val -= mLoadedLaunches; |
| 7667 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 7668 | val -= mUnpluggedLaunches; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7669 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7670 | return val; |
| 7671 | } |
| 7672 | |
| 7673 | @Override |
| 7674 | public long getStartTime(long now, int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 7675 | long val = getStartTimeToNowLocked(now); |
| 7676 | if (which == STATS_CURRENT) { |
| 7677 | val -= mLoadedStartTime; |
| 7678 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 7679 | val -= mUnpluggedStartTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7680 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7681 | return val; |
| 7682 | } |
| 7683 | |
| 7684 | @Override |
| 7685 | public int getStarts(int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 7686 | int val = mStarts; |
| 7687 | if (which == STATS_CURRENT) { |
| 7688 | val -= mLoadedStarts; |
| 7689 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 7690 | val -= mUnpluggedStarts; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7691 | } |
| 7692 | |
| 7693 | return val; |
| 7694 | } |
| 7695 | } |
| 7696 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7697 | final Serv newServiceStatsLocked() { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7698 | return new Serv(mBsi); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7699 | } |
| 7700 | } |
| 7701 | |
| 7702 | /** |
| 7703 | * Retrieve the statistics object for a particular process, creating |
| 7704 | * if needed. |
| 7705 | */ |
| 7706 | public Proc getProcessStatsLocked(String name) { |
| 7707 | Proc ps = mProcessStats.get(name); |
| 7708 | if (ps == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7709 | ps = new Proc(mBsi, name); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7710 | mProcessStats.put(name, ps); |
| 7711 | } |
| 7712 | |
| 7713 | return ps; |
| 7714 | } |
| 7715 | |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 7716 | public void updateUidProcessStateLocked(int procState) { |
| 7717 | int uidRunningState; |
| 7718 | if (procState == ActivityManager.PROCESS_STATE_NONEXISTENT) { |
| 7719 | uidRunningState = ActivityManager.PROCESS_STATE_NONEXISTENT; |
| 7720 | } else if (procState == ActivityManager.PROCESS_STATE_TOP) { |
| 7721 | uidRunningState = PROCESS_STATE_TOP; |
| 7722 | } else if (procState <= ActivityManager.PROCESS_STATE_FOREGROUND_SERVICE) { |
| 7723 | // Persistent and other foreground states go here. |
| 7724 | uidRunningState = PROCESS_STATE_FOREGROUND_SERVICE; |
| 7725 | } else if (procState <= ActivityManager.PROCESS_STATE_TOP_SLEEPING) { |
| 7726 | uidRunningState = PROCESS_STATE_TOP_SLEEPING; |
| 7727 | } else if (procState <= ActivityManager.PROCESS_STATE_IMPORTANT_FOREGROUND) { |
| 7728 | // Persistent and other foreground states go here. |
| 7729 | uidRunningState = PROCESS_STATE_FOREGROUND; |
| 7730 | } else if (procState <= ActivityManager.PROCESS_STATE_RECEIVER) { |
| 7731 | uidRunningState = PROCESS_STATE_BACKGROUND; |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 7732 | } else { |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 7733 | uidRunningState = PROCESS_STATE_CACHED; |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 7734 | } |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 7735 | |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 7736 | if (mProcessState == uidRunningState) return; |
| 7737 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7738 | final long elapsedRealtime = mBsi.mClocks.elapsedRealtime(); |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 7739 | |
| 7740 | if (mProcessState != ActivityManager.PROCESS_STATE_NONEXISTENT) { |
| 7741 | mProcessStateTimer[mProcessState].stopRunningLocked(elapsedRealtime); |
| 7742 | } |
| 7743 | mProcessState = uidRunningState; |
| 7744 | if (uidRunningState != ActivityManager.PROCESS_STATE_NONEXISTENT) { |
| 7745 | if (mProcessStateTimer[uidRunningState] == null) { |
| 7746 | makeProcessState(uidRunningState, null); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 7747 | } |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 7748 | mProcessStateTimer[uidRunningState].startRunningLocked(elapsedRealtime); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 7749 | } |
| 7750 | } |
| 7751 | |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 7752 | public SparseArray<? extends Pid> getPidStats() { |
| 7753 | return mPids; |
| 7754 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7755 | |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 7756 | public Pid getPidStatsLocked(int pid) { |
| 7757 | Pid p = mPids.get(pid); |
| 7758 | if (p == null) { |
| 7759 | p = new Pid(); |
| 7760 | mPids.put(pid, p); |
| 7761 | } |
| 7762 | return p; |
| 7763 | } |
| 7764 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7765 | /** |
| 7766 | * Retrieve the statistics object for a particular service, creating |
| 7767 | * if needed. |
| 7768 | */ |
| 7769 | public Pkg getPackageStatsLocked(String name) { |
| 7770 | Pkg ps = mPackageStats.get(name); |
| 7771 | if (ps == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7772 | ps = new Pkg(mBsi); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7773 | mPackageStats.put(name, ps); |
| 7774 | } |
| 7775 | |
| 7776 | return ps; |
| 7777 | } |
| 7778 | |
| 7779 | /** |
| 7780 | * Retrieve the statistics object for a particular service, creating |
| 7781 | * if needed. |
| 7782 | */ |
| 7783 | public Pkg.Serv getServiceStatsLocked(String pkg, String serv) { |
| 7784 | Pkg ps = getPackageStatsLocked(pkg); |
| 7785 | Pkg.Serv ss = ps.mServiceStats.get(serv); |
| 7786 | if (ss == null) { |
| 7787 | ss = ps.newServiceStatsLocked(); |
| 7788 | ps.mServiceStats.put(serv, ss); |
| 7789 | } |
| 7790 | |
| 7791 | return ss; |
| 7792 | } |
| 7793 | |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 7794 | public void readSyncSummaryFromParcelLocked(String name, Parcel in) { |
| 7795 | StopwatchTimer timer = mSyncStats.instantiateObject(); |
| 7796 | timer.readSummaryFromParcelLocked(in); |
| 7797 | mSyncStats.add(name, timer); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 7798 | } |
| 7799 | |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 7800 | public void readJobSummaryFromParcelLocked(String name, Parcel in) { |
| 7801 | StopwatchTimer timer = mJobStats.instantiateObject(); |
| 7802 | timer.readSummaryFromParcelLocked(in); |
| 7803 | mJobStats.add(name, timer); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 7804 | } |
| 7805 | |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 7806 | public void readWakeSummaryFromParcelLocked(String wlName, Parcel in) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7807 | Wakelock wl = new Wakelock(mBsi, this); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 7808 | mWakelockStats.add(wlName, wl); |
| 7809 | if (in.readInt() != 0) { |
| 7810 | wl.getStopwatchTimer(WAKE_TYPE_FULL).readSummaryFromParcelLocked(in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7811 | } |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 7812 | if (in.readInt() != 0) { |
| 7813 | wl.getStopwatchTimer(WAKE_TYPE_PARTIAL).readSummaryFromParcelLocked(in); |
| 7814 | } |
| 7815 | if (in.readInt() != 0) { |
| 7816 | wl.getStopwatchTimer(WAKE_TYPE_WINDOW).readSummaryFromParcelLocked(in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7817 | } |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 7818 | if (in.readInt() != 0) { |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 7819 | wl.getStopwatchTimer(WAKE_TYPE_DRAW).readSummaryFromParcelLocked(in); |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 7820 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7821 | } |
| 7822 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 7823 | public StopwatchTimer getSensorTimerLocked(int sensor, boolean create) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7824 | Sensor se = mSensorStats.get(sensor); |
| 7825 | if (se == null) { |
| 7826 | if (!create) { |
| 7827 | return null; |
| 7828 | } |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7829 | se = new Sensor(mBsi, this, sensor); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7830 | mSensorStats.put(sensor, se); |
| 7831 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 7832 | StopwatchTimer t = se.mTimer; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7833 | if (t != null) { |
| 7834 | return t; |
| 7835 | } |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7836 | ArrayList<StopwatchTimer> timers = mBsi.mSensorTimers.get(sensor); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7837 | if (timers == null) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 7838 | timers = new ArrayList<StopwatchTimer>(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7839 | mBsi.mSensorTimers.put(sensor, timers); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7840 | } |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7841 | t = new StopwatchTimer(mBsi.mClocks, this, BatteryStats.SENSOR, timers, |
| 7842 | mBsi.mOnBatteryTimeBase); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7843 | se.mTimer = t; |
| 7844 | return t; |
| 7845 | } |
| 7846 | |
Amith Yamasani | ab9ad19 | 2016-12-06 12:46:59 -0800 | [diff] [blame] | 7847 | public Counter getSensorBgCounterLocked(int sensor, boolean create) { |
| 7848 | Sensor se = mSensorStats.get(sensor); |
| 7849 | if (se == null) { |
| 7850 | if (!create) { |
| 7851 | return null; |
| 7852 | } |
| 7853 | se = new Sensor(mBsi, this, sensor); |
| 7854 | mSensorStats.put(sensor, se); |
| 7855 | } |
| 7856 | Counter c = se.mBgCounter; |
| 7857 | if (c != null) return c; |
| 7858 | c = new Counter(mBsi.mOnBatteryTimeBase); |
| 7859 | se.mBgCounter = c; |
| 7860 | return c; |
| 7861 | } |
| 7862 | |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 7863 | public void noteStartSyncLocked(String name, long elapsedRealtimeMs) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 7864 | StopwatchTimer t = mSyncStats.startObject(name); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 7865 | if (t != null) { |
| 7866 | t.startRunningLocked(elapsedRealtimeMs); |
| 7867 | } |
| 7868 | } |
| 7869 | |
| 7870 | public void noteStopSyncLocked(String name, long elapsedRealtimeMs) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 7871 | StopwatchTimer t = mSyncStats.stopObject(name); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 7872 | if (t != null) { |
| 7873 | t.stopRunningLocked(elapsedRealtimeMs); |
| 7874 | } |
| 7875 | } |
| 7876 | |
| 7877 | public void noteStartJobLocked(String name, long elapsedRealtimeMs) { |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 7878 | StopwatchTimer t = mJobStats.startObject(name); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 7879 | if (t != null) { |
| 7880 | t.startRunningLocked(elapsedRealtimeMs); |
| 7881 | } |
| 7882 | } |
| 7883 | |
| 7884 | public void noteStopJobLocked(String name, long elapsedRealtimeMs) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 7885 | StopwatchTimer t = mJobStats.stopObject(name); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 7886 | if (t != null) { |
| 7887 | t.stopRunningLocked(elapsedRealtimeMs); |
| 7888 | } |
| 7889 | } |
| 7890 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7891 | public void noteStartWakeLocked(int pid, String name, int type, long elapsedRealtimeMs) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 7892 | Wakelock wl = mWakelockStats.startObject(name); |
| 7893 | if (wl != null) { |
| 7894 | wl.getStopwatchTimer(type).startRunningLocked(elapsedRealtimeMs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7895 | } |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 7896 | if (pid >= 0 && type == WAKE_TYPE_PARTIAL) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 7897 | Pid p = getPidStatsLocked(pid); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 7898 | if (p.mWakeNesting++ == 0) { |
| 7899 | p.mWakeStartMs = elapsedRealtimeMs; |
Dianne Hackborn | b8071d79 | 2010-09-09 16:45:15 -0700 | [diff] [blame] | 7900 | } |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 7901 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7902 | } |
| 7903 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7904 | public void noteStopWakeLocked(int pid, String name, int type, long elapsedRealtimeMs) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 7905 | Wakelock wl = mWakelockStats.stopObject(name); |
| 7906 | if (wl != null) { |
| 7907 | wl.getStopwatchTimer(type).stopRunningLocked(elapsedRealtimeMs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7908 | } |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 7909 | if (pid >= 0 && type == WAKE_TYPE_PARTIAL) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 7910 | Pid p = mPids.get(pid); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 7911 | if (p != null && p.mWakeNesting > 0) { |
| 7912 | if (p.mWakeNesting-- == 1) { |
| 7913 | p.mWakeSumMs += elapsedRealtimeMs - p.mWakeStartMs; |
| 7914 | p.mWakeStartMs = 0; |
| 7915 | } |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 7916 | } |
| 7917 | } |
| 7918 | } |
| 7919 | |
| 7920 | public void reportExcessiveWakeLocked(String proc, long overTime, long usedTime) { |
| 7921 | Proc p = getProcessStatsLocked(proc); |
| 7922 | if (p != null) { |
| 7923 | p.addExcessiveWake(overTime, usedTime); |
| 7924 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7925 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7926 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 7927 | public void reportExcessiveCpuLocked(String proc, long overTime, long usedTime) { |
| 7928 | Proc p = getProcessStatsLocked(proc); |
| 7929 | if (p != null) { |
| 7930 | p.addExcessiveCpu(overTime, usedTime); |
| 7931 | } |
| 7932 | } |
| 7933 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7934 | public void noteStartSensor(int sensor, long elapsedRealtimeMs) { |
Amith Yamasani | 154d124 | 2017-02-16 10:01:48 -0800 | [diff] [blame] | 7935 | StopwatchTimer t = getSensorTimerLocked(sensor, /* create= */ true); |
| 7936 | t.startRunningLocked(elapsedRealtimeMs); |
| 7937 | |
| 7938 | Counter c = getSensorBgCounterLocked(sensor, /* create= */ true); |
| 7939 | if (mProcessState >= PROCESS_STATE_BACKGROUND && t.mNesting == 1) { |
Amith Yamasani | ab9ad19 | 2016-12-06 12:46:59 -0800 | [diff] [blame] | 7940 | c.stepAtomic(); |
| 7941 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7942 | } |
| 7943 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7944 | public void noteStopSensor(int sensor, long elapsedRealtimeMs) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7945 | // Don't create a timer if one doesn't already exist |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 7946 | StopwatchTimer t = getSensorTimerLocked(sensor, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7947 | if (t != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7948 | t.stopRunningLocked(elapsedRealtimeMs); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7949 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7950 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7951 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7952 | public void noteStartGps(long elapsedRealtimeMs) { |
Amith Yamasani | 154d124 | 2017-02-16 10:01:48 -0800 | [diff] [blame] | 7953 | StopwatchTimer t = getSensorTimerLocked(Sensor.GPS, /* create= */ true); |
| 7954 | t.startRunningLocked(elapsedRealtimeMs); |
| 7955 | |
| 7956 | Counter c = getSensorBgCounterLocked(Sensor.GPS, /* create= */ true); |
| 7957 | if (mProcessState >= PROCESS_STATE_BACKGROUND && t.mNesting == 1) { |
Amith Yamasani | ab9ad19 | 2016-12-06 12:46:59 -0800 | [diff] [blame] | 7958 | c.stepAtomic(); |
| 7959 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7960 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7961 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7962 | public void noteStopGps(long elapsedRealtimeMs) { |
Amith Yamasani | 154d124 | 2017-02-16 10:01:48 -0800 | [diff] [blame] | 7963 | // Don't create a timer if one doesn't already exist |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 7964 | StopwatchTimer t = getSensorTimerLocked(Sensor.GPS, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7965 | if (t != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7966 | t.stopRunningLocked(elapsedRealtimeMs); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 7967 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7968 | } |
| 7969 | |
| 7970 | public BatteryStatsImpl getBatteryStats() { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7971 | return mBsi; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7972 | } |
| 7973 | } |
| 7974 | |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 7975 | public BatteryStatsImpl(File systemDir, Handler handler, ExternalStatsSync externalSync) { |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 7976 | this(new SystemClocks(), systemDir, handler, externalSync, null); |
| 7977 | } |
| 7978 | |
| 7979 | public BatteryStatsImpl(File systemDir, Handler handler, ExternalStatsSync externalSync, |
| 7980 | PlatformIdleStateCallback cb) { |
| 7981 | this(new SystemClocks(), systemDir, handler, externalSync, cb); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7982 | } |
| 7983 | |
| 7984 | public BatteryStatsImpl(Clocks clocks, File systemDir, Handler handler, |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 7985 | ExternalStatsSync externalSync, PlatformIdleStateCallback cb) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7986 | init(clocks); |
| 7987 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 7988 | if (systemDir != null) { |
| 7989 | mFile = new JournaledFile(new File(systemDir, "batterystats.bin"), |
| 7990 | new File(systemDir, "batterystats.bin.tmp")); |
| 7991 | } else { |
| 7992 | mFile = null; |
| 7993 | } |
| 7994 | mCheckinFile = new AtomicFile(new File(systemDir, "batterystats-checkin.bin")); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 7995 | mDailyFile = new AtomicFile(new File(systemDir, "batterystats-daily.xml")); |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 7996 | mExternalSync = externalSync; |
Jeff Brown | 6f357d3 | 2014-01-15 20:40:55 -0800 | [diff] [blame] | 7997 | mHandler = new MyHandler(handler.getLooper()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7998 | mStartCount++; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7999 | mScreenOnTimer = new StopwatchTimer(mClocks, null, -1, null, mOnBatteryTimeBase); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 8000 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8001 | mScreenBrightnessTimer[i] = new StopwatchTimer(mClocks, null, -100-i, null, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8002 | mOnBatteryTimeBase); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 8003 | } |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8004 | mInteractiveTimer = new StopwatchTimer(mClocks, null, -10, null, mOnBatteryTimeBase); |
| 8005 | mPowerSaveModeEnabledTimer = new StopwatchTimer(mClocks, null, -2, null, |
| 8006 | mOnBatteryTimeBase); |
| 8007 | mDeviceIdleModeLightTimer = new StopwatchTimer(mClocks, null, -11, null, |
| 8008 | mOnBatteryTimeBase); |
| 8009 | mDeviceIdleModeFullTimer = new StopwatchTimer(mClocks, null, -14, null, mOnBatteryTimeBase); |
| 8010 | mDeviceLightIdlingTimer = new StopwatchTimer(mClocks, null, -15, null, mOnBatteryTimeBase); |
| 8011 | mDeviceIdlingTimer = new StopwatchTimer(mClocks, null, -12, null, mOnBatteryTimeBase); |
| 8012 | mPhoneOnTimer = new StopwatchTimer(mClocks, null, -3, null, mOnBatteryTimeBase); |
| 8013 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
| 8014 | mPhoneSignalStrengthsTimer[i] = new StopwatchTimer(mClocks, null, -200-i, null, |
| 8015 | mOnBatteryTimeBase); |
| 8016 | } |
| 8017 | mPhoneSignalScanningTimer = new StopwatchTimer(mClocks, null, -200+1, null, |
| 8018 | mOnBatteryTimeBase); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 8019 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8020 | mPhoneDataConnectionsTimer[i] = new StopwatchTimer(mClocks, null, -300-i, null, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8021 | mOnBatteryTimeBase); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 8022 | } |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 8023 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8024 | mNetworkByteActivityCounters[i] = new LongSamplingCounter(mOnBatteryTimeBase); |
| 8025 | mNetworkPacketActivityCounters[i] = new LongSamplingCounter(mOnBatteryTimeBase); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 8026 | } |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 8027 | mWifiActivity = new ControllerActivityCounterImpl(mOnBatteryTimeBase, NUM_WIFI_TX_LEVELS); |
| 8028 | mBluetoothActivity = new ControllerActivityCounterImpl(mOnBatteryTimeBase, |
| 8029 | NUM_BT_TX_LEVELS); |
| 8030 | mModemActivity = new ControllerActivityCounterImpl(mOnBatteryTimeBase, |
| 8031 | ModemActivityInfo.TX_POWER_LEVELS); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8032 | mMobileRadioActiveTimer = new StopwatchTimer(mClocks, null, -400, null, mOnBatteryTimeBase); |
| 8033 | mMobileRadioActivePerAppTimer = new StopwatchTimer(mClocks, null, -401, null, |
| 8034 | mOnBatteryTimeBase); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 8035 | mMobileRadioActiveAdjustedTime = new LongSamplingCounter(mOnBatteryTimeBase); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8036 | mMobileRadioActiveUnknownTime = new LongSamplingCounter(mOnBatteryTimeBase); |
| 8037 | mMobileRadioActiveUnknownCount = new LongSamplingCounter(mOnBatteryTimeBase); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8038 | mWifiOnTimer = new StopwatchTimer(mClocks, null, -4, null, mOnBatteryTimeBase); |
| 8039 | mGlobalWifiRunningTimer = new StopwatchTimer(mClocks, null, -5, null, mOnBatteryTimeBase); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 8040 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8041 | mWifiStateTimer[i] = new StopwatchTimer(mClocks, null, -600-i, null, |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 8042 | mOnBatteryTimeBase); |
| 8043 | } |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8044 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
| 8045 | mWifiSupplStateTimer[i] = new StopwatchTimer(mClocks, null, -700-i, null, |
| 8046 | mOnBatteryTimeBase); |
| 8047 | } |
| 8048 | for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 8049 | mWifiSignalStrengthsTimer[i] = new StopwatchTimer(mClocks, null, -800-i, null, |
| 8050 | mOnBatteryTimeBase); |
| 8051 | } |
| 8052 | mAudioOnTimer = new StopwatchTimer(mClocks, null, -7, null, mOnBatteryTimeBase); |
| 8053 | mVideoOnTimer = new StopwatchTimer(mClocks, null, -8, null, mOnBatteryTimeBase); |
| 8054 | mFlashlightOnTimer = new StopwatchTimer(mClocks, null, -9, null, mOnBatteryTimeBase); |
| 8055 | mCameraOnTimer = new StopwatchTimer(mClocks, null, -13, null, mOnBatteryTimeBase); |
| 8056 | mBluetoothScanTimer = new StopwatchTimer(mClocks, null, -14, null, mOnBatteryTimeBase); |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 8057 | mDischargeScreenOffCounter = new LongSamplingCounter(mOnBatteryScreenOffTimeBase); |
| 8058 | mDischargeCounter = new LongSamplingCounter(mOnBatteryTimeBase); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8059 | mOnBattery = mOnBatteryInternal = false; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8060 | long uptime = mClocks.uptimeMillis() * 1000; |
| 8061 | long realtime = mClocks.elapsedRealtime() * 1000; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8062 | initTimes(uptime, realtime); |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 8063 | mStartPlatformVersion = mEndPlatformVersion = Build.ID; |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 8064 | mDischargeStartLevel = 0; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8065 | mDischargeUnplugLevel = 0; |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 8066 | mDischargePlugLevel = -1; |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 8067 | mDischargeCurrentLevel = 0; |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 8068 | mCurrentBatteryLevel = 0; |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 8069 | initDischarge(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 8070 | clearHistoryLocked(); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 8071 | updateDailyDeadlineLocked(); |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 8072 | mPlatformIdleStateCallback = cb; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8073 | } |
| 8074 | |
| 8075 | public BatteryStatsImpl(Parcel p) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8076 | this(new SystemClocks(), p); |
| 8077 | } |
| 8078 | |
| 8079 | public BatteryStatsImpl(Clocks clocks, Parcel p) { |
| 8080 | init(clocks); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 8081 | mFile = null; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 8082 | mCheckinFile = null; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 8083 | mDailyFile = null; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 8084 | mHandler = null; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8085 | mExternalSync = null; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 8086 | clearHistoryLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8087 | readFromParcel(p); |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 8088 | mPlatformIdleStateCallback = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8089 | } |
| 8090 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 8091 | public void setPowerProfile(PowerProfile profile) { |
| 8092 | synchronized (this) { |
| 8093 | mPowerProfile = profile; |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 8094 | |
| 8095 | // We need to initialize the KernelCpuSpeedReaders to read from |
| 8096 | // the first cpu of each core. Once we have the PowerProfile, we have access to this |
| 8097 | // information. |
| 8098 | final int numClusters = mPowerProfile.getNumCpuClusters(); |
| 8099 | mKernelCpuSpeedReaders = new KernelCpuSpeedReader[numClusters]; |
| 8100 | int firstCpuOfCluster = 0; |
| 8101 | for (int i = 0; i < numClusters; i++) { |
| 8102 | final int numSpeedSteps = mPowerProfile.getNumSpeedStepsInCpuCluster(i); |
| 8103 | mKernelCpuSpeedReaders[i] = new KernelCpuSpeedReader(firstCpuOfCluster, |
| 8104 | numSpeedSteps); |
| 8105 | firstCpuOfCluster += mPowerProfile.getNumCoresInCpuCluster(i); |
| 8106 | } |
Adam Lesinski | f9b20a9 | 2016-06-17 17:30:01 -0700 | [diff] [blame] | 8107 | |
| 8108 | if (mEstimatedBatteryCapacity == -1) { |
| 8109 | // Initialize the estimated battery capacity to a known preset one. |
| 8110 | mEstimatedBatteryCapacity = (int) mPowerProfile.getBatteryCapacity(); |
| 8111 | } |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 8112 | } |
| 8113 | } |
| 8114 | |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 8115 | public void setCallback(BatteryCallback cb) { |
| 8116 | mCallback = cb; |
| 8117 | } |
| 8118 | |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 8119 | public void setRadioScanningTimeout(long timeout) { |
| 8120 | if (mPhoneSignalScanningTimer != null) { |
| 8121 | mPhoneSignalScanningTimer.setTimeout(timeout); |
| 8122 | } |
| 8123 | } |
| 8124 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 8125 | public void updateDailyDeadlineLocked() { |
| 8126 | // Get the current time. |
| 8127 | long currentTime = mDailyStartTime = System.currentTimeMillis(); |
| 8128 | Calendar calDeadline = Calendar.getInstance(); |
| 8129 | calDeadline.setTimeInMillis(currentTime); |
| 8130 | |
| 8131 | // Move time up to the next day, ranging from 1am to 3pm. |
| 8132 | calDeadline.set(Calendar.DAY_OF_YEAR, calDeadline.get(Calendar.DAY_OF_YEAR) + 1); |
| 8133 | calDeadline.set(Calendar.MILLISECOND, 0); |
| 8134 | calDeadline.set(Calendar.SECOND, 0); |
| 8135 | calDeadline.set(Calendar.MINUTE, 0); |
| 8136 | calDeadline.set(Calendar.HOUR_OF_DAY, 1); |
| 8137 | mNextMinDailyDeadline = calDeadline.getTimeInMillis(); |
| 8138 | calDeadline.set(Calendar.HOUR_OF_DAY, 3); |
| 8139 | mNextMaxDailyDeadline = calDeadline.getTimeInMillis(); |
| 8140 | } |
| 8141 | |
| 8142 | public void recordDailyStatsIfNeededLocked(boolean settled) { |
| 8143 | long currentTime = System.currentTimeMillis(); |
| 8144 | if (currentTime >= mNextMaxDailyDeadline) { |
| 8145 | recordDailyStatsLocked(); |
| 8146 | } else if (settled && currentTime >= mNextMinDailyDeadline) { |
| 8147 | recordDailyStatsLocked(); |
| 8148 | } else if (currentTime < (mDailyStartTime-(1000*60*60*24))) { |
| 8149 | recordDailyStatsLocked(); |
| 8150 | } |
| 8151 | } |
| 8152 | |
| 8153 | public void recordDailyStatsLocked() { |
| 8154 | DailyItem item = new DailyItem(); |
| 8155 | item.mStartTime = mDailyStartTime; |
| 8156 | item.mEndTime = System.currentTimeMillis(); |
| 8157 | boolean hasData = false; |
| 8158 | if (mDailyDischargeStepTracker.mNumStepDurations > 0) { |
| 8159 | hasData = true; |
| 8160 | item.mDischargeSteps = new LevelStepTracker( |
| 8161 | mDailyDischargeStepTracker.mNumStepDurations, |
| 8162 | mDailyDischargeStepTracker.mStepDurations); |
| 8163 | } |
| 8164 | if (mDailyChargeStepTracker.mNumStepDurations > 0) { |
| 8165 | hasData = true; |
| 8166 | item.mChargeSteps = new LevelStepTracker( |
| 8167 | mDailyChargeStepTracker.mNumStepDurations, |
| 8168 | mDailyChargeStepTracker.mStepDurations); |
| 8169 | } |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 8170 | if (mDailyPackageChanges != null) { |
| 8171 | hasData = true; |
| 8172 | item.mPackageChanges = mDailyPackageChanges; |
| 8173 | mDailyPackageChanges = null; |
| 8174 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 8175 | mDailyDischargeStepTracker.init(); |
| 8176 | mDailyChargeStepTracker.init(); |
| 8177 | updateDailyDeadlineLocked(); |
| 8178 | |
| 8179 | if (hasData) { |
| 8180 | mDailyItems.add(item); |
| 8181 | while (mDailyItems.size() > MAX_DAILY_ITEMS) { |
| 8182 | mDailyItems.remove(0); |
| 8183 | } |
| 8184 | final ByteArrayOutputStream memStream = new ByteArrayOutputStream(); |
| 8185 | try { |
| 8186 | XmlSerializer out = new FastXmlSerializer(); |
Wojciech Staszkiewicz | 9e9e2e7 | 2015-05-08 14:58:46 +0100 | [diff] [blame] | 8187 | out.setOutput(memStream, StandardCharsets.UTF_8.name()); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 8188 | writeDailyItemsLocked(out); |
| 8189 | BackgroundThread.getHandler().post(new Runnable() { |
| 8190 | @Override |
| 8191 | public void run() { |
| 8192 | synchronized (mCheckinFile) { |
| 8193 | FileOutputStream stream = null; |
| 8194 | try { |
| 8195 | stream = mDailyFile.startWrite(); |
| 8196 | memStream.writeTo(stream); |
| 8197 | stream.flush(); |
| 8198 | FileUtils.sync(stream); |
| 8199 | stream.close(); |
| 8200 | mDailyFile.finishWrite(stream); |
| 8201 | } catch (IOException e) { |
| 8202 | Slog.w("BatteryStats", |
| 8203 | "Error writing battery daily items", e); |
| 8204 | mDailyFile.failWrite(stream); |
| 8205 | } |
| 8206 | } |
| 8207 | } |
| 8208 | }); |
| 8209 | } catch (IOException e) { |
| 8210 | } |
| 8211 | } |
| 8212 | } |
| 8213 | |
| 8214 | private void writeDailyItemsLocked(XmlSerializer out) throws IOException { |
| 8215 | StringBuilder sb = new StringBuilder(64); |
| 8216 | out.startDocument(null, true); |
| 8217 | out.startTag(null, "daily-items"); |
| 8218 | for (int i=0; i<mDailyItems.size(); i++) { |
| 8219 | final DailyItem dit = mDailyItems.get(i); |
| 8220 | out.startTag(null, "item"); |
| 8221 | out.attribute(null, "start", Long.toString(dit.mStartTime)); |
| 8222 | out.attribute(null, "end", Long.toString(dit.mEndTime)); |
| 8223 | writeDailyLevelSteps(out, "dis", dit.mDischargeSteps, sb); |
| 8224 | writeDailyLevelSteps(out, "chg", dit.mChargeSteps, sb); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 8225 | if (dit.mPackageChanges != null) { |
| 8226 | for (int j=0; j<dit.mPackageChanges.size(); j++) { |
| 8227 | PackageChange pc = dit.mPackageChanges.get(j); |
| 8228 | if (pc.mUpdate) { |
| 8229 | out.startTag(null, "upd"); |
| 8230 | out.attribute(null, "pkg", pc.mPackageName); |
| 8231 | out.attribute(null, "ver", Integer.toString(pc.mVersionCode)); |
| 8232 | out.endTag(null, "upd"); |
| 8233 | } else { |
| 8234 | out.startTag(null, "rem"); |
| 8235 | out.attribute(null, "pkg", pc.mPackageName); |
| 8236 | out.endTag(null, "rem"); |
| 8237 | } |
| 8238 | } |
| 8239 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 8240 | out.endTag(null, "item"); |
| 8241 | } |
| 8242 | out.endTag(null, "daily-items"); |
| 8243 | out.endDocument(); |
| 8244 | } |
| 8245 | |
| 8246 | private void writeDailyLevelSteps(XmlSerializer out, String tag, LevelStepTracker steps, |
| 8247 | StringBuilder tmpBuilder) throws IOException { |
| 8248 | if (steps != null) { |
| 8249 | out.startTag(null, tag); |
| 8250 | out.attribute(null, "n", Integer.toString(steps.mNumStepDurations)); |
| 8251 | for (int i=0; i<steps.mNumStepDurations; i++) { |
| 8252 | out.startTag(null, "s"); |
| 8253 | tmpBuilder.setLength(0); |
| 8254 | steps.encodeEntryAt(i, tmpBuilder); |
| 8255 | out.attribute(null, "v", tmpBuilder.toString()); |
| 8256 | out.endTag(null, "s"); |
| 8257 | } |
| 8258 | out.endTag(null, tag); |
| 8259 | } |
| 8260 | } |
| 8261 | |
| 8262 | public void readDailyStatsLocked() { |
| 8263 | Slog.d(TAG, "Reading daily items from " + mDailyFile.getBaseFile()); |
| 8264 | mDailyItems.clear(); |
| 8265 | FileInputStream stream; |
| 8266 | try { |
| 8267 | stream = mDailyFile.openRead(); |
| 8268 | } catch (FileNotFoundException e) { |
| 8269 | return; |
| 8270 | } |
| 8271 | try { |
| 8272 | XmlPullParser parser = Xml.newPullParser(); |
Wojciech Staszkiewicz | 9e9e2e7 | 2015-05-08 14:58:46 +0100 | [diff] [blame] | 8273 | parser.setInput(stream, StandardCharsets.UTF_8.name()); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 8274 | readDailyItemsLocked(parser); |
| 8275 | } catch (XmlPullParserException e) { |
| 8276 | } finally { |
| 8277 | try { |
| 8278 | stream.close(); |
| 8279 | } catch (IOException e) { |
| 8280 | } |
| 8281 | } |
| 8282 | } |
| 8283 | |
| 8284 | private void readDailyItemsLocked(XmlPullParser parser) { |
| 8285 | try { |
| 8286 | int type; |
| 8287 | while ((type = parser.next()) != XmlPullParser.START_TAG |
| 8288 | && type != XmlPullParser.END_DOCUMENT) { |
| 8289 | ; |
| 8290 | } |
| 8291 | |
| 8292 | if (type != XmlPullParser.START_TAG) { |
| 8293 | throw new IllegalStateException("no start tag found"); |
| 8294 | } |
| 8295 | |
| 8296 | int outerDepth = parser.getDepth(); |
| 8297 | while ((type = parser.next()) != XmlPullParser.END_DOCUMENT |
| 8298 | && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) { |
| 8299 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 8300 | continue; |
| 8301 | } |
| 8302 | |
| 8303 | String tagName = parser.getName(); |
| 8304 | if (tagName.equals("item")) { |
| 8305 | readDailyItemTagLocked(parser); |
| 8306 | } else { |
| 8307 | Slog.w(TAG, "Unknown element under <daily-items>: " |
| 8308 | + parser.getName()); |
| 8309 | XmlUtils.skipCurrentTag(parser); |
| 8310 | } |
| 8311 | } |
| 8312 | |
| 8313 | } catch (IllegalStateException e) { |
| 8314 | Slog.w(TAG, "Failed parsing daily " + e); |
| 8315 | } catch (NullPointerException e) { |
| 8316 | Slog.w(TAG, "Failed parsing daily " + e); |
| 8317 | } catch (NumberFormatException e) { |
| 8318 | Slog.w(TAG, "Failed parsing daily " + e); |
| 8319 | } catch (XmlPullParserException e) { |
| 8320 | Slog.w(TAG, "Failed parsing daily " + e); |
| 8321 | } catch (IOException e) { |
| 8322 | Slog.w(TAG, "Failed parsing daily " + e); |
| 8323 | } catch (IndexOutOfBoundsException e) { |
| 8324 | Slog.w(TAG, "Failed parsing daily " + e); |
| 8325 | } |
| 8326 | } |
| 8327 | |
| 8328 | void readDailyItemTagLocked(XmlPullParser parser) throws NumberFormatException, |
| 8329 | XmlPullParserException, IOException { |
| 8330 | DailyItem dit = new DailyItem(); |
| 8331 | String attr = parser.getAttributeValue(null, "start"); |
| 8332 | if (attr != null) { |
| 8333 | dit.mStartTime = Long.parseLong(attr); |
| 8334 | } |
| 8335 | attr = parser.getAttributeValue(null, "end"); |
| 8336 | if (attr != null) { |
| 8337 | dit.mEndTime = Long.parseLong(attr); |
| 8338 | } |
| 8339 | int outerDepth = parser.getDepth(); |
| 8340 | int type; |
| 8341 | while ((type = parser.next()) != XmlPullParser.END_DOCUMENT |
| 8342 | && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) { |
| 8343 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 8344 | continue; |
| 8345 | } |
| 8346 | |
| 8347 | String tagName = parser.getName(); |
| 8348 | if (tagName.equals("dis")) { |
| 8349 | readDailyItemTagDetailsLocked(parser, dit, false, "dis"); |
| 8350 | } else if (tagName.equals("chg")) { |
| 8351 | readDailyItemTagDetailsLocked(parser, dit, true, "chg"); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 8352 | } else if (tagName.equals("upd")) { |
| 8353 | if (dit.mPackageChanges == null) { |
| 8354 | dit.mPackageChanges = new ArrayList<>(); |
| 8355 | } |
| 8356 | PackageChange pc = new PackageChange(); |
| 8357 | pc.mUpdate = true; |
| 8358 | pc.mPackageName = parser.getAttributeValue(null, "pkg"); |
| 8359 | String verStr = parser.getAttributeValue(null, "ver"); |
| 8360 | pc.mVersionCode = verStr != null ? Integer.parseInt(verStr) : 0; |
| 8361 | dit.mPackageChanges.add(pc); |
| 8362 | XmlUtils.skipCurrentTag(parser); |
| 8363 | } else if (tagName.equals("rem")) { |
| 8364 | if (dit.mPackageChanges == null) { |
| 8365 | dit.mPackageChanges = new ArrayList<>(); |
| 8366 | } |
| 8367 | PackageChange pc = new PackageChange(); |
| 8368 | pc.mUpdate = false; |
| 8369 | pc.mPackageName = parser.getAttributeValue(null, "pkg"); |
| 8370 | dit.mPackageChanges.add(pc); |
| 8371 | XmlUtils.skipCurrentTag(parser); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 8372 | } else { |
| 8373 | Slog.w(TAG, "Unknown element under <item>: " |
| 8374 | + parser.getName()); |
| 8375 | XmlUtils.skipCurrentTag(parser); |
| 8376 | } |
| 8377 | } |
| 8378 | mDailyItems.add(dit); |
| 8379 | } |
| 8380 | |
| 8381 | void readDailyItemTagDetailsLocked(XmlPullParser parser, DailyItem dit, boolean isCharge, |
| 8382 | String tag) |
| 8383 | throws NumberFormatException, XmlPullParserException, IOException { |
| 8384 | final String numAttr = parser.getAttributeValue(null, "n"); |
| 8385 | if (numAttr == null) { |
| 8386 | Slog.w(TAG, "Missing 'n' attribute at " + parser.getPositionDescription()); |
| 8387 | XmlUtils.skipCurrentTag(parser); |
| 8388 | return; |
| 8389 | } |
| 8390 | final int num = Integer.parseInt(numAttr); |
| 8391 | LevelStepTracker steps = new LevelStepTracker(num); |
| 8392 | if (isCharge) { |
| 8393 | dit.mChargeSteps = steps; |
| 8394 | } else { |
| 8395 | dit.mDischargeSteps = steps; |
| 8396 | } |
| 8397 | int i = 0; |
| 8398 | int outerDepth = parser.getDepth(); |
| 8399 | int type; |
| 8400 | while ((type = parser.next()) != XmlPullParser.END_DOCUMENT |
| 8401 | && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) { |
| 8402 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 8403 | continue; |
| 8404 | } |
| 8405 | |
| 8406 | String tagName = parser.getName(); |
| 8407 | if ("s".equals(tagName)) { |
| 8408 | if (i < num) { |
| 8409 | String valueAttr = parser.getAttributeValue(null, "v"); |
| 8410 | if (valueAttr != null) { |
| 8411 | steps.decodeEntryAt(i, valueAttr); |
| 8412 | i++; |
| 8413 | } |
| 8414 | } |
| 8415 | } else { |
| 8416 | Slog.w(TAG, "Unknown element under <" + tag + ">: " |
| 8417 | + parser.getName()); |
| 8418 | XmlUtils.skipCurrentTag(parser); |
| 8419 | } |
| 8420 | } |
| 8421 | steps.mNumStepDurations = i; |
| 8422 | } |
| 8423 | |
| 8424 | @Override |
| 8425 | public DailyItem getDailyItemLocked(int daysAgo) { |
| 8426 | int index = mDailyItems.size()-1-daysAgo; |
| 8427 | return index >= 0 ? mDailyItems.get(index) : null; |
| 8428 | } |
| 8429 | |
| 8430 | @Override |
| 8431 | public long getCurrentDailyStartTime() { |
| 8432 | return mDailyStartTime; |
| 8433 | } |
| 8434 | |
| 8435 | @Override |
| 8436 | public long getNextMinDailyDeadline() { |
| 8437 | return mNextMinDailyDeadline; |
| 8438 | } |
| 8439 | |
| 8440 | @Override |
| 8441 | public long getNextMaxDailyDeadline() { |
| 8442 | return mNextMaxDailyDeadline; |
| 8443 | } |
| 8444 | |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 8445 | @Override |
| 8446 | public boolean startIteratingOldHistoryLocked() { |
| 8447 | if (DEBUG_HISTORY) Slog.i(TAG, "ITERATING: buff size=" + mHistoryBuffer.dataSize() |
| 8448 | + " pos=" + mHistoryBuffer.dataPosition()); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 8449 | if ((mHistoryIterator = mHistory) == null) { |
| 8450 | return false; |
| 8451 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 8452 | mHistoryBuffer.setDataPosition(0); |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 8453 | mHistoryReadTmp.clear(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 8454 | mReadOverflow = false; |
| 8455 | mIteratingHistory = true; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 8456 | return true; |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 8457 | } |
| 8458 | |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 8459 | @Override |
| 8460 | public boolean getNextOldHistoryLocked(HistoryItem out) { |
| 8461 | boolean end = mHistoryBuffer.dataPosition() >= mHistoryBuffer.dataSize(); |
| 8462 | if (!end) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 8463 | readHistoryDelta(mHistoryBuffer, mHistoryReadTmp); |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 8464 | mReadOverflow |= mHistoryReadTmp.cmd == HistoryItem.CMD_OVERFLOW; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 8465 | } |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 8466 | HistoryItem cur = mHistoryIterator; |
| 8467 | if (cur == null) { |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 8468 | if (!mReadOverflow && !end) { |
| 8469 | Slog.w(TAG, "Old history ends before new history!"); |
| 8470 | } |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 8471 | return false; |
| 8472 | } |
| 8473 | out.setTo(cur); |
| 8474 | mHistoryIterator = cur.next; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 8475 | if (!mReadOverflow) { |
| 8476 | if (end) { |
| 8477 | Slog.w(TAG, "New history ends before old history!"); |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 8478 | } else if (!out.same(mHistoryReadTmp)) { |
Dianne Hackborn | 8c84109 | 2013-06-24 13:46:13 -0700 | [diff] [blame] | 8479 | PrintWriter pw = new FastPrintWriter(new LogWriter(android.util.Log.WARN, TAG)); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 8480 | pw.println("Histories differ!"); |
| 8481 | pw.println("Old history:"); |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 8482 | (new HistoryPrinter()).printNextItem(pw, out, 0, false, true); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 8483 | pw.println("New history:"); |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 8484 | (new HistoryPrinter()).printNextItem(pw, mHistoryReadTmp, 0, false, |
| 8485 | true); |
Dianne Hackborn | 8c84109 | 2013-06-24 13:46:13 -0700 | [diff] [blame] | 8486 | pw.flush(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 8487 | } |
| 8488 | } |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 8489 | return true; |
| 8490 | } |
| 8491 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8492 | @Override |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 8493 | public void finishIteratingOldHistoryLocked() { |
| 8494 | mIteratingHistory = false; |
| 8495 | mHistoryBuffer.setDataPosition(mHistoryBuffer.dataSize()); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 8496 | mHistoryIterator = null; |
| 8497 | } |
| 8498 | |
| 8499 | public int getHistoryTotalSize() { |
| 8500 | return MAX_HISTORY_BUFFER; |
| 8501 | } |
| 8502 | |
| 8503 | public int getHistoryUsedSize() { |
| 8504 | return mHistoryBuffer.dataSize(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 8505 | } |
| 8506 | |
| 8507 | @Override |
| 8508 | public boolean startIteratingHistoryLocked() { |
| 8509 | if (DEBUG_HISTORY) Slog.i(TAG, "ITERATING: buff size=" + mHistoryBuffer.dataSize() |
| 8510 | + " pos=" + mHistoryBuffer.dataPosition()); |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 8511 | if (mHistoryBuffer.dataSize() <= 0) { |
| 8512 | return false; |
| 8513 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 8514 | mHistoryBuffer.setDataPosition(0); |
| 8515 | mReadOverflow = false; |
| 8516 | mIteratingHistory = true; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 8517 | mReadHistoryStrings = new String[mHistoryTagPool.size()]; |
| 8518 | mReadHistoryUids = new int[mHistoryTagPool.size()]; |
| 8519 | mReadHistoryChars = 0; |
| 8520 | for (HashMap.Entry<HistoryTag, Integer> ent : mHistoryTagPool.entrySet()) { |
| 8521 | final HistoryTag tag = ent.getKey(); |
| 8522 | final int idx = ent.getValue(); |
| 8523 | mReadHistoryStrings[idx] = tag.string; |
| 8524 | mReadHistoryUids[idx] = tag.uid; |
| 8525 | mReadHistoryChars += tag.string.length() + 1; |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 8526 | } |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 8527 | return true; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 8528 | } |
| 8529 | |
| 8530 | @Override |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 8531 | public int getHistoryStringPoolSize() { |
| 8532 | return mReadHistoryStrings.length; |
| 8533 | } |
| 8534 | |
| 8535 | @Override |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 8536 | public int getHistoryStringPoolBytes() { |
| 8537 | // Each entry is a fixed 12 bytes: 4 for index, 4 for uid, 4 for string size |
| 8538 | // Each string character is 2 bytes. |
| 8539 | return (mReadHistoryStrings.length * 12) + (mReadHistoryChars * 2); |
| 8540 | } |
| 8541 | |
| 8542 | @Override |
| 8543 | public String getHistoryTagPoolString(int index) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 8544 | return mReadHistoryStrings[index]; |
| 8545 | } |
| 8546 | |
| 8547 | @Override |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 8548 | public int getHistoryTagPoolUid(int index) { |
| 8549 | return mReadHistoryUids[index]; |
| 8550 | } |
| 8551 | |
| 8552 | @Override |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 8553 | public boolean getNextHistoryLocked(HistoryItem out) { |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 8554 | final int pos = mHistoryBuffer.dataPosition(); |
| 8555 | if (pos == 0) { |
| 8556 | out.clear(); |
| 8557 | } |
| 8558 | boolean end = pos >= mHistoryBuffer.dataSize(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 8559 | if (end) { |
| 8560 | return false; |
| 8561 | } |
| 8562 | |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 8563 | final long lastRealtime = out.time; |
| 8564 | final long lastWalltime = out.currentTime; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 8565 | readHistoryDelta(mHistoryBuffer, out); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 8566 | if (out.cmd != HistoryItem.CMD_CURRENT_TIME |
| 8567 | && out.cmd != HistoryItem.CMD_RESET && lastWalltime != 0) { |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 8568 | out.currentTime = lastWalltime + (out.time - lastRealtime); |
| 8569 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 8570 | return true; |
| 8571 | } |
| 8572 | |
| 8573 | @Override |
| 8574 | public void finishIteratingHistoryLocked() { |
| 8575 | mIteratingHistory = false; |
| 8576 | mHistoryBuffer.setDataPosition(mHistoryBuffer.dataSize()); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 8577 | mReadHistoryStrings = null; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 8578 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 8579 | |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 8580 | @Override |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 8581 | public long getHistoryBaseTime() { |
| 8582 | return mHistoryBaseTime; |
| 8583 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 8584 | |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 8585 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8586 | public int getStartCount() { |
| 8587 | return mStartCount; |
| 8588 | } |
| 8589 | |
| 8590 | public boolean isOnBattery() { |
| 8591 | return mOnBattery; |
| 8592 | } |
| 8593 | |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 8594 | public boolean isCharging() { |
| 8595 | return mCharging; |
| 8596 | } |
| 8597 | |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 8598 | public boolean isScreenOn() { |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 8599 | return mScreenState == Display.STATE_ON; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 8600 | } |
| 8601 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8602 | void initTimes(long uptime, long realtime) { |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 8603 | mStartClockTime = System.currentTimeMillis(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8604 | mOnBatteryTimeBase.init(uptime, realtime); |
| 8605 | mOnBatteryScreenOffTimeBase.init(uptime, realtime); |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 8606 | mRealtime = 0; |
| 8607 | mUptime = 0; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8608 | mRealtimeStart = realtime; |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 8609 | mUptimeStart = uptime; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8610 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 8611 | |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 8612 | void initDischarge() { |
| 8613 | mLowDischargeAmountSinceCharge = 0; |
| 8614 | mHighDischargeAmountSinceCharge = 0; |
| 8615 | mDischargeAmountScreenOn = 0; |
| 8616 | mDischargeAmountScreenOnSinceCharge = 0; |
| 8617 | mDischargeAmountScreenOff = 0; |
| 8618 | mDischargeAmountScreenOffSinceCharge = 0; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 8619 | mDischargeStepTracker.init(); |
| 8620 | mChargeStepTracker.init(); |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 8621 | mDischargeScreenOffCounter.reset(false); |
| 8622 | mDischargeCounter.reset(false); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 8623 | } |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 8624 | |
| 8625 | public void resetAllStatsCmdLocked() { |
| 8626 | resetAllStatsLocked(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8627 | final long mSecUptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 8628 | long uptime = mSecUptime * 1000; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8629 | long mSecRealtime = mClocks.elapsedRealtime(); |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 8630 | long realtime = mSecRealtime * 1000; |
| 8631 | mDischargeStartLevel = mHistoryCur.batteryLevel; |
| 8632 | pullPendingStateUpdatesLocked(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 8633 | addHistoryRecordLocked(mSecRealtime, mSecUptime); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 8634 | mDischargeCurrentLevel = mDischargeUnplugLevel = mDischargePlugLevel |
| 8635 | = mCurrentBatteryLevel = mHistoryCur.batteryLevel; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8636 | mOnBatteryTimeBase.reset(uptime, realtime); |
| 8637 | mOnBatteryScreenOffTimeBase.reset(uptime, realtime); |
| 8638 | if ((mHistoryCur.states&HistoryItem.STATE_BATTERY_PLUGGED_FLAG) == 0) { |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 8639 | if (mScreenState == Display.STATE_ON) { |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 8640 | mDischargeScreenOnUnplugLevel = mHistoryCur.batteryLevel; |
| 8641 | mDischargeScreenOffUnplugLevel = 0; |
| 8642 | } else { |
| 8643 | mDischargeScreenOnUnplugLevel = 0; |
| 8644 | mDischargeScreenOffUnplugLevel = mHistoryCur.batteryLevel; |
| 8645 | } |
| 8646 | mDischargeAmountScreenOn = 0; |
| 8647 | mDischargeAmountScreenOff = 0; |
| 8648 | } |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 8649 | initActiveHistoryEventsLocked(mSecRealtime, mSecUptime); |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 8650 | } |
| 8651 | |
| 8652 | private void resetAllStatsLocked() { |
Adam Lesinski | 8ce3694 | 2016-05-26 16:05:35 -0700 | [diff] [blame] | 8653 | final long uptimeMillis = mClocks.uptimeMillis(); |
| 8654 | final long elapsedRealtimeMillis = mClocks.elapsedRealtime(); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8655 | mStartCount = 0; |
Adam Lesinski | 8ce3694 | 2016-05-26 16:05:35 -0700 | [diff] [blame] | 8656 | initTimes(uptimeMillis * 1000, elapsedRealtimeMillis * 1000); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8657 | mScreenOnTimer.reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8658 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8659 | mScreenBrightnessTimer[i].reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8660 | } |
Adam Lesinski | 1a76a62 | 2016-06-22 10:28:47 -0700 | [diff] [blame] | 8661 | |
| 8662 | if (mPowerProfile != null) { |
| 8663 | mEstimatedBatteryCapacity = (int) mPowerProfile.getBatteryCapacity(); |
| 8664 | } else { |
| 8665 | mEstimatedBatteryCapacity = -1; |
| 8666 | } |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 8667 | mInteractiveTimer.reset(false); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 8668 | mPowerSaveModeEnabledTimer.reset(false); |
Adam Lesinski | 8ce3694 | 2016-05-26 16:05:35 -0700 | [diff] [blame] | 8669 | mLastIdleTimeStart = elapsedRealtimeMillis; |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 8670 | mLongestLightIdleTime = 0; |
| 8671 | mLongestFullIdleTime = 0; |
| 8672 | mDeviceIdleModeLightTimer.reset(false); |
| 8673 | mDeviceIdleModeFullTimer.reset(false); |
| 8674 | mDeviceLightIdlingTimer.reset(false); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 8675 | mDeviceIdlingTimer.reset(false); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8676 | mPhoneOnTimer.reset(false); |
| 8677 | mAudioOnTimer.reset(false); |
| 8678 | mVideoOnTimer.reset(false); |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 8679 | mFlashlightOnTimer.reset(false); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 8680 | mCameraOnTimer.reset(false); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 8681 | mBluetoothScanTimer.reset(false); |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 8682 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8683 | mPhoneSignalStrengthsTimer[i].reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8684 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8685 | mPhoneSignalScanningTimer.reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8686 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8687 | mPhoneDataConnectionsTimer[i].reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8688 | } |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 8689 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 8690 | mNetworkByteActivityCounters[i].reset(false); |
| 8691 | mNetworkPacketActivityCounters[i].reset(false); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 8692 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8693 | mMobileRadioActiveTimer.reset(false); |
| 8694 | mMobileRadioActivePerAppTimer.reset(false); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 8695 | mMobileRadioActiveAdjustedTime.reset(false); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 8696 | mMobileRadioActiveUnknownTime.reset(false); |
| 8697 | mMobileRadioActiveUnknownCount.reset(false); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8698 | mWifiOnTimer.reset(false); |
| 8699 | mGlobalWifiRunningTimer.reset(false); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 8700 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8701 | mWifiStateTimer[i].reset(false); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 8702 | } |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 8703 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
| 8704 | mWifiSupplStateTimer[i].reset(false); |
| 8705 | } |
| 8706 | for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 8707 | mWifiSignalStrengthsTimer[i].reset(false); |
| 8708 | } |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 8709 | mWifiActivity.reset(false); |
| 8710 | mBluetoothActivity.reset(false); |
| 8711 | mModemActivity.reset(false); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 8712 | mNumConnectivityChange = mLoadedNumConnectivityChange = mUnpluggedNumConnectivityChange = 0; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 8713 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8714 | for (int i=0; i<mUidStats.size(); i++) { |
| 8715 | if (mUidStats.valueAt(i).reset()) { |
| 8716 | mUidStats.remove(mUidStats.keyAt(i)); |
| 8717 | i--; |
| 8718 | } |
| 8719 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 8720 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8721 | if (mKernelWakelockStats.size() > 0) { |
| 8722 | for (SamplingTimer timer : mKernelWakelockStats.values()) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8723 | mOnBatteryScreenOffTimeBase.remove(timer); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8724 | } |
| 8725 | mKernelWakelockStats.clear(); |
| 8726 | } |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 8727 | |
James Carr | 3a22605 | 2016-07-01 14:49:52 -0700 | [diff] [blame] | 8728 | if (mKernelMemoryStats.size() > 0) { |
| 8729 | for (int i = 0; i < mKernelMemoryStats.size(); i++) { |
| 8730 | mOnBatteryTimeBase.remove(mKernelMemoryStats.valueAt(i)); |
| 8731 | } |
| 8732 | mKernelMemoryStats.clear(); |
| 8733 | } |
| 8734 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 8735 | if (mWakeupReasonStats.size() > 0) { |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 8736 | for (SamplingTimer timer : mWakeupReasonStats.values()) { |
| 8737 | mOnBatteryTimeBase.remove(timer); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 8738 | } |
| 8739 | mWakeupReasonStats.clear(); |
| 8740 | } |
| 8741 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 8742 | mLastHistoryStepDetails = null; |
| 8743 | mLastStepCpuUserTime = mLastStepCpuSystemTime = 0; |
| 8744 | mCurStepCpuUserTime = mCurStepCpuSystemTime = 0; |
| 8745 | mLastStepCpuUserTime = mCurStepCpuUserTime = 0; |
| 8746 | mLastStepCpuSystemTime = mCurStepCpuSystemTime = 0; |
| 8747 | mLastStepStatUserTime = mCurStepStatUserTime = 0; |
| 8748 | mLastStepStatSystemTime = mCurStepStatSystemTime = 0; |
| 8749 | mLastStepStatIOWaitTime = mCurStepStatIOWaitTime = 0; |
| 8750 | mLastStepStatIrqTime = mCurStepStatIrqTime = 0; |
| 8751 | mLastStepStatSoftIrqTime = mCurStepStatSoftIrqTime = 0; |
| 8752 | mLastStepStatIdleTime = mCurStepStatIdleTime = 0; |
| 8753 | |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 8754 | initDischarge(); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 8755 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8756 | clearHistoryLocked(); |
| 8757 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 8758 | |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 8759 | private void initActiveHistoryEventsLocked(long elapsedRealtimeMs, long uptimeMs) { |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 8760 | for (int i=0; i<HistoryItem.EVENT_COUNT; i++) { |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 8761 | if (!mRecordAllHistory && i == HistoryItem.EVENT_PROC) { |
| 8762 | // Not recording process starts/stops. |
| 8763 | continue; |
| 8764 | } |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 8765 | HashMap<String, SparseIntArray> active = mActiveEvents.getStateForEvent(i); |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 8766 | if (active == null) { |
| 8767 | continue; |
| 8768 | } |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 8769 | for (HashMap.Entry<String, SparseIntArray> ent : active.entrySet()) { |
| 8770 | SparseIntArray uids = ent.getValue(); |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 8771 | for (int j=0; j<uids.size(); j++) { |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 8772 | addHistoryEventLocked(elapsedRealtimeMs, uptimeMs, i, ent.getKey(), |
| 8773 | uids.keyAt(j)); |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 8774 | } |
| 8775 | } |
| 8776 | } |
| 8777 | } |
| 8778 | |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 8779 | void updateDischargeScreenLevelsLocked(boolean oldScreenOn, boolean newScreenOn) { |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 8780 | if (oldScreenOn) { |
| 8781 | int diff = mDischargeScreenOnUnplugLevel - mDischargeCurrentLevel; |
| 8782 | if (diff > 0) { |
| 8783 | mDischargeAmountScreenOn += diff; |
| 8784 | mDischargeAmountScreenOnSinceCharge += diff; |
| 8785 | } |
| 8786 | } else { |
| 8787 | int diff = mDischargeScreenOffUnplugLevel - mDischargeCurrentLevel; |
| 8788 | if (diff > 0) { |
| 8789 | mDischargeAmountScreenOff += diff; |
| 8790 | mDischargeAmountScreenOffSinceCharge += diff; |
| 8791 | } |
| 8792 | } |
| 8793 | if (newScreenOn) { |
| 8794 | mDischargeScreenOnUnplugLevel = mDischargeCurrentLevel; |
| 8795 | mDischargeScreenOffUnplugLevel = 0; |
| 8796 | } else { |
| 8797 | mDischargeScreenOnUnplugLevel = 0; |
| 8798 | mDischargeScreenOffUnplugLevel = mDischargeCurrentLevel; |
| 8799 | } |
| 8800 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8801 | |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 8802 | public void pullPendingStateUpdatesLocked() { |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 8803 | if (mOnBatteryInternal) { |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 8804 | final boolean screenOn = mScreenState == Display.STATE_ON; |
| 8805 | updateDischargeScreenLevelsLocked(screenOn, screenOn); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 8806 | } |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 8807 | } |
| 8808 | |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8809 | private String[] mMobileIfaces = EmptyArray.STRING; |
| 8810 | private String[] mWifiIfaces = EmptyArray.STRING; |
| 8811 | |
| 8812 | private final NetworkStatsFactory mNetworkStatsFactory = new NetworkStatsFactory(); |
| 8813 | |
| 8814 | private static final int NETWORK_STATS_LAST = 0; |
| 8815 | private static final int NETWORK_STATS_NEXT = 1; |
| 8816 | private static final int NETWORK_STATS_DELTA = 2; |
| 8817 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8818 | private NetworkStats[] mMobileNetworkStats; |
| 8819 | private NetworkStats[] mWifiNetworkStats; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8820 | |
| 8821 | /** |
| 8822 | * Retrieves the delta of network stats for the given network ifaces. Uses networkStatsBuffer |
| 8823 | * as a buffer of NetworkStats objects to cycle through when computing deltas. |
| 8824 | */ |
| 8825 | private NetworkStats getNetworkStatsDeltaLocked(String[] ifaces, |
| 8826 | NetworkStats[] networkStatsBuffer) |
| 8827 | throws IOException { |
| 8828 | if (!SystemProperties.getBoolean(NetworkManagementSocketTagger.PROP_QTAGUID_ENABLED, |
| 8829 | false)) { |
| 8830 | return null; |
| 8831 | } |
| 8832 | |
| 8833 | final NetworkStats stats = mNetworkStatsFactory.readNetworkStatsDetail(NetworkStats.UID_ALL, |
| 8834 | ifaces, NetworkStats.TAG_NONE, networkStatsBuffer[NETWORK_STATS_NEXT]); |
| 8835 | networkStatsBuffer[NETWORK_STATS_DELTA] = NetworkStats.subtract(stats, |
| 8836 | networkStatsBuffer[NETWORK_STATS_LAST], null, null, |
| 8837 | networkStatsBuffer[NETWORK_STATS_DELTA]); |
| 8838 | networkStatsBuffer[NETWORK_STATS_NEXT] = networkStatsBuffer[NETWORK_STATS_LAST]; |
| 8839 | networkStatsBuffer[NETWORK_STATS_LAST] = stats; |
| 8840 | return networkStatsBuffer[NETWORK_STATS_DELTA]; |
| 8841 | } |
| 8842 | |
| 8843 | /** |
| 8844 | * Distribute WiFi energy info and network traffic to apps. |
| 8845 | * @param info The energy information from the WiFi controller. |
| 8846 | */ |
| 8847 | public void updateWifiStateLocked(@Nullable final WifiActivityEnergyInfo info) { |
Adam Lesinski | a7c90c8 | 2015-06-18 14:52:24 -0700 | [diff] [blame] | 8848 | if (DEBUG_ENERGY) { |
| 8849 | Slog.d(TAG, "Updating wifi stats"); |
| 8850 | } |
| 8851 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8852 | final long elapsedRealtimeMs = mClocks.elapsedRealtime(); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 8853 | NetworkStats delta = null; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8854 | try { |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 8855 | if (!ArrayUtils.isEmpty(mWifiIfaces)) { |
| 8856 | delta = getNetworkStatsDeltaLocked(mWifiIfaces, mWifiNetworkStats); |
| 8857 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8858 | } catch (IOException e) { |
| 8859 | Slog.wtf(TAG, "Failed to get wifi network stats", e); |
| 8860 | return; |
| 8861 | } |
| 8862 | |
| 8863 | if (!mOnBatteryInternal) { |
| 8864 | return; |
| 8865 | } |
| 8866 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 8867 | SparseLongArray rxPackets = new SparseLongArray(); |
| 8868 | SparseLongArray txPackets = new SparseLongArray(); |
| 8869 | long totalTxPackets = 0; |
| 8870 | long totalRxPackets = 0; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8871 | if (delta != null) { |
| 8872 | final int size = delta.size(); |
| 8873 | for (int i = 0; i < size; i++) { |
| 8874 | final NetworkStats.Entry entry = delta.getValues(i, mTmpNetworkStatsEntry); |
| 8875 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 8876 | if (DEBUG_ENERGY) { |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8877 | Slog.d(TAG, "Wifi uid " + entry.uid + ": delta rx=" + entry.rxBytes |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 8878 | + " tx=" + entry.txBytes + " rxPackets=" + entry.rxPackets |
| 8879 | + " txPackets=" + entry.txPackets); |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8880 | } |
| 8881 | |
Adam Lesinski | 6cca414 | 2016-02-25 18:23:02 -0800 | [diff] [blame] | 8882 | if (entry.rxBytes == 0 && entry.txBytes == 0) { |
| 8883 | // Skip the lookup below since there is no work to do. |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8884 | continue; |
| 8885 | } |
| 8886 | |
| 8887 | final Uid u = getUidStatsLocked(mapUid(entry.uid)); |
Adam Lesinski | ba88e68 | 2015-12-08 12:06:55 -0800 | [diff] [blame] | 8888 | if (entry.rxBytes != 0) { |
| 8889 | u.noteNetworkActivityLocked(NETWORK_WIFI_RX_DATA, entry.rxBytes, |
| 8890 | entry.rxPackets); |
Amith Yamasani | 59fe841 | 2017-03-03 16:28:52 -0800 | [diff] [blame] | 8891 | if (entry.set == NetworkStats.SET_DEFAULT) { // Background transfers |
| 8892 | u.noteNetworkActivityLocked(NETWORK_WIFI_BG_RX_DATA, entry.rxBytes, |
| 8893 | entry.rxPackets); |
| 8894 | } |
Adam Lesinski | ba88e68 | 2015-12-08 12:06:55 -0800 | [diff] [blame] | 8895 | mNetworkByteActivityCounters[NETWORK_WIFI_RX_DATA].addCountLocked( |
| 8896 | entry.rxBytes); |
| 8897 | mNetworkPacketActivityCounters[NETWORK_WIFI_RX_DATA].addCountLocked( |
| 8898 | entry.rxPackets); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 8899 | |
Adam Lesinski | ba88e68 | 2015-12-08 12:06:55 -0800 | [diff] [blame] | 8900 | rxPackets.put(u.getUid(), entry.rxPackets); |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8901 | |
Adam Lesinski | ba88e68 | 2015-12-08 12:06:55 -0800 | [diff] [blame] | 8902 | // Sum the total number of packets so that the Rx Power can |
| 8903 | // be evenly distributed amongst the apps. |
| 8904 | totalRxPackets += entry.rxPackets; |
| 8905 | } |
| 8906 | |
| 8907 | if (entry.txBytes != 0) { |
| 8908 | u.noteNetworkActivityLocked(NETWORK_WIFI_TX_DATA, entry.txBytes, |
| 8909 | entry.txPackets); |
Amith Yamasani | 59fe841 | 2017-03-03 16:28:52 -0800 | [diff] [blame] | 8910 | if (entry.set == NetworkStats.SET_DEFAULT) { // Background transfers |
| 8911 | u.noteNetworkActivityLocked(NETWORK_WIFI_BG_TX_DATA, entry.txBytes, |
| 8912 | entry.txPackets); |
| 8913 | } |
Adam Lesinski | ba88e68 | 2015-12-08 12:06:55 -0800 | [diff] [blame] | 8914 | mNetworkByteActivityCounters[NETWORK_WIFI_TX_DATA].addCountLocked( |
| 8915 | entry.txBytes); |
| 8916 | mNetworkPacketActivityCounters[NETWORK_WIFI_TX_DATA].addCountLocked( |
| 8917 | entry.txPackets); |
| 8918 | |
| 8919 | txPackets.put(u.getUid(), entry.txPackets); |
| 8920 | |
| 8921 | // Sum the total number of packets so that the Tx Power can |
| 8922 | // be evenly distributed amongst the apps. |
| 8923 | totalTxPackets += entry.txPackets; |
| 8924 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8925 | } |
| 8926 | } |
| 8927 | |
| 8928 | if (info != null) { |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 8929 | mHasWifiReporting = true; |
Adam Lesinski | 1739076 | 2015-04-10 13:17:47 -0700 | [diff] [blame] | 8930 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 8931 | // Measured in mAms |
| 8932 | final long txTimeMs = info.getControllerTxTimeMillis(); |
| 8933 | final long rxTimeMs = info.getControllerRxTimeMillis(); |
| 8934 | final long idleTimeMs = info.getControllerIdleTimeMillis(); |
| 8935 | final long totalTimeMs = txTimeMs + rxTimeMs + idleTimeMs; |
| 8936 | |
| 8937 | long leftOverRxTimeMs = rxTimeMs; |
Mitchell Wills | f901649 | 2015-07-29 17:47:44 -0700 | [diff] [blame] | 8938 | long leftOverTxTimeMs = txTimeMs; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 8939 | |
| 8940 | if (DEBUG_ENERGY) { |
| 8941 | Slog.d(TAG, "------ BEGIN WiFi power blaming ------"); |
| 8942 | Slog.d(TAG, " Tx Time: " + txTimeMs + " ms"); |
| 8943 | Slog.d(TAG, " Rx Time: " + rxTimeMs + " ms"); |
| 8944 | Slog.d(TAG, " Idle Time: " + idleTimeMs + " ms"); |
| 8945 | Slog.d(TAG, " Total Time: " + totalTimeMs + " ms"); |
| 8946 | } |
| 8947 | |
| 8948 | long totalWifiLockTimeMs = 0; |
| 8949 | long totalScanTimeMs = 0; |
| 8950 | |
| 8951 | // On the first pass, collect some totals so that we can normalize power |
| 8952 | // calculations if we need to. |
| 8953 | final int uidStatsSize = mUidStats.size(); |
| 8954 | for (int i = 0; i < uidStatsSize; i++) { |
| 8955 | final Uid uid = mUidStats.valueAt(i); |
| 8956 | |
| 8957 | // Sum the total scan power for all apps. |
| 8958 | totalScanTimeMs += uid.mWifiScanTimer.getTimeSinceMarkLocked( |
| 8959 | elapsedRealtimeMs * 1000) / 1000; |
| 8960 | |
| 8961 | // Sum the total time holding wifi lock for all apps. |
| 8962 | totalWifiLockTimeMs += uid.mFullWifiLockTimer.getTimeSinceMarkLocked( |
| 8963 | elapsedRealtimeMs * 1000) / 1000; |
| 8964 | } |
| 8965 | |
| 8966 | if (DEBUG_ENERGY && totalScanTimeMs > rxTimeMs) { |
| 8967 | Slog.d(TAG, " !Estimated scan time > Actual rx time (" + totalScanTimeMs + " ms > " |
| 8968 | + rxTimeMs + " ms). Normalizing scan time."); |
| 8969 | } |
Mitchell Wills | f901649 | 2015-07-29 17:47:44 -0700 | [diff] [blame] | 8970 | if (DEBUG_ENERGY && totalScanTimeMs > txTimeMs) { |
| 8971 | Slog.d(TAG, " !Estimated scan time > Actual tx time (" + totalScanTimeMs + " ms > " |
| 8972 | + txTimeMs + " ms). Normalizing scan time."); |
| 8973 | } |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 8974 | |
| 8975 | // Actually assign and distribute power usage to apps. |
| 8976 | for (int i = 0; i < uidStatsSize; i++) { |
| 8977 | final Uid uid = mUidStats.valueAt(i); |
| 8978 | |
| 8979 | long scanTimeSinceMarkMs = uid.mWifiScanTimer.getTimeSinceMarkLocked( |
| 8980 | elapsedRealtimeMs * 1000) / 1000; |
| 8981 | if (scanTimeSinceMarkMs > 0) { |
| 8982 | // Set the new mark so that next time we get new data since this point. |
| 8983 | uid.mWifiScanTimer.setMark(elapsedRealtimeMs); |
| 8984 | |
Mitchell Wills | f901649 | 2015-07-29 17:47:44 -0700 | [diff] [blame] | 8985 | long scanRxTimeSinceMarkMs = scanTimeSinceMarkMs; |
| 8986 | long scanTxTimeSinceMarkMs = scanTimeSinceMarkMs; |
| 8987 | |
| 8988 | // Our total scan time is more than the reported Tx/Rx time. |
| 8989 | // This is possible because the cost of a scan is approximate. |
| 8990 | // Let's normalize the result so that we evenly blame each app |
| 8991 | // scanning. |
| 8992 | // |
| 8993 | // This means that we may have apps that transmitted/received packets not be |
| 8994 | // 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] | 8995 | if (totalScanTimeMs > rxTimeMs) { |
Mitchell Wills | f901649 | 2015-07-29 17:47:44 -0700 | [diff] [blame] | 8996 | scanRxTimeSinceMarkMs = (rxTimeMs * scanRxTimeSinceMarkMs) / |
| 8997 | totalScanTimeMs; |
| 8998 | } |
| 8999 | if (totalScanTimeMs > txTimeMs) { |
| 9000 | scanTxTimeSinceMarkMs = (txTimeMs * scanTxTimeSinceMarkMs) / |
| 9001 | totalScanTimeMs; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 9002 | } |
| 9003 | |
| 9004 | if (DEBUG_ENERGY) { |
Mitchell Wills | f901649 | 2015-07-29 17:47:44 -0700 | [diff] [blame] | 9005 | Slog.d(TAG, " ScanTime for UID " + uid.getUid() + ": Rx:" |
| 9006 | + scanRxTimeSinceMarkMs + " ms Tx:" |
| 9007 | + scanTxTimeSinceMarkMs + " ms)"); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 9008 | } |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 9009 | |
| 9010 | ControllerActivityCounterImpl activityCounter = |
| 9011 | uid.getOrCreateWifiControllerActivityLocked(); |
| 9012 | activityCounter.getRxTimeCounter().addCountLocked(scanRxTimeSinceMarkMs); |
| 9013 | activityCounter.getTxTimeCounters()[0].addCountLocked(scanTxTimeSinceMarkMs); |
Mitchell Wills | f901649 | 2015-07-29 17:47:44 -0700 | [diff] [blame] | 9014 | leftOverRxTimeMs -= scanRxTimeSinceMarkMs; |
| 9015 | leftOverTxTimeMs -= scanTxTimeSinceMarkMs; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 9016 | } |
| 9017 | |
| 9018 | // Distribute evenly the power consumed while Idle to each app holding a WiFi |
| 9019 | // lock. |
| 9020 | final long wifiLockTimeSinceMarkMs = uid.mFullWifiLockTimer.getTimeSinceMarkLocked( |
| 9021 | elapsedRealtimeMs * 1000) / 1000; |
| 9022 | if (wifiLockTimeSinceMarkMs > 0) { |
| 9023 | // Set the new mark so that next time we get new data since this point. |
| 9024 | uid.mFullWifiLockTimer.setMark(elapsedRealtimeMs); |
| 9025 | |
| 9026 | final long myIdleTimeMs = (wifiLockTimeSinceMarkMs * idleTimeMs) |
| 9027 | / totalWifiLockTimeMs; |
| 9028 | if (DEBUG_ENERGY) { |
| 9029 | Slog.d(TAG, " IdleTime for UID " + uid.getUid() + ": " |
| 9030 | + myIdleTimeMs + " ms"); |
| 9031 | } |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 9032 | uid.getOrCreateWifiControllerActivityLocked().getIdleTimeCounter() |
| 9033 | .addCountLocked(myIdleTimeMs); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 9034 | } |
| 9035 | } |
| 9036 | |
| 9037 | if (DEBUG_ENERGY) { |
| 9038 | Slog.d(TAG, " New RxPower: " + leftOverRxTimeMs + " ms"); |
Mitchell Wills | f901649 | 2015-07-29 17:47:44 -0700 | [diff] [blame] | 9039 | Slog.d(TAG, " New TxPower: " + leftOverTxTimeMs + " ms"); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 9040 | } |
| 9041 | |
Mitchell Wills | f901649 | 2015-07-29 17:47:44 -0700 | [diff] [blame] | 9042 | // Distribute the remaining Tx power appropriately between all apps that transmitted |
| 9043 | // packets. |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 9044 | for (int i = 0; i < txPackets.size(); i++) { |
| 9045 | final Uid uid = getUidStatsLocked(txPackets.keyAt(i)); |
Mitchell Wills | f901649 | 2015-07-29 17:47:44 -0700 | [diff] [blame] | 9046 | final long myTxTimeMs = (txPackets.valueAt(i) * leftOverTxTimeMs) / totalTxPackets; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 9047 | if (DEBUG_ENERGY) { |
| 9048 | Slog.d(TAG, " TxTime for UID " + uid.getUid() + ": " + myTxTimeMs + " ms"); |
| 9049 | } |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 9050 | uid.getOrCreateWifiControllerActivityLocked().getTxTimeCounters()[0] |
| 9051 | .addCountLocked(myTxTimeMs); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 9052 | } |
| 9053 | |
| 9054 | // Distribute the remaining Rx power appropriately between all apps that received |
| 9055 | // packets. |
| 9056 | for (int i = 0; i < rxPackets.size(); i++) { |
| 9057 | final Uid uid = getUidStatsLocked(rxPackets.keyAt(i)); |
| 9058 | final long myRxTimeMs = (rxPackets.valueAt(i) * leftOverRxTimeMs) / totalRxPackets; |
| 9059 | if (DEBUG_ENERGY) { |
| 9060 | Slog.d(TAG, " RxTime for UID " + uid.getUid() + ": " + myRxTimeMs + " ms"); |
| 9061 | } |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 9062 | uid.getOrCreateWifiControllerActivityLocked().getRxTimeCounter() |
| 9063 | .addCountLocked(myRxTimeMs); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 9064 | } |
| 9065 | |
| 9066 | // Any left over power use will be picked up by the WiFi category in BatteryStatsHelper. |
| 9067 | |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 9068 | // Update WiFi controller stats. |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 9069 | mWifiActivity.getRxTimeCounter().addCountLocked(info.getControllerRxTimeMillis()); |
| 9070 | mWifiActivity.getTxTimeCounters()[0].addCountLocked(info.getControllerTxTimeMillis()); |
| 9071 | mWifiActivity.getIdleTimeCounter().addCountLocked(info.getControllerIdleTimeMillis()); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 9072 | |
Adam Lesinski | 8576cf9 | 2015-06-09 12:48:25 -0700 | [diff] [blame] | 9073 | // POWER_WIFI_CONTROLLER_OPERATING_VOLTAGE is measured in mV, so convert to V. |
| 9074 | final double opVolt = mPowerProfile.getAveragePower( |
| 9075 | PowerProfile.POWER_WIFI_CONTROLLER_OPERATING_VOLTAGE) / 1000.0; |
| 9076 | if (opVolt != 0) { |
| 9077 | // We store the power drain as mAms. |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 9078 | mWifiActivity.getPowerCounter().addCountLocked( |
Adam Lesinski | 8576cf9 | 2015-06-09 12:48:25 -0700 | [diff] [blame] | 9079 | (long)(info.getControllerEnergyUsed() / opVolt)); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 9080 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 9081 | } |
| 9082 | } |
| 9083 | |
| 9084 | /** |
| 9085 | * Distribute Cell radio energy info and network traffic to apps. |
| 9086 | */ |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 9087 | public void updateMobileRadioStateLocked(final long elapsedRealtimeMs, |
| 9088 | final ModemActivityInfo activityInfo) { |
Adam Lesinski | a7c90c8 | 2015-06-18 14:52:24 -0700 | [diff] [blame] | 9089 | if (DEBUG_ENERGY) { |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 9090 | Slog.d(TAG, "Updating mobile radio stats with " + activityInfo); |
Adam Lesinski | a7c90c8 | 2015-06-18 14:52:24 -0700 | [diff] [blame] | 9091 | } |
| 9092 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 9093 | NetworkStats delta = null; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 9094 | try { |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 9095 | if (!ArrayUtils.isEmpty(mMobileIfaces)) { |
| 9096 | delta = getNetworkStatsDeltaLocked(mMobileIfaces, mMobileNetworkStats); |
| 9097 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 9098 | } catch (IOException e) { |
| 9099 | Slog.wtf(TAG, "Failed to get mobile network stats", e); |
| 9100 | return; |
| 9101 | } |
| 9102 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 9103 | if (!mOnBatteryInternal) { |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 9104 | return; |
| 9105 | } |
| 9106 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 9107 | long radioTime = mMobileRadioActivePerAppTimer.getTimeSinceMarkLocked( |
| 9108 | elapsedRealtimeMs * 1000); |
| 9109 | mMobileRadioActivePerAppTimer.setMark(elapsedRealtimeMs); |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 9110 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 9111 | long totalRxPackets = 0; |
| 9112 | long totalTxPackets = 0; |
| 9113 | if (delta != null) { |
| 9114 | final int size = delta.size(); |
| 9115 | for (int i = 0; i < size; i++) { |
| 9116 | final NetworkStats.Entry entry = delta.getValues(i, mTmpNetworkStatsEntry); |
Adam Lesinski | a426817 | 2016-01-29 12:13:54 -0800 | [diff] [blame] | 9117 | if (entry.rxPackets == 0 && entry.txPackets == 0) { |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 9118 | continue; |
| 9119 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 9120 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 9121 | if (DEBUG_ENERGY) { |
| 9122 | Slog.d(TAG, "Mobile uid " + entry.uid + ": delta rx=" + entry.rxBytes |
| 9123 | + " tx=" + entry.txBytes + " rxPackets=" + entry.rxPackets |
| 9124 | + " txPackets=" + entry.txPackets); |
| 9125 | } |
| 9126 | |
| 9127 | totalRxPackets += entry.rxPackets; |
| 9128 | totalTxPackets += entry.txPackets; |
| 9129 | |
| 9130 | final Uid u = getUidStatsLocked(mapUid(entry.uid)); |
| 9131 | u.noteNetworkActivityLocked(NETWORK_MOBILE_RX_DATA, entry.rxBytes, entry.rxPackets); |
| 9132 | u.noteNetworkActivityLocked(NETWORK_MOBILE_TX_DATA, entry.txBytes, entry.txPackets); |
Amith Yamasani | 59fe841 | 2017-03-03 16:28:52 -0800 | [diff] [blame] | 9133 | if (entry.set == NetworkStats.SET_DEFAULT) { // Background transfers |
| 9134 | u.noteNetworkActivityLocked(NETWORK_MOBILE_BG_RX_DATA, |
| 9135 | entry.rxBytes, entry.rxPackets); |
| 9136 | u.noteNetworkActivityLocked(NETWORK_MOBILE_BG_TX_DATA, |
| 9137 | entry.txBytes, entry.txPackets); |
| 9138 | } |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 9139 | |
| 9140 | mNetworkByteActivityCounters[NETWORK_MOBILE_RX_DATA].addCountLocked( |
| 9141 | entry.rxBytes); |
| 9142 | mNetworkByteActivityCounters[NETWORK_MOBILE_TX_DATA].addCountLocked( |
| 9143 | entry.txBytes); |
| 9144 | mNetworkPacketActivityCounters[NETWORK_MOBILE_RX_DATA].addCountLocked( |
| 9145 | entry.rxPackets); |
| 9146 | mNetworkPacketActivityCounters[NETWORK_MOBILE_TX_DATA].addCountLocked( |
| 9147 | entry.txPackets); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 9148 | } |
| 9149 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 9150 | // Now distribute proportional blame to the apps that did networking. |
| 9151 | long totalPackets = totalRxPackets + totalTxPackets; |
| 9152 | if (totalPackets > 0) { |
| 9153 | for (int i = 0; i < size; i++) { |
| 9154 | final NetworkStats.Entry entry = delta.getValues(i, mTmpNetworkStatsEntry); |
| 9155 | if (entry.rxPackets == 0 && entry.txPackets == 0) { |
| 9156 | continue; |
| 9157 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 9158 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 9159 | final Uid u = getUidStatsLocked(mapUid(entry.uid)); |
| 9160 | |
| 9161 | // Distribute total radio active time in to this app. |
| 9162 | final long appPackets = entry.rxPackets + entry.txPackets; |
| 9163 | final long appRadioTime = (radioTime * appPackets) / totalPackets; |
| 9164 | u.noteMobileRadioActiveTimeLocked(appRadioTime); |
| 9165 | |
| 9166 | // Remove this app from the totals, so that we don't lose any time |
| 9167 | // due to rounding. |
| 9168 | radioTime -= appRadioTime; |
| 9169 | totalPackets -= appPackets; |
| 9170 | |
| 9171 | if (activityInfo != null) { |
| 9172 | ControllerActivityCounterImpl activityCounter = |
| 9173 | u.getOrCreateModemControllerActivityLocked(); |
Adam Lesinski | a426817 | 2016-01-29 12:13:54 -0800 | [diff] [blame] | 9174 | if (totalRxPackets > 0 && entry.rxPackets > 0) { |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 9175 | final long rxMs = (entry.rxPackets * activityInfo.getRxTimeMillis()) |
| 9176 | / totalRxPackets; |
| 9177 | activityCounter.getRxTimeCounter().addCountLocked(rxMs); |
| 9178 | } |
| 9179 | |
Adam Lesinski | a426817 | 2016-01-29 12:13:54 -0800 | [diff] [blame] | 9180 | if (totalTxPackets > 0 && entry.txPackets > 0) { |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 9181 | for (int lvl = 0; lvl < ModemActivityInfo.TX_POWER_LEVELS; lvl++) { |
| 9182 | long txMs = entry.txPackets * activityInfo.getTxTimeMillis()[lvl]; |
| 9183 | txMs /= totalTxPackets; |
| 9184 | activityCounter.getTxTimeCounters()[lvl].addCountLocked(txMs); |
| 9185 | } |
| 9186 | } |
| 9187 | } |
| 9188 | } |
| 9189 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 9190 | |
| 9191 | if (radioTime > 0) { |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 9192 | // Whoops, there is some radio time we can't blame on an app! |
| 9193 | mMobileRadioActiveUnknownTime.addCountLocked(radioTime); |
| 9194 | mMobileRadioActiveUnknownCount.addCountLocked(1); |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 9195 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 9196 | } |
| 9197 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 9198 | if (activityInfo != null) { |
| 9199 | mHasModemReporting = true; |
| 9200 | mModemActivity.getIdleTimeCounter().addCountLocked(activityInfo.getIdleTimeMillis()); |
| 9201 | mModemActivity.getRxTimeCounter().addCountLocked(activityInfo.getRxTimeMillis()); |
| 9202 | for (int lvl = 0; lvl < ModemActivityInfo.TX_POWER_LEVELS; lvl++) { |
| 9203 | mModemActivity.getTxTimeCounters()[lvl] |
| 9204 | .addCountLocked(activityInfo.getTxTimeMillis()[lvl]); |
| 9205 | } |
| 9206 | |
| 9207 | // POWER_MODEM_CONTROLLER_OPERATING_VOLTAGE is measured in mV, so convert to V. |
| 9208 | final double opVolt = mPowerProfile.getAveragePower( |
| 9209 | PowerProfile.POWER_MODEM_CONTROLLER_OPERATING_VOLTAGE) / 1000.0; |
| 9210 | if (opVolt != 0) { |
| 9211 | // We store the power drain as mAms. |
| 9212 | mModemActivity.getPowerCounter().addCountLocked( |
| 9213 | (long) (activityInfo.getEnergyUsed() / opVolt)); |
| 9214 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 9215 | } |
| 9216 | } |
| 9217 | |
| 9218 | /** |
| 9219 | * Distribute Bluetooth energy info and network traffic to apps. |
| 9220 | * @param info The energy information from the bluetooth controller. |
| 9221 | */ |
| 9222 | public void updateBluetoothStateLocked(@Nullable final BluetoothActivityEnergyInfo info) { |
Adam Lesinski | a7c90c8 | 2015-06-18 14:52:24 -0700 | [diff] [blame] | 9223 | if (DEBUG_ENERGY) { |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 9224 | Slog.d(TAG, "Updating bluetooth stats: " + info); |
Adam Lesinski | a7c90c8 | 2015-06-18 14:52:24 -0700 | [diff] [blame] | 9225 | } |
| 9226 | |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 9227 | if (info == null || !mOnBatteryInternal) { |
| 9228 | return; |
| 9229 | } |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 9230 | |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 9231 | mHasBluetoothReporting = true; |
| 9232 | |
| 9233 | final long elapsedRealtimeMs = SystemClock.elapsedRealtime(); |
| 9234 | final long rxTimeMs = info.getControllerRxTimeMillis(); |
| 9235 | final long txTimeMs = info.getControllerTxTimeMillis(); |
| 9236 | |
| 9237 | if (DEBUG_ENERGY) { |
| 9238 | Slog.d(TAG, "------ BEGIN BLE power blaming ------"); |
| 9239 | Slog.d(TAG, " Tx Time: " + txTimeMs + " ms"); |
| 9240 | Slog.d(TAG, " Rx Time: " + rxTimeMs + " ms"); |
| 9241 | Slog.d(TAG, " Idle Time: " + info.getControllerIdleTimeMillis() + " ms"); |
| 9242 | } |
| 9243 | |
| 9244 | long totalScanTimeMs = 0; |
| 9245 | |
| 9246 | final int uidCount = mUidStats.size(); |
| 9247 | for (int i = 0; i < uidCount; i++) { |
| 9248 | final Uid u = mUidStats.valueAt(i); |
| 9249 | if (u.mBluetoothScanTimer == null) { |
| 9250 | continue; |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 9251 | } |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 9252 | |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 9253 | totalScanTimeMs += u.mBluetoothScanTimer.getTimeSinceMarkLocked( |
| 9254 | elapsedRealtimeMs * 1000) / 1000; |
| 9255 | } |
| 9256 | |
| 9257 | final boolean normalizeScanRxTime = (totalScanTimeMs > rxTimeMs); |
| 9258 | final boolean normalizeScanTxTime = (totalScanTimeMs > txTimeMs); |
| 9259 | |
| 9260 | if (DEBUG_ENERGY) { |
| 9261 | Slog.d(TAG, "Normalizing scan power for RX=" + normalizeScanRxTime |
| 9262 | + " TX=" + normalizeScanTxTime); |
| 9263 | } |
| 9264 | |
| 9265 | long leftOverRxTimeMs = rxTimeMs; |
| 9266 | long leftOverTxTimeMs = txTimeMs; |
| 9267 | |
| 9268 | for (int i = 0; i < uidCount; i++) { |
| 9269 | final Uid u = mUidStats.valueAt(i); |
| 9270 | if (u.mBluetoothScanTimer == null) { |
| 9271 | continue; |
| 9272 | } |
| 9273 | |
| 9274 | long scanTimeSinceMarkMs = u.mBluetoothScanTimer.getTimeSinceMarkLocked( |
| 9275 | elapsedRealtimeMs * 1000) / 1000; |
| 9276 | if (scanTimeSinceMarkMs > 0) { |
| 9277 | // Set the new mark so that next time we get new data since this point. |
| 9278 | u.mBluetoothScanTimer.setMark(elapsedRealtimeMs); |
| 9279 | |
| 9280 | long scanTimeRxSinceMarkMs = scanTimeSinceMarkMs; |
| 9281 | long scanTimeTxSinceMarkMs = scanTimeSinceMarkMs; |
| 9282 | |
| 9283 | if (normalizeScanRxTime) { |
| 9284 | // Scan time is longer than the total rx time in the controller, |
| 9285 | // so distribute the scan time proportionately. This means regular traffic |
| 9286 | // will not blamed, but scans are more expensive anyways. |
| 9287 | scanTimeRxSinceMarkMs = (rxTimeMs * scanTimeRxSinceMarkMs) / totalScanTimeMs; |
| 9288 | } |
| 9289 | |
| 9290 | if (normalizeScanTxTime) { |
| 9291 | // Scan time is longer than the total tx time in the controller, |
| 9292 | // so distribute the scan time proportionately. This means regular traffic |
| 9293 | // will not blamed, but scans are more expensive anyways. |
| 9294 | scanTimeTxSinceMarkMs = (txTimeMs * scanTimeTxSinceMarkMs) / totalScanTimeMs; |
| 9295 | } |
| 9296 | |
| 9297 | final ControllerActivityCounterImpl counter = |
| 9298 | u.getOrCreateBluetoothControllerActivityLocked(); |
| 9299 | counter.getRxTimeCounter().addCountLocked(scanTimeRxSinceMarkMs); |
| 9300 | counter.getTxTimeCounters()[0].addCountLocked(scanTimeTxSinceMarkMs); |
| 9301 | |
| 9302 | leftOverRxTimeMs -= scanTimeRxSinceMarkMs; |
| 9303 | leftOverTxTimeMs -= scanTimeTxSinceMarkMs; |
| 9304 | } |
| 9305 | } |
| 9306 | |
| 9307 | if (DEBUG_ENERGY) { |
| 9308 | Slog.d(TAG, "Left over time for traffic RX=" + leftOverRxTimeMs |
| 9309 | + " TX=" + leftOverTxTimeMs); |
| 9310 | } |
| 9311 | |
| 9312 | // |
| 9313 | // Now distribute blame to apps that did bluetooth traffic. |
| 9314 | // |
| 9315 | |
| 9316 | long totalTxBytes = 0; |
| 9317 | long totalRxBytes = 0; |
| 9318 | |
| 9319 | final UidTraffic[] uidTraffic = info.getUidTraffic(); |
| 9320 | final int numUids = uidTraffic != null ? uidTraffic.length : 0; |
| 9321 | for (int i = 0; i < numUids; i++) { |
| 9322 | final UidTraffic traffic = uidTraffic[i]; |
| 9323 | |
| 9324 | // Add to the global counters. |
| 9325 | mNetworkByteActivityCounters[NETWORK_BT_RX_DATA].addCountLocked( |
| 9326 | traffic.getRxBytes()); |
| 9327 | mNetworkByteActivityCounters[NETWORK_BT_TX_DATA].addCountLocked( |
| 9328 | traffic.getTxBytes()); |
| 9329 | |
| 9330 | // Add to the UID counters. |
| 9331 | final Uid u = getUidStatsLocked(mapUid(traffic.getUid())); |
| 9332 | u.noteNetworkActivityLocked(NETWORK_BT_RX_DATA, traffic.getRxBytes(), 0); |
| 9333 | u.noteNetworkActivityLocked(NETWORK_BT_TX_DATA, traffic.getTxBytes(), 0); |
| 9334 | |
| 9335 | // Calculate the total traffic. |
| 9336 | totalTxBytes += traffic.getTxBytes(); |
| 9337 | totalRxBytes += traffic.getRxBytes(); |
| 9338 | } |
| 9339 | |
| 9340 | if ((totalTxBytes != 0 || totalRxBytes != 0) && |
| 9341 | (leftOverRxTimeMs != 0 || leftOverTxTimeMs != 0)) { |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 9342 | for (int i = 0; i < numUids; i++) { |
| 9343 | final UidTraffic traffic = uidTraffic[i]; |
| 9344 | |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 9345 | final Uid u = getUidStatsLocked(mapUid(traffic.getUid())); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 9346 | final ControllerActivityCounterImpl counter = |
| 9347 | u.getOrCreateBluetoothControllerActivityLocked(); |
| 9348 | |
| 9349 | if (totalRxBytes > 0 && traffic.getRxBytes() > 0) { |
| 9350 | final long timeRxMs = (leftOverRxTimeMs * traffic.getRxBytes()) / totalRxBytes; |
| 9351 | |
| 9352 | if (DEBUG_ENERGY) { |
| 9353 | Slog.d(TAG, "UID=" + traffic.getUid() + " rx_bytes=" + traffic.getRxBytes() |
| 9354 | + " rx_time=" + timeRxMs); |
| 9355 | } |
| 9356 | counter.getRxTimeCounter().addCountLocked(timeRxMs); |
| 9357 | leftOverRxTimeMs -= timeRxMs; |
| 9358 | } |
| 9359 | |
| 9360 | if (totalTxBytes > 0 && traffic.getTxBytes() > 0) { |
| 9361 | final long timeTxMs = (leftOverTxTimeMs * traffic.getTxBytes()) / totalTxBytes; |
| 9362 | |
| 9363 | if (DEBUG_ENERGY) { |
| 9364 | Slog.d(TAG, "UID=" + traffic.getUid() + " tx_bytes=" + traffic.getTxBytes() |
| 9365 | + " tx_time=" + timeTxMs); |
| 9366 | } |
| 9367 | |
| 9368 | counter.getTxTimeCounters()[0].addCountLocked(timeTxMs); |
| 9369 | leftOverTxTimeMs -= timeTxMs; |
| 9370 | } |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 9371 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 9372 | } |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 9373 | |
| 9374 | mBluetoothActivity.getRxTimeCounter().addCountLocked( |
| 9375 | info.getControllerRxTimeMillis()); |
| 9376 | mBluetoothActivity.getTxTimeCounters()[0].addCountLocked( |
| 9377 | info.getControllerTxTimeMillis()); |
| 9378 | mBluetoothActivity.getIdleTimeCounter().addCountLocked( |
| 9379 | info.getControllerIdleTimeMillis()); |
| 9380 | |
| 9381 | // POWER_BLUETOOTH_CONTROLLER_OPERATING_VOLTAGE is measured in mV, so convert to V. |
| 9382 | final double opVolt = mPowerProfile.getAveragePower( |
| 9383 | PowerProfile.POWER_BLUETOOTH_CONTROLLER_OPERATING_VOLTAGE) / 1000.0; |
| 9384 | if (opVolt != 0) { |
| 9385 | // We store the power drain as mAms. |
| 9386 | mBluetoothActivity.getPowerCounter().addCountLocked( |
| 9387 | (long) (info.getControllerEnergyUsed() / opVolt)); |
| 9388 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 9389 | } |
| 9390 | |
| 9391 | /** |
| 9392 | * Read and distribute kernel wake lock use across apps. |
| 9393 | */ |
| 9394 | public void updateKernelWakelocksLocked() { |
| 9395 | final KernelWakelockStats wakelockStats = mKernelWakelockReader.readKernelWakelockStats( |
| 9396 | mTmpWakelockStats); |
| 9397 | if (wakelockStats == null) { |
| 9398 | // Not crashing might make board bringup easier. |
| 9399 | Slog.w(TAG, "Couldn't get kernel wake lock stats"); |
| 9400 | return; |
| 9401 | } |
| 9402 | |
| 9403 | for (Map.Entry<String, KernelWakelockStats.Entry> ent : wakelockStats.entrySet()) { |
| 9404 | String name = ent.getKey(); |
| 9405 | KernelWakelockStats.Entry kws = ent.getValue(); |
| 9406 | |
| 9407 | SamplingTimer kwlt = mKernelWakelockStats.get(name); |
| 9408 | if (kwlt == null) { |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 9409 | kwlt = new SamplingTimer(mClocks, mOnBatteryScreenOffTimeBase); |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 9410 | mKernelWakelockStats.put(name, kwlt); |
| 9411 | } |
Adam Lesinski | d84ad30 | 2016-05-17 18:31:02 -0700 | [diff] [blame] | 9412 | |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 9413 | kwlt.update(kws.mTotalTime, kws.mCount); |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 9414 | kwlt.setUpdateVersion(kws.mVersion); |
| 9415 | } |
| 9416 | |
Adam Lesinski | fbabe7d | 2015-08-03 14:37:38 -0700 | [diff] [blame] | 9417 | int numWakelocksSetStale = 0; |
Adam Lesinski | d84ad30 | 2016-05-17 18:31:02 -0700 | [diff] [blame] | 9418 | // Set timers to stale if they didn't appear in /d/wakeup_sources (or /proc/wakelocks) |
| 9419 | // this time. |
| 9420 | for (Map.Entry<String, SamplingTimer> ent : mKernelWakelockStats.entrySet()) { |
| 9421 | SamplingTimer st = ent.getValue(); |
| 9422 | if (st.getUpdateVersion() != wakelockStats.kernelWakelockVersion) { |
| 9423 | st.endSample(); |
| 9424 | numWakelocksSetStale++; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 9425 | } |
| 9426 | } |
Adam Lesinski | fbabe7d | 2015-08-03 14:37:38 -0700 | [diff] [blame] | 9427 | |
Adam Lesinski | d84ad30 | 2016-05-17 18:31:02 -0700 | [diff] [blame] | 9428 | // Record whether we've seen a non-zero time (for debugging b/22716723). |
| 9429 | if (wakelockStats.isEmpty()) { |
Adam Lesinski | fbabe7d | 2015-08-03 14:37:38 -0700 | [diff] [blame] | 9430 | Slog.wtf(TAG, "All kernel wakelocks had time of zero"); |
| 9431 | } |
| 9432 | |
| 9433 | if (numWakelocksSetStale == mKernelWakelockStats.size()) { |
| 9434 | Slog.wtf(TAG, "All kernel wakelocks were set stale. new version=" + |
| 9435 | wakelockStats.kernelWakelockVersion); |
| 9436 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 9437 | } |
| 9438 | |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 9439 | // We use an anonymous class to access these variables, |
| 9440 | // so they can't live on the stack or they'd have to be |
| 9441 | // final MutableLong objects (more allocations). |
| 9442 | // Used in updateCpuTimeLocked(). |
| 9443 | long mTempTotalCpuUserTimeUs; |
| 9444 | long mTempTotalCpuSystemTimeUs; |
| 9445 | |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 9446 | /** |
James Carr | 3a22605 | 2016-07-01 14:49:52 -0700 | [diff] [blame] | 9447 | * Reads the newest memory stats from the kernel. |
| 9448 | */ |
| 9449 | public void updateKernelMemoryBandwidthLocked() { |
| 9450 | mKernelMemoryBandwidthStats.updateStats(); |
| 9451 | LongSparseLongArray bandwidthEntries = mKernelMemoryBandwidthStats.getBandwidthEntries(); |
| 9452 | final int bandwidthEntryCount = bandwidthEntries.size(); |
| 9453 | int index; |
| 9454 | for (int i = 0; i < bandwidthEntryCount; i++) { |
| 9455 | SamplingTimer timer; |
| 9456 | if ((index = mKernelMemoryStats.indexOfKey(bandwidthEntries.keyAt(i))) >= 0) { |
| 9457 | timer = mKernelMemoryStats.valueAt(index); |
| 9458 | } else { |
| 9459 | timer = new SamplingTimer(mClocks, mOnBatteryTimeBase); |
| 9460 | mKernelMemoryStats.put(bandwidthEntries.keyAt(i), timer); |
| 9461 | } |
| 9462 | timer.update(bandwidthEntries.valueAt(i), 1); |
| 9463 | if (DEBUG_MEMORY) { |
| 9464 | Slog.d(TAG, String.format("Added entry %d and updated timer to: " |
| 9465 | + "mUnpluggedReportedTotalTime %d size %d", bandwidthEntries.keyAt(i), |
| 9466 | mKernelMemoryStats.get( |
| 9467 | bandwidthEntries.keyAt(i)).mUnpluggedReportedTotalTime, |
| 9468 | mKernelMemoryStats.size())); |
| 9469 | } |
| 9470 | } |
| 9471 | } |
| 9472 | |
| 9473 | /** |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 9474 | * Read and distribute CPU usage across apps. If their are partial wakelocks being held |
| 9475 | * and we are on battery with screen off, we give more of the cpu time to those apps holding |
| 9476 | * 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] | 9477 | */ |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 9478 | public void updateCpuTimeLocked() { |
Adam Lesinski | 52290c9c | 2015-09-21 16:54:52 -0700 | [diff] [blame] | 9479 | if (mPowerProfile == null) { |
| 9480 | return; |
| 9481 | } |
| 9482 | |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 9483 | if (DEBUG_ENERGY_CPU) { |
| 9484 | Slog.d(TAG, "!Cpu updating!"); |
| 9485 | } |
| 9486 | |
| 9487 | // Holding a wakelock costs more than just using the cpu. |
| 9488 | // Currently, we assign only half the cpu time to an app that is running but |
| 9489 | // not holding a wakelock. The apps holding wakelocks get the rest of the blame. |
| 9490 | // If no app is holding a wakelock, then the distribution is normal. |
| 9491 | final int wakelockWeight = 50; |
| 9492 | |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 9493 | // Read the time spent for each cluster at various cpu frequencies. |
| 9494 | final long[][] clusterSpeeds = new long[mKernelCpuSpeedReaders.length][]; |
| 9495 | for (int cluster = 0; cluster < mKernelCpuSpeedReaders.length; cluster++) { |
| 9496 | clusterSpeeds[cluster] = mKernelCpuSpeedReaders[cluster].readDelta(); |
| 9497 | } |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 9498 | |
| 9499 | int numWakelocks = 0; |
| 9500 | |
| 9501 | // Calculate how many wakelocks we have to distribute amongst. The system is excluded. |
| 9502 | // Only distribute cpu power to wakelocks if the screen is off and we're on battery. |
| 9503 | final int numPartialTimers = mPartialTimers.size(); |
| 9504 | if (mOnBatteryScreenOffTimeBase.isRunning()) { |
| 9505 | for (int i = 0; i < numPartialTimers; i++) { |
| 9506 | final StopwatchTimer timer = mPartialTimers.get(i); |
| 9507 | if (timer.mInList && timer.mUid != null && timer.mUid.mUid != Process.SYSTEM_UID) { |
| 9508 | // Since the collection and blaming of wakelocks can be scheduled to run after |
| 9509 | // some delay, the mPartialTimers list may have new entries. We can't blame |
| 9510 | // the newly added timer for past cpu time, so we only consider timers that |
| 9511 | // were present for one round of collection. Once a timer has gone through |
| 9512 | // a round of collection, its mInList field is set to true. |
| 9513 | numWakelocks++; |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 9514 | } |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 9515 | } |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 9516 | } |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 9517 | |
| 9518 | final int numWakelocksF = numWakelocks; |
| 9519 | mTempTotalCpuUserTimeUs = 0; |
| 9520 | mTempTotalCpuSystemTimeUs = 0; |
| 9521 | |
| 9522 | // Read the CPU data for each UID. This will internally generate a snapshot so next time |
| 9523 | // we read, we get a delta. If we are to distribute the cpu time, then do so. Otherwise |
| 9524 | // we just ignore the data. |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9525 | final long startTimeMs = mClocks.elapsedRealtime(); |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 9526 | mKernelUidCpuTimeReader.readDelta(!mOnBatteryInternal ? null : |
| 9527 | new KernelUidCpuTimeReader.Callback() { |
| 9528 | @Override |
Adam Lesinski | a7a4ccc | 2015-06-26 17:43:04 -0700 | [diff] [blame] | 9529 | public void onUidCpuTime(int uid, long userTimeUs, long systemTimeUs, |
| 9530 | long powerMaUs) { |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 9531 | final Uid u = getUidStatsLocked(mapUid(uid)); |
| 9532 | |
| 9533 | // Accumulate the total system and user time. |
| 9534 | mTempTotalCpuUserTimeUs += userTimeUs; |
| 9535 | mTempTotalCpuSystemTimeUs += systemTimeUs; |
| 9536 | |
| 9537 | StringBuilder sb = null; |
| 9538 | if (DEBUG_ENERGY_CPU) { |
| 9539 | sb = new StringBuilder(); |
| 9540 | sb.append(" got time for uid=").append(u.mUid).append(": u="); |
| 9541 | TimeUtils.formatDuration(userTimeUs / 1000, sb); |
| 9542 | sb.append(" s="); |
| 9543 | TimeUtils.formatDuration(systemTimeUs / 1000, sb); |
Adam Lesinski | a7a4ccc | 2015-06-26 17:43:04 -0700 | [diff] [blame] | 9544 | sb.append(" p=").append(powerMaUs / 1000).append("mAms\n"); |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 9545 | } |
| 9546 | |
| 9547 | if (numWakelocksF > 0) { |
| 9548 | // We have wakelocks being held, so only give a portion of the |
| 9549 | // time to the process. The rest will be distributed among wakelock |
| 9550 | // holders. |
| 9551 | userTimeUs = (userTimeUs * wakelockWeight) / 100; |
| 9552 | systemTimeUs = (systemTimeUs * wakelockWeight) / 100; |
| 9553 | } |
| 9554 | |
| 9555 | if (sb != null) { |
| 9556 | sb.append(" adding to uid=").append(u.mUid).append(": u="); |
| 9557 | TimeUtils.formatDuration(userTimeUs / 1000, sb); |
| 9558 | sb.append(" s="); |
| 9559 | TimeUtils.formatDuration(systemTimeUs / 1000, sb); |
Adam Lesinski | a7a4ccc | 2015-06-26 17:43:04 -0700 | [diff] [blame] | 9560 | sb.append(" p=").append(powerMaUs / 1000).append("mAms"); |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 9561 | Slog.d(TAG, sb.toString()); |
| 9562 | } |
| 9563 | |
| 9564 | u.mUserCpuTime.addCountLocked(userTimeUs); |
| 9565 | u.mSystemCpuTime.addCountLocked(systemTimeUs); |
Adam Lesinski | a7a4ccc | 2015-06-26 17:43:04 -0700 | [diff] [blame] | 9566 | u.mCpuPower.addCountLocked(powerMaUs); |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 9567 | |
| 9568 | // Add the cpu speeds to this UID. These are used as a ratio |
| 9569 | // for computing the power this UID used. |
Adam Lesinski | 52290c9c | 2015-09-21 16:54:52 -0700 | [diff] [blame] | 9570 | final int numClusters = mPowerProfile.getNumCpuClusters(); |
| 9571 | if (u.mCpuClusterSpeed == null || u.mCpuClusterSpeed.length != |
| 9572 | numClusters) { |
| 9573 | u.mCpuClusterSpeed = new LongSamplingCounter[numClusters][]; |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 9574 | } |
| 9575 | |
| 9576 | for (int cluster = 0; cluster < clusterSpeeds.length; cluster++) { |
Adam Lesinski | 52290c9c | 2015-09-21 16:54:52 -0700 | [diff] [blame] | 9577 | final int speedsInCluster = mPowerProfile.getNumSpeedStepsInCpuCluster( |
| 9578 | cluster); |
| 9579 | if (u.mCpuClusterSpeed[cluster] == null || speedsInCluster != |
| 9580 | u.mCpuClusterSpeed[cluster].length) { |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 9581 | u.mCpuClusterSpeed[cluster] = |
Adam Lesinski | 52290c9c | 2015-09-21 16:54:52 -0700 | [diff] [blame] | 9582 | new LongSamplingCounter[speedsInCluster]; |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 9583 | } |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 9584 | |
| 9585 | final LongSamplingCounter[] cpuSpeeds = u.mCpuClusterSpeed[cluster]; |
| 9586 | for (int speed = 0; speed < clusterSpeeds[cluster].length; speed++) { |
| 9587 | if (cpuSpeeds[speed] == null) { |
| 9588 | cpuSpeeds[speed] = new LongSamplingCounter(mOnBatteryTimeBase); |
| 9589 | } |
| 9590 | cpuSpeeds[speed].addCountLocked(clusterSpeeds[cluster][speed]); |
| 9591 | } |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 9592 | } |
| 9593 | } |
| 9594 | }); |
| 9595 | |
Amith Yamasani | d245086 | 2017-02-07 15:58:24 -0800 | [diff] [blame] | 9596 | // TODO: STOPSHIP, remove the "true" below after b/34961340 is fixed |
| 9597 | if (DEBUG_ENERGY_CPU || true) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9598 | Slog.d(TAG, "Reading cpu stats took " + (mClocks.elapsedRealtime() - startTimeMs) + |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 9599 | " ms"); |
| 9600 | } |
| 9601 | |
| 9602 | if (mOnBatteryInternal && numWakelocks > 0) { |
| 9603 | // Distribute a portion of the total cpu time to wakelock holders. |
| 9604 | mTempTotalCpuUserTimeUs = (mTempTotalCpuUserTimeUs * (100 - wakelockWeight)) / 100; |
| 9605 | mTempTotalCpuSystemTimeUs = |
| 9606 | (mTempTotalCpuSystemTimeUs * (100 - wakelockWeight)) / 100; |
| 9607 | |
| 9608 | for (int i = 0; i < numPartialTimers; i++) { |
| 9609 | final StopwatchTimer timer = mPartialTimers.get(i); |
| 9610 | |
| 9611 | // The system does not share any blame, as it is usually holding the wakelock |
| 9612 | // on behalf of an app. |
| 9613 | if (timer.mInList && timer.mUid != null && timer.mUid.mUid != Process.SYSTEM_UID) { |
| 9614 | int userTimeUs = (int) (mTempTotalCpuUserTimeUs / numWakelocks); |
| 9615 | int systemTimeUs = (int) (mTempTotalCpuSystemTimeUs / numWakelocks); |
| 9616 | |
| 9617 | if (DEBUG_ENERGY_CPU) { |
| 9618 | StringBuilder sb = new StringBuilder(); |
| 9619 | sb.append(" Distributing wakelock uid=").append(timer.mUid.mUid) |
| 9620 | .append(": u="); |
| 9621 | TimeUtils.formatDuration(userTimeUs / 1000, sb); |
| 9622 | sb.append(" s="); |
| 9623 | TimeUtils.formatDuration(systemTimeUs / 1000, sb); |
| 9624 | Slog.d(TAG, sb.toString()); |
| 9625 | } |
| 9626 | |
| 9627 | timer.mUid.mUserCpuTime.addCountLocked(userTimeUs); |
| 9628 | timer.mUid.mSystemCpuTime.addCountLocked(systemTimeUs); |
| 9629 | |
| 9630 | final Uid.Proc proc = timer.mUid.getProcessStatsLocked("*wakelock*"); |
Adam Lesinski | 062e66c | 2015-07-14 12:02:44 -0700 | [diff] [blame] | 9631 | proc.addCpuTimeLocked(userTimeUs / 1000, systemTimeUs / 1000); |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 9632 | |
| 9633 | mTempTotalCpuUserTimeUs -= userTimeUs; |
| 9634 | mTempTotalCpuSystemTimeUs -= systemTimeUs; |
| 9635 | numWakelocks--; |
| 9636 | } |
| 9637 | } |
| 9638 | |
| 9639 | if (mTempTotalCpuUserTimeUs > 0 || mTempTotalCpuSystemTimeUs > 0) { |
| 9640 | // Anything left over is given to the system. |
| 9641 | if (DEBUG_ENERGY_CPU) { |
| 9642 | StringBuilder sb = new StringBuilder(); |
| 9643 | sb.append(" Distributing lost time to system: u="); |
| 9644 | TimeUtils.formatDuration(mTempTotalCpuUserTimeUs / 1000, sb); |
| 9645 | sb.append(" s="); |
| 9646 | TimeUtils.formatDuration(mTempTotalCpuSystemTimeUs / 1000, sb); |
| 9647 | Slog.d(TAG, sb.toString()); |
| 9648 | } |
| 9649 | |
| 9650 | final Uid u = getUidStatsLocked(Process.SYSTEM_UID); |
| 9651 | u.mUserCpuTime.addCountLocked(mTempTotalCpuUserTimeUs); |
| 9652 | u.mSystemCpuTime.addCountLocked(mTempTotalCpuSystemTimeUs); |
| 9653 | |
| 9654 | final Uid.Proc proc = u.getProcessStatsLocked("*lost*"); |
Adam Lesinski | 062e66c | 2015-07-14 12:02:44 -0700 | [diff] [blame] | 9655 | proc.addCpuTimeLocked((int) mTempTotalCpuUserTimeUs / 1000, |
| 9656 | (int) mTempTotalCpuSystemTimeUs / 1000); |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 9657 | } |
| 9658 | } |
| 9659 | |
| 9660 | // See if there is a difference in wakelocks between this collection and the last |
| 9661 | // collection. |
| 9662 | if (ArrayUtils.referenceEquals(mPartialTimers, mLastPartialTimers)) { |
| 9663 | // No difference, so each timer is now considered for the next collection. |
| 9664 | for (int i = 0; i < numPartialTimers; i++) { |
| 9665 | mPartialTimers.get(i).mInList = true; |
| 9666 | } |
| 9667 | } else { |
| 9668 | // The lists are different, meaning we added (or removed a timer) since the last |
| 9669 | // collection. |
| 9670 | final int numLastPartialTimers = mLastPartialTimers.size(); |
| 9671 | for (int i = 0; i < numLastPartialTimers; i++) { |
| 9672 | mLastPartialTimers.get(i).mInList = false; |
| 9673 | } |
| 9674 | mLastPartialTimers.clear(); |
| 9675 | |
| 9676 | // Mark the current timers as gone through a collection. |
| 9677 | for (int i = 0; i < numPartialTimers; i++) { |
| 9678 | final StopwatchTimer timer = mPartialTimers.get(i); |
| 9679 | timer.mInList = true; |
| 9680 | mLastPartialTimers.add(timer); |
| 9681 | } |
| 9682 | } |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 9683 | } |
| 9684 | |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 9685 | boolean setChargingLocked(boolean charging) { |
| 9686 | if (mCharging != charging) { |
| 9687 | mCharging = charging; |
| 9688 | if (charging) { |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 9689 | mHistoryCur.states2 |= HistoryItem.STATE2_CHARGING_FLAG; |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 9690 | } else { |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 9691 | mHistoryCur.states2 &= ~HistoryItem.STATE2_CHARGING_FLAG; |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 9692 | } |
| 9693 | mHandler.sendEmptyMessage(MSG_REPORT_CHARGING); |
| 9694 | return true; |
| 9695 | } |
| 9696 | return false; |
| 9697 | } |
| 9698 | |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 9699 | void setOnBatteryLocked(final long mSecRealtime, final long mSecUptime, final boolean onBattery, |
Adam Lesinski | f9b20a9 | 2016-06-17 17:30:01 -0700 | [diff] [blame] | 9700 | final int oldStatus, final int level, final int chargeUAh) { |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 9701 | boolean doWrite = false; |
| 9702 | Message m = mHandler.obtainMessage(MSG_REPORT_POWER_CHANGE); |
| 9703 | m.arg1 = onBattery ? 1 : 0; |
| 9704 | mHandler.sendMessage(m); |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 9705 | |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 9706 | final long uptime = mSecUptime * 1000; |
| 9707 | final long realtime = mSecRealtime * 1000; |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 9708 | final boolean screenOn = mScreenState == Display.STATE_ON; |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 9709 | if (onBattery) { |
| 9710 | // We will reset our status if we are unplugging after the |
| 9711 | // battery was last full, or the level is at 100, or |
| 9712 | // we have gone through a significant charge (from a very low |
| 9713 | // level to a now very high level). |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 9714 | boolean reset = false; |
Dianne Hackborn | 9a75543 | 2014-05-15 17:05:22 -0700 | [diff] [blame] | 9715 | if (!mNoAutoReset && (oldStatus == BatteryManager.BATTERY_STATUS_FULL |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 9716 | || level >= 90 |
Dianne Hackborn | fb3809c | 2014-09-29 18:31:22 -0700 | [diff] [blame] | 9717 | || (mDischargeCurrentLevel < 20 && level >= 80) |
| 9718 | || (getHighDischargeAmountSinceCharge() >= 200 |
| 9719 | && mHistoryBuffer.dataSize() >= MAX_HISTORY_BUFFER))) { |
Dianne Hackborn | 73d6a82 | 2014-09-29 10:52:47 -0700 | [diff] [blame] | 9720 | Slog.i(TAG, "Resetting battery stats: level=" + level + " status=" + oldStatus |
Dianne Hackborn | fb3809c | 2014-09-29 18:31:22 -0700 | [diff] [blame] | 9721 | + " dischargeLevel=" + mDischargeCurrentLevel |
Dianne Hackborn | 73d6a82 | 2014-09-29 10:52:47 -0700 | [diff] [blame] | 9722 | + " lowAmount=" + getLowDischargeAmountSinceCharge() |
| 9723 | + " highAmount=" + getHighDischargeAmountSinceCharge()); |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 9724 | // Before we write, collect a snapshot of the final aggregated |
| 9725 | // stats to be reported in the next checkin. Only do this if we have |
| 9726 | // a sufficient amount of data to make it interesting. |
| 9727 | if (getLowDischargeAmountSinceCharge() >= 20) { |
| 9728 | final Parcel parcel = Parcel.obtain(); |
| 9729 | writeSummaryToParcel(parcel, true); |
| 9730 | BackgroundThread.getHandler().post(new Runnable() { |
| 9731 | @Override public void run() { |
| 9732 | synchronized (mCheckinFile) { |
| 9733 | FileOutputStream stream = null; |
| 9734 | try { |
| 9735 | stream = mCheckinFile.startWrite(); |
| 9736 | stream.write(parcel.marshall()); |
| 9737 | stream.flush(); |
| 9738 | FileUtils.sync(stream); |
| 9739 | stream.close(); |
| 9740 | mCheckinFile.finishWrite(stream); |
| 9741 | } catch (IOException e) { |
| 9742 | Slog.w("BatteryStats", |
| 9743 | "Error writing checkin battery statistics", e); |
| 9744 | mCheckinFile.failWrite(stream); |
| 9745 | } finally { |
| 9746 | parcel.recycle(); |
| 9747 | } |
| 9748 | } |
| 9749 | } |
| 9750 | }); |
| 9751 | } |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 9752 | doWrite = true; |
| 9753 | resetAllStatsLocked(); |
Ying Wai (Daniel) Fan | 442ab76 | 2017-01-31 22:00:10 -0800 | [diff] [blame] | 9754 | if (chargeUAh > 0 && level > 0) { |
Adam Lesinski | f9b20a9 | 2016-06-17 17:30:01 -0700 | [diff] [blame] | 9755 | // Only use the reported coulomb charge value if it is supported and reported. |
Ying Wai (Daniel) Fan | 9238b61 | 2017-01-18 15:50:19 -0800 | [diff] [blame] | 9756 | mEstimatedBatteryCapacity = (int) ((chargeUAh / 1000) / (level / 100.0)); |
Adam Lesinski | f9b20a9 | 2016-06-17 17:30:01 -0700 | [diff] [blame] | 9757 | } |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 9758 | mDischargeStartLevel = level; |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 9759 | reset = true; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 9760 | mDischargeStepTracker.init(); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9761 | } |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 9762 | if (mCharging) { |
| 9763 | setChargingLocked(false); |
| 9764 | } |
| 9765 | mLastChargingStateLevel = level; |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 9766 | mOnBattery = mOnBatteryInternal = true; |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 9767 | mLastDischargeStepLevel = level; |
Dianne Hackborn | 2932513 | 2014-05-21 15:01:03 -0700 | [diff] [blame] | 9768 | mMinDischargeStepLevel = level; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 9769 | mDischargeStepTracker.clearTime(); |
| 9770 | mDailyDischargeStepTracker.clearTime(); |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 9771 | mInitStepMode = mCurStepMode; |
| 9772 | mModStepMode = 0; |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 9773 | pullPendingStateUpdatesLocked(); |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 9774 | mHistoryCur.batteryLevel = (byte)level; |
| 9775 | mHistoryCur.states &= ~HistoryItem.STATE_BATTERY_PLUGGED_FLAG; |
| 9776 | if (DEBUG_HISTORY) Slog.v(TAG, "Battery unplugged to: " |
| 9777 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 9778 | if (reset) { |
| 9779 | mRecordingHistory = true; |
| 9780 | startRecordingHistory(mSecRealtime, mSecUptime, reset); |
| 9781 | } |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 9782 | addHistoryRecordLocked(mSecRealtime, mSecUptime); |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 9783 | mDischargeCurrentLevel = mDischargeUnplugLevel = level; |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 9784 | if (screenOn) { |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 9785 | mDischargeScreenOnUnplugLevel = level; |
| 9786 | mDischargeScreenOffUnplugLevel = 0; |
| 9787 | } else { |
| 9788 | mDischargeScreenOnUnplugLevel = 0; |
| 9789 | mDischargeScreenOffUnplugLevel = level; |
| 9790 | } |
| 9791 | mDischargeAmountScreenOn = 0; |
| 9792 | mDischargeAmountScreenOff = 0; |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 9793 | updateTimeBasesLocked(true, !screenOn, uptime, realtime); |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 9794 | } else { |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 9795 | mLastChargingStateLevel = level; |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 9796 | mOnBattery = mOnBatteryInternal = false; |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 9797 | pullPendingStateUpdatesLocked(); |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 9798 | mHistoryCur.batteryLevel = (byte)level; |
| 9799 | mHistoryCur.states |= HistoryItem.STATE_BATTERY_PLUGGED_FLAG; |
| 9800 | if (DEBUG_HISTORY) Slog.v(TAG, "Battery plugged to: " |
| 9801 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 9802 | addHistoryRecordLocked(mSecRealtime, mSecUptime); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 9803 | mDischargeCurrentLevel = mDischargePlugLevel = level; |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 9804 | if (level < mDischargeUnplugLevel) { |
| 9805 | mLowDischargeAmountSinceCharge += mDischargeUnplugLevel-level-1; |
| 9806 | mHighDischargeAmountSinceCharge += mDischargeUnplugLevel-level; |
| 9807 | } |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 9808 | updateDischargeScreenLevelsLocked(screenOn, screenOn); |
| 9809 | updateTimeBasesLocked(false, !screenOn, uptime, realtime); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 9810 | mChargeStepTracker.init(); |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 9811 | mLastChargeStepLevel = level; |
Dianne Hackborn | 2932513 | 2014-05-21 15:01:03 -0700 | [diff] [blame] | 9812 | mMaxChargeStepLevel = level; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 9813 | mInitStepMode = mCurStepMode; |
| 9814 | mModStepMode = 0; |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 9815 | } |
| 9816 | if (doWrite || (mLastWriteTime + (60 * 1000)) < mSecRealtime) { |
| 9817 | if (mFile != null) { |
| 9818 | writeAsyncLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9819 | } |
| 9820 | } |
| 9821 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 9822 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 9823 | private void startRecordingHistory(final long elapsedRealtimeMs, final long uptimeMs, |
| 9824 | boolean reset) { |
| 9825 | mRecordingHistory = true; |
| 9826 | mHistoryCur.currentTime = System.currentTimeMillis(); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 9827 | addHistoryBufferLocked(elapsedRealtimeMs, uptimeMs, |
| 9828 | reset ? HistoryItem.CMD_RESET : HistoryItem.CMD_CURRENT_TIME, |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 9829 | mHistoryCur); |
| 9830 | mHistoryCur.currentTime = 0; |
| 9831 | if (reset) { |
| 9832 | initActiveHistoryEventsLocked(elapsedRealtimeMs, uptimeMs); |
| 9833 | } |
| 9834 | } |
| 9835 | |
Dianne Hackborn | 7d9eefd | 2014-08-27 18:30:31 -0700 | [diff] [blame] | 9836 | private void recordCurrentTimeChangeLocked(final long currentTime, final long elapsedRealtimeMs, |
| 9837 | final long uptimeMs) { |
| 9838 | if (mRecordingHistory) { |
| 9839 | mHistoryCur.currentTime = currentTime; |
| 9840 | addHistoryBufferLocked(elapsedRealtimeMs, uptimeMs, HistoryItem.CMD_CURRENT_TIME, |
| 9841 | mHistoryCur); |
| 9842 | mHistoryCur.currentTime = 0; |
| 9843 | } |
| 9844 | } |
| 9845 | |
Dianne Hackborn | 29cd7f1 | 2015-01-08 10:37:05 -0800 | [diff] [blame] | 9846 | private void recordShutdownLocked(final long elapsedRealtimeMs, final long uptimeMs) { |
| 9847 | if (mRecordingHistory) { |
| 9848 | mHistoryCur.currentTime = System.currentTimeMillis(); |
Dianne Hackborn | 29cd7f1 | 2015-01-08 10:37:05 -0800 | [diff] [blame] | 9849 | addHistoryBufferLocked(elapsedRealtimeMs, uptimeMs, HistoryItem.CMD_SHUTDOWN, |
| 9850 | mHistoryCur); |
| 9851 | mHistoryCur.currentTime = 0; |
| 9852 | } |
| 9853 | } |
| 9854 | |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 9855 | private void scheduleSyncExternalStatsLocked(String reason, int updateFlags) { |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 9856 | if (mExternalSync != null) { |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 9857 | mExternalSync.scheduleSync(reason, updateFlags); |
Adam Lesinski | a7c90c8 | 2015-06-18 14:52:24 -0700 | [diff] [blame] | 9858 | } |
| 9859 | } |
| 9860 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9861 | // 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] | 9862 | public static final int BATTERY_PLUGGED_NONE = 0; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 9863 | |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 9864 | public void setBatteryStateLocked(int status, int health, int plugType, int level, |
Adam Lesinski | 041d917 | 2016-12-12 12:03:56 -0800 | [diff] [blame] | 9865 | int temp, int volt, int chargeUAh, int chargeFullUAh) { |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 9866 | final boolean onBattery = plugType == BATTERY_PLUGGED_NONE; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9867 | final long uptime = mClocks.uptimeMillis(); |
| 9868 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 9869 | if (!mHaveBatteryLevel) { |
| 9870 | mHaveBatteryLevel = true; |
| 9871 | // We start out assuming that the device is plugged in (not |
| 9872 | // on battery). If our first report is now that we are indeed |
| 9873 | // plugged in, then twiddle our state to correctly reflect that |
| 9874 | // since we won't be going through the full setOnBattery(). |
| 9875 | if (onBattery == mOnBattery) { |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 9876 | if (onBattery) { |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 9877 | mHistoryCur.states &= ~HistoryItem.STATE_BATTERY_PLUGGED_FLAG; |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 9878 | } else { |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 9879 | mHistoryCur.states |= HistoryItem.STATE_BATTERY_PLUGGED_FLAG; |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 9880 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9881 | } |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 9882 | // Always start out assuming charging, that will be updated later. |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 9883 | mHistoryCur.states2 |= HistoryItem.STATE2_CHARGING_FLAG; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 9884 | mHistoryCur.batteryStatus = (byte)status; |
| 9885 | mHistoryCur.batteryLevel = (byte)level; |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 9886 | mHistoryCur.batteryChargeUAh = chargeUAh; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 9887 | mMaxChargeStepLevel = mMinDischargeStepLevel = |
| 9888 | mLastChargeStepLevel = mLastDischargeStepLevel = level; |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 9889 | mLastChargingStateLevel = level; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 9890 | } else if (mCurrentBatteryLevel != level || mOnBattery != onBattery) { |
| 9891 | recordDailyStatsIfNeededLocked(level >= 100 && onBattery); |
| 9892 | } |
| 9893 | int oldStatus = mHistoryCur.batteryStatus; |
| 9894 | if (onBattery) { |
| 9895 | mDischargeCurrentLevel = level; |
| 9896 | if (!mRecordingHistory) { |
| 9897 | mRecordingHistory = true; |
| 9898 | startRecordingHistory(elapsedRealtime, uptime, true); |
| 9899 | } |
| 9900 | } else if (level < 96) { |
| 9901 | if (!mRecordingHistory) { |
| 9902 | mRecordingHistory = true; |
| 9903 | startRecordingHistory(elapsedRealtime, uptime, true); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9904 | } |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 9905 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 9906 | mCurrentBatteryLevel = level; |
| 9907 | if (mDischargePlugLevel < 0) { |
| 9908 | mDischargePlugLevel = level; |
Marco Nelissen | d859331 | 2009-04-30 14:45:06 -0700 | [diff] [blame] | 9909 | } |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 9910 | |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 9911 | if (onBattery != mOnBattery) { |
| 9912 | mHistoryCur.batteryLevel = (byte)level; |
| 9913 | mHistoryCur.batteryStatus = (byte)status; |
| 9914 | mHistoryCur.batteryHealth = (byte)health; |
| 9915 | mHistoryCur.batteryPlugType = (byte)plugType; |
| 9916 | mHistoryCur.batteryTemperature = (short)temp; |
| 9917 | mHistoryCur.batteryVoltage = (char)volt; |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 9918 | if (chargeUAh < mHistoryCur.batteryChargeUAh) { |
| 9919 | // Only record discharges |
| 9920 | final long chargeDiff = mHistoryCur.batteryChargeUAh - chargeUAh; |
| 9921 | mDischargeCounter.addCountLocked(chargeDiff); |
| 9922 | mDischargeScreenOffCounter.addCountLocked(chargeDiff); |
| 9923 | } |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 9924 | mHistoryCur.batteryChargeUAh = chargeUAh; |
Adam Lesinski | f9b20a9 | 2016-06-17 17:30:01 -0700 | [diff] [blame] | 9925 | setOnBatteryLocked(elapsedRealtime, uptime, onBattery, oldStatus, level, chargeUAh); |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 9926 | } else { |
| 9927 | boolean changed = false; |
| 9928 | if (mHistoryCur.batteryLevel != level) { |
| 9929 | mHistoryCur.batteryLevel = (byte)level; |
| 9930 | changed = true; |
Marco Nelissen | d859331 | 2009-04-30 14:45:06 -0700 | [diff] [blame] | 9931 | |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 9932 | // TODO(adamlesinski): Schedule the creation of a HistoryStepDetails record |
| 9933 | // which will pull external stats. |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 9934 | scheduleSyncExternalStatsLocked("battery-level", ExternalStatsSync.UPDATE_ALL); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 9935 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 9936 | if (mHistoryCur.batteryStatus != status) { |
| 9937 | mHistoryCur.batteryStatus = (byte)status; |
| 9938 | changed = true; |
| 9939 | } |
| 9940 | if (mHistoryCur.batteryHealth != health) { |
| 9941 | mHistoryCur.batteryHealth = (byte)health; |
| 9942 | changed = true; |
| 9943 | } |
| 9944 | if (mHistoryCur.batteryPlugType != plugType) { |
| 9945 | mHistoryCur.batteryPlugType = (byte)plugType; |
| 9946 | changed = true; |
| 9947 | } |
| 9948 | if (temp >= (mHistoryCur.batteryTemperature+10) |
| 9949 | || temp <= (mHistoryCur.batteryTemperature-10)) { |
| 9950 | mHistoryCur.batteryTemperature = (short)temp; |
| 9951 | changed = true; |
| 9952 | } |
| 9953 | if (volt > (mHistoryCur.batteryVoltage+20) |
| 9954 | || volt < (mHistoryCur.batteryVoltage-20)) { |
| 9955 | mHistoryCur.batteryVoltage = (char)volt; |
| 9956 | changed = true; |
| 9957 | } |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 9958 | if (chargeUAh >= (mHistoryCur.batteryChargeUAh+10) |
| 9959 | || chargeUAh <= (mHistoryCur.batteryChargeUAh-10)) { |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 9960 | if (chargeUAh < mHistoryCur.batteryChargeUAh) { |
| 9961 | // Only record discharges |
| 9962 | final long chargeDiff = mHistoryCur.batteryChargeUAh - chargeUAh; |
| 9963 | mDischargeCounter.addCountLocked(chargeDiff); |
| 9964 | mDischargeScreenOffCounter.addCountLocked(chargeDiff); |
| 9965 | } |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 9966 | mHistoryCur.batteryChargeUAh = chargeUAh; |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 9967 | changed = true; |
| 9968 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 9969 | long modeBits = (((long)mInitStepMode) << STEP_LEVEL_INITIAL_MODE_SHIFT) |
| 9970 | | (((long)mModStepMode) << STEP_LEVEL_MODIFIED_MODE_SHIFT) |
| 9971 | | (((long)(level&0xff)) << STEP_LEVEL_LEVEL_SHIFT); |
| 9972 | if (onBattery) { |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 9973 | changed |= setChargingLocked(false); |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 9974 | if (mLastDischargeStepLevel != level && mMinDischargeStepLevel > level) { |
| 9975 | mDischargeStepTracker.addLevelSteps(mLastDischargeStepLevel - level, |
| 9976 | modeBits, elapsedRealtime); |
| 9977 | mDailyDischargeStepTracker.addLevelSteps(mLastDischargeStepLevel - level, |
| 9978 | modeBits, elapsedRealtime); |
| 9979 | mLastDischargeStepLevel = level; |
| 9980 | mMinDischargeStepLevel = level; |
| 9981 | mInitStepMode = mCurStepMode; |
| 9982 | mModStepMode = 0; |
| 9983 | } |
| 9984 | } else { |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 9985 | if (level >= 90) { |
| 9986 | // If the battery level is at least 90%, always consider the device to be |
| 9987 | // charging even if it happens to go down a level. |
| 9988 | changed |= setChargingLocked(true); |
| 9989 | mLastChargeStepLevel = level; |
| 9990 | } if (!mCharging) { |
| 9991 | if (mLastChargeStepLevel < level) { |
| 9992 | // We have not reporting that we are charging, but the level has now |
| 9993 | // gone up, so consider the state to be charging. |
| 9994 | changed |= setChargingLocked(true); |
| 9995 | mLastChargeStepLevel = level; |
| 9996 | } |
| 9997 | } else { |
| 9998 | if (mLastChargeStepLevel > level) { |
| 9999 | // We had reported that the device was charging, but here we are with |
| 10000 | // power connected and the level going down. Looks like the current |
| 10001 | // power supplied isn't enough, so consider the device to now be |
| 10002 | // discharging. |
| 10003 | changed |= setChargingLocked(false); |
| 10004 | mLastChargeStepLevel = level; |
| 10005 | } |
| 10006 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 10007 | if (mLastChargeStepLevel != level && mMaxChargeStepLevel < level) { |
| 10008 | mChargeStepTracker.addLevelSteps(level - mLastChargeStepLevel, |
| 10009 | modeBits, elapsedRealtime); |
| 10010 | mDailyChargeStepTracker.addLevelSteps(level - mLastChargeStepLevel, |
| 10011 | modeBits, elapsedRealtime); |
| 10012 | mLastChargeStepLevel = level; |
| 10013 | mMaxChargeStepLevel = level; |
| 10014 | mInitStepMode = mCurStepMode; |
| 10015 | mModStepMode = 0; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 10016 | } |
| 10017 | } |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 10018 | if (changed) { |
| 10019 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 10020 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 10021 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 10022 | if (!onBattery && status == BatteryManager.BATTERY_STATUS_FULL) { |
| 10023 | // We don't record history while we are plugged in and fully charged. |
| 10024 | // The next time we are unplugged, history will be cleared. |
| 10025 | mRecordingHistory = DEBUG; |
Dianne Hackborn | d0c5b9a | 2014-02-21 16:19:05 -0800 | [diff] [blame] | 10026 | } |
Adam Lesinski | 041d917 | 2016-12-12 12:03:56 -0800 | [diff] [blame] | 10027 | |
| 10028 | if (differsByMoreThan(chargeFullUAh, mLastChargeFullUAh, 100)) { |
| 10029 | mLastChargeFullUAh = chargeFullUAh; |
| 10030 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_ESTIMATED_BATTERY_CAP, |
| 10031 | "", chargeFullUAh / 1000); |
| 10032 | } |
| 10033 | } |
| 10034 | |
| 10035 | private static boolean differsByMoreThan(int left, int right, int diff) { |
| 10036 | return Math.abs(left - right) > diff; |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 10037 | } |
| 10038 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10039 | public long getAwakeTimeBattery() { |
| 10040 | return computeBatteryUptime(getBatteryUptimeLocked(), STATS_CURRENT); |
| 10041 | } |
| 10042 | |
| 10043 | public long getAwakeTimePlugged() { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 10044 | return (mClocks.uptimeMillis() * 1000) - getAwakeTimeBattery(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10045 | } |
| 10046 | |
| 10047 | @Override |
| 10048 | public long computeUptime(long curTime, int which) { |
| 10049 | switch (which) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10050 | case STATS_SINCE_CHARGED: return mUptime + (curTime-mUptimeStart); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10051 | case STATS_CURRENT: return (curTime-mUptimeStart); |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 10052 | case STATS_SINCE_UNPLUGGED: return (curTime-mOnBatteryTimeBase.getUptimeStart()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10053 | } |
| 10054 | return 0; |
| 10055 | } |
| 10056 | |
| 10057 | @Override |
| 10058 | public long computeRealtime(long curTime, int which) { |
| 10059 | switch (which) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10060 | case STATS_SINCE_CHARGED: return mRealtime + (curTime-mRealtimeStart); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10061 | case STATS_CURRENT: return (curTime-mRealtimeStart); |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 10062 | case STATS_SINCE_UNPLUGGED: return (curTime-mOnBatteryTimeBase.getRealtimeStart()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10063 | } |
| 10064 | return 0; |
| 10065 | } |
| 10066 | |
| 10067 | @Override |
| 10068 | public long computeBatteryUptime(long curTime, int which) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10069 | return mOnBatteryTimeBase.computeUptime(curTime, which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10070 | } |
| 10071 | |
| 10072 | @Override |
| 10073 | public long computeBatteryRealtime(long curTime, int which) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10074 | return mOnBatteryTimeBase.computeRealtime(curTime, which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10075 | } |
| 10076 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10077 | @Override |
| 10078 | public long computeBatteryScreenOffUptime(long curTime, int which) { |
| 10079 | return mOnBatteryScreenOffTimeBase.computeUptime(curTime, which); |
| 10080 | } |
| 10081 | |
| 10082 | @Override |
| 10083 | public long computeBatteryScreenOffRealtime(long curTime, int which) { |
| 10084 | return mOnBatteryScreenOffTimeBase.computeRealtime(curTime, which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10085 | } |
| 10086 | |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 10087 | private long computeTimePerLevel(long[] steps, int numSteps) { |
| 10088 | // For now we'll do a simple average across all steps. |
| 10089 | if (numSteps <= 0) { |
| 10090 | return -1; |
| 10091 | } |
| 10092 | long total = 0; |
| 10093 | for (int i=0; i<numSteps; i++) { |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 10094 | total += steps[i] & STEP_LEVEL_TIME_MASK; |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 10095 | } |
| 10096 | return total / numSteps; |
| 10097 | /* |
| 10098 | long[] buckets = new long[numSteps]; |
| 10099 | int numBuckets = 0; |
| 10100 | int numToAverage = 4; |
| 10101 | int i = 0; |
| 10102 | while (i < numSteps) { |
| 10103 | long totalTime = 0; |
| 10104 | int num = 0; |
| 10105 | for (int j=0; j<numToAverage && (i+j)<numSteps; j++) { |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 10106 | totalTime += steps[i+j] & STEP_LEVEL_TIME_MASK; |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 10107 | num++; |
| 10108 | } |
| 10109 | buckets[numBuckets] = totalTime / num; |
| 10110 | numBuckets++; |
| 10111 | numToAverage *= 2; |
| 10112 | i += num; |
| 10113 | } |
| 10114 | if (numBuckets < 1) { |
| 10115 | return -1; |
| 10116 | } |
| 10117 | long averageTime = buckets[numBuckets-1]; |
| 10118 | for (i=numBuckets-2; i>=0; i--) { |
| 10119 | averageTime = (averageTime + buckets[i]) / 2; |
| 10120 | } |
| 10121 | return averageTime; |
| 10122 | */ |
| 10123 | } |
| 10124 | |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 10125 | @Override |
| 10126 | public long computeBatteryTimeRemaining(long curTime) { |
| 10127 | if (!mOnBattery) { |
| 10128 | return -1; |
| 10129 | } |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 10130 | /* Simple implementation just looks at the average discharge per level across the |
| 10131 | entire sample period. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 10132 | int discharge = (getLowDischargeAmountSinceCharge()+getHighDischargeAmountSinceCharge())/2; |
| 10133 | if (discharge < 2) { |
| 10134 | return -1; |
| 10135 | } |
| 10136 | long duration = computeBatteryRealtime(curTime, STATS_SINCE_CHARGED); |
| 10137 | if (duration < 1000*1000) { |
| 10138 | return -1; |
| 10139 | } |
| 10140 | long usPerLevel = duration/discharge; |
| 10141 | return usPerLevel * mCurrentBatteryLevel; |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 10142 | */ |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 10143 | if (mDischargeStepTracker.mNumStepDurations < 1) { |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 10144 | return -1; |
| 10145 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 10146 | long msPerLevel = mDischargeStepTracker.computeTimePerLevel(); |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 10147 | if (msPerLevel <= 0) { |
| 10148 | return -1; |
| 10149 | } |
| 10150 | return (msPerLevel * mCurrentBatteryLevel) * 1000; |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 10151 | } |
| 10152 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 10153 | @Override |
| 10154 | public LevelStepTracker getDischargeLevelStepTracker() { |
| 10155 | return mDischargeStepTracker; |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 10156 | } |
| 10157 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 10158 | @Override |
| 10159 | public LevelStepTracker getDailyDischargeLevelStepTracker() { |
| 10160 | return mDailyDischargeStepTracker; |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 10161 | } |
| 10162 | |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 10163 | @Override |
| 10164 | public long computeChargeTimeRemaining(long curTime) { |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 10165 | if (mOnBattery) { |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 10166 | // Not yet working. |
| 10167 | return -1; |
| 10168 | } |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 10169 | /* Broken |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 10170 | int curLevel = mCurrentBatteryLevel; |
| 10171 | int plugLevel = mDischargePlugLevel; |
| 10172 | if (plugLevel < 0 || curLevel < (plugLevel+1)) { |
| 10173 | return -1; |
| 10174 | } |
| 10175 | long duration = computeBatteryRealtime(curTime, STATS_SINCE_UNPLUGGED); |
| 10176 | if (duration < 1000*1000) { |
| 10177 | return -1; |
| 10178 | } |
| 10179 | long usPerLevel = duration/(curLevel-plugLevel); |
| 10180 | return usPerLevel * (100-curLevel); |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 10181 | */ |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 10182 | if (mChargeStepTracker.mNumStepDurations < 1) { |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 10183 | return -1; |
| 10184 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 10185 | long msPerLevel = mChargeStepTracker.computeTimePerLevel(); |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 10186 | if (msPerLevel <= 0) { |
| 10187 | return -1; |
| 10188 | } |
| 10189 | return (msPerLevel * (100-mCurrentBatteryLevel)) * 1000; |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 10190 | } |
| 10191 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 10192 | @Override |
| 10193 | public LevelStepTracker getChargeLevelStepTracker() { |
| 10194 | return mChargeStepTracker; |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 10195 | } |
| 10196 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 10197 | @Override |
| 10198 | public LevelStepTracker getDailyChargeLevelStepTracker() { |
| 10199 | return mDailyChargeStepTracker; |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 10200 | } |
| 10201 | |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 10202 | @Override |
| 10203 | public ArrayList<PackageChange> getDailyPackageChanges() { |
| 10204 | return mDailyPackageChanges; |
| 10205 | } |
| 10206 | |
Joe Onorato | e1acd63 | 2016-02-23 13:25:10 -0800 | [diff] [blame] | 10207 | protected long getBatteryUptimeLocked() { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 10208 | return mOnBatteryTimeBase.getUptime(mClocks.uptimeMillis() * 1000); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10209 | } |
| 10210 | |
| 10211 | @Override |
| 10212 | public long getBatteryUptime(long curTime) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10213 | return mOnBatteryTimeBase.getUptime(curTime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10214 | } |
| 10215 | |
| 10216 | @Override |
| 10217 | public long getBatteryRealtime(long curTime) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10218 | return mOnBatteryTimeBase.getRealtime(curTime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10219 | } |
Amith Yamasani | 3718aaa | 2009-06-09 06:32:35 -0700 | [diff] [blame] | 10220 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 10221 | @Override |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 10222 | public int getDischargeStartLevel() { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 10223 | synchronized(this) { |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 10224 | return getDischargeStartLevelLocked(); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 10225 | } |
| 10226 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 10227 | |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 10228 | public int getDischargeStartLevelLocked() { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10229 | return mDischargeUnplugLevel; |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 10230 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 10231 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 10232 | @Override |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 10233 | public int getDischargeCurrentLevel() { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 10234 | synchronized(this) { |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 10235 | return getDischargeCurrentLevelLocked(); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 10236 | } |
| 10237 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 10238 | |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 10239 | public int getDischargeCurrentLevelLocked() { |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 10240 | return mDischargeCurrentLevel; |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 10241 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10242 | |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 10243 | @Override |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 10244 | public int getLowDischargeAmountSinceCharge() { |
| 10245 | synchronized(this) { |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 10246 | int val = mLowDischargeAmountSinceCharge; |
| 10247 | if (mOnBattery && mDischargeCurrentLevel < mDischargeUnplugLevel) { |
| 10248 | val += mDischargeUnplugLevel-mDischargeCurrentLevel-1; |
| 10249 | } |
| 10250 | return val; |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 10251 | } |
| 10252 | } |
| 10253 | |
| 10254 | @Override |
| 10255 | public int getHighDischargeAmountSinceCharge() { |
| 10256 | synchronized(this) { |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 10257 | int val = mHighDischargeAmountSinceCharge; |
| 10258 | if (mOnBattery && mDischargeCurrentLevel < mDischargeUnplugLevel) { |
| 10259 | val += mDischargeUnplugLevel-mDischargeCurrentLevel; |
| 10260 | } |
| 10261 | return val; |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 10262 | } |
| 10263 | } |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 10264 | |
| 10265 | @Override |
| 10266 | public int getDischargeAmount(int which) { |
| 10267 | int dischargeAmount = which == STATS_SINCE_CHARGED |
| 10268 | ? getHighDischargeAmountSinceCharge() |
| 10269 | : (getDischargeStartLevel() - getDischargeCurrentLevel()); |
| 10270 | if (dischargeAmount < 0) { |
| 10271 | dischargeAmount = 0; |
| 10272 | } |
| 10273 | return dischargeAmount; |
| 10274 | } |
| 10275 | |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 10276 | public int getDischargeAmountScreenOn() { |
| 10277 | synchronized(this) { |
| 10278 | int val = mDischargeAmountScreenOn; |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 10279 | if (mOnBattery && mScreenState == Display.STATE_ON |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 10280 | && mDischargeCurrentLevel < mDischargeScreenOnUnplugLevel) { |
| 10281 | val += mDischargeScreenOnUnplugLevel-mDischargeCurrentLevel; |
| 10282 | } |
| 10283 | return val; |
| 10284 | } |
| 10285 | } |
| 10286 | |
| 10287 | public int getDischargeAmountScreenOnSinceCharge() { |
| 10288 | synchronized(this) { |
| 10289 | int val = mDischargeAmountScreenOnSinceCharge; |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 10290 | if (mOnBattery && mScreenState == Display.STATE_ON |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 10291 | && mDischargeCurrentLevel < mDischargeScreenOnUnplugLevel) { |
| 10292 | val += mDischargeScreenOnUnplugLevel-mDischargeCurrentLevel; |
| 10293 | } |
| 10294 | return val; |
| 10295 | } |
| 10296 | } |
| 10297 | |
| 10298 | public int getDischargeAmountScreenOff() { |
| 10299 | synchronized(this) { |
| 10300 | int val = mDischargeAmountScreenOff; |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 10301 | if (mOnBattery && mScreenState != Display.STATE_ON |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 10302 | && mDischargeCurrentLevel < mDischargeScreenOffUnplugLevel) { |
| 10303 | val += mDischargeScreenOffUnplugLevel-mDischargeCurrentLevel; |
| 10304 | } |
| 10305 | return val; |
| 10306 | } |
| 10307 | } |
| 10308 | |
| 10309 | public int getDischargeAmountScreenOffSinceCharge() { |
| 10310 | synchronized(this) { |
| 10311 | int val = mDischargeAmountScreenOffSinceCharge; |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 10312 | if (mOnBattery && mScreenState != Display.STATE_ON |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 10313 | && mDischargeCurrentLevel < mDischargeScreenOffUnplugLevel) { |
| 10314 | val += mDischargeScreenOffUnplugLevel-mDischargeCurrentLevel; |
| 10315 | } |
| 10316 | return val; |
| 10317 | } |
| 10318 | } |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 10319 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10320 | /** |
| 10321 | * Retrieve the statistics object for a particular uid, creating if needed. |
| 10322 | */ |
| 10323 | public Uid getUidStatsLocked(int uid) { |
| 10324 | Uid u = mUidStats.get(uid); |
| 10325 | if (u == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 10326 | u = new Uid(this, uid); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10327 | mUidStats.put(uid, u); |
| 10328 | } |
| 10329 | return u; |
| 10330 | } |
| 10331 | |
| 10332 | /** |
| 10333 | * Remove the statistics object for a particular uid. |
| 10334 | */ |
| 10335 | public void removeUidStatsLocked(int uid) { |
Adam Lesinski | b83ffee | 2015-05-12 14:43:47 -0700 | [diff] [blame] | 10336 | mKernelUidCpuTimeReader.removeUid(uid); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10337 | mUidStats.remove(uid); |
| 10338 | } |
Amith Yamasani | 32dbefd | 2009-06-19 09:21:17 -0700 | [diff] [blame] | 10339 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10340 | /** |
| 10341 | * Retrieve the statistics object for a particular process, creating |
| 10342 | * if needed. |
| 10343 | */ |
| 10344 | public Uid.Proc getProcessStatsLocked(int uid, String name) { |
Dianne Hackborn | bbb7472 | 2014-03-13 09:50:24 -0700 | [diff] [blame] | 10345 | uid = mapUid(uid); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10346 | Uid u = getUidStatsLocked(uid); |
| 10347 | return u.getProcessStatsLocked(name); |
| 10348 | } |
| 10349 | |
| 10350 | /** |
| 10351 | * Retrieve the statistics object for a particular process, creating |
| 10352 | * if needed. |
| 10353 | */ |
| 10354 | public Uid.Pkg getPackageStatsLocked(int uid, String pkg) { |
Dianne Hackborn | bbb7472 | 2014-03-13 09:50:24 -0700 | [diff] [blame] | 10355 | uid = mapUid(uid); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10356 | Uid u = getUidStatsLocked(uid); |
| 10357 | return u.getPackageStatsLocked(pkg); |
| 10358 | } |
| 10359 | |
| 10360 | /** |
| 10361 | * Retrieve the statistics object for a particular service, creating |
| 10362 | * if needed. |
| 10363 | */ |
| 10364 | public Uid.Pkg.Serv getServiceStatsLocked(int uid, String pkg, String name) { |
Dianne Hackborn | bbb7472 | 2014-03-13 09:50:24 -0700 | [diff] [blame] | 10365 | uid = mapUid(uid); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10366 | Uid u = getUidStatsLocked(uid); |
| 10367 | return u.getServiceStatsLocked(pkg, name); |
| 10368 | } |
| 10369 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10370 | public void shutdownLocked() { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 10371 | recordShutdownLocked(mClocks.elapsedRealtime(), mClocks.uptimeMillis()); |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 10372 | writeSyncLocked(); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10373 | mShuttingDown = true; |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 10374 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 10375 | |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 10376 | Parcel mPendingWrite = null; |
| 10377 | final ReentrantLock mWriteLock = new ReentrantLock(); |
| 10378 | |
| 10379 | public void writeAsyncLocked() { |
| 10380 | writeLocked(false); |
| 10381 | } |
| 10382 | |
| 10383 | public void writeSyncLocked() { |
| 10384 | writeLocked(true); |
| 10385 | } |
| 10386 | |
| 10387 | void writeLocked(boolean sync) { |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 10388 | if (mFile == null) { |
| 10389 | 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] | 10390 | return; |
| 10391 | } |
| 10392 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10393 | if (mShuttingDown) { |
| 10394 | return; |
| 10395 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 10396 | |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 10397 | Parcel out = Parcel.obtain(); |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 10398 | writeSummaryToParcel(out, true); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 10399 | mLastWriteTime = mClocks.elapsedRealtime(); |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 10400 | |
| 10401 | if (mPendingWrite != null) { |
| 10402 | mPendingWrite.recycle(); |
| 10403 | } |
| 10404 | mPendingWrite = out; |
| 10405 | |
| 10406 | if (sync) { |
| 10407 | commitPendingDataToDisk(); |
| 10408 | } else { |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 10409 | BackgroundThread.getHandler().post(new Runnable() { |
| 10410 | @Override public void run() { |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 10411 | commitPendingDataToDisk(); |
| 10412 | } |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 10413 | }); |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 10414 | } |
| 10415 | } |
| 10416 | |
| 10417 | public void commitPendingDataToDisk() { |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 10418 | final Parcel next; |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 10419 | synchronized (this) { |
| 10420 | next = mPendingWrite; |
| 10421 | mPendingWrite = null; |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 10422 | if (next == null) { |
| 10423 | return; |
| 10424 | } |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 10425 | } |
| 10426 | |
Amith Yamasani | d245086 | 2017-02-07 15:58:24 -0800 | [diff] [blame] | 10427 | mWriteLock.lock(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10428 | try { |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 10429 | FileOutputStream stream = new FileOutputStream(mFile.chooseForWrite()); |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 10430 | stream.write(next.marshall()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10431 | stream.flush(); |
Dianne Hackborn | 8bdf593 | 2010-10-15 12:54:40 -0700 | [diff] [blame] | 10432 | FileUtils.sync(stream); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10433 | stream.close(); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 10434 | mFile.commit(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10435 | } catch (IOException e) { |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 10436 | Slog.w("BatteryStats", "Error writing battery statistics", e); |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 10437 | mFile.rollback(); |
| 10438 | } finally { |
| 10439 | next.recycle(); |
| 10440 | mWriteLock.unlock(); |
Suchi Amalapurapu | 8550f25 | 2009-09-29 15:20:32 -0700 | [diff] [blame] | 10441 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10442 | } |
| 10443 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10444 | public void readLocked() { |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 10445 | if (mDailyFile != null) { |
| 10446 | readDailyStatsLocked(); |
| 10447 | } |
| 10448 | |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 10449 | if (mFile == null) { |
| 10450 | 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] | 10451 | return; |
| 10452 | } |
| 10453 | |
| 10454 | mUidStats.clear(); |
| 10455 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10456 | try { |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 10457 | File file = mFile.chooseForRead(); |
| 10458 | if (!file.exists()) { |
| 10459 | return; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10460 | } |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 10461 | FileInputStream stream = new FileInputStream(file); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10462 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 10463 | byte[] raw = BatteryStatsHelper.readFully(stream); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10464 | Parcel in = Parcel.obtain(); |
| 10465 | in.unmarshall(raw, 0, raw.length); |
| 10466 | in.setDataPosition(0); |
| 10467 | stream.close(); |
| 10468 | |
| 10469 | readSummaryFromParcel(in); |
Dianne Hackborn | 00e2521 | 2014-02-19 10:49:24 -0800 | [diff] [blame] | 10470 | } catch(Exception e) { |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 10471 | Slog.e("BatteryStats", "Error reading battery statistics", e); |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 10472 | resetAllStatsLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10473 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 10474 | |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 10475 | mEndPlatformVersion = Build.ID; |
| 10476 | |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 10477 | if (mHistoryBuffer.dataPosition() > 0) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 10478 | mRecordingHistory = true; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 10479 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 10480 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 10481 | if (USE_OLD_HISTORY) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 10482 | addHistoryRecordLocked(elapsedRealtime, uptime, HistoryItem.CMD_START, mHistoryCur); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 10483 | } |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 10484 | addHistoryBufferLocked(elapsedRealtime, uptime, HistoryItem.CMD_START, mHistoryCur); |
| 10485 | startRecordingHistory(elapsedRealtime, uptime, false); |
Dianne Hackborn | e8c88e6 | 2011-08-17 19:09:09 -0700 | [diff] [blame] | 10486 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 10487 | |
| 10488 | recordDailyStatsIfNeededLocked(false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10489 | } |
| 10490 | |
| 10491 | public int describeContents() { |
| 10492 | return 0; |
| 10493 | } |
| 10494 | |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 10495 | void readHistory(Parcel in, boolean andOldHistory) throws ParcelFormatException { |
Dianne Hackborn | ae38445 | 2011-06-28 12:33:48 -0700 | [diff] [blame] | 10496 | final long historyBaseTime = in.readLong(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 10497 | |
| 10498 | mHistoryBuffer.setDataSize(0); |
| 10499 | mHistoryBuffer.setDataPosition(0); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 10500 | mHistoryTagPool.clear(); |
| 10501 | mNextHistoryTagIdx = 0; |
| 10502 | mNumHistoryTagChars = 0; |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 10503 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 10504 | int numTags = in.readInt(); |
| 10505 | for (int i=0; i<numTags; i++) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 10506 | int idx = in.readInt(); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 10507 | String str = in.readString(); |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 10508 | if (str == null) { |
| 10509 | throw new ParcelFormatException("null history tag string"); |
| 10510 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 10511 | int uid = in.readInt(); |
| 10512 | HistoryTag tag = new HistoryTag(); |
| 10513 | tag.string = str; |
| 10514 | tag.uid = uid; |
| 10515 | tag.poolIdx = idx; |
| 10516 | mHistoryTagPool.put(tag, idx); |
| 10517 | if (idx >= mNextHistoryTagIdx) { |
| 10518 | mNextHistoryTagIdx = idx+1; |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 10519 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 10520 | mNumHistoryTagChars += tag.string.length() + 1; |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 10521 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 10522 | |
| 10523 | int bufSize = in.readInt(); |
| 10524 | int curPos = in.dataPosition(); |
| 10525 | if (bufSize >= (MAX_MAX_HISTORY_BUFFER*3)) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 10526 | throw new ParcelFormatException("File corrupt: history data buffer too large " + |
| 10527 | bufSize); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 10528 | } else if ((bufSize&~3) != bufSize) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 10529 | throw new ParcelFormatException("File corrupt: history data buffer not aligned " + |
| 10530 | bufSize); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 10531 | } else { |
| 10532 | if (DEBUG_HISTORY) Slog.i(TAG, "***************** READING NEW HISTORY: " + bufSize |
| 10533 | + " bytes at " + curPos); |
| 10534 | mHistoryBuffer.appendFrom(in, curPos, bufSize); |
| 10535 | in.setDataPosition(curPos + bufSize); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 10536 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 10537 | |
Dianne Hackborn | ae38445 | 2011-06-28 12:33:48 -0700 | [diff] [blame] | 10538 | if (andOldHistory) { |
| 10539 | readOldHistory(in); |
| 10540 | } |
| 10541 | |
| 10542 | if (DEBUG_HISTORY) { |
| 10543 | StringBuilder sb = new StringBuilder(128); |
| 10544 | sb.append("****************** OLD mHistoryBaseTime: "); |
| 10545 | TimeUtils.formatDuration(mHistoryBaseTime, sb); |
| 10546 | Slog.i(TAG, sb.toString()); |
| 10547 | } |
| 10548 | mHistoryBaseTime = historyBaseTime; |
| 10549 | if (DEBUG_HISTORY) { |
| 10550 | StringBuilder sb = new StringBuilder(128); |
| 10551 | sb.append("****************** NEW mHistoryBaseTime: "); |
| 10552 | TimeUtils.formatDuration(mHistoryBaseTime, sb); |
| 10553 | Slog.i(TAG, sb.toString()); |
| 10554 | } |
| 10555 | |
| 10556 | // We are just arbitrarily going to insert 1 minute from the sample of |
| 10557 | // the last run until samples in this run. |
| 10558 | if (mHistoryBaseTime > 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 10559 | long oldnow = mClocks.elapsedRealtime(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 10560 | mHistoryBaseTime = mHistoryBaseTime - oldnow + 1; |
Dianne Hackborn | ae38445 | 2011-06-28 12:33:48 -0700 | [diff] [blame] | 10561 | if (DEBUG_HISTORY) { |
| 10562 | StringBuilder sb = new StringBuilder(128); |
| 10563 | sb.append("****************** ADJUSTED mHistoryBaseTime: "); |
| 10564 | TimeUtils.formatDuration(mHistoryBaseTime, sb); |
| 10565 | Slog.i(TAG, sb.toString()); |
| 10566 | } |
Dianne Hackborn | 1e4b9f3 | 2010-06-23 14:10:57 -0700 | [diff] [blame] | 10567 | } |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 10568 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 10569 | |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 10570 | void readOldHistory(Parcel in) { |
Dianne Hackborn | e8c88e6 | 2011-08-17 19:09:09 -0700 | [diff] [blame] | 10571 | if (!USE_OLD_HISTORY) { |
| 10572 | return; |
| 10573 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 10574 | mHistory = mHistoryEnd = mHistoryCache = null; |
| 10575 | long time; |
Conley Owens | 5e3357f | 2011-05-02 09:59:30 -0700 | [diff] [blame] | 10576 | while (in.dataAvail() > 0 && (time=in.readLong()) >= 0) { |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 10577 | HistoryItem rec = new HistoryItem(time, in); |
| 10578 | addHistoryRecordLocked(rec); |
| 10579 | } |
| 10580 | } |
| 10581 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 10582 | void writeHistory(Parcel out, boolean inclData, boolean andOldHistory) { |
Dianne Hackborn | ae38445 | 2011-06-28 12:33:48 -0700 | [diff] [blame] | 10583 | if (DEBUG_HISTORY) { |
| 10584 | StringBuilder sb = new StringBuilder(128); |
| 10585 | sb.append("****************** WRITING mHistoryBaseTime: "); |
| 10586 | TimeUtils.formatDuration(mHistoryBaseTime, sb); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 10587 | sb.append(" mLastHistoryElapsedRealtime: "); |
| 10588 | TimeUtils.formatDuration(mLastHistoryElapsedRealtime, sb); |
Dianne Hackborn | ae38445 | 2011-06-28 12:33:48 -0700 | [diff] [blame] | 10589 | Slog.i(TAG, sb.toString()); |
| 10590 | } |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 10591 | out.writeLong(mHistoryBaseTime + mLastHistoryElapsedRealtime); |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 10592 | if (!inclData) { |
| 10593 | out.writeInt(0); |
| 10594 | out.writeInt(0); |
| 10595 | return; |
| 10596 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 10597 | out.writeInt(mHistoryTagPool.size()); |
| 10598 | for (HashMap.Entry<HistoryTag, Integer> ent : mHistoryTagPool.entrySet()) { |
| 10599 | HistoryTag tag = ent.getKey(); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 10600 | out.writeInt(ent.getValue()); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 10601 | out.writeString(tag.string); |
| 10602 | out.writeInt(tag.uid); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 10603 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 10604 | out.writeInt(mHistoryBuffer.dataSize()); |
| 10605 | if (DEBUG_HISTORY) Slog.i(TAG, "***************** WRITING HISTORY: " |
| 10606 | + mHistoryBuffer.dataSize() + " bytes at " + out.dataPosition()); |
| 10607 | out.appendFrom(mHistoryBuffer, 0, mHistoryBuffer.dataSize()); |
Dianne Hackborn | ae38445 | 2011-06-28 12:33:48 -0700 | [diff] [blame] | 10608 | |
| 10609 | if (andOldHistory) { |
| 10610 | writeOldHistory(out); |
| 10611 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 10612 | } |
| 10613 | |
| 10614 | void writeOldHistory(Parcel out) { |
Dianne Hackborn | e8c88e6 | 2011-08-17 19:09:09 -0700 | [diff] [blame] | 10615 | if (!USE_OLD_HISTORY) { |
| 10616 | return; |
| 10617 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10618 | HistoryItem rec = mHistory; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 10619 | while (rec != null) { |
| 10620 | if (rec.time >= 0) rec.writeToParcel(out, 0); |
| 10621 | rec = rec.next; |
| 10622 | } |
| 10623 | out.writeLong(-1); |
| 10624 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 10625 | |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 10626 | public void readSummaryFromParcel(Parcel in) throws ParcelFormatException { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10627 | final int version = in.readInt(); |
| 10628 | if (version != VERSION) { |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 10629 | Slog.w("BatteryStats", "readFromParcel: version got " + version |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10630 | + ", expected " + VERSION + "; erasing old stats"); |
| 10631 | return; |
| 10632 | } |
| 10633 | |
Dianne Hackborn | ae38445 | 2011-06-28 12:33:48 -0700 | [diff] [blame] | 10634 | readHistory(in, true); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 10635 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10636 | mStartCount = in.readInt(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10637 | mUptime = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10638 | mRealtime = in.readLong(); |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 10639 | mStartClockTime = in.readLong(); |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 10640 | mStartPlatformVersion = in.readString(); |
| 10641 | mEndPlatformVersion = in.readString(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10642 | mOnBatteryTimeBase.readSummaryFromParcel(in); |
| 10643 | mOnBatteryScreenOffTimeBase.readSummaryFromParcel(in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10644 | mDischargeUnplugLevel = in.readInt(); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 10645 | mDischargePlugLevel = in.readInt(); |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 10646 | mDischargeCurrentLevel = in.readInt(); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 10647 | mCurrentBatteryLevel = in.readInt(); |
Adam Lesinski | f9b20a9 | 2016-06-17 17:30:01 -0700 | [diff] [blame] | 10648 | mEstimatedBatteryCapacity = in.readInt(); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 10649 | mLowDischargeAmountSinceCharge = in.readInt(); |
| 10650 | mHighDischargeAmountSinceCharge = in.readInt(); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 10651 | mDischargeAmountScreenOnSinceCharge = in.readInt(); |
| 10652 | mDischargeAmountScreenOffSinceCharge = in.readInt(); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 10653 | mDischargeStepTracker.readFromParcel(in); |
| 10654 | mChargeStepTracker.readFromParcel(in); |
| 10655 | mDailyDischargeStepTracker.readFromParcel(in); |
| 10656 | mDailyChargeStepTracker.readFromParcel(in); |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 10657 | mDischargeCounter.readSummaryFromParcelLocked(in); |
| 10658 | mDischargeScreenOffCounter.readSummaryFromParcelLocked(in); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 10659 | int NPKG = in.readInt(); |
| 10660 | if (NPKG > 0) { |
| 10661 | mDailyPackageChanges = new ArrayList<>(NPKG); |
| 10662 | while (NPKG > 0) { |
| 10663 | NPKG--; |
| 10664 | PackageChange pc = new PackageChange(); |
| 10665 | pc.mPackageName = in.readString(); |
| 10666 | pc.mUpdate = in.readInt() != 0; |
| 10667 | pc.mVersionCode = in.readInt(); |
| 10668 | mDailyPackageChanges.add(pc); |
| 10669 | } |
| 10670 | } else { |
| 10671 | mDailyPackageChanges = null; |
| 10672 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 10673 | mDailyStartTime = in.readLong(); |
| 10674 | mNextMinDailyDeadline = in.readLong(); |
| 10675 | mNextMaxDailyDeadline = in.readLong(); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 10676 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10677 | mStartCount++; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 10678 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 10679 | mScreenState = Display.STATE_UNKNOWN; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10680 | mScreenOnTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 10681 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
| 10682 | mScreenBrightnessTimer[i].readSummaryFromParcelLocked(in); |
| 10683 | } |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 10684 | mInteractive = false; |
| 10685 | mInteractiveTimer.readSummaryFromParcelLocked(in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10686 | mPhoneOn = false; |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 10687 | mPowerSaveModeEnabledTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 10688 | mLongestLightIdleTime = in.readLong(); |
| 10689 | mLongestFullIdleTime = in.readLong(); |
| 10690 | mDeviceIdleModeLightTimer.readSummaryFromParcelLocked(in); |
| 10691 | mDeviceIdleModeFullTimer.readSummaryFromParcelLocked(in); |
| 10692 | mDeviceLightIdlingTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 10693 | mDeviceIdlingTimer.readSummaryFromParcelLocked(in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10694 | mPhoneOnTimer.readSummaryFromParcelLocked(in); |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 10695 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 10696 | mPhoneSignalStrengthsTimer[i].readSummaryFromParcelLocked(in); |
| 10697 | } |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 10698 | mPhoneSignalScanningTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 10699 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
| 10700 | mPhoneDataConnectionsTimer[i].readSummaryFromParcelLocked(in); |
| 10701 | } |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 10702 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 10703 | mNetworkByteActivityCounters[i].readSummaryFromParcelLocked(in); |
| 10704 | mNetworkPacketActivityCounters[i].readSummaryFromParcelLocked(in); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 10705 | } |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 10706 | mMobileRadioPowerState = DataConnectionRealTimeInfo.DC_POWER_STATE_LOW; |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 10707 | mMobileRadioActiveTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 10708 | mMobileRadioActivePerAppTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 10709 | mMobileRadioActiveAdjustedTime.readSummaryFromParcelLocked(in); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 10710 | mMobileRadioActiveUnknownTime.readSummaryFromParcelLocked(in); |
| 10711 | mMobileRadioActiveUnknownCount.readSummaryFromParcelLocked(in); |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 10712 | mWifiRadioPowerState = DataConnectionRealTimeInfo.DC_POWER_STATE_LOW; |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 10713 | mWifiOn = false; |
| 10714 | mWifiOnTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 10715 | mGlobalWifiRunning = false; |
| 10716 | mGlobalWifiRunningTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 10717 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
| 10718 | mWifiStateTimer[i].readSummaryFromParcelLocked(in); |
| 10719 | } |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 10720 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
| 10721 | mWifiSupplStateTimer[i].readSummaryFromParcelLocked(in); |
| 10722 | } |
| 10723 | for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 10724 | mWifiSignalStrengthsTimer[i].readSummaryFromParcelLocked(in); |
| 10725 | } |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 10726 | mWifiActivity.readSummaryFromParcel(in); |
| 10727 | mBluetoothActivity.readSummaryFromParcel(in); |
| 10728 | mModemActivity.readSummaryFromParcel(in); |
| 10729 | mHasWifiReporting = in.readInt() != 0; |
| 10730 | mHasBluetoothReporting = in.readInt() != 0; |
| 10731 | mHasModemReporting = in.readInt() != 0; |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 10732 | |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 10733 | mNumConnectivityChange = mLoadedNumConnectivityChange = in.readInt(); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 10734 | mFlashlightOnNesting = 0; |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 10735 | mFlashlightOnTimer.readSummaryFromParcelLocked(in); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 10736 | mCameraOnNesting = 0; |
| 10737 | mCameraOnTimer.readSummaryFromParcelLocked(in); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 10738 | mBluetoothScanNesting = 0; |
| 10739 | mBluetoothScanTimer.readSummaryFromParcelLocked(in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10740 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 10741 | int NKW = in.readInt(); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 10742 | if (NKW > 10000) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 10743 | throw new ParcelFormatException("File corrupt: too many kernel wake locks " + NKW); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 10744 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 10745 | for (int ikw = 0; ikw < NKW; ikw++) { |
| 10746 | if (in.readInt() != 0) { |
| 10747 | String kwltName = in.readString(); |
| 10748 | getKernelWakelockTimerLocked(kwltName).readSummaryFromParcelLocked(in); |
| 10749 | } |
| 10750 | } |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 10751 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 10752 | int NWR = in.readInt(); |
| 10753 | if (NWR > 10000) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 10754 | throw new ParcelFormatException("File corrupt: too many wakeup reasons " + NWR); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 10755 | } |
| 10756 | for (int iwr = 0; iwr < NWR; iwr++) { |
| 10757 | if (in.readInt() != 0) { |
| 10758 | String reasonName = in.readString(); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 10759 | getWakeupReasonTimerLocked(reasonName).readSummaryFromParcelLocked(in); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 10760 | } |
| 10761 | } |
| 10762 | |
James Carr | 3a22605 | 2016-07-01 14:49:52 -0700 | [diff] [blame] | 10763 | int NMS = in.readInt(); |
| 10764 | for (int ims = 0; ims < NMS; ims++) { |
| 10765 | if (in.readInt() != 0) { |
| 10766 | long kmstName = in.readLong(); |
| 10767 | getKernelMemoryTimerLocked(kmstName).readSummaryFromParcelLocked(in); |
| 10768 | } |
| 10769 | } |
| 10770 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10771 | final int NU = in.readInt(); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 10772 | if (NU > 10000) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 10773 | throw new ParcelFormatException("File corrupt: too many uids " + NU); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 10774 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10775 | for (int iu = 0; iu < NU; iu++) { |
| 10776 | int uid = in.readInt(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 10777 | Uid u = new Uid(this, uid); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10778 | mUidStats.put(uid, u); |
| 10779 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 10780 | u.mWifiRunning = false; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10781 | if (in.readInt() != 0) { |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 10782 | u.mWifiRunningTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10783 | } |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 10784 | u.mFullWifiLockOut = false; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10785 | if (in.readInt() != 0) { |
| 10786 | u.mFullWifiLockTimer.readSummaryFromParcelLocked(in); |
| 10787 | } |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 10788 | u.mWifiScanStarted = false; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10789 | if (in.readInt() != 0) { |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 10790 | u.mWifiScanTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10791 | } |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 10792 | u.mWifiBatchedScanBinStarted = Uid.NO_BATCHED_SCAN_STARTED; |
| 10793 | for (int i = 0; i < Uid.NUM_WIFI_BATCHED_SCAN_BINS; i++) { |
| 10794 | if (in.readInt() != 0) { |
| 10795 | u.makeWifiBatchedScanBin(i, null); |
| 10796 | u.mWifiBatchedScanTimer[i].readSummaryFromParcelLocked(in); |
| 10797 | } |
| 10798 | } |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 10799 | u.mWifiMulticastEnabled = false; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10800 | if (in.readInt() != 0) { |
| 10801 | u.mWifiMulticastTimer.readSummaryFromParcelLocked(in); |
| 10802 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10803 | if (in.readInt() != 0) { |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 10804 | u.createAudioTurnedOnTimerLocked().readSummaryFromParcelLocked(in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10805 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10806 | if (in.readInt() != 0) { |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 10807 | u.createVideoTurnedOnTimerLocked().readSummaryFromParcelLocked(in); |
| 10808 | } |
| 10809 | if (in.readInt() != 0) { |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 10810 | u.createFlashlightTurnedOnTimerLocked().readSummaryFromParcelLocked(in); |
| 10811 | } |
| 10812 | if (in.readInt() != 0) { |
| 10813 | u.createCameraTurnedOnTimerLocked().readSummaryFromParcelLocked(in); |
| 10814 | } |
| 10815 | if (in.readInt() != 0) { |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 10816 | u.createForegroundActivityTimerLocked().readSummaryFromParcelLocked(in); |
| 10817 | } |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 10818 | if (in.readInt() != 0) { |
| 10819 | u.createBluetoothScanTimerLocked().readSummaryFromParcelLocked(in); |
| 10820 | } |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 10821 | u.mProcessState = ActivityManager.PROCESS_STATE_NONEXISTENT; |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 10822 | for (int i = 0; i < Uid.NUM_PROCESS_STATE; i++) { |
| 10823 | if (in.readInt() != 0) { |
| 10824 | u.makeProcessState(i, null); |
| 10825 | u.mProcessStateTimer[i].readSummaryFromParcelLocked(in); |
| 10826 | } |
| 10827 | } |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 10828 | if (in.readInt() != 0) { |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 10829 | u.createVibratorOnTimerLocked().readSummaryFromParcelLocked(in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10830 | } |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 10831 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 10832 | if (in.readInt() != 0) { |
| 10833 | if (u.mUserActivityCounters == null) { |
| 10834 | u.initUserActivityLocked(); |
| 10835 | } |
| 10836 | for (int i=0; i<Uid.NUM_USER_ACTIVITY_TYPES; i++) { |
| 10837 | u.mUserActivityCounters[i].readSummaryFromParcelLocked(in); |
| 10838 | } |
| 10839 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 10840 | |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 10841 | if (in.readInt() != 0) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 10842 | if (u.mNetworkByteActivityCounters == null) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 10843 | u.initNetworkActivityLocked(); |
| 10844 | } |
| 10845 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 10846 | u.mNetworkByteActivityCounters[i].readSummaryFromParcelLocked(in); |
| 10847 | u.mNetworkPacketActivityCounters[i].readSummaryFromParcelLocked(in); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 10848 | } |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 10849 | u.mMobileRadioActiveTime.readSummaryFromParcelLocked(in); |
| 10850 | u.mMobileRadioActiveCount.readSummaryFromParcelLocked(in); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 10851 | } |
| 10852 | |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 10853 | u.mUserCpuTime.readSummaryFromParcelLocked(in); |
| 10854 | u.mSystemCpuTime.readSummaryFromParcelLocked(in); |
Adam Lesinski | a7a4ccc | 2015-06-26 17:43:04 -0700 | [diff] [blame] | 10855 | u.mCpuPower.readSummaryFromParcelLocked(in); |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 10856 | |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 10857 | if (in.readInt() != 0) { |
| 10858 | final int numClusters = in.readInt(); |
| 10859 | if (mPowerProfile != null && mPowerProfile.getNumCpuClusters() != numClusters) { |
| 10860 | throw new ParcelFormatException("Incompatible cpu cluster arrangement"); |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 10861 | } |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 10862 | |
| 10863 | u.mCpuClusterSpeed = new LongSamplingCounter[numClusters][]; |
| 10864 | for (int cluster = 0; cluster < numClusters; cluster++) { |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 10865 | if (in.readInt() != 0) { |
Adam Lesinski | a57a540 | 2015-09-28 10:21:33 -0700 | [diff] [blame] | 10866 | final int NSB = in.readInt(); |
| 10867 | if (mPowerProfile != null && |
| 10868 | mPowerProfile.getNumSpeedStepsInCpuCluster(cluster) != NSB) { |
| 10869 | throw new ParcelFormatException("File corrupt: too many speed bins " + |
| 10870 | NSB); |
| 10871 | } |
| 10872 | |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 10873 | u.mCpuClusterSpeed[cluster] = new LongSamplingCounter[NSB]; |
| 10874 | for (int speed = 0; speed < NSB; speed++) { |
| 10875 | if (in.readInt() != 0) { |
| 10876 | u.mCpuClusterSpeed[cluster][speed] = new LongSamplingCounter( |
| 10877 | mOnBatteryTimeBase); |
| 10878 | u.mCpuClusterSpeed[cluster][speed].readSummaryFromParcelLocked(in); |
| 10879 | } |
| 10880 | } |
Adam Lesinski | a57a540 | 2015-09-28 10:21:33 -0700 | [diff] [blame] | 10881 | } else { |
| 10882 | u.mCpuClusterSpeed[cluster] = null; |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 10883 | } |
| 10884 | } |
| 10885 | } else { |
| 10886 | u.mCpuClusterSpeed = null; |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 10887 | } |
| 10888 | |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 10889 | if (in.readInt() != 0) { |
| 10890 | u.mMobileRadioApWakeupCount = new LongSamplingCounter(mOnBatteryTimeBase); |
| 10891 | u.mMobileRadioApWakeupCount.readSummaryFromParcelLocked(in); |
| 10892 | } else { |
| 10893 | u.mMobileRadioApWakeupCount = null; |
| 10894 | } |
| 10895 | |
| 10896 | if (in.readInt() != 0) { |
| 10897 | u.mWifiRadioApWakeupCount = new LongSamplingCounter(mOnBatteryTimeBase); |
| 10898 | u.mWifiRadioApWakeupCount.readSummaryFromParcelLocked(in); |
| 10899 | } else { |
| 10900 | u.mWifiRadioApWakeupCount = null; |
| 10901 | } |
| 10902 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10903 | int NW = in.readInt(); |
Dianne Hackborn | cb99a72 | 2016-10-03 17:00:02 -0700 | [diff] [blame] | 10904 | if (NW > (MAX_WAKELOCKS_PER_UID+1)) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 10905 | throw new ParcelFormatException("File corrupt: too many wake locks " + NW); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 10906 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10907 | for (int iw = 0; iw < NW; iw++) { |
| 10908 | String wlName = in.readString(); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 10909 | u.readWakeSummaryFromParcelLocked(wlName, in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10910 | } |
| 10911 | |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 10912 | int NS = in.readInt(); |
Dianne Hackborn | cb99a72 | 2016-10-03 17:00:02 -0700 | [diff] [blame] | 10913 | if (NS > (MAX_WAKELOCKS_PER_UID+1)) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 10914 | throw new ParcelFormatException("File corrupt: too many syncs " + NS); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 10915 | } |
| 10916 | for (int is = 0; is < NS; is++) { |
| 10917 | String name = in.readString(); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 10918 | u.readSyncSummaryFromParcelLocked(name, in); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 10919 | } |
| 10920 | |
| 10921 | int NJ = in.readInt(); |
Dianne Hackborn | cb99a72 | 2016-10-03 17:00:02 -0700 | [diff] [blame] | 10922 | if (NJ > (MAX_WAKELOCKS_PER_UID+1)) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 10923 | throw new ParcelFormatException("File corrupt: too many job timers " + NJ); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 10924 | } |
| 10925 | for (int ij = 0; ij < NJ; ij++) { |
| 10926 | String name = in.readString(); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 10927 | u.readJobSummaryFromParcelLocked(name, in); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 10928 | } |
| 10929 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10930 | int NP = in.readInt(); |
Dianne Hackborn | 7b9c56f | 2010-12-07 11:14:53 -0800 | [diff] [blame] | 10931 | if (NP > 1000) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 10932 | throw new ParcelFormatException("File corrupt: too many sensors " + NP); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 10933 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10934 | for (int is = 0; is < NP; is++) { |
| 10935 | int seNumber = in.readInt(); |
| 10936 | if (in.readInt() != 0) { |
| 10937 | u.getSensorTimerLocked(seNumber, true) |
| 10938 | .readSummaryFromParcelLocked(in); |
| 10939 | } |
| 10940 | } |
| 10941 | |
| 10942 | NP = in.readInt(); |
Dianne Hackborn | 7b9c56f | 2010-12-07 11:14:53 -0800 | [diff] [blame] | 10943 | if (NP > 1000) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 10944 | throw new ParcelFormatException("File corrupt: too many processes " + NP); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 10945 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10946 | for (int ip = 0; ip < NP; ip++) { |
| 10947 | String procName = in.readString(); |
| 10948 | Uid.Proc p = u.getProcessStatsLocked(procName); |
| 10949 | p.mUserTime = p.mLoadedUserTime = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10950 | p.mSystemTime = p.mLoadedSystemTime = in.readLong(); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 10951 | p.mForegroundTime = p.mLoadedForegroundTime = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10952 | p.mStarts = p.mLoadedStarts = in.readInt(); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 10953 | p.mNumCrashes = p.mLoadedNumCrashes = in.readInt(); |
| 10954 | p.mNumAnrs = p.mLoadedNumAnrs = in.readInt(); |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 10955 | p.readExcessivePowerFromParcelLocked(in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10956 | } |
| 10957 | |
| 10958 | NP = in.readInt(); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 10959 | if (NP > 10000) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 10960 | throw new ParcelFormatException("File corrupt: too many packages " + NP); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 10961 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10962 | for (int ip = 0; ip < NP; ip++) { |
| 10963 | String pkgName = in.readString(); |
| 10964 | Uid.Pkg p = u.getPackageStatsLocked(pkgName); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 10965 | final int NWA = in.readInt(); |
| 10966 | if (NWA > 1000) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 10967 | throw new ParcelFormatException("File corrupt: too many wakeup alarms " + NWA); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 10968 | } |
| 10969 | p.mWakeupAlarms.clear(); |
| 10970 | for (int iwa=0; iwa<NWA; iwa++) { |
| 10971 | String tag = in.readString(); |
| 10972 | Counter c = new Counter(mOnBatteryTimeBase); |
| 10973 | c.readSummaryFromParcelLocked(in); |
| 10974 | p.mWakeupAlarms.put(tag, c); |
| 10975 | } |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 10976 | NS = in.readInt(); |
Dianne Hackborn | 7b9c56f | 2010-12-07 11:14:53 -0800 | [diff] [blame] | 10977 | if (NS > 1000) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 10978 | throw new ParcelFormatException("File corrupt: too many services " + NS); |
Dianne Hackborn | 7b9c56f | 2010-12-07 11:14:53 -0800 | [diff] [blame] | 10979 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10980 | for (int is = 0; is < NS; is++) { |
| 10981 | String servName = in.readString(); |
| 10982 | Uid.Pkg.Serv s = u.getServiceStatsLocked(pkgName, servName); |
| 10983 | s.mStartTime = s.mLoadedStartTime = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10984 | s.mStarts = s.mLoadedStarts = in.readInt(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10985 | s.mLaunches = s.mLoadedLaunches = in.readInt(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10986 | } |
| 10987 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10988 | } |
| 10989 | } |
| 10990 | |
| 10991 | /** |
| 10992 | * Writes a summary of the statistics to a Parcel, in a format suitable to be written to |
| 10993 | * disk. This format does not allow a lossless round-trip. |
| 10994 | * |
| 10995 | * @param out the Parcel to be written to. |
| 10996 | */ |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 10997 | public void writeSummaryToParcel(Parcel out, boolean inclHistory) { |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 10998 | pullPendingStateUpdatesLocked(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 10999 | |
Dianne Hackborn | 7d9eefd | 2014-08-27 18:30:31 -0700 | [diff] [blame] | 11000 | // Pull the clock time. This may update the time and make a new history entry |
| 11001 | // if we had originally pulled a time before the RTC was set. |
| 11002 | long startClockTime = getStartClockTime(); |
| 11003 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 11004 | final long NOW_SYS = mClocks.uptimeMillis() * 1000; |
| 11005 | final long NOWREAL_SYS = mClocks.elapsedRealtime() * 1000; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11006 | |
| 11007 | out.writeInt(VERSION); |
| 11008 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 11009 | writeHistory(out, inclHistory, true); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 11010 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11011 | out.writeInt(mStartCount); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 11012 | out.writeLong(computeUptime(NOW_SYS, STATS_SINCE_CHARGED)); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 11013 | out.writeLong(computeRealtime(NOWREAL_SYS, STATS_SINCE_CHARGED)); |
Dianne Hackborn | 7d9eefd | 2014-08-27 18:30:31 -0700 | [diff] [blame] | 11014 | out.writeLong(startClockTime); |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 11015 | out.writeString(mStartPlatformVersion); |
| 11016 | out.writeString(mEndPlatformVersion); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 11017 | mOnBatteryTimeBase.writeSummaryToParcel(out, NOW_SYS, NOWREAL_SYS); |
| 11018 | mOnBatteryScreenOffTimeBase.writeSummaryToParcel(out, NOW_SYS, NOWREAL_SYS); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 11019 | out.writeInt(mDischargeUnplugLevel); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 11020 | out.writeInt(mDischargePlugLevel); |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 11021 | out.writeInt(mDischargeCurrentLevel); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 11022 | out.writeInt(mCurrentBatteryLevel); |
Adam Lesinski | f9b20a9 | 2016-06-17 17:30:01 -0700 | [diff] [blame] | 11023 | out.writeInt(mEstimatedBatteryCapacity); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 11024 | out.writeInt(getLowDischargeAmountSinceCharge()); |
| 11025 | out.writeInt(getHighDischargeAmountSinceCharge()); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 11026 | out.writeInt(getDischargeAmountScreenOnSinceCharge()); |
| 11027 | out.writeInt(getDischargeAmountScreenOffSinceCharge()); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 11028 | mDischargeStepTracker.writeToParcel(out); |
| 11029 | mChargeStepTracker.writeToParcel(out); |
| 11030 | mDailyDischargeStepTracker.writeToParcel(out); |
| 11031 | mDailyChargeStepTracker.writeToParcel(out); |
Adam Lesinski | 67c134f | 2016-06-10 15:15:08 -0700 | [diff] [blame] | 11032 | mDischargeCounter.writeSummaryFromParcelLocked(out); |
| 11033 | mDischargeScreenOffCounter.writeSummaryFromParcelLocked(out); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 11034 | if (mDailyPackageChanges != null) { |
| 11035 | final int NPKG = mDailyPackageChanges.size(); |
| 11036 | out.writeInt(NPKG); |
| 11037 | for (int i=0; i<NPKG; i++) { |
| 11038 | PackageChange pc = mDailyPackageChanges.get(i); |
| 11039 | out.writeString(pc.mPackageName); |
| 11040 | out.writeInt(pc.mUpdate ? 1 : 0); |
| 11041 | out.writeInt(pc.mVersionCode); |
| 11042 | } |
| 11043 | } else { |
| 11044 | out.writeInt(0); |
| 11045 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 11046 | out.writeLong(mDailyStartTime); |
| 11047 | out.writeLong(mNextMinDailyDeadline); |
| 11048 | out.writeLong(mNextMaxDailyDeadline); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 11049 | |
| 11050 | mScreenOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 11051 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 11052 | mScreenBrightnessTimer[i].writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 11053 | } |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 11054 | mInteractiveTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 11055 | mPowerSaveModeEnabledTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 11056 | out.writeLong(mLongestLightIdleTime); |
| 11057 | out.writeLong(mLongestFullIdleTime); |
| 11058 | mDeviceIdleModeLightTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 11059 | mDeviceIdleModeFullTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 11060 | mDeviceLightIdlingTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 11061 | mDeviceIdlingTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 11062 | mPhoneOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 11063 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 11064 | mPhoneSignalStrengthsTimer[i].writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 11065 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 11066 | mPhoneSignalScanningTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 11067 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 11068 | mPhoneDataConnectionsTimer[i].writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 11069 | } |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 11070 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 11071 | mNetworkByteActivityCounters[i].writeSummaryFromParcelLocked(out); |
| 11072 | mNetworkPacketActivityCounters[i].writeSummaryFromParcelLocked(out); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 11073 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 11074 | mMobileRadioActiveTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 11075 | mMobileRadioActivePerAppTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 11076 | mMobileRadioActiveAdjustedTime.writeSummaryFromParcelLocked(out); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 11077 | mMobileRadioActiveUnknownTime.writeSummaryFromParcelLocked(out); |
| 11078 | mMobileRadioActiveUnknownCount.writeSummaryFromParcelLocked(out); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 11079 | mWifiOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 11080 | mGlobalWifiRunningTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 11081 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 11082 | mWifiStateTimer[i].writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 11083 | } |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 11084 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
| 11085 | mWifiSupplStateTimer[i].writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 11086 | } |
| 11087 | for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 11088 | mWifiSignalStrengthsTimer[i].writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 11089 | } |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 11090 | mWifiActivity.writeSummaryToParcel(out); |
| 11091 | mBluetoothActivity.writeSummaryToParcel(out); |
| 11092 | mModemActivity.writeSummaryToParcel(out); |
| 11093 | out.writeInt(mHasWifiReporting ? 1 : 0); |
| 11094 | out.writeInt(mHasBluetoothReporting ? 1 : 0); |
| 11095 | out.writeInt(mHasModemReporting ? 1 : 0); |
| 11096 | |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 11097 | out.writeInt(mNumConnectivityChange); |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 11098 | mFlashlightOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 11099 | mCameraOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 11100 | mBluetoothScanTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11101 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 11102 | out.writeInt(mKernelWakelockStats.size()); |
| 11103 | for (Map.Entry<String, SamplingTimer> ent : mKernelWakelockStats.entrySet()) { |
| 11104 | Timer kwlt = ent.getValue(); |
| 11105 | if (kwlt != null) { |
| 11106 | out.writeInt(1); |
| 11107 | out.writeString(ent.getKey()); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 11108 | kwlt.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 11109 | } else { |
| 11110 | out.writeInt(0); |
| 11111 | } |
| 11112 | } |
| 11113 | |
| 11114 | out.writeInt(mWakeupReasonStats.size()); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 11115 | for (Map.Entry<String, SamplingTimer> ent : mWakeupReasonStats.entrySet()) { |
| 11116 | SamplingTimer timer = ent.getValue(); |
| 11117 | if (timer != null) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 11118 | out.writeInt(1); |
| 11119 | out.writeString(ent.getKey()); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 11120 | timer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 11121 | } else { |
| 11122 | out.writeInt(0); |
| 11123 | } |
| 11124 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 11125 | |
James Carr | 3a22605 | 2016-07-01 14:49:52 -0700 | [diff] [blame] | 11126 | out.writeInt(mKernelMemoryStats.size()); |
| 11127 | for (int i = 0; i < mKernelMemoryStats.size(); i++) { |
| 11128 | Timer kmt = mKernelMemoryStats.valueAt(i); |
| 11129 | if (kmt != null) { |
| 11130 | out.writeInt(1); |
| 11131 | out.writeLong(mKernelMemoryStats.keyAt(i)); |
| 11132 | kmt.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 11133 | } else { |
| 11134 | out.writeInt(0); |
| 11135 | } |
| 11136 | } |
| 11137 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11138 | final int NU = mUidStats.size(); |
| 11139 | out.writeInt(NU); |
| 11140 | for (int iu = 0; iu < NU; iu++) { |
| 11141 | out.writeInt(mUidStats.keyAt(iu)); |
| 11142 | Uid u = mUidStats.valueAt(iu); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 11143 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 11144 | if (u.mWifiRunningTimer != null) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 11145 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 11146 | u.mWifiRunningTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 11147 | } else { |
| 11148 | out.writeInt(0); |
| 11149 | } |
| 11150 | if (u.mFullWifiLockTimer != null) { |
| 11151 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 11152 | u.mFullWifiLockTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 11153 | } else { |
| 11154 | out.writeInt(0); |
| 11155 | } |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 11156 | if (u.mWifiScanTimer != null) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 11157 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 11158 | u.mWifiScanTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 11159 | } else { |
| 11160 | out.writeInt(0); |
| 11161 | } |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 11162 | for (int i = 0; i < Uid.NUM_WIFI_BATCHED_SCAN_BINS; i++) { |
| 11163 | if (u.mWifiBatchedScanTimer[i] != null) { |
| 11164 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 11165 | u.mWifiBatchedScanTimer[i].writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 11166 | } else { |
| 11167 | out.writeInt(0); |
| 11168 | } |
| 11169 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 11170 | if (u.mWifiMulticastTimer != null) { |
| 11171 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 11172 | u.mWifiMulticastTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 11173 | } else { |
| 11174 | out.writeInt(0); |
| 11175 | } |
| 11176 | if (u.mAudioTurnedOnTimer != null) { |
| 11177 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 11178 | u.mAudioTurnedOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 11179 | } else { |
| 11180 | out.writeInt(0); |
| 11181 | } |
| 11182 | if (u.mVideoTurnedOnTimer != null) { |
| 11183 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 11184 | u.mVideoTurnedOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 11185 | } else { |
| 11186 | out.writeInt(0); |
| 11187 | } |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 11188 | if (u.mFlashlightTurnedOnTimer != null) { |
| 11189 | out.writeInt(1); |
| 11190 | u.mFlashlightTurnedOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 11191 | } else { |
| 11192 | out.writeInt(0); |
| 11193 | } |
| 11194 | if (u.mCameraTurnedOnTimer != null) { |
| 11195 | out.writeInt(1); |
| 11196 | u.mCameraTurnedOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 11197 | } else { |
| 11198 | out.writeInt(0); |
| 11199 | } |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 11200 | if (u.mForegroundActivityTimer != null) { |
| 11201 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 11202 | u.mForegroundActivityTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 11203 | } else { |
| 11204 | out.writeInt(0); |
| 11205 | } |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 11206 | if (u.mBluetoothScanTimer != null) { |
| 11207 | out.writeInt(1); |
| 11208 | u.mBluetoothScanTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 11209 | } else { |
| 11210 | out.writeInt(0); |
| 11211 | } |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 11212 | for (int i = 0; i < Uid.NUM_PROCESS_STATE; i++) { |
| 11213 | if (u.mProcessStateTimer[i] != null) { |
| 11214 | out.writeInt(1); |
| 11215 | u.mProcessStateTimer[i].writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 11216 | } else { |
| 11217 | out.writeInt(0); |
| 11218 | } |
| 11219 | } |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 11220 | if (u.mVibratorOnTimer != null) { |
| 11221 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 11222 | u.mVibratorOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 11223 | } else { |
| 11224 | out.writeInt(0); |
| 11225 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11226 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 11227 | if (u.mUserActivityCounters == null) { |
| 11228 | out.writeInt(0); |
| 11229 | } else { |
| 11230 | out.writeInt(1); |
| 11231 | for (int i=0; i<Uid.NUM_USER_ACTIVITY_TYPES; i++) { |
| 11232 | u.mUserActivityCounters[i].writeSummaryFromParcelLocked(out); |
| 11233 | } |
| 11234 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 11235 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 11236 | if (u.mNetworkByteActivityCounters == null) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 11237 | out.writeInt(0); |
| 11238 | } else { |
| 11239 | out.writeInt(1); |
| 11240 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 11241 | u.mNetworkByteActivityCounters[i].writeSummaryFromParcelLocked(out); |
| 11242 | u.mNetworkPacketActivityCounters[i].writeSummaryFromParcelLocked(out); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 11243 | } |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 11244 | u.mMobileRadioActiveTime.writeSummaryFromParcelLocked(out); |
| 11245 | u.mMobileRadioActiveCount.writeSummaryFromParcelLocked(out); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 11246 | } |
| 11247 | |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 11248 | u.mUserCpuTime.writeSummaryFromParcelLocked(out); |
| 11249 | u.mSystemCpuTime.writeSummaryFromParcelLocked(out); |
Adam Lesinski | a7a4ccc | 2015-06-26 17:43:04 -0700 | [diff] [blame] | 11250 | u.mCpuPower.writeSummaryFromParcelLocked(out); |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 11251 | |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 11252 | if (u.mCpuClusterSpeed != null) { |
| 11253 | out.writeInt(1); |
| 11254 | out.writeInt(u.mCpuClusterSpeed.length); |
| 11255 | for (LongSamplingCounter[] cpuSpeeds : u.mCpuClusterSpeed) { |
| 11256 | if (cpuSpeeds != null) { |
| 11257 | out.writeInt(1); |
| 11258 | out.writeInt(cpuSpeeds.length); |
| 11259 | for (LongSamplingCounter c : cpuSpeeds) { |
| 11260 | if (c != null) { |
| 11261 | out.writeInt(1); |
| 11262 | c.writeSummaryFromParcelLocked(out); |
| 11263 | } else { |
| 11264 | out.writeInt(0); |
| 11265 | } |
| 11266 | } |
| 11267 | } else { |
| 11268 | out.writeInt(0); |
| 11269 | } |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 11270 | } |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 11271 | } else { |
| 11272 | out.writeInt(0); |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 11273 | } |
| 11274 | |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 11275 | if (u.mMobileRadioApWakeupCount != null) { |
| 11276 | out.writeInt(1); |
| 11277 | u.mMobileRadioApWakeupCount.writeSummaryFromParcelLocked(out); |
| 11278 | } else { |
| 11279 | out.writeInt(0); |
| 11280 | } |
| 11281 | |
| 11282 | if (u.mWifiRadioApWakeupCount != null) { |
| 11283 | out.writeInt(1); |
| 11284 | u.mWifiRadioApWakeupCount.writeSummaryFromParcelLocked(out); |
| 11285 | } else { |
| 11286 | out.writeInt(0); |
| 11287 | } |
| 11288 | |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 11289 | final ArrayMap<String, Uid.Wakelock> wakeStats = u.mWakelockStats.getMap(); |
| 11290 | int NW = wakeStats.size(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11291 | out.writeInt(NW); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 11292 | for (int iw=0; iw<NW; iw++) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 11293 | out.writeString(wakeStats.keyAt(iw)); |
| 11294 | Uid.Wakelock wl = wakeStats.valueAt(iw); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 11295 | if (wl.mTimerFull != null) { |
| 11296 | out.writeInt(1); |
| 11297 | wl.mTimerFull.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 11298 | } else { |
| 11299 | out.writeInt(0); |
| 11300 | } |
| 11301 | if (wl.mTimerPartial != null) { |
| 11302 | out.writeInt(1); |
| 11303 | wl.mTimerPartial.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 11304 | } else { |
| 11305 | out.writeInt(0); |
| 11306 | } |
| 11307 | if (wl.mTimerWindow != null) { |
| 11308 | out.writeInt(1); |
| 11309 | wl.mTimerWindow.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 11310 | } else { |
| 11311 | out.writeInt(0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11312 | } |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 11313 | if (wl.mTimerDraw != null) { |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 11314 | out.writeInt(1); |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 11315 | wl.mTimerDraw.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 11316 | } else { |
| 11317 | out.writeInt(0); |
| 11318 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11319 | } |
| 11320 | |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 11321 | final ArrayMap<String, StopwatchTimer> syncStats = u.mSyncStats.getMap(); |
| 11322 | int NS = syncStats.size(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 11323 | out.writeInt(NS); |
| 11324 | for (int is=0; is<NS; is++) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 11325 | out.writeString(syncStats.keyAt(is)); |
| 11326 | syncStats.valueAt(is).writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 11327 | } |
| 11328 | |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 11329 | final ArrayMap<String, StopwatchTimer> jobStats = u.mJobStats.getMap(); |
| 11330 | int NJ = jobStats.size(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 11331 | out.writeInt(NJ); |
| 11332 | for (int ij=0; ij<NJ; ij++) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 11333 | out.writeString(jobStats.keyAt(ij)); |
| 11334 | jobStats.valueAt(ij).writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 11335 | } |
| 11336 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11337 | int NSE = u.mSensorStats.size(); |
| 11338 | out.writeInt(NSE); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 11339 | for (int ise=0; ise<NSE; ise++) { |
| 11340 | out.writeInt(u.mSensorStats.keyAt(ise)); |
| 11341 | Uid.Sensor se = u.mSensorStats.valueAt(ise); |
| 11342 | if (se.mTimer != null) { |
| 11343 | out.writeInt(1); |
| 11344 | se.mTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 11345 | } else { |
| 11346 | out.writeInt(0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11347 | } |
| 11348 | } |
| 11349 | |
| 11350 | int NP = u.mProcessStats.size(); |
| 11351 | out.writeInt(NP); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 11352 | for (int ip=0; ip<NP; ip++) { |
| 11353 | out.writeString(u.mProcessStats.keyAt(ip)); |
| 11354 | Uid.Proc ps = u.mProcessStats.valueAt(ip); |
| 11355 | out.writeLong(ps.mUserTime); |
| 11356 | out.writeLong(ps.mSystemTime); |
| 11357 | out.writeLong(ps.mForegroundTime); |
| 11358 | out.writeInt(ps.mStarts); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 11359 | out.writeInt(ps.mNumCrashes); |
| 11360 | out.writeInt(ps.mNumAnrs); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 11361 | ps.writeExcessivePowerToParcelLocked(out); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11362 | } |
| 11363 | |
| 11364 | NP = u.mPackageStats.size(); |
| 11365 | out.writeInt(NP); |
| 11366 | if (NP > 0) { |
| 11367 | for (Map.Entry<String, BatteryStatsImpl.Uid.Pkg> ent |
| 11368 | : u.mPackageStats.entrySet()) { |
| 11369 | out.writeString(ent.getKey()); |
| 11370 | Uid.Pkg ps = ent.getValue(); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 11371 | final int NWA = ps.mWakeupAlarms.size(); |
| 11372 | out.writeInt(NWA); |
| 11373 | for (int iwa=0; iwa<NWA; iwa++) { |
| 11374 | out.writeString(ps.mWakeupAlarms.keyAt(iwa)); |
| 11375 | ps.mWakeupAlarms.valueAt(iwa).writeSummaryFromParcelLocked(out); |
| 11376 | } |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 11377 | NS = ps.mServiceStats.size(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11378 | out.writeInt(NS); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 11379 | for (int is=0; is<NS; is++) { |
| 11380 | out.writeString(ps.mServiceStats.keyAt(is)); |
| 11381 | BatteryStatsImpl.Uid.Pkg.Serv ss = ps.mServiceStats.valueAt(is); |
| 11382 | long time = ss.getStartTimeToNowLocked( |
| 11383 | mOnBatteryTimeBase.getUptime(NOW_SYS)); |
| 11384 | out.writeLong(time); |
| 11385 | out.writeInt(ss.mStarts); |
| 11386 | out.writeInt(ss.mLaunches); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11387 | } |
| 11388 | } |
| 11389 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11390 | } |
| 11391 | } |
| 11392 | |
| 11393 | public void readFromParcel(Parcel in) { |
| 11394 | readFromParcelLocked(in); |
| 11395 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 11396 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11397 | void readFromParcelLocked(Parcel in) { |
| 11398 | int magic = in.readInt(); |
| 11399 | if (magic != MAGIC) { |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 11400 | throw new ParcelFormatException("Bad magic number: #" + Integer.toHexString(magic)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11401 | } |
| 11402 | |
Dianne Hackborn | ae38445 | 2011-06-28 12:33:48 -0700 | [diff] [blame] | 11403 | readHistory(in, false); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 11404 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11405 | mStartCount = in.readInt(); |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 11406 | mStartClockTime = in.readLong(); |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 11407 | mStartPlatformVersion = in.readString(); |
| 11408 | mEndPlatformVersion = in.readString(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11409 | mUptime = in.readLong(); |
| 11410 | mUptimeStart = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11411 | mRealtime = in.readLong(); |
| 11412 | mRealtimeStart = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11413 | mOnBattery = in.readInt() != 0; |
Adam Lesinski | f9b20a9 | 2016-06-17 17:30:01 -0700 | [diff] [blame] | 11414 | mEstimatedBatteryCapacity = in.readInt(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11415 | mOnBatteryInternal = false; // we are no longer really running. |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 11416 | mOnBatteryTimeBase.readFromParcel(in); |
| 11417 | mOnBatteryScreenOffTimeBase.readFromParcel(in); |
| 11418 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 11419 | mScreenState = Display.STATE_UNKNOWN; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 11420 | mScreenOnTimer = new StopwatchTimer(mClocks, null, -1, null, mOnBatteryTimeBase, in); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 11421 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 11422 | mScreenBrightnessTimer[i] = new StopwatchTimer(mClocks, null, -100-i, null, |
| 11423 | mOnBatteryTimeBase, in); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 11424 | } |
Dianne Hackborn | 2932513 | 2014-05-21 15:01:03 -0700 | [diff] [blame] | 11425 | mInteractive = false; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 11426 | mInteractiveTimer = new StopwatchTimer(mClocks, null, -10, null, mOnBatteryTimeBase, in); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 11427 | mPhoneOn = false; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 11428 | mPowerSaveModeEnabledTimer = new StopwatchTimer(mClocks, null, -2, null, |
| 11429 | mOnBatteryTimeBase, in); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 11430 | mLongestLightIdleTime = in.readLong(); |
| 11431 | mLongestFullIdleTime = in.readLong(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 11432 | mDeviceIdleModeLightTimer = new StopwatchTimer(mClocks, null, -14, null, |
| 11433 | mOnBatteryTimeBase, in); |
| 11434 | mDeviceIdleModeFullTimer = new StopwatchTimer(mClocks, null, -11, null, |
| 11435 | mOnBatteryTimeBase, in); |
| 11436 | mDeviceLightIdlingTimer = new StopwatchTimer(mClocks, null, -15, null, |
| 11437 | mOnBatteryTimeBase, in); |
| 11438 | mDeviceIdlingTimer = new StopwatchTimer(mClocks, null, -12, null, mOnBatteryTimeBase, in); |
| 11439 | mPhoneOnTimer = new StopwatchTimer(mClocks, null, -3, null, mOnBatteryTimeBase, in); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 11440 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 11441 | mPhoneSignalStrengthsTimer[i] = new StopwatchTimer(mClocks, null, -200-i, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 11442 | null, mOnBatteryTimeBase, in); |
| 11443 | } |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 11444 | mPhoneSignalScanningTimer = new StopwatchTimer(mClocks, null, -200+1, null, |
| 11445 | mOnBatteryTimeBase, in); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 11446 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 11447 | mPhoneDataConnectionsTimer[i] = new StopwatchTimer(mClocks, null, -300-i, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 11448 | null, mOnBatteryTimeBase, in); |
| 11449 | } |
| 11450 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
| 11451 | mNetworkByteActivityCounters[i] = new LongSamplingCounter(mOnBatteryTimeBase, in); |
| 11452 | mNetworkPacketActivityCounters[i] = new LongSamplingCounter(mOnBatteryTimeBase, in); |
| 11453 | } |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 11454 | mMobileRadioPowerState = DataConnectionRealTimeInfo.DC_POWER_STATE_LOW; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 11455 | mMobileRadioActiveTimer = new StopwatchTimer(mClocks, null, -400, null, |
| 11456 | mOnBatteryTimeBase, in); |
| 11457 | mMobileRadioActivePerAppTimer = new StopwatchTimer(mClocks, null, -401, null, |
| 11458 | mOnBatteryTimeBase, in); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 11459 | mMobileRadioActiveAdjustedTime = new LongSamplingCounter(mOnBatteryTimeBase, in); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 11460 | mMobileRadioActiveUnknownTime = new LongSamplingCounter(mOnBatteryTimeBase, in); |
| 11461 | mMobileRadioActiveUnknownCount = new LongSamplingCounter(mOnBatteryTimeBase, in); |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 11462 | mWifiRadioPowerState = DataConnectionRealTimeInfo.DC_POWER_STATE_LOW; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 11463 | mWifiOn = false; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 11464 | mWifiOnTimer = new StopwatchTimer(mClocks, null, -4, null, mOnBatteryTimeBase, in); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 11465 | mGlobalWifiRunning = false; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 11466 | mGlobalWifiRunningTimer = new StopwatchTimer(mClocks, null, -5, null, |
| 11467 | mOnBatteryTimeBase, in); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 11468 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 11469 | mWifiStateTimer[i] = new StopwatchTimer(mClocks, null, -600-i, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 11470 | null, mOnBatteryTimeBase, in); |
| 11471 | } |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 11472 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 11473 | mWifiSupplStateTimer[i] = new StopwatchTimer(mClocks, null, -700-i, |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 11474 | null, mOnBatteryTimeBase, in); |
| 11475 | } |
| 11476 | for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 11477 | mWifiSignalStrengthsTimer[i] = new StopwatchTimer(mClocks, null, -800-i, |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 11478 | null, mOnBatteryTimeBase, in); |
| 11479 | } |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 11480 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 11481 | mWifiActivity = new ControllerActivityCounterImpl(mOnBatteryTimeBase, |
| 11482 | NUM_WIFI_TX_LEVELS, in); |
| 11483 | mBluetoothActivity = new ControllerActivityCounterImpl(mOnBatteryTimeBase, |
| 11484 | NUM_BT_TX_LEVELS, in); |
| 11485 | mModemActivity = new ControllerActivityCounterImpl(mOnBatteryTimeBase, |
| 11486 | ModemActivityInfo.TX_POWER_LEVELS, in); |
| 11487 | mHasWifiReporting = in.readInt() != 0; |
| 11488 | mHasBluetoothReporting = in.readInt() != 0; |
| 11489 | mHasModemReporting = in.readInt() != 0; |
| 11490 | |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 11491 | mNumConnectivityChange = in.readInt(); |
| 11492 | mLoadedNumConnectivityChange = in.readInt(); |
| 11493 | mUnpluggedNumConnectivityChange = in.readInt(); |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 11494 | mAudioOnNesting = 0; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 11495 | mAudioOnTimer = new StopwatchTimer(mClocks, null, -7, null, mOnBatteryTimeBase); |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 11496 | mVideoOnNesting = 0; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 11497 | mVideoOnTimer = new StopwatchTimer(mClocks, null, -8, null, mOnBatteryTimeBase); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 11498 | mFlashlightOnNesting = 0; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 11499 | mFlashlightOnTimer = new StopwatchTimer(mClocks, null, -9, null, mOnBatteryTimeBase, in); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 11500 | mCameraOnNesting = 0; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 11501 | mCameraOnTimer = new StopwatchTimer(mClocks, null, -13, null, mOnBatteryTimeBase, in); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 11502 | mBluetoothScanNesting = 0; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 11503 | mBluetoothScanTimer = new StopwatchTimer(mClocks, null, -14, null, mOnBatteryTimeBase, in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 11504 | mDischargeUnplugLevel = in.readInt(); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 11505 | mDischargePlugLevel = in.readInt(); |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 11506 | mDischargeCurrentLevel = in.readInt(); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 11507 | mCurrentBatteryLevel = in.readInt(); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 11508 | mLowDischargeAmountSinceCharge = in.readInt(); |
| 11509 | mHighDischargeAmountSinceCharge = in.readInt(); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 11510 | mDischargeAmountScreenOn = in.readInt(); |
| 11511 | mDischargeAmountScreenOnSinceCharge = in.readInt(); |
| 11512 | mDischargeAmountScreenOff = in.readInt(); |
| 11513 | mDischargeAmountScreenOffSinceCharge = in.readInt(); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 11514 | mDischargeStepTracker.readFromParcel(in); |
| 11515 | mChargeStepTracker.readFromParcel(in); |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 11516 | mDischargeCounter = new LongSamplingCounter(mOnBatteryTimeBase, in); |
| 11517 | mDischargeScreenOffCounter = new LongSamplingCounter(mOnBatteryTimeBase, in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11518 | mLastWriteTime = in.readLong(); |
| 11519 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 11520 | mKernelWakelockStats.clear(); |
| 11521 | int NKW = in.readInt(); |
| 11522 | for (int ikw = 0; ikw < NKW; ikw++) { |
| 11523 | if (in.readInt() != 0) { |
| 11524 | String wakelockName = in.readString(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 11525 | SamplingTimer kwlt = new SamplingTimer(mClocks, mOnBatteryScreenOffTimeBase, in); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 11526 | mKernelWakelockStats.put(wakelockName, kwlt); |
| 11527 | } |
| 11528 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 11529 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 11530 | mWakeupReasonStats.clear(); |
| 11531 | int NWR = in.readInt(); |
| 11532 | for (int iwr = 0; iwr < NWR; iwr++) { |
| 11533 | if (in.readInt() != 0) { |
| 11534 | String reasonName = in.readString(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 11535 | SamplingTimer timer = new SamplingTimer(mClocks, mOnBatteryTimeBase, in); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 11536 | mWakeupReasonStats.put(reasonName, timer); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 11537 | } |
| 11538 | } |
| 11539 | |
James Carr | 3a22605 | 2016-07-01 14:49:52 -0700 | [diff] [blame] | 11540 | mKernelMemoryStats.clear(); |
| 11541 | int nmt = in.readInt(); |
| 11542 | for (int imt = 0; imt < nmt; imt++) { |
| 11543 | if (in.readInt() != 0) { |
| 11544 | Long bucket = in.readLong(); |
| 11545 | SamplingTimer kmt = new SamplingTimer(mClocks, mOnBatteryTimeBase, in); |
| 11546 | mKernelMemoryStats.put(bucket, kmt); |
| 11547 | } |
| 11548 | } |
| 11549 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11550 | mPartialTimers.clear(); |
| 11551 | mFullTimers.clear(); |
| 11552 | mWindowTimers.clear(); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 11553 | mWifiRunningTimers.clear(); |
| 11554 | mFullWifiLockTimers.clear(); |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 11555 | mWifiScanTimers.clear(); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 11556 | mWifiBatchedScanTimers.clear(); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 11557 | mWifiMulticastTimers.clear(); |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 11558 | mAudioTurnedOnTimers.clear(); |
| 11559 | mVideoTurnedOnTimers.clear(); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 11560 | mFlashlightTurnedOnTimers.clear(); |
| 11561 | mCameraTurnedOnTimers.clear(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11562 | |
| 11563 | int numUids = in.readInt(); |
| 11564 | mUidStats.clear(); |
| 11565 | for (int i = 0; i < numUids; i++) { |
| 11566 | int uid = in.readInt(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 11567 | Uid u = new Uid(this, uid); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 11568 | u.readFromParcelLocked(mOnBatteryTimeBase, mOnBatteryScreenOffTimeBase, in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11569 | mUidStats.append(uid, u); |
| 11570 | } |
| 11571 | } |
| 11572 | |
| 11573 | public void writeToParcel(Parcel out, int flags) { |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 11574 | writeToParcelLocked(out, true, flags); |
| 11575 | } |
| 11576 | |
| 11577 | public void writeToParcelWithoutUids(Parcel out, int flags) { |
| 11578 | writeToParcelLocked(out, false, flags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11579 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 11580 | |
| 11581 | @SuppressWarnings("unused") |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 11582 | void writeToParcelLocked(Parcel out, boolean inclUids, int flags) { |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 11583 | // Need to update with current kernel wake lock counts. |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 11584 | pullPendingStateUpdatesLocked(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 11585 | |
Dianne Hackborn | 7d9eefd | 2014-08-27 18:30:31 -0700 | [diff] [blame] | 11586 | // Pull the clock time. This may update the time and make a new history entry |
| 11587 | // if we had originally pulled a time before the RTC was set. |
| 11588 | long startClockTime = getStartClockTime(); |
| 11589 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 11590 | final long uSecUptime = mClocks.uptimeMillis() * 1000; |
| 11591 | final long uSecRealtime = mClocks.elapsedRealtime() * 1000; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 11592 | final long batteryRealtime = mOnBatteryTimeBase.getRealtime(uSecRealtime); |
| 11593 | final long batteryScreenOffRealtime = mOnBatteryScreenOffTimeBase.getRealtime(uSecRealtime); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 11594 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11595 | out.writeInt(MAGIC); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 11596 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 11597 | writeHistory(out, true, false); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 11598 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11599 | out.writeInt(mStartCount); |
Dianne Hackborn | 7d9eefd | 2014-08-27 18:30:31 -0700 | [diff] [blame] | 11600 | out.writeLong(startClockTime); |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 11601 | out.writeString(mStartPlatformVersion); |
| 11602 | out.writeString(mEndPlatformVersion); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11603 | out.writeLong(mUptime); |
| 11604 | out.writeLong(mUptimeStart); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11605 | out.writeLong(mRealtime); |
| 11606 | out.writeLong(mRealtimeStart); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11607 | out.writeInt(mOnBattery ? 1 : 0); |
Adam Lesinski | f9b20a9 | 2016-06-17 17:30:01 -0700 | [diff] [blame] | 11608 | out.writeInt(mEstimatedBatteryCapacity); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 11609 | mOnBatteryTimeBase.writeToParcel(out, uSecUptime, uSecRealtime); |
| 11610 | mOnBatteryScreenOffTimeBase.writeToParcel(out, uSecUptime, uSecRealtime); |
| 11611 | |
| 11612 | mScreenOnTimer.writeToParcel(out, uSecRealtime); |
| 11613 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
| 11614 | mScreenBrightnessTimer[i].writeToParcel(out, uSecRealtime); |
| 11615 | } |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 11616 | mInteractiveTimer.writeToParcel(out, uSecRealtime); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 11617 | mPowerSaveModeEnabledTimer.writeToParcel(out, uSecRealtime); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 11618 | out.writeLong(mLongestLightIdleTime); |
| 11619 | out.writeLong(mLongestFullIdleTime); |
| 11620 | mDeviceIdleModeLightTimer.writeToParcel(out, uSecRealtime); |
| 11621 | mDeviceIdleModeFullTimer.writeToParcel(out, uSecRealtime); |
| 11622 | mDeviceLightIdlingTimer.writeToParcel(out, uSecRealtime); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 11623 | mDeviceIdlingTimer.writeToParcel(out, uSecRealtime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 11624 | mPhoneOnTimer.writeToParcel(out, uSecRealtime); |
| 11625 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
| 11626 | mPhoneSignalStrengthsTimer[i].writeToParcel(out, uSecRealtime); |
| 11627 | } |
| 11628 | mPhoneSignalScanningTimer.writeToParcel(out, uSecRealtime); |
| 11629 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
| 11630 | mPhoneDataConnectionsTimer[i].writeToParcel(out, uSecRealtime); |
| 11631 | } |
| 11632 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
| 11633 | mNetworkByteActivityCounters[i].writeToParcel(out); |
| 11634 | mNetworkPacketActivityCounters[i].writeToParcel(out); |
| 11635 | } |
| 11636 | mMobileRadioActiveTimer.writeToParcel(out, uSecRealtime); |
| 11637 | mMobileRadioActivePerAppTimer.writeToParcel(out, uSecRealtime); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 11638 | mMobileRadioActiveAdjustedTime.writeToParcel(out); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 11639 | mMobileRadioActiveUnknownTime.writeToParcel(out); |
| 11640 | mMobileRadioActiveUnknownCount.writeToParcel(out); |
| 11641 | mWifiOnTimer.writeToParcel(out, uSecRealtime); |
| 11642 | mGlobalWifiRunningTimer.writeToParcel(out, uSecRealtime); |
| 11643 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
| 11644 | mWifiStateTimer[i].writeToParcel(out, uSecRealtime); |
| 11645 | } |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 11646 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
| 11647 | mWifiSupplStateTimer[i].writeToParcel(out, uSecRealtime); |
| 11648 | } |
| 11649 | for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 11650 | mWifiSignalStrengthsTimer[i].writeToParcel(out, uSecRealtime); |
| 11651 | } |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 11652 | mWifiActivity.writeToParcel(out, 0); |
| 11653 | mBluetoothActivity.writeToParcel(out, 0); |
| 11654 | mModemActivity.writeToParcel(out, 0); |
| 11655 | out.writeInt(mHasWifiReporting ? 1 : 0); |
| 11656 | out.writeInt(mHasBluetoothReporting ? 1 : 0); |
| 11657 | out.writeInt(mHasModemReporting ? 1 : 0); |
| 11658 | |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 11659 | out.writeInt(mNumConnectivityChange); |
| 11660 | out.writeInt(mLoadedNumConnectivityChange); |
| 11661 | out.writeInt(mUnpluggedNumConnectivityChange); |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 11662 | mFlashlightOnTimer.writeToParcel(out, uSecRealtime); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 11663 | mCameraOnTimer.writeToParcel(out, uSecRealtime); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 11664 | mBluetoothScanTimer.writeToParcel(out, uSecRealtime); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 11665 | out.writeInt(mDischargeUnplugLevel); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 11666 | out.writeInt(mDischargePlugLevel); |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 11667 | out.writeInt(mDischargeCurrentLevel); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 11668 | out.writeInt(mCurrentBatteryLevel); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 11669 | out.writeInt(mLowDischargeAmountSinceCharge); |
| 11670 | out.writeInt(mHighDischargeAmountSinceCharge); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 11671 | out.writeInt(mDischargeAmountScreenOn); |
| 11672 | out.writeInt(mDischargeAmountScreenOnSinceCharge); |
| 11673 | out.writeInt(mDischargeAmountScreenOff); |
| 11674 | out.writeInt(mDischargeAmountScreenOffSinceCharge); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 11675 | mDischargeStepTracker.writeToParcel(out); |
| 11676 | mChargeStepTracker.writeToParcel(out); |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 11677 | mDischargeCounter.writeToParcel(out); |
| 11678 | mDischargeScreenOffCounter.writeToParcel(out); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11679 | out.writeLong(mLastWriteTime); |
| 11680 | |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 11681 | if (inclUids) { |
| 11682 | out.writeInt(mKernelWakelockStats.size()); |
| 11683 | for (Map.Entry<String, SamplingTimer> ent : mKernelWakelockStats.entrySet()) { |
| 11684 | SamplingTimer kwlt = ent.getValue(); |
| 11685 | if (kwlt != null) { |
| 11686 | out.writeInt(1); |
| 11687 | out.writeString(ent.getKey()); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 11688 | kwlt.writeToParcel(out, uSecRealtime); |
| 11689 | } else { |
| 11690 | out.writeInt(0); |
| 11691 | } |
| 11692 | } |
| 11693 | out.writeInt(mWakeupReasonStats.size()); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 11694 | for (Map.Entry<String, SamplingTimer> ent : mWakeupReasonStats.entrySet()) { |
| 11695 | SamplingTimer timer = ent.getValue(); |
| 11696 | if (timer != null) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 11697 | out.writeInt(1); |
| 11698 | out.writeString(ent.getKey()); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 11699 | timer.writeToParcel(out, uSecRealtime); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 11700 | } else { |
| 11701 | out.writeInt(0); |
| 11702 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 11703 | } |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 11704 | } else { |
| 11705 | out.writeInt(0); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 11706 | } |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 11707 | |
James Carr | 3a22605 | 2016-07-01 14:49:52 -0700 | [diff] [blame] | 11708 | out.writeInt(mKernelMemoryStats.size()); |
| 11709 | for (int i = 0; i < mKernelMemoryStats.size(); i++) { |
| 11710 | SamplingTimer kmt = mKernelMemoryStats.valueAt(i); |
| 11711 | if (kmt != null) { |
| 11712 | out.writeInt(1); |
| 11713 | out.writeLong(mKernelMemoryStats.keyAt(i)); |
| 11714 | kmt.writeToParcel(out, uSecRealtime); |
| 11715 | } else { |
| 11716 | out.writeInt(0); |
| 11717 | } |
| 11718 | } |
| 11719 | |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 11720 | if (inclUids) { |
| 11721 | int size = mUidStats.size(); |
| 11722 | out.writeInt(size); |
| 11723 | for (int i = 0; i < size; i++) { |
| 11724 | out.writeInt(mUidStats.keyAt(i)); |
| 11725 | Uid uid = mUidStats.valueAt(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11726 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 11727 | uid.writeToParcelLocked(out, uSecRealtime); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 11728 | } |
| 11729 | } else { |
| 11730 | out.writeInt(0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11731 | } |
| 11732 | } |
| 11733 | |
| 11734 | public static final Parcelable.Creator<BatteryStatsImpl> CREATOR = |
| 11735 | new Parcelable.Creator<BatteryStatsImpl>() { |
| 11736 | public BatteryStatsImpl createFromParcel(Parcel in) { |
| 11737 | return new BatteryStatsImpl(in); |
| 11738 | } |
| 11739 | |
| 11740 | public BatteryStatsImpl[] newArray(int size) { |
| 11741 | return new BatteryStatsImpl[size]; |
| 11742 | } |
| 11743 | }; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 11744 | |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 11745 | public void prepareForDumpLocked() { |
| 11746 | // Need to retrieve current kernel wake lock stats before printing. |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 11747 | pullPendingStateUpdatesLocked(); |
Dianne Hackborn | 7d9eefd | 2014-08-27 18:30:31 -0700 | [diff] [blame] | 11748 | |
| 11749 | // Pull the clock time. This may update the time and make a new history entry |
| 11750 | // if we had originally pulled a time before the RTC was set. |
| 11751 | getStartClockTime(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 11752 | } |
| 11753 | |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 11754 | 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] | 11755 | if (DEBUG) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 11756 | pw.println("mOnBatteryTimeBase:"); |
| 11757 | mOnBatteryTimeBase.dump(pw, " "); |
| 11758 | pw.println("mOnBatteryScreenOffTimeBase:"); |
| 11759 | mOnBatteryScreenOffTimeBase.dump(pw, " "); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11760 | Printer pr = new PrintWriterPrinter(pw); |
| 11761 | pr.println("*** Screen timer:"); |
| 11762 | mScreenOnTimer.logState(pr, " "); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 11763 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11764 | pr.println("*** Screen brightness #" + i + ":"); |
| 11765 | mScreenBrightnessTimer[i].logState(pr, " "); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 11766 | } |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 11767 | pr.println("*** Interactive timer:"); |
| 11768 | mInteractiveTimer.logState(pr, " "); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 11769 | pr.println("*** Power save mode timer:"); |
| 11770 | mPowerSaveModeEnabledTimer.logState(pr, " "); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 11771 | pr.println("*** Device idle mode light timer:"); |
| 11772 | mDeviceIdleModeLightTimer.logState(pr, " "); |
| 11773 | pr.println("*** Device idle mode full timer:"); |
| 11774 | mDeviceIdleModeFullTimer.logState(pr, " "); |
| 11775 | pr.println("*** Device light idling timer:"); |
| 11776 | mDeviceLightIdlingTimer.logState(pr, " "); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 11777 | pr.println("*** Device idling timer:"); |
| 11778 | mDeviceIdlingTimer.logState(pr, " "); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11779 | pr.println("*** Phone timer:"); |
| 11780 | mPhoneOnTimer.logState(pr, " "); |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 11781 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 11782 | pr.println("*** Phone signal strength #" + i + ":"); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11783 | mPhoneSignalStrengthsTimer[i].logState(pr, " "); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 11784 | } |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 11785 | pr.println("*** Signal scanning :"); |
| 11786 | mPhoneSignalScanningTimer.logState(pr, " "); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 11787 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11788 | pr.println("*** Data connection type #" + i + ":"); |
| 11789 | mPhoneDataConnectionsTimer[i].logState(pr, " "); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 11790 | } |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 11791 | pr.println("*** mMobileRadioPowerState=" + mMobileRadioPowerState); |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 11792 | pr.println("*** Mobile network active timer:"); |
| 11793 | mMobileRadioActiveTimer.logState(pr, " "); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 11794 | pr.println("*** Mobile network active adjusted timer:"); |
| 11795 | mMobileRadioActiveAdjustedTime.logState(pr, " "); |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 11796 | pr.println("*** mWifiRadioPowerState=" + mWifiRadioPowerState); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11797 | pr.println("*** Wifi timer:"); |
| 11798 | mWifiOnTimer.logState(pr, " "); |
| 11799 | pr.println("*** WifiRunning timer:"); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 11800 | mGlobalWifiRunningTimer.logState(pr, " "); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 11801 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
| 11802 | pr.println("*** Wifi state #" + i + ":"); |
| 11803 | mWifiStateTimer[i].logState(pr, " "); |
| 11804 | } |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 11805 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
| 11806 | pr.println("*** Wifi suppl state #" + i + ":"); |
| 11807 | mWifiSupplStateTimer[i].logState(pr, " "); |
| 11808 | } |
| 11809 | for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 11810 | pr.println("*** Wifi signal strength #" + i + ":"); |
| 11811 | mWifiSignalStrengthsTimer[i].logState(pr, " "); |
| 11812 | } |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 11813 | pr.println("*** Flashlight timer:"); |
| 11814 | mFlashlightOnTimer.logState(pr, " "); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 11815 | pr.println("*** Camera timer:"); |
| 11816 | mCameraOnTimer.logState(pr, " "); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11817 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 11818 | super.dumpLocked(context, pw, flags, reqUid, histStart); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11819 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11820 | } |