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; |
Adam Lesinski | e1f480d | 2017-02-15 18:51:23 -0800 | [diff] [blame] | 34 | import android.os.IBatteryPropertiesRegistrar; |
Jeff Brown | 6f357d3 | 2014-01-15 20:40:55 -0800 | [diff] [blame] | 35 | import android.os.Looper; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 36 | import android.os.Message; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 37 | import android.os.Parcel; |
| 38 | import android.os.ParcelFormatException; |
| 39 | import android.os.Parcelable; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 40 | import android.os.Process; |
Adam Lesinski | e1f480d | 2017-02-15 18:51:23 -0800 | [diff] [blame] | 41 | import android.os.RemoteException; |
| 42 | import android.os.ServiceManager; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 43 | import android.os.SystemClock; |
Jeff Sharkey | 418d12d | 2011-12-13 15:38:03 -0800 | [diff] [blame] | 44 | import android.os.SystemProperties; |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 45 | import android.os.WorkSource; |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 46 | import android.telephony.DataConnectionRealTimeInfo; |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 47 | import android.telephony.ModemActivityInfo; |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 48 | import android.telephony.ServiceState; |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 49 | import android.telephony.SignalStrength; |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 50 | import android.telephony.TelephonyManager; |
Jeff Sharkey | 9da2f1e | 2014-08-14 12:55:00 -0700 | [diff] [blame] | 51 | import android.text.TextUtils; |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 52 | import android.util.ArrayMap; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 53 | import android.util.Log; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 54 | import android.util.LogWriter; |
James Carr | 3a22605 | 2016-07-01 14:49:52 -0700 | [diff] [blame] | 55 | import android.util.LongSparseArray; |
| 56 | import android.util.LongSparseLongArray; |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 57 | import android.util.MutableInt; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 58 | import android.util.PrintWriterPrinter; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 59 | import android.util.Printer; |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 60 | import android.util.Slog; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 61 | import android.util.SparseArray; |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 62 | import android.util.SparseIntArray; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 63 | import android.util.SparseLongArray; |
Dianne Hackborn | ae38445 | 2011-06-28 12:33:48 -0700 | [diff] [blame] | 64 | import android.util.TimeUtils; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 65 | import android.util.Xml; |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 66 | import android.view.Display; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 67 | |
Adam Lesinski | 98f0d46 | 2016-04-19 16:46:20 -0700 | [diff] [blame] | 68 | import com.android.internal.annotations.VisibleForTesting; |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 69 | import com.android.internal.net.NetworkStatsFactory; |
Dianne Hackborn | d0c5b9a | 2014-02-21 16:19:05 -0800 | [diff] [blame] | 70 | import com.android.internal.util.ArrayUtils; |
Dianne Hackborn | 8c84109 | 2013-06-24 13:46:13 -0700 | [diff] [blame] | 71 | import com.android.internal.util.FastPrintWriter; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 72 | import com.android.internal.util.FastXmlSerializer; |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 73 | import com.android.internal.util.JournaledFile; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 74 | import com.android.internal.util.XmlUtils; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 75 | import com.android.server.NetworkManagementSocketTagger; |
| 76 | import libcore.util.EmptyArray; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 77 | import org.xmlpull.v1.XmlPullParser; |
| 78 | import org.xmlpull.v1.XmlPullParserException; |
| 79 | import org.xmlpull.v1.XmlSerializer; |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 80 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 81 | import java.io.ByteArrayOutputStream; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 82 | import java.io.File; |
| 83 | import java.io.FileInputStream; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 84 | import java.io.FileNotFoundException; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 85 | import java.io.FileOutputStream; |
| 86 | import java.io.IOException; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 87 | import java.io.PrintWriter; |
Wojciech Staszkiewicz | 9e9e2e7 | 2015-05-08 14:58:46 +0100 | [diff] [blame] | 88 | import java.nio.charset.StandardCharsets; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 89 | import java.util.ArrayList; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 90 | import java.util.Calendar; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 91 | import java.util.HashMap; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 92 | import java.util.Iterator; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 93 | import java.util.Map; |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 94 | import java.util.concurrent.atomic.AtomicInteger; |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 95 | import java.util.concurrent.locks.ReentrantLock; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 96 | |
| 97 | /** |
| 98 | * All information we are collecting about things that can happen that impact |
| 99 | * battery life. All times are represented in microseconds except where indicated |
| 100 | * otherwise. |
| 101 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 102 | public class BatteryStatsImpl extends BatteryStats { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 103 | private static final String TAG = "BatteryStatsImpl"; |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 104 | private static final boolean DEBUG = false; |
Adam Lesinski | a7c90c8 | 2015-06-18 14:52:24 -0700 | [diff] [blame] | 105 | public static final boolean DEBUG_ENERGY = false; |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 106 | private static final boolean DEBUG_ENERGY_CPU = DEBUG_ENERGY; |
James Carr | 3a22605 | 2016-07-01 14:49:52 -0700 | [diff] [blame] | 107 | private static final boolean DEBUG_MEMORY = false; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 108 | private static final boolean DEBUG_HISTORY = false; |
Dianne Hackborn | e8c88e6 | 2011-08-17 19:09:09 -0700 | [diff] [blame] | 109 | private static final boolean USE_OLD_HISTORY = false; // for debugging. |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 110 | |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 111 | // TODO: remove "tcp" from network methods, since we measure total stats. |
| 112 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 113 | // 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] | 114 | private static final int MAGIC = 0xBA757475; // 'BATSTATS' |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 115 | |
| 116 | // Current on-disk Parcel version |
Jocelyn Dang | c627d10 | 2017-04-14 13:15:14 -0700 | [diff] [blame^] | 117 | private static final int VERSION = 155 + (USE_OLD_HISTORY ? 1000 : 0); |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 118 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 119 | // Maximum number of items we will record in the history. |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 120 | private static final int MAX_HISTORY_ITEMS = 2000; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 121 | |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 122 | // No, really, THIS is the maximum number of items we will record in the history. |
| 123 | private static final int MAX_MAX_HISTORY_ITEMS = 3000; |
| 124 | |
Dianne Hackborn | 9e0f5d9 | 2010-02-22 15:05:42 -0800 | [diff] [blame] | 125 | // The maximum number of names wakelocks we will keep track of |
| 126 | // per uid; once the limit is reached, we batch the remaining wakelocks |
| 127 | // in to one common name. |
Dianne Hackborn | acc4a12 | 2014-08-18 16:33:44 -0700 | [diff] [blame] | 128 | private static final int MAX_WAKELOCKS_PER_UID = 100; |
Dianne Hackborn | c24ab86 | 2011-10-18 15:55:03 -0700 | [diff] [blame] | 129 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 130 | // Number of transmit power states the Wifi controller can be in. |
| 131 | private static final int NUM_WIFI_TX_LEVELS = 1; |
| 132 | |
| 133 | // Number of transmit power states the Bluetooth controller can be in. |
| 134 | private static final int NUM_BT_TX_LEVELS = 1; |
| 135 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 136 | protected Clocks mClocks; |
| 137 | |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 138 | private final JournaledFile mFile; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 139 | public final AtomicFile mCheckinFile; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 140 | public final AtomicFile mDailyFile; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 141 | |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 142 | static final int MSG_UPDATE_WAKELOCKS = 1; |
| 143 | static final int MSG_REPORT_POWER_CHANGE = 2; |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 144 | static final int MSG_REPORT_CHARGING = 3; |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 145 | static final long DELAY_UPDATE_WAKELOCKS = 5*1000; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 146 | |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 147 | private final KernelWakelockReader mKernelWakelockReader = new KernelWakelockReader(); |
| 148 | private final KernelWakelockStats mTmpWakelockStats = new KernelWakelockStats(); |
| 149 | |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 150 | private final KernelUidCpuTimeReader mKernelUidCpuTimeReader = new KernelUidCpuTimeReader(); |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 151 | private KernelCpuSpeedReader[] mKernelCpuSpeedReaders; |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 152 | |
James Carr | 3a22605 | 2016-07-01 14:49:52 -0700 | [diff] [blame] | 153 | private final KernelMemoryBandwidthStats mKernelMemoryBandwidthStats |
| 154 | = new KernelMemoryBandwidthStats(); |
| 155 | private final LongSparseArray<SamplingTimer> mKernelMemoryStats = new LongSparseArray<>(); |
| 156 | public LongSparseArray<SamplingTimer> getKernelMemoryStats() { |
| 157 | return mKernelMemoryStats; |
| 158 | } |
| 159 | |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 160 | public interface BatteryCallback { |
| 161 | public void batteryNeedsCpuUpdate(); |
| 162 | public void batteryPowerChanged(boolean onBattery); |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 163 | public void batterySendBroadcast(Intent intent); |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 164 | } |
| 165 | |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 166 | public interface PlatformIdleStateCallback { |
| 167 | public String getPlatformLowPowerStats(); |
| 168 | } |
| 169 | |
| 170 | private final PlatformIdleStateCallback mPlatformIdleStateCallback; |
| 171 | |
| 172 | |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 173 | final class MyHandler extends Handler { |
Jeff Brown | 6f357d3 | 2014-01-15 20:40:55 -0800 | [diff] [blame] | 174 | public MyHandler(Looper looper) { |
| 175 | super(looper, null, true); |
| 176 | } |
| 177 | |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 178 | @Override |
| 179 | public void handleMessage(Message msg) { |
| 180 | BatteryCallback cb = mCallback; |
| 181 | switch (msg.what) { |
| 182 | case MSG_UPDATE_WAKELOCKS: |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 183 | synchronized (BatteryStatsImpl.this) { |
| 184 | updateCpuTimeLocked(); |
| 185 | } |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 186 | if (cb != null) { |
| 187 | cb.batteryNeedsCpuUpdate(); |
| 188 | } |
| 189 | break; |
| 190 | case MSG_REPORT_POWER_CHANGE: |
| 191 | if (cb != null) { |
| 192 | cb.batteryPowerChanged(msg.arg1 != 0); |
| 193 | } |
| 194 | break; |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 195 | case MSG_REPORT_CHARGING: |
| 196 | if (cb != null) { |
| 197 | final String action; |
| 198 | synchronized (BatteryStatsImpl.this) { |
| 199 | action = mCharging ? BatteryManager.ACTION_CHARGING |
| 200 | : BatteryManager.ACTION_DISCHARGING; |
| 201 | } |
| 202 | Intent intent = new Intent(action); |
| 203 | intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT); |
| 204 | cb.batterySendBroadcast(intent); |
| 205 | } |
| 206 | break; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 207 | } |
| 208 | } |
| 209 | } |
| 210 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 211 | public interface Clocks { |
| 212 | public long elapsedRealtime(); |
| 213 | public long uptimeMillis(); |
| 214 | } |
| 215 | |
| 216 | public static class SystemClocks implements Clocks { |
| 217 | public long elapsedRealtime() { |
| 218 | return SystemClock.elapsedRealtime(); |
| 219 | } |
| 220 | |
| 221 | public long uptimeMillis() { |
| 222 | return SystemClock.uptimeMillis(); |
| 223 | } |
| 224 | } |
| 225 | |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 226 | public interface ExternalStatsSync { |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 227 | public static final int UPDATE_CPU = 0x01; |
| 228 | public static final int UPDATE_WIFI = 0x02; |
| 229 | public static final int UPDATE_RADIO = 0x04; |
| 230 | public static final int UPDATE_BT = 0x08; |
| 231 | public static final int UPDATE_ALL = UPDATE_CPU | UPDATE_WIFI | UPDATE_RADIO | UPDATE_BT; |
| 232 | |
| 233 | void scheduleSync(String reason, int flags); |
Adam Lesinski | 61db88f | 2015-07-01 15:05:07 -0700 | [diff] [blame] | 234 | void scheduleCpuSyncDueToRemovedUid(int uid); |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 235 | } |
| 236 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 237 | public final MyHandler mHandler; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 238 | private final ExternalStatsSync mExternalSync; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 239 | |
| 240 | private BatteryCallback mCallback; |
| 241 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 242 | /** |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 243 | * Mapping isolated uids to the actual owning app uid. |
| 244 | */ |
| 245 | final SparseIntArray mIsolatedUids = new SparseIntArray(); |
| 246 | |
| 247 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 248 | * The statistics we have collected organized by uids. |
| 249 | */ |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 250 | final SparseArray<BatteryStatsImpl.Uid> mUidStats = new SparseArray<>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 251 | |
| 252 | // A set of pools of currently active timers. When a timer is queried, we will divide the |
| 253 | // elapsed time by the number of active timers to arrive at that timer's share of the time. |
| 254 | // In order to do this, we must refresh each timer whenever the number of active timers |
| 255 | // changes. |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 256 | final ArrayList<StopwatchTimer> mPartialTimers = new ArrayList<>(); |
| 257 | final ArrayList<StopwatchTimer> mFullTimers = new ArrayList<>(); |
| 258 | final ArrayList<StopwatchTimer> mWindowTimers = new ArrayList<>(); |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 259 | final ArrayList<StopwatchTimer> mDrawTimers = new ArrayList<>(); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 260 | final SparseArray<ArrayList<StopwatchTimer>> mSensorTimers = new SparseArray<>(); |
| 261 | final ArrayList<StopwatchTimer> mWifiRunningTimers = new ArrayList<>(); |
| 262 | final ArrayList<StopwatchTimer> mFullWifiLockTimers = new ArrayList<>(); |
| 263 | final ArrayList<StopwatchTimer> mWifiMulticastTimers = new ArrayList<>(); |
| 264 | final ArrayList<StopwatchTimer> mWifiScanTimers = new ArrayList<>(); |
| 265 | final SparseArray<ArrayList<StopwatchTimer>> mWifiBatchedScanTimers = new SparseArray<>(); |
| 266 | final ArrayList<StopwatchTimer> mAudioTurnedOnTimers = new ArrayList<>(); |
| 267 | final ArrayList<StopwatchTimer> mVideoTurnedOnTimers = new ArrayList<>(); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 268 | final ArrayList<StopwatchTimer> mFlashlightTurnedOnTimers = new ArrayList<>(); |
| 269 | final ArrayList<StopwatchTimer> mCameraTurnedOnTimers = new ArrayList<>(); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 270 | final ArrayList<StopwatchTimer> mBluetoothScanOnTimers = new ArrayList<>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 271 | |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 272 | // Last partial timers we use for distributing CPU usage. |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 273 | final ArrayList<StopwatchTimer> mLastPartialTimers = new ArrayList<>(); |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 274 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 275 | // These are the objects that will want to do something when the device |
| 276 | // is unplugged from power. |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 277 | protected final TimeBase mOnBatteryTimeBase = new TimeBase(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 278 | |
| 279 | // These are the objects that will want to do something when the device |
| 280 | // is unplugged from power *and* the screen is off. |
| 281 | final TimeBase mOnBatteryScreenOffTimeBase = new TimeBase(); |
| 282 | |
| 283 | // Set to true when we want to distribute CPU across wakelocks for the next |
| 284 | // CPU update, even if we aren't currently running wake locks. |
| 285 | boolean mDistributeWakelockCpu; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 286 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 287 | boolean mShuttingDown; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 288 | |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 289 | final HistoryEventTracker mActiveEvents = new HistoryEventTracker(); |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 290 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 291 | long mHistoryBaseTime; |
| 292 | boolean mHaveBatteryLevel = false; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 293 | boolean mRecordingHistory = false; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 294 | int mNumHistoryItems; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 295 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 296 | static final int MAX_HISTORY_BUFFER = 256*1024; // 256KB |
| 297 | static final int MAX_MAX_HISTORY_BUFFER = 320*1024; // 320KB |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 298 | final Parcel mHistoryBuffer = Parcel.obtain(); |
| 299 | final HistoryItem mHistoryLastWritten = new HistoryItem(); |
| 300 | final HistoryItem mHistoryLastLastWritten = new HistoryItem(); |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 301 | final HistoryItem mHistoryReadTmp = new HistoryItem(); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 302 | final HistoryItem mHistoryAddTmp = new HistoryItem(); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 303 | final HashMap<HistoryTag, Integer> mHistoryTagPool = new HashMap<>(); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 304 | String[] mReadHistoryStrings; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 305 | int[] mReadHistoryUids; |
| 306 | int mReadHistoryChars; |
| 307 | int mNextHistoryTagIdx = 0; |
| 308 | int mNumHistoryTagChars = 0; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 309 | int mHistoryBufferLastPos = -1; |
| 310 | boolean mHistoryOverflow = false; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 311 | int mActiveHistoryStates = 0xffffffff; |
| 312 | int mActiveHistoryStates2 = 0xffffffff; |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 313 | long mLastHistoryElapsedRealtime = 0; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 314 | long mTrackRunningHistoryElapsedRealtime = 0; |
| 315 | long mTrackRunningHistoryUptime = 0; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 316 | |
| 317 | final HistoryItem mHistoryCur = new HistoryItem(); |
| 318 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 319 | HistoryItem mHistory; |
| 320 | HistoryItem mHistoryEnd; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 321 | HistoryItem mHistoryLastEnd; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 322 | HistoryItem mHistoryCache; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 323 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 324 | // Used by computeHistoryStepDetails |
| 325 | HistoryStepDetails mLastHistoryStepDetails = null; |
| 326 | byte mLastHistoryStepLevel = 0; |
| 327 | final HistoryStepDetails mCurHistoryStepDetails = new HistoryStepDetails(); |
| 328 | final HistoryStepDetails mReadHistoryStepDetails = new HistoryStepDetails(); |
| 329 | final HistoryStepDetails mTmpHistoryStepDetails = new HistoryStepDetails(); |
Adam Lesinski | 7b83b0c | 2015-06-05 12:59:36 -0700 | [diff] [blame] | 330 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 331 | /** |
Adam Lesinski | 7b83b0c | 2015-06-05 12:59:36 -0700 | [diff] [blame] | 332 | * Total time (in milliseconds) spent executing in user code. |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 333 | */ |
| 334 | long mLastStepCpuUserTime; |
| 335 | long mCurStepCpuUserTime; |
| 336 | /** |
Adam Lesinski | 7b83b0c | 2015-06-05 12:59:36 -0700 | [diff] [blame] | 337 | * Total time (in milliseconds) spent executing in kernel code. |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 338 | */ |
| 339 | long mLastStepCpuSystemTime; |
| 340 | long mCurStepCpuSystemTime; |
| 341 | /** |
Adam Lesinski | 7b83b0c | 2015-06-05 12:59:36 -0700 | [diff] [blame] | 342 | * Times from /proc/stat (but measured in milliseconds). |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 343 | */ |
| 344 | long mLastStepStatUserTime; |
| 345 | long mLastStepStatSystemTime; |
| 346 | long mLastStepStatIOWaitTime; |
| 347 | long mLastStepStatIrqTime; |
| 348 | long mLastStepStatSoftIrqTime; |
| 349 | long mLastStepStatIdleTime; |
| 350 | long mCurStepStatUserTime; |
| 351 | long mCurStepStatSystemTime; |
| 352 | long mCurStepStatIOWaitTime; |
| 353 | long mCurStepStatIrqTime; |
| 354 | long mCurStepStatSoftIrqTime; |
| 355 | long mCurStepStatIdleTime; |
| 356 | |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 357 | private HistoryItem mHistoryIterator; |
| 358 | private boolean mReadOverflow; |
| 359 | private boolean mIteratingHistory; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 360 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 361 | int mStartCount; |
| 362 | |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 363 | long mStartClockTime; |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 364 | String mStartPlatformVersion; |
| 365 | String mEndPlatformVersion; |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 366 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 367 | long mUptime; |
| 368 | long mUptimeStart; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 369 | long mRealtime; |
| 370 | long mRealtimeStart; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 371 | |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 372 | int mWakeLockNesting; |
| 373 | boolean mWakeLockImportant; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 374 | public boolean mRecordAllHistory; |
Dianne Hackborn | 9a75543 | 2014-05-15 17:05:22 -0700 | [diff] [blame] | 375 | boolean mNoAutoReset; |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 376 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 377 | int mScreenState = Display.STATE_UNKNOWN; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 378 | StopwatchTimer mScreenOnTimer; |
Amith Yamasani | 3718aaa | 2009-06-09 06:32:35 -0700 | [diff] [blame] | 379 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 380 | int mScreenBrightnessBin = -1; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 381 | final StopwatchTimer[] mScreenBrightnessTimer = new StopwatchTimer[NUM_SCREEN_BRIGHTNESS_BINS]; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 382 | |
Amith Yamasani | 674c9bb | 2017-02-01 09:45:17 -0800 | [diff] [blame] | 383 | boolean mPretendScreenOff; |
| 384 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 385 | boolean mInteractive; |
| 386 | StopwatchTimer mInteractiveTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 387 | |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 388 | boolean mPowerSaveModeEnabled; |
| 389 | StopwatchTimer mPowerSaveModeEnabledTimer; |
| 390 | |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 391 | boolean mDeviceIdling; |
| 392 | StopwatchTimer mDeviceIdlingTimer; |
| 393 | |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 394 | boolean mDeviceLightIdling; |
| 395 | StopwatchTimer mDeviceLightIdlingTimer; |
| 396 | |
| 397 | int mDeviceIdleMode; |
| 398 | long mLastIdleTimeStart; |
| 399 | long mLongestLightIdleTime; |
| 400 | long mLongestFullIdleTime; |
| 401 | StopwatchTimer mDeviceIdleModeLightTimer; |
| 402 | StopwatchTimer mDeviceIdleModeFullTimer; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 403 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 404 | boolean mPhoneOn; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 405 | StopwatchTimer mPhoneOnTimer; |
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 mAudioOnNesting; |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 408 | StopwatchTimer mAudioOnTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 409 | |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 410 | int mVideoOnNesting; |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 411 | StopwatchTimer mVideoOnTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 412 | |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 413 | int mFlashlightOnNesting; |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 414 | StopwatchTimer mFlashlightOnTimer; |
| 415 | |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 416 | int mCameraOnNesting; |
| 417 | StopwatchTimer mCameraOnTimer; |
| 418 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 419 | int mPhoneSignalStrengthBin = -1; |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 420 | int mPhoneSignalStrengthBinRaw = -1; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 421 | final StopwatchTimer[] mPhoneSignalStrengthsTimer = |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 422 | new StopwatchTimer[SignalStrength.NUM_SIGNAL_STRENGTH_BINS]; |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 423 | |
| 424 | StopwatchTimer mPhoneSignalScanningTimer; |
| 425 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 426 | int mPhoneDataConnectionType = -1; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 427 | final StopwatchTimer[] mPhoneDataConnectionsTimer = |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 428 | new StopwatchTimer[NUM_DATA_CONNECTION_TYPES]; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 429 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 430 | final LongSamplingCounter[] mNetworkByteActivityCounters = |
| 431 | new LongSamplingCounter[NUM_NETWORK_ACTIVITY_TYPES]; |
| 432 | final LongSamplingCounter[] mNetworkPacketActivityCounters = |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 433 | new LongSamplingCounter[NUM_NETWORK_ACTIVITY_TYPES]; |
| 434 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 435 | /** |
| 436 | * The WiFi controller activity (time in tx, rx, idle, and power consumed) for the device. |
| 437 | */ |
| 438 | ControllerActivityCounterImpl mWifiActivity; |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 439 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 440 | /** |
| 441 | * The Bluetooth controller activity (time in tx, rx, idle, and power consumed) for the device. |
| 442 | */ |
| 443 | ControllerActivityCounterImpl mBluetoothActivity; |
| 444 | |
| 445 | /** |
| 446 | * The Modem controller activity (time in tx, rx, idle, and power consumed) for the device. |
| 447 | */ |
| 448 | ControllerActivityCounterImpl mModemActivity; |
| 449 | |
| 450 | /** |
| 451 | * Whether the device supports WiFi controller energy reporting. This is set to true on |
| 452 | * the first WiFi energy report. See {@link #mWifiActivity}. |
| 453 | */ |
| 454 | boolean mHasWifiReporting = false; |
| 455 | |
| 456 | /** |
| 457 | * Whether the device supports Bluetooth controller energy reporting. This is set to true on |
| 458 | * the first Bluetooth energy report. See {@link #mBluetoothActivity}. |
| 459 | */ |
| 460 | boolean mHasBluetoothReporting = false; |
| 461 | |
| 462 | /** |
| 463 | * Whether the device supports Modem controller energy reporting. This is set to true on |
| 464 | * the first Modem energy report. See {@link #mModemActivity}. |
| 465 | */ |
| 466 | boolean mHasModemReporting = false; |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 467 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 468 | boolean mWifiOn; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 469 | StopwatchTimer mWifiOnTimer; |
Eric Shienbrood | d4c5f89 | 2009-03-24 18:13:20 -0700 | [diff] [blame] | 470 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 471 | boolean mGlobalWifiRunning; |
| 472 | StopwatchTimer mGlobalWifiRunningTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 473 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 474 | int mWifiState = -1; |
| 475 | final StopwatchTimer[] mWifiStateTimer = new StopwatchTimer[NUM_WIFI_STATES]; |
| 476 | |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 477 | int mWifiSupplState = -1; |
| 478 | final StopwatchTimer[] mWifiSupplStateTimer = new StopwatchTimer[NUM_WIFI_SUPPL_STATES]; |
| 479 | |
| 480 | int mWifiSignalStrengthBin = -1; |
| 481 | final StopwatchTimer[] mWifiSignalStrengthsTimer = |
| 482 | new StopwatchTimer[NUM_WIFI_SIGNAL_STRENGTH_BINS]; |
| 483 | |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 484 | int mBluetoothScanNesting; |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 485 | @VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE) |
| 486 | protected StopwatchTimer mBluetoothScanTimer; |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 487 | |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 488 | int mMobileRadioPowerState = DataConnectionRealTimeInfo.DC_POWER_STATE_LOW; |
Dianne Hackborn | f7097a5 | 2014-05-13 09:56:14 -0700 | [diff] [blame] | 489 | long mMobileRadioActiveStartTime; |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 490 | StopwatchTimer mMobileRadioActiveTimer; |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 491 | StopwatchTimer mMobileRadioActivePerAppTimer; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 492 | LongSamplingCounter mMobileRadioActiveAdjustedTime; |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 493 | LongSamplingCounter mMobileRadioActiveUnknownTime; |
| 494 | LongSamplingCounter mMobileRadioActiveUnknownCount; |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 495 | |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 496 | int mWifiRadioPowerState = DataConnectionRealTimeInfo.DC_POWER_STATE_LOW; |
| 497 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 498 | /** |
| 499 | * These provide time bases that discount the time the device is plugged |
| 500 | * in to power. |
| 501 | */ |
| 502 | boolean mOnBattery; |
| 503 | boolean mOnBatteryInternal; |
Amith Yamasani | 3718aaa | 2009-06-09 06:32:35 -0700 | [diff] [blame] | 504 | |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 505 | /** |
| 506 | * External reporting of whether the device is actually charging. |
| 507 | */ |
| 508 | boolean mCharging = true; |
| 509 | int mLastChargingStateLevel; |
| 510 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 511 | /* |
| 512 | * These keep track of battery levels (1-100) at the last plug event and the last unplug event. |
| 513 | */ |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 514 | int mDischargeStartLevel; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 515 | int mDischargeUnplugLevel; |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 516 | int mDischargePlugLevel; |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 517 | int mDischargeCurrentLevel; |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 518 | int mCurrentBatteryLevel; |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 519 | int mLowDischargeAmountSinceCharge; |
| 520 | int mHighDischargeAmountSinceCharge; |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 521 | int mDischargeScreenOnUnplugLevel; |
| 522 | int mDischargeScreenOffUnplugLevel; |
| 523 | int mDischargeAmountScreenOn; |
| 524 | int mDischargeAmountScreenOnSinceCharge; |
| 525 | int mDischargeAmountScreenOff; |
| 526 | int mDischargeAmountScreenOffSinceCharge; |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 527 | |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 528 | private LongSamplingCounter mDischargeScreenOffCounter; |
| 529 | private LongSamplingCounter mDischargeCounter; |
| 530 | |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 531 | static final int MAX_LEVEL_STEPS = 200; |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 532 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 533 | int mInitStepMode = 0; |
| 534 | int mCurStepMode = 0; |
| 535 | int mModStepMode = 0; |
| 536 | |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 537 | int mLastDischargeStepLevel; |
Dianne Hackborn | 2932513 | 2014-05-21 15:01:03 -0700 | [diff] [blame] | 538 | int mMinDischargeStepLevel; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 539 | final LevelStepTracker mDischargeStepTracker = new LevelStepTracker(MAX_LEVEL_STEPS); |
| 540 | final LevelStepTracker mDailyDischargeStepTracker = new LevelStepTracker(MAX_LEVEL_STEPS*2); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 541 | ArrayList<PackageChange> mDailyPackageChanges; |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 542 | |
| 543 | int mLastChargeStepLevel; |
Dianne Hackborn | 2932513 | 2014-05-21 15:01:03 -0700 | [diff] [blame] | 544 | int mMaxChargeStepLevel; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 545 | final LevelStepTracker mChargeStepTracker = new LevelStepTracker(MAX_LEVEL_STEPS); |
| 546 | final LevelStepTracker mDailyChargeStepTracker = new LevelStepTracker(MAX_LEVEL_STEPS*2); |
| 547 | |
| 548 | static final int MAX_DAILY_ITEMS = 10; |
| 549 | |
| 550 | long mDailyStartTime = 0; |
| 551 | long mNextMinDailyDeadline = 0; |
| 552 | long mNextMaxDailyDeadline = 0; |
| 553 | |
| 554 | final ArrayList<DailyItem> mDailyItems = new ArrayList<>(); |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 555 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 556 | long mLastWriteTime = 0; // Milliseconds |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 557 | |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 558 | private int mPhoneServiceState = -1; |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 559 | private int mPhoneServiceStateRaw = -1; |
| 560 | private int mPhoneSimStateRaw = -1; |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 561 | |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 562 | private int mNumConnectivityChange; |
| 563 | private int mLoadedNumConnectivityChange; |
| 564 | private int mUnpluggedNumConnectivityChange; |
| 565 | |
Adam Lesinski | f9b20a9 | 2016-06-17 17:30:01 -0700 | [diff] [blame] | 566 | private int mEstimatedBatteryCapacity = -1; |
| 567 | |
Jocelyn Dang | c627d10 | 2017-04-14 13:15:14 -0700 | [diff] [blame^] | 568 | private int mMinLearnedBatteryCapacity = -1; |
| 569 | private int mMaxLearnedBatteryCapacity = -1; |
Adam Lesinski | 041d917 | 2016-12-12 12:03:56 -0800 | [diff] [blame] | 570 | |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 571 | private final NetworkStats.Entry mTmpNetworkStatsEntry = new NetworkStats.Entry(); |
| 572 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 573 | private PowerProfile mPowerProfile; |
| 574 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 575 | /* |
| 576 | * Holds a SamplingTimer associated with each kernel wakelock name being tracked. |
| 577 | */ |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 578 | private final HashMap<String, SamplingTimer> mKernelWakelockStats = new HashMap<>(); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 579 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 580 | public Map<String, ? extends Timer> getKernelWakelockStats() { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 581 | return mKernelWakelockStats; |
| 582 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 583 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 584 | String mLastWakeupReason = null; |
| 585 | long mLastWakeupUptimeMs = 0; |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 586 | private final HashMap<String, SamplingTimer> mWakeupReasonStats = new HashMap<>(); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 587 | |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 588 | public Map<String, ? extends Timer> getWakeupReasonStats() { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 589 | return mWakeupReasonStats; |
| 590 | } |
| 591 | |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 592 | @Override |
| 593 | public LongCounter getDischargeScreenOffCoulombCounter() { |
| 594 | return mDischargeScreenOffCounter; |
| 595 | } |
| 596 | |
| 597 | @Override |
| 598 | public LongCounter getDischargeCoulombCounter() { |
| 599 | return mDischargeCounter; |
| 600 | } |
| 601 | |
Adam Lesinski | f9b20a9 | 2016-06-17 17:30:01 -0700 | [diff] [blame] | 602 | @Override |
| 603 | public int getEstimatedBatteryCapacity() { |
| 604 | return mEstimatedBatteryCapacity; |
| 605 | } |
| 606 | |
Jocelyn Dang | c627d10 | 2017-04-14 13:15:14 -0700 | [diff] [blame^] | 607 | @Override |
| 608 | public int getMinLearnedBatteryCapacity() { |
| 609 | return mMinLearnedBatteryCapacity; |
| 610 | } |
| 611 | |
| 612 | @Override |
| 613 | public int getMaxLearnedBatteryCapacity() { |
| 614 | return mMaxLearnedBatteryCapacity; |
| 615 | } |
| 616 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 617 | public BatteryStatsImpl() { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 618 | this(new SystemClocks()); |
| 619 | } |
| 620 | |
| 621 | public BatteryStatsImpl(Clocks clocks) { |
| 622 | init(clocks); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 623 | mFile = null; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 624 | mCheckinFile = null; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 625 | mDailyFile = null; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 626 | mHandler = null; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 627 | mExternalSync = null; |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 628 | mPlatformIdleStateCallback = null; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 629 | clearHistoryLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 630 | } |
| 631 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 632 | private void init(Clocks clocks) { |
| 633 | mClocks = clocks; |
| 634 | mMobileNetworkStats = new NetworkStats[] { |
| 635 | new NetworkStats(mClocks.elapsedRealtime(), 50), |
| 636 | new NetworkStats(mClocks.elapsedRealtime(), 50), |
| 637 | new NetworkStats(mClocks.elapsedRealtime(), 50) |
| 638 | }; |
| 639 | mWifiNetworkStats = new NetworkStats[] { |
| 640 | new NetworkStats(mClocks.elapsedRealtime(), 50), |
| 641 | new NetworkStats(mClocks.elapsedRealtime(), 50), |
| 642 | new NetworkStats(mClocks.elapsedRealtime(), 50) |
| 643 | }; |
| 644 | } |
| 645 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 646 | public static interface TimeBaseObs { |
| 647 | void onTimeStarted(long elapsedRealtime, long baseUptime, long baseRealtime); |
| 648 | void onTimeStopped(long elapsedRealtime, long baseUptime, long baseRealtime); |
| 649 | } |
| 650 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 651 | // methods are protected not private to be VisibleForTesting |
| 652 | public static class TimeBase { |
| 653 | protected final ArrayList<TimeBaseObs> mObservers = new ArrayList<>(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 654 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 655 | protected long mUptime; |
| 656 | protected long mRealtime; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 657 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 658 | protected boolean mRunning; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 659 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 660 | protected long mPastUptime; |
| 661 | protected long mUptimeStart; |
| 662 | protected long mPastRealtime; |
| 663 | protected long mRealtimeStart; |
| 664 | protected long mUnpluggedUptime; |
| 665 | protected long mUnpluggedRealtime; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 666 | |
| 667 | public void dump(PrintWriter pw, String prefix) { |
| 668 | StringBuilder sb = new StringBuilder(128); |
| 669 | pw.print(prefix); pw.print("mRunning="); pw.println(mRunning); |
| 670 | sb.setLength(0); |
| 671 | sb.append(prefix); |
| 672 | sb.append("mUptime="); |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 673 | formatTimeMs(sb, mUptime / 1000); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 674 | pw.println(sb.toString()); |
| 675 | sb.setLength(0); |
| 676 | sb.append(prefix); |
| 677 | sb.append("mRealtime="); |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 678 | formatTimeMs(sb, mRealtime / 1000); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 679 | pw.println(sb.toString()); |
| 680 | sb.setLength(0); |
| 681 | sb.append(prefix); |
| 682 | sb.append("mPastUptime="); |
| 683 | formatTimeMs(sb, mPastUptime / 1000); sb.append("mUptimeStart="); |
| 684 | formatTimeMs(sb, mUptimeStart / 1000); |
| 685 | sb.append("mUnpluggedUptime="); formatTimeMs(sb, mUnpluggedUptime / 1000); |
| 686 | pw.println(sb.toString()); |
| 687 | sb.setLength(0); |
| 688 | sb.append(prefix); |
| 689 | sb.append("mPastRealtime="); |
| 690 | formatTimeMs(sb, mPastRealtime / 1000); sb.append("mRealtimeStart="); |
| 691 | formatTimeMs(sb, mRealtimeStart / 1000); |
| 692 | sb.append("mUnpluggedRealtime="); formatTimeMs(sb, mUnpluggedRealtime / 1000); |
| 693 | pw.println(sb.toString()); |
| 694 | } |
| 695 | |
| 696 | public void add(TimeBaseObs observer) { |
| 697 | mObservers.add(observer); |
| 698 | } |
| 699 | |
| 700 | public void remove(TimeBaseObs observer) { |
| 701 | if (!mObservers.remove(observer)) { |
| 702 | Slog.wtf(TAG, "Removed unknown observer: " + observer); |
| 703 | } |
| 704 | } |
| 705 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 706 | public boolean hasObserver(TimeBaseObs observer) { |
| 707 | return mObservers.contains(observer); |
| 708 | } |
| 709 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 710 | public void init(long uptime, long realtime) { |
| 711 | mRealtime = 0; |
| 712 | mUptime = 0; |
| 713 | mPastUptime = 0; |
| 714 | mPastRealtime = 0; |
| 715 | mUptimeStart = uptime; |
| 716 | mRealtimeStart = realtime; |
| 717 | mUnpluggedUptime = getUptime(mUptimeStart); |
| 718 | mUnpluggedRealtime = getRealtime(mRealtimeStart); |
| 719 | } |
| 720 | |
| 721 | public void reset(long uptime, long realtime) { |
| 722 | if (!mRunning) { |
| 723 | mPastUptime = 0; |
| 724 | mPastRealtime = 0; |
| 725 | } else { |
| 726 | mUptimeStart = uptime; |
| 727 | mRealtimeStart = realtime; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 728 | // TODO: Since mUptimeStart was just reset and we are running, getUptime will |
| 729 | // 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] | 730 | mUnpluggedUptime = getUptime(uptime); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 731 | // TODO: likewise. |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 732 | mUnpluggedRealtime = getRealtime(realtime); |
| 733 | } |
| 734 | } |
| 735 | |
| 736 | public long computeUptime(long curTime, int which) { |
| 737 | switch (which) { |
| 738 | case STATS_SINCE_CHARGED: |
| 739 | return mUptime + getUptime(curTime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 740 | case STATS_CURRENT: |
| 741 | return getUptime(curTime); |
| 742 | case STATS_SINCE_UNPLUGGED: |
| 743 | return getUptime(curTime) - mUnpluggedUptime; |
| 744 | } |
| 745 | return 0; |
| 746 | } |
| 747 | |
| 748 | public long computeRealtime(long curTime, int which) { |
| 749 | switch (which) { |
| 750 | case STATS_SINCE_CHARGED: |
| 751 | return mRealtime + getRealtime(curTime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 752 | case STATS_CURRENT: |
| 753 | return getRealtime(curTime); |
| 754 | case STATS_SINCE_UNPLUGGED: |
| 755 | return getRealtime(curTime) - mUnpluggedRealtime; |
| 756 | } |
| 757 | return 0; |
| 758 | } |
| 759 | |
| 760 | public long getUptime(long curTime) { |
| 761 | long time = mPastUptime; |
| 762 | if (mRunning) { |
| 763 | time += curTime - mUptimeStart; |
| 764 | } |
| 765 | return time; |
| 766 | } |
| 767 | |
| 768 | public long getRealtime(long curTime) { |
| 769 | long time = mPastRealtime; |
| 770 | if (mRunning) { |
| 771 | time += curTime - mRealtimeStart; |
| 772 | } |
| 773 | return time; |
| 774 | } |
| 775 | |
| 776 | public long getUptimeStart() { |
| 777 | return mUptimeStart; |
| 778 | } |
| 779 | |
| 780 | public long getRealtimeStart() { |
| 781 | return mRealtimeStart; |
| 782 | } |
| 783 | |
| 784 | public boolean isRunning() { |
| 785 | return mRunning; |
| 786 | } |
| 787 | |
| 788 | public boolean setRunning(boolean running, long uptime, long realtime) { |
| 789 | if (mRunning != running) { |
| 790 | mRunning = running; |
| 791 | if (running) { |
| 792 | mUptimeStart = uptime; |
| 793 | mRealtimeStart = realtime; |
| 794 | long batteryUptime = mUnpluggedUptime = getUptime(uptime); |
| 795 | long batteryRealtime = mUnpluggedRealtime = getRealtime(realtime); |
| 796 | |
| 797 | for (int i = mObservers.size() - 1; i >= 0; i--) { |
| 798 | mObservers.get(i).onTimeStarted(realtime, batteryUptime, batteryRealtime); |
| 799 | } |
| 800 | } else { |
| 801 | mPastUptime += uptime - mUptimeStart; |
| 802 | mPastRealtime += realtime - mRealtimeStart; |
| 803 | |
| 804 | long batteryUptime = getUptime(uptime); |
| 805 | long batteryRealtime = getRealtime(realtime); |
| 806 | |
| 807 | for (int i = mObservers.size() - 1; i >= 0; i--) { |
| 808 | mObservers.get(i).onTimeStopped(realtime, batteryUptime, batteryRealtime); |
| 809 | } |
| 810 | } |
| 811 | return true; |
| 812 | } |
| 813 | return false; |
| 814 | } |
| 815 | |
| 816 | public void readSummaryFromParcel(Parcel in) { |
| 817 | mUptime = in.readLong(); |
| 818 | mRealtime = in.readLong(); |
| 819 | } |
| 820 | |
| 821 | public void writeSummaryToParcel(Parcel out, long uptime, long realtime) { |
| 822 | out.writeLong(computeUptime(uptime, STATS_SINCE_CHARGED)); |
| 823 | out.writeLong(computeRealtime(realtime, STATS_SINCE_CHARGED)); |
| 824 | } |
| 825 | |
| 826 | public void readFromParcel(Parcel in) { |
| 827 | mRunning = false; |
| 828 | mUptime = in.readLong(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 829 | mPastUptime = in.readLong(); |
| 830 | mUptimeStart = in.readLong(); |
Dianne Hackborn | ef640cd | 2014-03-25 14:41:05 -0700 | [diff] [blame] | 831 | mRealtime = in.readLong(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 832 | mPastRealtime = in.readLong(); |
| 833 | mRealtimeStart = in.readLong(); |
| 834 | mUnpluggedUptime = in.readLong(); |
| 835 | mUnpluggedRealtime = in.readLong(); |
| 836 | } |
| 837 | |
| 838 | public void writeToParcel(Parcel out, long uptime, long realtime) { |
| 839 | final long runningUptime = getUptime(uptime); |
| 840 | final long runningRealtime = getRealtime(realtime); |
| 841 | out.writeLong(mUptime); |
| 842 | out.writeLong(runningUptime); |
| 843 | out.writeLong(mUptimeStart); |
Dianne Hackborn | ef640cd | 2014-03-25 14:41:05 -0700 | [diff] [blame] | 844 | out.writeLong(mRealtime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 845 | out.writeLong(runningRealtime); |
| 846 | out.writeLong(mRealtimeStart); |
| 847 | out.writeLong(mUnpluggedUptime); |
| 848 | out.writeLong(mUnpluggedRealtime); |
| 849 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 850 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 851 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 852 | /** |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 853 | * State for keeping track of counting information. |
| 854 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 855 | public static class Counter extends BatteryStats.Counter implements TimeBaseObs { |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 856 | final AtomicInteger mCount = new AtomicInteger(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 857 | final TimeBase mTimeBase; |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 858 | int mLoadedCount; |
| 859 | int mLastCount; |
| 860 | int mUnpluggedCount; |
| 861 | int mPluggedCount; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 862 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 863 | Counter(TimeBase timeBase, Parcel in) { |
| 864 | mTimeBase = timeBase; |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 865 | mPluggedCount = in.readInt(); |
| 866 | mCount.set(mPluggedCount); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 867 | mLoadedCount = in.readInt(); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 868 | mLastCount = 0; |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 869 | mUnpluggedCount = in.readInt(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 870 | timeBase.add(this); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 871 | } |
| 872 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 873 | Counter(TimeBase timeBase) { |
| 874 | mTimeBase = timeBase; |
| 875 | timeBase.add(this); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 876 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 877 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 878 | public void writeToParcel(Parcel out) { |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 879 | out.writeInt(mCount.get()); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 880 | out.writeInt(mLoadedCount); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 881 | out.writeInt(mUnpluggedCount); |
| 882 | } |
| 883 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 884 | public void onTimeStarted(long elapsedRealtime, long baseUptime, long baseRealtime) { |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 885 | mUnpluggedCount = mPluggedCount; |
| 886 | mCount.set(mPluggedCount); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 887 | } |
| 888 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 889 | public void onTimeStopped(long elapsedRealtime, long baseUptime, long baseRealtime) { |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 890 | mPluggedCount = mCount.get(); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 891 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 892 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 893 | /** |
| 894 | * Writes a possibly null Counter to a Parcel. |
| 895 | * |
| 896 | * @param out the Parcel to be written to. |
| 897 | * @param counter a Counter, or null. |
| 898 | */ |
| 899 | public static void writeCounterToParcel(Parcel out, Counter counter) { |
| 900 | if (counter == null) { |
| 901 | out.writeInt(0); // indicates null |
| 902 | return; |
| 903 | } |
| 904 | out.writeInt(1); // indicates non-null |
| 905 | |
| 906 | counter.writeToParcel(out); |
| 907 | } |
| 908 | |
| 909 | @Override |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 910 | public int getCountLocked(int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 911 | int val = mCount.get(); |
| 912 | if (which == STATS_SINCE_UNPLUGGED) { |
| 913 | val -= mUnpluggedCount; |
| 914 | } else if (which != STATS_SINCE_CHARGED) { |
| 915 | val -= mLoadedCount; |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 916 | } |
| 917 | |
| 918 | return val; |
| 919 | } |
| 920 | |
| 921 | public void logState(Printer pw, String prefix) { |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 922 | pw.println(prefix + "mCount=" + mCount.get() |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 923 | + " mLoadedCount=" + mLoadedCount + " mLastCount=" + mLastCount |
| 924 | + " mUnpluggedCount=" + mUnpluggedCount |
| 925 | + " mPluggedCount=" + mPluggedCount); |
| 926 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 927 | |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 928 | void stepAtomic() { |
| 929 | mCount.incrementAndGet(); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 930 | } |
| 931 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 932 | /** |
| 933 | * Clear state of this counter. |
| 934 | */ |
| 935 | void reset(boolean detachIfReset) { |
| 936 | mCount.set(0); |
| 937 | mLoadedCount = mLastCount = mPluggedCount = mUnpluggedCount = 0; |
| 938 | if (detachIfReset) { |
| 939 | detach(); |
| 940 | } |
| 941 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 942 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 943 | void detach() { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 944 | mTimeBase.remove(this); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 945 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 946 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 947 | void writeSummaryFromParcelLocked(Parcel out) { |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 948 | int count = mCount.get(); |
| 949 | out.writeInt(count); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 950 | } |
| 951 | |
| 952 | void readSummaryFromParcelLocked(Parcel in) { |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 953 | mLoadedCount = in.readInt(); |
| 954 | mCount.set(mLoadedCount); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 955 | mLastCount = 0; |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 956 | mUnpluggedCount = mPluggedCount = mLoadedCount; |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 957 | } |
| 958 | } |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 959 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 960 | public static class LongSamplingCounter extends LongCounter implements TimeBaseObs { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 961 | final TimeBase mTimeBase; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 962 | long mCount; |
| 963 | long mLoadedCount; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 964 | long mUnpluggedCount; |
| 965 | long mPluggedCount; |
| 966 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 967 | LongSamplingCounter(TimeBase timeBase, Parcel in) { |
| 968 | mTimeBase = timeBase; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 969 | mPluggedCount = in.readLong(); |
| 970 | mCount = mPluggedCount; |
| 971 | mLoadedCount = in.readLong(); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 972 | mUnpluggedCount = in.readLong(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 973 | timeBase.add(this); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 974 | } |
| 975 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 976 | LongSamplingCounter(TimeBase timeBase) { |
| 977 | mTimeBase = timeBase; |
| 978 | timeBase.add(this); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 979 | } |
| 980 | |
| 981 | public void writeToParcel(Parcel out) { |
| 982 | out.writeLong(mCount); |
| 983 | out.writeLong(mLoadedCount); |
| 984 | out.writeLong(mUnpluggedCount); |
| 985 | } |
| 986 | |
| 987 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 988 | public void onTimeStarted(long elapsedRealtime, long baseUptime, long baseRealtime) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 989 | mUnpluggedCount = mPluggedCount; |
| 990 | mCount = mPluggedCount; |
| 991 | } |
| 992 | |
| 993 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 994 | public void onTimeStopped(long elapsedRealtime, long baseUptime, long baseRealtime) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 995 | mPluggedCount = mCount; |
| 996 | } |
| 997 | |
| 998 | public long getCountLocked(int which) { |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 999 | long val = mTimeBase.isRunning() ? mCount : mPluggedCount; |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 1000 | if (which == STATS_SINCE_UNPLUGGED) { |
| 1001 | val -= mUnpluggedCount; |
| 1002 | } else if (which != STATS_SINCE_CHARGED) { |
| 1003 | val -= mLoadedCount; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 1004 | } |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 1005 | return val; |
| 1006 | } |
| 1007 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1008 | @Override |
| 1009 | public void logState(Printer pw, String prefix) { |
| 1010 | pw.println(prefix + "mCount=" + mCount |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 1011 | + " mLoadedCount=" + mLoadedCount |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1012 | + " mUnpluggedCount=" + mUnpluggedCount |
| 1013 | + " mPluggedCount=" + mPluggedCount); |
| 1014 | } |
| 1015 | |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 1016 | void addCountLocked(long count) { |
| 1017 | mCount += count; |
| 1018 | } |
| 1019 | |
| 1020 | /** |
| 1021 | * Clear state of this counter. |
| 1022 | */ |
| 1023 | void reset(boolean detachIfReset) { |
| 1024 | mCount = 0; |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 1025 | mLoadedCount = mPluggedCount = mUnpluggedCount = 0; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 1026 | if (detachIfReset) { |
| 1027 | detach(); |
| 1028 | } |
| 1029 | } |
| 1030 | |
| 1031 | void detach() { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1032 | mTimeBase.remove(this); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 1033 | } |
| 1034 | |
| 1035 | void writeSummaryFromParcelLocked(Parcel out) { |
| 1036 | out.writeLong(mCount); |
| 1037 | } |
| 1038 | |
| 1039 | void readSummaryFromParcelLocked(Parcel in) { |
| 1040 | mLoadedCount = in.readLong(); |
| 1041 | mCount = mLoadedCount; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 1042 | mUnpluggedCount = mPluggedCount = mLoadedCount; |
| 1043 | } |
| 1044 | } |
| 1045 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1046 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1047 | * State for keeping track of timing information. |
| 1048 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1049 | public static abstract class Timer extends BatteryStats.Timer implements TimeBaseObs { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1050 | protected final Clocks mClocks; |
| 1051 | protected final int mType; |
| 1052 | protected final TimeBase mTimeBase; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1053 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1054 | protected int mCount; |
| 1055 | protected int mLoadedCount; |
| 1056 | protected int mLastCount; |
| 1057 | protected int mUnpluggedCount; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1058 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1059 | // Times are in microseconds for better accuracy when dividing by the |
| 1060 | // lock count, and are in "battery realtime" units. |
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 total time we have accumulated since the start of the original |
| 1064 | * boot, to the last time something interesting happened in the |
| 1065 | * current run. |
| 1066 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1067 | protected long mTotalTime; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1068 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1069 | /** |
| 1070 | * The total time we loaded for the previous runs. Subtract this from |
| 1071 | * mTotalTime to find the time for the current run of the system. |
| 1072 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1073 | protected long mLoadedTime; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1074 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1075 | /** |
| 1076 | * The run time of the last run of the system, as loaded from the |
| 1077 | * saved data. |
| 1078 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1079 | protected long mLastTime; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1080 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1081 | /** |
| 1082 | * The value of mTotalTime when unplug() was last called. Subtract |
| 1083 | * this from mTotalTime to find the time since the last unplug from |
| 1084 | * power. |
| 1085 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1086 | protected long mUnpluggedTime; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1087 | |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 1088 | /** |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 1089 | * The total time this timer has been running until the latest mark has been set. |
| 1090 | * Subtract this from mTotalTime to get the time spent running since the mark was set. |
| 1091 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1092 | protected long mTimeBeforeMark; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 1093 | |
| 1094 | /** |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 1095 | * Constructs from a parcel. |
| 1096 | * @param type |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1097 | * @param timeBase |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 1098 | * @param in |
| 1099 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1100 | public Timer(Clocks clocks, int type, TimeBase timeBase, Parcel in) { |
| 1101 | mClocks = clocks; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1102 | mType = type; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1103 | mTimeBase = timeBase; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1104 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1105 | mCount = in.readInt(); |
| 1106 | mLoadedCount = in.readInt(); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 1107 | mLastCount = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1108 | mUnpluggedCount = in.readInt(); |
| 1109 | mTotalTime = in.readLong(); |
| 1110 | mLoadedTime = in.readLong(); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 1111 | mLastTime = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1112 | mUnpluggedTime = in.readLong(); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 1113 | mTimeBeforeMark = in.readLong(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1114 | timeBase.add(this); |
Dianne Hackborn | 2932513 | 2014-05-21 15:01:03 -0700 | [diff] [blame] | 1115 | 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] | 1116 | } |
| 1117 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1118 | public Timer(Clocks clocks, int type, TimeBase timeBase) { |
| 1119 | mClocks = clocks; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1120 | mType = type; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1121 | mTimeBase = timeBase; |
| 1122 | timeBase.add(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1123 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1124 | |
| 1125 | protected abstract long computeRunTimeLocked(long curBatteryRealtime); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1126 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1127 | protected abstract int computeCurrentCountLocked(); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1128 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1129 | /** |
| 1130 | * Clear state of this timer. Returns true if the timer is inactive |
| 1131 | * so can be completely dropped. |
| 1132 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1133 | public boolean reset(boolean detachIfReset) { |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 1134 | mTotalTime = mLoadedTime = mLastTime = mTimeBeforeMark = 0; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1135 | mCount = mLoadedCount = mLastCount = 0; |
| 1136 | if (detachIfReset) { |
| 1137 | detach(); |
| 1138 | } |
| 1139 | return true; |
| 1140 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1141 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1142 | public void detach() { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1143 | mTimeBase.remove(this); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1144 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1145 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1146 | public void writeToParcel(Parcel out, long elapsedRealtimeUs) { |
Dianne Hackborn | 2932513 | 2014-05-21 15:01:03 -0700 | [diff] [blame] | 1147 | if (DEBUG) Log.i(TAG, "**** WRITING TIMER #" + mType + ": mTotalTime=" |
| 1148 | + computeRunTimeLocked(mTimeBase.getRealtime(elapsedRealtimeUs))); |
Adam Lesinski | 98f0d46 | 2016-04-19 16:46:20 -0700 | [diff] [blame] | 1149 | out.writeInt(computeCurrentCountLocked()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1150 | out.writeInt(mLoadedCount); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1151 | out.writeInt(mUnpluggedCount); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1152 | out.writeLong(computeRunTimeLocked(mTimeBase.getRealtime(elapsedRealtimeUs))); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1153 | out.writeLong(mLoadedTime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1154 | out.writeLong(mUnpluggedTime); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 1155 | out.writeLong(mTimeBeforeMark); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1156 | } |
| 1157 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 1158 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1159 | public void onTimeStarted(long elapsedRealtime, long timeBaseUptime, long baseRealtime) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1160 | if (DEBUG && mType < 0) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1161 | Log.v(TAG, "unplug #" + mType + ": realtime=" + baseRealtime |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1162 | + " old mUnpluggedTime=" + mUnpluggedTime |
| 1163 | + " old mUnpluggedCount=" + mUnpluggedCount); |
| 1164 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1165 | mUnpluggedTime = computeRunTimeLocked(baseRealtime); |
Adam Lesinski | 98f0d46 | 2016-04-19 16:46:20 -0700 | [diff] [blame] | 1166 | mUnpluggedCount = computeCurrentCountLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1167 | if (DEBUG && mType < 0) { |
| 1168 | Log.v(TAG, "unplug #" + mType |
| 1169 | + ": new mUnpluggedTime=" + mUnpluggedTime |
| 1170 | + " new mUnpluggedCount=" + mUnpluggedCount); |
| 1171 | } |
| 1172 | } |
| 1173 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 1174 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1175 | public void onTimeStopped(long elapsedRealtime, long baseUptime, long baseRealtime) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1176 | if (DEBUG && mType < 0) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1177 | Log.v(TAG, "plug #" + mType + ": realtime=" + baseRealtime |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1178 | + " old mTotalTime=" + mTotalTime); |
| 1179 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1180 | mTotalTime = computeRunTimeLocked(baseRealtime); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1181 | mCount = computeCurrentCountLocked(); |
| 1182 | if (DEBUG && mType < 0) { |
| 1183 | Log.v(TAG, "plug #" + mType |
| 1184 | + ": new mTotalTime=" + mTotalTime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1185 | } |
| 1186 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1187 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1188 | /** |
| 1189 | * Writes a possibly null Timer to a Parcel. |
| 1190 | * |
| 1191 | * @param out the Parcel to be written to. |
| 1192 | * @param timer a Timer, or null. |
| 1193 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1194 | 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] | 1195 | if (timer == null) { |
| 1196 | out.writeInt(0); // indicates null |
| 1197 | return; |
| 1198 | } |
| 1199 | out.writeInt(1); // indicates non-null |
| 1200 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1201 | timer.writeToParcel(out, elapsedRealtimeUs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1202 | } |
| 1203 | |
| 1204 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1205 | public long getTotalTimeLocked(long elapsedRealtimeUs, int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 1206 | long val = computeRunTimeLocked(mTimeBase.getRealtime(elapsedRealtimeUs)); |
| 1207 | if (which == STATS_SINCE_UNPLUGGED) { |
| 1208 | val -= mUnpluggedTime; |
| 1209 | } else if (which != STATS_SINCE_CHARGED) { |
| 1210 | val -= mLoadedTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1211 | } |
| 1212 | |
| 1213 | return val; |
| 1214 | } |
| 1215 | |
| 1216 | @Override |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1217 | public int getCountLocked(int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 1218 | int val = computeCurrentCountLocked(); |
| 1219 | if (which == STATS_SINCE_UNPLUGGED) { |
| 1220 | val -= mUnpluggedCount; |
| 1221 | } else if (which != STATS_SINCE_CHARGED) { |
| 1222 | val -= mLoadedCount; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1223 | } |
| 1224 | |
| 1225 | return val; |
| 1226 | } |
| 1227 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 1228 | @Override |
| 1229 | public long getTimeSinceMarkLocked(long elapsedRealtimeUs) { |
| 1230 | long val = computeRunTimeLocked(mTimeBase.getRealtime(elapsedRealtimeUs)); |
| 1231 | return val - mTimeBeforeMark; |
| 1232 | } |
| 1233 | |
| 1234 | @Override |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 1235 | public void logState(Printer pw, String prefix) { |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 1236 | pw.println(prefix + "mCount=" + mCount |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1237 | + " mLoadedCount=" + mLoadedCount + " mLastCount=" + mLastCount |
| 1238 | + " mUnpluggedCount=" + mUnpluggedCount); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 1239 | pw.println(prefix + "mTotalTime=" + mTotalTime |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1240 | + " mLoadedTime=" + mLoadedTime); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 1241 | pw.println(prefix + "mLastTime=" + mLastTime |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1242 | + " mUnpluggedTime=" + mUnpluggedTime); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1243 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1244 | |
| 1245 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1246 | public void writeSummaryFromParcelLocked(Parcel out, long elapsedRealtimeUs) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1247 | long runTime = computeRunTimeLocked(mTimeBase.getRealtime(elapsedRealtimeUs)); |
| 1248 | out.writeLong(runTime); |
Adam Lesinski | 98f0d46 | 2016-04-19 16:46:20 -0700 | [diff] [blame] | 1249 | out.writeInt(computeCurrentCountLocked()); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1250 | } |
| 1251 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1252 | public void readSummaryFromParcelLocked(Parcel in) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1253 | // Multiply by 1000 for backwards compatibility |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1254 | mTotalTime = mLoadedTime = in.readLong(); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 1255 | mLastTime = 0; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1256 | mUnpluggedTime = mTotalTime; |
| 1257 | mCount = mLoadedCount = in.readInt(); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 1258 | mLastCount = 0; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1259 | mUnpluggedCount = mCount; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 1260 | |
| 1261 | // When reading the summary, we set the mark to be the latest information. |
| 1262 | mTimeBeforeMark = mTotalTime; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1263 | } |
| 1264 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1265 | |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 1266 | /** |
| 1267 | * A counter meant to accept monotonically increasing values to its {@link #update(long, int)} |
| 1268 | * method. The state of the timer according to its {@link TimeBase} will determine how much |
| 1269 | * of the value is recorded. |
| 1270 | * |
| 1271 | * If the value being recorded resets, {@link #endSample()} can be called in order to |
| 1272 | * account for the change. If the value passed in to {@link #update(long, int)} decreased |
| 1273 | * between calls, the {@link #endSample()} is automatically called and the new value is |
| 1274 | * expected to increase monotonically from that point on. |
| 1275 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1276 | public static class SamplingTimer extends Timer { |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1277 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1278 | /** |
| 1279 | * The most recent reported count from /proc/wakelocks. |
| 1280 | */ |
| 1281 | int mCurrentReportedCount; |
| 1282 | |
| 1283 | /** |
| 1284 | * The reported count from /proc/wakelocks when unplug() was last |
| 1285 | * called. |
| 1286 | */ |
| 1287 | int mUnpluggedReportedCount; |
| 1288 | |
| 1289 | /** |
| 1290 | * The most recent reported total_time from /proc/wakelocks. |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1291 | */ |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1292 | long mCurrentReportedTotalTime; |
| 1293 | |
| 1294 | |
| 1295 | /** |
| 1296 | * The reported total_time from /proc/wakelocks when unplug() was last |
| 1297 | * called. |
| 1298 | */ |
| 1299 | long mUnpluggedReportedTotalTime; |
| 1300 | |
| 1301 | /** |
| 1302 | * Whether we are currently in a discharge cycle. |
| 1303 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1304 | boolean mTimeBaseRunning; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1305 | |
| 1306 | /** |
| 1307 | * Whether we are currently recording reported values. |
| 1308 | */ |
| 1309 | boolean mTrackingReportedValues; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1310 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1311 | /* |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1312 | * A sequence counter, incremented once for each update of the stats. |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1313 | */ |
| 1314 | int mUpdateVersion; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1315 | |
Adam Lesinski | 98f0d46 | 2016-04-19 16:46:20 -0700 | [diff] [blame] | 1316 | @VisibleForTesting |
| 1317 | public SamplingTimer(Clocks clocks, TimeBase timeBase, Parcel in) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1318 | super(clocks, 0, timeBase, in); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1319 | mCurrentReportedCount = in.readInt(); |
| 1320 | mUnpluggedReportedCount = in.readInt(); |
| 1321 | mCurrentReportedTotalTime = in.readLong(); |
| 1322 | mUnpluggedReportedTotalTime = in.readLong(); |
| 1323 | mTrackingReportedValues = in.readInt() == 1; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1324 | mTimeBaseRunning = timeBase.isRunning(); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1325 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1326 | |
Adam Lesinski | 98f0d46 | 2016-04-19 16:46:20 -0700 | [diff] [blame] | 1327 | @VisibleForTesting |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 1328 | public SamplingTimer(Clocks clocks, TimeBase timeBase) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1329 | super(clocks, 0, timeBase); |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 1330 | mTrackingReportedValues = false; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1331 | mTimeBaseRunning = timeBase.isRunning(); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1332 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1333 | |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 1334 | /** |
| 1335 | * Ends the current sample, allowing subsequent values to {@link #update(long, int)} to |
| 1336 | * be less than the values used for a previous invocation. |
| 1337 | */ |
| 1338 | public void endSample() { |
| 1339 | mTotalTime = computeRunTimeLocked(0 /* unused by us */); |
| 1340 | mCount = computeCurrentCountLocked(); |
| 1341 | mUnpluggedReportedTotalTime = mCurrentReportedTotalTime = 0; |
| 1342 | mUnpluggedReportedCount = mCurrentReportedCount = 0; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1343 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1344 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1345 | public void setUpdateVersion(int version) { |
| 1346 | mUpdateVersion = version; |
| 1347 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1348 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1349 | public int getUpdateVersion() { |
| 1350 | return mUpdateVersion; |
| 1351 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1352 | |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 1353 | /** |
| 1354 | * Updates the current recorded values. These are meant to be monotonically increasing |
| 1355 | * and cumulative. If you are dealing with deltas, use {@link #add(long, int)}. |
| 1356 | * |
| 1357 | * If the values being recorded have been reset, the monotonically increasing requirement |
| 1358 | * will be broken. In this case, {@link #endSample()} is automatically called and |
| 1359 | * the total value of totalTime and count are recorded, starting a new monotonically |
| 1360 | * increasing sample. |
| 1361 | * |
| 1362 | * @param totalTime total time of sample in microseconds. |
| 1363 | * @param count total number of times the event being sampled occurred. |
| 1364 | */ |
| 1365 | public void update(long totalTime, int count) { |
| 1366 | if (mTimeBaseRunning && !mTrackingReportedValues) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1367 | // Updating the reported value for the first time. |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 1368 | mUnpluggedReportedTotalTime = totalTime; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1369 | mUnpluggedReportedCount = count; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1370 | } |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 1371 | |
| 1372 | mTrackingReportedValues = true; |
| 1373 | |
| 1374 | if (totalTime < mCurrentReportedTotalTime || count < mCurrentReportedCount) { |
| 1375 | endSample(); |
| 1376 | } |
| 1377 | |
| 1378 | mCurrentReportedTotalTime = totalTime; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1379 | mCurrentReportedCount = count; |
| 1380 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1381 | |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 1382 | /** |
| 1383 | * Adds deltaTime and deltaCount to the current sample. |
| 1384 | * |
| 1385 | * @param deltaTime additional time recorded since the last sampled event, in microseconds. |
| 1386 | * @param deltaCount additional number of times the event being sampled occurred. |
| 1387 | */ |
| 1388 | public void add(long deltaTime, int deltaCount) { |
| 1389 | update(mCurrentReportedTotalTime + deltaTime, mCurrentReportedCount + deltaCount); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 1390 | } |
| 1391 | |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 1392 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1393 | public void onTimeStarted(long elapsedRealtime, long baseUptime, long baseRealtime) { |
| 1394 | super.onTimeStarted(elapsedRealtime, baseUptime, baseRealtime); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1395 | if (mTrackingReportedValues) { |
| 1396 | mUnpluggedReportedTotalTime = mCurrentReportedTotalTime; |
| 1397 | mUnpluggedReportedCount = mCurrentReportedCount; |
| 1398 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1399 | mTimeBaseRunning = true; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1400 | } |
| 1401 | |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 1402 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1403 | public void onTimeStopped(long elapsedRealtime, long baseUptime, long baseRealtime) { |
| 1404 | super.onTimeStopped(elapsedRealtime, baseUptime, baseRealtime); |
| 1405 | mTimeBaseRunning = false; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1406 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1407 | |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 1408 | @Override |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1409 | public void logState(Printer pw, String prefix) { |
| 1410 | super.logState(pw, prefix); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1411 | pw.println(prefix + "mCurrentReportedCount=" + mCurrentReportedCount |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1412 | + " mUnpluggedReportedCount=" + mUnpluggedReportedCount |
| 1413 | + " mCurrentReportedTotalTime=" + mCurrentReportedTotalTime |
| 1414 | + " mUnpluggedReportedTotalTime=" + mUnpluggedReportedTotalTime); |
| 1415 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1416 | |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 1417 | @Override |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1418 | protected long computeRunTimeLocked(long curBatteryRealtime) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1419 | return mTotalTime + (mTimeBaseRunning && mTrackingReportedValues |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1420 | ? mCurrentReportedTotalTime - mUnpluggedReportedTotalTime : 0); |
| 1421 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1422 | |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 1423 | @Override |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1424 | protected int computeCurrentCountLocked() { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1425 | return mCount + (mTimeBaseRunning && mTrackingReportedValues |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1426 | ? mCurrentReportedCount - mUnpluggedReportedCount : 0); |
| 1427 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1428 | |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 1429 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1430 | public void writeToParcel(Parcel out, long elapsedRealtimeUs) { |
| 1431 | super.writeToParcel(out, elapsedRealtimeUs); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1432 | out.writeInt(mCurrentReportedCount); |
| 1433 | out.writeInt(mUnpluggedReportedCount); |
| 1434 | out.writeLong(mCurrentReportedTotalTime); |
| 1435 | out.writeLong(mUnpluggedReportedTotalTime); |
| 1436 | out.writeInt(mTrackingReportedValues ? 1 : 0); |
| 1437 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1438 | |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 1439 | @Override |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1440 | public boolean reset(boolean detachIfReset) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1441 | super.reset(detachIfReset); |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 1442 | mTrackingReportedValues = false; |
| 1443 | mUnpluggedReportedTotalTime = 0; |
| 1444 | mUnpluggedReportedCount = 0; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1445 | return true; |
| 1446 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1447 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1448 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1449 | /** |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1450 | * A timer that increments in batches. It does not run for durations, but just jumps |
| 1451 | * for a pre-determined amount. |
| 1452 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1453 | public static class BatchTimer extends Timer { |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1454 | final Uid mUid; |
| 1455 | |
| 1456 | /** |
| 1457 | * The last time at which we updated the timer. This is in elapsed realtime microseconds. |
| 1458 | */ |
| 1459 | long mLastAddedTime; |
| 1460 | |
| 1461 | /** |
| 1462 | * The last duration that we added to the timer. This is in microseconds. |
| 1463 | */ |
| 1464 | long mLastAddedDuration; |
| 1465 | |
| 1466 | /** |
| 1467 | * Whether we are currently in a discharge cycle. |
| 1468 | */ |
| 1469 | boolean mInDischarge; |
| 1470 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1471 | BatchTimer(Clocks clocks, Uid uid, int type, TimeBase timeBase, Parcel in) { |
| 1472 | super(clocks, type, timeBase, in); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1473 | mUid = uid; |
| 1474 | mLastAddedTime = in.readLong(); |
| 1475 | mLastAddedDuration = in.readLong(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1476 | mInDischarge = timeBase.isRunning(); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1477 | } |
| 1478 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1479 | BatchTimer(Clocks clocks, Uid uid, int type, TimeBase timeBase) { |
| 1480 | super(clocks, type, timeBase); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1481 | mUid = uid; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1482 | mInDischarge = timeBase.isRunning(); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1483 | } |
| 1484 | |
| 1485 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1486 | public void writeToParcel(Parcel out, long elapsedRealtimeUs) { |
| 1487 | super.writeToParcel(out, elapsedRealtimeUs); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1488 | out.writeLong(mLastAddedTime); |
| 1489 | out.writeLong(mLastAddedDuration); |
| 1490 | } |
| 1491 | |
| 1492 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1493 | public void onTimeStopped(long elapsedRealtime, long baseUptime, long baseRealtime) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1494 | recomputeLastDuration(mClocks.elapsedRealtime() * 1000, false); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1495 | mInDischarge = false; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1496 | super.onTimeStopped(elapsedRealtime, baseUptime, baseRealtime); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1497 | } |
| 1498 | |
| 1499 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1500 | public void onTimeStarted(long elapsedRealtime, long baseUptime, long baseRealtime) { |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1501 | recomputeLastDuration(elapsedRealtime, false); |
| 1502 | mInDischarge = true; |
| 1503 | // If we are still within the last added duration, then re-added whatever remains. |
| 1504 | if (mLastAddedTime == elapsedRealtime) { |
| 1505 | mTotalTime += mLastAddedDuration; |
| 1506 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1507 | super.onTimeStarted(elapsedRealtime, baseUptime, baseRealtime); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1508 | } |
| 1509 | |
| 1510 | @Override |
| 1511 | public void logState(Printer pw, String prefix) { |
| 1512 | super.logState(pw, prefix); |
| 1513 | pw.println(prefix + "mLastAddedTime=" + mLastAddedTime |
| 1514 | + " mLastAddedDuration=" + mLastAddedDuration); |
| 1515 | } |
| 1516 | |
| 1517 | private long computeOverage(long curTime) { |
| 1518 | if (mLastAddedTime > 0) { |
| 1519 | return mLastTime + mLastAddedDuration - curTime; |
| 1520 | } |
| 1521 | return 0; |
| 1522 | } |
| 1523 | |
| 1524 | private void recomputeLastDuration(long curTime, boolean abort) { |
| 1525 | final long overage = computeOverage(curTime); |
| 1526 | if (overage > 0) { |
| 1527 | // Aborting before the duration ran out -- roll back the remaining |
| 1528 | // duration. Only do this if currently discharging; otherwise we didn't |
| 1529 | // actually add the time. |
| 1530 | if (mInDischarge) { |
| 1531 | mTotalTime -= overage; |
| 1532 | } |
| 1533 | if (abort) { |
| 1534 | mLastAddedTime = 0; |
| 1535 | } else { |
| 1536 | mLastAddedTime = curTime; |
| 1537 | mLastAddedDuration -= overage; |
| 1538 | } |
| 1539 | } |
| 1540 | } |
| 1541 | |
| 1542 | public void addDuration(BatteryStatsImpl stats, long durationMillis) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1543 | final long now = mClocks.elapsedRealtime() * 1000; |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1544 | recomputeLastDuration(now, true); |
| 1545 | mLastAddedTime = now; |
| 1546 | mLastAddedDuration = durationMillis * 1000; |
| 1547 | if (mInDischarge) { |
| 1548 | mTotalTime += mLastAddedDuration; |
| 1549 | mCount++; |
| 1550 | } |
| 1551 | } |
| 1552 | |
| 1553 | public void abortLastDuration(BatteryStatsImpl stats) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1554 | final long now = mClocks.elapsedRealtime() * 1000; |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1555 | recomputeLastDuration(now, true); |
| 1556 | } |
| 1557 | |
| 1558 | @Override |
| 1559 | protected int computeCurrentCountLocked() { |
| 1560 | return mCount; |
| 1561 | } |
| 1562 | |
| 1563 | @Override |
| 1564 | protected long computeRunTimeLocked(long curBatteryRealtime) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1565 | final long overage = computeOverage(mClocks.elapsedRealtime() * 1000); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1566 | if (overage > 0) { |
| 1567 | return mTotalTime = overage; |
| 1568 | } |
| 1569 | return mTotalTime; |
| 1570 | } |
| 1571 | |
| 1572 | @Override |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1573 | public boolean reset(boolean detachIfReset) { |
| 1574 | final long now = mClocks.elapsedRealtime() * 1000; |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1575 | recomputeLastDuration(now, true); |
| 1576 | boolean stillActive = mLastAddedTime == now; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1577 | super.reset(!stillActive && detachIfReset); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1578 | return !stillActive; |
| 1579 | } |
| 1580 | } |
| 1581 | |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 1582 | |
| 1583 | /** |
| 1584 | * A StopwatchTimer that also tracks the total and max individual |
| 1585 | * time spent active according to the given timebase. Whereas |
| 1586 | * StopwatchTimer apportions the time amongst all in the pool, |
| 1587 | * the total and max durations are not apportioned. |
| 1588 | */ |
| 1589 | public static class DurationTimer extends StopwatchTimer { |
| 1590 | /** |
| 1591 | * The time (in ms) that the timer was last acquired or the time base |
| 1592 | * last (re-)started. Increasing the nesting depth does not reset this time. |
| 1593 | * |
| 1594 | * -1 if the timer is currently not running or the time base is not running. |
| 1595 | * |
| 1596 | * If written to a parcel, the start time is reset, as is mNesting in the base class |
| 1597 | * StopwatchTimer. |
| 1598 | */ |
| 1599 | long mStartTimeMs = -1; |
| 1600 | |
| 1601 | /** |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 1602 | * The longest time period (in ms) that the timer has been active. Not pooled. |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 1603 | */ |
| 1604 | long mMaxDurationMs; |
| 1605 | |
| 1606 | /** |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 1607 | * The time (in ms) that that the timer has been active since most recent |
| 1608 | * stopRunningLocked() or reset(). Not pooled. |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 1609 | */ |
| 1610 | long mCurrentDurationMs; |
| 1611 | |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 1612 | /** |
| 1613 | * The total time (in ms) that that the timer has been active since most recent reset() |
| 1614 | * prior to the current startRunningLocked. This is the sum of all past currentDurations |
| 1615 | * (but not including the present currentDuration) since reset. Not pooled. |
| 1616 | */ |
| 1617 | long mTotalDurationMs; |
| 1618 | |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 1619 | public DurationTimer(Clocks clocks, Uid uid, int type, ArrayList<StopwatchTimer> timerPool, |
| 1620 | TimeBase timeBase, Parcel in) { |
| 1621 | super(clocks, uid, type, timerPool, timeBase, in); |
| 1622 | mMaxDurationMs = in.readLong(); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 1623 | mTotalDurationMs = in.readLong(); |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 1624 | } |
| 1625 | |
| 1626 | public DurationTimer(Clocks clocks, Uid uid, int type, ArrayList<StopwatchTimer> timerPool, |
| 1627 | TimeBase timeBase) { |
| 1628 | super(clocks, uid, type, timerPool, timeBase); |
| 1629 | } |
| 1630 | |
| 1631 | @Override |
| 1632 | public void writeToParcel(Parcel out, long elapsedRealtimeUs) { |
| 1633 | super.writeToParcel(out, elapsedRealtimeUs); |
Kweku Adams | 47db5a8 | 2016-12-09 19:04:50 -0800 | [diff] [blame] | 1634 | out.writeLong(getMaxDurationMsLocked(elapsedRealtimeUs / 1000)); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 1635 | out.writeLong(getTotalDurationMsLocked(elapsedRealtimeUs / 1000)); |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 1636 | } |
| 1637 | |
| 1638 | /** |
| 1639 | * Write the summary to the parcel. |
| 1640 | * |
| 1641 | * Since the time base is probably meaningless after we come back, reading |
| 1642 | * from this will have the effect of stopping the timer. So here all we write |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 1643 | * is the max and total durations. |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 1644 | */ |
| 1645 | @Override |
| 1646 | public void writeSummaryFromParcelLocked(Parcel out, long elapsedRealtimeUs) { |
| 1647 | super.writeSummaryFromParcelLocked(out, elapsedRealtimeUs); |
Kweku Adams | 47db5a8 | 2016-12-09 19:04:50 -0800 | [diff] [blame] | 1648 | out.writeLong(getMaxDurationMsLocked(elapsedRealtimeUs / 1000)); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 1649 | out.writeLong(getTotalDurationMsLocked(elapsedRealtimeUs / 1000)); |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 1650 | } |
| 1651 | |
| 1652 | /** |
| 1653 | * Read the summary parcel. |
| 1654 | * |
| 1655 | * Has the side effect of stopping the timer. |
| 1656 | */ |
| 1657 | @Override |
| 1658 | public void readSummaryFromParcelLocked(Parcel in) { |
| 1659 | super.readSummaryFromParcelLocked(in); |
| 1660 | mMaxDurationMs = in.readLong(); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 1661 | mTotalDurationMs = in.readLong(); |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 1662 | mStartTimeMs = -1; |
| 1663 | mCurrentDurationMs = 0; |
| 1664 | } |
| 1665 | |
| 1666 | /** |
| 1667 | * The TimeBase time started (again). |
| 1668 | * |
| 1669 | * If the timer is also running, store the start time. |
| 1670 | */ |
| 1671 | public void onTimeStarted(long elapsedRealtimeUs, long baseUptime, long baseRealtime) { |
| 1672 | super.onTimeStarted(elapsedRealtimeUs, baseUptime, baseRealtime); |
| 1673 | if (mNesting > 0) { |
Kweku Adams | 47db5a8 | 2016-12-09 19:04:50 -0800 | [diff] [blame] | 1674 | mStartTimeMs = baseRealtime / 1000; |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 1675 | } |
| 1676 | } |
| 1677 | |
| 1678 | /** |
| 1679 | * The TimeBase stopped running. |
| 1680 | * |
| 1681 | * If the timer is running, add the duration into mCurrentDurationMs. |
| 1682 | */ |
| 1683 | @Override |
Kweku Adams | 47db5a8 | 2016-12-09 19:04:50 -0800 | [diff] [blame] | 1684 | public void onTimeStopped(long elapsedRealtimeUs, long baseUptime, long baseRealtimeUs) { |
| 1685 | super.onTimeStopped(elapsedRealtimeUs, baseUptime, baseRealtimeUs); |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 1686 | if (mNesting > 0) { |
Kweku Adams | 47db5a8 | 2016-12-09 19:04:50 -0800 | [diff] [blame] | 1687 | // baseRealtimeUs has already been converted to the timebase's realtime. |
| 1688 | mCurrentDurationMs += (baseRealtimeUs / 1000) - mStartTimeMs; |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 1689 | } |
| 1690 | mStartTimeMs = -1; |
| 1691 | } |
| 1692 | |
| 1693 | @Override |
| 1694 | public void logState(Printer pw, String prefix) { |
| 1695 | super.logState(pw, prefix); |
| 1696 | } |
| 1697 | |
| 1698 | @Override |
| 1699 | public void startRunningLocked(long elapsedRealtimeMs) { |
| 1700 | super.startRunningLocked(elapsedRealtimeMs); |
| 1701 | if (mNesting == 1 && mTimeBase.isRunning()) { |
| 1702 | // Just started |
Kweku Adams | 47db5a8 | 2016-12-09 19:04:50 -0800 | [diff] [blame] | 1703 | mStartTimeMs = mTimeBase.getRealtime(elapsedRealtimeMs * 1000) / 1000; |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 1704 | } |
| 1705 | } |
| 1706 | |
| 1707 | /** |
| 1708 | * Decrements the mNesting ref-count on this timer. |
| 1709 | * |
| 1710 | * If it actually stopped (mNesting went to 0), then possibly update |
| 1711 | * mMaxDuration if the current duration was the longest ever. |
| 1712 | */ |
| 1713 | @Override |
| 1714 | public void stopRunningLocked(long elapsedRealtimeMs) { |
Kweku Adams | 47db5a8 | 2016-12-09 19:04:50 -0800 | [diff] [blame] | 1715 | if (mNesting == 1) { |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 1716 | final long durationMs = getCurrentDurationMsLocked(elapsedRealtimeMs); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 1717 | mTotalDurationMs += durationMs; |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 1718 | if (durationMs > mMaxDurationMs) { |
| 1719 | mMaxDurationMs = durationMs; |
| 1720 | } |
| 1721 | mStartTimeMs = -1; |
| 1722 | mCurrentDurationMs = 0; |
| 1723 | } |
Kweku Adams | 47db5a8 | 2016-12-09 19:04:50 -0800 | [diff] [blame] | 1724 | // super method decrements mNesting, which getCurrentDurationMsLocked relies on, |
| 1725 | // so call super.stopRunningLocked after calling getCurrentDurationMsLocked. |
| 1726 | super.stopRunningLocked(elapsedRealtimeMs); |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 1727 | } |
| 1728 | |
| 1729 | @Override |
| 1730 | public boolean reset(boolean detachIfReset) { |
| 1731 | boolean result = super.reset(detachIfReset); |
| 1732 | mMaxDurationMs = 0; |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 1733 | mTotalDurationMs = 0; |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 1734 | mCurrentDurationMs = 0; |
| 1735 | if (mNesting > 0) { |
| 1736 | mStartTimeMs = mTimeBase.getRealtime(mClocks.elapsedRealtime()*1000) / 1000; |
| 1737 | } else { |
| 1738 | mStartTimeMs = -1; |
| 1739 | } |
| 1740 | return result; |
| 1741 | } |
| 1742 | |
| 1743 | /** |
| 1744 | * Returns the max duration that this timer has ever seen. |
| 1745 | * |
| 1746 | * Note that this time is NOT split between the timers in the timer group that |
| 1747 | * this timer is attached to. It is the TOTAL time. |
| 1748 | */ |
| 1749 | @Override |
| 1750 | public long getMaxDurationMsLocked(long elapsedRealtimeMs) { |
| 1751 | if (mNesting > 0) { |
| 1752 | final long durationMs = getCurrentDurationMsLocked(elapsedRealtimeMs); |
| 1753 | if (durationMs > mMaxDurationMs) { |
| 1754 | return durationMs; |
| 1755 | } |
| 1756 | } |
| 1757 | return mMaxDurationMs; |
| 1758 | } |
| 1759 | |
| 1760 | /** |
| 1761 | * Returns the time since the timer was started. |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 1762 | * Returns 0 if the timer is not currently running. |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 1763 | * |
| 1764 | * Note that this time is NOT split between the timers in the timer group that |
| 1765 | * this timer is attached to. It is the TOTAL time. |
| 1766 | */ |
| 1767 | @Override |
| 1768 | public long getCurrentDurationMsLocked(long elapsedRealtimeMs) { |
| 1769 | long durationMs = mCurrentDurationMs; |
Kweku Adams | 47db5a8 | 2016-12-09 19:04:50 -0800 | [diff] [blame] | 1770 | if (mNesting > 0 && mTimeBase.isRunning()) { |
| 1771 | durationMs += (mTimeBase.getRealtime(elapsedRealtimeMs*1000)/1000) |
| 1772 | - mStartTimeMs; |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 1773 | } |
| 1774 | return durationMs; |
| 1775 | } |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 1776 | |
| 1777 | /** |
| 1778 | * Returns the total cumulative duration that this timer has been on since reset(). |
| 1779 | * If mTimerPool == null, this should be the same |
| 1780 | * as getTotalTimeLocked(elapsedRealtimeMs*1000, STATS_SINCE_CHARGED)/1000. |
| 1781 | * |
| 1782 | * Note that this time is NOT split between the timers in the timer group that |
| 1783 | * this timer is attached to. It is the TOTAL time. For this reason, if mTimerPool != null, |
| 1784 | * the result will not be equivalent to getTotalTimeLocked. |
| 1785 | */ |
| 1786 | @Override |
| 1787 | public long getTotalDurationMsLocked(long elapsedRealtimeMs) { |
| 1788 | return mTotalDurationMs + getCurrentDurationMsLocked(elapsedRealtimeMs); |
| 1789 | } |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 1790 | } |
| 1791 | |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1792 | /** |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1793 | * State for keeping track of timing information. |
| 1794 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1795 | public static class StopwatchTimer extends Timer { |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 1796 | final Uid mUid; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1797 | final ArrayList<StopwatchTimer> mTimerPool; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 1798 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1799 | int mNesting; |
| 1800 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1801 | /** |
| 1802 | * The last time at which we updated the timer. If mNesting is > 0, |
| 1803 | * subtract this from the current battery time to find the amount of |
| 1804 | * time we have been running since we last computed an update. |
| 1805 | */ |
| 1806 | long mUpdateTime; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1807 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1808 | /** |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 1809 | * The total time at which the timer was acquired, to determine if it |
Bookatz | ceebafe | 2017-04-06 11:59:13 -0700 | [diff] [blame] | 1810 | * was actually held for an interesting duration. If time base was not running when timer |
| 1811 | * was acquired, will be -1. |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1812 | */ |
Bookatz | ceebafe | 2017-04-06 11:59:13 -0700 | [diff] [blame] | 1813 | long mAcquireTime = -1; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1814 | |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 1815 | long mTimeout; |
| 1816 | |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 1817 | /** |
| 1818 | * For partial wake locks, keep track of whether we are in the list |
| 1819 | * to consume CPU cycles. |
| 1820 | */ |
| 1821 | boolean mInList; |
| 1822 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1823 | public StopwatchTimer(Clocks clocks, Uid uid, int type, ArrayList<StopwatchTimer> timerPool, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1824 | TimeBase timeBase, Parcel in) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1825 | super(clocks, type, timeBase, in); |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 1826 | mUid = uid; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1827 | mTimerPool = timerPool; |
| 1828 | mUpdateTime = in.readLong(); |
| 1829 | } |
| 1830 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1831 | public StopwatchTimer(Clocks clocks, Uid uid, int type, ArrayList<StopwatchTimer> timerPool, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1832 | TimeBase timeBase) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1833 | super(clocks, type, timeBase); |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 1834 | mUid = uid; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1835 | mTimerPool = timerPool; |
| 1836 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1837 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1838 | public void setTimeout(long timeout) { |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 1839 | mTimeout = timeout; |
| 1840 | } |
| 1841 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1842 | public void writeToParcel(Parcel out, long elapsedRealtimeUs) { |
| 1843 | super.writeToParcel(out, elapsedRealtimeUs); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1844 | out.writeLong(mUpdateTime); |
| 1845 | } |
| 1846 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1847 | public void onTimeStopped(long elapsedRealtime, long baseUptime, long baseRealtime) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1848 | if (mNesting > 0) { |
| 1849 | if (DEBUG && mType < 0) { |
| 1850 | Log.v(TAG, "old mUpdateTime=" + mUpdateTime); |
| 1851 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1852 | super.onTimeStopped(elapsedRealtime, baseUptime, baseRealtime); |
| 1853 | mUpdateTime = baseRealtime; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1854 | if (DEBUG && mType < 0) { |
| 1855 | Log.v(TAG, "new mUpdateTime=" + mUpdateTime); |
| 1856 | } |
| 1857 | } |
| 1858 | } |
| 1859 | |
| 1860 | public void logState(Printer pw, String prefix) { |
| 1861 | super.logState(pw, prefix); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 1862 | pw.println(prefix + "mNesting=" + mNesting + " mUpdateTime=" + mUpdateTime |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1863 | + " mAcquireTime=" + mAcquireTime); |
| 1864 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1865 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1866 | public void startRunningLocked(long elapsedRealtimeMs) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1867 | if (mNesting++ == 0) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1868 | final long batteryRealtime = mTimeBase.getRealtime(elapsedRealtimeMs * 1000); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 1869 | mUpdateTime = batteryRealtime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1870 | if (mTimerPool != null) { |
| 1871 | // Accumulate time to all currently active timers before adding |
| 1872 | // this new one to the pool. |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1873 | refreshTimersLocked(batteryRealtime, mTimerPool, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1874 | // Add this timer to the active pool |
| 1875 | mTimerPool.add(this); |
| 1876 | } |
Bookatz | ceebafe | 2017-04-06 11:59:13 -0700 | [diff] [blame] | 1877 | if (mTimeBase.isRunning()) { |
| 1878 | // Increment the count |
| 1879 | mCount++; |
| 1880 | mAcquireTime = mTotalTime; |
| 1881 | } else { |
| 1882 | mAcquireTime = -1; |
| 1883 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1884 | if (DEBUG && mType < 0) { |
| 1885 | Log.v(TAG, "start #" + mType + ": mUpdateTime=" + mUpdateTime |
| 1886 | + " mTotalTime=" + mTotalTime + " mCount=" + mCount |
| 1887 | + " mAcquireTime=" + mAcquireTime); |
| 1888 | } |
| 1889 | } |
| 1890 | } |
| 1891 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1892 | public boolean isRunningLocked() { |
Amith Yamasani | 32dbefd | 2009-06-19 09:21:17 -0700 | [diff] [blame] | 1893 | return mNesting > 0; |
| 1894 | } |
| 1895 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1896 | public void stopRunningLocked(long elapsedRealtimeMs) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1897 | // Ignore attempt to stop a timer that isn't running |
| 1898 | if (mNesting == 0) { |
| 1899 | return; |
| 1900 | } |
| 1901 | if (--mNesting == 0) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1902 | final long batteryRealtime = mTimeBase.getRealtime(elapsedRealtimeMs * 1000); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1903 | if (mTimerPool != null) { |
| 1904 | // Accumulate time to all active counters, scaled by the total |
| 1905 | // active in the pool, before taking this one out of the pool. |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1906 | refreshTimersLocked(batteryRealtime, mTimerPool, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1907 | // Remove this timer from the active pool |
| 1908 | mTimerPool.remove(this); |
| 1909 | } else { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1910 | mNesting = 1; |
| 1911 | mTotalTime = computeRunTimeLocked(batteryRealtime); |
| 1912 | mNesting = 0; |
| 1913 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1914 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1915 | if (DEBUG && mType < 0) { |
| 1916 | Log.v(TAG, "stop #" + mType + ": mUpdateTime=" + mUpdateTime |
| 1917 | + " mTotalTime=" + mTotalTime + " mCount=" + mCount |
| 1918 | + " mAcquireTime=" + mAcquireTime); |
| 1919 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1920 | |
Bookatz | ceebafe | 2017-04-06 11:59:13 -0700 | [diff] [blame] | 1921 | if (mAcquireTime >= 0 && mTotalTime == mAcquireTime) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1922 | // If there was no change in the time, then discard this |
| 1923 | // count. A somewhat cheezy strategy, but hey. |
| 1924 | mCount--; |
| 1925 | } |
| 1926 | } |
| 1927 | } |
| 1928 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1929 | public void stopAllRunningLocked(long elapsedRealtimeMs) { |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 1930 | if (mNesting > 0) { |
| 1931 | mNesting = 1; |
| 1932 | stopRunningLocked(elapsedRealtimeMs); |
| 1933 | } |
| 1934 | } |
| 1935 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1936 | // Update the total time for all other running Timers with the same type as this Timer |
| 1937 | // due to a change in timer count |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1938 | private static long refreshTimersLocked(long batteryRealtime, |
| 1939 | final ArrayList<StopwatchTimer> pool, StopwatchTimer self) { |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 1940 | long selfTime = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1941 | final int N = pool.size(); |
| 1942 | for (int i=N-1; i>= 0; i--) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1943 | final StopwatchTimer t = pool.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1944 | long heldTime = batteryRealtime - t.mUpdateTime; |
| 1945 | if (heldTime > 0) { |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 1946 | final long myTime = heldTime / N; |
| 1947 | if (t == self) { |
| 1948 | selfTime = myTime; |
| 1949 | } |
| 1950 | t.mTotalTime += myTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1951 | } |
| 1952 | t.mUpdateTime = batteryRealtime; |
| 1953 | } |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 1954 | return selfTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1955 | } |
| 1956 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1957 | @Override |
| 1958 | protected long computeRunTimeLocked(long curBatteryRealtime) { |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 1959 | if (mTimeout > 0 && curBatteryRealtime > mUpdateTime + mTimeout) { |
| 1960 | curBatteryRealtime = mUpdateTime + mTimeout; |
| 1961 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1962 | return mTotalTime + (mNesting > 0 |
| 1963 | ? (curBatteryRealtime - mUpdateTime) |
| 1964 | / (mTimerPool != null ? mTimerPool.size() : 1) |
| 1965 | : 0); |
| 1966 | } |
| 1967 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1968 | @Override |
| 1969 | protected int computeCurrentCountLocked() { |
| 1970 | return mCount; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1971 | } |
| 1972 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 1973 | @Override |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1974 | public boolean reset(boolean detachIfReset) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1975 | boolean canDetach = mNesting <= 0; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1976 | super.reset(canDetach && detachIfReset); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 1977 | if (mNesting > 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1978 | mUpdateTime = mTimeBase.getRealtime(mClocks.elapsedRealtime() * 1000); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 1979 | } |
Bookatz | ceebafe | 2017-04-06 11:59:13 -0700 | [diff] [blame] | 1980 | mAcquireTime = -1; // to ensure mCount isn't decreased to -1 if timer is stopped later. |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1981 | return canDetach; |
| 1982 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1983 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 1984 | @Override |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1985 | public void detach() { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1986 | super.detach(); |
| 1987 | if (mTimerPool != null) { |
| 1988 | mTimerPool.remove(this); |
| 1989 | } |
| 1990 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1991 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 1992 | @Override |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1993 | public void readSummaryFromParcelLocked(Parcel in) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1994 | super.readSummaryFromParcelLocked(in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1995 | mNesting = 0; |
| 1996 | } |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 1997 | |
| 1998 | /** |
| 1999 | * Set the mark so that we can query later for the total time the timer has |
| 2000 | * accumulated since this point. The timer can be running or not. |
| 2001 | * |
| 2002 | * @param elapsedRealtimeMs the current elapsed realtime in milliseconds. |
| 2003 | */ |
| 2004 | public void setMark(long elapsedRealtimeMs) { |
| 2005 | final long batteryRealtime = mTimeBase.getRealtime(elapsedRealtimeMs * 1000); |
| 2006 | if (mNesting > 0) { |
| 2007 | // We are running. |
| 2008 | if (mTimerPool != null) { |
| 2009 | refreshTimersLocked(batteryRealtime, mTimerPool, this); |
| 2010 | } else { |
| 2011 | mTotalTime += batteryRealtime - mUpdateTime; |
| 2012 | mUpdateTime = batteryRealtime; |
| 2013 | } |
| 2014 | } |
| 2015 | mTimeBeforeMark = mTotalTime; |
| 2016 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2017 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2018 | |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2019 | /** |
| 2020 | * State for keeping track of two DurationTimers with different TimeBases, presumably where one |
| 2021 | * TimeBase is effectively a subset of the other. |
| 2022 | */ |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 2023 | public static class DualTimer extends DurationTimer { |
| 2024 | // This class both is a DurationTimer and also holds a second DurationTimer. |
| 2025 | // The main timer (this) typically tracks the total time. It may be pooled (but since it's a |
| 2026 | // durationTimer, it also has the unpooled getTotalDurationMsLocked() for |
| 2027 | // STATS_SINCE_CHARGED). |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2028 | // mSubTimer typically tracks only part of the total time, such as background time, as |
| 2029 | // determined by a subTimeBase. It is NOT pooled. |
| 2030 | private final DurationTimer mSubTimer; |
| 2031 | |
| 2032 | /** |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 2033 | * Creates a DualTimer to hold a main timer (this) and a mSubTimer. |
| 2034 | * The main timer (this) is based on the given timeBase and timerPool. |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2035 | * The mSubTimer is based on the given subTimeBase. The mSubTimer is not pooled, even if |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 2036 | * the main timer is. |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2037 | */ |
| 2038 | public DualTimer(Clocks clocks, Uid uid, int type, ArrayList<StopwatchTimer> timerPool, |
| 2039 | TimeBase timeBase, TimeBase subTimeBase, Parcel in) { |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 2040 | super(clocks, uid, type, timerPool, timeBase, in); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2041 | mSubTimer = new DurationTimer(clocks, uid, type, null, subTimeBase, in); |
| 2042 | } |
| 2043 | |
| 2044 | /** |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 2045 | * Creates a DualTimer to hold a main timer (this) and a mSubTimer. |
| 2046 | * The main timer (this) is based on the given timeBase and timerPool. |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2047 | * The mSubTimer is based on the given subTimeBase. The mSubTimer is not pooled, even if |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 2048 | * the main timer is. |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2049 | */ |
| 2050 | public DualTimer(Clocks clocks, Uid uid, int type, ArrayList<StopwatchTimer> timerPool, |
| 2051 | TimeBase timeBase, TimeBase subTimeBase) { |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 2052 | super(clocks, uid, type, timerPool, timeBase); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2053 | mSubTimer = new DurationTimer(clocks, uid, type, null, subTimeBase); |
| 2054 | } |
| 2055 | |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2056 | /** Get the secondary timer. */ |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 2057 | @Override |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2058 | public DurationTimer getSubTimer() { |
| 2059 | return mSubTimer; |
| 2060 | } |
| 2061 | |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 2062 | @Override |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2063 | public void startRunningLocked(long elapsedRealtimeMs) { |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 2064 | super.startRunningLocked(elapsedRealtimeMs); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2065 | mSubTimer.startRunningLocked(elapsedRealtimeMs); |
| 2066 | } |
| 2067 | |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 2068 | @Override |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2069 | public void stopRunningLocked(long elapsedRealtimeMs) { |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 2070 | super.stopRunningLocked(elapsedRealtimeMs); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2071 | mSubTimer.stopRunningLocked(elapsedRealtimeMs); |
| 2072 | } |
| 2073 | |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 2074 | @Override |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2075 | public void stopAllRunningLocked(long elapsedRealtimeMs) { |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 2076 | super.stopAllRunningLocked(elapsedRealtimeMs); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2077 | mSubTimer.stopAllRunningLocked(elapsedRealtimeMs); |
| 2078 | } |
| 2079 | |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 2080 | @Override |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2081 | public boolean reset(boolean detachIfReset) { |
| 2082 | boolean active = false; |
Bookatz | 4a3eda9 | 2017-04-10 13:10:46 -0700 | [diff] [blame] | 2083 | // Do not detach the subTimer explicitly since that'll be done by DualTimer.detach(). |
| 2084 | active |= !mSubTimer.reset(false); |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 2085 | active |= !super.reset(detachIfReset); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2086 | return !active; |
| 2087 | } |
| 2088 | |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 2089 | @Override |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2090 | public void detach() { |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2091 | mSubTimer.detach(); |
Bookatz | 4a3eda9 | 2017-04-10 13:10:46 -0700 | [diff] [blame] | 2092 | super.detach(); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2093 | } |
| 2094 | |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 2095 | @Override |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2096 | public void writeToParcel(Parcel out, long elapsedRealtimeUs) { |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 2097 | super.writeToParcel(out, elapsedRealtimeUs); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2098 | mSubTimer.writeToParcel(out, elapsedRealtimeUs); |
| 2099 | } |
| 2100 | |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 2101 | @Override |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2102 | public void writeSummaryFromParcelLocked(Parcel out, long elapsedRealtimeUs) { |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 2103 | super.writeSummaryFromParcelLocked(out, elapsedRealtimeUs); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2104 | mSubTimer.writeSummaryFromParcelLocked(out, elapsedRealtimeUs); |
| 2105 | } |
| 2106 | |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 2107 | @Override |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2108 | public void readSummaryFromParcelLocked(Parcel in) { |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 2109 | super.readSummaryFromParcelLocked(in); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2110 | mSubTimer.readSummaryFromParcelLocked(in); |
| 2111 | } |
| 2112 | } |
| 2113 | |
| 2114 | |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 2115 | public abstract class OverflowArrayMap<T> { |
| 2116 | private static final String OVERFLOW_NAME = "*overflow*"; |
| 2117 | |
Dianne Hackborn | 657153b | 2016-07-29 14:54:14 -0700 | [diff] [blame] | 2118 | final int mUid; |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 2119 | final ArrayMap<String, T> mMap = new ArrayMap<>(); |
| 2120 | T mCurOverflow; |
| 2121 | ArrayMap<String, MutableInt> mActiveOverflow; |
Dianne Hackborn | 657153b | 2016-07-29 14:54:14 -0700 | [diff] [blame] | 2122 | long mLastOverflowTime; |
| 2123 | long mLastOverflowFinishTime; |
| 2124 | long mLastClearTime; |
| 2125 | long mLastCleanupTime; |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 2126 | |
Dianne Hackborn | 657153b | 2016-07-29 14:54:14 -0700 | [diff] [blame] | 2127 | public OverflowArrayMap(int uid) { |
| 2128 | mUid = uid; |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 2129 | } |
| 2130 | |
| 2131 | public ArrayMap<String, T> getMap() { |
| 2132 | return mMap; |
| 2133 | } |
| 2134 | |
| 2135 | public void clear() { |
Dianne Hackborn | 657153b | 2016-07-29 14:54:14 -0700 | [diff] [blame] | 2136 | mLastClearTime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 2137 | mMap.clear(); |
| 2138 | mCurOverflow = null; |
| 2139 | mActiveOverflow = null; |
| 2140 | } |
| 2141 | |
| 2142 | public void add(String name, T obj) { |
Joe Onorato | 388fc33 | 2016-04-12 17:06:47 -0700 | [diff] [blame] | 2143 | if (name == null) { |
| 2144 | name = ""; |
| 2145 | } |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 2146 | mMap.put(name, obj); |
| 2147 | if (OVERFLOW_NAME.equals(name)) { |
| 2148 | mCurOverflow = obj; |
| 2149 | } |
| 2150 | } |
| 2151 | |
| 2152 | public void cleanup() { |
Dianne Hackborn | 657153b | 2016-07-29 14:54:14 -0700 | [diff] [blame] | 2153 | mLastCleanupTime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 2154 | if (mActiveOverflow != null) { |
| 2155 | if (mActiveOverflow.size() == 0) { |
| 2156 | mActiveOverflow = null; |
| 2157 | } |
| 2158 | } |
| 2159 | if (mActiveOverflow == null) { |
| 2160 | // There is no currently active overflow, so we should no longer have |
| 2161 | // an overflow entry. |
| 2162 | if (mMap.containsKey(OVERFLOW_NAME)) { |
| 2163 | Slog.wtf(TAG, "Cleaning up with no active overflow, but have overflow entry " |
| 2164 | + mMap.get(OVERFLOW_NAME)); |
| 2165 | mMap.remove(OVERFLOW_NAME); |
| 2166 | } |
| 2167 | mCurOverflow = null; |
| 2168 | } else { |
| 2169 | // There is currently active overflow, so we should still have an overflow entry. |
| 2170 | if (mCurOverflow == null || !mMap.containsKey(OVERFLOW_NAME)) { |
| 2171 | Slog.wtf(TAG, "Cleaning up with active overflow, but no overflow entry: cur=" |
| 2172 | + mCurOverflow + " map=" + mMap.get(OVERFLOW_NAME)); |
| 2173 | } |
| 2174 | } |
| 2175 | } |
| 2176 | |
| 2177 | public T startObject(String name) { |
Joe Onorato | 388fc33 | 2016-04-12 17:06:47 -0700 | [diff] [blame] | 2178 | if (name == null) { |
| 2179 | name = ""; |
| 2180 | } |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 2181 | T obj = mMap.get(name); |
| 2182 | if (obj != null) { |
| 2183 | return obj; |
| 2184 | } |
| 2185 | |
| 2186 | // No object exists for the given name, but do we currently have it |
| 2187 | // running as part of the overflow? |
| 2188 | if (mActiveOverflow != null) { |
| 2189 | MutableInt over = mActiveOverflow.get(name); |
| 2190 | if (over != null) { |
| 2191 | // We are already actively counting this name in the overflow object. |
| 2192 | obj = mCurOverflow; |
| 2193 | if (obj == null) { |
| 2194 | // Shouldn't be here, but we'll try to recover. |
| 2195 | Slog.wtf(TAG, "Have active overflow " + name + " but null overflow"); |
| 2196 | obj = mCurOverflow = instantiateObject(); |
| 2197 | mMap.put(OVERFLOW_NAME, obj); |
| 2198 | } |
| 2199 | over.value++; |
| 2200 | return obj; |
| 2201 | } |
| 2202 | } |
| 2203 | |
| 2204 | // No object exists for given name nor in the overflow; we need to make |
| 2205 | // a new one. |
| 2206 | final int N = mMap.size(); |
| 2207 | if (N >= MAX_WAKELOCKS_PER_UID) { |
| 2208 | // Went over the limit on number of objects to track; this one goes |
| 2209 | // in to the overflow. |
| 2210 | obj = mCurOverflow; |
| 2211 | if (obj == null) { |
| 2212 | // Need to start overflow now... |
| 2213 | obj = mCurOverflow = instantiateObject(); |
| 2214 | mMap.put(OVERFLOW_NAME, obj); |
| 2215 | } |
| 2216 | if (mActiveOverflow == null) { |
| 2217 | mActiveOverflow = new ArrayMap<>(); |
| 2218 | } |
| 2219 | mActiveOverflow.put(name, new MutableInt(1)); |
Dianne Hackborn | 657153b | 2016-07-29 14:54:14 -0700 | [diff] [blame] | 2220 | mLastOverflowTime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 2221 | return obj; |
| 2222 | } |
| 2223 | |
| 2224 | // Normal case where we just need to make a new object. |
| 2225 | obj = instantiateObject(); |
| 2226 | mMap.put(name, obj); |
| 2227 | return obj; |
| 2228 | } |
| 2229 | |
| 2230 | public T stopObject(String name) { |
Joe Onorato | 388fc33 | 2016-04-12 17:06:47 -0700 | [diff] [blame] | 2231 | if (name == null) { |
| 2232 | name = ""; |
| 2233 | } |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 2234 | T obj = mMap.get(name); |
| 2235 | if (obj != null) { |
| 2236 | return obj; |
| 2237 | } |
| 2238 | |
| 2239 | // No object exists for the given name, but do we currently have it |
| 2240 | // running as part of the overflow? |
| 2241 | if (mActiveOverflow != null) { |
| 2242 | MutableInt over = mActiveOverflow.get(name); |
| 2243 | if (over != null) { |
| 2244 | // We are already actively counting this name in the overflow object. |
| 2245 | obj = mCurOverflow; |
| 2246 | if (obj != null) { |
| 2247 | over.value--; |
| 2248 | if (over.value <= 0) { |
| 2249 | mActiveOverflow.remove(name); |
Dianne Hackborn | 657153b | 2016-07-29 14:54:14 -0700 | [diff] [blame] | 2250 | mLastOverflowFinishTime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 2251 | } |
| 2252 | return obj; |
| 2253 | } |
| 2254 | } |
| 2255 | } |
| 2256 | |
| 2257 | // Huh, they are stopping an active operation but we can't find one! |
| 2258 | // That's not good. |
Dianne Hackborn | 657153b | 2016-07-29 14:54:14 -0700 | [diff] [blame] | 2259 | StringBuilder sb = new StringBuilder(); |
| 2260 | sb.append("Unable to find object for "); |
| 2261 | sb.append(name); |
| 2262 | sb.append(" in uid "); |
| 2263 | sb.append(mUid); |
| 2264 | sb.append(" mapsize="); |
| 2265 | sb.append(mMap.size()); |
| 2266 | sb.append(" activeoverflow="); |
| 2267 | sb.append(mActiveOverflow); |
| 2268 | sb.append(" curoverflow="); |
| 2269 | sb.append(mCurOverflow); |
| 2270 | long now = SystemClock.elapsedRealtime(); |
| 2271 | if (mLastOverflowTime != 0) { |
| 2272 | sb.append(" lastOverflowTime="); |
| 2273 | TimeUtils.formatDuration(mLastOverflowTime-now, sb); |
| 2274 | } |
| 2275 | if (mLastOverflowFinishTime != 0) { |
| 2276 | sb.append(" lastOverflowFinishTime="); |
| 2277 | TimeUtils.formatDuration(mLastOverflowFinishTime-now, sb); |
| 2278 | } |
| 2279 | if (mLastClearTime != 0) { |
| 2280 | sb.append(" lastClearTime="); |
| 2281 | TimeUtils.formatDuration(mLastClearTime-now, sb); |
| 2282 | } |
| 2283 | if (mLastCleanupTime != 0) { |
| 2284 | sb.append(" lastCleanupTime="); |
| 2285 | TimeUtils.formatDuration(mLastCleanupTime-now, sb); |
| 2286 | } |
| 2287 | Slog.wtf(TAG, sb.toString()); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 2288 | return null; |
| 2289 | } |
| 2290 | |
| 2291 | public abstract T instantiateObject(); |
| 2292 | } |
| 2293 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 2294 | public static class ControllerActivityCounterImpl extends ControllerActivityCounter |
| 2295 | implements Parcelable { |
| 2296 | private final LongSamplingCounter mIdleTimeMillis; |
| 2297 | private final LongSamplingCounter mRxTimeMillis; |
| 2298 | private final LongSamplingCounter[] mTxTimeMillis; |
| 2299 | private final LongSamplingCounter mPowerDrainMaMs; |
| 2300 | |
| 2301 | public ControllerActivityCounterImpl(TimeBase timeBase, int numTxStates) { |
| 2302 | mIdleTimeMillis = new LongSamplingCounter(timeBase); |
| 2303 | mRxTimeMillis = new LongSamplingCounter(timeBase); |
| 2304 | mTxTimeMillis = new LongSamplingCounter[numTxStates]; |
| 2305 | for (int i = 0; i < numTxStates; i++) { |
| 2306 | mTxTimeMillis[i] = new LongSamplingCounter(timeBase); |
| 2307 | } |
| 2308 | mPowerDrainMaMs = new LongSamplingCounter(timeBase); |
| 2309 | } |
| 2310 | |
| 2311 | public ControllerActivityCounterImpl(TimeBase timeBase, int numTxStates, Parcel in) { |
| 2312 | mIdleTimeMillis = new LongSamplingCounter(timeBase, in); |
| 2313 | mRxTimeMillis = new LongSamplingCounter(timeBase, in); |
| 2314 | final int recordedTxStates = in.readInt(); |
| 2315 | if (recordedTxStates != numTxStates) { |
| 2316 | throw new ParcelFormatException("inconsistent tx state lengths"); |
| 2317 | } |
| 2318 | |
| 2319 | mTxTimeMillis = new LongSamplingCounter[numTxStates]; |
| 2320 | for (int i = 0; i < numTxStates; i++) { |
| 2321 | mTxTimeMillis[i] = new LongSamplingCounter(timeBase, in); |
| 2322 | } |
| 2323 | mPowerDrainMaMs = new LongSamplingCounter(timeBase, in); |
| 2324 | } |
| 2325 | |
| 2326 | public void readSummaryFromParcel(Parcel in) { |
| 2327 | mIdleTimeMillis.readSummaryFromParcelLocked(in); |
| 2328 | mRxTimeMillis.readSummaryFromParcelLocked(in); |
| 2329 | final int recordedTxStates = in.readInt(); |
| 2330 | if (recordedTxStates != mTxTimeMillis.length) { |
| 2331 | throw new ParcelFormatException("inconsistent tx state lengths"); |
| 2332 | } |
| 2333 | for (LongSamplingCounter counter : mTxTimeMillis) { |
| 2334 | counter.readSummaryFromParcelLocked(in); |
| 2335 | } |
| 2336 | mPowerDrainMaMs.readSummaryFromParcelLocked(in); |
| 2337 | } |
| 2338 | |
| 2339 | @Override |
| 2340 | public int describeContents() { |
| 2341 | return 0; |
| 2342 | } |
| 2343 | |
| 2344 | public void writeSummaryToParcel(Parcel dest) { |
| 2345 | mIdleTimeMillis.writeSummaryFromParcelLocked(dest); |
| 2346 | mRxTimeMillis.writeSummaryFromParcelLocked(dest); |
| 2347 | dest.writeInt(mTxTimeMillis.length); |
| 2348 | for (LongSamplingCounter counter : mTxTimeMillis) { |
| 2349 | counter.writeSummaryFromParcelLocked(dest); |
| 2350 | } |
| 2351 | mPowerDrainMaMs.writeSummaryFromParcelLocked(dest); |
| 2352 | } |
| 2353 | |
| 2354 | @Override |
| 2355 | public void writeToParcel(Parcel dest, int flags) { |
| 2356 | mIdleTimeMillis.writeToParcel(dest); |
| 2357 | mRxTimeMillis.writeToParcel(dest); |
| 2358 | dest.writeInt(mTxTimeMillis.length); |
| 2359 | for (LongSamplingCounter counter : mTxTimeMillis) { |
| 2360 | counter.writeToParcel(dest); |
| 2361 | } |
| 2362 | mPowerDrainMaMs.writeToParcel(dest); |
| 2363 | } |
| 2364 | |
| 2365 | public void reset(boolean detachIfReset) { |
| 2366 | mIdleTimeMillis.reset(detachIfReset); |
| 2367 | mRxTimeMillis.reset(detachIfReset); |
| 2368 | for (LongSamplingCounter counter : mTxTimeMillis) { |
| 2369 | counter.reset(detachIfReset); |
| 2370 | } |
| 2371 | mPowerDrainMaMs.reset(detachIfReset); |
| 2372 | } |
| 2373 | |
| 2374 | public void detach() { |
| 2375 | mIdleTimeMillis.detach(); |
| 2376 | mRxTimeMillis.detach(); |
| 2377 | for (LongSamplingCounter counter : mTxTimeMillis) { |
| 2378 | counter.detach(); |
| 2379 | } |
| 2380 | mPowerDrainMaMs.detach(); |
| 2381 | } |
| 2382 | |
| 2383 | /** |
| 2384 | * @return a LongSamplingCounter, measuring time spent in the idle state in |
| 2385 | * milliseconds. |
| 2386 | */ |
| 2387 | @Override |
| 2388 | public LongSamplingCounter getIdleTimeCounter() { |
Roshan Pius | 8164330 | 2016-03-14 16:45:55 -0700 | [diff] [blame] | 2389 | return mIdleTimeMillis; |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 2390 | } |
| 2391 | |
| 2392 | /** |
| 2393 | * @return a LongSamplingCounter, measuring time spent in the receive state in |
| 2394 | * milliseconds. |
| 2395 | */ |
| 2396 | @Override |
| 2397 | public LongSamplingCounter getRxTimeCounter() { |
| 2398 | return mRxTimeMillis; |
| 2399 | } |
| 2400 | |
| 2401 | /** |
| 2402 | * @return a LongSamplingCounter[], measuring time spent in various transmit states in |
| 2403 | * milliseconds. |
| 2404 | */ |
| 2405 | @Override |
| 2406 | public LongSamplingCounter[] getTxTimeCounters() { |
| 2407 | return mTxTimeMillis; |
| 2408 | } |
| 2409 | |
| 2410 | /** |
| 2411 | * @return a LongSamplingCounter, measuring power use in milli-ampere milliseconds (mAmS). |
| 2412 | */ |
| 2413 | @Override |
| 2414 | public LongSamplingCounter getPowerCounter() { |
| 2415 | return mPowerDrainMaMs; |
| 2416 | } |
| 2417 | } |
| 2418 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2419 | /* |
| 2420 | * Get the wakeup reason counter, and create a new one if one |
| 2421 | * doesn't already exist. |
| 2422 | */ |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 2423 | public SamplingTimer getWakeupReasonTimerLocked(String name) { |
| 2424 | SamplingTimer timer = mWakeupReasonStats.get(name); |
| 2425 | if (timer == null) { |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 2426 | timer = new SamplingTimer(mClocks, mOnBatteryTimeBase); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 2427 | mWakeupReasonStats.put(name, timer); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2428 | } |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 2429 | return timer; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2430 | } |
| 2431 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2432 | /* |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2433 | * 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] | 2434 | * doesn't already exist. |
| 2435 | */ |
| 2436 | public SamplingTimer getKernelWakelockTimerLocked(String name) { |
| 2437 | SamplingTimer kwlt = mKernelWakelockStats.get(name); |
| 2438 | if (kwlt == null) { |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 2439 | kwlt = new SamplingTimer(mClocks, mOnBatteryScreenOffTimeBase); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2440 | mKernelWakelockStats.put(name, kwlt); |
| 2441 | } |
| 2442 | return kwlt; |
| 2443 | } |
Amith Yamasani | 3718aaa | 2009-06-09 06:32:35 -0700 | [diff] [blame] | 2444 | |
James Carr | 3a22605 | 2016-07-01 14:49:52 -0700 | [diff] [blame] | 2445 | public SamplingTimer getKernelMemoryTimerLocked(long bucket) { |
| 2446 | SamplingTimer kmt = mKernelMemoryStats.get(bucket); |
| 2447 | if (kmt == null) { |
| 2448 | kmt = new SamplingTimer(mClocks, mOnBatteryTimeBase); |
| 2449 | mKernelMemoryStats.put(bucket, kmt); |
| 2450 | } |
| 2451 | return kmt; |
| 2452 | } |
| 2453 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2454 | private int writeHistoryTag(HistoryTag tag) { |
| 2455 | Integer idxObj = mHistoryTagPool.get(tag); |
| 2456 | int idx; |
| 2457 | if (idxObj != null) { |
| 2458 | idx = idxObj; |
| 2459 | } else { |
| 2460 | idx = mNextHistoryTagIdx; |
| 2461 | HistoryTag key = new HistoryTag(); |
| 2462 | key.setTo(tag); |
| 2463 | tag.poolIdx = idx; |
| 2464 | mHistoryTagPool.put(key, idx); |
| 2465 | mNextHistoryTagIdx++; |
| 2466 | mNumHistoryTagChars += key.string.length() + 1; |
| 2467 | } |
| 2468 | return idx; |
| 2469 | } |
| 2470 | |
| 2471 | private void readHistoryTag(int index, HistoryTag tag) { |
| 2472 | tag.string = mReadHistoryStrings[index]; |
| 2473 | tag.uid = mReadHistoryUids[index]; |
| 2474 | tag.poolIdx = index; |
| 2475 | } |
| 2476 | |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 2477 | /* |
| 2478 | The history delta format uses flags to denote further data in subsequent ints in the parcel. |
| 2479 | |
| 2480 | There is always the first token, which may contain the delta time, or an indicator of |
| 2481 | the length of the time (int or long) following this token. |
| 2482 | |
| 2483 | First token: always present, |
| 2484 | 31 23 15 7 0 |
| 2485 | â–ˆ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â–ˆ |
| 2486 | |
| 2487 | T: the delta time if it is <= 0x7fffd. Otherwise 0x7fffe indicates an int immediately |
| 2488 | follows containing the time, and 0x7ffff indicates a long immediately follows with the |
| 2489 | delta time. |
| 2490 | A: battery level changed and an int follows with battery data. |
| 2491 | B: state changed and an int follows with state change data. |
| 2492 | C: state2 has changed and an int follows with state2 change data. |
| 2493 | D: wakelock/wakereason has changed and an wakelock/wakereason struct follows. |
| 2494 | E: event data has changed and an event struct follows. |
| 2495 | F: battery charge in coulombs has changed and an int with the charge follows. |
| 2496 | G: state flag denoting that the mobile radio was active. |
| 2497 | H: state flag denoting that the wifi radio was active. |
| 2498 | I: state flag denoting that a wifi scan occurred. |
| 2499 | J: state flag denoting that a wifi full lock was held. |
| 2500 | K: state flag denoting that the gps was on. |
| 2501 | L: state flag denoting that a wakelock was held. |
| 2502 | M: state flag denoting that the cpu was running. |
| 2503 | |
| 2504 | Time int/long: if T in the first token is 0x7ffff or 0x7fffe, then an int or long follows |
| 2505 | with the time delta. |
| 2506 | |
| 2507 | Battery level int: if A in the first token is set, |
| 2508 | 31 23 15 7 0 |
| 2509 | â–ˆ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â–ˆ |
| 2510 | |
| 2511 | D: indicates that extra history details follow. |
| 2512 | V: the battery voltage. |
| 2513 | T: the battery temperature. |
| 2514 | L: the battery level (out of 100). |
| 2515 | |
| 2516 | State change int: if B in the first token is set, |
| 2517 | 31 23 15 7 0 |
| 2518 | â–ˆS|S|S|H|H|H|P|Pâ–ˆF|E|D|C|B| | |Aâ–ˆ | | | | | | | â–ˆ | | | | | | | â–ˆ |
| 2519 | |
| 2520 | A: wifi multicast was on. |
| 2521 | B: battery was plugged in. |
| 2522 | C: screen was on. |
| 2523 | D: phone was scanning for signal. |
| 2524 | E: audio was on. |
| 2525 | F: a sensor was active. |
| 2526 | |
| 2527 | State2 change int: if C in the first token is set, |
| 2528 | 31 23 15 7 0 |
| 2529 | â–ˆM|L|K|J|I|H|H|Gâ–ˆF|E|D|C| | | | â–ˆ | | | | | | | â–ˆ |B|B|B|A|A|A|Aâ–ˆ |
| 2530 | |
| 2531 | A: 4 bits indicating the wifi supplicant state: {@link BatteryStats#WIFI_SUPPL_STATE_NAMES}. |
| 2532 | B: 3 bits indicating the wifi signal strength: 0, 1, 2, 3, 4. |
| 2533 | C: a bluetooth scan was active. |
| 2534 | D: the camera was active. |
| 2535 | E: bluetooth was on. |
| 2536 | F: a phone call was active. |
| 2537 | G: the device was charging. |
| 2538 | H: 2 bits indicating the device-idle (doze) state: off, light, full |
| 2539 | I: the flashlight was on. |
| 2540 | J: wifi was on. |
| 2541 | K: wifi was running. |
| 2542 | L: video was playing. |
| 2543 | M: power save mode was on. |
| 2544 | |
| 2545 | Wakelock/wakereason struct: if D in the first token is set, |
| 2546 | TODO(adamlesinski): describe wakelock/wakereason struct. |
| 2547 | |
| 2548 | Event struct: if E in the first token is set, |
| 2549 | TODO(adamlesinski): describe the event struct. |
| 2550 | |
| 2551 | History step details struct: if D in the battery level int is set, |
| 2552 | TODO(adamlesinski): describe the history step details struct. |
| 2553 | |
| 2554 | Battery charge int: if F in the first token is set, an int representing the battery charge |
| 2555 | in coulombs follows. |
| 2556 | */ |
| 2557 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2558 | // Part of initial delta int that specifies the time delta. |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 2559 | static final int DELTA_TIME_MASK = 0x7ffff; |
| 2560 | static final int DELTA_TIME_LONG = 0x7ffff; // The delta is a following long |
| 2561 | static final int DELTA_TIME_INT = 0x7fffe; // The delta is a following int |
| 2562 | 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] | 2563 | // Flag in delta int: a new battery level int follows. |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 2564 | static final int DELTA_BATTERY_LEVEL_FLAG = 0x00080000; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2565 | // 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] | 2566 | static final int DELTA_STATE_FLAG = 0x00100000; |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 2567 | // Flag in delta int: a new full state2 int follows. |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 2568 | static final int DELTA_STATE2_FLAG = 0x00200000; |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 2569 | // Flag in delta int: contains a wakelock or wakeReason tag. |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 2570 | static final int DELTA_WAKELOCK_FLAG = 0x00400000; |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2571 | // Flag in delta int: contains an event description. |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 2572 | static final int DELTA_EVENT_FLAG = 0x00800000; |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 2573 | // Flag in delta int: contains the battery charge count in uAh. |
| 2574 | static final int DELTA_BATTERY_CHARGE_FLAG = 0x01000000; |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2575 | // These upper bits are the frequently changing state bits. |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 2576 | static final int DELTA_STATE_MASK = 0xfe000000; |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 2577 | |
| 2578 | // These are the pieces of battery state that are packed in to the upper bits of |
| 2579 | // 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] | 2580 | // in STATE_BATTERY_MASK. |
| 2581 | static final int STATE_BATTERY_MASK = 0xff000000; |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 2582 | static final int STATE_BATTERY_STATUS_MASK = 0x00000007; |
| 2583 | static final int STATE_BATTERY_STATUS_SHIFT = 29; |
| 2584 | static final int STATE_BATTERY_HEALTH_MASK = 0x00000007; |
| 2585 | static final int STATE_BATTERY_HEALTH_SHIFT = 26; |
| 2586 | static final int STATE_BATTERY_PLUG_MASK = 0x00000003; |
| 2587 | static final int STATE_BATTERY_PLUG_SHIFT = 24; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2588 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 2589 | // We use the low bit of the battery state int to indicate that we have full details |
| 2590 | // from a battery level change. |
| 2591 | static final int BATTERY_DELTA_LEVEL_FLAG = 0x00000001; |
| 2592 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2593 | public void writeHistoryDelta(Parcel dest, HistoryItem cur, HistoryItem last) { |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2594 | if (last == null || cur.cmd != HistoryItem.CMD_UPDATE) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2595 | dest.writeInt(DELTA_TIME_ABS); |
| 2596 | cur.writeToParcel(dest, 0); |
| 2597 | return; |
| 2598 | } |
| 2599 | |
| 2600 | final long deltaTime = cur.time - last.time; |
| 2601 | final int lastBatteryLevelInt = buildBatteryLevelInt(last); |
| 2602 | final int lastStateInt = buildStateInt(last); |
| 2603 | |
| 2604 | int deltaTimeToken; |
| 2605 | if (deltaTime < 0 || deltaTime > Integer.MAX_VALUE) { |
| 2606 | deltaTimeToken = DELTA_TIME_LONG; |
| 2607 | } else if (deltaTime >= DELTA_TIME_ABS) { |
| 2608 | deltaTimeToken = DELTA_TIME_INT; |
| 2609 | } else { |
| 2610 | deltaTimeToken = (int)deltaTime; |
| 2611 | } |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2612 | int firstToken = deltaTimeToken | (cur.states&DELTA_STATE_MASK); |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 2613 | final int includeStepDetails = mLastHistoryStepLevel > cur.batteryLevel |
| 2614 | ? BATTERY_DELTA_LEVEL_FLAG : 0; |
| 2615 | final boolean computeStepDetails = includeStepDetails != 0 |
| 2616 | || mLastHistoryStepDetails == null; |
| 2617 | final int batteryLevelInt = buildBatteryLevelInt(cur) | includeStepDetails; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2618 | final boolean batteryLevelIntChanged = batteryLevelInt != lastBatteryLevelInt; |
| 2619 | if (batteryLevelIntChanged) { |
| 2620 | firstToken |= DELTA_BATTERY_LEVEL_FLAG; |
| 2621 | } |
| 2622 | final int stateInt = buildStateInt(cur); |
| 2623 | final boolean stateIntChanged = stateInt != lastStateInt; |
| 2624 | if (stateIntChanged) { |
| 2625 | firstToken |= DELTA_STATE_FLAG; |
| 2626 | } |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2627 | final boolean state2IntChanged = cur.states2 != last.states2; |
| 2628 | if (state2IntChanged) { |
| 2629 | firstToken |= DELTA_STATE2_FLAG; |
| 2630 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 2631 | if (cur.wakelockTag != null || cur.wakeReasonTag != null) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2632 | firstToken |= DELTA_WAKELOCK_FLAG; |
| 2633 | } |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2634 | if (cur.eventCode != HistoryItem.EVENT_NONE) { |
| 2635 | firstToken |= DELTA_EVENT_FLAG; |
| 2636 | } |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 2637 | |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 2638 | final boolean batteryChargeChanged = cur.batteryChargeUAh != last.batteryChargeUAh; |
| 2639 | if (batteryChargeChanged) { |
| 2640 | firstToken |= DELTA_BATTERY_CHARGE_FLAG; |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 2641 | } |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2642 | dest.writeInt(firstToken); |
| 2643 | if (DEBUG) Slog.i(TAG, "WRITE DELTA: firstToken=0x" + Integer.toHexString(firstToken) |
| 2644 | + " deltaTime=" + deltaTime); |
| 2645 | |
| 2646 | if (deltaTimeToken >= DELTA_TIME_INT) { |
| 2647 | if (deltaTimeToken == DELTA_TIME_INT) { |
| 2648 | if (DEBUG) Slog.i(TAG, "WRITE DELTA: int deltaTime=" + (int)deltaTime); |
| 2649 | dest.writeInt((int)deltaTime); |
| 2650 | } else { |
| 2651 | if (DEBUG) Slog.i(TAG, "WRITE DELTA: long deltaTime=" + deltaTime); |
| 2652 | dest.writeLong(deltaTime); |
| 2653 | } |
| 2654 | } |
| 2655 | if (batteryLevelIntChanged) { |
| 2656 | dest.writeInt(batteryLevelInt); |
| 2657 | if (DEBUG) Slog.i(TAG, "WRITE DELTA: batteryToken=0x" |
| 2658 | + Integer.toHexString(batteryLevelInt) |
| 2659 | + " batteryLevel=" + cur.batteryLevel |
| 2660 | + " batteryTemp=" + cur.batteryTemperature |
| 2661 | + " batteryVolt=" + (int)cur.batteryVoltage); |
| 2662 | } |
| 2663 | if (stateIntChanged) { |
| 2664 | dest.writeInt(stateInt); |
| 2665 | if (DEBUG) Slog.i(TAG, "WRITE DELTA: stateToken=0x" |
| 2666 | + Integer.toHexString(stateInt) |
| 2667 | + " batteryStatus=" + cur.batteryStatus |
| 2668 | + " batteryHealth=" + cur.batteryHealth |
| 2669 | + " batteryPlugType=" + cur.batteryPlugType |
| 2670 | + " states=0x" + Integer.toHexString(cur.states)); |
| 2671 | } |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2672 | if (state2IntChanged) { |
| 2673 | dest.writeInt(cur.states2); |
| 2674 | if (DEBUG) Slog.i(TAG, "WRITE DELTA: states2=0x" |
| 2675 | + Integer.toHexString(cur.states2)); |
| 2676 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 2677 | if (cur.wakelockTag != null || cur.wakeReasonTag != null) { |
| 2678 | int wakeLockIndex; |
| 2679 | int wakeReasonIndex; |
| 2680 | if (cur.wakelockTag != null) { |
| 2681 | wakeLockIndex = writeHistoryTag(cur.wakelockTag); |
| 2682 | if (DEBUG) Slog.i(TAG, "WRITE DELTA: wakelockTag=#" + cur.wakelockTag.poolIdx |
| 2683 | + " " + cur.wakelockTag.uid + ":" + cur.wakelockTag.string); |
| 2684 | } else { |
| 2685 | wakeLockIndex = 0xffff; |
| 2686 | } |
| 2687 | if (cur.wakeReasonTag != null) { |
| 2688 | wakeReasonIndex = writeHistoryTag(cur.wakeReasonTag); |
| 2689 | if (DEBUG) Slog.i(TAG, "WRITE DELTA: wakeReasonTag=#" + cur.wakeReasonTag.poolIdx |
| 2690 | + " " + cur.wakeReasonTag.uid + ":" + cur.wakeReasonTag.string); |
| 2691 | } else { |
| 2692 | wakeReasonIndex = 0xffff; |
| 2693 | } |
| 2694 | dest.writeInt((wakeReasonIndex<<16) | wakeLockIndex); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2695 | } |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2696 | if (cur.eventCode != HistoryItem.EVENT_NONE) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2697 | int index = writeHistoryTag(cur.eventTag); |
| 2698 | int codeAndIndex = (cur.eventCode&0xffff) | (index<<16); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 2699 | dest.writeInt(codeAndIndex); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2700 | if (DEBUG) Slog.i(TAG, "WRITE DELTA: event=" + cur.eventCode + " tag=#" |
| 2701 | + cur.eventTag.poolIdx + " " + cur.eventTag.uid + ":" |
| 2702 | + cur.eventTag.string); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2703 | } |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 2704 | if (computeStepDetails) { |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 2705 | if (mPlatformIdleStateCallback != null) { |
| 2706 | mCurHistoryStepDetails.statPlatformIdleState = |
| 2707 | mPlatformIdleStateCallback.getPlatformLowPowerStats(); |
| 2708 | if (DEBUG) Slog.i(TAG, "WRITE PlatformIdleState:" + |
| 2709 | mCurHistoryStepDetails.statPlatformIdleState); |
| 2710 | } |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 2711 | computeHistoryStepDetails(mCurHistoryStepDetails, mLastHistoryStepDetails); |
| 2712 | if (includeStepDetails != 0) { |
| 2713 | mCurHistoryStepDetails.writeToParcel(dest); |
| 2714 | } |
| 2715 | cur.stepDetails = mCurHistoryStepDetails; |
| 2716 | mLastHistoryStepDetails = mCurHistoryStepDetails; |
| 2717 | } else { |
| 2718 | cur.stepDetails = null; |
| 2719 | } |
| 2720 | if (mLastHistoryStepLevel < cur.batteryLevel) { |
| 2721 | mLastHistoryStepDetails = null; |
| 2722 | } |
| 2723 | mLastHistoryStepLevel = cur.batteryLevel; |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 2724 | |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 2725 | if (batteryChargeChanged) { |
| 2726 | if (DEBUG) Slog.i(TAG, "WRITE DELTA: batteryChargeUAh=" + cur.batteryChargeUAh); |
| 2727 | dest.writeInt(cur.batteryChargeUAh); |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 2728 | } |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2729 | } |
| 2730 | |
| 2731 | private int buildBatteryLevelInt(HistoryItem h) { |
| 2732 | return ((((int)h.batteryLevel)<<25)&0xfe000000) |
Adam Lesinski | 3944c81 | 2015-11-13 15:54:59 -0800 | [diff] [blame] | 2733 | | ((((int)h.batteryTemperature)<<15)&0x01ff8000) |
| 2734 | | ((((int)h.batteryVoltage)<<1)&0x00007ffe); |
| 2735 | } |
| 2736 | |
| 2737 | private void readBatteryLevelInt(int batteryLevelInt, HistoryItem out) { |
| 2738 | out.batteryLevel = (byte)((batteryLevelInt & 0xfe000000) >>> 25); |
| 2739 | out.batteryTemperature = (short)((batteryLevelInt & 0x01ff8000) >>> 15); |
| 2740 | out.batteryVoltage = (char)((batteryLevelInt & 0x00007ffe) >>> 1); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2741 | } |
| 2742 | |
| 2743 | private int buildStateInt(HistoryItem h) { |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 2744 | int plugType = 0; |
| 2745 | if ((h.batteryPlugType&BatteryManager.BATTERY_PLUGGED_AC) != 0) { |
| 2746 | plugType = 1; |
| 2747 | } else if ((h.batteryPlugType&BatteryManager.BATTERY_PLUGGED_USB) != 0) { |
| 2748 | plugType = 2; |
| 2749 | } else if ((h.batteryPlugType&BatteryManager.BATTERY_PLUGGED_WIRELESS) != 0) { |
| 2750 | plugType = 3; |
| 2751 | } |
| 2752 | return ((h.batteryStatus&STATE_BATTERY_STATUS_MASK)<<STATE_BATTERY_STATUS_SHIFT) |
| 2753 | | ((h.batteryHealth&STATE_BATTERY_HEALTH_MASK)<<STATE_BATTERY_HEALTH_SHIFT) |
| 2754 | | ((plugType&STATE_BATTERY_PLUG_MASK)<<STATE_BATTERY_PLUG_SHIFT) |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 2755 | | (h.states&(~STATE_BATTERY_MASK)); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2756 | } |
| 2757 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 2758 | private void computeHistoryStepDetails(final HistoryStepDetails out, |
| 2759 | final HistoryStepDetails last) { |
| 2760 | final HistoryStepDetails tmp = last != null ? mTmpHistoryStepDetails : out; |
| 2761 | |
| 2762 | // Perform a CPU update right after we do this collection, so we have started |
| 2763 | // collecting good data for the next step. |
| 2764 | requestImmediateCpuUpdate(); |
| 2765 | |
| 2766 | if (last == null) { |
| 2767 | // We are not generating a delta, so all we need to do is reset the stats |
| 2768 | // we will later be doing a delta from. |
| 2769 | final int NU = mUidStats.size(); |
| 2770 | for (int i=0; i<NU; i++) { |
| 2771 | final BatteryStatsImpl.Uid uid = mUidStats.valueAt(i); |
| 2772 | uid.mLastStepUserTime = uid.mCurStepUserTime; |
| 2773 | uid.mLastStepSystemTime = uid.mCurStepSystemTime; |
| 2774 | } |
| 2775 | mLastStepCpuUserTime = mCurStepCpuUserTime; |
| 2776 | mLastStepCpuSystemTime = mCurStepCpuSystemTime; |
| 2777 | mLastStepStatUserTime = mCurStepStatUserTime; |
| 2778 | mLastStepStatSystemTime = mCurStepStatSystemTime; |
| 2779 | mLastStepStatIOWaitTime = mCurStepStatIOWaitTime; |
| 2780 | mLastStepStatIrqTime = mCurStepStatIrqTime; |
| 2781 | mLastStepStatSoftIrqTime = mCurStepStatSoftIrqTime; |
| 2782 | mLastStepStatIdleTime = mCurStepStatIdleTime; |
| 2783 | tmp.clear(); |
| 2784 | return; |
| 2785 | } |
| 2786 | if (DEBUG) { |
| 2787 | Slog.d(TAG, "Step stats last: user=" + mLastStepCpuUserTime + " sys=" |
| 2788 | + mLastStepStatSystemTime + " io=" + mLastStepStatIOWaitTime |
| 2789 | + " irq=" + mLastStepStatIrqTime + " sirq=" |
| 2790 | + mLastStepStatSoftIrqTime + " idle=" + mLastStepStatIdleTime); |
| 2791 | Slog.d(TAG, "Step stats cur: user=" + mCurStepCpuUserTime + " sys=" |
| 2792 | + mCurStepStatSystemTime + " io=" + mCurStepStatIOWaitTime |
| 2793 | + " irq=" + mCurStepStatIrqTime + " sirq=" |
| 2794 | + mCurStepStatSoftIrqTime + " idle=" + mCurStepStatIdleTime); |
| 2795 | } |
| 2796 | out.userTime = (int)(mCurStepCpuUserTime - mLastStepCpuUserTime); |
| 2797 | out.systemTime = (int)(mCurStepCpuSystemTime - mLastStepCpuSystemTime); |
| 2798 | out.statUserTime = (int)(mCurStepStatUserTime - mLastStepStatUserTime); |
| 2799 | out.statSystemTime = (int)(mCurStepStatSystemTime - mLastStepStatSystemTime); |
| 2800 | out.statIOWaitTime = (int)(mCurStepStatIOWaitTime - mLastStepStatIOWaitTime); |
| 2801 | out.statIrqTime = (int)(mCurStepStatIrqTime - mLastStepStatIrqTime); |
| 2802 | out.statSoftIrqTime = (int)(mCurStepStatSoftIrqTime - mLastStepStatSoftIrqTime); |
| 2803 | out.statIdlTime = (int)(mCurStepStatIdleTime - mLastStepStatIdleTime); |
| 2804 | out.appCpuUid1 = out.appCpuUid2 = out.appCpuUid3 = -1; |
| 2805 | out.appCpuUTime1 = out.appCpuUTime2 = out.appCpuUTime3 = 0; |
| 2806 | out.appCpuSTime1 = out.appCpuSTime2 = out.appCpuSTime3 = 0; |
| 2807 | final int NU = mUidStats.size(); |
| 2808 | for (int i=0; i<NU; i++) { |
| 2809 | final BatteryStatsImpl.Uid uid = mUidStats.valueAt(i); |
| 2810 | final int totalUTime = (int)(uid.mCurStepUserTime - uid.mLastStepUserTime); |
| 2811 | final int totalSTime = (int)(uid.mCurStepSystemTime - uid.mLastStepSystemTime); |
| 2812 | final int totalTime = totalUTime + totalSTime; |
| 2813 | uid.mLastStepUserTime = uid.mCurStepUserTime; |
| 2814 | uid.mLastStepSystemTime = uid.mCurStepSystemTime; |
| 2815 | if (totalTime <= (out.appCpuUTime3+out.appCpuSTime3)) { |
| 2816 | continue; |
| 2817 | } |
| 2818 | if (totalTime <= (out.appCpuUTime2+out.appCpuSTime2)) { |
| 2819 | out.appCpuUid3 = uid.mUid; |
| 2820 | out.appCpuUTime3 = totalUTime; |
| 2821 | out.appCpuSTime3 = totalSTime; |
| 2822 | } else { |
| 2823 | out.appCpuUid3 = out.appCpuUid2; |
| 2824 | out.appCpuUTime3 = out.appCpuUTime2; |
| 2825 | out.appCpuSTime3 = out.appCpuSTime2; |
| 2826 | if (totalTime <= (out.appCpuUTime1+out.appCpuSTime1)) { |
| 2827 | out.appCpuUid2 = uid.mUid; |
| 2828 | out.appCpuUTime2 = totalUTime; |
| 2829 | out.appCpuSTime2 = totalSTime; |
| 2830 | } else { |
| 2831 | out.appCpuUid2 = out.appCpuUid1; |
| 2832 | out.appCpuUTime2 = out.appCpuUTime1; |
| 2833 | out.appCpuSTime2 = out.appCpuSTime1; |
| 2834 | out.appCpuUid1 = uid.mUid; |
| 2835 | out.appCpuUTime1 = totalUTime; |
| 2836 | out.appCpuSTime1 = totalSTime; |
| 2837 | } |
| 2838 | } |
| 2839 | } |
| 2840 | mLastStepCpuUserTime = mCurStepCpuUserTime; |
| 2841 | mLastStepCpuSystemTime = mCurStepCpuSystemTime; |
| 2842 | mLastStepStatUserTime = mCurStepStatUserTime; |
| 2843 | mLastStepStatSystemTime = mCurStepStatSystemTime; |
| 2844 | mLastStepStatIOWaitTime = mCurStepStatIOWaitTime; |
| 2845 | mLastStepStatIrqTime = mCurStepStatIrqTime; |
| 2846 | mLastStepStatSoftIrqTime = mCurStepStatSoftIrqTime; |
| 2847 | mLastStepStatIdleTime = mCurStepStatIdleTime; |
| 2848 | } |
| 2849 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2850 | public void readHistoryDelta(Parcel src, HistoryItem cur) { |
| 2851 | int firstToken = src.readInt(); |
| 2852 | int deltaTimeToken = firstToken&DELTA_TIME_MASK; |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2853 | cur.cmd = HistoryItem.CMD_UPDATE; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2854 | cur.numReadInts = 1; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2855 | if (DEBUG) Slog.i(TAG, "READ DELTA: firstToken=0x" + Integer.toHexString(firstToken) |
| 2856 | + " deltaTimeToken=" + deltaTimeToken); |
| 2857 | |
| 2858 | if (deltaTimeToken < DELTA_TIME_ABS) { |
| 2859 | cur.time += deltaTimeToken; |
| 2860 | } else if (deltaTimeToken == DELTA_TIME_ABS) { |
| 2861 | cur.time = src.readLong(); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2862 | cur.numReadInts += 2; |
| 2863 | if (DEBUG) Slog.i(TAG, "READ DELTA: ABS time=" + cur.time); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2864 | cur.readFromParcel(src); |
| 2865 | return; |
| 2866 | } else if (deltaTimeToken == DELTA_TIME_INT) { |
| 2867 | int delta = src.readInt(); |
| 2868 | cur.time += delta; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2869 | cur.numReadInts += 1; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2870 | if (DEBUG) Slog.i(TAG, "READ DELTA: time delta=" + delta + " new time=" + cur.time); |
| 2871 | } else { |
| 2872 | long delta = src.readLong(); |
| 2873 | if (DEBUG) Slog.i(TAG, "READ DELTA: time delta=" + delta + " new time=" + cur.time); |
| 2874 | cur.time += delta; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2875 | cur.numReadInts += 2; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2876 | } |
| 2877 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 2878 | final int batteryLevelInt; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2879 | if ((firstToken&DELTA_BATTERY_LEVEL_FLAG) != 0) { |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 2880 | batteryLevelInt = src.readInt(); |
Adam Lesinski | 3944c81 | 2015-11-13 15:54:59 -0800 | [diff] [blame] | 2881 | readBatteryLevelInt(batteryLevelInt, cur); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2882 | cur.numReadInts += 1; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2883 | if (DEBUG) Slog.i(TAG, "READ DELTA: batteryToken=0x" |
| 2884 | + Integer.toHexString(batteryLevelInt) |
| 2885 | + " batteryLevel=" + cur.batteryLevel |
| 2886 | + " batteryTemp=" + cur.batteryTemperature |
| 2887 | + " batteryVolt=" + (int)cur.batteryVoltage); |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 2888 | } else { |
| 2889 | batteryLevelInt = 0; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2890 | } |
| 2891 | |
| 2892 | if ((firstToken&DELTA_STATE_FLAG) != 0) { |
| 2893 | int stateInt = src.readInt(); |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 2894 | cur.states = (firstToken&DELTA_STATE_MASK) | (stateInt&(~STATE_BATTERY_MASK)); |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 2895 | cur.batteryStatus = (byte)((stateInt>>STATE_BATTERY_STATUS_SHIFT) |
| 2896 | & STATE_BATTERY_STATUS_MASK); |
| 2897 | cur.batteryHealth = (byte)((stateInt>>STATE_BATTERY_HEALTH_SHIFT) |
| 2898 | & STATE_BATTERY_HEALTH_MASK); |
| 2899 | cur.batteryPlugType = (byte)((stateInt>>STATE_BATTERY_PLUG_SHIFT) |
| 2900 | & STATE_BATTERY_PLUG_MASK); |
| 2901 | switch (cur.batteryPlugType) { |
| 2902 | case 1: |
| 2903 | cur.batteryPlugType = BatteryManager.BATTERY_PLUGGED_AC; |
| 2904 | break; |
| 2905 | case 2: |
| 2906 | cur.batteryPlugType = BatteryManager.BATTERY_PLUGGED_USB; |
| 2907 | break; |
| 2908 | case 3: |
| 2909 | cur.batteryPlugType = BatteryManager.BATTERY_PLUGGED_WIRELESS; |
| 2910 | break; |
| 2911 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2912 | cur.numReadInts += 1; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2913 | if (DEBUG) Slog.i(TAG, "READ DELTA: stateToken=0x" |
| 2914 | + Integer.toHexString(stateInt) |
| 2915 | + " batteryStatus=" + cur.batteryStatus |
| 2916 | + " batteryHealth=" + cur.batteryHealth |
| 2917 | + " batteryPlugType=" + cur.batteryPlugType |
| 2918 | + " states=0x" + Integer.toHexString(cur.states)); |
| 2919 | } else { |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 2920 | cur.states = (firstToken&DELTA_STATE_MASK) | (cur.states&(~STATE_BATTERY_MASK)); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2921 | } |
| 2922 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2923 | if ((firstToken&DELTA_STATE2_FLAG) != 0) { |
| 2924 | cur.states2 = src.readInt(); |
| 2925 | if (DEBUG) Slog.i(TAG, "READ DELTA: states2=0x" |
| 2926 | + Integer.toHexString(cur.states2)); |
| 2927 | } |
| 2928 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2929 | if ((firstToken&DELTA_WAKELOCK_FLAG) != 0) { |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 2930 | int indexes = src.readInt(); |
| 2931 | int wakeLockIndex = indexes&0xffff; |
| 2932 | int wakeReasonIndex = (indexes>>16)&0xffff; |
| 2933 | if (wakeLockIndex != 0xffff) { |
| 2934 | cur.wakelockTag = cur.localWakelockTag; |
| 2935 | readHistoryTag(wakeLockIndex, cur.wakelockTag); |
| 2936 | if (DEBUG) Slog.i(TAG, "READ DELTA: wakelockTag=#" + cur.wakelockTag.poolIdx |
| 2937 | + " " + cur.wakelockTag.uid + ":" + cur.wakelockTag.string); |
| 2938 | } else { |
| 2939 | cur.wakelockTag = null; |
| 2940 | } |
| 2941 | if (wakeReasonIndex != 0xffff) { |
| 2942 | cur.wakeReasonTag = cur.localWakeReasonTag; |
| 2943 | readHistoryTag(wakeReasonIndex, cur.wakeReasonTag); |
| 2944 | if (DEBUG) Slog.i(TAG, "READ DELTA: wakeReasonTag=#" + cur.wakeReasonTag.poolIdx |
| 2945 | + " " + cur.wakeReasonTag.uid + ":" + cur.wakeReasonTag.string); |
| 2946 | } else { |
| 2947 | cur.wakeReasonTag = null; |
| 2948 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2949 | cur.numReadInts += 1; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2950 | } else { |
| 2951 | cur.wakelockTag = null; |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 2952 | cur.wakeReasonTag = null; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2953 | } |
| 2954 | |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2955 | if ((firstToken&DELTA_EVENT_FLAG) != 0) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2956 | cur.eventTag = cur.localEventTag; |
| 2957 | final int codeAndIndex = src.readInt(); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 2958 | cur.eventCode = (codeAndIndex&0xffff); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2959 | final int index = ((codeAndIndex>>16)&0xffff); |
| 2960 | readHistoryTag(index, cur.eventTag); |
| 2961 | cur.numReadInts += 1; |
| 2962 | if (DEBUG) Slog.i(TAG, "READ DELTA: event=" + cur.eventCode + " tag=#" |
| 2963 | + cur.eventTag.poolIdx + " " + cur.eventTag.uid + ":" |
| 2964 | + cur.eventTag.string); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2965 | } else { |
| 2966 | cur.eventCode = HistoryItem.EVENT_NONE; |
| 2967 | } |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 2968 | |
| 2969 | if ((batteryLevelInt&BATTERY_DELTA_LEVEL_FLAG) != 0) { |
| 2970 | cur.stepDetails = mReadHistoryStepDetails; |
| 2971 | cur.stepDetails.readFromParcel(src); |
| 2972 | } else { |
| 2973 | cur.stepDetails = null; |
| 2974 | } |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 2975 | |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 2976 | if ((firstToken&DELTA_BATTERY_CHARGE_FLAG) != 0) { |
| 2977 | cur.batteryChargeUAh = src.readInt(); |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 2978 | } |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2979 | } |
| 2980 | |
Dianne Hackborn | fc06413 | 2014-06-02 12:42:12 -0700 | [diff] [blame] | 2981 | @Override |
| 2982 | public void commitCurrentHistoryBatchLocked() { |
| 2983 | mHistoryLastWritten.cmd = HistoryItem.CMD_NULL; |
| 2984 | } |
| 2985 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2986 | void addHistoryBufferLocked(long elapsedRealtimeMs, long uptimeMs, HistoryItem cur) { |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2987 | if (!mHaveBatteryLevel || !mRecordingHistory) { |
| 2988 | return; |
| 2989 | } |
| 2990 | |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2991 | final long timeDiff = (mHistoryBaseTime+elapsedRealtimeMs) - mHistoryLastWritten.time; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 2992 | final int diffStates = mHistoryLastWritten.states^(cur.states&mActiveHistoryStates); |
| 2993 | final int diffStates2 = mHistoryLastWritten.states2^(cur.states2&mActiveHistoryStates2); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2994 | final int lastDiffStates = mHistoryLastWritten.states^mHistoryLastLastWritten.states; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2995 | final int lastDiffStates2 = mHistoryLastWritten.states2^mHistoryLastLastWritten.states2; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2996 | if (DEBUG) Slog.i(TAG, "ADD: tdelta=" + timeDiff + " diff=" |
| 2997 | + Integer.toHexString(diffStates) + " lastDiff=" |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2998 | + Integer.toHexString(lastDiffStates) + " diff2=" |
| 2999 | + Integer.toHexString(diffStates2) + " lastDiff2=" |
| 3000 | + Integer.toHexString(lastDiffStates2)); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 3001 | if (mHistoryBufferLastPos >= 0 && mHistoryLastWritten.cmd == HistoryItem.CMD_UPDATE |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3002 | && timeDiff < 1000 && (diffStates&lastDiffStates) == 0 |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3003 | && (diffStates2&lastDiffStates2) == 0 |
| 3004 | && (mHistoryLastWritten.wakelockTag == null || cur.wakelockTag == null) |
| 3005 | && (mHistoryLastWritten.wakeReasonTag == null || cur.wakeReasonTag == null) |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 3006 | && mHistoryLastWritten.stepDetails == null |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 3007 | && (mHistoryLastWritten.eventCode == HistoryItem.EVENT_NONE |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3008 | || cur.eventCode == HistoryItem.EVENT_NONE) |
| 3009 | && mHistoryLastWritten.batteryLevel == cur.batteryLevel |
| 3010 | && mHistoryLastWritten.batteryStatus == cur.batteryStatus |
| 3011 | && mHistoryLastWritten.batteryHealth == cur.batteryHealth |
| 3012 | && mHistoryLastWritten.batteryPlugType == cur.batteryPlugType |
| 3013 | && mHistoryLastWritten.batteryTemperature == cur.batteryTemperature |
| 3014 | && mHistoryLastWritten.batteryVoltage == cur.batteryVoltage) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3015 | // 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] | 3016 | // 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] | 3017 | // as long as no bit has changed both between now and the last entry, as |
| 3018 | // well as the last entry and the one before it (so we capture any toggles). |
| 3019 | if (DEBUG) Slog.i(TAG, "ADD: rewinding back to " + mHistoryBufferLastPos); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 3020 | mHistoryBuffer.setDataSize(mHistoryBufferLastPos); |
| 3021 | mHistoryBuffer.setDataPosition(mHistoryBufferLastPos); |
| 3022 | mHistoryBufferLastPos = -1; |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3023 | elapsedRealtimeMs = mHistoryLastWritten.time - mHistoryBaseTime; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3024 | // If the last written history had a wakelock tag, we need to retain it. |
| 3025 | // Note that the condition above made sure that we aren't in a case where |
| 3026 | // both it and the current history item have a wakelock tag. |
| 3027 | if (mHistoryLastWritten.wakelockTag != null) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3028 | cur.wakelockTag = cur.localWakelockTag; |
| 3029 | cur.wakelockTag.setTo(mHistoryLastWritten.wakelockTag); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3030 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 3031 | // If the last written history had a wake reason tag, we need to retain it. |
| 3032 | // Note that the condition above made sure that we aren't in a case where |
| 3033 | // both it and the current history item have a wakelock tag. |
| 3034 | if (mHistoryLastWritten.wakeReasonTag != null) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3035 | cur.wakeReasonTag = cur.localWakeReasonTag; |
| 3036 | cur.wakeReasonTag.setTo(mHistoryLastWritten.wakeReasonTag); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 3037 | } |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 3038 | // If the last written history had an event, we need to retain it. |
| 3039 | // Note that the condition above made sure that we aren't in a case where |
| 3040 | // both it and the current history item have an event. |
| 3041 | if (mHistoryLastWritten.eventCode != HistoryItem.EVENT_NONE) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3042 | cur.eventCode = mHistoryLastWritten.eventCode; |
| 3043 | cur.eventTag = cur.localEventTag; |
| 3044 | cur.eventTag.setTo(mHistoryLastWritten.eventTag); |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 3045 | } |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 3046 | mHistoryLastWritten.setTo(mHistoryLastLastWritten); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 3047 | } |
| 3048 | |
Adam Lesinski | 4548978 | 2016-12-15 23:45:17 -0800 | [diff] [blame] | 3049 | boolean recordResetDueToOverflow = false; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 3050 | final int dataSize = mHistoryBuffer.dataSize(); |
Adam Lesinski | 4548978 | 2016-12-15 23:45:17 -0800 | [diff] [blame] | 3051 | if (dataSize >= MAX_MAX_HISTORY_BUFFER*3) { |
| 3052 | // Clients can't deal with history buffers this large. This only |
| 3053 | // really happens when the device is on charger and interacted with |
| 3054 | // for long periods of time, like in retail mode. Since the device is |
| 3055 | // most likely charged, when unplugged, stats would have reset anyways. |
| 3056 | // Reset the stats and mark that we overflowed. |
| 3057 | // b/32540341 |
| 3058 | resetAllStatsLocked(); |
| 3059 | |
| 3060 | // Mark that we want to set *OVERFLOW* event and the RESET:START |
| 3061 | // events. |
| 3062 | recordResetDueToOverflow = true; |
| 3063 | |
| 3064 | } else if (dataSize >= MAX_HISTORY_BUFFER) { |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 3065 | if (!mHistoryOverflow) { |
| 3066 | mHistoryOverflow = true; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3067 | addHistoryBufferLocked(elapsedRealtimeMs, uptimeMs, HistoryItem.CMD_UPDATE, cur); |
| 3068 | addHistoryBufferLocked(elapsedRealtimeMs, uptimeMs, HistoryItem.CMD_OVERFLOW, cur); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3069 | return; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 3070 | } |
| 3071 | |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 3072 | // After overflow, we allow various bit-wise states to settle to 0. |
| 3073 | boolean writeAnyway = false; |
| 3074 | final int curStates = cur.states & HistoryItem.SETTLE_TO_ZERO_STATES |
| 3075 | & mActiveHistoryStates; |
| 3076 | if (mHistoryLastWritten.states != curStates) { |
| 3077 | // mActiveHistoryStates keeps track of which bits in .states are now being |
| 3078 | // forced to 0. |
| 3079 | int old = mActiveHistoryStates; |
| 3080 | mActiveHistoryStates &= curStates | ~HistoryItem.SETTLE_TO_ZERO_STATES; |
| 3081 | writeAnyway |= old != mActiveHistoryStates; |
| 3082 | } |
| 3083 | final int curStates2 = cur.states2 & HistoryItem.SETTLE_TO_ZERO_STATES2 |
| 3084 | & mActiveHistoryStates2; |
| 3085 | if (mHistoryLastWritten.states2 != curStates2) { |
| 3086 | // mActiveHistoryStates2 keeps track of which bits in .states2 are now being |
| 3087 | // forced to 0. |
| 3088 | int old = mActiveHistoryStates2; |
| 3089 | mActiveHistoryStates2 &= curStates2 | ~HistoryItem.SETTLE_TO_ZERO_STATES2; |
| 3090 | writeAnyway |= old != mActiveHistoryStates2; |
| 3091 | } |
| 3092 | |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 3093 | // Once we've reached the maximum number of items, we only |
| 3094 | // record changes to the battery level and the most interesting states. |
| 3095 | // Once we've reached the maximum maximum number of items, we only |
| 3096 | // record changes to the battery level. |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 3097 | if (!writeAnyway && mHistoryLastWritten.batteryLevel == cur.batteryLevel && |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 3098 | (dataSize >= MAX_MAX_HISTORY_BUFFER |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3099 | || ((mHistoryLastWritten.states^cur.states) |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 3100 | & HistoryItem.MOST_INTERESTING_STATES) == 0 |
| 3101 | || ((mHistoryLastWritten.states2^cur.states2) |
| 3102 | & HistoryItem.MOST_INTERESTING_STATES2) == 0)) { |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 3103 | return; |
| 3104 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3105 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3106 | addHistoryBufferLocked(elapsedRealtimeMs, uptimeMs, HistoryItem.CMD_UPDATE, cur); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3107 | return; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 3108 | } |
| 3109 | |
Adam Lesinski | 4548978 | 2016-12-15 23:45:17 -0800 | [diff] [blame] | 3110 | if (dataSize == 0 || recordResetDueToOverflow) { |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 3111 | // The history is currently empty; we need it to start with a time stamp. |
| 3112 | cur.currentTime = System.currentTimeMillis(); |
Adam Lesinski | 4548978 | 2016-12-15 23:45:17 -0800 | [diff] [blame] | 3113 | if (recordResetDueToOverflow) { |
| 3114 | addHistoryBufferLocked(elapsedRealtimeMs, uptimeMs, HistoryItem.CMD_OVERFLOW, cur); |
| 3115 | } |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 3116 | addHistoryBufferLocked(elapsedRealtimeMs, uptimeMs, HistoryItem.CMD_RESET, cur); |
| 3117 | } |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3118 | addHistoryBufferLocked(elapsedRealtimeMs, uptimeMs, HistoryItem.CMD_UPDATE, cur); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 3119 | } |
| 3120 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3121 | private void addHistoryBufferLocked(long elapsedRealtimeMs, long uptimeMs, byte cmd, |
| 3122 | HistoryItem cur) { |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 3123 | if (mIteratingHistory) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3124 | throw new IllegalStateException("Can't do this while iterating history!"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 3125 | } |
| 3126 | mHistoryBufferLastPos = mHistoryBuffer.dataPosition(); |
| 3127 | mHistoryLastLastWritten.setTo(mHistoryLastWritten); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3128 | mHistoryLastWritten.setTo(mHistoryBaseTime + elapsedRealtimeMs, cmd, cur); |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 3129 | mHistoryLastWritten.states &= mActiveHistoryStates; |
| 3130 | mHistoryLastWritten.states2 &= mActiveHistoryStates2; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3131 | writeHistoryDelta(mHistoryBuffer, mHistoryLastWritten, mHistoryLastLastWritten); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3132 | mLastHistoryElapsedRealtime = elapsedRealtimeMs; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3133 | cur.wakelockTag = null; |
| 3134 | cur.wakeReasonTag = null; |
| 3135 | cur.eventCode = HistoryItem.EVENT_NONE; |
| 3136 | cur.eventTag = null; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 3137 | if (DEBUG_HISTORY) Slog.i(TAG, "Writing history buffer: was " + mHistoryBufferLastPos |
| 3138 | + " now " + mHistoryBuffer.dataPosition() |
| 3139 | + " size is now " + mHistoryBuffer.dataSize()); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 3140 | } |
| 3141 | |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 3142 | int mChangedStates = 0; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3143 | int mChangedStates2 = 0; |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 3144 | |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3145 | void addHistoryRecordLocked(long elapsedRealtimeMs, long uptimeMs) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3146 | if (mTrackRunningHistoryElapsedRealtime != 0) { |
| 3147 | final long diffElapsed = elapsedRealtimeMs - mTrackRunningHistoryElapsedRealtime; |
| 3148 | final long diffUptime = uptimeMs - mTrackRunningHistoryUptime; |
| 3149 | if (diffUptime < (diffElapsed-20)) { |
| 3150 | final long wakeElapsedTime = elapsedRealtimeMs - (diffElapsed - diffUptime); |
| 3151 | mHistoryAddTmp.setTo(mHistoryLastWritten); |
| 3152 | mHistoryAddTmp.wakelockTag = null; |
| 3153 | mHistoryAddTmp.wakeReasonTag = null; |
| 3154 | mHistoryAddTmp.eventCode = HistoryItem.EVENT_NONE; |
| 3155 | mHistoryAddTmp.states &= ~HistoryItem.STATE_CPU_RUNNING_FLAG; |
| 3156 | addHistoryRecordInnerLocked(wakeElapsedTime, uptimeMs, mHistoryAddTmp); |
| 3157 | } |
| 3158 | } |
| 3159 | mHistoryCur.states |= HistoryItem.STATE_CPU_RUNNING_FLAG; |
| 3160 | mTrackRunningHistoryElapsedRealtime = elapsedRealtimeMs; |
| 3161 | mTrackRunningHistoryUptime = uptimeMs; |
| 3162 | addHistoryRecordInnerLocked(elapsedRealtimeMs, uptimeMs, mHistoryCur); |
| 3163 | } |
| 3164 | |
| 3165 | void addHistoryRecordInnerLocked(long elapsedRealtimeMs, long uptimeMs, HistoryItem cur) { |
| 3166 | addHistoryBufferLocked(elapsedRealtimeMs, uptimeMs, cur); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 3167 | |
Dianne Hackborn | e8c88e6 | 2011-08-17 19:09:09 -0700 | [diff] [blame] | 3168 | if (!USE_OLD_HISTORY) { |
| 3169 | return; |
| 3170 | } |
| 3171 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3172 | if (!mHaveBatteryLevel || !mRecordingHistory) { |
| 3173 | return; |
| 3174 | } |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3175 | |
| 3176 | // If the current time is basically the same as the last time, |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 3177 | // and no states have since the last recorded entry changed and |
| 3178 | // are now resetting back to their original value, then just collapse |
| 3179 | // into one record. |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3180 | if (mHistoryEnd != null && mHistoryEnd.cmd == HistoryItem.CMD_UPDATE |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3181 | && (mHistoryBaseTime+elapsedRealtimeMs) < (mHistoryEnd.time+1000) |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 3182 | && ((mHistoryEnd.states^cur.states)&mChangedStates&mActiveHistoryStates) == 0 |
| 3183 | && ((mHistoryEnd.states2^cur.states2)&mChangedStates2&mActiveHistoryStates2) == 0) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3184 | // If the current is the same as the one before, then we no |
| 3185 | // longer need the entry. |
| 3186 | if (mHistoryLastEnd != null && mHistoryLastEnd.cmd == HistoryItem.CMD_UPDATE |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3187 | && (mHistoryBaseTime+elapsedRealtimeMs) < (mHistoryEnd.time+500) |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3188 | && mHistoryLastEnd.sameNonEvent(cur)) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3189 | mHistoryLastEnd.next = null; |
| 3190 | mHistoryEnd.next = mHistoryCache; |
| 3191 | mHistoryCache = mHistoryEnd; |
| 3192 | mHistoryEnd = mHistoryLastEnd; |
| 3193 | mHistoryLastEnd = null; |
| 3194 | } else { |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 3195 | mChangedStates |= mHistoryEnd.states^(cur.states&mActiveHistoryStates); |
| 3196 | mChangedStates2 |= mHistoryEnd.states^(cur.states2&mActiveHistoryStates2); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3197 | mHistoryEnd.setTo(mHistoryEnd.time, HistoryItem.CMD_UPDATE, cur); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3198 | } |
| 3199 | return; |
| 3200 | } |
| 3201 | |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 3202 | mChangedStates = 0; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3203 | mChangedStates2 = 0; |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 3204 | |
| 3205 | if (mNumHistoryItems == MAX_HISTORY_ITEMS |
| 3206 | || mNumHistoryItems == MAX_MAX_HISTORY_ITEMS) { |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3207 | addHistoryRecordLocked(elapsedRealtimeMs, HistoryItem.CMD_OVERFLOW); |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 3208 | } |
| 3209 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3210 | if (mNumHistoryItems >= MAX_HISTORY_ITEMS) { |
| 3211 | // Once we've reached the maximum number of items, we only |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 3212 | // record changes to the battery level and the most interesting states. |
| 3213 | // Once we've reached the maximum maximum number of items, we only |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3214 | // record changes to the battery level. |
| 3215 | if (mHistoryEnd != null && mHistoryEnd.batteryLevel |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3216 | == cur.batteryLevel && |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 3217 | (mNumHistoryItems >= MAX_MAX_HISTORY_ITEMS |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 3218 | || ((mHistoryEnd.states^(cur.states&mActiveHistoryStates)) |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 3219 | & HistoryItem.MOST_INTERESTING_STATES) == 0)) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3220 | return; |
| 3221 | } |
| 3222 | } |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3223 | |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3224 | addHistoryRecordLocked(elapsedRealtimeMs, HistoryItem.CMD_UPDATE); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3225 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3226 | |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 3227 | public void addHistoryEventLocked(long elapsedRealtimeMs, long uptimeMs, int code, |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3228 | String name, int uid) { |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 3229 | mHistoryCur.eventCode = code; |
| 3230 | mHistoryCur.eventTag = mHistoryCur.localEventTag; |
| 3231 | mHistoryCur.eventTag.string = name; |
| 3232 | mHistoryCur.eventTag.uid = uid; |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 3233 | addHistoryRecordLocked(elapsedRealtimeMs, uptimeMs); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3234 | } |
| 3235 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3236 | void addHistoryRecordLocked(long elapsedRealtimeMs, long uptimeMs, byte cmd, HistoryItem cur) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3237 | HistoryItem rec = mHistoryCache; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3238 | if (rec != null) { |
| 3239 | mHistoryCache = rec.next; |
| 3240 | } else { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3241 | rec = new HistoryItem(); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3242 | } |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3243 | rec.setTo(mHistoryBaseTime + elapsedRealtimeMs, cmd, cur); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3244 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3245 | addHistoryRecordLocked(rec); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3246 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3247 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3248 | void addHistoryRecordLocked(HistoryItem rec) { |
| 3249 | mNumHistoryItems++; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3250 | rec.next = null; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3251 | mHistoryLastEnd = mHistoryEnd; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3252 | if (mHistoryEnd != null) { |
| 3253 | mHistoryEnd.next = rec; |
| 3254 | mHistoryEnd = rec; |
| 3255 | } else { |
| 3256 | mHistory = mHistoryEnd = rec; |
| 3257 | } |
| 3258 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3259 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3260 | void clearHistoryLocked() { |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 3261 | if (DEBUG_HISTORY) Slog.i(TAG, "********** CLEARING HISTORY!"); |
Dianne Hackborn | e8c88e6 | 2011-08-17 19:09:09 -0700 | [diff] [blame] | 3262 | if (USE_OLD_HISTORY) { |
| 3263 | if (mHistory != null) { |
| 3264 | mHistoryEnd.next = mHistoryCache; |
| 3265 | mHistoryCache = mHistory; |
| 3266 | mHistory = mHistoryLastEnd = mHistoryEnd = null; |
| 3267 | } |
| 3268 | mNumHistoryItems = 0; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3269 | } |
Dianne Hackborn | e8c88e6 | 2011-08-17 19:09:09 -0700 | [diff] [blame] | 3270 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3271 | mHistoryBaseTime = 0; |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3272 | mLastHistoryElapsedRealtime = 0; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3273 | mTrackRunningHistoryElapsedRealtime = 0; |
| 3274 | mTrackRunningHistoryUptime = 0; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 3275 | |
| 3276 | mHistoryBuffer.setDataSize(0); |
| 3277 | mHistoryBuffer.setDataPosition(0); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3278 | mHistoryBuffer.setDataCapacity(MAX_HISTORY_BUFFER / 2); |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 3279 | mHistoryLastLastWritten.clear(); |
| 3280 | mHistoryLastWritten.clear(); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3281 | mHistoryTagPool.clear(); |
| 3282 | mNextHistoryTagIdx = 0; |
| 3283 | mNumHistoryTagChars = 0; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 3284 | mHistoryBufferLastPos = -1; |
| 3285 | mHistoryOverflow = false; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 3286 | mActiveHistoryStates = 0xffffffff; |
| 3287 | mActiveHistoryStates2 = 0xffffffff; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3288 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3289 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3290 | public void updateTimeBasesLocked(boolean unplugged, boolean screenOff, long uptime, |
| 3291 | long realtime) { |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 3292 | boolean batteryStatusChanged = mOnBatteryTimeBase.setRunning(unplugged, uptime, realtime); |
| 3293 | |
| 3294 | if (batteryStatusChanged) { |
| 3295 | for (int i=0; i<mUidStats.size(); i++) { |
| 3296 | mUidStats.valueAt(i).updateBgTimeBase(uptime, realtime); |
| 3297 | } |
| 3298 | } |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 3299 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3300 | boolean unpluggedScreenOff = unplugged && screenOff; |
| 3301 | if (unpluggedScreenOff != mOnBatteryScreenOffTimeBase.isRunning()) { |
| 3302 | updateKernelWakelocksLocked(); |
Adam Lesinski | e1f480d | 2017-02-15 18:51:23 -0800 | [diff] [blame] | 3303 | updateBatteryPropertiesLocked(); |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 3304 | if (DEBUG_ENERGY_CPU) { |
| 3305 | Slog.d(TAG, "Updating cpu time because screen is now " + |
| 3306 | (unpluggedScreenOff ? "off" : "on")); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3307 | } |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 3308 | updateCpuTimeLocked(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3309 | mOnBatteryScreenOffTimeBase.setRunning(unpluggedScreenOff, uptime, realtime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3310 | } |
| 3311 | } |
Amith Yamasani | 3718aaa | 2009-06-09 06:32:35 -0700 | [diff] [blame] | 3312 | |
Adam Lesinski | e1f480d | 2017-02-15 18:51:23 -0800 | [diff] [blame] | 3313 | private void updateBatteryPropertiesLocked() { |
| 3314 | try { |
| 3315 | IBatteryPropertiesRegistrar registrar = IBatteryPropertiesRegistrar.Stub.asInterface( |
| 3316 | ServiceManager.getService("batteryproperties")); |
| 3317 | registrar.scheduleUpdate(); |
| 3318 | } catch (RemoteException e) { |
| 3319 | // Ignore. |
| 3320 | } |
| 3321 | } |
| 3322 | |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3323 | public void addIsolatedUidLocked(int isolatedUid, int appUid) { |
| 3324 | mIsolatedUids.put(isolatedUid, appUid); |
| 3325 | } |
| 3326 | |
Adam Lesinski | 61db88f | 2015-07-01 15:05:07 -0700 | [diff] [blame] | 3327 | /** |
| 3328 | * Schedules a read of the latest cpu times before removing the isolated UID. |
| 3329 | * @see #removeIsolatedUidLocked(int) |
| 3330 | */ |
| 3331 | public void scheduleRemoveIsolatedUidLocked(int isolatedUid, int appUid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3332 | int curUid = mIsolatedUids.get(isolatedUid, -1); |
| 3333 | if (curUid == appUid) { |
Adam Lesinski | 61db88f | 2015-07-01 15:05:07 -0700 | [diff] [blame] | 3334 | if (mExternalSync != null) { |
| 3335 | mExternalSync.scheduleCpuSyncDueToRemovedUid(isolatedUid); |
| 3336 | } |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3337 | } |
| 3338 | } |
| 3339 | |
Adam Lesinski | 61db88f | 2015-07-01 15:05:07 -0700 | [diff] [blame] | 3340 | /** |
| 3341 | * This should only be called after the cpu times have been read. |
| 3342 | * @see #scheduleRemoveIsolatedUidLocked(int, int) |
| 3343 | */ |
| 3344 | public void removeIsolatedUidLocked(int isolatedUid) { |
| 3345 | mIsolatedUids.delete(isolatedUid); |
| 3346 | mKernelUidCpuTimeReader.removeUid(isolatedUid); |
| 3347 | } |
| 3348 | |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3349 | public int mapUid(int uid) { |
| 3350 | int isolated = mIsolatedUids.get(uid, -1); |
| 3351 | return isolated > 0 ? isolated : uid; |
| 3352 | } |
| 3353 | |
| 3354 | public void noteEventLocked(int code, String name, int uid) { |
| 3355 | uid = mapUid(uid); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 3356 | if (!mActiveEvents.updateState(code, name, uid, 0)) { |
| 3357 | return; |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 3358 | } |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3359 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3360 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3361 | addHistoryEventLocked(elapsedRealtime, uptime, code, name, uid); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3362 | } |
| 3363 | |
Dianne Hackborn | d48954f | 2015-07-22 17:20:33 -0700 | [diff] [blame] | 3364 | boolean ensureStartClockTime(final long currentTime) { |
| 3365 | final long ABOUT_ONE_YEAR = 365*24*60*60*1000L; |
| 3366 | if (currentTime > ABOUT_ONE_YEAR && mStartClockTime < (currentTime-ABOUT_ONE_YEAR)) { |
| 3367 | // If the start clock time has changed by more than a year, then presumably |
| 3368 | // the previous time was completely bogus. So we are going to figure out a |
| 3369 | // 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] | 3370 | mStartClockTime = currentTime - (mClocks.elapsedRealtime()-(mRealtimeStart/1000)); |
Dianne Hackborn | d48954f | 2015-07-22 17:20:33 -0700 | [diff] [blame] | 3371 | return true; |
| 3372 | } |
| 3373 | return false; |
| 3374 | } |
| 3375 | |
Dianne Hackborn | 7d9eefd | 2014-08-27 18:30:31 -0700 | [diff] [blame] | 3376 | public void noteCurrentTimeChangedLocked() { |
| 3377 | final long currentTime = System.currentTimeMillis(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3378 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3379 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 7d9eefd | 2014-08-27 18:30:31 -0700 | [diff] [blame] | 3380 | recordCurrentTimeChangeLocked(currentTime, elapsedRealtime, uptime); |
Dianne Hackborn | d48954f | 2015-07-22 17:20:33 -0700 | [diff] [blame] | 3381 | ensureStartClockTime(currentTime); |
Dianne Hackborn | 7d9eefd | 2014-08-27 18:30:31 -0700 | [diff] [blame] | 3382 | } |
| 3383 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 3384 | public void noteProcessStartLocked(String name, int uid) { |
| 3385 | uid = mapUid(uid); |
| 3386 | if (isOnBattery()) { |
| 3387 | Uid u = getUidStatsLocked(uid); |
| 3388 | u.getProcessStatsLocked(name).incStartsLocked(); |
| 3389 | } |
| 3390 | if (!mActiveEvents.updateState(HistoryItem.EVENT_PROC_START, name, uid, 0)) { |
| 3391 | return; |
| 3392 | } |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 3393 | if (!mRecordAllHistory) { |
| 3394 | return; |
| 3395 | } |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3396 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3397 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 3398 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_PROC_START, name, uid); |
| 3399 | } |
| 3400 | |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 3401 | public void noteProcessCrashLocked(String name, int uid) { |
| 3402 | uid = mapUid(uid); |
| 3403 | if (isOnBattery()) { |
| 3404 | Uid u = getUidStatsLocked(uid); |
| 3405 | u.getProcessStatsLocked(name).incNumCrashesLocked(); |
| 3406 | } |
| 3407 | } |
| 3408 | |
| 3409 | public void noteProcessAnrLocked(String name, int uid) { |
| 3410 | uid = mapUid(uid); |
| 3411 | if (isOnBattery()) { |
| 3412 | Uid u = getUidStatsLocked(uid); |
| 3413 | u.getProcessStatsLocked(name).incNumAnrsLocked(); |
| 3414 | } |
| 3415 | } |
| 3416 | |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 3417 | public void noteUidProcessStateLocked(int uid, int state) { |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 3418 | uid = mapUid(uid); |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 3419 | getUidStatsLocked(uid).updateUidProcessStateLocked(state); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 3420 | } |
| 3421 | |
| 3422 | public void noteProcessFinishLocked(String name, int uid) { |
| 3423 | uid = mapUid(uid); |
| 3424 | if (!mActiveEvents.updateState(HistoryItem.EVENT_PROC_FINISH, name, uid, 0)) { |
| 3425 | return; |
| 3426 | } |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 3427 | if (!mRecordAllHistory) { |
| 3428 | return; |
| 3429 | } |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3430 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3431 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 3432 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_PROC_FINISH, name, uid); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 3433 | } |
| 3434 | |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 3435 | public void noteSyncStartLocked(String name, int uid) { |
| 3436 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3437 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3438 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 3439 | getUidStatsLocked(uid).noteStartSyncLocked(name, elapsedRealtime); |
| 3440 | if (!mActiveEvents.updateState(HistoryItem.EVENT_SYNC_START, name, uid, 0)) { |
| 3441 | return; |
| 3442 | } |
| 3443 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_SYNC_START, name, uid); |
| 3444 | } |
| 3445 | |
| 3446 | public void noteSyncFinishLocked(String name, int uid) { |
| 3447 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3448 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3449 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 3450 | getUidStatsLocked(uid).noteStopSyncLocked(name, elapsedRealtime); |
| 3451 | if (!mActiveEvents.updateState(HistoryItem.EVENT_SYNC_FINISH, name, uid, 0)) { |
| 3452 | return; |
| 3453 | } |
| 3454 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_SYNC_FINISH, name, uid); |
| 3455 | } |
| 3456 | |
| 3457 | public void noteJobStartLocked(String name, int uid) { |
| 3458 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3459 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3460 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 3461 | getUidStatsLocked(uid).noteStartJobLocked(name, elapsedRealtime); |
| 3462 | if (!mActiveEvents.updateState(HistoryItem.EVENT_JOB_START, name, uid, 0)) { |
| 3463 | return; |
| 3464 | } |
| 3465 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_JOB_START, name, uid); |
| 3466 | } |
| 3467 | |
| 3468 | public void noteJobFinishLocked(String name, int uid) { |
| 3469 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3470 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3471 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 3472 | getUidStatsLocked(uid).noteStopJobLocked(name, elapsedRealtime); |
| 3473 | if (!mActiveEvents.updateState(HistoryItem.EVENT_JOB_FINISH, name, uid, 0)) { |
| 3474 | return; |
| 3475 | } |
| 3476 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_JOB_FINISH, name, uid); |
| 3477 | } |
| 3478 | |
Dianne Hackborn | 1e38382 | 2015-04-10 14:02:33 -0700 | [diff] [blame] | 3479 | public void noteAlarmStartLocked(String name, int uid) { |
| 3480 | if (!mRecordAllHistory) { |
| 3481 | return; |
| 3482 | } |
| 3483 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3484 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3485 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 1e38382 | 2015-04-10 14:02:33 -0700 | [diff] [blame] | 3486 | if (!mActiveEvents.updateState(HistoryItem.EVENT_ALARM_START, name, uid, 0)) { |
| 3487 | return; |
| 3488 | } |
| 3489 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_ALARM_START, name, uid); |
| 3490 | } |
| 3491 | |
| 3492 | public void noteAlarmFinishLocked(String name, int uid) { |
| 3493 | if (!mRecordAllHistory) { |
| 3494 | return; |
| 3495 | } |
| 3496 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3497 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3498 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 1e38382 | 2015-04-10 14:02:33 -0700 | [diff] [blame] | 3499 | if (!mActiveEvents.updateState(HistoryItem.EVENT_ALARM_FINISH, name, uid, 0)) { |
| 3500 | return; |
| 3501 | } |
| 3502 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_ALARM_FINISH, name, uid); |
| 3503 | } |
| 3504 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3505 | private void requestWakelockCpuUpdate() { |
| 3506 | if (!mHandler.hasMessages(MSG_UPDATE_WAKELOCKS)) { |
| 3507 | Message m = mHandler.obtainMessage(MSG_UPDATE_WAKELOCKS); |
| 3508 | mHandler.sendMessageDelayed(m, DELAY_UPDATE_WAKELOCKS); |
| 3509 | } |
| 3510 | } |
| 3511 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 3512 | private void requestImmediateCpuUpdate() { |
| 3513 | mHandler.removeMessages(MSG_UPDATE_WAKELOCKS); |
| 3514 | mHandler.sendEmptyMessage(MSG_UPDATE_WAKELOCKS); |
| 3515 | } |
| 3516 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 3517 | public void setRecordAllHistoryLocked(boolean enabled) { |
| 3518 | mRecordAllHistory = enabled; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3519 | if (!enabled) { |
| 3520 | // Clear out any existing state. |
| 3521 | mActiveEvents.removeEvents(HistoryItem.EVENT_WAKE_LOCK); |
Dianne Hackborn | 1e38382 | 2015-04-10 14:02:33 -0700 | [diff] [blame] | 3522 | mActiveEvents.removeEvents(HistoryItem.EVENT_ALARM); |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 3523 | // Record the currently running processes as stopping, now that we are no |
| 3524 | // longer tracking them. |
| 3525 | HashMap<String, SparseIntArray> active = mActiveEvents.getStateForEvent( |
| 3526 | HistoryItem.EVENT_PROC); |
| 3527 | if (active != null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3528 | long mSecRealtime = mClocks.elapsedRealtime(); |
| 3529 | final long mSecUptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 3530 | for (HashMap.Entry<String, SparseIntArray> ent : active.entrySet()) { |
| 3531 | SparseIntArray uids = ent.getValue(); |
| 3532 | for (int j=0; j<uids.size(); j++) { |
| 3533 | addHistoryEventLocked(mSecRealtime, mSecUptime, |
| 3534 | HistoryItem.EVENT_PROC_FINISH, ent.getKey(), uids.keyAt(j)); |
| 3535 | } |
| 3536 | } |
| 3537 | } |
| 3538 | } else { |
| 3539 | // Record the currently running processes as starting, now that we are tracking them. |
| 3540 | HashMap<String, SparseIntArray> active = mActiveEvents.getStateForEvent( |
| 3541 | HistoryItem.EVENT_PROC); |
| 3542 | if (active != null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3543 | long mSecRealtime = mClocks.elapsedRealtime(); |
| 3544 | final long mSecUptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 3545 | for (HashMap.Entry<String, SparseIntArray> ent : active.entrySet()) { |
| 3546 | SparseIntArray uids = ent.getValue(); |
| 3547 | for (int j=0; j<uids.size(); j++) { |
| 3548 | addHistoryEventLocked(mSecRealtime, mSecUptime, |
| 3549 | HistoryItem.EVENT_PROC_START, ent.getKey(), uids.keyAt(j)); |
| 3550 | } |
| 3551 | } |
| 3552 | } |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3553 | } |
| 3554 | } |
| 3555 | |
Dianne Hackborn | 9a75543 | 2014-05-15 17:05:22 -0700 | [diff] [blame] | 3556 | public void setNoAutoReset(boolean enabled) { |
| 3557 | mNoAutoReset = enabled; |
| 3558 | } |
| 3559 | |
Amith Yamasani | 674c9bb | 2017-02-01 09:45:17 -0800 | [diff] [blame] | 3560 | public void setPretendScreenOff(boolean pretendScreenOff) { |
| 3561 | mPretendScreenOff = pretendScreenOff; |
| 3562 | noteScreenStateLocked(pretendScreenOff ? Display.STATE_OFF : Display.STATE_ON); |
| 3563 | } |
| 3564 | |
Dianne Hackborn | 9a75543 | 2014-05-15 17:05:22 -0700 | [diff] [blame] | 3565 | private String mInitialAcquireWakeName; |
| 3566 | private int mInitialAcquireWakeUid = -1; |
| 3567 | |
Dianne Hackborn | a1f1a3c | 2014-02-24 18:12:28 -0800 | [diff] [blame] | 3568 | 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] | 3569 | boolean unimportantForLogging, long elapsedRealtime, long uptime) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3570 | uid = mapUid(uid); |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 3571 | if (type == WAKE_TYPE_PARTIAL) { |
| 3572 | // Only care about partial wake locks, since full wake locks |
| 3573 | // will be canceled when the user puts the screen to sleep. |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3574 | aggregateLastWakeupUptimeLocked(uptime); |
Dianne Hackborn | fc06413 | 2014-06-02 12:42:12 -0700 | [diff] [blame] | 3575 | if (historyName == null) { |
| 3576 | historyName = name; |
| 3577 | } |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 3578 | if (mRecordAllHistory) { |
Dianne Hackborn | fc06413 | 2014-06-02 12:42:12 -0700 | [diff] [blame] | 3579 | if (mActiveEvents.updateState(HistoryItem.EVENT_WAKE_LOCK_START, historyName, |
| 3580 | uid, 0)) { |
Dianne Hackborn | 536456f | 2014-05-23 16:51:05 -0700 | [diff] [blame] | 3581 | addHistoryEventLocked(elapsedRealtime, uptime, |
Dianne Hackborn | fc06413 | 2014-06-02 12:42:12 -0700 | [diff] [blame] | 3582 | HistoryItem.EVENT_WAKE_LOCK_START, historyName, uid); |
Dianne Hackborn | 536456f | 2014-05-23 16:51:05 -0700 | [diff] [blame] | 3583 | } |
| 3584 | } |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 3585 | if (mWakeLockNesting == 0) { |
| 3586 | mHistoryCur.states |= HistoryItem.STATE_WAKE_LOCK_FLAG; |
| 3587 | if (DEBUG_HISTORY) Slog.v(TAG, "Start wake lock to: " |
| 3588 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3589 | mHistoryCur.wakelockTag = mHistoryCur.localWakelockTag; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3590 | mHistoryCur.wakelockTag.string = mInitialAcquireWakeName = historyName; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 3591 | mHistoryCur.wakelockTag.uid = mInitialAcquireWakeUid = uid; |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 3592 | mWakeLockImportant = !unimportantForLogging; |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3593 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | fc06413 | 2014-06-02 12:42:12 -0700 | [diff] [blame] | 3594 | } else if (!mWakeLockImportant && !unimportantForLogging |
| 3595 | && mHistoryLastWritten.cmd == HistoryItem.CMD_UPDATE) { |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 3596 | if (mHistoryLastWritten.wakelockTag != null) { |
| 3597 | // We'll try to update the last tag. |
| 3598 | mHistoryLastWritten.wakelockTag = null; |
| 3599 | mHistoryCur.wakelockTag = mHistoryCur.localWakelockTag; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3600 | mHistoryCur.wakelockTag.string = mInitialAcquireWakeName = historyName; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 3601 | mHistoryCur.wakelockTag.uid = mInitialAcquireWakeUid = uid; |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3602 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 3603 | } |
| 3604 | mWakeLockImportant = true; |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 3605 | } |
| 3606 | mWakeLockNesting++; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3607 | } |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3608 | if (uid >= 0) { |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 3609 | if (mOnBatteryScreenOffTimeBase.isRunning()) { |
| 3610 | // We only update the cpu time when a wake lock is acquired if the screen is off. |
| 3611 | // If the screen is on, we don't distribute the power amongst partial wakelocks. |
| 3612 | if (DEBUG_ENERGY_CPU) { |
| 3613 | Slog.d(TAG, "Updating cpu time because of +wake_lock"); |
| 3614 | } |
| 3615 | requestWakelockCpuUpdate(); |
| 3616 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3617 | getUidStatsLocked(uid).noteStartWakeLocked(pid, name, type, elapsedRealtime); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3618 | } |
| 3619 | } |
| 3620 | |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3621 | public void noteStopWakeLocked(int uid, int pid, String name, String historyName, int type, |
| 3622 | long elapsedRealtime, long uptime) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3623 | uid = mapUid(uid); |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 3624 | if (type == WAKE_TYPE_PARTIAL) { |
| 3625 | mWakeLockNesting--; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 3626 | if (mRecordAllHistory) { |
Dianne Hackborn | fc06413 | 2014-06-02 12:42:12 -0700 | [diff] [blame] | 3627 | if (historyName == null) { |
| 3628 | historyName = name; |
| 3629 | } |
| 3630 | if (mActiveEvents.updateState(HistoryItem.EVENT_WAKE_LOCK_FINISH, historyName, |
| 3631 | uid, 0)) { |
Dianne Hackborn | 536456f | 2014-05-23 16:51:05 -0700 | [diff] [blame] | 3632 | addHistoryEventLocked(elapsedRealtime, uptime, |
Dianne Hackborn | fc06413 | 2014-06-02 12:42:12 -0700 | [diff] [blame] | 3633 | HistoryItem.EVENT_WAKE_LOCK_FINISH, historyName, uid); |
Dianne Hackborn | 536456f | 2014-05-23 16:51:05 -0700 | [diff] [blame] | 3634 | } |
| 3635 | } |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 3636 | if (mWakeLockNesting == 0) { |
| 3637 | mHistoryCur.states &= ~HistoryItem.STATE_WAKE_LOCK_FLAG; |
| 3638 | if (DEBUG_HISTORY) Slog.v(TAG, "Stop wake lock to: " |
| 3639 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 3640 | mInitialAcquireWakeName = null; |
| 3641 | mInitialAcquireWakeUid = -1; |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3642 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 3643 | } |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3644 | } |
| 3645 | if (uid >= 0) { |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 3646 | if (mOnBatteryScreenOffTimeBase.isRunning()) { |
| 3647 | if (DEBUG_ENERGY_CPU) { |
| 3648 | Slog.d(TAG, "Updating cpu time because of -wake_lock"); |
| 3649 | } |
| 3650 | requestWakelockCpuUpdate(); |
| 3651 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3652 | getUidStatsLocked(uid).noteStopWakeLocked(pid, name, type, elapsedRealtime); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3653 | } |
| 3654 | } |
| 3655 | |
Dianne Hackborn | a1f1a3c | 2014-02-24 18:12:28 -0800 | [diff] [blame] | 3656 | public void noteStartWakeFromSourceLocked(WorkSource ws, int pid, String name, |
| 3657 | String historyName, int type, boolean unimportantForLogging) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3658 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3659 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 3660 | final int N = ws.size(); |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 3661 | for (int i=0; i<N; i++) { |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 3662 | noteStartWakeLocked(ws.get(i), pid, name, historyName, type, unimportantForLogging, |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3663 | elapsedRealtime, uptime); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 3664 | } |
| 3665 | } |
| 3666 | |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3667 | public void noteChangeWakelockFromSourceLocked(WorkSource ws, int pid, String name, |
| 3668 | String historyName, int type, WorkSource newWs, int newPid, String newName, |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 3669 | String newHistoryName, int newType, boolean newUnimportantForLogging) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3670 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3671 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 3672 | // For correct semantics, we start the need worksources first, so that we won't |
| 3673 | // make inappropriate history items as if all wake locks went away and new ones |
| 3674 | // appeared. This is okay because tracking of wake locks allows nesting. |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3675 | final int NN = newWs.size(); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 3676 | for (int i=0; i<NN; i++) { |
| 3677 | noteStartWakeLocked(newWs.get(i), newPid, newName, newHistoryName, newType, |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3678 | newUnimportantForLogging, elapsedRealtime, uptime); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 3679 | } |
| 3680 | final int NO = ws.size(); |
| 3681 | for (int i=0; i<NO; i++) { |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3682 | noteStopWakeLocked(ws.get(i), pid, name, historyName, type, elapsedRealtime, uptime); |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 3683 | } |
| 3684 | } |
| 3685 | |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3686 | public void noteStopWakeFromSourceLocked(WorkSource ws, int pid, String name, |
| 3687 | String historyName, int type) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3688 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3689 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 3690 | final int N = ws.size(); |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 3691 | for (int i=0; i<N; i++) { |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3692 | noteStopWakeLocked(ws.get(i), pid, name, historyName, type, elapsedRealtime, uptime); |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 3693 | } |
| 3694 | } |
| 3695 | |
Dianne Hackborn | d0db6f0 | 2016-07-18 14:14:20 -0700 | [diff] [blame] | 3696 | public void noteLongPartialWakelockStart(String name, String historyName, int uid) { |
| 3697 | uid = mapUid(uid); |
| 3698 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3699 | final long uptime = mClocks.uptimeMillis(); |
| 3700 | if (historyName == null) { |
| 3701 | historyName = name; |
| 3702 | } |
| 3703 | if (!mActiveEvents.updateState(HistoryItem.EVENT_LONG_WAKE_LOCK_START, historyName, uid, |
| 3704 | 0)) { |
| 3705 | return; |
| 3706 | } |
| 3707 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_LONG_WAKE_LOCK_START, |
| 3708 | historyName, uid); |
| 3709 | } |
| 3710 | |
| 3711 | public void noteLongPartialWakelockFinish(String name, String historyName, int uid) { |
| 3712 | uid = mapUid(uid); |
| 3713 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3714 | final long uptime = mClocks.uptimeMillis(); |
| 3715 | if (historyName == null) { |
| 3716 | historyName = name; |
| 3717 | } |
| 3718 | if (!mActiveEvents.updateState(HistoryItem.EVENT_LONG_WAKE_LOCK_FINISH, historyName, uid, |
| 3719 | 0)) { |
| 3720 | return; |
| 3721 | } |
| 3722 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_LONG_WAKE_LOCK_FINISH, |
| 3723 | historyName, uid); |
| 3724 | } |
| 3725 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3726 | void aggregateLastWakeupUptimeLocked(long uptimeMs) { |
| 3727 | if (mLastWakeupReason != null) { |
| 3728 | long deltaUptime = uptimeMs - mLastWakeupUptimeMs; |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 3729 | SamplingTimer timer = getWakeupReasonTimerLocked(mLastWakeupReason); |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 3730 | timer.add(deltaUptime * 1000, 1); // time in in microseconds |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3731 | mLastWakeupReason = null; |
| 3732 | } |
| 3733 | } |
| 3734 | |
| 3735 | public void noteWakeupReasonLocked(String reason) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3736 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3737 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 3738 | if (DEBUG_HISTORY) Slog.v(TAG, "Wakeup reason \"" + reason +"\": " |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 3739 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3740 | aggregateLastWakeupUptimeLocked(uptime); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 3741 | mHistoryCur.wakeReasonTag = mHistoryCur.localWakeReasonTag; |
| 3742 | mHistoryCur.wakeReasonTag.string = reason; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3743 | mHistoryCur.wakeReasonTag.uid = 0; |
| 3744 | mLastWakeupReason = reason; |
| 3745 | mLastWakeupUptimeMs = uptime; |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3746 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 3747 | } |
| 3748 | |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 3749 | public boolean startAddingCpuLocked() { |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 3750 | mHandler.removeMessages(MSG_UPDATE_WAKELOCKS); |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 3751 | return mOnBatteryInternal; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 3752 | } |
| 3753 | |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 3754 | public void finishAddingCpuLocked(int totalUTime, int totalSTime, int statUserTime, |
| 3755 | int statSystemTime, int statIOWaitTime, int statIrqTime, |
| 3756 | int statSoftIrqTime, int statIdleTime) { |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 3757 | if (DEBUG) Slog.d(TAG, "Adding cpu: tuser=" + totalUTime + " tsys=" + totalSTime |
| 3758 | + " user=" + statUserTime + " sys=" + statSystemTime |
| 3759 | + " io=" + statIOWaitTime + " irq=" + statIrqTime |
| 3760 | + " sirq=" + statSoftIrqTime + " idle=" + statIdleTime); |
| 3761 | mCurStepCpuUserTime += totalUTime; |
| 3762 | mCurStepCpuSystemTime += totalSTime; |
| 3763 | mCurStepStatUserTime += statUserTime; |
| 3764 | mCurStepStatSystemTime += statSystemTime; |
| 3765 | mCurStepStatIOWaitTime += statIOWaitTime; |
| 3766 | mCurStepStatIrqTime += statIrqTime; |
| 3767 | mCurStepStatSoftIrqTime += statSoftIrqTime; |
| 3768 | mCurStepStatIdleTime += statIdleTime; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 3769 | } |
| 3770 | |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3771 | public void noteProcessDiedLocked(int uid, int pid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3772 | uid = mapUid(uid); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3773 | Uid u = mUidStats.get(uid); |
| 3774 | if (u != null) { |
| 3775 | u.mPids.remove(pid); |
| 3776 | } |
| 3777 | } |
| 3778 | |
| 3779 | public long getProcessWakeTime(int uid, int pid, long realtime) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3780 | uid = mapUid(uid); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3781 | Uid u = mUidStats.get(uid); |
| 3782 | if (u != null) { |
| 3783 | Uid.Pid p = u.mPids.get(pid); |
| 3784 | if (p != null) { |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 3785 | return p.mWakeSumMs + (p.mWakeNesting > 0 ? (realtime - p.mWakeStartMs) : 0); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3786 | } |
| 3787 | } |
| 3788 | return 0; |
| 3789 | } |
| 3790 | |
| 3791 | public void reportExcessiveWakeLocked(int uid, String proc, long overTime, long usedTime) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3792 | uid = mapUid(uid); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3793 | Uid u = mUidStats.get(uid); |
| 3794 | if (u != null) { |
| 3795 | u.reportExcessiveWakeLocked(proc, overTime, usedTime); |
| 3796 | } |
| 3797 | } |
| 3798 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 3799 | public void reportExcessiveCpuLocked(int uid, String proc, long overTime, long usedTime) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3800 | uid = mapUid(uid); |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 3801 | Uid u = mUidStats.get(uid); |
| 3802 | if (u != null) { |
| 3803 | u.reportExcessiveCpuLocked(proc, overTime, usedTime); |
| 3804 | } |
| 3805 | } |
| 3806 | |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3807 | int mSensorNesting; |
| 3808 | |
| 3809 | public void noteStartSensorLocked(int uid, int sensor) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3810 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3811 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3812 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3813 | if (mSensorNesting == 0) { |
| 3814 | mHistoryCur.states |= HistoryItem.STATE_SENSOR_ON_FLAG; |
| 3815 | if (DEBUG_HISTORY) Slog.v(TAG, "Start sensor to: " |
| 3816 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3817 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3818 | } |
| 3819 | mSensorNesting++; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3820 | getUidStatsLocked(uid).noteStartSensor(sensor, elapsedRealtime); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3821 | } |
| 3822 | |
| 3823 | public void noteStopSensorLocked(int uid, int sensor) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3824 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3825 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3826 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3827 | mSensorNesting--; |
| 3828 | if (mSensorNesting == 0) { |
| 3829 | mHistoryCur.states &= ~HistoryItem.STATE_SENSOR_ON_FLAG; |
| 3830 | if (DEBUG_HISTORY) Slog.v(TAG, "Stop sensor to: " |
| 3831 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3832 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3833 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3834 | getUidStatsLocked(uid).noteStopSensor(sensor, elapsedRealtime); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3835 | } |
| 3836 | |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3837 | int mGpsNesting; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3838 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3839 | public void noteStartGpsLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3840 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3841 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3842 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3843 | if (mGpsNesting == 0) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3844 | mHistoryCur.states |= HistoryItem.STATE_GPS_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3845 | if (DEBUG_HISTORY) Slog.v(TAG, "Start GPS to: " |
| 3846 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3847 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3848 | } |
| 3849 | mGpsNesting++; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3850 | getUidStatsLocked(uid).noteStartGps(elapsedRealtime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3851 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3852 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3853 | public void noteStopGpsLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3854 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3855 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3856 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3857 | mGpsNesting--; |
| 3858 | if (mGpsNesting == 0) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3859 | mHistoryCur.states &= ~HistoryItem.STATE_GPS_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3860 | if (DEBUG_HISTORY) Slog.v(TAG, "Stop GPS to: " |
| 3861 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3862 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3863 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3864 | getUidStatsLocked(uid).noteStopGps(elapsedRealtime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3865 | } |
Amith Yamasani | 3718aaa | 2009-06-09 06:32:35 -0700 | [diff] [blame] | 3866 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 3867 | public void noteScreenStateLocked(int state) { |
Amith Yamasani | 674c9bb | 2017-02-01 09:45:17 -0800 | [diff] [blame] | 3868 | state = mPretendScreenOff ? Display.STATE_OFF : state; |
Santos Cordon | e94f050 | 2017-02-24 12:31:20 -0800 | [diff] [blame] | 3869 | |
| 3870 | // Battery stats relies on there being 4 states. To accommodate this, new states beyond the |
| 3871 | // original 4 are mapped to one of the originals. |
| 3872 | if (state > MAX_TRACKED_SCREEN_STATE) { |
| 3873 | switch (state) { |
| 3874 | case Display.STATE_VR: |
| 3875 | state = Display.STATE_ON; |
| 3876 | break; |
| 3877 | default: |
| 3878 | Slog.wtf(TAG, "Unknown screen state (not mapped): " + state); |
| 3879 | break; |
| 3880 | } |
| 3881 | } |
| 3882 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 3883 | if (mScreenState != state) { |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 3884 | recordDailyStatsIfNeededLocked(true); |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 3885 | final int oldState = mScreenState; |
| 3886 | mScreenState = state; |
| 3887 | if (DEBUG) Slog.v(TAG, "Screen state: oldState=" + Display.stateToString(oldState) |
| 3888 | + ", newState=" + Display.stateToString(state)); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3889 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 3890 | if (state != Display.STATE_UNKNOWN) { |
| 3891 | int stepState = state-1; |
Santos Cordon | e94f050 | 2017-02-24 12:31:20 -0800 | [diff] [blame] | 3892 | if ((stepState & STEP_LEVEL_MODE_SCREEN_STATE) == stepState) { |
| 3893 | mModStepMode |= (mCurStepMode & STEP_LEVEL_MODE_SCREEN_STATE) ^ stepState; |
| 3894 | mCurStepMode = (mCurStepMode & ~STEP_LEVEL_MODE_SCREEN_STATE) | stepState; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 3895 | } else { |
| 3896 | Slog.wtf(TAG, "Unexpected screen state: " + state); |
| 3897 | } |
| 3898 | } |
| 3899 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 3900 | if (state == Display.STATE_ON) { |
| 3901 | // Screen turning on. |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3902 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3903 | final long uptime = mClocks.uptimeMillis(); |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 3904 | mHistoryCur.states |= HistoryItem.STATE_SCREEN_ON_FLAG; |
| 3905 | if (DEBUG_HISTORY) Slog.v(TAG, "Screen on to: " |
| 3906 | + Integer.toHexString(mHistoryCur.states)); |
| 3907 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 3908 | mScreenOnTimer.startRunningLocked(elapsedRealtime); |
| 3909 | if (mScreenBrightnessBin >= 0) { |
| 3910 | mScreenBrightnessTimer[mScreenBrightnessBin].startRunningLocked(elapsedRealtime); |
| 3911 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3912 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 3913 | updateTimeBasesLocked(mOnBatteryTimeBase.isRunning(), false, |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3914 | mClocks.uptimeMillis() * 1000, elapsedRealtime * 1000); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 3915 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 3916 | // Fake a wake lock, so we consider the device waked as long |
| 3917 | // as the screen is on. |
| 3918 | noteStartWakeLocked(-1, -1, "screen", null, WAKE_TYPE_PARTIAL, false, |
| 3919 | elapsedRealtime, uptime); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3920 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 3921 | // Update discharge amounts. |
| 3922 | if (mOnBatteryInternal) { |
| 3923 | updateDischargeScreenLevelsLocked(false, true); |
| 3924 | } |
| 3925 | } else if (oldState == Display.STATE_ON) { |
| 3926 | // Screen turning off or dozing. |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3927 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3928 | final long uptime = mClocks.uptimeMillis(); |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 3929 | mHistoryCur.states &= ~HistoryItem.STATE_SCREEN_ON_FLAG; |
| 3930 | if (DEBUG_HISTORY) Slog.v(TAG, "Screen off to: " |
| 3931 | + Integer.toHexString(mHistoryCur.states)); |
| 3932 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 3933 | mScreenOnTimer.stopRunningLocked(elapsedRealtime); |
| 3934 | if (mScreenBrightnessBin >= 0) { |
| 3935 | mScreenBrightnessTimer[mScreenBrightnessBin].stopRunningLocked(elapsedRealtime); |
| 3936 | } |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3937 | |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3938 | noteStopWakeLocked(-1, -1, "screen", "screen", WAKE_TYPE_PARTIAL, |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 3939 | elapsedRealtime, uptime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3940 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 3941 | updateTimeBasesLocked(mOnBatteryTimeBase.isRunning(), true, |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3942 | mClocks.uptimeMillis() * 1000, elapsedRealtime * 1000); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3943 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 3944 | // Update discharge amounts. |
| 3945 | if (mOnBatteryInternal) { |
| 3946 | updateDischargeScreenLevelsLocked(true, false); |
| 3947 | } |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 3948 | } |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3949 | } |
| 3950 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3951 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3952 | public void noteScreenBrightnessLocked(int brightness) { |
| 3953 | // Bin the brightness. |
| 3954 | int bin = brightness / (256/NUM_SCREEN_BRIGHTNESS_BINS); |
| 3955 | if (bin < 0) bin = 0; |
| 3956 | else if (bin >= NUM_SCREEN_BRIGHTNESS_BINS) bin = NUM_SCREEN_BRIGHTNESS_BINS-1; |
| 3957 | if (mScreenBrightnessBin != bin) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3958 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3959 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3960 | mHistoryCur.states = (mHistoryCur.states&~HistoryItem.STATE_BRIGHTNESS_MASK) |
| 3961 | | (bin << HistoryItem.STATE_BRIGHTNESS_SHIFT); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3962 | if (DEBUG_HISTORY) Slog.v(TAG, "Screen brightness " + bin + " to: " |
| 3963 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3964 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 3965 | if (mScreenState == Display.STATE_ON) { |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3966 | if (mScreenBrightnessBin >= 0) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3967 | mScreenBrightnessTimer[mScreenBrightnessBin].stopRunningLocked(elapsedRealtime); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3968 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3969 | mScreenBrightnessTimer[bin].startRunningLocked(elapsedRealtime); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3970 | } |
| 3971 | mScreenBrightnessBin = bin; |
| 3972 | } |
| 3973 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3974 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3975 | public void noteUserActivityLocked(int uid, int event) { |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 3976 | if (mOnBatteryInternal) { |
| 3977 | uid = mapUid(uid); |
| 3978 | getUidStatsLocked(uid).noteUserActivityLocked(event); |
| 3979 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3980 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3981 | |
Dianne Hackborn | 280a64e | 2015-07-13 14:48:08 -0700 | [diff] [blame] | 3982 | public void noteWakeUpLocked(String reason, int reasonUid) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3983 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3984 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 280a64e | 2015-07-13 14:48:08 -0700 | [diff] [blame] | 3985 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_SCREEN_WAKE_UP, |
| 3986 | reason, reasonUid); |
| 3987 | } |
| 3988 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 3989 | public void noteInteractiveLocked(boolean interactive) { |
| 3990 | if (mInteractive != interactive) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3991 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 3992 | mInteractive = interactive; |
| 3993 | if (DEBUG) Slog.v(TAG, "Interactive: " + interactive); |
| 3994 | if (interactive) { |
| 3995 | mInteractiveTimer.startRunningLocked(elapsedRealtime); |
| 3996 | } else { |
| 3997 | mInteractiveTimer.stopRunningLocked(elapsedRealtime); |
| 3998 | } |
| 3999 | } |
| 4000 | } |
| 4001 | |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 4002 | public void noteConnectivityChangedLocked(int type, String extra) { |
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 | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 4005 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_CONNECTIVITY_CHANGED, |
| 4006 | extra, type); |
| 4007 | mNumConnectivityChange++; |
| 4008 | } |
| 4009 | |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 4010 | private void noteMobileRadioApWakeupLocked(final long elapsedRealtimeMillis, |
| 4011 | final long uptimeMillis, int uid) { |
| 4012 | uid = mapUid(uid); |
| 4013 | addHistoryEventLocked(elapsedRealtimeMillis, uptimeMillis, HistoryItem.EVENT_WAKEUP_AP, "", |
| 4014 | uid); |
| 4015 | getUidStatsLocked(uid).noteMobileRadioApWakeupLocked(); |
| 4016 | } |
| 4017 | |
Ruchi Kandoi | fa97fcf | 2016-05-13 15:10:39 -0700 | [diff] [blame] | 4018 | public void noteMobileRadioPowerState(int powerState, long timestampNs, int uid) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4019 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4020 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 4021 | if (mMobileRadioPowerState != powerState) { |
| 4022 | long realElapsedRealtimeMs; |
| 4023 | final boolean active = |
| 4024 | powerState == DataConnectionRealTimeInfo.DC_POWER_STATE_MEDIUM |
| 4025 | || powerState == DataConnectionRealTimeInfo.DC_POWER_STATE_HIGH; |
| 4026 | if (active) { |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 4027 | if (uid > 0) { |
| 4028 | noteMobileRadioApWakeupLocked(elapsedRealtime, uptime, uid); |
| 4029 | } |
| 4030 | |
Adam Lesinski | 9acfd81 | 2016-04-19 18:29:50 -0700 | [diff] [blame] | 4031 | mMobileRadioActiveStartTime = realElapsedRealtimeMs = timestampNs / (1000 * 1000); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 4032 | mHistoryCur.states |= HistoryItem.STATE_MOBILE_RADIO_ACTIVE_FLAG; |
| 4033 | } else { |
| 4034 | realElapsedRealtimeMs = timestampNs / (1000*1000); |
Dianne Hackborn | f7097a5 | 2014-05-13 09:56:14 -0700 | [diff] [blame] | 4035 | long lastUpdateTimeMs = mMobileRadioActiveStartTime; |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 4036 | if (realElapsedRealtimeMs < lastUpdateTimeMs) { |
| 4037 | Slog.wtf(TAG, "Data connection inactive timestamp " + realElapsedRealtimeMs |
| 4038 | + " is before start time " + lastUpdateTimeMs); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 4039 | realElapsedRealtimeMs = elapsedRealtime; |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 4040 | } else if (realElapsedRealtimeMs < elapsedRealtime) { |
| 4041 | mMobileRadioActiveAdjustedTime.addCountLocked(elapsedRealtime |
| 4042 | - realElapsedRealtimeMs); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 4043 | } |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 4044 | mHistoryCur.states &= ~HistoryItem.STATE_MOBILE_RADIO_ACTIVE_FLAG; |
| 4045 | } |
| 4046 | if (DEBUG_HISTORY) Slog.v(TAG, "Mobile network active " + active + " to: " |
| 4047 | + Integer.toHexString(mHistoryCur.states)); |
| 4048 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 4049 | mMobileRadioPowerState = powerState; |
| 4050 | if (active) { |
| 4051 | mMobileRadioActiveTimer.startRunningLocked(elapsedRealtime); |
| 4052 | mMobileRadioActivePerAppTimer.startRunningLocked(elapsedRealtime); |
| 4053 | } else { |
| 4054 | mMobileRadioActiveTimer.stopRunningLocked(realElapsedRealtimeMs); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 4055 | updateMobileRadioStateLocked(realElapsedRealtimeMs, null); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 4056 | mMobileRadioActivePerAppTimer.stopRunningLocked(realElapsedRealtimeMs); |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 4057 | } |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 4058 | } |
| 4059 | } |
| 4060 | |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4061 | public void notePowerSaveMode(boolean enabled) { |
| 4062 | if (mPowerSaveModeEnabled != enabled) { |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 4063 | int stepState = enabled ? STEP_LEVEL_MODE_POWER_SAVE : 0; |
| 4064 | mModStepMode |= (mCurStepMode&STEP_LEVEL_MODE_POWER_SAVE) ^ stepState; |
| 4065 | mCurStepMode = (mCurStepMode&~STEP_LEVEL_MODE_POWER_SAVE) | stepState; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4066 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4067 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4068 | mPowerSaveModeEnabled = enabled; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 4069 | if (enabled) { |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4070 | mHistoryCur.states2 |= HistoryItem.STATE2_POWER_SAVE_FLAG; |
| 4071 | if (DEBUG_HISTORY) Slog.v(TAG, "Power save mode enabled to: " |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 4072 | + Integer.toHexString(mHistoryCur.states2)); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4073 | mPowerSaveModeEnabledTimer.startRunningLocked(elapsedRealtime); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 4074 | } else { |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4075 | mHistoryCur.states2 &= ~HistoryItem.STATE2_POWER_SAVE_FLAG; |
| 4076 | if (DEBUG_HISTORY) Slog.v(TAG, "Power save mode disabled to: " |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 4077 | + Integer.toHexString(mHistoryCur.states2)); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4078 | mPowerSaveModeEnabledTimer.stopRunningLocked(elapsedRealtime); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 4079 | } |
| 4080 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 4081 | } |
| 4082 | } |
| 4083 | |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4084 | public void noteDeviceIdleModeLocked(int mode, String activeReason, int activeUid) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4085 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4086 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 4087 | boolean nowIdling = mode == DEVICE_IDLE_MODE_DEEP; |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4088 | if (mDeviceIdling && !nowIdling && activeReason == null) { |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 4089 | // We don't go out of general idling mode until explicitly taken out of |
| 4090 | // device idle through going active or significant motion. |
| 4091 | nowIdling = true; |
| 4092 | } |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4093 | boolean nowLightIdling = mode == DEVICE_IDLE_MODE_LIGHT; |
| 4094 | if (mDeviceLightIdling && !nowLightIdling && !nowIdling && activeReason == null) { |
| 4095 | // We don't go out of general light idling mode until explicitly taken out of |
| 4096 | // device idle through going active or significant motion. |
| 4097 | nowLightIdling = true; |
| 4098 | } |
| 4099 | if (activeReason != null && (mDeviceIdling || mDeviceLightIdling)) { |
| 4100 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_ACTIVE, |
| 4101 | activeReason, activeUid); |
| 4102 | } |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 4103 | if (mDeviceIdling != nowIdling) { |
| 4104 | mDeviceIdling = nowIdling; |
| 4105 | int stepState = nowIdling ? STEP_LEVEL_MODE_DEVICE_IDLE : 0; |
| 4106 | mModStepMode |= (mCurStepMode&STEP_LEVEL_MODE_DEVICE_IDLE) ^ stepState; |
| 4107 | mCurStepMode = (mCurStepMode&~STEP_LEVEL_MODE_DEVICE_IDLE) | stepState; |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4108 | if (nowIdling) { |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 4109 | mDeviceIdlingTimer.startRunningLocked(elapsedRealtime); |
| 4110 | } else { |
| 4111 | mDeviceIdlingTimer.stopRunningLocked(elapsedRealtime); |
| 4112 | } |
| 4113 | } |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4114 | if (mDeviceLightIdling != nowLightIdling) { |
| 4115 | mDeviceLightIdling = nowLightIdling; |
| 4116 | if (nowLightIdling) { |
| 4117 | mDeviceLightIdlingTimer.startRunningLocked(elapsedRealtime); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4118 | } else { |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4119 | mDeviceLightIdlingTimer.stopRunningLocked(elapsedRealtime); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4120 | } |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4121 | } |
| 4122 | if (mDeviceIdleMode != mode) { |
| 4123 | mHistoryCur.states2 = (mHistoryCur.states2 & ~HistoryItem.STATE2_DEVICE_IDLE_MASK) |
| 4124 | | (mode << HistoryItem.STATE2_DEVICE_IDLE_SHIFT); |
| 4125 | if (DEBUG_HISTORY) Slog.v(TAG, "Device idle mode changed to: " |
| 4126 | + Integer.toHexString(mHistoryCur.states2)); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4127 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4128 | long lastDuration = elapsedRealtime - mLastIdleTimeStart; |
| 4129 | mLastIdleTimeStart = elapsedRealtime; |
| 4130 | if (mDeviceIdleMode == DEVICE_IDLE_MODE_LIGHT) { |
| 4131 | if (lastDuration > mLongestLightIdleTime) { |
| 4132 | mLongestLightIdleTime = lastDuration; |
| 4133 | } |
| 4134 | mDeviceIdleModeLightTimer.stopRunningLocked(elapsedRealtime); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 4135 | } else if (mDeviceIdleMode == DEVICE_IDLE_MODE_DEEP) { |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4136 | if (lastDuration > mLongestFullIdleTime) { |
| 4137 | mLongestFullIdleTime = lastDuration; |
| 4138 | } |
| 4139 | mDeviceIdleModeFullTimer.stopRunningLocked(elapsedRealtime); |
| 4140 | } |
| 4141 | if (mode == DEVICE_IDLE_MODE_LIGHT) { |
| 4142 | mDeviceIdleModeLightTimer.startRunningLocked(elapsedRealtime); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 4143 | } else if (mode == DEVICE_IDLE_MODE_DEEP) { |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4144 | mDeviceIdleModeFullTimer.startRunningLocked(elapsedRealtime); |
| 4145 | } |
| 4146 | mDeviceIdleMode = mode; |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4147 | } |
| 4148 | } |
| 4149 | |
| 4150 | public void notePackageInstalledLocked(String pkgName, int versionCode) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4151 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4152 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4153 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_PACKAGE_INSTALLED, |
| 4154 | pkgName, versionCode); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 4155 | PackageChange pc = new PackageChange(); |
| 4156 | pc.mPackageName = pkgName; |
| 4157 | pc.mUpdate = true; |
| 4158 | pc.mVersionCode = versionCode; |
| 4159 | addPackageChange(pc); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4160 | } |
| 4161 | |
| 4162 | public void notePackageUninstalledLocked(String pkgName) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4163 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4164 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4165 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_PACKAGE_UNINSTALLED, |
| 4166 | pkgName, 0); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 4167 | PackageChange pc = new PackageChange(); |
| 4168 | pc.mPackageName = pkgName; |
| 4169 | pc.mUpdate = true; |
| 4170 | addPackageChange(pc); |
| 4171 | } |
| 4172 | |
| 4173 | private void addPackageChange(PackageChange pc) { |
| 4174 | if (mDailyPackageChanges == null) { |
| 4175 | mDailyPackageChanges = new ArrayList<>(); |
| 4176 | } |
| 4177 | mDailyPackageChanges.add(pc); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4178 | } |
| 4179 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4180 | public void notePhoneOnLocked() { |
| 4181 | if (!mPhoneOn) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4182 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4183 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 4184 | mHistoryCur.states2 |= HistoryItem.STATE2_PHONE_IN_CALL_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4185 | if (DEBUG_HISTORY) Slog.v(TAG, "Phone on to: " |
| 4186 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 4187 | addHistoryRecordLocked(elapsedRealtime, uptime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4188 | mPhoneOn = true; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4189 | mPhoneOnTimer.startRunningLocked(elapsedRealtime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4190 | } |
| 4191 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4192 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4193 | public void notePhoneOffLocked() { |
| 4194 | if (mPhoneOn) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4195 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4196 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 4197 | mHistoryCur.states2 &= ~HistoryItem.STATE2_PHONE_IN_CALL_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4198 | if (DEBUG_HISTORY) Slog.v(TAG, "Phone off to: " |
| 4199 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 4200 | addHistoryRecordLocked(elapsedRealtime, uptime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4201 | mPhoneOn = false; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4202 | mPhoneOnTimer.stopRunningLocked(elapsedRealtime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4203 | } |
| 4204 | } |
Amith Yamasani | 32dbefd | 2009-06-19 09:21:17 -0700 | [diff] [blame] | 4205 | |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 4206 | void stopAllPhoneSignalStrengthTimersLocked(int except) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4207 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 4208 | for (int i = 0; i < SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 4209 | if (i == except) { |
| 4210 | continue; |
| 4211 | } |
| 4212 | while (mPhoneSignalStrengthsTimer[i].isRunningLocked()) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4213 | mPhoneSignalStrengthsTimer[i].stopRunningLocked(elapsedRealtime); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 4214 | } |
| 4215 | } |
| 4216 | } |
| 4217 | |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 4218 | private int fixPhoneServiceState(int state, int signalBin) { |
| 4219 | if (mPhoneSimStateRaw == TelephonyManager.SIM_STATE_ABSENT) { |
| 4220 | // In this case we will always be STATE_OUT_OF_SERVICE, so need |
| 4221 | // to infer that we are scanning from other data. |
| 4222 | if (state == ServiceState.STATE_OUT_OF_SERVICE |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 4223 | && signalBin > SignalStrength.SIGNAL_STRENGTH_NONE_OR_UNKNOWN) { |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 4224 | state = ServiceState.STATE_IN_SERVICE; |
| 4225 | } |
| 4226 | } |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 4227 | |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 4228 | return state; |
| 4229 | } |
| 4230 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4231 | private void updateAllPhoneStateLocked(int state, int simState, int strengthBin) { |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 4232 | boolean scanning = false; |
| 4233 | boolean newHistory = false; |
| 4234 | |
| 4235 | mPhoneServiceStateRaw = state; |
| 4236 | mPhoneSimStateRaw = simState; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4237 | mPhoneSignalStrengthBinRaw = strengthBin; |
| 4238 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4239 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4240 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 4241 | |
| 4242 | if (simState == TelephonyManager.SIM_STATE_ABSENT) { |
| 4243 | // In this case we will always be STATE_OUT_OF_SERVICE, so need |
| 4244 | // to infer that we are scanning from other data. |
| 4245 | if (state == ServiceState.STATE_OUT_OF_SERVICE |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4246 | && strengthBin > SignalStrength.SIGNAL_STRENGTH_NONE_OR_UNKNOWN) { |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 4247 | state = ServiceState.STATE_IN_SERVICE; |
| 4248 | } |
| 4249 | } |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 4250 | |
| 4251 | // If the phone is powered off, stop all timers. |
| 4252 | if (state == ServiceState.STATE_POWER_OFF) { |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4253 | strengthBin = -1; |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 4254 | |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 4255 | // If we are in service, make sure the correct signal string timer is running. |
| 4256 | } else if (state == ServiceState.STATE_IN_SERVICE) { |
| 4257 | // Bin will be changed below. |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 4258 | |
| 4259 | // If we're out of service, we are in the lowest signal strength |
| 4260 | // bin and have the scanning bit set. |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 4261 | } else if (state == ServiceState.STATE_OUT_OF_SERVICE) { |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 4262 | scanning = true; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4263 | strengthBin = SignalStrength.SIGNAL_STRENGTH_NONE_OR_UNKNOWN; |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 4264 | if (!mPhoneSignalScanningTimer.isRunningLocked()) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4265 | mHistoryCur.states |= HistoryItem.STATE_PHONE_SCANNING_FLAG; |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 4266 | newHistory = true; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4267 | if (DEBUG_HISTORY) Slog.v(TAG, "Phone started scanning to: " |
| 4268 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4269 | mPhoneSignalScanningTimer.startRunningLocked(elapsedRealtime); |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 4270 | } |
| 4271 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4272 | |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 4273 | if (!scanning) { |
| 4274 | // If we are no longer scanning, then stop the scanning timer. |
| 4275 | if (mPhoneSignalScanningTimer.isRunningLocked()) { |
| 4276 | mHistoryCur.states &= ~HistoryItem.STATE_PHONE_SCANNING_FLAG; |
| 4277 | if (DEBUG_HISTORY) Slog.v(TAG, "Phone stopped scanning to: " |
| 4278 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 4279 | newHistory = true; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4280 | mPhoneSignalScanningTimer.stopRunningLocked(elapsedRealtime); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 4281 | } |
| 4282 | } |
| 4283 | |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4284 | if (mPhoneServiceState != state) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4285 | mHistoryCur.states = (mHistoryCur.states&~HistoryItem.STATE_PHONE_STATE_MASK) |
| 4286 | | (state << HistoryItem.STATE_PHONE_STATE_SHIFT); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 4287 | if (DEBUG_HISTORY) Slog.v(TAG, "Phone state " + state + " to: " |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4288 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 4289 | newHistory = true; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4290 | mPhoneServiceState = state; |
| 4291 | } |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 4292 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4293 | if (mPhoneSignalStrengthBin != strengthBin) { |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 4294 | if (mPhoneSignalStrengthBin >= 0) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4295 | mPhoneSignalStrengthsTimer[mPhoneSignalStrengthBin].stopRunningLocked( |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4296 | elapsedRealtime); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 4297 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4298 | if (strengthBin >= 0) { |
| 4299 | if (!mPhoneSignalStrengthsTimer[strengthBin].isRunningLocked()) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4300 | mPhoneSignalStrengthsTimer[strengthBin].startRunningLocked(elapsedRealtime); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 4301 | } |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 4302 | mHistoryCur.states = (mHistoryCur.states&~HistoryItem.STATE_PHONE_SIGNAL_STRENGTH_MASK) |
| 4303 | | (strengthBin << HistoryItem.STATE_PHONE_SIGNAL_STRENGTH_SHIFT); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4304 | if (DEBUG_HISTORY) Slog.v(TAG, "Signal strength " + strengthBin + " to: " |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 4305 | + Integer.toHexString(mHistoryCur.states)); |
| 4306 | newHistory = true; |
| 4307 | } else { |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 4308 | stopAllPhoneSignalStrengthTimersLocked(-1); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 4309 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4310 | mPhoneSignalStrengthBin = strengthBin; |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 4311 | } |
| 4312 | |
| 4313 | if (newHistory) { |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 4314 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 4315 | } |
| 4316 | } |
| 4317 | |
| 4318 | /** |
| 4319 | * Telephony stack updates the phone state. |
| 4320 | * @param state phone state from ServiceState.getState() |
| 4321 | */ |
| 4322 | public void notePhoneStateLocked(int state, int simState) { |
| 4323 | updateAllPhoneStateLocked(state, simState, mPhoneSignalStrengthBinRaw); |
Amith Yamasani | 32dbefd | 2009-06-19 09:21:17 -0700 | [diff] [blame] | 4324 | } |
| 4325 | |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 4326 | public void notePhoneSignalStrengthLocked(SignalStrength signalStrength) { |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4327 | // Bin the strength. |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 4328 | int bin = signalStrength.getLevel(); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 4329 | updateAllPhoneStateLocked(mPhoneServiceStateRaw, mPhoneSimStateRaw, bin); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4330 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4331 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4332 | public void notePhoneDataConnectionStateLocked(int dataType, boolean hasData) { |
| 4333 | int bin = DATA_CONNECTION_NONE; |
| 4334 | if (hasData) { |
| 4335 | switch (dataType) { |
| 4336 | case TelephonyManager.NETWORK_TYPE_EDGE: |
| 4337 | bin = DATA_CONNECTION_EDGE; |
| 4338 | break; |
| 4339 | case TelephonyManager.NETWORK_TYPE_GPRS: |
| 4340 | bin = DATA_CONNECTION_GPRS; |
| 4341 | break; |
| 4342 | case TelephonyManager.NETWORK_TYPE_UMTS: |
| 4343 | bin = DATA_CONNECTION_UMTS; |
| 4344 | break; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4345 | case TelephonyManager.NETWORK_TYPE_CDMA: |
| 4346 | bin = DATA_CONNECTION_CDMA; |
| 4347 | break; |
| 4348 | case TelephonyManager.NETWORK_TYPE_EVDO_0: |
| 4349 | bin = DATA_CONNECTION_EVDO_0; |
| 4350 | break; |
| 4351 | case TelephonyManager.NETWORK_TYPE_EVDO_A: |
| 4352 | bin = DATA_CONNECTION_EVDO_A; |
| 4353 | break; |
| 4354 | case TelephonyManager.NETWORK_TYPE_1xRTT: |
| 4355 | bin = DATA_CONNECTION_1xRTT; |
| 4356 | break; |
| 4357 | case TelephonyManager.NETWORK_TYPE_HSDPA: |
| 4358 | bin = DATA_CONNECTION_HSDPA; |
| 4359 | break; |
| 4360 | case TelephonyManager.NETWORK_TYPE_HSUPA: |
| 4361 | bin = DATA_CONNECTION_HSUPA; |
| 4362 | break; |
| 4363 | case TelephonyManager.NETWORK_TYPE_HSPA: |
| 4364 | bin = DATA_CONNECTION_HSPA; |
| 4365 | break; |
| 4366 | case TelephonyManager.NETWORK_TYPE_IDEN: |
| 4367 | bin = DATA_CONNECTION_IDEN; |
| 4368 | break; |
| 4369 | case TelephonyManager.NETWORK_TYPE_EVDO_B: |
| 4370 | bin = DATA_CONNECTION_EVDO_B; |
| 4371 | break; |
Robert Greenwalt | 962a990 | 2010-11-02 11:10:25 -0700 | [diff] [blame] | 4372 | case TelephonyManager.NETWORK_TYPE_LTE: |
| 4373 | bin = DATA_CONNECTION_LTE; |
| 4374 | break; |
| 4375 | case TelephonyManager.NETWORK_TYPE_EHRPD: |
| 4376 | bin = DATA_CONNECTION_EHRPD; |
| 4377 | break; |
Patrick Tjin | b71703c | 2013-11-06 09:27:03 -0800 | [diff] [blame] | 4378 | case TelephonyManager.NETWORK_TYPE_HSPAP: |
| 4379 | bin = DATA_CONNECTION_HSPAP; |
| 4380 | break; |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4381 | default: |
| 4382 | bin = DATA_CONNECTION_OTHER; |
| 4383 | break; |
| 4384 | } |
| 4385 | } |
Amith Yamasani | 3718aaa | 2009-06-09 06:32:35 -0700 | [diff] [blame] | 4386 | if (DEBUG) Log.i(TAG, "Phone Data Connection -> " + dataType + " = " + hasData); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4387 | if (mPhoneDataConnectionType != bin) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4388 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4389 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4390 | mHistoryCur.states = (mHistoryCur.states&~HistoryItem.STATE_DATA_CONNECTION_MASK) |
| 4391 | | (bin << HistoryItem.STATE_DATA_CONNECTION_SHIFT); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4392 | if (DEBUG_HISTORY) Slog.v(TAG, "Data connection " + bin + " to: " |
| 4393 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 4394 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4395 | if (mPhoneDataConnectionType >= 0) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4396 | mPhoneDataConnectionsTimer[mPhoneDataConnectionType].stopRunningLocked( |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4397 | elapsedRealtime); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4398 | } |
| 4399 | mPhoneDataConnectionType = bin; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4400 | mPhoneDataConnectionsTimer[bin].startRunningLocked(elapsedRealtime); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4401 | } |
| 4402 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4403 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 4404 | public void noteWifiOnLocked() { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4405 | if (!mWifiOn) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4406 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4407 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 4408 | mHistoryCur.states2 |= HistoryItem.STATE2_WIFI_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4409 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI on to: " |
| 4410 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 4411 | addHistoryRecordLocked(elapsedRealtime, uptime); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4412 | mWifiOn = true; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4413 | mWifiOnTimer.startRunningLocked(elapsedRealtime); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 4414 | scheduleSyncExternalStatsLocked("wifi-off", ExternalStatsSync.UPDATE_WIFI); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4415 | } |
| 4416 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4417 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 4418 | public void noteWifiOffLocked() { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4419 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4420 | final long uptime = mClocks.uptimeMillis(); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4421 | if (mWifiOn) { |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 4422 | mHistoryCur.states2 &= ~HistoryItem.STATE2_WIFI_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4423 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI off to: " |
| 4424 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 4425 | addHistoryRecordLocked(elapsedRealtime, uptime); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4426 | mWifiOn = false; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4427 | mWifiOnTimer.stopRunningLocked(elapsedRealtime); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 4428 | scheduleSyncExternalStatsLocked("wifi-on", ExternalStatsSync.UPDATE_WIFI); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4429 | } |
| 4430 | } |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 4431 | |
| 4432 | public void noteAudioOnLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4433 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4434 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4435 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 4436 | if (mAudioOnNesting == 0) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4437 | mHistoryCur.states |= HistoryItem.STATE_AUDIO_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4438 | if (DEBUG_HISTORY) Slog.v(TAG, "Audio on to: " |
| 4439 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 4440 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4441 | mAudioOnTimer.startRunningLocked(elapsedRealtime); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 4442 | } |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 4443 | mAudioOnNesting++; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4444 | getUidStatsLocked(uid).noteAudioTurnedOnLocked(elapsedRealtime); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 4445 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4446 | |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 4447 | public void noteAudioOffLocked(int uid) { |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 4448 | if (mAudioOnNesting == 0) { |
| 4449 | return; |
| 4450 | } |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4451 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4452 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4453 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 4454 | if (--mAudioOnNesting == 0) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4455 | mHistoryCur.states &= ~HistoryItem.STATE_AUDIO_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4456 | if (DEBUG_HISTORY) Slog.v(TAG, "Audio off to: " |
| 4457 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 4458 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4459 | mAudioOnTimer.stopRunningLocked(elapsedRealtime); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 4460 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4461 | getUidStatsLocked(uid).noteAudioTurnedOffLocked(elapsedRealtime); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 4462 | } |
| 4463 | |
| 4464 | public void noteVideoOnLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4465 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4466 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4467 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 4468 | if (mVideoOnNesting == 0) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 4469 | mHistoryCur.states2 |= HistoryItem.STATE2_VIDEO_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4470 | if (DEBUG_HISTORY) Slog.v(TAG, "Video on to: " |
| 4471 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 4472 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4473 | mVideoOnTimer.startRunningLocked(elapsedRealtime); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 4474 | } |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 4475 | mVideoOnNesting++; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4476 | getUidStatsLocked(uid).noteVideoTurnedOnLocked(elapsedRealtime); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 4477 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4478 | |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 4479 | public void noteVideoOffLocked(int uid) { |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 4480 | if (mVideoOnNesting == 0) { |
| 4481 | return; |
| 4482 | } |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4483 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4484 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4485 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 4486 | if (--mVideoOnNesting == 0) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 4487 | mHistoryCur.states2 &= ~HistoryItem.STATE2_VIDEO_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4488 | if (DEBUG_HISTORY) Slog.v(TAG, "Video off to: " |
| 4489 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 4490 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4491 | mVideoOnTimer.stopRunningLocked(elapsedRealtime); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 4492 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4493 | getUidStatsLocked(uid).noteVideoTurnedOffLocked(elapsedRealtime); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 4494 | } |
| 4495 | |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 4496 | public void noteResetAudioLocked() { |
| 4497 | if (mAudioOnNesting > 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4498 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4499 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 4500 | mAudioOnNesting = 0; |
| 4501 | mHistoryCur.states &= ~HistoryItem.STATE_AUDIO_ON_FLAG; |
| 4502 | if (DEBUG_HISTORY) Slog.v(TAG, "Audio off to: " |
| 4503 | + Integer.toHexString(mHistoryCur.states)); |
| 4504 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 4505 | mAudioOnTimer.stopAllRunningLocked(elapsedRealtime); |
| 4506 | for (int i=0; i<mUidStats.size(); i++) { |
| 4507 | BatteryStatsImpl.Uid uid = mUidStats.valueAt(i); |
| 4508 | uid.noteResetAudioLocked(elapsedRealtime); |
| 4509 | } |
| 4510 | } |
| 4511 | } |
| 4512 | |
| 4513 | public void noteResetVideoLocked() { |
| 4514 | if (mVideoOnNesting > 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4515 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4516 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 4517 | mAudioOnNesting = 0; |
| 4518 | mHistoryCur.states2 &= ~HistoryItem.STATE2_VIDEO_ON_FLAG; |
| 4519 | if (DEBUG_HISTORY) Slog.v(TAG, "Video off to: " |
| 4520 | + Integer.toHexString(mHistoryCur.states)); |
| 4521 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 4522 | mVideoOnTimer.stopAllRunningLocked(elapsedRealtime); |
| 4523 | for (int i=0; i<mUidStats.size(); i++) { |
| 4524 | BatteryStatsImpl.Uid uid = mUidStats.valueAt(i); |
| 4525 | uid.noteResetVideoLocked(elapsedRealtime); |
| 4526 | } |
| 4527 | } |
| 4528 | } |
| 4529 | |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 4530 | public void noteActivityResumedLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4531 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4532 | getUidStatsLocked(uid).noteActivityResumedLocked(mClocks.elapsedRealtime()); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 4533 | } |
| 4534 | |
| 4535 | public void noteActivityPausedLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4536 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4537 | getUidStatsLocked(uid).noteActivityPausedLocked(mClocks.elapsedRealtime()); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 4538 | } |
| 4539 | |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 4540 | public void noteVibratorOnLocked(int uid, long durationMillis) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4541 | uid = mapUid(uid); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 4542 | getUidStatsLocked(uid).noteVibratorOnLocked(durationMillis); |
| 4543 | } |
| 4544 | |
| 4545 | public void noteVibratorOffLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4546 | uid = mapUid(uid); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 4547 | getUidStatsLocked(uid).noteVibratorOffLocked(); |
| 4548 | } |
| 4549 | |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 4550 | public void noteFlashlightOnLocked(int uid) { |
| 4551 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4552 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4553 | final long uptime = mClocks.uptimeMillis(); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 4554 | if (mFlashlightOnNesting++ == 0) { |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 4555 | mHistoryCur.states2 |= HistoryItem.STATE2_FLASHLIGHT_FLAG; |
| 4556 | if (DEBUG_HISTORY) Slog.v(TAG, "Flashlight on to: " |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 4557 | + Integer.toHexString(mHistoryCur.states2)); |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 4558 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 4559 | mFlashlightOnTimer.startRunningLocked(elapsedRealtime); |
| 4560 | } |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 4561 | getUidStatsLocked(uid).noteFlashlightTurnedOnLocked(elapsedRealtime); |
| 4562 | } |
| 4563 | |
| 4564 | public void noteFlashlightOffLocked(int uid) { |
| 4565 | if (mFlashlightOnNesting == 0) { |
| 4566 | return; |
| 4567 | } |
| 4568 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4569 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4570 | final long uptime = mClocks.uptimeMillis(); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 4571 | if (--mFlashlightOnNesting == 0) { |
| 4572 | mHistoryCur.states2 &= ~HistoryItem.STATE2_FLASHLIGHT_FLAG; |
| 4573 | if (DEBUG_HISTORY) Slog.v(TAG, "Flashlight off to: " |
| 4574 | + Integer.toHexString(mHistoryCur.states2)); |
| 4575 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 4576 | mFlashlightOnTimer.stopRunningLocked(elapsedRealtime); |
| 4577 | } |
| 4578 | getUidStatsLocked(uid).noteFlashlightTurnedOffLocked(elapsedRealtime); |
| 4579 | } |
| 4580 | |
| 4581 | public void noteCameraOnLocked(int uid) { |
| 4582 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4583 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4584 | final long uptime = mClocks.uptimeMillis(); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 4585 | if (mCameraOnNesting++ == 0) { |
| 4586 | mHistoryCur.states2 |= HistoryItem.STATE2_CAMERA_FLAG; |
| 4587 | if (DEBUG_HISTORY) Slog.v(TAG, "Camera on to: " |
| 4588 | + Integer.toHexString(mHistoryCur.states2)); |
| 4589 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 4590 | mCameraOnTimer.startRunningLocked(elapsedRealtime); |
| 4591 | } |
| 4592 | getUidStatsLocked(uid).noteCameraTurnedOnLocked(elapsedRealtime); |
| 4593 | } |
| 4594 | |
| 4595 | public void noteCameraOffLocked(int uid) { |
| 4596 | if (mCameraOnNesting == 0) { |
| 4597 | return; |
| 4598 | } |
| 4599 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4600 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4601 | final long uptime = mClocks.uptimeMillis(); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 4602 | if (--mCameraOnNesting == 0) { |
| 4603 | mHistoryCur.states2 &= ~HistoryItem.STATE2_CAMERA_FLAG; |
| 4604 | if (DEBUG_HISTORY) Slog.v(TAG, "Camera off to: " |
| 4605 | + Integer.toHexString(mHistoryCur.states2)); |
| 4606 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 4607 | mCameraOnTimer.stopRunningLocked(elapsedRealtime); |
| 4608 | } |
| 4609 | getUidStatsLocked(uid).noteCameraTurnedOffLocked(elapsedRealtime); |
| 4610 | } |
| 4611 | |
| 4612 | public void noteResetCameraLocked() { |
| 4613 | if (mCameraOnNesting > 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4614 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4615 | final long uptime = mClocks.uptimeMillis(); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 4616 | mCameraOnNesting = 0; |
| 4617 | mHistoryCur.states2 &= ~HistoryItem.STATE2_CAMERA_FLAG; |
| 4618 | if (DEBUG_HISTORY) Slog.v(TAG, "Camera off to: " |
| 4619 | + Integer.toHexString(mHistoryCur.states2)); |
| 4620 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 4621 | mCameraOnTimer.stopAllRunningLocked(elapsedRealtime); |
| 4622 | for (int i=0; i<mUidStats.size(); i++) { |
| 4623 | BatteryStatsImpl.Uid uid = mUidStats.valueAt(i); |
| 4624 | uid.noteResetCameraLocked(elapsedRealtime); |
| 4625 | } |
| 4626 | } |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 4627 | } |
| 4628 | |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 4629 | public void noteResetFlashlightLocked() { |
| 4630 | if (mFlashlightOnNesting > 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4631 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4632 | final long uptime = mClocks.uptimeMillis(); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 4633 | mFlashlightOnNesting = 0; |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 4634 | mHistoryCur.states2 &= ~HistoryItem.STATE2_FLASHLIGHT_FLAG; |
| 4635 | if (DEBUG_HISTORY) Slog.v(TAG, "Flashlight off to: " |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 4636 | + Integer.toHexString(mHistoryCur.states2)); |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 4637 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 4638 | mFlashlightOnTimer.stopAllRunningLocked(elapsedRealtime); |
| 4639 | for (int i=0; i<mUidStats.size(); i++) { |
| 4640 | BatteryStatsImpl.Uid uid = mUidStats.valueAt(i); |
| 4641 | uid.noteResetFlashlightLocked(elapsedRealtime); |
| 4642 | } |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 4643 | } |
| 4644 | } |
| 4645 | |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 4646 | private void noteBluetoothScanStartedLocked(int uid) { |
| 4647 | uid = mapUid(uid); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 4648 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4649 | final long uptime = mClocks.uptimeMillis(); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 4650 | if (mBluetoothScanNesting == 0) { |
| 4651 | mHistoryCur.states2 |= HistoryItem.STATE2_BLUETOOTH_SCAN_FLAG; |
| 4652 | if (DEBUG_HISTORY) Slog.v(TAG, "BLE scan started for: " |
| 4653 | + Integer.toHexString(mHistoryCur.states2)); |
| 4654 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Adam Lesinski | d9b99be | 2016-03-30 16:58:51 -0700 | [diff] [blame] | 4655 | mBluetoothScanTimer.startRunningLocked(elapsedRealtime); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 4656 | } |
| 4657 | mBluetoothScanNesting++; |
| 4658 | getUidStatsLocked(uid).noteBluetoothScanStartedLocked(elapsedRealtime); |
| 4659 | } |
| 4660 | |
| 4661 | public void noteBluetoothScanStartedFromSourceLocked(WorkSource ws) { |
| 4662 | final int N = ws.size(); |
| 4663 | for (int i = 0; i < N; i++) { |
| 4664 | noteBluetoothScanStartedLocked(ws.get(i)); |
| 4665 | } |
| 4666 | } |
| 4667 | |
| 4668 | private void noteBluetoothScanStoppedLocked(int uid) { |
| 4669 | uid = mapUid(uid); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 4670 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4671 | final long uptime = mClocks.uptimeMillis(); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 4672 | mBluetoothScanNesting--; |
| 4673 | if (mBluetoothScanNesting == 0) { |
| 4674 | mHistoryCur.states2 &= ~HistoryItem.STATE2_BLUETOOTH_SCAN_FLAG; |
| 4675 | if (DEBUG_HISTORY) Slog.v(TAG, "BLE scan stopped for: " |
| 4676 | + Integer.toHexString(mHistoryCur.states2)); |
| 4677 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Adam Lesinski | d9b99be | 2016-03-30 16:58:51 -0700 | [diff] [blame] | 4678 | mBluetoothScanTimer.stopRunningLocked(elapsedRealtime); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 4679 | } |
| 4680 | getUidStatsLocked(uid).noteBluetoothScanStoppedLocked(elapsedRealtime); |
| 4681 | } |
| 4682 | |
| 4683 | public void noteBluetoothScanStoppedFromSourceLocked(WorkSource ws) { |
| 4684 | final int N = ws.size(); |
| 4685 | for (int i = 0; i < N; i++) { |
| 4686 | noteBluetoothScanStoppedLocked(ws.get(i)); |
| 4687 | } |
| 4688 | } |
| 4689 | |
| 4690 | public void noteResetBluetoothScanLocked() { |
| 4691 | if (mBluetoothScanNesting > 0) { |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 4692 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4693 | final long uptime = mClocks.uptimeMillis(); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 4694 | mBluetoothScanNesting = 0; |
| 4695 | mHistoryCur.states2 &= ~HistoryItem.STATE2_BLUETOOTH_SCAN_FLAG; |
| 4696 | if (DEBUG_HISTORY) Slog.v(TAG, "BLE can stopped for: " |
| 4697 | + Integer.toHexString(mHistoryCur.states2)); |
| 4698 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 4699 | mBluetoothScanTimer.stopAllRunningLocked(elapsedRealtime); |
| 4700 | for (int i=0; i<mUidStats.size(); i++) { |
| 4701 | BatteryStatsImpl.Uid uid = mUidStats.valueAt(i); |
| 4702 | uid.noteResetBluetoothScanLocked(elapsedRealtime); |
| 4703 | } |
| 4704 | } |
| 4705 | } |
| 4706 | |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 4707 | private void noteWifiRadioApWakeupLocked(final long elapsedRealtimeMillis, |
| 4708 | final long uptimeMillis, int uid) { |
| 4709 | uid = mapUid(uid); |
| 4710 | addHistoryEventLocked(elapsedRealtimeMillis, uptimeMillis, HistoryItem.EVENT_WAKEUP_AP, "", |
| 4711 | uid); |
| 4712 | getUidStatsLocked(uid).noteWifiRadioApWakeupLocked(); |
| 4713 | } |
| 4714 | |
| 4715 | public void noteWifiRadioPowerState(int powerState, long timestampNs, int uid) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4716 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4717 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 4718 | if (mWifiRadioPowerState != powerState) { |
| 4719 | final boolean active = |
| 4720 | powerState == DataConnectionRealTimeInfo.DC_POWER_STATE_MEDIUM |
| 4721 | || powerState == DataConnectionRealTimeInfo.DC_POWER_STATE_HIGH; |
| 4722 | if (active) { |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 4723 | if (uid > 0) { |
| 4724 | noteWifiRadioApWakeupLocked(elapsedRealtime, uptime, uid); |
| 4725 | } |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 4726 | mHistoryCur.states |= HistoryItem.STATE_WIFI_RADIO_ACTIVE_FLAG; |
| 4727 | } else { |
| 4728 | mHistoryCur.states &= ~HistoryItem.STATE_WIFI_RADIO_ACTIVE_FLAG; |
| 4729 | } |
| 4730 | if (DEBUG_HISTORY) Slog.v(TAG, "Wifi network active " + active + " to: " |
| 4731 | + Integer.toHexString(mHistoryCur.states)); |
| 4732 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 4733 | mWifiRadioPowerState = powerState; |
| 4734 | } |
| 4735 | } |
| 4736 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 4737 | public void noteWifiRunningLocked(WorkSource ws) { |
| 4738 | if (!mGlobalWifiRunning) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4739 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4740 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 4741 | mHistoryCur.states2 |= HistoryItem.STATE2_WIFI_RUNNING_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4742 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI running to: " |
| 4743 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 4744 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 4745 | mGlobalWifiRunning = true; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4746 | mGlobalWifiRunningTimer.startRunningLocked(elapsedRealtime); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 4747 | int N = ws.size(); |
| 4748 | for (int i=0; i<N; i++) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4749 | int uid = mapUid(ws.get(i)); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4750 | getUidStatsLocked(uid).noteWifiRunningLocked(elapsedRealtime); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 4751 | } |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 4752 | scheduleSyncExternalStatsLocked("wifi-running", ExternalStatsSync.UPDATE_WIFI); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 4753 | } else { |
| 4754 | Log.w(TAG, "noteWifiRunningLocked -- called while WIFI running"); |
Eric Shienbrood | d4c5f89 | 2009-03-24 18:13:20 -0700 | [diff] [blame] | 4755 | } |
| 4756 | } |
| 4757 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 4758 | public void noteWifiRunningChangedLocked(WorkSource oldWs, WorkSource newWs) { |
| 4759 | if (mGlobalWifiRunning) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4760 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 4761 | int N = oldWs.size(); |
| 4762 | for (int i=0; i<N; i++) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4763 | int uid = mapUid(oldWs.get(i)); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4764 | getUidStatsLocked(uid).noteWifiStoppedLocked(elapsedRealtime); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 4765 | } |
| 4766 | N = newWs.size(); |
| 4767 | for (int i=0; i<N; i++) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4768 | int uid = mapUid(newWs.get(i)); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4769 | getUidStatsLocked(uid).noteWifiRunningLocked(elapsedRealtime); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 4770 | } |
| 4771 | } else { |
| 4772 | Log.w(TAG, "noteWifiRunningChangedLocked -- called while WIFI not running"); |
| 4773 | } |
| 4774 | } |
| 4775 | |
| 4776 | public void noteWifiStoppedLocked(WorkSource ws) { |
| 4777 | if (mGlobalWifiRunning) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4778 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4779 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 4780 | mHistoryCur.states2 &= ~HistoryItem.STATE2_WIFI_RUNNING_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4781 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI stopped to: " |
| 4782 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 4783 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 4784 | mGlobalWifiRunning = false; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4785 | mGlobalWifiRunningTimer.stopRunningLocked(elapsedRealtime); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 4786 | int N = ws.size(); |
| 4787 | for (int i=0; i<N; i++) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4788 | int uid = mapUid(ws.get(i)); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4789 | getUidStatsLocked(uid).noteWifiStoppedLocked(elapsedRealtime); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 4790 | } |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 4791 | scheduleSyncExternalStatsLocked("wifi-stopped", ExternalStatsSync.UPDATE_WIFI); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 4792 | } else { |
| 4793 | Log.w(TAG, "noteWifiStoppedLocked -- called while WIFI not running"); |
Eric Shienbrood | d4c5f89 | 2009-03-24 18:13:20 -0700 | [diff] [blame] | 4794 | } |
| 4795 | } |
| 4796 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4797 | public void noteWifiStateLocked(int wifiState, String accessPoint) { |
| 4798 | if (DEBUG) Log.i(TAG, "WiFi state -> " + wifiState); |
| 4799 | if (mWifiState != wifiState) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4800 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4801 | if (mWifiState >= 0) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4802 | mWifiStateTimer[mWifiState].stopRunningLocked(elapsedRealtime); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4803 | } |
| 4804 | mWifiState = wifiState; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4805 | mWifiStateTimer[wifiState].startRunningLocked(elapsedRealtime); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 4806 | scheduleSyncExternalStatsLocked("wifi-state", ExternalStatsSync.UPDATE_WIFI); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4807 | } |
| 4808 | } |
| 4809 | |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 4810 | public void noteWifiSupplicantStateChangedLocked(int supplState, boolean failedAuth) { |
| 4811 | if (DEBUG) Log.i(TAG, "WiFi suppl state -> " + supplState); |
| 4812 | if (mWifiSupplState != supplState) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4813 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4814 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 4815 | if (mWifiSupplState >= 0) { |
| 4816 | mWifiSupplStateTimer[mWifiSupplState].stopRunningLocked(elapsedRealtime); |
| 4817 | } |
| 4818 | mWifiSupplState = supplState; |
| 4819 | mWifiSupplStateTimer[supplState].startRunningLocked(elapsedRealtime); |
| 4820 | mHistoryCur.states2 = |
| 4821 | (mHistoryCur.states2&~HistoryItem.STATE2_WIFI_SUPPL_STATE_MASK) |
| 4822 | | (supplState << HistoryItem.STATE2_WIFI_SUPPL_STATE_SHIFT); |
| 4823 | if (DEBUG_HISTORY) Slog.v(TAG, "Wifi suppl state " + supplState + " to: " |
| 4824 | + Integer.toHexString(mHistoryCur.states2)); |
| 4825 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 4826 | } |
| 4827 | } |
| 4828 | |
| 4829 | void stopAllWifiSignalStrengthTimersLocked(int except) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4830 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 4831 | for (int i = 0; i < NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 4832 | if (i == except) { |
| 4833 | continue; |
| 4834 | } |
| 4835 | while (mWifiSignalStrengthsTimer[i].isRunningLocked()) { |
| 4836 | mWifiSignalStrengthsTimer[i].stopRunningLocked(elapsedRealtime); |
| 4837 | } |
| 4838 | } |
| 4839 | } |
| 4840 | |
| 4841 | public void noteWifiRssiChangedLocked(int newRssi) { |
| 4842 | int strengthBin = WifiManager.calculateSignalLevel(newRssi, NUM_WIFI_SIGNAL_STRENGTH_BINS); |
| 4843 | if (DEBUG) Log.i(TAG, "WiFi rssi -> " + newRssi + " bin=" + strengthBin); |
| 4844 | if (mWifiSignalStrengthBin != strengthBin) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4845 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4846 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 4847 | if (mWifiSignalStrengthBin >= 0) { |
| 4848 | mWifiSignalStrengthsTimer[mWifiSignalStrengthBin].stopRunningLocked( |
| 4849 | elapsedRealtime); |
| 4850 | } |
| 4851 | if (strengthBin >= 0) { |
| 4852 | if (!mWifiSignalStrengthsTimer[strengthBin].isRunningLocked()) { |
| 4853 | mWifiSignalStrengthsTimer[strengthBin].startRunningLocked(elapsedRealtime); |
| 4854 | } |
| 4855 | mHistoryCur.states2 = |
| 4856 | (mHistoryCur.states2&~HistoryItem.STATE2_WIFI_SIGNAL_STRENGTH_MASK) |
| 4857 | | (strengthBin << HistoryItem.STATE2_WIFI_SIGNAL_STRENGTH_SHIFT); |
| 4858 | if (DEBUG_HISTORY) Slog.v(TAG, "Wifi signal strength " + strengthBin + " to: " |
| 4859 | + Integer.toHexString(mHistoryCur.states2)); |
| 4860 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 4861 | } else { |
| 4862 | stopAllWifiSignalStrengthTimersLocked(-1); |
| 4863 | } |
| 4864 | mWifiSignalStrengthBin = strengthBin; |
| 4865 | } |
| 4866 | } |
| 4867 | |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4868 | int mWifiFullLockNesting = 0; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4869 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4870 | public void noteFullWifiLockAcquiredLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4871 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4872 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4873 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4874 | if (mWifiFullLockNesting == 0) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4875 | mHistoryCur.states |= HistoryItem.STATE_WIFI_FULL_LOCK_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4876 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI full lock on to: " |
| 4877 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 4878 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4879 | } |
| 4880 | mWifiFullLockNesting++; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4881 | getUidStatsLocked(uid).noteFullWifiLockAcquiredLocked(elapsedRealtime); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4882 | } |
| 4883 | |
| 4884 | public void noteFullWifiLockReleasedLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4885 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4886 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4887 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4888 | mWifiFullLockNesting--; |
| 4889 | if (mWifiFullLockNesting == 0) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4890 | mHistoryCur.states &= ~HistoryItem.STATE_WIFI_FULL_LOCK_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4891 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI full lock off to: " |
| 4892 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 4893 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4894 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4895 | getUidStatsLocked(uid).noteFullWifiLockReleasedLocked(elapsedRealtime); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4896 | } |
| 4897 | |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 4898 | int mWifiScanNesting = 0; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4899 | |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 4900 | public void noteWifiScanStartedLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4901 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4902 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4903 | final long uptime = mClocks.uptimeMillis(); |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 4904 | if (mWifiScanNesting == 0) { |
| 4905 | mHistoryCur.states |= HistoryItem.STATE_WIFI_SCAN_FLAG; |
| 4906 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI scan started for: " |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4907 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 4908 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4909 | } |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 4910 | mWifiScanNesting++; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4911 | getUidStatsLocked(uid).noteWifiScanStartedLocked(elapsedRealtime); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4912 | } |
| 4913 | |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 4914 | public void noteWifiScanStoppedLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4915 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4916 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4917 | final long uptime = mClocks.uptimeMillis(); |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 4918 | mWifiScanNesting--; |
| 4919 | if (mWifiScanNesting == 0) { |
| 4920 | mHistoryCur.states &= ~HistoryItem.STATE_WIFI_SCAN_FLAG; |
| 4921 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI scan stopped for: " |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4922 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 4923 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4924 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4925 | getUidStatsLocked(uid).noteWifiScanStoppedLocked(elapsedRealtime); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4926 | } |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 4927 | |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 4928 | public void noteWifiBatchedScanStartedLocked(int uid, int csph) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4929 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4930 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4931 | getUidStatsLocked(uid).noteWifiBatchedScanStartedLocked(csph, elapsedRealtime); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 4932 | } |
| 4933 | |
| 4934 | public void noteWifiBatchedScanStoppedLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4935 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4936 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4937 | getUidStatsLocked(uid).noteWifiBatchedScanStoppedLocked(elapsedRealtime); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 4938 | } |
| 4939 | |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4940 | int mWifiMulticastNesting = 0; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4941 | |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 4942 | public void noteWifiMulticastEnabledLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4943 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4944 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4945 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4946 | if (mWifiMulticastNesting == 0) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4947 | mHistoryCur.states |= HistoryItem.STATE_WIFI_MULTICAST_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4948 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI multicast on to: " |
| 4949 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 4950 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4951 | } |
| 4952 | mWifiMulticastNesting++; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4953 | getUidStatsLocked(uid).noteWifiMulticastEnabledLocked(elapsedRealtime); |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 4954 | } |
| 4955 | |
| 4956 | public void noteWifiMulticastDisabledLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4957 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4958 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4959 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4960 | mWifiMulticastNesting--; |
| 4961 | if (mWifiMulticastNesting == 0) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4962 | mHistoryCur.states &= ~HistoryItem.STATE_WIFI_MULTICAST_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4963 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI multicast off to: " |
| 4964 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 4965 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4966 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4967 | getUidStatsLocked(uid).noteWifiMulticastDisabledLocked(elapsedRealtime); |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 4968 | } |
| 4969 | |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 4970 | public void noteFullWifiLockAcquiredFromSourceLocked(WorkSource ws) { |
| 4971 | int N = ws.size(); |
| 4972 | for (int i=0; i<N; i++) { |
| 4973 | noteFullWifiLockAcquiredLocked(ws.get(i)); |
| 4974 | } |
| 4975 | } |
| 4976 | |
| 4977 | public void noteFullWifiLockReleasedFromSourceLocked(WorkSource ws) { |
| 4978 | int N = ws.size(); |
| 4979 | for (int i=0; i<N; i++) { |
| 4980 | noteFullWifiLockReleasedLocked(ws.get(i)); |
| 4981 | } |
| 4982 | } |
| 4983 | |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 4984 | public void noteWifiScanStartedFromSourceLocked(WorkSource ws) { |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 4985 | int N = ws.size(); |
| 4986 | for (int i=0; i<N; i++) { |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 4987 | noteWifiScanStartedLocked(ws.get(i)); |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 4988 | } |
| 4989 | } |
| 4990 | |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 4991 | public void noteWifiScanStoppedFromSourceLocked(WorkSource ws) { |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 4992 | int N = ws.size(); |
| 4993 | for (int i=0; i<N; i++) { |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 4994 | noteWifiScanStoppedLocked(ws.get(i)); |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 4995 | } |
| 4996 | } |
| 4997 | |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 4998 | public void noteWifiBatchedScanStartedFromSourceLocked(WorkSource ws, int csph) { |
| 4999 | int N = ws.size(); |
| 5000 | for (int i=0; i<N; i++) { |
| 5001 | noteWifiBatchedScanStartedLocked(ws.get(i), csph); |
| 5002 | } |
| 5003 | } |
| 5004 | |
| 5005 | public void noteWifiBatchedScanStoppedFromSourceLocked(WorkSource ws) { |
| 5006 | int N = ws.size(); |
| 5007 | for (int i=0; i<N; i++) { |
| 5008 | noteWifiBatchedScanStoppedLocked(ws.get(i)); |
| 5009 | } |
| 5010 | } |
| 5011 | |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 5012 | public void noteWifiMulticastEnabledFromSourceLocked(WorkSource ws) { |
| 5013 | int N = ws.size(); |
| 5014 | for (int i=0; i<N; i++) { |
| 5015 | noteWifiMulticastEnabledLocked(ws.get(i)); |
| 5016 | } |
| 5017 | } |
| 5018 | |
| 5019 | public void noteWifiMulticastDisabledFromSourceLocked(WorkSource ws) { |
| 5020 | int N = ws.size(); |
| 5021 | for (int i=0; i<N; i++) { |
| 5022 | noteWifiMulticastDisabledLocked(ws.get(i)); |
| 5023 | } |
| 5024 | } |
| 5025 | |
Dianne Hackborn | d0c5b9a | 2014-02-21 16:19:05 -0800 | [diff] [blame] | 5026 | private static String[] includeInStringArray(String[] array, String str) { |
| 5027 | if (ArrayUtils.indexOf(array, str) >= 0) { |
| 5028 | return array; |
| 5029 | } |
| 5030 | String[] newArray = new String[array.length+1]; |
| 5031 | System.arraycopy(array, 0, newArray, 0, array.length); |
| 5032 | newArray[array.length] = str; |
| 5033 | return newArray; |
| 5034 | } |
| 5035 | |
| 5036 | private static String[] excludeFromStringArray(String[] array, String str) { |
| 5037 | int index = ArrayUtils.indexOf(array, str); |
| 5038 | if (index >= 0) { |
| 5039 | String[] newArray = new String[array.length-1]; |
| 5040 | if (index > 0) { |
| 5041 | System.arraycopy(array, 0, newArray, 0, index); |
| 5042 | } |
| 5043 | if (index < array.length-1) { |
| 5044 | System.arraycopy(array, index+1, newArray, index, array.length-index-1); |
| 5045 | } |
| 5046 | return newArray; |
| 5047 | } |
| 5048 | return array; |
| 5049 | } |
| 5050 | |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 5051 | public void noteNetworkInterfaceTypeLocked(String iface, int networkType) { |
Jeff Sharkey | 9da2f1e | 2014-08-14 12:55:00 -0700 | [diff] [blame] | 5052 | if (TextUtils.isEmpty(iface)) return; |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 5053 | if (ConnectivityManager.isNetworkTypeMobile(networkType)) { |
Dianne Hackborn | d0c5b9a | 2014-02-21 16:19:05 -0800 | [diff] [blame] | 5054 | mMobileIfaces = includeInStringArray(mMobileIfaces, iface); |
| 5055 | if (DEBUG) Slog.d(TAG, "Note mobile iface " + iface + ": " + mMobileIfaces); |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 5056 | } else { |
Dianne Hackborn | d0c5b9a | 2014-02-21 16:19:05 -0800 | [diff] [blame] | 5057 | mMobileIfaces = excludeFromStringArray(mMobileIfaces, iface); |
| 5058 | if (DEBUG) Slog.d(TAG, "Note non-mobile iface " + iface + ": " + mMobileIfaces); |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 5059 | } |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5060 | if (ConnectivityManager.isNetworkTypeWifi(networkType)) { |
Dianne Hackborn | d0c5b9a | 2014-02-21 16:19:05 -0800 | [diff] [blame] | 5061 | mWifiIfaces = includeInStringArray(mWifiIfaces, iface); |
| 5062 | if (DEBUG) Slog.d(TAG, "Note wifi iface " + iface + ": " + mWifiIfaces); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5063 | } else { |
Dianne Hackborn | d0c5b9a | 2014-02-21 16:19:05 -0800 | [diff] [blame] | 5064 | mWifiIfaces = excludeFromStringArray(mWifiIfaces, iface); |
| 5065 | if (DEBUG) Slog.d(TAG, "Note non-wifi iface " + iface + ": " + mWifiIfaces); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5066 | } |
| 5067 | } |
| 5068 | |
| 5069 | public void noteNetworkStatsEnabledLocked() { |
| 5070 | // During device boot, qtaguid isn't enabled until after the inital |
| 5071 | // loading of battery stats. Now that they're enabled, take our initial |
| 5072 | // snapshot for future delta calculation. |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5073 | updateMobileRadioStateLocked(mClocks.elapsedRealtime(), null); |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 5074 | updateWifiStateLocked(null); |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 5075 | } |
| 5076 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5077 | @Override public long getScreenOnTime(long elapsedRealtimeUs, int which) { |
| 5078 | return mScreenOnTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5079 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5080 | |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 5081 | @Override public int getScreenOnCount(int which) { |
| 5082 | return mScreenOnTimer.getCountLocked(which); |
| 5083 | } |
| 5084 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 5085 | @Override public long getScreenBrightnessTime(int brightnessBin, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5086 | long elapsedRealtimeUs, int which) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 5087 | return mScreenBrightnessTimer[brightnessBin].getTotalTimeLocked( |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5088 | elapsedRealtimeUs, which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 5089 | } |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 5090 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 5091 | @Override public long getInteractiveTime(long elapsedRealtimeUs, int which) { |
| 5092 | return mInteractiveTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 5093 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5094 | |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 5095 | @Override public long getPowerSaveModeEnabledTime(long elapsedRealtimeUs, int which) { |
| 5096 | return mPowerSaveModeEnabledTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 5097 | } |
| 5098 | |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 5099 | @Override public int getPowerSaveModeEnabledCount(int which) { |
| 5100 | return mPowerSaveModeEnabledTimer.getCountLocked(which); |
| 5101 | } |
| 5102 | |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 5103 | @Override public long getDeviceIdleModeTime(int mode, long elapsedRealtimeUs, |
| 5104 | int which) { |
| 5105 | switch (mode) { |
| 5106 | case DEVICE_IDLE_MODE_LIGHT: |
| 5107 | return mDeviceIdleModeLightTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 5108 | case DEVICE_IDLE_MODE_DEEP: |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 5109 | return mDeviceIdleModeFullTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
| 5110 | } |
| 5111 | return 0; |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 5112 | } |
| 5113 | |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 5114 | @Override public int getDeviceIdleModeCount(int mode, int which) { |
| 5115 | switch (mode) { |
| 5116 | case DEVICE_IDLE_MODE_LIGHT: |
| 5117 | return mDeviceIdleModeLightTimer.getCountLocked(which); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 5118 | case DEVICE_IDLE_MODE_DEEP: |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 5119 | return mDeviceIdleModeFullTimer.getCountLocked(which); |
| 5120 | } |
| 5121 | return 0; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 5122 | } |
| 5123 | |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 5124 | @Override public long getLongestDeviceIdleModeTime(int mode) { |
| 5125 | switch (mode) { |
| 5126 | case DEVICE_IDLE_MODE_LIGHT: |
| 5127 | return mLongestLightIdleTime; |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 5128 | case DEVICE_IDLE_MODE_DEEP: |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 5129 | return mLongestFullIdleTime; |
| 5130 | } |
| 5131 | return 0; |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 5132 | } |
| 5133 | |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 5134 | @Override public long getDeviceIdlingTime(int mode, long elapsedRealtimeUs, int which) { |
| 5135 | switch (mode) { |
| 5136 | case DEVICE_IDLE_MODE_LIGHT: |
| 5137 | return mDeviceLightIdlingTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 5138 | case DEVICE_IDLE_MODE_DEEP: |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 5139 | return mDeviceIdlingTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
| 5140 | } |
| 5141 | return 0; |
| 5142 | } |
| 5143 | |
| 5144 | @Override public int getDeviceIdlingCount(int mode, int which) { |
| 5145 | switch (mode) { |
| 5146 | case DEVICE_IDLE_MODE_LIGHT: |
| 5147 | return mDeviceLightIdlingTimer.getCountLocked(which); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 5148 | case DEVICE_IDLE_MODE_DEEP: |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 5149 | return mDeviceIdlingTimer.getCountLocked(which); |
| 5150 | } |
| 5151 | return 0; |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 5152 | } |
| 5153 | |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 5154 | @Override public int getNumConnectivityChange(int which) { |
| 5155 | int val = mNumConnectivityChange; |
| 5156 | if (which == STATS_CURRENT) { |
| 5157 | val -= mLoadedNumConnectivityChange; |
| 5158 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 5159 | val -= mUnpluggedNumConnectivityChange; |
| 5160 | } |
| 5161 | return val; |
| 5162 | } |
| 5163 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5164 | @Override public long getPhoneOnTime(long elapsedRealtimeUs, int which) { |
| 5165 | return mPhoneOnTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5166 | } |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 5167 | |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 5168 | @Override public int getPhoneOnCount(int which) { |
| 5169 | return mPhoneOnTimer.getCountLocked(which); |
| 5170 | } |
| 5171 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 5172 | @Override public long getPhoneSignalStrengthTime(int strengthBin, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5173 | long elapsedRealtimeUs, int which) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 5174 | return mPhoneSignalStrengthsTimer[strengthBin].getTotalTimeLocked( |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5175 | elapsedRealtimeUs, which); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 5176 | } |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 5177 | |
| 5178 | @Override public long getPhoneSignalScanningTime( |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5179 | long elapsedRealtimeUs, int which) { |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 5180 | return mPhoneSignalScanningTimer.getTotalTimeLocked( |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5181 | elapsedRealtimeUs, which); |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 5182 | } |
| 5183 | |
Catherine Liu | fb90081 | 2012-07-17 14:12:56 -0500 | [diff] [blame] | 5184 | @Override public int getPhoneSignalStrengthCount(int strengthBin, int which) { |
| 5185 | return mPhoneSignalStrengthsTimer[strengthBin].getCountLocked(which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 5186 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5187 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 5188 | @Override public long getPhoneDataConnectionTime(int dataType, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5189 | long elapsedRealtimeUs, int which) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 5190 | return mPhoneDataConnectionsTimer[dataType].getTotalTimeLocked( |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5191 | elapsedRealtimeUs, which); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 5192 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5193 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 5194 | @Override public int getPhoneDataConnectionCount(int dataType, int which) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 5195 | return mPhoneDataConnectionsTimer[dataType].getCountLocked(which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 5196 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5197 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5198 | @Override public long getMobileRadioActiveTime(long elapsedRealtimeUs, int which) { |
| 5199 | return mMobileRadioActiveTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 5200 | } |
| 5201 | |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 5202 | @Override public int getMobileRadioActiveCount(int which) { |
| 5203 | return mMobileRadioActiveTimer.getCountLocked(which); |
| 5204 | } |
| 5205 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 5206 | @Override public long getMobileRadioActiveAdjustedTime(int which) { |
| 5207 | return mMobileRadioActiveAdjustedTime.getCountLocked(which); |
| 5208 | } |
| 5209 | |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 5210 | @Override public long getMobileRadioActiveUnknownTime(int which) { |
| 5211 | return mMobileRadioActiveUnknownTime.getCountLocked(which); |
| 5212 | } |
| 5213 | |
| 5214 | @Override public int getMobileRadioActiveUnknownCount(int which) { |
| 5215 | return (int)mMobileRadioActiveUnknownCount.getCountLocked(which); |
| 5216 | } |
| 5217 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5218 | @Override public long getWifiOnTime(long elapsedRealtimeUs, int which) { |
| 5219 | return mWifiOnTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 5220 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5221 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5222 | @Override public long getGlobalWifiRunningTime(long elapsedRealtimeUs, int which) { |
| 5223 | return mGlobalWifiRunningTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Eric Shienbrood | d4c5f89 | 2009-03-24 18:13:20 -0700 | [diff] [blame] | 5224 | } |
| 5225 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 5226 | @Override public long getWifiStateTime(int wifiState, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5227 | long elapsedRealtimeUs, int which) { |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 5228 | return mWifiStateTimer[wifiState].getTotalTimeLocked( |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5229 | elapsedRealtimeUs, which); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 5230 | } |
| 5231 | |
| 5232 | @Override public int getWifiStateCount(int wifiState, int which) { |
| 5233 | return mWifiStateTimer[wifiState].getCountLocked(which); |
| 5234 | } |
| 5235 | |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 5236 | @Override public long getWifiSupplStateTime(int state, |
| 5237 | long elapsedRealtimeUs, int which) { |
| 5238 | return mWifiSupplStateTimer[state].getTotalTimeLocked( |
| 5239 | elapsedRealtimeUs, which); |
| 5240 | } |
| 5241 | |
| 5242 | @Override public int getWifiSupplStateCount(int state, int which) { |
| 5243 | return mWifiSupplStateTimer[state].getCountLocked(which); |
| 5244 | } |
| 5245 | |
| 5246 | @Override public long getWifiSignalStrengthTime(int strengthBin, |
| 5247 | long elapsedRealtimeUs, int which) { |
| 5248 | return mWifiSignalStrengthsTimer[strengthBin].getTotalTimeLocked( |
| 5249 | elapsedRealtimeUs, which); |
| 5250 | } |
| 5251 | |
| 5252 | @Override public int getWifiSignalStrengthCount(int strengthBin, int which) { |
| 5253 | return mWifiSignalStrengthsTimer[strengthBin].getCountLocked(which); |
| 5254 | } |
| 5255 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 5256 | @Override |
| 5257 | public ControllerActivityCounter getBluetoothControllerActivity() { |
| 5258 | return mBluetoothActivity; |
Adam Lesinski | 1739076 | 2015-04-10 13:17:47 -0700 | [diff] [blame] | 5259 | } |
| 5260 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 5261 | @Override |
| 5262 | public ControllerActivityCounter getWifiControllerActivity() { |
| 5263 | return mWifiActivity; |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 5264 | } |
| 5265 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 5266 | @Override |
| 5267 | public ControllerActivityCounter getModemControllerActivity() { |
| 5268 | return mModemActivity; |
Adam Lesinski | 1739076 | 2015-04-10 13:17:47 -0700 | [diff] [blame] | 5269 | } |
| 5270 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 5271 | @Override |
| 5272 | public boolean hasBluetoothActivityReporting() { |
| 5273 | return mHasBluetoothReporting; |
| 5274 | } |
| 5275 | |
| 5276 | @Override |
| 5277 | public boolean hasWifiActivityReporting() { |
| 5278 | return mHasWifiReporting; |
| 5279 | } |
| 5280 | |
| 5281 | @Override |
| 5282 | public boolean hasModemActivityReporting() { |
| 5283 | return mHasModemReporting; |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 5284 | } |
| 5285 | |
Ruben Brunk | 5b1308f | 2015-06-03 18:49:27 -0700 | [diff] [blame] | 5286 | @Override |
| 5287 | public long getFlashlightOnTime(long elapsedRealtimeUs, int which) { |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 5288 | return mFlashlightOnTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
| 5289 | } |
| 5290 | |
Ruben Brunk | 5b1308f | 2015-06-03 18:49:27 -0700 | [diff] [blame] | 5291 | @Override |
| 5292 | public long getFlashlightOnCount(int which) { |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 5293 | return mFlashlightOnTimer.getCountLocked(which); |
| 5294 | } |
| 5295 | |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5296 | @Override |
Ruben Brunk | 5b1308f | 2015-06-03 18:49:27 -0700 | [diff] [blame] | 5297 | public long getCameraOnTime(long elapsedRealtimeUs, int which) { |
| 5298 | return mCameraOnTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
| 5299 | } |
| 5300 | |
| 5301 | @Override |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 5302 | public long getBluetoothScanTime(long elapsedRealtimeUs, int which) { |
| 5303 | return mBluetoothScanTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
| 5304 | } |
| 5305 | |
| 5306 | @Override |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5307 | public long getNetworkActivityBytes(int type, int which) { |
| 5308 | if (type >= 0 && type < mNetworkByteActivityCounters.length) { |
| 5309 | return mNetworkByteActivityCounters[type].getCountLocked(which); |
| 5310 | } else { |
| 5311 | return 0; |
| 5312 | } |
| 5313 | } |
| 5314 | |
| 5315 | @Override |
| 5316 | public long getNetworkActivityPackets(int type, int which) { |
| 5317 | if (type >= 0 && type < mNetworkPacketActivityCounters.length) { |
| 5318 | return mNetworkPacketActivityCounters[type].getCountLocked(which); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5319 | } else { |
| 5320 | return 0; |
| 5321 | } |
| 5322 | } |
| 5323 | |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 5324 | @Override public long getStartClockTime() { |
Dianne Hackborn | d48954f | 2015-07-22 17:20:33 -0700 | [diff] [blame] | 5325 | final long currentTime = System.currentTimeMillis(); |
| 5326 | if (ensureStartClockTime(currentTime)) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5327 | recordCurrentTimeChangeLocked(currentTime, mClocks.elapsedRealtime(), |
| 5328 | mClocks.uptimeMillis()); |
Dianne Hackborn | 7d9eefd | 2014-08-27 18:30:31 -0700 | [diff] [blame] | 5329 | } |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 5330 | return mStartClockTime; |
| 5331 | } |
| 5332 | |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 5333 | @Override public String getStartPlatformVersion() { |
| 5334 | return mStartPlatformVersion; |
| 5335 | } |
| 5336 | |
| 5337 | @Override public String getEndPlatformVersion() { |
| 5338 | return mEndPlatformVersion; |
| 5339 | } |
| 5340 | |
| 5341 | @Override public int getParcelVersion() { |
| 5342 | return VERSION; |
| 5343 | } |
| 5344 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5345 | @Override public boolean getIsOnBattery() { |
| 5346 | return mOnBattery; |
| 5347 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5348 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5349 | @Override public SparseArray<? extends BatteryStats.Uid> getUidStats() { |
| 5350 | return mUidStats; |
| 5351 | } |
| 5352 | |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 5353 | private static void detachTimerIfNotNull(BatteryStatsImpl.Timer timer) { |
| 5354 | if (timer != null) { |
| 5355 | timer.detach(); |
| 5356 | } |
| 5357 | } |
| 5358 | |
| 5359 | private static boolean resetTimerIfNotNull(BatteryStatsImpl.Timer timer, |
| 5360 | boolean detachIfReset) { |
| 5361 | if (timer != null) { |
| 5362 | return timer.reset(detachIfReset); |
| 5363 | } |
| 5364 | return true; |
| 5365 | } |
| 5366 | |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5367 | private static boolean resetTimerIfNotNull(DualTimer timer, boolean detachIfReset) { |
| 5368 | if (timer != null) { |
| 5369 | return timer.reset(detachIfReset); |
| 5370 | } |
| 5371 | return true; |
| 5372 | } |
| 5373 | |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 5374 | private static void detachLongCounterIfNotNull(LongSamplingCounter counter) { |
| 5375 | if (counter != null) { |
| 5376 | counter.detach(); |
| 5377 | } |
| 5378 | } |
| 5379 | |
| 5380 | private static void resetLongCounterIfNotNull(LongSamplingCounter counter, |
| 5381 | boolean detachIfReset) { |
| 5382 | if (counter != null) { |
| 5383 | counter.reset(detachIfReset); |
| 5384 | } |
| 5385 | } |
| 5386 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5387 | /** |
| 5388 | * The statistics associated with a particular uid. |
| 5389 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5390 | public static class Uid extends BatteryStats.Uid { |
| 5391 | /** |
| 5392 | * BatteryStatsImpl that we are associated with. |
| 5393 | */ |
| 5394 | protected BatteryStatsImpl mBsi; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5395 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5396 | final int mUid; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5397 | |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5398 | /** TimeBase for when uid is in background and device is on battery. */ |
| 5399 | @VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE) |
| 5400 | public final TimeBase mOnBatteryBackgroundTimeBase; |
| 5401 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 5402 | boolean mWifiRunning; |
| 5403 | StopwatchTimer mWifiRunningTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5404 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 5405 | boolean mFullWifiLockOut; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 5406 | StopwatchTimer mFullWifiLockTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5407 | |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 5408 | boolean mWifiScanStarted; |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5409 | DualTimer mWifiScanTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5410 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5411 | static final int NO_BATCHED_SCAN_STARTED = -1; |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 5412 | int mWifiBatchedScanBinStarted = NO_BATCHED_SCAN_STARTED; |
| 5413 | StopwatchTimer[] mWifiBatchedScanTimer; |
| 5414 | |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 5415 | boolean mWifiMulticastEnabled; |
| 5416 | StopwatchTimer mWifiMulticastTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5417 | |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 5418 | StopwatchTimer mAudioTurnedOnTimer; |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 5419 | StopwatchTimer mVideoTurnedOnTimer; |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 5420 | StopwatchTimer mFlashlightTurnedOnTimer; |
| 5421 | StopwatchTimer mCameraTurnedOnTimer; |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 5422 | StopwatchTimer mForegroundActivityTimer; |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5423 | DualTimer mBluetoothScanTimer; |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 5424 | |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 5425 | int mProcessState = ActivityManager.PROCESS_STATE_NONEXISTENT; |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5426 | StopwatchTimer[] mProcessStateTimer; |
| 5427 | |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 5428 | BatchTimer mVibratorOnTimer; |
| 5429 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 5430 | Counter[] mUserActivityCounters; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5431 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5432 | LongSamplingCounter[] mNetworkByteActivityCounters; |
| 5433 | LongSamplingCounter[] mNetworkPacketActivityCounters; |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 5434 | LongSamplingCounter mMobileRadioActiveTime; |
| 5435 | LongSamplingCounter mMobileRadioActiveCount; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5436 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5437 | /** |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 5438 | * How many times this UID woke up the Application Processor due to a Mobile radio packet. |
| 5439 | */ |
| 5440 | private LongSamplingCounter mMobileRadioApWakeupCount; |
| 5441 | |
| 5442 | /** |
| 5443 | * How many times this UID woke up the Application Processor due to a Wifi packet. |
| 5444 | */ |
| 5445 | private LongSamplingCounter mWifiRadioApWakeupCount; |
| 5446 | |
| 5447 | /** |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 5448 | * 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] | 5449 | * Can be null if the UID has had no such activity. |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 5450 | */ |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 5451 | private ControllerActivityCounterImpl mWifiControllerActivity; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 5452 | |
| 5453 | /** |
| 5454 | * 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] | 5455 | * Can be null if the UID has had no such activity. |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 5456 | */ |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 5457 | private ControllerActivityCounterImpl mBluetoothControllerActivity; |
| 5458 | |
| 5459 | /** |
| 5460 | * The amount of time this uid has kept the Modem controller in idle, tx, and rx mode. |
| 5461 | * Can be null if the UID has had no such activity. |
| 5462 | */ |
| 5463 | private ControllerActivityCounterImpl mModemControllerActivity; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 5464 | |
| 5465 | /** |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 5466 | * The CPU times we had at the last history details update. |
| 5467 | */ |
| 5468 | long mLastStepUserTime; |
| 5469 | long mLastStepSystemTime; |
| 5470 | long mCurStepUserTime; |
| 5471 | long mCurStepSystemTime; |
| 5472 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5473 | LongSamplingCounter mUserCpuTime; |
| 5474 | LongSamplingCounter mSystemCpuTime; |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 5475 | LongSamplingCounter[][] mCpuClusterSpeed; |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 5476 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 5477 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5478 | * The statistics we have collected for this uid's wake locks. |
| 5479 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5480 | final OverflowArrayMap<Wakelock> mWakelockStats; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5481 | |
| 5482 | /** |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 5483 | * The statistics we have collected for this uid's syncs. |
| 5484 | */ |
Bookatz | 2bffb5b | 2017-04-13 11:59:33 -0700 | [diff] [blame] | 5485 | final OverflowArrayMap<DualTimer> mSyncStats; |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 5486 | |
| 5487 | /** |
| 5488 | * The statistics we have collected for this uid's jobs. |
| 5489 | */ |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 5490 | final OverflowArrayMap<DualTimer> mJobStats; |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 5491 | |
| 5492 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5493 | * The statistics we have collected for this uid's sensor activations. |
| 5494 | */ |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 5495 | final SparseArray<Sensor> mSensorStats = new SparseArray<>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5496 | |
| 5497 | /** |
| 5498 | * The statistics we have collected for this uid's processes. |
| 5499 | */ |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 5500 | final ArrayMap<String, Proc> mProcessStats = new ArrayMap<>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5501 | |
| 5502 | /** |
| 5503 | * The statistics we have collected for this uid's processes. |
| 5504 | */ |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 5505 | final ArrayMap<String, Pkg> mPackageStats = new ArrayMap<>(); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5506 | |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 5507 | /** |
| 5508 | * The transient wake stats we have collected for this uid's pids. |
| 5509 | */ |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 5510 | final SparseArray<Pid> mPids = new SparseArray<>(); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 5511 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5512 | public Uid(BatteryStatsImpl bsi, int uid) { |
| 5513 | mBsi = bsi; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5514 | mUid = uid; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5515 | |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5516 | mOnBatteryBackgroundTimeBase = new TimeBase(); |
| 5517 | mOnBatteryBackgroundTimeBase.init(mBsi.mClocks.uptimeMillis() * 1000, |
| 5518 | mBsi.mClocks.elapsedRealtime() * 1000); |
| 5519 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5520 | mUserCpuTime = new LongSamplingCounter(mBsi.mOnBatteryTimeBase); |
| 5521 | mSystemCpuTime = new LongSamplingCounter(mBsi.mOnBatteryTimeBase); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5522 | |
Dianne Hackborn | 657153b | 2016-07-29 14:54:14 -0700 | [diff] [blame] | 5523 | mWakelockStats = mBsi.new OverflowArrayMap<Wakelock>(uid) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5524 | @Override public Wakelock instantiateObject() { |
| 5525 | return new Wakelock(mBsi, Uid.this); |
| 5526 | } |
| 5527 | }; |
Bookatz | 2bffb5b | 2017-04-13 11:59:33 -0700 | [diff] [blame] | 5528 | mSyncStats = mBsi.new OverflowArrayMap<DualTimer>(uid) { |
| 5529 | @Override public DualTimer instantiateObject() { |
| 5530 | return new DualTimer(mBsi.mClocks, Uid.this, SYNC, null, |
| 5531 | mBsi.mOnBatteryTimeBase, mOnBatteryBackgroundTimeBase); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5532 | } |
| 5533 | }; |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 5534 | mJobStats = mBsi.new OverflowArrayMap<DualTimer>(uid) { |
| 5535 | @Override public DualTimer instantiateObject() { |
| 5536 | return new DualTimer(mBsi.mClocks, Uid.this, JOB, null, |
| 5537 | mBsi.mOnBatteryTimeBase, mOnBatteryBackgroundTimeBase); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5538 | } |
| 5539 | }; |
| 5540 | |
| 5541 | mWifiRunningTimer = new StopwatchTimer(mBsi.mClocks, this, WIFI_RUNNING, |
| 5542 | mBsi.mWifiRunningTimers, mBsi.mOnBatteryTimeBase); |
| 5543 | mFullWifiLockTimer = new StopwatchTimer(mBsi.mClocks, this, FULL_WIFI_LOCK, |
| 5544 | mBsi.mFullWifiLockTimers, mBsi.mOnBatteryTimeBase); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5545 | mWifiScanTimer = new DualTimer(mBsi.mClocks, this, WIFI_SCAN, |
| 5546 | mBsi.mWifiScanTimers, mBsi.mOnBatteryTimeBase, mOnBatteryBackgroundTimeBase); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 5547 | mWifiBatchedScanTimer = new StopwatchTimer[NUM_WIFI_BATCHED_SCAN_BINS]; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5548 | mWifiMulticastTimer = new StopwatchTimer(mBsi.mClocks, this, WIFI_MULTICAST_ENABLED, |
| 5549 | mBsi.mWifiMulticastTimers, mBsi.mOnBatteryTimeBase); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5550 | mProcessStateTimer = new StopwatchTimer[NUM_PROCESS_STATE]; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5551 | } |
| 5552 | |
| 5553 | @Override |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5554 | public ArrayMap<String, ? extends BatteryStats.Uid.Wakelock> getWakelockStats() { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 5555 | return mWakelockStats.getMap(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5556 | } |
| 5557 | |
| 5558 | @Override |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5559 | public ArrayMap<String, ? extends BatteryStats.Timer> getSyncStats() { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 5560 | return mSyncStats.getMap(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 5561 | } |
| 5562 | |
| 5563 | @Override |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5564 | public ArrayMap<String, ? extends BatteryStats.Timer> getJobStats() { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 5565 | return mJobStats.getMap(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 5566 | } |
| 5567 | |
| 5568 | @Override |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5569 | public SparseArray<? extends BatteryStats.Uid.Sensor> getSensorStats() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5570 | return mSensorStats; |
| 5571 | } |
| 5572 | |
| 5573 | @Override |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5574 | public ArrayMap<String, ? extends BatteryStats.Uid.Proc> getProcessStats() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5575 | return mProcessStats; |
| 5576 | } |
| 5577 | |
| 5578 | @Override |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5579 | public ArrayMap<String, ? extends BatteryStats.Uid.Pkg> getPackageStats() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5580 | return mPackageStats; |
| 5581 | } |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 5582 | |
| 5583 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5584 | public int getUid() { |
| 5585 | return mUid; |
| 5586 | } |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 5587 | |
| 5588 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5589 | public void noteWifiRunningLocked(long elapsedRealtimeMs) { |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 5590 | if (!mWifiRunning) { |
| 5591 | mWifiRunning = true; |
| 5592 | if (mWifiRunningTimer == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5593 | mWifiRunningTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, WIFI_RUNNING, |
| 5594 | mBsi.mWifiRunningTimers, mBsi.mOnBatteryTimeBase); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5595 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5596 | mWifiRunningTimer.startRunningLocked(elapsedRealtimeMs); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 5597 | } |
| 5598 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5599 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 5600 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5601 | public void noteWifiStoppedLocked(long elapsedRealtimeMs) { |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 5602 | if (mWifiRunning) { |
| 5603 | mWifiRunning = false; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5604 | mWifiRunningTimer.stopRunningLocked(elapsedRealtimeMs); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 5605 | } |
| 5606 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5607 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 5608 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5609 | public void noteFullWifiLockAcquiredLocked(long elapsedRealtimeMs) { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 5610 | if (!mFullWifiLockOut) { |
| 5611 | mFullWifiLockOut = true; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5612 | if (mFullWifiLockTimer == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5613 | mFullWifiLockTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, FULL_WIFI_LOCK, |
| 5614 | mBsi.mFullWifiLockTimers, mBsi.mOnBatteryTimeBase); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5615 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5616 | mFullWifiLockTimer.startRunningLocked(elapsedRealtimeMs); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 5617 | } |
| 5618 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5619 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 5620 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5621 | public void noteFullWifiLockReleasedLocked(long elapsedRealtimeMs) { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 5622 | if (mFullWifiLockOut) { |
| 5623 | mFullWifiLockOut = false; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5624 | mFullWifiLockTimer.stopRunningLocked(elapsedRealtimeMs); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 5625 | } |
| 5626 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5627 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 5628 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5629 | public void noteWifiScanStartedLocked(long elapsedRealtimeMs) { |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 5630 | if (!mWifiScanStarted) { |
| 5631 | mWifiScanStarted = true; |
| 5632 | if (mWifiScanTimer == null) { |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5633 | mWifiScanTimer = new DualTimer(mBsi.mClocks, Uid.this, WIFI_SCAN, |
| 5634 | mBsi.mWifiScanTimers, mBsi.mOnBatteryTimeBase, |
| 5635 | mOnBatteryBackgroundTimeBase); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5636 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5637 | mWifiScanTimer.startRunningLocked(elapsedRealtimeMs); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 5638 | } |
| 5639 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5640 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 5641 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5642 | public void noteWifiScanStoppedLocked(long elapsedRealtimeMs) { |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 5643 | if (mWifiScanStarted) { |
| 5644 | mWifiScanStarted = false; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5645 | mWifiScanTimer.stopRunningLocked(elapsedRealtimeMs); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 5646 | } |
| 5647 | } |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 5648 | |
| 5649 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5650 | public void noteWifiBatchedScanStartedLocked(int csph, long elapsedRealtimeMs) { |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 5651 | int bin = 0; |
Navtej Singh Mann | 3c0ce5c | 2015-06-11 16:53:11 -0700 | [diff] [blame] | 5652 | while (csph > 8 && bin < NUM_WIFI_BATCHED_SCAN_BINS-1) { |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 5653 | csph = csph >> 3; |
| 5654 | bin++; |
| 5655 | } |
| 5656 | |
| 5657 | if (mWifiBatchedScanBinStarted == bin) return; |
| 5658 | |
| 5659 | if (mWifiBatchedScanBinStarted != NO_BATCHED_SCAN_STARTED) { |
| 5660 | mWifiBatchedScanTimer[mWifiBatchedScanBinStarted]. |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5661 | stopRunningLocked(elapsedRealtimeMs); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 5662 | } |
| 5663 | mWifiBatchedScanBinStarted = bin; |
| 5664 | if (mWifiBatchedScanTimer[bin] == null) { |
| 5665 | makeWifiBatchedScanBin(bin, null); |
| 5666 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5667 | mWifiBatchedScanTimer[bin].startRunningLocked(elapsedRealtimeMs); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 5668 | } |
| 5669 | |
| 5670 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5671 | public void noteWifiBatchedScanStoppedLocked(long elapsedRealtimeMs) { |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 5672 | if (mWifiBatchedScanBinStarted != NO_BATCHED_SCAN_STARTED) { |
| 5673 | mWifiBatchedScanTimer[mWifiBatchedScanBinStarted]. |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5674 | stopRunningLocked(elapsedRealtimeMs); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 5675 | mWifiBatchedScanBinStarted = NO_BATCHED_SCAN_STARTED; |
| 5676 | } |
| 5677 | } |
| 5678 | |
| 5679 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5680 | public void noteWifiMulticastEnabledLocked(long elapsedRealtimeMs) { |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 5681 | if (!mWifiMulticastEnabled) { |
| 5682 | mWifiMulticastEnabled = true; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5683 | if (mWifiMulticastTimer == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5684 | mWifiMulticastTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, |
| 5685 | WIFI_MULTICAST_ENABLED, mBsi.mWifiMulticastTimers, mBsi.mOnBatteryTimeBase); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5686 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5687 | mWifiMulticastTimer.startRunningLocked(elapsedRealtimeMs); |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 5688 | } |
| 5689 | } |
| 5690 | |
| 5691 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5692 | public void noteWifiMulticastDisabledLocked(long elapsedRealtimeMs) { |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 5693 | if (mWifiMulticastEnabled) { |
| 5694 | mWifiMulticastEnabled = false; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5695 | mWifiMulticastTimer.stopRunningLocked(elapsedRealtimeMs); |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 5696 | } |
| 5697 | } |
| 5698 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 5699 | @Override |
| 5700 | public ControllerActivityCounter getWifiControllerActivity() { |
| 5701 | return mWifiControllerActivity; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 5702 | } |
| 5703 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 5704 | @Override |
| 5705 | public ControllerActivityCounter getBluetoothControllerActivity() { |
| 5706 | return mBluetoothControllerActivity; |
| 5707 | } |
| 5708 | |
| 5709 | @Override |
| 5710 | public ControllerActivityCounter getModemControllerActivity() { |
| 5711 | return mModemControllerActivity; |
| 5712 | } |
| 5713 | |
| 5714 | public ControllerActivityCounterImpl getOrCreateWifiControllerActivityLocked() { |
| 5715 | if (mWifiControllerActivity == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5716 | mWifiControllerActivity = new ControllerActivityCounterImpl(mBsi.mOnBatteryTimeBase, |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 5717 | NUM_BT_TX_LEVELS); |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 5718 | } |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 5719 | return mWifiControllerActivity; |
| 5720 | } |
| 5721 | |
| 5722 | public ControllerActivityCounterImpl getOrCreateBluetoothControllerActivityLocked() { |
| 5723 | if (mBluetoothControllerActivity == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5724 | mBluetoothControllerActivity = new ControllerActivityCounterImpl(mBsi.mOnBatteryTimeBase, |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 5725 | NUM_BT_TX_LEVELS); |
| 5726 | } |
| 5727 | return mBluetoothControllerActivity; |
| 5728 | } |
| 5729 | |
| 5730 | public ControllerActivityCounterImpl getOrCreateModemControllerActivityLocked() { |
| 5731 | if (mModemControllerActivity == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5732 | mModemControllerActivity = new ControllerActivityCounterImpl(mBsi.mOnBatteryTimeBase, |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 5733 | ModemActivityInfo.TX_POWER_LEVELS); |
| 5734 | } |
| 5735 | return mModemControllerActivity; |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 5736 | } |
| 5737 | |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 5738 | public StopwatchTimer createAudioTurnedOnTimerLocked() { |
| 5739 | if (mAudioTurnedOnTimer == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5740 | mAudioTurnedOnTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, AUDIO_TURNED_ON, |
| 5741 | mBsi.mAudioTurnedOnTimers, mBsi.mOnBatteryTimeBase); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 5742 | } |
| 5743 | return mAudioTurnedOnTimer; |
| 5744 | } |
| 5745 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5746 | public void noteAudioTurnedOnLocked(long elapsedRealtimeMs) { |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 5747 | createAudioTurnedOnTimerLocked().startRunningLocked(elapsedRealtimeMs); |
| 5748 | } |
| 5749 | |
| 5750 | public void noteAudioTurnedOffLocked(long elapsedRealtimeMs) { |
| 5751 | if (mAudioTurnedOnTimer != null) { |
| 5752 | mAudioTurnedOnTimer.stopRunningLocked(elapsedRealtimeMs); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5753 | } |
| 5754 | } |
| 5755 | |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 5756 | public void noteResetAudioLocked(long elapsedRealtimeMs) { |
| 5757 | if (mAudioTurnedOnTimer != null) { |
| 5758 | mAudioTurnedOnTimer.stopAllRunningLocked(elapsedRealtimeMs); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5759 | } |
| 5760 | } |
| 5761 | |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 5762 | public StopwatchTimer createVideoTurnedOnTimerLocked() { |
| 5763 | if (mVideoTurnedOnTimer == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5764 | mVideoTurnedOnTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, VIDEO_TURNED_ON, |
| 5765 | mBsi.mVideoTurnedOnTimers, mBsi.mOnBatteryTimeBase); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 5766 | } |
| 5767 | return mVideoTurnedOnTimer; |
| 5768 | } |
| 5769 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5770 | public void noteVideoTurnedOnLocked(long elapsedRealtimeMs) { |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 5771 | createVideoTurnedOnTimerLocked().startRunningLocked(elapsedRealtimeMs); |
| 5772 | } |
| 5773 | |
| 5774 | public void noteVideoTurnedOffLocked(long elapsedRealtimeMs) { |
| 5775 | if (mVideoTurnedOnTimer != null) { |
| 5776 | mVideoTurnedOnTimer.stopRunningLocked(elapsedRealtimeMs); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5777 | } |
| 5778 | } |
| 5779 | |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 5780 | public void noteResetVideoLocked(long elapsedRealtimeMs) { |
| 5781 | if (mVideoTurnedOnTimer != null) { |
| 5782 | mVideoTurnedOnTimer.stopAllRunningLocked(elapsedRealtimeMs); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 5783 | } |
| 5784 | } |
| 5785 | |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 5786 | public StopwatchTimer createFlashlightTurnedOnTimerLocked() { |
| 5787 | if (mFlashlightTurnedOnTimer == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5788 | mFlashlightTurnedOnTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, |
| 5789 | FLASHLIGHT_TURNED_ON, mBsi.mFlashlightTurnedOnTimers, mBsi.mOnBatteryTimeBase); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 5790 | } |
| 5791 | return mFlashlightTurnedOnTimer; |
| 5792 | } |
| 5793 | |
| 5794 | public void noteFlashlightTurnedOnLocked(long elapsedRealtimeMs) { |
| 5795 | createFlashlightTurnedOnTimerLocked().startRunningLocked(elapsedRealtimeMs); |
| 5796 | } |
| 5797 | |
| 5798 | public void noteFlashlightTurnedOffLocked(long elapsedRealtimeMs) { |
| 5799 | if (mFlashlightTurnedOnTimer != null) { |
| 5800 | mFlashlightTurnedOnTimer.stopRunningLocked(elapsedRealtimeMs); |
| 5801 | } |
| 5802 | } |
| 5803 | |
| 5804 | public void noteResetFlashlightLocked(long elapsedRealtimeMs) { |
| 5805 | if (mFlashlightTurnedOnTimer != null) { |
| 5806 | mFlashlightTurnedOnTimer.stopAllRunningLocked(elapsedRealtimeMs); |
| 5807 | } |
| 5808 | } |
| 5809 | |
| 5810 | public StopwatchTimer createCameraTurnedOnTimerLocked() { |
| 5811 | if (mCameraTurnedOnTimer == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5812 | mCameraTurnedOnTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, CAMERA_TURNED_ON, |
| 5813 | mBsi.mCameraTurnedOnTimers, mBsi.mOnBatteryTimeBase); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 5814 | } |
| 5815 | return mCameraTurnedOnTimer; |
| 5816 | } |
| 5817 | |
| 5818 | public void noteCameraTurnedOnLocked(long elapsedRealtimeMs) { |
| 5819 | createCameraTurnedOnTimerLocked().startRunningLocked(elapsedRealtimeMs); |
| 5820 | } |
| 5821 | |
| 5822 | public void noteCameraTurnedOffLocked(long elapsedRealtimeMs) { |
| 5823 | if (mCameraTurnedOnTimer != null) { |
| 5824 | mCameraTurnedOnTimer.stopRunningLocked(elapsedRealtimeMs); |
| 5825 | } |
| 5826 | } |
| 5827 | |
| 5828 | public void noteResetCameraLocked(long elapsedRealtimeMs) { |
| 5829 | if (mCameraTurnedOnTimer != null) { |
| 5830 | mCameraTurnedOnTimer.stopAllRunningLocked(elapsedRealtimeMs); |
| 5831 | } |
| 5832 | } |
| 5833 | |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 5834 | public StopwatchTimer createForegroundActivityTimerLocked() { |
| 5835 | if (mForegroundActivityTimer == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5836 | mForegroundActivityTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, |
| 5837 | FOREGROUND_ACTIVITY, null, mBsi.mOnBatteryTimeBase); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 5838 | } |
| 5839 | return mForegroundActivityTimer; |
| 5840 | } |
| 5841 | |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5842 | public DualTimer createBluetoothScanTimerLocked() { |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 5843 | if (mBluetoothScanTimer == null) { |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5844 | mBluetoothScanTimer = new DualTimer(mBsi.mClocks, Uid.this, BLUETOOTH_SCAN_ON, |
| 5845 | mBsi.mBluetoothScanOnTimers, mBsi.mOnBatteryTimeBase, |
| 5846 | mOnBatteryBackgroundTimeBase); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 5847 | } |
| 5848 | return mBluetoothScanTimer; |
| 5849 | } |
| 5850 | |
| 5851 | public void noteBluetoothScanStartedLocked(long elapsedRealtimeMs) { |
| 5852 | createBluetoothScanTimerLocked().startRunningLocked(elapsedRealtimeMs); |
| 5853 | } |
| 5854 | |
| 5855 | public void noteBluetoothScanStoppedLocked(long elapsedRealtimeMs) { |
| 5856 | if (mBluetoothScanTimer != null) { |
| 5857 | mBluetoothScanTimer.stopRunningLocked(elapsedRealtimeMs); |
| 5858 | } |
| 5859 | } |
| 5860 | |
| 5861 | public void noteResetBluetoothScanLocked(long elapsedRealtimeMs) { |
| 5862 | if (mBluetoothScanTimer != null) { |
| 5863 | mBluetoothScanTimer.stopAllRunningLocked(elapsedRealtimeMs); |
| 5864 | } |
| 5865 | } |
| 5866 | |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 5867 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5868 | public void noteActivityResumedLocked(long elapsedRealtimeMs) { |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 5869 | // We always start, since we want multiple foreground PIDs to nest |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5870 | createForegroundActivityTimerLocked().startRunningLocked(elapsedRealtimeMs); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 5871 | } |
| 5872 | |
| 5873 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5874 | public void noteActivityPausedLocked(long elapsedRealtimeMs) { |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 5875 | if (mForegroundActivityTimer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5876 | mForegroundActivityTimer.stopRunningLocked(elapsedRealtimeMs); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 5877 | } |
| 5878 | } |
| 5879 | |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 5880 | public BatchTimer createVibratorOnTimerLocked() { |
| 5881 | if (mVibratorOnTimer == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5882 | mVibratorOnTimer = new BatchTimer(mBsi.mClocks, Uid.this, VIBRATOR_ON, |
| 5883 | mBsi.mOnBatteryTimeBase); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 5884 | } |
| 5885 | return mVibratorOnTimer; |
| 5886 | } |
| 5887 | |
| 5888 | public void noteVibratorOnLocked(long durationMillis) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5889 | createVibratorOnTimerLocked().addDuration(mBsi, durationMillis); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 5890 | } |
| 5891 | |
| 5892 | public void noteVibratorOffLocked() { |
| 5893 | if (mVibratorOnTimer != null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5894 | mVibratorOnTimer.abortLastDuration(mBsi); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5895 | } |
| 5896 | } |
| 5897 | |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5898 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5899 | public long getWifiRunningTime(long elapsedRealtimeUs, int which) { |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 5900 | if (mWifiRunningTimer == null) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5901 | return 0; |
| 5902 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5903 | return mWifiRunningTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 5904 | } |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 5905 | |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5906 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5907 | public long getFullWifiLockTime(long elapsedRealtimeUs, int which) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5908 | if (mFullWifiLockTimer == null) { |
| 5909 | return 0; |
| 5910 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5911 | return mFullWifiLockTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 5912 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5913 | |
| 5914 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5915 | public long getWifiScanTime(long elapsedRealtimeUs, int which) { |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 5916 | if (mWifiScanTimer == null) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5917 | return 0; |
| 5918 | } |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 5919 | return mWifiScanTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 5920 | } |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 5921 | |
| 5922 | @Override |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 5923 | public int getWifiScanCount(int which) { |
| 5924 | if (mWifiScanTimer == null) { |
| 5925 | return 0; |
| 5926 | } |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 5927 | return mWifiScanTimer.getCountLocked(which); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5928 | } |
| 5929 | |
| 5930 | @Override |
| 5931 | public int getWifiScanBackgroundCount(int which) { |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 5932 | if (mWifiScanTimer == null || mWifiScanTimer.getSubTimer() == null) { |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5933 | return 0; |
| 5934 | } |
| 5935 | return mWifiScanTimer.getSubTimer().getCountLocked(which); |
| 5936 | } |
| 5937 | |
| 5938 | @Override |
| 5939 | public long getWifiScanActualTime(final long elapsedRealtimeUs) { |
| 5940 | if (mWifiScanTimer == null) { |
| 5941 | return 0; |
| 5942 | } |
| 5943 | final long elapsedRealtimeMs = (elapsedRealtimeUs + 500) / 1000; |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 5944 | return mWifiScanTimer.getTotalDurationMsLocked(elapsedRealtimeMs) * 1000; |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5945 | } |
| 5946 | |
| 5947 | @Override |
| 5948 | public long getWifiScanBackgroundTime(final long elapsedRealtimeUs) { |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 5949 | if (mWifiScanTimer == null || mWifiScanTimer.getSubTimer() == null) { |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5950 | return 0; |
| 5951 | } |
| 5952 | final long elapsedRealtimeMs = (elapsedRealtimeUs + 500) / 1000; |
| 5953 | return mWifiScanTimer.getSubTimer().getTotalDurationMsLocked(elapsedRealtimeMs) * 1000; |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 5954 | } |
| 5955 | |
| 5956 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5957 | public long getWifiBatchedScanTime(int csphBin, long elapsedRealtimeUs, int which) { |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 5958 | if (csphBin < 0 || csphBin >= NUM_WIFI_BATCHED_SCAN_BINS) return 0; |
| 5959 | if (mWifiBatchedScanTimer[csphBin] == null) { |
| 5960 | return 0; |
| 5961 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5962 | return mWifiBatchedScanTimer[csphBin].getTotalTimeLocked(elapsedRealtimeUs, which); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 5963 | } |
| 5964 | |
| 5965 | @Override |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 5966 | public int getWifiBatchedScanCount(int csphBin, int which) { |
| 5967 | if (csphBin < 0 || csphBin >= NUM_WIFI_BATCHED_SCAN_BINS) return 0; |
| 5968 | if (mWifiBatchedScanTimer[csphBin] == null) { |
| 5969 | return 0; |
| 5970 | } |
| 5971 | return mWifiBatchedScanTimer[csphBin].getCountLocked(which); |
| 5972 | } |
| 5973 | |
| 5974 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5975 | public long getWifiMulticastTime(long elapsedRealtimeUs, int which) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5976 | if (mWifiMulticastTimer == null) { |
| 5977 | return 0; |
| 5978 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5979 | return mWifiMulticastTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 5980 | } |
| 5981 | |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5982 | @Override |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 5983 | public Timer getAudioTurnedOnTimer() { |
| 5984 | return mAudioTurnedOnTimer; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5985 | } |
| 5986 | |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5987 | @Override |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 5988 | public Timer getVideoTurnedOnTimer() { |
| 5989 | return mVideoTurnedOnTimer; |
| 5990 | } |
| 5991 | |
| 5992 | @Override |
| 5993 | public Timer getFlashlightTurnedOnTimer() { |
| 5994 | return mFlashlightTurnedOnTimer; |
| 5995 | } |
| 5996 | |
| 5997 | @Override |
| 5998 | public Timer getCameraTurnedOnTimer() { |
| 5999 | return mCameraTurnedOnTimer; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6000 | } |
| 6001 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 6002 | @Override |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 6003 | public Timer getForegroundActivityTimer() { |
| 6004 | return mForegroundActivityTimer; |
| 6005 | } |
| 6006 | |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 6007 | @Override |
| 6008 | public Timer getBluetoothScanTimer() { |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 6009 | return mBluetoothScanTimer; |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 6010 | } |
| 6011 | |
| 6012 | @Override |
| 6013 | public Timer getBluetoothScanBackgroundTimer() { |
| 6014 | if (mBluetoothScanTimer == null) { |
| 6015 | return null; |
| 6016 | } |
| 6017 | return mBluetoothScanTimer.getSubTimer(); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 6018 | } |
| 6019 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 6020 | void makeProcessState(int i, Parcel in) { |
| 6021 | if (i < 0 || i >= NUM_PROCESS_STATE) return; |
| 6022 | |
| 6023 | if (in == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6024 | mProcessStateTimer[i] = new StopwatchTimer(mBsi.mClocks, this, PROCESS_STATE, null, |
| 6025 | mBsi.mOnBatteryTimeBase); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 6026 | } else { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6027 | mProcessStateTimer[i] = new StopwatchTimer(mBsi.mClocks, this, PROCESS_STATE, null, |
| 6028 | mBsi.mOnBatteryTimeBase, in); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 6029 | } |
| 6030 | } |
| 6031 | |
| 6032 | @Override |
| 6033 | public long getProcessStateTime(int state, long elapsedRealtimeUs, int which) { |
| 6034 | if (state < 0 || state >= NUM_PROCESS_STATE) return 0; |
| 6035 | if (mProcessStateTimer[state] == null) { |
| 6036 | return 0; |
| 6037 | } |
| 6038 | return mProcessStateTimer[state].getTotalTimeLocked(elapsedRealtimeUs, which); |
| 6039 | } |
| 6040 | |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 6041 | @Override |
Joe Onorato | 713fec8 | 2016-03-04 10:34:02 -0800 | [diff] [blame] | 6042 | public Timer getProcessStateTimer(int state) { |
| 6043 | if (state < 0 || state >= NUM_PROCESS_STATE) return null; |
| 6044 | return mProcessStateTimer[state]; |
| 6045 | } |
| 6046 | |
| 6047 | @Override |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 6048 | public Timer getVibratorOnTimer() { |
| 6049 | return mVibratorOnTimer; |
| 6050 | } |
| 6051 | |
| 6052 | @Override |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 6053 | public void noteUserActivityLocked(int type) { |
| 6054 | if (mUserActivityCounters == null) { |
| 6055 | initUserActivityLocked(); |
| 6056 | } |
Jeff Brown | df693de | 2012-07-27 12:03:38 -0700 | [diff] [blame] | 6057 | if (type >= 0 && type < NUM_USER_ACTIVITY_TYPES) { |
| 6058 | mUserActivityCounters[type].stepAtomic(); |
| 6059 | } else { |
| 6060 | Slog.w(TAG, "Unknown user activity type " + type + " was specified.", |
| 6061 | new Throwable()); |
| 6062 | } |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 6063 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6064 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 6065 | @Override |
| 6066 | public boolean hasUserActivity() { |
| 6067 | return mUserActivityCounters != null; |
| 6068 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6069 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 6070 | @Override |
| 6071 | public int getUserActivityCount(int type, int which) { |
| 6072 | if (mUserActivityCounters == null) { |
| 6073 | return 0; |
| 6074 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 6075 | return mUserActivityCounters[type].getCountLocked(which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 6076 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6077 | |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 6078 | void makeWifiBatchedScanBin(int i, Parcel in) { |
| 6079 | if (i < 0 || i >= NUM_WIFI_BATCHED_SCAN_BINS) return; |
| 6080 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6081 | ArrayList<StopwatchTimer> collected = mBsi.mWifiBatchedScanTimers.get(i); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 6082 | if (collected == null) { |
| 6083 | collected = new ArrayList<StopwatchTimer>(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6084 | mBsi.mWifiBatchedScanTimers.put(i, collected); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 6085 | } |
| 6086 | if (in == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6087 | mWifiBatchedScanTimer[i] = new StopwatchTimer(mBsi.mClocks, this, WIFI_BATCHED_SCAN, |
| 6088 | collected, mBsi.mOnBatteryTimeBase); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 6089 | } else { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6090 | mWifiBatchedScanTimer[i] = new StopwatchTimer(mBsi.mClocks, this, WIFI_BATCHED_SCAN, |
| 6091 | collected, mBsi.mOnBatteryTimeBase, in); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 6092 | } |
| 6093 | } |
| 6094 | |
| 6095 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 6096 | void initUserActivityLocked() { |
| 6097 | mUserActivityCounters = new Counter[NUM_USER_ACTIVITY_TYPES]; |
| 6098 | for (int i=0; i<NUM_USER_ACTIVITY_TYPES; i++) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6099 | mUserActivityCounters[i] = new Counter(mBsi.mOnBatteryTimeBase); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 6100 | } |
| 6101 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6102 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6103 | void noteNetworkActivityLocked(int type, long deltaBytes, long deltaPackets) { |
| 6104 | if (mNetworkByteActivityCounters == null) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 6105 | initNetworkActivityLocked(); |
| 6106 | } |
| 6107 | if (type >= 0 && type < NUM_NETWORK_ACTIVITY_TYPES) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6108 | mNetworkByteActivityCounters[type].addCountLocked(deltaBytes); |
| 6109 | mNetworkPacketActivityCounters[type].addCountLocked(deltaPackets); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 6110 | } else { |
| 6111 | Slog.w(TAG, "Unknown network activity type " + type + " was specified.", |
| 6112 | new Throwable()); |
| 6113 | } |
| 6114 | } |
| 6115 | |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 6116 | void noteMobileRadioActiveTimeLocked(long batteryUptime) { |
| 6117 | if (mNetworkByteActivityCounters == null) { |
| 6118 | initNetworkActivityLocked(); |
| 6119 | } |
| 6120 | mMobileRadioActiveTime.addCountLocked(batteryUptime); |
| 6121 | mMobileRadioActiveCount.addCountLocked(1); |
| 6122 | } |
| 6123 | |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 6124 | @Override |
| 6125 | public boolean hasNetworkActivity() { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6126 | return mNetworkByteActivityCounters != null; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 6127 | } |
| 6128 | |
| 6129 | @Override |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6130 | public long getNetworkActivityBytes(int type, int which) { |
| 6131 | if (mNetworkByteActivityCounters != null && type >= 0 |
| 6132 | && type < mNetworkByteActivityCounters.length) { |
| 6133 | return mNetworkByteActivityCounters[type].getCountLocked(which); |
| 6134 | } else { |
| 6135 | return 0; |
| 6136 | } |
| 6137 | } |
| 6138 | |
| 6139 | @Override |
| 6140 | public long getNetworkActivityPackets(int type, int which) { |
| 6141 | if (mNetworkPacketActivityCounters != null && type >= 0 |
| 6142 | && type < mNetworkPacketActivityCounters.length) { |
| 6143 | return mNetworkPacketActivityCounters[type].getCountLocked(which); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 6144 | } else { |
| 6145 | return 0; |
| 6146 | } |
| 6147 | } |
| 6148 | |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 6149 | @Override |
| 6150 | public long getMobileRadioActiveTime(int which) { |
| 6151 | return mMobileRadioActiveTime != null |
| 6152 | ? mMobileRadioActiveTime.getCountLocked(which) : 0; |
| 6153 | } |
| 6154 | |
| 6155 | @Override |
| 6156 | public int getMobileRadioActiveCount(int which) { |
| 6157 | return mMobileRadioActiveCount != null |
| 6158 | ? (int)mMobileRadioActiveCount.getCountLocked(which) : 0; |
| 6159 | } |
| 6160 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 6161 | @Override |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 6162 | public long getUserCpuTimeUs(int which) { |
| 6163 | return mUserCpuTime.getCountLocked(which); |
| 6164 | } |
| 6165 | |
| 6166 | @Override |
| 6167 | public long getSystemCpuTimeUs(int which) { |
| 6168 | return mSystemCpuTime.getCountLocked(which); |
| 6169 | } |
| 6170 | |
| 6171 | @Override |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 6172 | public long getTimeAtCpuSpeed(int cluster, int step, int which) { |
| 6173 | if (mCpuClusterSpeed != null) { |
| 6174 | if (cluster >= 0 && cluster < mCpuClusterSpeed.length) { |
| 6175 | final LongSamplingCounter[] cpuSpeeds = mCpuClusterSpeed[cluster]; |
| 6176 | if (cpuSpeeds != null) { |
| 6177 | if (step >= 0 && step < cpuSpeeds.length) { |
| 6178 | final LongSamplingCounter c = cpuSpeeds[step]; |
| 6179 | if (c != null) { |
| 6180 | return c.getCountLocked(which); |
| 6181 | } |
| 6182 | } |
| 6183 | } |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 6184 | } |
| 6185 | } |
| 6186 | return 0; |
| 6187 | } |
| 6188 | |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 6189 | public void noteMobileRadioApWakeupLocked() { |
| 6190 | if (mMobileRadioApWakeupCount == null) { |
| 6191 | mMobileRadioApWakeupCount = new LongSamplingCounter(mBsi.mOnBatteryTimeBase); |
| 6192 | } |
| 6193 | mMobileRadioApWakeupCount.addCountLocked(1); |
| 6194 | } |
| 6195 | |
| 6196 | @Override |
| 6197 | public long getMobileRadioApWakeupCount(int which) { |
| 6198 | if (mMobileRadioApWakeupCount != null) { |
| 6199 | return mMobileRadioApWakeupCount.getCountLocked(which); |
| 6200 | } |
| 6201 | return 0; |
| 6202 | } |
| 6203 | |
| 6204 | public void noteWifiRadioApWakeupLocked() { |
| 6205 | if (mWifiRadioApWakeupCount == null) { |
| 6206 | mWifiRadioApWakeupCount = new LongSamplingCounter(mBsi.mOnBatteryTimeBase); |
| 6207 | } |
| 6208 | mWifiRadioApWakeupCount.addCountLocked(1); |
| 6209 | } |
| 6210 | |
| 6211 | @Override |
| 6212 | public long getWifiRadioApWakeupCount(int which) { |
| 6213 | if (mWifiRadioApWakeupCount != null) { |
| 6214 | return mWifiRadioApWakeupCount.getCountLocked(which); |
| 6215 | } |
| 6216 | return 0; |
| 6217 | } |
| 6218 | |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 6219 | void initNetworkActivityLocked() { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6220 | mNetworkByteActivityCounters = new LongSamplingCounter[NUM_NETWORK_ACTIVITY_TYPES]; |
| 6221 | mNetworkPacketActivityCounters = new LongSamplingCounter[NUM_NETWORK_ACTIVITY_TYPES]; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 6222 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6223 | mNetworkByteActivityCounters[i] = new LongSamplingCounter(mBsi.mOnBatteryTimeBase); |
| 6224 | mNetworkPacketActivityCounters[i] = new LongSamplingCounter(mBsi.mOnBatteryTimeBase); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 6225 | } |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6226 | mMobileRadioActiveTime = new LongSamplingCounter(mBsi.mOnBatteryTimeBase); |
| 6227 | mMobileRadioActiveCount = new LongSamplingCounter(mBsi.mOnBatteryTimeBase); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6228 | } |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 6229 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6230 | /** |
| 6231 | * Clear all stats for this uid. Returns true if the uid is completely |
| 6232 | * inactive so can be dropped. |
| 6233 | */ |
Adam Lesinski | 5f212c8 | 2017-03-13 12:25:13 -0700 | [diff] [blame] | 6234 | @VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE) |
| 6235 | public boolean reset() { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6236 | boolean active = false; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6237 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 6238 | if (mWifiRunningTimer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6239 | active |= !mWifiRunningTimer.reset(false); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 6240 | active |= mWifiRunning; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6241 | } |
| 6242 | if (mFullWifiLockTimer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6243 | active |= !mFullWifiLockTimer.reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6244 | active |= mFullWifiLockOut; |
| 6245 | } |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 6246 | if (mWifiScanTimer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6247 | active |= !mWifiScanTimer.reset(false); |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 6248 | active |= mWifiScanStarted; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6249 | } |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 6250 | if (mWifiBatchedScanTimer != null) { |
| 6251 | for (int i = 0; i < NUM_WIFI_BATCHED_SCAN_BINS; i++) { |
| 6252 | if (mWifiBatchedScanTimer[i] != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6253 | active |= !mWifiBatchedScanTimer[i].reset(false); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 6254 | } |
| 6255 | } |
| 6256 | active |= (mWifiBatchedScanBinStarted != NO_BATCHED_SCAN_STARTED); |
| 6257 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6258 | if (mWifiMulticastTimer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6259 | active |= !mWifiMulticastTimer.reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6260 | active |= mWifiMulticastEnabled; |
| 6261 | } |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 6262 | |
| 6263 | active |= !resetTimerIfNotNull(mAudioTurnedOnTimer, false); |
| 6264 | active |= !resetTimerIfNotNull(mVideoTurnedOnTimer, false); |
| 6265 | active |= !resetTimerIfNotNull(mFlashlightTurnedOnTimer, false); |
| 6266 | active |= !resetTimerIfNotNull(mCameraTurnedOnTimer, false); |
| 6267 | active |= !resetTimerIfNotNull(mForegroundActivityTimer, false); |
| 6268 | active |= !resetTimerIfNotNull(mBluetoothScanTimer, false); |
| 6269 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 6270 | if (mProcessStateTimer != null) { |
| 6271 | for (int i = 0; i < NUM_PROCESS_STATE; i++) { |
| 6272 | if (mProcessStateTimer[i] != null) { |
| 6273 | active |= !mProcessStateTimer[i].reset(false); |
| 6274 | } |
| 6275 | } |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 6276 | active |= (mProcessState != ActivityManager.PROCESS_STATE_NONEXISTENT); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 6277 | } |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 6278 | if (mVibratorOnTimer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6279 | if (mVibratorOnTimer.reset(false)) { |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 6280 | mVibratorOnTimer.detach(); |
| 6281 | mVibratorOnTimer = null; |
| 6282 | } else { |
| 6283 | active = true; |
| 6284 | } |
| 6285 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6286 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6287 | if (mUserActivityCounters != null) { |
| 6288 | for (int i=0; i<NUM_USER_ACTIVITY_TYPES; i++) { |
| 6289 | mUserActivityCounters[i].reset(false); |
| 6290 | } |
| 6291 | } |
| 6292 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6293 | if (mNetworkByteActivityCounters != null) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 6294 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6295 | mNetworkByteActivityCounters[i].reset(false); |
| 6296 | mNetworkPacketActivityCounters[i].reset(false); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 6297 | } |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 6298 | mMobileRadioActiveTime.reset(false); |
| 6299 | mMobileRadioActiveCount.reset(false); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 6300 | } |
| 6301 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 6302 | if (mWifiControllerActivity != null) { |
| 6303 | mWifiControllerActivity.reset(false); |
| 6304 | } |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 6305 | |
Adam Lesinski | 1a2b39e | 2016-04-29 17:56:58 -0700 | [diff] [blame] | 6306 | if (mBluetoothControllerActivity != null) { |
| 6307 | mBluetoothControllerActivity.reset(false); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 6308 | } |
| 6309 | |
Adam Lesinski | 1a2b39e | 2016-04-29 17:56:58 -0700 | [diff] [blame] | 6310 | if (mModemControllerActivity != null) { |
| 6311 | mModemControllerActivity.reset(false); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 6312 | } |
| 6313 | |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 6314 | mUserCpuTime.reset(false); |
| 6315 | mSystemCpuTime.reset(false); |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 6316 | |
| 6317 | if (mCpuClusterSpeed != null) { |
| 6318 | for (LongSamplingCounter[] speeds : mCpuClusterSpeed) { |
| 6319 | if (speeds != null) { |
| 6320 | for (LongSamplingCounter speed : speeds) { |
| 6321 | if (speed != null) { |
| 6322 | speed.reset(false); |
| 6323 | } |
| 6324 | } |
| 6325 | } |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 6326 | } |
| 6327 | } |
| 6328 | |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 6329 | resetLongCounterIfNotNull(mMobileRadioApWakeupCount, false); |
| 6330 | resetLongCounterIfNotNull(mWifiRadioApWakeupCount, false); |
| 6331 | |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 6332 | final ArrayMap<String, Wakelock> wakeStats = mWakelockStats.getMap(); |
| 6333 | for (int iw=wakeStats.size()-1; iw>=0; iw--) { |
| 6334 | Wakelock wl = wakeStats.valueAt(iw); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 6335 | if (wl.reset()) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 6336 | wakeStats.removeAt(iw); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 6337 | } else { |
| 6338 | active = true; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6339 | } |
| 6340 | } |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 6341 | mWakelockStats.cleanup(); |
Bookatz | 2bffb5b | 2017-04-13 11:59:33 -0700 | [diff] [blame] | 6342 | final ArrayMap<String, DualTimer> syncStats = mSyncStats.getMap(); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 6343 | for (int is=syncStats.size()-1; is>=0; is--) { |
Bookatz | 2bffb5b | 2017-04-13 11:59:33 -0700 | [diff] [blame] | 6344 | DualTimer timer = syncStats.valueAt(is); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 6345 | if (timer.reset(false)) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 6346 | syncStats.removeAt(is); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 6347 | timer.detach(); |
| 6348 | } else { |
| 6349 | active = true; |
| 6350 | } |
| 6351 | } |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 6352 | mSyncStats.cleanup(); |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 6353 | final ArrayMap<String, DualTimer> jobStats = mJobStats.getMap(); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 6354 | for (int ij=jobStats.size()-1; ij>=0; ij--) { |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 6355 | DualTimer timer = jobStats.valueAt(ij); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 6356 | if (timer.reset(false)) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 6357 | jobStats.removeAt(ij); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 6358 | timer.detach(); |
| 6359 | } else { |
| 6360 | active = true; |
| 6361 | } |
| 6362 | } |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 6363 | mJobStats.cleanup(); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 6364 | for (int ise=mSensorStats.size()-1; ise>=0; ise--) { |
| 6365 | Sensor s = mSensorStats.valueAt(ise); |
| 6366 | if (s.reset()) { |
| 6367 | mSensorStats.removeAt(ise); |
| 6368 | } else { |
| 6369 | active = true; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6370 | } |
| 6371 | } |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 6372 | for (int ip=mProcessStats.size()-1; ip>=0; ip--) { |
| 6373 | Proc proc = mProcessStats.valueAt(ip); |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 6374 | proc.detach(); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6375 | } |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 6376 | mProcessStats.clear(); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 6377 | if (mPids.size() > 0) { |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 6378 | for (int i=mPids.size()-1; i>=0; i--) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 6379 | Pid pid = mPids.valueAt(i); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 6380 | if (pid.mWakeNesting > 0) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 6381 | active = true; |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 6382 | } else { |
| 6383 | mPids.removeAt(i); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 6384 | } |
| 6385 | } |
| 6386 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6387 | if (mPackageStats.size() > 0) { |
| 6388 | Iterator<Map.Entry<String, Pkg>> it = mPackageStats.entrySet().iterator(); |
| 6389 | while (it.hasNext()) { |
| 6390 | Map.Entry<String, Pkg> pkgEntry = it.next(); |
| 6391 | Pkg p = pkgEntry.getValue(); |
| 6392 | p.detach(); |
| 6393 | if (p.mServiceStats.size() > 0) { |
| 6394 | Iterator<Map.Entry<String, Pkg.Serv>> it2 |
| 6395 | = p.mServiceStats.entrySet().iterator(); |
| 6396 | while (it2.hasNext()) { |
| 6397 | Map.Entry<String, Pkg.Serv> servEntry = it2.next(); |
| 6398 | servEntry.getValue().detach(); |
| 6399 | } |
| 6400 | } |
| 6401 | } |
| 6402 | mPackageStats.clear(); |
| 6403 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6404 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 6405 | mLastStepUserTime = mLastStepSystemTime = 0; |
| 6406 | mCurStepUserTime = mCurStepSystemTime = 0; |
| 6407 | |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 6408 | mOnBatteryBackgroundTimeBase.reset(mBsi.mClocks.elapsedRealtime() * 1000, |
| 6409 | mBsi.mClocks.uptimeMillis() * 1000); |
| 6410 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6411 | if (!active) { |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 6412 | if (mWifiRunningTimer != null) { |
| 6413 | mWifiRunningTimer.detach(); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6414 | } |
| 6415 | if (mFullWifiLockTimer != null) { |
| 6416 | mFullWifiLockTimer.detach(); |
| 6417 | } |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 6418 | if (mWifiScanTimer != null) { |
| 6419 | mWifiScanTimer.detach(); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6420 | } |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 6421 | for (int i = 0; i < NUM_WIFI_BATCHED_SCAN_BINS; i++) { |
| 6422 | if (mWifiBatchedScanTimer[i] != null) { |
| 6423 | mWifiBatchedScanTimer[i].detach(); |
| 6424 | } |
| 6425 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6426 | if (mWifiMulticastTimer != null) { |
| 6427 | mWifiMulticastTimer.detach(); |
| 6428 | } |
| 6429 | if (mAudioTurnedOnTimer != null) { |
| 6430 | mAudioTurnedOnTimer.detach(); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 6431 | mAudioTurnedOnTimer = null; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6432 | } |
| 6433 | if (mVideoTurnedOnTimer != null) { |
| 6434 | mVideoTurnedOnTimer.detach(); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 6435 | mVideoTurnedOnTimer = null; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6436 | } |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 6437 | if (mFlashlightTurnedOnTimer != null) { |
| 6438 | mFlashlightTurnedOnTimer.detach(); |
| 6439 | mFlashlightTurnedOnTimer = null; |
| 6440 | } |
| 6441 | if (mCameraTurnedOnTimer != null) { |
| 6442 | mCameraTurnedOnTimer.detach(); |
| 6443 | mCameraTurnedOnTimer = null; |
| 6444 | } |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 6445 | if (mForegroundActivityTimer != null) { |
| 6446 | mForegroundActivityTimer.detach(); |
| 6447 | mForegroundActivityTimer = null; |
| 6448 | } |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 6449 | if (mBluetoothScanTimer != null) { |
| 6450 | mBluetoothScanTimer.detach(); |
| 6451 | mBluetoothScanTimer = null; |
| 6452 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6453 | if (mUserActivityCounters != null) { |
| 6454 | for (int i=0; i<NUM_USER_ACTIVITY_TYPES; i++) { |
| 6455 | mUserActivityCounters[i].detach(); |
| 6456 | } |
| 6457 | } |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6458 | if (mNetworkByteActivityCounters != null) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 6459 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6460 | mNetworkByteActivityCounters[i].detach(); |
| 6461 | mNetworkPacketActivityCounters[i].detach(); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 6462 | } |
| 6463 | } |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 6464 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 6465 | if (mWifiControllerActivity != null) { |
| 6466 | mWifiControllerActivity.detach(); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 6467 | } |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 6468 | |
| 6469 | if (mBluetoothControllerActivity != null) { |
| 6470 | mBluetoothControllerActivity.detach(); |
| 6471 | } |
| 6472 | |
| 6473 | if (mModemControllerActivity != null) { |
| 6474 | mModemControllerActivity.detach(); |
| 6475 | } |
| 6476 | |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 6477 | mPids.clear(); |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 6478 | |
| 6479 | mUserCpuTime.detach(); |
| 6480 | mSystemCpuTime.detach(); |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 6481 | |
| 6482 | if (mCpuClusterSpeed != null) { |
| 6483 | for (LongSamplingCounter[] cpuSpeeds : mCpuClusterSpeed) { |
| 6484 | if (cpuSpeeds != null) { |
| 6485 | for (LongSamplingCounter c : cpuSpeeds) { |
| 6486 | if (c != null) { |
| 6487 | c.detach(); |
| 6488 | } |
| 6489 | } |
| 6490 | } |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 6491 | } |
| 6492 | } |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 6493 | |
| 6494 | detachLongCounterIfNotNull(mMobileRadioApWakeupCount); |
| 6495 | detachLongCounterIfNotNull(mWifiRadioApWakeupCount); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6496 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6497 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6498 | return !active; |
| 6499 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6500 | |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 6501 | void writeToParcelLocked(Parcel out, long uptimeUs, long elapsedRealtimeUs) { |
| 6502 | mOnBatteryBackgroundTimeBase.writeToParcel(out, uptimeUs, elapsedRealtimeUs); |
| 6503 | |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 6504 | final ArrayMap<String, Wakelock> wakeStats = mWakelockStats.getMap(); |
| 6505 | int NW = wakeStats.size(); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 6506 | out.writeInt(NW); |
| 6507 | for (int iw=0; iw<NW; iw++) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 6508 | out.writeString(wakeStats.keyAt(iw)); |
| 6509 | Uid.Wakelock wakelock = wakeStats.valueAt(iw); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6510 | wakelock.writeToParcelLocked(out, elapsedRealtimeUs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6511 | } |
| 6512 | |
Bookatz | 2bffb5b | 2017-04-13 11:59:33 -0700 | [diff] [blame] | 6513 | final ArrayMap<String, DualTimer> syncStats = mSyncStats.getMap(); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 6514 | int NS = syncStats.size(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 6515 | out.writeInt(NS); |
| 6516 | for (int is=0; is<NS; is++) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 6517 | out.writeString(syncStats.keyAt(is)); |
Bookatz | 2bffb5b | 2017-04-13 11:59:33 -0700 | [diff] [blame] | 6518 | DualTimer timer = syncStats.valueAt(is); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 6519 | Timer.writeTimerToParcel(out, timer, elapsedRealtimeUs); |
| 6520 | } |
| 6521 | |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 6522 | final ArrayMap<String, DualTimer> jobStats = mJobStats.getMap(); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 6523 | int NJ = jobStats.size(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 6524 | out.writeInt(NJ); |
| 6525 | for (int ij=0; ij<NJ; ij++) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 6526 | out.writeString(jobStats.keyAt(ij)); |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 6527 | DualTimer timer = jobStats.valueAt(ij); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 6528 | Timer.writeTimerToParcel(out, timer, elapsedRealtimeUs); |
| 6529 | } |
| 6530 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 6531 | int NSE = mSensorStats.size(); |
| 6532 | out.writeInt(NSE); |
| 6533 | for (int ise=0; ise<NSE; ise++) { |
| 6534 | out.writeInt(mSensorStats.keyAt(ise)); |
| 6535 | Uid.Sensor sensor = mSensorStats.valueAt(ise); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6536 | sensor.writeToParcelLocked(out, elapsedRealtimeUs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6537 | } |
| 6538 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 6539 | int NP = mProcessStats.size(); |
| 6540 | out.writeInt(NP); |
| 6541 | for (int ip=0; ip<NP; ip++) { |
| 6542 | out.writeString(mProcessStats.keyAt(ip)); |
| 6543 | Uid.Proc proc = mProcessStats.valueAt(ip); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6544 | proc.writeToParcelLocked(out); |
| 6545 | } |
| 6546 | |
| 6547 | out.writeInt(mPackageStats.size()); |
| 6548 | for (Map.Entry<String, Uid.Pkg> pkgEntry : mPackageStats.entrySet()) { |
| 6549 | out.writeString(pkgEntry.getKey()); |
| 6550 | Uid.Pkg pkg = pkgEntry.getValue(); |
| 6551 | pkg.writeToParcelLocked(out); |
| 6552 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6553 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 6554 | if (mWifiRunningTimer != null) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6555 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6556 | mWifiRunningTimer.writeToParcel(out, elapsedRealtimeUs); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 6557 | } else { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6558 | out.writeInt(0); |
| 6559 | } |
| 6560 | if (mFullWifiLockTimer != null) { |
| 6561 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6562 | mFullWifiLockTimer.writeToParcel(out, elapsedRealtimeUs); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6563 | } else { |
| 6564 | out.writeInt(0); |
| 6565 | } |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 6566 | if (mWifiScanTimer != null) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6567 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6568 | mWifiScanTimer.writeToParcel(out, elapsedRealtimeUs); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6569 | } else { |
| 6570 | out.writeInt(0); |
| 6571 | } |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 6572 | for (int i = 0; i < NUM_WIFI_BATCHED_SCAN_BINS; i++) { |
| 6573 | if (mWifiBatchedScanTimer[i] != null) { |
| 6574 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6575 | mWifiBatchedScanTimer[i].writeToParcel(out, elapsedRealtimeUs); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 6576 | } else { |
| 6577 | out.writeInt(0); |
| 6578 | } |
| 6579 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6580 | if (mWifiMulticastTimer != null) { |
| 6581 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6582 | mWifiMulticastTimer.writeToParcel(out, elapsedRealtimeUs); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6583 | } else { |
| 6584 | out.writeInt(0); |
| 6585 | } |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 6586 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6587 | if (mAudioTurnedOnTimer != null) { |
| 6588 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6589 | mAudioTurnedOnTimer.writeToParcel(out, elapsedRealtimeUs); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6590 | } else { |
| 6591 | out.writeInt(0); |
| 6592 | } |
| 6593 | if (mVideoTurnedOnTimer != null) { |
| 6594 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6595 | mVideoTurnedOnTimer.writeToParcel(out, elapsedRealtimeUs); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6596 | } else { |
| 6597 | out.writeInt(0); |
| 6598 | } |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 6599 | if (mFlashlightTurnedOnTimer != null) { |
| 6600 | out.writeInt(1); |
| 6601 | mFlashlightTurnedOnTimer.writeToParcel(out, elapsedRealtimeUs); |
| 6602 | } else { |
| 6603 | out.writeInt(0); |
| 6604 | } |
| 6605 | if (mCameraTurnedOnTimer != null) { |
| 6606 | out.writeInt(1); |
| 6607 | mCameraTurnedOnTimer.writeToParcel(out, elapsedRealtimeUs); |
| 6608 | } else { |
| 6609 | out.writeInt(0); |
| 6610 | } |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 6611 | if (mForegroundActivityTimer != null) { |
| 6612 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6613 | mForegroundActivityTimer.writeToParcel(out, elapsedRealtimeUs); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 6614 | } else { |
| 6615 | out.writeInt(0); |
| 6616 | } |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 6617 | if (mBluetoothScanTimer != null) { |
| 6618 | out.writeInt(1); |
| 6619 | mBluetoothScanTimer.writeToParcel(out, elapsedRealtimeUs); |
| 6620 | } else { |
| 6621 | out.writeInt(0); |
| 6622 | } |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 6623 | for (int i = 0; i < NUM_PROCESS_STATE; i++) { |
| 6624 | if (mProcessStateTimer[i] != null) { |
| 6625 | out.writeInt(1); |
| 6626 | mProcessStateTimer[i].writeToParcel(out, elapsedRealtimeUs); |
| 6627 | } else { |
| 6628 | out.writeInt(0); |
| 6629 | } |
| 6630 | } |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 6631 | if (mVibratorOnTimer != null) { |
| 6632 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6633 | mVibratorOnTimer.writeToParcel(out, elapsedRealtimeUs); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 6634 | } else { |
| 6635 | out.writeInt(0); |
| 6636 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6637 | if (mUserActivityCounters != null) { |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 6638 | out.writeInt(1); |
| 6639 | for (int i=0; i<NUM_USER_ACTIVITY_TYPES; i++) { |
| 6640 | mUserActivityCounters[i].writeToParcel(out); |
| 6641 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6642 | } else { |
| 6643 | out.writeInt(0); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 6644 | } |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6645 | if (mNetworkByteActivityCounters != null) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 6646 | out.writeInt(1); |
| 6647 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6648 | mNetworkByteActivityCounters[i].writeToParcel(out); |
| 6649 | mNetworkPacketActivityCounters[i].writeToParcel(out); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 6650 | } |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 6651 | mMobileRadioActiveTime.writeToParcel(out); |
| 6652 | mMobileRadioActiveCount.writeToParcel(out); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 6653 | } else { |
| 6654 | out.writeInt(0); |
| 6655 | } |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 6656 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 6657 | if (mWifiControllerActivity != null) { |
| 6658 | out.writeInt(1); |
| 6659 | mWifiControllerActivity.writeToParcel(out, 0); |
| 6660 | } else { |
| 6661 | out.writeInt(0); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 6662 | } |
| 6663 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 6664 | if (mBluetoothControllerActivity != null) { |
| 6665 | out.writeInt(1); |
| 6666 | mBluetoothControllerActivity.writeToParcel(out, 0); |
| 6667 | } else { |
| 6668 | out.writeInt(0); |
| 6669 | } |
| 6670 | |
| 6671 | if (mModemControllerActivity != null) { |
| 6672 | out.writeInt(1); |
| 6673 | mModemControllerActivity.writeToParcel(out, 0); |
| 6674 | } else { |
| 6675 | out.writeInt(0); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 6676 | } |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 6677 | |
| 6678 | mUserCpuTime.writeToParcel(out); |
| 6679 | mSystemCpuTime.writeToParcel(out); |
| 6680 | |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 6681 | if (mCpuClusterSpeed != null) { |
| 6682 | out.writeInt(1); |
| 6683 | out.writeInt(mCpuClusterSpeed.length); |
| 6684 | for (LongSamplingCounter[] cpuSpeeds : mCpuClusterSpeed) { |
| 6685 | if (cpuSpeeds != null) { |
| 6686 | out.writeInt(1); |
| 6687 | out.writeInt(cpuSpeeds.length); |
| 6688 | for (LongSamplingCounter c : cpuSpeeds) { |
| 6689 | if (c != null) { |
| 6690 | out.writeInt(1); |
| 6691 | c.writeToParcel(out); |
| 6692 | } else { |
| 6693 | out.writeInt(0); |
| 6694 | } |
| 6695 | } |
| 6696 | } else { |
| 6697 | out.writeInt(0); |
| 6698 | } |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 6699 | } |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 6700 | } else { |
| 6701 | out.writeInt(0); |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 6702 | } |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 6703 | |
| 6704 | if (mMobileRadioApWakeupCount != null) { |
| 6705 | out.writeInt(1); |
| 6706 | mMobileRadioApWakeupCount.writeToParcel(out); |
| 6707 | } else { |
| 6708 | out.writeInt(0); |
| 6709 | } |
| 6710 | |
| 6711 | if (mWifiRadioApWakeupCount != null) { |
| 6712 | out.writeInt(1); |
| 6713 | mWifiRadioApWakeupCount.writeToParcel(out); |
| 6714 | } else { |
| 6715 | out.writeInt(0); |
| 6716 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6717 | } |
| 6718 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6719 | void readFromParcelLocked(TimeBase timeBase, TimeBase screenOffTimeBase, Parcel in) { |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 6720 | mOnBatteryBackgroundTimeBase.readFromParcel(in); |
| 6721 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6722 | int numWakelocks = in.readInt(); |
| 6723 | mWakelockStats.clear(); |
| 6724 | for (int j = 0; j < numWakelocks; j++) { |
| 6725 | String wakelockName = in.readString(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6726 | Uid.Wakelock wakelock = new Wakelock(mBsi, this); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6727 | wakelock.readFromParcelLocked(timeBase, screenOffTimeBase, in); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 6728 | mWakelockStats.add(wakelockName, wakelock); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6729 | } |
| 6730 | |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 6731 | int numSyncs = in.readInt(); |
| 6732 | mSyncStats.clear(); |
| 6733 | for (int j = 0; j < numSyncs; j++) { |
| 6734 | String syncName = in.readString(); |
| 6735 | if (in.readInt() != 0) { |
Bookatz | 2bffb5b | 2017-04-13 11:59:33 -0700 | [diff] [blame] | 6736 | mSyncStats.add(syncName, new DualTimer(mBsi.mClocks, Uid.this, SYNC, null, |
| 6737 | mBsi.mOnBatteryTimeBase, mOnBatteryBackgroundTimeBase, in)); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 6738 | } |
| 6739 | } |
| 6740 | |
| 6741 | int numJobs = in.readInt(); |
| 6742 | mJobStats.clear(); |
| 6743 | for (int j = 0; j < numJobs; j++) { |
| 6744 | String jobName = in.readString(); |
| 6745 | if (in.readInt() != 0) { |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 6746 | mJobStats.add(jobName, new DualTimer(mBsi.mClocks, Uid.this, JOB, null, |
| 6747 | mBsi.mOnBatteryTimeBase, mOnBatteryBackgroundTimeBase, in)); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 6748 | } |
| 6749 | } |
| 6750 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6751 | int numSensors = in.readInt(); |
| 6752 | mSensorStats.clear(); |
| 6753 | for (int k = 0; k < numSensors; k++) { |
| 6754 | int sensorNumber = in.readInt(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6755 | Uid.Sensor sensor = new Sensor(mBsi, this, sensorNumber); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 6756 | sensor.readFromParcelLocked(mBsi.mOnBatteryTimeBase, mOnBatteryBackgroundTimeBase, |
| 6757 | in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6758 | mSensorStats.put(sensorNumber, sensor); |
| 6759 | } |
| 6760 | |
| 6761 | int numProcs = in.readInt(); |
| 6762 | mProcessStats.clear(); |
| 6763 | for (int k = 0; k < numProcs; k++) { |
| 6764 | String processName = in.readString(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6765 | Uid.Proc proc = new Proc(mBsi, processName); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6766 | proc.readFromParcelLocked(in); |
| 6767 | mProcessStats.put(processName, proc); |
| 6768 | } |
| 6769 | |
| 6770 | int numPkgs = in.readInt(); |
| 6771 | mPackageStats.clear(); |
| 6772 | for (int l = 0; l < numPkgs; l++) { |
| 6773 | String packageName = in.readString(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6774 | Uid.Pkg pkg = new Pkg(mBsi); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6775 | pkg.readFromParcelLocked(in); |
| 6776 | mPackageStats.put(packageName, pkg); |
| 6777 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6778 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 6779 | mWifiRunning = false; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6780 | if (in.readInt() != 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6781 | mWifiRunningTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, WIFI_RUNNING, |
| 6782 | mBsi.mWifiRunningTimers, mBsi.mOnBatteryTimeBase, in); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 6783 | } else { |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 6784 | mWifiRunningTimer = null; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6785 | } |
| 6786 | mFullWifiLockOut = false; |
| 6787 | if (in.readInt() != 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6788 | mFullWifiLockTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, FULL_WIFI_LOCK, |
| 6789 | mBsi.mFullWifiLockTimers, mBsi.mOnBatteryTimeBase, in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6790 | } else { |
| 6791 | mFullWifiLockTimer = null; |
| 6792 | } |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 6793 | mWifiScanStarted = false; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6794 | if (in.readInt() != 0) { |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 6795 | mWifiScanTimer = new DualTimer(mBsi.mClocks, Uid.this, WIFI_SCAN, |
| 6796 | mBsi.mWifiScanTimers, mBsi.mOnBatteryTimeBase, mOnBatteryBackgroundTimeBase, |
| 6797 | in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6798 | } else { |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 6799 | mWifiScanTimer = null; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6800 | } |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 6801 | mWifiBatchedScanBinStarted = NO_BATCHED_SCAN_STARTED; |
| 6802 | for (int i = 0; i < NUM_WIFI_BATCHED_SCAN_BINS; i++) { |
| 6803 | if (in.readInt() != 0) { |
| 6804 | makeWifiBatchedScanBin(i, in); |
| 6805 | } else { |
| 6806 | mWifiBatchedScanTimer[i] = null; |
| 6807 | } |
| 6808 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6809 | mWifiMulticastEnabled = false; |
| 6810 | if (in.readInt() != 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6811 | mWifiMulticastTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, WIFI_MULTICAST_ENABLED, |
| 6812 | mBsi.mWifiMulticastTimers, mBsi.mOnBatteryTimeBase, in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6813 | } else { |
| 6814 | mWifiMulticastTimer = null; |
| 6815 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6816 | if (in.readInt() != 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6817 | mAudioTurnedOnTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, AUDIO_TURNED_ON, |
| 6818 | mBsi.mAudioTurnedOnTimers, mBsi.mOnBatteryTimeBase, in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6819 | } else { |
| 6820 | mAudioTurnedOnTimer = null; |
| 6821 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6822 | if (in.readInt() != 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6823 | mVideoTurnedOnTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, VIDEO_TURNED_ON, |
| 6824 | mBsi.mVideoTurnedOnTimers, mBsi.mOnBatteryTimeBase, in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6825 | } else { |
| 6826 | mVideoTurnedOnTimer = null; |
| 6827 | } |
| 6828 | if (in.readInt() != 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6829 | mFlashlightTurnedOnTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, |
| 6830 | FLASHLIGHT_TURNED_ON, mBsi.mFlashlightTurnedOnTimers, mBsi.mOnBatteryTimeBase, in); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 6831 | } else { |
| 6832 | mFlashlightTurnedOnTimer = null; |
| 6833 | } |
| 6834 | if (in.readInt() != 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6835 | mCameraTurnedOnTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, CAMERA_TURNED_ON, |
| 6836 | mBsi.mCameraTurnedOnTimers, mBsi.mOnBatteryTimeBase, in); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 6837 | } else { |
| 6838 | mCameraTurnedOnTimer = null; |
| 6839 | } |
| 6840 | if (in.readInt() != 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6841 | mForegroundActivityTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, |
| 6842 | FOREGROUND_ACTIVITY, null, mBsi.mOnBatteryTimeBase, in); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 6843 | } else { |
| 6844 | mForegroundActivityTimer = null; |
| 6845 | } |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 6846 | if (in.readInt() != 0) { |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 6847 | mBluetoothScanTimer = new DualTimer(mBsi.mClocks, Uid.this, BLUETOOTH_SCAN_ON, |
| 6848 | mBsi.mBluetoothScanOnTimers, mBsi.mOnBatteryTimeBase, |
| 6849 | mOnBatteryBackgroundTimeBase, in); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 6850 | } else { |
| 6851 | mBluetoothScanTimer = null; |
| 6852 | } |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 6853 | mProcessState = ActivityManager.PROCESS_STATE_NONEXISTENT; |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 6854 | for (int i = 0; i < NUM_PROCESS_STATE; i++) { |
| 6855 | if (in.readInt() != 0) { |
| 6856 | makeProcessState(i, in); |
| 6857 | } else { |
| 6858 | mProcessStateTimer[i] = null; |
| 6859 | } |
| 6860 | } |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 6861 | if (in.readInt() != 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6862 | mVibratorOnTimer = new BatchTimer(mBsi.mClocks, Uid.this, VIBRATOR_ON, |
| 6863 | mBsi.mOnBatteryTimeBase, in); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 6864 | } else { |
| 6865 | mVibratorOnTimer = null; |
| 6866 | } |
| 6867 | if (in.readInt() != 0) { |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 6868 | mUserActivityCounters = new Counter[NUM_USER_ACTIVITY_TYPES]; |
| 6869 | for (int i=0; i<NUM_USER_ACTIVITY_TYPES; i++) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6870 | mUserActivityCounters[i] = new Counter(mBsi.mOnBatteryTimeBase, in); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 6871 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6872 | } else { |
| 6873 | mUserActivityCounters = null; |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 6874 | } |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 6875 | if (in.readInt() != 0) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6876 | mNetworkByteActivityCounters = new LongSamplingCounter[NUM_NETWORK_ACTIVITY_TYPES]; |
| 6877 | mNetworkPacketActivityCounters |
| 6878 | = new LongSamplingCounter[NUM_NETWORK_ACTIVITY_TYPES]; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 6879 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6880 | mNetworkByteActivityCounters[i] |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6881 | = new LongSamplingCounter(mBsi.mOnBatteryTimeBase, in); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6882 | mNetworkPacketActivityCounters[i] |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6883 | = new LongSamplingCounter(mBsi.mOnBatteryTimeBase, in); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 6884 | } |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6885 | mMobileRadioActiveTime = new LongSamplingCounter(mBsi.mOnBatteryTimeBase, in); |
| 6886 | mMobileRadioActiveCount = new LongSamplingCounter(mBsi.mOnBatteryTimeBase, in); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 6887 | } else { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6888 | mNetworkByteActivityCounters = null; |
| 6889 | mNetworkPacketActivityCounters = null; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 6890 | } |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 6891 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 6892 | if (in.readInt() != 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6893 | mWifiControllerActivity = new ControllerActivityCounterImpl(mBsi.mOnBatteryTimeBase, |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 6894 | NUM_WIFI_TX_LEVELS, in); |
| 6895 | } else { |
| 6896 | mWifiControllerActivity = null; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 6897 | } |
| 6898 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 6899 | if (in.readInt() != 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6900 | mBluetoothControllerActivity = new ControllerActivityCounterImpl(mBsi.mOnBatteryTimeBase, |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 6901 | NUM_BT_TX_LEVELS, in); |
| 6902 | } else { |
| 6903 | mBluetoothControllerActivity = null; |
| 6904 | } |
| 6905 | |
| 6906 | if (in.readInt() != 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6907 | mModemControllerActivity = new ControllerActivityCounterImpl(mBsi.mOnBatteryTimeBase, |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 6908 | ModemActivityInfo.TX_POWER_LEVELS, in); |
| 6909 | } else { |
| 6910 | mModemControllerActivity = null; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 6911 | } |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 6912 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6913 | mUserCpuTime = new LongSamplingCounter(mBsi.mOnBatteryTimeBase, in); |
| 6914 | mSystemCpuTime = new LongSamplingCounter(mBsi.mOnBatteryTimeBase, in); |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 6915 | |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 6916 | if (in.readInt() != 0) { |
| 6917 | int numCpuClusters = in.readInt(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6918 | if (mBsi.mPowerProfile != null && mBsi.mPowerProfile.getNumCpuClusters() != numCpuClusters) { |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 6919 | throw new ParcelFormatException("Incompatible number of cpu clusters"); |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 6920 | } |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 6921 | |
| 6922 | mCpuClusterSpeed = new LongSamplingCounter[numCpuClusters][]; |
| 6923 | for (int cluster = 0; cluster < numCpuClusters; cluster++) { |
| 6924 | if (in.readInt() != 0) { |
| 6925 | int numSpeeds = in.readInt(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6926 | if (mBsi.mPowerProfile != null && |
| 6927 | mBsi.mPowerProfile.getNumSpeedStepsInCpuCluster(cluster) != numSpeeds) { |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 6928 | throw new ParcelFormatException("Incompatible number of cpu speeds"); |
| 6929 | } |
| 6930 | |
| 6931 | final LongSamplingCounter[] cpuSpeeds = new LongSamplingCounter[numSpeeds]; |
| 6932 | mCpuClusterSpeed[cluster] = cpuSpeeds; |
| 6933 | for (int speed = 0; speed < numSpeeds; speed++) { |
| 6934 | if (in.readInt() != 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6935 | cpuSpeeds[speed] = new LongSamplingCounter(mBsi.mOnBatteryTimeBase, in); |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 6936 | } |
| 6937 | } |
Adam Lesinski | a57a540 | 2015-09-28 10:21:33 -0700 | [diff] [blame] | 6938 | } else { |
| 6939 | mCpuClusterSpeed[cluster] = null; |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 6940 | } |
| 6941 | } |
| 6942 | } else { |
| 6943 | mCpuClusterSpeed = null; |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 6944 | } |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 6945 | |
| 6946 | if (in.readInt() != 0) { |
| 6947 | mMobileRadioApWakeupCount = new LongSamplingCounter(mBsi.mOnBatteryTimeBase, in); |
| 6948 | } else { |
| 6949 | mMobileRadioApWakeupCount = null; |
| 6950 | } |
| 6951 | |
| 6952 | if (in.readInt() != 0) { |
| 6953 | mWifiRadioApWakeupCount = new LongSamplingCounter(mBsi.mOnBatteryTimeBase, in); |
| 6954 | } else { |
| 6955 | mWifiRadioApWakeupCount = null; |
| 6956 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6957 | } |
| 6958 | |
| 6959 | /** |
| 6960 | * The statistics associated with a particular wake lock. |
| 6961 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6962 | public static class Wakelock extends BatteryStats.Uid.Wakelock { |
| 6963 | /** |
| 6964 | * BatteryStatsImpl that we are associated with. |
| 6965 | */ |
| 6966 | protected BatteryStatsImpl mBsi; |
| 6967 | |
| 6968 | /** |
| 6969 | * BatteryStatsImpl that we are associated with. |
| 6970 | */ |
| 6971 | protected Uid mUid; |
| 6972 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6973 | /** |
| 6974 | * How long (in ms) this uid has been keeping the device partially awake. |
| 6975 | */ |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 6976 | DurationTimer mTimerPartial; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6977 | |
| 6978 | /** |
| 6979 | * How long (in ms) this uid has been keeping the device fully awake. |
| 6980 | */ |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 6981 | StopwatchTimer mTimerFull; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6982 | |
| 6983 | /** |
| 6984 | * How long (in ms) this uid has had a window keeping the device awake. |
| 6985 | */ |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 6986 | StopwatchTimer mTimerWindow; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6987 | |
| 6988 | /** |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 6989 | * How long (in ms) this uid has had a draw wake lock. |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 6990 | */ |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 6991 | StopwatchTimer mTimerDraw; |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 6992 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6993 | public Wakelock(BatteryStatsImpl bsi, Uid uid) { |
| 6994 | mBsi = bsi; |
| 6995 | mUid = uid; |
| 6996 | } |
| 6997 | |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 6998 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6999 | * Reads a possibly null Timer from a Parcel. The timer is associated with the |
| 7000 | * proper timer pool from the given BatteryStatsImpl object. |
| 7001 | * |
| 7002 | * @param in the Parcel to be read from. |
| 7003 | * return a new Timer, or null. |
| 7004 | */ |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 7005 | private StopwatchTimer readStopwatchTimerFromParcel(int type, |
| 7006 | ArrayList<StopwatchTimer> pool, TimeBase timeBase, Parcel in) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7007 | if (in.readInt() == 0) { |
| 7008 | return null; |
| 7009 | } |
| 7010 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7011 | 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] | 7012 | } |
| 7013 | |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 7014 | /** |
| 7015 | * Reads a possibly null Timer from a Parcel. The timer is associated with the |
| 7016 | * proper timer pool from the given BatteryStatsImpl object. |
| 7017 | * |
| 7018 | * @param in the Parcel to be read from. |
| 7019 | * return a new Timer, or null. |
| 7020 | */ |
| 7021 | private DurationTimer readDurationTimerFromParcel(int type, |
| 7022 | ArrayList<StopwatchTimer> pool, TimeBase timeBase, Parcel in) { |
| 7023 | if (in.readInt() == 0) { |
| 7024 | return null; |
| 7025 | } |
| 7026 | |
| 7027 | return new DurationTimer(mBsi.mClocks, mUid, type, pool, timeBase, in); |
| 7028 | } |
| 7029 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7030 | boolean reset() { |
| 7031 | boolean wlactive = false; |
| 7032 | if (mTimerFull != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7033 | wlactive |= !mTimerFull.reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7034 | } |
| 7035 | if (mTimerPartial != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7036 | wlactive |= !mTimerPartial.reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7037 | } |
| 7038 | if (mTimerWindow != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7039 | wlactive |= !mTimerWindow.reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7040 | } |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 7041 | if (mTimerDraw != null) { |
| 7042 | wlactive |= !mTimerDraw.reset(false); |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 7043 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7044 | if (!wlactive) { |
| 7045 | if (mTimerFull != null) { |
| 7046 | mTimerFull.detach(); |
| 7047 | mTimerFull = null; |
| 7048 | } |
| 7049 | if (mTimerPartial != null) { |
| 7050 | mTimerPartial.detach(); |
| 7051 | mTimerPartial = null; |
| 7052 | } |
| 7053 | if (mTimerWindow != null) { |
| 7054 | mTimerWindow.detach(); |
| 7055 | mTimerWindow = null; |
| 7056 | } |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 7057 | if (mTimerDraw != null) { |
| 7058 | mTimerDraw.detach(); |
| 7059 | mTimerDraw = null; |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 7060 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7061 | } |
| 7062 | return !wlactive; |
| 7063 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7064 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7065 | void readFromParcelLocked(TimeBase timeBase, TimeBase screenOffTimeBase, Parcel in) { |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 7066 | mTimerPartial = readDurationTimerFromParcel(WAKE_TYPE_PARTIAL, |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7067 | mBsi.mPartialTimers, screenOffTimeBase, in); |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 7068 | mTimerFull = readStopwatchTimerFromParcel(WAKE_TYPE_FULL, |
| 7069 | mBsi.mFullTimers, timeBase, in); |
| 7070 | mTimerWindow = readStopwatchTimerFromParcel(WAKE_TYPE_WINDOW, |
| 7071 | mBsi.mWindowTimers, timeBase, in); |
| 7072 | mTimerDraw = readStopwatchTimerFromParcel(WAKE_TYPE_DRAW, |
| 7073 | mBsi.mDrawTimers, timeBase, in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7074 | } |
| 7075 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7076 | void writeToParcelLocked(Parcel out, long elapsedRealtimeUs) { |
| 7077 | Timer.writeTimerToParcel(out, mTimerPartial, elapsedRealtimeUs); |
| 7078 | Timer.writeTimerToParcel(out, mTimerFull, elapsedRealtimeUs); |
| 7079 | Timer.writeTimerToParcel(out, mTimerWindow, elapsedRealtimeUs); |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 7080 | Timer.writeTimerToParcel(out, mTimerDraw, elapsedRealtimeUs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7081 | } |
| 7082 | |
| 7083 | @Override |
| 7084 | public Timer getWakeTime(int type) { |
| 7085 | switch (type) { |
| 7086 | case WAKE_TYPE_FULL: return mTimerFull; |
| 7087 | case WAKE_TYPE_PARTIAL: return mTimerPartial; |
| 7088 | case WAKE_TYPE_WINDOW: return mTimerWindow; |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 7089 | case WAKE_TYPE_DRAW: return mTimerDraw; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7090 | default: throw new IllegalArgumentException("type = " + type); |
| 7091 | } |
| 7092 | } |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 7093 | |
| 7094 | public StopwatchTimer getStopwatchTimer(int type) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 7095 | switch (type) { |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 7096 | case WAKE_TYPE_PARTIAL: { |
| 7097 | DurationTimer t = mTimerPartial; |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 7098 | if (t == null) { |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 7099 | t = new DurationTimer(mBsi.mClocks, mUid, WAKE_TYPE_PARTIAL, |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7100 | mBsi.mPartialTimers, mBsi.mOnBatteryScreenOffTimeBase); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 7101 | mTimerPartial = t; |
| 7102 | } |
| 7103 | return t; |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 7104 | } |
| 7105 | case WAKE_TYPE_FULL: { |
| 7106 | StopwatchTimer t = mTimerFull; |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 7107 | if (t == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7108 | t = new StopwatchTimer(mBsi.mClocks, mUid, WAKE_TYPE_FULL, |
| 7109 | mBsi.mFullTimers, mBsi.mOnBatteryTimeBase); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 7110 | mTimerFull = t; |
| 7111 | } |
| 7112 | return t; |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 7113 | } |
| 7114 | case WAKE_TYPE_WINDOW: { |
| 7115 | StopwatchTimer t = mTimerWindow; |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 7116 | if (t == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7117 | t = new StopwatchTimer(mBsi.mClocks, mUid, WAKE_TYPE_WINDOW, |
| 7118 | mBsi.mWindowTimers, mBsi.mOnBatteryTimeBase); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 7119 | mTimerWindow = t; |
| 7120 | } |
| 7121 | return t; |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 7122 | } |
| 7123 | case WAKE_TYPE_DRAW: { |
| 7124 | StopwatchTimer t = mTimerDraw; |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 7125 | if (t == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7126 | t = new StopwatchTimer(mBsi.mClocks, mUid, WAKE_TYPE_DRAW, |
| 7127 | mBsi.mDrawTimers, mBsi.mOnBatteryTimeBase); |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 7128 | mTimerDraw = t; |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 7129 | } |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 7130 | return t; |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 7131 | } |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 7132 | default: |
| 7133 | throw new IllegalArgumentException("type=" + type); |
| 7134 | } |
| 7135 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7136 | } |
| 7137 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7138 | public static class Sensor extends BatteryStats.Uid.Sensor { |
| 7139 | /** |
| 7140 | * BatteryStatsImpl that we are associated with. |
| 7141 | */ |
| 7142 | protected BatteryStatsImpl mBsi; |
| 7143 | |
| 7144 | /** |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 7145 | * Uid that we are associated with. |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7146 | */ |
| 7147 | protected Uid mUid; |
| 7148 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7149 | final int mHandle; |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 7150 | DualTimer mTimer; |
Amith Yamasani | ab9ad19 | 2016-12-06 12:46:59 -0800 | [diff] [blame] | 7151 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7152 | public Sensor(BatteryStatsImpl bsi, Uid uid, int handle) { |
| 7153 | mBsi = bsi; |
| 7154 | mUid = uid; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7155 | mHandle = handle; |
| 7156 | } |
| 7157 | |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 7158 | private DualTimer readTimersFromParcel( |
| 7159 | TimeBase timeBase, TimeBase bgTimeBase, Parcel in) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7160 | if (in.readInt() == 0) { |
| 7161 | return null; |
| 7162 | } |
| 7163 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7164 | ArrayList<StopwatchTimer> pool = mBsi.mSensorTimers.get(mHandle); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7165 | if (pool == null) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 7166 | pool = new ArrayList<StopwatchTimer>(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7167 | mBsi.mSensorTimers.put(mHandle, pool); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7168 | } |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 7169 | return new DualTimer(mBsi.mClocks, mUid, 0, pool, timeBase, bgTimeBase, in); |
Amith Yamasani | ab9ad19 | 2016-12-06 12:46:59 -0800 | [diff] [blame] | 7170 | } |
| 7171 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7172 | boolean reset() { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7173 | if (mTimer.reset(true)) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7174 | mTimer = null; |
| 7175 | return true; |
| 7176 | } |
| 7177 | return false; |
| 7178 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7179 | |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 7180 | void readFromParcelLocked(TimeBase timeBase, TimeBase bgTimeBase, Parcel in) { |
| 7181 | mTimer = readTimersFromParcel(timeBase, bgTimeBase, in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7182 | } |
| 7183 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7184 | void writeToParcelLocked(Parcel out, long elapsedRealtimeUs) { |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 7185 | Timer.writeTimerToParcel(out, mTimer, elapsedRealtimeUs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7186 | } |
| 7187 | |
| 7188 | @Override |
| 7189 | public Timer getSensorTime() { |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 7190 | return mTimer; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7191 | } |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 7192 | |
| 7193 | @Override |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 7194 | public Timer getSensorBackgroundTime() { |
| 7195 | if (mTimer == null) { |
| 7196 | return null; |
| 7197 | } |
| 7198 | return mTimer.getSubTimer(); |
Amith Yamasani | ab9ad19 | 2016-12-06 12:46:59 -0800 | [diff] [blame] | 7199 | } |
| 7200 | |
| 7201 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7202 | public int getHandle() { |
| 7203 | return mHandle; |
| 7204 | } |
| 7205 | } |
| 7206 | |
| 7207 | /** |
| 7208 | * The statistics associated with a particular process. |
| 7209 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7210 | public static class Proc extends BatteryStats.Uid.Proc implements TimeBaseObs { |
| 7211 | /** |
| 7212 | * BatteryStatsImpl that we are associated with. |
| 7213 | */ |
| 7214 | protected BatteryStatsImpl mBsi; |
| 7215 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7216 | /** |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 7217 | * The name of this process. |
| 7218 | */ |
| 7219 | final String mName; |
| 7220 | |
| 7221 | /** |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 7222 | * Remains true until removed from the stats. |
| 7223 | */ |
| 7224 | boolean mActive = true; |
| 7225 | |
| 7226 | /** |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 7227 | * Total time (in ms) spent executing in user code. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7228 | */ |
| 7229 | long mUserTime; |
| 7230 | |
| 7231 | /** |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 7232 | * Total time (in ms) spent executing in kernel code. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7233 | */ |
| 7234 | long mSystemTime; |
| 7235 | |
| 7236 | /** |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 7237 | * Amount of time (in ms) the process was running in the foreground. |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 7238 | */ |
| 7239 | long mForegroundTime; |
| 7240 | |
| 7241 | /** |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 7242 | * Number of times the process has been started. |
| 7243 | */ |
| 7244 | int mStarts; |
| 7245 | |
| 7246 | /** |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 7247 | * Number of times the process has crashed. |
| 7248 | */ |
| 7249 | int mNumCrashes; |
| 7250 | |
| 7251 | /** |
| 7252 | * Number of times the process has had an ANR. |
| 7253 | */ |
| 7254 | int mNumAnrs; |
| 7255 | |
| 7256 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7257 | * The amount of user time loaded from a previous save. |
| 7258 | */ |
| 7259 | long mLoadedUserTime; |
| 7260 | |
| 7261 | /** |
| 7262 | * The amount of system time loaded from a previous save. |
| 7263 | */ |
| 7264 | long mLoadedSystemTime; |
| 7265 | |
| 7266 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 7267 | * The amount of foreground time loaded from a previous save. |
| 7268 | */ |
| 7269 | long mLoadedForegroundTime; |
| 7270 | |
| 7271 | /** |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 7272 | * The number of times the process has started from a previous save. |
| 7273 | */ |
| 7274 | int mLoadedStarts; |
| 7275 | |
| 7276 | /** |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 7277 | * 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] | 7278 | */ |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 7279 | int mLoadedNumCrashes; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7280 | |
| 7281 | /** |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 7282 | * 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] | 7283 | */ |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 7284 | int mLoadedNumAnrs; |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 7285 | |
| 7286 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7287 | * The amount of user time when last unplugged. |
| 7288 | */ |
| 7289 | long mUnpluggedUserTime; |
| 7290 | |
| 7291 | /** |
| 7292 | * The amount of system time when last unplugged. |
| 7293 | */ |
| 7294 | long mUnpluggedSystemTime; |
| 7295 | |
| 7296 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 7297 | * The amount of foreground time since unplugged. |
| 7298 | */ |
| 7299 | long mUnpluggedForegroundTime; |
| 7300 | |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 7301 | /** |
| 7302 | * The number of times the process has started before unplugged. |
| 7303 | */ |
| 7304 | int mUnpluggedStarts; |
| 7305 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 7306 | /** |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 7307 | * Number of times the process has crashed before unplugged. |
| 7308 | */ |
| 7309 | int mUnpluggedNumCrashes; |
| 7310 | |
| 7311 | /** |
| 7312 | * Number of times the process has had an ANR before unplugged. |
| 7313 | */ |
| 7314 | int mUnpluggedNumAnrs; |
| 7315 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 7316 | ArrayList<ExcessivePower> mExcessivePower; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 7317 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7318 | public Proc(BatteryStatsImpl bsi, String name) { |
| 7319 | mBsi = bsi; |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 7320 | mName = name; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7321 | mBsi.mOnBatteryTimeBase.add(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7322 | } |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 7323 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7324 | public void onTimeStarted(long elapsedRealtime, long baseUptime, long baseRealtime) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7325 | mUnpluggedUserTime = mUserTime; |
| 7326 | mUnpluggedSystemTime = mSystemTime; |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 7327 | mUnpluggedForegroundTime = mForegroundTime; |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 7328 | mUnpluggedStarts = mStarts; |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 7329 | mUnpluggedNumCrashes = mNumCrashes; |
| 7330 | mUnpluggedNumAnrs = mNumAnrs; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7331 | } |
| 7332 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7333 | public void onTimeStopped(long elapsedRealtime, long baseUptime, long baseRealtime) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7334 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7335 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7336 | void detach() { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 7337 | mActive = false; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7338 | mBsi.mOnBatteryTimeBase.remove(this); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7339 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7340 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 7341 | public int countExcessivePowers() { |
| 7342 | return mExcessivePower != null ? mExcessivePower.size() : 0; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 7343 | } |
| 7344 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 7345 | public ExcessivePower getExcessivePower(int i) { |
| 7346 | if (mExcessivePower != null) { |
| 7347 | return mExcessivePower.get(i); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 7348 | } |
| 7349 | return null; |
| 7350 | } |
| 7351 | |
| 7352 | public void addExcessiveWake(long overTime, long usedTime) { |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 7353 | if (mExcessivePower == null) { |
| 7354 | mExcessivePower = new ArrayList<ExcessivePower>(); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 7355 | } |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 7356 | ExcessivePower ew = new ExcessivePower(); |
| 7357 | ew.type = ExcessivePower.TYPE_WAKE; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 7358 | ew.overTime = overTime; |
| 7359 | ew.usedTime = usedTime; |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 7360 | mExcessivePower.add(ew); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 7361 | } |
| 7362 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 7363 | public void addExcessiveCpu(long overTime, long usedTime) { |
| 7364 | if (mExcessivePower == null) { |
| 7365 | mExcessivePower = new ArrayList<ExcessivePower>(); |
| 7366 | } |
| 7367 | ExcessivePower ew = new ExcessivePower(); |
| 7368 | ew.type = ExcessivePower.TYPE_CPU; |
| 7369 | ew.overTime = overTime; |
| 7370 | ew.usedTime = usedTime; |
| 7371 | mExcessivePower.add(ew); |
| 7372 | } |
| 7373 | |
| 7374 | void writeExcessivePowerToParcelLocked(Parcel out) { |
| 7375 | if (mExcessivePower == null) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 7376 | out.writeInt(0); |
| 7377 | return; |
| 7378 | } |
| 7379 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 7380 | final int N = mExcessivePower.size(); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 7381 | out.writeInt(N); |
| 7382 | for (int i=0; i<N; i++) { |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 7383 | ExcessivePower ew = mExcessivePower.get(i); |
| 7384 | out.writeInt(ew.type); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 7385 | out.writeLong(ew.overTime); |
| 7386 | out.writeLong(ew.usedTime); |
| 7387 | } |
| 7388 | } |
| 7389 | |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 7390 | void readExcessivePowerFromParcelLocked(Parcel in) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 7391 | final int N = in.readInt(); |
| 7392 | if (N == 0) { |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 7393 | mExcessivePower = null; |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 7394 | return; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 7395 | } |
| 7396 | |
Dianne Hackborn | 7b9c56f | 2010-12-07 11:14:53 -0800 | [diff] [blame] | 7397 | if (N > 10000) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 7398 | throw new ParcelFormatException( |
| 7399 | "File corrupt: too many excessive power entries " + N); |
Dianne Hackborn | 7b9c56f | 2010-12-07 11:14:53 -0800 | [diff] [blame] | 7400 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 7401 | |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 7402 | mExcessivePower = new ArrayList<>(); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 7403 | for (int i=0; i<N; i++) { |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 7404 | ExcessivePower ew = new ExcessivePower(); |
| 7405 | ew.type = in.readInt(); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 7406 | ew.overTime = in.readLong(); |
| 7407 | ew.usedTime = in.readLong(); |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 7408 | mExcessivePower.add(ew); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 7409 | } |
| 7410 | } |
| 7411 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7412 | void writeToParcelLocked(Parcel out) { |
| 7413 | out.writeLong(mUserTime); |
| 7414 | out.writeLong(mSystemTime); |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 7415 | out.writeLong(mForegroundTime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7416 | out.writeInt(mStarts); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 7417 | out.writeInt(mNumCrashes); |
| 7418 | out.writeInt(mNumAnrs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7419 | out.writeLong(mLoadedUserTime); |
| 7420 | out.writeLong(mLoadedSystemTime); |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 7421 | out.writeLong(mLoadedForegroundTime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7422 | out.writeInt(mLoadedStarts); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 7423 | out.writeInt(mLoadedNumCrashes); |
| 7424 | out.writeInt(mLoadedNumAnrs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7425 | out.writeLong(mUnpluggedUserTime); |
| 7426 | out.writeLong(mUnpluggedSystemTime); |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 7427 | out.writeLong(mUnpluggedForegroundTime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7428 | out.writeInt(mUnpluggedStarts); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 7429 | out.writeInt(mUnpluggedNumCrashes); |
| 7430 | out.writeInt(mUnpluggedNumAnrs); |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 7431 | writeExcessivePowerToParcelLocked(out); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7432 | } |
| 7433 | |
| 7434 | void readFromParcelLocked(Parcel in) { |
| 7435 | mUserTime = in.readLong(); |
| 7436 | mSystemTime = in.readLong(); |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 7437 | mForegroundTime = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7438 | mStarts = in.readInt(); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 7439 | mNumCrashes = in.readInt(); |
| 7440 | mNumAnrs = in.readInt(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7441 | mLoadedUserTime = in.readLong(); |
| 7442 | mLoadedSystemTime = in.readLong(); |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 7443 | mLoadedForegroundTime = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7444 | mLoadedStarts = in.readInt(); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 7445 | mLoadedNumCrashes = in.readInt(); |
| 7446 | mLoadedNumAnrs = in.readInt(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7447 | mUnpluggedUserTime = in.readLong(); |
| 7448 | mUnpluggedSystemTime = in.readLong(); |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 7449 | mUnpluggedForegroundTime = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7450 | mUnpluggedStarts = in.readInt(); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 7451 | mUnpluggedNumCrashes = in.readInt(); |
| 7452 | mUnpluggedNumAnrs = in.readInt(); |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 7453 | readExcessivePowerFromParcelLocked(in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7454 | } |
| 7455 | |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 7456 | public void addCpuTimeLocked(int utime, int stime) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7457 | mUserTime += utime; |
| 7458 | mSystemTime += stime; |
| 7459 | } |
| 7460 | |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 7461 | public void addForegroundTimeLocked(long ttime) { |
| 7462 | mForegroundTime += ttime; |
| 7463 | } |
| 7464 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7465 | public void incStartsLocked() { |
| 7466 | mStarts++; |
| 7467 | } |
| 7468 | |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 7469 | public void incNumCrashesLocked() { |
| 7470 | mNumCrashes++; |
| 7471 | } |
| 7472 | |
| 7473 | public void incNumAnrsLocked() { |
| 7474 | mNumAnrs++; |
| 7475 | } |
| 7476 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7477 | @Override |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 7478 | public boolean isActive() { |
| 7479 | return mActive; |
| 7480 | } |
| 7481 | |
| 7482 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7483 | public long getUserTime(int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 7484 | long val = mUserTime; |
| 7485 | if (which == STATS_CURRENT) { |
| 7486 | val -= mLoadedUserTime; |
| 7487 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 7488 | val -= mUnpluggedUserTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7489 | } |
| 7490 | return val; |
| 7491 | } |
| 7492 | |
| 7493 | @Override |
| 7494 | public long getSystemTime(int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 7495 | long val = mSystemTime; |
| 7496 | if (which == STATS_CURRENT) { |
| 7497 | val -= mLoadedSystemTime; |
| 7498 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 7499 | val -= mUnpluggedSystemTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7500 | } |
| 7501 | return val; |
| 7502 | } |
| 7503 | |
| 7504 | @Override |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 7505 | public long getForegroundTime(int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 7506 | long val = mForegroundTime; |
| 7507 | if (which == STATS_CURRENT) { |
| 7508 | val -= mLoadedForegroundTime; |
| 7509 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 7510 | val -= mUnpluggedForegroundTime; |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 7511 | } |
| 7512 | return val; |
| 7513 | } |
| 7514 | |
| 7515 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7516 | public int getStarts(int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 7517 | int val = mStarts; |
| 7518 | if (which == STATS_CURRENT) { |
| 7519 | val -= mLoadedStarts; |
| 7520 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 7521 | val -= mUnpluggedStarts; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7522 | } |
| 7523 | return val; |
| 7524 | } |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 7525 | |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 7526 | @Override |
| 7527 | public int getNumCrashes(int which) { |
| 7528 | int val = mNumCrashes; |
| 7529 | if (which == STATS_CURRENT) { |
| 7530 | val -= mLoadedNumCrashes; |
| 7531 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 7532 | val -= mUnpluggedNumCrashes; |
| 7533 | } |
| 7534 | return val; |
| 7535 | } |
| 7536 | |
| 7537 | @Override |
| 7538 | public int getNumAnrs(int which) { |
| 7539 | int val = mNumAnrs; |
| 7540 | if (which == STATS_CURRENT) { |
| 7541 | val -= mLoadedNumAnrs; |
| 7542 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 7543 | val -= mUnpluggedNumAnrs; |
| 7544 | } |
| 7545 | return val; |
| 7546 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7547 | } |
| 7548 | |
| 7549 | /** |
| 7550 | * The statistics associated with a particular package. |
| 7551 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7552 | public static class Pkg extends BatteryStats.Uid.Pkg implements TimeBaseObs { |
| 7553 | /** |
| 7554 | * BatteryStatsImpl that we are associated with. |
| 7555 | */ |
| 7556 | protected BatteryStatsImpl mBsi; |
| 7557 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7558 | /** |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 7559 | * 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] | 7560 | */ |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 7561 | ArrayMap<String, Counter> mWakeupAlarms = new ArrayMap<>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7562 | |
| 7563 | /** |
| 7564 | * The statics we have collected for this package's services. |
| 7565 | */ |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 7566 | final ArrayMap<String, Serv> mServiceStats = new ArrayMap<>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7567 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7568 | public Pkg(BatteryStatsImpl bsi) { |
| 7569 | mBsi = bsi; |
| 7570 | mBsi.mOnBatteryScreenOffTimeBase.add(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7571 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7572 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7573 | public void onTimeStarted(long elapsedRealtime, long baseUptime, long baseRealtime) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7574 | } |
| 7575 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7576 | public void onTimeStopped(long elapsedRealtime, long baseUptime, long baseRealtime) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7577 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7578 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7579 | void detach() { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7580 | mBsi.mOnBatteryScreenOffTimeBase.remove(this); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7581 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7582 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7583 | void readFromParcelLocked(Parcel in) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 7584 | int numWA = in.readInt(); |
| 7585 | mWakeupAlarms.clear(); |
| 7586 | for (int i=0; i<numWA; i++) { |
| 7587 | String tag = in.readString(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7588 | mWakeupAlarms.put(tag, new Counter(mBsi.mOnBatteryTimeBase, in)); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 7589 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7590 | |
| 7591 | int numServs = in.readInt(); |
| 7592 | mServiceStats.clear(); |
| 7593 | for (int m = 0; m < numServs; m++) { |
| 7594 | String serviceName = in.readString(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7595 | Uid.Pkg.Serv serv = new Serv(mBsi); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7596 | mServiceStats.put(serviceName, serv); |
| 7597 | |
| 7598 | serv.readFromParcelLocked(in); |
| 7599 | } |
| 7600 | } |
| 7601 | |
| 7602 | void writeToParcelLocked(Parcel out) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 7603 | int numWA = mWakeupAlarms.size(); |
| 7604 | out.writeInt(numWA); |
| 7605 | for (int i=0; i<numWA; i++) { |
| 7606 | out.writeString(mWakeupAlarms.keyAt(i)); |
| 7607 | mWakeupAlarms.valueAt(i).writeToParcel(out); |
| 7608 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7609 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 7610 | final int NS = mServiceStats.size(); |
| 7611 | out.writeInt(NS); |
| 7612 | for (int i=0; i<NS; i++) { |
| 7613 | out.writeString(mServiceStats.keyAt(i)); |
| 7614 | Uid.Pkg.Serv serv = mServiceStats.valueAt(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7615 | serv.writeToParcelLocked(out); |
| 7616 | } |
| 7617 | } |
| 7618 | |
| 7619 | @Override |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 7620 | public ArrayMap<String, ? extends BatteryStats.Counter> getWakeupAlarmStats() { |
| 7621 | return mWakeupAlarms; |
| 7622 | } |
| 7623 | |
| 7624 | public void noteWakeupAlarmLocked(String tag) { |
| 7625 | Counter c = mWakeupAlarms.get(tag); |
| 7626 | if (c == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7627 | c = new Counter(mBsi.mOnBatteryTimeBase); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 7628 | mWakeupAlarms.put(tag, c); |
| 7629 | } |
| 7630 | c.stepAtomic(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7631 | } |
| 7632 | |
| 7633 | @Override |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 7634 | public ArrayMap<String, ? extends BatteryStats.Uid.Pkg.Serv> getServiceStats() { |
| 7635 | return mServiceStats; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7636 | } |
| 7637 | |
| 7638 | /** |
| 7639 | * The statistics associated with a particular service. |
| 7640 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7641 | public static class Serv extends BatteryStats.Uid.Pkg.Serv implements TimeBaseObs { |
| 7642 | /** |
| 7643 | * BatteryStatsImpl that we are associated with. |
| 7644 | */ |
| 7645 | protected BatteryStatsImpl mBsi; |
| 7646 | |
| 7647 | /** |
| 7648 | * The android package in which this service resides. |
| 7649 | */ |
| 7650 | protected Pkg mPkg; |
| 7651 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7652 | /** |
| 7653 | * Total time (ms in battery uptime) the service has been left started. |
| 7654 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7655 | protected long mStartTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7656 | |
| 7657 | /** |
| 7658 | * If service has been started and not yet stopped, this is |
| 7659 | * when it was started. |
| 7660 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7661 | protected long mRunningSince; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7662 | |
| 7663 | /** |
| 7664 | * True if we are currently running. |
| 7665 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7666 | protected boolean mRunning; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7667 | |
| 7668 | /** |
| 7669 | * Total number of times startService() has been called. |
| 7670 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7671 | protected int mStarts; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7672 | |
| 7673 | /** |
| 7674 | * Total time (ms in battery uptime) the service has been left launched. |
| 7675 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7676 | protected long mLaunchedTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7677 | |
| 7678 | /** |
| 7679 | * If service has been launched and not yet exited, this is |
| 7680 | * when it was launched (ms in battery uptime). |
| 7681 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7682 | protected long mLaunchedSince; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7683 | |
| 7684 | /** |
| 7685 | * True if we are currently launched. |
| 7686 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7687 | protected boolean mLaunched; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7688 | |
| 7689 | /** |
| 7690 | * Total number times the service has been launched. |
| 7691 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7692 | protected int mLaunches; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7693 | |
| 7694 | /** |
| 7695 | * The amount of time spent started loaded from a previous save |
| 7696 | * (ms in battery uptime). |
| 7697 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7698 | protected long mLoadedStartTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7699 | |
| 7700 | /** |
| 7701 | * The number of starts loaded from a previous save. |
| 7702 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7703 | protected int mLoadedStarts; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7704 | |
| 7705 | /** |
| 7706 | * The number of launches loaded from a previous save. |
| 7707 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7708 | protected int mLoadedLaunches; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7709 | |
| 7710 | /** |
| 7711 | * The amount of time spent started as of the last run (ms |
| 7712 | * in battery uptime). |
| 7713 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7714 | protected long mLastStartTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7715 | |
| 7716 | /** |
| 7717 | * The number of starts as of the last run. |
| 7718 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7719 | protected int mLastStarts; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7720 | |
| 7721 | /** |
| 7722 | * The number of launches as of the last run. |
| 7723 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7724 | protected int mLastLaunches; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7725 | |
| 7726 | /** |
| 7727 | * The amount of time spent started when last unplugged (ms |
| 7728 | * in battery uptime). |
| 7729 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7730 | protected long mUnpluggedStartTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7731 | |
| 7732 | /** |
| 7733 | * The number of starts when last unplugged. |
| 7734 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7735 | protected int mUnpluggedStarts; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7736 | |
| 7737 | /** |
| 7738 | * The number of launches when last unplugged. |
| 7739 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7740 | protected int mUnpluggedLaunches; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7741 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7742 | /** |
| 7743 | * Construct a Serv. Also adds it to the on-battery time base as a listener. |
| 7744 | */ |
| 7745 | public Serv(BatteryStatsImpl bsi) { |
| 7746 | mBsi = bsi; |
| 7747 | mBsi.mOnBatteryTimeBase.add(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7748 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7749 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7750 | public void onTimeStarted(long elapsedRealtime, long baseUptime, |
| 7751 | long baseRealtime) { |
| 7752 | mUnpluggedStartTime = getStartTimeToNowLocked(baseUptime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7753 | mUnpluggedStarts = mStarts; |
| 7754 | mUnpluggedLaunches = mLaunches; |
| 7755 | } |
| 7756 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7757 | public void onTimeStopped(long elapsedRealtime, long baseUptime, |
| 7758 | long baseRealtime) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7759 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7760 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7761 | /** |
| 7762 | * Remove this Serv as a listener from the time base. |
| 7763 | */ |
| 7764 | public void detach() { |
| 7765 | mBsi.mOnBatteryTimeBase.remove(this); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7766 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7767 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7768 | public void readFromParcelLocked(Parcel in) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7769 | mStartTime = in.readLong(); |
| 7770 | mRunningSince = in.readLong(); |
| 7771 | mRunning = in.readInt() != 0; |
| 7772 | mStarts = in.readInt(); |
| 7773 | mLaunchedTime = in.readLong(); |
| 7774 | mLaunchedSince = in.readLong(); |
| 7775 | mLaunched = in.readInt() != 0; |
| 7776 | mLaunches = in.readInt(); |
| 7777 | mLoadedStartTime = in.readLong(); |
| 7778 | mLoadedStarts = in.readInt(); |
| 7779 | mLoadedLaunches = in.readInt(); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 7780 | mLastStartTime = 0; |
| 7781 | mLastStarts = 0; |
| 7782 | mLastLaunches = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7783 | mUnpluggedStartTime = in.readLong(); |
| 7784 | mUnpluggedStarts = in.readInt(); |
| 7785 | mUnpluggedLaunches = in.readInt(); |
| 7786 | } |
| 7787 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7788 | public void writeToParcelLocked(Parcel out) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7789 | out.writeLong(mStartTime); |
| 7790 | out.writeLong(mRunningSince); |
| 7791 | out.writeInt(mRunning ? 1 : 0); |
| 7792 | out.writeInt(mStarts); |
| 7793 | out.writeLong(mLaunchedTime); |
| 7794 | out.writeLong(mLaunchedSince); |
| 7795 | out.writeInt(mLaunched ? 1 : 0); |
| 7796 | out.writeInt(mLaunches); |
| 7797 | out.writeLong(mLoadedStartTime); |
| 7798 | out.writeInt(mLoadedStarts); |
| 7799 | out.writeInt(mLoadedLaunches); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7800 | out.writeLong(mUnpluggedStartTime); |
| 7801 | out.writeInt(mUnpluggedStarts); |
| 7802 | out.writeInt(mUnpluggedLaunches); |
| 7803 | } |
| 7804 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7805 | public long getLaunchTimeToNowLocked(long batteryUptime) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7806 | if (!mLaunched) return mLaunchedTime; |
| 7807 | return mLaunchedTime + batteryUptime - mLaunchedSince; |
| 7808 | } |
| 7809 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7810 | public long getStartTimeToNowLocked(long batteryUptime) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7811 | if (!mRunning) return mStartTime; |
| 7812 | return mStartTime + batteryUptime - mRunningSince; |
| 7813 | } |
| 7814 | |
| 7815 | public void startLaunchedLocked() { |
| 7816 | if (!mLaunched) { |
| 7817 | mLaunches++; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7818 | mLaunchedSince = mBsi.getBatteryUptimeLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7819 | mLaunched = true; |
| 7820 | } |
| 7821 | } |
| 7822 | |
| 7823 | public void stopLaunchedLocked() { |
| 7824 | if (mLaunched) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7825 | long time = mBsi.getBatteryUptimeLocked() - mLaunchedSince; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7826 | if (time > 0) { |
| 7827 | mLaunchedTime += time; |
| 7828 | } else { |
| 7829 | mLaunches--; |
| 7830 | } |
| 7831 | mLaunched = false; |
| 7832 | } |
| 7833 | } |
| 7834 | |
| 7835 | public void startRunningLocked() { |
| 7836 | if (!mRunning) { |
| 7837 | mStarts++; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7838 | mRunningSince = mBsi.getBatteryUptimeLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7839 | mRunning = true; |
| 7840 | } |
| 7841 | } |
| 7842 | |
| 7843 | public void stopRunningLocked() { |
| 7844 | if (mRunning) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7845 | long time = mBsi.getBatteryUptimeLocked() - mRunningSince; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7846 | if (time > 0) { |
| 7847 | mStartTime += time; |
| 7848 | } else { |
| 7849 | mStarts--; |
| 7850 | } |
| 7851 | mRunning = false; |
| 7852 | } |
| 7853 | } |
| 7854 | |
| 7855 | public BatteryStatsImpl getBatteryStats() { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7856 | return mBsi; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7857 | } |
| 7858 | |
| 7859 | @Override |
| 7860 | public int getLaunches(int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 7861 | int val = mLaunches; |
| 7862 | if (which == STATS_CURRENT) { |
| 7863 | val -= mLoadedLaunches; |
| 7864 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 7865 | val -= mUnpluggedLaunches; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7866 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7867 | return val; |
| 7868 | } |
| 7869 | |
| 7870 | @Override |
| 7871 | public long getStartTime(long now, int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 7872 | long val = getStartTimeToNowLocked(now); |
| 7873 | if (which == STATS_CURRENT) { |
| 7874 | val -= mLoadedStartTime; |
| 7875 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 7876 | val -= mUnpluggedStartTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7877 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7878 | return val; |
| 7879 | } |
| 7880 | |
| 7881 | @Override |
| 7882 | public int getStarts(int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 7883 | int val = mStarts; |
| 7884 | if (which == STATS_CURRENT) { |
| 7885 | val -= mLoadedStarts; |
| 7886 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 7887 | val -= mUnpluggedStarts; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7888 | } |
| 7889 | |
| 7890 | return val; |
| 7891 | } |
| 7892 | } |
| 7893 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7894 | final Serv newServiceStatsLocked() { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7895 | return new Serv(mBsi); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7896 | } |
| 7897 | } |
| 7898 | |
| 7899 | /** |
| 7900 | * Retrieve the statistics object for a particular process, creating |
| 7901 | * if needed. |
| 7902 | */ |
| 7903 | public Proc getProcessStatsLocked(String name) { |
| 7904 | Proc ps = mProcessStats.get(name); |
| 7905 | if (ps == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7906 | ps = new Proc(mBsi, name); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7907 | mProcessStats.put(name, ps); |
| 7908 | } |
| 7909 | |
| 7910 | return ps; |
| 7911 | } |
| 7912 | |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 7913 | public void updateUidProcessStateLocked(int procState) { |
| 7914 | int uidRunningState; |
| 7915 | if (procState == ActivityManager.PROCESS_STATE_NONEXISTENT) { |
| 7916 | uidRunningState = ActivityManager.PROCESS_STATE_NONEXISTENT; |
| 7917 | } else if (procState == ActivityManager.PROCESS_STATE_TOP) { |
| 7918 | uidRunningState = PROCESS_STATE_TOP; |
| 7919 | } else if (procState <= ActivityManager.PROCESS_STATE_FOREGROUND_SERVICE) { |
| 7920 | // Persistent and other foreground states go here. |
| 7921 | uidRunningState = PROCESS_STATE_FOREGROUND_SERVICE; |
| 7922 | } else if (procState <= ActivityManager.PROCESS_STATE_TOP_SLEEPING) { |
| 7923 | uidRunningState = PROCESS_STATE_TOP_SLEEPING; |
| 7924 | } else if (procState <= ActivityManager.PROCESS_STATE_IMPORTANT_FOREGROUND) { |
| 7925 | // Persistent and other foreground states go here. |
| 7926 | uidRunningState = PROCESS_STATE_FOREGROUND; |
| 7927 | } else if (procState <= ActivityManager.PROCESS_STATE_RECEIVER) { |
| 7928 | uidRunningState = PROCESS_STATE_BACKGROUND; |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 7929 | } else { |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 7930 | uidRunningState = PROCESS_STATE_CACHED; |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 7931 | } |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 7932 | |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 7933 | if (mProcessState == uidRunningState) return; |
| 7934 | |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 7935 | final long elapsedRealtimeMs = mBsi.mClocks.elapsedRealtime(); |
| 7936 | final long uptimeMs = mBsi.mClocks.uptimeMillis(); |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 7937 | |
| 7938 | if (mProcessState != ActivityManager.PROCESS_STATE_NONEXISTENT) { |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 7939 | mProcessStateTimer[mProcessState].stopRunningLocked(elapsedRealtimeMs); |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 7940 | } |
| 7941 | mProcessState = uidRunningState; |
| 7942 | if (uidRunningState != ActivityManager.PROCESS_STATE_NONEXISTENT) { |
| 7943 | if (mProcessStateTimer[uidRunningState] == null) { |
| 7944 | makeProcessState(uidRunningState, null); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 7945 | } |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 7946 | mProcessStateTimer[uidRunningState].startRunningLocked(elapsedRealtimeMs); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 7947 | } |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 7948 | |
| 7949 | updateBgTimeBase(uptimeMs * 1000, elapsedRealtimeMs * 1000); |
| 7950 | } |
| 7951 | |
| 7952 | public boolean updateBgTimeBase(long uptimeUs, long realtimeUs) { |
| 7953 | // Note that PROCESS_STATE_CACHED and ActivityManager.PROCESS_STATE_NONEXISTENT is |
| 7954 | // also considered to be 'background' for our purposes, because it's not foreground. |
| 7955 | boolean isBgAndUnplugged = mBsi.mOnBatteryTimeBase.isRunning() |
| 7956 | && mProcessState >= PROCESS_STATE_BACKGROUND; |
| 7957 | return mOnBatteryBackgroundTimeBase.setRunning(isBgAndUnplugged, uptimeUs, realtimeUs); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 7958 | } |
| 7959 | |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 7960 | public SparseArray<? extends Pid> getPidStats() { |
| 7961 | return mPids; |
| 7962 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7963 | |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 7964 | public Pid getPidStatsLocked(int pid) { |
| 7965 | Pid p = mPids.get(pid); |
| 7966 | if (p == null) { |
| 7967 | p = new Pid(); |
| 7968 | mPids.put(pid, p); |
| 7969 | } |
| 7970 | return p; |
| 7971 | } |
| 7972 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7973 | /** |
| 7974 | * Retrieve the statistics object for a particular service, creating |
| 7975 | * if needed. |
| 7976 | */ |
| 7977 | public Pkg getPackageStatsLocked(String name) { |
| 7978 | Pkg ps = mPackageStats.get(name); |
| 7979 | if (ps == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7980 | ps = new Pkg(mBsi); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7981 | mPackageStats.put(name, ps); |
| 7982 | } |
| 7983 | |
| 7984 | return ps; |
| 7985 | } |
| 7986 | |
| 7987 | /** |
| 7988 | * Retrieve the statistics object for a particular service, creating |
| 7989 | * if needed. |
| 7990 | */ |
| 7991 | public Pkg.Serv getServiceStatsLocked(String pkg, String serv) { |
| 7992 | Pkg ps = getPackageStatsLocked(pkg); |
| 7993 | Pkg.Serv ss = ps.mServiceStats.get(serv); |
| 7994 | if (ss == null) { |
| 7995 | ss = ps.newServiceStatsLocked(); |
| 7996 | ps.mServiceStats.put(serv, ss); |
| 7997 | } |
| 7998 | |
| 7999 | return ss; |
| 8000 | } |
| 8001 | |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 8002 | public void readSyncSummaryFromParcelLocked(String name, Parcel in) { |
Bookatz | 2bffb5b | 2017-04-13 11:59:33 -0700 | [diff] [blame] | 8003 | DualTimer timer = mSyncStats.instantiateObject(); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 8004 | timer.readSummaryFromParcelLocked(in); |
| 8005 | mSyncStats.add(name, timer); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 8006 | } |
| 8007 | |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 8008 | public void readJobSummaryFromParcelLocked(String name, Parcel in) { |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 8009 | DualTimer timer = mJobStats.instantiateObject(); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 8010 | timer.readSummaryFromParcelLocked(in); |
| 8011 | mJobStats.add(name, timer); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 8012 | } |
| 8013 | |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 8014 | public void readWakeSummaryFromParcelLocked(String wlName, Parcel in) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8015 | Wakelock wl = new Wakelock(mBsi, this); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 8016 | mWakelockStats.add(wlName, wl); |
| 8017 | if (in.readInt() != 0) { |
| 8018 | wl.getStopwatchTimer(WAKE_TYPE_FULL).readSummaryFromParcelLocked(in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8019 | } |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 8020 | if (in.readInt() != 0) { |
| 8021 | wl.getStopwatchTimer(WAKE_TYPE_PARTIAL).readSummaryFromParcelLocked(in); |
| 8022 | } |
| 8023 | if (in.readInt() != 0) { |
| 8024 | wl.getStopwatchTimer(WAKE_TYPE_WINDOW).readSummaryFromParcelLocked(in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8025 | } |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 8026 | if (in.readInt() != 0) { |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 8027 | wl.getStopwatchTimer(WAKE_TYPE_DRAW).readSummaryFromParcelLocked(in); |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 8028 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8029 | } |
| 8030 | |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 8031 | public DualTimer getSensorTimerLocked(int sensor, boolean create) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8032 | Sensor se = mSensorStats.get(sensor); |
| 8033 | if (se == null) { |
| 8034 | if (!create) { |
| 8035 | return null; |
| 8036 | } |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8037 | se = new Sensor(mBsi, this, sensor); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8038 | mSensorStats.put(sensor, se); |
| 8039 | } |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 8040 | DualTimer t = se.mTimer; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8041 | if (t != null) { |
| 8042 | return t; |
| 8043 | } |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8044 | ArrayList<StopwatchTimer> timers = mBsi.mSensorTimers.get(sensor); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8045 | if (timers == null) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 8046 | timers = new ArrayList<StopwatchTimer>(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8047 | mBsi.mSensorTimers.put(sensor, timers); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8048 | } |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 8049 | t = new DualTimer(mBsi.mClocks, this, BatteryStats.SENSOR, timers, |
| 8050 | mBsi.mOnBatteryTimeBase, mOnBatteryBackgroundTimeBase); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8051 | se.mTimer = t; |
| 8052 | return t; |
| 8053 | } |
| 8054 | |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 8055 | public void noteStartSyncLocked(String name, long elapsedRealtimeMs) { |
Bookatz | 2bffb5b | 2017-04-13 11:59:33 -0700 | [diff] [blame] | 8056 | DualTimer t = mSyncStats.startObject(name); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 8057 | if (t != null) { |
| 8058 | t.startRunningLocked(elapsedRealtimeMs); |
| 8059 | } |
| 8060 | } |
| 8061 | |
| 8062 | public void noteStopSyncLocked(String name, long elapsedRealtimeMs) { |
Bookatz | 2bffb5b | 2017-04-13 11:59:33 -0700 | [diff] [blame] | 8063 | DualTimer t = mSyncStats.stopObject(name); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 8064 | if (t != null) { |
| 8065 | t.stopRunningLocked(elapsedRealtimeMs); |
| 8066 | } |
| 8067 | } |
| 8068 | |
| 8069 | public void noteStartJobLocked(String name, long elapsedRealtimeMs) { |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 8070 | DualTimer t = mJobStats.startObject(name); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 8071 | if (t != null) { |
| 8072 | t.startRunningLocked(elapsedRealtimeMs); |
| 8073 | } |
| 8074 | } |
| 8075 | |
| 8076 | public void noteStopJobLocked(String name, long elapsedRealtimeMs) { |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 8077 | DualTimer t = mJobStats.stopObject(name); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 8078 | if (t != null) { |
| 8079 | t.stopRunningLocked(elapsedRealtimeMs); |
| 8080 | } |
| 8081 | } |
| 8082 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8083 | public void noteStartWakeLocked(int pid, String name, int type, long elapsedRealtimeMs) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 8084 | Wakelock wl = mWakelockStats.startObject(name); |
| 8085 | if (wl != null) { |
| 8086 | wl.getStopwatchTimer(type).startRunningLocked(elapsedRealtimeMs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8087 | } |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 8088 | if (pid >= 0 && type == WAKE_TYPE_PARTIAL) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 8089 | Pid p = getPidStatsLocked(pid); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 8090 | if (p.mWakeNesting++ == 0) { |
| 8091 | p.mWakeStartMs = elapsedRealtimeMs; |
Dianne Hackborn | b8071d79 | 2010-09-09 16:45:15 -0700 | [diff] [blame] | 8092 | } |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 8093 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8094 | } |
| 8095 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8096 | public void noteStopWakeLocked(int pid, String name, int type, long elapsedRealtimeMs) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 8097 | Wakelock wl = mWakelockStats.stopObject(name); |
| 8098 | if (wl != null) { |
| 8099 | wl.getStopwatchTimer(type).stopRunningLocked(elapsedRealtimeMs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8100 | } |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 8101 | if (pid >= 0 && type == WAKE_TYPE_PARTIAL) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 8102 | Pid p = mPids.get(pid); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 8103 | if (p != null && p.mWakeNesting > 0) { |
| 8104 | if (p.mWakeNesting-- == 1) { |
| 8105 | p.mWakeSumMs += elapsedRealtimeMs - p.mWakeStartMs; |
| 8106 | p.mWakeStartMs = 0; |
| 8107 | } |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 8108 | } |
| 8109 | } |
| 8110 | } |
| 8111 | |
| 8112 | public void reportExcessiveWakeLocked(String proc, long overTime, long usedTime) { |
| 8113 | Proc p = getProcessStatsLocked(proc); |
| 8114 | if (p != null) { |
| 8115 | p.addExcessiveWake(overTime, usedTime); |
| 8116 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8117 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 8118 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 8119 | public void reportExcessiveCpuLocked(String proc, long overTime, long usedTime) { |
| 8120 | Proc p = getProcessStatsLocked(proc); |
| 8121 | if (p != null) { |
| 8122 | p.addExcessiveCpu(overTime, usedTime); |
| 8123 | } |
| 8124 | } |
| 8125 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8126 | public void noteStartSensor(int sensor, long elapsedRealtimeMs) { |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 8127 | DualTimer t = getSensorTimerLocked(sensor, /* create= */ true); |
Amith Yamasani | 154d124 | 2017-02-16 10:01:48 -0800 | [diff] [blame] | 8128 | t.startRunningLocked(elapsedRealtimeMs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8129 | } |
| 8130 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8131 | public void noteStopSensor(int sensor, long elapsedRealtimeMs) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8132 | // Don't create a timer if one doesn't already exist |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 8133 | DualTimer t = getSensorTimerLocked(sensor, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8134 | if (t != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8135 | t.stopRunningLocked(elapsedRealtimeMs); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 8136 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8137 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 8138 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8139 | public void noteStartGps(long elapsedRealtimeMs) { |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 8140 | noteStartSensor(Sensor.GPS, elapsedRealtimeMs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8141 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 8142 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8143 | public void noteStopGps(long elapsedRealtimeMs) { |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 8144 | noteStopSensor(Sensor.GPS, elapsedRealtimeMs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8145 | } |
| 8146 | |
| 8147 | public BatteryStatsImpl getBatteryStats() { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8148 | return mBsi; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8149 | } |
| 8150 | } |
| 8151 | |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8152 | public BatteryStatsImpl(File systemDir, Handler handler, ExternalStatsSync externalSync) { |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 8153 | this(new SystemClocks(), systemDir, handler, externalSync, null); |
| 8154 | } |
| 8155 | |
| 8156 | public BatteryStatsImpl(File systemDir, Handler handler, ExternalStatsSync externalSync, |
| 8157 | PlatformIdleStateCallback cb) { |
| 8158 | this(new SystemClocks(), systemDir, handler, externalSync, cb); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8159 | } |
| 8160 | |
| 8161 | public BatteryStatsImpl(Clocks clocks, File systemDir, Handler handler, |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 8162 | ExternalStatsSync externalSync, PlatformIdleStateCallback cb) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8163 | init(clocks); |
| 8164 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 8165 | if (systemDir != null) { |
| 8166 | mFile = new JournaledFile(new File(systemDir, "batterystats.bin"), |
| 8167 | new File(systemDir, "batterystats.bin.tmp")); |
| 8168 | } else { |
| 8169 | mFile = null; |
| 8170 | } |
| 8171 | mCheckinFile = new AtomicFile(new File(systemDir, "batterystats-checkin.bin")); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 8172 | mDailyFile = new AtomicFile(new File(systemDir, "batterystats-daily.xml")); |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8173 | mExternalSync = externalSync; |
Jeff Brown | 6f357d3 | 2014-01-15 20:40:55 -0800 | [diff] [blame] | 8174 | mHandler = new MyHandler(handler.getLooper()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8175 | mStartCount++; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8176 | mScreenOnTimer = new StopwatchTimer(mClocks, null, -1, null, mOnBatteryTimeBase); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 8177 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8178 | mScreenBrightnessTimer[i] = new StopwatchTimer(mClocks, null, -100-i, null, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8179 | mOnBatteryTimeBase); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 8180 | } |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8181 | mInteractiveTimer = new StopwatchTimer(mClocks, null, -10, null, mOnBatteryTimeBase); |
| 8182 | mPowerSaveModeEnabledTimer = new StopwatchTimer(mClocks, null, -2, null, |
| 8183 | mOnBatteryTimeBase); |
| 8184 | mDeviceIdleModeLightTimer = new StopwatchTimer(mClocks, null, -11, null, |
| 8185 | mOnBatteryTimeBase); |
| 8186 | mDeviceIdleModeFullTimer = new StopwatchTimer(mClocks, null, -14, null, mOnBatteryTimeBase); |
| 8187 | mDeviceLightIdlingTimer = new StopwatchTimer(mClocks, null, -15, null, mOnBatteryTimeBase); |
| 8188 | mDeviceIdlingTimer = new StopwatchTimer(mClocks, null, -12, null, mOnBatteryTimeBase); |
| 8189 | mPhoneOnTimer = new StopwatchTimer(mClocks, null, -3, null, mOnBatteryTimeBase); |
| 8190 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
| 8191 | mPhoneSignalStrengthsTimer[i] = new StopwatchTimer(mClocks, null, -200-i, null, |
| 8192 | mOnBatteryTimeBase); |
| 8193 | } |
| 8194 | mPhoneSignalScanningTimer = new StopwatchTimer(mClocks, null, -200+1, null, |
| 8195 | mOnBatteryTimeBase); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 8196 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8197 | mPhoneDataConnectionsTimer[i] = new StopwatchTimer(mClocks, null, -300-i, null, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8198 | mOnBatteryTimeBase); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 8199 | } |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 8200 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8201 | mNetworkByteActivityCounters[i] = new LongSamplingCounter(mOnBatteryTimeBase); |
| 8202 | mNetworkPacketActivityCounters[i] = new LongSamplingCounter(mOnBatteryTimeBase); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 8203 | } |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 8204 | mWifiActivity = new ControllerActivityCounterImpl(mOnBatteryTimeBase, NUM_WIFI_TX_LEVELS); |
| 8205 | mBluetoothActivity = new ControllerActivityCounterImpl(mOnBatteryTimeBase, |
| 8206 | NUM_BT_TX_LEVELS); |
| 8207 | mModemActivity = new ControllerActivityCounterImpl(mOnBatteryTimeBase, |
| 8208 | ModemActivityInfo.TX_POWER_LEVELS); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8209 | mMobileRadioActiveTimer = new StopwatchTimer(mClocks, null, -400, null, mOnBatteryTimeBase); |
| 8210 | mMobileRadioActivePerAppTimer = new StopwatchTimer(mClocks, null, -401, null, |
| 8211 | mOnBatteryTimeBase); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 8212 | mMobileRadioActiveAdjustedTime = new LongSamplingCounter(mOnBatteryTimeBase); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8213 | mMobileRadioActiveUnknownTime = new LongSamplingCounter(mOnBatteryTimeBase); |
| 8214 | mMobileRadioActiveUnknownCount = new LongSamplingCounter(mOnBatteryTimeBase); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8215 | mWifiOnTimer = new StopwatchTimer(mClocks, null, -4, null, mOnBatteryTimeBase); |
| 8216 | mGlobalWifiRunningTimer = new StopwatchTimer(mClocks, null, -5, null, mOnBatteryTimeBase); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 8217 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8218 | mWifiStateTimer[i] = new StopwatchTimer(mClocks, null, -600-i, null, |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 8219 | mOnBatteryTimeBase); |
| 8220 | } |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8221 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
| 8222 | mWifiSupplStateTimer[i] = new StopwatchTimer(mClocks, null, -700-i, null, |
| 8223 | mOnBatteryTimeBase); |
| 8224 | } |
| 8225 | for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 8226 | mWifiSignalStrengthsTimer[i] = new StopwatchTimer(mClocks, null, -800-i, null, |
| 8227 | mOnBatteryTimeBase); |
| 8228 | } |
| 8229 | mAudioOnTimer = new StopwatchTimer(mClocks, null, -7, null, mOnBatteryTimeBase); |
| 8230 | mVideoOnTimer = new StopwatchTimer(mClocks, null, -8, null, mOnBatteryTimeBase); |
| 8231 | mFlashlightOnTimer = new StopwatchTimer(mClocks, null, -9, null, mOnBatteryTimeBase); |
| 8232 | mCameraOnTimer = new StopwatchTimer(mClocks, null, -13, null, mOnBatteryTimeBase); |
| 8233 | mBluetoothScanTimer = new StopwatchTimer(mClocks, null, -14, null, mOnBatteryTimeBase); |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 8234 | mDischargeScreenOffCounter = new LongSamplingCounter(mOnBatteryScreenOffTimeBase); |
| 8235 | mDischargeCounter = new LongSamplingCounter(mOnBatteryTimeBase); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8236 | mOnBattery = mOnBatteryInternal = false; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8237 | long uptime = mClocks.uptimeMillis() * 1000; |
| 8238 | long realtime = mClocks.elapsedRealtime() * 1000; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8239 | initTimes(uptime, realtime); |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 8240 | mStartPlatformVersion = mEndPlatformVersion = Build.ID; |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 8241 | mDischargeStartLevel = 0; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8242 | mDischargeUnplugLevel = 0; |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 8243 | mDischargePlugLevel = -1; |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 8244 | mDischargeCurrentLevel = 0; |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 8245 | mCurrentBatteryLevel = 0; |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 8246 | initDischarge(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 8247 | clearHistoryLocked(); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 8248 | updateDailyDeadlineLocked(); |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 8249 | mPlatformIdleStateCallback = cb; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8250 | } |
| 8251 | |
| 8252 | public BatteryStatsImpl(Parcel p) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8253 | this(new SystemClocks(), p); |
| 8254 | } |
| 8255 | |
| 8256 | public BatteryStatsImpl(Clocks clocks, Parcel p) { |
| 8257 | init(clocks); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 8258 | mFile = null; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 8259 | mCheckinFile = null; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 8260 | mDailyFile = null; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 8261 | mHandler = null; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8262 | mExternalSync = null; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 8263 | clearHistoryLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8264 | readFromParcel(p); |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 8265 | mPlatformIdleStateCallback = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8266 | } |
| 8267 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 8268 | public void setPowerProfile(PowerProfile profile) { |
| 8269 | synchronized (this) { |
| 8270 | mPowerProfile = profile; |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 8271 | |
| 8272 | // We need to initialize the KernelCpuSpeedReaders to read from |
| 8273 | // the first cpu of each core. Once we have the PowerProfile, we have access to this |
| 8274 | // information. |
| 8275 | final int numClusters = mPowerProfile.getNumCpuClusters(); |
| 8276 | mKernelCpuSpeedReaders = new KernelCpuSpeedReader[numClusters]; |
| 8277 | int firstCpuOfCluster = 0; |
| 8278 | for (int i = 0; i < numClusters; i++) { |
| 8279 | final int numSpeedSteps = mPowerProfile.getNumSpeedStepsInCpuCluster(i); |
| 8280 | mKernelCpuSpeedReaders[i] = new KernelCpuSpeedReader(firstCpuOfCluster, |
| 8281 | numSpeedSteps); |
| 8282 | firstCpuOfCluster += mPowerProfile.getNumCoresInCpuCluster(i); |
| 8283 | } |
Adam Lesinski | f9b20a9 | 2016-06-17 17:30:01 -0700 | [diff] [blame] | 8284 | |
| 8285 | if (mEstimatedBatteryCapacity == -1) { |
| 8286 | // Initialize the estimated battery capacity to a known preset one. |
| 8287 | mEstimatedBatteryCapacity = (int) mPowerProfile.getBatteryCapacity(); |
| 8288 | } |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 8289 | } |
| 8290 | } |
| 8291 | |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 8292 | public void setCallback(BatteryCallback cb) { |
| 8293 | mCallback = cb; |
| 8294 | } |
| 8295 | |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 8296 | public void setRadioScanningTimeout(long timeout) { |
| 8297 | if (mPhoneSignalScanningTimer != null) { |
| 8298 | mPhoneSignalScanningTimer.setTimeout(timeout); |
| 8299 | } |
| 8300 | } |
| 8301 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 8302 | public void updateDailyDeadlineLocked() { |
| 8303 | // Get the current time. |
| 8304 | long currentTime = mDailyStartTime = System.currentTimeMillis(); |
| 8305 | Calendar calDeadline = Calendar.getInstance(); |
| 8306 | calDeadline.setTimeInMillis(currentTime); |
| 8307 | |
| 8308 | // Move time up to the next day, ranging from 1am to 3pm. |
| 8309 | calDeadline.set(Calendar.DAY_OF_YEAR, calDeadline.get(Calendar.DAY_OF_YEAR) + 1); |
| 8310 | calDeadline.set(Calendar.MILLISECOND, 0); |
| 8311 | calDeadline.set(Calendar.SECOND, 0); |
| 8312 | calDeadline.set(Calendar.MINUTE, 0); |
| 8313 | calDeadline.set(Calendar.HOUR_OF_DAY, 1); |
| 8314 | mNextMinDailyDeadline = calDeadline.getTimeInMillis(); |
| 8315 | calDeadline.set(Calendar.HOUR_OF_DAY, 3); |
| 8316 | mNextMaxDailyDeadline = calDeadline.getTimeInMillis(); |
| 8317 | } |
| 8318 | |
| 8319 | public void recordDailyStatsIfNeededLocked(boolean settled) { |
| 8320 | long currentTime = System.currentTimeMillis(); |
| 8321 | if (currentTime >= mNextMaxDailyDeadline) { |
| 8322 | recordDailyStatsLocked(); |
| 8323 | } else if (settled && currentTime >= mNextMinDailyDeadline) { |
| 8324 | recordDailyStatsLocked(); |
| 8325 | } else if (currentTime < (mDailyStartTime-(1000*60*60*24))) { |
| 8326 | recordDailyStatsLocked(); |
| 8327 | } |
| 8328 | } |
| 8329 | |
| 8330 | public void recordDailyStatsLocked() { |
| 8331 | DailyItem item = new DailyItem(); |
| 8332 | item.mStartTime = mDailyStartTime; |
| 8333 | item.mEndTime = System.currentTimeMillis(); |
| 8334 | boolean hasData = false; |
| 8335 | if (mDailyDischargeStepTracker.mNumStepDurations > 0) { |
| 8336 | hasData = true; |
| 8337 | item.mDischargeSteps = new LevelStepTracker( |
| 8338 | mDailyDischargeStepTracker.mNumStepDurations, |
| 8339 | mDailyDischargeStepTracker.mStepDurations); |
| 8340 | } |
| 8341 | if (mDailyChargeStepTracker.mNumStepDurations > 0) { |
| 8342 | hasData = true; |
| 8343 | item.mChargeSteps = new LevelStepTracker( |
| 8344 | mDailyChargeStepTracker.mNumStepDurations, |
| 8345 | mDailyChargeStepTracker.mStepDurations); |
| 8346 | } |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 8347 | if (mDailyPackageChanges != null) { |
| 8348 | hasData = true; |
| 8349 | item.mPackageChanges = mDailyPackageChanges; |
| 8350 | mDailyPackageChanges = null; |
| 8351 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 8352 | mDailyDischargeStepTracker.init(); |
| 8353 | mDailyChargeStepTracker.init(); |
| 8354 | updateDailyDeadlineLocked(); |
| 8355 | |
| 8356 | if (hasData) { |
| 8357 | mDailyItems.add(item); |
| 8358 | while (mDailyItems.size() > MAX_DAILY_ITEMS) { |
| 8359 | mDailyItems.remove(0); |
| 8360 | } |
| 8361 | final ByteArrayOutputStream memStream = new ByteArrayOutputStream(); |
| 8362 | try { |
| 8363 | XmlSerializer out = new FastXmlSerializer(); |
Wojciech Staszkiewicz | 9e9e2e7 | 2015-05-08 14:58:46 +0100 | [diff] [blame] | 8364 | out.setOutput(memStream, StandardCharsets.UTF_8.name()); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 8365 | writeDailyItemsLocked(out); |
| 8366 | BackgroundThread.getHandler().post(new Runnable() { |
| 8367 | @Override |
| 8368 | public void run() { |
| 8369 | synchronized (mCheckinFile) { |
| 8370 | FileOutputStream stream = null; |
| 8371 | try { |
| 8372 | stream = mDailyFile.startWrite(); |
| 8373 | memStream.writeTo(stream); |
| 8374 | stream.flush(); |
| 8375 | FileUtils.sync(stream); |
| 8376 | stream.close(); |
| 8377 | mDailyFile.finishWrite(stream); |
| 8378 | } catch (IOException e) { |
| 8379 | Slog.w("BatteryStats", |
| 8380 | "Error writing battery daily items", e); |
| 8381 | mDailyFile.failWrite(stream); |
| 8382 | } |
| 8383 | } |
| 8384 | } |
| 8385 | }); |
| 8386 | } catch (IOException e) { |
| 8387 | } |
| 8388 | } |
| 8389 | } |
| 8390 | |
| 8391 | private void writeDailyItemsLocked(XmlSerializer out) throws IOException { |
| 8392 | StringBuilder sb = new StringBuilder(64); |
| 8393 | out.startDocument(null, true); |
| 8394 | out.startTag(null, "daily-items"); |
| 8395 | for (int i=0; i<mDailyItems.size(); i++) { |
| 8396 | final DailyItem dit = mDailyItems.get(i); |
| 8397 | out.startTag(null, "item"); |
| 8398 | out.attribute(null, "start", Long.toString(dit.mStartTime)); |
| 8399 | out.attribute(null, "end", Long.toString(dit.mEndTime)); |
| 8400 | writeDailyLevelSteps(out, "dis", dit.mDischargeSteps, sb); |
| 8401 | writeDailyLevelSteps(out, "chg", dit.mChargeSteps, sb); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 8402 | if (dit.mPackageChanges != null) { |
| 8403 | for (int j=0; j<dit.mPackageChanges.size(); j++) { |
| 8404 | PackageChange pc = dit.mPackageChanges.get(j); |
| 8405 | if (pc.mUpdate) { |
| 8406 | out.startTag(null, "upd"); |
| 8407 | out.attribute(null, "pkg", pc.mPackageName); |
| 8408 | out.attribute(null, "ver", Integer.toString(pc.mVersionCode)); |
| 8409 | out.endTag(null, "upd"); |
| 8410 | } else { |
| 8411 | out.startTag(null, "rem"); |
| 8412 | out.attribute(null, "pkg", pc.mPackageName); |
| 8413 | out.endTag(null, "rem"); |
| 8414 | } |
| 8415 | } |
| 8416 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 8417 | out.endTag(null, "item"); |
| 8418 | } |
| 8419 | out.endTag(null, "daily-items"); |
| 8420 | out.endDocument(); |
| 8421 | } |
| 8422 | |
| 8423 | private void writeDailyLevelSteps(XmlSerializer out, String tag, LevelStepTracker steps, |
| 8424 | StringBuilder tmpBuilder) throws IOException { |
| 8425 | if (steps != null) { |
| 8426 | out.startTag(null, tag); |
| 8427 | out.attribute(null, "n", Integer.toString(steps.mNumStepDurations)); |
| 8428 | for (int i=0; i<steps.mNumStepDurations; i++) { |
| 8429 | out.startTag(null, "s"); |
| 8430 | tmpBuilder.setLength(0); |
| 8431 | steps.encodeEntryAt(i, tmpBuilder); |
| 8432 | out.attribute(null, "v", tmpBuilder.toString()); |
| 8433 | out.endTag(null, "s"); |
| 8434 | } |
| 8435 | out.endTag(null, tag); |
| 8436 | } |
| 8437 | } |
| 8438 | |
| 8439 | public void readDailyStatsLocked() { |
| 8440 | Slog.d(TAG, "Reading daily items from " + mDailyFile.getBaseFile()); |
| 8441 | mDailyItems.clear(); |
| 8442 | FileInputStream stream; |
| 8443 | try { |
| 8444 | stream = mDailyFile.openRead(); |
| 8445 | } catch (FileNotFoundException e) { |
| 8446 | return; |
| 8447 | } |
| 8448 | try { |
| 8449 | XmlPullParser parser = Xml.newPullParser(); |
Wojciech Staszkiewicz | 9e9e2e7 | 2015-05-08 14:58:46 +0100 | [diff] [blame] | 8450 | parser.setInput(stream, StandardCharsets.UTF_8.name()); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 8451 | readDailyItemsLocked(parser); |
| 8452 | } catch (XmlPullParserException e) { |
| 8453 | } finally { |
| 8454 | try { |
| 8455 | stream.close(); |
| 8456 | } catch (IOException e) { |
| 8457 | } |
| 8458 | } |
| 8459 | } |
| 8460 | |
| 8461 | private void readDailyItemsLocked(XmlPullParser parser) { |
| 8462 | try { |
| 8463 | int type; |
| 8464 | while ((type = parser.next()) != XmlPullParser.START_TAG |
| 8465 | && type != XmlPullParser.END_DOCUMENT) { |
| 8466 | ; |
| 8467 | } |
| 8468 | |
| 8469 | if (type != XmlPullParser.START_TAG) { |
| 8470 | throw new IllegalStateException("no start tag found"); |
| 8471 | } |
| 8472 | |
| 8473 | int outerDepth = parser.getDepth(); |
| 8474 | while ((type = parser.next()) != XmlPullParser.END_DOCUMENT |
| 8475 | && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) { |
| 8476 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 8477 | continue; |
| 8478 | } |
| 8479 | |
| 8480 | String tagName = parser.getName(); |
| 8481 | if (tagName.equals("item")) { |
| 8482 | readDailyItemTagLocked(parser); |
| 8483 | } else { |
| 8484 | Slog.w(TAG, "Unknown element under <daily-items>: " |
| 8485 | + parser.getName()); |
| 8486 | XmlUtils.skipCurrentTag(parser); |
| 8487 | } |
| 8488 | } |
| 8489 | |
| 8490 | } catch (IllegalStateException e) { |
| 8491 | Slog.w(TAG, "Failed parsing daily " + e); |
| 8492 | } catch (NullPointerException e) { |
| 8493 | Slog.w(TAG, "Failed parsing daily " + e); |
| 8494 | } catch (NumberFormatException e) { |
| 8495 | Slog.w(TAG, "Failed parsing daily " + e); |
| 8496 | } catch (XmlPullParserException e) { |
| 8497 | Slog.w(TAG, "Failed parsing daily " + e); |
| 8498 | } catch (IOException e) { |
| 8499 | Slog.w(TAG, "Failed parsing daily " + e); |
| 8500 | } catch (IndexOutOfBoundsException e) { |
| 8501 | Slog.w(TAG, "Failed parsing daily " + e); |
| 8502 | } |
| 8503 | } |
| 8504 | |
| 8505 | void readDailyItemTagLocked(XmlPullParser parser) throws NumberFormatException, |
| 8506 | XmlPullParserException, IOException { |
| 8507 | DailyItem dit = new DailyItem(); |
| 8508 | String attr = parser.getAttributeValue(null, "start"); |
| 8509 | if (attr != null) { |
| 8510 | dit.mStartTime = Long.parseLong(attr); |
| 8511 | } |
| 8512 | attr = parser.getAttributeValue(null, "end"); |
| 8513 | if (attr != null) { |
| 8514 | dit.mEndTime = Long.parseLong(attr); |
| 8515 | } |
| 8516 | int outerDepth = parser.getDepth(); |
| 8517 | int type; |
| 8518 | while ((type = parser.next()) != XmlPullParser.END_DOCUMENT |
| 8519 | && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) { |
| 8520 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 8521 | continue; |
| 8522 | } |
| 8523 | |
| 8524 | String tagName = parser.getName(); |
| 8525 | if (tagName.equals("dis")) { |
| 8526 | readDailyItemTagDetailsLocked(parser, dit, false, "dis"); |
| 8527 | } else if (tagName.equals("chg")) { |
| 8528 | readDailyItemTagDetailsLocked(parser, dit, true, "chg"); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 8529 | } else if (tagName.equals("upd")) { |
| 8530 | if (dit.mPackageChanges == null) { |
| 8531 | dit.mPackageChanges = new ArrayList<>(); |
| 8532 | } |
| 8533 | PackageChange pc = new PackageChange(); |
| 8534 | pc.mUpdate = true; |
| 8535 | pc.mPackageName = parser.getAttributeValue(null, "pkg"); |
| 8536 | String verStr = parser.getAttributeValue(null, "ver"); |
| 8537 | pc.mVersionCode = verStr != null ? Integer.parseInt(verStr) : 0; |
| 8538 | dit.mPackageChanges.add(pc); |
| 8539 | XmlUtils.skipCurrentTag(parser); |
| 8540 | } else if (tagName.equals("rem")) { |
| 8541 | if (dit.mPackageChanges == null) { |
| 8542 | dit.mPackageChanges = new ArrayList<>(); |
| 8543 | } |
| 8544 | PackageChange pc = new PackageChange(); |
| 8545 | pc.mUpdate = false; |
| 8546 | pc.mPackageName = parser.getAttributeValue(null, "pkg"); |
| 8547 | dit.mPackageChanges.add(pc); |
| 8548 | XmlUtils.skipCurrentTag(parser); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 8549 | } else { |
| 8550 | Slog.w(TAG, "Unknown element under <item>: " |
| 8551 | + parser.getName()); |
| 8552 | XmlUtils.skipCurrentTag(parser); |
| 8553 | } |
| 8554 | } |
| 8555 | mDailyItems.add(dit); |
| 8556 | } |
| 8557 | |
| 8558 | void readDailyItemTagDetailsLocked(XmlPullParser parser, DailyItem dit, boolean isCharge, |
| 8559 | String tag) |
| 8560 | throws NumberFormatException, XmlPullParserException, IOException { |
| 8561 | final String numAttr = parser.getAttributeValue(null, "n"); |
| 8562 | if (numAttr == null) { |
| 8563 | Slog.w(TAG, "Missing 'n' attribute at " + parser.getPositionDescription()); |
| 8564 | XmlUtils.skipCurrentTag(parser); |
| 8565 | return; |
| 8566 | } |
| 8567 | final int num = Integer.parseInt(numAttr); |
| 8568 | LevelStepTracker steps = new LevelStepTracker(num); |
| 8569 | if (isCharge) { |
| 8570 | dit.mChargeSteps = steps; |
| 8571 | } else { |
| 8572 | dit.mDischargeSteps = steps; |
| 8573 | } |
| 8574 | int i = 0; |
| 8575 | int outerDepth = parser.getDepth(); |
| 8576 | int type; |
| 8577 | while ((type = parser.next()) != XmlPullParser.END_DOCUMENT |
| 8578 | && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) { |
| 8579 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 8580 | continue; |
| 8581 | } |
| 8582 | |
| 8583 | String tagName = parser.getName(); |
| 8584 | if ("s".equals(tagName)) { |
| 8585 | if (i < num) { |
| 8586 | String valueAttr = parser.getAttributeValue(null, "v"); |
| 8587 | if (valueAttr != null) { |
| 8588 | steps.decodeEntryAt(i, valueAttr); |
| 8589 | i++; |
| 8590 | } |
| 8591 | } |
| 8592 | } else { |
| 8593 | Slog.w(TAG, "Unknown element under <" + tag + ">: " |
| 8594 | + parser.getName()); |
| 8595 | XmlUtils.skipCurrentTag(parser); |
| 8596 | } |
| 8597 | } |
| 8598 | steps.mNumStepDurations = i; |
| 8599 | } |
| 8600 | |
| 8601 | @Override |
| 8602 | public DailyItem getDailyItemLocked(int daysAgo) { |
| 8603 | int index = mDailyItems.size()-1-daysAgo; |
| 8604 | return index >= 0 ? mDailyItems.get(index) : null; |
| 8605 | } |
| 8606 | |
| 8607 | @Override |
| 8608 | public long getCurrentDailyStartTime() { |
| 8609 | return mDailyStartTime; |
| 8610 | } |
| 8611 | |
| 8612 | @Override |
| 8613 | public long getNextMinDailyDeadline() { |
| 8614 | return mNextMinDailyDeadline; |
| 8615 | } |
| 8616 | |
| 8617 | @Override |
| 8618 | public long getNextMaxDailyDeadline() { |
| 8619 | return mNextMaxDailyDeadline; |
| 8620 | } |
| 8621 | |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 8622 | @Override |
| 8623 | public boolean startIteratingOldHistoryLocked() { |
| 8624 | if (DEBUG_HISTORY) Slog.i(TAG, "ITERATING: buff size=" + mHistoryBuffer.dataSize() |
| 8625 | + " pos=" + mHistoryBuffer.dataPosition()); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 8626 | if ((mHistoryIterator = mHistory) == null) { |
| 8627 | return false; |
| 8628 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 8629 | mHistoryBuffer.setDataPosition(0); |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 8630 | mHistoryReadTmp.clear(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 8631 | mReadOverflow = false; |
| 8632 | mIteratingHistory = true; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 8633 | return true; |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 8634 | } |
| 8635 | |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 8636 | @Override |
| 8637 | public boolean getNextOldHistoryLocked(HistoryItem out) { |
| 8638 | boolean end = mHistoryBuffer.dataPosition() >= mHistoryBuffer.dataSize(); |
| 8639 | if (!end) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 8640 | readHistoryDelta(mHistoryBuffer, mHistoryReadTmp); |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 8641 | mReadOverflow |= mHistoryReadTmp.cmd == HistoryItem.CMD_OVERFLOW; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 8642 | } |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 8643 | HistoryItem cur = mHistoryIterator; |
| 8644 | if (cur == null) { |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 8645 | if (!mReadOverflow && !end) { |
| 8646 | Slog.w(TAG, "Old history ends before new history!"); |
| 8647 | } |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 8648 | return false; |
| 8649 | } |
| 8650 | out.setTo(cur); |
| 8651 | mHistoryIterator = cur.next; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 8652 | if (!mReadOverflow) { |
| 8653 | if (end) { |
| 8654 | Slog.w(TAG, "New history ends before old history!"); |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 8655 | } else if (!out.same(mHistoryReadTmp)) { |
Dianne Hackborn | 8c84109 | 2013-06-24 13:46:13 -0700 | [diff] [blame] | 8656 | PrintWriter pw = new FastPrintWriter(new LogWriter(android.util.Log.WARN, TAG)); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 8657 | pw.println("Histories differ!"); |
| 8658 | pw.println("Old history:"); |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 8659 | (new HistoryPrinter()).printNextItem(pw, out, 0, false, true); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 8660 | pw.println("New history:"); |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 8661 | (new HistoryPrinter()).printNextItem(pw, mHistoryReadTmp, 0, false, |
| 8662 | true); |
Dianne Hackborn | 8c84109 | 2013-06-24 13:46:13 -0700 | [diff] [blame] | 8663 | pw.flush(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 8664 | } |
| 8665 | } |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 8666 | return true; |
| 8667 | } |
| 8668 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8669 | @Override |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 8670 | public void finishIteratingOldHistoryLocked() { |
| 8671 | mIteratingHistory = false; |
| 8672 | mHistoryBuffer.setDataPosition(mHistoryBuffer.dataSize()); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 8673 | mHistoryIterator = null; |
| 8674 | } |
| 8675 | |
| 8676 | public int getHistoryTotalSize() { |
| 8677 | return MAX_HISTORY_BUFFER; |
| 8678 | } |
| 8679 | |
| 8680 | public int getHistoryUsedSize() { |
| 8681 | return mHistoryBuffer.dataSize(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 8682 | } |
| 8683 | |
| 8684 | @Override |
| 8685 | public boolean startIteratingHistoryLocked() { |
| 8686 | if (DEBUG_HISTORY) Slog.i(TAG, "ITERATING: buff size=" + mHistoryBuffer.dataSize() |
| 8687 | + " pos=" + mHistoryBuffer.dataPosition()); |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 8688 | if (mHistoryBuffer.dataSize() <= 0) { |
| 8689 | return false; |
| 8690 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 8691 | mHistoryBuffer.setDataPosition(0); |
| 8692 | mReadOverflow = false; |
| 8693 | mIteratingHistory = true; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 8694 | mReadHistoryStrings = new String[mHistoryTagPool.size()]; |
| 8695 | mReadHistoryUids = new int[mHistoryTagPool.size()]; |
| 8696 | mReadHistoryChars = 0; |
| 8697 | for (HashMap.Entry<HistoryTag, Integer> ent : mHistoryTagPool.entrySet()) { |
| 8698 | final HistoryTag tag = ent.getKey(); |
| 8699 | final int idx = ent.getValue(); |
| 8700 | mReadHistoryStrings[idx] = tag.string; |
| 8701 | mReadHistoryUids[idx] = tag.uid; |
| 8702 | mReadHistoryChars += tag.string.length() + 1; |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 8703 | } |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 8704 | return true; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 8705 | } |
| 8706 | |
| 8707 | @Override |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 8708 | public int getHistoryStringPoolSize() { |
| 8709 | return mReadHistoryStrings.length; |
| 8710 | } |
| 8711 | |
| 8712 | @Override |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 8713 | public int getHistoryStringPoolBytes() { |
| 8714 | // Each entry is a fixed 12 bytes: 4 for index, 4 for uid, 4 for string size |
| 8715 | // Each string character is 2 bytes. |
| 8716 | return (mReadHistoryStrings.length * 12) + (mReadHistoryChars * 2); |
| 8717 | } |
| 8718 | |
| 8719 | @Override |
| 8720 | public String getHistoryTagPoolString(int index) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 8721 | return mReadHistoryStrings[index]; |
| 8722 | } |
| 8723 | |
| 8724 | @Override |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 8725 | public int getHistoryTagPoolUid(int index) { |
| 8726 | return mReadHistoryUids[index]; |
| 8727 | } |
| 8728 | |
| 8729 | @Override |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 8730 | public boolean getNextHistoryLocked(HistoryItem out) { |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 8731 | final int pos = mHistoryBuffer.dataPosition(); |
| 8732 | if (pos == 0) { |
| 8733 | out.clear(); |
| 8734 | } |
| 8735 | boolean end = pos >= mHistoryBuffer.dataSize(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 8736 | if (end) { |
| 8737 | return false; |
| 8738 | } |
| 8739 | |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 8740 | final long lastRealtime = out.time; |
| 8741 | final long lastWalltime = out.currentTime; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 8742 | readHistoryDelta(mHistoryBuffer, out); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 8743 | if (out.cmd != HistoryItem.CMD_CURRENT_TIME |
| 8744 | && out.cmd != HistoryItem.CMD_RESET && lastWalltime != 0) { |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 8745 | out.currentTime = lastWalltime + (out.time - lastRealtime); |
| 8746 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 8747 | return true; |
| 8748 | } |
| 8749 | |
| 8750 | @Override |
| 8751 | public void finishIteratingHistoryLocked() { |
| 8752 | mIteratingHistory = false; |
| 8753 | mHistoryBuffer.setDataPosition(mHistoryBuffer.dataSize()); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 8754 | mReadHistoryStrings = null; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 8755 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 8756 | |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 8757 | @Override |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 8758 | public long getHistoryBaseTime() { |
| 8759 | return mHistoryBaseTime; |
| 8760 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 8761 | |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 8762 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8763 | public int getStartCount() { |
| 8764 | return mStartCount; |
| 8765 | } |
| 8766 | |
| 8767 | public boolean isOnBattery() { |
| 8768 | return mOnBattery; |
| 8769 | } |
| 8770 | |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 8771 | public boolean isCharging() { |
| 8772 | return mCharging; |
| 8773 | } |
| 8774 | |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 8775 | public boolean isScreenOn() { |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 8776 | return mScreenState == Display.STATE_ON; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 8777 | } |
| 8778 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8779 | void initTimes(long uptime, long realtime) { |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 8780 | mStartClockTime = System.currentTimeMillis(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8781 | mOnBatteryTimeBase.init(uptime, realtime); |
| 8782 | mOnBatteryScreenOffTimeBase.init(uptime, realtime); |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 8783 | mRealtime = 0; |
| 8784 | mUptime = 0; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8785 | mRealtimeStart = realtime; |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 8786 | mUptimeStart = uptime; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8787 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 8788 | |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 8789 | void initDischarge() { |
| 8790 | mLowDischargeAmountSinceCharge = 0; |
| 8791 | mHighDischargeAmountSinceCharge = 0; |
| 8792 | mDischargeAmountScreenOn = 0; |
| 8793 | mDischargeAmountScreenOnSinceCharge = 0; |
| 8794 | mDischargeAmountScreenOff = 0; |
| 8795 | mDischargeAmountScreenOffSinceCharge = 0; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 8796 | mDischargeStepTracker.init(); |
| 8797 | mChargeStepTracker.init(); |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 8798 | mDischargeScreenOffCounter.reset(false); |
| 8799 | mDischargeCounter.reset(false); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 8800 | } |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 8801 | |
| 8802 | public void resetAllStatsCmdLocked() { |
| 8803 | resetAllStatsLocked(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8804 | final long mSecUptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 8805 | long uptime = mSecUptime * 1000; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8806 | long mSecRealtime = mClocks.elapsedRealtime(); |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 8807 | long realtime = mSecRealtime * 1000; |
| 8808 | mDischargeStartLevel = mHistoryCur.batteryLevel; |
| 8809 | pullPendingStateUpdatesLocked(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 8810 | addHistoryRecordLocked(mSecRealtime, mSecUptime); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 8811 | mDischargeCurrentLevel = mDischargeUnplugLevel = mDischargePlugLevel |
| 8812 | = mCurrentBatteryLevel = mHistoryCur.batteryLevel; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8813 | mOnBatteryTimeBase.reset(uptime, realtime); |
| 8814 | mOnBatteryScreenOffTimeBase.reset(uptime, realtime); |
| 8815 | if ((mHistoryCur.states&HistoryItem.STATE_BATTERY_PLUGGED_FLAG) == 0) { |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 8816 | if (mScreenState == Display.STATE_ON) { |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 8817 | mDischargeScreenOnUnplugLevel = mHistoryCur.batteryLevel; |
| 8818 | mDischargeScreenOffUnplugLevel = 0; |
| 8819 | } else { |
| 8820 | mDischargeScreenOnUnplugLevel = 0; |
| 8821 | mDischargeScreenOffUnplugLevel = mHistoryCur.batteryLevel; |
| 8822 | } |
| 8823 | mDischargeAmountScreenOn = 0; |
| 8824 | mDischargeAmountScreenOff = 0; |
| 8825 | } |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 8826 | initActiveHistoryEventsLocked(mSecRealtime, mSecUptime); |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 8827 | } |
| 8828 | |
| 8829 | private void resetAllStatsLocked() { |
Adam Lesinski | 8ce3694 | 2016-05-26 16:05:35 -0700 | [diff] [blame] | 8830 | final long uptimeMillis = mClocks.uptimeMillis(); |
| 8831 | final long elapsedRealtimeMillis = mClocks.elapsedRealtime(); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8832 | mStartCount = 0; |
Adam Lesinski | 8ce3694 | 2016-05-26 16:05:35 -0700 | [diff] [blame] | 8833 | initTimes(uptimeMillis * 1000, elapsedRealtimeMillis * 1000); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8834 | mScreenOnTimer.reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8835 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8836 | mScreenBrightnessTimer[i].reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8837 | } |
Adam Lesinski | 1a76a62 | 2016-06-22 10:28:47 -0700 | [diff] [blame] | 8838 | |
| 8839 | if (mPowerProfile != null) { |
| 8840 | mEstimatedBatteryCapacity = (int) mPowerProfile.getBatteryCapacity(); |
| 8841 | } else { |
| 8842 | mEstimatedBatteryCapacity = -1; |
| 8843 | } |
Jocelyn Dang | c627d10 | 2017-04-14 13:15:14 -0700 | [diff] [blame^] | 8844 | mMinLearnedBatteryCapacity = -1; |
| 8845 | mMaxLearnedBatteryCapacity = -1; |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 8846 | mInteractiveTimer.reset(false); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 8847 | mPowerSaveModeEnabledTimer.reset(false); |
Adam Lesinski | 8ce3694 | 2016-05-26 16:05:35 -0700 | [diff] [blame] | 8848 | mLastIdleTimeStart = elapsedRealtimeMillis; |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 8849 | mLongestLightIdleTime = 0; |
| 8850 | mLongestFullIdleTime = 0; |
| 8851 | mDeviceIdleModeLightTimer.reset(false); |
| 8852 | mDeviceIdleModeFullTimer.reset(false); |
| 8853 | mDeviceLightIdlingTimer.reset(false); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 8854 | mDeviceIdlingTimer.reset(false); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8855 | mPhoneOnTimer.reset(false); |
| 8856 | mAudioOnTimer.reset(false); |
| 8857 | mVideoOnTimer.reset(false); |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 8858 | mFlashlightOnTimer.reset(false); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 8859 | mCameraOnTimer.reset(false); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 8860 | mBluetoothScanTimer.reset(false); |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 8861 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8862 | mPhoneSignalStrengthsTimer[i].reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8863 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8864 | mPhoneSignalScanningTimer.reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8865 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8866 | mPhoneDataConnectionsTimer[i].reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8867 | } |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 8868 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 8869 | mNetworkByteActivityCounters[i].reset(false); |
| 8870 | mNetworkPacketActivityCounters[i].reset(false); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 8871 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8872 | mMobileRadioActiveTimer.reset(false); |
| 8873 | mMobileRadioActivePerAppTimer.reset(false); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 8874 | mMobileRadioActiveAdjustedTime.reset(false); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 8875 | mMobileRadioActiveUnknownTime.reset(false); |
| 8876 | mMobileRadioActiveUnknownCount.reset(false); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8877 | mWifiOnTimer.reset(false); |
| 8878 | mGlobalWifiRunningTimer.reset(false); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 8879 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8880 | mWifiStateTimer[i].reset(false); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 8881 | } |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 8882 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
| 8883 | mWifiSupplStateTimer[i].reset(false); |
| 8884 | } |
| 8885 | for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 8886 | mWifiSignalStrengthsTimer[i].reset(false); |
| 8887 | } |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 8888 | mWifiActivity.reset(false); |
| 8889 | mBluetoothActivity.reset(false); |
| 8890 | mModemActivity.reset(false); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 8891 | mNumConnectivityChange = mLoadedNumConnectivityChange = mUnpluggedNumConnectivityChange = 0; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 8892 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8893 | for (int i=0; i<mUidStats.size(); i++) { |
| 8894 | if (mUidStats.valueAt(i).reset()) { |
| 8895 | mUidStats.remove(mUidStats.keyAt(i)); |
| 8896 | i--; |
| 8897 | } |
| 8898 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 8899 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8900 | if (mKernelWakelockStats.size() > 0) { |
| 8901 | for (SamplingTimer timer : mKernelWakelockStats.values()) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8902 | mOnBatteryScreenOffTimeBase.remove(timer); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8903 | } |
| 8904 | mKernelWakelockStats.clear(); |
| 8905 | } |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 8906 | |
James Carr | 3a22605 | 2016-07-01 14:49:52 -0700 | [diff] [blame] | 8907 | if (mKernelMemoryStats.size() > 0) { |
| 8908 | for (int i = 0; i < mKernelMemoryStats.size(); i++) { |
| 8909 | mOnBatteryTimeBase.remove(mKernelMemoryStats.valueAt(i)); |
| 8910 | } |
| 8911 | mKernelMemoryStats.clear(); |
| 8912 | } |
| 8913 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 8914 | if (mWakeupReasonStats.size() > 0) { |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 8915 | for (SamplingTimer timer : mWakeupReasonStats.values()) { |
| 8916 | mOnBatteryTimeBase.remove(timer); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 8917 | } |
| 8918 | mWakeupReasonStats.clear(); |
| 8919 | } |
| 8920 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 8921 | mLastHistoryStepDetails = null; |
| 8922 | mLastStepCpuUserTime = mLastStepCpuSystemTime = 0; |
| 8923 | mCurStepCpuUserTime = mCurStepCpuSystemTime = 0; |
| 8924 | mLastStepCpuUserTime = mCurStepCpuUserTime = 0; |
| 8925 | mLastStepCpuSystemTime = mCurStepCpuSystemTime = 0; |
| 8926 | mLastStepStatUserTime = mCurStepStatUserTime = 0; |
| 8927 | mLastStepStatSystemTime = mCurStepStatSystemTime = 0; |
| 8928 | mLastStepStatIOWaitTime = mCurStepStatIOWaitTime = 0; |
| 8929 | mLastStepStatIrqTime = mCurStepStatIrqTime = 0; |
| 8930 | mLastStepStatSoftIrqTime = mCurStepStatSoftIrqTime = 0; |
| 8931 | mLastStepStatIdleTime = mCurStepStatIdleTime = 0; |
| 8932 | |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 8933 | initDischarge(); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 8934 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8935 | clearHistoryLocked(); |
| 8936 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 8937 | |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 8938 | private void initActiveHistoryEventsLocked(long elapsedRealtimeMs, long uptimeMs) { |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 8939 | for (int i=0; i<HistoryItem.EVENT_COUNT; i++) { |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 8940 | if (!mRecordAllHistory && i == HistoryItem.EVENT_PROC) { |
| 8941 | // Not recording process starts/stops. |
| 8942 | continue; |
| 8943 | } |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 8944 | HashMap<String, SparseIntArray> active = mActiveEvents.getStateForEvent(i); |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 8945 | if (active == null) { |
| 8946 | continue; |
| 8947 | } |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 8948 | for (HashMap.Entry<String, SparseIntArray> ent : active.entrySet()) { |
| 8949 | SparseIntArray uids = ent.getValue(); |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 8950 | for (int j=0; j<uids.size(); j++) { |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 8951 | addHistoryEventLocked(elapsedRealtimeMs, uptimeMs, i, ent.getKey(), |
| 8952 | uids.keyAt(j)); |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 8953 | } |
| 8954 | } |
| 8955 | } |
| 8956 | } |
| 8957 | |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 8958 | void updateDischargeScreenLevelsLocked(boolean oldScreenOn, boolean newScreenOn) { |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 8959 | if (oldScreenOn) { |
| 8960 | int diff = mDischargeScreenOnUnplugLevel - mDischargeCurrentLevel; |
| 8961 | if (diff > 0) { |
| 8962 | mDischargeAmountScreenOn += diff; |
| 8963 | mDischargeAmountScreenOnSinceCharge += diff; |
| 8964 | } |
| 8965 | } else { |
| 8966 | int diff = mDischargeScreenOffUnplugLevel - mDischargeCurrentLevel; |
| 8967 | if (diff > 0) { |
| 8968 | mDischargeAmountScreenOff += diff; |
| 8969 | mDischargeAmountScreenOffSinceCharge += diff; |
| 8970 | } |
| 8971 | } |
| 8972 | if (newScreenOn) { |
| 8973 | mDischargeScreenOnUnplugLevel = mDischargeCurrentLevel; |
| 8974 | mDischargeScreenOffUnplugLevel = 0; |
| 8975 | } else { |
| 8976 | mDischargeScreenOnUnplugLevel = 0; |
| 8977 | mDischargeScreenOffUnplugLevel = mDischargeCurrentLevel; |
| 8978 | } |
| 8979 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8980 | |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 8981 | public void pullPendingStateUpdatesLocked() { |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 8982 | if (mOnBatteryInternal) { |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 8983 | final boolean screenOn = mScreenState == Display.STATE_ON; |
| 8984 | updateDischargeScreenLevelsLocked(screenOn, screenOn); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 8985 | } |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 8986 | } |
| 8987 | |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8988 | private String[] mMobileIfaces = EmptyArray.STRING; |
| 8989 | private String[] mWifiIfaces = EmptyArray.STRING; |
| 8990 | |
| 8991 | private final NetworkStatsFactory mNetworkStatsFactory = new NetworkStatsFactory(); |
| 8992 | |
| 8993 | private static final int NETWORK_STATS_LAST = 0; |
| 8994 | private static final int NETWORK_STATS_NEXT = 1; |
| 8995 | private static final int NETWORK_STATS_DELTA = 2; |
| 8996 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8997 | private NetworkStats[] mMobileNetworkStats; |
| 8998 | private NetworkStats[] mWifiNetworkStats; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8999 | |
| 9000 | /** |
| 9001 | * Retrieves the delta of network stats for the given network ifaces. Uses networkStatsBuffer |
| 9002 | * as a buffer of NetworkStats objects to cycle through when computing deltas. |
| 9003 | */ |
| 9004 | private NetworkStats getNetworkStatsDeltaLocked(String[] ifaces, |
| 9005 | NetworkStats[] networkStatsBuffer) |
| 9006 | throws IOException { |
| 9007 | if (!SystemProperties.getBoolean(NetworkManagementSocketTagger.PROP_QTAGUID_ENABLED, |
| 9008 | false)) { |
| 9009 | return null; |
| 9010 | } |
| 9011 | |
| 9012 | final NetworkStats stats = mNetworkStatsFactory.readNetworkStatsDetail(NetworkStats.UID_ALL, |
| 9013 | ifaces, NetworkStats.TAG_NONE, networkStatsBuffer[NETWORK_STATS_NEXT]); |
| 9014 | networkStatsBuffer[NETWORK_STATS_DELTA] = NetworkStats.subtract(stats, |
| 9015 | networkStatsBuffer[NETWORK_STATS_LAST], null, null, |
| 9016 | networkStatsBuffer[NETWORK_STATS_DELTA]); |
| 9017 | networkStatsBuffer[NETWORK_STATS_NEXT] = networkStatsBuffer[NETWORK_STATS_LAST]; |
| 9018 | networkStatsBuffer[NETWORK_STATS_LAST] = stats; |
| 9019 | return networkStatsBuffer[NETWORK_STATS_DELTA]; |
| 9020 | } |
| 9021 | |
| 9022 | /** |
| 9023 | * Distribute WiFi energy info and network traffic to apps. |
| 9024 | * @param info The energy information from the WiFi controller. |
| 9025 | */ |
| 9026 | public void updateWifiStateLocked(@Nullable final WifiActivityEnergyInfo info) { |
Adam Lesinski | a7c90c8 | 2015-06-18 14:52:24 -0700 | [diff] [blame] | 9027 | if (DEBUG_ENERGY) { |
| 9028 | Slog.d(TAG, "Updating wifi stats"); |
| 9029 | } |
| 9030 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9031 | final long elapsedRealtimeMs = mClocks.elapsedRealtime(); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 9032 | NetworkStats delta = null; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 9033 | try { |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 9034 | if (!ArrayUtils.isEmpty(mWifiIfaces)) { |
| 9035 | delta = getNetworkStatsDeltaLocked(mWifiIfaces, mWifiNetworkStats); |
| 9036 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 9037 | } catch (IOException e) { |
| 9038 | Slog.wtf(TAG, "Failed to get wifi network stats", e); |
| 9039 | return; |
| 9040 | } |
| 9041 | |
| 9042 | if (!mOnBatteryInternal) { |
| 9043 | return; |
| 9044 | } |
| 9045 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 9046 | SparseLongArray rxPackets = new SparseLongArray(); |
| 9047 | SparseLongArray txPackets = new SparseLongArray(); |
| 9048 | long totalTxPackets = 0; |
| 9049 | long totalRxPackets = 0; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 9050 | if (delta != null) { |
| 9051 | final int size = delta.size(); |
| 9052 | for (int i = 0; i < size; i++) { |
| 9053 | final NetworkStats.Entry entry = delta.getValues(i, mTmpNetworkStatsEntry); |
| 9054 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 9055 | if (DEBUG_ENERGY) { |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 9056 | Slog.d(TAG, "Wifi uid " + entry.uid + ": delta rx=" + entry.rxBytes |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 9057 | + " tx=" + entry.txBytes + " rxPackets=" + entry.rxPackets |
| 9058 | + " txPackets=" + entry.txPackets); |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 9059 | } |
| 9060 | |
Adam Lesinski | 6cca414 | 2016-02-25 18:23:02 -0800 | [diff] [blame] | 9061 | if (entry.rxBytes == 0 && entry.txBytes == 0) { |
| 9062 | // Skip the lookup below since there is no work to do. |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 9063 | continue; |
| 9064 | } |
| 9065 | |
| 9066 | final Uid u = getUidStatsLocked(mapUid(entry.uid)); |
Adam Lesinski | ba88e68 | 2015-12-08 12:06:55 -0800 | [diff] [blame] | 9067 | if (entry.rxBytes != 0) { |
| 9068 | u.noteNetworkActivityLocked(NETWORK_WIFI_RX_DATA, entry.rxBytes, |
| 9069 | entry.rxPackets); |
Amith Yamasani | 59fe841 | 2017-03-03 16:28:52 -0800 | [diff] [blame] | 9070 | if (entry.set == NetworkStats.SET_DEFAULT) { // Background transfers |
| 9071 | u.noteNetworkActivityLocked(NETWORK_WIFI_BG_RX_DATA, entry.rxBytes, |
| 9072 | entry.rxPackets); |
| 9073 | } |
Adam Lesinski | ba88e68 | 2015-12-08 12:06:55 -0800 | [diff] [blame] | 9074 | mNetworkByteActivityCounters[NETWORK_WIFI_RX_DATA].addCountLocked( |
| 9075 | entry.rxBytes); |
| 9076 | mNetworkPacketActivityCounters[NETWORK_WIFI_RX_DATA].addCountLocked( |
| 9077 | entry.rxPackets); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 9078 | |
Adam Lesinski | ba88e68 | 2015-12-08 12:06:55 -0800 | [diff] [blame] | 9079 | rxPackets.put(u.getUid(), entry.rxPackets); |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 9080 | |
Adam Lesinski | ba88e68 | 2015-12-08 12:06:55 -0800 | [diff] [blame] | 9081 | // Sum the total number of packets so that the Rx Power can |
| 9082 | // be evenly distributed amongst the apps. |
| 9083 | totalRxPackets += entry.rxPackets; |
| 9084 | } |
| 9085 | |
| 9086 | if (entry.txBytes != 0) { |
| 9087 | u.noteNetworkActivityLocked(NETWORK_WIFI_TX_DATA, entry.txBytes, |
| 9088 | entry.txPackets); |
Amith Yamasani | 59fe841 | 2017-03-03 16:28:52 -0800 | [diff] [blame] | 9089 | if (entry.set == NetworkStats.SET_DEFAULT) { // Background transfers |
| 9090 | u.noteNetworkActivityLocked(NETWORK_WIFI_BG_TX_DATA, entry.txBytes, |
| 9091 | entry.txPackets); |
| 9092 | } |
Adam Lesinski | ba88e68 | 2015-12-08 12:06:55 -0800 | [diff] [blame] | 9093 | mNetworkByteActivityCounters[NETWORK_WIFI_TX_DATA].addCountLocked( |
| 9094 | entry.txBytes); |
| 9095 | mNetworkPacketActivityCounters[NETWORK_WIFI_TX_DATA].addCountLocked( |
| 9096 | entry.txPackets); |
| 9097 | |
| 9098 | txPackets.put(u.getUid(), entry.txPackets); |
| 9099 | |
| 9100 | // Sum the total number of packets so that the Tx Power can |
| 9101 | // be evenly distributed amongst the apps. |
| 9102 | totalTxPackets += entry.txPackets; |
| 9103 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 9104 | } |
| 9105 | } |
| 9106 | |
| 9107 | if (info != null) { |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 9108 | mHasWifiReporting = true; |
Adam Lesinski | 1739076 | 2015-04-10 13:17:47 -0700 | [diff] [blame] | 9109 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 9110 | // Measured in mAms |
| 9111 | final long txTimeMs = info.getControllerTxTimeMillis(); |
| 9112 | final long rxTimeMs = info.getControllerRxTimeMillis(); |
| 9113 | final long idleTimeMs = info.getControllerIdleTimeMillis(); |
| 9114 | final long totalTimeMs = txTimeMs + rxTimeMs + idleTimeMs; |
| 9115 | |
| 9116 | long leftOverRxTimeMs = rxTimeMs; |
Mitchell Wills | f901649 | 2015-07-29 17:47:44 -0700 | [diff] [blame] | 9117 | long leftOverTxTimeMs = txTimeMs; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 9118 | |
| 9119 | if (DEBUG_ENERGY) { |
| 9120 | Slog.d(TAG, "------ BEGIN WiFi power blaming ------"); |
| 9121 | Slog.d(TAG, " Tx Time: " + txTimeMs + " ms"); |
| 9122 | Slog.d(TAG, " Rx Time: " + rxTimeMs + " ms"); |
| 9123 | Slog.d(TAG, " Idle Time: " + idleTimeMs + " ms"); |
| 9124 | Slog.d(TAG, " Total Time: " + totalTimeMs + " ms"); |
| 9125 | } |
| 9126 | |
| 9127 | long totalWifiLockTimeMs = 0; |
| 9128 | long totalScanTimeMs = 0; |
| 9129 | |
| 9130 | // On the first pass, collect some totals so that we can normalize power |
| 9131 | // calculations if we need to. |
| 9132 | final int uidStatsSize = mUidStats.size(); |
| 9133 | for (int i = 0; i < uidStatsSize; i++) { |
| 9134 | final Uid uid = mUidStats.valueAt(i); |
| 9135 | |
| 9136 | // Sum the total scan power for all apps. |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 9137 | totalScanTimeMs += uid.mWifiScanTimer.getTimeSinceMarkLocked( |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 9138 | elapsedRealtimeMs * 1000) / 1000; |
| 9139 | |
| 9140 | // Sum the total time holding wifi lock for all apps. |
| 9141 | totalWifiLockTimeMs += uid.mFullWifiLockTimer.getTimeSinceMarkLocked( |
| 9142 | elapsedRealtimeMs * 1000) / 1000; |
| 9143 | } |
| 9144 | |
| 9145 | if (DEBUG_ENERGY && totalScanTimeMs > rxTimeMs) { |
| 9146 | Slog.d(TAG, " !Estimated scan time > Actual rx time (" + totalScanTimeMs + " ms > " |
| 9147 | + rxTimeMs + " ms). Normalizing scan time."); |
| 9148 | } |
Mitchell Wills | f901649 | 2015-07-29 17:47:44 -0700 | [diff] [blame] | 9149 | if (DEBUG_ENERGY && totalScanTimeMs > txTimeMs) { |
| 9150 | Slog.d(TAG, " !Estimated scan time > Actual tx time (" + totalScanTimeMs + " ms > " |
| 9151 | + txTimeMs + " ms). Normalizing scan time."); |
| 9152 | } |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 9153 | |
| 9154 | // Actually assign and distribute power usage to apps. |
| 9155 | for (int i = 0; i < uidStatsSize; i++) { |
| 9156 | final Uid uid = mUidStats.valueAt(i); |
| 9157 | |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 9158 | long scanTimeSinceMarkMs = uid.mWifiScanTimer.getTimeSinceMarkLocked( |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 9159 | elapsedRealtimeMs * 1000) / 1000; |
| 9160 | if (scanTimeSinceMarkMs > 0) { |
| 9161 | // Set the new mark so that next time we get new data since this point. |
| 9162 | uid.mWifiScanTimer.setMark(elapsedRealtimeMs); |
| 9163 | |
Mitchell Wills | f901649 | 2015-07-29 17:47:44 -0700 | [diff] [blame] | 9164 | long scanRxTimeSinceMarkMs = scanTimeSinceMarkMs; |
| 9165 | long scanTxTimeSinceMarkMs = scanTimeSinceMarkMs; |
| 9166 | |
| 9167 | // Our total scan time is more than the reported Tx/Rx time. |
| 9168 | // This is possible because the cost of a scan is approximate. |
| 9169 | // Let's normalize the result so that we evenly blame each app |
| 9170 | // scanning. |
| 9171 | // |
| 9172 | // This means that we may have apps that transmitted/received packets not be |
| 9173 | // 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] | 9174 | if (totalScanTimeMs > rxTimeMs) { |
Mitchell Wills | f901649 | 2015-07-29 17:47:44 -0700 | [diff] [blame] | 9175 | scanRxTimeSinceMarkMs = (rxTimeMs * scanRxTimeSinceMarkMs) / |
| 9176 | totalScanTimeMs; |
| 9177 | } |
| 9178 | if (totalScanTimeMs > txTimeMs) { |
| 9179 | scanTxTimeSinceMarkMs = (txTimeMs * scanTxTimeSinceMarkMs) / |
| 9180 | totalScanTimeMs; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 9181 | } |
| 9182 | |
| 9183 | if (DEBUG_ENERGY) { |
Mitchell Wills | f901649 | 2015-07-29 17:47:44 -0700 | [diff] [blame] | 9184 | Slog.d(TAG, " ScanTime for UID " + uid.getUid() + ": Rx:" |
| 9185 | + scanRxTimeSinceMarkMs + " ms Tx:" |
| 9186 | + scanTxTimeSinceMarkMs + " ms)"); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 9187 | } |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 9188 | |
| 9189 | ControllerActivityCounterImpl activityCounter = |
| 9190 | uid.getOrCreateWifiControllerActivityLocked(); |
| 9191 | activityCounter.getRxTimeCounter().addCountLocked(scanRxTimeSinceMarkMs); |
| 9192 | activityCounter.getTxTimeCounters()[0].addCountLocked(scanTxTimeSinceMarkMs); |
Mitchell Wills | f901649 | 2015-07-29 17:47:44 -0700 | [diff] [blame] | 9193 | leftOverRxTimeMs -= scanRxTimeSinceMarkMs; |
| 9194 | leftOverTxTimeMs -= scanTxTimeSinceMarkMs; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 9195 | } |
| 9196 | |
| 9197 | // Distribute evenly the power consumed while Idle to each app holding a WiFi |
| 9198 | // lock. |
| 9199 | final long wifiLockTimeSinceMarkMs = uid.mFullWifiLockTimer.getTimeSinceMarkLocked( |
| 9200 | elapsedRealtimeMs * 1000) / 1000; |
| 9201 | if (wifiLockTimeSinceMarkMs > 0) { |
| 9202 | // Set the new mark so that next time we get new data since this point. |
| 9203 | uid.mFullWifiLockTimer.setMark(elapsedRealtimeMs); |
| 9204 | |
| 9205 | final long myIdleTimeMs = (wifiLockTimeSinceMarkMs * idleTimeMs) |
| 9206 | / totalWifiLockTimeMs; |
| 9207 | if (DEBUG_ENERGY) { |
| 9208 | Slog.d(TAG, " IdleTime for UID " + uid.getUid() + ": " |
| 9209 | + myIdleTimeMs + " ms"); |
| 9210 | } |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 9211 | uid.getOrCreateWifiControllerActivityLocked().getIdleTimeCounter() |
| 9212 | .addCountLocked(myIdleTimeMs); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 9213 | } |
| 9214 | } |
| 9215 | |
| 9216 | if (DEBUG_ENERGY) { |
| 9217 | Slog.d(TAG, " New RxPower: " + leftOverRxTimeMs + " ms"); |
Mitchell Wills | f901649 | 2015-07-29 17:47:44 -0700 | [diff] [blame] | 9218 | Slog.d(TAG, " New TxPower: " + leftOverTxTimeMs + " ms"); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 9219 | } |
| 9220 | |
Mitchell Wills | f901649 | 2015-07-29 17:47:44 -0700 | [diff] [blame] | 9221 | // Distribute the remaining Tx power appropriately between all apps that transmitted |
| 9222 | // packets. |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 9223 | for (int i = 0; i < txPackets.size(); i++) { |
| 9224 | final Uid uid = getUidStatsLocked(txPackets.keyAt(i)); |
Mitchell Wills | f901649 | 2015-07-29 17:47:44 -0700 | [diff] [blame] | 9225 | final long myTxTimeMs = (txPackets.valueAt(i) * leftOverTxTimeMs) / totalTxPackets; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 9226 | if (DEBUG_ENERGY) { |
| 9227 | Slog.d(TAG, " TxTime for UID " + uid.getUid() + ": " + myTxTimeMs + " ms"); |
| 9228 | } |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 9229 | uid.getOrCreateWifiControllerActivityLocked().getTxTimeCounters()[0] |
| 9230 | .addCountLocked(myTxTimeMs); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 9231 | } |
| 9232 | |
| 9233 | // Distribute the remaining Rx power appropriately between all apps that received |
| 9234 | // packets. |
| 9235 | for (int i = 0; i < rxPackets.size(); i++) { |
| 9236 | final Uid uid = getUidStatsLocked(rxPackets.keyAt(i)); |
| 9237 | final long myRxTimeMs = (rxPackets.valueAt(i) * leftOverRxTimeMs) / totalRxPackets; |
| 9238 | if (DEBUG_ENERGY) { |
| 9239 | Slog.d(TAG, " RxTime for UID " + uid.getUid() + ": " + myRxTimeMs + " ms"); |
| 9240 | } |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 9241 | uid.getOrCreateWifiControllerActivityLocked().getRxTimeCounter() |
| 9242 | .addCountLocked(myRxTimeMs); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 9243 | } |
| 9244 | |
| 9245 | // Any left over power use will be picked up by the WiFi category in BatteryStatsHelper. |
| 9246 | |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 9247 | // Update WiFi controller stats. |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 9248 | mWifiActivity.getRxTimeCounter().addCountLocked(info.getControllerRxTimeMillis()); |
| 9249 | mWifiActivity.getTxTimeCounters()[0].addCountLocked(info.getControllerTxTimeMillis()); |
| 9250 | mWifiActivity.getIdleTimeCounter().addCountLocked(info.getControllerIdleTimeMillis()); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 9251 | |
Adam Lesinski | 8576cf9 | 2015-06-09 12:48:25 -0700 | [diff] [blame] | 9252 | // POWER_WIFI_CONTROLLER_OPERATING_VOLTAGE is measured in mV, so convert to V. |
| 9253 | final double opVolt = mPowerProfile.getAveragePower( |
| 9254 | PowerProfile.POWER_WIFI_CONTROLLER_OPERATING_VOLTAGE) / 1000.0; |
| 9255 | if (opVolt != 0) { |
| 9256 | // We store the power drain as mAms. |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 9257 | mWifiActivity.getPowerCounter().addCountLocked( |
Adam Lesinski | 8576cf9 | 2015-06-09 12:48:25 -0700 | [diff] [blame] | 9258 | (long)(info.getControllerEnergyUsed() / opVolt)); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 9259 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 9260 | } |
| 9261 | } |
| 9262 | |
| 9263 | /** |
| 9264 | * Distribute Cell radio energy info and network traffic to apps. |
| 9265 | */ |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 9266 | public void updateMobileRadioStateLocked(final long elapsedRealtimeMs, |
| 9267 | final ModemActivityInfo activityInfo) { |
Adam Lesinski | a7c90c8 | 2015-06-18 14:52:24 -0700 | [diff] [blame] | 9268 | if (DEBUG_ENERGY) { |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 9269 | Slog.d(TAG, "Updating mobile radio stats with " + activityInfo); |
Adam Lesinski | a7c90c8 | 2015-06-18 14:52:24 -0700 | [diff] [blame] | 9270 | } |
| 9271 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 9272 | NetworkStats delta = null; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 9273 | try { |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 9274 | if (!ArrayUtils.isEmpty(mMobileIfaces)) { |
| 9275 | delta = getNetworkStatsDeltaLocked(mMobileIfaces, mMobileNetworkStats); |
| 9276 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 9277 | } catch (IOException e) { |
| 9278 | Slog.wtf(TAG, "Failed to get mobile network stats", e); |
| 9279 | return; |
| 9280 | } |
| 9281 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 9282 | if (!mOnBatteryInternal) { |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 9283 | return; |
| 9284 | } |
| 9285 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 9286 | long radioTime = mMobileRadioActivePerAppTimer.getTimeSinceMarkLocked( |
| 9287 | elapsedRealtimeMs * 1000); |
| 9288 | mMobileRadioActivePerAppTimer.setMark(elapsedRealtimeMs); |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 9289 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 9290 | long totalRxPackets = 0; |
| 9291 | long totalTxPackets = 0; |
| 9292 | if (delta != null) { |
| 9293 | final int size = delta.size(); |
| 9294 | for (int i = 0; i < size; i++) { |
| 9295 | final NetworkStats.Entry entry = delta.getValues(i, mTmpNetworkStatsEntry); |
Adam Lesinski | a426817 | 2016-01-29 12:13:54 -0800 | [diff] [blame] | 9296 | if (entry.rxPackets == 0 && entry.txPackets == 0) { |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 9297 | continue; |
| 9298 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 9299 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 9300 | if (DEBUG_ENERGY) { |
| 9301 | Slog.d(TAG, "Mobile uid " + entry.uid + ": delta rx=" + entry.rxBytes |
| 9302 | + " tx=" + entry.txBytes + " rxPackets=" + entry.rxPackets |
| 9303 | + " txPackets=" + entry.txPackets); |
| 9304 | } |
| 9305 | |
| 9306 | totalRxPackets += entry.rxPackets; |
| 9307 | totalTxPackets += entry.txPackets; |
| 9308 | |
| 9309 | final Uid u = getUidStatsLocked(mapUid(entry.uid)); |
| 9310 | u.noteNetworkActivityLocked(NETWORK_MOBILE_RX_DATA, entry.rxBytes, entry.rxPackets); |
| 9311 | u.noteNetworkActivityLocked(NETWORK_MOBILE_TX_DATA, entry.txBytes, entry.txPackets); |
Amith Yamasani | 59fe841 | 2017-03-03 16:28:52 -0800 | [diff] [blame] | 9312 | if (entry.set == NetworkStats.SET_DEFAULT) { // Background transfers |
| 9313 | u.noteNetworkActivityLocked(NETWORK_MOBILE_BG_RX_DATA, |
| 9314 | entry.rxBytes, entry.rxPackets); |
| 9315 | u.noteNetworkActivityLocked(NETWORK_MOBILE_BG_TX_DATA, |
| 9316 | entry.txBytes, entry.txPackets); |
| 9317 | } |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 9318 | |
| 9319 | mNetworkByteActivityCounters[NETWORK_MOBILE_RX_DATA].addCountLocked( |
| 9320 | entry.rxBytes); |
| 9321 | mNetworkByteActivityCounters[NETWORK_MOBILE_TX_DATA].addCountLocked( |
| 9322 | entry.txBytes); |
| 9323 | mNetworkPacketActivityCounters[NETWORK_MOBILE_RX_DATA].addCountLocked( |
| 9324 | entry.rxPackets); |
| 9325 | mNetworkPacketActivityCounters[NETWORK_MOBILE_TX_DATA].addCountLocked( |
| 9326 | entry.txPackets); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 9327 | } |
| 9328 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 9329 | // Now distribute proportional blame to the apps that did networking. |
| 9330 | long totalPackets = totalRxPackets + totalTxPackets; |
| 9331 | if (totalPackets > 0) { |
| 9332 | for (int i = 0; i < size; i++) { |
| 9333 | final NetworkStats.Entry entry = delta.getValues(i, mTmpNetworkStatsEntry); |
| 9334 | if (entry.rxPackets == 0 && entry.txPackets == 0) { |
| 9335 | continue; |
| 9336 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 9337 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 9338 | final Uid u = getUidStatsLocked(mapUid(entry.uid)); |
| 9339 | |
| 9340 | // Distribute total radio active time in to this app. |
| 9341 | final long appPackets = entry.rxPackets + entry.txPackets; |
| 9342 | final long appRadioTime = (radioTime * appPackets) / totalPackets; |
| 9343 | u.noteMobileRadioActiveTimeLocked(appRadioTime); |
| 9344 | |
| 9345 | // Remove this app from the totals, so that we don't lose any time |
| 9346 | // due to rounding. |
| 9347 | radioTime -= appRadioTime; |
| 9348 | totalPackets -= appPackets; |
| 9349 | |
| 9350 | if (activityInfo != null) { |
| 9351 | ControllerActivityCounterImpl activityCounter = |
| 9352 | u.getOrCreateModemControllerActivityLocked(); |
Adam Lesinski | a426817 | 2016-01-29 12:13:54 -0800 | [diff] [blame] | 9353 | if (totalRxPackets > 0 && entry.rxPackets > 0) { |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 9354 | final long rxMs = (entry.rxPackets * activityInfo.getRxTimeMillis()) |
| 9355 | / totalRxPackets; |
| 9356 | activityCounter.getRxTimeCounter().addCountLocked(rxMs); |
| 9357 | } |
| 9358 | |
Adam Lesinski | a426817 | 2016-01-29 12:13:54 -0800 | [diff] [blame] | 9359 | if (totalTxPackets > 0 && entry.txPackets > 0) { |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 9360 | for (int lvl = 0; lvl < ModemActivityInfo.TX_POWER_LEVELS; lvl++) { |
| 9361 | long txMs = entry.txPackets * activityInfo.getTxTimeMillis()[lvl]; |
| 9362 | txMs /= totalTxPackets; |
| 9363 | activityCounter.getTxTimeCounters()[lvl].addCountLocked(txMs); |
| 9364 | } |
| 9365 | } |
| 9366 | } |
| 9367 | } |
| 9368 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 9369 | |
| 9370 | if (radioTime > 0) { |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 9371 | // Whoops, there is some radio time we can't blame on an app! |
| 9372 | mMobileRadioActiveUnknownTime.addCountLocked(radioTime); |
| 9373 | mMobileRadioActiveUnknownCount.addCountLocked(1); |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 9374 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 9375 | } |
| 9376 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 9377 | if (activityInfo != null) { |
| 9378 | mHasModemReporting = true; |
| 9379 | mModemActivity.getIdleTimeCounter().addCountLocked(activityInfo.getIdleTimeMillis()); |
| 9380 | mModemActivity.getRxTimeCounter().addCountLocked(activityInfo.getRxTimeMillis()); |
| 9381 | for (int lvl = 0; lvl < ModemActivityInfo.TX_POWER_LEVELS; lvl++) { |
| 9382 | mModemActivity.getTxTimeCounters()[lvl] |
| 9383 | .addCountLocked(activityInfo.getTxTimeMillis()[lvl]); |
| 9384 | } |
| 9385 | |
| 9386 | // POWER_MODEM_CONTROLLER_OPERATING_VOLTAGE is measured in mV, so convert to V. |
| 9387 | final double opVolt = mPowerProfile.getAveragePower( |
| 9388 | PowerProfile.POWER_MODEM_CONTROLLER_OPERATING_VOLTAGE) / 1000.0; |
| 9389 | if (opVolt != 0) { |
| 9390 | // We store the power drain as mAms. |
| 9391 | mModemActivity.getPowerCounter().addCountLocked( |
| 9392 | (long) (activityInfo.getEnergyUsed() / opVolt)); |
| 9393 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 9394 | } |
| 9395 | } |
| 9396 | |
| 9397 | /** |
| 9398 | * Distribute Bluetooth energy info and network traffic to apps. |
| 9399 | * @param info The energy information from the bluetooth controller. |
| 9400 | */ |
| 9401 | public void updateBluetoothStateLocked(@Nullable final BluetoothActivityEnergyInfo info) { |
Adam Lesinski | a7c90c8 | 2015-06-18 14:52:24 -0700 | [diff] [blame] | 9402 | if (DEBUG_ENERGY) { |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 9403 | Slog.d(TAG, "Updating bluetooth stats: " + info); |
Adam Lesinski | a7c90c8 | 2015-06-18 14:52:24 -0700 | [diff] [blame] | 9404 | } |
| 9405 | |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 9406 | if (info == null || !mOnBatteryInternal) { |
| 9407 | return; |
| 9408 | } |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 9409 | |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 9410 | mHasBluetoothReporting = true; |
| 9411 | |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 9412 | final long elapsedRealtimeMs = mClocks.elapsedRealtime(); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 9413 | final long rxTimeMs = info.getControllerRxTimeMillis(); |
| 9414 | final long txTimeMs = info.getControllerTxTimeMillis(); |
| 9415 | |
| 9416 | if (DEBUG_ENERGY) { |
| 9417 | Slog.d(TAG, "------ BEGIN BLE power blaming ------"); |
| 9418 | Slog.d(TAG, " Tx Time: " + txTimeMs + " ms"); |
| 9419 | Slog.d(TAG, " Rx Time: " + rxTimeMs + " ms"); |
| 9420 | Slog.d(TAG, " Idle Time: " + info.getControllerIdleTimeMillis() + " ms"); |
| 9421 | } |
| 9422 | |
| 9423 | long totalScanTimeMs = 0; |
| 9424 | |
| 9425 | final int uidCount = mUidStats.size(); |
| 9426 | for (int i = 0; i < uidCount; i++) { |
| 9427 | final Uid u = mUidStats.valueAt(i); |
| 9428 | if (u.mBluetoothScanTimer == null) { |
| 9429 | continue; |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 9430 | } |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 9431 | |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 9432 | totalScanTimeMs += u.mBluetoothScanTimer.getTimeSinceMarkLocked( |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 9433 | elapsedRealtimeMs * 1000) / 1000; |
| 9434 | } |
| 9435 | |
| 9436 | final boolean normalizeScanRxTime = (totalScanTimeMs > rxTimeMs); |
| 9437 | final boolean normalizeScanTxTime = (totalScanTimeMs > txTimeMs); |
| 9438 | |
| 9439 | if (DEBUG_ENERGY) { |
| 9440 | Slog.d(TAG, "Normalizing scan power for RX=" + normalizeScanRxTime |
| 9441 | + " TX=" + normalizeScanTxTime); |
| 9442 | } |
| 9443 | |
| 9444 | long leftOverRxTimeMs = rxTimeMs; |
| 9445 | long leftOverTxTimeMs = txTimeMs; |
| 9446 | |
| 9447 | for (int i = 0; i < uidCount; i++) { |
| 9448 | final Uid u = mUidStats.valueAt(i); |
| 9449 | if (u.mBluetoothScanTimer == null) { |
| 9450 | continue; |
| 9451 | } |
| 9452 | |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 9453 | long scanTimeSinceMarkMs = u.mBluetoothScanTimer.getTimeSinceMarkLocked( |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 9454 | elapsedRealtimeMs * 1000) / 1000; |
| 9455 | if (scanTimeSinceMarkMs > 0) { |
| 9456 | // Set the new mark so that next time we get new data since this point. |
| 9457 | u.mBluetoothScanTimer.setMark(elapsedRealtimeMs); |
| 9458 | |
| 9459 | long scanTimeRxSinceMarkMs = scanTimeSinceMarkMs; |
| 9460 | long scanTimeTxSinceMarkMs = scanTimeSinceMarkMs; |
| 9461 | |
| 9462 | if (normalizeScanRxTime) { |
| 9463 | // Scan time is longer than the total rx time in the controller, |
| 9464 | // so distribute the scan time proportionately. This means regular traffic |
| 9465 | // will not blamed, but scans are more expensive anyways. |
| 9466 | scanTimeRxSinceMarkMs = (rxTimeMs * scanTimeRxSinceMarkMs) / totalScanTimeMs; |
| 9467 | } |
| 9468 | |
| 9469 | if (normalizeScanTxTime) { |
| 9470 | // Scan time is longer than the total tx time in the controller, |
| 9471 | // so distribute the scan time proportionately. This means regular traffic |
| 9472 | // will not blamed, but scans are more expensive anyways. |
| 9473 | scanTimeTxSinceMarkMs = (txTimeMs * scanTimeTxSinceMarkMs) / totalScanTimeMs; |
| 9474 | } |
| 9475 | |
| 9476 | final ControllerActivityCounterImpl counter = |
| 9477 | u.getOrCreateBluetoothControllerActivityLocked(); |
| 9478 | counter.getRxTimeCounter().addCountLocked(scanTimeRxSinceMarkMs); |
| 9479 | counter.getTxTimeCounters()[0].addCountLocked(scanTimeTxSinceMarkMs); |
| 9480 | |
| 9481 | leftOverRxTimeMs -= scanTimeRxSinceMarkMs; |
| 9482 | leftOverTxTimeMs -= scanTimeTxSinceMarkMs; |
| 9483 | } |
| 9484 | } |
| 9485 | |
| 9486 | if (DEBUG_ENERGY) { |
| 9487 | Slog.d(TAG, "Left over time for traffic RX=" + leftOverRxTimeMs |
| 9488 | + " TX=" + leftOverTxTimeMs); |
| 9489 | } |
| 9490 | |
| 9491 | // |
| 9492 | // Now distribute blame to apps that did bluetooth traffic. |
| 9493 | // |
| 9494 | |
| 9495 | long totalTxBytes = 0; |
| 9496 | long totalRxBytes = 0; |
| 9497 | |
| 9498 | final UidTraffic[] uidTraffic = info.getUidTraffic(); |
| 9499 | final int numUids = uidTraffic != null ? uidTraffic.length : 0; |
| 9500 | for (int i = 0; i < numUids; i++) { |
| 9501 | final UidTraffic traffic = uidTraffic[i]; |
| 9502 | |
| 9503 | // Add to the global counters. |
| 9504 | mNetworkByteActivityCounters[NETWORK_BT_RX_DATA].addCountLocked( |
| 9505 | traffic.getRxBytes()); |
| 9506 | mNetworkByteActivityCounters[NETWORK_BT_TX_DATA].addCountLocked( |
| 9507 | traffic.getTxBytes()); |
| 9508 | |
| 9509 | // Add to the UID counters. |
| 9510 | final Uid u = getUidStatsLocked(mapUid(traffic.getUid())); |
| 9511 | u.noteNetworkActivityLocked(NETWORK_BT_RX_DATA, traffic.getRxBytes(), 0); |
| 9512 | u.noteNetworkActivityLocked(NETWORK_BT_TX_DATA, traffic.getTxBytes(), 0); |
| 9513 | |
| 9514 | // Calculate the total traffic. |
| 9515 | totalTxBytes += traffic.getTxBytes(); |
| 9516 | totalRxBytes += traffic.getRxBytes(); |
| 9517 | } |
| 9518 | |
| 9519 | if ((totalTxBytes != 0 || totalRxBytes != 0) && |
| 9520 | (leftOverRxTimeMs != 0 || leftOverTxTimeMs != 0)) { |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 9521 | for (int i = 0; i < numUids; i++) { |
| 9522 | final UidTraffic traffic = uidTraffic[i]; |
| 9523 | |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 9524 | final Uid u = getUidStatsLocked(mapUid(traffic.getUid())); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 9525 | final ControllerActivityCounterImpl counter = |
| 9526 | u.getOrCreateBluetoothControllerActivityLocked(); |
| 9527 | |
| 9528 | if (totalRxBytes > 0 && traffic.getRxBytes() > 0) { |
| 9529 | final long timeRxMs = (leftOverRxTimeMs * traffic.getRxBytes()) / totalRxBytes; |
| 9530 | |
| 9531 | if (DEBUG_ENERGY) { |
| 9532 | Slog.d(TAG, "UID=" + traffic.getUid() + " rx_bytes=" + traffic.getRxBytes() |
| 9533 | + " rx_time=" + timeRxMs); |
| 9534 | } |
| 9535 | counter.getRxTimeCounter().addCountLocked(timeRxMs); |
| 9536 | leftOverRxTimeMs -= timeRxMs; |
| 9537 | } |
| 9538 | |
| 9539 | if (totalTxBytes > 0 && traffic.getTxBytes() > 0) { |
| 9540 | final long timeTxMs = (leftOverTxTimeMs * traffic.getTxBytes()) / totalTxBytes; |
| 9541 | |
| 9542 | if (DEBUG_ENERGY) { |
| 9543 | Slog.d(TAG, "UID=" + traffic.getUid() + " tx_bytes=" + traffic.getTxBytes() |
| 9544 | + " tx_time=" + timeTxMs); |
| 9545 | } |
| 9546 | |
| 9547 | counter.getTxTimeCounters()[0].addCountLocked(timeTxMs); |
| 9548 | leftOverTxTimeMs -= timeTxMs; |
| 9549 | } |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 9550 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 9551 | } |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 9552 | |
| 9553 | mBluetoothActivity.getRxTimeCounter().addCountLocked( |
| 9554 | info.getControllerRxTimeMillis()); |
| 9555 | mBluetoothActivity.getTxTimeCounters()[0].addCountLocked( |
| 9556 | info.getControllerTxTimeMillis()); |
| 9557 | mBluetoothActivity.getIdleTimeCounter().addCountLocked( |
| 9558 | info.getControllerIdleTimeMillis()); |
| 9559 | |
| 9560 | // POWER_BLUETOOTH_CONTROLLER_OPERATING_VOLTAGE is measured in mV, so convert to V. |
| 9561 | final double opVolt = mPowerProfile.getAveragePower( |
| 9562 | PowerProfile.POWER_BLUETOOTH_CONTROLLER_OPERATING_VOLTAGE) / 1000.0; |
| 9563 | if (opVolt != 0) { |
| 9564 | // We store the power drain as mAms. |
| 9565 | mBluetoothActivity.getPowerCounter().addCountLocked( |
| 9566 | (long) (info.getControllerEnergyUsed() / opVolt)); |
| 9567 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 9568 | } |
| 9569 | |
| 9570 | /** |
| 9571 | * Read and distribute kernel wake lock use across apps. |
| 9572 | */ |
| 9573 | public void updateKernelWakelocksLocked() { |
| 9574 | final KernelWakelockStats wakelockStats = mKernelWakelockReader.readKernelWakelockStats( |
| 9575 | mTmpWakelockStats); |
| 9576 | if (wakelockStats == null) { |
| 9577 | // Not crashing might make board bringup easier. |
| 9578 | Slog.w(TAG, "Couldn't get kernel wake lock stats"); |
| 9579 | return; |
| 9580 | } |
| 9581 | |
| 9582 | for (Map.Entry<String, KernelWakelockStats.Entry> ent : wakelockStats.entrySet()) { |
| 9583 | String name = ent.getKey(); |
| 9584 | KernelWakelockStats.Entry kws = ent.getValue(); |
| 9585 | |
| 9586 | SamplingTimer kwlt = mKernelWakelockStats.get(name); |
| 9587 | if (kwlt == null) { |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 9588 | kwlt = new SamplingTimer(mClocks, mOnBatteryScreenOffTimeBase); |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 9589 | mKernelWakelockStats.put(name, kwlt); |
| 9590 | } |
Adam Lesinski | d84ad30 | 2016-05-17 18:31:02 -0700 | [diff] [blame] | 9591 | |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 9592 | kwlt.update(kws.mTotalTime, kws.mCount); |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 9593 | kwlt.setUpdateVersion(kws.mVersion); |
| 9594 | } |
| 9595 | |
Adam Lesinski | fbabe7d | 2015-08-03 14:37:38 -0700 | [diff] [blame] | 9596 | int numWakelocksSetStale = 0; |
Adam Lesinski | d84ad30 | 2016-05-17 18:31:02 -0700 | [diff] [blame] | 9597 | // Set timers to stale if they didn't appear in /d/wakeup_sources (or /proc/wakelocks) |
| 9598 | // this time. |
| 9599 | for (Map.Entry<String, SamplingTimer> ent : mKernelWakelockStats.entrySet()) { |
| 9600 | SamplingTimer st = ent.getValue(); |
| 9601 | if (st.getUpdateVersion() != wakelockStats.kernelWakelockVersion) { |
| 9602 | st.endSample(); |
| 9603 | numWakelocksSetStale++; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 9604 | } |
| 9605 | } |
Adam Lesinski | fbabe7d | 2015-08-03 14:37:38 -0700 | [diff] [blame] | 9606 | |
Adam Lesinski | d84ad30 | 2016-05-17 18:31:02 -0700 | [diff] [blame] | 9607 | // Record whether we've seen a non-zero time (for debugging b/22716723). |
| 9608 | if (wakelockStats.isEmpty()) { |
Adam Lesinski | fbabe7d | 2015-08-03 14:37:38 -0700 | [diff] [blame] | 9609 | Slog.wtf(TAG, "All kernel wakelocks had time of zero"); |
| 9610 | } |
| 9611 | |
| 9612 | if (numWakelocksSetStale == mKernelWakelockStats.size()) { |
| 9613 | Slog.wtf(TAG, "All kernel wakelocks were set stale. new version=" + |
| 9614 | wakelockStats.kernelWakelockVersion); |
| 9615 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 9616 | } |
| 9617 | |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 9618 | // We use an anonymous class to access these variables, |
| 9619 | // so they can't live on the stack or they'd have to be |
| 9620 | // final MutableLong objects (more allocations). |
| 9621 | // Used in updateCpuTimeLocked(). |
| 9622 | long mTempTotalCpuUserTimeUs; |
| 9623 | long mTempTotalCpuSystemTimeUs; |
| 9624 | |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 9625 | /** |
James Carr | 3a22605 | 2016-07-01 14:49:52 -0700 | [diff] [blame] | 9626 | * Reads the newest memory stats from the kernel. |
| 9627 | */ |
| 9628 | public void updateKernelMemoryBandwidthLocked() { |
| 9629 | mKernelMemoryBandwidthStats.updateStats(); |
| 9630 | LongSparseLongArray bandwidthEntries = mKernelMemoryBandwidthStats.getBandwidthEntries(); |
| 9631 | final int bandwidthEntryCount = bandwidthEntries.size(); |
| 9632 | int index; |
| 9633 | for (int i = 0; i < bandwidthEntryCount; i++) { |
| 9634 | SamplingTimer timer; |
| 9635 | if ((index = mKernelMemoryStats.indexOfKey(bandwidthEntries.keyAt(i))) >= 0) { |
| 9636 | timer = mKernelMemoryStats.valueAt(index); |
| 9637 | } else { |
| 9638 | timer = new SamplingTimer(mClocks, mOnBatteryTimeBase); |
| 9639 | mKernelMemoryStats.put(bandwidthEntries.keyAt(i), timer); |
| 9640 | } |
| 9641 | timer.update(bandwidthEntries.valueAt(i), 1); |
| 9642 | if (DEBUG_MEMORY) { |
| 9643 | Slog.d(TAG, String.format("Added entry %d and updated timer to: " |
| 9644 | + "mUnpluggedReportedTotalTime %d size %d", bandwidthEntries.keyAt(i), |
| 9645 | mKernelMemoryStats.get( |
| 9646 | bandwidthEntries.keyAt(i)).mUnpluggedReportedTotalTime, |
| 9647 | mKernelMemoryStats.size())); |
| 9648 | } |
| 9649 | } |
| 9650 | } |
| 9651 | |
| 9652 | /** |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 9653 | * Read and distribute CPU usage across apps. If their are partial wakelocks being held |
| 9654 | * and we are on battery with screen off, we give more of the cpu time to those apps holding |
| 9655 | * 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] | 9656 | */ |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 9657 | public void updateCpuTimeLocked() { |
Adam Lesinski | 52290c9c | 2015-09-21 16:54:52 -0700 | [diff] [blame] | 9658 | if (mPowerProfile == null) { |
| 9659 | return; |
| 9660 | } |
| 9661 | |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 9662 | if (DEBUG_ENERGY_CPU) { |
| 9663 | Slog.d(TAG, "!Cpu updating!"); |
| 9664 | } |
| 9665 | |
| 9666 | // Holding a wakelock costs more than just using the cpu. |
| 9667 | // Currently, we assign only half the cpu time to an app that is running but |
| 9668 | // not holding a wakelock. The apps holding wakelocks get the rest of the blame. |
| 9669 | // If no app is holding a wakelock, then the distribution is normal. |
| 9670 | final int wakelockWeight = 50; |
| 9671 | |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 9672 | // Read the time spent for each cluster at various cpu frequencies. |
| 9673 | final long[][] clusterSpeeds = new long[mKernelCpuSpeedReaders.length][]; |
| 9674 | for (int cluster = 0; cluster < mKernelCpuSpeedReaders.length; cluster++) { |
| 9675 | clusterSpeeds[cluster] = mKernelCpuSpeedReaders[cluster].readDelta(); |
| 9676 | } |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 9677 | |
| 9678 | int numWakelocks = 0; |
| 9679 | |
| 9680 | // Calculate how many wakelocks we have to distribute amongst. The system is excluded. |
| 9681 | // Only distribute cpu power to wakelocks if the screen is off and we're on battery. |
| 9682 | final int numPartialTimers = mPartialTimers.size(); |
| 9683 | if (mOnBatteryScreenOffTimeBase.isRunning()) { |
| 9684 | for (int i = 0; i < numPartialTimers; i++) { |
| 9685 | final StopwatchTimer timer = mPartialTimers.get(i); |
| 9686 | if (timer.mInList && timer.mUid != null && timer.mUid.mUid != Process.SYSTEM_UID) { |
| 9687 | // Since the collection and blaming of wakelocks can be scheduled to run after |
| 9688 | // some delay, the mPartialTimers list may have new entries. We can't blame |
| 9689 | // the newly added timer for past cpu time, so we only consider timers that |
| 9690 | // were present for one round of collection. Once a timer has gone through |
| 9691 | // a round of collection, its mInList field is set to true. |
| 9692 | numWakelocks++; |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 9693 | } |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 9694 | } |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 9695 | } |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 9696 | |
| 9697 | final int numWakelocksF = numWakelocks; |
| 9698 | mTempTotalCpuUserTimeUs = 0; |
| 9699 | mTempTotalCpuSystemTimeUs = 0; |
| 9700 | |
| 9701 | // Read the CPU data for each UID. This will internally generate a snapshot so next time |
| 9702 | // we read, we get a delta. If we are to distribute the cpu time, then do so. Otherwise |
| 9703 | // we just ignore the data. |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9704 | final long startTimeMs = mClocks.elapsedRealtime(); |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 9705 | mKernelUidCpuTimeReader.readDelta(!mOnBatteryInternal ? null : |
| 9706 | new KernelUidCpuTimeReader.Callback() { |
| 9707 | @Override |
Adam Lesinski | d4abd1e | 2017-04-12 11:29:13 -0700 | [diff] [blame] | 9708 | public void onUidCpuTime(int uid, long userTimeUs, long systemTimeUs) { |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 9709 | final Uid u = getUidStatsLocked(mapUid(uid)); |
| 9710 | |
| 9711 | // Accumulate the total system and user time. |
| 9712 | mTempTotalCpuUserTimeUs += userTimeUs; |
| 9713 | mTempTotalCpuSystemTimeUs += systemTimeUs; |
| 9714 | |
| 9715 | StringBuilder sb = null; |
| 9716 | if (DEBUG_ENERGY_CPU) { |
| 9717 | sb = new StringBuilder(); |
| 9718 | sb.append(" got time for uid=").append(u.mUid).append(": u="); |
| 9719 | TimeUtils.formatDuration(userTimeUs / 1000, sb); |
| 9720 | sb.append(" s="); |
| 9721 | TimeUtils.formatDuration(systemTimeUs / 1000, sb); |
Adam Lesinski | d4abd1e | 2017-04-12 11:29:13 -0700 | [diff] [blame] | 9722 | sb.append("\n"); |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 9723 | } |
| 9724 | |
| 9725 | if (numWakelocksF > 0) { |
| 9726 | // We have wakelocks being held, so only give a portion of the |
| 9727 | // time to the process. The rest will be distributed among wakelock |
| 9728 | // holders. |
| 9729 | userTimeUs = (userTimeUs * wakelockWeight) / 100; |
| 9730 | systemTimeUs = (systemTimeUs * wakelockWeight) / 100; |
| 9731 | } |
| 9732 | |
| 9733 | if (sb != null) { |
| 9734 | sb.append(" adding to uid=").append(u.mUid).append(": u="); |
| 9735 | TimeUtils.formatDuration(userTimeUs / 1000, sb); |
| 9736 | sb.append(" s="); |
| 9737 | TimeUtils.formatDuration(systemTimeUs / 1000, sb); |
| 9738 | Slog.d(TAG, sb.toString()); |
| 9739 | } |
| 9740 | |
| 9741 | u.mUserCpuTime.addCountLocked(userTimeUs); |
| 9742 | u.mSystemCpuTime.addCountLocked(systemTimeUs); |
| 9743 | |
| 9744 | // Add the cpu speeds to this UID. These are used as a ratio |
| 9745 | // for computing the power this UID used. |
Adam Lesinski | 52290c9c | 2015-09-21 16:54:52 -0700 | [diff] [blame] | 9746 | final int numClusters = mPowerProfile.getNumCpuClusters(); |
| 9747 | if (u.mCpuClusterSpeed == null || u.mCpuClusterSpeed.length != |
| 9748 | numClusters) { |
| 9749 | u.mCpuClusterSpeed = new LongSamplingCounter[numClusters][]; |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 9750 | } |
| 9751 | |
| 9752 | for (int cluster = 0; cluster < clusterSpeeds.length; cluster++) { |
Adam Lesinski | 52290c9c | 2015-09-21 16:54:52 -0700 | [diff] [blame] | 9753 | final int speedsInCluster = mPowerProfile.getNumSpeedStepsInCpuCluster( |
| 9754 | cluster); |
| 9755 | if (u.mCpuClusterSpeed[cluster] == null || speedsInCluster != |
| 9756 | u.mCpuClusterSpeed[cluster].length) { |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 9757 | u.mCpuClusterSpeed[cluster] = |
Adam Lesinski | 52290c9c | 2015-09-21 16:54:52 -0700 | [diff] [blame] | 9758 | new LongSamplingCounter[speedsInCluster]; |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 9759 | } |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 9760 | |
| 9761 | final LongSamplingCounter[] cpuSpeeds = u.mCpuClusterSpeed[cluster]; |
| 9762 | for (int speed = 0; speed < clusterSpeeds[cluster].length; speed++) { |
| 9763 | if (cpuSpeeds[speed] == null) { |
| 9764 | cpuSpeeds[speed] = new LongSamplingCounter(mOnBatteryTimeBase); |
| 9765 | } |
| 9766 | cpuSpeeds[speed].addCountLocked(clusterSpeeds[cluster][speed]); |
| 9767 | } |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 9768 | } |
| 9769 | } |
| 9770 | }); |
| 9771 | |
Amith Yamasani | d245086 | 2017-02-07 15:58:24 -0800 | [diff] [blame] | 9772 | // TODO: STOPSHIP, remove the "true" below after b/34961340 is fixed |
| 9773 | if (DEBUG_ENERGY_CPU || true) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9774 | Slog.d(TAG, "Reading cpu stats took " + (mClocks.elapsedRealtime() - startTimeMs) + |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 9775 | " ms"); |
| 9776 | } |
| 9777 | |
| 9778 | if (mOnBatteryInternal && numWakelocks > 0) { |
| 9779 | // Distribute a portion of the total cpu time to wakelock holders. |
| 9780 | mTempTotalCpuUserTimeUs = (mTempTotalCpuUserTimeUs * (100 - wakelockWeight)) / 100; |
| 9781 | mTempTotalCpuSystemTimeUs = |
| 9782 | (mTempTotalCpuSystemTimeUs * (100 - wakelockWeight)) / 100; |
| 9783 | |
| 9784 | for (int i = 0; i < numPartialTimers; i++) { |
| 9785 | final StopwatchTimer timer = mPartialTimers.get(i); |
| 9786 | |
| 9787 | // The system does not share any blame, as it is usually holding the wakelock |
| 9788 | // on behalf of an app. |
| 9789 | if (timer.mInList && timer.mUid != null && timer.mUid.mUid != Process.SYSTEM_UID) { |
| 9790 | int userTimeUs = (int) (mTempTotalCpuUserTimeUs / numWakelocks); |
| 9791 | int systemTimeUs = (int) (mTempTotalCpuSystemTimeUs / numWakelocks); |
| 9792 | |
| 9793 | if (DEBUG_ENERGY_CPU) { |
| 9794 | StringBuilder sb = new StringBuilder(); |
| 9795 | sb.append(" Distributing wakelock uid=").append(timer.mUid.mUid) |
| 9796 | .append(": u="); |
| 9797 | TimeUtils.formatDuration(userTimeUs / 1000, sb); |
| 9798 | sb.append(" s="); |
| 9799 | TimeUtils.formatDuration(systemTimeUs / 1000, sb); |
| 9800 | Slog.d(TAG, sb.toString()); |
| 9801 | } |
| 9802 | |
| 9803 | timer.mUid.mUserCpuTime.addCountLocked(userTimeUs); |
| 9804 | timer.mUid.mSystemCpuTime.addCountLocked(systemTimeUs); |
| 9805 | |
| 9806 | final Uid.Proc proc = timer.mUid.getProcessStatsLocked("*wakelock*"); |
Adam Lesinski | 062e66c | 2015-07-14 12:02:44 -0700 | [diff] [blame] | 9807 | proc.addCpuTimeLocked(userTimeUs / 1000, systemTimeUs / 1000); |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 9808 | |
| 9809 | mTempTotalCpuUserTimeUs -= userTimeUs; |
| 9810 | mTempTotalCpuSystemTimeUs -= systemTimeUs; |
| 9811 | numWakelocks--; |
| 9812 | } |
| 9813 | } |
| 9814 | |
| 9815 | if (mTempTotalCpuUserTimeUs > 0 || mTempTotalCpuSystemTimeUs > 0) { |
| 9816 | // Anything left over is given to the system. |
| 9817 | if (DEBUG_ENERGY_CPU) { |
| 9818 | StringBuilder sb = new StringBuilder(); |
| 9819 | sb.append(" Distributing lost time to system: u="); |
| 9820 | TimeUtils.formatDuration(mTempTotalCpuUserTimeUs / 1000, sb); |
| 9821 | sb.append(" s="); |
| 9822 | TimeUtils.formatDuration(mTempTotalCpuSystemTimeUs / 1000, sb); |
| 9823 | Slog.d(TAG, sb.toString()); |
| 9824 | } |
| 9825 | |
| 9826 | final Uid u = getUidStatsLocked(Process.SYSTEM_UID); |
| 9827 | u.mUserCpuTime.addCountLocked(mTempTotalCpuUserTimeUs); |
| 9828 | u.mSystemCpuTime.addCountLocked(mTempTotalCpuSystemTimeUs); |
| 9829 | |
| 9830 | final Uid.Proc proc = u.getProcessStatsLocked("*lost*"); |
Adam Lesinski | 062e66c | 2015-07-14 12:02:44 -0700 | [diff] [blame] | 9831 | proc.addCpuTimeLocked((int) mTempTotalCpuUserTimeUs / 1000, |
| 9832 | (int) mTempTotalCpuSystemTimeUs / 1000); |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 9833 | } |
| 9834 | } |
| 9835 | |
| 9836 | // See if there is a difference in wakelocks between this collection and the last |
| 9837 | // collection. |
| 9838 | if (ArrayUtils.referenceEquals(mPartialTimers, mLastPartialTimers)) { |
| 9839 | // No difference, so each timer is now considered for the next collection. |
| 9840 | for (int i = 0; i < numPartialTimers; i++) { |
| 9841 | mPartialTimers.get(i).mInList = true; |
| 9842 | } |
| 9843 | } else { |
| 9844 | // The lists are different, meaning we added (or removed a timer) since the last |
| 9845 | // collection. |
| 9846 | final int numLastPartialTimers = mLastPartialTimers.size(); |
| 9847 | for (int i = 0; i < numLastPartialTimers; i++) { |
| 9848 | mLastPartialTimers.get(i).mInList = false; |
| 9849 | } |
| 9850 | mLastPartialTimers.clear(); |
| 9851 | |
| 9852 | // Mark the current timers as gone through a collection. |
| 9853 | for (int i = 0; i < numPartialTimers; i++) { |
| 9854 | final StopwatchTimer timer = mPartialTimers.get(i); |
| 9855 | timer.mInList = true; |
| 9856 | mLastPartialTimers.add(timer); |
| 9857 | } |
| 9858 | } |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 9859 | } |
| 9860 | |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 9861 | boolean setChargingLocked(boolean charging) { |
| 9862 | if (mCharging != charging) { |
| 9863 | mCharging = charging; |
| 9864 | if (charging) { |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 9865 | mHistoryCur.states2 |= HistoryItem.STATE2_CHARGING_FLAG; |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 9866 | } else { |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 9867 | mHistoryCur.states2 &= ~HistoryItem.STATE2_CHARGING_FLAG; |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 9868 | } |
| 9869 | mHandler.sendEmptyMessage(MSG_REPORT_CHARGING); |
| 9870 | return true; |
| 9871 | } |
| 9872 | return false; |
| 9873 | } |
| 9874 | |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 9875 | void setOnBatteryLocked(final long mSecRealtime, final long mSecUptime, final boolean onBattery, |
Adam Lesinski | f9b20a9 | 2016-06-17 17:30:01 -0700 | [diff] [blame] | 9876 | final int oldStatus, final int level, final int chargeUAh) { |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 9877 | boolean doWrite = false; |
| 9878 | Message m = mHandler.obtainMessage(MSG_REPORT_POWER_CHANGE); |
| 9879 | m.arg1 = onBattery ? 1 : 0; |
| 9880 | mHandler.sendMessage(m); |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 9881 | |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 9882 | final long uptime = mSecUptime * 1000; |
| 9883 | final long realtime = mSecRealtime * 1000; |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 9884 | final boolean screenOn = mScreenState == Display.STATE_ON; |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 9885 | if (onBattery) { |
| 9886 | // We will reset our status if we are unplugging after the |
| 9887 | // battery was last full, or the level is at 100, or |
| 9888 | // we have gone through a significant charge (from a very low |
| 9889 | // level to a now very high level). |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 9890 | boolean reset = false; |
Dianne Hackborn | 9a75543 | 2014-05-15 17:05:22 -0700 | [diff] [blame] | 9891 | if (!mNoAutoReset && (oldStatus == BatteryManager.BATTERY_STATUS_FULL |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 9892 | || level >= 90 |
Dianne Hackborn | fb3809c | 2014-09-29 18:31:22 -0700 | [diff] [blame] | 9893 | || (mDischargeCurrentLevel < 20 && level >= 80) |
| 9894 | || (getHighDischargeAmountSinceCharge() >= 200 |
| 9895 | && mHistoryBuffer.dataSize() >= MAX_HISTORY_BUFFER))) { |
Dianne Hackborn | 73d6a82 | 2014-09-29 10:52:47 -0700 | [diff] [blame] | 9896 | Slog.i(TAG, "Resetting battery stats: level=" + level + " status=" + oldStatus |
Dianne Hackborn | fb3809c | 2014-09-29 18:31:22 -0700 | [diff] [blame] | 9897 | + " dischargeLevel=" + mDischargeCurrentLevel |
Dianne Hackborn | 73d6a82 | 2014-09-29 10:52:47 -0700 | [diff] [blame] | 9898 | + " lowAmount=" + getLowDischargeAmountSinceCharge() |
| 9899 | + " highAmount=" + getHighDischargeAmountSinceCharge()); |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 9900 | // Before we write, collect a snapshot of the final aggregated |
| 9901 | // stats to be reported in the next checkin. Only do this if we have |
| 9902 | // a sufficient amount of data to make it interesting. |
| 9903 | if (getLowDischargeAmountSinceCharge() >= 20) { |
| 9904 | final Parcel parcel = Parcel.obtain(); |
| 9905 | writeSummaryToParcel(parcel, true); |
| 9906 | BackgroundThread.getHandler().post(new Runnable() { |
| 9907 | @Override public void run() { |
| 9908 | synchronized (mCheckinFile) { |
| 9909 | FileOutputStream stream = null; |
| 9910 | try { |
| 9911 | stream = mCheckinFile.startWrite(); |
| 9912 | stream.write(parcel.marshall()); |
| 9913 | stream.flush(); |
| 9914 | FileUtils.sync(stream); |
| 9915 | stream.close(); |
| 9916 | mCheckinFile.finishWrite(stream); |
| 9917 | } catch (IOException e) { |
| 9918 | Slog.w("BatteryStats", |
| 9919 | "Error writing checkin battery statistics", e); |
| 9920 | mCheckinFile.failWrite(stream); |
| 9921 | } finally { |
| 9922 | parcel.recycle(); |
| 9923 | } |
| 9924 | } |
| 9925 | } |
| 9926 | }); |
| 9927 | } |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 9928 | doWrite = true; |
| 9929 | resetAllStatsLocked(); |
Ying Wai (Daniel) Fan | 442ab76 | 2017-01-31 22:00:10 -0800 | [diff] [blame] | 9930 | if (chargeUAh > 0 && level > 0) { |
Adam Lesinski | f9b20a9 | 2016-06-17 17:30:01 -0700 | [diff] [blame] | 9931 | // 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] | 9932 | mEstimatedBatteryCapacity = (int) ((chargeUAh / 1000) / (level / 100.0)); |
Adam Lesinski | f9b20a9 | 2016-06-17 17:30:01 -0700 | [diff] [blame] | 9933 | } |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 9934 | mDischargeStartLevel = level; |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 9935 | reset = true; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 9936 | mDischargeStepTracker.init(); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9937 | } |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 9938 | if (mCharging) { |
| 9939 | setChargingLocked(false); |
| 9940 | } |
| 9941 | mLastChargingStateLevel = level; |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 9942 | mOnBattery = mOnBatteryInternal = true; |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 9943 | mLastDischargeStepLevel = level; |
Dianne Hackborn | 2932513 | 2014-05-21 15:01:03 -0700 | [diff] [blame] | 9944 | mMinDischargeStepLevel = level; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 9945 | mDischargeStepTracker.clearTime(); |
| 9946 | mDailyDischargeStepTracker.clearTime(); |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 9947 | mInitStepMode = mCurStepMode; |
| 9948 | mModStepMode = 0; |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 9949 | pullPendingStateUpdatesLocked(); |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 9950 | mHistoryCur.batteryLevel = (byte)level; |
| 9951 | mHistoryCur.states &= ~HistoryItem.STATE_BATTERY_PLUGGED_FLAG; |
| 9952 | if (DEBUG_HISTORY) Slog.v(TAG, "Battery unplugged to: " |
| 9953 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 9954 | if (reset) { |
| 9955 | mRecordingHistory = true; |
| 9956 | startRecordingHistory(mSecRealtime, mSecUptime, reset); |
| 9957 | } |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 9958 | addHistoryRecordLocked(mSecRealtime, mSecUptime); |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 9959 | mDischargeCurrentLevel = mDischargeUnplugLevel = level; |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 9960 | if (screenOn) { |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 9961 | mDischargeScreenOnUnplugLevel = level; |
| 9962 | mDischargeScreenOffUnplugLevel = 0; |
| 9963 | } else { |
| 9964 | mDischargeScreenOnUnplugLevel = 0; |
| 9965 | mDischargeScreenOffUnplugLevel = level; |
| 9966 | } |
| 9967 | mDischargeAmountScreenOn = 0; |
| 9968 | mDischargeAmountScreenOff = 0; |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 9969 | updateTimeBasesLocked(true, !screenOn, uptime, realtime); |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 9970 | } else { |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 9971 | mLastChargingStateLevel = level; |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 9972 | mOnBattery = mOnBatteryInternal = false; |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 9973 | pullPendingStateUpdatesLocked(); |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 9974 | mHistoryCur.batteryLevel = (byte)level; |
| 9975 | mHistoryCur.states |= HistoryItem.STATE_BATTERY_PLUGGED_FLAG; |
| 9976 | if (DEBUG_HISTORY) Slog.v(TAG, "Battery plugged to: " |
| 9977 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 9978 | addHistoryRecordLocked(mSecRealtime, mSecUptime); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 9979 | mDischargeCurrentLevel = mDischargePlugLevel = level; |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 9980 | if (level < mDischargeUnplugLevel) { |
| 9981 | mLowDischargeAmountSinceCharge += mDischargeUnplugLevel-level-1; |
| 9982 | mHighDischargeAmountSinceCharge += mDischargeUnplugLevel-level; |
| 9983 | } |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 9984 | updateDischargeScreenLevelsLocked(screenOn, screenOn); |
| 9985 | updateTimeBasesLocked(false, !screenOn, uptime, realtime); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 9986 | mChargeStepTracker.init(); |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 9987 | mLastChargeStepLevel = level; |
Dianne Hackborn | 2932513 | 2014-05-21 15:01:03 -0700 | [diff] [blame] | 9988 | mMaxChargeStepLevel = level; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 9989 | mInitStepMode = mCurStepMode; |
| 9990 | mModStepMode = 0; |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 9991 | } |
| 9992 | if (doWrite || (mLastWriteTime + (60 * 1000)) < mSecRealtime) { |
| 9993 | if (mFile != null) { |
| 9994 | writeAsyncLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9995 | } |
| 9996 | } |
| 9997 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 9998 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 9999 | private void startRecordingHistory(final long elapsedRealtimeMs, final long uptimeMs, |
| 10000 | boolean reset) { |
| 10001 | mRecordingHistory = true; |
| 10002 | mHistoryCur.currentTime = System.currentTimeMillis(); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 10003 | addHistoryBufferLocked(elapsedRealtimeMs, uptimeMs, |
| 10004 | reset ? HistoryItem.CMD_RESET : HistoryItem.CMD_CURRENT_TIME, |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 10005 | mHistoryCur); |
| 10006 | mHistoryCur.currentTime = 0; |
| 10007 | if (reset) { |
| 10008 | initActiveHistoryEventsLocked(elapsedRealtimeMs, uptimeMs); |
| 10009 | } |
| 10010 | } |
| 10011 | |
Dianne Hackborn | 7d9eefd | 2014-08-27 18:30:31 -0700 | [diff] [blame] | 10012 | private void recordCurrentTimeChangeLocked(final long currentTime, final long elapsedRealtimeMs, |
| 10013 | final long uptimeMs) { |
| 10014 | if (mRecordingHistory) { |
| 10015 | mHistoryCur.currentTime = currentTime; |
| 10016 | addHistoryBufferLocked(elapsedRealtimeMs, uptimeMs, HistoryItem.CMD_CURRENT_TIME, |
| 10017 | mHistoryCur); |
| 10018 | mHistoryCur.currentTime = 0; |
| 10019 | } |
| 10020 | } |
| 10021 | |
Dianne Hackborn | 29cd7f1 | 2015-01-08 10:37:05 -0800 | [diff] [blame] | 10022 | private void recordShutdownLocked(final long elapsedRealtimeMs, final long uptimeMs) { |
| 10023 | if (mRecordingHistory) { |
| 10024 | mHistoryCur.currentTime = System.currentTimeMillis(); |
Dianne Hackborn | 29cd7f1 | 2015-01-08 10:37:05 -0800 | [diff] [blame] | 10025 | addHistoryBufferLocked(elapsedRealtimeMs, uptimeMs, HistoryItem.CMD_SHUTDOWN, |
| 10026 | mHistoryCur); |
| 10027 | mHistoryCur.currentTime = 0; |
| 10028 | } |
| 10029 | } |
| 10030 | |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 10031 | private void scheduleSyncExternalStatsLocked(String reason, int updateFlags) { |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 10032 | if (mExternalSync != null) { |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 10033 | mExternalSync.scheduleSync(reason, updateFlags); |
Adam Lesinski | a7c90c8 | 2015-06-18 14:52:24 -0700 | [diff] [blame] | 10034 | } |
| 10035 | } |
| 10036 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10037 | // 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] | 10038 | public static final int BATTERY_PLUGGED_NONE = 0; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 10039 | |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 10040 | public void setBatteryStateLocked(int status, int health, int plugType, int level, |
Adam Lesinski | 041d917 | 2016-12-12 12:03:56 -0800 | [diff] [blame] | 10041 | int temp, int volt, int chargeUAh, int chargeFullUAh) { |
Adam Lesinski | 29ddfe5 | 2017-03-29 19:29:00 -0700 | [diff] [blame] | 10042 | // Temperature is encoded without the signed bit, so clamp any negative temperatures to 0. |
| 10043 | temp = Math.max(0, temp); |
| 10044 | |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 10045 | final boolean onBattery = plugType == BATTERY_PLUGGED_NONE; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 10046 | final long uptime = mClocks.uptimeMillis(); |
| 10047 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 10048 | if (!mHaveBatteryLevel) { |
| 10049 | mHaveBatteryLevel = true; |
| 10050 | // We start out assuming that the device is plugged in (not |
| 10051 | // on battery). If our first report is now that we are indeed |
| 10052 | // plugged in, then twiddle our state to correctly reflect that |
| 10053 | // since we won't be going through the full setOnBattery(). |
| 10054 | if (onBattery == mOnBattery) { |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 10055 | if (onBattery) { |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 10056 | mHistoryCur.states &= ~HistoryItem.STATE_BATTERY_PLUGGED_FLAG; |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 10057 | } else { |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 10058 | mHistoryCur.states |= HistoryItem.STATE_BATTERY_PLUGGED_FLAG; |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 10059 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10060 | } |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 10061 | // Always start out assuming charging, that will be updated later. |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 10062 | mHistoryCur.states2 |= HistoryItem.STATE2_CHARGING_FLAG; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 10063 | mHistoryCur.batteryStatus = (byte)status; |
| 10064 | mHistoryCur.batteryLevel = (byte)level; |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 10065 | mHistoryCur.batteryChargeUAh = chargeUAh; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 10066 | mMaxChargeStepLevel = mMinDischargeStepLevel = |
| 10067 | mLastChargeStepLevel = mLastDischargeStepLevel = level; |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 10068 | mLastChargingStateLevel = level; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 10069 | } else if (mCurrentBatteryLevel != level || mOnBattery != onBattery) { |
| 10070 | recordDailyStatsIfNeededLocked(level >= 100 && onBattery); |
| 10071 | } |
| 10072 | int oldStatus = mHistoryCur.batteryStatus; |
| 10073 | if (onBattery) { |
| 10074 | mDischargeCurrentLevel = level; |
| 10075 | if (!mRecordingHistory) { |
| 10076 | mRecordingHistory = true; |
| 10077 | startRecordingHistory(elapsedRealtime, uptime, true); |
| 10078 | } |
| 10079 | } else if (level < 96) { |
| 10080 | if (!mRecordingHistory) { |
| 10081 | mRecordingHistory = true; |
| 10082 | startRecordingHistory(elapsedRealtime, uptime, true); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10083 | } |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 10084 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 10085 | mCurrentBatteryLevel = level; |
| 10086 | if (mDischargePlugLevel < 0) { |
| 10087 | mDischargePlugLevel = level; |
Marco Nelissen | d859331 | 2009-04-30 14:45:06 -0700 | [diff] [blame] | 10088 | } |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 10089 | |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 10090 | if (onBattery != mOnBattery) { |
| 10091 | mHistoryCur.batteryLevel = (byte)level; |
| 10092 | mHistoryCur.batteryStatus = (byte)status; |
| 10093 | mHistoryCur.batteryHealth = (byte)health; |
| 10094 | mHistoryCur.batteryPlugType = (byte)plugType; |
| 10095 | mHistoryCur.batteryTemperature = (short)temp; |
| 10096 | mHistoryCur.batteryVoltage = (char)volt; |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 10097 | if (chargeUAh < mHistoryCur.batteryChargeUAh) { |
| 10098 | // Only record discharges |
| 10099 | final long chargeDiff = mHistoryCur.batteryChargeUAh - chargeUAh; |
| 10100 | mDischargeCounter.addCountLocked(chargeDiff); |
| 10101 | mDischargeScreenOffCounter.addCountLocked(chargeDiff); |
| 10102 | } |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 10103 | mHistoryCur.batteryChargeUAh = chargeUAh; |
Adam Lesinski | f9b20a9 | 2016-06-17 17:30:01 -0700 | [diff] [blame] | 10104 | setOnBatteryLocked(elapsedRealtime, uptime, onBattery, oldStatus, level, chargeUAh); |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 10105 | } else { |
| 10106 | boolean changed = false; |
| 10107 | if (mHistoryCur.batteryLevel != level) { |
| 10108 | mHistoryCur.batteryLevel = (byte)level; |
| 10109 | changed = true; |
Marco Nelissen | d859331 | 2009-04-30 14:45:06 -0700 | [diff] [blame] | 10110 | |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 10111 | // TODO(adamlesinski): Schedule the creation of a HistoryStepDetails record |
| 10112 | // which will pull external stats. |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 10113 | scheduleSyncExternalStatsLocked("battery-level", ExternalStatsSync.UPDATE_ALL); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 10114 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 10115 | if (mHistoryCur.batteryStatus != status) { |
| 10116 | mHistoryCur.batteryStatus = (byte)status; |
| 10117 | changed = true; |
| 10118 | } |
| 10119 | if (mHistoryCur.batteryHealth != health) { |
| 10120 | mHistoryCur.batteryHealth = (byte)health; |
| 10121 | changed = true; |
| 10122 | } |
| 10123 | if (mHistoryCur.batteryPlugType != plugType) { |
| 10124 | mHistoryCur.batteryPlugType = (byte)plugType; |
| 10125 | changed = true; |
| 10126 | } |
| 10127 | if (temp >= (mHistoryCur.batteryTemperature+10) |
| 10128 | || temp <= (mHistoryCur.batteryTemperature-10)) { |
| 10129 | mHistoryCur.batteryTemperature = (short)temp; |
| 10130 | changed = true; |
| 10131 | } |
| 10132 | if (volt > (mHistoryCur.batteryVoltage+20) |
| 10133 | || volt < (mHistoryCur.batteryVoltage-20)) { |
| 10134 | mHistoryCur.batteryVoltage = (char)volt; |
| 10135 | changed = true; |
| 10136 | } |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 10137 | if (chargeUAh >= (mHistoryCur.batteryChargeUAh+10) |
| 10138 | || chargeUAh <= (mHistoryCur.batteryChargeUAh-10)) { |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 10139 | if (chargeUAh < mHistoryCur.batteryChargeUAh) { |
| 10140 | // Only record discharges |
| 10141 | final long chargeDiff = mHistoryCur.batteryChargeUAh - chargeUAh; |
| 10142 | mDischargeCounter.addCountLocked(chargeDiff); |
| 10143 | mDischargeScreenOffCounter.addCountLocked(chargeDiff); |
| 10144 | } |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 10145 | mHistoryCur.batteryChargeUAh = chargeUAh; |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 10146 | changed = true; |
| 10147 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 10148 | long modeBits = (((long)mInitStepMode) << STEP_LEVEL_INITIAL_MODE_SHIFT) |
| 10149 | | (((long)mModStepMode) << STEP_LEVEL_MODIFIED_MODE_SHIFT) |
| 10150 | | (((long)(level&0xff)) << STEP_LEVEL_LEVEL_SHIFT); |
| 10151 | if (onBattery) { |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 10152 | changed |= setChargingLocked(false); |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 10153 | if (mLastDischargeStepLevel != level && mMinDischargeStepLevel > level) { |
| 10154 | mDischargeStepTracker.addLevelSteps(mLastDischargeStepLevel - level, |
| 10155 | modeBits, elapsedRealtime); |
| 10156 | mDailyDischargeStepTracker.addLevelSteps(mLastDischargeStepLevel - level, |
| 10157 | modeBits, elapsedRealtime); |
| 10158 | mLastDischargeStepLevel = level; |
| 10159 | mMinDischargeStepLevel = level; |
| 10160 | mInitStepMode = mCurStepMode; |
| 10161 | mModStepMode = 0; |
| 10162 | } |
| 10163 | } else { |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 10164 | if (level >= 90) { |
| 10165 | // If the battery level is at least 90%, always consider the device to be |
| 10166 | // charging even if it happens to go down a level. |
| 10167 | changed |= setChargingLocked(true); |
| 10168 | mLastChargeStepLevel = level; |
| 10169 | } if (!mCharging) { |
| 10170 | if (mLastChargeStepLevel < level) { |
| 10171 | // We have not reporting that we are charging, but the level has now |
| 10172 | // gone up, so consider the state to be charging. |
| 10173 | changed |= setChargingLocked(true); |
| 10174 | mLastChargeStepLevel = level; |
| 10175 | } |
| 10176 | } else { |
| 10177 | if (mLastChargeStepLevel > level) { |
| 10178 | // We had reported that the device was charging, but here we are with |
| 10179 | // power connected and the level going down. Looks like the current |
| 10180 | // power supplied isn't enough, so consider the device to now be |
| 10181 | // discharging. |
| 10182 | changed |= setChargingLocked(false); |
| 10183 | mLastChargeStepLevel = level; |
| 10184 | } |
| 10185 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 10186 | if (mLastChargeStepLevel != level && mMaxChargeStepLevel < level) { |
| 10187 | mChargeStepTracker.addLevelSteps(level - mLastChargeStepLevel, |
| 10188 | modeBits, elapsedRealtime); |
| 10189 | mDailyChargeStepTracker.addLevelSteps(level - mLastChargeStepLevel, |
| 10190 | modeBits, elapsedRealtime); |
| 10191 | mLastChargeStepLevel = level; |
| 10192 | mMaxChargeStepLevel = level; |
| 10193 | mInitStepMode = mCurStepMode; |
| 10194 | mModStepMode = 0; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 10195 | } |
| 10196 | } |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 10197 | if (changed) { |
| 10198 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 10199 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 10200 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 10201 | if (!onBattery && status == BatteryManager.BATTERY_STATUS_FULL) { |
| 10202 | // We don't record history while we are plugged in and fully charged. |
| 10203 | // The next time we are unplugged, history will be cleared. |
| 10204 | mRecordingHistory = DEBUG; |
Dianne Hackborn | d0c5b9a | 2014-02-21 16:19:05 -0800 | [diff] [blame] | 10205 | } |
Adam Lesinski | 041d917 | 2016-12-12 12:03:56 -0800 | [diff] [blame] | 10206 | |
Jocelyn Dang | c627d10 | 2017-04-14 13:15:14 -0700 | [diff] [blame^] | 10207 | if (mMinLearnedBatteryCapacity == -1) { |
| 10208 | mMinLearnedBatteryCapacity = chargeFullUAh; |
| 10209 | } else { |
| 10210 | Math.min(mMinLearnedBatteryCapacity, chargeFullUAh); |
Adam Lesinski | 041d917 | 2016-12-12 12:03:56 -0800 | [diff] [blame] | 10211 | } |
Jocelyn Dang | c627d10 | 2017-04-14 13:15:14 -0700 | [diff] [blame^] | 10212 | mMaxLearnedBatteryCapacity = Math.max(mMaxLearnedBatteryCapacity, chargeFullUAh); |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 10213 | } |
| 10214 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10215 | public long getAwakeTimeBattery() { |
| 10216 | return computeBatteryUptime(getBatteryUptimeLocked(), STATS_CURRENT); |
| 10217 | } |
| 10218 | |
| 10219 | public long getAwakeTimePlugged() { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 10220 | return (mClocks.uptimeMillis() * 1000) - getAwakeTimeBattery(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10221 | } |
| 10222 | |
| 10223 | @Override |
| 10224 | public long computeUptime(long curTime, int which) { |
| 10225 | switch (which) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10226 | case STATS_SINCE_CHARGED: return mUptime + (curTime-mUptimeStart); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10227 | case STATS_CURRENT: return (curTime-mUptimeStart); |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 10228 | case STATS_SINCE_UNPLUGGED: return (curTime-mOnBatteryTimeBase.getUptimeStart()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10229 | } |
| 10230 | return 0; |
| 10231 | } |
| 10232 | |
| 10233 | @Override |
| 10234 | public long computeRealtime(long curTime, int which) { |
| 10235 | switch (which) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10236 | case STATS_SINCE_CHARGED: return mRealtime + (curTime-mRealtimeStart); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10237 | case STATS_CURRENT: return (curTime-mRealtimeStart); |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 10238 | case STATS_SINCE_UNPLUGGED: return (curTime-mOnBatteryTimeBase.getRealtimeStart()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10239 | } |
| 10240 | return 0; |
| 10241 | } |
| 10242 | |
| 10243 | @Override |
| 10244 | public long computeBatteryUptime(long curTime, int which) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10245 | return mOnBatteryTimeBase.computeUptime(curTime, which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10246 | } |
| 10247 | |
| 10248 | @Override |
| 10249 | public long computeBatteryRealtime(long curTime, int which) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10250 | return mOnBatteryTimeBase.computeRealtime(curTime, which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10251 | } |
| 10252 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10253 | @Override |
| 10254 | public long computeBatteryScreenOffUptime(long curTime, int which) { |
| 10255 | return mOnBatteryScreenOffTimeBase.computeUptime(curTime, which); |
| 10256 | } |
| 10257 | |
| 10258 | @Override |
| 10259 | public long computeBatteryScreenOffRealtime(long curTime, int which) { |
| 10260 | return mOnBatteryScreenOffTimeBase.computeRealtime(curTime, which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10261 | } |
| 10262 | |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 10263 | private long computeTimePerLevel(long[] steps, int numSteps) { |
| 10264 | // For now we'll do a simple average across all steps. |
| 10265 | if (numSteps <= 0) { |
| 10266 | return -1; |
| 10267 | } |
| 10268 | long total = 0; |
| 10269 | for (int i=0; i<numSteps; i++) { |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 10270 | total += steps[i] & STEP_LEVEL_TIME_MASK; |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 10271 | } |
| 10272 | return total / numSteps; |
| 10273 | /* |
| 10274 | long[] buckets = new long[numSteps]; |
| 10275 | int numBuckets = 0; |
| 10276 | int numToAverage = 4; |
| 10277 | int i = 0; |
| 10278 | while (i < numSteps) { |
| 10279 | long totalTime = 0; |
| 10280 | int num = 0; |
| 10281 | for (int j=0; j<numToAverage && (i+j)<numSteps; j++) { |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 10282 | totalTime += steps[i+j] & STEP_LEVEL_TIME_MASK; |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 10283 | num++; |
| 10284 | } |
| 10285 | buckets[numBuckets] = totalTime / num; |
| 10286 | numBuckets++; |
| 10287 | numToAverage *= 2; |
| 10288 | i += num; |
| 10289 | } |
| 10290 | if (numBuckets < 1) { |
| 10291 | return -1; |
| 10292 | } |
| 10293 | long averageTime = buckets[numBuckets-1]; |
| 10294 | for (i=numBuckets-2; i>=0; i--) { |
| 10295 | averageTime = (averageTime + buckets[i]) / 2; |
| 10296 | } |
| 10297 | return averageTime; |
| 10298 | */ |
| 10299 | } |
| 10300 | |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 10301 | @Override |
| 10302 | public long computeBatteryTimeRemaining(long curTime) { |
| 10303 | if (!mOnBattery) { |
| 10304 | return -1; |
| 10305 | } |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 10306 | /* Simple implementation just looks at the average discharge per level across the |
| 10307 | entire sample period. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 10308 | int discharge = (getLowDischargeAmountSinceCharge()+getHighDischargeAmountSinceCharge())/2; |
| 10309 | if (discharge < 2) { |
| 10310 | return -1; |
| 10311 | } |
| 10312 | long duration = computeBatteryRealtime(curTime, STATS_SINCE_CHARGED); |
| 10313 | if (duration < 1000*1000) { |
| 10314 | return -1; |
| 10315 | } |
| 10316 | long usPerLevel = duration/discharge; |
| 10317 | return usPerLevel * mCurrentBatteryLevel; |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 10318 | */ |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 10319 | if (mDischargeStepTracker.mNumStepDurations < 1) { |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 10320 | return -1; |
| 10321 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 10322 | long msPerLevel = mDischargeStepTracker.computeTimePerLevel(); |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 10323 | if (msPerLevel <= 0) { |
| 10324 | return -1; |
| 10325 | } |
| 10326 | return (msPerLevel * mCurrentBatteryLevel) * 1000; |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 10327 | } |
| 10328 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 10329 | @Override |
| 10330 | public LevelStepTracker getDischargeLevelStepTracker() { |
| 10331 | return mDischargeStepTracker; |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 10332 | } |
| 10333 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 10334 | @Override |
| 10335 | public LevelStepTracker getDailyDischargeLevelStepTracker() { |
| 10336 | return mDailyDischargeStepTracker; |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 10337 | } |
| 10338 | |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 10339 | @Override |
| 10340 | public long computeChargeTimeRemaining(long curTime) { |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 10341 | if (mOnBattery) { |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 10342 | // Not yet working. |
| 10343 | return -1; |
| 10344 | } |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 10345 | /* Broken |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 10346 | int curLevel = mCurrentBatteryLevel; |
| 10347 | int plugLevel = mDischargePlugLevel; |
| 10348 | if (plugLevel < 0 || curLevel < (plugLevel+1)) { |
| 10349 | return -1; |
| 10350 | } |
| 10351 | long duration = computeBatteryRealtime(curTime, STATS_SINCE_UNPLUGGED); |
| 10352 | if (duration < 1000*1000) { |
| 10353 | return -1; |
| 10354 | } |
| 10355 | long usPerLevel = duration/(curLevel-plugLevel); |
| 10356 | return usPerLevel * (100-curLevel); |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 10357 | */ |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 10358 | if (mChargeStepTracker.mNumStepDurations < 1) { |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 10359 | return -1; |
| 10360 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 10361 | long msPerLevel = mChargeStepTracker.computeTimePerLevel(); |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 10362 | if (msPerLevel <= 0) { |
| 10363 | return -1; |
| 10364 | } |
| 10365 | return (msPerLevel * (100-mCurrentBatteryLevel)) * 1000; |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 10366 | } |
| 10367 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 10368 | @Override |
| 10369 | public LevelStepTracker getChargeLevelStepTracker() { |
| 10370 | return mChargeStepTracker; |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 10371 | } |
| 10372 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 10373 | @Override |
| 10374 | public LevelStepTracker getDailyChargeLevelStepTracker() { |
| 10375 | return mDailyChargeStepTracker; |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 10376 | } |
| 10377 | |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 10378 | @Override |
| 10379 | public ArrayList<PackageChange> getDailyPackageChanges() { |
| 10380 | return mDailyPackageChanges; |
| 10381 | } |
| 10382 | |
Joe Onorato | e1acd63 | 2016-02-23 13:25:10 -0800 | [diff] [blame] | 10383 | protected long getBatteryUptimeLocked() { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 10384 | return mOnBatteryTimeBase.getUptime(mClocks.uptimeMillis() * 1000); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10385 | } |
| 10386 | |
| 10387 | @Override |
| 10388 | public long getBatteryUptime(long curTime) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10389 | return mOnBatteryTimeBase.getUptime(curTime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10390 | } |
| 10391 | |
| 10392 | @Override |
| 10393 | public long getBatteryRealtime(long curTime) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10394 | return mOnBatteryTimeBase.getRealtime(curTime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10395 | } |
Amith Yamasani | 3718aaa | 2009-06-09 06:32:35 -0700 | [diff] [blame] | 10396 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 10397 | @Override |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 10398 | public int getDischargeStartLevel() { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 10399 | synchronized(this) { |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 10400 | return getDischargeStartLevelLocked(); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 10401 | } |
| 10402 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 10403 | |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 10404 | public int getDischargeStartLevelLocked() { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10405 | return mDischargeUnplugLevel; |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 10406 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 10407 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 10408 | @Override |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 10409 | public int getDischargeCurrentLevel() { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 10410 | synchronized(this) { |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 10411 | return getDischargeCurrentLevelLocked(); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 10412 | } |
| 10413 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 10414 | |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 10415 | public int getDischargeCurrentLevelLocked() { |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 10416 | return mDischargeCurrentLevel; |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 10417 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10418 | |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 10419 | @Override |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 10420 | public int getLowDischargeAmountSinceCharge() { |
| 10421 | synchronized(this) { |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 10422 | int val = mLowDischargeAmountSinceCharge; |
| 10423 | if (mOnBattery && mDischargeCurrentLevel < mDischargeUnplugLevel) { |
| 10424 | val += mDischargeUnplugLevel-mDischargeCurrentLevel-1; |
| 10425 | } |
| 10426 | return val; |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 10427 | } |
| 10428 | } |
| 10429 | |
| 10430 | @Override |
| 10431 | public int getHighDischargeAmountSinceCharge() { |
| 10432 | synchronized(this) { |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 10433 | int val = mHighDischargeAmountSinceCharge; |
| 10434 | if (mOnBattery && mDischargeCurrentLevel < mDischargeUnplugLevel) { |
| 10435 | val += mDischargeUnplugLevel-mDischargeCurrentLevel; |
| 10436 | } |
| 10437 | return val; |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 10438 | } |
| 10439 | } |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 10440 | |
| 10441 | @Override |
| 10442 | public int getDischargeAmount(int which) { |
| 10443 | int dischargeAmount = which == STATS_SINCE_CHARGED |
| 10444 | ? getHighDischargeAmountSinceCharge() |
| 10445 | : (getDischargeStartLevel() - getDischargeCurrentLevel()); |
| 10446 | if (dischargeAmount < 0) { |
| 10447 | dischargeAmount = 0; |
| 10448 | } |
| 10449 | return dischargeAmount; |
| 10450 | } |
| 10451 | |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 10452 | public int getDischargeAmountScreenOn() { |
| 10453 | synchronized(this) { |
| 10454 | int val = mDischargeAmountScreenOn; |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 10455 | if (mOnBattery && mScreenState == Display.STATE_ON |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 10456 | && mDischargeCurrentLevel < mDischargeScreenOnUnplugLevel) { |
| 10457 | val += mDischargeScreenOnUnplugLevel-mDischargeCurrentLevel; |
| 10458 | } |
| 10459 | return val; |
| 10460 | } |
| 10461 | } |
| 10462 | |
| 10463 | public int getDischargeAmountScreenOnSinceCharge() { |
| 10464 | synchronized(this) { |
| 10465 | int val = mDischargeAmountScreenOnSinceCharge; |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 10466 | if (mOnBattery && mScreenState == Display.STATE_ON |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 10467 | && mDischargeCurrentLevel < mDischargeScreenOnUnplugLevel) { |
| 10468 | val += mDischargeScreenOnUnplugLevel-mDischargeCurrentLevel; |
| 10469 | } |
| 10470 | return val; |
| 10471 | } |
| 10472 | } |
| 10473 | |
| 10474 | public int getDischargeAmountScreenOff() { |
| 10475 | synchronized(this) { |
| 10476 | int val = mDischargeAmountScreenOff; |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 10477 | if (mOnBattery && mScreenState != Display.STATE_ON |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 10478 | && mDischargeCurrentLevel < mDischargeScreenOffUnplugLevel) { |
| 10479 | val += mDischargeScreenOffUnplugLevel-mDischargeCurrentLevel; |
| 10480 | } |
| 10481 | return val; |
| 10482 | } |
| 10483 | } |
| 10484 | |
| 10485 | public int getDischargeAmountScreenOffSinceCharge() { |
| 10486 | synchronized(this) { |
| 10487 | int val = mDischargeAmountScreenOffSinceCharge; |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 10488 | if (mOnBattery && mScreenState != Display.STATE_ON |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 10489 | && mDischargeCurrentLevel < mDischargeScreenOffUnplugLevel) { |
| 10490 | val += mDischargeScreenOffUnplugLevel-mDischargeCurrentLevel; |
| 10491 | } |
| 10492 | return val; |
| 10493 | } |
| 10494 | } |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 10495 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10496 | /** |
| 10497 | * Retrieve the statistics object for a particular uid, creating if needed. |
| 10498 | */ |
| 10499 | public Uid getUidStatsLocked(int uid) { |
| 10500 | Uid u = mUidStats.get(uid); |
| 10501 | if (u == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 10502 | u = new Uid(this, uid); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10503 | mUidStats.put(uid, u); |
| 10504 | } |
| 10505 | return u; |
| 10506 | } |
| 10507 | |
| 10508 | /** |
| 10509 | * Remove the statistics object for a particular uid. |
| 10510 | */ |
| 10511 | public void removeUidStatsLocked(int uid) { |
Adam Lesinski | b83ffee | 2015-05-12 14:43:47 -0700 | [diff] [blame] | 10512 | mKernelUidCpuTimeReader.removeUid(uid); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10513 | mUidStats.remove(uid); |
| 10514 | } |
Amith Yamasani | 32dbefd | 2009-06-19 09:21:17 -0700 | [diff] [blame] | 10515 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10516 | /** |
| 10517 | * Retrieve the statistics object for a particular process, creating |
| 10518 | * if needed. |
| 10519 | */ |
| 10520 | public Uid.Proc getProcessStatsLocked(int uid, String name) { |
Dianne Hackborn | bbb7472 | 2014-03-13 09:50:24 -0700 | [diff] [blame] | 10521 | uid = mapUid(uid); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10522 | Uid u = getUidStatsLocked(uid); |
| 10523 | return u.getProcessStatsLocked(name); |
| 10524 | } |
| 10525 | |
| 10526 | /** |
| 10527 | * Retrieve the statistics object for a particular process, creating |
| 10528 | * if needed. |
| 10529 | */ |
| 10530 | public Uid.Pkg getPackageStatsLocked(int uid, String pkg) { |
Dianne Hackborn | bbb7472 | 2014-03-13 09:50:24 -0700 | [diff] [blame] | 10531 | uid = mapUid(uid); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10532 | Uid u = getUidStatsLocked(uid); |
| 10533 | return u.getPackageStatsLocked(pkg); |
| 10534 | } |
| 10535 | |
| 10536 | /** |
| 10537 | * Retrieve the statistics object for a particular service, creating |
| 10538 | * if needed. |
| 10539 | */ |
| 10540 | public Uid.Pkg.Serv getServiceStatsLocked(int uid, String pkg, String name) { |
Dianne Hackborn | bbb7472 | 2014-03-13 09:50:24 -0700 | [diff] [blame] | 10541 | uid = mapUid(uid); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10542 | Uid u = getUidStatsLocked(uid); |
| 10543 | return u.getServiceStatsLocked(pkg, name); |
| 10544 | } |
| 10545 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10546 | public void shutdownLocked() { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 10547 | recordShutdownLocked(mClocks.elapsedRealtime(), mClocks.uptimeMillis()); |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 10548 | writeSyncLocked(); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10549 | mShuttingDown = true; |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 10550 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 10551 | |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 10552 | Parcel mPendingWrite = null; |
| 10553 | final ReentrantLock mWriteLock = new ReentrantLock(); |
| 10554 | |
| 10555 | public void writeAsyncLocked() { |
| 10556 | writeLocked(false); |
| 10557 | } |
| 10558 | |
| 10559 | public void writeSyncLocked() { |
| 10560 | writeLocked(true); |
| 10561 | } |
| 10562 | |
| 10563 | void writeLocked(boolean sync) { |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 10564 | if (mFile == null) { |
| 10565 | 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] | 10566 | return; |
| 10567 | } |
| 10568 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10569 | if (mShuttingDown) { |
| 10570 | return; |
| 10571 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 10572 | |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 10573 | Parcel out = Parcel.obtain(); |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 10574 | writeSummaryToParcel(out, true); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 10575 | mLastWriteTime = mClocks.elapsedRealtime(); |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 10576 | |
| 10577 | if (mPendingWrite != null) { |
| 10578 | mPendingWrite.recycle(); |
| 10579 | } |
| 10580 | mPendingWrite = out; |
| 10581 | |
| 10582 | if (sync) { |
| 10583 | commitPendingDataToDisk(); |
| 10584 | } else { |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 10585 | BackgroundThread.getHandler().post(new Runnable() { |
| 10586 | @Override public void run() { |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 10587 | commitPendingDataToDisk(); |
| 10588 | } |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 10589 | }); |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 10590 | } |
| 10591 | } |
| 10592 | |
| 10593 | public void commitPendingDataToDisk() { |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 10594 | final Parcel next; |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 10595 | synchronized (this) { |
| 10596 | next = mPendingWrite; |
| 10597 | mPendingWrite = null; |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 10598 | if (next == null) { |
| 10599 | return; |
| 10600 | } |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 10601 | } |
| 10602 | |
Amith Yamasani | d245086 | 2017-02-07 15:58:24 -0800 | [diff] [blame] | 10603 | mWriteLock.lock(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10604 | try { |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 10605 | FileOutputStream stream = new FileOutputStream(mFile.chooseForWrite()); |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 10606 | stream.write(next.marshall()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10607 | stream.flush(); |
Dianne Hackborn | 8bdf593 | 2010-10-15 12:54:40 -0700 | [diff] [blame] | 10608 | FileUtils.sync(stream); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10609 | stream.close(); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 10610 | mFile.commit(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10611 | } catch (IOException e) { |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 10612 | Slog.w("BatteryStats", "Error writing battery statistics", e); |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 10613 | mFile.rollback(); |
| 10614 | } finally { |
| 10615 | next.recycle(); |
| 10616 | mWriteLock.unlock(); |
Suchi Amalapurapu | 8550f25 | 2009-09-29 15:20:32 -0700 | [diff] [blame] | 10617 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10618 | } |
| 10619 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10620 | public void readLocked() { |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 10621 | if (mDailyFile != null) { |
| 10622 | readDailyStatsLocked(); |
| 10623 | } |
| 10624 | |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 10625 | if (mFile == null) { |
| 10626 | 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] | 10627 | return; |
| 10628 | } |
| 10629 | |
| 10630 | mUidStats.clear(); |
| 10631 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10632 | try { |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 10633 | File file = mFile.chooseForRead(); |
| 10634 | if (!file.exists()) { |
| 10635 | return; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10636 | } |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 10637 | FileInputStream stream = new FileInputStream(file); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10638 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 10639 | byte[] raw = BatteryStatsHelper.readFully(stream); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10640 | Parcel in = Parcel.obtain(); |
| 10641 | in.unmarshall(raw, 0, raw.length); |
| 10642 | in.setDataPosition(0); |
| 10643 | stream.close(); |
| 10644 | |
| 10645 | readSummaryFromParcel(in); |
Dianne Hackborn | 00e2521 | 2014-02-19 10:49:24 -0800 | [diff] [blame] | 10646 | } catch(Exception e) { |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 10647 | Slog.e("BatteryStats", "Error reading battery statistics", e); |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 10648 | resetAllStatsLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10649 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 10650 | |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 10651 | mEndPlatformVersion = Build.ID; |
| 10652 | |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 10653 | if (mHistoryBuffer.dataPosition() > 0) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 10654 | mRecordingHistory = true; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 10655 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 10656 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 10657 | if (USE_OLD_HISTORY) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 10658 | addHistoryRecordLocked(elapsedRealtime, uptime, HistoryItem.CMD_START, mHistoryCur); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 10659 | } |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 10660 | addHistoryBufferLocked(elapsedRealtime, uptime, HistoryItem.CMD_START, mHistoryCur); |
| 10661 | startRecordingHistory(elapsedRealtime, uptime, false); |
Dianne Hackborn | e8c88e6 | 2011-08-17 19:09:09 -0700 | [diff] [blame] | 10662 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 10663 | |
| 10664 | recordDailyStatsIfNeededLocked(false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10665 | } |
| 10666 | |
| 10667 | public int describeContents() { |
| 10668 | return 0; |
| 10669 | } |
| 10670 | |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 10671 | void readHistory(Parcel in, boolean andOldHistory) throws ParcelFormatException { |
Dianne Hackborn | ae38445 | 2011-06-28 12:33:48 -0700 | [diff] [blame] | 10672 | final long historyBaseTime = in.readLong(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 10673 | |
| 10674 | mHistoryBuffer.setDataSize(0); |
| 10675 | mHistoryBuffer.setDataPosition(0); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 10676 | mHistoryTagPool.clear(); |
| 10677 | mNextHistoryTagIdx = 0; |
| 10678 | mNumHistoryTagChars = 0; |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 10679 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 10680 | int numTags = in.readInt(); |
| 10681 | for (int i=0; i<numTags; i++) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 10682 | int idx = in.readInt(); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 10683 | String str = in.readString(); |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 10684 | if (str == null) { |
| 10685 | throw new ParcelFormatException("null history tag string"); |
| 10686 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 10687 | int uid = in.readInt(); |
| 10688 | HistoryTag tag = new HistoryTag(); |
| 10689 | tag.string = str; |
| 10690 | tag.uid = uid; |
| 10691 | tag.poolIdx = idx; |
| 10692 | mHistoryTagPool.put(tag, idx); |
| 10693 | if (idx >= mNextHistoryTagIdx) { |
| 10694 | mNextHistoryTagIdx = idx+1; |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 10695 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 10696 | mNumHistoryTagChars += tag.string.length() + 1; |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 10697 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 10698 | |
| 10699 | int bufSize = in.readInt(); |
| 10700 | int curPos = in.dataPosition(); |
| 10701 | if (bufSize >= (MAX_MAX_HISTORY_BUFFER*3)) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 10702 | throw new ParcelFormatException("File corrupt: history data buffer too large " + |
| 10703 | bufSize); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 10704 | } else if ((bufSize&~3) != bufSize) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 10705 | throw new ParcelFormatException("File corrupt: history data buffer not aligned " + |
| 10706 | bufSize); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 10707 | } else { |
| 10708 | if (DEBUG_HISTORY) Slog.i(TAG, "***************** READING NEW HISTORY: " + bufSize |
| 10709 | + " bytes at " + curPos); |
| 10710 | mHistoryBuffer.appendFrom(in, curPos, bufSize); |
| 10711 | in.setDataPosition(curPos + bufSize); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 10712 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 10713 | |
Dianne Hackborn | ae38445 | 2011-06-28 12:33:48 -0700 | [diff] [blame] | 10714 | if (andOldHistory) { |
| 10715 | readOldHistory(in); |
| 10716 | } |
| 10717 | |
| 10718 | if (DEBUG_HISTORY) { |
| 10719 | StringBuilder sb = new StringBuilder(128); |
| 10720 | sb.append("****************** OLD mHistoryBaseTime: "); |
| 10721 | TimeUtils.formatDuration(mHistoryBaseTime, sb); |
| 10722 | Slog.i(TAG, sb.toString()); |
| 10723 | } |
| 10724 | mHistoryBaseTime = historyBaseTime; |
| 10725 | if (DEBUG_HISTORY) { |
| 10726 | StringBuilder sb = new StringBuilder(128); |
| 10727 | sb.append("****************** NEW mHistoryBaseTime: "); |
| 10728 | TimeUtils.formatDuration(mHistoryBaseTime, sb); |
| 10729 | Slog.i(TAG, sb.toString()); |
| 10730 | } |
| 10731 | |
| 10732 | // We are just arbitrarily going to insert 1 minute from the sample of |
| 10733 | // the last run until samples in this run. |
| 10734 | if (mHistoryBaseTime > 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 10735 | long oldnow = mClocks.elapsedRealtime(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 10736 | mHistoryBaseTime = mHistoryBaseTime - oldnow + 1; |
Dianne Hackborn | ae38445 | 2011-06-28 12:33:48 -0700 | [diff] [blame] | 10737 | if (DEBUG_HISTORY) { |
| 10738 | StringBuilder sb = new StringBuilder(128); |
| 10739 | sb.append("****************** ADJUSTED mHistoryBaseTime: "); |
| 10740 | TimeUtils.formatDuration(mHistoryBaseTime, sb); |
| 10741 | Slog.i(TAG, sb.toString()); |
| 10742 | } |
Dianne Hackborn | 1e4b9f3 | 2010-06-23 14:10:57 -0700 | [diff] [blame] | 10743 | } |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 10744 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 10745 | |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 10746 | void readOldHistory(Parcel in) { |
Dianne Hackborn | e8c88e6 | 2011-08-17 19:09:09 -0700 | [diff] [blame] | 10747 | if (!USE_OLD_HISTORY) { |
| 10748 | return; |
| 10749 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 10750 | mHistory = mHistoryEnd = mHistoryCache = null; |
| 10751 | long time; |
Conley Owens | 5e3357f | 2011-05-02 09:59:30 -0700 | [diff] [blame] | 10752 | while (in.dataAvail() > 0 && (time=in.readLong()) >= 0) { |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 10753 | HistoryItem rec = new HistoryItem(time, in); |
| 10754 | addHistoryRecordLocked(rec); |
| 10755 | } |
| 10756 | } |
| 10757 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 10758 | void writeHistory(Parcel out, boolean inclData, boolean andOldHistory) { |
Dianne Hackborn | ae38445 | 2011-06-28 12:33:48 -0700 | [diff] [blame] | 10759 | if (DEBUG_HISTORY) { |
| 10760 | StringBuilder sb = new StringBuilder(128); |
| 10761 | sb.append("****************** WRITING mHistoryBaseTime: "); |
| 10762 | TimeUtils.formatDuration(mHistoryBaseTime, sb); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 10763 | sb.append(" mLastHistoryElapsedRealtime: "); |
| 10764 | TimeUtils.formatDuration(mLastHistoryElapsedRealtime, sb); |
Dianne Hackborn | ae38445 | 2011-06-28 12:33:48 -0700 | [diff] [blame] | 10765 | Slog.i(TAG, sb.toString()); |
| 10766 | } |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 10767 | out.writeLong(mHistoryBaseTime + mLastHistoryElapsedRealtime); |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 10768 | if (!inclData) { |
| 10769 | out.writeInt(0); |
| 10770 | out.writeInt(0); |
| 10771 | return; |
| 10772 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 10773 | out.writeInt(mHistoryTagPool.size()); |
| 10774 | for (HashMap.Entry<HistoryTag, Integer> ent : mHistoryTagPool.entrySet()) { |
| 10775 | HistoryTag tag = ent.getKey(); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 10776 | out.writeInt(ent.getValue()); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 10777 | out.writeString(tag.string); |
| 10778 | out.writeInt(tag.uid); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 10779 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 10780 | out.writeInt(mHistoryBuffer.dataSize()); |
| 10781 | if (DEBUG_HISTORY) Slog.i(TAG, "***************** WRITING HISTORY: " |
| 10782 | + mHistoryBuffer.dataSize() + " bytes at " + out.dataPosition()); |
| 10783 | out.appendFrom(mHistoryBuffer, 0, mHistoryBuffer.dataSize()); |
Dianne Hackborn | ae38445 | 2011-06-28 12:33:48 -0700 | [diff] [blame] | 10784 | |
| 10785 | if (andOldHistory) { |
| 10786 | writeOldHistory(out); |
| 10787 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 10788 | } |
| 10789 | |
| 10790 | void writeOldHistory(Parcel out) { |
Dianne Hackborn | e8c88e6 | 2011-08-17 19:09:09 -0700 | [diff] [blame] | 10791 | if (!USE_OLD_HISTORY) { |
| 10792 | return; |
| 10793 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10794 | HistoryItem rec = mHistory; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 10795 | while (rec != null) { |
| 10796 | if (rec.time >= 0) rec.writeToParcel(out, 0); |
| 10797 | rec = rec.next; |
| 10798 | } |
| 10799 | out.writeLong(-1); |
| 10800 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 10801 | |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 10802 | public void readSummaryFromParcel(Parcel in) throws ParcelFormatException { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10803 | final int version = in.readInt(); |
| 10804 | if (version != VERSION) { |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 10805 | Slog.w("BatteryStats", "readFromParcel: version got " + version |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10806 | + ", expected " + VERSION + "; erasing old stats"); |
| 10807 | return; |
| 10808 | } |
| 10809 | |
Dianne Hackborn | ae38445 | 2011-06-28 12:33:48 -0700 | [diff] [blame] | 10810 | readHistory(in, true); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 10811 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10812 | mStartCount = in.readInt(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10813 | mUptime = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10814 | mRealtime = in.readLong(); |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 10815 | mStartClockTime = in.readLong(); |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 10816 | mStartPlatformVersion = in.readString(); |
| 10817 | mEndPlatformVersion = in.readString(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10818 | mOnBatteryTimeBase.readSummaryFromParcel(in); |
| 10819 | mOnBatteryScreenOffTimeBase.readSummaryFromParcel(in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10820 | mDischargeUnplugLevel = in.readInt(); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 10821 | mDischargePlugLevel = in.readInt(); |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 10822 | mDischargeCurrentLevel = in.readInt(); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 10823 | mCurrentBatteryLevel = in.readInt(); |
Adam Lesinski | f9b20a9 | 2016-06-17 17:30:01 -0700 | [diff] [blame] | 10824 | mEstimatedBatteryCapacity = in.readInt(); |
Jocelyn Dang | c627d10 | 2017-04-14 13:15:14 -0700 | [diff] [blame^] | 10825 | mMinLearnedBatteryCapacity = in.readInt(); |
| 10826 | mMaxLearnedBatteryCapacity = in.readInt(); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 10827 | mLowDischargeAmountSinceCharge = in.readInt(); |
| 10828 | mHighDischargeAmountSinceCharge = in.readInt(); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 10829 | mDischargeAmountScreenOnSinceCharge = in.readInt(); |
| 10830 | mDischargeAmountScreenOffSinceCharge = in.readInt(); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 10831 | mDischargeStepTracker.readFromParcel(in); |
| 10832 | mChargeStepTracker.readFromParcel(in); |
| 10833 | mDailyDischargeStepTracker.readFromParcel(in); |
| 10834 | mDailyChargeStepTracker.readFromParcel(in); |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 10835 | mDischargeCounter.readSummaryFromParcelLocked(in); |
| 10836 | mDischargeScreenOffCounter.readSummaryFromParcelLocked(in); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 10837 | int NPKG = in.readInt(); |
| 10838 | if (NPKG > 0) { |
| 10839 | mDailyPackageChanges = new ArrayList<>(NPKG); |
| 10840 | while (NPKG > 0) { |
| 10841 | NPKG--; |
| 10842 | PackageChange pc = new PackageChange(); |
| 10843 | pc.mPackageName = in.readString(); |
| 10844 | pc.mUpdate = in.readInt() != 0; |
| 10845 | pc.mVersionCode = in.readInt(); |
| 10846 | mDailyPackageChanges.add(pc); |
| 10847 | } |
| 10848 | } else { |
| 10849 | mDailyPackageChanges = null; |
| 10850 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 10851 | mDailyStartTime = in.readLong(); |
| 10852 | mNextMinDailyDeadline = in.readLong(); |
| 10853 | mNextMaxDailyDeadline = in.readLong(); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 10854 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10855 | mStartCount++; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 10856 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 10857 | mScreenState = Display.STATE_UNKNOWN; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10858 | mScreenOnTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 10859 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
| 10860 | mScreenBrightnessTimer[i].readSummaryFromParcelLocked(in); |
| 10861 | } |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 10862 | mInteractive = false; |
| 10863 | mInteractiveTimer.readSummaryFromParcelLocked(in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10864 | mPhoneOn = false; |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 10865 | mPowerSaveModeEnabledTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 10866 | mLongestLightIdleTime = in.readLong(); |
| 10867 | mLongestFullIdleTime = in.readLong(); |
| 10868 | mDeviceIdleModeLightTimer.readSummaryFromParcelLocked(in); |
| 10869 | mDeviceIdleModeFullTimer.readSummaryFromParcelLocked(in); |
| 10870 | mDeviceLightIdlingTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 10871 | mDeviceIdlingTimer.readSummaryFromParcelLocked(in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10872 | mPhoneOnTimer.readSummaryFromParcelLocked(in); |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 10873 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 10874 | mPhoneSignalStrengthsTimer[i].readSummaryFromParcelLocked(in); |
| 10875 | } |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 10876 | mPhoneSignalScanningTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 10877 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
| 10878 | mPhoneDataConnectionsTimer[i].readSummaryFromParcelLocked(in); |
| 10879 | } |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 10880 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 10881 | mNetworkByteActivityCounters[i].readSummaryFromParcelLocked(in); |
| 10882 | mNetworkPacketActivityCounters[i].readSummaryFromParcelLocked(in); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 10883 | } |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 10884 | mMobileRadioPowerState = DataConnectionRealTimeInfo.DC_POWER_STATE_LOW; |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 10885 | mMobileRadioActiveTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 10886 | mMobileRadioActivePerAppTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 10887 | mMobileRadioActiveAdjustedTime.readSummaryFromParcelLocked(in); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 10888 | mMobileRadioActiveUnknownTime.readSummaryFromParcelLocked(in); |
| 10889 | mMobileRadioActiveUnknownCount.readSummaryFromParcelLocked(in); |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 10890 | mWifiRadioPowerState = DataConnectionRealTimeInfo.DC_POWER_STATE_LOW; |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 10891 | mWifiOn = false; |
| 10892 | mWifiOnTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 10893 | mGlobalWifiRunning = false; |
| 10894 | mGlobalWifiRunningTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 10895 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
| 10896 | mWifiStateTimer[i].readSummaryFromParcelLocked(in); |
| 10897 | } |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 10898 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
| 10899 | mWifiSupplStateTimer[i].readSummaryFromParcelLocked(in); |
| 10900 | } |
| 10901 | for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 10902 | mWifiSignalStrengthsTimer[i].readSummaryFromParcelLocked(in); |
| 10903 | } |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 10904 | mWifiActivity.readSummaryFromParcel(in); |
| 10905 | mBluetoothActivity.readSummaryFromParcel(in); |
| 10906 | mModemActivity.readSummaryFromParcel(in); |
| 10907 | mHasWifiReporting = in.readInt() != 0; |
| 10908 | mHasBluetoothReporting = in.readInt() != 0; |
| 10909 | mHasModemReporting = in.readInt() != 0; |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 10910 | |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 10911 | mNumConnectivityChange = mLoadedNumConnectivityChange = in.readInt(); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 10912 | mFlashlightOnNesting = 0; |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 10913 | mFlashlightOnTimer.readSummaryFromParcelLocked(in); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 10914 | mCameraOnNesting = 0; |
| 10915 | mCameraOnTimer.readSummaryFromParcelLocked(in); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 10916 | mBluetoothScanNesting = 0; |
| 10917 | mBluetoothScanTimer.readSummaryFromParcelLocked(in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10918 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 10919 | int NKW = in.readInt(); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 10920 | if (NKW > 10000) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 10921 | throw new ParcelFormatException("File corrupt: too many kernel wake locks " + NKW); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 10922 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 10923 | for (int ikw = 0; ikw < NKW; ikw++) { |
| 10924 | if (in.readInt() != 0) { |
| 10925 | String kwltName = in.readString(); |
| 10926 | getKernelWakelockTimerLocked(kwltName).readSummaryFromParcelLocked(in); |
| 10927 | } |
| 10928 | } |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 10929 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 10930 | int NWR = in.readInt(); |
| 10931 | if (NWR > 10000) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 10932 | throw new ParcelFormatException("File corrupt: too many wakeup reasons " + NWR); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 10933 | } |
| 10934 | for (int iwr = 0; iwr < NWR; iwr++) { |
| 10935 | if (in.readInt() != 0) { |
| 10936 | String reasonName = in.readString(); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 10937 | getWakeupReasonTimerLocked(reasonName).readSummaryFromParcelLocked(in); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 10938 | } |
| 10939 | } |
| 10940 | |
James Carr | 3a22605 | 2016-07-01 14:49:52 -0700 | [diff] [blame] | 10941 | int NMS = in.readInt(); |
| 10942 | for (int ims = 0; ims < NMS; ims++) { |
| 10943 | if (in.readInt() != 0) { |
| 10944 | long kmstName = in.readLong(); |
| 10945 | getKernelMemoryTimerLocked(kmstName).readSummaryFromParcelLocked(in); |
| 10946 | } |
| 10947 | } |
| 10948 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10949 | final int NU = in.readInt(); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 10950 | if (NU > 10000) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 10951 | throw new ParcelFormatException("File corrupt: too many uids " + NU); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 10952 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10953 | for (int iu = 0; iu < NU; iu++) { |
| 10954 | int uid = in.readInt(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 10955 | Uid u = new Uid(this, uid); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10956 | mUidStats.put(uid, u); |
| 10957 | |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 10958 | u.mOnBatteryBackgroundTimeBase.readSummaryFromParcel(in); |
| 10959 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 10960 | u.mWifiRunning = false; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10961 | if (in.readInt() != 0) { |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 10962 | u.mWifiRunningTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10963 | } |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 10964 | u.mFullWifiLockOut = false; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10965 | if (in.readInt() != 0) { |
| 10966 | u.mFullWifiLockTimer.readSummaryFromParcelLocked(in); |
| 10967 | } |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 10968 | u.mWifiScanStarted = false; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10969 | if (in.readInt() != 0) { |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 10970 | u.mWifiScanTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10971 | } |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 10972 | u.mWifiBatchedScanBinStarted = Uid.NO_BATCHED_SCAN_STARTED; |
| 10973 | for (int i = 0; i < Uid.NUM_WIFI_BATCHED_SCAN_BINS; i++) { |
| 10974 | if (in.readInt() != 0) { |
| 10975 | u.makeWifiBatchedScanBin(i, null); |
| 10976 | u.mWifiBatchedScanTimer[i].readSummaryFromParcelLocked(in); |
| 10977 | } |
| 10978 | } |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 10979 | u.mWifiMulticastEnabled = false; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10980 | if (in.readInt() != 0) { |
| 10981 | u.mWifiMulticastTimer.readSummaryFromParcelLocked(in); |
| 10982 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10983 | if (in.readInt() != 0) { |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 10984 | u.createAudioTurnedOnTimerLocked().readSummaryFromParcelLocked(in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10985 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10986 | if (in.readInt() != 0) { |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 10987 | u.createVideoTurnedOnTimerLocked().readSummaryFromParcelLocked(in); |
| 10988 | } |
| 10989 | if (in.readInt() != 0) { |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 10990 | u.createFlashlightTurnedOnTimerLocked().readSummaryFromParcelLocked(in); |
| 10991 | } |
| 10992 | if (in.readInt() != 0) { |
| 10993 | u.createCameraTurnedOnTimerLocked().readSummaryFromParcelLocked(in); |
| 10994 | } |
| 10995 | if (in.readInt() != 0) { |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 10996 | u.createForegroundActivityTimerLocked().readSummaryFromParcelLocked(in); |
| 10997 | } |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 10998 | if (in.readInt() != 0) { |
| 10999 | u.createBluetoothScanTimerLocked().readSummaryFromParcelLocked(in); |
| 11000 | } |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 11001 | u.mProcessState = ActivityManager.PROCESS_STATE_NONEXISTENT; |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 11002 | for (int i = 0; i < Uid.NUM_PROCESS_STATE; i++) { |
| 11003 | if (in.readInt() != 0) { |
| 11004 | u.makeProcessState(i, null); |
| 11005 | u.mProcessStateTimer[i].readSummaryFromParcelLocked(in); |
| 11006 | } |
| 11007 | } |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 11008 | if (in.readInt() != 0) { |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 11009 | u.createVibratorOnTimerLocked().readSummaryFromParcelLocked(in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 11010 | } |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 11011 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 11012 | if (in.readInt() != 0) { |
| 11013 | if (u.mUserActivityCounters == null) { |
| 11014 | u.initUserActivityLocked(); |
| 11015 | } |
| 11016 | for (int i=0; i<Uid.NUM_USER_ACTIVITY_TYPES; i++) { |
| 11017 | u.mUserActivityCounters[i].readSummaryFromParcelLocked(in); |
| 11018 | } |
| 11019 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 11020 | |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 11021 | if (in.readInt() != 0) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 11022 | if (u.mNetworkByteActivityCounters == null) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 11023 | u.initNetworkActivityLocked(); |
| 11024 | } |
| 11025 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 11026 | u.mNetworkByteActivityCounters[i].readSummaryFromParcelLocked(in); |
| 11027 | u.mNetworkPacketActivityCounters[i].readSummaryFromParcelLocked(in); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 11028 | } |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 11029 | u.mMobileRadioActiveTime.readSummaryFromParcelLocked(in); |
| 11030 | u.mMobileRadioActiveCount.readSummaryFromParcelLocked(in); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 11031 | } |
| 11032 | |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 11033 | u.mUserCpuTime.readSummaryFromParcelLocked(in); |
| 11034 | u.mSystemCpuTime.readSummaryFromParcelLocked(in); |
| 11035 | |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 11036 | if (in.readInt() != 0) { |
| 11037 | final int numClusters = in.readInt(); |
| 11038 | if (mPowerProfile != null && mPowerProfile.getNumCpuClusters() != numClusters) { |
| 11039 | throw new ParcelFormatException("Incompatible cpu cluster arrangement"); |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 11040 | } |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 11041 | |
| 11042 | u.mCpuClusterSpeed = new LongSamplingCounter[numClusters][]; |
| 11043 | for (int cluster = 0; cluster < numClusters; cluster++) { |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 11044 | if (in.readInt() != 0) { |
Adam Lesinski | a57a540 | 2015-09-28 10:21:33 -0700 | [diff] [blame] | 11045 | final int NSB = in.readInt(); |
| 11046 | if (mPowerProfile != null && |
| 11047 | mPowerProfile.getNumSpeedStepsInCpuCluster(cluster) != NSB) { |
| 11048 | throw new ParcelFormatException("File corrupt: too many speed bins " + |
| 11049 | NSB); |
| 11050 | } |
| 11051 | |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 11052 | u.mCpuClusterSpeed[cluster] = new LongSamplingCounter[NSB]; |
| 11053 | for (int speed = 0; speed < NSB; speed++) { |
| 11054 | if (in.readInt() != 0) { |
| 11055 | u.mCpuClusterSpeed[cluster][speed] = new LongSamplingCounter( |
| 11056 | mOnBatteryTimeBase); |
| 11057 | u.mCpuClusterSpeed[cluster][speed].readSummaryFromParcelLocked(in); |
| 11058 | } |
| 11059 | } |
Adam Lesinski | a57a540 | 2015-09-28 10:21:33 -0700 | [diff] [blame] | 11060 | } else { |
| 11061 | u.mCpuClusterSpeed[cluster] = null; |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 11062 | } |
| 11063 | } |
| 11064 | } else { |
| 11065 | u.mCpuClusterSpeed = null; |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 11066 | } |
| 11067 | |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 11068 | if (in.readInt() != 0) { |
| 11069 | u.mMobileRadioApWakeupCount = new LongSamplingCounter(mOnBatteryTimeBase); |
| 11070 | u.mMobileRadioApWakeupCount.readSummaryFromParcelLocked(in); |
| 11071 | } else { |
| 11072 | u.mMobileRadioApWakeupCount = null; |
| 11073 | } |
| 11074 | |
| 11075 | if (in.readInt() != 0) { |
| 11076 | u.mWifiRadioApWakeupCount = new LongSamplingCounter(mOnBatteryTimeBase); |
| 11077 | u.mWifiRadioApWakeupCount.readSummaryFromParcelLocked(in); |
| 11078 | } else { |
| 11079 | u.mWifiRadioApWakeupCount = null; |
| 11080 | } |
| 11081 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11082 | int NW = in.readInt(); |
Dianne Hackborn | cb99a72 | 2016-10-03 17:00:02 -0700 | [diff] [blame] | 11083 | if (NW > (MAX_WAKELOCKS_PER_UID+1)) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 11084 | throw new ParcelFormatException("File corrupt: too many wake locks " + NW); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 11085 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11086 | for (int iw = 0; iw < NW; iw++) { |
| 11087 | String wlName = in.readString(); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 11088 | u.readWakeSummaryFromParcelLocked(wlName, in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11089 | } |
| 11090 | |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 11091 | int NS = in.readInt(); |
Dianne Hackborn | cb99a72 | 2016-10-03 17:00:02 -0700 | [diff] [blame] | 11092 | if (NS > (MAX_WAKELOCKS_PER_UID+1)) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 11093 | throw new ParcelFormatException("File corrupt: too many syncs " + NS); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 11094 | } |
| 11095 | for (int is = 0; is < NS; is++) { |
| 11096 | String name = in.readString(); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 11097 | u.readSyncSummaryFromParcelLocked(name, in); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 11098 | } |
| 11099 | |
| 11100 | int NJ = in.readInt(); |
Dianne Hackborn | cb99a72 | 2016-10-03 17:00:02 -0700 | [diff] [blame] | 11101 | if (NJ > (MAX_WAKELOCKS_PER_UID+1)) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 11102 | throw new ParcelFormatException("File corrupt: too many job timers " + NJ); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 11103 | } |
| 11104 | for (int ij = 0; ij < NJ; ij++) { |
| 11105 | String name = in.readString(); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 11106 | u.readJobSummaryFromParcelLocked(name, in); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 11107 | } |
| 11108 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11109 | int NP = in.readInt(); |
Dianne Hackborn | 7b9c56f | 2010-12-07 11:14:53 -0800 | [diff] [blame] | 11110 | if (NP > 1000) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 11111 | throw new ParcelFormatException("File corrupt: too many sensors " + NP); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 11112 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11113 | for (int is = 0; is < NP; is++) { |
| 11114 | int seNumber = in.readInt(); |
| 11115 | if (in.readInt() != 0) { |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 11116 | u.getSensorTimerLocked(seNumber, true).readSummaryFromParcelLocked(in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11117 | } |
| 11118 | } |
| 11119 | |
| 11120 | NP = in.readInt(); |
Dianne Hackborn | 7b9c56f | 2010-12-07 11:14:53 -0800 | [diff] [blame] | 11121 | if (NP > 1000) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 11122 | throw new ParcelFormatException("File corrupt: too many processes " + NP); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 11123 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11124 | for (int ip = 0; ip < NP; ip++) { |
| 11125 | String procName = in.readString(); |
| 11126 | Uid.Proc p = u.getProcessStatsLocked(procName); |
| 11127 | p.mUserTime = p.mLoadedUserTime = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11128 | p.mSystemTime = p.mLoadedSystemTime = in.readLong(); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 11129 | p.mForegroundTime = p.mLoadedForegroundTime = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11130 | p.mStarts = p.mLoadedStarts = in.readInt(); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 11131 | p.mNumCrashes = p.mLoadedNumCrashes = in.readInt(); |
| 11132 | p.mNumAnrs = p.mLoadedNumAnrs = in.readInt(); |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 11133 | p.readExcessivePowerFromParcelLocked(in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11134 | } |
| 11135 | |
| 11136 | NP = in.readInt(); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 11137 | if (NP > 10000) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 11138 | throw new ParcelFormatException("File corrupt: too many packages " + NP); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 11139 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11140 | for (int ip = 0; ip < NP; ip++) { |
| 11141 | String pkgName = in.readString(); |
| 11142 | Uid.Pkg p = u.getPackageStatsLocked(pkgName); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 11143 | final int NWA = in.readInt(); |
| 11144 | if (NWA > 1000) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 11145 | throw new ParcelFormatException("File corrupt: too many wakeup alarms " + NWA); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 11146 | } |
| 11147 | p.mWakeupAlarms.clear(); |
| 11148 | for (int iwa=0; iwa<NWA; iwa++) { |
| 11149 | String tag = in.readString(); |
| 11150 | Counter c = new Counter(mOnBatteryTimeBase); |
| 11151 | c.readSummaryFromParcelLocked(in); |
| 11152 | p.mWakeupAlarms.put(tag, c); |
| 11153 | } |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 11154 | NS = in.readInt(); |
Dianne Hackborn | 7b9c56f | 2010-12-07 11:14:53 -0800 | [diff] [blame] | 11155 | if (NS > 1000) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 11156 | throw new ParcelFormatException("File corrupt: too many services " + NS); |
Dianne Hackborn | 7b9c56f | 2010-12-07 11:14:53 -0800 | [diff] [blame] | 11157 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11158 | for (int is = 0; is < NS; is++) { |
| 11159 | String servName = in.readString(); |
| 11160 | Uid.Pkg.Serv s = u.getServiceStatsLocked(pkgName, servName); |
| 11161 | s.mStartTime = s.mLoadedStartTime = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11162 | s.mStarts = s.mLoadedStarts = in.readInt(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11163 | s.mLaunches = s.mLoadedLaunches = in.readInt(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11164 | } |
| 11165 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11166 | } |
| 11167 | } |
| 11168 | |
| 11169 | /** |
| 11170 | * Writes a summary of the statistics to a Parcel, in a format suitable to be written to |
| 11171 | * disk. This format does not allow a lossless round-trip. |
| 11172 | * |
| 11173 | * @param out the Parcel to be written to. |
| 11174 | */ |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 11175 | public void writeSummaryToParcel(Parcel out, boolean inclHistory) { |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 11176 | pullPendingStateUpdatesLocked(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 11177 | |
Dianne Hackborn | 7d9eefd | 2014-08-27 18:30:31 -0700 | [diff] [blame] | 11178 | // Pull the clock time. This may update the time and make a new history entry |
| 11179 | // if we had originally pulled a time before the RTC was set. |
| 11180 | long startClockTime = getStartClockTime(); |
| 11181 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 11182 | final long NOW_SYS = mClocks.uptimeMillis() * 1000; |
| 11183 | final long NOWREAL_SYS = mClocks.elapsedRealtime() * 1000; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11184 | |
| 11185 | out.writeInt(VERSION); |
| 11186 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 11187 | writeHistory(out, inclHistory, true); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 11188 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11189 | out.writeInt(mStartCount); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 11190 | out.writeLong(computeUptime(NOW_SYS, STATS_SINCE_CHARGED)); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 11191 | out.writeLong(computeRealtime(NOWREAL_SYS, STATS_SINCE_CHARGED)); |
Dianne Hackborn | 7d9eefd | 2014-08-27 18:30:31 -0700 | [diff] [blame] | 11192 | out.writeLong(startClockTime); |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 11193 | out.writeString(mStartPlatformVersion); |
| 11194 | out.writeString(mEndPlatformVersion); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 11195 | mOnBatteryTimeBase.writeSummaryToParcel(out, NOW_SYS, NOWREAL_SYS); |
| 11196 | mOnBatteryScreenOffTimeBase.writeSummaryToParcel(out, NOW_SYS, NOWREAL_SYS); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 11197 | out.writeInt(mDischargeUnplugLevel); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 11198 | out.writeInt(mDischargePlugLevel); |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 11199 | out.writeInt(mDischargeCurrentLevel); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 11200 | out.writeInt(mCurrentBatteryLevel); |
Adam Lesinski | f9b20a9 | 2016-06-17 17:30:01 -0700 | [diff] [blame] | 11201 | out.writeInt(mEstimatedBatteryCapacity); |
Jocelyn Dang | c627d10 | 2017-04-14 13:15:14 -0700 | [diff] [blame^] | 11202 | out.writeInt(mMinLearnedBatteryCapacity); |
| 11203 | out.writeInt(mMaxLearnedBatteryCapacity); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 11204 | out.writeInt(getLowDischargeAmountSinceCharge()); |
| 11205 | out.writeInt(getHighDischargeAmountSinceCharge()); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 11206 | out.writeInt(getDischargeAmountScreenOnSinceCharge()); |
| 11207 | out.writeInt(getDischargeAmountScreenOffSinceCharge()); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 11208 | mDischargeStepTracker.writeToParcel(out); |
| 11209 | mChargeStepTracker.writeToParcel(out); |
| 11210 | mDailyDischargeStepTracker.writeToParcel(out); |
| 11211 | mDailyChargeStepTracker.writeToParcel(out); |
Adam Lesinski | 67c134f | 2016-06-10 15:15:08 -0700 | [diff] [blame] | 11212 | mDischargeCounter.writeSummaryFromParcelLocked(out); |
| 11213 | mDischargeScreenOffCounter.writeSummaryFromParcelLocked(out); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 11214 | if (mDailyPackageChanges != null) { |
| 11215 | final int NPKG = mDailyPackageChanges.size(); |
| 11216 | out.writeInt(NPKG); |
| 11217 | for (int i=0; i<NPKG; i++) { |
| 11218 | PackageChange pc = mDailyPackageChanges.get(i); |
| 11219 | out.writeString(pc.mPackageName); |
| 11220 | out.writeInt(pc.mUpdate ? 1 : 0); |
| 11221 | out.writeInt(pc.mVersionCode); |
| 11222 | } |
| 11223 | } else { |
| 11224 | out.writeInt(0); |
| 11225 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 11226 | out.writeLong(mDailyStartTime); |
| 11227 | out.writeLong(mNextMinDailyDeadline); |
| 11228 | out.writeLong(mNextMaxDailyDeadline); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 11229 | |
| 11230 | mScreenOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 11231 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 11232 | mScreenBrightnessTimer[i].writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 11233 | } |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 11234 | mInteractiveTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 11235 | mPowerSaveModeEnabledTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 11236 | out.writeLong(mLongestLightIdleTime); |
| 11237 | out.writeLong(mLongestFullIdleTime); |
| 11238 | mDeviceIdleModeLightTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 11239 | mDeviceIdleModeFullTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 11240 | mDeviceLightIdlingTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 11241 | mDeviceIdlingTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 11242 | mPhoneOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 11243 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 11244 | mPhoneSignalStrengthsTimer[i].writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 11245 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 11246 | mPhoneSignalScanningTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 11247 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 11248 | mPhoneDataConnectionsTimer[i].writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 11249 | } |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 11250 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 11251 | mNetworkByteActivityCounters[i].writeSummaryFromParcelLocked(out); |
| 11252 | mNetworkPacketActivityCounters[i].writeSummaryFromParcelLocked(out); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 11253 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 11254 | mMobileRadioActiveTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 11255 | mMobileRadioActivePerAppTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 11256 | mMobileRadioActiveAdjustedTime.writeSummaryFromParcelLocked(out); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 11257 | mMobileRadioActiveUnknownTime.writeSummaryFromParcelLocked(out); |
| 11258 | mMobileRadioActiveUnknownCount.writeSummaryFromParcelLocked(out); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 11259 | mWifiOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 11260 | mGlobalWifiRunningTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 11261 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 11262 | mWifiStateTimer[i].writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 11263 | } |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 11264 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
| 11265 | mWifiSupplStateTimer[i].writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 11266 | } |
| 11267 | for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 11268 | mWifiSignalStrengthsTimer[i].writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 11269 | } |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 11270 | mWifiActivity.writeSummaryToParcel(out); |
| 11271 | mBluetoothActivity.writeSummaryToParcel(out); |
| 11272 | mModemActivity.writeSummaryToParcel(out); |
| 11273 | out.writeInt(mHasWifiReporting ? 1 : 0); |
| 11274 | out.writeInt(mHasBluetoothReporting ? 1 : 0); |
| 11275 | out.writeInt(mHasModemReporting ? 1 : 0); |
| 11276 | |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 11277 | out.writeInt(mNumConnectivityChange); |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 11278 | mFlashlightOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 11279 | mCameraOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 11280 | mBluetoothScanTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11281 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 11282 | out.writeInt(mKernelWakelockStats.size()); |
| 11283 | for (Map.Entry<String, SamplingTimer> ent : mKernelWakelockStats.entrySet()) { |
| 11284 | Timer kwlt = ent.getValue(); |
| 11285 | if (kwlt != null) { |
| 11286 | out.writeInt(1); |
| 11287 | out.writeString(ent.getKey()); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 11288 | kwlt.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 11289 | } else { |
| 11290 | out.writeInt(0); |
| 11291 | } |
| 11292 | } |
| 11293 | |
| 11294 | out.writeInt(mWakeupReasonStats.size()); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 11295 | for (Map.Entry<String, SamplingTimer> ent : mWakeupReasonStats.entrySet()) { |
| 11296 | SamplingTimer timer = ent.getValue(); |
| 11297 | if (timer != null) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 11298 | out.writeInt(1); |
| 11299 | out.writeString(ent.getKey()); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 11300 | timer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 11301 | } else { |
| 11302 | out.writeInt(0); |
| 11303 | } |
| 11304 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 11305 | |
James Carr | 3a22605 | 2016-07-01 14:49:52 -0700 | [diff] [blame] | 11306 | out.writeInt(mKernelMemoryStats.size()); |
| 11307 | for (int i = 0; i < mKernelMemoryStats.size(); i++) { |
| 11308 | Timer kmt = mKernelMemoryStats.valueAt(i); |
| 11309 | if (kmt != null) { |
| 11310 | out.writeInt(1); |
| 11311 | out.writeLong(mKernelMemoryStats.keyAt(i)); |
| 11312 | kmt.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 11313 | } else { |
| 11314 | out.writeInt(0); |
| 11315 | } |
| 11316 | } |
| 11317 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11318 | final int NU = mUidStats.size(); |
| 11319 | out.writeInt(NU); |
| 11320 | for (int iu = 0; iu < NU; iu++) { |
| 11321 | out.writeInt(mUidStats.keyAt(iu)); |
| 11322 | Uid u = mUidStats.valueAt(iu); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 11323 | |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 11324 | u.mOnBatteryBackgroundTimeBase.writeSummaryToParcel(out, NOW_SYS, NOWREAL_SYS); |
| 11325 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 11326 | if (u.mWifiRunningTimer != null) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 11327 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 11328 | u.mWifiRunningTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 11329 | } else { |
| 11330 | out.writeInt(0); |
| 11331 | } |
| 11332 | if (u.mFullWifiLockTimer != null) { |
| 11333 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 11334 | u.mFullWifiLockTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 11335 | } else { |
| 11336 | out.writeInt(0); |
| 11337 | } |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 11338 | if (u.mWifiScanTimer != null) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 11339 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 11340 | u.mWifiScanTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 11341 | } else { |
| 11342 | out.writeInt(0); |
| 11343 | } |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 11344 | for (int i = 0; i < Uid.NUM_WIFI_BATCHED_SCAN_BINS; i++) { |
| 11345 | if (u.mWifiBatchedScanTimer[i] != null) { |
| 11346 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 11347 | u.mWifiBatchedScanTimer[i].writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 11348 | } else { |
| 11349 | out.writeInt(0); |
| 11350 | } |
| 11351 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 11352 | if (u.mWifiMulticastTimer != null) { |
| 11353 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 11354 | u.mWifiMulticastTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 11355 | } else { |
| 11356 | out.writeInt(0); |
| 11357 | } |
| 11358 | if (u.mAudioTurnedOnTimer != null) { |
| 11359 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 11360 | u.mAudioTurnedOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 11361 | } else { |
| 11362 | out.writeInt(0); |
| 11363 | } |
| 11364 | if (u.mVideoTurnedOnTimer != null) { |
| 11365 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 11366 | u.mVideoTurnedOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 11367 | } else { |
| 11368 | out.writeInt(0); |
| 11369 | } |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 11370 | if (u.mFlashlightTurnedOnTimer != null) { |
| 11371 | out.writeInt(1); |
| 11372 | u.mFlashlightTurnedOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 11373 | } else { |
| 11374 | out.writeInt(0); |
| 11375 | } |
| 11376 | if (u.mCameraTurnedOnTimer != null) { |
| 11377 | out.writeInt(1); |
| 11378 | u.mCameraTurnedOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 11379 | } else { |
| 11380 | out.writeInt(0); |
| 11381 | } |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 11382 | if (u.mForegroundActivityTimer != null) { |
| 11383 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 11384 | u.mForegroundActivityTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 11385 | } else { |
| 11386 | out.writeInt(0); |
| 11387 | } |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 11388 | if (u.mBluetoothScanTimer != null) { |
| 11389 | out.writeInt(1); |
| 11390 | u.mBluetoothScanTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 11391 | } else { |
| 11392 | out.writeInt(0); |
| 11393 | } |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 11394 | for (int i = 0; i < Uid.NUM_PROCESS_STATE; i++) { |
| 11395 | if (u.mProcessStateTimer[i] != null) { |
| 11396 | out.writeInt(1); |
| 11397 | u.mProcessStateTimer[i].writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 11398 | } else { |
| 11399 | out.writeInt(0); |
| 11400 | } |
| 11401 | } |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 11402 | if (u.mVibratorOnTimer != null) { |
| 11403 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 11404 | u.mVibratorOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 11405 | } else { |
| 11406 | out.writeInt(0); |
| 11407 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11408 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 11409 | if (u.mUserActivityCounters == null) { |
| 11410 | out.writeInt(0); |
| 11411 | } else { |
| 11412 | out.writeInt(1); |
| 11413 | for (int i=0; i<Uid.NUM_USER_ACTIVITY_TYPES; i++) { |
| 11414 | u.mUserActivityCounters[i].writeSummaryFromParcelLocked(out); |
| 11415 | } |
| 11416 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 11417 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 11418 | if (u.mNetworkByteActivityCounters == null) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 11419 | out.writeInt(0); |
| 11420 | } else { |
| 11421 | out.writeInt(1); |
| 11422 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 11423 | u.mNetworkByteActivityCounters[i].writeSummaryFromParcelLocked(out); |
| 11424 | u.mNetworkPacketActivityCounters[i].writeSummaryFromParcelLocked(out); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 11425 | } |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 11426 | u.mMobileRadioActiveTime.writeSummaryFromParcelLocked(out); |
| 11427 | u.mMobileRadioActiveCount.writeSummaryFromParcelLocked(out); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 11428 | } |
| 11429 | |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 11430 | u.mUserCpuTime.writeSummaryFromParcelLocked(out); |
| 11431 | u.mSystemCpuTime.writeSummaryFromParcelLocked(out); |
| 11432 | |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 11433 | if (u.mCpuClusterSpeed != null) { |
| 11434 | out.writeInt(1); |
| 11435 | out.writeInt(u.mCpuClusterSpeed.length); |
| 11436 | for (LongSamplingCounter[] cpuSpeeds : u.mCpuClusterSpeed) { |
| 11437 | if (cpuSpeeds != null) { |
| 11438 | out.writeInt(1); |
| 11439 | out.writeInt(cpuSpeeds.length); |
| 11440 | for (LongSamplingCounter c : cpuSpeeds) { |
| 11441 | if (c != null) { |
| 11442 | out.writeInt(1); |
| 11443 | c.writeSummaryFromParcelLocked(out); |
| 11444 | } else { |
| 11445 | out.writeInt(0); |
| 11446 | } |
| 11447 | } |
| 11448 | } else { |
| 11449 | out.writeInt(0); |
| 11450 | } |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 11451 | } |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 11452 | } else { |
| 11453 | out.writeInt(0); |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 11454 | } |
| 11455 | |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 11456 | if (u.mMobileRadioApWakeupCount != null) { |
| 11457 | out.writeInt(1); |
| 11458 | u.mMobileRadioApWakeupCount.writeSummaryFromParcelLocked(out); |
| 11459 | } else { |
| 11460 | out.writeInt(0); |
| 11461 | } |
| 11462 | |
| 11463 | if (u.mWifiRadioApWakeupCount != null) { |
| 11464 | out.writeInt(1); |
| 11465 | u.mWifiRadioApWakeupCount.writeSummaryFromParcelLocked(out); |
| 11466 | } else { |
| 11467 | out.writeInt(0); |
| 11468 | } |
| 11469 | |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 11470 | final ArrayMap<String, Uid.Wakelock> wakeStats = u.mWakelockStats.getMap(); |
| 11471 | int NW = wakeStats.size(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11472 | out.writeInt(NW); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 11473 | for (int iw=0; iw<NW; iw++) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 11474 | out.writeString(wakeStats.keyAt(iw)); |
| 11475 | Uid.Wakelock wl = wakeStats.valueAt(iw); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 11476 | if (wl.mTimerFull != null) { |
| 11477 | out.writeInt(1); |
| 11478 | wl.mTimerFull.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 11479 | } else { |
| 11480 | out.writeInt(0); |
| 11481 | } |
| 11482 | if (wl.mTimerPartial != null) { |
| 11483 | out.writeInt(1); |
| 11484 | wl.mTimerPartial.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 11485 | } else { |
| 11486 | out.writeInt(0); |
| 11487 | } |
| 11488 | if (wl.mTimerWindow != null) { |
| 11489 | out.writeInt(1); |
| 11490 | wl.mTimerWindow.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 11491 | } else { |
| 11492 | out.writeInt(0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11493 | } |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 11494 | if (wl.mTimerDraw != null) { |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 11495 | out.writeInt(1); |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 11496 | wl.mTimerDraw.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 11497 | } else { |
| 11498 | out.writeInt(0); |
| 11499 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11500 | } |
| 11501 | |
Bookatz | 2bffb5b | 2017-04-13 11:59:33 -0700 | [diff] [blame] | 11502 | final ArrayMap<String, DualTimer> syncStats = u.mSyncStats.getMap(); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 11503 | int NS = syncStats.size(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 11504 | out.writeInt(NS); |
| 11505 | for (int is=0; is<NS; is++) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 11506 | out.writeString(syncStats.keyAt(is)); |
| 11507 | syncStats.valueAt(is).writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 11508 | } |
| 11509 | |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 11510 | final ArrayMap<String, DualTimer> jobStats = u.mJobStats.getMap(); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 11511 | int NJ = jobStats.size(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 11512 | out.writeInt(NJ); |
| 11513 | for (int ij=0; ij<NJ; ij++) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 11514 | out.writeString(jobStats.keyAt(ij)); |
| 11515 | jobStats.valueAt(ij).writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 11516 | } |
| 11517 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11518 | int NSE = u.mSensorStats.size(); |
| 11519 | out.writeInt(NSE); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 11520 | for (int ise=0; ise<NSE; ise++) { |
| 11521 | out.writeInt(u.mSensorStats.keyAt(ise)); |
| 11522 | Uid.Sensor se = u.mSensorStats.valueAt(ise); |
| 11523 | if (se.mTimer != null) { |
| 11524 | out.writeInt(1); |
| 11525 | se.mTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 11526 | } else { |
| 11527 | out.writeInt(0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11528 | } |
| 11529 | } |
| 11530 | |
| 11531 | int NP = u.mProcessStats.size(); |
| 11532 | out.writeInt(NP); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 11533 | for (int ip=0; ip<NP; ip++) { |
| 11534 | out.writeString(u.mProcessStats.keyAt(ip)); |
| 11535 | Uid.Proc ps = u.mProcessStats.valueAt(ip); |
| 11536 | out.writeLong(ps.mUserTime); |
| 11537 | out.writeLong(ps.mSystemTime); |
| 11538 | out.writeLong(ps.mForegroundTime); |
| 11539 | out.writeInt(ps.mStarts); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 11540 | out.writeInt(ps.mNumCrashes); |
| 11541 | out.writeInt(ps.mNumAnrs); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 11542 | ps.writeExcessivePowerToParcelLocked(out); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11543 | } |
| 11544 | |
| 11545 | NP = u.mPackageStats.size(); |
| 11546 | out.writeInt(NP); |
| 11547 | if (NP > 0) { |
| 11548 | for (Map.Entry<String, BatteryStatsImpl.Uid.Pkg> ent |
| 11549 | : u.mPackageStats.entrySet()) { |
| 11550 | out.writeString(ent.getKey()); |
| 11551 | Uid.Pkg ps = ent.getValue(); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 11552 | final int NWA = ps.mWakeupAlarms.size(); |
| 11553 | out.writeInt(NWA); |
| 11554 | for (int iwa=0; iwa<NWA; iwa++) { |
| 11555 | out.writeString(ps.mWakeupAlarms.keyAt(iwa)); |
| 11556 | ps.mWakeupAlarms.valueAt(iwa).writeSummaryFromParcelLocked(out); |
| 11557 | } |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 11558 | NS = ps.mServiceStats.size(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11559 | out.writeInt(NS); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 11560 | for (int is=0; is<NS; is++) { |
| 11561 | out.writeString(ps.mServiceStats.keyAt(is)); |
| 11562 | BatteryStatsImpl.Uid.Pkg.Serv ss = ps.mServiceStats.valueAt(is); |
| 11563 | long time = ss.getStartTimeToNowLocked( |
| 11564 | mOnBatteryTimeBase.getUptime(NOW_SYS)); |
| 11565 | out.writeLong(time); |
| 11566 | out.writeInt(ss.mStarts); |
| 11567 | out.writeInt(ss.mLaunches); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11568 | } |
| 11569 | } |
| 11570 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11571 | } |
| 11572 | } |
| 11573 | |
| 11574 | public void readFromParcel(Parcel in) { |
| 11575 | readFromParcelLocked(in); |
| 11576 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 11577 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11578 | void readFromParcelLocked(Parcel in) { |
| 11579 | int magic = in.readInt(); |
| 11580 | if (magic != MAGIC) { |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 11581 | throw new ParcelFormatException("Bad magic number: #" + Integer.toHexString(magic)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11582 | } |
| 11583 | |
Dianne Hackborn | ae38445 | 2011-06-28 12:33:48 -0700 | [diff] [blame] | 11584 | readHistory(in, false); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 11585 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11586 | mStartCount = in.readInt(); |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 11587 | mStartClockTime = in.readLong(); |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 11588 | mStartPlatformVersion = in.readString(); |
| 11589 | mEndPlatformVersion = in.readString(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11590 | mUptime = in.readLong(); |
| 11591 | mUptimeStart = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11592 | mRealtime = in.readLong(); |
| 11593 | mRealtimeStart = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11594 | mOnBattery = in.readInt() != 0; |
Adam Lesinski | f9b20a9 | 2016-06-17 17:30:01 -0700 | [diff] [blame] | 11595 | mEstimatedBatteryCapacity = in.readInt(); |
Jocelyn Dang | c627d10 | 2017-04-14 13:15:14 -0700 | [diff] [blame^] | 11596 | mMinLearnedBatteryCapacity = in.readInt(); |
| 11597 | mMaxLearnedBatteryCapacity = in.readInt(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11598 | mOnBatteryInternal = false; // we are no longer really running. |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 11599 | mOnBatteryTimeBase.readFromParcel(in); |
| 11600 | mOnBatteryScreenOffTimeBase.readFromParcel(in); |
| 11601 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 11602 | mScreenState = Display.STATE_UNKNOWN; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 11603 | mScreenOnTimer = new StopwatchTimer(mClocks, null, -1, null, mOnBatteryTimeBase, in); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 11604 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 11605 | mScreenBrightnessTimer[i] = new StopwatchTimer(mClocks, null, -100-i, null, |
| 11606 | mOnBatteryTimeBase, in); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 11607 | } |
Dianne Hackborn | 2932513 | 2014-05-21 15:01:03 -0700 | [diff] [blame] | 11608 | mInteractive = false; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 11609 | mInteractiveTimer = new StopwatchTimer(mClocks, null, -10, null, mOnBatteryTimeBase, in); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 11610 | mPhoneOn = false; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 11611 | mPowerSaveModeEnabledTimer = new StopwatchTimer(mClocks, null, -2, null, |
| 11612 | mOnBatteryTimeBase, in); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 11613 | mLongestLightIdleTime = in.readLong(); |
| 11614 | mLongestFullIdleTime = in.readLong(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 11615 | mDeviceIdleModeLightTimer = new StopwatchTimer(mClocks, null, -14, null, |
| 11616 | mOnBatteryTimeBase, in); |
| 11617 | mDeviceIdleModeFullTimer = new StopwatchTimer(mClocks, null, -11, null, |
| 11618 | mOnBatteryTimeBase, in); |
| 11619 | mDeviceLightIdlingTimer = new StopwatchTimer(mClocks, null, -15, null, |
| 11620 | mOnBatteryTimeBase, in); |
| 11621 | mDeviceIdlingTimer = new StopwatchTimer(mClocks, null, -12, null, mOnBatteryTimeBase, in); |
| 11622 | mPhoneOnTimer = new StopwatchTimer(mClocks, null, -3, null, mOnBatteryTimeBase, in); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 11623 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 11624 | mPhoneSignalStrengthsTimer[i] = new StopwatchTimer(mClocks, null, -200-i, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 11625 | null, mOnBatteryTimeBase, in); |
| 11626 | } |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 11627 | mPhoneSignalScanningTimer = new StopwatchTimer(mClocks, null, -200+1, null, |
| 11628 | mOnBatteryTimeBase, in); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 11629 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 11630 | mPhoneDataConnectionsTimer[i] = new StopwatchTimer(mClocks, null, -300-i, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 11631 | null, mOnBatteryTimeBase, in); |
| 11632 | } |
| 11633 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
| 11634 | mNetworkByteActivityCounters[i] = new LongSamplingCounter(mOnBatteryTimeBase, in); |
| 11635 | mNetworkPacketActivityCounters[i] = new LongSamplingCounter(mOnBatteryTimeBase, in); |
| 11636 | } |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 11637 | mMobileRadioPowerState = DataConnectionRealTimeInfo.DC_POWER_STATE_LOW; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 11638 | mMobileRadioActiveTimer = new StopwatchTimer(mClocks, null, -400, null, |
| 11639 | mOnBatteryTimeBase, in); |
| 11640 | mMobileRadioActivePerAppTimer = new StopwatchTimer(mClocks, null, -401, null, |
| 11641 | mOnBatteryTimeBase, in); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 11642 | mMobileRadioActiveAdjustedTime = new LongSamplingCounter(mOnBatteryTimeBase, in); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 11643 | mMobileRadioActiveUnknownTime = new LongSamplingCounter(mOnBatteryTimeBase, in); |
| 11644 | mMobileRadioActiveUnknownCount = new LongSamplingCounter(mOnBatteryTimeBase, in); |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 11645 | mWifiRadioPowerState = DataConnectionRealTimeInfo.DC_POWER_STATE_LOW; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 11646 | mWifiOn = false; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 11647 | mWifiOnTimer = new StopwatchTimer(mClocks, null, -4, null, mOnBatteryTimeBase, in); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 11648 | mGlobalWifiRunning = false; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 11649 | mGlobalWifiRunningTimer = new StopwatchTimer(mClocks, null, -5, null, |
| 11650 | mOnBatteryTimeBase, in); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 11651 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 11652 | mWifiStateTimer[i] = new StopwatchTimer(mClocks, null, -600-i, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 11653 | null, mOnBatteryTimeBase, in); |
| 11654 | } |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 11655 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 11656 | mWifiSupplStateTimer[i] = new StopwatchTimer(mClocks, null, -700-i, |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 11657 | null, mOnBatteryTimeBase, in); |
| 11658 | } |
| 11659 | for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 11660 | mWifiSignalStrengthsTimer[i] = new StopwatchTimer(mClocks, null, -800-i, |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 11661 | null, mOnBatteryTimeBase, in); |
| 11662 | } |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 11663 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 11664 | mWifiActivity = new ControllerActivityCounterImpl(mOnBatteryTimeBase, |
| 11665 | NUM_WIFI_TX_LEVELS, in); |
| 11666 | mBluetoothActivity = new ControllerActivityCounterImpl(mOnBatteryTimeBase, |
| 11667 | NUM_BT_TX_LEVELS, in); |
| 11668 | mModemActivity = new ControllerActivityCounterImpl(mOnBatteryTimeBase, |
| 11669 | ModemActivityInfo.TX_POWER_LEVELS, in); |
| 11670 | mHasWifiReporting = in.readInt() != 0; |
| 11671 | mHasBluetoothReporting = in.readInt() != 0; |
| 11672 | mHasModemReporting = in.readInt() != 0; |
| 11673 | |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 11674 | mNumConnectivityChange = in.readInt(); |
| 11675 | mLoadedNumConnectivityChange = in.readInt(); |
| 11676 | mUnpluggedNumConnectivityChange = in.readInt(); |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 11677 | mAudioOnNesting = 0; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 11678 | mAudioOnTimer = new StopwatchTimer(mClocks, null, -7, null, mOnBatteryTimeBase); |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 11679 | mVideoOnNesting = 0; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 11680 | mVideoOnTimer = new StopwatchTimer(mClocks, null, -8, null, mOnBatteryTimeBase); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 11681 | mFlashlightOnNesting = 0; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 11682 | mFlashlightOnTimer = new StopwatchTimer(mClocks, null, -9, null, mOnBatteryTimeBase, in); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 11683 | mCameraOnNesting = 0; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 11684 | mCameraOnTimer = new StopwatchTimer(mClocks, null, -13, null, mOnBatteryTimeBase, in); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 11685 | mBluetoothScanNesting = 0; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 11686 | mBluetoothScanTimer = new StopwatchTimer(mClocks, null, -14, null, mOnBatteryTimeBase, in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 11687 | mDischargeUnplugLevel = in.readInt(); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 11688 | mDischargePlugLevel = in.readInt(); |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 11689 | mDischargeCurrentLevel = in.readInt(); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 11690 | mCurrentBatteryLevel = in.readInt(); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 11691 | mLowDischargeAmountSinceCharge = in.readInt(); |
| 11692 | mHighDischargeAmountSinceCharge = in.readInt(); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 11693 | mDischargeAmountScreenOn = in.readInt(); |
| 11694 | mDischargeAmountScreenOnSinceCharge = in.readInt(); |
| 11695 | mDischargeAmountScreenOff = in.readInt(); |
| 11696 | mDischargeAmountScreenOffSinceCharge = in.readInt(); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 11697 | mDischargeStepTracker.readFromParcel(in); |
| 11698 | mChargeStepTracker.readFromParcel(in); |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 11699 | mDischargeCounter = new LongSamplingCounter(mOnBatteryTimeBase, in); |
| 11700 | mDischargeScreenOffCounter = new LongSamplingCounter(mOnBatteryTimeBase, in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11701 | mLastWriteTime = in.readLong(); |
| 11702 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 11703 | mKernelWakelockStats.clear(); |
| 11704 | int NKW = in.readInt(); |
| 11705 | for (int ikw = 0; ikw < NKW; ikw++) { |
| 11706 | if (in.readInt() != 0) { |
| 11707 | String wakelockName = in.readString(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 11708 | SamplingTimer kwlt = new SamplingTimer(mClocks, mOnBatteryScreenOffTimeBase, in); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 11709 | mKernelWakelockStats.put(wakelockName, kwlt); |
| 11710 | } |
| 11711 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 11712 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 11713 | mWakeupReasonStats.clear(); |
| 11714 | int NWR = in.readInt(); |
| 11715 | for (int iwr = 0; iwr < NWR; iwr++) { |
| 11716 | if (in.readInt() != 0) { |
| 11717 | String reasonName = in.readString(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 11718 | SamplingTimer timer = new SamplingTimer(mClocks, mOnBatteryTimeBase, in); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 11719 | mWakeupReasonStats.put(reasonName, timer); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 11720 | } |
| 11721 | } |
| 11722 | |
James Carr | 3a22605 | 2016-07-01 14:49:52 -0700 | [diff] [blame] | 11723 | mKernelMemoryStats.clear(); |
| 11724 | int nmt = in.readInt(); |
| 11725 | for (int imt = 0; imt < nmt; imt++) { |
| 11726 | if (in.readInt() != 0) { |
| 11727 | Long bucket = in.readLong(); |
| 11728 | SamplingTimer kmt = new SamplingTimer(mClocks, mOnBatteryTimeBase, in); |
| 11729 | mKernelMemoryStats.put(bucket, kmt); |
| 11730 | } |
| 11731 | } |
| 11732 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11733 | mPartialTimers.clear(); |
| 11734 | mFullTimers.clear(); |
| 11735 | mWindowTimers.clear(); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 11736 | mWifiRunningTimers.clear(); |
| 11737 | mFullWifiLockTimers.clear(); |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 11738 | mWifiScanTimers.clear(); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 11739 | mWifiBatchedScanTimers.clear(); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 11740 | mWifiMulticastTimers.clear(); |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 11741 | mAudioTurnedOnTimers.clear(); |
| 11742 | mVideoTurnedOnTimers.clear(); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 11743 | mFlashlightTurnedOnTimers.clear(); |
| 11744 | mCameraTurnedOnTimers.clear(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11745 | |
| 11746 | int numUids = in.readInt(); |
| 11747 | mUidStats.clear(); |
| 11748 | for (int i = 0; i < numUids; i++) { |
| 11749 | int uid = in.readInt(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 11750 | Uid u = new Uid(this, uid); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 11751 | u.readFromParcelLocked(mOnBatteryTimeBase, mOnBatteryScreenOffTimeBase, in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11752 | mUidStats.append(uid, u); |
| 11753 | } |
| 11754 | } |
| 11755 | |
| 11756 | public void writeToParcel(Parcel out, int flags) { |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 11757 | writeToParcelLocked(out, true, flags); |
| 11758 | } |
| 11759 | |
| 11760 | public void writeToParcelWithoutUids(Parcel out, int flags) { |
| 11761 | writeToParcelLocked(out, false, flags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11762 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 11763 | |
| 11764 | @SuppressWarnings("unused") |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 11765 | void writeToParcelLocked(Parcel out, boolean inclUids, int flags) { |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 11766 | // Need to update with current kernel wake lock counts. |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 11767 | pullPendingStateUpdatesLocked(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 11768 | |
Dianne Hackborn | 7d9eefd | 2014-08-27 18:30:31 -0700 | [diff] [blame] | 11769 | // Pull the clock time. This may update the time and make a new history entry |
| 11770 | // if we had originally pulled a time before the RTC was set. |
| 11771 | long startClockTime = getStartClockTime(); |
| 11772 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 11773 | final long uSecUptime = mClocks.uptimeMillis() * 1000; |
| 11774 | final long uSecRealtime = mClocks.elapsedRealtime() * 1000; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 11775 | final long batteryRealtime = mOnBatteryTimeBase.getRealtime(uSecRealtime); |
| 11776 | final long batteryScreenOffRealtime = mOnBatteryScreenOffTimeBase.getRealtime(uSecRealtime); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 11777 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11778 | out.writeInt(MAGIC); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 11779 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 11780 | writeHistory(out, true, false); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 11781 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11782 | out.writeInt(mStartCount); |
Dianne Hackborn | 7d9eefd | 2014-08-27 18:30:31 -0700 | [diff] [blame] | 11783 | out.writeLong(startClockTime); |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 11784 | out.writeString(mStartPlatformVersion); |
| 11785 | out.writeString(mEndPlatformVersion); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11786 | out.writeLong(mUptime); |
| 11787 | out.writeLong(mUptimeStart); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11788 | out.writeLong(mRealtime); |
| 11789 | out.writeLong(mRealtimeStart); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11790 | out.writeInt(mOnBattery ? 1 : 0); |
Adam Lesinski | f9b20a9 | 2016-06-17 17:30:01 -0700 | [diff] [blame] | 11791 | out.writeInt(mEstimatedBatteryCapacity); |
Jocelyn Dang | c627d10 | 2017-04-14 13:15:14 -0700 | [diff] [blame^] | 11792 | out.writeInt(mMinLearnedBatteryCapacity); |
| 11793 | out.writeInt(mMaxLearnedBatteryCapacity); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 11794 | mOnBatteryTimeBase.writeToParcel(out, uSecUptime, uSecRealtime); |
| 11795 | mOnBatteryScreenOffTimeBase.writeToParcel(out, uSecUptime, uSecRealtime); |
| 11796 | |
| 11797 | mScreenOnTimer.writeToParcel(out, uSecRealtime); |
| 11798 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
| 11799 | mScreenBrightnessTimer[i].writeToParcel(out, uSecRealtime); |
| 11800 | } |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 11801 | mInteractiveTimer.writeToParcel(out, uSecRealtime); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 11802 | mPowerSaveModeEnabledTimer.writeToParcel(out, uSecRealtime); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 11803 | out.writeLong(mLongestLightIdleTime); |
| 11804 | out.writeLong(mLongestFullIdleTime); |
| 11805 | mDeviceIdleModeLightTimer.writeToParcel(out, uSecRealtime); |
| 11806 | mDeviceIdleModeFullTimer.writeToParcel(out, uSecRealtime); |
| 11807 | mDeviceLightIdlingTimer.writeToParcel(out, uSecRealtime); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 11808 | mDeviceIdlingTimer.writeToParcel(out, uSecRealtime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 11809 | mPhoneOnTimer.writeToParcel(out, uSecRealtime); |
| 11810 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
| 11811 | mPhoneSignalStrengthsTimer[i].writeToParcel(out, uSecRealtime); |
| 11812 | } |
| 11813 | mPhoneSignalScanningTimer.writeToParcel(out, uSecRealtime); |
| 11814 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
| 11815 | mPhoneDataConnectionsTimer[i].writeToParcel(out, uSecRealtime); |
| 11816 | } |
| 11817 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
| 11818 | mNetworkByteActivityCounters[i].writeToParcel(out); |
| 11819 | mNetworkPacketActivityCounters[i].writeToParcel(out); |
| 11820 | } |
| 11821 | mMobileRadioActiveTimer.writeToParcel(out, uSecRealtime); |
| 11822 | mMobileRadioActivePerAppTimer.writeToParcel(out, uSecRealtime); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 11823 | mMobileRadioActiveAdjustedTime.writeToParcel(out); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 11824 | mMobileRadioActiveUnknownTime.writeToParcel(out); |
| 11825 | mMobileRadioActiveUnknownCount.writeToParcel(out); |
| 11826 | mWifiOnTimer.writeToParcel(out, uSecRealtime); |
| 11827 | mGlobalWifiRunningTimer.writeToParcel(out, uSecRealtime); |
| 11828 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
| 11829 | mWifiStateTimer[i].writeToParcel(out, uSecRealtime); |
| 11830 | } |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 11831 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
| 11832 | mWifiSupplStateTimer[i].writeToParcel(out, uSecRealtime); |
| 11833 | } |
| 11834 | for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 11835 | mWifiSignalStrengthsTimer[i].writeToParcel(out, uSecRealtime); |
| 11836 | } |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 11837 | mWifiActivity.writeToParcel(out, 0); |
| 11838 | mBluetoothActivity.writeToParcel(out, 0); |
| 11839 | mModemActivity.writeToParcel(out, 0); |
| 11840 | out.writeInt(mHasWifiReporting ? 1 : 0); |
| 11841 | out.writeInt(mHasBluetoothReporting ? 1 : 0); |
| 11842 | out.writeInt(mHasModemReporting ? 1 : 0); |
| 11843 | |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 11844 | out.writeInt(mNumConnectivityChange); |
| 11845 | out.writeInt(mLoadedNumConnectivityChange); |
| 11846 | out.writeInt(mUnpluggedNumConnectivityChange); |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 11847 | mFlashlightOnTimer.writeToParcel(out, uSecRealtime); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 11848 | mCameraOnTimer.writeToParcel(out, uSecRealtime); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 11849 | mBluetoothScanTimer.writeToParcel(out, uSecRealtime); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 11850 | out.writeInt(mDischargeUnplugLevel); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 11851 | out.writeInt(mDischargePlugLevel); |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 11852 | out.writeInt(mDischargeCurrentLevel); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 11853 | out.writeInt(mCurrentBatteryLevel); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 11854 | out.writeInt(mLowDischargeAmountSinceCharge); |
| 11855 | out.writeInt(mHighDischargeAmountSinceCharge); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 11856 | out.writeInt(mDischargeAmountScreenOn); |
| 11857 | out.writeInt(mDischargeAmountScreenOnSinceCharge); |
| 11858 | out.writeInt(mDischargeAmountScreenOff); |
| 11859 | out.writeInt(mDischargeAmountScreenOffSinceCharge); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 11860 | mDischargeStepTracker.writeToParcel(out); |
| 11861 | mChargeStepTracker.writeToParcel(out); |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 11862 | mDischargeCounter.writeToParcel(out); |
| 11863 | mDischargeScreenOffCounter.writeToParcel(out); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11864 | out.writeLong(mLastWriteTime); |
| 11865 | |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 11866 | if (inclUids) { |
| 11867 | out.writeInt(mKernelWakelockStats.size()); |
| 11868 | for (Map.Entry<String, SamplingTimer> ent : mKernelWakelockStats.entrySet()) { |
| 11869 | SamplingTimer kwlt = ent.getValue(); |
| 11870 | if (kwlt != null) { |
| 11871 | out.writeInt(1); |
| 11872 | out.writeString(ent.getKey()); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 11873 | kwlt.writeToParcel(out, uSecRealtime); |
| 11874 | } else { |
| 11875 | out.writeInt(0); |
| 11876 | } |
| 11877 | } |
| 11878 | out.writeInt(mWakeupReasonStats.size()); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 11879 | for (Map.Entry<String, SamplingTimer> ent : mWakeupReasonStats.entrySet()) { |
| 11880 | SamplingTimer timer = ent.getValue(); |
| 11881 | if (timer != null) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 11882 | out.writeInt(1); |
| 11883 | out.writeString(ent.getKey()); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 11884 | timer.writeToParcel(out, uSecRealtime); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 11885 | } else { |
| 11886 | out.writeInt(0); |
| 11887 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 11888 | } |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 11889 | } else { |
| 11890 | out.writeInt(0); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 11891 | } |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 11892 | |
James Carr | 3a22605 | 2016-07-01 14:49:52 -0700 | [diff] [blame] | 11893 | out.writeInt(mKernelMemoryStats.size()); |
| 11894 | for (int i = 0; i < mKernelMemoryStats.size(); i++) { |
| 11895 | SamplingTimer kmt = mKernelMemoryStats.valueAt(i); |
| 11896 | if (kmt != null) { |
| 11897 | out.writeInt(1); |
| 11898 | out.writeLong(mKernelMemoryStats.keyAt(i)); |
| 11899 | kmt.writeToParcel(out, uSecRealtime); |
| 11900 | } else { |
| 11901 | out.writeInt(0); |
| 11902 | } |
| 11903 | } |
| 11904 | |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 11905 | if (inclUids) { |
| 11906 | int size = mUidStats.size(); |
| 11907 | out.writeInt(size); |
| 11908 | for (int i = 0; i < size; i++) { |
| 11909 | out.writeInt(mUidStats.keyAt(i)); |
| 11910 | Uid uid = mUidStats.valueAt(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11911 | |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 11912 | uid.writeToParcelLocked(out, uSecUptime, uSecRealtime); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 11913 | } |
| 11914 | } else { |
| 11915 | out.writeInt(0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11916 | } |
| 11917 | } |
| 11918 | |
| 11919 | public static final Parcelable.Creator<BatteryStatsImpl> CREATOR = |
| 11920 | new Parcelable.Creator<BatteryStatsImpl>() { |
| 11921 | public BatteryStatsImpl createFromParcel(Parcel in) { |
| 11922 | return new BatteryStatsImpl(in); |
| 11923 | } |
| 11924 | |
| 11925 | public BatteryStatsImpl[] newArray(int size) { |
| 11926 | return new BatteryStatsImpl[size]; |
| 11927 | } |
| 11928 | }; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 11929 | |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 11930 | public void prepareForDumpLocked() { |
| 11931 | // Need to retrieve current kernel wake lock stats before printing. |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 11932 | pullPendingStateUpdatesLocked(); |
Dianne Hackborn | 7d9eefd | 2014-08-27 18:30:31 -0700 | [diff] [blame] | 11933 | |
| 11934 | // Pull the clock time. This may update the time and make a new history entry |
| 11935 | // if we had originally pulled a time before the RTC was set. |
| 11936 | getStartClockTime(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 11937 | } |
| 11938 | |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 11939 | 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] | 11940 | if (DEBUG) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 11941 | pw.println("mOnBatteryTimeBase:"); |
| 11942 | mOnBatteryTimeBase.dump(pw, " "); |
| 11943 | pw.println("mOnBatteryScreenOffTimeBase:"); |
| 11944 | mOnBatteryScreenOffTimeBase.dump(pw, " "); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11945 | Printer pr = new PrintWriterPrinter(pw); |
| 11946 | pr.println("*** Screen timer:"); |
| 11947 | mScreenOnTimer.logState(pr, " "); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 11948 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11949 | pr.println("*** Screen brightness #" + i + ":"); |
| 11950 | mScreenBrightnessTimer[i].logState(pr, " "); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 11951 | } |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 11952 | pr.println("*** Interactive timer:"); |
| 11953 | mInteractiveTimer.logState(pr, " "); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 11954 | pr.println("*** Power save mode timer:"); |
| 11955 | mPowerSaveModeEnabledTimer.logState(pr, " "); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 11956 | pr.println("*** Device idle mode light timer:"); |
| 11957 | mDeviceIdleModeLightTimer.logState(pr, " "); |
| 11958 | pr.println("*** Device idle mode full timer:"); |
| 11959 | mDeviceIdleModeFullTimer.logState(pr, " "); |
| 11960 | pr.println("*** Device light idling timer:"); |
| 11961 | mDeviceLightIdlingTimer.logState(pr, " "); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 11962 | pr.println("*** Device idling timer:"); |
| 11963 | mDeviceIdlingTimer.logState(pr, " "); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11964 | pr.println("*** Phone timer:"); |
| 11965 | mPhoneOnTimer.logState(pr, " "); |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 11966 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 11967 | pr.println("*** Phone signal strength #" + i + ":"); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11968 | mPhoneSignalStrengthsTimer[i].logState(pr, " "); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 11969 | } |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 11970 | pr.println("*** Signal scanning :"); |
| 11971 | mPhoneSignalScanningTimer.logState(pr, " "); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 11972 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11973 | pr.println("*** Data connection type #" + i + ":"); |
| 11974 | mPhoneDataConnectionsTimer[i].logState(pr, " "); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 11975 | } |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 11976 | pr.println("*** mMobileRadioPowerState=" + mMobileRadioPowerState); |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 11977 | pr.println("*** Mobile network active timer:"); |
| 11978 | mMobileRadioActiveTimer.logState(pr, " "); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 11979 | pr.println("*** Mobile network active adjusted timer:"); |
| 11980 | mMobileRadioActiveAdjustedTime.logState(pr, " "); |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 11981 | pr.println("*** mWifiRadioPowerState=" + mWifiRadioPowerState); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11982 | pr.println("*** Wifi timer:"); |
| 11983 | mWifiOnTimer.logState(pr, " "); |
| 11984 | pr.println("*** WifiRunning timer:"); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 11985 | mGlobalWifiRunningTimer.logState(pr, " "); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 11986 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
| 11987 | pr.println("*** Wifi state #" + i + ":"); |
| 11988 | mWifiStateTimer[i].logState(pr, " "); |
| 11989 | } |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 11990 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
| 11991 | pr.println("*** Wifi suppl state #" + i + ":"); |
| 11992 | mWifiSupplStateTimer[i].logState(pr, " "); |
| 11993 | } |
| 11994 | for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 11995 | pr.println("*** Wifi signal strength #" + i + ":"); |
| 11996 | mWifiSignalStrengthsTimer[i].logState(pr, " "); |
| 11997 | } |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 11998 | pr.println("*** Flashlight timer:"); |
| 11999 | mFlashlightOnTimer.logState(pr, " "); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 12000 | pr.println("*** Camera timer:"); |
| 12001 | mCameraOnTimer.logState(pr, " "); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12002 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 12003 | super.dumpLocked(context, pw, flags, reqUid, histStart); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12004 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12005 | } |