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 | |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 19 | import android.annotation.NonNull; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 20 | import android.annotation.Nullable; |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 21 | import android.app.ActivityManager; |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 22 | import android.bluetooth.BluetoothActivityEnergyInfo; |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 23 | import android.bluetooth.UidTraffic; |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 24 | import android.content.Context; |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 25 | import android.content.Intent; |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 26 | import android.net.ConnectivityManager; |
| 27 | import android.net.NetworkStats; |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 28 | import android.net.wifi.WifiActivityEnergyInfo; |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 29 | import android.net.wifi.WifiManager; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 30 | import android.os.BatteryManager; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 31 | import android.os.BatteryStats; |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 32 | import android.os.Build; |
Dianne Hackborn | 8bdf593 | 2010-10-15 12:54:40 -0700 | [diff] [blame] | 33 | import android.os.FileUtils; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 34 | import android.os.Handler; |
Adam Lesinski | e1f480d | 2017-02-15 18:51:23 -0800 | [diff] [blame] | 35 | import android.os.IBatteryPropertiesRegistrar; |
Jeff Brown | 6f357d3 | 2014-01-15 20:40:55 -0800 | [diff] [blame] | 36 | import android.os.Looper; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 37 | import android.os.Message; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 38 | import android.os.Parcel; |
| 39 | import android.os.ParcelFormatException; |
| 40 | import android.os.Parcelable; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 41 | import android.os.Process; |
Adam Lesinski | e1f480d | 2017-02-15 18:51:23 -0800 | [diff] [blame] | 42 | import android.os.RemoteException; |
| 43 | import android.os.ServiceManager; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 44 | import android.os.SystemClock; |
Jeff Sharkey | 418d12d | 2011-12-13 15:38:03 -0800 | [diff] [blame] | 45 | import android.os.SystemProperties; |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 46 | import android.os.WorkSource; |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 47 | import android.telephony.DataConnectionRealTimeInfo; |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 48 | import android.telephony.ModemActivityInfo; |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 49 | import android.telephony.ServiceState; |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 50 | import android.telephony.SignalStrength; |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 51 | import android.telephony.TelephonyManager; |
Jeff Sharkey | 9da2f1e | 2014-08-14 12:55:00 -0700 | [diff] [blame] | 52 | import android.text.TextUtils; |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 53 | import android.util.ArrayMap; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 54 | import android.util.Log; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 55 | import android.util.LogWriter; |
James Carr | 3a22605 | 2016-07-01 14:49:52 -0700 | [diff] [blame] | 56 | import android.util.LongSparseArray; |
| 57 | import android.util.LongSparseLongArray; |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 58 | import android.util.MutableInt; |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 59 | import android.util.Pools; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 60 | import android.util.PrintWriterPrinter; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 61 | import android.util.Printer; |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 62 | import android.util.Slog; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 63 | import android.util.SparseArray; |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 64 | import android.util.SparseIntArray; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 65 | import android.util.SparseLongArray; |
Dianne Hackborn | ae38445 | 2011-06-28 12:33:48 -0700 | [diff] [blame] | 66 | import android.util.TimeUtils; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 67 | import android.util.Xml; |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 68 | import android.view.Display; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 69 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 70 | import com.android.internal.annotations.GuardedBy; |
Adam Lesinski | 98f0d46 | 2016-04-19 16:46:20 -0700 | [diff] [blame] | 71 | import com.android.internal.annotations.VisibleForTesting; |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 72 | import com.android.internal.net.NetworkStatsFactory; |
Dianne Hackborn | d0c5b9a | 2014-02-21 16:19:05 -0800 | [diff] [blame] | 73 | import com.android.internal.util.ArrayUtils; |
Dianne Hackborn | 8c84109 | 2013-06-24 13:46:13 -0700 | [diff] [blame] | 74 | import com.android.internal.util.FastPrintWriter; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 75 | import com.android.internal.util.FastXmlSerializer; |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 76 | import com.android.internal.util.JournaledFile; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 77 | import com.android.internal.util.XmlUtils; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 78 | import com.android.server.NetworkManagementSocketTagger; |
| 79 | import libcore.util.EmptyArray; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 80 | import org.xmlpull.v1.XmlPullParser; |
| 81 | import org.xmlpull.v1.XmlPullParserException; |
| 82 | import org.xmlpull.v1.XmlSerializer; |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 83 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 84 | import java.io.ByteArrayOutputStream; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 85 | import java.io.File; |
| 86 | import java.io.FileInputStream; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 87 | import java.io.FileNotFoundException; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 88 | import java.io.FileOutputStream; |
| 89 | import java.io.IOException; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 90 | import java.io.PrintWriter; |
Wojciech Staszkiewicz | 9e9e2e7 | 2015-05-08 14:58:46 +0100 | [diff] [blame] | 91 | import java.nio.charset.StandardCharsets; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 92 | import java.util.ArrayList; |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 93 | import java.util.Arrays; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 94 | import java.util.Calendar; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 95 | import java.util.HashMap; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 96 | import java.util.Iterator; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 97 | import java.util.Map; |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 98 | import java.util.concurrent.atomic.AtomicInteger; |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 99 | import java.util.concurrent.locks.ReentrantLock; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 100 | |
| 101 | /** |
| 102 | * All information we are collecting about things that can happen that impact |
| 103 | * battery life. All times are represented in microseconds except where indicated |
| 104 | * otherwise. |
| 105 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 106 | public class BatteryStatsImpl extends BatteryStats { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 107 | private static final String TAG = "BatteryStatsImpl"; |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 108 | private static final boolean DEBUG = false; |
Adam Lesinski | a7c90c8 | 2015-06-18 14:52:24 -0700 | [diff] [blame] | 109 | public static final boolean DEBUG_ENERGY = false; |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 110 | private static final boolean DEBUG_ENERGY_CPU = DEBUG_ENERGY; |
James Carr | 3a22605 | 2016-07-01 14:49:52 -0700 | [diff] [blame] | 111 | private static final boolean DEBUG_MEMORY = false; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 112 | private static final boolean DEBUG_HISTORY = false; |
Dianne Hackborn | e8c88e6 | 2011-08-17 19:09:09 -0700 | [diff] [blame] | 113 | private static final boolean USE_OLD_HISTORY = false; // for debugging. |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 114 | |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 115 | // TODO: remove "tcp" from network methods, since we measure total stats. |
| 116 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 117 | // 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] | 118 | private static final int MAGIC = 0xBA757475; // 'BATSTATS' |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 119 | |
| 120 | // Current on-disk Parcel version |
Bookatz | 5b5ec32 | 2017-05-26 09:40:38 -0700 | [diff] [blame] | 121 | private static final int VERSION = 159 + (USE_OLD_HISTORY ? 1000 : 0); |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 122 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 123 | // Maximum number of items we will record in the history. |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 124 | private static final int MAX_HISTORY_ITEMS = 2000; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 125 | |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 126 | // No, really, THIS is the maximum number of items we will record in the history. |
| 127 | private static final int MAX_MAX_HISTORY_ITEMS = 3000; |
| 128 | |
Dianne Hackborn | 9e0f5d9 | 2010-02-22 15:05:42 -0800 | [diff] [blame] | 129 | // The maximum number of names wakelocks we will keep track of |
| 130 | // per uid; once the limit is reached, we batch the remaining wakelocks |
| 131 | // in to one common name. |
Dianne Hackborn | acc4a12 | 2014-08-18 16:33:44 -0700 | [diff] [blame] | 132 | private static final int MAX_WAKELOCKS_PER_UID = 100; |
Dianne Hackborn | c24ab86 | 2011-10-18 15:55:03 -0700 | [diff] [blame] | 133 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 134 | // Number of transmit power states the Wifi controller can be in. |
| 135 | private static final int NUM_WIFI_TX_LEVELS = 1; |
| 136 | |
| 137 | // Number of transmit power states the Bluetooth controller can be in. |
| 138 | private static final int NUM_BT_TX_LEVELS = 1; |
| 139 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 140 | protected Clocks mClocks; |
| 141 | |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 142 | private final JournaledFile mFile; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 143 | public final AtomicFile mCheckinFile; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 144 | public final AtomicFile mDailyFile; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 145 | |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 146 | static final int MSG_UPDATE_WAKELOCKS = 1; |
| 147 | static final int MSG_REPORT_POWER_CHANGE = 2; |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 148 | static final int MSG_REPORT_CHARGING = 3; |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 149 | static final long DELAY_UPDATE_WAKELOCKS = 5*1000; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 150 | |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 151 | private final KernelWakelockReader mKernelWakelockReader = new KernelWakelockReader(); |
| 152 | private final KernelWakelockStats mTmpWakelockStats = new KernelWakelockStats(); |
| 153 | |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 154 | private final KernelUidCpuTimeReader mKernelUidCpuTimeReader = new KernelUidCpuTimeReader(); |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 155 | private KernelCpuSpeedReader[] mKernelCpuSpeedReaders; |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 156 | private final KernelUidCpuFreqTimeReader mKernelUidCpuFreqTimeReader = |
| 157 | new KernelUidCpuFreqTimeReader(); |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 158 | |
James Carr | 3a22605 | 2016-07-01 14:49:52 -0700 | [diff] [blame] | 159 | private final KernelMemoryBandwidthStats mKernelMemoryBandwidthStats |
| 160 | = new KernelMemoryBandwidthStats(); |
| 161 | private final LongSparseArray<SamplingTimer> mKernelMemoryStats = new LongSparseArray<>(); |
| 162 | public LongSparseArray<SamplingTimer> getKernelMemoryStats() { |
| 163 | return mKernelMemoryStats; |
| 164 | } |
| 165 | |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 166 | public interface BatteryCallback { |
| 167 | public void batteryNeedsCpuUpdate(); |
| 168 | public void batteryPowerChanged(boolean onBattery); |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 169 | public void batterySendBroadcast(Intent intent); |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 170 | } |
| 171 | |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 172 | public interface PlatformIdleStateCallback { |
| 173 | public String getPlatformLowPowerStats(); |
| 174 | } |
| 175 | |
| 176 | private final PlatformIdleStateCallback mPlatformIdleStateCallback; |
| 177 | |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 178 | final class MyHandler extends Handler { |
Jeff Brown | 6f357d3 | 2014-01-15 20:40:55 -0800 | [diff] [blame] | 179 | public MyHandler(Looper looper) { |
| 180 | super(looper, null, true); |
| 181 | } |
| 182 | |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 183 | @Override |
| 184 | public void handleMessage(Message msg) { |
| 185 | BatteryCallback cb = mCallback; |
| 186 | switch (msg.what) { |
| 187 | case MSG_UPDATE_WAKELOCKS: |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 188 | synchronized (BatteryStatsImpl.this) { |
Sudheer Shanka | 671985f | 2017-05-19 11:33:42 -0700 | [diff] [blame] | 189 | updateCpuTimeLocked(false /* updateCpuFreqData */); |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 190 | } |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 191 | if (cb != null) { |
| 192 | cb.batteryNeedsCpuUpdate(); |
| 193 | } |
| 194 | break; |
| 195 | case MSG_REPORT_POWER_CHANGE: |
| 196 | if (cb != null) { |
| 197 | cb.batteryPowerChanged(msg.arg1 != 0); |
| 198 | } |
| 199 | break; |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 200 | case MSG_REPORT_CHARGING: |
| 201 | if (cb != null) { |
| 202 | final String action; |
| 203 | synchronized (BatteryStatsImpl.this) { |
| 204 | action = mCharging ? BatteryManager.ACTION_CHARGING |
| 205 | : BatteryManager.ACTION_DISCHARGING; |
| 206 | } |
| 207 | Intent intent = new Intent(action); |
| 208 | intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT); |
| 209 | cb.batterySendBroadcast(intent); |
| 210 | } |
| 211 | break; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 212 | } |
| 213 | } |
| 214 | } |
| 215 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 216 | public interface Clocks { |
| 217 | public long elapsedRealtime(); |
| 218 | public long uptimeMillis(); |
| 219 | } |
| 220 | |
| 221 | public static class SystemClocks implements Clocks { |
| 222 | public long elapsedRealtime() { |
| 223 | return SystemClock.elapsedRealtime(); |
| 224 | } |
| 225 | |
| 226 | public long uptimeMillis() { |
| 227 | return SystemClock.uptimeMillis(); |
| 228 | } |
| 229 | } |
| 230 | |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 231 | public interface ExternalStatsSync { |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 232 | int UPDATE_CPU = 0x01; |
| 233 | int UPDATE_WIFI = 0x02; |
| 234 | int UPDATE_RADIO = 0x04; |
| 235 | int UPDATE_BT = 0x08; |
| 236 | int UPDATE_ALL = UPDATE_CPU | UPDATE_WIFI | UPDATE_RADIO | UPDATE_BT; |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 237 | |
| 238 | void scheduleSync(String reason, int flags); |
Adam Lesinski | 61db88f | 2015-07-01 15:05:07 -0700 | [diff] [blame] | 239 | void scheduleCpuSyncDueToRemovedUid(int uid); |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 240 | } |
| 241 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 242 | public final MyHandler mHandler; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 243 | private final ExternalStatsSync mExternalSync; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 244 | |
| 245 | private BatteryCallback mCallback; |
| 246 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 247 | /** |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 248 | * Mapping isolated uids to the actual owning app uid. |
| 249 | */ |
| 250 | final SparseIntArray mIsolatedUids = new SparseIntArray(); |
| 251 | |
| 252 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 253 | * The statistics we have collected organized by uids. |
| 254 | */ |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 255 | final SparseArray<BatteryStatsImpl.Uid> mUidStats = new SparseArray<>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 256 | |
| 257 | // A set of pools of currently active timers. When a timer is queried, we will divide the |
| 258 | // elapsed time by the number of active timers to arrive at that timer's share of the time. |
| 259 | // In order to do this, we must refresh each timer whenever the number of active timers |
| 260 | // changes. |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 261 | final ArrayList<StopwatchTimer> mPartialTimers = new ArrayList<>(); |
| 262 | final ArrayList<StopwatchTimer> mFullTimers = new ArrayList<>(); |
| 263 | final ArrayList<StopwatchTimer> mWindowTimers = new ArrayList<>(); |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 264 | final ArrayList<StopwatchTimer> mDrawTimers = new ArrayList<>(); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 265 | final SparseArray<ArrayList<StopwatchTimer>> mSensorTimers = new SparseArray<>(); |
| 266 | final ArrayList<StopwatchTimer> mWifiRunningTimers = new ArrayList<>(); |
| 267 | final ArrayList<StopwatchTimer> mFullWifiLockTimers = new ArrayList<>(); |
| 268 | final ArrayList<StopwatchTimer> mWifiMulticastTimers = new ArrayList<>(); |
| 269 | final ArrayList<StopwatchTimer> mWifiScanTimers = new ArrayList<>(); |
| 270 | final SparseArray<ArrayList<StopwatchTimer>> mWifiBatchedScanTimers = new SparseArray<>(); |
| 271 | final ArrayList<StopwatchTimer> mAudioTurnedOnTimers = new ArrayList<>(); |
| 272 | final ArrayList<StopwatchTimer> mVideoTurnedOnTimers = new ArrayList<>(); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 273 | final ArrayList<StopwatchTimer> mFlashlightTurnedOnTimers = new ArrayList<>(); |
| 274 | final ArrayList<StopwatchTimer> mCameraTurnedOnTimers = new ArrayList<>(); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 275 | final ArrayList<StopwatchTimer> mBluetoothScanOnTimers = new ArrayList<>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 276 | |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 277 | // Last partial timers we use for distributing CPU usage. |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 278 | final ArrayList<StopwatchTimer> mLastPartialTimers = new ArrayList<>(); |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 279 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 280 | // These are the objects that will want to do something when the device |
| 281 | // is unplugged from power. |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 282 | protected final TimeBase mOnBatteryTimeBase = new TimeBase(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 283 | |
| 284 | // These are the objects that will want to do something when the device |
| 285 | // is unplugged from power *and* the screen is off. |
| 286 | final TimeBase mOnBatteryScreenOffTimeBase = new TimeBase(); |
| 287 | |
| 288 | // Set to true when we want to distribute CPU across wakelocks for the next |
| 289 | // CPU update, even if we aren't currently running wake locks. |
| 290 | boolean mDistributeWakelockCpu; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 291 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 292 | boolean mShuttingDown; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 293 | |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 294 | final HistoryEventTracker mActiveEvents = new HistoryEventTracker(); |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 295 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 296 | long mHistoryBaseTime; |
| 297 | boolean mHaveBatteryLevel = false; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 298 | boolean mRecordingHistory = false; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 299 | int mNumHistoryItems; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 300 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 301 | static final int MAX_HISTORY_BUFFER = 256*1024; // 256KB |
| 302 | static final int MAX_MAX_HISTORY_BUFFER = 320*1024; // 320KB |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 303 | final Parcel mHistoryBuffer = Parcel.obtain(); |
| 304 | final HistoryItem mHistoryLastWritten = new HistoryItem(); |
| 305 | final HistoryItem mHistoryLastLastWritten = new HistoryItem(); |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 306 | final HistoryItem mHistoryReadTmp = new HistoryItem(); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 307 | final HistoryItem mHistoryAddTmp = new HistoryItem(); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 308 | final HashMap<HistoryTag, Integer> mHistoryTagPool = new HashMap<>(); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 309 | String[] mReadHistoryStrings; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 310 | int[] mReadHistoryUids; |
| 311 | int mReadHistoryChars; |
| 312 | int mNextHistoryTagIdx = 0; |
| 313 | int mNumHistoryTagChars = 0; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 314 | int mHistoryBufferLastPos = -1; |
| 315 | boolean mHistoryOverflow = false; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 316 | int mActiveHistoryStates = 0xffffffff; |
| 317 | int mActiveHistoryStates2 = 0xffffffff; |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 318 | long mLastHistoryElapsedRealtime = 0; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 319 | long mTrackRunningHistoryElapsedRealtime = 0; |
| 320 | long mTrackRunningHistoryUptime = 0; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 321 | |
| 322 | final HistoryItem mHistoryCur = new HistoryItem(); |
| 323 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 324 | HistoryItem mHistory; |
| 325 | HistoryItem mHistoryEnd; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 326 | HistoryItem mHistoryLastEnd; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 327 | HistoryItem mHistoryCache; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 328 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 329 | // Used by computeHistoryStepDetails |
| 330 | HistoryStepDetails mLastHistoryStepDetails = null; |
| 331 | byte mLastHistoryStepLevel = 0; |
| 332 | final HistoryStepDetails mCurHistoryStepDetails = new HistoryStepDetails(); |
| 333 | final HistoryStepDetails mReadHistoryStepDetails = new HistoryStepDetails(); |
| 334 | final HistoryStepDetails mTmpHistoryStepDetails = new HistoryStepDetails(); |
Adam Lesinski | 7b83b0c | 2015-06-05 12:59:36 -0700 | [diff] [blame] | 335 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 336 | /** |
Adam Lesinski | 7b83b0c | 2015-06-05 12:59:36 -0700 | [diff] [blame] | 337 | * Total time (in milliseconds) spent executing in user code. |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 338 | */ |
| 339 | long mLastStepCpuUserTime; |
| 340 | long mCurStepCpuUserTime; |
| 341 | /** |
Adam Lesinski | 7b83b0c | 2015-06-05 12:59:36 -0700 | [diff] [blame] | 342 | * Total time (in milliseconds) spent executing in kernel code. |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 343 | */ |
| 344 | long mLastStepCpuSystemTime; |
| 345 | long mCurStepCpuSystemTime; |
| 346 | /** |
Adam Lesinski | 7b83b0c | 2015-06-05 12:59:36 -0700 | [diff] [blame] | 347 | * Times from /proc/stat (but measured in milliseconds). |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 348 | */ |
| 349 | long mLastStepStatUserTime; |
| 350 | long mLastStepStatSystemTime; |
| 351 | long mLastStepStatIOWaitTime; |
| 352 | long mLastStepStatIrqTime; |
| 353 | long mLastStepStatSoftIrqTime; |
| 354 | long mLastStepStatIdleTime; |
| 355 | long mCurStepStatUserTime; |
| 356 | long mCurStepStatSystemTime; |
| 357 | long mCurStepStatIOWaitTime; |
| 358 | long mCurStepStatIrqTime; |
| 359 | long mCurStepStatSoftIrqTime; |
| 360 | long mCurStepStatIdleTime; |
| 361 | |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 362 | private HistoryItem mHistoryIterator; |
| 363 | private boolean mReadOverflow; |
| 364 | private boolean mIteratingHistory; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 365 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 366 | int mStartCount; |
| 367 | |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 368 | long mStartClockTime; |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 369 | String mStartPlatformVersion; |
| 370 | String mEndPlatformVersion; |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 371 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 372 | long mUptime; |
| 373 | long mUptimeStart; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 374 | long mRealtime; |
| 375 | long mRealtimeStart; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 376 | |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 377 | int mWakeLockNesting; |
| 378 | boolean mWakeLockImportant; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 379 | public boolean mRecordAllHistory; |
Dianne Hackborn | 9a75543 | 2014-05-15 17:05:22 -0700 | [diff] [blame] | 380 | boolean mNoAutoReset; |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 381 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 382 | int mScreenState = Display.STATE_UNKNOWN; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 383 | StopwatchTimer mScreenOnTimer; |
Amith Yamasani | 3718aaa | 2009-06-09 06:32:35 -0700 | [diff] [blame] | 384 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 385 | int mScreenBrightnessBin = -1; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 386 | final StopwatchTimer[] mScreenBrightnessTimer = new StopwatchTimer[NUM_SCREEN_BRIGHTNESS_BINS]; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 387 | |
Amith Yamasani | 674c9bb | 2017-02-01 09:45:17 -0800 | [diff] [blame] | 388 | boolean mPretendScreenOff; |
| 389 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 390 | boolean mInteractive; |
| 391 | StopwatchTimer mInteractiveTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 392 | |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 393 | boolean mPowerSaveModeEnabled; |
| 394 | StopwatchTimer mPowerSaveModeEnabledTimer; |
| 395 | |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 396 | boolean mDeviceIdling; |
| 397 | StopwatchTimer mDeviceIdlingTimer; |
| 398 | |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 399 | boolean mDeviceLightIdling; |
| 400 | StopwatchTimer mDeviceLightIdlingTimer; |
| 401 | |
| 402 | int mDeviceIdleMode; |
| 403 | long mLastIdleTimeStart; |
| 404 | long mLongestLightIdleTime; |
| 405 | long mLongestFullIdleTime; |
| 406 | StopwatchTimer mDeviceIdleModeLightTimer; |
| 407 | StopwatchTimer mDeviceIdleModeFullTimer; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 408 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 409 | boolean mPhoneOn; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 410 | StopwatchTimer mPhoneOnTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 411 | |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 412 | int mAudioOnNesting; |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 413 | StopwatchTimer mAudioOnTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 414 | |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 415 | int mVideoOnNesting; |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 416 | StopwatchTimer mVideoOnTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 417 | |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 418 | int mFlashlightOnNesting; |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 419 | StopwatchTimer mFlashlightOnTimer; |
| 420 | |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 421 | int mCameraOnNesting; |
| 422 | StopwatchTimer mCameraOnTimer; |
| 423 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 424 | int mPhoneSignalStrengthBin = -1; |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 425 | int mPhoneSignalStrengthBinRaw = -1; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 426 | final StopwatchTimer[] mPhoneSignalStrengthsTimer = |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 427 | new StopwatchTimer[SignalStrength.NUM_SIGNAL_STRENGTH_BINS]; |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 428 | |
| 429 | StopwatchTimer mPhoneSignalScanningTimer; |
| 430 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 431 | int mPhoneDataConnectionType = -1; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 432 | final StopwatchTimer[] mPhoneDataConnectionsTimer = |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 433 | new StopwatchTimer[NUM_DATA_CONNECTION_TYPES]; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 434 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 435 | final LongSamplingCounter[] mNetworkByteActivityCounters = |
| 436 | new LongSamplingCounter[NUM_NETWORK_ACTIVITY_TYPES]; |
| 437 | final LongSamplingCounter[] mNetworkPacketActivityCounters = |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 438 | new LongSamplingCounter[NUM_NETWORK_ACTIVITY_TYPES]; |
| 439 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 440 | /** |
| 441 | * The WiFi controller activity (time in tx, rx, idle, and power consumed) for the device. |
| 442 | */ |
| 443 | ControllerActivityCounterImpl mWifiActivity; |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 444 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 445 | /** |
| 446 | * The Bluetooth controller activity (time in tx, rx, idle, and power consumed) for the device. |
| 447 | */ |
| 448 | ControllerActivityCounterImpl mBluetoothActivity; |
| 449 | |
| 450 | /** |
| 451 | * The Modem controller activity (time in tx, rx, idle, and power consumed) for the device. |
| 452 | */ |
| 453 | ControllerActivityCounterImpl mModemActivity; |
| 454 | |
| 455 | /** |
| 456 | * Whether the device supports WiFi controller energy reporting. This is set to true on |
| 457 | * the first WiFi energy report. See {@link #mWifiActivity}. |
| 458 | */ |
| 459 | boolean mHasWifiReporting = false; |
| 460 | |
| 461 | /** |
| 462 | * Whether the device supports Bluetooth controller energy reporting. This is set to true on |
| 463 | * the first Bluetooth energy report. See {@link #mBluetoothActivity}. |
| 464 | */ |
| 465 | boolean mHasBluetoothReporting = false; |
| 466 | |
| 467 | /** |
| 468 | * Whether the device supports Modem controller energy reporting. This is set to true on |
| 469 | * the first Modem energy report. See {@link #mModemActivity}. |
| 470 | */ |
| 471 | boolean mHasModemReporting = false; |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 472 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 473 | boolean mWifiOn; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 474 | StopwatchTimer mWifiOnTimer; |
Eric Shienbrood | d4c5f89 | 2009-03-24 18:13:20 -0700 | [diff] [blame] | 475 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 476 | boolean mGlobalWifiRunning; |
| 477 | StopwatchTimer mGlobalWifiRunningTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 478 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 479 | int mWifiState = -1; |
| 480 | final StopwatchTimer[] mWifiStateTimer = new StopwatchTimer[NUM_WIFI_STATES]; |
| 481 | |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 482 | int mWifiSupplState = -1; |
| 483 | final StopwatchTimer[] mWifiSupplStateTimer = new StopwatchTimer[NUM_WIFI_SUPPL_STATES]; |
| 484 | |
| 485 | int mWifiSignalStrengthBin = -1; |
| 486 | final StopwatchTimer[] mWifiSignalStrengthsTimer = |
| 487 | new StopwatchTimer[NUM_WIFI_SIGNAL_STRENGTH_BINS]; |
| 488 | |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 489 | int mBluetoothScanNesting; |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 490 | @VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE) |
| 491 | protected StopwatchTimer mBluetoothScanTimer; |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 492 | |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 493 | int mMobileRadioPowerState = DataConnectionRealTimeInfo.DC_POWER_STATE_LOW; |
Dianne Hackborn | f7097a5 | 2014-05-13 09:56:14 -0700 | [diff] [blame] | 494 | long mMobileRadioActiveStartTime; |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 495 | StopwatchTimer mMobileRadioActiveTimer; |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 496 | StopwatchTimer mMobileRadioActivePerAppTimer; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 497 | LongSamplingCounter mMobileRadioActiveAdjustedTime; |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 498 | LongSamplingCounter mMobileRadioActiveUnknownTime; |
| 499 | LongSamplingCounter mMobileRadioActiveUnknownCount; |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 500 | |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 501 | int mWifiRadioPowerState = DataConnectionRealTimeInfo.DC_POWER_STATE_LOW; |
| 502 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 503 | /** |
| 504 | * These provide time bases that discount the time the device is plugged |
| 505 | * in to power. |
| 506 | */ |
| 507 | boolean mOnBattery; |
| 508 | boolean mOnBatteryInternal; |
Amith Yamasani | 3718aaa | 2009-06-09 06:32:35 -0700 | [diff] [blame] | 509 | |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 510 | /** |
| 511 | * External reporting of whether the device is actually charging. |
| 512 | */ |
| 513 | boolean mCharging = true; |
| 514 | int mLastChargingStateLevel; |
| 515 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 516 | /* |
| 517 | * These keep track of battery levels (1-100) at the last plug event and the last unplug event. |
| 518 | */ |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 519 | int mDischargeStartLevel; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 520 | int mDischargeUnplugLevel; |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 521 | int mDischargePlugLevel; |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 522 | int mDischargeCurrentLevel; |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 523 | int mCurrentBatteryLevel; |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 524 | int mLowDischargeAmountSinceCharge; |
| 525 | int mHighDischargeAmountSinceCharge; |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 526 | int mDischargeScreenOnUnplugLevel; |
| 527 | int mDischargeScreenOffUnplugLevel; |
| 528 | int mDischargeAmountScreenOn; |
| 529 | int mDischargeAmountScreenOnSinceCharge; |
| 530 | int mDischargeAmountScreenOff; |
| 531 | int mDischargeAmountScreenOffSinceCharge; |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 532 | |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 533 | private LongSamplingCounter mDischargeScreenOffCounter; |
| 534 | private LongSamplingCounter mDischargeCounter; |
| 535 | |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 536 | static final int MAX_LEVEL_STEPS = 200; |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 537 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 538 | int mInitStepMode = 0; |
| 539 | int mCurStepMode = 0; |
| 540 | int mModStepMode = 0; |
| 541 | |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 542 | int mLastDischargeStepLevel; |
Dianne Hackborn | 2932513 | 2014-05-21 15:01:03 -0700 | [diff] [blame] | 543 | int mMinDischargeStepLevel; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 544 | final LevelStepTracker mDischargeStepTracker = new LevelStepTracker(MAX_LEVEL_STEPS); |
| 545 | final LevelStepTracker mDailyDischargeStepTracker = new LevelStepTracker(MAX_LEVEL_STEPS*2); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 546 | ArrayList<PackageChange> mDailyPackageChanges; |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 547 | |
| 548 | int mLastChargeStepLevel; |
Dianne Hackborn | 2932513 | 2014-05-21 15:01:03 -0700 | [diff] [blame] | 549 | int mMaxChargeStepLevel; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 550 | final LevelStepTracker mChargeStepTracker = new LevelStepTracker(MAX_LEVEL_STEPS); |
| 551 | final LevelStepTracker mDailyChargeStepTracker = new LevelStepTracker(MAX_LEVEL_STEPS*2); |
| 552 | |
| 553 | static final int MAX_DAILY_ITEMS = 10; |
| 554 | |
| 555 | long mDailyStartTime = 0; |
| 556 | long mNextMinDailyDeadline = 0; |
| 557 | long mNextMaxDailyDeadline = 0; |
| 558 | |
| 559 | final ArrayList<DailyItem> mDailyItems = new ArrayList<>(); |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 560 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 561 | long mLastWriteTime = 0; // Milliseconds |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 562 | |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 563 | private int mPhoneServiceState = -1; |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 564 | private int mPhoneServiceStateRaw = -1; |
| 565 | private int mPhoneSimStateRaw = -1; |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 566 | |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 567 | private int mNumConnectivityChange; |
| 568 | private int mLoadedNumConnectivityChange; |
| 569 | private int mUnpluggedNumConnectivityChange; |
| 570 | |
Adam Lesinski | f9b20a9 | 2016-06-17 17:30:01 -0700 | [diff] [blame] | 571 | private int mEstimatedBatteryCapacity = -1; |
| 572 | |
Jocelyn Dang | c627d10 | 2017-04-14 13:15:14 -0700 | [diff] [blame] | 573 | private int mMinLearnedBatteryCapacity = -1; |
| 574 | private int mMaxLearnedBatteryCapacity = -1; |
Adam Lesinski | 041d917 | 2016-12-12 12:03:56 -0800 | [diff] [blame] | 575 | |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 576 | private long[] mCpuFreqs; |
| 577 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 578 | private PowerProfile mPowerProfile; |
| 579 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 580 | /* |
| 581 | * Holds a SamplingTimer associated with each kernel wakelock name being tracked. |
| 582 | */ |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 583 | private final HashMap<String, SamplingTimer> mKernelWakelockStats = new HashMap<>(); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 584 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 585 | public Map<String, ? extends Timer> getKernelWakelockStats() { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 586 | return mKernelWakelockStats; |
| 587 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 588 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 589 | String mLastWakeupReason = null; |
| 590 | long mLastWakeupUptimeMs = 0; |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 591 | private final HashMap<String, SamplingTimer> mWakeupReasonStats = new HashMap<>(); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 592 | |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 593 | public Map<String, ? extends Timer> getWakeupReasonStats() { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 594 | return mWakeupReasonStats; |
| 595 | } |
| 596 | |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 597 | @Override |
| 598 | public LongCounter getDischargeScreenOffCoulombCounter() { |
| 599 | return mDischargeScreenOffCounter; |
| 600 | } |
| 601 | |
| 602 | @Override |
| 603 | public LongCounter getDischargeCoulombCounter() { |
| 604 | return mDischargeCounter; |
| 605 | } |
| 606 | |
Adam Lesinski | f9b20a9 | 2016-06-17 17:30:01 -0700 | [diff] [blame] | 607 | @Override |
| 608 | public int getEstimatedBatteryCapacity() { |
| 609 | return mEstimatedBatteryCapacity; |
| 610 | } |
| 611 | |
Jocelyn Dang | c627d10 | 2017-04-14 13:15:14 -0700 | [diff] [blame] | 612 | @Override |
| 613 | public int getMinLearnedBatteryCapacity() { |
| 614 | return mMinLearnedBatteryCapacity; |
| 615 | } |
| 616 | |
| 617 | @Override |
| 618 | public int getMaxLearnedBatteryCapacity() { |
| 619 | return mMaxLearnedBatteryCapacity; |
| 620 | } |
| 621 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 622 | public BatteryStatsImpl() { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 623 | this(new SystemClocks()); |
| 624 | } |
| 625 | |
| 626 | public BatteryStatsImpl(Clocks clocks) { |
| 627 | init(clocks); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 628 | mFile = null; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 629 | mCheckinFile = null; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 630 | mDailyFile = null; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 631 | mHandler = null; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 632 | mExternalSync = null; |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 633 | mPlatformIdleStateCallback = null; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 634 | clearHistoryLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 635 | } |
| 636 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 637 | private void init(Clocks clocks) { |
| 638 | mClocks = clocks; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 639 | } |
| 640 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 641 | public interface TimeBaseObs { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 642 | void onTimeStarted(long elapsedRealtime, long baseUptime, long baseRealtime); |
| 643 | void onTimeStopped(long elapsedRealtime, long baseUptime, long baseRealtime); |
| 644 | } |
| 645 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 646 | // methods are protected not private to be VisibleForTesting |
| 647 | public static class TimeBase { |
| 648 | protected final ArrayList<TimeBaseObs> mObservers = new ArrayList<>(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 649 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 650 | protected long mUptime; |
| 651 | protected long mRealtime; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 652 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 653 | protected boolean mRunning; |
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 mPastUptime; |
| 656 | protected long mUptimeStart; |
| 657 | protected long mPastRealtime; |
| 658 | protected long mRealtimeStart; |
| 659 | protected long mUnpluggedUptime; |
| 660 | protected long mUnpluggedRealtime; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 661 | |
| 662 | public void dump(PrintWriter pw, String prefix) { |
| 663 | StringBuilder sb = new StringBuilder(128); |
| 664 | pw.print(prefix); pw.print("mRunning="); pw.println(mRunning); |
| 665 | sb.setLength(0); |
| 666 | sb.append(prefix); |
| 667 | sb.append("mUptime="); |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 668 | formatTimeMs(sb, mUptime / 1000); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 669 | pw.println(sb.toString()); |
| 670 | sb.setLength(0); |
| 671 | sb.append(prefix); |
| 672 | sb.append("mRealtime="); |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 673 | formatTimeMs(sb, mRealtime / 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("mPastUptime="); |
| 678 | formatTimeMs(sb, mPastUptime / 1000); sb.append("mUptimeStart="); |
| 679 | formatTimeMs(sb, mUptimeStart / 1000); |
| 680 | sb.append("mUnpluggedUptime="); formatTimeMs(sb, mUnpluggedUptime / 1000); |
| 681 | pw.println(sb.toString()); |
| 682 | sb.setLength(0); |
| 683 | sb.append(prefix); |
| 684 | sb.append("mPastRealtime="); |
| 685 | formatTimeMs(sb, mPastRealtime / 1000); sb.append("mRealtimeStart="); |
| 686 | formatTimeMs(sb, mRealtimeStart / 1000); |
| 687 | sb.append("mUnpluggedRealtime="); formatTimeMs(sb, mUnpluggedRealtime / 1000); |
| 688 | pw.println(sb.toString()); |
| 689 | } |
| 690 | |
| 691 | public void add(TimeBaseObs observer) { |
| 692 | mObservers.add(observer); |
| 693 | } |
| 694 | |
| 695 | public void remove(TimeBaseObs observer) { |
| 696 | if (!mObservers.remove(observer)) { |
| 697 | Slog.wtf(TAG, "Removed unknown observer: " + observer); |
| 698 | } |
| 699 | } |
| 700 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 701 | public boolean hasObserver(TimeBaseObs observer) { |
| 702 | return mObservers.contains(observer); |
| 703 | } |
| 704 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 705 | public void init(long uptime, long realtime) { |
| 706 | mRealtime = 0; |
| 707 | mUptime = 0; |
| 708 | mPastUptime = 0; |
| 709 | mPastRealtime = 0; |
| 710 | mUptimeStart = uptime; |
| 711 | mRealtimeStart = realtime; |
| 712 | mUnpluggedUptime = getUptime(mUptimeStart); |
| 713 | mUnpluggedRealtime = getRealtime(mRealtimeStart); |
| 714 | } |
| 715 | |
| 716 | public void reset(long uptime, long realtime) { |
| 717 | if (!mRunning) { |
| 718 | mPastUptime = 0; |
| 719 | mPastRealtime = 0; |
| 720 | } else { |
| 721 | mUptimeStart = uptime; |
| 722 | mRealtimeStart = realtime; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 723 | // TODO: Since mUptimeStart was just reset and we are running, getUptime will |
| 724 | // 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] | 725 | mUnpluggedUptime = getUptime(uptime); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 726 | // TODO: likewise. |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 727 | mUnpluggedRealtime = getRealtime(realtime); |
| 728 | } |
| 729 | } |
| 730 | |
| 731 | public long computeUptime(long curTime, int which) { |
| 732 | switch (which) { |
| 733 | case STATS_SINCE_CHARGED: |
| 734 | return mUptime + getUptime(curTime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 735 | case STATS_CURRENT: |
| 736 | return getUptime(curTime); |
| 737 | case STATS_SINCE_UNPLUGGED: |
| 738 | return getUptime(curTime) - mUnpluggedUptime; |
| 739 | } |
| 740 | return 0; |
| 741 | } |
| 742 | |
| 743 | public long computeRealtime(long curTime, int which) { |
| 744 | switch (which) { |
| 745 | case STATS_SINCE_CHARGED: |
| 746 | return mRealtime + getRealtime(curTime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 747 | case STATS_CURRENT: |
| 748 | return getRealtime(curTime); |
| 749 | case STATS_SINCE_UNPLUGGED: |
| 750 | return getRealtime(curTime) - mUnpluggedRealtime; |
| 751 | } |
| 752 | return 0; |
| 753 | } |
| 754 | |
| 755 | public long getUptime(long curTime) { |
| 756 | long time = mPastUptime; |
| 757 | if (mRunning) { |
| 758 | time += curTime - mUptimeStart; |
| 759 | } |
| 760 | return time; |
| 761 | } |
| 762 | |
| 763 | public long getRealtime(long curTime) { |
| 764 | long time = mPastRealtime; |
| 765 | if (mRunning) { |
| 766 | time += curTime - mRealtimeStart; |
| 767 | } |
| 768 | return time; |
| 769 | } |
| 770 | |
| 771 | public long getUptimeStart() { |
| 772 | return mUptimeStart; |
| 773 | } |
| 774 | |
| 775 | public long getRealtimeStart() { |
| 776 | return mRealtimeStart; |
| 777 | } |
| 778 | |
| 779 | public boolean isRunning() { |
| 780 | return mRunning; |
| 781 | } |
| 782 | |
| 783 | public boolean setRunning(boolean running, long uptime, long realtime) { |
| 784 | if (mRunning != running) { |
| 785 | mRunning = running; |
| 786 | if (running) { |
| 787 | mUptimeStart = uptime; |
| 788 | mRealtimeStart = realtime; |
| 789 | long batteryUptime = mUnpluggedUptime = getUptime(uptime); |
| 790 | long batteryRealtime = mUnpluggedRealtime = getRealtime(realtime); |
| 791 | |
| 792 | for (int i = mObservers.size() - 1; i >= 0; i--) { |
| 793 | mObservers.get(i).onTimeStarted(realtime, batteryUptime, batteryRealtime); |
| 794 | } |
| 795 | } else { |
| 796 | mPastUptime += uptime - mUptimeStart; |
| 797 | mPastRealtime += realtime - mRealtimeStart; |
| 798 | |
| 799 | long batteryUptime = getUptime(uptime); |
| 800 | long batteryRealtime = getRealtime(realtime); |
| 801 | |
| 802 | for (int i = mObservers.size() - 1; i >= 0; i--) { |
| 803 | mObservers.get(i).onTimeStopped(realtime, batteryUptime, batteryRealtime); |
| 804 | } |
| 805 | } |
| 806 | return true; |
| 807 | } |
| 808 | return false; |
| 809 | } |
| 810 | |
| 811 | public void readSummaryFromParcel(Parcel in) { |
| 812 | mUptime = in.readLong(); |
| 813 | mRealtime = in.readLong(); |
| 814 | } |
| 815 | |
| 816 | public void writeSummaryToParcel(Parcel out, long uptime, long realtime) { |
| 817 | out.writeLong(computeUptime(uptime, STATS_SINCE_CHARGED)); |
| 818 | out.writeLong(computeRealtime(realtime, STATS_SINCE_CHARGED)); |
| 819 | } |
| 820 | |
| 821 | public void readFromParcel(Parcel in) { |
| 822 | mRunning = false; |
| 823 | mUptime = in.readLong(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 824 | mPastUptime = in.readLong(); |
| 825 | mUptimeStart = in.readLong(); |
Dianne Hackborn | ef640cd | 2014-03-25 14:41:05 -0700 | [diff] [blame] | 826 | mRealtime = in.readLong(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 827 | mPastRealtime = in.readLong(); |
| 828 | mRealtimeStart = in.readLong(); |
| 829 | mUnpluggedUptime = in.readLong(); |
| 830 | mUnpluggedRealtime = in.readLong(); |
| 831 | } |
| 832 | |
| 833 | public void writeToParcel(Parcel out, long uptime, long realtime) { |
| 834 | final long runningUptime = getUptime(uptime); |
| 835 | final long runningRealtime = getRealtime(realtime); |
| 836 | out.writeLong(mUptime); |
| 837 | out.writeLong(runningUptime); |
| 838 | out.writeLong(mUptimeStart); |
Dianne Hackborn | ef640cd | 2014-03-25 14:41:05 -0700 | [diff] [blame] | 839 | out.writeLong(mRealtime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 840 | out.writeLong(runningRealtime); |
| 841 | out.writeLong(mRealtimeStart); |
| 842 | out.writeLong(mUnpluggedUptime); |
| 843 | out.writeLong(mUnpluggedRealtime); |
| 844 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 845 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 846 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 847 | /** |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 848 | * State for keeping track of counting information. |
| 849 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 850 | public static class Counter extends BatteryStats.Counter implements TimeBaseObs { |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 851 | final AtomicInteger mCount = new AtomicInteger(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 852 | final TimeBase mTimeBase; |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 853 | int mLoadedCount; |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 854 | int mUnpluggedCount; |
| 855 | int mPluggedCount; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 856 | |
Bookatz | 8c6f3c5 | 2017-05-24 12:00:17 -0700 | [diff] [blame] | 857 | public Counter(TimeBase timeBase, Parcel in) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 858 | mTimeBase = timeBase; |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 859 | mPluggedCount = in.readInt(); |
| 860 | mCount.set(mPluggedCount); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 861 | mLoadedCount = in.readInt(); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 862 | mUnpluggedCount = in.readInt(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 863 | timeBase.add(this); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 864 | } |
| 865 | |
Bookatz | 8c6f3c5 | 2017-05-24 12:00:17 -0700 | [diff] [blame] | 866 | public Counter(TimeBase timeBase) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 867 | mTimeBase = timeBase; |
| 868 | timeBase.add(this); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 869 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 870 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 871 | public void writeToParcel(Parcel out) { |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 872 | out.writeInt(mCount.get()); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 873 | out.writeInt(mLoadedCount); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 874 | out.writeInt(mUnpluggedCount); |
| 875 | } |
| 876 | |
Bookatz | 8c6f3c5 | 2017-05-24 12:00:17 -0700 | [diff] [blame] | 877 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 878 | public void onTimeStarted(long elapsedRealtime, long baseUptime, long baseRealtime) { |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 879 | mUnpluggedCount = mPluggedCount; |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 880 | } |
| 881 | |
Bookatz | 8c6f3c5 | 2017-05-24 12:00:17 -0700 | [diff] [blame] | 882 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 883 | public void onTimeStopped(long elapsedRealtime, long baseUptime, long baseRealtime) { |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 884 | mPluggedCount = mCount.get(); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 885 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 886 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 887 | /** |
| 888 | * Writes a possibly null Counter to a Parcel. |
| 889 | * |
| 890 | * @param out the Parcel to be written to. |
| 891 | * @param counter a Counter, or null. |
| 892 | */ |
| 893 | public static void writeCounterToParcel(Parcel out, Counter counter) { |
| 894 | if (counter == null) { |
| 895 | out.writeInt(0); // indicates null |
| 896 | return; |
| 897 | } |
| 898 | out.writeInt(1); // indicates non-null |
| 899 | |
| 900 | counter.writeToParcel(out); |
| 901 | } |
| 902 | |
| 903 | @Override |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 904 | public int getCountLocked(int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 905 | int val = mCount.get(); |
| 906 | if (which == STATS_SINCE_UNPLUGGED) { |
| 907 | val -= mUnpluggedCount; |
| 908 | } else if (which != STATS_SINCE_CHARGED) { |
| 909 | val -= mLoadedCount; |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 910 | } |
| 911 | |
| 912 | return val; |
| 913 | } |
| 914 | |
| 915 | public void logState(Printer pw, String prefix) { |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 916 | pw.println(prefix + "mCount=" + mCount.get() |
Bookatz | 8c6f3c5 | 2017-05-24 12:00:17 -0700 | [diff] [blame] | 917 | + " mLoadedCount=" + mLoadedCount |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 918 | + " mUnpluggedCount=" + mUnpluggedCount |
| 919 | + " mPluggedCount=" + mPluggedCount); |
| 920 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 921 | |
Bookatz | 8c6f3c5 | 2017-05-24 12:00:17 -0700 | [diff] [blame] | 922 | @VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE) |
| 923 | public void stepAtomic() { |
| 924 | if (mTimeBase.isRunning()) { |
| 925 | mCount.incrementAndGet(); |
| 926 | } |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 927 | } |
| 928 | |
Bookatz | 4ebc064 | 2017-05-11 12:21:19 -0700 | [diff] [blame] | 929 | void addAtomic(int delta) { |
Bookatz | 8c6f3c5 | 2017-05-24 12:00:17 -0700 | [diff] [blame] | 930 | if (mTimeBase.isRunning()) { |
| 931 | mCount.addAndGet(delta); |
| 932 | } |
Bookatz | 4ebc064 | 2017-05-11 12:21:19 -0700 | [diff] [blame] | 933 | } |
| 934 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 935 | /** |
| 936 | * Clear state of this counter. |
| 937 | */ |
| 938 | void reset(boolean detachIfReset) { |
| 939 | mCount.set(0); |
Bookatz | 8c6f3c5 | 2017-05-24 12:00:17 -0700 | [diff] [blame] | 940 | mLoadedCount = mPluggedCount = mUnpluggedCount = 0; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 941 | if (detachIfReset) { |
| 942 | detach(); |
| 943 | } |
| 944 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 945 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 946 | void detach() { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 947 | mTimeBase.remove(this); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 948 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 949 | |
Bookatz | 8c6f3c5 | 2017-05-24 12:00:17 -0700 | [diff] [blame] | 950 | @VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE) |
| 951 | public void writeSummaryFromParcelLocked(Parcel out) { |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 952 | int count = mCount.get(); |
| 953 | out.writeInt(count); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 954 | } |
| 955 | |
Bookatz | 8c6f3c5 | 2017-05-24 12:00:17 -0700 | [diff] [blame] | 956 | @VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE) |
| 957 | public void readSummaryFromParcelLocked(Parcel in) { |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 958 | mLoadedCount = in.readInt(); |
| 959 | mCount.set(mLoadedCount); |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 960 | mUnpluggedCount = mPluggedCount = mLoadedCount; |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 961 | } |
| 962 | } |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 963 | |
Sudheer Shanka | 59f5c00 | 2017-05-15 10:57:15 -0700 | [diff] [blame] | 964 | @VisibleForTesting |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 965 | public static class LongSamplingCounterArray extends LongCounterArray implements TimeBaseObs { |
| 966 | final TimeBase mTimeBase; |
Sudheer Shanka | 59f5c00 | 2017-05-15 10:57:15 -0700 | [diff] [blame] | 967 | public long[] mCounts; |
| 968 | public long[] mLoadedCounts; |
| 969 | public long[] mUnpluggedCounts; |
| 970 | public long[] mPluggedCounts; |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 971 | |
Sudheer Shanka | 59f5c00 | 2017-05-15 10:57:15 -0700 | [diff] [blame] | 972 | private LongSamplingCounterArray(TimeBase timeBase, Parcel in) { |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 973 | mTimeBase = timeBase; |
| 974 | mPluggedCounts = in.createLongArray(); |
| 975 | mCounts = copyArray(mPluggedCounts, mCounts); |
| 976 | mLoadedCounts = in.createLongArray(); |
| 977 | mUnpluggedCounts = in.createLongArray(); |
| 978 | timeBase.add(this); |
| 979 | } |
| 980 | |
Sudheer Shanka | 59f5c00 | 2017-05-15 10:57:15 -0700 | [diff] [blame] | 981 | public LongSamplingCounterArray(TimeBase timeBase) { |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 982 | mTimeBase = timeBase; |
| 983 | timeBase.add(this); |
| 984 | } |
| 985 | |
Sudheer Shanka | 59f5c00 | 2017-05-15 10:57:15 -0700 | [diff] [blame] | 986 | private void writeToParcel(Parcel out) { |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 987 | out.writeLongArray(mCounts); |
| 988 | out.writeLongArray(mLoadedCounts); |
| 989 | out.writeLongArray(mUnpluggedCounts); |
| 990 | } |
| 991 | |
| 992 | @Override |
| 993 | public void onTimeStarted(long elapsedRealTime, long baseUptime, long baseRealtime) { |
| 994 | mUnpluggedCounts = copyArray(mPluggedCounts, mUnpluggedCounts); |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 995 | } |
| 996 | |
| 997 | @Override |
| 998 | public void onTimeStopped(long elapsedRealtime, long baseUptime, long baseRealtime) { |
| 999 | mPluggedCounts = copyArray(mCounts, mPluggedCounts); |
| 1000 | } |
| 1001 | |
| 1002 | @Override |
| 1003 | public long[] getCountsLocked(int which) { |
| 1004 | long[] val = copyArray(mTimeBase.isRunning() ? mCounts : mPluggedCounts, null); |
| 1005 | if (which == STATS_SINCE_UNPLUGGED) { |
| 1006 | subtract(val, mUnpluggedCounts); |
| 1007 | } else if (which != STATS_SINCE_CHARGED) { |
| 1008 | subtract(val, mLoadedCounts); |
| 1009 | } |
| 1010 | return val; |
| 1011 | } |
| 1012 | |
| 1013 | @Override |
| 1014 | public void logState(Printer pw, String prefix) { |
| 1015 | pw.println(prefix + "mCounts=" + Arrays.toString(mCounts) |
| 1016 | + " mLoadedCounts=" + Arrays.toString(mLoadedCounts) |
| 1017 | + " mUnpluggedCounts=" + Arrays.toString(mUnpluggedCounts) |
| 1018 | + " mPluggedCounts=" + Arrays.toString(mPluggedCounts)); |
| 1019 | } |
| 1020 | |
Sudheer Shanka | 59f5c00 | 2017-05-15 10:57:15 -0700 | [diff] [blame] | 1021 | public void addCountLocked(long[] counts) { |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 1022 | if (counts == null) { |
| 1023 | return; |
| 1024 | } |
Bookatz | 8c6f3c5 | 2017-05-24 12:00:17 -0700 | [diff] [blame] | 1025 | if (mTimeBase.isRunning()) { |
| 1026 | if (mCounts == null) { |
| 1027 | mCounts = new long[counts.length]; |
| 1028 | } |
| 1029 | for (int i = 0; i < counts.length; ++i) { |
| 1030 | mCounts[i] += counts[i]; |
| 1031 | } |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 1032 | } |
| 1033 | } |
| 1034 | |
| 1035 | /** |
| 1036 | * Clear state of this counter. |
| 1037 | */ |
Sudheer Shanka | 59f5c00 | 2017-05-15 10:57:15 -0700 | [diff] [blame] | 1038 | public void reset(boolean detachIfReset) { |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 1039 | fillArray(mCounts, 0); |
| 1040 | fillArray(mLoadedCounts, 0); |
| 1041 | fillArray(mPluggedCounts, 0); |
| 1042 | fillArray(mUnpluggedCounts, 0); |
| 1043 | if (detachIfReset) { |
| 1044 | detach(); |
| 1045 | } |
| 1046 | } |
| 1047 | |
Sudheer Shanka | 59f5c00 | 2017-05-15 10:57:15 -0700 | [diff] [blame] | 1048 | public void detach() { |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 1049 | mTimeBase.remove(this); |
| 1050 | } |
| 1051 | |
Sudheer Shanka | 59f5c00 | 2017-05-15 10:57:15 -0700 | [diff] [blame] | 1052 | private void writeSummaryToParcelLocked(Parcel out) { |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 1053 | out.writeLongArray(mCounts); |
| 1054 | } |
| 1055 | |
Sudheer Shanka | 59f5c00 | 2017-05-15 10:57:15 -0700 | [diff] [blame] | 1056 | private void readSummaryFromParcelLocked(Parcel in) { |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 1057 | mCounts = in.createLongArray(); |
| 1058 | mLoadedCounts = copyArray(mCounts, mLoadedCounts); |
| 1059 | mUnpluggedCounts = copyArray(mCounts, mUnpluggedCounts); |
| 1060 | mPluggedCounts = copyArray(mCounts, mPluggedCounts); |
| 1061 | } |
| 1062 | |
Sudheer Shanka | 59f5c00 | 2017-05-15 10:57:15 -0700 | [diff] [blame] | 1063 | public static void writeToParcel(Parcel out, LongSamplingCounterArray counterArray) { |
| 1064 | if (counterArray != null) { |
| 1065 | out.writeInt(1); |
| 1066 | counterArray.writeToParcel(out); |
| 1067 | } else { |
| 1068 | out.writeInt(0); |
| 1069 | } |
| 1070 | } |
| 1071 | |
| 1072 | public static LongSamplingCounterArray readFromParcel(Parcel in, TimeBase timeBase) { |
| 1073 | if (in.readInt() != 0) { |
| 1074 | return new LongSamplingCounterArray(timeBase, in); |
| 1075 | } else { |
| 1076 | return null; |
| 1077 | } |
| 1078 | } |
| 1079 | |
| 1080 | public static void writeSummaryToParcelLocked(Parcel out, |
| 1081 | LongSamplingCounterArray counterArray) { |
| 1082 | if (counterArray != null) { |
| 1083 | out.writeInt(1); |
| 1084 | counterArray.writeSummaryToParcelLocked(out); |
| 1085 | } else { |
| 1086 | out.writeInt(0); |
| 1087 | } |
| 1088 | } |
| 1089 | |
| 1090 | public static LongSamplingCounterArray readSummaryFromParcelLocked(Parcel in, |
| 1091 | TimeBase timeBase) { |
| 1092 | if (in.readInt() != 0) { |
| 1093 | final LongSamplingCounterArray counterArray |
| 1094 | = new LongSamplingCounterArray(timeBase); |
| 1095 | counterArray.readSummaryFromParcelLocked(in); |
| 1096 | return counterArray; |
| 1097 | } else { |
| 1098 | return null; |
| 1099 | } |
| 1100 | } |
| 1101 | |
Bookatz | 8c6f3c5 | 2017-05-24 12:00:17 -0700 | [diff] [blame] | 1102 | private static void fillArray(long[] a, long val) { |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 1103 | if (a != null) { |
| 1104 | Arrays.fill(a, val); |
| 1105 | } |
| 1106 | } |
| 1107 | |
Bookatz | 8c6f3c5 | 2017-05-24 12:00:17 -0700 | [diff] [blame] | 1108 | private static void subtract(@NonNull long[] val, long[] toSubtract) { |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 1109 | if (toSubtract == null) { |
| 1110 | return; |
| 1111 | } |
| 1112 | for (int i = 0; i < val.length; i++) { |
| 1113 | val[i] -= toSubtract[i]; |
| 1114 | } |
| 1115 | } |
| 1116 | |
Bookatz | 8c6f3c5 | 2017-05-24 12:00:17 -0700 | [diff] [blame] | 1117 | private static long[] copyArray(long[] src, long[] dest) { |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 1118 | if (src == null) { |
| 1119 | return null; |
| 1120 | } else { |
| 1121 | if (dest == null) { |
| 1122 | dest = new long[src.length]; |
| 1123 | } |
| 1124 | System.arraycopy(src, 0, dest, 0, src.length); |
| 1125 | return dest; |
| 1126 | } |
| 1127 | } |
| 1128 | } |
| 1129 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1130 | public static class LongSamplingCounter extends LongCounter implements TimeBaseObs { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1131 | final TimeBase mTimeBase; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 1132 | long mCount; |
| 1133 | long mLoadedCount; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 1134 | long mUnpluggedCount; |
| 1135 | long mPluggedCount; |
| 1136 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1137 | LongSamplingCounter(TimeBase timeBase, Parcel in) { |
| 1138 | mTimeBase = timeBase; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 1139 | mPluggedCount = in.readLong(); |
| 1140 | mCount = mPluggedCount; |
| 1141 | mLoadedCount = in.readLong(); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 1142 | mUnpluggedCount = in.readLong(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1143 | timeBase.add(this); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 1144 | } |
| 1145 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1146 | LongSamplingCounter(TimeBase timeBase) { |
| 1147 | mTimeBase = timeBase; |
| 1148 | timeBase.add(this); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 1149 | } |
| 1150 | |
| 1151 | public void writeToParcel(Parcel out) { |
| 1152 | out.writeLong(mCount); |
| 1153 | out.writeLong(mLoadedCount); |
| 1154 | out.writeLong(mUnpluggedCount); |
| 1155 | } |
| 1156 | |
| 1157 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1158 | public void onTimeStarted(long elapsedRealtime, long baseUptime, long baseRealtime) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 1159 | mUnpluggedCount = mPluggedCount; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 1160 | } |
| 1161 | |
| 1162 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1163 | public void onTimeStopped(long elapsedRealtime, long baseUptime, long baseRealtime) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 1164 | mPluggedCount = mCount; |
| 1165 | } |
| 1166 | |
| 1167 | public long getCountLocked(int which) { |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 1168 | long val = mTimeBase.isRunning() ? mCount : mPluggedCount; |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 1169 | if (which == STATS_SINCE_UNPLUGGED) { |
| 1170 | val -= mUnpluggedCount; |
| 1171 | } else if (which != STATS_SINCE_CHARGED) { |
| 1172 | val -= mLoadedCount; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 1173 | } |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 1174 | return val; |
| 1175 | } |
| 1176 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1177 | @Override |
| 1178 | public void logState(Printer pw, String prefix) { |
| 1179 | pw.println(prefix + "mCount=" + mCount |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 1180 | + " mLoadedCount=" + mLoadedCount |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 1181 | + " mUnpluggedCount=" + mUnpluggedCount |
| 1182 | + " mPluggedCount=" + mPluggedCount); |
| 1183 | } |
| 1184 | |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 1185 | void addCountLocked(long count) { |
Bookatz | 8c6f3c5 | 2017-05-24 12:00:17 -0700 | [diff] [blame] | 1186 | if (mTimeBase.isRunning()) { |
| 1187 | mCount += count; |
| 1188 | } |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 1189 | } |
| 1190 | |
| 1191 | /** |
| 1192 | * Clear state of this counter. |
| 1193 | */ |
| 1194 | void reset(boolean detachIfReset) { |
| 1195 | mCount = 0; |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 1196 | mLoadedCount = mPluggedCount = mUnpluggedCount = 0; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 1197 | if (detachIfReset) { |
| 1198 | detach(); |
| 1199 | } |
| 1200 | } |
| 1201 | |
| 1202 | void detach() { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1203 | mTimeBase.remove(this); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 1204 | } |
| 1205 | |
| 1206 | void writeSummaryFromParcelLocked(Parcel out) { |
| 1207 | out.writeLong(mCount); |
| 1208 | } |
| 1209 | |
| 1210 | void readSummaryFromParcelLocked(Parcel in) { |
| 1211 | mLoadedCount = in.readLong(); |
| 1212 | mCount = mLoadedCount; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 1213 | mUnpluggedCount = mPluggedCount = mLoadedCount; |
| 1214 | } |
| 1215 | } |
| 1216 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1217 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1218 | * State for keeping track of timing information. |
| 1219 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1220 | public static abstract class Timer extends BatteryStats.Timer implements TimeBaseObs { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1221 | protected final Clocks mClocks; |
| 1222 | protected final int mType; |
| 1223 | protected final TimeBase mTimeBase; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1224 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1225 | protected int mCount; |
| 1226 | protected int mLoadedCount; |
| 1227 | protected int mLastCount; |
| 1228 | protected int mUnpluggedCount; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1229 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1230 | // Times are in microseconds for better accuracy when dividing by the |
| 1231 | // lock count, and are in "battery realtime" units. |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1232 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1233 | /** |
| 1234 | * The total time we have accumulated since the start of the original |
| 1235 | * boot, to the last time something interesting happened in the |
| 1236 | * current run. |
| 1237 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1238 | protected long mTotalTime; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1239 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1240 | /** |
| 1241 | * The total time we loaded for the previous runs. Subtract this from |
| 1242 | * mTotalTime to find the time for the current run of the system. |
| 1243 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1244 | protected long mLoadedTime; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1245 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1246 | /** |
| 1247 | * The run time of the last run of the system, as loaded from the |
| 1248 | * saved data. |
| 1249 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1250 | protected long mLastTime; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1251 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1252 | /** |
| 1253 | * The value of mTotalTime when unplug() was last called. Subtract |
| 1254 | * this from mTotalTime to find the time since the last unplug from |
| 1255 | * power. |
| 1256 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1257 | protected long mUnpluggedTime; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1258 | |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 1259 | /** |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 1260 | * The total time this timer has been running until the latest mark has been set. |
| 1261 | * Subtract this from mTotalTime to get the time spent running since the mark was set. |
| 1262 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1263 | protected long mTimeBeforeMark; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 1264 | |
| 1265 | /** |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 1266 | * Constructs from a parcel. |
| 1267 | * @param type |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1268 | * @param timeBase |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 1269 | * @param in |
| 1270 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1271 | public Timer(Clocks clocks, int type, TimeBase timeBase, Parcel in) { |
| 1272 | mClocks = clocks; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1273 | mType = type; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1274 | mTimeBase = timeBase; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1275 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1276 | mCount = in.readInt(); |
| 1277 | mLoadedCount = in.readInt(); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 1278 | mLastCount = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1279 | mUnpluggedCount = in.readInt(); |
| 1280 | mTotalTime = in.readLong(); |
| 1281 | mLoadedTime = in.readLong(); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 1282 | mLastTime = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1283 | mUnpluggedTime = in.readLong(); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 1284 | mTimeBeforeMark = in.readLong(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1285 | timeBase.add(this); |
Dianne Hackborn | 2932513 | 2014-05-21 15:01:03 -0700 | [diff] [blame] | 1286 | 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] | 1287 | } |
| 1288 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1289 | public Timer(Clocks clocks, int type, TimeBase timeBase) { |
| 1290 | mClocks = clocks; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1291 | mType = type; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1292 | mTimeBase = timeBase; |
| 1293 | timeBase.add(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1294 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1295 | |
| 1296 | protected abstract long computeRunTimeLocked(long curBatteryRealtime); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1297 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1298 | protected abstract int computeCurrentCountLocked(); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1299 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1300 | /** |
| 1301 | * Clear state of this timer. Returns true if the timer is inactive |
| 1302 | * so can be completely dropped. |
| 1303 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1304 | public boolean reset(boolean detachIfReset) { |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 1305 | mTotalTime = mLoadedTime = mLastTime = mTimeBeforeMark = 0; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1306 | mCount = mLoadedCount = mLastCount = 0; |
| 1307 | if (detachIfReset) { |
| 1308 | detach(); |
| 1309 | } |
| 1310 | return true; |
| 1311 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1312 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1313 | public void detach() { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1314 | mTimeBase.remove(this); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1315 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1316 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1317 | public void writeToParcel(Parcel out, long elapsedRealtimeUs) { |
Dianne Hackborn | 2932513 | 2014-05-21 15:01:03 -0700 | [diff] [blame] | 1318 | if (DEBUG) Log.i(TAG, "**** WRITING TIMER #" + mType + ": mTotalTime=" |
| 1319 | + computeRunTimeLocked(mTimeBase.getRealtime(elapsedRealtimeUs))); |
Adam Lesinski | 98f0d46 | 2016-04-19 16:46:20 -0700 | [diff] [blame] | 1320 | out.writeInt(computeCurrentCountLocked()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1321 | out.writeInt(mLoadedCount); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1322 | out.writeInt(mUnpluggedCount); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1323 | out.writeLong(computeRunTimeLocked(mTimeBase.getRealtime(elapsedRealtimeUs))); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1324 | out.writeLong(mLoadedTime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1325 | out.writeLong(mUnpluggedTime); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 1326 | out.writeLong(mTimeBeforeMark); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1327 | } |
| 1328 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 1329 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1330 | public void onTimeStarted(long elapsedRealtime, long timeBaseUptime, long baseRealtime) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1331 | if (DEBUG && mType < 0) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1332 | Log.v(TAG, "unplug #" + mType + ": realtime=" + baseRealtime |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1333 | + " old mUnpluggedTime=" + mUnpluggedTime |
| 1334 | + " old mUnpluggedCount=" + mUnpluggedCount); |
| 1335 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1336 | mUnpluggedTime = computeRunTimeLocked(baseRealtime); |
Adam Lesinski | 98f0d46 | 2016-04-19 16:46:20 -0700 | [diff] [blame] | 1337 | mUnpluggedCount = computeCurrentCountLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1338 | if (DEBUG && mType < 0) { |
| 1339 | Log.v(TAG, "unplug #" + mType |
| 1340 | + ": new mUnpluggedTime=" + mUnpluggedTime |
| 1341 | + " new mUnpluggedCount=" + mUnpluggedCount); |
| 1342 | } |
| 1343 | } |
| 1344 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 1345 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1346 | public void onTimeStopped(long elapsedRealtime, long baseUptime, long baseRealtime) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1347 | if (DEBUG && mType < 0) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1348 | Log.v(TAG, "plug #" + mType + ": realtime=" + baseRealtime |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1349 | + " old mTotalTime=" + mTotalTime); |
| 1350 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1351 | mTotalTime = computeRunTimeLocked(baseRealtime); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1352 | mCount = computeCurrentCountLocked(); |
| 1353 | if (DEBUG && mType < 0) { |
| 1354 | Log.v(TAG, "plug #" + mType |
| 1355 | + ": new mTotalTime=" + mTotalTime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1356 | } |
| 1357 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1358 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1359 | /** |
| 1360 | * Writes a possibly null Timer to a Parcel. |
| 1361 | * |
| 1362 | * @param out the Parcel to be written to. |
| 1363 | * @param timer a Timer, or null. |
| 1364 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1365 | 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] | 1366 | if (timer == null) { |
| 1367 | out.writeInt(0); // indicates null |
| 1368 | return; |
| 1369 | } |
| 1370 | out.writeInt(1); // indicates non-null |
| 1371 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1372 | timer.writeToParcel(out, elapsedRealtimeUs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1373 | } |
| 1374 | |
| 1375 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1376 | public long getTotalTimeLocked(long elapsedRealtimeUs, int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 1377 | long val = computeRunTimeLocked(mTimeBase.getRealtime(elapsedRealtimeUs)); |
| 1378 | if (which == STATS_SINCE_UNPLUGGED) { |
| 1379 | val -= mUnpluggedTime; |
| 1380 | } else if (which != STATS_SINCE_CHARGED) { |
| 1381 | val -= mLoadedTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1382 | } |
| 1383 | |
| 1384 | return val; |
| 1385 | } |
| 1386 | |
| 1387 | @Override |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1388 | public int getCountLocked(int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 1389 | int val = computeCurrentCountLocked(); |
| 1390 | if (which == STATS_SINCE_UNPLUGGED) { |
| 1391 | val -= mUnpluggedCount; |
| 1392 | } else if (which != STATS_SINCE_CHARGED) { |
| 1393 | val -= mLoadedCount; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1394 | } |
| 1395 | |
| 1396 | return val; |
| 1397 | } |
| 1398 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 1399 | @Override |
| 1400 | public long getTimeSinceMarkLocked(long elapsedRealtimeUs) { |
| 1401 | long val = computeRunTimeLocked(mTimeBase.getRealtime(elapsedRealtimeUs)); |
| 1402 | return val - mTimeBeforeMark; |
| 1403 | } |
| 1404 | |
| 1405 | @Override |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 1406 | public void logState(Printer pw, String prefix) { |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 1407 | pw.println(prefix + "mCount=" + mCount |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1408 | + " mLoadedCount=" + mLoadedCount + " mLastCount=" + mLastCount |
| 1409 | + " mUnpluggedCount=" + mUnpluggedCount); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 1410 | pw.println(prefix + "mTotalTime=" + mTotalTime |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1411 | + " mLoadedTime=" + mLoadedTime); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 1412 | pw.println(prefix + "mLastTime=" + mLastTime |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1413 | + " mUnpluggedTime=" + mUnpluggedTime); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1414 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1415 | |
| 1416 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1417 | public void writeSummaryFromParcelLocked(Parcel out, long elapsedRealtimeUs) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1418 | long runTime = computeRunTimeLocked(mTimeBase.getRealtime(elapsedRealtimeUs)); |
| 1419 | out.writeLong(runTime); |
Adam Lesinski | 98f0d46 | 2016-04-19 16:46:20 -0700 | [diff] [blame] | 1420 | out.writeInt(computeCurrentCountLocked()); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1421 | } |
| 1422 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1423 | public void readSummaryFromParcelLocked(Parcel in) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1424 | // Multiply by 1000 for backwards compatibility |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1425 | mTotalTime = mLoadedTime = in.readLong(); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 1426 | mLastTime = 0; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1427 | mUnpluggedTime = mTotalTime; |
| 1428 | mCount = mLoadedCount = in.readInt(); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 1429 | mLastCount = 0; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1430 | mUnpluggedCount = mCount; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 1431 | |
| 1432 | // When reading the summary, we set the mark to be the latest information. |
| 1433 | mTimeBeforeMark = mTotalTime; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1434 | } |
| 1435 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1436 | |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 1437 | /** |
| 1438 | * A counter meant to accept monotonically increasing values to its {@link #update(long, int)} |
| 1439 | * method. The state of the timer according to its {@link TimeBase} will determine how much |
| 1440 | * of the value is recorded. |
| 1441 | * |
| 1442 | * If the value being recorded resets, {@link #endSample()} can be called in order to |
| 1443 | * account for the change. If the value passed in to {@link #update(long, int)} decreased |
| 1444 | * between calls, the {@link #endSample()} is automatically called and the new value is |
| 1445 | * expected to increase monotonically from that point on. |
| 1446 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1447 | public static class SamplingTimer extends Timer { |
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 | /** |
| 1450 | * The most recent reported count from /proc/wakelocks. |
| 1451 | */ |
| 1452 | int mCurrentReportedCount; |
| 1453 | |
| 1454 | /** |
| 1455 | * The reported count from /proc/wakelocks when unplug() was last |
| 1456 | * called. |
| 1457 | */ |
| 1458 | int mUnpluggedReportedCount; |
| 1459 | |
| 1460 | /** |
| 1461 | * The most recent reported total_time from /proc/wakelocks. |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1462 | */ |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1463 | long mCurrentReportedTotalTime; |
| 1464 | |
| 1465 | |
| 1466 | /** |
| 1467 | * The reported total_time from /proc/wakelocks when unplug() was last |
| 1468 | * called. |
| 1469 | */ |
| 1470 | long mUnpluggedReportedTotalTime; |
| 1471 | |
| 1472 | /** |
| 1473 | * Whether we are currently in a discharge cycle. |
| 1474 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1475 | boolean mTimeBaseRunning; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1476 | |
| 1477 | /** |
| 1478 | * Whether we are currently recording reported values. |
| 1479 | */ |
| 1480 | boolean mTrackingReportedValues; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1481 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1482 | /* |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1483 | * A sequence counter, incremented once for each update of the stats. |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1484 | */ |
| 1485 | int mUpdateVersion; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1486 | |
Adam Lesinski | 98f0d46 | 2016-04-19 16:46:20 -0700 | [diff] [blame] | 1487 | @VisibleForTesting |
| 1488 | public SamplingTimer(Clocks clocks, TimeBase timeBase, Parcel in) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1489 | super(clocks, 0, timeBase, in); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1490 | mCurrentReportedCount = in.readInt(); |
| 1491 | mUnpluggedReportedCount = in.readInt(); |
| 1492 | mCurrentReportedTotalTime = in.readLong(); |
| 1493 | mUnpluggedReportedTotalTime = in.readLong(); |
| 1494 | mTrackingReportedValues = in.readInt() == 1; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1495 | mTimeBaseRunning = timeBase.isRunning(); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1496 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1497 | |
Adam Lesinski | 98f0d46 | 2016-04-19 16:46:20 -0700 | [diff] [blame] | 1498 | @VisibleForTesting |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 1499 | public SamplingTimer(Clocks clocks, TimeBase timeBase) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1500 | super(clocks, 0, timeBase); |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 1501 | mTrackingReportedValues = false; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1502 | mTimeBaseRunning = timeBase.isRunning(); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1503 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1504 | |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 1505 | /** |
| 1506 | * Ends the current sample, allowing subsequent values to {@link #update(long, int)} to |
| 1507 | * be less than the values used for a previous invocation. |
| 1508 | */ |
| 1509 | public void endSample() { |
| 1510 | mTotalTime = computeRunTimeLocked(0 /* unused by us */); |
| 1511 | mCount = computeCurrentCountLocked(); |
| 1512 | mUnpluggedReportedTotalTime = mCurrentReportedTotalTime = 0; |
| 1513 | mUnpluggedReportedCount = mCurrentReportedCount = 0; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1514 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1515 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1516 | public void setUpdateVersion(int version) { |
| 1517 | mUpdateVersion = version; |
| 1518 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1519 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1520 | public int getUpdateVersion() { |
| 1521 | return mUpdateVersion; |
| 1522 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1523 | |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 1524 | /** |
| 1525 | * Updates the current recorded values. These are meant to be monotonically increasing |
| 1526 | * and cumulative. If you are dealing with deltas, use {@link #add(long, int)}. |
| 1527 | * |
| 1528 | * If the values being recorded have been reset, the monotonically increasing requirement |
| 1529 | * will be broken. In this case, {@link #endSample()} is automatically called and |
| 1530 | * the total value of totalTime and count are recorded, starting a new monotonically |
| 1531 | * increasing sample. |
| 1532 | * |
| 1533 | * @param totalTime total time of sample in microseconds. |
| 1534 | * @param count total number of times the event being sampled occurred. |
| 1535 | */ |
| 1536 | public void update(long totalTime, int count) { |
| 1537 | if (mTimeBaseRunning && !mTrackingReportedValues) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1538 | // Updating the reported value for the first time. |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 1539 | mUnpluggedReportedTotalTime = totalTime; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1540 | mUnpluggedReportedCount = count; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1541 | } |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 1542 | |
| 1543 | mTrackingReportedValues = true; |
| 1544 | |
| 1545 | if (totalTime < mCurrentReportedTotalTime || count < mCurrentReportedCount) { |
| 1546 | endSample(); |
| 1547 | } |
| 1548 | |
| 1549 | mCurrentReportedTotalTime = totalTime; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1550 | mCurrentReportedCount = count; |
| 1551 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1552 | |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 1553 | /** |
| 1554 | * Adds deltaTime and deltaCount to the current sample. |
| 1555 | * |
| 1556 | * @param deltaTime additional time recorded since the last sampled event, in microseconds. |
| 1557 | * @param deltaCount additional number of times the event being sampled occurred. |
| 1558 | */ |
| 1559 | public void add(long deltaTime, int deltaCount) { |
| 1560 | update(mCurrentReportedTotalTime + deltaTime, mCurrentReportedCount + deltaCount); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 1561 | } |
| 1562 | |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 1563 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1564 | public void onTimeStarted(long elapsedRealtime, long baseUptime, long baseRealtime) { |
| 1565 | super.onTimeStarted(elapsedRealtime, baseUptime, baseRealtime); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1566 | if (mTrackingReportedValues) { |
| 1567 | mUnpluggedReportedTotalTime = mCurrentReportedTotalTime; |
| 1568 | mUnpluggedReportedCount = mCurrentReportedCount; |
| 1569 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1570 | mTimeBaseRunning = true; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1571 | } |
| 1572 | |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 1573 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1574 | public void onTimeStopped(long elapsedRealtime, long baseUptime, long baseRealtime) { |
| 1575 | super.onTimeStopped(elapsedRealtime, baseUptime, baseRealtime); |
| 1576 | mTimeBaseRunning = false; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1577 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1578 | |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 1579 | @Override |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1580 | public void logState(Printer pw, String prefix) { |
| 1581 | super.logState(pw, prefix); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1582 | pw.println(prefix + "mCurrentReportedCount=" + mCurrentReportedCount |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1583 | + " mUnpluggedReportedCount=" + mUnpluggedReportedCount |
| 1584 | + " mCurrentReportedTotalTime=" + mCurrentReportedTotalTime |
| 1585 | + " mUnpluggedReportedTotalTime=" + mUnpluggedReportedTotalTime); |
| 1586 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1587 | |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 1588 | @Override |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1589 | protected long computeRunTimeLocked(long curBatteryRealtime) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1590 | return mTotalTime + (mTimeBaseRunning && mTrackingReportedValues |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1591 | ? mCurrentReportedTotalTime - mUnpluggedReportedTotalTime : 0); |
| 1592 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1593 | |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 1594 | @Override |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1595 | protected int computeCurrentCountLocked() { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1596 | return mCount + (mTimeBaseRunning && mTrackingReportedValues |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1597 | ? mCurrentReportedCount - mUnpluggedReportedCount : 0); |
| 1598 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1599 | |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 1600 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1601 | public void writeToParcel(Parcel out, long elapsedRealtimeUs) { |
| 1602 | super.writeToParcel(out, elapsedRealtimeUs); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1603 | out.writeInt(mCurrentReportedCount); |
| 1604 | out.writeInt(mUnpluggedReportedCount); |
| 1605 | out.writeLong(mCurrentReportedTotalTime); |
| 1606 | out.writeLong(mUnpluggedReportedTotalTime); |
| 1607 | out.writeInt(mTrackingReportedValues ? 1 : 0); |
| 1608 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1609 | |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 1610 | @Override |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1611 | public boolean reset(boolean detachIfReset) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1612 | super.reset(detachIfReset); |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 1613 | mTrackingReportedValues = false; |
| 1614 | mUnpluggedReportedTotalTime = 0; |
| 1615 | mUnpluggedReportedCount = 0; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1616 | return true; |
| 1617 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1618 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1619 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1620 | /** |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1621 | * A timer that increments in batches. It does not run for durations, but just jumps |
| 1622 | * for a pre-determined amount. |
| 1623 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1624 | public static class BatchTimer extends Timer { |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1625 | final Uid mUid; |
| 1626 | |
| 1627 | /** |
| 1628 | * The last time at which we updated the timer. This is in elapsed realtime microseconds. |
| 1629 | */ |
| 1630 | long mLastAddedTime; |
| 1631 | |
| 1632 | /** |
| 1633 | * The last duration that we added to the timer. This is in microseconds. |
| 1634 | */ |
| 1635 | long mLastAddedDuration; |
| 1636 | |
| 1637 | /** |
| 1638 | * Whether we are currently in a discharge cycle. |
| 1639 | */ |
| 1640 | boolean mInDischarge; |
| 1641 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1642 | BatchTimer(Clocks clocks, Uid uid, int type, TimeBase timeBase, Parcel in) { |
| 1643 | super(clocks, type, timeBase, in); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1644 | mUid = uid; |
| 1645 | mLastAddedTime = in.readLong(); |
| 1646 | mLastAddedDuration = in.readLong(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1647 | mInDischarge = timeBase.isRunning(); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1648 | } |
| 1649 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1650 | BatchTimer(Clocks clocks, Uid uid, int type, TimeBase timeBase) { |
| 1651 | super(clocks, type, timeBase); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1652 | mUid = uid; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1653 | mInDischarge = timeBase.isRunning(); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1654 | } |
| 1655 | |
| 1656 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1657 | public void writeToParcel(Parcel out, long elapsedRealtimeUs) { |
| 1658 | super.writeToParcel(out, elapsedRealtimeUs); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1659 | out.writeLong(mLastAddedTime); |
| 1660 | out.writeLong(mLastAddedDuration); |
| 1661 | } |
| 1662 | |
| 1663 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1664 | public void onTimeStopped(long elapsedRealtime, long baseUptime, long baseRealtime) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1665 | recomputeLastDuration(mClocks.elapsedRealtime() * 1000, false); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1666 | mInDischarge = false; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1667 | super.onTimeStopped(elapsedRealtime, baseUptime, baseRealtime); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1668 | } |
| 1669 | |
| 1670 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1671 | public void onTimeStarted(long elapsedRealtime, long baseUptime, long baseRealtime) { |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1672 | recomputeLastDuration(elapsedRealtime, false); |
| 1673 | mInDischarge = true; |
| 1674 | // If we are still within the last added duration, then re-added whatever remains. |
| 1675 | if (mLastAddedTime == elapsedRealtime) { |
| 1676 | mTotalTime += mLastAddedDuration; |
| 1677 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1678 | super.onTimeStarted(elapsedRealtime, baseUptime, baseRealtime); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1679 | } |
| 1680 | |
| 1681 | @Override |
| 1682 | public void logState(Printer pw, String prefix) { |
| 1683 | super.logState(pw, prefix); |
| 1684 | pw.println(prefix + "mLastAddedTime=" + mLastAddedTime |
| 1685 | + " mLastAddedDuration=" + mLastAddedDuration); |
| 1686 | } |
| 1687 | |
| 1688 | private long computeOverage(long curTime) { |
| 1689 | if (mLastAddedTime > 0) { |
| 1690 | return mLastTime + mLastAddedDuration - curTime; |
| 1691 | } |
| 1692 | return 0; |
| 1693 | } |
| 1694 | |
| 1695 | private void recomputeLastDuration(long curTime, boolean abort) { |
| 1696 | final long overage = computeOverage(curTime); |
| 1697 | if (overage > 0) { |
| 1698 | // Aborting before the duration ran out -- roll back the remaining |
| 1699 | // duration. Only do this if currently discharging; otherwise we didn't |
| 1700 | // actually add the time. |
| 1701 | if (mInDischarge) { |
| 1702 | mTotalTime -= overage; |
| 1703 | } |
| 1704 | if (abort) { |
| 1705 | mLastAddedTime = 0; |
| 1706 | } else { |
| 1707 | mLastAddedTime = curTime; |
| 1708 | mLastAddedDuration -= overage; |
| 1709 | } |
| 1710 | } |
| 1711 | } |
| 1712 | |
| 1713 | public void addDuration(BatteryStatsImpl stats, long durationMillis) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1714 | final long now = mClocks.elapsedRealtime() * 1000; |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1715 | recomputeLastDuration(now, true); |
| 1716 | mLastAddedTime = now; |
| 1717 | mLastAddedDuration = durationMillis * 1000; |
| 1718 | if (mInDischarge) { |
| 1719 | mTotalTime += mLastAddedDuration; |
| 1720 | mCount++; |
| 1721 | } |
| 1722 | } |
| 1723 | |
| 1724 | public void abortLastDuration(BatteryStatsImpl stats) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1725 | final long now = mClocks.elapsedRealtime() * 1000; |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1726 | recomputeLastDuration(now, true); |
| 1727 | } |
| 1728 | |
| 1729 | @Override |
| 1730 | protected int computeCurrentCountLocked() { |
| 1731 | return mCount; |
| 1732 | } |
| 1733 | |
| 1734 | @Override |
| 1735 | protected long computeRunTimeLocked(long curBatteryRealtime) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1736 | final long overage = computeOverage(mClocks.elapsedRealtime() * 1000); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1737 | if (overage > 0) { |
| 1738 | return mTotalTime = overage; |
| 1739 | } |
| 1740 | return mTotalTime; |
| 1741 | } |
| 1742 | |
| 1743 | @Override |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1744 | public boolean reset(boolean detachIfReset) { |
| 1745 | final long now = mClocks.elapsedRealtime() * 1000; |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1746 | recomputeLastDuration(now, true); |
| 1747 | boolean stillActive = mLastAddedTime == now; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1748 | super.reset(!stillActive && detachIfReset); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1749 | return !stillActive; |
| 1750 | } |
| 1751 | } |
| 1752 | |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 1753 | |
| 1754 | /** |
| 1755 | * A StopwatchTimer that also tracks the total and max individual |
| 1756 | * time spent active according to the given timebase. Whereas |
| 1757 | * StopwatchTimer apportions the time amongst all in the pool, |
| 1758 | * the total and max durations are not apportioned. |
| 1759 | */ |
| 1760 | public static class DurationTimer extends StopwatchTimer { |
| 1761 | /** |
| 1762 | * The time (in ms) that the timer was last acquired or the time base |
| 1763 | * last (re-)started. Increasing the nesting depth does not reset this time. |
| 1764 | * |
| 1765 | * -1 if the timer is currently not running or the time base is not running. |
| 1766 | * |
| 1767 | * If written to a parcel, the start time is reset, as is mNesting in the base class |
| 1768 | * StopwatchTimer. |
| 1769 | */ |
| 1770 | long mStartTimeMs = -1; |
| 1771 | |
| 1772 | /** |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 1773 | * 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] | 1774 | */ |
| 1775 | long mMaxDurationMs; |
| 1776 | |
| 1777 | /** |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 1778 | * The time (in ms) that that the timer has been active since most recent |
| 1779 | * stopRunningLocked() or reset(). Not pooled. |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 1780 | */ |
| 1781 | long mCurrentDurationMs; |
| 1782 | |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 1783 | /** |
| 1784 | * The total time (in ms) that that the timer has been active since most recent reset() |
| 1785 | * prior to the current startRunningLocked. This is the sum of all past currentDurations |
| 1786 | * (but not including the present currentDuration) since reset. Not pooled. |
| 1787 | */ |
| 1788 | long mTotalDurationMs; |
| 1789 | |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 1790 | public DurationTimer(Clocks clocks, Uid uid, int type, ArrayList<StopwatchTimer> timerPool, |
| 1791 | TimeBase timeBase, Parcel in) { |
| 1792 | super(clocks, uid, type, timerPool, timeBase, in); |
| 1793 | mMaxDurationMs = in.readLong(); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 1794 | mTotalDurationMs = in.readLong(); |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 1795 | } |
| 1796 | |
| 1797 | public DurationTimer(Clocks clocks, Uid uid, int type, ArrayList<StopwatchTimer> timerPool, |
| 1798 | TimeBase timeBase) { |
| 1799 | super(clocks, uid, type, timerPool, timeBase); |
| 1800 | } |
| 1801 | |
| 1802 | @Override |
| 1803 | public void writeToParcel(Parcel out, long elapsedRealtimeUs) { |
| 1804 | super.writeToParcel(out, elapsedRealtimeUs); |
Kweku Adams | 47db5a8 | 2016-12-09 19:04:50 -0800 | [diff] [blame] | 1805 | out.writeLong(getMaxDurationMsLocked(elapsedRealtimeUs / 1000)); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 1806 | out.writeLong(getTotalDurationMsLocked(elapsedRealtimeUs / 1000)); |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 1807 | } |
| 1808 | |
| 1809 | /** |
| 1810 | * Write the summary to the parcel. |
| 1811 | * |
| 1812 | * Since the time base is probably meaningless after we come back, reading |
| 1813 | * 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] | 1814 | * is the max and total durations. |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 1815 | */ |
| 1816 | @Override |
| 1817 | public void writeSummaryFromParcelLocked(Parcel out, long elapsedRealtimeUs) { |
| 1818 | super.writeSummaryFromParcelLocked(out, elapsedRealtimeUs); |
Kweku Adams | 47db5a8 | 2016-12-09 19:04:50 -0800 | [diff] [blame] | 1819 | out.writeLong(getMaxDurationMsLocked(elapsedRealtimeUs / 1000)); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 1820 | out.writeLong(getTotalDurationMsLocked(elapsedRealtimeUs / 1000)); |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 1821 | } |
| 1822 | |
| 1823 | /** |
| 1824 | * Read the summary parcel. |
| 1825 | * |
| 1826 | * Has the side effect of stopping the timer. |
| 1827 | */ |
| 1828 | @Override |
| 1829 | public void readSummaryFromParcelLocked(Parcel in) { |
| 1830 | super.readSummaryFromParcelLocked(in); |
| 1831 | mMaxDurationMs = in.readLong(); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 1832 | mTotalDurationMs = in.readLong(); |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 1833 | mStartTimeMs = -1; |
| 1834 | mCurrentDurationMs = 0; |
| 1835 | } |
| 1836 | |
| 1837 | /** |
| 1838 | * The TimeBase time started (again). |
| 1839 | * |
| 1840 | * If the timer is also running, store the start time. |
| 1841 | */ |
| 1842 | public void onTimeStarted(long elapsedRealtimeUs, long baseUptime, long baseRealtime) { |
| 1843 | super.onTimeStarted(elapsedRealtimeUs, baseUptime, baseRealtime); |
| 1844 | if (mNesting > 0) { |
Kweku Adams | 47db5a8 | 2016-12-09 19:04:50 -0800 | [diff] [blame] | 1845 | mStartTimeMs = baseRealtime / 1000; |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 1846 | } |
| 1847 | } |
| 1848 | |
| 1849 | /** |
| 1850 | * The TimeBase stopped running. |
| 1851 | * |
| 1852 | * If the timer is running, add the duration into mCurrentDurationMs. |
| 1853 | */ |
| 1854 | @Override |
Kweku Adams | 47db5a8 | 2016-12-09 19:04:50 -0800 | [diff] [blame] | 1855 | public void onTimeStopped(long elapsedRealtimeUs, long baseUptime, long baseRealtimeUs) { |
| 1856 | super.onTimeStopped(elapsedRealtimeUs, baseUptime, baseRealtimeUs); |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 1857 | if (mNesting > 0) { |
Kweku Adams | 47db5a8 | 2016-12-09 19:04:50 -0800 | [diff] [blame] | 1858 | // baseRealtimeUs has already been converted to the timebase's realtime. |
| 1859 | mCurrentDurationMs += (baseRealtimeUs / 1000) - mStartTimeMs; |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 1860 | } |
| 1861 | mStartTimeMs = -1; |
| 1862 | } |
| 1863 | |
| 1864 | @Override |
| 1865 | public void logState(Printer pw, String prefix) { |
| 1866 | super.logState(pw, prefix); |
| 1867 | } |
| 1868 | |
| 1869 | @Override |
| 1870 | public void startRunningLocked(long elapsedRealtimeMs) { |
| 1871 | super.startRunningLocked(elapsedRealtimeMs); |
| 1872 | if (mNesting == 1 && mTimeBase.isRunning()) { |
| 1873 | // Just started |
Kweku Adams | 47db5a8 | 2016-12-09 19:04:50 -0800 | [diff] [blame] | 1874 | mStartTimeMs = mTimeBase.getRealtime(elapsedRealtimeMs * 1000) / 1000; |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 1875 | } |
| 1876 | } |
| 1877 | |
| 1878 | /** |
| 1879 | * Decrements the mNesting ref-count on this timer. |
| 1880 | * |
| 1881 | * If it actually stopped (mNesting went to 0), then possibly update |
| 1882 | * mMaxDuration if the current duration was the longest ever. |
| 1883 | */ |
| 1884 | @Override |
| 1885 | public void stopRunningLocked(long elapsedRealtimeMs) { |
Kweku Adams | 47db5a8 | 2016-12-09 19:04:50 -0800 | [diff] [blame] | 1886 | if (mNesting == 1) { |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 1887 | final long durationMs = getCurrentDurationMsLocked(elapsedRealtimeMs); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 1888 | mTotalDurationMs += durationMs; |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 1889 | if (durationMs > mMaxDurationMs) { |
| 1890 | mMaxDurationMs = durationMs; |
| 1891 | } |
| 1892 | mStartTimeMs = -1; |
| 1893 | mCurrentDurationMs = 0; |
| 1894 | } |
Kweku Adams | 47db5a8 | 2016-12-09 19:04:50 -0800 | [diff] [blame] | 1895 | // super method decrements mNesting, which getCurrentDurationMsLocked relies on, |
| 1896 | // so call super.stopRunningLocked after calling getCurrentDurationMsLocked. |
| 1897 | super.stopRunningLocked(elapsedRealtimeMs); |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 1898 | } |
| 1899 | |
| 1900 | @Override |
| 1901 | public boolean reset(boolean detachIfReset) { |
| 1902 | boolean result = super.reset(detachIfReset); |
| 1903 | mMaxDurationMs = 0; |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 1904 | mTotalDurationMs = 0; |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 1905 | mCurrentDurationMs = 0; |
| 1906 | if (mNesting > 0) { |
| 1907 | mStartTimeMs = mTimeBase.getRealtime(mClocks.elapsedRealtime()*1000) / 1000; |
| 1908 | } else { |
| 1909 | mStartTimeMs = -1; |
| 1910 | } |
| 1911 | return result; |
| 1912 | } |
| 1913 | |
| 1914 | /** |
| 1915 | * Returns the max duration that this timer has ever seen. |
| 1916 | * |
| 1917 | * Note that this time is NOT split between the timers in the timer group that |
| 1918 | * this timer is attached to. It is the TOTAL time. |
| 1919 | */ |
| 1920 | @Override |
| 1921 | public long getMaxDurationMsLocked(long elapsedRealtimeMs) { |
| 1922 | if (mNesting > 0) { |
| 1923 | final long durationMs = getCurrentDurationMsLocked(elapsedRealtimeMs); |
| 1924 | if (durationMs > mMaxDurationMs) { |
| 1925 | return durationMs; |
| 1926 | } |
| 1927 | } |
| 1928 | return mMaxDurationMs; |
| 1929 | } |
| 1930 | |
| 1931 | /** |
| 1932 | * Returns the time since the timer was started. |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 1933 | * Returns 0 if the timer is not currently running. |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 1934 | * |
| 1935 | * Note that this time is NOT split between the timers in the timer group that |
| 1936 | * this timer is attached to. It is the TOTAL time. |
| 1937 | */ |
| 1938 | @Override |
| 1939 | public long getCurrentDurationMsLocked(long elapsedRealtimeMs) { |
| 1940 | long durationMs = mCurrentDurationMs; |
Kweku Adams | 47db5a8 | 2016-12-09 19:04:50 -0800 | [diff] [blame] | 1941 | if (mNesting > 0 && mTimeBase.isRunning()) { |
| 1942 | durationMs += (mTimeBase.getRealtime(elapsedRealtimeMs*1000)/1000) |
| 1943 | - mStartTimeMs; |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 1944 | } |
| 1945 | return durationMs; |
| 1946 | } |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 1947 | |
| 1948 | /** |
| 1949 | * Returns the total cumulative duration that this timer has been on since reset(). |
| 1950 | * If mTimerPool == null, this should be the same |
| 1951 | * as getTotalTimeLocked(elapsedRealtimeMs*1000, STATS_SINCE_CHARGED)/1000. |
| 1952 | * |
| 1953 | * Note that this time is NOT split between the timers in the timer group that |
| 1954 | * this timer is attached to. It is the TOTAL time. For this reason, if mTimerPool != null, |
| 1955 | * the result will not be equivalent to getTotalTimeLocked. |
| 1956 | */ |
| 1957 | @Override |
| 1958 | public long getTotalDurationMsLocked(long elapsedRealtimeMs) { |
| 1959 | return mTotalDurationMs + getCurrentDurationMsLocked(elapsedRealtimeMs); |
| 1960 | } |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 1961 | } |
| 1962 | |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1963 | /** |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1964 | * State for keeping track of timing information. |
| 1965 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1966 | public static class StopwatchTimer extends Timer { |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 1967 | final Uid mUid; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1968 | final ArrayList<StopwatchTimer> mTimerPool; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 1969 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1970 | int mNesting; |
| 1971 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1972 | /** |
| 1973 | * The last time at which we updated the timer. If mNesting is > 0, |
| 1974 | * subtract this from the current battery time to find the amount of |
| 1975 | * time we have been running since we last computed an update. |
| 1976 | */ |
| 1977 | long mUpdateTime; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1978 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1979 | /** |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 1980 | * The total time at which the timer was acquired, to determine if it |
Bookatz | ceebafe | 2017-04-06 11:59:13 -0700 | [diff] [blame] | 1981 | * was actually held for an interesting duration. If time base was not running when timer |
| 1982 | * was acquired, will be -1. |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1983 | */ |
Bookatz | ceebafe | 2017-04-06 11:59:13 -0700 | [diff] [blame] | 1984 | long mAcquireTime = -1; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1985 | |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 1986 | long mTimeout; |
| 1987 | |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 1988 | /** |
| 1989 | * For partial wake locks, keep track of whether we are in the list |
| 1990 | * to consume CPU cycles. |
| 1991 | */ |
| 1992 | boolean mInList; |
| 1993 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1994 | public StopwatchTimer(Clocks clocks, Uid uid, int type, ArrayList<StopwatchTimer> timerPool, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1995 | TimeBase timeBase, Parcel in) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1996 | super(clocks, type, timeBase, in); |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 1997 | mUid = uid; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1998 | mTimerPool = timerPool; |
| 1999 | mUpdateTime = in.readLong(); |
| 2000 | } |
| 2001 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 2002 | public StopwatchTimer(Clocks clocks, Uid uid, int type, ArrayList<StopwatchTimer> timerPool, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2003 | TimeBase timeBase) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 2004 | super(clocks, type, timeBase); |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 2005 | mUid = uid; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2006 | mTimerPool = timerPool; |
| 2007 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2008 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 2009 | public void setTimeout(long timeout) { |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 2010 | mTimeout = timeout; |
| 2011 | } |
| 2012 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2013 | public void writeToParcel(Parcel out, long elapsedRealtimeUs) { |
| 2014 | super.writeToParcel(out, elapsedRealtimeUs); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2015 | out.writeLong(mUpdateTime); |
| 2016 | } |
| 2017 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2018 | public void onTimeStopped(long elapsedRealtime, long baseUptime, long baseRealtime) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2019 | if (mNesting > 0) { |
| 2020 | if (DEBUG && mType < 0) { |
| 2021 | Log.v(TAG, "old mUpdateTime=" + mUpdateTime); |
| 2022 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2023 | super.onTimeStopped(elapsedRealtime, baseUptime, baseRealtime); |
| 2024 | mUpdateTime = baseRealtime; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2025 | if (DEBUG && mType < 0) { |
| 2026 | Log.v(TAG, "new mUpdateTime=" + mUpdateTime); |
| 2027 | } |
| 2028 | } |
| 2029 | } |
| 2030 | |
| 2031 | public void logState(Printer pw, String prefix) { |
| 2032 | super.logState(pw, prefix); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 2033 | pw.println(prefix + "mNesting=" + mNesting + " mUpdateTime=" + mUpdateTime |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2034 | + " mAcquireTime=" + mAcquireTime); |
| 2035 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2036 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 2037 | public void startRunningLocked(long elapsedRealtimeMs) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2038 | if (mNesting++ == 0) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2039 | final long batteryRealtime = mTimeBase.getRealtime(elapsedRealtimeMs * 1000); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 2040 | mUpdateTime = batteryRealtime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2041 | if (mTimerPool != null) { |
| 2042 | // Accumulate time to all currently active timers before adding |
| 2043 | // this new one to the pool. |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2044 | refreshTimersLocked(batteryRealtime, mTimerPool, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2045 | // Add this timer to the active pool |
| 2046 | mTimerPool.add(this); |
| 2047 | } |
Bookatz | ceebafe | 2017-04-06 11:59:13 -0700 | [diff] [blame] | 2048 | if (mTimeBase.isRunning()) { |
| 2049 | // Increment the count |
| 2050 | mCount++; |
| 2051 | mAcquireTime = mTotalTime; |
| 2052 | } else { |
| 2053 | mAcquireTime = -1; |
| 2054 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2055 | if (DEBUG && mType < 0) { |
| 2056 | Log.v(TAG, "start #" + mType + ": mUpdateTime=" + mUpdateTime |
| 2057 | + " mTotalTime=" + mTotalTime + " mCount=" + mCount |
| 2058 | + " mAcquireTime=" + mAcquireTime); |
| 2059 | } |
| 2060 | } |
| 2061 | } |
| 2062 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 2063 | public boolean isRunningLocked() { |
Amith Yamasani | 32dbefd | 2009-06-19 09:21:17 -0700 | [diff] [blame] | 2064 | return mNesting > 0; |
| 2065 | } |
| 2066 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 2067 | public void stopRunningLocked(long elapsedRealtimeMs) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2068 | // Ignore attempt to stop a timer that isn't running |
| 2069 | if (mNesting == 0) { |
| 2070 | return; |
| 2071 | } |
| 2072 | if (--mNesting == 0) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2073 | final long batteryRealtime = mTimeBase.getRealtime(elapsedRealtimeMs * 1000); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2074 | if (mTimerPool != null) { |
| 2075 | // Accumulate time to all active counters, scaled by the total |
| 2076 | // active in the pool, before taking this one out of the pool. |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2077 | refreshTimersLocked(batteryRealtime, mTimerPool, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2078 | // Remove this timer from the active pool |
| 2079 | mTimerPool.remove(this); |
| 2080 | } else { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2081 | mNesting = 1; |
| 2082 | mTotalTime = computeRunTimeLocked(batteryRealtime); |
| 2083 | mNesting = 0; |
| 2084 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2085 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2086 | if (DEBUG && mType < 0) { |
| 2087 | Log.v(TAG, "stop #" + mType + ": mUpdateTime=" + mUpdateTime |
| 2088 | + " mTotalTime=" + mTotalTime + " mCount=" + mCount |
| 2089 | + " mAcquireTime=" + mAcquireTime); |
| 2090 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2091 | |
Bookatz | ceebafe | 2017-04-06 11:59:13 -0700 | [diff] [blame] | 2092 | if (mAcquireTime >= 0 && mTotalTime == mAcquireTime) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2093 | // If there was no change in the time, then discard this |
| 2094 | // count. A somewhat cheezy strategy, but hey. |
| 2095 | mCount--; |
| 2096 | } |
| 2097 | } |
| 2098 | } |
| 2099 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 2100 | public void stopAllRunningLocked(long elapsedRealtimeMs) { |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 2101 | if (mNesting > 0) { |
| 2102 | mNesting = 1; |
| 2103 | stopRunningLocked(elapsedRealtimeMs); |
| 2104 | } |
| 2105 | } |
| 2106 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2107 | // Update the total time for all other running Timers with the same type as this Timer |
| 2108 | // due to a change in timer count |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2109 | private static long refreshTimersLocked(long batteryRealtime, |
| 2110 | final ArrayList<StopwatchTimer> pool, StopwatchTimer self) { |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 2111 | long selfTime = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2112 | final int N = pool.size(); |
| 2113 | for (int i=N-1; i>= 0; i--) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2114 | final StopwatchTimer t = pool.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2115 | long heldTime = batteryRealtime - t.mUpdateTime; |
| 2116 | if (heldTime > 0) { |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 2117 | final long myTime = heldTime / N; |
| 2118 | if (t == self) { |
| 2119 | selfTime = myTime; |
| 2120 | } |
| 2121 | t.mTotalTime += myTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2122 | } |
| 2123 | t.mUpdateTime = batteryRealtime; |
| 2124 | } |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 2125 | return selfTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2126 | } |
| 2127 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2128 | @Override |
| 2129 | protected long computeRunTimeLocked(long curBatteryRealtime) { |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 2130 | if (mTimeout > 0 && curBatteryRealtime > mUpdateTime + mTimeout) { |
| 2131 | curBatteryRealtime = mUpdateTime + mTimeout; |
| 2132 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2133 | return mTotalTime + (mNesting > 0 |
| 2134 | ? (curBatteryRealtime - mUpdateTime) |
| 2135 | / (mTimerPool != null ? mTimerPool.size() : 1) |
| 2136 | : 0); |
| 2137 | } |
| 2138 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2139 | @Override |
| 2140 | protected int computeCurrentCountLocked() { |
| 2141 | return mCount; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2142 | } |
| 2143 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 2144 | @Override |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 2145 | public boolean reset(boolean detachIfReset) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2146 | boolean canDetach = mNesting <= 0; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2147 | super.reset(canDetach && detachIfReset); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2148 | if (mNesting > 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 2149 | mUpdateTime = mTimeBase.getRealtime(mClocks.elapsedRealtime() * 1000); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2150 | } |
Bookatz | ceebafe | 2017-04-06 11:59:13 -0700 | [diff] [blame] | 2151 | 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] | 2152 | return canDetach; |
| 2153 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2154 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 2155 | @Override |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 2156 | public void detach() { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2157 | super.detach(); |
| 2158 | if (mTimerPool != null) { |
| 2159 | mTimerPool.remove(this); |
| 2160 | } |
| 2161 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2162 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 2163 | @Override |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 2164 | public void readSummaryFromParcelLocked(Parcel in) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2165 | super.readSummaryFromParcelLocked(in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2166 | mNesting = 0; |
| 2167 | } |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 2168 | |
| 2169 | /** |
| 2170 | * Set the mark so that we can query later for the total time the timer has |
| 2171 | * accumulated since this point. The timer can be running or not. |
| 2172 | * |
| 2173 | * @param elapsedRealtimeMs the current elapsed realtime in milliseconds. |
| 2174 | */ |
| 2175 | public void setMark(long elapsedRealtimeMs) { |
| 2176 | final long batteryRealtime = mTimeBase.getRealtime(elapsedRealtimeMs * 1000); |
| 2177 | if (mNesting > 0) { |
| 2178 | // We are running. |
| 2179 | if (mTimerPool != null) { |
| 2180 | refreshTimersLocked(batteryRealtime, mTimerPool, this); |
| 2181 | } else { |
| 2182 | mTotalTime += batteryRealtime - mUpdateTime; |
| 2183 | mUpdateTime = batteryRealtime; |
| 2184 | } |
| 2185 | } |
| 2186 | mTimeBeforeMark = mTotalTime; |
| 2187 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2188 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2189 | |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2190 | /** |
| 2191 | * State for keeping track of two DurationTimers with different TimeBases, presumably where one |
| 2192 | * TimeBase is effectively a subset of the other. |
| 2193 | */ |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 2194 | public static class DualTimer extends DurationTimer { |
| 2195 | // This class both is a DurationTimer and also holds a second DurationTimer. |
| 2196 | // The main timer (this) typically tracks the total time. It may be pooled (but since it's a |
| 2197 | // durationTimer, it also has the unpooled getTotalDurationMsLocked() for |
| 2198 | // STATS_SINCE_CHARGED). |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2199 | // mSubTimer typically tracks only part of the total time, such as background time, as |
| 2200 | // determined by a subTimeBase. It is NOT pooled. |
| 2201 | private final DurationTimer mSubTimer; |
| 2202 | |
| 2203 | /** |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 2204 | * Creates a DualTimer to hold a main timer (this) and a mSubTimer. |
| 2205 | * The main timer (this) is based on the given timeBase and timerPool. |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2206 | * 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] | 2207 | * the main timer is. |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2208 | */ |
| 2209 | public DualTimer(Clocks clocks, Uid uid, int type, ArrayList<StopwatchTimer> timerPool, |
| 2210 | TimeBase timeBase, TimeBase subTimeBase, Parcel in) { |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 2211 | super(clocks, uid, type, timerPool, timeBase, in); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2212 | mSubTimer = new DurationTimer(clocks, uid, type, null, subTimeBase, in); |
| 2213 | } |
| 2214 | |
| 2215 | /** |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 2216 | * Creates a DualTimer to hold a main timer (this) and a mSubTimer. |
| 2217 | * The main timer (this) is based on the given timeBase and timerPool. |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2218 | * 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] | 2219 | * the main timer is. |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2220 | */ |
| 2221 | public DualTimer(Clocks clocks, Uid uid, int type, ArrayList<StopwatchTimer> timerPool, |
| 2222 | TimeBase timeBase, TimeBase subTimeBase) { |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 2223 | super(clocks, uid, type, timerPool, timeBase); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2224 | mSubTimer = new DurationTimer(clocks, uid, type, null, subTimeBase); |
| 2225 | } |
| 2226 | |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2227 | /** Get the secondary timer. */ |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 2228 | @Override |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2229 | public DurationTimer getSubTimer() { |
| 2230 | return mSubTimer; |
| 2231 | } |
| 2232 | |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 2233 | @Override |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2234 | public void startRunningLocked(long elapsedRealtimeMs) { |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 2235 | super.startRunningLocked(elapsedRealtimeMs); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2236 | mSubTimer.startRunningLocked(elapsedRealtimeMs); |
| 2237 | } |
| 2238 | |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 2239 | @Override |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2240 | public void stopRunningLocked(long elapsedRealtimeMs) { |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 2241 | super.stopRunningLocked(elapsedRealtimeMs); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2242 | mSubTimer.stopRunningLocked(elapsedRealtimeMs); |
| 2243 | } |
| 2244 | |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 2245 | @Override |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2246 | public void stopAllRunningLocked(long elapsedRealtimeMs) { |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 2247 | super.stopAllRunningLocked(elapsedRealtimeMs); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2248 | mSubTimer.stopAllRunningLocked(elapsedRealtimeMs); |
| 2249 | } |
| 2250 | |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 2251 | @Override |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2252 | public boolean reset(boolean detachIfReset) { |
| 2253 | boolean active = false; |
Bookatz | 4a3eda9 | 2017-04-10 13:10:46 -0700 | [diff] [blame] | 2254 | // Do not detach the subTimer explicitly since that'll be done by DualTimer.detach(). |
| 2255 | active |= !mSubTimer.reset(false); |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 2256 | active |= !super.reset(detachIfReset); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2257 | return !active; |
| 2258 | } |
| 2259 | |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 2260 | @Override |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2261 | public void detach() { |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2262 | mSubTimer.detach(); |
Bookatz | 4a3eda9 | 2017-04-10 13:10:46 -0700 | [diff] [blame] | 2263 | super.detach(); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2264 | } |
| 2265 | |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 2266 | @Override |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2267 | public void writeToParcel(Parcel out, long elapsedRealtimeUs) { |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 2268 | super.writeToParcel(out, elapsedRealtimeUs); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2269 | mSubTimer.writeToParcel(out, elapsedRealtimeUs); |
| 2270 | } |
| 2271 | |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 2272 | @Override |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2273 | public void writeSummaryFromParcelLocked(Parcel out, long elapsedRealtimeUs) { |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 2274 | super.writeSummaryFromParcelLocked(out, elapsedRealtimeUs); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2275 | mSubTimer.writeSummaryFromParcelLocked(out, elapsedRealtimeUs); |
| 2276 | } |
| 2277 | |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 2278 | @Override |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2279 | public void readSummaryFromParcelLocked(Parcel in) { |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 2280 | super.readSummaryFromParcelLocked(in); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 2281 | mSubTimer.readSummaryFromParcelLocked(in); |
| 2282 | } |
| 2283 | } |
| 2284 | |
| 2285 | |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 2286 | public abstract class OverflowArrayMap<T> { |
| 2287 | private static final String OVERFLOW_NAME = "*overflow*"; |
| 2288 | |
Dianne Hackborn | 657153b | 2016-07-29 14:54:14 -0700 | [diff] [blame] | 2289 | final int mUid; |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 2290 | final ArrayMap<String, T> mMap = new ArrayMap<>(); |
| 2291 | T mCurOverflow; |
| 2292 | ArrayMap<String, MutableInt> mActiveOverflow; |
Dianne Hackborn | 657153b | 2016-07-29 14:54:14 -0700 | [diff] [blame] | 2293 | long mLastOverflowTime; |
| 2294 | long mLastOverflowFinishTime; |
| 2295 | long mLastClearTime; |
| 2296 | long mLastCleanupTime; |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 2297 | |
Dianne Hackborn | 657153b | 2016-07-29 14:54:14 -0700 | [diff] [blame] | 2298 | public OverflowArrayMap(int uid) { |
| 2299 | mUid = uid; |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 2300 | } |
| 2301 | |
| 2302 | public ArrayMap<String, T> getMap() { |
| 2303 | return mMap; |
| 2304 | } |
| 2305 | |
| 2306 | public void clear() { |
Dianne Hackborn | 657153b | 2016-07-29 14:54:14 -0700 | [diff] [blame] | 2307 | mLastClearTime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 2308 | mMap.clear(); |
| 2309 | mCurOverflow = null; |
| 2310 | mActiveOverflow = null; |
| 2311 | } |
| 2312 | |
| 2313 | public void add(String name, T obj) { |
Joe Onorato | 388fc33 | 2016-04-12 17:06:47 -0700 | [diff] [blame] | 2314 | if (name == null) { |
| 2315 | name = ""; |
| 2316 | } |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 2317 | mMap.put(name, obj); |
| 2318 | if (OVERFLOW_NAME.equals(name)) { |
| 2319 | mCurOverflow = obj; |
| 2320 | } |
| 2321 | } |
| 2322 | |
| 2323 | public void cleanup() { |
Dianne Hackborn | 657153b | 2016-07-29 14:54:14 -0700 | [diff] [blame] | 2324 | mLastCleanupTime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 2325 | if (mActiveOverflow != null) { |
| 2326 | if (mActiveOverflow.size() == 0) { |
| 2327 | mActiveOverflow = null; |
| 2328 | } |
| 2329 | } |
| 2330 | if (mActiveOverflow == null) { |
| 2331 | // There is no currently active overflow, so we should no longer have |
| 2332 | // an overflow entry. |
| 2333 | if (mMap.containsKey(OVERFLOW_NAME)) { |
| 2334 | Slog.wtf(TAG, "Cleaning up with no active overflow, but have overflow entry " |
| 2335 | + mMap.get(OVERFLOW_NAME)); |
| 2336 | mMap.remove(OVERFLOW_NAME); |
| 2337 | } |
| 2338 | mCurOverflow = null; |
| 2339 | } else { |
| 2340 | // There is currently active overflow, so we should still have an overflow entry. |
| 2341 | if (mCurOverflow == null || !mMap.containsKey(OVERFLOW_NAME)) { |
| 2342 | Slog.wtf(TAG, "Cleaning up with active overflow, but no overflow entry: cur=" |
| 2343 | + mCurOverflow + " map=" + mMap.get(OVERFLOW_NAME)); |
| 2344 | } |
| 2345 | } |
| 2346 | } |
| 2347 | |
| 2348 | public T startObject(String name) { |
Joe Onorato | 388fc33 | 2016-04-12 17:06:47 -0700 | [diff] [blame] | 2349 | if (name == null) { |
| 2350 | name = ""; |
| 2351 | } |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 2352 | T obj = mMap.get(name); |
| 2353 | if (obj != null) { |
| 2354 | return obj; |
| 2355 | } |
| 2356 | |
| 2357 | // No object exists for the given name, but do we currently have it |
| 2358 | // running as part of the overflow? |
| 2359 | if (mActiveOverflow != null) { |
| 2360 | MutableInt over = mActiveOverflow.get(name); |
| 2361 | if (over != null) { |
| 2362 | // We are already actively counting this name in the overflow object. |
| 2363 | obj = mCurOverflow; |
| 2364 | if (obj == null) { |
| 2365 | // Shouldn't be here, but we'll try to recover. |
| 2366 | Slog.wtf(TAG, "Have active overflow " + name + " but null overflow"); |
| 2367 | obj = mCurOverflow = instantiateObject(); |
| 2368 | mMap.put(OVERFLOW_NAME, obj); |
| 2369 | } |
| 2370 | over.value++; |
| 2371 | return obj; |
| 2372 | } |
| 2373 | } |
| 2374 | |
| 2375 | // No object exists for given name nor in the overflow; we need to make |
| 2376 | // a new one. |
| 2377 | final int N = mMap.size(); |
| 2378 | if (N >= MAX_WAKELOCKS_PER_UID) { |
| 2379 | // Went over the limit on number of objects to track; this one goes |
| 2380 | // in to the overflow. |
| 2381 | obj = mCurOverflow; |
| 2382 | if (obj == null) { |
| 2383 | // Need to start overflow now... |
| 2384 | obj = mCurOverflow = instantiateObject(); |
| 2385 | mMap.put(OVERFLOW_NAME, obj); |
| 2386 | } |
| 2387 | if (mActiveOverflow == null) { |
| 2388 | mActiveOverflow = new ArrayMap<>(); |
| 2389 | } |
| 2390 | mActiveOverflow.put(name, new MutableInt(1)); |
Dianne Hackborn | 657153b | 2016-07-29 14:54:14 -0700 | [diff] [blame] | 2391 | mLastOverflowTime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 2392 | return obj; |
| 2393 | } |
| 2394 | |
| 2395 | // Normal case where we just need to make a new object. |
| 2396 | obj = instantiateObject(); |
| 2397 | mMap.put(name, obj); |
| 2398 | return obj; |
| 2399 | } |
| 2400 | |
| 2401 | public T stopObject(String name) { |
Joe Onorato | 388fc33 | 2016-04-12 17:06:47 -0700 | [diff] [blame] | 2402 | if (name == null) { |
| 2403 | name = ""; |
| 2404 | } |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 2405 | T obj = mMap.get(name); |
| 2406 | if (obj != null) { |
| 2407 | return obj; |
| 2408 | } |
| 2409 | |
| 2410 | // No object exists for the given name, but do we currently have it |
| 2411 | // running as part of the overflow? |
| 2412 | if (mActiveOverflow != null) { |
| 2413 | MutableInt over = mActiveOverflow.get(name); |
| 2414 | if (over != null) { |
| 2415 | // We are already actively counting this name in the overflow object. |
| 2416 | obj = mCurOverflow; |
| 2417 | if (obj != null) { |
| 2418 | over.value--; |
| 2419 | if (over.value <= 0) { |
| 2420 | mActiveOverflow.remove(name); |
Dianne Hackborn | 657153b | 2016-07-29 14:54:14 -0700 | [diff] [blame] | 2421 | mLastOverflowFinishTime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 2422 | } |
| 2423 | return obj; |
| 2424 | } |
| 2425 | } |
| 2426 | } |
| 2427 | |
| 2428 | // Huh, they are stopping an active operation but we can't find one! |
| 2429 | // That's not good. |
Dianne Hackborn | 657153b | 2016-07-29 14:54:14 -0700 | [diff] [blame] | 2430 | StringBuilder sb = new StringBuilder(); |
| 2431 | sb.append("Unable to find object for "); |
| 2432 | sb.append(name); |
| 2433 | sb.append(" in uid "); |
| 2434 | sb.append(mUid); |
| 2435 | sb.append(" mapsize="); |
| 2436 | sb.append(mMap.size()); |
| 2437 | sb.append(" activeoverflow="); |
| 2438 | sb.append(mActiveOverflow); |
| 2439 | sb.append(" curoverflow="); |
| 2440 | sb.append(mCurOverflow); |
| 2441 | long now = SystemClock.elapsedRealtime(); |
| 2442 | if (mLastOverflowTime != 0) { |
| 2443 | sb.append(" lastOverflowTime="); |
| 2444 | TimeUtils.formatDuration(mLastOverflowTime-now, sb); |
| 2445 | } |
| 2446 | if (mLastOverflowFinishTime != 0) { |
| 2447 | sb.append(" lastOverflowFinishTime="); |
| 2448 | TimeUtils.formatDuration(mLastOverflowFinishTime-now, sb); |
| 2449 | } |
| 2450 | if (mLastClearTime != 0) { |
| 2451 | sb.append(" lastClearTime="); |
| 2452 | TimeUtils.formatDuration(mLastClearTime-now, sb); |
| 2453 | } |
| 2454 | if (mLastCleanupTime != 0) { |
| 2455 | sb.append(" lastCleanupTime="); |
| 2456 | TimeUtils.formatDuration(mLastCleanupTime-now, sb); |
| 2457 | } |
| 2458 | Slog.wtf(TAG, sb.toString()); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 2459 | return null; |
| 2460 | } |
| 2461 | |
| 2462 | public abstract T instantiateObject(); |
| 2463 | } |
| 2464 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 2465 | public static class ControllerActivityCounterImpl extends ControllerActivityCounter |
| 2466 | implements Parcelable { |
| 2467 | private final LongSamplingCounter mIdleTimeMillis; |
| 2468 | private final LongSamplingCounter mRxTimeMillis; |
| 2469 | private final LongSamplingCounter[] mTxTimeMillis; |
| 2470 | private final LongSamplingCounter mPowerDrainMaMs; |
| 2471 | |
| 2472 | public ControllerActivityCounterImpl(TimeBase timeBase, int numTxStates) { |
| 2473 | mIdleTimeMillis = new LongSamplingCounter(timeBase); |
| 2474 | mRxTimeMillis = new LongSamplingCounter(timeBase); |
| 2475 | mTxTimeMillis = new LongSamplingCounter[numTxStates]; |
| 2476 | for (int i = 0; i < numTxStates; i++) { |
| 2477 | mTxTimeMillis[i] = new LongSamplingCounter(timeBase); |
| 2478 | } |
| 2479 | mPowerDrainMaMs = new LongSamplingCounter(timeBase); |
| 2480 | } |
| 2481 | |
| 2482 | public ControllerActivityCounterImpl(TimeBase timeBase, int numTxStates, Parcel in) { |
| 2483 | mIdleTimeMillis = new LongSamplingCounter(timeBase, in); |
| 2484 | mRxTimeMillis = new LongSamplingCounter(timeBase, in); |
| 2485 | final int recordedTxStates = in.readInt(); |
| 2486 | if (recordedTxStates != numTxStates) { |
| 2487 | throw new ParcelFormatException("inconsistent tx state lengths"); |
| 2488 | } |
| 2489 | |
| 2490 | mTxTimeMillis = new LongSamplingCounter[numTxStates]; |
| 2491 | for (int i = 0; i < numTxStates; i++) { |
| 2492 | mTxTimeMillis[i] = new LongSamplingCounter(timeBase, in); |
| 2493 | } |
| 2494 | mPowerDrainMaMs = new LongSamplingCounter(timeBase, in); |
| 2495 | } |
| 2496 | |
| 2497 | public void readSummaryFromParcel(Parcel in) { |
| 2498 | mIdleTimeMillis.readSummaryFromParcelLocked(in); |
| 2499 | mRxTimeMillis.readSummaryFromParcelLocked(in); |
| 2500 | final int recordedTxStates = in.readInt(); |
| 2501 | if (recordedTxStates != mTxTimeMillis.length) { |
| 2502 | throw new ParcelFormatException("inconsistent tx state lengths"); |
| 2503 | } |
| 2504 | for (LongSamplingCounter counter : mTxTimeMillis) { |
| 2505 | counter.readSummaryFromParcelLocked(in); |
| 2506 | } |
| 2507 | mPowerDrainMaMs.readSummaryFromParcelLocked(in); |
| 2508 | } |
| 2509 | |
| 2510 | @Override |
| 2511 | public int describeContents() { |
| 2512 | return 0; |
| 2513 | } |
| 2514 | |
| 2515 | public void writeSummaryToParcel(Parcel dest) { |
| 2516 | mIdleTimeMillis.writeSummaryFromParcelLocked(dest); |
| 2517 | mRxTimeMillis.writeSummaryFromParcelLocked(dest); |
| 2518 | dest.writeInt(mTxTimeMillis.length); |
| 2519 | for (LongSamplingCounter counter : mTxTimeMillis) { |
| 2520 | counter.writeSummaryFromParcelLocked(dest); |
| 2521 | } |
| 2522 | mPowerDrainMaMs.writeSummaryFromParcelLocked(dest); |
| 2523 | } |
| 2524 | |
| 2525 | @Override |
| 2526 | public void writeToParcel(Parcel dest, int flags) { |
| 2527 | mIdleTimeMillis.writeToParcel(dest); |
| 2528 | mRxTimeMillis.writeToParcel(dest); |
| 2529 | dest.writeInt(mTxTimeMillis.length); |
| 2530 | for (LongSamplingCounter counter : mTxTimeMillis) { |
| 2531 | counter.writeToParcel(dest); |
| 2532 | } |
| 2533 | mPowerDrainMaMs.writeToParcel(dest); |
| 2534 | } |
| 2535 | |
| 2536 | public void reset(boolean detachIfReset) { |
| 2537 | mIdleTimeMillis.reset(detachIfReset); |
| 2538 | mRxTimeMillis.reset(detachIfReset); |
| 2539 | for (LongSamplingCounter counter : mTxTimeMillis) { |
| 2540 | counter.reset(detachIfReset); |
| 2541 | } |
| 2542 | mPowerDrainMaMs.reset(detachIfReset); |
| 2543 | } |
| 2544 | |
| 2545 | public void detach() { |
| 2546 | mIdleTimeMillis.detach(); |
| 2547 | mRxTimeMillis.detach(); |
| 2548 | for (LongSamplingCounter counter : mTxTimeMillis) { |
| 2549 | counter.detach(); |
| 2550 | } |
| 2551 | mPowerDrainMaMs.detach(); |
| 2552 | } |
| 2553 | |
| 2554 | /** |
| 2555 | * @return a LongSamplingCounter, measuring time spent in the idle state in |
| 2556 | * milliseconds. |
| 2557 | */ |
| 2558 | @Override |
| 2559 | public LongSamplingCounter getIdleTimeCounter() { |
Roshan Pius | 8164330 | 2016-03-14 16:45:55 -0700 | [diff] [blame] | 2560 | return mIdleTimeMillis; |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 2561 | } |
| 2562 | |
| 2563 | /** |
| 2564 | * @return a LongSamplingCounter, measuring time spent in the receive state in |
| 2565 | * milliseconds. |
| 2566 | */ |
| 2567 | @Override |
| 2568 | public LongSamplingCounter getRxTimeCounter() { |
| 2569 | return mRxTimeMillis; |
| 2570 | } |
| 2571 | |
| 2572 | /** |
| 2573 | * @return a LongSamplingCounter[], measuring time spent in various transmit states in |
| 2574 | * milliseconds. |
| 2575 | */ |
| 2576 | @Override |
| 2577 | public LongSamplingCounter[] getTxTimeCounters() { |
| 2578 | return mTxTimeMillis; |
| 2579 | } |
| 2580 | |
| 2581 | /** |
| 2582 | * @return a LongSamplingCounter, measuring power use in milli-ampere milliseconds (mAmS). |
| 2583 | */ |
| 2584 | @Override |
| 2585 | public LongSamplingCounter getPowerCounter() { |
| 2586 | return mPowerDrainMaMs; |
| 2587 | } |
| 2588 | } |
| 2589 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2590 | /* |
| 2591 | * Get the wakeup reason counter, and create a new one if one |
| 2592 | * doesn't already exist. |
| 2593 | */ |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 2594 | public SamplingTimer getWakeupReasonTimerLocked(String name) { |
| 2595 | SamplingTimer timer = mWakeupReasonStats.get(name); |
| 2596 | if (timer == null) { |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 2597 | timer = new SamplingTimer(mClocks, mOnBatteryTimeBase); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 2598 | mWakeupReasonStats.put(name, timer); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2599 | } |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 2600 | return timer; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2601 | } |
| 2602 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2603 | /* |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2604 | * 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] | 2605 | * doesn't already exist. |
| 2606 | */ |
| 2607 | public SamplingTimer getKernelWakelockTimerLocked(String name) { |
| 2608 | SamplingTimer kwlt = mKernelWakelockStats.get(name); |
| 2609 | if (kwlt == null) { |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 2610 | kwlt = new SamplingTimer(mClocks, mOnBatteryScreenOffTimeBase); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2611 | mKernelWakelockStats.put(name, kwlt); |
| 2612 | } |
| 2613 | return kwlt; |
| 2614 | } |
Amith Yamasani | 3718aaa | 2009-06-09 06:32:35 -0700 | [diff] [blame] | 2615 | |
James Carr | 3a22605 | 2016-07-01 14:49:52 -0700 | [diff] [blame] | 2616 | public SamplingTimer getKernelMemoryTimerLocked(long bucket) { |
| 2617 | SamplingTimer kmt = mKernelMemoryStats.get(bucket); |
| 2618 | if (kmt == null) { |
| 2619 | kmt = new SamplingTimer(mClocks, mOnBatteryTimeBase); |
| 2620 | mKernelMemoryStats.put(bucket, kmt); |
| 2621 | } |
| 2622 | return kmt; |
| 2623 | } |
| 2624 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2625 | private int writeHistoryTag(HistoryTag tag) { |
| 2626 | Integer idxObj = mHistoryTagPool.get(tag); |
| 2627 | int idx; |
| 2628 | if (idxObj != null) { |
| 2629 | idx = idxObj; |
| 2630 | } else { |
| 2631 | idx = mNextHistoryTagIdx; |
| 2632 | HistoryTag key = new HistoryTag(); |
| 2633 | key.setTo(tag); |
| 2634 | tag.poolIdx = idx; |
| 2635 | mHistoryTagPool.put(key, idx); |
| 2636 | mNextHistoryTagIdx++; |
| 2637 | mNumHistoryTagChars += key.string.length() + 1; |
| 2638 | } |
| 2639 | return idx; |
| 2640 | } |
| 2641 | |
| 2642 | private void readHistoryTag(int index, HistoryTag tag) { |
| 2643 | tag.string = mReadHistoryStrings[index]; |
| 2644 | tag.uid = mReadHistoryUids[index]; |
| 2645 | tag.poolIdx = index; |
| 2646 | } |
| 2647 | |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 2648 | /* |
| 2649 | The history delta format uses flags to denote further data in subsequent ints in the parcel. |
| 2650 | |
| 2651 | There is always the first token, which may contain the delta time, or an indicator of |
| 2652 | the length of the time (int or long) following this token. |
| 2653 | |
| 2654 | First token: always present, |
| 2655 | 31 23 15 7 0 |
| 2656 | â–ˆ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â–ˆ |
| 2657 | |
| 2658 | T: the delta time if it is <= 0x7fffd. Otherwise 0x7fffe indicates an int immediately |
| 2659 | follows containing the time, and 0x7ffff indicates a long immediately follows with the |
| 2660 | delta time. |
| 2661 | A: battery level changed and an int follows with battery data. |
| 2662 | B: state changed and an int follows with state change data. |
| 2663 | C: state2 has changed and an int follows with state2 change data. |
| 2664 | D: wakelock/wakereason has changed and an wakelock/wakereason struct follows. |
| 2665 | E: event data has changed and an event struct follows. |
| 2666 | F: battery charge in coulombs has changed and an int with the charge follows. |
| 2667 | G: state flag denoting that the mobile radio was active. |
| 2668 | H: state flag denoting that the wifi radio was active. |
| 2669 | I: state flag denoting that a wifi scan occurred. |
| 2670 | J: state flag denoting that a wifi full lock was held. |
| 2671 | K: state flag denoting that the gps was on. |
| 2672 | L: state flag denoting that a wakelock was held. |
| 2673 | M: state flag denoting that the cpu was running. |
| 2674 | |
| 2675 | Time int/long: if T in the first token is 0x7ffff or 0x7fffe, then an int or long follows |
| 2676 | with the time delta. |
| 2677 | |
| 2678 | Battery level int: if A in the first token is set, |
| 2679 | 31 23 15 7 0 |
| 2680 | â–ˆ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â–ˆ |
| 2681 | |
| 2682 | D: indicates that extra history details follow. |
| 2683 | V: the battery voltage. |
| 2684 | T: the battery temperature. |
| 2685 | L: the battery level (out of 100). |
| 2686 | |
| 2687 | State change int: if B in the first token is set, |
| 2688 | 31 23 15 7 0 |
| 2689 | â–ˆS|S|S|H|H|H|P|Pâ–ˆF|E|D|C|B| | |Aâ–ˆ | | | | | | | â–ˆ | | | | | | | â–ˆ |
| 2690 | |
| 2691 | A: wifi multicast was on. |
| 2692 | B: battery was plugged in. |
| 2693 | C: screen was on. |
| 2694 | D: phone was scanning for signal. |
| 2695 | E: audio was on. |
| 2696 | F: a sensor was active. |
| 2697 | |
| 2698 | State2 change int: if C in the first token is set, |
| 2699 | 31 23 15 7 0 |
| 2700 | â–ˆM|L|K|J|I|H|H|Gâ–ˆF|E|D|C| | | | â–ˆ | | | | | | | â–ˆ |B|B|B|A|A|A|Aâ–ˆ |
| 2701 | |
| 2702 | A: 4 bits indicating the wifi supplicant state: {@link BatteryStats#WIFI_SUPPL_STATE_NAMES}. |
| 2703 | B: 3 bits indicating the wifi signal strength: 0, 1, 2, 3, 4. |
| 2704 | C: a bluetooth scan was active. |
| 2705 | D: the camera was active. |
| 2706 | E: bluetooth was on. |
| 2707 | F: a phone call was active. |
| 2708 | G: the device was charging. |
| 2709 | H: 2 bits indicating the device-idle (doze) state: off, light, full |
| 2710 | I: the flashlight was on. |
| 2711 | J: wifi was on. |
| 2712 | K: wifi was running. |
| 2713 | L: video was playing. |
| 2714 | M: power save mode was on. |
| 2715 | |
| 2716 | Wakelock/wakereason struct: if D in the first token is set, |
| 2717 | TODO(adamlesinski): describe wakelock/wakereason struct. |
| 2718 | |
| 2719 | Event struct: if E in the first token is set, |
| 2720 | TODO(adamlesinski): describe the event struct. |
| 2721 | |
| 2722 | History step details struct: if D in the battery level int is set, |
| 2723 | TODO(adamlesinski): describe the history step details struct. |
| 2724 | |
| 2725 | Battery charge int: if F in the first token is set, an int representing the battery charge |
| 2726 | in coulombs follows. |
| 2727 | */ |
| 2728 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2729 | // Part of initial delta int that specifies the time delta. |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 2730 | static final int DELTA_TIME_MASK = 0x7ffff; |
| 2731 | static final int DELTA_TIME_LONG = 0x7ffff; // The delta is a following long |
| 2732 | static final int DELTA_TIME_INT = 0x7fffe; // The delta is a following int |
| 2733 | 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] | 2734 | // Flag in delta int: a new battery level int follows. |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 2735 | static final int DELTA_BATTERY_LEVEL_FLAG = 0x00080000; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2736 | // 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] | 2737 | static final int DELTA_STATE_FLAG = 0x00100000; |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 2738 | // Flag in delta int: a new full state2 int follows. |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 2739 | static final int DELTA_STATE2_FLAG = 0x00200000; |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 2740 | // Flag in delta int: contains a wakelock or wakeReason tag. |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 2741 | static final int DELTA_WAKELOCK_FLAG = 0x00400000; |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2742 | // Flag in delta int: contains an event description. |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 2743 | static final int DELTA_EVENT_FLAG = 0x00800000; |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 2744 | // Flag in delta int: contains the battery charge count in uAh. |
| 2745 | static final int DELTA_BATTERY_CHARGE_FLAG = 0x01000000; |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2746 | // These upper bits are the frequently changing state bits. |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 2747 | static final int DELTA_STATE_MASK = 0xfe000000; |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 2748 | |
| 2749 | // These are the pieces of battery state that are packed in to the upper bits of |
| 2750 | // 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] | 2751 | // in STATE_BATTERY_MASK. |
| 2752 | static final int STATE_BATTERY_MASK = 0xff000000; |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 2753 | static final int STATE_BATTERY_STATUS_MASK = 0x00000007; |
| 2754 | static final int STATE_BATTERY_STATUS_SHIFT = 29; |
| 2755 | static final int STATE_BATTERY_HEALTH_MASK = 0x00000007; |
| 2756 | static final int STATE_BATTERY_HEALTH_SHIFT = 26; |
| 2757 | static final int STATE_BATTERY_PLUG_MASK = 0x00000003; |
| 2758 | static final int STATE_BATTERY_PLUG_SHIFT = 24; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2759 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 2760 | // We use the low bit of the battery state int to indicate that we have full details |
| 2761 | // from a battery level change. |
| 2762 | static final int BATTERY_DELTA_LEVEL_FLAG = 0x00000001; |
| 2763 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2764 | public void writeHistoryDelta(Parcel dest, HistoryItem cur, HistoryItem last) { |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2765 | if (last == null || cur.cmd != HistoryItem.CMD_UPDATE) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2766 | dest.writeInt(DELTA_TIME_ABS); |
| 2767 | cur.writeToParcel(dest, 0); |
| 2768 | return; |
| 2769 | } |
| 2770 | |
| 2771 | final long deltaTime = cur.time - last.time; |
| 2772 | final int lastBatteryLevelInt = buildBatteryLevelInt(last); |
| 2773 | final int lastStateInt = buildStateInt(last); |
| 2774 | |
| 2775 | int deltaTimeToken; |
| 2776 | if (deltaTime < 0 || deltaTime > Integer.MAX_VALUE) { |
| 2777 | deltaTimeToken = DELTA_TIME_LONG; |
| 2778 | } else if (deltaTime >= DELTA_TIME_ABS) { |
| 2779 | deltaTimeToken = DELTA_TIME_INT; |
| 2780 | } else { |
| 2781 | deltaTimeToken = (int)deltaTime; |
| 2782 | } |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2783 | int firstToken = deltaTimeToken | (cur.states&DELTA_STATE_MASK); |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 2784 | final int includeStepDetails = mLastHistoryStepLevel > cur.batteryLevel |
| 2785 | ? BATTERY_DELTA_LEVEL_FLAG : 0; |
| 2786 | final boolean computeStepDetails = includeStepDetails != 0 |
| 2787 | || mLastHistoryStepDetails == null; |
| 2788 | final int batteryLevelInt = buildBatteryLevelInt(cur) | includeStepDetails; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2789 | final boolean batteryLevelIntChanged = batteryLevelInt != lastBatteryLevelInt; |
| 2790 | if (batteryLevelIntChanged) { |
| 2791 | firstToken |= DELTA_BATTERY_LEVEL_FLAG; |
| 2792 | } |
| 2793 | final int stateInt = buildStateInt(cur); |
| 2794 | final boolean stateIntChanged = stateInt != lastStateInt; |
| 2795 | if (stateIntChanged) { |
| 2796 | firstToken |= DELTA_STATE_FLAG; |
| 2797 | } |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2798 | final boolean state2IntChanged = cur.states2 != last.states2; |
| 2799 | if (state2IntChanged) { |
| 2800 | firstToken |= DELTA_STATE2_FLAG; |
| 2801 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 2802 | if (cur.wakelockTag != null || cur.wakeReasonTag != null) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2803 | firstToken |= DELTA_WAKELOCK_FLAG; |
| 2804 | } |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2805 | if (cur.eventCode != HistoryItem.EVENT_NONE) { |
| 2806 | firstToken |= DELTA_EVENT_FLAG; |
| 2807 | } |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 2808 | |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 2809 | final boolean batteryChargeChanged = cur.batteryChargeUAh != last.batteryChargeUAh; |
| 2810 | if (batteryChargeChanged) { |
| 2811 | firstToken |= DELTA_BATTERY_CHARGE_FLAG; |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 2812 | } |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2813 | dest.writeInt(firstToken); |
| 2814 | if (DEBUG) Slog.i(TAG, "WRITE DELTA: firstToken=0x" + Integer.toHexString(firstToken) |
| 2815 | + " deltaTime=" + deltaTime); |
| 2816 | |
| 2817 | if (deltaTimeToken >= DELTA_TIME_INT) { |
| 2818 | if (deltaTimeToken == DELTA_TIME_INT) { |
| 2819 | if (DEBUG) Slog.i(TAG, "WRITE DELTA: int deltaTime=" + (int)deltaTime); |
| 2820 | dest.writeInt((int)deltaTime); |
| 2821 | } else { |
| 2822 | if (DEBUG) Slog.i(TAG, "WRITE DELTA: long deltaTime=" + deltaTime); |
| 2823 | dest.writeLong(deltaTime); |
| 2824 | } |
| 2825 | } |
| 2826 | if (batteryLevelIntChanged) { |
| 2827 | dest.writeInt(batteryLevelInt); |
| 2828 | if (DEBUG) Slog.i(TAG, "WRITE DELTA: batteryToken=0x" |
| 2829 | + Integer.toHexString(batteryLevelInt) |
| 2830 | + " batteryLevel=" + cur.batteryLevel |
| 2831 | + " batteryTemp=" + cur.batteryTemperature |
| 2832 | + " batteryVolt=" + (int)cur.batteryVoltage); |
| 2833 | } |
| 2834 | if (stateIntChanged) { |
| 2835 | dest.writeInt(stateInt); |
| 2836 | if (DEBUG) Slog.i(TAG, "WRITE DELTA: stateToken=0x" |
| 2837 | + Integer.toHexString(stateInt) |
| 2838 | + " batteryStatus=" + cur.batteryStatus |
| 2839 | + " batteryHealth=" + cur.batteryHealth |
| 2840 | + " batteryPlugType=" + cur.batteryPlugType |
| 2841 | + " states=0x" + Integer.toHexString(cur.states)); |
| 2842 | } |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2843 | if (state2IntChanged) { |
| 2844 | dest.writeInt(cur.states2); |
| 2845 | if (DEBUG) Slog.i(TAG, "WRITE DELTA: states2=0x" |
| 2846 | + Integer.toHexString(cur.states2)); |
| 2847 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 2848 | if (cur.wakelockTag != null || cur.wakeReasonTag != null) { |
| 2849 | int wakeLockIndex; |
| 2850 | int wakeReasonIndex; |
| 2851 | if (cur.wakelockTag != null) { |
| 2852 | wakeLockIndex = writeHistoryTag(cur.wakelockTag); |
| 2853 | if (DEBUG) Slog.i(TAG, "WRITE DELTA: wakelockTag=#" + cur.wakelockTag.poolIdx |
| 2854 | + " " + cur.wakelockTag.uid + ":" + cur.wakelockTag.string); |
| 2855 | } else { |
| 2856 | wakeLockIndex = 0xffff; |
| 2857 | } |
| 2858 | if (cur.wakeReasonTag != null) { |
| 2859 | wakeReasonIndex = writeHistoryTag(cur.wakeReasonTag); |
| 2860 | if (DEBUG) Slog.i(TAG, "WRITE DELTA: wakeReasonTag=#" + cur.wakeReasonTag.poolIdx |
| 2861 | + " " + cur.wakeReasonTag.uid + ":" + cur.wakeReasonTag.string); |
| 2862 | } else { |
| 2863 | wakeReasonIndex = 0xffff; |
| 2864 | } |
| 2865 | dest.writeInt((wakeReasonIndex<<16) | wakeLockIndex); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2866 | } |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2867 | if (cur.eventCode != HistoryItem.EVENT_NONE) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2868 | int index = writeHistoryTag(cur.eventTag); |
| 2869 | int codeAndIndex = (cur.eventCode&0xffff) | (index<<16); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 2870 | dest.writeInt(codeAndIndex); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2871 | if (DEBUG) Slog.i(TAG, "WRITE DELTA: event=" + cur.eventCode + " tag=#" |
| 2872 | + cur.eventTag.poolIdx + " " + cur.eventTag.uid + ":" |
| 2873 | + cur.eventTag.string); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2874 | } |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 2875 | if (computeStepDetails) { |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 2876 | if (mPlatformIdleStateCallback != null) { |
| 2877 | mCurHistoryStepDetails.statPlatformIdleState = |
| 2878 | mPlatformIdleStateCallback.getPlatformLowPowerStats(); |
| 2879 | if (DEBUG) Slog.i(TAG, "WRITE PlatformIdleState:" + |
| 2880 | mCurHistoryStepDetails.statPlatformIdleState); |
| 2881 | } |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 2882 | computeHistoryStepDetails(mCurHistoryStepDetails, mLastHistoryStepDetails); |
| 2883 | if (includeStepDetails != 0) { |
| 2884 | mCurHistoryStepDetails.writeToParcel(dest); |
| 2885 | } |
| 2886 | cur.stepDetails = mCurHistoryStepDetails; |
| 2887 | mLastHistoryStepDetails = mCurHistoryStepDetails; |
| 2888 | } else { |
| 2889 | cur.stepDetails = null; |
| 2890 | } |
| 2891 | if (mLastHistoryStepLevel < cur.batteryLevel) { |
| 2892 | mLastHistoryStepDetails = null; |
| 2893 | } |
| 2894 | mLastHistoryStepLevel = cur.batteryLevel; |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 2895 | |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 2896 | if (batteryChargeChanged) { |
| 2897 | if (DEBUG) Slog.i(TAG, "WRITE DELTA: batteryChargeUAh=" + cur.batteryChargeUAh); |
| 2898 | dest.writeInt(cur.batteryChargeUAh); |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 2899 | } |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2900 | } |
| 2901 | |
| 2902 | private int buildBatteryLevelInt(HistoryItem h) { |
| 2903 | return ((((int)h.batteryLevel)<<25)&0xfe000000) |
Adam Lesinski | 3944c81 | 2015-11-13 15:54:59 -0800 | [diff] [blame] | 2904 | | ((((int)h.batteryTemperature)<<15)&0x01ff8000) |
| 2905 | | ((((int)h.batteryVoltage)<<1)&0x00007ffe); |
| 2906 | } |
| 2907 | |
| 2908 | private void readBatteryLevelInt(int batteryLevelInt, HistoryItem out) { |
| 2909 | out.batteryLevel = (byte)((batteryLevelInt & 0xfe000000) >>> 25); |
| 2910 | out.batteryTemperature = (short)((batteryLevelInt & 0x01ff8000) >>> 15); |
| 2911 | out.batteryVoltage = (char)((batteryLevelInt & 0x00007ffe) >>> 1); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2912 | } |
| 2913 | |
| 2914 | private int buildStateInt(HistoryItem h) { |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 2915 | int plugType = 0; |
| 2916 | if ((h.batteryPlugType&BatteryManager.BATTERY_PLUGGED_AC) != 0) { |
| 2917 | plugType = 1; |
| 2918 | } else if ((h.batteryPlugType&BatteryManager.BATTERY_PLUGGED_USB) != 0) { |
| 2919 | plugType = 2; |
| 2920 | } else if ((h.batteryPlugType&BatteryManager.BATTERY_PLUGGED_WIRELESS) != 0) { |
| 2921 | plugType = 3; |
| 2922 | } |
| 2923 | return ((h.batteryStatus&STATE_BATTERY_STATUS_MASK)<<STATE_BATTERY_STATUS_SHIFT) |
| 2924 | | ((h.batteryHealth&STATE_BATTERY_HEALTH_MASK)<<STATE_BATTERY_HEALTH_SHIFT) |
| 2925 | | ((plugType&STATE_BATTERY_PLUG_MASK)<<STATE_BATTERY_PLUG_SHIFT) |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 2926 | | (h.states&(~STATE_BATTERY_MASK)); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2927 | } |
| 2928 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 2929 | private void computeHistoryStepDetails(final HistoryStepDetails out, |
| 2930 | final HistoryStepDetails last) { |
| 2931 | final HistoryStepDetails tmp = last != null ? mTmpHistoryStepDetails : out; |
| 2932 | |
| 2933 | // Perform a CPU update right after we do this collection, so we have started |
| 2934 | // collecting good data for the next step. |
| 2935 | requestImmediateCpuUpdate(); |
| 2936 | |
| 2937 | if (last == null) { |
| 2938 | // We are not generating a delta, so all we need to do is reset the stats |
| 2939 | // we will later be doing a delta from. |
| 2940 | final int NU = mUidStats.size(); |
| 2941 | for (int i=0; i<NU; i++) { |
| 2942 | final BatteryStatsImpl.Uid uid = mUidStats.valueAt(i); |
| 2943 | uid.mLastStepUserTime = uid.mCurStepUserTime; |
| 2944 | uid.mLastStepSystemTime = uid.mCurStepSystemTime; |
| 2945 | } |
| 2946 | mLastStepCpuUserTime = mCurStepCpuUserTime; |
| 2947 | mLastStepCpuSystemTime = mCurStepCpuSystemTime; |
| 2948 | mLastStepStatUserTime = mCurStepStatUserTime; |
| 2949 | mLastStepStatSystemTime = mCurStepStatSystemTime; |
| 2950 | mLastStepStatIOWaitTime = mCurStepStatIOWaitTime; |
| 2951 | mLastStepStatIrqTime = mCurStepStatIrqTime; |
| 2952 | mLastStepStatSoftIrqTime = mCurStepStatSoftIrqTime; |
| 2953 | mLastStepStatIdleTime = mCurStepStatIdleTime; |
| 2954 | tmp.clear(); |
| 2955 | return; |
| 2956 | } |
| 2957 | if (DEBUG) { |
| 2958 | Slog.d(TAG, "Step stats last: user=" + mLastStepCpuUserTime + " sys=" |
| 2959 | + mLastStepStatSystemTime + " io=" + mLastStepStatIOWaitTime |
| 2960 | + " irq=" + mLastStepStatIrqTime + " sirq=" |
| 2961 | + mLastStepStatSoftIrqTime + " idle=" + mLastStepStatIdleTime); |
| 2962 | Slog.d(TAG, "Step stats cur: user=" + mCurStepCpuUserTime + " sys=" |
| 2963 | + mCurStepStatSystemTime + " io=" + mCurStepStatIOWaitTime |
| 2964 | + " irq=" + mCurStepStatIrqTime + " sirq=" |
| 2965 | + mCurStepStatSoftIrqTime + " idle=" + mCurStepStatIdleTime); |
| 2966 | } |
| 2967 | out.userTime = (int)(mCurStepCpuUserTime - mLastStepCpuUserTime); |
| 2968 | out.systemTime = (int)(mCurStepCpuSystemTime - mLastStepCpuSystemTime); |
| 2969 | out.statUserTime = (int)(mCurStepStatUserTime - mLastStepStatUserTime); |
| 2970 | out.statSystemTime = (int)(mCurStepStatSystemTime - mLastStepStatSystemTime); |
| 2971 | out.statIOWaitTime = (int)(mCurStepStatIOWaitTime - mLastStepStatIOWaitTime); |
| 2972 | out.statIrqTime = (int)(mCurStepStatIrqTime - mLastStepStatIrqTime); |
| 2973 | out.statSoftIrqTime = (int)(mCurStepStatSoftIrqTime - mLastStepStatSoftIrqTime); |
| 2974 | out.statIdlTime = (int)(mCurStepStatIdleTime - mLastStepStatIdleTime); |
| 2975 | out.appCpuUid1 = out.appCpuUid2 = out.appCpuUid3 = -1; |
| 2976 | out.appCpuUTime1 = out.appCpuUTime2 = out.appCpuUTime3 = 0; |
| 2977 | out.appCpuSTime1 = out.appCpuSTime2 = out.appCpuSTime3 = 0; |
| 2978 | final int NU = mUidStats.size(); |
| 2979 | for (int i=0; i<NU; i++) { |
| 2980 | final BatteryStatsImpl.Uid uid = mUidStats.valueAt(i); |
| 2981 | final int totalUTime = (int)(uid.mCurStepUserTime - uid.mLastStepUserTime); |
| 2982 | final int totalSTime = (int)(uid.mCurStepSystemTime - uid.mLastStepSystemTime); |
| 2983 | final int totalTime = totalUTime + totalSTime; |
| 2984 | uid.mLastStepUserTime = uid.mCurStepUserTime; |
| 2985 | uid.mLastStepSystemTime = uid.mCurStepSystemTime; |
| 2986 | if (totalTime <= (out.appCpuUTime3+out.appCpuSTime3)) { |
| 2987 | continue; |
| 2988 | } |
| 2989 | if (totalTime <= (out.appCpuUTime2+out.appCpuSTime2)) { |
| 2990 | out.appCpuUid3 = uid.mUid; |
| 2991 | out.appCpuUTime3 = totalUTime; |
| 2992 | out.appCpuSTime3 = totalSTime; |
| 2993 | } else { |
| 2994 | out.appCpuUid3 = out.appCpuUid2; |
| 2995 | out.appCpuUTime3 = out.appCpuUTime2; |
| 2996 | out.appCpuSTime3 = out.appCpuSTime2; |
| 2997 | if (totalTime <= (out.appCpuUTime1+out.appCpuSTime1)) { |
| 2998 | out.appCpuUid2 = uid.mUid; |
| 2999 | out.appCpuUTime2 = totalUTime; |
| 3000 | out.appCpuSTime2 = totalSTime; |
| 3001 | } else { |
| 3002 | out.appCpuUid2 = out.appCpuUid1; |
| 3003 | out.appCpuUTime2 = out.appCpuUTime1; |
| 3004 | out.appCpuSTime2 = out.appCpuSTime1; |
| 3005 | out.appCpuUid1 = uid.mUid; |
| 3006 | out.appCpuUTime1 = totalUTime; |
| 3007 | out.appCpuSTime1 = totalSTime; |
| 3008 | } |
| 3009 | } |
| 3010 | } |
| 3011 | mLastStepCpuUserTime = mCurStepCpuUserTime; |
| 3012 | mLastStepCpuSystemTime = mCurStepCpuSystemTime; |
| 3013 | mLastStepStatUserTime = mCurStepStatUserTime; |
| 3014 | mLastStepStatSystemTime = mCurStepStatSystemTime; |
| 3015 | mLastStepStatIOWaitTime = mCurStepStatIOWaitTime; |
| 3016 | mLastStepStatIrqTime = mCurStepStatIrqTime; |
| 3017 | mLastStepStatSoftIrqTime = mCurStepStatSoftIrqTime; |
| 3018 | mLastStepStatIdleTime = mCurStepStatIdleTime; |
| 3019 | } |
| 3020 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3021 | public void readHistoryDelta(Parcel src, HistoryItem cur) { |
| 3022 | int firstToken = src.readInt(); |
| 3023 | int deltaTimeToken = firstToken&DELTA_TIME_MASK; |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 3024 | cur.cmd = HistoryItem.CMD_UPDATE; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3025 | cur.numReadInts = 1; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3026 | if (DEBUG) Slog.i(TAG, "READ DELTA: firstToken=0x" + Integer.toHexString(firstToken) |
| 3027 | + " deltaTimeToken=" + deltaTimeToken); |
| 3028 | |
| 3029 | if (deltaTimeToken < DELTA_TIME_ABS) { |
| 3030 | cur.time += deltaTimeToken; |
| 3031 | } else if (deltaTimeToken == DELTA_TIME_ABS) { |
| 3032 | cur.time = src.readLong(); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3033 | cur.numReadInts += 2; |
| 3034 | if (DEBUG) Slog.i(TAG, "READ DELTA: ABS time=" + cur.time); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3035 | cur.readFromParcel(src); |
| 3036 | return; |
| 3037 | } else if (deltaTimeToken == DELTA_TIME_INT) { |
| 3038 | int delta = src.readInt(); |
| 3039 | cur.time += delta; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3040 | cur.numReadInts += 1; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3041 | if (DEBUG) Slog.i(TAG, "READ DELTA: time delta=" + delta + " new time=" + cur.time); |
| 3042 | } else { |
| 3043 | long delta = src.readLong(); |
| 3044 | if (DEBUG) Slog.i(TAG, "READ DELTA: time delta=" + delta + " new time=" + cur.time); |
| 3045 | cur.time += delta; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3046 | cur.numReadInts += 2; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3047 | } |
| 3048 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 3049 | final int batteryLevelInt; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3050 | if ((firstToken&DELTA_BATTERY_LEVEL_FLAG) != 0) { |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 3051 | batteryLevelInt = src.readInt(); |
Adam Lesinski | 3944c81 | 2015-11-13 15:54:59 -0800 | [diff] [blame] | 3052 | readBatteryLevelInt(batteryLevelInt, cur); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3053 | cur.numReadInts += 1; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3054 | if (DEBUG) Slog.i(TAG, "READ DELTA: batteryToken=0x" |
| 3055 | + Integer.toHexString(batteryLevelInt) |
| 3056 | + " batteryLevel=" + cur.batteryLevel |
| 3057 | + " batteryTemp=" + cur.batteryTemperature |
| 3058 | + " batteryVolt=" + (int)cur.batteryVoltage); |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 3059 | } else { |
| 3060 | batteryLevelInt = 0; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3061 | } |
| 3062 | |
| 3063 | if ((firstToken&DELTA_STATE_FLAG) != 0) { |
| 3064 | int stateInt = src.readInt(); |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 3065 | cur.states = (firstToken&DELTA_STATE_MASK) | (stateInt&(~STATE_BATTERY_MASK)); |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 3066 | cur.batteryStatus = (byte)((stateInt>>STATE_BATTERY_STATUS_SHIFT) |
| 3067 | & STATE_BATTERY_STATUS_MASK); |
| 3068 | cur.batteryHealth = (byte)((stateInt>>STATE_BATTERY_HEALTH_SHIFT) |
| 3069 | & STATE_BATTERY_HEALTH_MASK); |
| 3070 | cur.batteryPlugType = (byte)((stateInt>>STATE_BATTERY_PLUG_SHIFT) |
| 3071 | & STATE_BATTERY_PLUG_MASK); |
| 3072 | switch (cur.batteryPlugType) { |
| 3073 | case 1: |
| 3074 | cur.batteryPlugType = BatteryManager.BATTERY_PLUGGED_AC; |
| 3075 | break; |
| 3076 | case 2: |
| 3077 | cur.batteryPlugType = BatteryManager.BATTERY_PLUGGED_USB; |
| 3078 | break; |
| 3079 | case 3: |
| 3080 | cur.batteryPlugType = BatteryManager.BATTERY_PLUGGED_WIRELESS; |
| 3081 | break; |
| 3082 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3083 | cur.numReadInts += 1; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3084 | if (DEBUG) Slog.i(TAG, "READ DELTA: stateToken=0x" |
| 3085 | + Integer.toHexString(stateInt) |
| 3086 | + " batteryStatus=" + cur.batteryStatus |
| 3087 | + " batteryHealth=" + cur.batteryHealth |
| 3088 | + " batteryPlugType=" + cur.batteryPlugType |
| 3089 | + " states=0x" + Integer.toHexString(cur.states)); |
| 3090 | } else { |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 3091 | cur.states = (firstToken&DELTA_STATE_MASK) | (cur.states&(~STATE_BATTERY_MASK)); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3092 | } |
| 3093 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3094 | if ((firstToken&DELTA_STATE2_FLAG) != 0) { |
| 3095 | cur.states2 = src.readInt(); |
| 3096 | if (DEBUG) Slog.i(TAG, "READ DELTA: states2=0x" |
| 3097 | + Integer.toHexString(cur.states2)); |
| 3098 | } |
| 3099 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3100 | if ((firstToken&DELTA_WAKELOCK_FLAG) != 0) { |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 3101 | int indexes = src.readInt(); |
| 3102 | int wakeLockIndex = indexes&0xffff; |
| 3103 | int wakeReasonIndex = (indexes>>16)&0xffff; |
| 3104 | if (wakeLockIndex != 0xffff) { |
| 3105 | cur.wakelockTag = cur.localWakelockTag; |
| 3106 | readHistoryTag(wakeLockIndex, cur.wakelockTag); |
| 3107 | if (DEBUG) Slog.i(TAG, "READ DELTA: wakelockTag=#" + cur.wakelockTag.poolIdx |
| 3108 | + " " + cur.wakelockTag.uid + ":" + cur.wakelockTag.string); |
| 3109 | } else { |
| 3110 | cur.wakelockTag = null; |
| 3111 | } |
| 3112 | if (wakeReasonIndex != 0xffff) { |
| 3113 | cur.wakeReasonTag = cur.localWakeReasonTag; |
| 3114 | readHistoryTag(wakeReasonIndex, cur.wakeReasonTag); |
| 3115 | if (DEBUG) Slog.i(TAG, "READ DELTA: wakeReasonTag=#" + cur.wakeReasonTag.poolIdx |
| 3116 | + " " + cur.wakeReasonTag.uid + ":" + cur.wakeReasonTag.string); |
| 3117 | } else { |
| 3118 | cur.wakeReasonTag = null; |
| 3119 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3120 | cur.numReadInts += 1; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3121 | } else { |
| 3122 | cur.wakelockTag = null; |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 3123 | cur.wakeReasonTag = null; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3124 | } |
| 3125 | |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 3126 | if ((firstToken&DELTA_EVENT_FLAG) != 0) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3127 | cur.eventTag = cur.localEventTag; |
| 3128 | final int codeAndIndex = src.readInt(); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3129 | cur.eventCode = (codeAndIndex&0xffff); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3130 | final int index = ((codeAndIndex>>16)&0xffff); |
| 3131 | readHistoryTag(index, cur.eventTag); |
| 3132 | cur.numReadInts += 1; |
| 3133 | if (DEBUG) Slog.i(TAG, "READ DELTA: event=" + cur.eventCode + " tag=#" |
| 3134 | + cur.eventTag.poolIdx + " " + cur.eventTag.uid + ":" |
| 3135 | + cur.eventTag.string); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3136 | } else { |
| 3137 | cur.eventCode = HistoryItem.EVENT_NONE; |
| 3138 | } |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 3139 | |
| 3140 | if ((batteryLevelInt&BATTERY_DELTA_LEVEL_FLAG) != 0) { |
| 3141 | cur.stepDetails = mReadHistoryStepDetails; |
| 3142 | cur.stepDetails.readFromParcel(src); |
| 3143 | } else { |
| 3144 | cur.stepDetails = null; |
| 3145 | } |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 3146 | |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 3147 | if ((firstToken&DELTA_BATTERY_CHARGE_FLAG) != 0) { |
| 3148 | cur.batteryChargeUAh = src.readInt(); |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 3149 | } |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3150 | } |
| 3151 | |
Dianne Hackborn | fc06413 | 2014-06-02 12:42:12 -0700 | [diff] [blame] | 3152 | @Override |
| 3153 | public void commitCurrentHistoryBatchLocked() { |
| 3154 | mHistoryLastWritten.cmd = HistoryItem.CMD_NULL; |
| 3155 | } |
| 3156 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3157 | void addHistoryBufferLocked(long elapsedRealtimeMs, long uptimeMs, HistoryItem cur) { |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 3158 | if (!mHaveBatteryLevel || !mRecordingHistory) { |
| 3159 | return; |
| 3160 | } |
| 3161 | |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3162 | final long timeDiff = (mHistoryBaseTime+elapsedRealtimeMs) - mHistoryLastWritten.time; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 3163 | final int diffStates = mHistoryLastWritten.states^(cur.states&mActiveHistoryStates); |
| 3164 | final int diffStates2 = mHistoryLastWritten.states2^(cur.states2&mActiveHistoryStates2); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3165 | final int lastDiffStates = mHistoryLastWritten.states^mHistoryLastLastWritten.states; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3166 | final int lastDiffStates2 = mHistoryLastWritten.states2^mHistoryLastLastWritten.states2; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3167 | if (DEBUG) Slog.i(TAG, "ADD: tdelta=" + timeDiff + " diff=" |
| 3168 | + Integer.toHexString(diffStates) + " lastDiff=" |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3169 | + Integer.toHexString(lastDiffStates) + " diff2=" |
| 3170 | + Integer.toHexString(diffStates2) + " lastDiff2=" |
| 3171 | + Integer.toHexString(lastDiffStates2)); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 3172 | if (mHistoryBufferLastPos >= 0 && mHistoryLastWritten.cmd == HistoryItem.CMD_UPDATE |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3173 | && timeDiff < 1000 && (diffStates&lastDiffStates) == 0 |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3174 | && (diffStates2&lastDiffStates2) == 0 |
| 3175 | && (mHistoryLastWritten.wakelockTag == null || cur.wakelockTag == null) |
| 3176 | && (mHistoryLastWritten.wakeReasonTag == null || cur.wakeReasonTag == null) |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 3177 | && mHistoryLastWritten.stepDetails == null |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 3178 | && (mHistoryLastWritten.eventCode == HistoryItem.EVENT_NONE |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3179 | || cur.eventCode == HistoryItem.EVENT_NONE) |
| 3180 | && mHistoryLastWritten.batteryLevel == cur.batteryLevel |
| 3181 | && mHistoryLastWritten.batteryStatus == cur.batteryStatus |
| 3182 | && mHistoryLastWritten.batteryHealth == cur.batteryHealth |
| 3183 | && mHistoryLastWritten.batteryPlugType == cur.batteryPlugType |
| 3184 | && mHistoryLastWritten.batteryTemperature == cur.batteryTemperature |
| 3185 | && mHistoryLastWritten.batteryVoltage == cur.batteryVoltage) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3186 | // 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] | 3187 | // 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] | 3188 | // as long as no bit has changed both between now and the last entry, as |
| 3189 | // well as the last entry and the one before it (so we capture any toggles). |
| 3190 | if (DEBUG) Slog.i(TAG, "ADD: rewinding back to " + mHistoryBufferLastPos); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 3191 | mHistoryBuffer.setDataSize(mHistoryBufferLastPos); |
| 3192 | mHistoryBuffer.setDataPosition(mHistoryBufferLastPos); |
| 3193 | mHistoryBufferLastPos = -1; |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3194 | elapsedRealtimeMs = mHistoryLastWritten.time - mHistoryBaseTime; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3195 | // If the last written history had a wakelock tag, we need to retain it. |
| 3196 | // Note that the condition above made sure that we aren't in a case where |
| 3197 | // both it and the current history item have a wakelock tag. |
| 3198 | if (mHistoryLastWritten.wakelockTag != null) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3199 | cur.wakelockTag = cur.localWakelockTag; |
| 3200 | cur.wakelockTag.setTo(mHistoryLastWritten.wakelockTag); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3201 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 3202 | // If the last written history had a wake reason tag, we need to retain it. |
| 3203 | // Note that the condition above made sure that we aren't in a case where |
| 3204 | // both it and the current history item have a wakelock tag. |
| 3205 | if (mHistoryLastWritten.wakeReasonTag != null) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3206 | cur.wakeReasonTag = cur.localWakeReasonTag; |
| 3207 | cur.wakeReasonTag.setTo(mHistoryLastWritten.wakeReasonTag); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 3208 | } |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 3209 | // If the last written history had an event, we need to retain it. |
| 3210 | // Note that the condition above made sure that we aren't in a case where |
| 3211 | // both it and the current history item have an event. |
| 3212 | if (mHistoryLastWritten.eventCode != HistoryItem.EVENT_NONE) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3213 | cur.eventCode = mHistoryLastWritten.eventCode; |
| 3214 | cur.eventTag = cur.localEventTag; |
| 3215 | cur.eventTag.setTo(mHistoryLastWritten.eventTag); |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 3216 | } |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 3217 | mHistoryLastWritten.setTo(mHistoryLastLastWritten); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 3218 | } |
| 3219 | |
Adam Lesinski | 4548978 | 2016-12-15 23:45:17 -0800 | [diff] [blame] | 3220 | boolean recordResetDueToOverflow = false; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 3221 | final int dataSize = mHistoryBuffer.dataSize(); |
Adam Lesinski | 4548978 | 2016-12-15 23:45:17 -0800 | [diff] [blame] | 3222 | if (dataSize >= MAX_MAX_HISTORY_BUFFER*3) { |
| 3223 | // Clients can't deal with history buffers this large. This only |
| 3224 | // really happens when the device is on charger and interacted with |
| 3225 | // for long periods of time, like in retail mode. Since the device is |
| 3226 | // most likely charged, when unplugged, stats would have reset anyways. |
| 3227 | // Reset the stats and mark that we overflowed. |
| 3228 | // b/32540341 |
| 3229 | resetAllStatsLocked(); |
| 3230 | |
| 3231 | // Mark that we want to set *OVERFLOW* event and the RESET:START |
| 3232 | // events. |
| 3233 | recordResetDueToOverflow = true; |
| 3234 | |
| 3235 | } else if (dataSize >= MAX_HISTORY_BUFFER) { |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 3236 | if (!mHistoryOverflow) { |
| 3237 | mHistoryOverflow = true; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3238 | addHistoryBufferLocked(elapsedRealtimeMs, uptimeMs, HistoryItem.CMD_UPDATE, cur); |
| 3239 | addHistoryBufferLocked(elapsedRealtimeMs, uptimeMs, HistoryItem.CMD_OVERFLOW, cur); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3240 | return; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 3241 | } |
| 3242 | |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 3243 | // After overflow, we allow various bit-wise states to settle to 0. |
| 3244 | boolean writeAnyway = false; |
| 3245 | final int curStates = cur.states & HistoryItem.SETTLE_TO_ZERO_STATES |
| 3246 | & mActiveHistoryStates; |
| 3247 | if (mHistoryLastWritten.states != curStates) { |
| 3248 | // mActiveHistoryStates keeps track of which bits in .states are now being |
| 3249 | // forced to 0. |
| 3250 | int old = mActiveHistoryStates; |
| 3251 | mActiveHistoryStates &= curStates | ~HistoryItem.SETTLE_TO_ZERO_STATES; |
| 3252 | writeAnyway |= old != mActiveHistoryStates; |
| 3253 | } |
| 3254 | final int curStates2 = cur.states2 & HistoryItem.SETTLE_TO_ZERO_STATES2 |
| 3255 | & mActiveHistoryStates2; |
| 3256 | if (mHistoryLastWritten.states2 != curStates2) { |
| 3257 | // mActiveHistoryStates2 keeps track of which bits in .states2 are now being |
| 3258 | // forced to 0. |
| 3259 | int old = mActiveHistoryStates2; |
| 3260 | mActiveHistoryStates2 &= curStates2 | ~HistoryItem.SETTLE_TO_ZERO_STATES2; |
| 3261 | writeAnyway |= old != mActiveHistoryStates2; |
| 3262 | } |
| 3263 | |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 3264 | // Once we've reached the maximum number of items, we only |
| 3265 | // record changes to the battery level and the most interesting states. |
| 3266 | // Once we've reached the maximum maximum number of items, we only |
| 3267 | // record changes to the battery level. |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 3268 | if (!writeAnyway && mHistoryLastWritten.batteryLevel == cur.batteryLevel && |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 3269 | (dataSize >= MAX_MAX_HISTORY_BUFFER |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3270 | || ((mHistoryLastWritten.states^cur.states) |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 3271 | & HistoryItem.MOST_INTERESTING_STATES) == 0 |
| 3272 | || ((mHistoryLastWritten.states2^cur.states2) |
| 3273 | & HistoryItem.MOST_INTERESTING_STATES2) == 0)) { |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 3274 | return; |
| 3275 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3276 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3277 | addHistoryBufferLocked(elapsedRealtimeMs, uptimeMs, HistoryItem.CMD_UPDATE, cur); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3278 | return; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 3279 | } |
| 3280 | |
Adam Lesinski | 4548978 | 2016-12-15 23:45:17 -0800 | [diff] [blame] | 3281 | if (dataSize == 0 || recordResetDueToOverflow) { |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 3282 | // The history is currently empty; we need it to start with a time stamp. |
| 3283 | cur.currentTime = System.currentTimeMillis(); |
Adam Lesinski | 4548978 | 2016-12-15 23:45:17 -0800 | [diff] [blame] | 3284 | if (recordResetDueToOverflow) { |
| 3285 | addHistoryBufferLocked(elapsedRealtimeMs, uptimeMs, HistoryItem.CMD_OVERFLOW, cur); |
| 3286 | } |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 3287 | addHistoryBufferLocked(elapsedRealtimeMs, uptimeMs, HistoryItem.CMD_RESET, cur); |
| 3288 | } |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3289 | addHistoryBufferLocked(elapsedRealtimeMs, uptimeMs, HistoryItem.CMD_UPDATE, cur); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 3290 | } |
| 3291 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3292 | private void addHistoryBufferLocked(long elapsedRealtimeMs, long uptimeMs, byte cmd, |
| 3293 | HistoryItem cur) { |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 3294 | if (mIteratingHistory) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3295 | throw new IllegalStateException("Can't do this while iterating history!"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 3296 | } |
| 3297 | mHistoryBufferLastPos = mHistoryBuffer.dataPosition(); |
| 3298 | mHistoryLastLastWritten.setTo(mHistoryLastWritten); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3299 | mHistoryLastWritten.setTo(mHistoryBaseTime + elapsedRealtimeMs, cmd, cur); |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 3300 | mHistoryLastWritten.states &= mActiveHistoryStates; |
| 3301 | mHistoryLastWritten.states2 &= mActiveHistoryStates2; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 3302 | writeHistoryDelta(mHistoryBuffer, mHistoryLastWritten, mHistoryLastLastWritten); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3303 | mLastHistoryElapsedRealtime = elapsedRealtimeMs; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3304 | cur.wakelockTag = null; |
| 3305 | cur.wakeReasonTag = null; |
| 3306 | cur.eventCode = HistoryItem.EVENT_NONE; |
| 3307 | cur.eventTag = null; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 3308 | if (DEBUG_HISTORY) Slog.i(TAG, "Writing history buffer: was " + mHistoryBufferLastPos |
| 3309 | + " now " + mHistoryBuffer.dataPosition() |
| 3310 | + " size is now " + mHistoryBuffer.dataSize()); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 3311 | } |
| 3312 | |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 3313 | int mChangedStates = 0; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3314 | int mChangedStates2 = 0; |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 3315 | |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3316 | void addHistoryRecordLocked(long elapsedRealtimeMs, long uptimeMs) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3317 | if (mTrackRunningHistoryElapsedRealtime != 0) { |
| 3318 | final long diffElapsed = elapsedRealtimeMs - mTrackRunningHistoryElapsedRealtime; |
| 3319 | final long diffUptime = uptimeMs - mTrackRunningHistoryUptime; |
| 3320 | if (diffUptime < (diffElapsed-20)) { |
| 3321 | final long wakeElapsedTime = elapsedRealtimeMs - (diffElapsed - diffUptime); |
| 3322 | mHistoryAddTmp.setTo(mHistoryLastWritten); |
| 3323 | mHistoryAddTmp.wakelockTag = null; |
| 3324 | mHistoryAddTmp.wakeReasonTag = null; |
| 3325 | mHistoryAddTmp.eventCode = HistoryItem.EVENT_NONE; |
| 3326 | mHistoryAddTmp.states &= ~HistoryItem.STATE_CPU_RUNNING_FLAG; |
| 3327 | addHistoryRecordInnerLocked(wakeElapsedTime, uptimeMs, mHistoryAddTmp); |
| 3328 | } |
| 3329 | } |
| 3330 | mHistoryCur.states |= HistoryItem.STATE_CPU_RUNNING_FLAG; |
| 3331 | mTrackRunningHistoryElapsedRealtime = elapsedRealtimeMs; |
| 3332 | mTrackRunningHistoryUptime = uptimeMs; |
| 3333 | addHistoryRecordInnerLocked(elapsedRealtimeMs, uptimeMs, mHistoryCur); |
| 3334 | } |
| 3335 | |
| 3336 | void addHistoryRecordInnerLocked(long elapsedRealtimeMs, long uptimeMs, HistoryItem cur) { |
| 3337 | addHistoryBufferLocked(elapsedRealtimeMs, uptimeMs, cur); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 3338 | |
Dianne Hackborn | e8c88e6 | 2011-08-17 19:09:09 -0700 | [diff] [blame] | 3339 | if (!USE_OLD_HISTORY) { |
| 3340 | return; |
| 3341 | } |
| 3342 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3343 | if (!mHaveBatteryLevel || !mRecordingHistory) { |
| 3344 | return; |
| 3345 | } |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3346 | |
| 3347 | // If the current time is basically the same as the last time, |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 3348 | // and no states have since the last recorded entry changed and |
| 3349 | // are now resetting back to their original value, then just collapse |
| 3350 | // into one record. |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3351 | if (mHistoryEnd != null && mHistoryEnd.cmd == HistoryItem.CMD_UPDATE |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3352 | && (mHistoryBaseTime+elapsedRealtimeMs) < (mHistoryEnd.time+1000) |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 3353 | && ((mHistoryEnd.states^cur.states)&mChangedStates&mActiveHistoryStates) == 0 |
| 3354 | && ((mHistoryEnd.states2^cur.states2)&mChangedStates2&mActiveHistoryStates2) == 0) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3355 | // If the current is the same as the one before, then we no |
| 3356 | // longer need the entry. |
| 3357 | if (mHistoryLastEnd != null && mHistoryLastEnd.cmd == HistoryItem.CMD_UPDATE |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3358 | && (mHistoryBaseTime+elapsedRealtimeMs) < (mHistoryEnd.time+500) |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3359 | && mHistoryLastEnd.sameNonEvent(cur)) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3360 | mHistoryLastEnd.next = null; |
| 3361 | mHistoryEnd.next = mHistoryCache; |
| 3362 | mHistoryCache = mHistoryEnd; |
| 3363 | mHistoryEnd = mHistoryLastEnd; |
| 3364 | mHistoryLastEnd = null; |
| 3365 | } else { |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 3366 | mChangedStates |= mHistoryEnd.states^(cur.states&mActiveHistoryStates); |
| 3367 | mChangedStates2 |= mHistoryEnd.states^(cur.states2&mActiveHistoryStates2); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3368 | mHistoryEnd.setTo(mHistoryEnd.time, HistoryItem.CMD_UPDATE, cur); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3369 | } |
| 3370 | return; |
| 3371 | } |
| 3372 | |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 3373 | mChangedStates = 0; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3374 | mChangedStates2 = 0; |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 3375 | |
| 3376 | if (mNumHistoryItems == MAX_HISTORY_ITEMS |
| 3377 | || mNumHistoryItems == MAX_MAX_HISTORY_ITEMS) { |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3378 | addHistoryRecordLocked(elapsedRealtimeMs, HistoryItem.CMD_OVERFLOW); |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 3379 | } |
| 3380 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3381 | if (mNumHistoryItems >= MAX_HISTORY_ITEMS) { |
| 3382 | // Once we've reached the maximum number of items, we only |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 3383 | // record changes to the battery level and the most interesting states. |
| 3384 | // Once we've reached the maximum maximum number of items, we only |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3385 | // record changes to the battery level. |
| 3386 | if (mHistoryEnd != null && mHistoryEnd.batteryLevel |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3387 | == cur.batteryLevel && |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 3388 | (mNumHistoryItems >= MAX_MAX_HISTORY_ITEMS |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 3389 | || ((mHistoryEnd.states^(cur.states&mActiveHistoryStates)) |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 3390 | & HistoryItem.MOST_INTERESTING_STATES) == 0)) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3391 | return; |
| 3392 | } |
| 3393 | } |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3394 | |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3395 | addHistoryRecordLocked(elapsedRealtimeMs, HistoryItem.CMD_UPDATE); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3396 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3397 | |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 3398 | public void addHistoryEventLocked(long elapsedRealtimeMs, long uptimeMs, int code, |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3399 | String name, int uid) { |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 3400 | mHistoryCur.eventCode = code; |
| 3401 | mHistoryCur.eventTag = mHistoryCur.localEventTag; |
| 3402 | mHistoryCur.eventTag.string = name; |
| 3403 | mHistoryCur.eventTag.uid = uid; |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 3404 | addHistoryRecordLocked(elapsedRealtimeMs, uptimeMs); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3405 | } |
| 3406 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3407 | void addHistoryRecordLocked(long elapsedRealtimeMs, long uptimeMs, byte cmd, HistoryItem cur) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3408 | HistoryItem rec = mHistoryCache; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3409 | if (rec != null) { |
| 3410 | mHistoryCache = rec.next; |
| 3411 | } else { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3412 | rec = new HistoryItem(); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3413 | } |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3414 | rec.setTo(mHistoryBaseTime + elapsedRealtimeMs, cmd, cur); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3415 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3416 | addHistoryRecordLocked(rec); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3417 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3418 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3419 | void addHistoryRecordLocked(HistoryItem rec) { |
| 3420 | mNumHistoryItems++; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3421 | rec.next = null; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3422 | mHistoryLastEnd = mHistoryEnd; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3423 | if (mHistoryEnd != null) { |
| 3424 | mHistoryEnd.next = rec; |
| 3425 | mHistoryEnd = rec; |
| 3426 | } else { |
| 3427 | mHistory = mHistoryEnd = rec; |
| 3428 | } |
| 3429 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3430 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3431 | void clearHistoryLocked() { |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 3432 | if (DEBUG_HISTORY) Slog.i(TAG, "********** CLEARING HISTORY!"); |
Dianne Hackborn | e8c88e6 | 2011-08-17 19:09:09 -0700 | [diff] [blame] | 3433 | if (USE_OLD_HISTORY) { |
| 3434 | if (mHistory != null) { |
| 3435 | mHistoryEnd.next = mHistoryCache; |
| 3436 | mHistoryCache = mHistory; |
| 3437 | mHistory = mHistoryLastEnd = mHistoryEnd = null; |
| 3438 | } |
| 3439 | mNumHistoryItems = 0; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3440 | } |
Dianne Hackborn | e8c88e6 | 2011-08-17 19:09:09 -0700 | [diff] [blame] | 3441 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3442 | mHistoryBaseTime = 0; |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3443 | mLastHistoryElapsedRealtime = 0; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3444 | mTrackRunningHistoryElapsedRealtime = 0; |
| 3445 | mTrackRunningHistoryUptime = 0; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 3446 | |
| 3447 | mHistoryBuffer.setDataSize(0); |
| 3448 | mHistoryBuffer.setDataPosition(0); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3449 | mHistoryBuffer.setDataCapacity(MAX_HISTORY_BUFFER / 2); |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 3450 | mHistoryLastLastWritten.clear(); |
| 3451 | mHistoryLastWritten.clear(); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3452 | mHistoryTagPool.clear(); |
| 3453 | mNextHistoryTagIdx = 0; |
| 3454 | mNumHistoryTagChars = 0; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 3455 | mHistoryBufferLastPos = -1; |
| 3456 | mHistoryOverflow = false; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 3457 | mActiveHistoryStates = 0xffffffff; |
| 3458 | mActiveHistoryStates2 = 0xffffffff; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3459 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3460 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3461 | public void updateTimeBasesLocked(boolean unplugged, boolean screenOff, long uptime, |
| 3462 | long realtime) { |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 3463 | boolean batteryStatusChanged = mOnBatteryTimeBase.setRunning(unplugged, uptime, realtime); |
| 3464 | |
| 3465 | if (batteryStatusChanged) { |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3466 | for (int i = 0; i < mUidStats.size(); i++) { |
| 3467 | mUidStats.valueAt(i).updateOnBatteryBgTimeBase(uptime, realtime); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 3468 | } |
| 3469 | } |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 3470 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3471 | boolean unpluggedScreenOff = unplugged && screenOff; |
| 3472 | if (unpluggedScreenOff != mOnBatteryScreenOffTimeBase.isRunning()) { |
| 3473 | updateKernelWakelocksLocked(); |
Adam Lesinski | e1f480d | 2017-02-15 18:51:23 -0800 | [diff] [blame] | 3474 | updateBatteryPropertiesLocked(); |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 3475 | if (DEBUG_ENERGY_CPU) { |
| 3476 | Slog.d(TAG, "Updating cpu time because screen is now " + |
| 3477 | (unpluggedScreenOff ? "off" : "on")); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3478 | } |
Sudheer Shanka | 671985f | 2017-05-19 11:33:42 -0700 | [diff] [blame] | 3479 | updateCpuTimeLocked(true /* updateCpuFreqData */); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3480 | mOnBatteryScreenOffTimeBase.setRunning(unpluggedScreenOff, uptime, realtime); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 3481 | for (int i = 0; i < mUidStats.size(); i++) { |
| 3482 | mUidStats.valueAt(i).updateOnBatteryScreenOffBgTimeBase(uptime, realtime); |
| 3483 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3484 | } |
| 3485 | } |
Amith Yamasani | 3718aaa | 2009-06-09 06:32:35 -0700 | [diff] [blame] | 3486 | |
Adam Lesinski | e1f480d | 2017-02-15 18:51:23 -0800 | [diff] [blame] | 3487 | private void updateBatteryPropertiesLocked() { |
| 3488 | try { |
| 3489 | IBatteryPropertiesRegistrar registrar = IBatteryPropertiesRegistrar.Stub.asInterface( |
| 3490 | ServiceManager.getService("batteryproperties")); |
| 3491 | registrar.scheduleUpdate(); |
| 3492 | } catch (RemoteException e) { |
| 3493 | // Ignore. |
| 3494 | } |
| 3495 | } |
| 3496 | |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3497 | public void addIsolatedUidLocked(int isolatedUid, int appUid) { |
| 3498 | mIsolatedUids.put(isolatedUid, appUid); |
| 3499 | } |
| 3500 | |
Adam Lesinski | 61db88f | 2015-07-01 15:05:07 -0700 | [diff] [blame] | 3501 | /** |
| 3502 | * Schedules a read of the latest cpu times before removing the isolated UID. |
| 3503 | * @see #removeIsolatedUidLocked(int) |
| 3504 | */ |
| 3505 | public void scheduleRemoveIsolatedUidLocked(int isolatedUid, int appUid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3506 | int curUid = mIsolatedUids.get(isolatedUid, -1); |
| 3507 | if (curUid == appUid) { |
Adam Lesinski | 61db88f | 2015-07-01 15:05:07 -0700 | [diff] [blame] | 3508 | if (mExternalSync != null) { |
| 3509 | mExternalSync.scheduleCpuSyncDueToRemovedUid(isolatedUid); |
| 3510 | } |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3511 | } |
| 3512 | } |
| 3513 | |
Adam Lesinski | 61db88f | 2015-07-01 15:05:07 -0700 | [diff] [blame] | 3514 | /** |
| 3515 | * This should only be called after the cpu times have been read. |
| 3516 | * @see #scheduleRemoveIsolatedUidLocked(int, int) |
| 3517 | */ |
| 3518 | public void removeIsolatedUidLocked(int isolatedUid) { |
| 3519 | mIsolatedUids.delete(isolatedUid); |
| 3520 | mKernelUidCpuTimeReader.removeUid(isolatedUid); |
Sudheer Shanka | 6d8dcec | 2017-06-01 12:09:03 -0700 | [diff] [blame] | 3521 | mKernelUidCpuFreqTimeReader.removeUid(isolatedUid); |
Adam Lesinski | 61db88f | 2015-07-01 15:05:07 -0700 | [diff] [blame] | 3522 | } |
| 3523 | |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3524 | public int mapUid(int uid) { |
| 3525 | int isolated = mIsolatedUids.get(uid, -1); |
| 3526 | return isolated > 0 ? isolated : uid; |
| 3527 | } |
| 3528 | |
| 3529 | public void noteEventLocked(int code, String name, int uid) { |
| 3530 | uid = mapUid(uid); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 3531 | if (!mActiveEvents.updateState(code, name, uid, 0)) { |
| 3532 | return; |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 3533 | } |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3534 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3535 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3536 | addHistoryEventLocked(elapsedRealtime, uptime, code, name, uid); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3537 | } |
| 3538 | |
Dianne Hackborn | d48954f | 2015-07-22 17:20:33 -0700 | [diff] [blame] | 3539 | boolean ensureStartClockTime(final long currentTime) { |
| 3540 | final long ABOUT_ONE_YEAR = 365*24*60*60*1000L; |
| 3541 | if (currentTime > ABOUT_ONE_YEAR && mStartClockTime < (currentTime-ABOUT_ONE_YEAR)) { |
| 3542 | // If the start clock time has changed by more than a year, then presumably |
| 3543 | // the previous time was completely bogus. So we are going to figure out a |
| 3544 | // 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] | 3545 | mStartClockTime = currentTime - (mClocks.elapsedRealtime()-(mRealtimeStart/1000)); |
Dianne Hackborn | d48954f | 2015-07-22 17:20:33 -0700 | [diff] [blame] | 3546 | return true; |
| 3547 | } |
| 3548 | return false; |
| 3549 | } |
| 3550 | |
Dianne Hackborn | 7d9eefd | 2014-08-27 18:30:31 -0700 | [diff] [blame] | 3551 | public void noteCurrentTimeChangedLocked() { |
| 3552 | final long currentTime = System.currentTimeMillis(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3553 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3554 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 7d9eefd | 2014-08-27 18:30:31 -0700 | [diff] [blame] | 3555 | recordCurrentTimeChangeLocked(currentTime, elapsedRealtime, uptime); |
Dianne Hackborn | d48954f | 2015-07-22 17:20:33 -0700 | [diff] [blame] | 3556 | ensureStartClockTime(currentTime); |
Dianne Hackborn | 7d9eefd | 2014-08-27 18:30:31 -0700 | [diff] [blame] | 3557 | } |
| 3558 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 3559 | public void noteProcessStartLocked(String name, int uid) { |
| 3560 | uid = mapUid(uid); |
| 3561 | if (isOnBattery()) { |
| 3562 | Uid u = getUidStatsLocked(uid); |
| 3563 | u.getProcessStatsLocked(name).incStartsLocked(); |
| 3564 | } |
| 3565 | if (!mActiveEvents.updateState(HistoryItem.EVENT_PROC_START, name, uid, 0)) { |
| 3566 | return; |
| 3567 | } |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 3568 | if (!mRecordAllHistory) { |
| 3569 | return; |
| 3570 | } |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3571 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3572 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 3573 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_PROC_START, name, uid); |
| 3574 | } |
| 3575 | |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 3576 | public void noteProcessCrashLocked(String name, int uid) { |
| 3577 | uid = mapUid(uid); |
| 3578 | if (isOnBattery()) { |
| 3579 | Uid u = getUidStatsLocked(uid); |
| 3580 | u.getProcessStatsLocked(name).incNumCrashesLocked(); |
| 3581 | } |
| 3582 | } |
| 3583 | |
| 3584 | public void noteProcessAnrLocked(String name, int uid) { |
| 3585 | uid = mapUid(uid); |
| 3586 | if (isOnBattery()) { |
| 3587 | Uid u = getUidStatsLocked(uid); |
| 3588 | u.getProcessStatsLocked(name).incNumAnrsLocked(); |
| 3589 | } |
| 3590 | } |
| 3591 | |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 3592 | public void noteUidProcessStateLocked(int uid, int state) { |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 3593 | uid = mapUid(uid); |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 3594 | getUidStatsLocked(uid).updateUidProcessStateLocked(state); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 3595 | } |
| 3596 | |
| 3597 | public void noteProcessFinishLocked(String name, int uid) { |
| 3598 | uid = mapUid(uid); |
| 3599 | if (!mActiveEvents.updateState(HistoryItem.EVENT_PROC_FINISH, name, uid, 0)) { |
| 3600 | return; |
| 3601 | } |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 3602 | if (!mRecordAllHistory) { |
| 3603 | return; |
| 3604 | } |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3605 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3606 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 3607 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_PROC_FINISH, name, uid); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 3608 | } |
| 3609 | |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 3610 | public void noteSyncStartLocked(String name, int uid) { |
| 3611 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3612 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3613 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 3614 | getUidStatsLocked(uid).noteStartSyncLocked(name, elapsedRealtime); |
| 3615 | if (!mActiveEvents.updateState(HistoryItem.EVENT_SYNC_START, name, uid, 0)) { |
| 3616 | return; |
| 3617 | } |
| 3618 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_SYNC_START, name, uid); |
| 3619 | } |
| 3620 | |
| 3621 | public void noteSyncFinishLocked(String name, int uid) { |
| 3622 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3623 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3624 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 3625 | getUidStatsLocked(uid).noteStopSyncLocked(name, elapsedRealtime); |
| 3626 | if (!mActiveEvents.updateState(HistoryItem.EVENT_SYNC_FINISH, name, uid, 0)) { |
| 3627 | return; |
| 3628 | } |
| 3629 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_SYNC_FINISH, name, uid); |
| 3630 | } |
| 3631 | |
| 3632 | public void noteJobStartLocked(String name, int uid) { |
| 3633 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3634 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3635 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 3636 | getUidStatsLocked(uid).noteStartJobLocked(name, elapsedRealtime); |
| 3637 | if (!mActiveEvents.updateState(HistoryItem.EVENT_JOB_START, name, uid, 0)) { |
| 3638 | return; |
| 3639 | } |
| 3640 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_JOB_START, name, uid); |
| 3641 | } |
| 3642 | |
| 3643 | public void noteJobFinishLocked(String name, int uid) { |
| 3644 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3645 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3646 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 3647 | getUidStatsLocked(uid).noteStopJobLocked(name, elapsedRealtime); |
| 3648 | if (!mActiveEvents.updateState(HistoryItem.EVENT_JOB_FINISH, name, uid, 0)) { |
| 3649 | return; |
| 3650 | } |
| 3651 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_JOB_FINISH, name, uid); |
| 3652 | } |
| 3653 | |
Dianne Hackborn | 1e38382 | 2015-04-10 14:02:33 -0700 | [diff] [blame] | 3654 | public void noteAlarmStartLocked(String name, int uid) { |
| 3655 | if (!mRecordAllHistory) { |
| 3656 | return; |
| 3657 | } |
| 3658 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3659 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3660 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 1e38382 | 2015-04-10 14:02:33 -0700 | [diff] [blame] | 3661 | if (!mActiveEvents.updateState(HistoryItem.EVENT_ALARM_START, name, uid, 0)) { |
| 3662 | return; |
| 3663 | } |
| 3664 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_ALARM_START, name, uid); |
| 3665 | } |
| 3666 | |
| 3667 | public void noteAlarmFinishLocked(String name, int uid) { |
| 3668 | if (!mRecordAllHistory) { |
| 3669 | return; |
| 3670 | } |
| 3671 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3672 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3673 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 1e38382 | 2015-04-10 14:02:33 -0700 | [diff] [blame] | 3674 | if (!mActiveEvents.updateState(HistoryItem.EVENT_ALARM_FINISH, name, uid, 0)) { |
| 3675 | return; |
| 3676 | } |
| 3677 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_ALARM_FINISH, name, uid); |
| 3678 | } |
| 3679 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3680 | private void requestWakelockCpuUpdate() { |
| 3681 | if (!mHandler.hasMessages(MSG_UPDATE_WAKELOCKS)) { |
| 3682 | Message m = mHandler.obtainMessage(MSG_UPDATE_WAKELOCKS); |
| 3683 | mHandler.sendMessageDelayed(m, DELAY_UPDATE_WAKELOCKS); |
| 3684 | } |
| 3685 | } |
| 3686 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 3687 | private void requestImmediateCpuUpdate() { |
| 3688 | mHandler.removeMessages(MSG_UPDATE_WAKELOCKS); |
| 3689 | mHandler.sendEmptyMessage(MSG_UPDATE_WAKELOCKS); |
| 3690 | } |
| 3691 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 3692 | public void setRecordAllHistoryLocked(boolean enabled) { |
| 3693 | mRecordAllHistory = enabled; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3694 | if (!enabled) { |
| 3695 | // Clear out any existing state. |
| 3696 | mActiveEvents.removeEvents(HistoryItem.EVENT_WAKE_LOCK); |
Dianne Hackborn | 1e38382 | 2015-04-10 14:02:33 -0700 | [diff] [blame] | 3697 | mActiveEvents.removeEvents(HistoryItem.EVENT_ALARM); |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 3698 | // Record the currently running processes as stopping, now that we are no |
| 3699 | // longer tracking them. |
| 3700 | HashMap<String, SparseIntArray> active = mActiveEvents.getStateForEvent( |
| 3701 | HistoryItem.EVENT_PROC); |
| 3702 | if (active != null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3703 | long mSecRealtime = mClocks.elapsedRealtime(); |
| 3704 | final long mSecUptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 3705 | for (HashMap.Entry<String, SparseIntArray> ent : active.entrySet()) { |
| 3706 | SparseIntArray uids = ent.getValue(); |
| 3707 | for (int j=0; j<uids.size(); j++) { |
| 3708 | addHistoryEventLocked(mSecRealtime, mSecUptime, |
| 3709 | HistoryItem.EVENT_PROC_FINISH, ent.getKey(), uids.keyAt(j)); |
| 3710 | } |
| 3711 | } |
| 3712 | } |
| 3713 | } else { |
| 3714 | // Record the currently running processes as starting, now that we are tracking them. |
| 3715 | HashMap<String, SparseIntArray> active = mActiveEvents.getStateForEvent( |
| 3716 | HistoryItem.EVENT_PROC); |
| 3717 | if (active != null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3718 | long mSecRealtime = mClocks.elapsedRealtime(); |
| 3719 | final long mSecUptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 3720 | for (HashMap.Entry<String, SparseIntArray> ent : active.entrySet()) { |
| 3721 | SparseIntArray uids = ent.getValue(); |
| 3722 | for (int j=0; j<uids.size(); j++) { |
| 3723 | addHistoryEventLocked(mSecRealtime, mSecUptime, |
| 3724 | HistoryItem.EVENT_PROC_START, ent.getKey(), uids.keyAt(j)); |
| 3725 | } |
| 3726 | } |
| 3727 | } |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3728 | } |
| 3729 | } |
| 3730 | |
Dianne Hackborn | 9a75543 | 2014-05-15 17:05:22 -0700 | [diff] [blame] | 3731 | public void setNoAutoReset(boolean enabled) { |
| 3732 | mNoAutoReset = enabled; |
| 3733 | } |
| 3734 | |
Amith Yamasani | 674c9bb | 2017-02-01 09:45:17 -0800 | [diff] [blame] | 3735 | public void setPretendScreenOff(boolean pretendScreenOff) { |
| 3736 | mPretendScreenOff = pretendScreenOff; |
| 3737 | noteScreenStateLocked(pretendScreenOff ? Display.STATE_OFF : Display.STATE_ON); |
| 3738 | } |
| 3739 | |
Dianne Hackborn | 9a75543 | 2014-05-15 17:05:22 -0700 | [diff] [blame] | 3740 | private String mInitialAcquireWakeName; |
| 3741 | private int mInitialAcquireWakeUid = -1; |
| 3742 | |
Dianne Hackborn | a1f1a3c | 2014-02-24 18:12:28 -0800 | [diff] [blame] | 3743 | 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] | 3744 | boolean unimportantForLogging, long elapsedRealtime, long uptime) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3745 | uid = mapUid(uid); |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 3746 | if (type == WAKE_TYPE_PARTIAL) { |
| 3747 | // Only care about partial wake locks, since full wake locks |
| 3748 | // will be canceled when the user puts the screen to sleep. |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3749 | aggregateLastWakeupUptimeLocked(uptime); |
Dianne Hackborn | fc06413 | 2014-06-02 12:42:12 -0700 | [diff] [blame] | 3750 | if (historyName == null) { |
| 3751 | historyName = name; |
| 3752 | } |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 3753 | if (mRecordAllHistory) { |
Dianne Hackborn | fc06413 | 2014-06-02 12:42:12 -0700 | [diff] [blame] | 3754 | if (mActiveEvents.updateState(HistoryItem.EVENT_WAKE_LOCK_START, historyName, |
| 3755 | uid, 0)) { |
Dianne Hackborn | 536456f | 2014-05-23 16:51:05 -0700 | [diff] [blame] | 3756 | addHistoryEventLocked(elapsedRealtime, uptime, |
Dianne Hackborn | fc06413 | 2014-06-02 12:42:12 -0700 | [diff] [blame] | 3757 | HistoryItem.EVENT_WAKE_LOCK_START, historyName, uid); |
Dianne Hackborn | 536456f | 2014-05-23 16:51:05 -0700 | [diff] [blame] | 3758 | } |
| 3759 | } |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 3760 | if (mWakeLockNesting == 0) { |
| 3761 | mHistoryCur.states |= HistoryItem.STATE_WAKE_LOCK_FLAG; |
| 3762 | if (DEBUG_HISTORY) Slog.v(TAG, "Start wake lock to: " |
| 3763 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3764 | mHistoryCur.wakelockTag = mHistoryCur.localWakelockTag; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3765 | mHistoryCur.wakelockTag.string = mInitialAcquireWakeName = historyName; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 3766 | mHistoryCur.wakelockTag.uid = mInitialAcquireWakeUid = uid; |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 3767 | mWakeLockImportant = !unimportantForLogging; |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3768 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | fc06413 | 2014-06-02 12:42:12 -0700 | [diff] [blame] | 3769 | } else if (!mWakeLockImportant && !unimportantForLogging |
| 3770 | && mHistoryLastWritten.cmd == HistoryItem.CMD_UPDATE) { |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 3771 | if (mHistoryLastWritten.wakelockTag != null) { |
| 3772 | // We'll try to update the last tag. |
| 3773 | mHistoryLastWritten.wakelockTag = null; |
| 3774 | mHistoryCur.wakelockTag = mHistoryCur.localWakelockTag; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3775 | mHistoryCur.wakelockTag.string = mInitialAcquireWakeName = historyName; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 3776 | mHistoryCur.wakelockTag.uid = mInitialAcquireWakeUid = uid; |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3777 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 3778 | } |
| 3779 | mWakeLockImportant = true; |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 3780 | } |
| 3781 | mWakeLockNesting++; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3782 | } |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3783 | if (uid >= 0) { |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 3784 | if (mOnBatteryScreenOffTimeBase.isRunning()) { |
| 3785 | // We only update the cpu time when a wake lock is acquired if the screen is off. |
| 3786 | // If the screen is on, we don't distribute the power amongst partial wakelocks. |
| 3787 | if (DEBUG_ENERGY_CPU) { |
| 3788 | Slog.d(TAG, "Updating cpu time because of +wake_lock"); |
| 3789 | } |
| 3790 | requestWakelockCpuUpdate(); |
| 3791 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3792 | getUidStatsLocked(uid).noteStartWakeLocked(pid, name, type, elapsedRealtime); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3793 | } |
| 3794 | } |
| 3795 | |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3796 | public void noteStopWakeLocked(int uid, int pid, String name, String historyName, int type, |
| 3797 | long elapsedRealtime, long uptime) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3798 | uid = mapUid(uid); |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 3799 | if (type == WAKE_TYPE_PARTIAL) { |
| 3800 | mWakeLockNesting--; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 3801 | if (mRecordAllHistory) { |
Dianne Hackborn | fc06413 | 2014-06-02 12:42:12 -0700 | [diff] [blame] | 3802 | if (historyName == null) { |
| 3803 | historyName = name; |
| 3804 | } |
| 3805 | if (mActiveEvents.updateState(HistoryItem.EVENT_WAKE_LOCK_FINISH, historyName, |
| 3806 | uid, 0)) { |
Dianne Hackborn | 536456f | 2014-05-23 16:51:05 -0700 | [diff] [blame] | 3807 | addHistoryEventLocked(elapsedRealtime, uptime, |
Dianne Hackborn | fc06413 | 2014-06-02 12:42:12 -0700 | [diff] [blame] | 3808 | HistoryItem.EVENT_WAKE_LOCK_FINISH, historyName, uid); |
Dianne Hackborn | 536456f | 2014-05-23 16:51:05 -0700 | [diff] [blame] | 3809 | } |
| 3810 | } |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 3811 | if (mWakeLockNesting == 0) { |
| 3812 | mHistoryCur.states &= ~HistoryItem.STATE_WAKE_LOCK_FLAG; |
| 3813 | if (DEBUG_HISTORY) Slog.v(TAG, "Stop wake lock to: " |
| 3814 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 3815 | mInitialAcquireWakeName = null; |
| 3816 | mInitialAcquireWakeUid = -1; |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3817 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 3818 | } |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3819 | } |
| 3820 | if (uid >= 0) { |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 3821 | if (mOnBatteryScreenOffTimeBase.isRunning()) { |
| 3822 | if (DEBUG_ENERGY_CPU) { |
| 3823 | Slog.d(TAG, "Updating cpu time because of -wake_lock"); |
| 3824 | } |
| 3825 | requestWakelockCpuUpdate(); |
| 3826 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3827 | getUidStatsLocked(uid).noteStopWakeLocked(pid, name, type, elapsedRealtime); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3828 | } |
| 3829 | } |
| 3830 | |
Dianne Hackborn | a1f1a3c | 2014-02-24 18:12:28 -0800 | [diff] [blame] | 3831 | public void noteStartWakeFromSourceLocked(WorkSource ws, int pid, String name, |
| 3832 | String historyName, int type, boolean unimportantForLogging) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3833 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3834 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 3835 | final int N = ws.size(); |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 3836 | for (int i=0; i<N; i++) { |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 3837 | noteStartWakeLocked(ws.get(i), pid, name, historyName, type, unimportantForLogging, |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3838 | elapsedRealtime, uptime); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 3839 | } |
| 3840 | } |
| 3841 | |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3842 | public void noteChangeWakelockFromSourceLocked(WorkSource ws, int pid, String name, |
| 3843 | String historyName, int type, WorkSource newWs, int newPid, String newName, |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 3844 | String newHistoryName, int newType, boolean newUnimportantForLogging) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3845 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3846 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 3847 | // For correct semantics, we start the need worksources first, so that we won't |
| 3848 | // make inappropriate history items as if all wake locks went away and new ones |
| 3849 | // appeared. This is okay because tracking of wake locks allows nesting. |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3850 | final int NN = newWs.size(); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 3851 | for (int i=0; i<NN; i++) { |
| 3852 | noteStartWakeLocked(newWs.get(i), newPid, newName, newHistoryName, newType, |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3853 | newUnimportantForLogging, elapsedRealtime, uptime); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 3854 | } |
| 3855 | final int NO = ws.size(); |
| 3856 | for (int i=0; i<NO; i++) { |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3857 | noteStopWakeLocked(ws.get(i), pid, name, historyName, type, elapsedRealtime, uptime); |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 3858 | } |
| 3859 | } |
| 3860 | |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3861 | public void noteStopWakeFromSourceLocked(WorkSource ws, int pid, String name, |
| 3862 | String historyName, int type) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3863 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3864 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 3865 | final int N = ws.size(); |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 3866 | for (int i=0; i<N; i++) { |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3867 | noteStopWakeLocked(ws.get(i), pid, name, historyName, type, elapsedRealtime, uptime); |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 3868 | } |
| 3869 | } |
| 3870 | |
Dianne Hackborn | d0db6f0 | 2016-07-18 14:14:20 -0700 | [diff] [blame] | 3871 | public void noteLongPartialWakelockStart(String name, String historyName, int uid) { |
| 3872 | uid = mapUid(uid); |
| 3873 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3874 | final long uptime = mClocks.uptimeMillis(); |
| 3875 | if (historyName == null) { |
| 3876 | historyName = name; |
| 3877 | } |
| 3878 | if (!mActiveEvents.updateState(HistoryItem.EVENT_LONG_WAKE_LOCK_START, historyName, uid, |
| 3879 | 0)) { |
| 3880 | return; |
| 3881 | } |
| 3882 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_LONG_WAKE_LOCK_START, |
| 3883 | historyName, uid); |
| 3884 | } |
| 3885 | |
| 3886 | public void noteLongPartialWakelockFinish(String name, String historyName, int uid) { |
| 3887 | uid = mapUid(uid); |
| 3888 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3889 | final long uptime = mClocks.uptimeMillis(); |
| 3890 | if (historyName == null) { |
| 3891 | historyName = name; |
| 3892 | } |
| 3893 | if (!mActiveEvents.updateState(HistoryItem.EVENT_LONG_WAKE_LOCK_FINISH, historyName, uid, |
| 3894 | 0)) { |
| 3895 | return; |
| 3896 | } |
| 3897 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_LONG_WAKE_LOCK_FINISH, |
| 3898 | historyName, uid); |
| 3899 | } |
| 3900 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3901 | void aggregateLastWakeupUptimeLocked(long uptimeMs) { |
| 3902 | if (mLastWakeupReason != null) { |
| 3903 | long deltaUptime = uptimeMs - mLastWakeupUptimeMs; |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 3904 | SamplingTimer timer = getWakeupReasonTimerLocked(mLastWakeupReason); |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 3905 | timer.add(deltaUptime * 1000, 1); // time in in microseconds |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3906 | mLastWakeupReason = null; |
| 3907 | } |
| 3908 | } |
| 3909 | |
| 3910 | public void noteWakeupReasonLocked(String reason) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3911 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3912 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 3913 | if (DEBUG_HISTORY) Slog.v(TAG, "Wakeup reason \"" + reason +"\": " |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 3914 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3915 | aggregateLastWakeupUptimeLocked(uptime); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 3916 | mHistoryCur.wakeReasonTag = mHistoryCur.localWakeReasonTag; |
| 3917 | mHistoryCur.wakeReasonTag.string = reason; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3918 | mHistoryCur.wakeReasonTag.uid = 0; |
| 3919 | mLastWakeupReason = reason; |
| 3920 | mLastWakeupUptimeMs = uptime; |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3921 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 3922 | } |
| 3923 | |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 3924 | public boolean startAddingCpuLocked() { |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 3925 | mHandler.removeMessages(MSG_UPDATE_WAKELOCKS); |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 3926 | return mOnBatteryInternal; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 3927 | } |
| 3928 | |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 3929 | public void finishAddingCpuLocked(int totalUTime, int totalSTime, int statUserTime, |
| 3930 | int statSystemTime, int statIOWaitTime, int statIrqTime, |
| 3931 | int statSoftIrqTime, int statIdleTime) { |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 3932 | if (DEBUG) Slog.d(TAG, "Adding cpu: tuser=" + totalUTime + " tsys=" + totalSTime |
| 3933 | + " user=" + statUserTime + " sys=" + statSystemTime |
| 3934 | + " io=" + statIOWaitTime + " irq=" + statIrqTime |
| 3935 | + " sirq=" + statSoftIrqTime + " idle=" + statIdleTime); |
| 3936 | mCurStepCpuUserTime += totalUTime; |
| 3937 | mCurStepCpuSystemTime += totalSTime; |
| 3938 | mCurStepStatUserTime += statUserTime; |
| 3939 | mCurStepStatSystemTime += statSystemTime; |
| 3940 | mCurStepStatIOWaitTime += statIOWaitTime; |
| 3941 | mCurStepStatIrqTime += statIrqTime; |
| 3942 | mCurStepStatSoftIrqTime += statSoftIrqTime; |
| 3943 | mCurStepStatIdleTime += statIdleTime; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 3944 | } |
| 3945 | |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3946 | public void noteProcessDiedLocked(int uid, int pid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3947 | uid = mapUid(uid); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3948 | Uid u = mUidStats.get(uid); |
| 3949 | if (u != null) { |
| 3950 | u.mPids.remove(pid); |
| 3951 | } |
| 3952 | } |
| 3953 | |
| 3954 | public long getProcessWakeTime(int uid, int pid, long realtime) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3955 | uid = mapUid(uid); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3956 | Uid u = mUidStats.get(uid); |
| 3957 | if (u != null) { |
| 3958 | Uid.Pid p = u.mPids.get(pid); |
| 3959 | if (p != null) { |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 3960 | return p.mWakeSumMs + (p.mWakeNesting > 0 ? (realtime - p.mWakeStartMs) : 0); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3961 | } |
| 3962 | } |
| 3963 | return 0; |
| 3964 | } |
| 3965 | |
| 3966 | public void reportExcessiveWakeLocked(int uid, String proc, long overTime, long usedTime) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3967 | uid = mapUid(uid); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3968 | Uid u = mUidStats.get(uid); |
| 3969 | if (u != null) { |
| 3970 | u.reportExcessiveWakeLocked(proc, overTime, usedTime); |
| 3971 | } |
| 3972 | } |
| 3973 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 3974 | public void reportExcessiveCpuLocked(int uid, String proc, long overTime, long usedTime) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3975 | uid = mapUid(uid); |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 3976 | Uid u = mUidStats.get(uid); |
| 3977 | if (u != null) { |
| 3978 | u.reportExcessiveCpuLocked(proc, overTime, usedTime); |
| 3979 | } |
| 3980 | } |
| 3981 | |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3982 | int mSensorNesting; |
| 3983 | |
| 3984 | public void noteStartSensorLocked(int uid, int sensor) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3985 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3986 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3987 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3988 | if (mSensorNesting == 0) { |
| 3989 | mHistoryCur.states |= HistoryItem.STATE_SENSOR_ON_FLAG; |
| 3990 | if (DEBUG_HISTORY) Slog.v(TAG, "Start sensor to: " |
| 3991 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3992 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3993 | } |
| 3994 | mSensorNesting++; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3995 | getUidStatsLocked(uid).noteStartSensor(sensor, elapsedRealtime); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3996 | } |
| 3997 | |
| 3998 | public void noteStopSensorLocked(int uid, int sensor) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3999 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4000 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4001 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4002 | mSensorNesting--; |
| 4003 | if (mSensorNesting == 0) { |
| 4004 | mHistoryCur.states &= ~HistoryItem.STATE_SENSOR_ON_FLAG; |
| 4005 | if (DEBUG_HISTORY) Slog.v(TAG, "Stop sensor to: " |
| 4006 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 4007 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4008 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4009 | getUidStatsLocked(uid).noteStopSensor(sensor, elapsedRealtime); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4010 | } |
| 4011 | |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4012 | int mGpsNesting; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4013 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4014 | public void noteStartGpsLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4015 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4016 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4017 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4018 | if (mGpsNesting == 0) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4019 | mHistoryCur.states |= HistoryItem.STATE_GPS_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4020 | if (DEBUG_HISTORY) Slog.v(TAG, "Start GPS to: " |
| 4021 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 4022 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4023 | } |
| 4024 | mGpsNesting++; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4025 | getUidStatsLocked(uid).noteStartGps(elapsedRealtime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4026 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4027 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4028 | public void noteStopGpsLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4029 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4030 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4031 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4032 | mGpsNesting--; |
| 4033 | if (mGpsNesting == 0) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4034 | mHistoryCur.states &= ~HistoryItem.STATE_GPS_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4035 | if (DEBUG_HISTORY) Slog.v(TAG, "Stop GPS to: " |
| 4036 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 4037 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4038 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4039 | getUidStatsLocked(uid).noteStopGps(elapsedRealtime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4040 | } |
Amith Yamasani | 3718aaa | 2009-06-09 06:32:35 -0700 | [diff] [blame] | 4041 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 4042 | public void noteScreenStateLocked(int state) { |
Amith Yamasani | 674c9bb | 2017-02-01 09:45:17 -0800 | [diff] [blame] | 4043 | state = mPretendScreenOff ? Display.STATE_OFF : state; |
Santos Cordon | e94f050 | 2017-02-24 12:31:20 -0800 | [diff] [blame] | 4044 | |
| 4045 | // Battery stats relies on there being 4 states. To accommodate this, new states beyond the |
| 4046 | // original 4 are mapped to one of the originals. |
| 4047 | if (state > MAX_TRACKED_SCREEN_STATE) { |
| 4048 | switch (state) { |
| 4049 | case Display.STATE_VR: |
| 4050 | state = Display.STATE_ON; |
| 4051 | break; |
| 4052 | default: |
| 4053 | Slog.wtf(TAG, "Unknown screen state (not mapped): " + state); |
| 4054 | break; |
| 4055 | } |
| 4056 | } |
| 4057 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 4058 | if (mScreenState != state) { |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 4059 | recordDailyStatsIfNeededLocked(true); |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 4060 | final int oldState = mScreenState; |
| 4061 | mScreenState = state; |
| 4062 | if (DEBUG) Slog.v(TAG, "Screen state: oldState=" + Display.stateToString(oldState) |
| 4063 | + ", newState=" + Display.stateToString(state)); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4064 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 4065 | if (state != Display.STATE_UNKNOWN) { |
| 4066 | int stepState = state-1; |
Santos Cordon | e94f050 | 2017-02-24 12:31:20 -0800 | [diff] [blame] | 4067 | if ((stepState & STEP_LEVEL_MODE_SCREEN_STATE) == stepState) { |
| 4068 | mModStepMode |= (mCurStepMode & STEP_LEVEL_MODE_SCREEN_STATE) ^ stepState; |
| 4069 | mCurStepMode = (mCurStepMode & ~STEP_LEVEL_MODE_SCREEN_STATE) | stepState; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 4070 | } else { |
| 4071 | Slog.wtf(TAG, "Unexpected screen state: " + state); |
| 4072 | } |
| 4073 | } |
| 4074 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 4075 | if (state == Display.STATE_ON) { |
| 4076 | // Screen turning on. |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4077 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4078 | final long uptime = mClocks.uptimeMillis(); |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 4079 | mHistoryCur.states |= HistoryItem.STATE_SCREEN_ON_FLAG; |
| 4080 | if (DEBUG_HISTORY) Slog.v(TAG, "Screen on to: " |
| 4081 | + Integer.toHexString(mHistoryCur.states)); |
| 4082 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 4083 | mScreenOnTimer.startRunningLocked(elapsedRealtime); |
| 4084 | if (mScreenBrightnessBin >= 0) { |
| 4085 | mScreenBrightnessTimer[mScreenBrightnessBin].startRunningLocked(elapsedRealtime); |
| 4086 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4087 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 4088 | updateTimeBasesLocked(mOnBatteryTimeBase.isRunning(), false, |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4089 | mClocks.uptimeMillis() * 1000, elapsedRealtime * 1000); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 4090 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 4091 | // Fake a wake lock, so we consider the device waked as long |
| 4092 | // as the screen is on. |
| 4093 | noteStartWakeLocked(-1, -1, "screen", null, WAKE_TYPE_PARTIAL, false, |
| 4094 | elapsedRealtime, uptime); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4095 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 4096 | // Update discharge amounts. |
| 4097 | if (mOnBatteryInternal) { |
| 4098 | updateDischargeScreenLevelsLocked(false, true); |
| 4099 | } |
| 4100 | } else if (oldState == Display.STATE_ON) { |
| 4101 | // Screen turning off or dozing. |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4102 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4103 | final long uptime = mClocks.uptimeMillis(); |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 4104 | mHistoryCur.states &= ~HistoryItem.STATE_SCREEN_ON_FLAG; |
| 4105 | if (DEBUG_HISTORY) Slog.v(TAG, "Screen off to: " |
| 4106 | + Integer.toHexString(mHistoryCur.states)); |
| 4107 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 4108 | mScreenOnTimer.stopRunningLocked(elapsedRealtime); |
| 4109 | if (mScreenBrightnessBin >= 0) { |
| 4110 | mScreenBrightnessTimer[mScreenBrightnessBin].stopRunningLocked(elapsedRealtime); |
| 4111 | } |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4112 | |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 4113 | noteStopWakeLocked(-1, -1, "screen", "screen", WAKE_TYPE_PARTIAL, |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 4114 | elapsedRealtime, uptime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4115 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 4116 | updateTimeBasesLocked(mOnBatteryTimeBase.isRunning(), true, |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4117 | mClocks.uptimeMillis() * 1000, elapsedRealtime * 1000); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4118 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 4119 | // Update discharge amounts. |
| 4120 | if (mOnBatteryInternal) { |
| 4121 | updateDischargeScreenLevelsLocked(true, false); |
| 4122 | } |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 4123 | } |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4124 | } |
| 4125 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4126 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4127 | public void noteScreenBrightnessLocked(int brightness) { |
| 4128 | // Bin the brightness. |
| 4129 | int bin = brightness / (256/NUM_SCREEN_BRIGHTNESS_BINS); |
| 4130 | if (bin < 0) bin = 0; |
| 4131 | else if (bin >= NUM_SCREEN_BRIGHTNESS_BINS) bin = NUM_SCREEN_BRIGHTNESS_BINS-1; |
| 4132 | if (mScreenBrightnessBin != bin) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4133 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4134 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4135 | mHistoryCur.states = (mHistoryCur.states&~HistoryItem.STATE_BRIGHTNESS_MASK) |
| 4136 | | (bin << HistoryItem.STATE_BRIGHTNESS_SHIFT); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4137 | if (DEBUG_HISTORY) Slog.v(TAG, "Screen brightness " + bin + " to: " |
| 4138 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 4139 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 4140 | if (mScreenState == Display.STATE_ON) { |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4141 | if (mScreenBrightnessBin >= 0) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4142 | mScreenBrightnessTimer[mScreenBrightnessBin].stopRunningLocked(elapsedRealtime); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4143 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4144 | mScreenBrightnessTimer[bin].startRunningLocked(elapsedRealtime); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4145 | } |
| 4146 | mScreenBrightnessBin = bin; |
| 4147 | } |
| 4148 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4149 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4150 | public void noteUserActivityLocked(int uid, int event) { |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 4151 | if (mOnBatteryInternal) { |
| 4152 | uid = mapUid(uid); |
| 4153 | getUidStatsLocked(uid).noteUserActivityLocked(event); |
| 4154 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4155 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4156 | |
Dianne Hackborn | 280a64e | 2015-07-13 14:48:08 -0700 | [diff] [blame] | 4157 | public void noteWakeUpLocked(String reason, int reasonUid) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4158 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4159 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 280a64e | 2015-07-13 14:48:08 -0700 | [diff] [blame] | 4160 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_SCREEN_WAKE_UP, |
| 4161 | reason, reasonUid); |
| 4162 | } |
| 4163 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 4164 | public void noteInteractiveLocked(boolean interactive) { |
| 4165 | if (mInteractive != interactive) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4166 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 4167 | mInteractive = interactive; |
| 4168 | if (DEBUG) Slog.v(TAG, "Interactive: " + interactive); |
| 4169 | if (interactive) { |
| 4170 | mInteractiveTimer.startRunningLocked(elapsedRealtime); |
| 4171 | } else { |
| 4172 | mInteractiveTimer.stopRunningLocked(elapsedRealtime); |
| 4173 | } |
| 4174 | } |
| 4175 | } |
| 4176 | |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 4177 | public void noteConnectivityChangedLocked(int type, String extra) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4178 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4179 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 4180 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_CONNECTIVITY_CHANGED, |
| 4181 | extra, type); |
| 4182 | mNumConnectivityChange++; |
| 4183 | } |
| 4184 | |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 4185 | private void noteMobileRadioApWakeupLocked(final long elapsedRealtimeMillis, |
| 4186 | final long uptimeMillis, int uid) { |
| 4187 | uid = mapUid(uid); |
| 4188 | addHistoryEventLocked(elapsedRealtimeMillis, uptimeMillis, HistoryItem.EVENT_WAKEUP_AP, "", |
| 4189 | uid); |
| 4190 | getUidStatsLocked(uid).noteMobileRadioApWakeupLocked(); |
| 4191 | } |
| 4192 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 4193 | /** |
| 4194 | * Updates the radio power state and returns true if an external stats collection should occur. |
| 4195 | */ |
| 4196 | public boolean noteMobileRadioPowerStateLocked(int powerState, long timestampNs, int uid) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4197 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4198 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 4199 | if (mMobileRadioPowerState != powerState) { |
| 4200 | long realElapsedRealtimeMs; |
| 4201 | final boolean active = |
| 4202 | powerState == DataConnectionRealTimeInfo.DC_POWER_STATE_MEDIUM |
| 4203 | || powerState == DataConnectionRealTimeInfo.DC_POWER_STATE_HIGH; |
| 4204 | if (active) { |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 4205 | if (uid > 0) { |
| 4206 | noteMobileRadioApWakeupLocked(elapsedRealtime, uptime, uid); |
| 4207 | } |
| 4208 | |
Adam Lesinski | 9acfd81 | 2016-04-19 18:29:50 -0700 | [diff] [blame] | 4209 | mMobileRadioActiveStartTime = realElapsedRealtimeMs = timestampNs / (1000 * 1000); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 4210 | mHistoryCur.states |= HistoryItem.STATE_MOBILE_RADIO_ACTIVE_FLAG; |
| 4211 | } else { |
| 4212 | realElapsedRealtimeMs = timestampNs / (1000*1000); |
Dianne Hackborn | f7097a5 | 2014-05-13 09:56:14 -0700 | [diff] [blame] | 4213 | long lastUpdateTimeMs = mMobileRadioActiveStartTime; |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 4214 | if (realElapsedRealtimeMs < lastUpdateTimeMs) { |
| 4215 | Slog.wtf(TAG, "Data connection inactive timestamp " + realElapsedRealtimeMs |
| 4216 | + " is before start time " + lastUpdateTimeMs); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 4217 | realElapsedRealtimeMs = elapsedRealtime; |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 4218 | } else if (realElapsedRealtimeMs < elapsedRealtime) { |
| 4219 | mMobileRadioActiveAdjustedTime.addCountLocked(elapsedRealtime |
| 4220 | - realElapsedRealtimeMs); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 4221 | } |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 4222 | mHistoryCur.states &= ~HistoryItem.STATE_MOBILE_RADIO_ACTIVE_FLAG; |
| 4223 | } |
| 4224 | if (DEBUG_HISTORY) Slog.v(TAG, "Mobile network active " + active + " to: " |
| 4225 | + Integer.toHexString(mHistoryCur.states)); |
| 4226 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 4227 | mMobileRadioPowerState = powerState; |
| 4228 | if (active) { |
| 4229 | mMobileRadioActiveTimer.startRunningLocked(elapsedRealtime); |
| 4230 | mMobileRadioActivePerAppTimer.startRunningLocked(elapsedRealtime); |
| 4231 | } else { |
| 4232 | mMobileRadioActiveTimer.stopRunningLocked(realElapsedRealtimeMs); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 4233 | mMobileRadioActivePerAppTimer.stopRunningLocked(realElapsedRealtimeMs); |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 4234 | // Tell the caller to collect radio network/power stats. |
| 4235 | return true; |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 4236 | } |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 4237 | } |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 4238 | return false; |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 4239 | } |
| 4240 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 4241 | public void notePowerSaveModeLocked(boolean enabled) { |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4242 | if (mPowerSaveModeEnabled != enabled) { |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 4243 | int stepState = enabled ? STEP_LEVEL_MODE_POWER_SAVE : 0; |
| 4244 | mModStepMode |= (mCurStepMode&STEP_LEVEL_MODE_POWER_SAVE) ^ stepState; |
| 4245 | mCurStepMode = (mCurStepMode&~STEP_LEVEL_MODE_POWER_SAVE) | stepState; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4246 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4247 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4248 | mPowerSaveModeEnabled = enabled; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 4249 | if (enabled) { |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4250 | mHistoryCur.states2 |= HistoryItem.STATE2_POWER_SAVE_FLAG; |
| 4251 | if (DEBUG_HISTORY) Slog.v(TAG, "Power save mode enabled to: " |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 4252 | + Integer.toHexString(mHistoryCur.states2)); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4253 | mPowerSaveModeEnabledTimer.startRunningLocked(elapsedRealtime); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 4254 | } else { |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4255 | mHistoryCur.states2 &= ~HistoryItem.STATE2_POWER_SAVE_FLAG; |
| 4256 | if (DEBUG_HISTORY) Slog.v(TAG, "Power save mode disabled to: " |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 4257 | + Integer.toHexString(mHistoryCur.states2)); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4258 | mPowerSaveModeEnabledTimer.stopRunningLocked(elapsedRealtime); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 4259 | } |
| 4260 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 4261 | } |
| 4262 | } |
| 4263 | |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4264 | public void noteDeviceIdleModeLocked(int mode, String activeReason, int activeUid) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4265 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4266 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 4267 | boolean nowIdling = mode == DEVICE_IDLE_MODE_DEEP; |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4268 | if (mDeviceIdling && !nowIdling && activeReason == null) { |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 4269 | // We don't go out of general idling mode until explicitly taken out of |
| 4270 | // device idle through going active or significant motion. |
| 4271 | nowIdling = true; |
| 4272 | } |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4273 | boolean nowLightIdling = mode == DEVICE_IDLE_MODE_LIGHT; |
| 4274 | if (mDeviceLightIdling && !nowLightIdling && !nowIdling && activeReason == null) { |
| 4275 | // We don't go out of general light idling mode until explicitly taken out of |
| 4276 | // device idle through going active or significant motion. |
| 4277 | nowLightIdling = true; |
| 4278 | } |
| 4279 | if (activeReason != null && (mDeviceIdling || mDeviceLightIdling)) { |
| 4280 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_ACTIVE, |
| 4281 | activeReason, activeUid); |
| 4282 | } |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 4283 | if (mDeviceIdling != nowIdling) { |
| 4284 | mDeviceIdling = nowIdling; |
| 4285 | int stepState = nowIdling ? STEP_LEVEL_MODE_DEVICE_IDLE : 0; |
| 4286 | mModStepMode |= (mCurStepMode&STEP_LEVEL_MODE_DEVICE_IDLE) ^ stepState; |
| 4287 | mCurStepMode = (mCurStepMode&~STEP_LEVEL_MODE_DEVICE_IDLE) | stepState; |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4288 | if (nowIdling) { |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 4289 | mDeviceIdlingTimer.startRunningLocked(elapsedRealtime); |
| 4290 | } else { |
| 4291 | mDeviceIdlingTimer.stopRunningLocked(elapsedRealtime); |
| 4292 | } |
| 4293 | } |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4294 | if (mDeviceLightIdling != nowLightIdling) { |
| 4295 | mDeviceLightIdling = nowLightIdling; |
| 4296 | if (nowLightIdling) { |
| 4297 | mDeviceLightIdlingTimer.startRunningLocked(elapsedRealtime); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4298 | } else { |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4299 | mDeviceLightIdlingTimer.stopRunningLocked(elapsedRealtime); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4300 | } |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4301 | } |
| 4302 | if (mDeviceIdleMode != mode) { |
| 4303 | mHistoryCur.states2 = (mHistoryCur.states2 & ~HistoryItem.STATE2_DEVICE_IDLE_MASK) |
| 4304 | | (mode << HistoryItem.STATE2_DEVICE_IDLE_SHIFT); |
| 4305 | if (DEBUG_HISTORY) Slog.v(TAG, "Device idle mode changed to: " |
| 4306 | + Integer.toHexString(mHistoryCur.states2)); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4307 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4308 | long lastDuration = elapsedRealtime - mLastIdleTimeStart; |
| 4309 | mLastIdleTimeStart = elapsedRealtime; |
| 4310 | if (mDeviceIdleMode == DEVICE_IDLE_MODE_LIGHT) { |
| 4311 | if (lastDuration > mLongestLightIdleTime) { |
| 4312 | mLongestLightIdleTime = lastDuration; |
| 4313 | } |
| 4314 | mDeviceIdleModeLightTimer.stopRunningLocked(elapsedRealtime); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 4315 | } else if (mDeviceIdleMode == DEVICE_IDLE_MODE_DEEP) { |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4316 | if (lastDuration > mLongestFullIdleTime) { |
| 4317 | mLongestFullIdleTime = lastDuration; |
| 4318 | } |
| 4319 | mDeviceIdleModeFullTimer.stopRunningLocked(elapsedRealtime); |
| 4320 | } |
| 4321 | if (mode == DEVICE_IDLE_MODE_LIGHT) { |
| 4322 | mDeviceIdleModeLightTimer.startRunningLocked(elapsedRealtime); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 4323 | } else if (mode == DEVICE_IDLE_MODE_DEEP) { |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4324 | mDeviceIdleModeFullTimer.startRunningLocked(elapsedRealtime); |
| 4325 | } |
| 4326 | mDeviceIdleMode = mode; |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4327 | } |
| 4328 | } |
| 4329 | |
| 4330 | public void notePackageInstalledLocked(String pkgName, int versionCode) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4331 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4332 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4333 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_PACKAGE_INSTALLED, |
| 4334 | pkgName, versionCode); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 4335 | PackageChange pc = new PackageChange(); |
| 4336 | pc.mPackageName = pkgName; |
| 4337 | pc.mUpdate = true; |
| 4338 | pc.mVersionCode = versionCode; |
| 4339 | addPackageChange(pc); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4340 | } |
| 4341 | |
| 4342 | public void notePackageUninstalledLocked(String pkgName) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4343 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4344 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4345 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_PACKAGE_UNINSTALLED, |
| 4346 | pkgName, 0); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 4347 | PackageChange pc = new PackageChange(); |
| 4348 | pc.mPackageName = pkgName; |
| 4349 | pc.mUpdate = true; |
| 4350 | addPackageChange(pc); |
| 4351 | } |
| 4352 | |
| 4353 | private void addPackageChange(PackageChange pc) { |
| 4354 | if (mDailyPackageChanges == null) { |
| 4355 | mDailyPackageChanges = new ArrayList<>(); |
| 4356 | } |
| 4357 | mDailyPackageChanges.add(pc); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4358 | } |
| 4359 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4360 | public void notePhoneOnLocked() { |
| 4361 | if (!mPhoneOn) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4362 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4363 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 4364 | mHistoryCur.states2 |= HistoryItem.STATE2_PHONE_IN_CALL_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4365 | if (DEBUG_HISTORY) Slog.v(TAG, "Phone on to: " |
| 4366 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 4367 | addHistoryRecordLocked(elapsedRealtime, uptime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4368 | mPhoneOn = true; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4369 | mPhoneOnTimer.startRunningLocked(elapsedRealtime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4370 | } |
| 4371 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4372 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4373 | public void notePhoneOffLocked() { |
| 4374 | if (mPhoneOn) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4375 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4376 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 4377 | mHistoryCur.states2 &= ~HistoryItem.STATE2_PHONE_IN_CALL_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4378 | if (DEBUG_HISTORY) Slog.v(TAG, "Phone off to: " |
| 4379 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 4380 | addHistoryRecordLocked(elapsedRealtime, uptime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4381 | mPhoneOn = false; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4382 | mPhoneOnTimer.stopRunningLocked(elapsedRealtime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4383 | } |
| 4384 | } |
Amith Yamasani | 32dbefd | 2009-06-19 09:21:17 -0700 | [diff] [blame] | 4385 | |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 4386 | void stopAllPhoneSignalStrengthTimersLocked(int except) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4387 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 4388 | for (int i = 0; i < SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 4389 | if (i == except) { |
| 4390 | continue; |
| 4391 | } |
| 4392 | while (mPhoneSignalStrengthsTimer[i].isRunningLocked()) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4393 | mPhoneSignalStrengthsTimer[i].stopRunningLocked(elapsedRealtime); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 4394 | } |
| 4395 | } |
| 4396 | } |
| 4397 | |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 4398 | private int fixPhoneServiceState(int state, int signalBin) { |
| 4399 | if (mPhoneSimStateRaw == TelephonyManager.SIM_STATE_ABSENT) { |
| 4400 | // In this case we will always be STATE_OUT_OF_SERVICE, so need |
| 4401 | // to infer that we are scanning from other data. |
| 4402 | if (state == ServiceState.STATE_OUT_OF_SERVICE |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 4403 | && signalBin > SignalStrength.SIGNAL_STRENGTH_NONE_OR_UNKNOWN) { |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 4404 | state = ServiceState.STATE_IN_SERVICE; |
| 4405 | } |
| 4406 | } |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 4407 | |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 4408 | return state; |
| 4409 | } |
| 4410 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4411 | private void updateAllPhoneStateLocked(int state, int simState, int strengthBin) { |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 4412 | boolean scanning = false; |
| 4413 | boolean newHistory = false; |
| 4414 | |
| 4415 | mPhoneServiceStateRaw = state; |
| 4416 | mPhoneSimStateRaw = simState; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4417 | mPhoneSignalStrengthBinRaw = strengthBin; |
| 4418 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4419 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4420 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 4421 | |
| 4422 | if (simState == TelephonyManager.SIM_STATE_ABSENT) { |
| 4423 | // In this case we will always be STATE_OUT_OF_SERVICE, so need |
| 4424 | // to infer that we are scanning from other data. |
| 4425 | if (state == ServiceState.STATE_OUT_OF_SERVICE |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4426 | && strengthBin > SignalStrength.SIGNAL_STRENGTH_NONE_OR_UNKNOWN) { |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 4427 | state = ServiceState.STATE_IN_SERVICE; |
| 4428 | } |
| 4429 | } |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 4430 | |
| 4431 | // If the phone is powered off, stop all timers. |
| 4432 | if (state == ServiceState.STATE_POWER_OFF) { |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4433 | strengthBin = -1; |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 4434 | |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 4435 | // If we are in service, make sure the correct signal string timer is running. |
| 4436 | } else if (state == ServiceState.STATE_IN_SERVICE) { |
| 4437 | // Bin will be changed below. |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 4438 | |
| 4439 | // If we're out of service, we are in the lowest signal strength |
| 4440 | // bin and have the scanning bit set. |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 4441 | } else if (state == ServiceState.STATE_OUT_OF_SERVICE) { |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 4442 | scanning = true; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4443 | strengthBin = SignalStrength.SIGNAL_STRENGTH_NONE_OR_UNKNOWN; |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 4444 | if (!mPhoneSignalScanningTimer.isRunningLocked()) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4445 | mHistoryCur.states |= HistoryItem.STATE_PHONE_SCANNING_FLAG; |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 4446 | newHistory = true; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4447 | if (DEBUG_HISTORY) Slog.v(TAG, "Phone started scanning to: " |
| 4448 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4449 | mPhoneSignalScanningTimer.startRunningLocked(elapsedRealtime); |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 4450 | } |
| 4451 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4452 | |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 4453 | if (!scanning) { |
| 4454 | // If we are no longer scanning, then stop the scanning timer. |
| 4455 | if (mPhoneSignalScanningTimer.isRunningLocked()) { |
| 4456 | mHistoryCur.states &= ~HistoryItem.STATE_PHONE_SCANNING_FLAG; |
| 4457 | if (DEBUG_HISTORY) Slog.v(TAG, "Phone stopped scanning to: " |
| 4458 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 4459 | newHistory = true; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4460 | mPhoneSignalScanningTimer.stopRunningLocked(elapsedRealtime); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 4461 | } |
| 4462 | } |
| 4463 | |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4464 | if (mPhoneServiceState != state) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4465 | mHistoryCur.states = (mHistoryCur.states&~HistoryItem.STATE_PHONE_STATE_MASK) |
| 4466 | | (state << HistoryItem.STATE_PHONE_STATE_SHIFT); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 4467 | if (DEBUG_HISTORY) Slog.v(TAG, "Phone state " + state + " to: " |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4468 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 4469 | newHistory = true; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4470 | mPhoneServiceState = state; |
| 4471 | } |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 4472 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4473 | if (mPhoneSignalStrengthBin != strengthBin) { |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 4474 | if (mPhoneSignalStrengthBin >= 0) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4475 | mPhoneSignalStrengthsTimer[mPhoneSignalStrengthBin].stopRunningLocked( |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4476 | elapsedRealtime); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 4477 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4478 | if (strengthBin >= 0) { |
| 4479 | if (!mPhoneSignalStrengthsTimer[strengthBin].isRunningLocked()) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4480 | mPhoneSignalStrengthsTimer[strengthBin].startRunningLocked(elapsedRealtime); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 4481 | } |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 4482 | mHistoryCur.states = (mHistoryCur.states&~HistoryItem.STATE_PHONE_SIGNAL_STRENGTH_MASK) |
| 4483 | | (strengthBin << HistoryItem.STATE_PHONE_SIGNAL_STRENGTH_SHIFT); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4484 | if (DEBUG_HISTORY) Slog.v(TAG, "Signal strength " + strengthBin + " to: " |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 4485 | + Integer.toHexString(mHistoryCur.states)); |
| 4486 | newHistory = true; |
| 4487 | } else { |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 4488 | stopAllPhoneSignalStrengthTimersLocked(-1); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 4489 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4490 | mPhoneSignalStrengthBin = strengthBin; |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 4491 | } |
| 4492 | |
| 4493 | if (newHistory) { |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 4494 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 4495 | } |
| 4496 | } |
| 4497 | |
| 4498 | /** |
| 4499 | * Telephony stack updates the phone state. |
| 4500 | * @param state phone state from ServiceState.getState() |
| 4501 | */ |
| 4502 | public void notePhoneStateLocked(int state, int simState) { |
| 4503 | updateAllPhoneStateLocked(state, simState, mPhoneSignalStrengthBinRaw); |
Amith Yamasani | 32dbefd | 2009-06-19 09:21:17 -0700 | [diff] [blame] | 4504 | } |
| 4505 | |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 4506 | public void notePhoneSignalStrengthLocked(SignalStrength signalStrength) { |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4507 | // Bin the strength. |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 4508 | int bin = signalStrength.getLevel(); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 4509 | updateAllPhoneStateLocked(mPhoneServiceStateRaw, mPhoneSimStateRaw, bin); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4510 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4511 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4512 | public void notePhoneDataConnectionStateLocked(int dataType, boolean hasData) { |
| 4513 | int bin = DATA_CONNECTION_NONE; |
| 4514 | if (hasData) { |
| 4515 | switch (dataType) { |
| 4516 | case TelephonyManager.NETWORK_TYPE_EDGE: |
| 4517 | bin = DATA_CONNECTION_EDGE; |
| 4518 | break; |
| 4519 | case TelephonyManager.NETWORK_TYPE_GPRS: |
| 4520 | bin = DATA_CONNECTION_GPRS; |
| 4521 | break; |
| 4522 | case TelephonyManager.NETWORK_TYPE_UMTS: |
| 4523 | bin = DATA_CONNECTION_UMTS; |
| 4524 | break; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4525 | case TelephonyManager.NETWORK_TYPE_CDMA: |
| 4526 | bin = DATA_CONNECTION_CDMA; |
| 4527 | break; |
| 4528 | case TelephonyManager.NETWORK_TYPE_EVDO_0: |
| 4529 | bin = DATA_CONNECTION_EVDO_0; |
| 4530 | break; |
| 4531 | case TelephonyManager.NETWORK_TYPE_EVDO_A: |
| 4532 | bin = DATA_CONNECTION_EVDO_A; |
| 4533 | break; |
| 4534 | case TelephonyManager.NETWORK_TYPE_1xRTT: |
| 4535 | bin = DATA_CONNECTION_1xRTT; |
| 4536 | break; |
| 4537 | case TelephonyManager.NETWORK_TYPE_HSDPA: |
| 4538 | bin = DATA_CONNECTION_HSDPA; |
| 4539 | break; |
| 4540 | case TelephonyManager.NETWORK_TYPE_HSUPA: |
| 4541 | bin = DATA_CONNECTION_HSUPA; |
| 4542 | break; |
| 4543 | case TelephonyManager.NETWORK_TYPE_HSPA: |
| 4544 | bin = DATA_CONNECTION_HSPA; |
| 4545 | break; |
| 4546 | case TelephonyManager.NETWORK_TYPE_IDEN: |
| 4547 | bin = DATA_CONNECTION_IDEN; |
| 4548 | break; |
| 4549 | case TelephonyManager.NETWORK_TYPE_EVDO_B: |
| 4550 | bin = DATA_CONNECTION_EVDO_B; |
| 4551 | break; |
Robert Greenwalt | 962a990 | 2010-11-02 11:10:25 -0700 | [diff] [blame] | 4552 | case TelephonyManager.NETWORK_TYPE_LTE: |
| 4553 | bin = DATA_CONNECTION_LTE; |
| 4554 | break; |
| 4555 | case TelephonyManager.NETWORK_TYPE_EHRPD: |
| 4556 | bin = DATA_CONNECTION_EHRPD; |
| 4557 | break; |
Patrick Tjin | b71703c | 2013-11-06 09:27:03 -0800 | [diff] [blame] | 4558 | case TelephonyManager.NETWORK_TYPE_HSPAP: |
| 4559 | bin = DATA_CONNECTION_HSPAP; |
| 4560 | break; |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4561 | default: |
| 4562 | bin = DATA_CONNECTION_OTHER; |
| 4563 | break; |
| 4564 | } |
| 4565 | } |
Amith Yamasani | 3718aaa | 2009-06-09 06:32:35 -0700 | [diff] [blame] | 4566 | if (DEBUG) Log.i(TAG, "Phone Data Connection -> " + dataType + " = " + hasData); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4567 | if (mPhoneDataConnectionType != bin) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4568 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4569 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4570 | mHistoryCur.states = (mHistoryCur.states&~HistoryItem.STATE_DATA_CONNECTION_MASK) |
| 4571 | | (bin << HistoryItem.STATE_DATA_CONNECTION_SHIFT); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4572 | if (DEBUG_HISTORY) Slog.v(TAG, "Data connection " + bin + " to: " |
| 4573 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 4574 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4575 | if (mPhoneDataConnectionType >= 0) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4576 | mPhoneDataConnectionsTimer[mPhoneDataConnectionType].stopRunningLocked( |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4577 | elapsedRealtime); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4578 | } |
| 4579 | mPhoneDataConnectionType = bin; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4580 | mPhoneDataConnectionsTimer[bin].startRunningLocked(elapsedRealtime); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4581 | } |
| 4582 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4583 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 4584 | public void noteWifiOnLocked() { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4585 | if (!mWifiOn) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4586 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4587 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 4588 | mHistoryCur.states2 |= HistoryItem.STATE2_WIFI_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4589 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI on to: " |
| 4590 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 4591 | addHistoryRecordLocked(elapsedRealtime, uptime); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4592 | mWifiOn = true; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4593 | mWifiOnTimer.startRunningLocked(elapsedRealtime); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 4594 | scheduleSyncExternalStatsLocked("wifi-off", ExternalStatsSync.UPDATE_WIFI); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4595 | } |
| 4596 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4597 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 4598 | public void noteWifiOffLocked() { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4599 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4600 | final long uptime = mClocks.uptimeMillis(); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4601 | if (mWifiOn) { |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 4602 | mHistoryCur.states2 &= ~HistoryItem.STATE2_WIFI_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4603 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI off to: " |
| 4604 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 4605 | addHistoryRecordLocked(elapsedRealtime, uptime); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4606 | mWifiOn = false; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4607 | mWifiOnTimer.stopRunningLocked(elapsedRealtime); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 4608 | scheduleSyncExternalStatsLocked("wifi-on", ExternalStatsSync.UPDATE_WIFI); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4609 | } |
| 4610 | } |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 4611 | |
| 4612 | public void noteAudioOnLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4613 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4614 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4615 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 4616 | if (mAudioOnNesting == 0) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4617 | mHistoryCur.states |= HistoryItem.STATE_AUDIO_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4618 | if (DEBUG_HISTORY) Slog.v(TAG, "Audio on to: " |
| 4619 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 4620 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4621 | mAudioOnTimer.startRunningLocked(elapsedRealtime); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 4622 | } |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 4623 | mAudioOnNesting++; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4624 | getUidStatsLocked(uid).noteAudioTurnedOnLocked(elapsedRealtime); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 4625 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4626 | |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 4627 | public void noteAudioOffLocked(int uid) { |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 4628 | if (mAudioOnNesting == 0) { |
| 4629 | return; |
| 4630 | } |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4631 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4632 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4633 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 4634 | if (--mAudioOnNesting == 0) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4635 | mHistoryCur.states &= ~HistoryItem.STATE_AUDIO_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4636 | if (DEBUG_HISTORY) Slog.v(TAG, "Audio off to: " |
| 4637 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 4638 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4639 | mAudioOnTimer.stopRunningLocked(elapsedRealtime); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 4640 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4641 | getUidStatsLocked(uid).noteAudioTurnedOffLocked(elapsedRealtime); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 4642 | } |
| 4643 | |
| 4644 | public void noteVideoOnLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4645 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4646 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4647 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 4648 | if (mVideoOnNesting == 0) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 4649 | mHistoryCur.states2 |= HistoryItem.STATE2_VIDEO_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4650 | if (DEBUG_HISTORY) Slog.v(TAG, "Video on to: " |
| 4651 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 4652 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4653 | mVideoOnTimer.startRunningLocked(elapsedRealtime); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 4654 | } |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 4655 | mVideoOnNesting++; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4656 | getUidStatsLocked(uid).noteVideoTurnedOnLocked(elapsedRealtime); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 4657 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4658 | |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 4659 | public void noteVideoOffLocked(int uid) { |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 4660 | if (mVideoOnNesting == 0) { |
| 4661 | return; |
| 4662 | } |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4663 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4664 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4665 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 4666 | if (--mVideoOnNesting == 0) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 4667 | mHistoryCur.states2 &= ~HistoryItem.STATE2_VIDEO_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4668 | if (DEBUG_HISTORY) Slog.v(TAG, "Video off to: " |
| 4669 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 4670 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4671 | mVideoOnTimer.stopRunningLocked(elapsedRealtime); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 4672 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4673 | getUidStatsLocked(uid).noteVideoTurnedOffLocked(elapsedRealtime); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 4674 | } |
| 4675 | |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 4676 | public void noteResetAudioLocked() { |
| 4677 | if (mAudioOnNesting > 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4678 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4679 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 4680 | mAudioOnNesting = 0; |
| 4681 | mHistoryCur.states &= ~HistoryItem.STATE_AUDIO_ON_FLAG; |
| 4682 | if (DEBUG_HISTORY) Slog.v(TAG, "Audio off to: " |
| 4683 | + Integer.toHexString(mHistoryCur.states)); |
| 4684 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 4685 | mAudioOnTimer.stopAllRunningLocked(elapsedRealtime); |
| 4686 | for (int i=0; i<mUidStats.size(); i++) { |
| 4687 | BatteryStatsImpl.Uid uid = mUidStats.valueAt(i); |
| 4688 | uid.noteResetAudioLocked(elapsedRealtime); |
| 4689 | } |
| 4690 | } |
| 4691 | } |
| 4692 | |
| 4693 | public void noteResetVideoLocked() { |
| 4694 | if (mVideoOnNesting > 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4695 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4696 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 4697 | mAudioOnNesting = 0; |
| 4698 | mHistoryCur.states2 &= ~HistoryItem.STATE2_VIDEO_ON_FLAG; |
| 4699 | if (DEBUG_HISTORY) Slog.v(TAG, "Video off to: " |
| 4700 | + Integer.toHexString(mHistoryCur.states)); |
| 4701 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 4702 | mVideoOnTimer.stopAllRunningLocked(elapsedRealtime); |
| 4703 | for (int i=0; i<mUidStats.size(); i++) { |
| 4704 | BatteryStatsImpl.Uid uid = mUidStats.valueAt(i); |
| 4705 | uid.noteResetVideoLocked(elapsedRealtime); |
| 4706 | } |
| 4707 | } |
| 4708 | } |
| 4709 | |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 4710 | public void noteActivityResumedLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4711 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4712 | getUidStatsLocked(uid).noteActivityResumedLocked(mClocks.elapsedRealtime()); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 4713 | } |
| 4714 | |
| 4715 | public void noteActivityPausedLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4716 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4717 | getUidStatsLocked(uid).noteActivityPausedLocked(mClocks.elapsedRealtime()); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 4718 | } |
| 4719 | |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 4720 | public void noteVibratorOnLocked(int uid, long durationMillis) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4721 | uid = mapUid(uid); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 4722 | getUidStatsLocked(uid).noteVibratorOnLocked(durationMillis); |
| 4723 | } |
| 4724 | |
| 4725 | public void noteVibratorOffLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4726 | uid = mapUid(uid); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 4727 | getUidStatsLocked(uid).noteVibratorOffLocked(); |
| 4728 | } |
| 4729 | |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 4730 | public void noteFlashlightOnLocked(int uid) { |
| 4731 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4732 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4733 | final long uptime = mClocks.uptimeMillis(); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 4734 | if (mFlashlightOnNesting++ == 0) { |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 4735 | mHistoryCur.states2 |= HistoryItem.STATE2_FLASHLIGHT_FLAG; |
| 4736 | if (DEBUG_HISTORY) Slog.v(TAG, "Flashlight on to: " |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 4737 | + Integer.toHexString(mHistoryCur.states2)); |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 4738 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 4739 | mFlashlightOnTimer.startRunningLocked(elapsedRealtime); |
| 4740 | } |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 4741 | getUidStatsLocked(uid).noteFlashlightTurnedOnLocked(elapsedRealtime); |
| 4742 | } |
| 4743 | |
| 4744 | public void noteFlashlightOffLocked(int uid) { |
| 4745 | if (mFlashlightOnNesting == 0) { |
| 4746 | return; |
| 4747 | } |
| 4748 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4749 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4750 | final long uptime = mClocks.uptimeMillis(); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 4751 | if (--mFlashlightOnNesting == 0) { |
| 4752 | mHistoryCur.states2 &= ~HistoryItem.STATE2_FLASHLIGHT_FLAG; |
| 4753 | if (DEBUG_HISTORY) Slog.v(TAG, "Flashlight off to: " |
| 4754 | + Integer.toHexString(mHistoryCur.states2)); |
| 4755 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 4756 | mFlashlightOnTimer.stopRunningLocked(elapsedRealtime); |
| 4757 | } |
| 4758 | getUidStatsLocked(uid).noteFlashlightTurnedOffLocked(elapsedRealtime); |
| 4759 | } |
| 4760 | |
| 4761 | public void noteCameraOnLocked(int uid) { |
| 4762 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4763 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4764 | final long uptime = mClocks.uptimeMillis(); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 4765 | if (mCameraOnNesting++ == 0) { |
| 4766 | mHistoryCur.states2 |= HistoryItem.STATE2_CAMERA_FLAG; |
| 4767 | if (DEBUG_HISTORY) Slog.v(TAG, "Camera on to: " |
| 4768 | + Integer.toHexString(mHistoryCur.states2)); |
| 4769 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 4770 | mCameraOnTimer.startRunningLocked(elapsedRealtime); |
| 4771 | } |
| 4772 | getUidStatsLocked(uid).noteCameraTurnedOnLocked(elapsedRealtime); |
| 4773 | } |
| 4774 | |
| 4775 | public void noteCameraOffLocked(int uid) { |
| 4776 | if (mCameraOnNesting == 0) { |
| 4777 | return; |
| 4778 | } |
| 4779 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4780 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4781 | final long uptime = mClocks.uptimeMillis(); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 4782 | if (--mCameraOnNesting == 0) { |
| 4783 | mHistoryCur.states2 &= ~HistoryItem.STATE2_CAMERA_FLAG; |
| 4784 | if (DEBUG_HISTORY) Slog.v(TAG, "Camera off to: " |
| 4785 | + Integer.toHexString(mHistoryCur.states2)); |
| 4786 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 4787 | mCameraOnTimer.stopRunningLocked(elapsedRealtime); |
| 4788 | } |
| 4789 | getUidStatsLocked(uid).noteCameraTurnedOffLocked(elapsedRealtime); |
| 4790 | } |
| 4791 | |
| 4792 | public void noteResetCameraLocked() { |
| 4793 | if (mCameraOnNesting > 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4794 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4795 | final long uptime = mClocks.uptimeMillis(); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 4796 | mCameraOnNesting = 0; |
| 4797 | mHistoryCur.states2 &= ~HistoryItem.STATE2_CAMERA_FLAG; |
| 4798 | if (DEBUG_HISTORY) Slog.v(TAG, "Camera off to: " |
| 4799 | + Integer.toHexString(mHistoryCur.states2)); |
| 4800 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 4801 | mCameraOnTimer.stopAllRunningLocked(elapsedRealtime); |
| 4802 | for (int i=0; i<mUidStats.size(); i++) { |
| 4803 | BatteryStatsImpl.Uid uid = mUidStats.valueAt(i); |
| 4804 | uid.noteResetCameraLocked(elapsedRealtime); |
| 4805 | } |
| 4806 | } |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 4807 | } |
| 4808 | |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 4809 | public void noteResetFlashlightLocked() { |
| 4810 | if (mFlashlightOnNesting > 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4811 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4812 | final long uptime = mClocks.uptimeMillis(); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 4813 | mFlashlightOnNesting = 0; |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 4814 | mHistoryCur.states2 &= ~HistoryItem.STATE2_FLASHLIGHT_FLAG; |
| 4815 | if (DEBUG_HISTORY) Slog.v(TAG, "Flashlight off to: " |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 4816 | + Integer.toHexString(mHistoryCur.states2)); |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 4817 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 4818 | mFlashlightOnTimer.stopAllRunningLocked(elapsedRealtime); |
| 4819 | for (int i=0; i<mUidStats.size(); i++) { |
| 4820 | BatteryStatsImpl.Uid uid = mUidStats.valueAt(i); |
| 4821 | uid.noteResetFlashlightLocked(elapsedRealtime); |
| 4822 | } |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 4823 | } |
| 4824 | } |
| 4825 | |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 4826 | private void noteBluetoothScanStartedLocked(int uid, boolean isUnoptimized) { |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 4827 | uid = mapUid(uid); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 4828 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4829 | final long uptime = mClocks.uptimeMillis(); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 4830 | if (mBluetoothScanNesting == 0) { |
| 4831 | mHistoryCur.states2 |= HistoryItem.STATE2_BLUETOOTH_SCAN_FLAG; |
| 4832 | if (DEBUG_HISTORY) Slog.v(TAG, "BLE scan started for: " |
| 4833 | + Integer.toHexString(mHistoryCur.states2)); |
| 4834 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Adam Lesinski | d9b99be | 2016-03-30 16:58:51 -0700 | [diff] [blame] | 4835 | mBluetoothScanTimer.startRunningLocked(elapsedRealtime); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 4836 | } |
| 4837 | mBluetoothScanNesting++; |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 4838 | getUidStatsLocked(uid).noteBluetoothScanStartedLocked(elapsedRealtime, isUnoptimized); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 4839 | } |
| 4840 | |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 4841 | public void noteBluetoothScanStartedFromSourceLocked(WorkSource ws, boolean isUnoptimized) { |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 4842 | final int N = ws.size(); |
| 4843 | for (int i = 0; i < N; i++) { |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 4844 | noteBluetoothScanStartedLocked(ws.get(i), isUnoptimized); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 4845 | } |
| 4846 | } |
| 4847 | |
Bookatz | 20e22f6 | 2017-07-11 16:49:17 -0700 | [diff] [blame] | 4848 | private void noteBluetoothScanStoppedLocked(int uid, boolean isUnoptimized) { |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 4849 | uid = mapUid(uid); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 4850 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4851 | final long uptime = mClocks.uptimeMillis(); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 4852 | mBluetoothScanNesting--; |
| 4853 | if (mBluetoothScanNesting == 0) { |
| 4854 | mHistoryCur.states2 &= ~HistoryItem.STATE2_BLUETOOTH_SCAN_FLAG; |
| 4855 | if (DEBUG_HISTORY) Slog.v(TAG, "BLE scan stopped for: " |
| 4856 | + Integer.toHexString(mHistoryCur.states2)); |
| 4857 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Adam Lesinski | d9b99be | 2016-03-30 16:58:51 -0700 | [diff] [blame] | 4858 | mBluetoothScanTimer.stopRunningLocked(elapsedRealtime); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 4859 | } |
Bookatz | 20e22f6 | 2017-07-11 16:49:17 -0700 | [diff] [blame] | 4860 | getUidStatsLocked(uid).noteBluetoothScanStoppedLocked(elapsedRealtime, isUnoptimized); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 4861 | } |
| 4862 | |
Bookatz | 20e22f6 | 2017-07-11 16:49:17 -0700 | [diff] [blame] | 4863 | public void noteBluetoothScanStoppedFromSourceLocked(WorkSource ws, boolean isUnoptimized) { |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 4864 | final int N = ws.size(); |
| 4865 | for (int i = 0; i < N; i++) { |
Bookatz | 20e22f6 | 2017-07-11 16:49:17 -0700 | [diff] [blame] | 4866 | noteBluetoothScanStoppedLocked(ws.get(i), isUnoptimized); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 4867 | } |
| 4868 | } |
| 4869 | |
| 4870 | public void noteResetBluetoothScanLocked() { |
| 4871 | if (mBluetoothScanNesting > 0) { |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 4872 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4873 | final long uptime = mClocks.uptimeMillis(); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 4874 | mBluetoothScanNesting = 0; |
| 4875 | mHistoryCur.states2 &= ~HistoryItem.STATE2_BLUETOOTH_SCAN_FLAG; |
| 4876 | if (DEBUG_HISTORY) Slog.v(TAG, "BLE can stopped for: " |
| 4877 | + Integer.toHexString(mHistoryCur.states2)); |
| 4878 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 4879 | mBluetoothScanTimer.stopAllRunningLocked(elapsedRealtime); |
| 4880 | for (int i=0; i<mUidStats.size(); i++) { |
| 4881 | BatteryStatsImpl.Uid uid = mUidStats.valueAt(i); |
| 4882 | uid.noteResetBluetoothScanLocked(elapsedRealtime); |
| 4883 | } |
| 4884 | } |
| 4885 | } |
| 4886 | |
Bookatz | 4ebc064 | 2017-05-11 12:21:19 -0700 | [diff] [blame] | 4887 | public void noteBluetoothScanResultsFromSourceLocked(WorkSource ws, int numNewResults) { |
Bookatz | 956f36bf | 2017-04-28 09:48:17 -0700 | [diff] [blame] | 4888 | final int N = ws.size(); |
| 4889 | for (int i = 0; i < N; i++) { |
| 4890 | int uid = mapUid(ws.get(i)); |
Bookatz | 4ebc064 | 2017-05-11 12:21:19 -0700 | [diff] [blame] | 4891 | getUidStatsLocked(uid).noteBluetoothScanResultsLocked(numNewResults); |
Bookatz | 956f36bf | 2017-04-28 09:48:17 -0700 | [diff] [blame] | 4892 | } |
| 4893 | } |
| 4894 | |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 4895 | private void noteWifiRadioApWakeupLocked(final long elapsedRealtimeMillis, |
| 4896 | final long uptimeMillis, int uid) { |
| 4897 | uid = mapUid(uid); |
| 4898 | addHistoryEventLocked(elapsedRealtimeMillis, uptimeMillis, HistoryItem.EVENT_WAKEUP_AP, "", |
| 4899 | uid); |
| 4900 | getUidStatsLocked(uid).noteWifiRadioApWakeupLocked(); |
| 4901 | } |
| 4902 | |
| 4903 | public void noteWifiRadioPowerState(int powerState, long timestampNs, int uid) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4904 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4905 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 4906 | if (mWifiRadioPowerState != powerState) { |
| 4907 | final boolean active = |
| 4908 | powerState == DataConnectionRealTimeInfo.DC_POWER_STATE_MEDIUM |
| 4909 | || powerState == DataConnectionRealTimeInfo.DC_POWER_STATE_HIGH; |
| 4910 | if (active) { |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 4911 | if (uid > 0) { |
| 4912 | noteWifiRadioApWakeupLocked(elapsedRealtime, uptime, uid); |
| 4913 | } |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 4914 | mHistoryCur.states |= HistoryItem.STATE_WIFI_RADIO_ACTIVE_FLAG; |
| 4915 | } else { |
| 4916 | mHistoryCur.states &= ~HistoryItem.STATE_WIFI_RADIO_ACTIVE_FLAG; |
| 4917 | } |
| 4918 | if (DEBUG_HISTORY) Slog.v(TAG, "Wifi network active " + active + " to: " |
| 4919 | + Integer.toHexString(mHistoryCur.states)); |
| 4920 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 4921 | mWifiRadioPowerState = powerState; |
| 4922 | } |
| 4923 | } |
| 4924 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 4925 | public void noteWifiRunningLocked(WorkSource ws) { |
| 4926 | if (!mGlobalWifiRunning) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4927 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4928 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 4929 | mHistoryCur.states2 |= HistoryItem.STATE2_WIFI_RUNNING_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4930 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI running to: " |
| 4931 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 4932 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 4933 | mGlobalWifiRunning = true; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4934 | mGlobalWifiRunningTimer.startRunningLocked(elapsedRealtime); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 4935 | int N = ws.size(); |
| 4936 | for (int i=0; i<N; i++) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4937 | int uid = mapUid(ws.get(i)); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4938 | getUidStatsLocked(uid).noteWifiRunningLocked(elapsedRealtime); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 4939 | } |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 4940 | scheduleSyncExternalStatsLocked("wifi-running", ExternalStatsSync.UPDATE_WIFI); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 4941 | } else { |
| 4942 | Log.w(TAG, "noteWifiRunningLocked -- called while WIFI running"); |
Eric Shienbrood | d4c5f89 | 2009-03-24 18:13:20 -0700 | [diff] [blame] | 4943 | } |
| 4944 | } |
| 4945 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 4946 | public void noteWifiRunningChangedLocked(WorkSource oldWs, WorkSource newWs) { |
| 4947 | if (mGlobalWifiRunning) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4948 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 4949 | int N = oldWs.size(); |
| 4950 | for (int i=0; i<N; i++) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4951 | int uid = mapUid(oldWs.get(i)); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4952 | getUidStatsLocked(uid).noteWifiStoppedLocked(elapsedRealtime); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 4953 | } |
| 4954 | N = newWs.size(); |
| 4955 | for (int i=0; i<N; i++) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4956 | int uid = mapUid(newWs.get(i)); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4957 | getUidStatsLocked(uid).noteWifiRunningLocked(elapsedRealtime); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 4958 | } |
| 4959 | } else { |
| 4960 | Log.w(TAG, "noteWifiRunningChangedLocked -- called while WIFI not running"); |
| 4961 | } |
| 4962 | } |
| 4963 | |
| 4964 | public void noteWifiStoppedLocked(WorkSource ws) { |
| 4965 | if (mGlobalWifiRunning) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4966 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4967 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 4968 | mHistoryCur.states2 &= ~HistoryItem.STATE2_WIFI_RUNNING_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4969 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI stopped to: " |
| 4970 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 4971 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 4972 | mGlobalWifiRunning = false; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4973 | mGlobalWifiRunningTimer.stopRunningLocked(elapsedRealtime); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 4974 | int N = ws.size(); |
| 4975 | for (int i=0; i<N; i++) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4976 | int uid = mapUid(ws.get(i)); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4977 | getUidStatsLocked(uid).noteWifiStoppedLocked(elapsedRealtime); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 4978 | } |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 4979 | scheduleSyncExternalStatsLocked("wifi-stopped", ExternalStatsSync.UPDATE_WIFI); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 4980 | } else { |
| 4981 | Log.w(TAG, "noteWifiStoppedLocked -- called while WIFI not running"); |
Eric Shienbrood | d4c5f89 | 2009-03-24 18:13:20 -0700 | [diff] [blame] | 4982 | } |
| 4983 | } |
| 4984 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4985 | public void noteWifiStateLocked(int wifiState, String accessPoint) { |
| 4986 | if (DEBUG) Log.i(TAG, "WiFi state -> " + wifiState); |
| 4987 | if (mWifiState != wifiState) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4988 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4989 | if (mWifiState >= 0) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4990 | mWifiStateTimer[mWifiState].stopRunningLocked(elapsedRealtime); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4991 | } |
| 4992 | mWifiState = wifiState; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4993 | mWifiStateTimer[wifiState].startRunningLocked(elapsedRealtime); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 4994 | scheduleSyncExternalStatsLocked("wifi-state", ExternalStatsSync.UPDATE_WIFI); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4995 | } |
| 4996 | } |
| 4997 | |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 4998 | public void noteWifiSupplicantStateChangedLocked(int supplState, boolean failedAuth) { |
| 4999 | if (DEBUG) Log.i(TAG, "WiFi suppl state -> " + supplState); |
| 5000 | if (mWifiSupplState != supplState) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5001 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 5002 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 5003 | if (mWifiSupplState >= 0) { |
| 5004 | mWifiSupplStateTimer[mWifiSupplState].stopRunningLocked(elapsedRealtime); |
| 5005 | } |
| 5006 | mWifiSupplState = supplState; |
| 5007 | mWifiSupplStateTimer[supplState].startRunningLocked(elapsedRealtime); |
| 5008 | mHistoryCur.states2 = |
| 5009 | (mHistoryCur.states2&~HistoryItem.STATE2_WIFI_SUPPL_STATE_MASK) |
| 5010 | | (supplState << HistoryItem.STATE2_WIFI_SUPPL_STATE_SHIFT); |
| 5011 | if (DEBUG_HISTORY) Slog.v(TAG, "Wifi suppl state " + supplState + " to: " |
| 5012 | + Integer.toHexString(mHistoryCur.states2)); |
| 5013 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 5014 | } |
| 5015 | } |
| 5016 | |
| 5017 | void stopAllWifiSignalStrengthTimersLocked(int except) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5018 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 5019 | for (int i = 0; i < NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 5020 | if (i == except) { |
| 5021 | continue; |
| 5022 | } |
| 5023 | while (mWifiSignalStrengthsTimer[i].isRunningLocked()) { |
| 5024 | mWifiSignalStrengthsTimer[i].stopRunningLocked(elapsedRealtime); |
| 5025 | } |
| 5026 | } |
| 5027 | } |
| 5028 | |
| 5029 | public void noteWifiRssiChangedLocked(int newRssi) { |
| 5030 | int strengthBin = WifiManager.calculateSignalLevel(newRssi, NUM_WIFI_SIGNAL_STRENGTH_BINS); |
| 5031 | if (DEBUG) Log.i(TAG, "WiFi rssi -> " + newRssi + " bin=" + strengthBin); |
| 5032 | if (mWifiSignalStrengthBin != strengthBin) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5033 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 5034 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 5035 | if (mWifiSignalStrengthBin >= 0) { |
| 5036 | mWifiSignalStrengthsTimer[mWifiSignalStrengthBin].stopRunningLocked( |
| 5037 | elapsedRealtime); |
| 5038 | } |
| 5039 | if (strengthBin >= 0) { |
| 5040 | if (!mWifiSignalStrengthsTimer[strengthBin].isRunningLocked()) { |
| 5041 | mWifiSignalStrengthsTimer[strengthBin].startRunningLocked(elapsedRealtime); |
| 5042 | } |
| 5043 | mHistoryCur.states2 = |
| 5044 | (mHistoryCur.states2&~HistoryItem.STATE2_WIFI_SIGNAL_STRENGTH_MASK) |
| 5045 | | (strengthBin << HistoryItem.STATE2_WIFI_SIGNAL_STRENGTH_SHIFT); |
| 5046 | if (DEBUG_HISTORY) Slog.v(TAG, "Wifi signal strength " + strengthBin + " to: " |
| 5047 | + Integer.toHexString(mHistoryCur.states2)); |
| 5048 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 5049 | } else { |
| 5050 | stopAllWifiSignalStrengthTimersLocked(-1); |
| 5051 | } |
| 5052 | mWifiSignalStrengthBin = strengthBin; |
| 5053 | } |
| 5054 | } |
| 5055 | |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 5056 | int mWifiFullLockNesting = 0; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5057 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 5058 | public void noteFullWifiLockAcquiredLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 5059 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5060 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 5061 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 5062 | if (mWifiFullLockNesting == 0) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5063 | mHistoryCur.states |= HistoryItem.STATE_WIFI_FULL_LOCK_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 5064 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI full lock on to: " |
| 5065 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 5066 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 5067 | } |
| 5068 | mWifiFullLockNesting++; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 5069 | getUidStatsLocked(uid).noteFullWifiLockAcquiredLocked(elapsedRealtime); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 5070 | } |
| 5071 | |
| 5072 | public void noteFullWifiLockReleasedLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 5073 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5074 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 5075 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 5076 | mWifiFullLockNesting--; |
| 5077 | if (mWifiFullLockNesting == 0) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5078 | mHistoryCur.states &= ~HistoryItem.STATE_WIFI_FULL_LOCK_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 5079 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI full lock off to: " |
| 5080 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 5081 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 5082 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 5083 | getUidStatsLocked(uid).noteFullWifiLockReleasedLocked(elapsedRealtime); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 5084 | } |
| 5085 | |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 5086 | int mWifiScanNesting = 0; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5087 | |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 5088 | public void noteWifiScanStartedLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 5089 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5090 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 5091 | final long uptime = mClocks.uptimeMillis(); |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 5092 | if (mWifiScanNesting == 0) { |
| 5093 | mHistoryCur.states |= HistoryItem.STATE_WIFI_SCAN_FLAG; |
| 5094 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI scan started for: " |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 5095 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 5096 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 5097 | } |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 5098 | mWifiScanNesting++; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 5099 | getUidStatsLocked(uid).noteWifiScanStartedLocked(elapsedRealtime); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 5100 | } |
| 5101 | |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 5102 | public void noteWifiScanStoppedLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 5103 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5104 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 5105 | final long uptime = mClocks.uptimeMillis(); |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 5106 | mWifiScanNesting--; |
| 5107 | if (mWifiScanNesting == 0) { |
| 5108 | mHistoryCur.states &= ~HistoryItem.STATE_WIFI_SCAN_FLAG; |
| 5109 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI scan stopped for: " |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 5110 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 5111 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 5112 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 5113 | getUidStatsLocked(uid).noteWifiScanStoppedLocked(elapsedRealtime); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 5114 | } |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 5115 | |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 5116 | public void noteWifiBatchedScanStartedLocked(int uid, int csph) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 5117 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5118 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 5119 | getUidStatsLocked(uid).noteWifiBatchedScanStartedLocked(csph, elapsedRealtime); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 5120 | } |
| 5121 | |
| 5122 | public void noteWifiBatchedScanStoppedLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 5123 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5124 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 5125 | getUidStatsLocked(uid).noteWifiBatchedScanStoppedLocked(elapsedRealtime); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 5126 | } |
| 5127 | |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 5128 | int mWifiMulticastNesting = 0; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5129 | |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 5130 | public void noteWifiMulticastEnabledLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 5131 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5132 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 5133 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 5134 | if (mWifiMulticastNesting == 0) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5135 | mHistoryCur.states |= HistoryItem.STATE_WIFI_MULTICAST_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 5136 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI multicast on to: " |
| 5137 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 5138 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 5139 | } |
| 5140 | mWifiMulticastNesting++; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 5141 | getUidStatsLocked(uid).noteWifiMulticastEnabledLocked(elapsedRealtime); |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 5142 | } |
| 5143 | |
| 5144 | public void noteWifiMulticastDisabledLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 5145 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5146 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 5147 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 5148 | mWifiMulticastNesting--; |
| 5149 | if (mWifiMulticastNesting == 0) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5150 | mHistoryCur.states &= ~HistoryItem.STATE_WIFI_MULTICAST_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 5151 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI multicast off to: " |
| 5152 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 5153 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 5154 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 5155 | getUidStatsLocked(uid).noteWifiMulticastDisabledLocked(elapsedRealtime); |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 5156 | } |
| 5157 | |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 5158 | public void noteFullWifiLockAcquiredFromSourceLocked(WorkSource ws) { |
| 5159 | int N = ws.size(); |
| 5160 | for (int i=0; i<N; i++) { |
| 5161 | noteFullWifiLockAcquiredLocked(ws.get(i)); |
| 5162 | } |
| 5163 | } |
| 5164 | |
| 5165 | public void noteFullWifiLockReleasedFromSourceLocked(WorkSource ws) { |
| 5166 | int N = ws.size(); |
| 5167 | for (int i=0; i<N; i++) { |
| 5168 | noteFullWifiLockReleasedLocked(ws.get(i)); |
| 5169 | } |
| 5170 | } |
| 5171 | |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 5172 | public void noteWifiScanStartedFromSourceLocked(WorkSource ws) { |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 5173 | int N = ws.size(); |
| 5174 | for (int i=0; i<N; i++) { |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 5175 | noteWifiScanStartedLocked(ws.get(i)); |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 5176 | } |
| 5177 | } |
| 5178 | |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 5179 | public void noteWifiScanStoppedFromSourceLocked(WorkSource ws) { |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 5180 | int N = ws.size(); |
| 5181 | for (int i=0; i<N; i++) { |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 5182 | noteWifiScanStoppedLocked(ws.get(i)); |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 5183 | } |
| 5184 | } |
| 5185 | |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 5186 | public void noteWifiBatchedScanStartedFromSourceLocked(WorkSource ws, int csph) { |
| 5187 | int N = ws.size(); |
| 5188 | for (int i=0; i<N; i++) { |
| 5189 | noteWifiBatchedScanStartedLocked(ws.get(i), csph); |
| 5190 | } |
| 5191 | } |
| 5192 | |
| 5193 | public void noteWifiBatchedScanStoppedFromSourceLocked(WorkSource ws) { |
| 5194 | int N = ws.size(); |
| 5195 | for (int i=0; i<N; i++) { |
| 5196 | noteWifiBatchedScanStoppedLocked(ws.get(i)); |
| 5197 | } |
| 5198 | } |
| 5199 | |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 5200 | public void noteWifiMulticastEnabledFromSourceLocked(WorkSource ws) { |
| 5201 | int N = ws.size(); |
| 5202 | for (int i=0; i<N; i++) { |
| 5203 | noteWifiMulticastEnabledLocked(ws.get(i)); |
| 5204 | } |
| 5205 | } |
| 5206 | |
| 5207 | public void noteWifiMulticastDisabledFromSourceLocked(WorkSource ws) { |
| 5208 | int N = ws.size(); |
| 5209 | for (int i=0; i<N; i++) { |
| 5210 | noteWifiMulticastDisabledLocked(ws.get(i)); |
| 5211 | } |
| 5212 | } |
| 5213 | |
Dianne Hackborn | d0c5b9a | 2014-02-21 16:19:05 -0800 | [diff] [blame] | 5214 | private static String[] includeInStringArray(String[] array, String str) { |
| 5215 | if (ArrayUtils.indexOf(array, str) >= 0) { |
| 5216 | return array; |
| 5217 | } |
| 5218 | String[] newArray = new String[array.length+1]; |
| 5219 | System.arraycopy(array, 0, newArray, 0, array.length); |
| 5220 | newArray[array.length] = str; |
| 5221 | return newArray; |
| 5222 | } |
| 5223 | |
| 5224 | private static String[] excludeFromStringArray(String[] array, String str) { |
| 5225 | int index = ArrayUtils.indexOf(array, str); |
| 5226 | if (index >= 0) { |
| 5227 | String[] newArray = new String[array.length-1]; |
| 5228 | if (index > 0) { |
| 5229 | System.arraycopy(array, 0, newArray, 0, index); |
| 5230 | } |
| 5231 | if (index < array.length-1) { |
| 5232 | System.arraycopy(array, index+1, newArray, index, array.length-index-1); |
| 5233 | } |
| 5234 | return newArray; |
| 5235 | } |
| 5236 | return array; |
| 5237 | } |
| 5238 | |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 5239 | public void noteNetworkInterfaceTypeLocked(String iface, int networkType) { |
Jeff Sharkey | 9da2f1e | 2014-08-14 12:55:00 -0700 | [diff] [blame] | 5240 | if (TextUtils.isEmpty(iface)) return; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5241 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 5242 | synchronized (mModemNetworkLock) { |
| 5243 | if (ConnectivityManager.isNetworkTypeMobile(networkType)) { |
| 5244 | mModemIfaces = includeInStringArray(mModemIfaces, iface); |
| 5245 | if (DEBUG) Slog.d(TAG, "Note mobile iface " + iface + ": " + mModemIfaces); |
| 5246 | } else { |
| 5247 | mModemIfaces = excludeFromStringArray(mModemIfaces, iface); |
| 5248 | if (DEBUG) Slog.d(TAG, "Note non-mobile iface " + iface + ": " + mModemIfaces); |
| 5249 | } |
| 5250 | } |
| 5251 | |
| 5252 | synchronized (mWifiNetworkLock) { |
| 5253 | if (ConnectivityManager.isNetworkTypeWifi(networkType)) { |
| 5254 | mWifiIfaces = includeInStringArray(mWifiIfaces, iface); |
| 5255 | if (DEBUG) Slog.d(TAG, "Note wifi iface " + iface + ": " + mWifiIfaces); |
| 5256 | } else { |
| 5257 | mWifiIfaces = excludeFromStringArray(mWifiIfaces, iface); |
| 5258 | if (DEBUG) Slog.d(TAG, "Note non-wifi iface " + iface + ": " + mWifiIfaces); |
| 5259 | } |
| 5260 | } |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 5261 | } |
| 5262 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5263 | @Override public long getScreenOnTime(long elapsedRealtimeUs, int which) { |
| 5264 | return mScreenOnTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5265 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5266 | |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 5267 | @Override public int getScreenOnCount(int which) { |
| 5268 | return mScreenOnTimer.getCountLocked(which); |
| 5269 | } |
| 5270 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 5271 | @Override public long getScreenBrightnessTime(int brightnessBin, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5272 | long elapsedRealtimeUs, int which) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 5273 | return mScreenBrightnessTimer[brightnessBin].getTotalTimeLocked( |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5274 | elapsedRealtimeUs, which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 5275 | } |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 5276 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 5277 | @Override public long getInteractiveTime(long elapsedRealtimeUs, int which) { |
| 5278 | return mInteractiveTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 5279 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5280 | |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 5281 | @Override public long getPowerSaveModeEnabledTime(long elapsedRealtimeUs, int which) { |
| 5282 | return mPowerSaveModeEnabledTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 5283 | } |
| 5284 | |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 5285 | @Override public int getPowerSaveModeEnabledCount(int which) { |
| 5286 | return mPowerSaveModeEnabledTimer.getCountLocked(which); |
| 5287 | } |
| 5288 | |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 5289 | @Override public long getDeviceIdleModeTime(int mode, long elapsedRealtimeUs, |
| 5290 | int which) { |
| 5291 | switch (mode) { |
| 5292 | case DEVICE_IDLE_MODE_LIGHT: |
| 5293 | return mDeviceIdleModeLightTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 5294 | case DEVICE_IDLE_MODE_DEEP: |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 5295 | return mDeviceIdleModeFullTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
| 5296 | } |
| 5297 | return 0; |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 5298 | } |
| 5299 | |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 5300 | @Override public int getDeviceIdleModeCount(int mode, int which) { |
| 5301 | switch (mode) { |
| 5302 | case DEVICE_IDLE_MODE_LIGHT: |
| 5303 | return mDeviceIdleModeLightTimer.getCountLocked(which); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 5304 | case DEVICE_IDLE_MODE_DEEP: |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 5305 | return mDeviceIdleModeFullTimer.getCountLocked(which); |
| 5306 | } |
| 5307 | return 0; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 5308 | } |
| 5309 | |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 5310 | @Override public long getLongestDeviceIdleModeTime(int mode) { |
| 5311 | switch (mode) { |
| 5312 | case DEVICE_IDLE_MODE_LIGHT: |
| 5313 | return mLongestLightIdleTime; |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 5314 | case DEVICE_IDLE_MODE_DEEP: |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 5315 | return mLongestFullIdleTime; |
| 5316 | } |
| 5317 | return 0; |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 5318 | } |
| 5319 | |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 5320 | @Override public long getDeviceIdlingTime(int mode, long elapsedRealtimeUs, int which) { |
| 5321 | switch (mode) { |
| 5322 | case DEVICE_IDLE_MODE_LIGHT: |
| 5323 | return mDeviceLightIdlingTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 5324 | case DEVICE_IDLE_MODE_DEEP: |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 5325 | return mDeviceIdlingTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
| 5326 | } |
| 5327 | return 0; |
| 5328 | } |
| 5329 | |
| 5330 | @Override public int getDeviceIdlingCount(int mode, int which) { |
| 5331 | switch (mode) { |
| 5332 | case DEVICE_IDLE_MODE_LIGHT: |
| 5333 | return mDeviceLightIdlingTimer.getCountLocked(which); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 5334 | case DEVICE_IDLE_MODE_DEEP: |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 5335 | return mDeviceIdlingTimer.getCountLocked(which); |
| 5336 | } |
| 5337 | return 0; |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 5338 | } |
| 5339 | |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 5340 | @Override public int getNumConnectivityChange(int which) { |
| 5341 | int val = mNumConnectivityChange; |
| 5342 | if (which == STATS_CURRENT) { |
| 5343 | val -= mLoadedNumConnectivityChange; |
| 5344 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 5345 | val -= mUnpluggedNumConnectivityChange; |
| 5346 | } |
| 5347 | return val; |
| 5348 | } |
| 5349 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5350 | @Override public long getPhoneOnTime(long elapsedRealtimeUs, int which) { |
| 5351 | return mPhoneOnTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5352 | } |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 5353 | |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 5354 | @Override public int getPhoneOnCount(int which) { |
| 5355 | return mPhoneOnTimer.getCountLocked(which); |
| 5356 | } |
| 5357 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 5358 | @Override public long getPhoneSignalStrengthTime(int strengthBin, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5359 | long elapsedRealtimeUs, int which) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 5360 | return mPhoneSignalStrengthsTimer[strengthBin].getTotalTimeLocked( |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5361 | elapsedRealtimeUs, which); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 5362 | } |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 5363 | |
| 5364 | @Override public long getPhoneSignalScanningTime( |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5365 | long elapsedRealtimeUs, int which) { |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 5366 | return mPhoneSignalScanningTimer.getTotalTimeLocked( |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5367 | elapsedRealtimeUs, which); |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 5368 | } |
| 5369 | |
Catherine Liu | fb90081 | 2012-07-17 14:12:56 -0500 | [diff] [blame] | 5370 | @Override public int getPhoneSignalStrengthCount(int strengthBin, int which) { |
| 5371 | return mPhoneSignalStrengthsTimer[strengthBin].getCountLocked(which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 5372 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5373 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 5374 | @Override public long getPhoneDataConnectionTime(int dataType, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5375 | long elapsedRealtimeUs, int which) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 5376 | return mPhoneDataConnectionsTimer[dataType].getTotalTimeLocked( |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5377 | elapsedRealtimeUs, which); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 5378 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5379 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 5380 | @Override public int getPhoneDataConnectionCount(int dataType, int which) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 5381 | return mPhoneDataConnectionsTimer[dataType].getCountLocked(which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 5382 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5383 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5384 | @Override public long getMobileRadioActiveTime(long elapsedRealtimeUs, int which) { |
| 5385 | return mMobileRadioActiveTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 5386 | } |
| 5387 | |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 5388 | @Override public int getMobileRadioActiveCount(int which) { |
| 5389 | return mMobileRadioActiveTimer.getCountLocked(which); |
| 5390 | } |
| 5391 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 5392 | @Override public long getMobileRadioActiveAdjustedTime(int which) { |
| 5393 | return mMobileRadioActiveAdjustedTime.getCountLocked(which); |
| 5394 | } |
| 5395 | |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 5396 | @Override public long getMobileRadioActiveUnknownTime(int which) { |
| 5397 | return mMobileRadioActiveUnknownTime.getCountLocked(which); |
| 5398 | } |
| 5399 | |
| 5400 | @Override public int getMobileRadioActiveUnknownCount(int which) { |
| 5401 | return (int)mMobileRadioActiveUnknownCount.getCountLocked(which); |
| 5402 | } |
| 5403 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5404 | @Override public long getWifiOnTime(long elapsedRealtimeUs, int which) { |
| 5405 | return mWifiOnTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 5406 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5407 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5408 | @Override public long getGlobalWifiRunningTime(long elapsedRealtimeUs, int which) { |
| 5409 | return mGlobalWifiRunningTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Eric Shienbrood | d4c5f89 | 2009-03-24 18:13:20 -0700 | [diff] [blame] | 5410 | } |
| 5411 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 5412 | @Override public long getWifiStateTime(int wifiState, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5413 | long elapsedRealtimeUs, int which) { |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 5414 | return mWifiStateTimer[wifiState].getTotalTimeLocked( |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5415 | elapsedRealtimeUs, which); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 5416 | } |
| 5417 | |
| 5418 | @Override public int getWifiStateCount(int wifiState, int which) { |
| 5419 | return mWifiStateTimer[wifiState].getCountLocked(which); |
| 5420 | } |
| 5421 | |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 5422 | @Override public long getWifiSupplStateTime(int state, |
| 5423 | long elapsedRealtimeUs, int which) { |
| 5424 | return mWifiSupplStateTimer[state].getTotalTimeLocked( |
| 5425 | elapsedRealtimeUs, which); |
| 5426 | } |
| 5427 | |
| 5428 | @Override public int getWifiSupplStateCount(int state, int which) { |
| 5429 | return mWifiSupplStateTimer[state].getCountLocked(which); |
| 5430 | } |
| 5431 | |
| 5432 | @Override public long getWifiSignalStrengthTime(int strengthBin, |
| 5433 | long elapsedRealtimeUs, int which) { |
| 5434 | return mWifiSignalStrengthsTimer[strengthBin].getTotalTimeLocked( |
| 5435 | elapsedRealtimeUs, which); |
| 5436 | } |
| 5437 | |
| 5438 | @Override public int getWifiSignalStrengthCount(int strengthBin, int which) { |
| 5439 | return mWifiSignalStrengthsTimer[strengthBin].getCountLocked(which); |
| 5440 | } |
| 5441 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 5442 | @Override |
| 5443 | public ControllerActivityCounter getBluetoothControllerActivity() { |
| 5444 | return mBluetoothActivity; |
Adam Lesinski | 1739076 | 2015-04-10 13:17:47 -0700 | [diff] [blame] | 5445 | } |
| 5446 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 5447 | @Override |
| 5448 | public ControllerActivityCounter getWifiControllerActivity() { |
| 5449 | return mWifiActivity; |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 5450 | } |
| 5451 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 5452 | @Override |
| 5453 | public ControllerActivityCounter getModemControllerActivity() { |
| 5454 | return mModemActivity; |
Adam Lesinski | 1739076 | 2015-04-10 13:17:47 -0700 | [diff] [blame] | 5455 | } |
| 5456 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 5457 | @Override |
| 5458 | public boolean hasBluetoothActivityReporting() { |
| 5459 | return mHasBluetoothReporting; |
| 5460 | } |
| 5461 | |
| 5462 | @Override |
| 5463 | public boolean hasWifiActivityReporting() { |
| 5464 | return mHasWifiReporting; |
| 5465 | } |
| 5466 | |
| 5467 | @Override |
| 5468 | public boolean hasModemActivityReporting() { |
| 5469 | return mHasModemReporting; |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 5470 | } |
| 5471 | |
Ruben Brunk | 5b1308f | 2015-06-03 18:49:27 -0700 | [diff] [blame] | 5472 | @Override |
| 5473 | public long getFlashlightOnTime(long elapsedRealtimeUs, int which) { |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 5474 | return mFlashlightOnTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
| 5475 | } |
| 5476 | |
Ruben Brunk | 5b1308f | 2015-06-03 18:49:27 -0700 | [diff] [blame] | 5477 | @Override |
| 5478 | public long getFlashlightOnCount(int which) { |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 5479 | return mFlashlightOnTimer.getCountLocked(which); |
| 5480 | } |
| 5481 | |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5482 | @Override |
Ruben Brunk | 5b1308f | 2015-06-03 18:49:27 -0700 | [diff] [blame] | 5483 | public long getCameraOnTime(long elapsedRealtimeUs, int which) { |
| 5484 | return mCameraOnTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
| 5485 | } |
| 5486 | |
| 5487 | @Override |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 5488 | public long getBluetoothScanTime(long elapsedRealtimeUs, int which) { |
| 5489 | return mBluetoothScanTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
| 5490 | } |
| 5491 | |
| 5492 | @Override |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5493 | public long getNetworkActivityBytes(int type, int which) { |
| 5494 | if (type >= 0 && type < mNetworkByteActivityCounters.length) { |
| 5495 | return mNetworkByteActivityCounters[type].getCountLocked(which); |
| 5496 | } else { |
| 5497 | return 0; |
| 5498 | } |
| 5499 | } |
| 5500 | |
| 5501 | @Override |
| 5502 | public long getNetworkActivityPackets(int type, int which) { |
| 5503 | if (type >= 0 && type < mNetworkPacketActivityCounters.length) { |
| 5504 | return mNetworkPacketActivityCounters[type].getCountLocked(which); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5505 | } else { |
| 5506 | return 0; |
| 5507 | } |
| 5508 | } |
| 5509 | |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 5510 | @Override public long getStartClockTime() { |
Dianne Hackborn | d48954f | 2015-07-22 17:20:33 -0700 | [diff] [blame] | 5511 | final long currentTime = System.currentTimeMillis(); |
| 5512 | if (ensureStartClockTime(currentTime)) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5513 | recordCurrentTimeChangeLocked(currentTime, mClocks.elapsedRealtime(), |
| 5514 | mClocks.uptimeMillis()); |
Dianne Hackborn | 7d9eefd | 2014-08-27 18:30:31 -0700 | [diff] [blame] | 5515 | } |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 5516 | return mStartClockTime; |
| 5517 | } |
| 5518 | |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 5519 | @Override public String getStartPlatformVersion() { |
| 5520 | return mStartPlatformVersion; |
| 5521 | } |
| 5522 | |
| 5523 | @Override public String getEndPlatformVersion() { |
| 5524 | return mEndPlatformVersion; |
| 5525 | } |
| 5526 | |
| 5527 | @Override public int getParcelVersion() { |
| 5528 | return VERSION; |
| 5529 | } |
| 5530 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5531 | @Override public boolean getIsOnBattery() { |
| 5532 | return mOnBattery; |
| 5533 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5534 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5535 | @Override public SparseArray<? extends BatteryStats.Uid> getUidStats() { |
| 5536 | return mUidStats; |
| 5537 | } |
| 5538 | |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 5539 | private static void detachTimerIfNotNull(BatteryStatsImpl.Timer timer) { |
| 5540 | if (timer != null) { |
| 5541 | timer.detach(); |
| 5542 | } |
| 5543 | } |
| 5544 | |
| 5545 | private static boolean resetTimerIfNotNull(BatteryStatsImpl.Timer timer, |
| 5546 | boolean detachIfReset) { |
| 5547 | if (timer != null) { |
| 5548 | return timer.reset(detachIfReset); |
| 5549 | } |
| 5550 | return true; |
| 5551 | } |
| 5552 | |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5553 | private static boolean resetTimerIfNotNull(DualTimer timer, boolean detachIfReset) { |
| 5554 | if (timer != null) { |
| 5555 | return timer.reset(detachIfReset); |
| 5556 | } |
| 5557 | return true; |
| 5558 | } |
| 5559 | |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 5560 | private static void detachLongCounterIfNotNull(LongSamplingCounter counter) { |
| 5561 | if (counter != null) { |
| 5562 | counter.detach(); |
| 5563 | } |
| 5564 | } |
| 5565 | |
| 5566 | private static void resetLongCounterIfNotNull(LongSamplingCounter counter, |
| 5567 | boolean detachIfReset) { |
| 5568 | if (counter != null) { |
| 5569 | counter.reset(detachIfReset); |
| 5570 | } |
| 5571 | } |
| 5572 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5573 | /** |
| 5574 | * The statistics associated with a particular uid. |
| 5575 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5576 | public static class Uid extends BatteryStats.Uid { |
| 5577 | /** |
| 5578 | * BatteryStatsImpl that we are associated with. |
| 5579 | */ |
| 5580 | protected BatteryStatsImpl mBsi; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5581 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5582 | final int mUid; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5583 | |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5584 | /** TimeBase for when uid is in background and device is on battery. */ |
| 5585 | @VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE) |
| 5586 | public final TimeBase mOnBatteryBackgroundTimeBase; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 5587 | @VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE) |
| 5588 | public final TimeBase mOnBatteryScreenOffBackgroundTimeBase; |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5589 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 5590 | boolean mWifiRunning; |
| 5591 | StopwatchTimer mWifiRunningTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5592 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 5593 | boolean mFullWifiLockOut; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 5594 | StopwatchTimer mFullWifiLockTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5595 | |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 5596 | boolean mWifiScanStarted; |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5597 | DualTimer mWifiScanTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5598 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5599 | static final int NO_BATCHED_SCAN_STARTED = -1; |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 5600 | int mWifiBatchedScanBinStarted = NO_BATCHED_SCAN_STARTED; |
| 5601 | StopwatchTimer[] mWifiBatchedScanTimer; |
| 5602 | |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 5603 | boolean mWifiMulticastEnabled; |
| 5604 | StopwatchTimer mWifiMulticastTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5605 | |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 5606 | StopwatchTimer mAudioTurnedOnTimer; |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 5607 | StopwatchTimer mVideoTurnedOnTimer; |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 5608 | StopwatchTimer mFlashlightTurnedOnTimer; |
| 5609 | StopwatchTimer mCameraTurnedOnTimer; |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 5610 | StopwatchTimer mForegroundActivityTimer; |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 5611 | /** Total time spent by the uid holding any partial wakelocks. */ |
| 5612 | DualTimer mAggregatedPartialWakelockTimer; |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5613 | DualTimer mBluetoothScanTimer; |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 5614 | DualTimer mBluetoothUnoptimizedScanTimer; |
Bookatz | 956f36bf | 2017-04-28 09:48:17 -0700 | [diff] [blame] | 5615 | Counter mBluetoothScanResultCounter; |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 5616 | Counter mBluetoothScanResultBgCounter; |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 5617 | |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 5618 | int mProcessState = ActivityManager.PROCESS_STATE_NONEXISTENT; |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5619 | StopwatchTimer[] mProcessStateTimer; |
| 5620 | |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 5621 | BatchTimer mVibratorOnTimer; |
| 5622 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 5623 | Counter[] mUserActivityCounters; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5624 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5625 | LongSamplingCounter[] mNetworkByteActivityCounters; |
| 5626 | LongSamplingCounter[] mNetworkPacketActivityCounters; |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 5627 | LongSamplingCounter mMobileRadioActiveTime; |
| 5628 | LongSamplingCounter mMobileRadioActiveCount; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5629 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5630 | /** |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 5631 | * How many times this UID woke up the Application Processor due to a Mobile radio packet. |
| 5632 | */ |
| 5633 | private LongSamplingCounter mMobileRadioApWakeupCount; |
| 5634 | |
| 5635 | /** |
| 5636 | * How many times this UID woke up the Application Processor due to a Wifi packet. |
| 5637 | */ |
| 5638 | private LongSamplingCounter mWifiRadioApWakeupCount; |
| 5639 | |
| 5640 | /** |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 5641 | * 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] | 5642 | * Can be null if the UID has had no such activity. |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 5643 | */ |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 5644 | private ControllerActivityCounterImpl mWifiControllerActivity; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 5645 | |
| 5646 | /** |
| 5647 | * 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] | 5648 | * Can be null if the UID has had no such activity. |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 5649 | */ |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 5650 | private ControllerActivityCounterImpl mBluetoothControllerActivity; |
| 5651 | |
| 5652 | /** |
| 5653 | * The amount of time this uid has kept the Modem controller in idle, tx, and rx mode. |
| 5654 | * Can be null if the UID has had no such activity. |
| 5655 | */ |
| 5656 | private ControllerActivityCounterImpl mModemControllerActivity; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 5657 | |
| 5658 | /** |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 5659 | * The CPU times we had at the last history details update. |
| 5660 | */ |
| 5661 | long mLastStepUserTime; |
| 5662 | long mLastStepSystemTime; |
| 5663 | long mCurStepUserTime; |
| 5664 | long mCurStepSystemTime; |
| 5665 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5666 | LongSamplingCounter mUserCpuTime; |
| 5667 | LongSamplingCounter mSystemCpuTime; |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 5668 | LongSamplingCounter[][] mCpuClusterSpeed; |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 5669 | |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 5670 | LongSamplingCounterArray mCpuFreqTimeMs; |
| 5671 | LongSamplingCounterArray mScreenOffCpuFreqTimeMs; |
| 5672 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 5673 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5674 | * The statistics we have collected for this uid's wake locks. |
| 5675 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5676 | final OverflowArrayMap<Wakelock> mWakelockStats; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5677 | |
| 5678 | /** |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 5679 | * The statistics we have collected for this uid's syncs. |
| 5680 | */ |
Bookatz | 2bffb5b | 2017-04-13 11:59:33 -0700 | [diff] [blame] | 5681 | final OverflowArrayMap<DualTimer> mSyncStats; |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 5682 | |
| 5683 | /** |
| 5684 | * The statistics we have collected for this uid's jobs. |
| 5685 | */ |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 5686 | final OverflowArrayMap<DualTimer> mJobStats; |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 5687 | |
| 5688 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5689 | * The statistics we have collected for this uid's sensor activations. |
| 5690 | */ |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 5691 | final SparseArray<Sensor> mSensorStats = new SparseArray<>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5692 | |
| 5693 | /** |
| 5694 | * The statistics we have collected for this uid's processes. |
| 5695 | */ |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 5696 | final ArrayMap<String, Proc> mProcessStats = new ArrayMap<>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5697 | |
| 5698 | /** |
| 5699 | * The statistics we have collected for this uid's processes. |
| 5700 | */ |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 5701 | final ArrayMap<String, Pkg> mPackageStats = new ArrayMap<>(); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5702 | |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 5703 | /** |
| 5704 | * The transient wake stats we have collected for this uid's pids. |
| 5705 | */ |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 5706 | final SparseArray<Pid> mPids = new SparseArray<>(); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 5707 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5708 | public Uid(BatteryStatsImpl bsi, int uid) { |
| 5709 | mBsi = bsi; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5710 | mUid = uid; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5711 | |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5712 | mOnBatteryBackgroundTimeBase = new TimeBase(); |
| 5713 | mOnBatteryBackgroundTimeBase.init(mBsi.mClocks.uptimeMillis() * 1000, |
| 5714 | mBsi.mClocks.elapsedRealtime() * 1000); |
| 5715 | |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 5716 | mOnBatteryScreenOffBackgroundTimeBase = new TimeBase(); |
| 5717 | mOnBatteryScreenOffBackgroundTimeBase.init(mBsi.mClocks.uptimeMillis() * 1000, |
| 5718 | mBsi.mClocks.elapsedRealtime() * 1000); |
| 5719 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5720 | mUserCpuTime = new LongSamplingCounter(mBsi.mOnBatteryTimeBase); |
| 5721 | mSystemCpuTime = new LongSamplingCounter(mBsi.mOnBatteryTimeBase); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5722 | |
Dianne Hackborn | 657153b | 2016-07-29 14:54:14 -0700 | [diff] [blame] | 5723 | mWakelockStats = mBsi.new OverflowArrayMap<Wakelock>(uid) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5724 | @Override public Wakelock instantiateObject() { |
| 5725 | return new Wakelock(mBsi, Uid.this); |
| 5726 | } |
| 5727 | }; |
Bookatz | 2bffb5b | 2017-04-13 11:59:33 -0700 | [diff] [blame] | 5728 | mSyncStats = mBsi.new OverflowArrayMap<DualTimer>(uid) { |
| 5729 | @Override public DualTimer instantiateObject() { |
| 5730 | return new DualTimer(mBsi.mClocks, Uid.this, SYNC, null, |
| 5731 | mBsi.mOnBatteryTimeBase, mOnBatteryBackgroundTimeBase); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5732 | } |
| 5733 | }; |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 5734 | mJobStats = mBsi.new OverflowArrayMap<DualTimer>(uid) { |
| 5735 | @Override public DualTimer instantiateObject() { |
| 5736 | return new DualTimer(mBsi.mClocks, Uid.this, JOB, null, |
| 5737 | mBsi.mOnBatteryTimeBase, mOnBatteryBackgroundTimeBase); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5738 | } |
| 5739 | }; |
| 5740 | |
| 5741 | mWifiRunningTimer = new StopwatchTimer(mBsi.mClocks, this, WIFI_RUNNING, |
| 5742 | mBsi.mWifiRunningTimers, mBsi.mOnBatteryTimeBase); |
| 5743 | mFullWifiLockTimer = new StopwatchTimer(mBsi.mClocks, this, FULL_WIFI_LOCK, |
| 5744 | mBsi.mFullWifiLockTimers, mBsi.mOnBatteryTimeBase); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5745 | mWifiScanTimer = new DualTimer(mBsi.mClocks, this, WIFI_SCAN, |
| 5746 | mBsi.mWifiScanTimers, mBsi.mOnBatteryTimeBase, mOnBatteryBackgroundTimeBase); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 5747 | mWifiBatchedScanTimer = new StopwatchTimer[NUM_WIFI_BATCHED_SCAN_BINS]; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5748 | mWifiMulticastTimer = new StopwatchTimer(mBsi.mClocks, this, WIFI_MULTICAST_ENABLED, |
| 5749 | mBsi.mWifiMulticastTimers, mBsi.mOnBatteryTimeBase); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5750 | mProcessStateTimer = new StopwatchTimer[NUM_PROCESS_STATE]; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5751 | } |
| 5752 | |
| 5753 | @Override |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 5754 | public long[] getCpuFreqTimes(int which) { |
| 5755 | if (mCpuFreqTimeMs == null) { |
| 5756 | return null; |
| 5757 | } |
| 5758 | final long[] cpuFreqTimes = mCpuFreqTimeMs.getCountsLocked(which); |
| 5759 | if (cpuFreqTimes == null) { |
| 5760 | return null; |
| 5761 | } |
| 5762 | // Return cpuFreqTimes only if atleast one of the elements in non-zero. |
| 5763 | for (int i = 0; i < cpuFreqTimes.length; ++i) { |
| 5764 | if (cpuFreqTimes[i] != 0) { |
| 5765 | return cpuFreqTimes; |
| 5766 | } |
| 5767 | } |
| 5768 | return null; |
| 5769 | } |
| 5770 | |
| 5771 | @Override |
| 5772 | public long[] getScreenOffCpuFreqTimes(int which) { |
| 5773 | if (mScreenOffCpuFreqTimeMs == null) { |
| 5774 | return null; |
| 5775 | } |
| 5776 | final long[] cpuFreqTimes = mScreenOffCpuFreqTimeMs.getCountsLocked(which); |
| 5777 | if (cpuFreqTimes == null) { |
| 5778 | return null; |
| 5779 | } |
| 5780 | // Return cpuFreqTimes only if atleast one of the elements in non-zero. |
| 5781 | for (int i = 0; i < cpuFreqTimes.length; ++i) { |
| 5782 | if (cpuFreqTimes[i] != 0) { |
| 5783 | return cpuFreqTimes; |
| 5784 | } |
| 5785 | } |
| 5786 | return null; |
| 5787 | } |
| 5788 | |
| 5789 | @Override |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 5790 | public Timer getAggregatedPartialWakelockTimer() { |
| 5791 | return mAggregatedPartialWakelockTimer; |
| 5792 | } |
| 5793 | |
| 5794 | @Override |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5795 | public ArrayMap<String, ? extends BatteryStats.Uid.Wakelock> getWakelockStats() { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 5796 | return mWakelockStats.getMap(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5797 | } |
| 5798 | |
| 5799 | @Override |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5800 | public ArrayMap<String, ? extends BatteryStats.Timer> getSyncStats() { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 5801 | return mSyncStats.getMap(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 5802 | } |
| 5803 | |
| 5804 | @Override |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5805 | public ArrayMap<String, ? extends BatteryStats.Timer> getJobStats() { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 5806 | return mJobStats.getMap(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 5807 | } |
| 5808 | |
| 5809 | @Override |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5810 | public SparseArray<? extends BatteryStats.Uid.Sensor> getSensorStats() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5811 | return mSensorStats; |
| 5812 | } |
| 5813 | |
| 5814 | @Override |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5815 | public ArrayMap<String, ? extends BatteryStats.Uid.Proc> getProcessStats() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5816 | return mProcessStats; |
| 5817 | } |
| 5818 | |
| 5819 | @Override |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5820 | public ArrayMap<String, ? extends BatteryStats.Uid.Pkg> getPackageStats() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5821 | return mPackageStats; |
| 5822 | } |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 5823 | |
| 5824 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5825 | public int getUid() { |
| 5826 | return mUid; |
| 5827 | } |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 5828 | |
| 5829 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5830 | public void noteWifiRunningLocked(long elapsedRealtimeMs) { |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 5831 | if (!mWifiRunning) { |
| 5832 | mWifiRunning = true; |
| 5833 | if (mWifiRunningTimer == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5834 | mWifiRunningTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, WIFI_RUNNING, |
| 5835 | mBsi.mWifiRunningTimers, mBsi.mOnBatteryTimeBase); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5836 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5837 | mWifiRunningTimer.startRunningLocked(elapsedRealtimeMs); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 5838 | } |
| 5839 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5840 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 5841 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5842 | public void noteWifiStoppedLocked(long elapsedRealtimeMs) { |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 5843 | if (mWifiRunning) { |
| 5844 | mWifiRunning = false; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5845 | mWifiRunningTimer.stopRunningLocked(elapsedRealtimeMs); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 5846 | } |
| 5847 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5848 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 5849 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5850 | public void noteFullWifiLockAcquiredLocked(long elapsedRealtimeMs) { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 5851 | if (!mFullWifiLockOut) { |
| 5852 | mFullWifiLockOut = true; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5853 | if (mFullWifiLockTimer == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5854 | mFullWifiLockTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, FULL_WIFI_LOCK, |
| 5855 | mBsi.mFullWifiLockTimers, mBsi.mOnBatteryTimeBase); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5856 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5857 | mFullWifiLockTimer.startRunningLocked(elapsedRealtimeMs); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 5858 | } |
| 5859 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5860 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 5861 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5862 | public void noteFullWifiLockReleasedLocked(long elapsedRealtimeMs) { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 5863 | if (mFullWifiLockOut) { |
| 5864 | mFullWifiLockOut = false; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5865 | mFullWifiLockTimer.stopRunningLocked(elapsedRealtimeMs); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 5866 | } |
| 5867 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5868 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 5869 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5870 | public void noteWifiScanStartedLocked(long elapsedRealtimeMs) { |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 5871 | if (!mWifiScanStarted) { |
| 5872 | mWifiScanStarted = true; |
| 5873 | if (mWifiScanTimer == null) { |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 5874 | mWifiScanTimer = new DualTimer(mBsi.mClocks, Uid.this, WIFI_SCAN, |
| 5875 | mBsi.mWifiScanTimers, mBsi.mOnBatteryTimeBase, |
| 5876 | mOnBatteryBackgroundTimeBase); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5877 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5878 | mWifiScanTimer.startRunningLocked(elapsedRealtimeMs); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 5879 | } |
| 5880 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5881 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 5882 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5883 | public void noteWifiScanStoppedLocked(long elapsedRealtimeMs) { |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 5884 | if (mWifiScanStarted) { |
| 5885 | mWifiScanStarted = false; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5886 | mWifiScanTimer.stopRunningLocked(elapsedRealtimeMs); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 5887 | } |
| 5888 | } |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 5889 | |
| 5890 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5891 | public void noteWifiBatchedScanStartedLocked(int csph, long elapsedRealtimeMs) { |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 5892 | int bin = 0; |
Navtej Singh Mann | 3c0ce5c | 2015-06-11 16:53:11 -0700 | [diff] [blame] | 5893 | while (csph > 8 && bin < NUM_WIFI_BATCHED_SCAN_BINS-1) { |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 5894 | csph = csph >> 3; |
| 5895 | bin++; |
| 5896 | } |
| 5897 | |
| 5898 | if (mWifiBatchedScanBinStarted == bin) return; |
| 5899 | |
| 5900 | if (mWifiBatchedScanBinStarted != NO_BATCHED_SCAN_STARTED) { |
| 5901 | mWifiBatchedScanTimer[mWifiBatchedScanBinStarted]. |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5902 | stopRunningLocked(elapsedRealtimeMs); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 5903 | } |
| 5904 | mWifiBatchedScanBinStarted = bin; |
| 5905 | if (mWifiBatchedScanTimer[bin] == null) { |
| 5906 | makeWifiBatchedScanBin(bin, null); |
| 5907 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5908 | mWifiBatchedScanTimer[bin].startRunningLocked(elapsedRealtimeMs); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 5909 | } |
| 5910 | |
| 5911 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5912 | public void noteWifiBatchedScanStoppedLocked(long elapsedRealtimeMs) { |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 5913 | if (mWifiBatchedScanBinStarted != NO_BATCHED_SCAN_STARTED) { |
| 5914 | mWifiBatchedScanTimer[mWifiBatchedScanBinStarted]. |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5915 | stopRunningLocked(elapsedRealtimeMs); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 5916 | mWifiBatchedScanBinStarted = NO_BATCHED_SCAN_STARTED; |
| 5917 | } |
| 5918 | } |
| 5919 | |
| 5920 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5921 | public void noteWifiMulticastEnabledLocked(long elapsedRealtimeMs) { |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 5922 | if (!mWifiMulticastEnabled) { |
| 5923 | mWifiMulticastEnabled = true; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5924 | if (mWifiMulticastTimer == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5925 | mWifiMulticastTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, |
| 5926 | WIFI_MULTICAST_ENABLED, mBsi.mWifiMulticastTimers, mBsi.mOnBatteryTimeBase); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5927 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5928 | mWifiMulticastTimer.startRunningLocked(elapsedRealtimeMs); |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 5929 | } |
| 5930 | } |
| 5931 | |
| 5932 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5933 | public void noteWifiMulticastDisabledLocked(long elapsedRealtimeMs) { |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 5934 | if (mWifiMulticastEnabled) { |
| 5935 | mWifiMulticastEnabled = false; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5936 | mWifiMulticastTimer.stopRunningLocked(elapsedRealtimeMs); |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 5937 | } |
| 5938 | } |
| 5939 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 5940 | @Override |
| 5941 | public ControllerActivityCounter getWifiControllerActivity() { |
| 5942 | return mWifiControllerActivity; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 5943 | } |
| 5944 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 5945 | @Override |
| 5946 | public ControllerActivityCounter getBluetoothControllerActivity() { |
| 5947 | return mBluetoothControllerActivity; |
| 5948 | } |
| 5949 | |
| 5950 | @Override |
| 5951 | public ControllerActivityCounter getModemControllerActivity() { |
| 5952 | return mModemControllerActivity; |
| 5953 | } |
| 5954 | |
| 5955 | public ControllerActivityCounterImpl getOrCreateWifiControllerActivityLocked() { |
| 5956 | if (mWifiControllerActivity == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5957 | mWifiControllerActivity = new ControllerActivityCounterImpl(mBsi.mOnBatteryTimeBase, |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 5958 | NUM_BT_TX_LEVELS); |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 5959 | } |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 5960 | return mWifiControllerActivity; |
| 5961 | } |
| 5962 | |
| 5963 | public ControllerActivityCounterImpl getOrCreateBluetoothControllerActivityLocked() { |
| 5964 | if (mBluetoothControllerActivity == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5965 | mBluetoothControllerActivity = new ControllerActivityCounterImpl(mBsi.mOnBatteryTimeBase, |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 5966 | NUM_BT_TX_LEVELS); |
| 5967 | } |
| 5968 | return mBluetoothControllerActivity; |
| 5969 | } |
| 5970 | |
| 5971 | public ControllerActivityCounterImpl getOrCreateModemControllerActivityLocked() { |
| 5972 | if (mModemControllerActivity == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5973 | mModemControllerActivity = new ControllerActivityCounterImpl(mBsi.mOnBatteryTimeBase, |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 5974 | ModemActivityInfo.TX_POWER_LEVELS); |
| 5975 | } |
| 5976 | return mModemControllerActivity; |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 5977 | } |
| 5978 | |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 5979 | public StopwatchTimer createAudioTurnedOnTimerLocked() { |
| 5980 | if (mAudioTurnedOnTimer == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5981 | mAudioTurnedOnTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, AUDIO_TURNED_ON, |
| 5982 | mBsi.mAudioTurnedOnTimers, mBsi.mOnBatteryTimeBase); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 5983 | } |
| 5984 | return mAudioTurnedOnTimer; |
| 5985 | } |
| 5986 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5987 | public void noteAudioTurnedOnLocked(long elapsedRealtimeMs) { |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 5988 | createAudioTurnedOnTimerLocked().startRunningLocked(elapsedRealtimeMs); |
| 5989 | } |
| 5990 | |
| 5991 | public void noteAudioTurnedOffLocked(long elapsedRealtimeMs) { |
| 5992 | if (mAudioTurnedOnTimer != null) { |
| 5993 | mAudioTurnedOnTimer.stopRunningLocked(elapsedRealtimeMs); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5994 | } |
| 5995 | } |
| 5996 | |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 5997 | public void noteResetAudioLocked(long elapsedRealtimeMs) { |
| 5998 | if (mAudioTurnedOnTimer != null) { |
| 5999 | mAudioTurnedOnTimer.stopAllRunningLocked(elapsedRealtimeMs); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6000 | } |
| 6001 | } |
| 6002 | |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 6003 | public StopwatchTimer createVideoTurnedOnTimerLocked() { |
| 6004 | if (mVideoTurnedOnTimer == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6005 | mVideoTurnedOnTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, VIDEO_TURNED_ON, |
| 6006 | mBsi.mVideoTurnedOnTimers, mBsi.mOnBatteryTimeBase); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 6007 | } |
| 6008 | return mVideoTurnedOnTimer; |
| 6009 | } |
| 6010 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6011 | public void noteVideoTurnedOnLocked(long elapsedRealtimeMs) { |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 6012 | createVideoTurnedOnTimerLocked().startRunningLocked(elapsedRealtimeMs); |
| 6013 | } |
| 6014 | |
| 6015 | public void noteVideoTurnedOffLocked(long elapsedRealtimeMs) { |
| 6016 | if (mVideoTurnedOnTimer != null) { |
| 6017 | mVideoTurnedOnTimer.stopRunningLocked(elapsedRealtimeMs); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6018 | } |
| 6019 | } |
| 6020 | |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 6021 | public void noteResetVideoLocked(long elapsedRealtimeMs) { |
| 6022 | if (mVideoTurnedOnTimer != null) { |
| 6023 | mVideoTurnedOnTimer.stopAllRunningLocked(elapsedRealtimeMs); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 6024 | } |
| 6025 | } |
| 6026 | |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 6027 | public StopwatchTimer createFlashlightTurnedOnTimerLocked() { |
| 6028 | if (mFlashlightTurnedOnTimer == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6029 | mFlashlightTurnedOnTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, |
| 6030 | FLASHLIGHT_TURNED_ON, mBsi.mFlashlightTurnedOnTimers, mBsi.mOnBatteryTimeBase); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 6031 | } |
| 6032 | return mFlashlightTurnedOnTimer; |
| 6033 | } |
| 6034 | |
| 6035 | public void noteFlashlightTurnedOnLocked(long elapsedRealtimeMs) { |
| 6036 | createFlashlightTurnedOnTimerLocked().startRunningLocked(elapsedRealtimeMs); |
| 6037 | } |
| 6038 | |
| 6039 | public void noteFlashlightTurnedOffLocked(long elapsedRealtimeMs) { |
| 6040 | if (mFlashlightTurnedOnTimer != null) { |
| 6041 | mFlashlightTurnedOnTimer.stopRunningLocked(elapsedRealtimeMs); |
| 6042 | } |
| 6043 | } |
| 6044 | |
| 6045 | public void noteResetFlashlightLocked(long elapsedRealtimeMs) { |
| 6046 | if (mFlashlightTurnedOnTimer != null) { |
| 6047 | mFlashlightTurnedOnTimer.stopAllRunningLocked(elapsedRealtimeMs); |
| 6048 | } |
| 6049 | } |
| 6050 | |
| 6051 | public StopwatchTimer createCameraTurnedOnTimerLocked() { |
| 6052 | if (mCameraTurnedOnTimer == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6053 | mCameraTurnedOnTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, CAMERA_TURNED_ON, |
| 6054 | mBsi.mCameraTurnedOnTimers, mBsi.mOnBatteryTimeBase); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 6055 | } |
| 6056 | return mCameraTurnedOnTimer; |
| 6057 | } |
| 6058 | |
| 6059 | public void noteCameraTurnedOnLocked(long elapsedRealtimeMs) { |
| 6060 | createCameraTurnedOnTimerLocked().startRunningLocked(elapsedRealtimeMs); |
| 6061 | } |
| 6062 | |
| 6063 | public void noteCameraTurnedOffLocked(long elapsedRealtimeMs) { |
| 6064 | if (mCameraTurnedOnTimer != null) { |
| 6065 | mCameraTurnedOnTimer.stopRunningLocked(elapsedRealtimeMs); |
| 6066 | } |
| 6067 | } |
| 6068 | |
| 6069 | public void noteResetCameraLocked(long elapsedRealtimeMs) { |
| 6070 | if (mCameraTurnedOnTimer != null) { |
| 6071 | mCameraTurnedOnTimer.stopAllRunningLocked(elapsedRealtimeMs); |
| 6072 | } |
| 6073 | } |
| 6074 | |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 6075 | public StopwatchTimer createForegroundActivityTimerLocked() { |
| 6076 | if (mForegroundActivityTimer == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6077 | mForegroundActivityTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, |
| 6078 | FOREGROUND_ACTIVITY, null, mBsi.mOnBatteryTimeBase); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 6079 | } |
| 6080 | return mForegroundActivityTimer; |
| 6081 | } |
| 6082 | |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 6083 | public DualTimer createAggregatedPartialWakelockTimerLocked() { |
| 6084 | if (mAggregatedPartialWakelockTimer == null) { |
| 6085 | mAggregatedPartialWakelockTimer = new DualTimer(mBsi.mClocks, this, |
| 6086 | AGGREGATED_WAKE_TYPE_PARTIAL, null, |
| 6087 | mBsi.mOnBatteryScreenOffTimeBase, mOnBatteryScreenOffBackgroundTimeBase); |
| 6088 | } |
| 6089 | return mAggregatedPartialWakelockTimer; |
| 6090 | } |
| 6091 | |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 6092 | public DualTimer createBluetoothScanTimerLocked() { |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 6093 | if (mBluetoothScanTimer == null) { |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 6094 | mBluetoothScanTimer = new DualTimer(mBsi.mClocks, Uid.this, BLUETOOTH_SCAN_ON, |
| 6095 | mBsi.mBluetoothScanOnTimers, mBsi.mOnBatteryTimeBase, |
| 6096 | mOnBatteryBackgroundTimeBase); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 6097 | } |
| 6098 | return mBluetoothScanTimer; |
| 6099 | } |
| 6100 | |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 6101 | public DualTimer createBluetoothUnoptimizedScanTimerLocked() { |
| 6102 | if (mBluetoothUnoptimizedScanTimer == null) { |
| 6103 | mBluetoothUnoptimizedScanTimer = new DualTimer(mBsi.mClocks, Uid.this, |
| 6104 | BLUETOOTH_UNOPTIMIZED_SCAN_ON, null, |
| 6105 | mBsi.mOnBatteryTimeBase, mOnBatteryBackgroundTimeBase); |
| 6106 | } |
| 6107 | return mBluetoothUnoptimizedScanTimer; |
| 6108 | } |
| 6109 | |
| 6110 | public void noteBluetoothScanStartedLocked(long elapsedRealtimeMs, boolean isUnoptimized) { |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 6111 | createBluetoothScanTimerLocked().startRunningLocked(elapsedRealtimeMs); |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 6112 | if (isUnoptimized) { |
| 6113 | createBluetoothUnoptimizedScanTimerLocked().startRunningLocked(elapsedRealtimeMs); |
| 6114 | } |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 6115 | } |
| 6116 | |
Bookatz | 20e22f6 | 2017-07-11 16:49:17 -0700 | [diff] [blame] | 6117 | public void noteBluetoothScanStoppedLocked(long elapsedRealtimeMs, boolean isUnoptimized) { |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 6118 | if (mBluetoothScanTimer != null) { |
| 6119 | mBluetoothScanTimer.stopRunningLocked(elapsedRealtimeMs); |
| 6120 | } |
Bookatz | 20e22f6 | 2017-07-11 16:49:17 -0700 | [diff] [blame] | 6121 | if (isUnoptimized && mBluetoothUnoptimizedScanTimer != null) { |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 6122 | mBluetoothUnoptimizedScanTimer.stopRunningLocked(elapsedRealtimeMs); |
| 6123 | } |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 6124 | } |
| 6125 | |
| 6126 | public void noteResetBluetoothScanLocked(long elapsedRealtimeMs) { |
| 6127 | if (mBluetoothScanTimer != null) { |
| 6128 | mBluetoothScanTimer.stopAllRunningLocked(elapsedRealtimeMs); |
| 6129 | } |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 6130 | if (mBluetoothUnoptimizedScanTimer != null) { |
| 6131 | mBluetoothUnoptimizedScanTimer.stopAllRunningLocked(elapsedRealtimeMs); |
| 6132 | } |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 6133 | } |
| 6134 | |
Bookatz | 956f36bf | 2017-04-28 09:48:17 -0700 | [diff] [blame] | 6135 | public Counter createBluetoothScanResultCounterLocked() { |
| 6136 | if (mBluetoothScanResultCounter == null) { |
| 6137 | mBluetoothScanResultCounter = new Counter(mBsi.mOnBatteryTimeBase); |
| 6138 | } |
| 6139 | return mBluetoothScanResultCounter; |
| 6140 | } |
| 6141 | |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 6142 | public Counter createBluetoothScanResultBgCounterLocked() { |
| 6143 | if (mBluetoothScanResultBgCounter == null) { |
| 6144 | mBluetoothScanResultBgCounter = new Counter(mOnBatteryBackgroundTimeBase); |
| 6145 | } |
| 6146 | return mBluetoothScanResultBgCounter; |
| 6147 | } |
| 6148 | |
Bookatz | 4ebc064 | 2017-05-11 12:21:19 -0700 | [diff] [blame] | 6149 | public void noteBluetoothScanResultsLocked(int numNewResults) { |
| 6150 | createBluetoothScanResultCounterLocked().addAtomic(numNewResults); |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 6151 | // Uses background timebase, so the count will only be incremented if uid in background. |
| 6152 | createBluetoothScanResultBgCounterLocked().addAtomic(numNewResults); |
Bookatz | 956f36bf | 2017-04-28 09:48:17 -0700 | [diff] [blame] | 6153 | } |
| 6154 | |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 6155 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6156 | public void noteActivityResumedLocked(long elapsedRealtimeMs) { |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 6157 | // We always start, since we want multiple foreground PIDs to nest |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6158 | createForegroundActivityTimerLocked().startRunningLocked(elapsedRealtimeMs); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 6159 | } |
| 6160 | |
| 6161 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6162 | public void noteActivityPausedLocked(long elapsedRealtimeMs) { |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 6163 | if (mForegroundActivityTimer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6164 | mForegroundActivityTimer.stopRunningLocked(elapsedRealtimeMs); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 6165 | } |
| 6166 | } |
| 6167 | |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 6168 | public BatchTimer createVibratorOnTimerLocked() { |
| 6169 | if (mVibratorOnTimer == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6170 | mVibratorOnTimer = new BatchTimer(mBsi.mClocks, Uid.this, VIBRATOR_ON, |
| 6171 | mBsi.mOnBatteryTimeBase); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 6172 | } |
| 6173 | return mVibratorOnTimer; |
| 6174 | } |
| 6175 | |
| 6176 | public void noteVibratorOnLocked(long durationMillis) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6177 | createVibratorOnTimerLocked().addDuration(mBsi, durationMillis); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 6178 | } |
| 6179 | |
| 6180 | public void noteVibratorOffLocked() { |
| 6181 | if (mVibratorOnTimer != null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6182 | mVibratorOnTimer.abortLastDuration(mBsi); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6183 | } |
| 6184 | } |
| 6185 | |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6186 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6187 | public long getWifiRunningTime(long elapsedRealtimeUs, int which) { |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 6188 | if (mWifiRunningTimer == null) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6189 | return 0; |
| 6190 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6191 | return mWifiRunningTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 6192 | } |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 6193 | |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6194 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6195 | public long getFullWifiLockTime(long elapsedRealtimeUs, int which) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6196 | if (mFullWifiLockTimer == null) { |
| 6197 | return 0; |
| 6198 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6199 | return mFullWifiLockTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 6200 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6201 | |
| 6202 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6203 | public long getWifiScanTime(long elapsedRealtimeUs, int which) { |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 6204 | if (mWifiScanTimer == null) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6205 | return 0; |
| 6206 | } |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 6207 | return mWifiScanTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 6208 | } |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 6209 | |
| 6210 | @Override |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 6211 | public int getWifiScanCount(int which) { |
| 6212 | if (mWifiScanTimer == null) { |
| 6213 | return 0; |
| 6214 | } |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 6215 | return mWifiScanTimer.getCountLocked(which); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 6216 | } |
| 6217 | |
| 6218 | @Override |
| 6219 | public int getWifiScanBackgroundCount(int which) { |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 6220 | if (mWifiScanTimer == null || mWifiScanTimer.getSubTimer() == null) { |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 6221 | return 0; |
| 6222 | } |
| 6223 | return mWifiScanTimer.getSubTimer().getCountLocked(which); |
| 6224 | } |
| 6225 | |
| 6226 | @Override |
| 6227 | public long getWifiScanActualTime(final long elapsedRealtimeUs) { |
| 6228 | if (mWifiScanTimer == null) { |
| 6229 | return 0; |
| 6230 | } |
| 6231 | final long elapsedRealtimeMs = (elapsedRealtimeUs + 500) / 1000; |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 6232 | return mWifiScanTimer.getTotalDurationMsLocked(elapsedRealtimeMs) * 1000; |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 6233 | } |
| 6234 | |
| 6235 | @Override |
| 6236 | public long getWifiScanBackgroundTime(final long elapsedRealtimeUs) { |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 6237 | if (mWifiScanTimer == null || mWifiScanTimer.getSubTimer() == null) { |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 6238 | return 0; |
| 6239 | } |
| 6240 | final long elapsedRealtimeMs = (elapsedRealtimeUs + 500) / 1000; |
| 6241 | return mWifiScanTimer.getSubTimer().getTotalDurationMsLocked(elapsedRealtimeMs) * 1000; |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 6242 | } |
| 6243 | |
| 6244 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6245 | public long getWifiBatchedScanTime(int csphBin, long elapsedRealtimeUs, int which) { |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 6246 | if (csphBin < 0 || csphBin >= NUM_WIFI_BATCHED_SCAN_BINS) return 0; |
| 6247 | if (mWifiBatchedScanTimer[csphBin] == null) { |
| 6248 | return 0; |
| 6249 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6250 | return mWifiBatchedScanTimer[csphBin].getTotalTimeLocked(elapsedRealtimeUs, which); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 6251 | } |
| 6252 | |
| 6253 | @Override |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 6254 | public int getWifiBatchedScanCount(int csphBin, int which) { |
| 6255 | if (csphBin < 0 || csphBin >= NUM_WIFI_BATCHED_SCAN_BINS) return 0; |
| 6256 | if (mWifiBatchedScanTimer[csphBin] == null) { |
| 6257 | return 0; |
| 6258 | } |
| 6259 | return mWifiBatchedScanTimer[csphBin].getCountLocked(which); |
| 6260 | } |
| 6261 | |
| 6262 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6263 | public long getWifiMulticastTime(long elapsedRealtimeUs, int which) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6264 | if (mWifiMulticastTimer == null) { |
| 6265 | return 0; |
| 6266 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6267 | return mWifiMulticastTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 6268 | } |
| 6269 | |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6270 | @Override |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 6271 | public Timer getAudioTurnedOnTimer() { |
| 6272 | return mAudioTurnedOnTimer; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6273 | } |
| 6274 | |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6275 | @Override |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 6276 | public Timer getVideoTurnedOnTimer() { |
| 6277 | return mVideoTurnedOnTimer; |
| 6278 | } |
| 6279 | |
| 6280 | @Override |
| 6281 | public Timer getFlashlightTurnedOnTimer() { |
| 6282 | return mFlashlightTurnedOnTimer; |
| 6283 | } |
| 6284 | |
| 6285 | @Override |
| 6286 | public Timer getCameraTurnedOnTimer() { |
| 6287 | return mCameraTurnedOnTimer; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6288 | } |
| 6289 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 6290 | @Override |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 6291 | public Timer getForegroundActivityTimer() { |
| 6292 | return mForegroundActivityTimer; |
| 6293 | } |
| 6294 | |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 6295 | @Override |
| 6296 | public Timer getBluetoothScanTimer() { |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 6297 | return mBluetoothScanTimer; |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 6298 | } |
| 6299 | |
| 6300 | @Override |
| 6301 | public Timer getBluetoothScanBackgroundTimer() { |
| 6302 | if (mBluetoothScanTimer == null) { |
| 6303 | return null; |
| 6304 | } |
| 6305 | return mBluetoothScanTimer.getSubTimer(); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 6306 | } |
| 6307 | |
Bookatz | 956f36bf | 2017-04-28 09:48:17 -0700 | [diff] [blame] | 6308 | @Override |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 6309 | public Timer getBluetoothUnoptimizedScanTimer() { |
| 6310 | return mBluetoothUnoptimizedScanTimer; |
| 6311 | } |
| 6312 | |
| 6313 | @Override |
| 6314 | public Timer getBluetoothUnoptimizedScanBackgroundTimer() { |
| 6315 | if (mBluetoothUnoptimizedScanTimer == null) { |
| 6316 | return null; |
| 6317 | } |
| 6318 | return mBluetoothUnoptimizedScanTimer.getSubTimer(); |
| 6319 | } |
| 6320 | |
| 6321 | @Override |
Bookatz | 956f36bf | 2017-04-28 09:48:17 -0700 | [diff] [blame] | 6322 | public Counter getBluetoothScanResultCounter() { |
| 6323 | return mBluetoothScanResultCounter; |
| 6324 | } |
| 6325 | |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 6326 | @Override |
| 6327 | public Counter getBluetoothScanResultBgCounter() { |
| 6328 | return mBluetoothScanResultBgCounter; |
| 6329 | } |
| 6330 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 6331 | void makeProcessState(int i, Parcel in) { |
| 6332 | if (i < 0 || i >= NUM_PROCESS_STATE) return; |
| 6333 | |
| 6334 | if (in == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6335 | mProcessStateTimer[i] = new StopwatchTimer(mBsi.mClocks, this, PROCESS_STATE, null, |
| 6336 | mBsi.mOnBatteryTimeBase); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 6337 | } else { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6338 | mProcessStateTimer[i] = new StopwatchTimer(mBsi.mClocks, this, PROCESS_STATE, null, |
| 6339 | mBsi.mOnBatteryTimeBase, in); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 6340 | } |
| 6341 | } |
| 6342 | |
| 6343 | @Override |
| 6344 | public long getProcessStateTime(int state, long elapsedRealtimeUs, int which) { |
| 6345 | if (state < 0 || state >= NUM_PROCESS_STATE) return 0; |
| 6346 | if (mProcessStateTimer[state] == null) { |
| 6347 | return 0; |
| 6348 | } |
| 6349 | return mProcessStateTimer[state].getTotalTimeLocked(elapsedRealtimeUs, which); |
| 6350 | } |
| 6351 | |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 6352 | @Override |
Joe Onorato | 713fec8 | 2016-03-04 10:34:02 -0800 | [diff] [blame] | 6353 | public Timer getProcessStateTimer(int state) { |
| 6354 | if (state < 0 || state >= NUM_PROCESS_STATE) return null; |
| 6355 | return mProcessStateTimer[state]; |
| 6356 | } |
| 6357 | |
| 6358 | @Override |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 6359 | public Timer getVibratorOnTimer() { |
| 6360 | return mVibratorOnTimer; |
| 6361 | } |
| 6362 | |
| 6363 | @Override |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 6364 | public void noteUserActivityLocked(int type) { |
| 6365 | if (mUserActivityCounters == null) { |
| 6366 | initUserActivityLocked(); |
| 6367 | } |
Jeff Brown | df693de | 2012-07-27 12:03:38 -0700 | [diff] [blame] | 6368 | if (type >= 0 && type < NUM_USER_ACTIVITY_TYPES) { |
| 6369 | mUserActivityCounters[type].stepAtomic(); |
| 6370 | } else { |
| 6371 | Slog.w(TAG, "Unknown user activity type " + type + " was specified.", |
| 6372 | new Throwable()); |
| 6373 | } |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 6374 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6375 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 6376 | @Override |
| 6377 | public boolean hasUserActivity() { |
| 6378 | return mUserActivityCounters != null; |
| 6379 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6380 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 6381 | @Override |
| 6382 | public int getUserActivityCount(int type, int which) { |
| 6383 | if (mUserActivityCounters == null) { |
| 6384 | return 0; |
| 6385 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 6386 | return mUserActivityCounters[type].getCountLocked(which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 6387 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6388 | |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 6389 | void makeWifiBatchedScanBin(int i, Parcel in) { |
| 6390 | if (i < 0 || i >= NUM_WIFI_BATCHED_SCAN_BINS) return; |
| 6391 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6392 | ArrayList<StopwatchTimer> collected = mBsi.mWifiBatchedScanTimers.get(i); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 6393 | if (collected == null) { |
| 6394 | collected = new ArrayList<StopwatchTimer>(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6395 | mBsi.mWifiBatchedScanTimers.put(i, collected); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 6396 | } |
| 6397 | if (in == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6398 | mWifiBatchedScanTimer[i] = new StopwatchTimer(mBsi.mClocks, this, WIFI_BATCHED_SCAN, |
| 6399 | collected, mBsi.mOnBatteryTimeBase); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 6400 | } else { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6401 | mWifiBatchedScanTimer[i] = new StopwatchTimer(mBsi.mClocks, this, WIFI_BATCHED_SCAN, |
| 6402 | collected, mBsi.mOnBatteryTimeBase, in); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 6403 | } |
| 6404 | } |
| 6405 | |
| 6406 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 6407 | void initUserActivityLocked() { |
| 6408 | mUserActivityCounters = new Counter[NUM_USER_ACTIVITY_TYPES]; |
| 6409 | for (int i=0; i<NUM_USER_ACTIVITY_TYPES; i++) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6410 | mUserActivityCounters[i] = new Counter(mBsi.mOnBatteryTimeBase); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 6411 | } |
| 6412 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6413 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6414 | void noteNetworkActivityLocked(int type, long deltaBytes, long deltaPackets) { |
| 6415 | if (mNetworkByteActivityCounters == null) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 6416 | initNetworkActivityLocked(); |
| 6417 | } |
| 6418 | if (type >= 0 && type < NUM_NETWORK_ACTIVITY_TYPES) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6419 | mNetworkByteActivityCounters[type].addCountLocked(deltaBytes); |
| 6420 | mNetworkPacketActivityCounters[type].addCountLocked(deltaPackets); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 6421 | } else { |
| 6422 | Slog.w(TAG, "Unknown network activity type " + type + " was specified.", |
| 6423 | new Throwable()); |
| 6424 | } |
| 6425 | } |
| 6426 | |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 6427 | void noteMobileRadioActiveTimeLocked(long batteryUptime) { |
| 6428 | if (mNetworkByteActivityCounters == null) { |
| 6429 | initNetworkActivityLocked(); |
| 6430 | } |
| 6431 | mMobileRadioActiveTime.addCountLocked(batteryUptime); |
| 6432 | mMobileRadioActiveCount.addCountLocked(1); |
| 6433 | } |
| 6434 | |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 6435 | @Override |
| 6436 | public boolean hasNetworkActivity() { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6437 | return mNetworkByteActivityCounters != null; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 6438 | } |
| 6439 | |
| 6440 | @Override |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6441 | public long getNetworkActivityBytes(int type, int which) { |
| 6442 | if (mNetworkByteActivityCounters != null && type >= 0 |
| 6443 | && type < mNetworkByteActivityCounters.length) { |
| 6444 | return mNetworkByteActivityCounters[type].getCountLocked(which); |
| 6445 | } else { |
| 6446 | return 0; |
| 6447 | } |
| 6448 | } |
| 6449 | |
| 6450 | @Override |
| 6451 | public long getNetworkActivityPackets(int type, int which) { |
| 6452 | if (mNetworkPacketActivityCounters != null && type >= 0 |
| 6453 | && type < mNetworkPacketActivityCounters.length) { |
| 6454 | return mNetworkPacketActivityCounters[type].getCountLocked(which); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 6455 | } else { |
| 6456 | return 0; |
| 6457 | } |
| 6458 | } |
| 6459 | |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 6460 | @Override |
| 6461 | public long getMobileRadioActiveTime(int which) { |
| 6462 | return mMobileRadioActiveTime != null |
| 6463 | ? mMobileRadioActiveTime.getCountLocked(which) : 0; |
| 6464 | } |
| 6465 | |
| 6466 | @Override |
| 6467 | public int getMobileRadioActiveCount(int which) { |
| 6468 | return mMobileRadioActiveCount != null |
| 6469 | ? (int)mMobileRadioActiveCount.getCountLocked(which) : 0; |
| 6470 | } |
| 6471 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 6472 | @Override |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 6473 | public long getUserCpuTimeUs(int which) { |
| 6474 | return mUserCpuTime.getCountLocked(which); |
| 6475 | } |
| 6476 | |
| 6477 | @Override |
| 6478 | public long getSystemCpuTimeUs(int which) { |
| 6479 | return mSystemCpuTime.getCountLocked(which); |
| 6480 | } |
| 6481 | |
| 6482 | @Override |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 6483 | public long getTimeAtCpuSpeed(int cluster, int step, int which) { |
| 6484 | if (mCpuClusterSpeed != null) { |
| 6485 | if (cluster >= 0 && cluster < mCpuClusterSpeed.length) { |
| 6486 | final LongSamplingCounter[] cpuSpeeds = mCpuClusterSpeed[cluster]; |
| 6487 | if (cpuSpeeds != null) { |
| 6488 | if (step >= 0 && step < cpuSpeeds.length) { |
| 6489 | final LongSamplingCounter c = cpuSpeeds[step]; |
| 6490 | if (c != null) { |
| 6491 | return c.getCountLocked(which); |
| 6492 | } |
| 6493 | } |
| 6494 | } |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 6495 | } |
| 6496 | } |
| 6497 | return 0; |
| 6498 | } |
| 6499 | |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 6500 | public void noteMobileRadioApWakeupLocked() { |
| 6501 | if (mMobileRadioApWakeupCount == null) { |
| 6502 | mMobileRadioApWakeupCount = new LongSamplingCounter(mBsi.mOnBatteryTimeBase); |
| 6503 | } |
| 6504 | mMobileRadioApWakeupCount.addCountLocked(1); |
| 6505 | } |
| 6506 | |
| 6507 | @Override |
| 6508 | public long getMobileRadioApWakeupCount(int which) { |
| 6509 | if (mMobileRadioApWakeupCount != null) { |
| 6510 | return mMobileRadioApWakeupCount.getCountLocked(which); |
| 6511 | } |
| 6512 | return 0; |
| 6513 | } |
| 6514 | |
| 6515 | public void noteWifiRadioApWakeupLocked() { |
| 6516 | if (mWifiRadioApWakeupCount == null) { |
| 6517 | mWifiRadioApWakeupCount = new LongSamplingCounter(mBsi.mOnBatteryTimeBase); |
| 6518 | } |
| 6519 | mWifiRadioApWakeupCount.addCountLocked(1); |
| 6520 | } |
| 6521 | |
| 6522 | @Override |
| 6523 | public long getWifiRadioApWakeupCount(int which) { |
| 6524 | if (mWifiRadioApWakeupCount != null) { |
| 6525 | return mWifiRadioApWakeupCount.getCountLocked(which); |
| 6526 | } |
| 6527 | return 0; |
| 6528 | } |
| 6529 | |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 6530 | void initNetworkActivityLocked() { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6531 | mNetworkByteActivityCounters = new LongSamplingCounter[NUM_NETWORK_ACTIVITY_TYPES]; |
| 6532 | mNetworkPacketActivityCounters = new LongSamplingCounter[NUM_NETWORK_ACTIVITY_TYPES]; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 6533 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6534 | mNetworkByteActivityCounters[i] = new LongSamplingCounter(mBsi.mOnBatteryTimeBase); |
| 6535 | mNetworkPacketActivityCounters[i] = new LongSamplingCounter(mBsi.mOnBatteryTimeBase); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 6536 | } |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6537 | mMobileRadioActiveTime = new LongSamplingCounter(mBsi.mOnBatteryTimeBase); |
| 6538 | mMobileRadioActiveCount = new LongSamplingCounter(mBsi.mOnBatteryTimeBase); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6539 | } |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 6540 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6541 | /** |
| 6542 | * Clear all stats for this uid. Returns true if the uid is completely |
| 6543 | * inactive so can be dropped. |
| 6544 | */ |
Adam Lesinski | 5f212c8 | 2017-03-13 12:25:13 -0700 | [diff] [blame] | 6545 | @VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE) |
| 6546 | public boolean reset() { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6547 | boolean active = false; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6548 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 6549 | if (mWifiRunningTimer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6550 | active |= !mWifiRunningTimer.reset(false); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 6551 | active |= mWifiRunning; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6552 | } |
| 6553 | if (mFullWifiLockTimer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6554 | active |= !mFullWifiLockTimer.reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6555 | active |= mFullWifiLockOut; |
| 6556 | } |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 6557 | if (mWifiScanTimer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6558 | active |= !mWifiScanTimer.reset(false); |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 6559 | active |= mWifiScanStarted; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6560 | } |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 6561 | if (mWifiBatchedScanTimer != null) { |
| 6562 | for (int i = 0; i < NUM_WIFI_BATCHED_SCAN_BINS; i++) { |
| 6563 | if (mWifiBatchedScanTimer[i] != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6564 | active |= !mWifiBatchedScanTimer[i].reset(false); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 6565 | } |
| 6566 | } |
| 6567 | active |= (mWifiBatchedScanBinStarted != NO_BATCHED_SCAN_STARTED); |
| 6568 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6569 | if (mWifiMulticastTimer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6570 | active |= !mWifiMulticastTimer.reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6571 | active |= mWifiMulticastEnabled; |
| 6572 | } |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 6573 | |
| 6574 | active |= !resetTimerIfNotNull(mAudioTurnedOnTimer, false); |
| 6575 | active |= !resetTimerIfNotNull(mVideoTurnedOnTimer, false); |
| 6576 | active |= !resetTimerIfNotNull(mFlashlightTurnedOnTimer, false); |
| 6577 | active |= !resetTimerIfNotNull(mCameraTurnedOnTimer, false); |
| 6578 | active |= !resetTimerIfNotNull(mForegroundActivityTimer, false); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 6579 | active |= !resetTimerIfNotNull(mAggregatedPartialWakelockTimer, false); |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 6580 | active |= !resetTimerIfNotNull(mBluetoothScanTimer, false); |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 6581 | active |= !resetTimerIfNotNull(mBluetoothUnoptimizedScanTimer, false); |
Bookatz | 956f36bf | 2017-04-28 09:48:17 -0700 | [diff] [blame] | 6582 | if (mBluetoothScanResultCounter != null) { |
| 6583 | mBluetoothScanResultCounter.reset(false); |
| 6584 | } |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 6585 | if (mBluetoothScanResultBgCounter != null) { |
| 6586 | mBluetoothScanResultBgCounter.reset(false); |
| 6587 | } |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 6588 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 6589 | if (mProcessStateTimer != null) { |
| 6590 | for (int i = 0; i < NUM_PROCESS_STATE; i++) { |
| 6591 | if (mProcessStateTimer[i] != null) { |
| 6592 | active |= !mProcessStateTimer[i].reset(false); |
| 6593 | } |
| 6594 | } |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 6595 | active |= (mProcessState != ActivityManager.PROCESS_STATE_NONEXISTENT); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 6596 | } |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 6597 | if (mVibratorOnTimer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6598 | if (mVibratorOnTimer.reset(false)) { |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 6599 | mVibratorOnTimer.detach(); |
| 6600 | mVibratorOnTimer = null; |
| 6601 | } else { |
| 6602 | active = true; |
| 6603 | } |
| 6604 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6605 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6606 | if (mUserActivityCounters != null) { |
| 6607 | for (int i=0; i<NUM_USER_ACTIVITY_TYPES; i++) { |
| 6608 | mUserActivityCounters[i].reset(false); |
| 6609 | } |
| 6610 | } |
| 6611 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6612 | if (mNetworkByteActivityCounters != null) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 6613 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6614 | mNetworkByteActivityCounters[i].reset(false); |
| 6615 | mNetworkPacketActivityCounters[i].reset(false); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 6616 | } |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 6617 | mMobileRadioActiveTime.reset(false); |
| 6618 | mMobileRadioActiveCount.reset(false); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 6619 | } |
| 6620 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 6621 | if (mWifiControllerActivity != null) { |
| 6622 | mWifiControllerActivity.reset(false); |
| 6623 | } |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 6624 | |
Adam Lesinski | 1a2b39e | 2016-04-29 17:56:58 -0700 | [diff] [blame] | 6625 | if (mBluetoothControllerActivity != null) { |
| 6626 | mBluetoothControllerActivity.reset(false); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 6627 | } |
| 6628 | |
Adam Lesinski | 1a2b39e | 2016-04-29 17:56:58 -0700 | [diff] [blame] | 6629 | if (mModemControllerActivity != null) { |
| 6630 | mModemControllerActivity.reset(false); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 6631 | } |
| 6632 | |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 6633 | mUserCpuTime.reset(false); |
| 6634 | mSystemCpuTime.reset(false); |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 6635 | |
| 6636 | if (mCpuClusterSpeed != null) { |
| 6637 | for (LongSamplingCounter[] speeds : mCpuClusterSpeed) { |
| 6638 | if (speeds != null) { |
| 6639 | for (LongSamplingCounter speed : speeds) { |
| 6640 | if (speed != null) { |
| 6641 | speed.reset(false); |
| 6642 | } |
| 6643 | } |
| 6644 | } |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 6645 | } |
| 6646 | } |
| 6647 | |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 6648 | if (mCpuFreqTimeMs != null) { |
| 6649 | mCpuFreqTimeMs.reset(false); |
| 6650 | } |
| 6651 | if (mScreenOffCpuFreqTimeMs != null) { |
| 6652 | mScreenOffCpuFreqTimeMs.reset(false); |
| 6653 | } |
| 6654 | |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 6655 | resetLongCounterIfNotNull(mMobileRadioApWakeupCount, false); |
| 6656 | resetLongCounterIfNotNull(mWifiRadioApWakeupCount, false); |
| 6657 | |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 6658 | final ArrayMap<String, Wakelock> wakeStats = mWakelockStats.getMap(); |
| 6659 | for (int iw=wakeStats.size()-1; iw>=0; iw--) { |
| 6660 | Wakelock wl = wakeStats.valueAt(iw); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 6661 | if (wl.reset()) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 6662 | wakeStats.removeAt(iw); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 6663 | } else { |
| 6664 | active = true; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6665 | } |
| 6666 | } |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 6667 | mWakelockStats.cleanup(); |
Bookatz | 2bffb5b | 2017-04-13 11:59:33 -0700 | [diff] [blame] | 6668 | final ArrayMap<String, DualTimer> syncStats = mSyncStats.getMap(); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 6669 | for (int is=syncStats.size()-1; is>=0; is--) { |
Bookatz | 2bffb5b | 2017-04-13 11:59:33 -0700 | [diff] [blame] | 6670 | DualTimer timer = syncStats.valueAt(is); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 6671 | if (timer.reset(false)) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 6672 | syncStats.removeAt(is); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 6673 | timer.detach(); |
| 6674 | } else { |
| 6675 | active = true; |
| 6676 | } |
| 6677 | } |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 6678 | mSyncStats.cleanup(); |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 6679 | final ArrayMap<String, DualTimer> jobStats = mJobStats.getMap(); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 6680 | for (int ij=jobStats.size()-1; ij>=0; ij--) { |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 6681 | DualTimer timer = jobStats.valueAt(ij); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 6682 | if (timer.reset(false)) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 6683 | jobStats.removeAt(ij); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 6684 | timer.detach(); |
| 6685 | } else { |
| 6686 | active = true; |
| 6687 | } |
| 6688 | } |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 6689 | mJobStats.cleanup(); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 6690 | for (int ise=mSensorStats.size()-1; ise>=0; ise--) { |
| 6691 | Sensor s = mSensorStats.valueAt(ise); |
| 6692 | if (s.reset()) { |
| 6693 | mSensorStats.removeAt(ise); |
| 6694 | } else { |
| 6695 | active = true; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6696 | } |
| 6697 | } |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 6698 | for (int ip=mProcessStats.size()-1; ip>=0; ip--) { |
| 6699 | Proc proc = mProcessStats.valueAt(ip); |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 6700 | proc.detach(); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6701 | } |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 6702 | mProcessStats.clear(); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 6703 | if (mPids.size() > 0) { |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 6704 | for (int i=mPids.size()-1; i>=0; i--) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 6705 | Pid pid = mPids.valueAt(i); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 6706 | if (pid.mWakeNesting > 0) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 6707 | active = true; |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 6708 | } else { |
| 6709 | mPids.removeAt(i); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 6710 | } |
| 6711 | } |
| 6712 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6713 | if (mPackageStats.size() > 0) { |
| 6714 | Iterator<Map.Entry<String, Pkg>> it = mPackageStats.entrySet().iterator(); |
| 6715 | while (it.hasNext()) { |
| 6716 | Map.Entry<String, Pkg> pkgEntry = it.next(); |
| 6717 | Pkg p = pkgEntry.getValue(); |
| 6718 | p.detach(); |
| 6719 | if (p.mServiceStats.size() > 0) { |
| 6720 | Iterator<Map.Entry<String, Pkg.Serv>> it2 |
| 6721 | = p.mServiceStats.entrySet().iterator(); |
| 6722 | while (it2.hasNext()) { |
| 6723 | Map.Entry<String, Pkg.Serv> servEntry = it2.next(); |
| 6724 | servEntry.getValue().detach(); |
| 6725 | } |
| 6726 | } |
| 6727 | } |
| 6728 | mPackageStats.clear(); |
| 6729 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6730 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 6731 | mLastStepUserTime = mLastStepSystemTime = 0; |
| 6732 | mCurStepUserTime = mCurStepSystemTime = 0; |
| 6733 | |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 6734 | mOnBatteryBackgroundTimeBase.reset(mBsi.mClocks.elapsedRealtime() * 1000, |
| 6735 | mBsi.mClocks.uptimeMillis() * 1000); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 6736 | mOnBatteryScreenOffBackgroundTimeBase.reset(mBsi.mClocks.elapsedRealtime() * 1000, |
| 6737 | mBsi.mClocks.uptimeMillis() * 1000); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 6738 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6739 | if (!active) { |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 6740 | if (mWifiRunningTimer != null) { |
| 6741 | mWifiRunningTimer.detach(); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6742 | } |
| 6743 | if (mFullWifiLockTimer != null) { |
| 6744 | mFullWifiLockTimer.detach(); |
| 6745 | } |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 6746 | if (mWifiScanTimer != null) { |
| 6747 | mWifiScanTimer.detach(); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6748 | } |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 6749 | for (int i = 0; i < NUM_WIFI_BATCHED_SCAN_BINS; i++) { |
| 6750 | if (mWifiBatchedScanTimer[i] != null) { |
| 6751 | mWifiBatchedScanTimer[i].detach(); |
| 6752 | } |
| 6753 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6754 | if (mWifiMulticastTimer != null) { |
| 6755 | mWifiMulticastTimer.detach(); |
| 6756 | } |
| 6757 | if (mAudioTurnedOnTimer != null) { |
| 6758 | mAudioTurnedOnTimer.detach(); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 6759 | mAudioTurnedOnTimer = null; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6760 | } |
| 6761 | if (mVideoTurnedOnTimer != null) { |
| 6762 | mVideoTurnedOnTimer.detach(); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 6763 | mVideoTurnedOnTimer = null; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6764 | } |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 6765 | if (mFlashlightTurnedOnTimer != null) { |
| 6766 | mFlashlightTurnedOnTimer.detach(); |
| 6767 | mFlashlightTurnedOnTimer = null; |
| 6768 | } |
| 6769 | if (mCameraTurnedOnTimer != null) { |
| 6770 | mCameraTurnedOnTimer.detach(); |
| 6771 | mCameraTurnedOnTimer = null; |
| 6772 | } |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 6773 | if (mForegroundActivityTimer != null) { |
| 6774 | mForegroundActivityTimer.detach(); |
| 6775 | mForegroundActivityTimer = null; |
| 6776 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 6777 | if (mAggregatedPartialWakelockTimer != null) { |
| 6778 | mAggregatedPartialWakelockTimer.detach(); |
| 6779 | mAggregatedPartialWakelockTimer = null; |
| 6780 | } |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 6781 | if (mBluetoothScanTimer != null) { |
| 6782 | mBluetoothScanTimer.detach(); |
| 6783 | mBluetoothScanTimer = null; |
| 6784 | } |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 6785 | if (mBluetoothUnoptimizedScanTimer != null) { |
| 6786 | mBluetoothUnoptimizedScanTimer.detach(); |
| 6787 | mBluetoothUnoptimizedScanTimer = null; |
| 6788 | } |
Bookatz | 956f36bf | 2017-04-28 09:48:17 -0700 | [diff] [blame] | 6789 | if (mBluetoothScanResultCounter != null) { |
| 6790 | mBluetoothScanResultCounter.detach(); |
| 6791 | mBluetoothScanResultCounter = null; |
| 6792 | } |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 6793 | if (mBluetoothScanResultBgCounter != null) { |
| 6794 | mBluetoothScanResultBgCounter.detach(); |
| 6795 | mBluetoothScanResultBgCounter = null; |
| 6796 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6797 | if (mUserActivityCounters != null) { |
| 6798 | for (int i=0; i<NUM_USER_ACTIVITY_TYPES; i++) { |
| 6799 | mUserActivityCounters[i].detach(); |
| 6800 | } |
| 6801 | } |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6802 | if (mNetworkByteActivityCounters != null) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 6803 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6804 | mNetworkByteActivityCounters[i].detach(); |
| 6805 | mNetworkPacketActivityCounters[i].detach(); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 6806 | } |
| 6807 | } |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 6808 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 6809 | if (mWifiControllerActivity != null) { |
| 6810 | mWifiControllerActivity.detach(); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 6811 | } |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 6812 | |
| 6813 | if (mBluetoothControllerActivity != null) { |
| 6814 | mBluetoothControllerActivity.detach(); |
| 6815 | } |
| 6816 | |
| 6817 | if (mModemControllerActivity != null) { |
| 6818 | mModemControllerActivity.detach(); |
| 6819 | } |
| 6820 | |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 6821 | mPids.clear(); |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 6822 | |
| 6823 | mUserCpuTime.detach(); |
| 6824 | mSystemCpuTime.detach(); |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 6825 | |
| 6826 | if (mCpuClusterSpeed != null) { |
| 6827 | for (LongSamplingCounter[] cpuSpeeds : mCpuClusterSpeed) { |
| 6828 | if (cpuSpeeds != null) { |
| 6829 | for (LongSamplingCounter c : cpuSpeeds) { |
| 6830 | if (c != null) { |
| 6831 | c.detach(); |
| 6832 | } |
| 6833 | } |
| 6834 | } |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 6835 | } |
| 6836 | } |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 6837 | |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 6838 | if (mCpuFreqTimeMs != null) { |
| 6839 | mCpuFreqTimeMs.detach(); |
| 6840 | } |
| 6841 | if (mScreenOffCpuFreqTimeMs != null) { |
| 6842 | mScreenOffCpuFreqTimeMs.detach(); |
| 6843 | } |
| 6844 | |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 6845 | detachLongCounterIfNotNull(mMobileRadioApWakeupCount); |
| 6846 | detachLongCounterIfNotNull(mWifiRadioApWakeupCount); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6847 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6848 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6849 | return !active; |
| 6850 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6851 | |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 6852 | void writeToParcelLocked(Parcel out, long uptimeUs, long elapsedRealtimeUs) { |
| 6853 | mOnBatteryBackgroundTimeBase.writeToParcel(out, uptimeUs, elapsedRealtimeUs); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 6854 | mOnBatteryScreenOffBackgroundTimeBase.writeToParcel(out, uptimeUs, elapsedRealtimeUs); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 6855 | |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 6856 | final ArrayMap<String, Wakelock> wakeStats = mWakelockStats.getMap(); |
| 6857 | int NW = wakeStats.size(); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 6858 | out.writeInt(NW); |
| 6859 | for (int iw=0; iw<NW; iw++) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 6860 | out.writeString(wakeStats.keyAt(iw)); |
| 6861 | Uid.Wakelock wakelock = wakeStats.valueAt(iw); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6862 | wakelock.writeToParcelLocked(out, elapsedRealtimeUs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6863 | } |
| 6864 | |
Bookatz | 2bffb5b | 2017-04-13 11:59:33 -0700 | [diff] [blame] | 6865 | final ArrayMap<String, DualTimer> syncStats = mSyncStats.getMap(); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 6866 | int NS = syncStats.size(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 6867 | out.writeInt(NS); |
| 6868 | for (int is=0; is<NS; is++) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 6869 | out.writeString(syncStats.keyAt(is)); |
Bookatz | 2bffb5b | 2017-04-13 11:59:33 -0700 | [diff] [blame] | 6870 | DualTimer timer = syncStats.valueAt(is); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 6871 | Timer.writeTimerToParcel(out, timer, elapsedRealtimeUs); |
| 6872 | } |
| 6873 | |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 6874 | final ArrayMap<String, DualTimer> jobStats = mJobStats.getMap(); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 6875 | int NJ = jobStats.size(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 6876 | out.writeInt(NJ); |
| 6877 | for (int ij=0; ij<NJ; ij++) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 6878 | out.writeString(jobStats.keyAt(ij)); |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 6879 | DualTimer timer = jobStats.valueAt(ij); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 6880 | Timer.writeTimerToParcel(out, timer, elapsedRealtimeUs); |
| 6881 | } |
| 6882 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 6883 | int NSE = mSensorStats.size(); |
| 6884 | out.writeInt(NSE); |
| 6885 | for (int ise=0; ise<NSE; ise++) { |
| 6886 | out.writeInt(mSensorStats.keyAt(ise)); |
| 6887 | Uid.Sensor sensor = mSensorStats.valueAt(ise); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6888 | sensor.writeToParcelLocked(out, elapsedRealtimeUs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6889 | } |
| 6890 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 6891 | int NP = mProcessStats.size(); |
| 6892 | out.writeInt(NP); |
| 6893 | for (int ip=0; ip<NP; ip++) { |
| 6894 | out.writeString(mProcessStats.keyAt(ip)); |
| 6895 | Uid.Proc proc = mProcessStats.valueAt(ip); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6896 | proc.writeToParcelLocked(out); |
| 6897 | } |
| 6898 | |
| 6899 | out.writeInt(mPackageStats.size()); |
| 6900 | for (Map.Entry<String, Uid.Pkg> pkgEntry : mPackageStats.entrySet()) { |
| 6901 | out.writeString(pkgEntry.getKey()); |
| 6902 | Uid.Pkg pkg = pkgEntry.getValue(); |
| 6903 | pkg.writeToParcelLocked(out); |
| 6904 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6905 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 6906 | if (mWifiRunningTimer != null) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6907 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6908 | mWifiRunningTimer.writeToParcel(out, elapsedRealtimeUs); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 6909 | } else { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6910 | out.writeInt(0); |
| 6911 | } |
| 6912 | if (mFullWifiLockTimer != null) { |
| 6913 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6914 | mFullWifiLockTimer.writeToParcel(out, elapsedRealtimeUs); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6915 | } else { |
| 6916 | out.writeInt(0); |
| 6917 | } |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 6918 | if (mWifiScanTimer != null) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6919 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6920 | mWifiScanTimer.writeToParcel(out, elapsedRealtimeUs); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6921 | } else { |
| 6922 | out.writeInt(0); |
| 6923 | } |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 6924 | for (int i = 0; i < NUM_WIFI_BATCHED_SCAN_BINS; i++) { |
| 6925 | if (mWifiBatchedScanTimer[i] != null) { |
| 6926 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6927 | mWifiBatchedScanTimer[i].writeToParcel(out, elapsedRealtimeUs); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 6928 | } else { |
| 6929 | out.writeInt(0); |
| 6930 | } |
| 6931 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6932 | if (mWifiMulticastTimer != null) { |
| 6933 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6934 | mWifiMulticastTimer.writeToParcel(out, elapsedRealtimeUs); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6935 | } else { |
| 6936 | out.writeInt(0); |
| 6937 | } |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 6938 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6939 | if (mAudioTurnedOnTimer != null) { |
| 6940 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6941 | mAudioTurnedOnTimer.writeToParcel(out, elapsedRealtimeUs); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6942 | } else { |
| 6943 | out.writeInt(0); |
| 6944 | } |
| 6945 | if (mVideoTurnedOnTimer != null) { |
| 6946 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6947 | mVideoTurnedOnTimer.writeToParcel(out, elapsedRealtimeUs); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6948 | } else { |
| 6949 | out.writeInt(0); |
| 6950 | } |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 6951 | if (mFlashlightTurnedOnTimer != null) { |
| 6952 | out.writeInt(1); |
| 6953 | mFlashlightTurnedOnTimer.writeToParcel(out, elapsedRealtimeUs); |
| 6954 | } else { |
| 6955 | out.writeInt(0); |
| 6956 | } |
| 6957 | if (mCameraTurnedOnTimer != null) { |
| 6958 | out.writeInt(1); |
| 6959 | mCameraTurnedOnTimer.writeToParcel(out, elapsedRealtimeUs); |
| 6960 | } else { |
| 6961 | out.writeInt(0); |
| 6962 | } |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 6963 | if (mForegroundActivityTimer != null) { |
| 6964 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6965 | mForegroundActivityTimer.writeToParcel(out, elapsedRealtimeUs); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 6966 | } else { |
| 6967 | out.writeInt(0); |
| 6968 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 6969 | if (mAggregatedPartialWakelockTimer != null) { |
| 6970 | out.writeInt(1); |
| 6971 | mAggregatedPartialWakelockTimer.writeToParcel(out, elapsedRealtimeUs); |
| 6972 | } else { |
| 6973 | out.writeInt(0); |
| 6974 | } |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 6975 | if (mBluetoothScanTimer != null) { |
| 6976 | out.writeInt(1); |
| 6977 | mBluetoothScanTimer.writeToParcel(out, elapsedRealtimeUs); |
| 6978 | } else { |
| 6979 | out.writeInt(0); |
| 6980 | } |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 6981 | if (mBluetoothUnoptimizedScanTimer != null) { |
| 6982 | out.writeInt(1); |
| 6983 | mBluetoothUnoptimizedScanTimer.writeToParcel(out, elapsedRealtimeUs); |
| 6984 | } else { |
| 6985 | out.writeInt(0); |
| 6986 | } |
Bookatz | 956f36bf | 2017-04-28 09:48:17 -0700 | [diff] [blame] | 6987 | if (mBluetoothScanResultCounter != null) { |
| 6988 | out.writeInt(1); |
| 6989 | mBluetoothScanResultCounter.writeToParcel(out); |
| 6990 | } else { |
| 6991 | out.writeInt(0); |
| 6992 | } |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 6993 | if (mBluetoothScanResultBgCounter != null) { |
| 6994 | out.writeInt(1); |
| 6995 | mBluetoothScanResultBgCounter.writeToParcel(out); |
| 6996 | } else { |
| 6997 | out.writeInt(0); |
| 6998 | } |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 6999 | for (int i = 0; i < NUM_PROCESS_STATE; i++) { |
| 7000 | if (mProcessStateTimer[i] != null) { |
| 7001 | out.writeInt(1); |
| 7002 | mProcessStateTimer[i].writeToParcel(out, elapsedRealtimeUs); |
| 7003 | } else { |
| 7004 | out.writeInt(0); |
| 7005 | } |
| 7006 | } |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 7007 | if (mVibratorOnTimer != null) { |
| 7008 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7009 | mVibratorOnTimer.writeToParcel(out, elapsedRealtimeUs); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 7010 | } else { |
| 7011 | out.writeInt(0); |
| 7012 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7013 | if (mUserActivityCounters != null) { |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 7014 | out.writeInt(1); |
| 7015 | for (int i=0; i<NUM_USER_ACTIVITY_TYPES; i++) { |
| 7016 | mUserActivityCounters[i].writeToParcel(out); |
| 7017 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7018 | } else { |
| 7019 | out.writeInt(0); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 7020 | } |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 7021 | if (mNetworkByteActivityCounters != null) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 7022 | out.writeInt(1); |
| 7023 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 7024 | mNetworkByteActivityCounters[i].writeToParcel(out); |
| 7025 | mNetworkPacketActivityCounters[i].writeToParcel(out); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 7026 | } |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 7027 | mMobileRadioActiveTime.writeToParcel(out); |
| 7028 | mMobileRadioActiveCount.writeToParcel(out); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 7029 | } else { |
| 7030 | out.writeInt(0); |
| 7031 | } |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 7032 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 7033 | if (mWifiControllerActivity != null) { |
| 7034 | out.writeInt(1); |
| 7035 | mWifiControllerActivity.writeToParcel(out, 0); |
| 7036 | } else { |
| 7037 | out.writeInt(0); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 7038 | } |
| 7039 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 7040 | if (mBluetoothControllerActivity != null) { |
| 7041 | out.writeInt(1); |
| 7042 | mBluetoothControllerActivity.writeToParcel(out, 0); |
| 7043 | } else { |
| 7044 | out.writeInt(0); |
| 7045 | } |
| 7046 | |
| 7047 | if (mModemControllerActivity != null) { |
| 7048 | out.writeInt(1); |
| 7049 | mModemControllerActivity.writeToParcel(out, 0); |
| 7050 | } else { |
| 7051 | out.writeInt(0); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 7052 | } |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 7053 | |
| 7054 | mUserCpuTime.writeToParcel(out); |
| 7055 | mSystemCpuTime.writeToParcel(out); |
| 7056 | |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 7057 | if (mCpuClusterSpeed != null) { |
| 7058 | out.writeInt(1); |
| 7059 | out.writeInt(mCpuClusterSpeed.length); |
| 7060 | for (LongSamplingCounter[] cpuSpeeds : mCpuClusterSpeed) { |
| 7061 | if (cpuSpeeds != null) { |
| 7062 | out.writeInt(1); |
| 7063 | out.writeInt(cpuSpeeds.length); |
| 7064 | for (LongSamplingCounter c : cpuSpeeds) { |
| 7065 | if (c != null) { |
| 7066 | out.writeInt(1); |
| 7067 | c.writeToParcel(out); |
| 7068 | } else { |
| 7069 | out.writeInt(0); |
| 7070 | } |
| 7071 | } |
| 7072 | } else { |
| 7073 | out.writeInt(0); |
| 7074 | } |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 7075 | } |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 7076 | } else { |
| 7077 | out.writeInt(0); |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 7078 | } |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 7079 | |
Sudheer Shanka | 59f5c00 | 2017-05-15 10:57:15 -0700 | [diff] [blame] | 7080 | LongSamplingCounterArray.writeToParcel(out, mCpuFreqTimeMs); |
| 7081 | LongSamplingCounterArray.writeToParcel(out, mScreenOffCpuFreqTimeMs); |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 7082 | |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 7083 | if (mMobileRadioApWakeupCount != null) { |
| 7084 | out.writeInt(1); |
| 7085 | mMobileRadioApWakeupCount.writeToParcel(out); |
| 7086 | } else { |
| 7087 | out.writeInt(0); |
| 7088 | } |
| 7089 | |
| 7090 | if (mWifiRadioApWakeupCount != null) { |
| 7091 | out.writeInt(1); |
| 7092 | mWifiRadioApWakeupCount.writeToParcel(out); |
| 7093 | } else { |
| 7094 | out.writeInt(0); |
| 7095 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7096 | } |
| 7097 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7098 | void readFromParcelLocked(TimeBase timeBase, TimeBase screenOffTimeBase, Parcel in) { |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 7099 | mOnBatteryBackgroundTimeBase.readFromParcel(in); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 7100 | mOnBatteryScreenOffBackgroundTimeBase.readFromParcel(in); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 7101 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7102 | int numWakelocks = in.readInt(); |
| 7103 | mWakelockStats.clear(); |
| 7104 | for (int j = 0; j < numWakelocks; j++) { |
| 7105 | String wakelockName = in.readString(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7106 | Uid.Wakelock wakelock = new Wakelock(mBsi, this); |
Bookatz | 5b5ec32 | 2017-05-26 09:40:38 -0700 | [diff] [blame] | 7107 | wakelock.readFromParcelLocked( |
| 7108 | timeBase, screenOffTimeBase, mOnBatteryScreenOffBackgroundTimeBase, in); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 7109 | mWakelockStats.add(wakelockName, wakelock); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7110 | } |
| 7111 | |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 7112 | int numSyncs = in.readInt(); |
| 7113 | mSyncStats.clear(); |
| 7114 | for (int j = 0; j < numSyncs; j++) { |
| 7115 | String syncName = in.readString(); |
| 7116 | if (in.readInt() != 0) { |
Bookatz | 2bffb5b | 2017-04-13 11:59:33 -0700 | [diff] [blame] | 7117 | mSyncStats.add(syncName, new DualTimer(mBsi.mClocks, Uid.this, SYNC, null, |
| 7118 | mBsi.mOnBatteryTimeBase, mOnBatteryBackgroundTimeBase, in)); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 7119 | } |
| 7120 | } |
| 7121 | |
| 7122 | int numJobs = in.readInt(); |
| 7123 | mJobStats.clear(); |
| 7124 | for (int j = 0; j < numJobs; j++) { |
| 7125 | String jobName = in.readString(); |
| 7126 | if (in.readInt() != 0) { |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 7127 | mJobStats.add(jobName, new DualTimer(mBsi.mClocks, Uid.this, JOB, null, |
| 7128 | mBsi.mOnBatteryTimeBase, mOnBatteryBackgroundTimeBase, in)); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 7129 | } |
| 7130 | } |
| 7131 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7132 | int numSensors = in.readInt(); |
| 7133 | mSensorStats.clear(); |
| 7134 | for (int k = 0; k < numSensors; k++) { |
| 7135 | int sensorNumber = in.readInt(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7136 | Uid.Sensor sensor = new Sensor(mBsi, this, sensorNumber); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 7137 | sensor.readFromParcelLocked(mBsi.mOnBatteryTimeBase, mOnBatteryBackgroundTimeBase, |
| 7138 | in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7139 | mSensorStats.put(sensorNumber, sensor); |
| 7140 | } |
| 7141 | |
| 7142 | int numProcs = in.readInt(); |
| 7143 | mProcessStats.clear(); |
| 7144 | for (int k = 0; k < numProcs; k++) { |
| 7145 | String processName = in.readString(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7146 | Uid.Proc proc = new Proc(mBsi, processName); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7147 | proc.readFromParcelLocked(in); |
| 7148 | mProcessStats.put(processName, proc); |
| 7149 | } |
| 7150 | |
| 7151 | int numPkgs = in.readInt(); |
| 7152 | mPackageStats.clear(); |
| 7153 | for (int l = 0; l < numPkgs; l++) { |
| 7154 | String packageName = in.readString(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7155 | Uid.Pkg pkg = new Pkg(mBsi); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7156 | pkg.readFromParcelLocked(in); |
| 7157 | mPackageStats.put(packageName, pkg); |
| 7158 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7159 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 7160 | mWifiRunning = false; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7161 | if (in.readInt() != 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7162 | mWifiRunningTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, WIFI_RUNNING, |
| 7163 | mBsi.mWifiRunningTimers, mBsi.mOnBatteryTimeBase, in); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 7164 | } else { |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 7165 | mWifiRunningTimer = null; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7166 | } |
| 7167 | mFullWifiLockOut = false; |
| 7168 | if (in.readInt() != 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7169 | mFullWifiLockTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, FULL_WIFI_LOCK, |
| 7170 | mBsi.mFullWifiLockTimers, mBsi.mOnBatteryTimeBase, in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7171 | } else { |
| 7172 | mFullWifiLockTimer = null; |
| 7173 | } |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 7174 | mWifiScanStarted = false; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7175 | if (in.readInt() != 0) { |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 7176 | mWifiScanTimer = new DualTimer(mBsi.mClocks, Uid.this, WIFI_SCAN, |
| 7177 | mBsi.mWifiScanTimers, mBsi.mOnBatteryTimeBase, mOnBatteryBackgroundTimeBase, |
| 7178 | in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7179 | } else { |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 7180 | mWifiScanTimer = null; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7181 | } |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 7182 | mWifiBatchedScanBinStarted = NO_BATCHED_SCAN_STARTED; |
| 7183 | for (int i = 0; i < NUM_WIFI_BATCHED_SCAN_BINS; i++) { |
| 7184 | if (in.readInt() != 0) { |
| 7185 | makeWifiBatchedScanBin(i, in); |
| 7186 | } else { |
| 7187 | mWifiBatchedScanTimer[i] = null; |
| 7188 | } |
| 7189 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7190 | mWifiMulticastEnabled = false; |
| 7191 | if (in.readInt() != 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7192 | mWifiMulticastTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, WIFI_MULTICAST_ENABLED, |
| 7193 | mBsi.mWifiMulticastTimers, mBsi.mOnBatteryTimeBase, in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7194 | } else { |
| 7195 | mWifiMulticastTimer = null; |
| 7196 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7197 | if (in.readInt() != 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7198 | mAudioTurnedOnTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, AUDIO_TURNED_ON, |
| 7199 | mBsi.mAudioTurnedOnTimers, mBsi.mOnBatteryTimeBase, in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7200 | } else { |
| 7201 | mAudioTurnedOnTimer = null; |
| 7202 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7203 | if (in.readInt() != 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7204 | mVideoTurnedOnTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, VIDEO_TURNED_ON, |
| 7205 | mBsi.mVideoTurnedOnTimers, mBsi.mOnBatteryTimeBase, in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7206 | } else { |
| 7207 | mVideoTurnedOnTimer = null; |
| 7208 | } |
| 7209 | if (in.readInt() != 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7210 | mFlashlightTurnedOnTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, |
| 7211 | FLASHLIGHT_TURNED_ON, mBsi.mFlashlightTurnedOnTimers, mBsi.mOnBatteryTimeBase, in); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 7212 | } else { |
| 7213 | mFlashlightTurnedOnTimer = null; |
| 7214 | } |
| 7215 | if (in.readInt() != 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7216 | mCameraTurnedOnTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, CAMERA_TURNED_ON, |
| 7217 | mBsi.mCameraTurnedOnTimers, mBsi.mOnBatteryTimeBase, in); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 7218 | } else { |
| 7219 | mCameraTurnedOnTimer = null; |
| 7220 | } |
| 7221 | if (in.readInt() != 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7222 | mForegroundActivityTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, |
| 7223 | FOREGROUND_ACTIVITY, null, mBsi.mOnBatteryTimeBase, in); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 7224 | } else { |
| 7225 | mForegroundActivityTimer = null; |
| 7226 | } |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 7227 | if (in.readInt() != 0) { |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 7228 | mAggregatedPartialWakelockTimer = new DualTimer(mBsi.mClocks, this, |
| 7229 | AGGREGATED_WAKE_TYPE_PARTIAL, null, |
| 7230 | mBsi.mOnBatteryScreenOffTimeBase, mOnBatteryScreenOffBackgroundTimeBase, |
| 7231 | in); |
| 7232 | } else { |
| 7233 | mAggregatedPartialWakelockTimer = null; |
| 7234 | } |
| 7235 | if (in.readInt() != 0) { |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 7236 | mBluetoothScanTimer = new DualTimer(mBsi.mClocks, Uid.this, BLUETOOTH_SCAN_ON, |
| 7237 | mBsi.mBluetoothScanOnTimers, mBsi.mOnBatteryTimeBase, |
| 7238 | mOnBatteryBackgroundTimeBase, in); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 7239 | } else { |
| 7240 | mBluetoothScanTimer = null; |
| 7241 | } |
Bookatz | 956f36bf | 2017-04-28 09:48:17 -0700 | [diff] [blame] | 7242 | if (in.readInt() != 0) { |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 7243 | mBluetoothUnoptimizedScanTimer = new DualTimer(mBsi.mClocks, Uid.this, |
| 7244 | BLUETOOTH_UNOPTIMIZED_SCAN_ON, null, |
| 7245 | mBsi.mOnBatteryTimeBase, mOnBatteryBackgroundTimeBase, in); |
| 7246 | } else { |
| 7247 | mBluetoothUnoptimizedScanTimer = null; |
| 7248 | } |
| 7249 | if (in.readInt() != 0) { |
Bookatz | 956f36bf | 2017-04-28 09:48:17 -0700 | [diff] [blame] | 7250 | mBluetoothScanResultCounter = new Counter(mBsi.mOnBatteryTimeBase, in); |
| 7251 | } else { |
| 7252 | mBluetoothScanResultCounter = null; |
| 7253 | } |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 7254 | if (in.readInt() != 0) { |
| 7255 | mBluetoothScanResultBgCounter = new Counter(mOnBatteryBackgroundTimeBase, in); |
| 7256 | } else { |
| 7257 | mBluetoothScanResultBgCounter = null; |
| 7258 | } |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 7259 | mProcessState = ActivityManager.PROCESS_STATE_NONEXISTENT; |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 7260 | for (int i = 0; i < NUM_PROCESS_STATE; i++) { |
| 7261 | if (in.readInt() != 0) { |
| 7262 | makeProcessState(i, in); |
| 7263 | } else { |
| 7264 | mProcessStateTimer[i] = null; |
| 7265 | } |
| 7266 | } |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 7267 | if (in.readInt() != 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7268 | mVibratorOnTimer = new BatchTimer(mBsi.mClocks, Uid.this, VIBRATOR_ON, |
| 7269 | mBsi.mOnBatteryTimeBase, in); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 7270 | } else { |
| 7271 | mVibratorOnTimer = null; |
| 7272 | } |
| 7273 | if (in.readInt() != 0) { |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 7274 | mUserActivityCounters = new Counter[NUM_USER_ACTIVITY_TYPES]; |
| 7275 | for (int i=0; i<NUM_USER_ACTIVITY_TYPES; i++) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7276 | mUserActivityCounters[i] = new Counter(mBsi.mOnBatteryTimeBase, in); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 7277 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7278 | } else { |
| 7279 | mUserActivityCounters = null; |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 7280 | } |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 7281 | if (in.readInt() != 0) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 7282 | mNetworkByteActivityCounters = new LongSamplingCounter[NUM_NETWORK_ACTIVITY_TYPES]; |
| 7283 | mNetworkPacketActivityCounters |
| 7284 | = new LongSamplingCounter[NUM_NETWORK_ACTIVITY_TYPES]; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 7285 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7286 | mNetworkByteActivityCounters[i] |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7287 | = new LongSamplingCounter(mBsi.mOnBatteryTimeBase, in); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7288 | mNetworkPacketActivityCounters[i] |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7289 | = new LongSamplingCounter(mBsi.mOnBatteryTimeBase, in); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 7290 | } |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7291 | mMobileRadioActiveTime = new LongSamplingCounter(mBsi.mOnBatteryTimeBase, in); |
| 7292 | mMobileRadioActiveCount = new LongSamplingCounter(mBsi.mOnBatteryTimeBase, in); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 7293 | } else { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 7294 | mNetworkByteActivityCounters = null; |
| 7295 | mNetworkPacketActivityCounters = null; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 7296 | } |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 7297 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 7298 | if (in.readInt() != 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7299 | mWifiControllerActivity = new ControllerActivityCounterImpl(mBsi.mOnBatteryTimeBase, |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 7300 | NUM_WIFI_TX_LEVELS, in); |
| 7301 | } else { |
| 7302 | mWifiControllerActivity = null; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 7303 | } |
| 7304 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 7305 | if (in.readInt() != 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7306 | mBluetoothControllerActivity = new ControllerActivityCounterImpl(mBsi.mOnBatteryTimeBase, |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 7307 | NUM_BT_TX_LEVELS, in); |
| 7308 | } else { |
| 7309 | mBluetoothControllerActivity = null; |
| 7310 | } |
| 7311 | |
| 7312 | if (in.readInt() != 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7313 | mModemControllerActivity = new ControllerActivityCounterImpl(mBsi.mOnBatteryTimeBase, |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 7314 | ModemActivityInfo.TX_POWER_LEVELS, in); |
| 7315 | } else { |
| 7316 | mModemControllerActivity = null; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 7317 | } |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 7318 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7319 | mUserCpuTime = new LongSamplingCounter(mBsi.mOnBatteryTimeBase, in); |
| 7320 | mSystemCpuTime = new LongSamplingCounter(mBsi.mOnBatteryTimeBase, in); |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 7321 | |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 7322 | if (in.readInt() != 0) { |
| 7323 | int numCpuClusters = in.readInt(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7324 | if (mBsi.mPowerProfile != null && mBsi.mPowerProfile.getNumCpuClusters() != numCpuClusters) { |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 7325 | throw new ParcelFormatException("Incompatible number of cpu clusters"); |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 7326 | } |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 7327 | |
| 7328 | mCpuClusterSpeed = new LongSamplingCounter[numCpuClusters][]; |
| 7329 | for (int cluster = 0; cluster < numCpuClusters; cluster++) { |
| 7330 | if (in.readInt() != 0) { |
| 7331 | int numSpeeds = in.readInt(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7332 | if (mBsi.mPowerProfile != null && |
| 7333 | mBsi.mPowerProfile.getNumSpeedStepsInCpuCluster(cluster) != numSpeeds) { |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 7334 | throw new ParcelFormatException("Incompatible number of cpu speeds"); |
| 7335 | } |
| 7336 | |
| 7337 | final LongSamplingCounter[] cpuSpeeds = new LongSamplingCounter[numSpeeds]; |
| 7338 | mCpuClusterSpeed[cluster] = cpuSpeeds; |
| 7339 | for (int speed = 0; speed < numSpeeds; speed++) { |
| 7340 | if (in.readInt() != 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7341 | cpuSpeeds[speed] = new LongSamplingCounter(mBsi.mOnBatteryTimeBase, in); |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 7342 | } |
| 7343 | } |
Adam Lesinski | a57a540 | 2015-09-28 10:21:33 -0700 | [diff] [blame] | 7344 | } else { |
| 7345 | mCpuClusterSpeed[cluster] = null; |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 7346 | } |
| 7347 | } |
| 7348 | } else { |
| 7349 | mCpuClusterSpeed = null; |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 7350 | } |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 7351 | |
Sudheer Shanka | 59f5c00 | 2017-05-15 10:57:15 -0700 | [diff] [blame] | 7352 | mCpuFreqTimeMs = LongSamplingCounterArray.readFromParcel(in, mBsi.mOnBatteryTimeBase); |
| 7353 | mScreenOffCpuFreqTimeMs = LongSamplingCounterArray.readFromParcel( |
| 7354 | in, mBsi.mOnBatteryScreenOffTimeBase); |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 7355 | |
| 7356 | if (in.readInt() != 0) { |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 7357 | mMobileRadioApWakeupCount = new LongSamplingCounter(mBsi.mOnBatteryTimeBase, in); |
| 7358 | } else { |
| 7359 | mMobileRadioApWakeupCount = null; |
| 7360 | } |
| 7361 | |
| 7362 | if (in.readInt() != 0) { |
| 7363 | mWifiRadioApWakeupCount = new LongSamplingCounter(mBsi.mOnBatteryTimeBase, in); |
| 7364 | } else { |
| 7365 | mWifiRadioApWakeupCount = null; |
| 7366 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7367 | } |
| 7368 | |
| 7369 | /** |
| 7370 | * The statistics associated with a particular wake lock. |
| 7371 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7372 | public static class Wakelock extends BatteryStats.Uid.Wakelock { |
| 7373 | /** |
| 7374 | * BatteryStatsImpl that we are associated with. |
| 7375 | */ |
| 7376 | protected BatteryStatsImpl mBsi; |
| 7377 | |
| 7378 | /** |
| 7379 | * BatteryStatsImpl that we are associated with. |
| 7380 | */ |
| 7381 | protected Uid mUid; |
| 7382 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7383 | /** |
| 7384 | * How long (in ms) this uid has been keeping the device partially awake. |
Bookatz | 5b5ec32 | 2017-05-26 09:40:38 -0700 | [diff] [blame] | 7385 | * Tracks both the total time and the time while the app was in the background. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7386 | */ |
Bookatz | 5b5ec32 | 2017-05-26 09:40:38 -0700 | [diff] [blame] | 7387 | DualTimer mTimerPartial; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7388 | |
| 7389 | /** |
| 7390 | * How long (in ms) this uid has been keeping the device fully awake. |
| 7391 | */ |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 7392 | StopwatchTimer mTimerFull; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7393 | |
| 7394 | /** |
| 7395 | * How long (in ms) this uid has had a window keeping the device awake. |
| 7396 | */ |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 7397 | StopwatchTimer mTimerWindow; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7398 | |
| 7399 | /** |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 7400 | * How long (in ms) this uid has had a draw wake lock. |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 7401 | */ |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 7402 | StopwatchTimer mTimerDraw; |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 7403 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7404 | public Wakelock(BatteryStatsImpl bsi, Uid uid) { |
| 7405 | mBsi = bsi; |
| 7406 | mUid = uid; |
| 7407 | } |
| 7408 | |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 7409 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7410 | * Reads a possibly null Timer from a Parcel. The timer is associated with the |
| 7411 | * proper timer pool from the given BatteryStatsImpl object. |
| 7412 | * |
| 7413 | * @param in the Parcel to be read from. |
| 7414 | * return a new Timer, or null. |
| 7415 | */ |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 7416 | private StopwatchTimer readStopwatchTimerFromParcel(int type, |
| 7417 | ArrayList<StopwatchTimer> pool, TimeBase timeBase, Parcel in) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7418 | if (in.readInt() == 0) { |
| 7419 | return null; |
| 7420 | } |
| 7421 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7422 | 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] | 7423 | } |
| 7424 | |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 7425 | /** |
| 7426 | * Reads a possibly null Timer from a Parcel. The timer is associated with the |
| 7427 | * proper timer pool from the given BatteryStatsImpl object. |
| 7428 | * |
| 7429 | * @param in the Parcel to be read from. |
| 7430 | * return a new Timer, or null. |
| 7431 | */ |
Bookatz | 5b5ec32 | 2017-05-26 09:40:38 -0700 | [diff] [blame] | 7432 | private DualTimer readDualTimerFromParcel(int type, ArrayList<StopwatchTimer> pool, |
| 7433 | TimeBase timeBase, TimeBase bgTimeBase, Parcel in) { |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 7434 | if (in.readInt() == 0) { |
| 7435 | return null; |
| 7436 | } |
| 7437 | |
Bookatz | 5b5ec32 | 2017-05-26 09:40:38 -0700 | [diff] [blame] | 7438 | return new DualTimer(mBsi.mClocks, mUid, type, pool, timeBase, bgTimeBase, in); |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 7439 | } |
| 7440 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7441 | boolean reset() { |
| 7442 | boolean wlactive = false; |
| 7443 | if (mTimerFull != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7444 | wlactive |= !mTimerFull.reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7445 | } |
| 7446 | if (mTimerPartial != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7447 | wlactive |= !mTimerPartial.reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7448 | } |
| 7449 | if (mTimerWindow != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7450 | wlactive |= !mTimerWindow.reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7451 | } |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 7452 | if (mTimerDraw != null) { |
| 7453 | wlactive |= !mTimerDraw.reset(false); |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 7454 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7455 | if (!wlactive) { |
| 7456 | if (mTimerFull != null) { |
| 7457 | mTimerFull.detach(); |
| 7458 | mTimerFull = null; |
| 7459 | } |
| 7460 | if (mTimerPartial != null) { |
| 7461 | mTimerPartial.detach(); |
| 7462 | mTimerPartial = null; |
| 7463 | } |
| 7464 | if (mTimerWindow != null) { |
| 7465 | mTimerWindow.detach(); |
| 7466 | mTimerWindow = null; |
| 7467 | } |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 7468 | if (mTimerDraw != null) { |
| 7469 | mTimerDraw.detach(); |
| 7470 | mTimerDraw = null; |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 7471 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7472 | } |
| 7473 | return !wlactive; |
| 7474 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7475 | |
Bookatz | 5b5ec32 | 2017-05-26 09:40:38 -0700 | [diff] [blame] | 7476 | void readFromParcelLocked(TimeBase timeBase, TimeBase screenOffTimeBase, |
| 7477 | TimeBase screenOffBgTimeBase, Parcel in) { |
| 7478 | mTimerPartial = readDualTimerFromParcel(WAKE_TYPE_PARTIAL, |
| 7479 | mBsi.mPartialTimers, screenOffTimeBase, screenOffBgTimeBase, in); |
Joe Onorato | 92fd23f | 2016-07-25 11:18:42 -0700 | [diff] [blame] | 7480 | mTimerFull = readStopwatchTimerFromParcel(WAKE_TYPE_FULL, |
| 7481 | mBsi.mFullTimers, timeBase, in); |
| 7482 | mTimerWindow = readStopwatchTimerFromParcel(WAKE_TYPE_WINDOW, |
| 7483 | mBsi.mWindowTimers, timeBase, in); |
| 7484 | mTimerDraw = readStopwatchTimerFromParcel(WAKE_TYPE_DRAW, |
| 7485 | mBsi.mDrawTimers, timeBase, in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7486 | } |
| 7487 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7488 | void writeToParcelLocked(Parcel out, long elapsedRealtimeUs) { |
| 7489 | Timer.writeTimerToParcel(out, mTimerPartial, elapsedRealtimeUs); |
| 7490 | Timer.writeTimerToParcel(out, mTimerFull, elapsedRealtimeUs); |
| 7491 | Timer.writeTimerToParcel(out, mTimerWindow, elapsedRealtimeUs); |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 7492 | Timer.writeTimerToParcel(out, mTimerDraw, elapsedRealtimeUs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7493 | } |
| 7494 | |
| 7495 | @Override |
| 7496 | public Timer getWakeTime(int type) { |
| 7497 | switch (type) { |
| 7498 | case WAKE_TYPE_FULL: return mTimerFull; |
| 7499 | case WAKE_TYPE_PARTIAL: return mTimerPartial; |
| 7500 | case WAKE_TYPE_WINDOW: return mTimerWindow; |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 7501 | case WAKE_TYPE_DRAW: return mTimerDraw; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7502 | default: throw new IllegalArgumentException("type = " + type); |
| 7503 | } |
| 7504 | } |
| 7505 | } |
| 7506 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7507 | public static class Sensor extends BatteryStats.Uid.Sensor { |
| 7508 | /** |
| 7509 | * BatteryStatsImpl that we are associated with. |
| 7510 | */ |
| 7511 | protected BatteryStatsImpl mBsi; |
| 7512 | |
| 7513 | /** |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 7514 | * Uid that we are associated with. |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7515 | */ |
| 7516 | protected Uid mUid; |
| 7517 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7518 | final int mHandle; |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 7519 | DualTimer mTimer; |
Amith Yamasani | ab9ad19 | 2016-12-06 12:46:59 -0800 | [diff] [blame] | 7520 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7521 | public Sensor(BatteryStatsImpl bsi, Uid uid, int handle) { |
| 7522 | mBsi = bsi; |
| 7523 | mUid = uid; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7524 | mHandle = handle; |
| 7525 | } |
| 7526 | |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 7527 | private DualTimer readTimersFromParcel( |
| 7528 | TimeBase timeBase, TimeBase bgTimeBase, Parcel in) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7529 | if (in.readInt() == 0) { |
| 7530 | return null; |
| 7531 | } |
| 7532 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7533 | ArrayList<StopwatchTimer> pool = mBsi.mSensorTimers.get(mHandle); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7534 | if (pool == null) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 7535 | pool = new ArrayList<StopwatchTimer>(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7536 | mBsi.mSensorTimers.put(mHandle, pool); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7537 | } |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 7538 | return new DualTimer(mBsi.mClocks, mUid, 0, pool, timeBase, bgTimeBase, in); |
Amith Yamasani | ab9ad19 | 2016-12-06 12:46:59 -0800 | [diff] [blame] | 7539 | } |
| 7540 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7541 | boolean reset() { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7542 | if (mTimer.reset(true)) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7543 | mTimer = null; |
| 7544 | return true; |
| 7545 | } |
| 7546 | return false; |
| 7547 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7548 | |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 7549 | void readFromParcelLocked(TimeBase timeBase, TimeBase bgTimeBase, Parcel in) { |
| 7550 | mTimer = readTimersFromParcel(timeBase, bgTimeBase, in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7551 | } |
| 7552 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7553 | void writeToParcelLocked(Parcel out, long elapsedRealtimeUs) { |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 7554 | Timer.writeTimerToParcel(out, mTimer, elapsedRealtimeUs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7555 | } |
| 7556 | |
| 7557 | @Override |
| 7558 | public Timer getSensorTime() { |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 7559 | return mTimer; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7560 | } |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 7561 | |
| 7562 | @Override |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 7563 | public Timer getSensorBackgroundTime() { |
| 7564 | if (mTimer == null) { |
| 7565 | return null; |
| 7566 | } |
| 7567 | return mTimer.getSubTimer(); |
Amith Yamasani | ab9ad19 | 2016-12-06 12:46:59 -0800 | [diff] [blame] | 7568 | } |
| 7569 | |
| 7570 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7571 | public int getHandle() { |
| 7572 | return mHandle; |
| 7573 | } |
| 7574 | } |
| 7575 | |
| 7576 | /** |
| 7577 | * The statistics associated with a particular process. |
| 7578 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7579 | public static class Proc extends BatteryStats.Uid.Proc implements TimeBaseObs { |
| 7580 | /** |
| 7581 | * BatteryStatsImpl that we are associated with. |
| 7582 | */ |
| 7583 | protected BatteryStatsImpl mBsi; |
| 7584 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7585 | /** |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 7586 | * The name of this process. |
| 7587 | */ |
| 7588 | final String mName; |
| 7589 | |
| 7590 | /** |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 7591 | * Remains true until removed from the stats. |
| 7592 | */ |
| 7593 | boolean mActive = true; |
| 7594 | |
| 7595 | /** |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 7596 | * Total time (in ms) spent executing in user code. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7597 | */ |
| 7598 | long mUserTime; |
| 7599 | |
| 7600 | /** |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 7601 | * Total time (in ms) spent executing in kernel code. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7602 | */ |
| 7603 | long mSystemTime; |
| 7604 | |
| 7605 | /** |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 7606 | * Amount of time (in ms) the process was running in the foreground. |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 7607 | */ |
| 7608 | long mForegroundTime; |
| 7609 | |
| 7610 | /** |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 7611 | * Number of times the process has been started. |
| 7612 | */ |
| 7613 | int mStarts; |
| 7614 | |
| 7615 | /** |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 7616 | * Number of times the process has crashed. |
| 7617 | */ |
| 7618 | int mNumCrashes; |
| 7619 | |
| 7620 | /** |
| 7621 | * Number of times the process has had an ANR. |
| 7622 | */ |
| 7623 | int mNumAnrs; |
| 7624 | |
| 7625 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7626 | * The amount of user time loaded from a previous save. |
| 7627 | */ |
| 7628 | long mLoadedUserTime; |
| 7629 | |
| 7630 | /** |
| 7631 | * The amount of system time loaded from a previous save. |
| 7632 | */ |
| 7633 | long mLoadedSystemTime; |
| 7634 | |
| 7635 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 7636 | * The amount of foreground time loaded from a previous save. |
| 7637 | */ |
| 7638 | long mLoadedForegroundTime; |
| 7639 | |
| 7640 | /** |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 7641 | * The number of times the process has started from a previous save. |
| 7642 | */ |
| 7643 | int mLoadedStarts; |
| 7644 | |
| 7645 | /** |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 7646 | * 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] | 7647 | */ |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 7648 | int mLoadedNumCrashes; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7649 | |
| 7650 | /** |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 7651 | * 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] | 7652 | */ |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 7653 | int mLoadedNumAnrs; |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 7654 | |
| 7655 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7656 | * The amount of user time when last unplugged. |
| 7657 | */ |
| 7658 | long mUnpluggedUserTime; |
| 7659 | |
| 7660 | /** |
| 7661 | * The amount of system time when last unplugged. |
| 7662 | */ |
| 7663 | long mUnpluggedSystemTime; |
| 7664 | |
| 7665 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 7666 | * The amount of foreground time since unplugged. |
| 7667 | */ |
| 7668 | long mUnpluggedForegroundTime; |
| 7669 | |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 7670 | /** |
| 7671 | * The number of times the process has started before unplugged. |
| 7672 | */ |
| 7673 | int mUnpluggedStarts; |
| 7674 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 7675 | /** |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 7676 | * Number of times the process has crashed before unplugged. |
| 7677 | */ |
| 7678 | int mUnpluggedNumCrashes; |
| 7679 | |
| 7680 | /** |
| 7681 | * Number of times the process has had an ANR before unplugged. |
| 7682 | */ |
| 7683 | int mUnpluggedNumAnrs; |
| 7684 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 7685 | ArrayList<ExcessivePower> mExcessivePower; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 7686 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7687 | public Proc(BatteryStatsImpl bsi, String name) { |
| 7688 | mBsi = bsi; |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 7689 | mName = name; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7690 | mBsi.mOnBatteryTimeBase.add(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7691 | } |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 7692 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7693 | public void onTimeStarted(long elapsedRealtime, long baseUptime, long baseRealtime) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7694 | mUnpluggedUserTime = mUserTime; |
| 7695 | mUnpluggedSystemTime = mSystemTime; |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 7696 | mUnpluggedForegroundTime = mForegroundTime; |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 7697 | mUnpluggedStarts = mStarts; |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 7698 | mUnpluggedNumCrashes = mNumCrashes; |
| 7699 | mUnpluggedNumAnrs = mNumAnrs; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7700 | } |
| 7701 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7702 | public void onTimeStopped(long elapsedRealtime, long baseUptime, long baseRealtime) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7703 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7704 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7705 | void detach() { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 7706 | mActive = false; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7707 | mBsi.mOnBatteryTimeBase.remove(this); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7708 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7709 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 7710 | public int countExcessivePowers() { |
| 7711 | return mExcessivePower != null ? mExcessivePower.size() : 0; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 7712 | } |
| 7713 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 7714 | public ExcessivePower getExcessivePower(int i) { |
| 7715 | if (mExcessivePower != null) { |
| 7716 | return mExcessivePower.get(i); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 7717 | } |
| 7718 | return null; |
| 7719 | } |
| 7720 | |
| 7721 | public void addExcessiveWake(long overTime, long usedTime) { |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 7722 | if (mExcessivePower == null) { |
| 7723 | mExcessivePower = new ArrayList<ExcessivePower>(); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 7724 | } |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 7725 | ExcessivePower ew = new ExcessivePower(); |
| 7726 | ew.type = ExcessivePower.TYPE_WAKE; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 7727 | ew.overTime = overTime; |
| 7728 | ew.usedTime = usedTime; |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 7729 | mExcessivePower.add(ew); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 7730 | } |
| 7731 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 7732 | public void addExcessiveCpu(long overTime, long usedTime) { |
| 7733 | if (mExcessivePower == null) { |
| 7734 | mExcessivePower = new ArrayList<ExcessivePower>(); |
| 7735 | } |
| 7736 | ExcessivePower ew = new ExcessivePower(); |
| 7737 | ew.type = ExcessivePower.TYPE_CPU; |
| 7738 | ew.overTime = overTime; |
| 7739 | ew.usedTime = usedTime; |
| 7740 | mExcessivePower.add(ew); |
| 7741 | } |
| 7742 | |
| 7743 | void writeExcessivePowerToParcelLocked(Parcel out) { |
| 7744 | if (mExcessivePower == null) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 7745 | out.writeInt(0); |
| 7746 | return; |
| 7747 | } |
| 7748 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 7749 | final int N = mExcessivePower.size(); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 7750 | out.writeInt(N); |
| 7751 | for (int i=0; i<N; i++) { |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 7752 | ExcessivePower ew = mExcessivePower.get(i); |
| 7753 | out.writeInt(ew.type); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 7754 | out.writeLong(ew.overTime); |
| 7755 | out.writeLong(ew.usedTime); |
| 7756 | } |
| 7757 | } |
| 7758 | |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 7759 | void readExcessivePowerFromParcelLocked(Parcel in) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 7760 | final int N = in.readInt(); |
| 7761 | if (N == 0) { |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 7762 | mExcessivePower = null; |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 7763 | return; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 7764 | } |
| 7765 | |
Dianne Hackborn | 7b9c56f | 2010-12-07 11:14:53 -0800 | [diff] [blame] | 7766 | if (N > 10000) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 7767 | throw new ParcelFormatException( |
| 7768 | "File corrupt: too many excessive power entries " + N); |
Dianne Hackborn | 7b9c56f | 2010-12-07 11:14:53 -0800 | [diff] [blame] | 7769 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 7770 | |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 7771 | mExcessivePower = new ArrayList<>(); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 7772 | for (int i=0; i<N; i++) { |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 7773 | ExcessivePower ew = new ExcessivePower(); |
| 7774 | ew.type = in.readInt(); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 7775 | ew.overTime = in.readLong(); |
| 7776 | ew.usedTime = in.readLong(); |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 7777 | mExcessivePower.add(ew); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 7778 | } |
| 7779 | } |
| 7780 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7781 | void writeToParcelLocked(Parcel out) { |
| 7782 | out.writeLong(mUserTime); |
| 7783 | out.writeLong(mSystemTime); |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 7784 | out.writeLong(mForegroundTime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7785 | out.writeInt(mStarts); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 7786 | out.writeInt(mNumCrashes); |
| 7787 | out.writeInt(mNumAnrs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7788 | out.writeLong(mLoadedUserTime); |
| 7789 | out.writeLong(mLoadedSystemTime); |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 7790 | out.writeLong(mLoadedForegroundTime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7791 | out.writeInt(mLoadedStarts); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 7792 | out.writeInt(mLoadedNumCrashes); |
| 7793 | out.writeInt(mLoadedNumAnrs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7794 | out.writeLong(mUnpluggedUserTime); |
| 7795 | out.writeLong(mUnpluggedSystemTime); |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 7796 | out.writeLong(mUnpluggedForegroundTime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7797 | out.writeInt(mUnpluggedStarts); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 7798 | out.writeInt(mUnpluggedNumCrashes); |
| 7799 | out.writeInt(mUnpluggedNumAnrs); |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 7800 | writeExcessivePowerToParcelLocked(out); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7801 | } |
| 7802 | |
| 7803 | void readFromParcelLocked(Parcel in) { |
| 7804 | mUserTime = in.readLong(); |
| 7805 | mSystemTime = in.readLong(); |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 7806 | mForegroundTime = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7807 | mStarts = in.readInt(); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 7808 | mNumCrashes = in.readInt(); |
| 7809 | mNumAnrs = in.readInt(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7810 | mLoadedUserTime = in.readLong(); |
| 7811 | mLoadedSystemTime = in.readLong(); |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 7812 | mLoadedForegroundTime = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7813 | mLoadedStarts = in.readInt(); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 7814 | mLoadedNumCrashes = in.readInt(); |
| 7815 | mLoadedNumAnrs = in.readInt(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7816 | mUnpluggedUserTime = in.readLong(); |
| 7817 | mUnpluggedSystemTime = in.readLong(); |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 7818 | mUnpluggedForegroundTime = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7819 | mUnpluggedStarts = in.readInt(); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 7820 | mUnpluggedNumCrashes = in.readInt(); |
| 7821 | mUnpluggedNumAnrs = in.readInt(); |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 7822 | readExcessivePowerFromParcelLocked(in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7823 | } |
| 7824 | |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 7825 | public void addCpuTimeLocked(int utime, int stime) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7826 | mUserTime += utime; |
| 7827 | mSystemTime += stime; |
| 7828 | } |
| 7829 | |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 7830 | public void addForegroundTimeLocked(long ttime) { |
| 7831 | mForegroundTime += ttime; |
| 7832 | } |
| 7833 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7834 | public void incStartsLocked() { |
| 7835 | mStarts++; |
| 7836 | } |
| 7837 | |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 7838 | public void incNumCrashesLocked() { |
| 7839 | mNumCrashes++; |
| 7840 | } |
| 7841 | |
| 7842 | public void incNumAnrsLocked() { |
| 7843 | mNumAnrs++; |
| 7844 | } |
| 7845 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7846 | @Override |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 7847 | public boolean isActive() { |
| 7848 | return mActive; |
| 7849 | } |
| 7850 | |
| 7851 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7852 | public long getUserTime(int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 7853 | long val = mUserTime; |
| 7854 | if (which == STATS_CURRENT) { |
| 7855 | val -= mLoadedUserTime; |
| 7856 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 7857 | val -= mUnpluggedUserTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7858 | } |
| 7859 | return val; |
| 7860 | } |
| 7861 | |
| 7862 | @Override |
| 7863 | public long getSystemTime(int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 7864 | long val = mSystemTime; |
| 7865 | if (which == STATS_CURRENT) { |
| 7866 | val -= mLoadedSystemTime; |
| 7867 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 7868 | val -= mUnpluggedSystemTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7869 | } |
| 7870 | return val; |
| 7871 | } |
| 7872 | |
| 7873 | @Override |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 7874 | public long getForegroundTime(int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 7875 | long val = mForegroundTime; |
| 7876 | if (which == STATS_CURRENT) { |
| 7877 | val -= mLoadedForegroundTime; |
| 7878 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 7879 | val -= mUnpluggedForegroundTime; |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 7880 | } |
| 7881 | return val; |
| 7882 | } |
| 7883 | |
| 7884 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7885 | public int getStarts(int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 7886 | int val = mStarts; |
| 7887 | if (which == STATS_CURRENT) { |
| 7888 | val -= mLoadedStarts; |
| 7889 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 7890 | val -= mUnpluggedStarts; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7891 | } |
| 7892 | return val; |
| 7893 | } |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 7894 | |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 7895 | @Override |
| 7896 | public int getNumCrashes(int which) { |
| 7897 | int val = mNumCrashes; |
| 7898 | if (which == STATS_CURRENT) { |
| 7899 | val -= mLoadedNumCrashes; |
| 7900 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 7901 | val -= mUnpluggedNumCrashes; |
| 7902 | } |
| 7903 | return val; |
| 7904 | } |
| 7905 | |
| 7906 | @Override |
| 7907 | public int getNumAnrs(int which) { |
| 7908 | int val = mNumAnrs; |
| 7909 | if (which == STATS_CURRENT) { |
| 7910 | val -= mLoadedNumAnrs; |
| 7911 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 7912 | val -= mUnpluggedNumAnrs; |
| 7913 | } |
| 7914 | return val; |
| 7915 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7916 | } |
| 7917 | |
| 7918 | /** |
| 7919 | * The statistics associated with a particular package. |
| 7920 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7921 | public static class Pkg extends BatteryStats.Uid.Pkg implements TimeBaseObs { |
| 7922 | /** |
| 7923 | * BatteryStatsImpl that we are associated with. |
| 7924 | */ |
| 7925 | protected BatteryStatsImpl mBsi; |
| 7926 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7927 | /** |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 7928 | * 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] | 7929 | */ |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 7930 | ArrayMap<String, Counter> mWakeupAlarms = new ArrayMap<>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7931 | |
| 7932 | /** |
| 7933 | * The statics we have collected for this package's services. |
| 7934 | */ |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 7935 | final ArrayMap<String, Serv> mServiceStats = new ArrayMap<>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7936 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7937 | public Pkg(BatteryStatsImpl bsi) { |
| 7938 | mBsi = bsi; |
| 7939 | mBsi.mOnBatteryScreenOffTimeBase.add(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7940 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7941 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7942 | public void onTimeStarted(long elapsedRealtime, long baseUptime, long baseRealtime) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7943 | } |
| 7944 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7945 | public void onTimeStopped(long elapsedRealtime, long baseUptime, long baseRealtime) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7946 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7947 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7948 | void detach() { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7949 | mBsi.mOnBatteryScreenOffTimeBase.remove(this); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7950 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7951 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7952 | void readFromParcelLocked(Parcel in) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 7953 | int numWA = in.readInt(); |
| 7954 | mWakeupAlarms.clear(); |
| 7955 | for (int i=0; i<numWA; i++) { |
| 7956 | String tag = in.readString(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7957 | mWakeupAlarms.put(tag, new Counter(mBsi.mOnBatteryTimeBase, in)); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 7958 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7959 | |
| 7960 | int numServs = in.readInt(); |
| 7961 | mServiceStats.clear(); |
| 7962 | for (int m = 0; m < numServs; m++) { |
| 7963 | String serviceName = in.readString(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7964 | Uid.Pkg.Serv serv = new Serv(mBsi); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7965 | mServiceStats.put(serviceName, serv); |
| 7966 | |
| 7967 | serv.readFromParcelLocked(in); |
| 7968 | } |
| 7969 | } |
| 7970 | |
| 7971 | void writeToParcelLocked(Parcel out) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 7972 | int numWA = mWakeupAlarms.size(); |
| 7973 | out.writeInt(numWA); |
| 7974 | for (int i=0; i<numWA; i++) { |
| 7975 | out.writeString(mWakeupAlarms.keyAt(i)); |
| 7976 | mWakeupAlarms.valueAt(i).writeToParcel(out); |
| 7977 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7978 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 7979 | final int NS = mServiceStats.size(); |
| 7980 | out.writeInt(NS); |
| 7981 | for (int i=0; i<NS; i++) { |
| 7982 | out.writeString(mServiceStats.keyAt(i)); |
| 7983 | Uid.Pkg.Serv serv = mServiceStats.valueAt(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7984 | serv.writeToParcelLocked(out); |
| 7985 | } |
| 7986 | } |
| 7987 | |
| 7988 | @Override |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 7989 | public ArrayMap<String, ? extends BatteryStats.Counter> getWakeupAlarmStats() { |
| 7990 | return mWakeupAlarms; |
| 7991 | } |
| 7992 | |
| 7993 | public void noteWakeupAlarmLocked(String tag) { |
| 7994 | Counter c = mWakeupAlarms.get(tag); |
| 7995 | if (c == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7996 | c = new Counter(mBsi.mOnBatteryTimeBase); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 7997 | mWakeupAlarms.put(tag, c); |
| 7998 | } |
| 7999 | c.stepAtomic(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8000 | } |
| 8001 | |
| 8002 | @Override |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 8003 | public ArrayMap<String, ? extends BatteryStats.Uid.Pkg.Serv> getServiceStats() { |
| 8004 | return mServiceStats; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8005 | } |
| 8006 | |
| 8007 | /** |
| 8008 | * The statistics associated with a particular service. |
| 8009 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8010 | public static class Serv extends BatteryStats.Uid.Pkg.Serv implements TimeBaseObs { |
| 8011 | /** |
| 8012 | * BatteryStatsImpl that we are associated with. |
| 8013 | */ |
| 8014 | protected BatteryStatsImpl mBsi; |
| 8015 | |
| 8016 | /** |
| 8017 | * The android package in which this service resides. |
| 8018 | */ |
| 8019 | protected Pkg mPkg; |
| 8020 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8021 | /** |
| 8022 | * Total time (ms in battery uptime) the service has been left started. |
| 8023 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8024 | protected long mStartTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8025 | |
| 8026 | /** |
| 8027 | * If service has been started and not yet stopped, this is |
| 8028 | * when it was started. |
| 8029 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8030 | protected long mRunningSince; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8031 | |
| 8032 | /** |
| 8033 | * True if we are currently running. |
| 8034 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8035 | protected boolean mRunning; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8036 | |
| 8037 | /** |
| 8038 | * Total number of times startService() has been called. |
| 8039 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8040 | protected int mStarts; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8041 | |
| 8042 | /** |
| 8043 | * Total time (ms in battery uptime) the service has been left launched. |
| 8044 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8045 | protected long mLaunchedTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8046 | |
| 8047 | /** |
| 8048 | * If service has been launched and not yet exited, this is |
| 8049 | * when it was launched (ms in battery uptime). |
| 8050 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8051 | protected long mLaunchedSince; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8052 | |
| 8053 | /** |
| 8054 | * True if we are currently launched. |
| 8055 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8056 | protected boolean mLaunched; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8057 | |
| 8058 | /** |
| 8059 | * Total number times the service has been launched. |
| 8060 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8061 | protected int mLaunches; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8062 | |
| 8063 | /** |
| 8064 | * The amount of time spent started loaded from a previous save |
| 8065 | * (ms in battery uptime). |
| 8066 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8067 | protected long mLoadedStartTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8068 | |
| 8069 | /** |
| 8070 | * The number of starts loaded from a previous save. |
| 8071 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8072 | protected int mLoadedStarts; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8073 | |
| 8074 | /** |
| 8075 | * The number of launches loaded from a previous save. |
| 8076 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8077 | protected int mLoadedLaunches; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8078 | |
| 8079 | /** |
| 8080 | * The amount of time spent started as of the last run (ms |
| 8081 | * in battery uptime). |
| 8082 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8083 | protected long mLastStartTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8084 | |
| 8085 | /** |
| 8086 | * The number of starts as of the last run. |
| 8087 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8088 | protected int mLastStarts; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8089 | |
| 8090 | /** |
| 8091 | * The number of launches as of the last run. |
| 8092 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8093 | protected int mLastLaunches; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8094 | |
| 8095 | /** |
| 8096 | * The amount of time spent started when last unplugged (ms |
| 8097 | * in battery uptime). |
| 8098 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8099 | protected long mUnpluggedStartTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8100 | |
| 8101 | /** |
| 8102 | * The number of starts when last unplugged. |
| 8103 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8104 | protected int mUnpluggedStarts; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8105 | |
| 8106 | /** |
| 8107 | * The number of launches when last unplugged. |
| 8108 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8109 | protected int mUnpluggedLaunches; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8110 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8111 | /** |
| 8112 | * Construct a Serv. Also adds it to the on-battery time base as a listener. |
| 8113 | */ |
| 8114 | public Serv(BatteryStatsImpl bsi) { |
| 8115 | mBsi = bsi; |
| 8116 | mBsi.mOnBatteryTimeBase.add(this); |
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 | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8119 | public void onTimeStarted(long elapsedRealtime, long baseUptime, |
| 8120 | long baseRealtime) { |
| 8121 | mUnpluggedStartTime = getStartTimeToNowLocked(baseUptime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8122 | mUnpluggedStarts = mStarts; |
| 8123 | mUnpluggedLaunches = mLaunches; |
| 8124 | } |
| 8125 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8126 | public void onTimeStopped(long elapsedRealtime, long baseUptime, |
| 8127 | long baseRealtime) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8128 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 8129 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8130 | /** |
| 8131 | * Remove this Serv as a listener from the time base. |
| 8132 | */ |
| 8133 | public void detach() { |
| 8134 | mBsi.mOnBatteryTimeBase.remove(this); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8135 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 8136 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8137 | public void readFromParcelLocked(Parcel in) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8138 | mStartTime = in.readLong(); |
| 8139 | mRunningSince = in.readLong(); |
| 8140 | mRunning = in.readInt() != 0; |
| 8141 | mStarts = in.readInt(); |
| 8142 | mLaunchedTime = in.readLong(); |
| 8143 | mLaunchedSince = in.readLong(); |
| 8144 | mLaunched = in.readInt() != 0; |
| 8145 | mLaunches = in.readInt(); |
| 8146 | mLoadedStartTime = in.readLong(); |
| 8147 | mLoadedStarts = in.readInt(); |
| 8148 | mLoadedLaunches = in.readInt(); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 8149 | mLastStartTime = 0; |
| 8150 | mLastStarts = 0; |
| 8151 | mLastLaunches = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8152 | mUnpluggedStartTime = in.readLong(); |
| 8153 | mUnpluggedStarts = in.readInt(); |
| 8154 | mUnpluggedLaunches = in.readInt(); |
| 8155 | } |
| 8156 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8157 | public void writeToParcelLocked(Parcel out) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8158 | out.writeLong(mStartTime); |
| 8159 | out.writeLong(mRunningSince); |
| 8160 | out.writeInt(mRunning ? 1 : 0); |
| 8161 | out.writeInt(mStarts); |
| 8162 | out.writeLong(mLaunchedTime); |
| 8163 | out.writeLong(mLaunchedSince); |
| 8164 | out.writeInt(mLaunched ? 1 : 0); |
| 8165 | out.writeInt(mLaunches); |
| 8166 | out.writeLong(mLoadedStartTime); |
| 8167 | out.writeInt(mLoadedStarts); |
| 8168 | out.writeInt(mLoadedLaunches); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8169 | out.writeLong(mUnpluggedStartTime); |
| 8170 | out.writeInt(mUnpluggedStarts); |
| 8171 | out.writeInt(mUnpluggedLaunches); |
| 8172 | } |
| 8173 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8174 | public long getLaunchTimeToNowLocked(long batteryUptime) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8175 | if (!mLaunched) return mLaunchedTime; |
| 8176 | return mLaunchedTime + batteryUptime - mLaunchedSince; |
| 8177 | } |
| 8178 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8179 | public long getStartTimeToNowLocked(long batteryUptime) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8180 | if (!mRunning) return mStartTime; |
| 8181 | return mStartTime + batteryUptime - mRunningSince; |
| 8182 | } |
| 8183 | |
| 8184 | public void startLaunchedLocked() { |
| 8185 | if (!mLaunched) { |
| 8186 | mLaunches++; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8187 | mLaunchedSince = mBsi.getBatteryUptimeLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8188 | mLaunched = true; |
| 8189 | } |
| 8190 | } |
| 8191 | |
| 8192 | public void stopLaunchedLocked() { |
| 8193 | if (mLaunched) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8194 | long time = mBsi.getBatteryUptimeLocked() - mLaunchedSince; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8195 | if (time > 0) { |
| 8196 | mLaunchedTime += time; |
| 8197 | } else { |
| 8198 | mLaunches--; |
| 8199 | } |
| 8200 | mLaunched = false; |
| 8201 | } |
| 8202 | } |
| 8203 | |
| 8204 | public void startRunningLocked() { |
| 8205 | if (!mRunning) { |
| 8206 | mStarts++; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8207 | mRunningSince = mBsi.getBatteryUptimeLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8208 | mRunning = true; |
| 8209 | } |
| 8210 | } |
| 8211 | |
| 8212 | public void stopRunningLocked() { |
| 8213 | if (mRunning) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8214 | long time = mBsi.getBatteryUptimeLocked() - mRunningSince; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8215 | if (time > 0) { |
| 8216 | mStartTime += time; |
| 8217 | } else { |
| 8218 | mStarts--; |
| 8219 | } |
| 8220 | mRunning = false; |
| 8221 | } |
| 8222 | } |
| 8223 | |
| 8224 | public BatteryStatsImpl getBatteryStats() { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8225 | return mBsi; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8226 | } |
| 8227 | |
| 8228 | @Override |
| 8229 | public int getLaunches(int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 8230 | int val = mLaunches; |
| 8231 | if (which == STATS_CURRENT) { |
| 8232 | val -= mLoadedLaunches; |
| 8233 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 8234 | val -= mUnpluggedLaunches; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8235 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8236 | return val; |
| 8237 | } |
| 8238 | |
| 8239 | @Override |
| 8240 | public long getStartTime(long now, int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 8241 | long val = getStartTimeToNowLocked(now); |
| 8242 | if (which == STATS_CURRENT) { |
| 8243 | val -= mLoadedStartTime; |
| 8244 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 8245 | val -= mUnpluggedStartTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8246 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8247 | return val; |
| 8248 | } |
| 8249 | |
| 8250 | @Override |
| 8251 | public int getStarts(int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 8252 | int val = mStarts; |
| 8253 | if (which == STATS_CURRENT) { |
| 8254 | val -= mLoadedStarts; |
| 8255 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 8256 | val -= mUnpluggedStarts; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8257 | } |
| 8258 | |
| 8259 | return val; |
| 8260 | } |
| 8261 | } |
| 8262 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8263 | final Serv newServiceStatsLocked() { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8264 | return new Serv(mBsi); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8265 | } |
| 8266 | } |
| 8267 | |
| 8268 | /** |
| 8269 | * Retrieve the statistics object for a particular process, creating |
| 8270 | * if needed. |
| 8271 | */ |
| 8272 | public Proc getProcessStatsLocked(String name) { |
| 8273 | Proc ps = mProcessStats.get(name); |
| 8274 | if (ps == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8275 | ps = new Proc(mBsi, name); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8276 | mProcessStats.put(name, ps); |
| 8277 | } |
| 8278 | |
| 8279 | return ps; |
| 8280 | } |
| 8281 | |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 8282 | public void updateUidProcessStateLocked(int procState) { |
| 8283 | int uidRunningState; |
| 8284 | if (procState == ActivityManager.PROCESS_STATE_NONEXISTENT) { |
| 8285 | uidRunningState = ActivityManager.PROCESS_STATE_NONEXISTENT; |
| 8286 | } else if (procState == ActivityManager.PROCESS_STATE_TOP) { |
| 8287 | uidRunningState = PROCESS_STATE_TOP; |
| 8288 | } else if (procState <= ActivityManager.PROCESS_STATE_FOREGROUND_SERVICE) { |
| 8289 | // Persistent and other foreground states go here. |
| 8290 | uidRunningState = PROCESS_STATE_FOREGROUND_SERVICE; |
| 8291 | } else if (procState <= ActivityManager.PROCESS_STATE_TOP_SLEEPING) { |
| 8292 | uidRunningState = PROCESS_STATE_TOP_SLEEPING; |
| 8293 | } else if (procState <= ActivityManager.PROCESS_STATE_IMPORTANT_FOREGROUND) { |
| 8294 | // Persistent and other foreground states go here. |
| 8295 | uidRunningState = PROCESS_STATE_FOREGROUND; |
| 8296 | } else if (procState <= ActivityManager.PROCESS_STATE_RECEIVER) { |
| 8297 | uidRunningState = PROCESS_STATE_BACKGROUND; |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 8298 | } else { |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 8299 | uidRunningState = PROCESS_STATE_CACHED; |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 8300 | } |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 8301 | |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 8302 | if (mProcessState == uidRunningState) return; |
| 8303 | |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 8304 | final long elapsedRealtimeMs = mBsi.mClocks.elapsedRealtime(); |
| 8305 | final long uptimeMs = mBsi.mClocks.uptimeMillis(); |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 8306 | |
| 8307 | if (mProcessState != ActivityManager.PROCESS_STATE_NONEXISTENT) { |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 8308 | mProcessStateTimer[mProcessState].stopRunningLocked(elapsedRealtimeMs); |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 8309 | } |
| 8310 | mProcessState = uidRunningState; |
| 8311 | if (uidRunningState != ActivityManager.PROCESS_STATE_NONEXISTENT) { |
| 8312 | if (mProcessStateTimer[uidRunningState] == null) { |
| 8313 | makeProcessState(uidRunningState, null); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 8314 | } |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 8315 | mProcessStateTimer[uidRunningState].startRunningLocked(elapsedRealtimeMs); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 8316 | } |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 8317 | |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 8318 | updateOnBatteryBgTimeBase(uptimeMs * 1000, elapsedRealtimeMs * 1000); |
| 8319 | updateOnBatteryScreenOffBgTimeBase(uptimeMs * 1000, elapsedRealtimeMs * 1000); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 8320 | } |
| 8321 | |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 8322 | /** Whether to consider Uid to be in the background for background timebase purposes. */ |
| 8323 | public boolean isInBackground() { |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 8324 | // Note that PROCESS_STATE_CACHED and ActivityManager.PROCESS_STATE_NONEXISTENT is |
| 8325 | // also considered to be 'background' for our purposes, because it's not foreground. |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 8326 | return mProcessState >= PROCESS_STATE_BACKGROUND; |
| 8327 | } |
| 8328 | |
| 8329 | public boolean updateOnBatteryBgTimeBase(long uptimeUs, long realtimeUs) { |
| 8330 | boolean on = mBsi.mOnBatteryTimeBase.isRunning() && isInBackground(); |
| 8331 | return mOnBatteryBackgroundTimeBase.setRunning(on, uptimeUs, realtimeUs); |
| 8332 | } |
| 8333 | |
| 8334 | public boolean updateOnBatteryScreenOffBgTimeBase(long uptimeUs, long realtimeUs) { |
| 8335 | boolean on = mBsi.mOnBatteryScreenOffTimeBase.isRunning() && isInBackground(); |
| 8336 | return mOnBatteryScreenOffBackgroundTimeBase.setRunning(on, uptimeUs, realtimeUs); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 8337 | } |
| 8338 | |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 8339 | public SparseArray<? extends Pid> getPidStats() { |
| 8340 | return mPids; |
| 8341 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 8342 | |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 8343 | public Pid getPidStatsLocked(int pid) { |
| 8344 | Pid p = mPids.get(pid); |
| 8345 | if (p == null) { |
| 8346 | p = new Pid(); |
| 8347 | mPids.put(pid, p); |
| 8348 | } |
| 8349 | return p; |
| 8350 | } |
| 8351 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8352 | /** |
| 8353 | * Retrieve the statistics object for a particular service, creating |
| 8354 | * if needed. |
| 8355 | */ |
| 8356 | public Pkg getPackageStatsLocked(String name) { |
| 8357 | Pkg ps = mPackageStats.get(name); |
| 8358 | if (ps == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8359 | ps = new Pkg(mBsi); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8360 | mPackageStats.put(name, ps); |
| 8361 | } |
| 8362 | |
| 8363 | return ps; |
| 8364 | } |
| 8365 | |
| 8366 | /** |
| 8367 | * Retrieve the statistics object for a particular service, creating |
| 8368 | * if needed. |
| 8369 | */ |
| 8370 | public Pkg.Serv getServiceStatsLocked(String pkg, String serv) { |
| 8371 | Pkg ps = getPackageStatsLocked(pkg); |
| 8372 | Pkg.Serv ss = ps.mServiceStats.get(serv); |
| 8373 | if (ss == null) { |
| 8374 | ss = ps.newServiceStatsLocked(); |
| 8375 | ps.mServiceStats.put(serv, ss); |
| 8376 | } |
| 8377 | |
| 8378 | return ss; |
| 8379 | } |
| 8380 | |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 8381 | public void readSyncSummaryFromParcelLocked(String name, Parcel in) { |
Bookatz | 2bffb5b | 2017-04-13 11:59:33 -0700 | [diff] [blame] | 8382 | DualTimer timer = mSyncStats.instantiateObject(); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 8383 | timer.readSummaryFromParcelLocked(in); |
| 8384 | mSyncStats.add(name, timer); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 8385 | } |
| 8386 | |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 8387 | public void readJobSummaryFromParcelLocked(String name, Parcel in) { |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 8388 | DualTimer timer = mJobStats.instantiateObject(); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 8389 | timer.readSummaryFromParcelLocked(in); |
| 8390 | mJobStats.add(name, timer); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 8391 | } |
| 8392 | |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 8393 | public void readWakeSummaryFromParcelLocked(String wlName, Parcel in) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8394 | Wakelock wl = new Wakelock(mBsi, this); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 8395 | mWakelockStats.add(wlName, wl); |
| 8396 | if (in.readInt() != 0) { |
Bookatz | 5b5ec32 | 2017-05-26 09:40:38 -0700 | [diff] [blame] | 8397 | getWakelockTimerLocked(wl, WAKE_TYPE_FULL).readSummaryFromParcelLocked(in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8398 | } |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 8399 | if (in.readInt() != 0) { |
Bookatz | 5b5ec32 | 2017-05-26 09:40:38 -0700 | [diff] [blame] | 8400 | getWakelockTimerLocked(wl, WAKE_TYPE_PARTIAL).readSummaryFromParcelLocked(in); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 8401 | } |
| 8402 | if (in.readInt() != 0) { |
Bookatz | 5b5ec32 | 2017-05-26 09:40:38 -0700 | [diff] [blame] | 8403 | getWakelockTimerLocked(wl, WAKE_TYPE_WINDOW).readSummaryFromParcelLocked(in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8404 | } |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 8405 | if (in.readInt() != 0) { |
Bookatz | 5b5ec32 | 2017-05-26 09:40:38 -0700 | [diff] [blame] | 8406 | getWakelockTimerLocked(wl, WAKE_TYPE_DRAW).readSummaryFromParcelLocked(in); |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 8407 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8408 | } |
| 8409 | |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 8410 | public DualTimer getSensorTimerLocked(int sensor, boolean create) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8411 | Sensor se = mSensorStats.get(sensor); |
| 8412 | if (se == null) { |
| 8413 | if (!create) { |
| 8414 | return null; |
| 8415 | } |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8416 | se = new Sensor(mBsi, this, sensor); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8417 | mSensorStats.put(sensor, se); |
| 8418 | } |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 8419 | DualTimer t = se.mTimer; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8420 | if (t != null) { |
| 8421 | return t; |
| 8422 | } |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8423 | ArrayList<StopwatchTimer> timers = mBsi.mSensorTimers.get(sensor); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8424 | if (timers == null) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 8425 | timers = new ArrayList<StopwatchTimer>(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8426 | mBsi.mSensorTimers.put(sensor, timers); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8427 | } |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 8428 | t = new DualTimer(mBsi.mClocks, this, BatteryStats.SENSOR, timers, |
| 8429 | mBsi.mOnBatteryTimeBase, mOnBatteryBackgroundTimeBase); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8430 | se.mTimer = t; |
| 8431 | return t; |
| 8432 | } |
| 8433 | |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 8434 | public void noteStartSyncLocked(String name, long elapsedRealtimeMs) { |
Bookatz | 2bffb5b | 2017-04-13 11:59:33 -0700 | [diff] [blame] | 8435 | DualTimer t = mSyncStats.startObject(name); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 8436 | if (t != null) { |
| 8437 | t.startRunningLocked(elapsedRealtimeMs); |
| 8438 | } |
| 8439 | } |
| 8440 | |
| 8441 | public void noteStopSyncLocked(String name, long elapsedRealtimeMs) { |
Bookatz | 2bffb5b | 2017-04-13 11:59:33 -0700 | [diff] [blame] | 8442 | DualTimer t = mSyncStats.stopObject(name); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 8443 | if (t != null) { |
| 8444 | t.stopRunningLocked(elapsedRealtimeMs); |
| 8445 | } |
| 8446 | } |
| 8447 | |
| 8448 | public void noteStartJobLocked(String name, long elapsedRealtimeMs) { |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 8449 | DualTimer t = mJobStats.startObject(name); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 8450 | if (t != null) { |
| 8451 | t.startRunningLocked(elapsedRealtimeMs); |
| 8452 | } |
| 8453 | } |
| 8454 | |
| 8455 | public void noteStopJobLocked(String name, long elapsedRealtimeMs) { |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 8456 | DualTimer t = mJobStats.stopObject(name); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 8457 | if (t != null) { |
| 8458 | t.stopRunningLocked(elapsedRealtimeMs); |
| 8459 | } |
| 8460 | } |
| 8461 | |
Bookatz | 5b5ec32 | 2017-05-26 09:40:38 -0700 | [diff] [blame] | 8462 | public StopwatchTimer getWakelockTimerLocked(Wakelock wl, int type) { |
| 8463 | if (wl == null) { |
| 8464 | return null; |
| 8465 | } |
| 8466 | switch (type) { |
| 8467 | case WAKE_TYPE_PARTIAL: { |
| 8468 | DualTimer t = wl.mTimerPartial; |
| 8469 | if (t == null) { |
| 8470 | t = new DualTimer(mBsi.mClocks, this, WAKE_TYPE_PARTIAL, |
| 8471 | mBsi.mPartialTimers, mBsi.mOnBatteryScreenOffTimeBase, |
| 8472 | mOnBatteryScreenOffBackgroundTimeBase); |
| 8473 | wl.mTimerPartial = t; |
| 8474 | } |
| 8475 | return t; |
| 8476 | } |
| 8477 | case WAKE_TYPE_FULL: { |
| 8478 | StopwatchTimer t = wl.mTimerFull; |
| 8479 | if (t == null) { |
| 8480 | t = new StopwatchTimer(mBsi.mClocks, this, WAKE_TYPE_FULL, |
| 8481 | mBsi.mFullTimers, mBsi.mOnBatteryTimeBase); |
| 8482 | wl.mTimerFull = t; |
| 8483 | } |
| 8484 | return t; |
| 8485 | } |
| 8486 | case WAKE_TYPE_WINDOW: { |
| 8487 | StopwatchTimer t = wl.mTimerWindow; |
| 8488 | if (t == null) { |
| 8489 | t = new StopwatchTimer(mBsi.mClocks, this, WAKE_TYPE_WINDOW, |
| 8490 | mBsi.mWindowTimers, mBsi.mOnBatteryTimeBase); |
| 8491 | wl.mTimerWindow = t; |
| 8492 | } |
| 8493 | return t; |
| 8494 | } |
| 8495 | case WAKE_TYPE_DRAW: { |
| 8496 | StopwatchTimer t = wl.mTimerDraw; |
| 8497 | if (t == null) { |
| 8498 | t = new StopwatchTimer(mBsi.mClocks, this, WAKE_TYPE_DRAW, |
| 8499 | mBsi.mDrawTimers, mBsi.mOnBatteryTimeBase); |
| 8500 | wl.mTimerDraw = t; |
| 8501 | } |
| 8502 | return t; |
| 8503 | } |
| 8504 | default: |
| 8505 | throw new IllegalArgumentException("type=" + type); |
| 8506 | } |
| 8507 | } |
| 8508 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8509 | public void noteStartWakeLocked(int pid, String name, int type, long elapsedRealtimeMs) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 8510 | Wakelock wl = mWakelockStats.startObject(name); |
| 8511 | if (wl != null) { |
Bookatz | 5b5ec32 | 2017-05-26 09:40:38 -0700 | [diff] [blame] | 8512 | getWakelockTimerLocked(wl, type).startRunningLocked(elapsedRealtimeMs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8513 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 8514 | if (type == WAKE_TYPE_PARTIAL) { |
| 8515 | createAggregatedPartialWakelockTimerLocked().startRunningLocked(elapsedRealtimeMs); |
| 8516 | if (pid >= 0) { |
| 8517 | Pid p = getPidStatsLocked(pid); |
| 8518 | if (p.mWakeNesting++ == 0) { |
| 8519 | p.mWakeStartMs = elapsedRealtimeMs; |
| 8520 | } |
Dianne Hackborn | b8071d79 | 2010-09-09 16:45:15 -0700 | [diff] [blame] | 8521 | } |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 8522 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8523 | } |
| 8524 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8525 | public void noteStopWakeLocked(int pid, String name, int type, long elapsedRealtimeMs) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 8526 | Wakelock wl = mWakelockStats.stopObject(name); |
| 8527 | if (wl != null) { |
Bookatz | 5b5ec32 | 2017-05-26 09:40:38 -0700 | [diff] [blame] | 8528 | getWakelockTimerLocked(wl, type).stopRunningLocked(elapsedRealtimeMs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8529 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 8530 | if (type == WAKE_TYPE_PARTIAL) { |
| 8531 | if (mAggregatedPartialWakelockTimer != null) { |
| 8532 | mAggregatedPartialWakelockTimer.stopRunningLocked(elapsedRealtimeMs); |
| 8533 | } |
| 8534 | if (pid >= 0) { |
| 8535 | Pid p = mPids.get(pid); |
| 8536 | if (p != null && p.mWakeNesting > 0) { |
| 8537 | if (p.mWakeNesting-- == 1) { |
| 8538 | p.mWakeSumMs += elapsedRealtimeMs - p.mWakeStartMs; |
| 8539 | p.mWakeStartMs = 0; |
| 8540 | } |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 8541 | } |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 8542 | } |
| 8543 | } |
| 8544 | } |
| 8545 | |
| 8546 | public void reportExcessiveWakeLocked(String proc, long overTime, long usedTime) { |
| 8547 | Proc p = getProcessStatsLocked(proc); |
| 8548 | if (p != null) { |
| 8549 | p.addExcessiveWake(overTime, usedTime); |
| 8550 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8551 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 8552 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 8553 | public void reportExcessiveCpuLocked(String proc, long overTime, long usedTime) { |
| 8554 | Proc p = getProcessStatsLocked(proc); |
| 8555 | if (p != null) { |
| 8556 | p.addExcessiveCpu(overTime, usedTime); |
| 8557 | } |
| 8558 | } |
| 8559 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8560 | public void noteStartSensor(int sensor, long elapsedRealtimeMs) { |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 8561 | DualTimer t = getSensorTimerLocked(sensor, /* create= */ true); |
Amith Yamasani | 154d124 | 2017-02-16 10:01:48 -0800 | [diff] [blame] | 8562 | t.startRunningLocked(elapsedRealtimeMs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8563 | } |
| 8564 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8565 | public void noteStopSensor(int sensor, long elapsedRealtimeMs) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8566 | // Don't create a timer if one doesn't already exist |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 8567 | DualTimer t = getSensorTimerLocked(sensor, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8568 | if (t != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8569 | t.stopRunningLocked(elapsedRealtimeMs); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 8570 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8571 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 8572 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8573 | public void noteStartGps(long elapsedRealtimeMs) { |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 8574 | noteStartSensor(Sensor.GPS, elapsedRealtimeMs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8575 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 8576 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8577 | public void noteStopGps(long elapsedRealtimeMs) { |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 8578 | noteStopSensor(Sensor.GPS, elapsedRealtimeMs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8579 | } |
| 8580 | |
| 8581 | public BatteryStatsImpl getBatteryStats() { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8582 | return mBsi; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8583 | } |
| 8584 | } |
| 8585 | |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 8586 | public long[] getCpuFreqs() { |
| 8587 | return mCpuFreqs; |
| 8588 | } |
| 8589 | |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8590 | public BatteryStatsImpl(File systemDir, Handler handler, ExternalStatsSync externalSync) { |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 8591 | this(new SystemClocks(), systemDir, handler, externalSync, null); |
| 8592 | } |
| 8593 | |
| 8594 | public BatteryStatsImpl(File systemDir, Handler handler, ExternalStatsSync externalSync, |
| 8595 | PlatformIdleStateCallback cb) { |
| 8596 | this(new SystemClocks(), systemDir, handler, externalSync, cb); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8597 | } |
| 8598 | |
| 8599 | public BatteryStatsImpl(Clocks clocks, File systemDir, Handler handler, |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 8600 | ExternalStatsSync externalSync, PlatformIdleStateCallback cb) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8601 | init(clocks); |
| 8602 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 8603 | if (systemDir != null) { |
| 8604 | mFile = new JournaledFile(new File(systemDir, "batterystats.bin"), |
| 8605 | new File(systemDir, "batterystats.bin.tmp")); |
| 8606 | } else { |
| 8607 | mFile = null; |
| 8608 | } |
| 8609 | mCheckinFile = new AtomicFile(new File(systemDir, "batterystats-checkin.bin")); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 8610 | mDailyFile = new AtomicFile(new File(systemDir, "batterystats-daily.xml")); |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8611 | mExternalSync = externalSync; |
Jeff Brown | 6f357d3 | 2014-01-15 20:40:55 -0800 | [diff] [blame] | 8612 | mHandler = new MyHandler(handler.getLooper()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8613 | mStartCount++; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8614 | mScreenOnTimer = new StopwatchTimer(mClocks, null, -1, null, mOnBatteryTimeBase); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 8615 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8616 | mScreenBrightnessTimer[i] = new StopwatchTimer(mClocks, null, -100-i, null, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8617 | mOnBatteryTimeBase); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 8618 | } |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8619 | mInteractiveTimer = new StopwatchTimer(mClocks, null, -10, null, mOnBatteryTimeBase); |
| 8620 | mPowerSaveModeEnabledTimer = new StopwatchTimer(mClocks, null, -2, null, |
| 8621 | mOnBatteryTimeBase); |
| 8622 | mDeviceIdleModeLightTimer = new StopwatchTimer(mClocks, null, -11, null, |
| 8623 | mOnBatteryTimeBase); |
| 8624 | mDeviceIdleModeFullTimer = new StopwatchTimer(mClocks, null, -14, null, mOnBatteryTimeBase); |
| 8625 | mDeviceLightIdlingTimer = new StopwatchTimer(mClocks, null, -15, null, mOnBatteryTimeBase); |
| 8626 | mDeviceIdlingTimer = new StopwatchTimer(mClocks, null, -12, null, mOnBatteryTimeBase); |
| 8627 | mPhoneOnTimer = new StopwatchTimer(mClocks, null, -3, null, mOnBatteryTimeBase); |
| 8628 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
| 8629 | mPhoneSignalStrengthsTimer[i] = new StopwatchTimer(mClocks, null, -200-i, null, |
| 8630 | mOnBatteryTimeBase); |
| 8631 | } |
| 8632 | mPhoneSignalScanningTimer = new StopwatchTimer(mClocks, null, -200+1, null, |
| 8633 | mOnBatteryTimeBase); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 8634 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8635 | mPhoneDataConnectionsTimer[i] = new StopwatchTimer(mClocks, null, -300-i, null, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8636 | mOnBatteryTimeBase); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 8637 | } |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 8638 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8639 | mNetworkByteActivityCounters[i] = new LongSamplingCounter(mOnBatteryTimeBase); |
| 8640 | mNetworkPacketActivityCounters[i] = new LongSamplingCounter(mOnBatteryTimeBase); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 8641 | } |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 8642 | mWifiActivity = new ControllerActivityCounterImpl(mOnBatteryTimeBase, NUM_WIFI_TX_LEVELS); |
| 8643 | mBluetoothActivity = new ControllerActivityCounterImpl(mOnBatteryTimeBase, |
| 8644 | NUM_BT_TX_LEVELS); |
| 8645 | mModemActivity = new ControllerActivityCounterImpl(mOnBatteryTimeBase, |
| 8646 | ModemActivityInfo.TX_POWER_LEVELS); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8647 | mMobileRadioActiveTimer = new StopwatchTimer(mClocks, null, -400, null, mOnBatteryTimeBase); |
| 8648 | mMobileRadioActivePerAppTimer = new StopwatchTimer(mClocks, null, -401, null, |
| 8649 | mOnBatteryTimeBase); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 8650 | mMobileRadioActiveAdjustedTime = new LongSamplingCounter(mOnBatteryTimeBase); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8651 | mMobileRadioActiveUnknownTime = new LongSamplingCounter(mOnBatteryTimeBase); |
| 8652 | mMobileRadioActiveUnknownCount = new LongSamplingCounter(mOnBatteryTimeBase); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8653 | mWifiOnTimer = new StopwatchTimer(mClocks, null, -4, null, mOnBatteryTimeBase); |
| 8654 | mGlobalWifiRunningTimer = new StopwatchTimer(mClocks, null, -5, null, mOnBatteryTimeBase); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 8655 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8656 | mWifiStateTimer[i] = new StopwatchTimer(mClocks, null, -600-i, null, |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 8657 | mOnBatteryTimeBase); |
| 8658 | } |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8659 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
| 8660 | mWifiSupplStateTimer[i] = new StopwatchTimer(mClocks, null, -700-i, null, |
| 8661 | mOnBatteryTimeBase); |
| 8662 | } |
| 8663 | for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 8664 | mWifiSignalStrengthsTimer[i] = new StopwatchTimer(mClocks, null, -800-i, null, |
| 8665 | mOnBatteryTimeBase); |
| 8666 | } |
| 8667 | mAudioOnTimer = new StopwatchTimer(mClocks, null, -7, null, mOnBatteryTimeBase); |
| 8668 | mVideoOnTimer = new StopwatchTimer(mClocks, null, -8, null, mOnBatteryTimeBase); |
| 8669 | mFlashlightOnTimer = new StopwatchTimer(mClocks, null, -9, null, mOnBatteryTimeBase); |
| 8670 | mCameraOnTimer = new StopwatchTimer(mClocks, null, -13, null, mOnBatteryTimeBase); |
| 8671 | mBluetoothScanTimer = new StopwatchTimer(mClocks, null, -14, null, mOnBatteryTimeBase); |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 8672 | mDischargeScreenOffCounter = new LongSamplingCounter(mOnBatteryScreenOffTimeBase); |
| 8673 | mDischargeCounter = new LongSamplingCounter(mOnBatteryTimeBase); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8674 | mOnBattery = mOnBatteryInternal = false; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8675 | long uptime = mClocks.uptimeMillis() * 1000; |
| 8676 | long realtime = mClocks.elapsedRealtime() * 1000; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8677 | initTimes(uptime, realtime); |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 8678 | mStartPlatformVersion = mEndPlatformVersion = Build.ID; |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 8679 | mDischargeStartLevel = 0; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8680 | mDischargeUnplugLevel = 0; |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 8681 | mDischargePlugLevel = -1; |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 8682 | mDischargeCurrentLevel = 0; |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 8683 | mCurrentBatteryLevel = 0; |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 8684 | initDischarge(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 8685 | clearHistoryLocked(); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 8686 | updateDailyDeadlineLocked(); |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 8687 | mPlatformIdleStateCallback = cb; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8688 | } |
| 8689 | |
| 8690 | public BatteryStatsImpl(Parcel p) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8691 | this(new SystemClocks(), p); |
| 8692 | } |
| 8693 | |
| 8694 | public BatteryStatsImpl(Clocks clocks, Parcel p) { |
| 8695 | init(clocks); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 8696 | mFile = null; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 8697 | mCheckinFile = null; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 8698 | mDailyFile = null; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 8699 | mHandler = null; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8700 | mExternalSync = null; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 8701 | clearHistoryLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8702 | readFromParcel(p); |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 8703 | mPlatformIdleStateCallback = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8704 | } |
| 8705 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 8706 | public void setPowerProfileLocked(PowerProfile profile) { |
| 8707 | mPowerProfile = profile; |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 8708 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 8709 | // We need to initialize the KernelCpuSpeedReaders to read from |
| 8710 | // the first cpu of each core. Once we have the PowerProfile, we have access to this |
| 8711 | // information. |
| 8712 | final int numClusters = mPowerProfile.getNumCpuClusters(); |
| 8713 | mKernelCpuSpeedReaders = new KernelCpuSpeedReader[numClusters]; |
| 8714 | int firstCpuOfCluster = 0; |
| 8715 | for (int i = 0; i < numClusters; i++) { |
| 8716 | final int numSpeedSteps = mPowerProfile.getNumSpeedStepsInCpuCluster(i); |
| 8717 | mKernelCpuSpeedReaders[i] = new KernelCpuSpeedReader(firstCpuOfCluster, |
| 8718 | numSpeedSteps); |
| 8719 | firstCpuOfCluster += mPowerProfile.getNumCoresInCpuCluster(i); |
| 8720 | } |
Adam Lesinski | f9b20a9 | 2016-06-17 17:30:01 -0700 | [diff] [blame] | 8721 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 8722 | if (mEstimatedBatteryCapacity == -1) { |
| 8723 | // Initialize the estimated battery capacity to a known preset one. |
| 8724 | mEstimatedBatteryCapacity = (int) mPowerProfile.getBatteryCapacity(); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 8725 | } |
| 8726 | } |
| 8727 | |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 8728 | public void setCallback(BatteryCallback cb) { |
| 8729 | mCallback = cb; |
| 8730 | } |
| 8731 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 8732 | public void setRadioScanningTimeoutLocked(long timeout) { |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 8733 | if (mPhoneSignalScanningTimer != null) { |
| 8734 | mPhoneSignalScanningTimer.setTimeout(timeout); |
| 8735 | } |
| 8736 | } |
| 8737 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 8738 | public void updateDailyDeadlineLocked() { |
| 8739 | // Get the current time. |
| 8740 | long currentTime = mDailyStartTime = System.currentTimeMillis(); |
| 8741 | Calendar calDeadline = Calendar.getInstance(); |
| 8742 | calDeadline.setTimeInMillis(currentTime); |
| 8743 | |
| 8744 | // Move time up to the next day, ranging from 1am to 3pm. |
| 8745 | calDeadline.set(Calendar.DAY_OF_YEAR, calDeadline.get(Calendar.DAY_OF_YEAR) + 1); |
| 8746 | calDeadline.set(Calendar.MILLISECOND, 0); |
| 8747 | calDeadline.set(Calendar.SECOND, 0); |
| 8748 | calDeadline.set(Calendar.MINUTE, 0); |
| 8749 | calDeadline.set(Calendar.HOUR_OF_DAY, 1); |
| 8750 | mNextMinDailyDeadline = calDeadline.getTimeInMillis(); |
| 8751 | calDeadline.set(Calendar.HOUR_OF_DAY, 3); |
| 8752 | mNextMaxDailyDeadline = calDeadline.getTimeInMillis(); |
| 8753 | } |
| 8754 | |
| 8755 | public void recordDailyStatsIfNeededLocked(boolean settled) { |
| 8756 | long currentTime = System.currentTimeMillis(); |
| 8757 | if (currentTime >= mNextMaxDailyDeadline) { |
| 8758 | recordDailyStatsLocked(); |
| 8759 | } else if (settled && currentTime >= mNextMinDailyDeadline) { |
| 8760 | recordDailyStatsLocked(); |
| 8761 | } else if (currentTime < (mDailyStartTime-(1000*60*60*24))) { |
| 8762 | recordDailyStatsLocked(); |
| 8763 | } |
| 8764 | } |
| 8765 | |
| 8766 | public void recordDailyStatsLocked() { |
| 8767 | DailyItem item = new DailyItem(); |
| 8768 | item.mStartTime = mDailyStartTime; |
| 8769 | item.mEndTime = System.currentTimeMillis(); |
| 8770 | boolean hasData = false; |
| 8771 | if (mDailyDischargeStepTracker.mNumStepDurations > 0) { |
| 8772 | hasData = true; |
| 8773 | item.mDischargeSteps = new LevelStepTracker( |
| 8774 | mDailyDischargeStepTracker.mNumStepDurations, |
| 8775 | mDailyDischargeStepTracker.mStepDurations); |
| 8776 | } |
| 8777 | if (mDailyChargeStepTracker.mNumStepDurations > 0) { |
| 8778 | hasData = true; |
| 8779 | item.mChargeSteps = new LevelStepTracker( |
| 8780 | mDailyChargeStepTracker.mNumStepDurations, |
| 8781 | mDailyChargeStepTracker.mStepDurations); |
| 8782 | } |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 8783 | if (mDailyPackageChanges != null) { |
| 8784 | hasData = true; |
| 8785 | item.mPackageChanges = mDailyPackageChanges; |
| 8786 | mDailyPackageChanges = null; |
| 8787 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 8788 | mDailyDischargeStepTracker.init(); |
| 8789 | mDailyChargeStepTracker.init(); |
| 8790 | updateDailyDeadlineLocked(); |
| 8791 | |
| 8792 | if (hasData) { |
| 8793 | mDailyItems.add(item); |
| 8794 | while (mDailyItems.size() > MAX_DAILY_ITEMS) { |
| 8795 | mDailyItems.remove(0); |
| 8796 | } |
| 8797 | final ByteArrayOutputStream memStream = new ByteArrayOutputStream(); |
| 8798 | try { |
| 8799 | XmlSerializer out = new FastXmlSerializer(); |
Wojciech Staszkiewicz | 9e9e2e7 | 2015-05-08 14:58:46 +0100 | [diff] [blame] | 8800 | out.setOutput(memStream, StandardCharsets.UTF_8.name()); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 8801 | writeDailyItemsLocked(out); |
| 8802 | BackgroundThread.getHandler().post(new Runnable() { |
| 8803 | @Override |
| 8804 | public void run() { |
| 8805 | synchronized (mCheckinFile) { |
| 8806 | FileOutputStream stream = null; |
| 8807 | try { |
| 8808 | stream = mDailyFile.startWrite(); |
| 8809 | memStream.writeTo(stream); |
| 8810 | stream.flush(); |
| 8811 | FileUtils.sync(stream); |
| 8812 | stream.close(); |
| 8813 | mDailyFile.finishWrite(stream); |
| 8814 | } catch (IOException e) { |
| 8815 | Slog.w("BatteryStats", |
| 8816 | "Error writing battery daily items", e); |
| 8817 | mDailyFile.failWrite(stream); |
| 8818 | } |
| 8819 | } |
| 8820 | } |
| 8821 | }); |
| 8822 | } catch (IOException e) { |
| 8823 | } |
| 8824 | } |
| 8825 | } |
| 8826 | |
| 8827 | private void writeDailyItemsLocked(XmlSerializer out) throws IOException { |
| 8828 | StringBuilder sb = new StringBuilder(64); |
| 8829 | out.startDocument(null, true); |
| 8830 | out.startTag(null, "daily-items"); |
| 8831 | for (int i=0; i<mDailyItems.size(); i++) { |
| 8832 | final DailyItem dit = mDailyItems.get(i); |
| 8833 | out.startTag(null, "item"); |
| 8834 | out.attribute(null, "start", Long.toString(dit.mStartTime)); |
| 8835 | out.attribute(null, "end", Long.toString(dit.mEndTime)); |
| 8836 | writeDailyLevelSteps(out, "dis", dit.mDischargeSteps, sb); |
| 8837 | writeDailyLevelSteps(out, "chg", dit.mChargeSteps, sb); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 8838 | if (dit.mPackageChanges != null) { |
| 8839 | for (int j=0; j<dit.mPackageChanges.size(); j++) { |
| 8840 | PackageChange pc = dit.mPackageChanges.get(j); |
| 8841 | if (pc.mUpdate) { |
| 8842 | out.startTag(null, "upd"); |
| 8843 | out.attribute(null, "pkg", pc.mPackageName); |
| 8844 | out.attribute(null, "ver", Integer.toString(pc.mVersionCode)); |
| 8845 | out.endTag(null, "upd"); |
| 8846 | } else { |
| 8847 | out.startTag(null, "rem"); |
| 8848 | out.attribute(null, "pkg", pc.mPackageName); |
| 8849 | out.endTag(null, "rem"); |
| 8850 | } |
| 8851 | } |
| 8852 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 8853 | out.endTag(null, "item"); |
| 8854 | } |
| 8855 | out.endTag(null, "daily-items"); |
| 8856 | out.endDocument(); |
| 8857 | } |
| 8858 | |
| 8859 | private void writeDailyLevelSteps(XmlSerializer out, String tag, LevelStepTracker steps, |
| 8860 | StringBuilder tmpBuilder) throws IOException { |
| 8861 | if (steps != null) { |
| 8862 | out.startTag(null, tag); |
| 8863 | out.attribute(null, "n", Integer.toString(steps.mNumStepDurations)); |
| 8864 | for (int i=0; i<steps.mNumStepDurations; i++) { |
| 8865 | out.startTag(null, "s"); |
| 8866 | tmpBuilder.setLength(0); |
| 8867 | steps.encodeEntryAt(i, tmpBuilder); |
| 8868 | out.attribute(null, "v", tmpBuilder.toString()); |
| 8869 | out.endTag(null, "s"); |
| 8870 | } |
| 8871 | out.endTag(null, tag); |
| 8872 | } |
| 8873 | } |
| 8874 | |
| 8875 | public void readDailyStatsLocked() { |
| 8876 | Slog.d(TAG, "Reading daily items from " + mDailyFile.getBaseFile()); |
| 8877 | mDailyItems.clear(); |
| 8878 | FileInputStream stream; |
| 8879 | try { |
| 8880 | stream = mDailyFile.openRead(); |
| 8881 | } catch (FileNotFoundException e) { |
| 8882 | return; |
| 8883 | } |
| 8884 | try { |
| 8885 | XmlPullParser parser = Xml.newPullParser(); |
Wojciech Staszkiewicz | 9e9e2e7 | 2015-05-08 14:58:46 +0100 | [diff] [blame] | 8886 | parser.setInput(stream, StandardCharsets.UTF_8.name()); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 8887 | readDailyItemsLocked(parser); |
| 8888 | } catch (XmlPullParserException e) { |
| 8889 | } finally { |
| 8890 | try { |
| 8891 | stream.close(); |
| 8892 | } catch (IOException e) { |
| 8893 | } |
| 8894 | } |
| 8895 | } |
| 8896 | |
| 8897 | private void readDailyItemsLocked(XmlPullParser parser) { |
| 8898 | try { |
| 8899 | int type; |
| 8900 | while ((type = parser.next()) != XmlPullParser.START_TAG |
| 8901 | && type != XmlPullParser.END_DOCUMENT) { |
| 8902 | ; |
| 8903 | } |
| 8904 | |
| 8905 | if (type != XmlPullParser.START_TAG) { |
| 8906 | throw new IllegalStateException("no start tag found"); |
| 8907 | } |
| 8908 | |
| 8909 | int outerDepth = parser.getDepth(); |
| 8910 | while ((type = parser.next()) != XmlPullParser.END_DOCUMENT |
| 8911 | && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) { |
| 8912 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 8913 | continue; |
| 8914 | } |
| 8915 | |
| 8916 | String tagName = parser.getName(); |
| 8917 | if (tagName.equals("item")) { |
| 8918 | readDailyItemTagLocked(parser); |
| 8919 | } else { |
| 8920 | Slog.w(TAG, "Unknown element under <daily-items>: " |
| 8921 | + parser.getName()); |
| 8922 | XmlUtils.skipCurrentTag(parser); |
| 8923 | } |
| 8924 | } |
| 8925 | |
| 8926 | } catch (IllegalStateException e) { |
| 8927 | Slog.w(TAG, "Failed parsing daily " + e); |
| 8928 | } catch (NullPointerException e) { |
| 8929 | Slog.w(TAG, "Failed parsing daily " + e); |
| 8930 | } catch (NumberFormatException e) { |
| 8931 | Slog.w(TAG, "Failed parsing daily " + e); |
| 8932 | } catch (XmlPullParserException e) { |
| 8933 | Slog.w(TAG, "Failed parsing daily " + e); |
| 8934 | } catch (IOException e) { |
| 8935 | Slog.w(TAG, "Failed parsing daily " + e); |
| 8936 | } catch (IndexOutOfBoundsException e) { |
| 8937 | Slog.w(TAG, "Failed parsing daily " + e); |
| 8938 | } |
| 8939 | } |
| 8940 | |
| 8941 | void readDailyItemTagLocked(XmlPullParser parser) throws NumberFormatException, |
| 8942 | XmlPullParserException, IOException { |
| 8943 | DailyItem dit = new DailyItem(); |
| 8944 | String attr = parser.getAttributeValue(null, "start"); |
| 8945 | if (attr != null) { |
| 8946 | dit.mStartTime = Long.parseLong(attr); |
| 8947 | } |
| 8948 | attr = parser.getAttributeValue(null, "end"); |
| 8949 | if (attr != null) { |
| 8950 | dit.mEndTime = Long.parseLong(attr); |
| 8951 | } |
| 8952 | int outerDepth = parser.getDepth(); |
| 8953 | int type; |
| 8954 | while ((type = parser.next()) != XmlPullParser.END_DOCUMENT |
| 8955 | && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) { |
| 8956 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 8957 | continue; |
| 8958 | } |
| 8959 | |
| 8960 | String tagName = parser.getName(); |
| 8961 | if (tagName.equals("dis")) { |
| 8962 | readDailyItemTagDetailsLocked(parser, dit, false, "dis"); |
| 8963 | } else if (tagName.equals("chg")) { |
| 8964 | readDailyItemTagDetailsLocked(parser, dit, true, "chg"); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 8965 | } else if (tagName.equals("upd")) { |
| 8966 | if (dit.mPackageChanges == null) { |
| 8967 | dit.mPackageChanges = new ArrayList<>(); |
| 8968 | } |
| 8969 | PackageChange pc = new PackageChange(); |
| 8970 | pc.mUpdate = true; |
| 8971 | pc.mPackageName = parser.getAttributeValue(null, "pkg"); |
| 8972 | String verStr = parser.getAttributeValue(null, "ver"); |
| 8973 | pc.mVersionCode = verStr != null ? Integer.parseInt(verStr) : 0; |
| 8974 | dit.mPackageChanges.add(pc); |
| 8975 | XmlUtils.skipCurrentTag(parser); |
| 8976 | } else if (tagName.equals("rem")) { |
| 8977 | if (dit.mPackageChanges == null) { |
| 8978 | dit.mPackageChanges = new ArrayList<>(); |
| 8979 | } |
| 8980 | PackageChange pc = new PackageChange(); |
| 8981 | pc.mUpdate = false; |
| 8982 | pc.mPackageName = parser.getAttributeValue(null, "pkg"); |
| 8983 | dit.mPackageChanges.add(pc); |
| 8984 | XmlUtils.skipCurrentTag(parser); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 8985 | } else { |
| 8986 | Slog.w(TAG, "Unknown element under <item>: " |
| 8987 | + parser.getName()); |
| 8988 | XmlUtils.skipCurrentTag(parser); |
| 8989 | } |
| 8990 | } |
| 8991 | mDailyItems.add(dit); |
| 8992 | } |
| 8993 | |
| 8994 | void readDailyItemTagDetailsLocked(XmlPullParser parser, DailyItem dit, boolean isCharge, |
| 8995 | String tag) |
| 8996 | throws NumberFormatException, XmlPullParserException, IOException { |
| 8997 | final String numAttr = parser.getAttributeValue(null, "n"); |
| 8998 | if (numAttr == null) { |
| 8999 | Slog.w(TAG, "Missing 'n' attribute at " + parser.getPositionDescription()); |
| 9000 | XmlUtils.skipCurrentTag(parser); |
| 9001 | return; |
| 9002 | } |
| 9003 | final int num = Integer.parseInt(numAttr); |
| 9004 | LevelStepTracker steps = new LevelStepTracker(num); |
| 9005 | if (isCharge) { |
| 9006 | dit.mChargeSteps = steps; |
| 9007 | } else { |
| 9008 | dit.mDischargeSteps = steps; |
| 9009 | } |
| 9010 | int i = 0; |
| 9011 | int outerDepth = parser.getDepth(); |
| 9012 | int type; |
| 9013 | while ((type = parser.next()) != XmlPullParser.END_DOCUMENT |
| 9014 | && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) { |
| 9015 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 9016 | continue; |
| 9017 | } |
| 9018 | |
| 9019 | String tagName = parser.getName(); |
| 9020 | if ("s".equals(tagName)) { |
| 9021 | if (i < num) { |
| 9022 | String valueAttr = parser.getAttributeValue(null, "v"); |
| 9023 | if (valueAttr != null) { |
| 9024 | steps.decodeEntryAt(i, valueAttr); |
| 9025 | i++; |
| 9026 | } |
| 9027 | } |
| 9028 | } else { |
| 9029 | Slog.w(TAG, "Unknown element under <" + tag + ">: " |
| 9030 | + parser.getName()); |
| 9031 | XmlUtils.skipCurrentTag(parser); |
| 9032 | } |
| 9033 | } |
| 9034 | steps.mNumStepDurations = i; |
| 9035 | } |
| 9036 | |
| 9037 | @Override |
| 9038 | public DailyItem getDailyItemLocked(int daysAgo) { |
| 9039 | int index = mDailyItems.size()-1-daysAgo; |
| 9040 | return index >= 0 ? mDailyItems.get(index) : null; |
| 9041 | } |
| 9042 | |
| 9043 | @Override |
| 9044 | public long getCurrentDailyStartTime() { |
| 9045 | return mDailyStartTime; |
| 9046 | } |
| 9047 | |
| 9048 | @Override |
| 9049 | public long getNextMinDailyDeadline() { |
| 9050 | return mNextMinDailyDeadline; |
| 9051 | } |
| 9052 | |
| 9053 | @Override |
| 9054 | public long getNextMaxDailyDeadline() { |
| 9055 | return mNextMaxDailyDeadline; |
| 9056 | } |
| 9057 | |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 9058 | @Override |
| 9059 | public boolean startIteratingOldHistoryLocked() { |
| 9060 | if (DEBUG_HISTORY) Slog.i(TAG, "ITERATING: buff size=" + mHistoryBuffer.dataSize() |
| 9061 | + " pos=" + mHistoryBuffer.dataPosition()); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 9062 | if ((mHistoryIterator = mHistory) == null) { |
| 9063 | return false; |
| 9064 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 9065 | mHistoryBuffer.setDataPosition(0); |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 9066 | mHistoryReadTmp.clear(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 9067 | mReadOverflow = false; |
| 9068 | mIteratingHistory = true; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 9069 | return true; |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 9070 | } |
| 9071 | |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 9072 | @Override |
| 9073 | public boolean getNextOldHistoryLocked(HistoryItem out) { |
| 9074 | boolean end = mHistoryBuffer.dataPosition() >= mHistoryBuffer.dataSize(); |
| 9075 | if (!end) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 9076 | readHistoryDelta(mHistoryBuffer, mHistoryReadTmp); |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 9077 | mReadOverflow |= mHistoryReadTmp.cmd == HistoryItem.CMD_OVERFLOW; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 9078 | } |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 9079 | HistoryItem cur = mHistoryIterator; |
| 9080 | if (cur == null) { |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 9081 | if (!mReadOverflow && !end) { |
| 9082 | Slog.w(TAG, "Old history ends before new history!"); |
| 9083 | } |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 9084 | return false; |
| 9085 | } |
| 9086 | out.setTo(cur); |
| 9087 | mHistoryIterator = cur.next; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 9088 | if (!mReadOverflow) { |
| 9089 | if (end) { |
| 9090 | Slog.w(TAG, "New history ends before old history!"); |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 9091 | } else if (!out.same(mHistoryReadTmp)) { |
Dianne Hackborn | 8c84109 | 2013-06-24 13:46:13 -0700 | [diff] [blame] | 9092 | PrintWriter pw = new FastPrintWriter(new LogWriter(android.util.Log.WARN, TAG)); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 9093 | pw.println("Histories differ!"); |
| 9094 | pw.println("Old history:"); |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 9095 | (new HistoryPrinter()).printNextItem(pw, out, 0, false, true); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 9096 | pw.println("New history:"); |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 9097 | (new HistoryPrinter()).printNextItem(pw, mHistoryReadTmp, 0, false, |
| 9098 | true); |
Dianne Hackborn | 8c84109 | 2013-06-24 13:46:13 -0700 | [diff] [blame] | 9099 | pw.flush(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 9100 | } |
| 9101 | } |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 9102 | return true; |
| 9103 | } |
| 9104 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9105 | @Override |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 9106 | public void finishIteratingOldHistoryLocked() { |
| 9107 | mIteratingHistory = false; |
| 9108 | mHistoryBuffer.setDataPosition(mHistoryBuffer.dataSize()); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 9109 | mHistoryIterator = null; |
| 9110 | } |
| 9111 | |
| 9112 | public int getHistoryTotalSize() { |
| 9113 | return MAX_HISTORY_BUFFER; |
| 9114 | } |
| 9115 | |
| 9116 | public int getHistoryUsedSize() { |
| 9117 | return mHistoryBuffer.dataSize(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 9118 | } |
| 9119 | |
| 9120 | @Override |
| 9121 | public boolean startIteratingHistoryLocked() { |
| 9122 | if (DEBUG_HISTORY) Slog.i(TAG, "ITERATING: buff size=" + mHistoryBuffer.dataSize() |
| 9123 | + " pos=" + mHistoryBuffer.dataPosition()); |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 9124 | if (mHistoryBuffer.dataSize() <= 0) { |
| 9125 | return false; |
| 9126 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 9127 | mHistoryBuffer.setDataPosition(0); |
| 9128 | mReadOverflow = false; |
| 9129 | mIteratingHistory = true; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 9130 | mReadHistoryStrings = new String[mHistoryTagPool.size()]; |
| 9131 | mReadHistoryUids = new int[mHistoryTagPool.size()]; |
| 9132 | mReadHistoryChars = 0; |
| 9133 | for (HashMap.Entry<HistoryTag, Integer> ent : mHistoryTagPool.entrySet()) { |
| 9134 | final HistoryTag tag = ent.getKey(); |
| 9135 | final int idx = ent.getValue(); |
| 9136 | mReadHistoryStrings[idx] = tag.string; |
| 9137 | mReadHistoryUids[idx] = tag.uid; |
| 9138 | mReadHistoryChars += tag.string.length() + 1; |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 9139 | } |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 9140 | return true; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 9141 | } |
| 9142 | |
| 9143 | @Override |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 9144 | public int getHistoryStringPoolSize() { |
| 9145 | return mReadHistoryStrings.length; |
| 9146 | } |
| 9147 | |
| 9148 | @Override |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 9149 | public int getHistoryStringPoolBytes() { |
| 9150 | // Each entry is a fixed 12 bytes: 4 for index, 4 for uid, 4 for string size |
| 9151 | // Each string character is 2 bytes. |
| 9152 | return (mReadHistoryStrings.length * 12) + (mReadHistoryChars * 2); |
| 9153 | } |
| 9154 | |
| 9155 | @Override |
| 9156 | public String getHistoryTagPoolString(int index) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 9157 | return mReadHistoryStrings[index]; |
| 9158 | } |
| 9159 | |
| 9160 | @Override |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 9161 | public int getHistoryTagPoolUid(int index) { |
| 9162 | return mReadHistoryUids[index]; |
| 9163 | } |
| 9164 | |
| 9165 | @Override |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 9166 | public boolean getNextHistoryLocked(HistoryItem out) { |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 9167 | final int pos = mHistoryBuffer.dataPosition(); |
| 9168 | if (pos == 0) { |
| 9169 | out.clear(); |
| 9170 | } |
| 9171 | boolean end = pos >= mHistoryBuffer.dataSize(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 9172 | if (end) { |
| 9173 | return false; |
| 9174 | } |
| 9175 | |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 9176 | final long lastRealtime = out.time; |
| 9177 | final long lastWalltime = out.currentTime; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 9178 | readHistoryDelta(mHistoryBuffer, out); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 9179 | if (out.cmd != HistoryItem.CMD_CURRENT_TIME |
| 9180 | && out.cmd != HistoryItem.CMD_RESET && lastWalltime != 0) { |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 9181 | out.currentTime = lastWalltime + (out.time - lastRealtime); |
| 9182 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 9183 | return true; |
| 9184 | } |
| 9185 | |
| 9186 | @Override |
| 9187 | public void finishIteratingHistoryLocked() { |
| 9188 | mIteratingHistory = false; |
| 9189 | mHistoryBuffer.setDataPosition(mHistoryBuffer.dataSize()); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 9190 | mReadHistoryStrings = null; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 9191 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 9192 | |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 9193 | @Override |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 9194 | public long getHistoryBaseTime() { |
| 9195 | return mHistoryBaseTime; |
| 9196 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 9197 | |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 9198 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9199 | public int getStartCount() { |
| 9200 | return mStartCount; |
| 9201 | } |
| 9202 | |
| 9203 | public boolean isOnBattery() { |
| 9204 | return mOnBattery; |
| 9205 | } |
| 9206 | |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 9207 | public boolean isCharging() { |
| 9208 | return mCharging; |
| 9209 | } |
| 9210 | |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 9211 | public boolean isScreenOn() { |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 9212 | return mScreenState == Display.STATE_ON; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 9213 | } |
| 9214 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9215 | void initTimes(long uptime, long realtime) { |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 9216 | mStartClockTime = System.currentTimeMillis(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9217 | mOnBatteryTimeBase.init(uptime, realtime); |
| 9218 | mOnBatteryScreenOffTimeBase.init(uptime, realtime); |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 9219 | mRealtime = 0; |
| 9220 | mUptime = 0; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9221 | mRealtimeStart = realtime; |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 9222 | mUptimeStart = uptime; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9223 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 9224 | |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 9225 | void initDischarge() { |
| 9226 | mLowDischargeAmountSinceCharge = 0; |
| 9227 | mHighDischargeAmountSinceCharge = 0; |
| 9228 | mDischargeAmountScreenOn = 0; |
| 9229 | mDischargeAmountScreenOnSinceCharge = 0; |
| 9230 | mDischargeAmountScreenOff = 0; |
| 9231 | mDischargeAmountScreenOffSinceCharge = 0; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 9232 | mDischargeStepTracker.init(); |
| 9233 | mChargeStepTracker.init(); |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 9234 | mDischargeScreenOffCounter.reset(false); |
| 9235 | mDischargeCounter.reset(false); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 9236 | } |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 9237 | |
| 9238 | public void resetAllStatsCmdLocked() { |
| 9239 | resetAllStatsLocked(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9240 | final long mSecUptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 9241 | long uptime = mSecUptime * 1000; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9242 | long mSecRealtime = mClocks.elapsedRealtime(); |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 9243 | long realtime = mSecRealtime * 1000; |
| 9244 | mDischargeStartLevel = mHistoryCur.batteryLevel; |
| 9245 | pullPendingStateUpdatesLocked(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 9246 | addHistoryRecordLocked(mSecRealtime, mSecUptime); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 9247 | mDischargeCurrentLevel = mDischargeUnplugLevel = mDischargePlugLevel |
| 9248 | = mCurrentBatteryLevel = mHistoryCur.batteryLevel; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9249 | mOnBatteryTimeBase.reset(uptime, realtime); |
| 9250 | mOnBatteryScreenOffTimeBase.reset(uptime, realtime); |
| 9251 | if ((mHistoryCur.states&HistoryItem.STATE_BATTERY_PLUGGED_FLAG) == 0) { |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 9252 | if (mScreenState == Display.STATE_ON) { |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 9253 | mDischargeScreenOnUnplugLevel = mHistoryCur.batteryLevel; |
| 9254 | mDischargeScreenOffUnplugLevel = 0; |
| 9255 | } else { |
| 9256 | mDischargeScreenOnUnplugLevel = 0; |
| 9257 | mDischargeScreenOffUnplugLevel = mHistoryCur.batteryLevel; |
| 9258 | } |
| 9259 | mDischargeAmountScreenOn = 0; |
| 9260 | mDischargeAmountScreenOff = 0; |
| 9261 | } |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 9262 | initActiveHistoryEventsLocked(mSecRealtime, mSecUptime); |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 9263 | } |
| 9264 | |
| 9265 | private void resetAllStatsLocked() { |
Adam Lesinski | 8ce3694 | 2016-05-26 16:05:35 -0700 | [diff] [blame] | 9266 | final long uptimeMillis = mClocks.uptimeMillis(); |
| 9267 | final long elapsedRealtimeMillis = mClocks.elapsedRealtime(); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9268 | mStartCount = 0; |
Adam Lesinski | 8ce3694 | 2016-05-26 16:05:35 -0700 | [diff] [blame] | 9269 | initTimes(uptimeMillis * 1000, elapsedRealtimeMillis * 1000); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9270 | mScreenOnTimer.reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9271 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9272 | mScreenBrightnessTimer[i].reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9273 | } |
Adam Lesinski | 1a76a62 | 2016-06-22 10:28:47 -0700 | [diff] [blame] | 9274 | |
| 9275 | if (mPowerProfile != null) { |
| 9276 | mEstimatedBatteryCapacity = (int) mPowerProfile.getBatteryCapacity(); |
| 9277 | } else { |
| 9278 | mEstimatedBatteryCapacity = -1; |
| 9279 | } |
Jocelyn Dang | c627d10 | 2017-04-14 13:15:14 -0700 | [diff] [blame] | 9280 | mMinLearnedBatteryCapacity = -1; |
| 9281 | mMaxLearnedBatteryCapacity = -1; |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 9282 | mInteractiveTimer.reset(false); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 9283 | mPowerSaveModeEnabledTimer.reset(false); |
Adam Lesinski | 8ce3694 | 2016-05-26 16:05:35 -0700 | [diff] [blame] | 9284 | mLastIdleTimeStart = elapsedRealtimeMillis; |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 9285 | mLongestLightIdleTime = 0; |
| 9286 | mLongestFullIdleTime = 0; |
| 9287 | mDeviceIdleModeLightTimer.reset(false); |
| 9288 | mDeviceIdleModeFullTimer.reset(false); |
| 9289 | mDeviceLightIdlingTimer.reset(false); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 9290 | mDeviceIdlingTimer.reset(false); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9291 | mPhoneOnTimer.reset(false); |
| 9292 | mAudioOnTimer.reset(false); |
| 9293 | mVideoOnTimer.reset(false); |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 9294 | mFlashlightOnTimer.reset(false); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 9295 | mCameraOnTimer.reset(false); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 9296 | mBluetoothScanTimer.reset(false); |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 9297 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9298 | mPhoneSignalStrengthsTimer[i].reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9299 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9300 | mPhoneSignalScanningTimer.reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9301 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9302 | mPhoneDataConnectionsTimer[i].reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9303 | } |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 9304 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 9305 | mNetworkByteActivityCounters[i].reset(false); |
| 9306 | mNetworkPacketActivityCounters[i].reset(false); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 9307 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9308 | mMobileRadioActiveTimer.reset(false); |
| 9309 | mMobileRadioActivePerAppTimer.reset(false); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 9310 | mMobileRadioActiveAdjustedTime.reset(false); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 9311 | mMobileRadioActiveUnknownTime.reset(false); |
| 9312 | mMobileRadioActiveUnknownCount.reset(false); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9313 | mWifiOnTimer.reset(false); |
| 9314 | mGlobalWifiRunningTimer.reset(false); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 9315 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9316 | mWifiStateTimer[i].reset(false); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 9317 | } |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 9318 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
| 9319 | mWifiSupplStateTimer[i].reset(false); |
| 9320 | } |
| 9321 | for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 9322 | mWifiSignalStrengthsTimer[i].reset(false); |
| 9323 | } |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 9324 | mWifiActivity.reset(false); |
| 9325 | mBluetoothActivity.reset(false); |
| 9326 | mModemActivity.reset(false); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 9327 | mNumConnectivityChange = mLoadedNumConnectivityChange = mUnpluggedNumConnectivityChange = 0; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 9328 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9329 | for (int i=0; i<mUidStats.size(); i++) { |
| 9330 | if (mUidStats.valueAt(i).reset()) { |
| 9331 | mUidStats.remove(mUidStats.keyAt(i)); |
| 9332 | i--; |
| 9333 | } |
| 9334 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 9335 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9336 | if (mKernelWakelockStats.size() > 0) { |
| 9337 | for (SamplingTimer timer : mKernelWakelockStats.values()) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9338 | mOnBatteryScreenOffTimeBase.remove(timer); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9339 | } |
| 9340 | mKernelWakelockStats.clear(); |
| 9341 | } |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 9342 | |
James Carr | 3a22605 | 2016-07-01 14:49:52 -0700 | [diff] [blame] | 9343 | if (mKernelMemoryStats.size() > 0) { |
| 9344 | for (int i = 0; i < mKernelMemoryStats.size(); i++) { |
| 9345 | mOnBatteryTimeBase.remove(mKernelMemoryStats.valueAt(i)); |
| 9346 | } |
| 9347 | mKernelMemoryStats.clear(); |
| 9348 | } |
| 9349 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 9350 | if (mWakeupReasonStats.size() > 0) { |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 9351 | for (SamplingTimer timer : mWakeupReasonStats.values()) { |
| 9352 | mOnBatteryTimeBase.remove(timer); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 9353 | } |
| 9354 | mWakeupReasonStats.clear(); |
| 9355 | } |
| 9356 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 9357 | mLastHistoryStepDetails = null; |
| 9358 | mLastStepCpuUserTime = mLastStepCpuSystemTime = 0; |
| 9359 | mCurStepCpuUserTime = mCurStepCpuSystemTime = 0; |
| 9360 | mLastStepCpuUserTime = mCurStepCpuUserTime = 0; |
| 9361 | mLastStepCpuSystemTime = mCurStepCpuSystemTime = 0; |
| 9362 | mLastStepStatUserTime = mCurStepStatUserTime = 0; |
| 9363 | mLastStepStatSystemTime = mCurStepStatSystemTime = 0; |
| 9364 | mLastStepStatIOWaitTime = mCurStepStatIOWaitTime = 0; |
| 9365 | mLastStepStatIrqTime = mCurStepStatIrqTime = 0; |
| 9366 | mLastStepStatSoftIrqTime = mCurStepStatSoftIrqTime = 0; |
| 9367 | mLastStepStatIdleTime = mCurStepStatIdleTime = 0; |
| 9368 | |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 9369 | initDischarge(); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 9370 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9371 | clearHistoryLocked(); |
| 9372 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 9373 | |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 9374 | private void initActiveHistoryEventsLocked(long elapsedRealtimeMs, long uptimeMs) { |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 9375 | for (int i=0; i<HistoryItem.EVENT_COUNT; i++) { |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 9376 | if (!mRecordAllHistory && i == HistoryItem.EVENT_PROC) { |
| 9377 | // Not recording process starts/stops. |
| 9378 | continue; |
| 9379 | } |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 9380 | HashMap<String, SparseIntArray> active = mActiveEvents.getStateForEvent(i); |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 9381 | if (active == null) { |
| 9382 | continue; |
| 9383 | } |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 9384 | for (HashMap.Entry<String, SparseIntArray> ent : active.entrySet()) { |
| 9385 | SparseIntArray uids = ent.getValue(); |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 9386 | for (int j=0; j<uids.size(); j++) { |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 9387 | addHistoryEventLocked(elapsedRealtimeMs, uptimeMs, i, ent.getKey(), |
| 9388 | uids.keyAt(j)); |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 9389 | } |
| 9390 | } |
| 9391 | } |
| 9392 | } |
| 9393 | |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 9394 | void updateDischargeScreenLevelsLocked(boolean oldScreenOn, boolean newScreenOn) { |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 9395 | if (oldScreenOn) { |
| 9396 | int diff = mDischargeScreenOnUnplugLevel - mDischargeCurrentLevel; |
| 9397 | if (diff > 0) { |
| 9398 | mDischargeAmountScreenOn += diff; |
| 9399 | mDischargeAmountScreenOnSinceCharge += diff; |
| 9400 | } |
| 9401 | } else { |
| 9402 | int diff = mDischargeScreenOffUnplugLevel - mDischargeCurrentLevel; |
| 9403 | if (diff > 0) { |
| 9404 | mDischargeAmountScreenOff += diff; |
| 9405 | mDischargeAmountScreenOffSinceCharge += diff; |
| 9406 | } |
| 9407 | } |
| 9408 | if (newScreenOn) { |
| 9409 | mDischargeScreenOnUnplugLevel = mDischargeCurrentLevel; |
| 9410 | mDischargeScreenOffUnplugLevel = 0; |
| 9411 | } else { |
| 9412 | mDischargeScreenOnUnplugLevel = 0; |
| 9413 | mDischargeScreenOffUnplugLevel = mDischargeCurrentLevel; |
| 9414 | } |
| 9415 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 9416 | |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 9417 | public void pullPendingStateUpdatesLocked() { |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 9418 | if (mOnBatteryInternal) { |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 9419 | final boolean screenOn = mScreenState == Display.STATE_ON; |
| 9420 | updateDischargeScreenLevelsLocked(screenOn, screenOn); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 9421 | } |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 9422 | } |
| 9423 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 9424 | private final NetworkStatsFactory mNetworkStatsFactory = new NetworkStatsFactory(); |
| 9425 | private final Pools.Pool<NetworkStats> mNetworkStatsPool = new Pools.SynchronizedPool<>(6); |
| 9426 | |
| 9427 | private final Object mWifiNetworkLock = new Object(); |
| 9428 | |
| 9429 | @GuardedBy("mWifiNetworkLock") |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 9430 | private String[] mWifiIfaces = EmptyArray.STRING; |
| 9431 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 9432 | @GuardedBy("mWifiNetworkLock") |
| 9433 | private NetworkStats mLastWifiNetworkStats = new NetworkStats(0, -1); |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 9434 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 9435 | private final Object mModemNetworkLock = new Object(); |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 9436 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 9437 | @GuardedBy("mModemNetworkLock") |
| 9438 | private String[] mModemIfaces = EmptyArray.STRING; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 9439 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 9440 | @GuardedBy("mModemNetworkLock") |
| 9441 | private NetworkStats mLastModemNetworkStats = new NetworkStats(0, -1); |
| 9442 | |
| 9443 | private NetworkStats readNetworkStatsLocked(String[] ifaces) { |
| 9444 | try { |
| 9445 | if (!ArrayUtils.isEmpty(ifaces)) { |
| 9446 | return mNetworkStatsFactory.readNetworkStatsDetail(NetworkStats.UID_ALL, ifaces, |
| 9447 | NetworkStats.TAG_NONE, mNetworkStatsPool.acquire()); |
| 9448 | } |
| 9449 | } catch (IOException e) { |
| 9450 | Slog.e(TAG, "failed to read network stats for ifaces: " + Arrays.toString(ifaces)); |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 9451 | } |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 9452 | return null; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 9453 | } |
| 9454 | |
| 9455 | /** |
| 9456 | * Distribute WiFi energy info and network traffic to apps. |
| 9457 | * @param info The energy information from the WiFi controller. |
| 9458 | */ |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 9459 | public void updateWifiState(@Nullable final WifiActivityEnergyInfo info) { |
Adam Lesinski | a7c90c8 | 2015-06-18 14:52:24 -0700 | [diff] [blame] | 9460 | if (DEBUG_ENERGY) { |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 9461 | Slog.d(TAG, "Updating wifi stats: " + Arrays.toString(mWifiIfaces)); |
Adam Lesinski | a7c90c8 | 2015-06-18 14:52:24 -0700 | [diff] [blame] | 9462 | } |
| 9463 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 9464 | // Grab a separate lock to acquire the network stats, which may do I/O. |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 9465 | NetworkStats delta = null; |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 9466 | synchronized (mWifiNetworkLock) { |
| 9467 | final NetworkStats latestStats = readNetworkStatsLocked(mWifiIfaces); |
| 9468 | if (latestStats != null) { |
| 9469 | delta = NetworkStats.subtract(latestStats, mLastWifiNetworkStats, null, null, |
| 9470 | mNetworkStatsPool.acquire()); |
| 9471 | mNetworkStatsPool.release(mLastWifiNetworkStats); |
| 9472 | mLastWifiNetworkStats = latestStats; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 9473 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 9474 | } |
| 9475 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 9476 | synchronized (this) { |
| 9477 | if (!mOnBatteryInternal) { |
| 9478 | if (delta != null) { |
| 9479 | mNetworkStatsPool.release(delta); |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 9480 | } |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 9481 | return; |
| 9482 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 9483 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 9484 | final long elapsedRealtimeMs = mClocks.elapsedRealtime(); |
| 9485 | SparseLongArray rxPackets = new SparseLongArray(); |
| 9486 | SparseLongArray txPackets = new SparseLongArray(); |
| 9487 | long totalTxPackets = 0; |
| 9488 | long totalRxPackets = 0; |
| 9489 | if (delta != null) { |
| 9490 | NetworkStats.Entry entry = new NetworkStats.Entry(); |
| 9491 | final int size = delta.size(); |
| 9492 | for (int i = 0; i < size; i++) { |
| 9493 | entry = delta.getValues(i, entry); |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 9494 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 9495 | if (DEBUG_ENERGY) { |
| 9496 | Slog.d(TAG, "Wifi uid " + entry.uid + ": delta rx=" + entry.rxBytes |
| 9497 | + " tx=" + entry.txBytes + " rxPackets=" + entry.rxPackets |
| 9498 | + " txPackets=" + entry.txPackets); |
| 9499 | } |
| 9500 | |
| 9501 | if (entry.rxBytes == 0 && entry.txBytes == 0) { |
| 9502 | // Skip the lookup below since there is no work to do. |
| 9503 | continue; |
| 9504 | } |
| 9505 | |
| 9506 | final Uid u = getUidStatsLocked(mapUid(entry.uid)); |
| 9507 | if (entry.rxBytes != 0) { |
| 9508 | u.noteNetworkActivityLocked(NETWORK_WIFI_RX_DATA, entry.rxBytes, |
Amith Yamasani | 59fe841 | 2017-03-03 16:28:52 -0800 | [diff] [blame] | 9509 | entry.rxPackets); |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 9510 | if (entry.set == NetworkStats.SET_DEFAULT) { // Background transfers |
| 9511 | u.noteNetworkActivityLocked(NETWORK_WIFI_BG_RX_DATA, entry.rxBytes, |
| 9512 | entry.rxPackets); |
| 9513 | } |
| 9514 | mNetworkByteActivityCounters[NETWORK_WIFI_RX_DATA].addCountLocked( |
| 9515 | entry.rxBytes); |
| 9516 | mNetworkPacketActivityCounters[NETWORK_WIFI_RX_DATA].addCountLocked( |
| 9517 | entry.rxPackets); |
| 9518 | |
| 9519 | rxPackets.put(u.getUid(), entry.rxPackets); |
| 9520 | |
| 9521 | // Sum the total number of packets so that the Rx Power can |
| 9522 | // be evenly distributed amongst the apps. |
| 9523 | totalRxPackets += entry.rxPackets; |
Amith Yamasani | 59fe841 | 2017-03-03 16:28:52 -0800 | [diff] [blame] | 9524 | } |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 9525 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 9526 | if (entry.txBytes != 0) { |
| 9527 | u.noteNetworkActivityLocked(NETWORK_WIFI_TX_DATA, entry.txBytes, |
Amith Yamasani | 59fe841 | 2017-03-03 16:28:52 -0800 | [diff] [blame] | 9528 | entry.txPackets); |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 9529 | if (entry.set == NetworkStats.SET_DEFAULT) { // Background transfers |
| 9530 | u.noteNetworkActivityLocked(NETWORK_WIFI_BG_TX_DATA, entry.txBytes, |
| 9531 | entry.txPackets); |
| 9532 | } |
| 9533 | mNetworkByteActivityCounters[NETWORK_WIFI_TX_DATA].addCountLocked( |
| 9534 | entry.txBytes); |
| 9535 | mNetworkPacketActivityCounters[NETWORK_WIFI_TX_DATA].addCountLocked( |
| 9536 | entry.txPackets); |
| 9537 | |
| 9538 | txPackets.put(u.getUid(), entry.txPackets); |
| 9539 | |
| 9540 | // Sum the total number of packets so that the Tx Power can |
| 9541 | // be evenly distributed amongst the apps. |
| 9542 | totalTxPackets += entry.txPackets; |
Amith Yamasani | 59fe841 | 2017-03-03 16:28:52 -0800 | [diff] [blame] | 9543 | } |
Adam Lesinski | ba88e68 | 2015-12-08 12:06:55 -0800 | [diff] [blame] | 9544 | } |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 9545 | mNetworkStatsPool.release(delta); |
| 9546 | delta = null; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 9547 | } |
| 9548 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 9549 | if (info != null) { |
| 9550 | mHasWifiReporting = true; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 9551 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 9552 | // Measured in mAms |
| 9553 | final long txTimeMs = info.getControllerTxTimeMillis(); |
| 9554 | final long rxTimeMs = info.getControllerRxTimeMillis(); |
| 9555 | final long idleTimeMs = info.getControllerIdleTimeMillis(); |
| 9556 | final long totalTimeMs = txTimeMs + rxTimeMs + idleTimeMs; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 9557 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 9558 | long leftOverRxTimeMs = rxTimeMs; |
| 9559 | long leftOverTxTimeMs = txTimeMs; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 9560 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 9561 | if (DEBUG_ENERGY) { |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 9562 | Slog.d(TAG, "------ BEGIN WiFi power blaming ------"); |
| 9563 | Slog.d(TAG, " Tx Time: " + txTimeMs + " ms"); |
| 9564 | Slog.d(TAG, " Rx Time: " + rxTimeMs + " ms"); |
| 9565 | Slog.d(TAG, " Idle Time: " + idleTimeMs + " ms"); |
| 9566 | Slog.d(TAG, " Total Time: " + totalTimeMs + " ms"); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 9567 | } |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 9568 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 9569 | long totalWifiLockTimeMs = 0; |
| 9570 | long totalScanTimeMs = 0; |
| 9571 | |
| 9572 | // On the first pass, collect some totals so that we can normalize power |
| 9573 | // calculations if we need to. |
| 9574 | final int uidStatsSize = mUidStats.size(); |
| 9575 | for (int i = 0; i < uidStatsSize; i++) { |
| 9576 | final Uid uid = mUidStats.valueAt(i); |
| 9577 | |
| 9578 | // Sum the total scan power for all apps. |
| 9579 | totalScanTimeMs += uid.mWifiScanTimer.getTimeSinceMarkLocked( |
| 9580 | elapsedRealtimeMs * 1000) / 1000; |
| 9581 | |
| 9582 | // Sum the total time holding wifi lock for all apps. |
| 9583 | totalWifiLockTimeMs += uid.mFullWifiLockTimer.getTimeSinceMarkLocked( |
| 9584 | elapsedRealtimeMs * 1000) / 1000; |
| 9585 | } |
| 9586 | |
| 9587 | if (DEBUG_ENERGY && totalScanTimeMs > rxTimeMs) { |
| 9588 | Slog.d(TAG, |
| 9589 | " !Estimated scan time > Actual rx time (" + totalScanTimeMs + " ms > " |
| 9590 | + rxTimeMs + " ms). Normalizing scan time."); |
| 9591 | } |
| 9592 | if (DEBUG_ENERGY && totalScanTimeMs > txTimeMs) { |
| 9593 | Slog.d(TAG, |
| 9594 | " !Estimated scan time > Actual tx time (" + totalScanTimeMs + " ms > " |
| 9595 | + txTimeMs + " ms). Normalizing scan time."); |
| 9596 | } |
| 9597 | |
| 9598 | // Actually assign and distribute power usage to apps. |
| 9599 | for (int i = 0; i < uidStatsSize; i++) { |
| 9600 | final Uid uid = mUidStats.valueAt(i); |
| 9601 | |
| 9602 | long scanTimeSinceMarkMs = uid.mWifiScanTimer.getTimeSinceMarkLocked( |
| 9603 | elapsedRealtimeMs * 1000) / 1000; |
| 9604 | if (scanTimeSinceMarkMs > 0) { |
| 9605 | // Set the new mark so that next time we get new data since this point. |
| 9606 | uid.mWifiScanTimer.setMark(elapsedRealtimeMs); |
| 9607 | |
| 9608 | long scanRxTimeSinceMarkMs = scanTimeSinceMarkMs; |
| 9609 | long scanTxTimeSinceMarkMs = scanTimeSinceMarkMs; |
| 9610 | |
| 9611 | // Our total scan time is more than the reported Tx/Rx time. |
| 9612 | // This is possible because the cost of a scan is approximate. |
| 9613 | // Let's normalize the result so that we evenly blame each app |
| 9614 | // scanning. |
| 9615 | // |
| 9616 | // This means that we may have apps that transmitted/received packets not be |
| 9617 | // blamed for this, but this is fine as scans are relatively more expensive. |
| 9618 | if (totalScanTimeMs > rxTimeMs) { |
| 9619 | scanRxTimeSinceMarkMs = (rxTimeMs * scanRxTimeSinceMarkMs) / |
| 9620 | totalScanTimeMs; |
| 9621 | } |
| 9622 | if (totalScanTimeMs > txTimeMs) { |
| 9623 | scanTxTimeSinceMarkMs = (txTimeMs * scanTxTimeSinceMarkMs) / |
| 9624 | totalScanTimeMs; |
| 9625 | } |
| 9626 | |
| 9627 | if (DEBUG_ENERGY) { |
| 9628 | Slog.d(TAG, " ScanTime for UID " + uid.getUid() + ": Rx:" |
| 9629 | + scanRxTimeSinceMarkMs + " ms Tx:" |
| 9630 | + scanTxTimeSinceMarkMs + " ms)"); |
| 9631 | } |
| 9632 | |
| 9633 | ControllerActivityCounterImpl activityCounter = |
| 9634 | uid.getOrCreateWifiControllerActivityLocked(); |
| 9635 | activityCounter.getRxTimeCounter().addCountLocked(scanRxTimeSinceMarkMs); |
| 9636 | activityCounter.getTxTimeCounters()[0].addCountLocked( |
| 9637 | scanTxTimeSinceMarkMs); |
| 9638 | leftOverRxTimeMs -= scanRxTimeSinceMarkMs; |
| 9639 | leftOverTxTimeMs -= scanTxTimeSinceMarkMs; |
| 9640 | } |
| 9641 | |
| 9642 | // Distribute evenly the power consumed while Idle to each app holding a WiFi |
| 9643 | // lock. |
| 9644 | final long wifiLockTimeSinceMarkMs = |
| 9645 | uid.mFullWifiLockTimer.getTimeSinceMarkLocked( |
| 9646 | elapsedRealtimeMs * 1000) / 1000; |
| 9647 | if (wifiLockTimeSinceMarkMs > 0) { |
| 9648 | // Set the new mark so that next time we get new data since this point. |
| 9649 | uid.mFullWifiLockTimer.setMark(elapsedRealtimeMs); |
| 9650 | |
| 9651 | final long myIdleTimeMs = (wifiLockTimeSinceMarkMs * idleTimeMs) |
| 9652 | / totalWifiLockTimeMs; |
| 9653 | if (DEBUG_ENERGY) { |
| 9654 | Slog.d(TAG, " IdleTime for UID " + uid.getUid() + ": " |
| 9655 | + myIdleTimeMs + " ms"); |
| 9656 | } |
| 9657 | uid.getOrCreateWifiControllerActivityLocked().getIdleTimeCounter() |
| 9658 | .addCountLocked(myIdleTimeMs); |
| 9659 | } |
| 9660 | } |
| 9661 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 9662 | if (DEBUG_ENERGY) { |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 9663 | Slog.d(TAG, " New RxPower: " + leftOverRxTimeMs + " ms"); |
| 9664 | Slog.d(TAG, " New TxPower: " + leftOverTxTimeMs + " ms"); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 9665 | } |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 9666 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 9667 | // Distribute the remaining Tx power appropriately between all apps that transmitted |
| 9668 | // packets. |
| 9669 | for (int i = 0; i < txPackets.size(); i++) { |
| 9670 | final Uid uid = getUidStatsLocked(txPackets.keyAt(i)); |
| 9671 | final long myTxTimeMs = (txPackets.valueAt(i) * leftOverTxTimeMs) |
| 9672 | / totalTxPackets; |
| 9673 | if (DEBUG_ENERGY) { |
| 9674 | Slog.d(TAG, " TxTime for UID " + uid.getUid() + ": " + myTxTimeMs + " ms"); |
| 9675 | } |
| 9676 | uid.getOrCreateWifiControllerActivityLocked().getTxTimeCounters()[0] |
| 9677 | .addCountLocked(myTxTimeMs); |
| 9678 | } |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 9679 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 9680 | // Distribute the remaining Rx power appropriately between all apps that received |
| 9681 | // packets. |
| 9682 | for (int i = 0; i < rxPackets.size(); i++) { |
| 9683 | final Uid uid = getUidStatsLocked(rxPackets.keyAt(i)); |
| 9684 | final long myRxTimeMs = (rxPackets.valueAt(i) * leftOverRxTimeMs) |
| 9685 | / totalRxPackets; |
| 9686 | if (DEBUG_ENERGY) { |
| 9687 | Slog.d(TAG, " RxTime for UID " + uid.getUid() + ": " + myRxTimeMs + " ms"); |
| 9688 | } |
| 9689 | uid.getOrCreateWifiControllerActivityLocked().getRxTimeCounter() |
| 9690 | .addCountLocked(myRxTimeMs); |
| 9691 | } |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 9692 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 9693 | // Any left over power use will be picked up by the WiFi category in BatteryStatsHelper. |
| 9694 | |
| 9695 | |
| 9696 | // Update WiFi controller stats. |
| 9697 | mWifiActivity.getRxTimeCounter().addCountLocked(info.getControllerRxTimeMillis()); |
| 9698 | mWifiActivity.getTxTimeCounters()[0].addCountLocked( |
| 9699 | info.getControllerTxTimeMillis()); |
| 9700 | mWifiActivity.getIdleTimeCounter().addCountLocked( |
| 9701 | info.getControllerIdleTimeMillis()); |
| 9702 | |
| 9703 | // POWER_WIFI_CONTROLLER_OPERATING_VOLTAGE is measured in mV, so convert to V. |
| 9704 | final double opVolt = mPowerProfile.getAveragePower( |
| 9705 | PowerProfile.POWER_WIFI_CONTROLLER_OPERATING_VOLTAGE) / 1000.0; |
| 9706 | if (opVolt != 0) { |
| 9707 | // We store the power drain as mAms. |
| 9708 | mWifiActivity.getPowerCounter().addCountLocked( |
| 9709 | (long) (info.getControllerEnergyUsed() / opVolt)); |
| 9710 | } |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 9711 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 9712 | } |
| 9713 | } |
| 9714 | |
| 9715 | /** |
| 9716 | * Distribute Cell radio energy info and network traffic to apps. |
| 9717 | */ |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 9718 | public void updateMobileRadioState(@Nullable final ModemActivityInfo activityInfo) { |
Adam Lesinski | a7c90c8 | 2015-06-18 14:52:24 -0700 | [diff] [blame] | 9719 | if (DEBUG_ENERGY) { |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 9720 | Slog.d(TAG, "Updating mobile radio stats with " + activityInfo); |
Adam Lesinski | a7c90c8 | 2015-06-18 14:52:24 -0700 | [diff] [blame] | 9721 | } |
| 9722 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 9723 | // Grab a separate lock to acquire the network stats, which may do I/O. |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 9724 | NetworkStats delta = null; |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 9725 | synchronized (mModemNetworkLock) { |
| 9726 | final NetworkStats latestStats = readNetworkStatsLocked(mModemIfaces); |
| 9727 | if (latestStats != null) { |
| 9728 | delta = NetworkStats.subtract(latestStats, mLastModemNetworkStats, null, null, |
| 9729 | mNetworkStatsPool.acquire()); |
| 9730 | mNetworkStatsPool.release(mLastModemNetworkStats); |
| 9731 | mLastModemNetworkStats = latestStats; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 9732 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 9733 | } |
| 9734 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 9735 | synchronized (this) { |
| 9736 | if (!mOnBatteryInternal) { |
| 9737 | if (delta != null) { |
| 9738 | mNetworkStatsPool.release(delta); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 9739 | } |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 9740 | return; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 9741 | } |
| 9742 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 9743 | final long elapsedRealtimeMs = SystemClock.elapsedRealtime(); |
| 9744 | long radioTime = mMobileRadioActivePerAppTimer.getTimeSinceMarkLocked( |
| 9745 | elapsedRealtimeMs * 1000); |
| 9746 | mMobileRadioActivePerAppTimer.setMark(elapsedRealtimeMs); |
| 9747 | |
| 9748 | long totalRxPackets = 0; |
| 9749 | long totalTxPackets = 0; |
| 9750 | if (delta != null) { |
| 9751 | NetworkStats.Entry entry = new NetworkStats.Entry(); |
| 9752 | final int size = delta.size(); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 9753 | for (int i = 0; i < size; i++) { |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 9754 | entry = delta.getValues(i, entry); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 9755 | if (entry.rxPackets == 0 && entry.txPackets == 0) { |
| 9756 | continue; |
| 9757 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 9758 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 9759 | if (DEBUG_ENERGY) { |
| 9760 | Slog.d(TAG, "Mobile uid " + entry.uid + ": delta rx=" + entry.rxBytes |
| 9761 | + " tx=" + entry.txBytes + " rxPackets=" + entry.rxPackets |
| 9762 | + " txPackets=" + entry.txPackets); |
| 9763 | } |
| 9764 | |
| 9765 | totalRxPackets += entry.rxPackets; |
| 9766 | totalTxPackets += entry.txPackets; |
| 9767 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 9768 | final Uid u = getUidStatsLocked(mapUid(entry.uid)); |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 9769 | u.noteNetworkActivityLocked(NETWORK_MOBILE_RX_DATA, entry.rxBytes, |
| 9770 | entry.rxPackets); |
| 9771 | u.noteNetworkActivityLocked(NETWORK_MOBILE_TX_DATA, entry.txBytes, |
| 9772 | entry.txPackets); |
| 9773 | if (entry.set == NetworkStats.SET_DEFAULT) { // Background transfers |
| 9774 | u.noteNetworkActivityLocked(NETWORK_MOBILE_BG_RX_DATA, |
| 9775 | entry.rxBytes, entry.rxPackets); |
| 9776 | u.noteNetworkActivityLocked(NETWORK_MOBILE_BG_TX_DATA, |
| 9777 | entry.txBytes, entry.txPackets); |
| 9778 | } |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 9779 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 9780 | mNetworkByteActivityCounters[NETWORK_MOBILE_RX_DATA].addCountLocked( |
| 9781 | entry.rxBytes); |
| 9782 | mNetworkByteActivityCounters[NETWORK_MOBILE_TX_DATA].addCountLocked( |
| 9783 | entry.txBytes); |
| 9784 | mNetworkPacketActivityCounters[NETWORK_MOBILE_RX_DATA].addCountLocked( |
| 9785 | entry.rxPackets); |
| 9786 | mNetworkPacketActivityCounters[NETWORK_MOBILE_TX_DATA].addCountLocked( |
| 9787 | entry.txPackets); |
| 9788 | } |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 9789 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 9790 | // Now distribute proportional blame to the apps that did networking. |
| 9791 | long totalPackets = totalRxPackets + totalTxPackets; |
| 9792 | if (totalPackets > 0) { |
| 9793 | for (int i = 0; i < size; i++) { |
| 9794 | entry = delta.getValues(i, entry); |
| 9795 | if (entry.rxPackets == 0 && entry.txPackets == 0) { |
| 9796 | continue; |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 9797 | } |
| 9798 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 9799 | final Uid u = getUidStatsLocked(mapUid(entry.uid)); |
| 9800 | |
| 9801 | // Distribute total radio active time in to this app. |
| 9802 | final long appPackets = entry.rxPackets + entry.txPackets; |
| 9803 | final long appRadioTime = (radioTime * appPackets) / totalPackets; |
| 9804 | u.noteMobileRadioActiveTimeLocked(appRadioTime); |
| 9805 | |
| 9806 | // Remove this app from the totals, so that we don't lose any time |
| 9807 | // due to rounding. |
| 9808 | radioTime -= appRadioTime; |
| 9809 | totalPackets -= appPackets; |
| 9810 | |
| 9811 | if (activityInfo != null) { |
| 9812 | ControllerActivityCounterImpl activityCounter = |
| 9813 | u.getOrCreateModemControllerActivityLocked(); |
| 9814 | if (totalRxPackets > 0 && entry.rxPackets > 0) { |
| 9815 | final long rxMs = (entry.rxPackets * activityInfo.getRxTimeMillis()) |
| 9816 | / totalRxPackets; |
| 9817 | activityCounter.getRxTimeCounter().addCountLocked(rxMs); |
| 9818 | } |
| 9819 | |
| 9820 | if (totalTxPackets > 0 && entry.txPackets > 0) { |
| 9821 | for (int lvl = 0; lvl < ModemActivityInfo.TX_POWER_LEVELS; lvl++) { |
| 9822 | long txMs = |
| 9823 | entry.txPackets * activityInfo.getTxTimeMillis()[lvl]; |
| 9824 | txMs /= totalTxPackets; |
| 9825 | activityCounter.getTxTimeCounters()[lvl].addCountLocked(txMs); |
| 9826 | } |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 9827 | } |
| 9828 | } |
| 9829 | } |
| 9830 | } |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 9831 | |
| 9832 | if (radioTime > 0) { |
| 9833 | // Whoops, there is some radio time we can't blame on an app! |
| 9834 | mMobileRadioActiveUnknownTime.addCountLocked(radioTime); |
| 9835 | mMobileRadioActiveUnknownCount.addCountLocked(1); |
| 9836 | } |
| 9837 | |
| 9838 | mNetworkStatsPool.release(delta); |
| 9839 | delta = null; |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 9840 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 9841 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 9842 | if (activityInfo != null) { |
| 9843 | mHasModemReporting = true; |
| 9844 | mModemActivity.getIdleTimeCounter().addCountLocked( |
| 9845 | activityInfo.getIdleTimeMillis()); |
| 9846 | mModemActivity.getRxTimeCounter().addCountLocked(activityInfo.getRxTimeMillis()); |
| 9847 | for (int lvl = 0; lvl < ModemActivityInfo.TX_POWER_LEVELS; lvl++) { |
| 9848 | mModemActivity.getTxTimeCounters()[lvl] |
| 9849 | .addCountLocked(activityInfo.getTxTimeMillis()[lvl]); |
| 9850 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 9851 | |
Adam Lesinski | 14ae39a | 2017-05-26 11:50:40 -0700 | [diff] [blame] | 9852 | // POWER_MODEM_CONTROLLER_OPERATING_VOLTAGE is measured in mV, so convert to V. |
| 9853 | final double opVolt = mPowerProfile.getAveragePower( |
| 9854 | PowerProfile.POWER_MODEM_CONTROLLER_OPERATING_VOLTAGE) / 1000.0; |
| 9855 | if (opVolt != 0) { |
| 9856 | // We store the power drain as mAms. |
| 9857 | mModemActivity.getPowerCounter().addCountLocked( |
| 9858 | (long) (activityInfo.getEnergyUsed() / opVolt)); |
| 9859 | } |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 9860 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 9861 | } |
| 9862 | } |
| 9863 | |
| 9864 | /** |
| 9865 | * Distribute Bluetooth energy info and network traffic to apps. |
| 9866 | * @param info The energy information from the bluetooth controller. |
| 9867 | */ |
| 9868 | public void updateBluetoothStateLocked(@Nullable final BluetoothActivityEnergyInfo info) { |
Adam Lesinski | a7c90c8 | 2015-06-18 14:52:24 -0700 | [diff] [blame] | 9869 | if (DEBUG_ENERGY) { |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 9870 | Slog.d(TAG, "Updating bluetooth stats: " + info); |
Adam Lesinski | a7c90c8 | 2015-06-18 14:52:24 -0700 | [diff] [blame] | 9871 | } |
| 9872 | |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 9873 | if (info == null || !mOnBatteryInternal) { |
| 9874 | return; |
| 9875 | } |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 9876 | |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 9877 | mHasBluetoothReporting = true; |
| 9878 | |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 9879 | final long elapsedRealtimeMs = mClocks.elapsedRealtime(); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 9880 | final long rxTimeMs = info.getControllerRxTimeMillis(); |
| 9881 | final long txTimeMs = info.getControllerTxTimeMillis(); |
| 9882 | |
| 9883 | if (DEBUG_ENERGY) { |
| 9884 | Slog.d(TAG, "------ BEGIN BLE power blaming ------"); |
| 9885 | Slog.d(TAG, " Tx Time: " + txTimeMs + " ms"); |
| 9886 | Slog.d(TAG, " Rx Time: " + rxTimeMs + " ms"); |
| 9887 | Slog.d(TAG, " Idle Time: " + info.getControllerIdleTimeMillis() + " ms"); |
| 9888 | } |
| 9889 | |
| 9890 | long totalScanTimeMs = 0; |
| 9891 | |
| 9892 | final int uidCount = mUidStats.size(); |
| 9893 | for (int i = 0; i < uidCount; i++) { |
| 9894 | final Uid u = mUidStats.valueAt(i); |
| 9895 | if (u.mBluetoothScanTimer == null) { |
| 9896 | continue; |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 9897 | } |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 9898 | |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 9899 | totalScanTimeMs += u.mBluetoothScanTimer.getTimeSinceMarkLocked( |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 9900 | elapsedRealtimeMs * 1000) / 1000; |
| 9901 | } |
| 9902 | |
| 9903 | final boolean normalizeScanRxTime = (totalScanTimeMs > rxTimeMs); |
| 9904 | final boolean normalizeScanTxTime = (totalScanTimeMs > txTimeMs); |
| 9905 | |
| 9906 | if (DEBUG_ENERGY) { |
| 9907 | Slog.d(TAG, "Normalizing scan power for RX=" + normalizeScanRxTime |
| 9908 | + " TX=" + normalizeScanTxTime); |
| 9909 | } |
| 9910 | |
| 9911 | long leftOverRxTimeMs = rxTimeMs; |
| 9912 | long leftOverTxTimeMs = txTimeMs; |
| 9913 | |
| 9914 | for (int i = 0; i < uidCount; i++) { |
| 9915 | final Uid u = mUidStats.valueAt(i); |
| 9916 | if (u.mBluetoothScanTimer == null) { |
| 9917 | continue; |
| 9918 | } |
| 9919 | |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 9920 | long scanTimeSinceMarkMs = u.mBluetoothScanTimer.getTimeSinceMarkLocked( |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 9921 | elapsedRealtimeMs * 1000) / 1000; |
| 9922 | if (scanTimeSinceMarkMs > 0) { |
| 9923 | // Set the new mark so that next time we get new data since this point. |
| 9924 | u.mBluetoothScanTimer.setMark(elapsedRealtimeMs); |
| 9925 | |
| 9926 | long scanTimeRxSinceMarkMs = scanTimeSinceMarkMs; |
| 9927 | long scanTimeTxSinceMarkMs = scanTimeSinceMarkMs; |
| 9928 | |
| 9929 | if (normalizeScanRxTime) { |
| 9930 | // Scan time is longer than the total rx time in the controller, |
| 9931 | // so distribute the scan time proportionately. This means regular traffic |
| 9932 | // will not blamed, but scans are more expensive anyways. |
| 9933 | scanTimeRxSinceMarkMs = (rxTimeMs * scanTimeRxSinceMarkMs) / totalScanTimeMs; |
| 9934 | } |
| 9935 | |
| 9936 | if (normalizeScanTxTime) { |
| 9937 | // Scan time is longer than the total tx time in the controller, |
| 9938 | // so distribute the scan time proportionately. This means regular traffic |
| 9939 | // will not blamed, but scans are more expensive anyways. |
| 9940 | scanTimeTxSinceMarkMs = (txTimeMs * scanTimeTxSinceMarkMs) / totalScanTimeMs; |
| 9941 | } |
| 9942 | |
| 9943 | final ControllerActivityCounterImpl counter = |
| 9944 | u.getOrCreateBluetoothControllerActivityLocked(); |
| 9945 | counter.getRxTimeCounter().addCountLocked(scanTimeRxSinceMarkMs); |
| 9946 | counter.getTxTimeCounters()[0].addCountLocked(scanTimeTxSinceMarkMs); |
| 9947 | |
| 9948 | leftOverRxTimeMs -= scanTimeRxSinceMarkMs; |
| 9949 | leftOverTxTimeMs -= scanTimeTxSinceMarkMs; |
| 9950 | } |
| 9951 | } |
| 9952 | |
| 9953 | if (DEBUG_ENERGY) { |
| 9954 | Slog.d(TAG, "Left over time for traffic RX=" + leftOverRxTimeMs |
| 9955 | + " TX=" + leftOverTxTimeMs); |
| 9956 | } |
| 9957 | |
| 9958 | // |
| 9959 | // Now distribute blame to apps that did bluetooth traffic. |
| 9960 | // |
| 9961 | |
| 9962 | long totalTxBytes = 0; |
| 9963 | long totalRxBytes = 0; |
| 9964 | |
| 9965 | final UidTraffic[] uidTraffic = info.getUidTraffic(); |
| 9966 | final int numUids = uidTraffic != null ? uidTraffic.length : 0; |
| 9967 | for (int i = 0; i < numUids; i++) { |
| 9968 | final UidTraffic traffic = uidTraffic[i]; |
| 9969 | |
| 9970 | // Add to the global counters. |
| 9971 | mNetworkByteActivityCounters[NETWORK_BT_RX_DATA].addCountLocked( |
| 9972 | traffic.getRxBytes()); |
| 9973 | mNetworkByteActivityCounters[NETWORK_BT_TX_DATA].addCountLocked( |
| 9974 | traffic.getTxBytes()); |
| 9975 | |
| 9976 | // Add to the UID counters. |
| 9977 | final Uid u = getUidStatsLocked(mapUid(traffic.getUid())); |
| 9978 | u.noteNetworkActivityLocked(NETWORK_BT_RX_DATA, traffic.getRxBytes(), 0); |
| 9979 | u.noteNetworkActivityLocked(NETWORK_BT_TX_DATA, traffic.getTxBytes(), 0); |
| 9980 | |
| 9981 | // Calculate the total traffic. |
| 9982 | totalTxBytes += traffic.getTxBytes(); |
| 9983 | totalRxBytes += traffic.getRxBytes(); |
| 9984 | } |
| 9985 | |
| 9986 | if ((totalTxBytes != 0 || totalRxBytes != 0) && |
| 9987 | (leftOverRxTimeMs != 0 || leftOverTxTimeMs != 0)) { |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 9988 | for (int i = 0; i < numUids; i++) { |
| 9989 | final UidTraffic traffic = uidTraffic[i]; |
| 9990 | |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 9991 | final Uid u = getUidStatsLocked(mapUid(traffic.getUid())); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 9992 | final ControllerActivityCounterImpl counter = |
| 9993 | u.getOrCreateBluetoothControllerActivityLocked(); |
| 9994 | |
| 9995 | if (totalRxBytes > 0 && traffic.getRxBytes() > 0) { |
| 9996 | final long timeRxMs = (leftOverRxTimeMs * traffic.getRxBytes()) / totalRxBytes; |
| 9997 | |
| 9998 | if (DEBUG_ENERGY) { |
| 9999 | Slog.d(TAG, "UID=" + traffic.getUid() + " rx_bytes=" + traffic.getRxBytes() |
| 10000 | + " rx_time=" + timeRxMs); |
| 10001 | } |
| 10002 | counter.getRxTimeCounter().addCountLocked(timeRxMs); |
| 10003 | leftOverRxTimeMs -= timeRxMs; |
| 10004 | } |
| 10005 | |
| 10006 | if (totalTxBytes > 0 && traffic.getTxBytes() > 0) { |
| 10007 | final long timeTxMs = (leftOverTxTimeMs * traffic.getTxBytes()) / totalTxBytes; |
| 10008 | |
| 10009 | if (DEBUG_ENERGY) { |
| 10010 | Slog.d(TAG, "UID=" + traffic.getUid() + " tx_bytes=" + traffic.getTxBytes() |
| 10011 | + " tx_time=" + timeTxMs); |
| 10012 | } |
| 10013 | |
| 10014 | counter.getTxTimeCounters()[0].addCountLocked(timeTxMs); |
| 10015 | leftOverTxTimeMs -= timeTxMs; |
| 10016 | } |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 10017 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 10018 | } |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 10019 | |
| 10020 | mBluetoothActivity.getRxTimeCounter().addCountLocked( |
| 10021 | info.getControllerRxTimeMillis()); |
| 10022 | mBluetoothActivity.getTxTimeCounters()[0].addCountLocked( |
| 10023 | info.getControllerTxTimeMillis()); |
| 10024 | mBluetoothActivity.getIdleTimeCounter().addCountLocked( |
| 10025 | info.getControllerIdleTimeMillis()); |
| 10026 | |
| 10027 | // POWER_BLUETOOTH_CONTROLLER_OPERATING_VOLTAGE is measured in mV, so convert to V. |
| 10028 | final double opVolt = mPowerProfile.getAveragePower( |
| 10029 | PowerProfile.POWER_BLUETOOTH_CONTROLLER_OPERATING_VOLTAGE) / 1000.0; |
| 10030 | if (opVolt != 0) { |
| 10031 | // We store the power drain as mAms. |
| 10032 | mBluetoothActivity.getPowerCounter().addCountLocked( |
| 10033 | (long) (info.getControllerEnergyUsed() / opVolt)); |
| 10034 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 10035 | } |
| 10036 | |
| 10037 | /** |
| 10038 | * Read and distribute kernel wake lock use across apps. |
| 10039 | */ |
| 10040 | public void updateKernelWakelocksLocked() { |
| 10041 | final KernelWakelockStats wakelockStats = mKernelWakelockReader.readKernelWakelockStats( |
| 10042 | mTmpWakelockStats); |
| 10043 | if (wakelockStats == null) { |
| 10044 | // Not crashing might make board bringup easier. |
| 10045 | Slog.w(TAG, "Couldn't get kernel wake lock stats"); |
| 10046 | return; |
| 10047 | } |
| 10048 | |
| 10049 | for (Map.Entry<String, KernelWakelockStats.Entry> ent : wakelockStats.entrySet()) { |
| 10050 | String name = ent.getKey(); |
| 10051 | KernelWakelockStats.Entry kws = ent.getValue(); |
| 10052 | |
| 10053 | SamplingTimer kwlt = mKernelWakelockStats.get(name); |
| 10054 | if (kwlt == null) { |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 10055 | kwlt = new SamplingTimer(mClocks, mOnBatteryScreenOffTimeBase); |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 10056 | mKernelWakelockStats.put(name, kwlt); |
| 10057 | } |
Adam Lesinski | d84ad30 | 2016-05-17 18:31:02 -0700 | [diff] [blame] | 10058 | |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 10059 | kwlt.update(kws.mTotalTime, kws.mCount); |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 10060 | kwlt.setUpdateVersion(kws.mVersion); |
| 10061 | } |
| 10062 | |
Adam Lesinski | fbabe7d | 2015-08-03 14:37:38 -0700 | [diff] [blame] | 10063 | int numWakelocksSetStale = 0; |
Adam Lesinski | d84ad30 | 2016-05-17 18:31:02 -0700 | [diff] [blame] | 10064 | // Set timers to stale if they didn't appear in /d/wakeup_sources (or /proc/wakelocks) |
| 10065 | // this time. |
| 10066 | for (Map.Entry<String, SamplingTimer> ent : mKernelWakelockStats.entrySet()) { |
| 10067 | SamplingTimer st = ent.getValue(); |
| 10068 | if (st.getUpdateVersion() != wakelockStats.kernelWakelockVersion) { |
| 10069 | st.endSample(); |
| 10070 | numWakelocksSetStale++; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 10071 | } |
| 10072 | } |
Adam Lesinski | fbabe7d | 2015-08-03 14:37:38 -0700 | [diff] [blame] | 10073 | |
Adam Lesinski | d84ad30 | 2016-05-17 18:31:02 -0700 | [diff] [blame] | 10074 | // Record whether we've seen a non-zero time (for debugging b/22716723). |
| 10075 | if (wakelockStats.isEmpty()) { |
Adam Lesinski | fbabe7d | 2015-08-03 14:37:38 -0700 | [diff] [blame] | 10076 | Slog.wtf(TAG, "All kernel wakelocks had time of zero"); |
| 10077 | } |
| 10078 | |
| 10079 | if (numWakelocksSetStale == mKernelWakelockStats.size()) { |
| 10080 | Slog.wtf(TAG, "All kernel wakelocks were set stale. new version=" + |
| 10081 | wakelockStats.kernelWakelockVersion); |
| 10082 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 10083 | } |
| 10084 | |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 10085 | // We use an anonymous class to access these variables, |
| 10086 | // so they can't live on the stack or they'd have to be |
| 10087 | // final MutableLong objects (more allocations). |
| 10088 | // Used in updateCpuTimeLocked(). |
| 10089 | long mTempTotalCpuUserTimeUs; |
| 10090 | long mTempTotalCpuSystemTimeUs; |
| 10091 | |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 10092 | /** |
James Carr | 3a22605 | 2016-07-01 14:49:52 -0700 | [diff] [blame] | 10093 | * Reads the newest memory stats from the kernel. |
| 10094 | */ |
| 10095 | public void updateKernelMemoryBandwidthLocked() { |
| 10096 | mKernelMemoryBandwidthStats.updateStats(); |
| 10097 | LongSparseLongArray bandwidthEntries = mKernelMemoryBandwidthStats.getBandwidthEntries(); |
| 10098 | final int bandwidthEntryCount = bandwidthEntries.size(); |
| 10099 | int index; |
| 10100 | for (int i = 0; i < bandwidthEntryCount; i++) { |
| 10101 | SamplingTimer timer; |
| 10102 | if ((index = mKernelMemoryStats.indexOfKey(bandwidthEntries.keyAt(i))) >= 0) { |
| 10103 | timer = mKernelMemoryStats.valueAt(index); |
| 10104 | } else { |
| 10105 | timer = new SamplingTimer(mClocks, mOnBatteryTimeBase); |
| 10106 | mKernelMemoryStats.put(bandwidthEntries.keyAt(i), timer); |
| 10107 | } |
| 10108 | timer.update(bandwidthEntries.valueAt(i), 1); |
| 10109 | if (DEBUG_MEMORY) { |
| 10110 | Slog.d(TAG, String.format("Added entry %d and updated timer to: " |
| 10111 | + "mUnpluggedReportedTotalTime %d size %d", bandwidthEntries.keyAt(i), |
| 10112 | mKernelMemoryStats.get( |
| 10113 | bandwidthEntries.keyAt(i)).mUnpluggedReportedTotalTime, |
| 10114 | mKernelMemoryStats.size())); |
| 10115 | } |
| 10116 | } |
| 10117 | } |
| 10118 | |
| 10119 | /** |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 10120 | * Read and distribute CPU usage across apps. If their are partial wakelocks being held |
| 10121 | * and we are on battery with screen off, we give more of the cpu time to those apps holding |
| 10122 | * 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] | 10123 | */ |
Sudheer Shanka | 671985f | 2017-05-19 11:33:42 -0700 | [diff] [blame] | 10124 | public void updateCpuTimeLocked(boolean updateCpuFreqData) { |
Adam Lesinski | 52290c9c | 2015-09-21 16:54:52 -0700 | [diff] [blame] | 10125 | if (mPowerProfile == null) { |
| 10126 | return; |
| 10127 | } |
| 10128 | |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 10129 | if (DEBUG_ENERGY_CPU) { |
| 10130 | Slog.d(TAG, "!Cpu updating!"); |
| 10131 | } |
| 10132 | |
| 10133 | // Holding a wakelock costs more than just using the cpu. |
| 10134 | // Currently, we assign only half the cpu time to an app that is running but |
| 10135 | // not holding a wakelock. The apps holding wakelocks get the rest of the blame. |
| 10136 | // If no app is holding a wakelock, then the distribution is normal. |
| 10137 | final int wakelockWeight = 50; |
| 10138 | |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 10139 | // Read the time spent for each cluster at various cpu frequencies. |
| 10140 | final long[][] clusterSpeeds = new long[mKernelCpuSpeedReaders.length][]; |
| 10141 | for (int cluster = 0; cluster < mKernelCpuSpeedReaders.length; cluster++) { |
| 10142 | clusterSpeeds[cluster] = mKernelCpuSpeedReaders[cluster].readDelta(); |
| 10143 | } |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 10144 | |
| 10145 | int numWakelocks = 0; |
| 10146 | |
| 10147 | // Calculate how many wakelocks we have to distribute amongst. The system is excluded. |
| 10148 | // Only distribute cpu power to wakelocks if the screen is off and we're on battery. |
| 10149 | final int numPartialTimers = mPartialTimers.size(); |
| 10150 | if (mOnBatteryScreenOffTimeBase.isRunning()) { |
| 10151 | for (int i = 0; i < numPartialTimers; i++) { |
| 10152 | final StopwatchTimer timer = mPartialTimers.get(i); |
| 10153 | if (timer.mInList && timer.mUid != null && timer.mUid.mUid != Process.SYSTEM_UID) { |
| 10154 | // Since the collection and blaming of wakelocks can be scheduled to run after |
| 10155 | // some delay, the mPartialTimers list may have new entries. We can't blame |
| 10156 | // the newly added timer for past cpu time, so we only consider timers that |
| 10157 | // were present for one round of collection. Once a timer has gone through |
| 10158 | // a round of collection, its mInList field is set to true. |
| 10159 | numWakelocks++; |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 10160 | } |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 10161 | } |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 10162 | } |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 10163 | |
| 10164 | final int numWakelocksF = numWakelocks; |
| 10165 | mTempTotalCpuUserTimeUs = 0; |
| 10166 | mTempTotalCpuSystemTimeUs = 0; |
| 10167 | |
| 10168 | // Read the CPU data for each UID. This will internally generate a snapshot so next time |
| 10169 | // we read, we get a delta. If we are to distribute the cpu time, then do so. Otherwise |
| 10170 | // we just ignore the data. |
Amith Yamasani | d0ddeba | 2017-05-26 09:46:58 -0700 | [diff] [blame] | 10171 | final long startTimeMs = mClocks.uptimeMillis(); |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 10172 | mKernelUidCpuTimeReader.readDelta(!mOnBatteryInternal ? null : |
| 10173 | new KernelUidCpuTimeReader.Callback() { |
| 10174 | @Override |
Adam Lesinski | d4abd1e | 2017-04-12 11:29:13 -0700 | [diff] [blame] | 10175 | public void onUidCpuTime(int uid, long userTimeUs, long systemTimeUs) { |
Sudheer Shanka | ea87a4b | 2017-06-02 16:48:13 -0700 | [diff] [blame] | 10176 | uid = mapUid(uid); |
| 10177 | if (Process.isIsolated(uid)) { |
| 10178 | // This could happen if the isolated uid mapping was removed before |
| 10179 | // that process was actually killed. |
| 10180 | mKernelUidCpuTimeReader.removeUid(uid); |
| 10181 | Slog.d(TAG, "Got readings for an isolated uid with" |
| 10182 | + " no mapping to owning uid: " + uid); |
| 10183 | return; |
| 10184 | } |
| 10185 | final Uid u = getUidStatsLocked(uid); |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 10186 | |
| 10187 | // Accumulate the total system and user time. |
| 10188 | mTempTotalCpuUserTimeUs += userTimeUs; |
| 10189 | mTempTotalCpuSystemTimeUs += systemTimeUs; |
| 10190 | |
| 10191 | StringBuilder sb = null; |
| 10192 | if (DEBUG_ENERGY_CPU) { |
| 10193 | sb = new StringBuilder(); |
| 10194 | sb.append(" got time for uid=").append(u.mUid).append(": u="); |
| 10195 | TimeUtils.formatDuration(userTimeUs / 1000, sb); |
| 10196 | sb.append(" s="); |
| 10197 | TimeUtils.formatDuration(systemTimeUs / 1000, sb); |
Adam Lesinski | d4abd1e | 2017-04-12 11:29:13 -0700 | [diff] [blame] | 10198 | sb.append("\n"); |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 10199 | } |
| 10200 | |
| 10201 | if (numWakelocksF > 0) { |
| 10202 | // We have wakelocks being held, so only give a portion of the |
| 10203 | // time to the process. The rest will be distributed among wakelock |
| 10204 | // holders. |
| 10205 | userTimeUs = (userTimeUs * wakelockWeight) / 100; |
| 10206 | systemTimeUs = (systemTimeUs * wakelockWeight) / 100; |
| 10207 | } |
| 10208 | |
| 10209 | if (sb != null) { |
| 10210 | sb.append(" adding to uid=").append(u.mUid).append(": u="); |
| 10211 | TimeUtils.formatDuration(userTimeUs / 1000, sb); |
| 10212 | sb.append(" s="); |
| 10213 | TimeUtils.formatDuration(systemTimeUs / 1000, sb); |
| 10214 | Slog.d(TAG, sb.toString()); |
| 10215 | } |
| 10216 | |
| 10217 | u.mUserCpuTime.addCountLocked(userTimeUs); |
| 10218 | u.mSystemCpuTime.addCountLocked(systemTimeUs); |
| 10219 | |
| 10220 | // Add the cpu speeds to this UID. These are used as a ratio |
| 10221 | // for computing the power this UID used. |
Adam Lesinski | 52290c9c | 2015-09-21 16:54:52 -0700 | [diff] [blame] | 10222 | final int numClusters = mPowerProfile.getNumCpuClusters(); |
| 10223 | if (u.mCpuClusterSpeed == null || u.mCpuClusterSpeed.length != |
| 10224 | numClusters) { |
| 10225 | u.mCpuClusterSpeed = new LongSamplingCounter[numClusters][]; |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 10226 | } |
| 10227 | |
| 10228 | for (int cluster = 0; cluster < clusterSpeeds.length; cluster++) { |
Adam Lesinski | 52290c9c | 2015-09-21 16:54:52 -0700 | [diff] [blame] | 10229 | final int speedsInCluster = mPowerProfile.getNumSpeedStepsInCpuCluster( |
| 10230 | cluster); |
| 10231 | if (u.mCpuClusterSpeed[cluster] == null || speedsInCluster != |
| 10232 | u.mCpuClusterSpeed[cluster].length) { |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 10233 | u.mCpuClusterSpeed[cluster] = |
Adam Lesinski | 52290c9c | 2015-09-21 16:54:52 -0700 | [diff] [blame] | 10234 | new LongSamplingCounter[speedsInCluster]; |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 10235 | } |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 10236 | |
| 10237 | final LongSamplingCounter[] cpuSpeeds = u.mCpuClusterSpeed[cluster]; |
| 10238 | for (int speed = 0; speed < clusterSpeeds[cluster].length; speed++) { |
| 10239 | if (cpuSpeeds[speed] == null) { |
| 10240 | cpuSpeeds[speed] = new LongSamplingCounter(mOnBatteryTimeBase); |
| 10241 | } |
| 10242 | cpuSpeeds[speed].addCountLocked(clusterSpeeds[cluster][speed]); |
| 10243 | } |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 10244 | } |
| 10245 | } |
| 10246 | }); |
| 10247 | |
Sudheer Shanka | 671985f | 2017-05-19 11:33:42 -0700 | [diff] [blame] | 10248 | if (updateCpuFreqData) { |
| 10249 | readKernelUidCpuFreqTimesLocked(); |
| 10250 | } |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 10251 | |
Amith Yamasani | d0ddeba | 2017-05-26 09:46:58 -0700 | [diff] [blame] | 10252 | final long elapse = (mClocks.uptimeMillis() - startTimeMs); |
Makoto Onuki | 3f8e297 | 2017-05-11 10:52:37 -0700 | [diff] [blame] | 10253 | if (DEBUG_ENERGY_CPU || (elapse >= 100)) { |
| 10254 | Slog.d(TAG, "Reading cpu stats took " + elapse + " ms"); |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 10255 | } |
| 10256 | |
| 10257 | if (mOnBatteryInternal && numWakelocks > 0) { |
| 10258 | // Distribute a portion of the total cpu time to wakelock holders. |
| 10259 | mTempTotalCpuUserTimeUs = (mTempTotalCpuUserTimeUs * (100 - wakelockWeight)) / 100; |
| 10260 | mTempTotalCpuSystemTimeUs = |
| 10261 | (mTempTotalCpuSystemTimeUs * (100 - wakelockWeight)) / 100; |
| 10262 | |
| 10263 | for (int i = 0; i < numPartialTimers; i++) { |
| 10264 | final StopwatchTimer timer = mPartialTimers.get(i); |
| 10265 | |
| 10266 | // The system does not share any blame, as it is usually holding the wakelock |
| 10267 | // on behalf of an app. |
| 10268 | if (timer.mInList && timer.mUid != null && timer.mUid.mUid != Process.SYSTEM_UID) { |
| 10269 | int userTimeUs = (int) (mTempTotalCpuUserTimeUs / numWakelocks); |
| 10270 | int systemTimeUs = (int) (mTempTotalCpuSystemTimeUs / numWakelocks); |
| 10271 | |
| 10272 | if (DEBUG_ENERGY_CPU) { |
| 10273 | StringBuilder sb = new StringBuilder(); |
| 10274 | sb.append(" Distributing wakelock uid=").append(timer.mUid.mUid) |
| 10275 | .append(": u="); |
| 10276 | TimeUtils.formatDuration(userTimeUs / 1000, sb); |
| 10277 | sb.append(" s="); |
| 10278 | TimeUtils.formatDuration(systemTimeUs / 1000, sb); |
| 10279 | Slog.d(TAG, sb.toString()); |
| 10280 | } |
| 10281 | |
| 10282 | timer.mUid.mUserCpuTime.addCountLocked(userTimeUs); |
| 10283 | timer.mUid.mSystemCpuTime.addCountLocked(systemTimeUs); |
| 10284 | |
| 10285 | final Uid.Proc proc = timer.mUid.getProcessStatsLocked("*wakelock*"); |
Adam Lesinski | 062e66c | 2015-07-14 12:02:44 -0700 | [diff] [blame] | 10286 | proc.addCpuTimeLocked(userTimeUs / 1000, systemTimeUs / 1000); |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 10287 | |
| 10288 | mTempTotalCpuUserTimeUs -= userTimeUs; |
| 10289 | mTempTotalCpuSystemTimeUs -= systemTimeUs; |
| 10290 | numWakelocks--; |
| 10291 | } |
| 10292 | } |
| 10293 | |
| 10294 | if (mTempTotalCpuUserTimeUs > 0 || mTempTotalCpuSystemTimeUs > 0) { |
| 10295 | // Anything left over is given to the system. |
| 10296 | if (DEBUG_ENERGY_CPU) { |
| 10297 | StringBuilder sb = new StringBuilder(); |
| 10298 | sb.append(" Distributing lost time to system: u="); |
| 10299 | TimeUtils.formatDuration(mTempTotalCpuUserTimeUs / 1000, sb); |
| 10300 | sb.append(" s="); |
| 10301 | TimeUtils.formatDuration(mTempTotalCpuSystemTimeUs / 1000, sb); |
| 10302 | Slog.d(TAG, sb.toString()); |
| 10303 | } |
| 10304 | |
| 10305 | final Uid u = getUidStatsLocked(Process.SYSTEM_UID); |
| 10306 | u.mUserCpuTime.addCountLocked(mTempTotalCpuUserTimeUs); |
| 10307 | u.mSystemCpuTime.addCountLocked(mTempTotalCpuSystemTimeUs); |
| 10308 | |
| 10309 | final Uid.Proc proc = u.getProcessStatsLocked("*lost*"); |
Adam Lesinski | 062e66c | 2015-07-14 12:02:44 -0700 | [diff] [blame] | 10310 | proc.addCpuTimeLocked((int) mTempTotalCpuUserTimeUs / 1000, |
| 10311 | (int) mTempTotalCpuSystemTimeUs / 1000); |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 10312 | } |
| 10313 | } |
| 10314 | |
| 10315 | // See if there is a difference in wakelocks between this collection and the last |
| 10316 | // collection. |
| 10317 | if (ArrayUtils.referenceEquals(mPartialTimers, mLastPartialTimers)) { |
| 10318 | // No difference, so each timer is now considered for the next collection. |
| 10319 | for (int i = 0; i < numPartialTimers; i++) { |
| 10320 | mPartialTimers.get(i).mInList = true; |
| 10321 | } |
| 10322 | } else { |
| 10323 | // The lists are different, meaning we added (or removed a timer) since the last |
| 10324 | // collection. |
| 10325 | final int numLastPartialTimers = mLastPartialTimers.size(); |
| 10326 | for (int i = 0; i < numLastPartialTimers; i++) { |
| 10327 | mLastPartialTimers.get(i).mInList = false; |
| 10328 | } |
| 10329 | mLastPartialTimers.clear(); |
| 10330 | |
| 10331 | // Mark the current timers as gone through a collection. |
| 10332 | for (int i = 0; i < numPartialTimers; i++) { |
| 10333 | final StopwatchTimer timer = mPartialTimers.get(i); |
| 10334 | timer.mInList = true; |
| 10335 | mLastPartialTimers.add(timer); |
| 10336 | } |
| 10337 | } |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 10338 | } |
| 10339 | |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 10340 | void readKernelUidCpuFreqTimesLocked() { |
| 10341 | mKernelUidCpuFreqTimeReader.readDelta(!mOnBatteryInternal ? null : |
| 10342 | new KernelUidCpuFreqTimeReader.Callback() { |
| 10343 | @Override |
| 10344 | public void onCpuFreqs(long[] cpuFreqs) { |
| 10345 | mCpuFreqs = cpuFreqs; |
| 10346 | } |
| 10347 | |
| 10348 | @Override |
| 10349 | public void onUidCpuFreqTime(int uid, long[] cpuFreqTimeMs) { |
Sudheer Shanka | ea87a4b | 2017-06-02 16:48:13 -0700 | [diff] [blame] | 10350 | uid = mapUid(uid); |
| 10351 | if (Process.isIsolated(uid)) { |
Sudheer Shanka | 6d8dcec | 2017-06-01 12:09:03 -0700 | [diff] [blame] | 10352 | mKernelUidCpuFreqTimeReader.removeUid(uid); |
| 10353 | Slog.d(TAG, "Got freq readings for an isolated uid with" |
| 10354 | + " no mapping to owning uid: " + uid); |
Sudheer Shanka | ea87a4b | 2017-06-02 16:48:13 -0700 | [diff] [blame] | 10355 | return; |
| 10356 | } |
| 10357 | final Uid u = getUidStatsLocked(uid); |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 10358 | if (u.mCpuFreqTimeMs == null) { |
| 10359 | u.mCpuFreqTimeMs = new LongSamplingCounterArray(mOnBatteryTimeBase); |
| 10360 | } |
| 10361 | u.mCpuFreqTimeMs.addCountLocked(cpuFreqTimeMs); |
| 10362 | if (u.mScreenOffCpuFreqTimeMs == null) { |
| 10363 | u.mScreenOffCpuFreqTimeMs = new LongSamplingCounterArray( |
| 10364 | mOnBatteryScreenOffTimeBase); |
| 10365 | } |
| 10366 | u.mScreenOffCpuFreqTimeMs.addCountLocked(cpuFreqTimeMs); |
| 10367 | } |
| 10368 | }); |
| 10369 | } |
| 10370 | |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 10371 | boolean setChargingLocked(boolean charging) { |
| 10372 | if (mCharging != charging) { |
| 10373 | mCharging = charging; |
| 10374 | if (charging) { |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 10375 | mHistoryCur.states2 |= HistoryItem.STATE2_CHARGING_FLAG; |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 10376 | } else { |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 10377 | mHistoryCur.states2 &= ~HistoryItem.STATE2_CHARGING_FLAG; |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 10378 | } |
| 10379 | mHandler.sendEmptyMessage(MSG_REPORT_CHARGING); |
| 10380 | return true; |
| 10381 | } |
| 10382 | return false; |
| 10383 | } |
| 10384 | |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 10385 | void setOnBatteryLocked(final long mSecRealtime, final long mSecUptime, final boolean onBattery, |
Adam Lesinski | f9b20a9 | 2016-06-17 17:30:01 -0700 | [diff] [blame] | 10386 | final int oldStatus, final int level, final int chargeUAh) { |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 10387 | boolean doWrite = false; |
| 10388 | Message m = mHandler.obtainMessage(MSG_REPORT_POWER_CHANGE); |
| 10389 | m.arg1 = onBattery ? 1 : 0; |
| 10390 | mHandler.sendMessage(m); |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 10391 | |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 10392 | final long uptime = mSecUptime * 1000; |
| 10393 | final long realtime = mSecRealtime * 1000; |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 10394 | final boolean screenOn = mScreenState == Display.STATE_ON; |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 10395 | if (onBattery) { |
| 10396 | // We will reset our status if we are unplugging after the |
| 10397 | // battery was last full, or the level is at 100, or |
| 10398 | // we have gone through a significant charge (from a very low |
| 10399 | // level to a now very high level). |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 10400 | boolean reset = false; |
Dianne Hackborn | 9a75543 | 2014-05-15 17:05:22 -0700 | [diff] [blame] | 10401 | if (!mNoAutoReset && (oldStatus == BatteryManager.BATTERY_STATUS_FULL |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 10402 | || level >= 90 |
Dianne Hackborn | fb3809c | 2014-09-29 18:31:22 -0700 | [diff] [blame] | 10403 | || (mDischargeCurrentLevel < 20 && level >= 80) |
| 10404 | || (getHighDischargeAmountSinceCharge() >= 200 |
| 10405 | && mHistoryBuffer.dataSize() >= MAX_HISTORY_BUFFER))) { |
Dianne Hackborn | 73d6a82 | 2014-09-29 10:52:47 -0700 | [diff] [blame] | 10406 | Slog.i(TAG, "Resetting battery stats: level=" + level + " status=" + oldStatus |
Dianne Hackborn | fb3809c | 2014-09-29 18:31:22 -0700 | [diff] [blame] | 10407 | + " dischargeLevel=" + mDischargeCurrentLevel |
Dianne Hackborn | 73d6a82 | 2014-09-29 10:52:47 -0700 | [diff] [blame] | 10408 | + " lowAmount=" + getLowDischargeAmountSinceCharge() |
| 10409 | + " highAmount=" + getHighDischargeAmountSinceCharge()); |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 10410 | // Before we write, collect a snapshot of the final aggregated |
| 10411 | // stats to be reported in the next checkin. Only do this if we have |
| 10412 | // a sufficient amount of data to make it interesting. |
| 10413 | if (getLowDischargeAmountSinceCharge() >= 20) { |
| 10414 | final Parcel parcel = Parcel.obtain(); |
| 10415 | writeSummaryToParcel(parcel, true); |
| 10416 | BackgroundThread.getHandler().post(new Runnable() { |
| 10417 | @Override public void run() { |
| 10418 | synchronized (mCheckinFile) { |
| 10419 | FileOutputStream stream = null; |
| 10420 | try { |
| 10421 | stream = mCheckinFile.startWrite(); |
| 10422 | stream.write(parcel.marshall()); |
| 10423 | stream.flush(); |
| 10424 | FileUtils.sync(stream); |
| 10425 | stream.close(); |
| 10426 | mCheckinFile.finishWrite(stream); |
| 10427 | } catch (IOException e) { |
| 10428 | Slog.w("BatteryStats", |
| 10429 | "Error writing checkin battery statistics", e); |
| 10430 | mCheckinFile.failWrite(stream); |
| 10431 | } finally { |
| 10432 | parcel.recycle(); |
| 10433 | } |
| 10434 | } |
| 10435 | } |
| 10436 | }); |
| 10437 | } |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 10438 | doWrite = true; |
| 10439 | resetAllStatsLocked(); |
Ying Wai (Daniel) Fan | 442ab76 | 2017-01-31 22:00:10 -0800 | [diff] [blame] | 10440 | if (chargeUAh > 0 && level > 0) { |
Adam Lesinski | f9b20a9 | 2016-06-17 17:30:01 -0700 | [diff] [blame] | 10441 | // 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] | 10442 | mEstimatedBatteryCapacity = (int) ((chargeUAh / 1000) / (level / 100.0)); |
Adam Lesinski | f9b20a9 | 2016-06-17 17:30:01 -0700 | [diff] [blame] | 10443 | } |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 10444 | mDischargeStartLevel = level; |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 10445 | reset = true; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 10446 | mDischargeStepTracker.init(); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10447 | } |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 10448 | if (mCharging) { |
| 10449 | setChargingLocked(false); |
| 10450 | } |
| 10451 | mLastChargingStateLevel = level; |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 10452 | mOnBattery = mOnBatteryInternal = true; |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 10453 | mLastDischargeStepLevel = level; |
Dianne Hackborn | 2932513 | 2014-05-21 15:01:03 -0700 | [diff] [blame] | 10454 | mMinDischargeStepLevel = level; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 10455 | mDischargeStepTracker.clearTime(); |
| 10456 | mDailyDischargeStepTracker.clearTime(); |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 10457 | mInitStepMode = mCurStepMode; |
| 10458 | mModStepMode = 0; |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 10459 | pullPendingStateUpdatesLocked(); |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 10460 | mHistoryCur.batteryLevel = (byte)level; |
| 10461 | mHistoryCur.states &= ~HistoryItem.STATE_BATTERY_PLUGGED_FLAG; |
| 10462 | if (DEBUG_HISTORY) Slog.v(TAG, "Battery unplugged to: " |
| 10463 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 10464 | if (reset) { |
| 10465 | mRecordingHistory = true; |
| 10466 | startRecordingHistory(mSecRealtime, mSecUptime, reset); |
| 10467 | } |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 10468 | addHistoryRecordLocked(mSecRealtime, mSecUptime); |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 10469 | mDischargeCurrentLevel = mDischargeUnplugLevel = level; |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 10470 | if (screenOn) { |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 10471 | mDischargeScreenOnUnplugLevel = level; |
| 10472 | mDischargeScreenOffUnplugLevel = 0; |
| 10473 | } else { |
| 10474 | mDischargeScreenOnUnplugLevel = 0; |
| 10475 | mDischargeScreenOffUnplugLevel = level; |
| 10476 | } |
| 10477 | mDischargeAmountScreenOn = 0; |
| 10478 | mDischargeAmountScreenOff = 0; |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 10479 | updateTimeBasesLocked(true, !screenOn, uptime, realtime); |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 10480 | } else { |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 10481 | mLastChargingStateLevel = level; |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 10482 | mOnBattery = mOnBatteryInternal = false; |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 10483 | pullPendingStateUpdatesLocked(); |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 10484 | mHistoryCur.batteryLevel = (byte)level; |
| 10485 | mHistoryCur.states |= HistoryItem.STATE_BATTERY_PLUGGED_FLAG; |
| 10486 | if (DEBUG_HISTORY) Slog.v(TAG, "Battery plugged to: " |
| 10487 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 10488 | addHistoryRecordLocked(mSecRealtime, mSecUptime); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 10489 | mDischargeCurrentLevel = mDischargePlugLevel = level; |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 10490 | if (level < mDischargeUnplugLevel) { |
| 10491 | mLowDischargeAmountSinceCharge += mDischargeUnplugLevel-level-1; |
| 10492 | mHighDischargeAmountSinceCharge += mDischargeUnplugLevel-level; |
| 10493 | } |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 10494 | updateDischargeScreenLevelsLocked(screenOn, screenOn); |
| 10495 | updateTimeBasesLocked(false, !screenOn, uptime, realtime); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 10496 | mChargeStepTracker.init(); |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 10497 | mLastChargeStepLevel = level; |
Dianne Hackborn | 2932513 | 2014-05-21 15:01:03 -0700 | [diff] [blame] | 10498 | mMaxChargeStepLevel = level; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 10499 | mInitStepMode = mCurStepMode; |
| 10500 | mModStepMode = 0; |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 10501 | } |
| 10502 | if (doWrite || (mLastWriteTime + (60 * 1000)) < mSecRealtime) { |
| 10503 | if (mFile != null) { |
| 10504 | writeAsyncLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10505 | } |
| 10506 | } |
| 10507 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 10508 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 10509 | private void startRecordingHistory(final long elapsedRealtimeMs, final long uptimeMs, |
| 10510 | boolean reset) { |
| 10511 | mRecordingHistory = true; |
| 10512 | mHistoryCur.currentTime = System.currentTimeMillis(); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 10513 | addHistoryBufferLocked(elapsedRealtimeMs, uptimeMs, |
| 10514 | reset ? HistoryItem.CMD_RESET : HistoryItem.CMD_CURRENT_TIME, |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 10515 | mHistoryCur); |
| 10516 | mHistoryCur.currentTime = 0; |
| 10517 | if (reset) { |
| 10518 | initActiveHistoryEventsLocked(elapsedRealtimeMs, uptimeMs); |
| 10519 | } |
| 10520 | } |
| 10521 | |
Dianne Hackborn | 7d9eefd | 2014-08-27 18:30:31 -0700 | [diff] [blame] | 10522 | private void recordCurrentTimeChangeLocked(final long currentTime, final long elapsedRealtimeMs, |
| 10523 | final long uptimeMs) { |
| 10524 | if (mRecordingHistory) { |
| 10525 | mHistoryCur.currentTime = currentTime; |
| 10526 | addHistoryBufferLocked(elapsedRealtimeMs, uptimeMs, HistoryItem.CMD_CURRENT_TIME, |
| 10527 | mHistoryCur); |
| 10528 | mHistoryCur.currentTime = 0; |
| 10529 | } |
| 10530 | } |
| 10531 | |
Dianne Hackborn | 29cd7f1 | 2015-01-08 10:37:05 -0800 | [diff] [blame] | 10532 | private void recordShutdownLocked(final long elapsedRealtimeMs, final long uptimeMs) { |
| 10533 | if (mRecordingHistory) { |
| 10534 | mHistoryCur.currentTime = System.currentTimeMillis(); |
Dianne Hackborn | 29cd7f1 | 2015-01-08 10:37:05 -0800 | [diff] [blame] | 10535 | addHistoryBufferLocked(elapsedRealtimeMs, uptimeMs, HistoryItem.CMD_SHUTDOWN, |
| 10536 | mHistoryCur); |
| 10537 | mHistoryCur.currentTime = 0; |
| 10538 | } |
| 10539 | } |
| 10540 | |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 10541 | private void scheduleSyncExternalStatsLocked(String reason, int updateFlags) { |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 10542 | if (mExternalSync != null) { |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 10543 | mExternalSync.scheduleSync(reason, updateFlags); |
Adam Lesinski | a7c90c8 | 2015-06-18 14:52:24 -0700 | [diff] [blame] | 10544 | } |
| 10545 | } |
| 10546 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10547 | // 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] | 10548 | public static final int BATTERY_PLUGGED_NONE = 0; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 10549 | |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 10550 | public void setBatteryStateLocked(int status, int health, int plugType, int level, |
Adam Lesinski | 041d917 | 2016-12-12 12:03:56 -0800 | [diff] [blame] | 10551 | int temp, int volt, int chargeUAh, int chargeFullUAh) { |
Adam Lesinski | 29ddfe5 | 2017-03-29 19:29:00 -0700 | [diff] [blame] | 10552 | // Temperature is encoded without the signed bit, so clamp any negative temperatures to 0. |
| 10553 | temp = Math.max(0, temp); |
| 10554 | |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 10555 | final boolean onBattery = plugType == BATTERY_PLUGGED_NONE; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 10556 | final long uptime = mClocks.uptimeMillis(); |
| 10557 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 10558 | if (!mHaveBatteryLevel) { |
| 10559 | mHaveBatteryLevel = true; |
| 10560 | // We start out assuming that the device is plugged in (not |
| 10561 | // on battery). If our first report is now that we are indeed |
| 10562 | // plugged in, then twiddle our state to correctly reflect that |
| 10563 | // since we won't be going through the full setOnBattery(). |
| 10564 | if (onBattery == mOnBattery) { |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 10565 | if (onBattery) { |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 10566 | mHistoryCur.states &= ~HistoryItem.STATE_BATTERY_PLUGGED_FLAG; |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 10567 | } else { |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 10568 | mHistoryCur.states |= HistoryItem.STATE_BATTERY_PLUGGED_FLAG; |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 10569 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10570 | } |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 10571 | // Always start out assuming charging, that will be updated later. |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 10572 | mHistoryCur.states2 |= HistoryItem.STATE2_CHARGING_FLAG; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 10573 | mHistoryCur.batteryStatus = (byte)status; |
| 10574 | mHistoryCur.batteryLevel = (byte)level; |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 10575 | mHistoryCur.batteryChargeUAh = chargeUAh; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 10576 | mMaxChargeStepLevel = mMinDischargeStepLevel = |
| 10577 | mLastChargeStepLevel = mLastDischargeStepLevel = level; |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 10578 | mLastChargingStateLevel = level; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 10579 | } else if (mCurrentBatteryLevel != level || mOnBattery != onBattery) { |
| 10580 | recordDailyStatsIfNeededLocked(level >= 100 && onBattery); |
| 10581 | } |
| 10582 | int oldStatus = mHistoryCur.batteryStatus; |
| 10583 | if (onBattery) { |
| 10584 | mDischargeCurrentLevel = level; |
| 10585 | if (!mRecordingHistory) { |
| 10586 | mRecordingHistory = true; |
| 10587 | startRecordingHistory(elapsedRealtime, uptime, true); |
| 10588 | } |
| 10589 | } else if (level < 96) { |
| 10590 | if (!mRecordingHistory) { |
| 10591 | mRecordingHistory = true; |
| 10592 | startRecordingHistory(elapsedRealtime, uptime, true); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10593 | } |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 10594 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 10595 | mCurrentBatteryLevel = level; |
| 10596 | if (mDischargePlugLevel < 0) { |
| 10597 | mDischargePlugLevel = level; |
Marco Nelissen | d859331 | 2009-04-30 14:45:06 -0700 | [diff] [blame] | 10598 | } |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 10599 | |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 10600 | if (onBattery != mOnBattery) { |
| 10601 | mHistoryCur.batteryLevel = (byte)level; |
| 10602 | mHistoryCur.batteryStatus = (byte)status; |
| 10603 | mHistoryCur.batteryHealth = (byte)health; |
| 10604 | mHistoryCur.batteryPlugType = (byte)plugType; |
| 10605 | mHistoryCur.batteryTemperature = (short)temp; |
| 10606 | mHistoryCur.batteryVoltage = (char)volt; |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 10607 | if (chargeUAh < mHistoryCur.batteryChargeUAh) { |
| 10608 | // Only record discharges |
| 10609 | final long chargeDiff = mHistoryCur.batteryChargeUAh - chargeUAh; |
| 10610 | mDischargeCounter.addCountLocked(chargeDiff); |
| 10611 | mDischargeScreenOffCounter.addCountLocked(chargeDiff); |
| 10612 | } |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 10613 | mHistoryCur.batteryChargeUAh = chargeUAh; |
Adam Lesinski | f9b20a9 | 2016-06-17 17:30:01 -0700 | [diff] [blame] | 10614 | setOnBatteryLocked(elapsedRealtime, uptime, onBattery, oldStatus, level, chargeUAh); |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 10615 | } else { |
| 10616 | boolean changed = false; |
| 10617 | if (mHistoryCur.batteryLevel != level) { |
| 10618 | mHistoryCur.batteryLevel = (byte)level; |
| 10619 | changed = true; |
Marco Nelissen | d859331 | 2009-04-30 14:45:06 -0700 | [diff] [blame] | 10620 | |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 10621 | // TODO(adamlesinski): Schedule the creation of a HistoryStepDetails record |
| 10622 | // which will pull external stats. |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 10623 | scheduleSyncExternalStatsLocked("battery-level", ExternalStatsSync.UPDATE_ALL); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 10624 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 10625 | if (mHistoryCur.batteryStatus != status) { |
| 10626 | mHistoryCur.batteryStatus = (byte)status; |
| 10627 | changed = true; |
| 10628 | } |
| 10629 | if (mHistoryCur.batteryHealth != health) { |
| 10630 | mHistoryCur.batteryHealth = (byte)health; |
| 10631 | changed = true; |
| 10632 | } |
| 10633 | if (mHistoryCur.batteryPlugType != plugType) { |
| 10634 | mHistoryCur.batteryPlugType = (byte)plugType; |
| 10635 | changed = true; |
| 10636 | } |
| 10637 | if (temp >= (mHistoryCur.batteryTemperature+10) |
| 10638 | || temp <= (mHistoryCur.batteryTemperature-10)) { |
| 10639 | mHistoryCur.batteryTemperature = (short)temp; |
| 10640 | changed = true; |
| 10641 | } |
| 10642 | if (volt > (mHistoryCur.batteryVoltage+20) |
| 10643 | || volt < (mHistoryCur.batteryVoltage-20)) { |
| 10644 | mHistoryCur.batteryVoltage = (char)volt; |
| 10645 | changed = true; |
| 10646 | } |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 10647 | if (chargeUAh >= (mHistoryCur.batteryChargeUAh+10) |
| 10648 | || chargeUAh <= (mHistoryCur.batteryChargeUAh-10)) { |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 10649 | if (chargeUAh < mHistoryCur.batteryChargeUAh) { |
| 10650 | // Only record discharges |
| 10651 | final long chargeDiff = mHistoryCur.batteryChargeUAh - chargeUAh; |
| 10652 | mDischargeCounter.addCountLocked(chargeDiff); |
| 10653 | mDischargeScreenOffCounter.addCountLocked(chargeDiff); |
| 10654 | } |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 10655 | mHistoryCur.batteryChargeUAh = chargeUAh; |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 10656 | changed = true; |
| 10657 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 10658 | long modeBits = (((long)mInitStepMode) << STEP_LEVEL_INITIAL_MODE_SHIFT) |
| 10659 | | (((long)mModStepMode) << STEP_LEVEL_MODIFIED_MODE_SHIFT) |
| 10660 | | (((long)(level&0xff)) << STEP_LEVEL_LEVEL_SHIFT); |
| 10661 | if (onBattery) { |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 10662 | changed |= setChargingLocked(false); |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 10663 | if (mLastDischargeStepLevel != level && mMinDischargeStepLevel > level) { |
| 10664 | mDischargeStepTracker.addLevelSteps(mLastDischargeStepLevel - level, |
| 10665 | modeBits, elapsedRealtime); |
| 10666 | mDailyDischargeStepTracker.addLevelSteps(mLastDischargeStepLevel - level, |
| 10667 | modeBits, elapsedRealtime); |
| 10668 | mLastDischargeStepLevel = level; |
| 10669 | mMinDischargeStepLevel = level; |
| 10670 | mInitStepMode = mCurStepMode; |
| 10671 | mModStepMode = 0; |
| 10672 | } |
| 10673 | } else { |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 10674 | if (level >= 90) { |
| 10675 | // If the battery level is at least 90%, always consider the device to be |
| 10676 | // charging even if it happens to go down a level. |
| 10677 | changed |= setChargingLocked(true); |
| 10678 | mLastChargeStepLevel = level; |
| 10679 | } if (!mCharging) { |
| 10680 | if (mLastChargeStepLevel < level) { |
| 10681 | // We have not reporting that we are charging, but the level has now |
| 10682 | // gone up, so consider the state to be charging. |
| 10683 | changed |= setChargingLocked(true); |
| 10684 | mLastChargeStepLevel = level; |
| 10685 | } |
| 10686 | } else { |
| 10687 | if (mLastChargeStepLevel > level) { |
| 10688 | // We had reported that the device was charging, but here we are with |
| 10689 | // power connected and the level going down. Looks like the current |
| 10690 | // power supplied isn't enough, so consider the device to now be |
| 10691 | // discharging. |
| 10692 | changed |= setChargingLocked(false); |
| 10693 | mLastChargeStepLevel = level; |
| 10694 | } |
| 10695 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 10696 | if (mLastChargeStepLevel != level && mMaxChargeStepLevel < level) { |
| 10697 | mChargeStepTracker.addLevelSteps(level - mLastChargeStepLevel, |
| 10698 | modeBits, elapsedRealtime); |
| 10699 | mDailyChargeStepTracker.addLevelSteps(level - mLastChargeStepLevel, |
| 10700 | modeBits, elapsedRealtime); |
| 10701 | mLastChargeStepLevel = level; |
| 10702 | mMaxChargeStepLevel = level; |
| 10703 | mInitStepMode = mCurStepMode; |
| 10704 | mModStepMode = 0; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 10705 | } |
| 10706 | } |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 10707 | if (changed) { |
| 10708 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 10709 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 10710 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 10711 | if (!onBattery && status == BatteryManager.BATTERY_STATUS_FULL) { |
| 10712 | // We don't record history while we are plugged in and fully charged. |
| 10713 | // The next time we are unplugged, history will be cleared. |
| 10714 | mRecordingHistory = DEBUG; |
Dianne Hackborn | d0c5b9a | 2014-02-21 16:19:05 -0800 | [diff] [blame] | 10715 | } |
Adam Lesinski | 041d917 | 2016-12-12 12:03:56 -0800 | [diff] [blame] | 10716 | |
Jocelyn Dang | c627d10 | 2017-04-14 13:15:14 -0700 | [diff] [blame] | 10717 | if (mMinLearnedBatteryCapacity == -1) { |
| 10718 | mMinLearnedBatteryCapacity = chargeFullUAh; |
| 10719 | } else { |
| 10720 | Math.min(mMinLearnedBatteryCapacity, chargeFullUAh); |
Adam Lesinski | 041d917 | 2016-12-12 12:03:56 -0800 | [diff] [blame] | 10721 | } |
Jocelyn Dang | c627d10 | 2017-04-14 13:15:14 -0700 | [diff] [blame] | 10722 | mMaxLearnedBatteryCapacity = Math.max(mMaxLearnedBatteryCapacity, chargeFullUAh); |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 10723 | } |
| 10724 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10725 | public long getAwakeTimeBattery() { |
| 10726 | return computeBatteryUptime(getBatteryUptimeLocked(), STATS_CURRENT); |
| 10727 | } |
| 10728 | |
| 10729 | public long getAwakeTimePlugged() { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 10730 | return (mClocks.uptimeMillis() * 1000) - getAwakeTimeBattery(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10731 | } |
| 10732 | |
| 10733 | @Override |
| 10734 | public long computeUptime(long curTime, int which) { |
| 10735 | switch (which) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10736 | case STATS_SINCE_CHARGED: return mUptime + (curTime-mUptimeStart); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10737 | case STATS_CURRENT: return (curTime-mUptimeStart); |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 10738 | case STATS_SINCE_UNPLUGGED: return (curTime-mOnBatteryTimeBase.getUptimeStart()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10739 | } |
| 10740 | return 0; |
| 10741 | } |
| 10742 | |
| 10743 | @Override |
| 10744 | public long computeRealtime(long curTime, int which) { |
| 10745 | switch (which) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10746 | case STATS_SINCE_CHARGED: return mRealtime + (curTime-mRealtimeStart); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10747 | case STATS_CURRENT: return (curTime-mRealtimeStart); |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 10748 | case STATS_SINCE_UNPLUGGED: return (curTime-mOnBatteryTimeBase.getRealtimeStart()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10749 | } |
| 10750 | return 0; |
| 10751 | } |
| 10752 | |
| 10753 | @Override |
| 10754 | public long computeBatteryUptime(long curTime, int which) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10755 | return mOnBatteryTimeBase.computeUptime(curTime, which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10756 | } |
| 10757 | |
| 10758 | @Override |
| 10759 | public long computeBatteryRealtime(long curTime, int which) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10760 | return mOnBatteryTimeBase.computeRealtime(curTime, which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10761 | } |
| 10762 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10763 | @Override |
| 10764 | public long computeBatteryScreenOffUptime(long curTime, int which) { |
| 10765 | return mOnBatteryScreenOffTimeBase.computeUptime(curTime, which); |
| 10766 | } |
| 10767 | |
| 10768 | @Override |
| 10769 | public long computeBatteryScreenOffRealtime(long curTime, int which) { |
| 10770 | return mOnBatteryScreenOffTimeBase.computeRealtime(curTime, which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10771 | } |
| 10772 | |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 10773 | private long computeTimePerLevel(long[] steps, int numSteps) { |
| 10774 | // For now we'll do a simple average across all steps. |
| 10775 | if (numSteps <= 0) { |
| 10776 | return -1; |
| 10777 | } |
| 10778 | long total = 0; |
| 10779 | for (int i=0; i<numSteps; i++) { |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 10780 | total += steps[i] & STEP_LEVEL_TIME_MASK; |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 10781 | } |
| 10782 | return total / numSteps; |
| 10783 | /* |
| 10784 | long[] buckets = new long[numSteps]; |
| 10785 | int numBuckets = 0; |
| 10786 | int numToAverage = 4; |
| 10787 | int i = 0; |
| 10788 | while (i < numSteps) { |
| 10789 | long totalTime = 0; |
| 10790 | int num = 0; |
| 10791 | for (int j=0; j<numToAverage && (i+j)<numSteps; j++) { |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 10792 | totalTime += steps[i+j] & STEP_LEVEL_TIME_MASK; |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 10793 | num++; |
| 10794 | } |
| 10795 | buckets[numBuckets] = totalTime / num; |
| 10796 | numBuckets++; |
| 10797 | numToAverage *= 2; |
| 10798 | i += num; |
| 10799 | } |
| 10800 | if (numBuckets < 1) { |
| 10801 | return -1; |
| 10802 | } |
| 10803 | long averageTime = buckets[numBuckets-1]; |
| 10804 | for (i=numBuckets-2; i>=0; i--) { |
| 10805 | averageTime = (averageTime + buckets[i]) / 2; |
| 10806 | } |
| 10807 | return averageTime; |
| 10808 | */ |
| 10809 | } |
| 10810 | |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 10811 | @Override |
| 10812 | public long computeBatteryTimeRemaining(long curTime) { |
| 10813 | if (!mOnBattery) { |
| 10814 | return -1; |
| 10815 | } |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 10816 | /* Simple implementation just looks at the average discharge per level across the |
| 10817 | entire sample period. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 10818 | int discharge = (getLowDischargeAmountSinceCharge()+getHighDischargeAmountSinceCharge())/2; |
| 10819 | if (discharge < 2) { |
| 10820 | return -1; |
| 10821 | } |
| 10822 | long duration = computeBatteryRealtime(curTime, STATS_SINCE_CHARGED); |
| 10823 | if (duration < 1000*1000) { |
| 10824 | return -1; |
| 10825 | } |
| 10826 | long usPerLevel = duration/discharge; |
| 10827 | return usPerLevel * mCurrentBatteryLevel; |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 10828 | */ |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 10829 | if (mDischargeStepTracker.mNumStepDurations < 1) { |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 10830 | return -1; |
| 10831 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 10832 | long msPerLevel = mDischargeStepTracker.computeTimePerLevel(); |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 10833 | if (msPerLevel <= 0) { |
| 10834 | return -1; |
| 10835 | } |
| 10836 | return (msPerLevel * mCurrentBatteryLevel) * 1000; |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 10837 | } |
| 10838 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 10839 | @Override |
| 10840 | public LevelStepTracker getDischargeLevelStepTracker() { |
| 10841 | return mDischargeStepTracker; |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 10842 | } |
| 10843 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 10844 | @Override |
| 10845 | public LevelStepTracker getDailyDischargeLevelStepTracker() { |
| 10846 | return mDailyDischargeStepTracker; |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 10847 | } |
| 10848 | |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 10849 | @Override |
| 10850 | public long computeChargeTimeRemaining(long curTime) { |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 10851 | if (mOnBattery) { |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 10852 | // Not yet working. |
| 10853 | return -1; |
| 10854 | } |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 10855 | /* Broken |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 10856 | int curLevel = mCurrentBatteryLevel; |
| 10857 | int plugLevel = mDischargePlugLevel; |
| 10858 | if (plugLevel < 0 || curLevel < (plugLevel+1)) { |
| 10859 | return -1; |
| 10860 | } |
| 10861 | long duration = computeBatteryRealtime(curTime, STATS_SINCE_UNPLUGGED); |
| 10862 | if (duration < 1000*1000) { |
| 10863 | return -1; |
| 10864 | } |
| 10865 | long usPerLevel = duration/(curLevel-plugLevel); |
| 10866 | return usPerLevel * (100-curLevel); |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 10867 | */ |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 10868 | if (mChargeStepTracker.mNumStepDurations < 1) { |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 10869 | return -1; |
| 10870 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 10871 | long msPerLevel = mChargeStepTracker.computeTimePerLevel(); |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 10872 | if (msPerLevel <= 0) { |
| 10873 | return -1; |
| 10874 | } |
| 10875 | return (msPerLevel * (100-mCurrentBatteryLevel)) * 1000; |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 10876 | } |
| 10877 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 10878 | @Override |
| 10879 | public LevelStepTracker getChargeLevelStepTracker() { |
| 10880 | return mChargeStepTracker; |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 10881 | } |
| 10882 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 10883 | @Override |
| 10884 | public LevelStepTracker getDailyChargeLevelStepTracker() { |
| 10885 | return mDailyChargeStepTracker; |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 10886 | } |
| 10887 | |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 10888 | @Override |
| 10889 | public ArrayList<PackageChange> getDailyPackageChanges() { |
| 10890 | return mDailyPackageChanges; |
| 10891 | } |
| 10892 | |
Joe Onorato | e1acd63 | 2016-02-23 13:25:10 -0800 | [diff] [blame] | 10893 | protected long getBatteryUptimeLocked() { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 10894 | return mOnBatteryTimeBase.getUptime(mClocks.uptimeMillis() * 1000); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10895 | } |
| 10896 | |
| 10897 | @Override |
| 10898 | public long getBatteryUptime(long curTime) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10899 | return mOnBatteryTimeBase.getUptime(curTime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10900 | } |
| 10901 | |
| 10902 | @Override |
| 10903 | public long getBatteryRealtime(long curTime) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10904 | return mOnBatteryTimeBase.getRealtime(curTime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10905 | } |
Amith Yamasani | 3718aaa | 2009-06-09 06:32:35 -0700 | [diff] [blame] | 10906 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 10907 | @Override |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 10908 | public int getDischargeStartLevel() { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 10909 | synchronized(this) { |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 10910 | return getDischargeStartLevelLocked(); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 10911 | } |
| 10912 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 10913 | |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 10914 | public int getDischargeStartLevelLocked() { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10915 | return mDischargeUnplugLevel; |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 10916 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 10917 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 10918 | @Override |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 10919 | public int getDischargeCurrentLevel() { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 10920 | synchronized(this) { |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 10921 | return getDischargeCurrentLevelLocked(); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 10922 | } |
| 10923 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 10924 | |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 10925 | public int getDischargeCurrentLevelLocked() { |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 10926 | return mDischargeCurrentLevel; |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 10927 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10928 | |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 10929 | @Override |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 10930 | public int getLowDischargeAmountSinceCharge() { |
| 10931 | synchronized(this) { |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 10932 | int val = mLowDischargeAmountSinceCharge; |
| 10933 | if (mOnBattery && mDischargeCurrentLevel < mDischargeUnplugLevel) { |
| 10934 | val += mDischargeUnplugLevel-mDischargeCurrentLevel-1; |
| 10935 | } |
| 10936 | return val; |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 10937 | } |
| 10938 | } |
| 10939 | |
| 10940 | @Override |
| 10941 | public int getHighDischargeAmountSinceCharge() { |
| 10942 | synchronized(this) { |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 10943 | int val = mHighDischargeAmountSinceCharge; |
| 10944 | if (mOnBattery && mDischargeCurrentLevel < mDischargeUnplugLevel) { |
| 10945 | val += mDischargeUnplugLevel-mDischargeCurrentLevel; |
| 10946 | } |
| 10947 | return val; |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 10948 | } |
| 10949 | } |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 10950 | |
| 10951 | @Override |
| 10952 | public int getDischargeAmount(int which) { |
| 10953 | int dischargeAmount = which == STATS_SINCE_CHARGED |
| 10954 | ? getHighDischargeAmountSinceCharge() |
| 10955 | : (getDischargeStartLevel() - getDischargeCurrentLevel()); |
| 10956 | if (dischargeAmount < 0) { |
| 10957 | dischargeAmount = 0; |
| 10958 | } |
| 10959 | return dischargeAmount; |
| 10960 | } |
| 10961 | |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 10962 | public int getDischargeAmountScreenOn() { |
| 10963 | synchronized(this) { |
| 10964 | int val = mDischargeAmountScreenOn; |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 10965 | if (mOnBattery && mScreenState == Display.STATE_ON |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 10966 | && mDischargeCurrentLevel < mDischargeScreenOnUnplugLevel) { |
| 10967 | val += mDischargeScreenOnUnplugLevel-mDischargeCurrentLevel; |
| 10968 | } |
| 10969 | return val; |
| 10970 | } |
| 10971 | } |
| 10972 | |
| 10973 | public int getDischargeAmountScreenOnSinceCharge() { |
| 10974 | synchronized(this) { |
| 10975 | int val = mDischargeAmountScreenOnSinceCharge; |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 10976 | if (mOnBattery && mScreenState == Display.STATE_ON |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 10977 | && mDischargeCurrentLevel < mDischargeScreenOnUnplugLevel) { |
| 10978 | val += mDischargeScreenOnUnplugLevel-mDischargeCurrentLevel; |
| 10979 | } |
| 10980 | return val; |
| 10981 | } |
| 10982 | } |
| 10983 | |
| 10984 | public int getDischargeAmountScreenOff() { |
| 10985 | synchronized(this) { |
| 10986 | int val = mDischargeAmountScreenOff; |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 10987 | if (mOnBattery && mScreenState != Display.STATE_ON |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 10988 | && mDischargeCurrentLevel < mDischargeScreenOffUnplugLevel) { |
| 10989 | val += mDischargeScreenOffUnplugLevel-mDischargeCurrentLevel; |
| 10990 | } |
| 10991 | return val; |
| 10992 | } |
| 10993 | } |
| 10994 | |
| 10995 | public int getDischargeAmountScreenOffSinceCharge() { |
| 10996 | synchronized(this) { |
| 10997 | int val = mDischargeAmountScreenOffSinceCharge; |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 10998 | if (mOnBattery && mScreenState != Display.STATE_ON |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 10999 | && mDischargeCurrentLevel < mDischargeScreenOffUnplugLevel) { |
| 11000 | val += mDischargeScreenOffUnplugLevel-mDischargeCurrentLevel; |
| 11001 | } |
| 11002 | return val; |
| 11003 | } |
| 11004 | } |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 11005 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11006 | /** |
| 11007 | * Retrieve the statistics object for a particular uid, creating if needed. |
| 11008 | */ |
| 11009 | public Uid getUidStatsLocked(int uid) { |
| 11010 | Uid u = mUidStats.get(uid); |
| 11011 | if (u == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 11012 | u = new Uid(this, uid); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11013 | mUidStats.put(uid, u); |
| 11014 | } |
| 11015 | return u; |
| 11016 | } |
| 11017 | |
| 11018 | /** |
| 11019 | * Remove the statistics object for a particular uid. |
| 11020 | */ |
| 11021 | public void removeUidStatsLocked(int uid) { |
Adam Lesinski | b83ffee | 2015-05-12 14:43:47 -0700 | [diff] [blame] | 11022 | mKernelUidCpuTimeReader.removeUid(uid); |
Sudheer Shanka | 6d8dcec | 2017-06-01 12:09:03 -0700 | [diff] [blame] | 11023 | mKernelUidCpuFreqTimeReader.removeUid(uid); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11024 | mUidStats.remove(uid); |
| 11025 | } |
Amith Yamasani | 32dbefd | 2009-06-19 09:21:17 -0700 | [diff] [blame] | 11026 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11027 | /** |
| 11028 | * Retrieve the statistics object for a particular process, creating |
| 11029 | * if needed. |
| 11030 | */ |
| 11031 | public Uid.Proc getProcessStatsLocked(int uid, String name) { |
Dianne Hackborn | bbb7472 | 2014-03-13 09:50:24 -0700 | [diff] [blame] | 11032 | uid = mapUid(uid); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11033 | Uid u = getUidStatsLocked(uid); |
| 11034 | return u.getProcessStatsLocked(name); |
| 11035 | } |
| 11036 | |
| 11037 | /** |
| 11038 | * Retrieve the statistics object for a particular process, creating |
| 11039 | * if needed. |
| 11040 | */ |
| 11041 | public Uid.Pkg getPackageStatsLocked(int uid, String pkg) { |
Dianne Hackborn | bbb7472 | 2014-03-13 09:50:24 -0700 | [diff] [blame] | 11042 | uid = mapUid(uid); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11043 | Uid u = getUidStatsLocked(uid); |
| 11044 | return u.getPackageStatsLocked(pkg); |
| 11045 | } |
| 11046 | |
| 11047 | /** |
| 11048 | * Retrieve the statistics object for a particular service, creating |
| 11049 | * if needed. |
| 11050 | */ |
| 11051 | public Uid.Pkg.Serv getServiceStatsLocked(int uid, String pkg, String name) { |
Dianne Hackborn | bbb7472 | 2014-03-13 09:50:24 -0700 | [diff] [blame] | 11052 | uid = mapUid(uid); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11053 | Uid u = getUidStatsLocked(uid); |
| 11054 | return u.getServiceStatsLocked(pkg, name); |
| 11055 | } |
| 11056 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 11057 | public void shutdownLocked() { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 11058 | recordShutdownLocked(mClocks.elapsedRealtime(), mClocks.uptimeMillis()); |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 11059 | writeSyncLocked(); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 11060 | mShuttingDown = true; |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 11061 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 11062 | |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 11063 | Parcel mPendingWrite = null; |
| 11064 | final ReentrantLock mWriteLock = new ReentrantLock(); |
| 11065 | |
| 11066 | public void writeAsyncLocked() { |
| 11067 | writeLocked(false); |
| 11068 | } |
| 11069 | |
| 11070 | public void writeSyncLocked() { |
| 11071 | writeLocked(true); |
| 11072 | } |
| 11073 | |
| 11074 | void writeLocked(boolean sync) { |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 11075 | if (mFile == null) { |
| 11076 | 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] | 11077 | return; |
| 11078 | } |
| 11079 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 11080 | if (mShuttingDown) { |
| 11081 | return; |
| 11082 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 11083 | |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 11084 | Parcel out = Parcel.obtain(); |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 11085 | writeSummaryToParcel(out, true); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 11086 | mLastWriteTime = mClocks.elapsedRealtime(); |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 11087 | |
| 11088 | if (mPendingWrite != null) { |
| 11089 | mPendingWrite.recycle(); |
| 11090 | } |
| 11091 | mPendingWrite = out; |
| 11092 | |
| 11093 | if (sync) { |
| 11094 | commitPendingDataToDisk(); |
| 11095 | } else { |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 11096 | BackgroundThread.getHandler().post(new Runnable() { |
| 11097 | @Override public void run() { |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 11098 | commitPendingDataToDisk(); |
| 11099 | } |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 11100 | }); |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 11101 | } |
| 11102 | } |
| 11103 | |
| 11104 | public void commitPendingDataToDisk() { |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 11105 | final Parcel next; |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 11106 | synchronized (this) { |
| 11107 | next = mPendingWrite; |
| 11108 | mPendingWrite = null; |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 11109 | if (next == null) { |
| 11110 | return; |
| 11111 | } |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 11112 | } |
| 11113 | |
Amith Yamasani | d245086 | 2017-02-07 15:58:24 -0800 | [diff] [blame] | 11114 | mWriteLock.lock(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11115 | try { |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 11116 | FileOutputStream stream = new FileOutputStream(mFile.chooseForWrite()); |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 11117 | stream.write(next.marshall()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11118 | stream.flush(); |
Dianne Hackborn | 8bdf593 | 2010-10-15 12:54:40 -0700 | [diff] [blame] | 11119 | FileUtils.sync(stream); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11120 | stream.close(); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 11121 | mFile.commit(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11122 | } catch (IOException e) { |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 11123 | Slog.w("BatteryStats", "Error writing battery statistics", e); |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 11124 | mFile.rollback(); |
| 11125 | } finally { |
| 11126 | next.recycle(); |
| 11127 | mWriteLock.unlock(); |
Suchi Amalapurapu | 8550f25 | 2009-09-29 15:20:32 -0700 | [diff] [blame] | 11128 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11129 | } |
| 11130 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11131 | public void readLocked() { |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 11132 | if (mDailyFile != null) { |
| 11133 | readDailyStatsLocked(); |
| 11134 | } |
| 11135 | |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 11136 | if (mFile == null) { |
| 11137 | 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] | 11138 | return; |
| 11139 | } |
| 11140 | |
| 11141 | mUidStats.clear(); |
| 11142 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11143 | try { |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 11144 | File file = mFile.chooseForRead(); |
| 11145 | if (!file.exists()) { |
| 11146 | return; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11147 | } |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 11148 | FileInputStream stream = new FileInputStream(file); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11149 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 11150 | byte[] raw = BatteryStatsHelper.readFully(stream); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11151 | Parcel in = Parcel.obtain(); |
| 11152 | in.unmarshall(raw, 0, raw.length); |
| 11153 | in.setDataPosition(0); |
| 11154 | stream.close(); |
| 11155 | |
| 11156 | readSummaryFromParcel(in); |
Dianne Hackborn | 00e2521 | 2014-02-19 10:49:24 -0800 | [diff] [blame] | 11157 | } catch(Exception e) { |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 11158 | Slog.e("BatteryStats", "Error reading battery statistics", e); |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 11159 | resetAllStatsLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11160 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 11161 | |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 11162 | mEndPlatformVersion = Build.ID; |
| 11163 | |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 11164 | if (mHistoryBuffer.dataPosition() > 0) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 11165 | mRecordingHistory = true; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 11166 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 11167 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 11168 | if (USE_OLD_HISTORY) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 11169 | addHistoryRecordLocked(elapsedRealtime, uptime, HistoryItem.CMD_START, mHistoryCur); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 11170 | } |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 11171 | addHistoryBufferLocked(elapsedRealtime, uptime, HistoryItem.CMD_START, mHistoryCur); |
| 11172 | startRecordingHistory(elapsedRealtime, uptime, false); |
Dianne Hackborn | e8c88e6 | 2011-08-17 19:09:09 -0700 | [diff] [blame] | 11173 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 11174 | |
| 11175 | recordDailyStatsIfNeededLocked(false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11176 | } |
| 11177 | |
| 11178 | public int describeContents() { |
| 11179 | return 0; |
| 11180 | } |
| 11181 | |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 11182 | void readHistory(Parcel in, boolean andOldHistory) throws ParcelFormatException { |
Dianne Hackborn | ae38445 | 2011-06-28 12:33:48 -0700 | [diff] [blame] | 11183 | final long historyBaseTime = in.readLong(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 11184 | |
| 11185 | mHistoryBuffer.setDataSize(0); |
| 11186 | mHistoryBuffer.setDataPosition(0); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 11187 | mHistoryTagPool.clear(); |
| 11188 | mNextHistoryTagIdx = 0; |
| 11189 | mNumHistoryTagChars = 0; |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 11190 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 11191 | int numTags = in.readInt(); |
| 11192 | for (int i=0; i<numTags; i++) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 11193 | int idx = in.readInt(); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 11194 | String str = in.readString(); |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 11195 | if (str == null) { |
| 11196 | throw new ParcelFormatException("null history tag string"); |
| 11197 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 11198 | int uid = in.readInt(); |
| 11199 | HistoryTag tag = new HistoryTag(); |
| 11200 | tag.string = str; |
| 11201 | tag.uid = uid; |
| 11202 | tag.poolIdx = idx; |
| 11203 | mHistoryTagPool.put(tag, idx); |
| 11204 | if (idx >= mNextHistoryTagIdx) { |
| 11205 | mNextHistoryTagIdx = idx+1; |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 11206 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 11207 | mNumHistoryTagChars += tag.string.length() + 1; |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 11208 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 11209 | |
| 11210 | int bufSize = in.readInt(); |
| 11211 | int curPos = in.dataPosition(); |
| 11212 | if (bufSize >= (MAX_MAX_HISTORY_BUFFER*3)) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 11213 | throw new ParcelFormatException("File corrupt: history data buffer too large " + |
| 11214 | bufSize); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 11215 | } else if ((bufSize&~3) != bufSize) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 11216 | throw new ParcelFormatException("File corrupt: history data buffer not aligned " + |
| 11217 | bufSize); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 11218 | } else { |
| 11219 | if (DEBUG_HISTORY) Slog.i(TAG, "***************** READING NEW HISTORY: " + bufSize |
| 11220 | + " bytes at " + curPos); |
| 11221 | mHistoryBuffer.appendFrom(in, curPos, bufSize); |
| 11222 | in.setDataPosition(curPos + bufSize); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 11223 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 11224 | |
Dianne Hackborn | ae38445 | 2011-06-28 12:33:48 -0700 | [diff] [blame] | 11225 | if (andOldHistory) { |
| 11226 | readOldHistory(in); |
| 11227 | } |
| 11228 | |
| 11229 | if (DEBUG_HISTORY) { |
| 11230 | StringBuilder sb = new StringBuilder(128); |
| 11231 | sb.append("****************** OLD mHistoryBaseTime: "); |
| 11232 | TimeUtils.formatDuration(mHistoryBaseTime, sb); |
| 11233 | Slog.i(TAG, sb.toString()); |
| 11234 | } |
| 11235 | mHistoryBaseTime = historyBaseTime; |
| 11236 | if (DEBUG_HISTORY) { |
| 11237 | StringBuilder sb = new StringBuilder(128); |
| 11238 | sb.append("****************** NEW mHistoryBaseTime: "); |
| 11239 | TimeUtils.formatDuration(mHistoryBaseTime, sb); |
| 11240 | Slog.i(TAG, sb.toString()); |
| 11241 | } |
| 11242 | |
| 11243 | // We are just arbitrarily going to insert 1 minute from the sample of |
| 11244 | // the last run until samples in this run. |
| 11245 | if (mHistoryBaseTime > 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 11246 | long oldnow = mClocks.elapsedRealtime(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 11247 | mHistoryBaseTime = mHistoryBaseTime - oldnow + 1; |
Dianne Hackborn | ae38445 | 2011-06-28 12:33:48 -0700 | [diff] [blame] | 11248 | if (DEBUG_HISTORY) { |
| 11249 | StringBuilder sb = new StringBuilder(128); |
| 11250 | sb.append("****************** ADJUSTED mHistoryBaseTime: "); |
| 11251 | TimeUtils.formatDuration(mHistoryBaseTime, sb); |
| 11252 | Slog.i(TAG, sb.toString()); |
| 11253 | } |
Dianne Hackborn | 1e4b9f3 | 2010-06-23 14:10:57 -0700 | [diff] [blame] | 11254 | } |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 11255 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 11256 | |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 11257 | void readOldHistory(Parcel in) { |
Dianne Hackborn | e8c88e6 | 2011-08-17 19:09:09 -0700 | [diff] [blame] | 11258 | if (!USE_OLD_HISTORY) { |
| 11259 | return; |
| 11260 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 11261 | mHistory = mHistoryEnd = mHistoryCache = null; |
| 11262 | long time; |
Conley Owens | 5e3357f | 2011-05-02 09:59:30 -0700 | [diff] [blame] | 11263 | while (in.dataAvail() > 0 && (time=in.readLong()) >= 0) { |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 11264 | HistoryItem rec = new HistoryItem(time, in); |
| 11265 | addHistoryRecordLocked(rec); |
| 11266 | } |
| 11267 | } |
| 11268 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 11269 | void writeHistory(Parcel out, boolean inclData, boolean andOldHistory) { |
Dianne Hackborn | ae38445 | 2011-06-28 12:33:48 -0700 | [diff] [blame] | 11270 | if (DEBUG_HISTORY) { |
| 11271 | StringBuilder sb = new StringBuilder(128); |
| 11272 | sb.append("****************** WRITING mHistoryBaseTime: "); |
| 11273 | TimeUtils.formatDuration(mHistoryBaseTime, sb); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 11274 | sb.append(" mLastHistoryElapsedRealtime: "); |
| 11275 | TimeUtils.formatDuration(mLastHistoryElapsedRealtime, sb); |
Dianne Hackborn | ae38445 | 2011-06-28 12:33:48 -0700 | [diff] [blame] | 11276 | Slog.i(TAG, sb.toString()); |
| 11277 | } |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 11278 | out.writeLong(mHistoryBaseTime + mLastHistoryElapsedRealtime); |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 11279 | if (!inclData) { |
| 11280 | out.writeInt(0); |
| 11281 | out.writeInt(0); |
| 11282 | return; |
| 11283 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 11284 | out.writeInt(mHistoryTagPool.size()); |
| 11285 | for (HashMap.Entry<HistoryTag, Integer> ent : mHistoryTagPool.entrySet()) { |
| 11286 | HistoryTag tag = ent.getKey(); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 11287 | out.writeInt(ent.getValue()); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 11288 | out.writeString(tag.string); |
| 11289 | out.writeInt(tag.uid); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 11290 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 11291 | out.writeInt(mHistoryBuffer.dataSize()); |
| 11292 | if (DEBUG_HISTORY) Slog.i(TAG, "***************** WRITING HISTORY: " |
| 11293 | + mHistoryBuffer.dataSize() + " bytes at " + out.dataPosition()); |
| 11294 | out.appendFrom(mHistoryBuffer, 0, mHistoryBuffer.dataSize()); |
Dianne Hackborn | ae38445 | 2011-06-28 12:33:48 -0700 | [diff] [blame] | 11295 | |
| 11296 | if (andOldHistory) { |
| 11297 | writeOldHistory(out); |
| 11298 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 11299 | } |
| 11300 | |
| 11301 | void writeOldHistory(Parcel out) { |
Dianne Hackborn | e8c88e6 | 2011-08-17 19:09:09 -0700 | [diff] [blame] | 11302 | if (!USE_OLD_HISTORY) { |
| 11303 | return; |
| 11304 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 11305 | HistoryItem rec = mHistory; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 11306 | while (rec != null) { |
| 11307 | if (rec.time >= 0) rec.writeToParcel(out, 0); |
| 11308 | rec = rec.next; |
| 11309 | } |
| 11310 | out.writeLong(-1); |
| 11311 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 11312 | |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 11313 | public void readSummaryFromParcel(Parcel in) throws ParcelFormatException { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11314 | final int version = in.readInt(); |
| 11315 | if (version != VERSION) { |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 11316 | Slog.w("BatteryStats", "readFromParcel: version got " + version |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11317 | + ", expected " + VERSION + "; erasing old stats"); |
| 11318 | return; |
| 11319 | } |
| 11320 | |
Dianne Hackborn | ae38445 | 2011-06-28 12:33:48 -0700 | [diff] [blame] | 11321 | readHistory(in, true); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 11322 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11323 | mStartCount = in.readInt(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11324 | mUptime = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11325 | mRealtime = in.readLong(); |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 11326 | mStartClockTime = in.readLong(); |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 11327 | mStartPlatformVersion = in.readString(); |
| 11328 | mEndPlatformVersion = in.readString(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 11329 | mOnBatteryTimeBase.readSummaryFromParcel(in); |
| 11330 | mOnBatteryScreenOffTimeBase.readSummaryFromParcel(in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 11331 | mDischargeUnplugLevel = in.readInt(); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 11332 | mDischargePlugLevel = in.readInt(); |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 11333 | mDischargeCurrentLevel = in.readInt(); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 11334 | mCurrentBatteryLevel = in.readInt(); |
Adam Lesinski | f9b20a9 | 2016-06-17 17:30:01 -0700 | [diff] [blame] | 11335 | mEstimatedBatteryCapacity = in.readInt(); |
Jocelyn Dang | c627d10 | 2017-04-14 13:15:14 -0700 | [diff] [blame] | 11336 | mMinLearnedBatteryCapacity = in.readInt(); |
| 11337 | mMaxLearnedBatteryCapacity = in.readInt(); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 11338 | mLowDischargeAmountSinceCharge = in.readInt(); |
| 11339 | mHighDischargeAmountSinceCharge = in.readInt(); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 11340 | mDischargeAmountScreenOnSinceCharge = in.readInt(); |
| 11341 | mDischargeAmountScreenOffSinceCharge = in.readInt(); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 11342 | mDischargeStepTracker.readFromParcel(in); |
| 11343 | mChargeStepTracker.readFromParcel(in); |
| 11344 | mDailyDischargeStepTracker.readFromParcel(in); |
| 11345 | mDailyChargeStepTracker.readFromParcel(in); |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 11346 | mDischargeCounter.readSummaryFromParcelLocked(in); |
| 11347 | mDischargeScreenOffCounter.readSummaryFromParcelLocked(in); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 11348 | int NPKG = in.readInt(); |
| 11349 | if (NPKG > 0) { |
| 11350 | mDailyPackageChanges = new ArrayList<>(NPKG); |
| 11351 | while (NPKG > 0) { |
| 11352 | NPKG--; |
| 11353 | PackageChange pc = new PackageChange(); |
| 11354 | pc.mPackageName = in.readString(); |
| 11355 | pc.mUpdate = in.readInt() != 0; |
| 11356 | pc.mVersionCode = in.readInt(); |
| 11357 | mDailyPackageChanges.add(pc); |
| 11358 | } |
| 11359 | } else { |
| 11360 | mDailyPackageChanges = null; |
| 11361 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 11362 | mDailyStartTime = in.readLong(); |
| 11363 | mNextMinDailyDeadline = in.readLong(); |
| 11364 | mNextMaxDailyDeadline = in.readLong(); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 11365 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11366 | mStartCount++; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 11367 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 11368 | mScreenState = Display.STATE_UNKNOWN; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11369 | mScreenOnTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 11370 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
| 11371 | mScreenBrightnessTimer[i].readSummaryFromParcelLocked(in); |
| 11372 | } |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 11373 | mInteractive = false; |
| 11374 | mInteractiveTimer.readSummaryFromParcelLocked(in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11375 | mPhoneOn = false; |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 11376 | mPowerSaveModeEnabledTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 11377 | mLongestLightIdleTime = in.readLong(); |
| 11378 | mLongestFullIdleTime = in.readLong(); |
| 11379 | mDeviceIdleModeLightTimer.readSummaryFromParcelLocked(in); |
| 11380 | mDeviceIdleModeFullTimer.readSummaryFromParcelLocked(in); |
| 11381 | mDeviceLightIdlingTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 11382 | mDeviceIdlingTimer.readSummaryFromParcelLocked(in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11383 | mPhoneOnTimer.readSummaryFromParcelLocked(in); |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 11384 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 11385 | mPhoneSignalStrengthsTimer[i].readSummaryFromParcelLocked(in); |
| 11386 | } |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 11387 | mPhoneSignalScanningTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 11388 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
| 11389 | mPhoneDataConnectionsTimer[i].readSummaryFromParcelLocked(in); |
| 11390 | } |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 11391 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 11392 | mNetworkByteActivityCounters[i].readSummaryFromParcelLocked(in); |
| 11393 | mNetworkPacketActivityCounters[i].readSummaryFromParcelLocked(in); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 11394 | } |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 11395 | mMobileRadioPowerState = DataConnectionRealTimeInfo.DC_POWER_STATE_LOW; |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 11396 | mMobileRadioActiveTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 11397 | mMobileRadioActivePerAppTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 11398 | mMobileRadioActiveAdjustedTime.readSummaryFromParcelLocked(in); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 11399 | mMobileRadioActiveUnknownTime.readSummaryFromParcelLocked(in); |
| 11400 | mMobileRadioActiveUnknownCount.readSummaryFromParcelLocked(in); |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 11401 | mWifiRadioPowerState = DataConnectionRealTimeInfo.DC_POWER_STATE_LOW; |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 11402 | mWifiOn = false; |
| 11403 | mWifiOnTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 11404 | mGlobalWifiRunning = false; |
| 11405 | mGlobalWifiRunningTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 11406 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
| 11407 | mWifiStateTimer[i].readSummaryFromParcelLocked(in); |
| 11408 | } |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 11409 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
| 11410 | mWifiSupplStateTimer[i].readSummaryFromParcelLocked(in); |
| 11411 | } |
| 11412 | for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 11413 | mWifiSignalStrengthsTimer[i].readSummaryFromParcelLocked(in); |
| 11414 | } |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 11415 | mWifiActivity.readSummaryFromParcel(in); |
| 11416 | mBluetoothActivity.readSummaryFromParcel(in); |
| 11417 | mModemActivity.readSummaryFromParcel(in); |
| 11418 | mHasWifiReporting = in.readInt() != 0; |
| 11419 | mHasBluetoothReporting = in.readInt() != 0; |
| 11420 | mHasModemReporting = in.readInt() != 0; |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 11421 | |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 11422 | mNumConnectivityChange = mLoadedNumConnectivityChange = in.readInt(); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 11423 | mFlashlightOnNesting = 0; |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 11424 | mFlashlightOnTimer.readSummaryFromParcelLocked(in); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 11425 | mCameraOnNesting = 0; |
| 11426 | mCameraOnTimer.readSummaryFromParcelLocked(in); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 11427 | mBluetoothScanNesting = 0; |
| 11428 | mBluetoothScanTimer.readSummaryFromParcelLocked(in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11429 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 11430 | int NKW = in.readInt(); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 11431 | if (NKW > 10000) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 11432 | throw new ParcelFormatException("File corrupt: too many kernel wake locks " + NKW); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 11433 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 11434 | for (int ikw = 0; ikw < NKW; ikw++) { |
| 11435 | if (in.readInt() != 0) { |
| 11436 | String kwltName = in.readString(); |
| 11437 | getKernelWakelockTimerLocked(kwltName).readSummaryFromParcelLocked(in); |
| 11438 | } |
| 11439 | } |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 11440 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 11441 | int NWR = in.readInt(); |
| 11442 | if (NWR > 10000) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 11443 | throw new ParcelFormatException("File corrupt: too many wakeup reasons " + NWR); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 11444 | } |
| 11445 | for (int iwr = 0; iwr < NWR; iwr++) { |
| 11446 | if (in.readInt() != 0) { |
| 11447 | String reasonName = in.readString(); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 11448 | getWakeupReasonTimerLocked(reasonName).readSummaryFromParcelLocked(in); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 11449 | } |
| 11450 | } |
| 11451 | |
James Carr | 3a22605 | 2016-07-01 14:49:52 -0700 | [diff] [blame] | 11452 | int NMS = in.readInt(); |
| 11453 | for (int ims = 0; ims < NMS; ims++) { |
| 11454 | if (in.readInt() != 0) { |
| 11455 | long kmstName = in.readLong(); |
| 11456 | getKernelMemoryTimerLocked(kmstName).readSummaryFromParcelLocked(in); |
| 11457 | } |
| 11458 | } |
| 11459 | |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 11460 | mCpuFreqs = in.createLongArray(); |
| 11461 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11462 | final int NU = in.readInt(); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 11463 | if (NU > 10000) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 11464 | throw new ParcelFormatException("File corrupt: too many uids " + NU); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 11465 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11466 | for (int iu = 0; iu < NU; iu++) { |
| 11467 | int uid = in.readInt(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 11468 | Uid u = new Uid(this, uid); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11469 | mUidStats.put(uid, u); |
| 11470 | |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 11471 | u.mOnBatteryBackgroundTimeBase.readSummaryFromParcel(in); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 11472 | u.mOnBatteryScreenOffBackgroundTimeBase.readSummaryFromParcel(in); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 11473 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 11474 | u.mWifiRunning = false; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 11475 | if (in.readInt() != 0) { |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 11476 | u.mWifiRunningTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 11477 | } |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 11478 | u.mFullWifiLockOut = false; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 11479 | if (in.readInt() != 0) { |
| 11480 | u.mFullWifiLockTimer.readSummaryFromParcelLocked(in); |
| 11481 | } |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 11482 | u.mWifiScanStarted = false; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 11483 | if (in.readInt() != 0) { |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 11484 | u.mWifiScanTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 11485 | } |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 11486 | u.mWifiBatchedScanBinStarted = Uid.NO_BATCHED_SCAN_STARTED; |
| 11487 | for (int i = 0; i < Uid.NUM_WIFI_BATCHED_SCAN_BINS; i++) { |
| 11488 | if (in.readInt() != 0) { |
| 11489 | u.makeWifiBatchedScanBin(i, null); |
| 11490 | u.mWifiBatchedScanTimer[i].readSummaryFromParcelLocked(in); |
| 11491 | } |
| 11492 | } |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 11493 | u.mWifiMulticastEnabled = false; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 11494 | if (in.readInt() != 0) { |
| 11495 | u.mWifiMulticastTimer.readSummaryFromParcelLocked(in); |
| 11496 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 11497 | if (in.readInt() != 0) { |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 11498 | u.createAudioTurnedOnTimerLocked().readSummaryFromParcelLocked(in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 11499 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 11500 | if (in.readInt() != 0) { |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 11501 | u.createVideoTurnedOnTimerLocked().readSummaryFromParcelLocked(in); |
| 11502 | } |
| 11503 | if (in.readInt() != 0) { |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 11504 | u.createFlashlightTurnedOnTimerLocked().readSummaryFromParcelLocked(in); |
| 11505 | } |
| 11506 | if (in.readInt() != 0) { |
| 11507 | u.createCameraTurnedOnTimerLocked().readSummaryFromParcelLocked(in); |
| 11508 | } |
| 11509 | if (in.readInt() != 0) { |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 11510 | u.createForegroundActivityTimerLocked().readSummaryFromParcelLocked(in); |
| 11511 | } |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 11512 | if (in.readInt() != 0) { |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 11513 | u.createAggregatedPartialWakelockTimerLocked().readSummaryFromParcelLocked(in); |
| 11514 | } |
| 11515 | if (in.readInt() != 0) { |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 11516 | u.createBluetoothScanTimerLocked().readSummaryFromParcelLocked(in); |
| 11517 | } |
Bookatz | 956f36bf | 2017-04-28 09:48:17 -0700 | [diff] [blame] | 11518 | if (in.readInt() != 0) { |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 11519 | u.createBluetoothUnoptimizedScanTimerLocked().readSummaryFromParcelLocked(in); |
| 11520 | } |
| 11521 | if (in.readInt() != 0) { |
Bookatz | 956f36bf | 2017-04-28 09:48:17 -0700 | [diff] [blame] | 11522 | u.createBluetoothScanResultCounterLocked().readSummaryFromParcelLocked(in); |
| 11523 | } |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 11524 | if (in.readInt() != 0) { |
| 11525 | u.createBluetoothScanResultBgCounterLocked().readSummaryFromParcelLocked(in); |
| 11526 | } |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 11527 | u.mProcessState = ActivityManager.PROCESS_STATE_NONEXISTENT; |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 11528 | for (int i = 0; i < Uid.NUM_PROCESS_STATE; i++) { |
| 11529 | if (in.readInt() != 0) { |
| 11530 | u.makeProcessState(i, null); |
| 11531 | u.mProcessStateTimer[i].readSummaryFromParcelLocked(in); |
| 11532 | } |
| 11533 | } |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 11534 | if (in.readInt() != 0) { |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 11535 | u.createVibratorOnTimerLocked().readSummaryFromParcelLocked(in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 11536 | } |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 11537 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 11538 | if (in.readInt() != 0) { |
| 11539 | if (u.mUserActivityCounters == null) { |
| 11540 | u.initUserActivityLocked(); |
| 11541 | } |
| 11542 | for (int i=0; i<Uid.NUM_USER_ACTIVITY_TYPES; i++) { |
| 11543 | u.mUserActivityCounters[i].readSummaryFromParcelLocked(in); |
| 11544 | } |
| 11545 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 11546 | |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 11547 | if (in.readInt() != 0) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 11548 | if (u.mNetworkByteActivityCounters == null) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 11549 | u.initNetworkActivityLocked(); |
| 11550 | } |
| 11551 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 11552 | u.mNetworkByteActivityCounters[i].readSummaryFromParcelLocked(in); |
| 11553 | u.mNetworkPacketActivityCounters[i].readSummaryFromParcelLocked(in); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 11554 | } |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 11555 | u.mMobileRadioActiveTime.readSummaryFromParcelLocked(in); |
| 11556 | u.mMobileRadioActiveCount.readSummaryFromParcelLocked(in); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 11557 | } |
| 11558 | |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 11559 | u.mUserCpuTime.readSummaryFromParcelLocked(in); |
| 11560 | u.mSystemCpuTime.readSummaryFromParcelLocked(in); |
| 11561 | |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 11562 | if (in.readInt() != 0) { |
| 11563 | final int numClusters = in.readInt(); |
| 11564 | if (mPowerProfile != null && mPowerProfile.getNumCpuClusters() != numClusters) { |
| 11565 | throw new ParcelFormatException("Incompatible cpu cluster arrangement"); |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 11566 | } |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 11567 | |
| 11568 | u.mCpuClusterSpeed = new LongSamplingCounter[numClusters][]; |
| 11569 | for (int cluster = 0; cluster < numClusters; cluster++) { |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 11570 | if (in.readInt() != 0) { |
Adam Lesinski | a57a540 | 2015-09-28 10:21:33 -0700 | [diff] [blame] | 11571 | final int NSB = in.readInt(); |
| 11572 | if (mPowerProfile != null && |
| 11573 | mPowerProfile.getNumSpeedStepsInCpuCluster(cluster) != NSB) { |
| 11574 | throw new ParcelFormatException("File corrupt: too many speed bins " + |
| 11575 | NSB); |
| 11576 | } |
| 11577 | |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 11578 | u.mCpuClusterSpeed[cluster] = new LongSamplingCounter[NSB]; |
| 11579 | for (int speed = 0; speed < NSB; speed++) { |
| 11580 | if (in.readInt() != 0) { |
| 11581 | u.mCpuClusterSpeed[cluster][speed] = new LongSamplingCounter( |
| 11582 | mOnBatteryTimeBase); |
| 11583 | u.mCpuClusterSpeed[cluster][speed].readSummaryFromParcelLocked(in); |
| 11584 | } |
| 11585 | } |
Adam Lesinski | a57a540 | 2015-09-28 10:21:33 -0700 | [diff] [blame] | 11586 | } else { |
| 11587 | u.mCpuClusterSpeed[cluster] = null; |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 11588 | } |
| 11589 | } |
| 11590 | } else { |
| 11591 | u.mCpuClusterSpeed = null; |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 11592 | } |
| 11593 | |
Sudheer Shanka | 59f5c00 | 2017-05-15 10:57:15 -0700 | [diff] [blame] | 11594 | u.mCpuFreqTimeMs = LongSamplingCounterArray.readSummaryFromParcelLocked( |
| 11595 | in, mOnBatteryTimeBase); |
| 11596 | u.mScreenOffCpuFreqTimeMs = LongSamplingCounterArray.readSummaryFromParcelLocked( |
| 11597 | in, mOnBatteryScreenOffTimeBase); |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 11598 | |
| 11599 | if (in.readInt() != 0) { |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 11600 | u.mMobileRadioApWakeupCount = new LongSamplingCounter(mOnBatteryTimeBase); |
| 11601 | u.mMobileRadioApWakeupCount.readSummaryFromParcelLocked(in); |
| 11602 | } else { |
| 11603 | u.mMobileRadioApWakeupCount = null; |
| 11604 | } |
| 11605 | |
| 11606 | if (in.readInt() != 0) { |
| 11607 | u.mWifiRadioApWakeupCount = new LongSamplingCounter(mOnBatteryTimeBase); |
| 11608 | u.mWifiRadioApWakeupCount.readSummaryFromParcelLocked(in); |
| 11609 | } else { |
| 11610 | u.mWifiRadioApWakeupCount = null; |
| 11611 | } |
| 11612 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11613 | int NW = in.readInt(); |
Dianne Hackborn | cb99a72 | 2016-10-03 17:00:02 -0700 | [diff] [blame] | 11614 | if (NW > (MAX_WAKELOCKS_PER_UID+1)) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 11615 | throw new ParcelFormatException("File corrupt: too many wake locks " + NW); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 11616 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11617 | for (int iw = 0; iw < NW; iw++) { |
| 11618 | String wlName = in.readString(); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 11619 | u.readWakeSummaryFromParcelLocked(wlName, in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11620 | } |
| 11621 | |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 11622 | int NS = in.readInt(); |
Dianne Hackborn | cb99a72 | 2016-10-03 17:00:02 -0700 | [diff] [blame] | 11623 | if (NS > (MAX_WAKELOCKS_PER_UID+1)) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 11624 | throw new ParcelFormatException("File corrupt: too many syncs " + NS); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 11625 | } |
| 11626 | for (int is = 0; is < NS; is++) { |
| 11627 | String name = in.readString(); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 11628 | u.readSyncSummaryFromParcelLocked(name, in); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 11629 | } |
| 11630 | |
| 11631 | int NJ = in.readInt(); |
Dianne Hackborn | cb99a72 | 2016-10-03 17:00:02 -0700 | [diff] [blame] | 11632 | if (NJ > (MAX_WAKELOCKS_PER_UID+1)) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 11633 | throw new ParcelFormatException("File corrupt: too many job timers " + NJ); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 11634 | } |
| 11635 | for (int ij = 0; ij < NJ; ij++) { |
| 11636 | String name = in.readString(); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 11637 | u.readJobSummaryFromParcelLocked(name, in); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 11638 | } |
| 11639 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11640 | int NP = in.readInt(); |
Dianne Hackborn | 7b9c56f | 2010-12-07 11:14:53 -0800 | [diff] [blame] | 11641 | if (NP > 1000) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 11642 | throw new ParcelFormatException("File corrupt: too many sensors " + NP); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 11643 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11644 | for (int is = 0; is < NP; is++) { |
| 11645 | int seNumber = in.readInt(); |
| 11646 | if (in.readInt() != 0) { |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 11647 | u.getSensorTimerLocked(seNumber, true).readSummaryFromParcelLocked(in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11648 | } |
| 11649 | } |
| 11650 | |
| 11651 | NP = in.readInt(); |
Dianne Hackborn | 7b9c56f | 2010-12-07 11:14:53 -0800 | [diff] [blame] | 11652 | if (NP > 1000) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 11653 | throw new ParcelFormatException("File corrupt: too many processes " + NP); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 11654 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11655 | for (int ip = 0; ip < NP; ip++) { |
| 11656 | String procName = in.readString(); |
| 11657 | Uid.Proc p = u.getProcessStatsLocked(procName); |
| 11658 | p.mUserTime = p.mLoadedUserTime = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11659 | p.mSystemTime = p.mLoadedSystemTime = in.readLong(); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 11660 | p.mForegroundTime = p.mLoadedForegroundTime = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11661 | p.mStarts = p.mLoadedStarts = in.readInt(); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 11662 | p.mNumCrashes = p.mLoadedNumCrashes = in.readInt(); |
| 11663 | p.mNumAnrs = p.mLoadedNumAnrs = in.readInt(); |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 11664 | p.readExcessivePowerFromParcelLocked(in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11665 | } |
| 11666 | |
| 11667 | NP = in.readInt(); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 11668 | if (NP > 10000) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 11669 | throw new ParcelFormatException("File corrupt: too many packages " + NP); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 11670 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11671 | for (int ip = 0; ip < NP; ip++) { |
| 11672 | String pkgName = in.readString(); |
| 11673 | Uid.Pkg p = u.getPackageStatsLocked(pkgName); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 11674 | final int NWA = in.readInt(); |
| 11675 | if (NWA > 1000) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 11676 | throw new ParcelFormatException("File corrupt: too many wakeup alarms " + NWA); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 11677 | } |
| 11678 | p.mWakeupAlarms.clear(); |
| 11679 | for (int iwa=0; iwa<NWA; iwa++) { |
| 11680 | String tag = in.readString(); |
| 11681 | Counter c = new Counter(mOnBatteryTimeBase); |
| 11682 | c.readSummaryFromParcelLocked(in); |
| 11683 | p.mWakeupAlarms.put(tag, c); |
| 11684 | } |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 11685 | NS = in.readInt(); |
Dianne Hackborn | 7b9c56f | 2010-12-07 11:14:53 -0800 | [diff] [blame] | 11686 | if (NS > 1000) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 11687 | throw new ParcelFormatException("File corrupt: too many services " + NS); |
Dianne Hackborn | 7b9c56f | 2010-12-07 11:14:53 -0800 | [diff] [blame] | 11688 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11689 | for (int is = 0; is < NS; is++) { |
| 11690 | String servName = in.readString(); |
| 11691 | Uid.Pkg.Serv s = u.getServiceStatsLocked(pkgName, servName); |
| 11692 | s.mStartTime = s.mLoadedStartTime = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11693 | s.mStarts = s.mLoadedStarts = in.readInt(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11694 | s.mLaunches = s.mLoadedLaunches = in.readInt(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11695 | } |
| 11696 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11697 | } |
| 11698 | } |
| 11699 | |
| 11700 | /** |
| 11701 | * Writes a summary of the statistics to a Parcel, in a format suitable to be written to |
| 11702 | * disk. This format does not allow a lossless round-trip. |
| 11703 | * |
| 11704 | * @param out the Parcel to be written to. |
| 11705 | */ |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 11706 | public void writeSummaryToParcel(Parcel out, boolean inclHistory) { |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 11707 | pullPendingStateUpdatesLocked(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 11708 | |
Dianne Hackborn | 7d9eefd | 2014-08-27 18:30:31 -0700 | [diff] [blame] | 11709 | // Pull the clock time. This may update the time and make a new history entry |
| 11710 | // if we had originally pulled a time before the RTC was set. |
| 11711 | long startClockTime = getStartClockTime(); |
| 11712 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 11713 | final long NOW_SYS = mClocks.uptimeMillis() * 1000; |
| 11714 | final long NOWREAL_SYS = mClocks.elapsedRealtime() * 1000; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11715 | |
| 11716 | out.writeInt(VERSION); |
| 11717 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 11718 | writeHistory(out, inclHistory, true); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 11719 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11720 | out.writeInt(mStartCount); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 11721 | out.writeLong(computeUptime(NOW_SYS, STATS_SINCE_CHARGED)); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 11722 | out.writeLong(computeRealtime(NOWREAL_SYS, STATS_SINCE_CHARGED)); |
Dianne Hackborn | 7d9eefd | 2014-08-27 18:30:31 -0700 | [diff] [blame] | 11723 | out.writeLong(startClockTime); |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 11724 | out.writeString(mStartPlatformVersion); |
| 11725 | out.writeString(mEndPlatformVersion); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 11726 | mOnBatteryTimeBase.writeSummaryToParcel(out, NOW_SYS, NOWREAL_SYS); |
| 11727 | mOnBatteryScreenOffTimeBase.writeSummaryToParcel(out, NOW_SYS, NOWREAL_SYS); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 11728 | out.writeInt(mDischargeUnplugLevel); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 11729 | out.writeInt(mDischargePlugLevel); |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 11730 | out.writeInt(mDischargeCurrentLevel); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 11731 | out.writeInt(mCurrentBatteryLevel); |
Adam Lesinski | f9b20a9 | 2016-06-17 17:30:01 -0700 | [diff] [blame] | 11732 | out.writeInt(mEstimatedBatteryCapacity); |
Jocelyn Dang | c627d10 | 2017-04-14 13:15:14 -0700 | [diff] [blame] | 11733 | out.writeInt(mMinLearnedBatteryCapacity); |
| 11734 | out.writeInt(mMaxLearnedBatteryCapacity); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 11735 | out.writeInt(getLowDischargeAmountSinceCharge()); |
| 11736 | out.writeInt(getHighDischargeAmountSinceCharge()); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 11737 | out.writeInt(getDischargeAmountScreenOnSinceCharge()); |
| 11738 | out.writeInt(getDischargeAmountScreenOffSinceCharge()); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 11739 | mDischargeStepTracker.writeToParcel(out); |
| 11740 | mChargeStepTracker.writeToParcel(out); |
| 11741 | mDailyDischargeStepTracker.writeToParcel(out); |
| 11742 | mDailyChargeStepTracker.writeToParcel(out); |
Adam Lesinski | 67c134f | 2016-06-10 15:15:08 -0700 | [diff] [blame] | 11743 | mDischargeCounter.writeSummaryFromParcelLocked(out); |
| 11744 | mDischargeScreenOffCounter.writeSummaryFromParcelLocked(out); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 11745 | if (mDailyPackageChanges != null) { |
| 11746 | final int NPKG = mDailyPackageChanges.size(); |
| 11747 | out.writeInt(NPKG); |
| 11748 | for (int i=0; i<NPKG; i++) { |
| 11749 | PackageChange pc = mDailyPackageChanges.get(i); |
| 11750 | out.writeString(pc.mPackageName); |
| 11751 | out.writeInt(pc.mUpdate ? 1 : 0); |
| 11752 | out.writeInt(pc.mVersionCode); |
| 11753 | } |
| 11754 | } else { |
| 11755 | out.writeInt(0); |
| 11756 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 11757 | out.writeLong(mDailyStartTime); |
| 11758 | out.writeLong(mNextMinDailyDeadline); |
| 11759 | out.writeLong(mNextMaxDailyDeadline); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 11760 | |
| 11761 | mScreenOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 11762 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 11763 | mScreenBrightnessTimer[i].writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 11764 | } |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 11765 | mInteractiveTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 11766 | mPowerSaveModeEnabledTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 11767 | out.writeLong(mLongestLightIdleTime); |
| 11768 | out.writeLong(mLongestFullIdleTime); |
| 11769 | mDeviceIdleModeLightTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 11770 | mDeviceIdleModeFullTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 11771 | mDeviceLightIdlingTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 11772 | mDeviceIdlingTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 11773 | mPhoneOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 11774 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 11775 | mPhoneSignalStrengthsTimer[i].writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 11776 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 11777 | mPhoneSignalScanningTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 11778 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 11779 | mPhoneDataConnectionsTimer[i].writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 11780 | } |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 11781 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 11782 | mNetworkByteActivityCounters[i].writeSummaryFromParcelLocked(out); |
| 11783 | mNetworkPacketActivityCounters[i].writeSummaryFromParcelLocked(out); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 11784 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 11785 | mMobileRadioActiveTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 11786 | mMobileRadioActivePerAppTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 11787 | mMobileRadioActiveAdjustedTime.writeSummaryFromParcelLocked(out); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 11788 | mMobileRadioActiveUnknownTime.writeSummaryFromParcelLocked(out); |
| 11789 | mMobileRadioActiveUnknownCount.writeSummaryFromParcelLocked(out); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 11790 | mWifiOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 11791 | mGlobalWifiRunningTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 11792 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 11793 | mWifiStateTimer[i].writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 11794 | } |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 11795 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
| 11796 | mWifiSupplStateTimer[i].writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 11797 | } |
| 11798 | for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 11799 | mWifiSignalStrengthsTimer[i].writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 11800 | } |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 11801 | mWifiActivity.writeSummaryToParcel(out); |
| 11802 | mBluetoothActivity.writeSummaryToParcel(out); |
| 11803 | mModemActivity.writeSummaryToParcel(out); |
| 11804 | out.writeInt(mHasWifiReporting ? 1 : 0); |
| 11805 | out.writeInt(mHasBluetoothReporting ? 1 : 0); |
| 11806 | out.writeInt(mHasModemReporting ? 1 : 0); |
| 11807 | |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 11808 | out.writeInt(mNumConnectivityChange); |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 11809 | mFlashlightOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 11810 | mCameraOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 11811 | mBluetoothScanTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11812 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 11813 | out.writeInt(mKernelWakelockStats.size()); |
| 11814 | for (Map.Entry<String, SamplingTimer> ent : mKernelWakelockStats.entrySet()) { |
| 11815 | Timer kwlt = ent.getValue(); |
| 11816 | if (kwlt != null) { |
| 11817 | out.writeInt(1); |
| 11818 | out.writeString(ent.getKey()); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 11819 | kwlt.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 11820 | } else { |
| 11821 | out.writeInt(0); |
| 11822 | } |
| 11823 | } |
| 11824 | |
| 11825 | out.writeInt(mWakeupReasonStats.size()); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 11826 | for (Map.Entry<String, SamplingTimer> ent : mWakeupReasonStats.entrySet()) { |
| 11827 | SamplingTimer timer = ent.getValue(); |
| 11828 | if (timer != null) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 11829 | out.writeInt(1); |
| 11830 | out.writeString(ent.getKey()); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 11831 | timer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 11832 | } else { |
| 11833 | out.writeInt(0); |
| 11834 | } |
| 11835 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 11836 | |
James Carr | 3a22605 | 2016-07-01 14:49:52 -0700 | [diff] [blame] | 11837 | out.writeInt(mKernelMemoryStats.size()); |
| 11838 | for (int i = 0; i < mKernelMemoryStats.size(); i++) { |
| 11839 | Timer kmt = mKernelMemoryStats.valueAt(i); |
| 11840 | if (kmt != null) { |
| 11841 | out.writeInt(1); |
| 11842 | out.writeLong(mKernelMemoryStats.keyAt(i)); |
| 11843 | kmt.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 11844 | } else { |
| 11845 | out.writeInt(0); |
| 11846 | } |
| 11847 | } |
| 11848 | |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 11849 | out.writeLongArray(mCpuFreqs); |
| 11850 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11851 | final int NU = mUidStats.size(); |
| 11852 | out.writeInt(NU); |
| 11853 | for (int iu = 0; iu < NU; iu++) { |
| 11854 | out.writeInt(mUidStats.keyAt(iu)); |
| 11855 | Uid u = mUidStats.valueAt(iu); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 11856 | |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 11857 | u.mOnBatteryBackgroundTimeBase.writeSummaryToParcel(out, NOW_SYS, NOWREAL_SYS); |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 11858 | u.mOnBatteryScreenOffBackgroundTimeBase.writeSummaryToParcel(out, NOW_SYS, NOWREAL_SYS); |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 11859 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 11860 | if (u.mWifiRunningTimer != null) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 11861 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 11862 | u.mWifiRunningTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 11863 | } else { |
| 11864 | out.writeInt(0); |
| 11865 | } |
| 11866 | if (u.mFullWifiLockTimer != null) { |
| 11867 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 11868 | u.mFullWifiLockTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 11869 | } else { |
| 11870 | out.writeInt(0); |
| 11871 | } |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 11872 | if (u.mWifiScanTimer != null) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 11873 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 11874 | u.mWifiScanTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 11875 | } else { |
| 11876 | out.writeInt(0); |
| 11877 | } |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 11878 | for (int i = 0; i < Uid.NUM_WIFI_BATCHED_SCAN_BINS; i++) { |
| 11879 | if (u.mWifiBatchedScanTimer[i] != null) { |
| 11880 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 11881 | u.mWifiBatchedScanTimer[i].writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 11882 | } else { |
| 11883 | out.writeInt(0); |
| 11884 | } |
| 11885 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 11886 | if (u.mWifiMulticastTimer != null) { |
| 11887 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 11888 | u.mWifiMulticastTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 11889 | } else { |
| 11890 | out.writeInt(0); |
| 11891 | } |
| 11892 | if (u.mAudioTurnedOnTimer != null) { |
| 11893 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 11894 | u.mAudioTurnedOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 11895 | } else { |
| 11896 | out.writeInt(0); |
| 11897 | } |
| 11898 | if (u.mVideoTurnedOnTimer != null) { |
| 11899 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 11900 | u.mVideoTurnedOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 11901 | } else { |
| 11902 | out.writeInt(0); |
| 11903 | } |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 11904 | if (u.mFlashlightTurnedOnTimer != null) { |
| 11905 | out.writeInt(1); |
| 11906 | u.mFlashlightTurnedOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 11907 | } else { |
| 11908 | out.writeInt(0); |
| 11909 | } |
| 11910 | if (u.mCameraTurnedOnTimer != null) { |
| 11911 | out.writeInt(1); |
| 11912 | u.mCameraTurnedOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 11913 | } else { |
| 11914 | out.writeInt(0); |
| 11915 | } |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 11916 | if (u.mForegroundActivityTimer != null) { |
| 11917 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 11918 | u.mForegroundActivityTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 11919 | } else { |
| 11920 | out.writeInt(0); |
| 11921 | } |
Bookatz | c8c4496 | 2017-05-11 12:12:54 -0700 | [diff] [blame] | 11922 | if (u.mAggregatedPartialWakelockTimer != null) { |
| 11923 | out.writeInt(1); |
| 11924 | u.mAggregatedPartialWakelockTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 11925 | } else { |
| 11926 | out.writeInt(0); |
| 11927 | } |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 11928 | if (u.mBluetoothScanTimer != null) { |
| 11929 | out.writeInt(1); |
| 11930 | u.mBluetoothScanTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 11931 | } else { |
| 11932 | out.writeInt(0); |
| 11933 | } |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 11934 | if (u.mBluetoothUnoptimizedScanTimer != null) { |
| 11935 | out.writeInt(1); |
| 11936 | u.mBluetoothUnoptimizedScanTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 11937 | } else { |
| 11938 | out.writeInt(0); |
| 11939 | } |
Bookatz | 956f36bf | 2017-04-28 09:48:17 -0700 | [diff] [blame] | 11940 | if (u.mBluetoothScanResultCounter != null) { |
| 11941 | out.writeInt(1); |
| 11942 | u.mBluetoothScanResultCounter.writeSummaryFromParcelLocked(out); |
| 11943 | } else { |
| 11944 | out.writeInt(0); |
| 11945 | } |
Bookatz | b1f04f3 | 2017-05-19 13:57:32 -0700 | [diff] [blame] | 11946 | if (u.mBluetoothScanResultBgCounter != null) { |
| 11947 | out.writeInt(1); |
| 11948 | u.mBluetoothScanResultBgCounter.writeSummaryFromParcelLocked(out); |
| 11949 | } else { |
| 11950 | out.writeInt(0); |
| 11951 | } |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 11952 | for (int i = 0; i < Uid.NUM_PROCESS_STATE; i++) { |
| 11953 | if (u.mProcessStateTimer[i] != null) { |
| 11954 | out.writeInt(1); |
| 11955 | u.mProcessStateTimer[i].writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 11956 | } else { |
| 11957 | out.writeInt(0); |
| 11958 | } |
| 11959 | } |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 11960 | if (u.mVibratorOnTimer != null) { |
| 11961 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 11962 | u.mVibratorOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 11963 | } else { |
| 11964 | out.writeInt(0); |
| 11965 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11966 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 11967 | if (u.mUserActivityCounters == null) { |
| 11968 | out.writeInt(0); |
| 11969 | } else { |
| 11970 | out.writeInt(1); |
| 11971 | for (int i=0; i<Uid.NUM_USER_ACTIVITY_TYPES; i++) { |
| 11972 | u.mUserActivityCounters[i].writeSummaryFromParcelLocked(out); |
| 11973 | } |
| 11974 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 11975 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 11976 | if (u.mNetworkByteActivityCounters == null) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 11977 | out.writeInt(0); |
| 11978 | } else { |
| 11979 | out.writeInt(1); |
| 11980 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 11981 | u.mNetworkByteActivityCounters[i].writeSummaryFromParcelLocked(out); |
| 11982 | u.mNetworkPacketActivityCounters[i].writeSummaryFromParcelLocked(out); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 11983 | } |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 11984 | u.mMobileRadioActiveTime.writeSummaryFromParcelLocked(out); |
| 11985 | u.mMobileRadioActiveCount.writeSummaryFromParcelLocked(out); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 11986 | } |
| 11987 | |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 11988 | u.mUserCpuTime.writeSummaryFromParcelLocked(out); |
| 11989 | u.mSystemCpuTime.writeSummaryFromParcelLocked(out); |
| 11990 | |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 11991 | if (u.mCpuClusterSpeed != null) { |
| 11992 | out.writeInt(1); |
| 11993 | out.writeInt(u.mCpuClusterSpeed.length); |
| 11994 | for (LongSamplingCounter[] cpuSpeeds : u.mCpuClusterSpeed) { |
| 11995 | if (cpuSpeeds != null) { |
| 11996 | out.writeInt(1); |
| 11997 | out.writeInt(cpuSpeeds.length); |
| 11998 | for (LongSamplingCounter c : cpuSpeeds) { |
| 11999 | if (c != null) { |
| 12000 | out.writeInt(1); |
| 12001 | c.writeSummaryFromParcelLocked(out); |
| 12002 | } else { |
| 12003 | out.writeInt(0); |
| 12004 | } |
| 12005 | } |
| 12006 | } else { |
| 12007 | out.writeInt(0); |
| 12008 | } |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 12009 | } |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 12010 | } else { |
| 12011 | out.writeInt(0); |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 12012 | } |
| 12013 | |
Sudheer Shanka | 59f5c00 | 2017-05-15 10:57:15 -0700 | [diff] [blame] | 12014 | LongSamplingCounterArray.writeSummaryToParcelLocked(out, u.mCpuFreqTimeMs); |
| 12015 | LongSamplingCounterArray.writeSummaryToParcelLocked(out, u.mScreenOffCpuFreqTimeMs); |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 12016 | |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 12017 | if (u.mMobileRadioApWakeupCount != null) { |
| 12018 | out.writeInt(1); |
| 12019 | u.mMobileRadioApWakeupCount.writeSummaryFromParcelLocked(out); |
| 12020 | } else { |
| 12021 | out.writeInt(0); |
| 12022 | } |
| 12023 | |
| 12024 | if (u.mWifiRadioApWakeupCount != null) { |
| 12025 | out.writeInt(1); |
| 12026 | u.mWifiRadioApWakeupCount.writeSummaryFromParcelLocked(out); |
| 12027 | } else { |
| 12028 | out.writeInt(0); |
| 12029 | } |
| 12030 | |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 12031 | final ArrayMap<String, Uid.Wakelock> wakeStats = u.mWakelockStats.getMap(); |
| 12032 | int NW = wakeStats.size(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12033 | out.writeInt(NW); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 12034 | for (int iw=0; iw<NW; iw++) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 12035 | out.writeString(wakeStats.keyAt(iw)); |
| 12036 | Uid.Wakelock wl = wakeStats.valueAt(iw); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 12037 | if (wl.mTimerFull != null) { |
| 12038 | out.writeInt(1); |
| 12039 | wl.mTimerFull.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 12040 | } else { |
| 12041 | out.writeInt(0); |
| 12042 | } |
| 12043 | if (wl.mTimerPartial != null) { |
| 12044 | out.writeInt(1); |
| 12045 | wl.mTimerPartial.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 12046 | } else { |
| 12047 | out.writeInt(0); |
| 12048 | } |
| 12049 | if (wl.mTimerWindow != null) { |
| 12050 | out.writeInt(1); |
| 12051 | wl.mTimerWindow.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 12052 | } else { |
| 12053 | out.writeInt(0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12054 | } |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 12055 | if (wl.mTimerDraw != null) { |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 12056 | out.writeInt(1); |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 12057 | wl.mTimerDraw.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 12058 | } else { |
| 12059 | out.writeInt(0); |
| 12060 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12061 | } |
| 12062 | |
Bookatz | 2bffb5b | 2017-04-13 11:59:33 -0700 | [diff] [blame] | 12063 | final ArrayMap<String, DualTimer> syncStats = u.mSyncStats.getMap(); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 12064 | int NS = syncStats.size(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 12065 | out.writeInt(NS); |
| 12066 | for (int is=0; is<NS; is++) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 12067 | out.writeString(syncStats.keyAt(is)); |
| 12068 | syncStats.valueAt(is).writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 12069 | } |
| 12070 | |
Bookatz | aa4594a | 2017-03-24 12:39:56 -0700 | [diff] [blame] | 12071 | final ArrayMap<String, DualTimer> jobStats = u.mJobStats.getMap(); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 12072 | int NJ = jobStats.size(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 12073 | out.writeInt(NJ); |
| 12074 | for (int ij=0; ij<NJ; ij++) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 12075 | out.writeString(jobStats.keyAt(ij)); |
| 12076 | jobStats.valueAt(ij).writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 12077 | } |
| 12078 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12079 | int NSE = u.mSensorStats.size(); |
| 12080 | out.writeInt(NSE); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 12081 | for (int ise=0; ise<NSE; ise++) { |
| 12082 | out.writeInt(u.mSensorStats.keyAt(ise)); |
| 12083 | Uid.Sensor se = u.mSensorStats.valueAt(ise); |
| 12084 | if (se.mTimer != null) { |
| 12085 | out.writeInt(1); |
| 12086 | se.mTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 12087 | } else { |
| 12088 | out.writeInt(0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12089 | } |
| 12090 | } |
| 12091 | |
| 12092 | int NP = u.mProcessStats.size(); |
| 12093 | out.writeInt(NP); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 12094 | for (int ip=0; ip<NP; ip++) { |
| 12095 | out.writeString(u.mProcessStats.keyAt(ip)); |
| 12096 | Uid.Proc ps = u.mProcessStats.valueAt(ip); |
| 12097 | out.writeLong(ps.mUserTime); |
| 12098 | out.writeLong(ps.mSystemTime); |
| 12099 | out.writeLong(ps.mForegroundTime); |
| 12100 | out.writeInt(ps.mStarts); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 12101 | out.writeInt(ps.mNumCrashes); |
| 12102 | out.writeInt(ps.mNumAnrs); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 12103 | ps.writeExcessivePowerToParcelLocked(out); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12104 | } |
| 12105 | |
| 12106 | NP = u.mPackageStats.size(); |
| 12107 | out.writeInt(NP); |
| 12108 | if (NP > 0) { |
| 12109 | for (Map.Entry<String, BatteryStatsImpl.Uid.Pkg> ent |
| 12110 | : u.mPackageStats.entrySet()) { |
| 12111 | out.writeString(ent.getKey()); |
| 12112 | Uid.Pkg ps = ent.getValue(); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 12113 | final int NWA = ps.mWakeupAlarms.size(); |
| 12114 | out.writeInt(NWA); |
| 12115 | for (int iwa=0; iwa<NWA; iwa++) { |
| 12116 | out.writeString(ps.mWakeupAlarms.keyAt(iwa)); |
| 12117 | ps.mWakeupAlarms.valueAt(iwa).writeSummaryFromParcelLocked(out); |
| 12118 | } |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 12119 | NS = ps.mServiceStats.size(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12120 | out.writeInt(NS); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 12121 | for (int is=0; is<NS; is++) { |
| 12122 | out.writeString(ps.mServiceStats.keyAt(is)); |
| 12123 | BatteryStatsImpl.Uid.Pkg.Serv ss = ps.mServiceStats.valueAt(is); |
| 12124 | long time = ss.getStartTimeToNowLocked( |
| 12125 | mOnBatteryTimeBase.getUptime(NOW_SYS)); |
| 12126 | out.writeLong(time); |
| 12127 | out.writeInt(ss.mStarts); |
| 12128 | out.writeInt(ss.mLaunches); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12129 | } |
| 12130 | } |
| 12131 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12132 | } |
| 12133 | } |
| 12134 | |
| 12135 | public void readFromParcel(Parcel in) { |
| 12136 | readFromParcelLocked(in); |
| 12137 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 12138 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12139 | void readFromParcelLocked(Parcel in) { |
| 12140 | int magic = in.readInt(); |
| 12141 | if (magic != MAGIC) { |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 12142 | throw new ParcelFormatException("Bad magic number: #" + Integer.toHexString(magic)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12143 | } |
| 12144 | |
Dianne Hackborn | ae38445 | 2011-06-28 12:33:48 -0700 | [diff] [blame] | 12145 | readHistory(in, false); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 12146 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12147 | mStartCount = in.readInt(); |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 12148 | mStartClockTime = in.readLong(); |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 12149 | mStartPlatformVersion = in.readString(); |
| 12150 | mEndPlatformVersion = in.readString(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12151 | mUptime = in.readLong(); |
| 12152 | mUptimeStart = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12153 | mRealtime = in.readLong(); |
| 12154 | mRealtimeStart = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12155 | mOnBattery = in.readInt() != 0; |
Adam Lesinski | f9b20a9 | 2016-06-17 17:30:01 -0700 | [diff] [blame] | 12156 | mEstimatedBatteryCapacity = in.readInt(); |
Jocelyn Dang | c627d10 | 2017-04-14 13:15:14 -0700 | [diff] [blame] | 12157 | mMinLearnedBatteryCapacity = in.readInt(); |
| 12158 | mMaxLearnedBatteryCapacity = in.readInt(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12159 | mOnBatteryInternal = false; // we are no longer really running. |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 12160 | mOnBatteryTimeBase.readFromParcel(in); |
| 12161 | mOnBatteryScreenOffTimeBase.readFromParcel(in); |
| 12162 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 12163 | mScreenState = Display.STATE_UNKNOWN; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 12164 | mScreenOnTimer = new StopwatchTimer(mClocks, null, -1, null, mOnBatteryTimeBase, in); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 12165 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 12166 | mScreenBrightnessTimer[i] = new StopwatchTimer(mClocks, null, -100-i, null, |
| 12167 | mOnBatteryTimeBase, in); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 12168 | } |
Dianne Hackborn | 2932513 | 2014-05-21 15:01:03 -0700 | [diff] [blame] | 12169 | mInteractive = false; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 12170 | mInteractiveTimer = new StopwatchTimer(mClocks, null, -10, null, mOnBatteryTimeBase, in); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 12171 | mPhoneOn = false; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 12172 | mPowerSaveModeEnabledTimer = new StopwatchTimer(mClocks, null, -2, null, |
| 12173 | mOnBatteryTimeBase, in); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 12174 | mLongestLightIdleTime = in.readLong(); |
| 12175 | mLongestFullIdleTime = in.readLong(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 12176 | mDeviceIdleModeLightTimer = new StopwatchTimer(mClocks, null, -14, null, |
| 12177 | mOnBatteryTimeBase, in); |
| 12178 | mDeviceIdleModeFullTimer = new StopwatchTimer(mClocks, null, -11, null, |
| 12179 | mOnBatteryTimeBase, in); |
| 12180 | mDeviceLightIdlingTimer = new StopwatchTimer(mClocks, null, -15, null, |
| 12181 | mOnBatteryTimeBase, in); |
| 12182 | mDeviceIdlingTimer = new StopwatchTimer(mClocks, null, -12, null, mOnBatteryTimeBase, in); |
| 12183 | mPhoneOnTimer = new StopwatchTimer(mClocks, null, -3, null, mOnBatteryTimeBase, in); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 12184 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 12185 | mPhoneSignalStrengthsTimer[i] = new StopwatchTimer(mClocks, null, -200-i, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 12186 | null, mOnBatteryTimeBase, in); |
| 12187 | } |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 12188 | mPhoneSignalScanningTimer = new StopwatchTimer(mClocks, null, -200+1, null, |
| 12189 | mOnBatteryTimeBase, in); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 12190 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 12191 | mPhoneDataConnectionsTimer[i] = new StopwatchTimer(mClocks, null, -300-i, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 12192 | null, mOnBatteryTimeBase, in); |
| 12193 | } |
| 12194 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
| 12195 | mNetworkByteActivityCounters[i] = new LongSamplingCounter(mOnBatteryTimeBase, in); |
| 12196 | mNetworkPacketActivityCounters[i] = new LongSamplingCounter(mOnBatteryTimeBase, in); |
| 12197 | } |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 12198 | mMobileRadioPowerState = DataConnectionRealTimeInfo.DC_POWER_STATE_LOW; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 12199 | mMobileRadioActiveTimer = new StopwatchTimer(mClocks, null, -400, null, |
| 12200 | mOnBatteryTimeBase, in); |
| 12201 | mMobileRadioActivePerAppTimer = new StopwatchTimer(mClocks, null, -401, null, |
| 12202 | mOnBatteryTimeBase, in); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 12203 | mMobileRadioActiveAdjustedTime = new LongSamplingCounter(mOnBatteryTimeBase, in); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 12204 | mMobileRadioActiveUnknownTime = new LongSamplingCounter(mOnBatteryTimeBase, in); |
| 12205 | mMobileRadioActiveUnknownCount = new LongSamplingCounter(mOnBatteryTimeBase, in); |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 12206 | mWifiRadioPowerState = DataConnectionRealTimeInfo.DC_POWER_STATE_LOW; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 12207 | mWifiOn = false; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 12208 | mWifiOnTimer = new StopwatchTimer(mClocks, null, -4, null, mOnBatteryTimeBase, in); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 12209 | mGlobalWifiRunning = false; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 12210 | mGlobalWifiRunningTimer = new StopwatchTimer(mClocks, null, -5, null, |
| 12211 | mOnBatteryTimeBase, in); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 12212 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 12213 | mWifiStateTimer[i] = new StopwatchTimer(mClocks, null, -600-i, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 12214 | null, mOnBatteryTimeBase, in); |
| 12215 | } |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 12216 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 12217 | mWifiSupplStateTimer[i] = new StopwatchTimer(mClocks, null, -700-i, |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 12218 | null, mOnBatteryTimeBase, in); |
| 12219 | } |
| 12220 | for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 12221 | mWifiSignalStrengthsTimer[i] = new StopwatchTimer(mClocks, null, -800-i, |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 12222 | null, mOnBatteryTimeBase, in); |
| 12223 | } |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 12224 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 12225 | mWifiActivity = new ControllerActivityCounterImpl(mOnBatteryTimeBase, |
| 12226 | NUM_WIFI_TX_LEVELS, in); |
| 12227 | mBluetoothActivity = new ControllerActivityCounterImpl(mOnBatteryTimeBase, |
| 12228 | NUM_BT_TX_LEVELS, in); |
| 12229 | mModemActivity = new ControllerActivityCounterImpl(mOnBatteryTimeBase, |
| 12230 | ModemActivityInfo.TX_POWER_LEVELS, in); |
| 12231 | mHasWifiReporting = in.readInt() != 0; |
| 12232 | mHasBluetoothReporting = in.readInt() != 0; |
| 12233 | mHasModemReporting = in.readInt() != 0; |
| 12234 | |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 12235 | mNumConnectivityChange = in.readInt(); |
| 12236 | mLoadedNumConnectivityChange = in.readInt(); |
| 12237 | mUnpluggedNumConnectivityChange = in.readInt(); |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 12238 | mAudioOnNesting = 0; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 12239 | mAudioOnTimer = new StopwatchTimer(mClocks, null, -7, null, mOnBatteryTimeBase); |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 12240 | mVideoOnNesting = 0; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 12241 | mVideoOnTimer = new StopwatchTimer(mClocks, null, -8, null, mOnBatteryTimeBase); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 12242 | mFlashlightOnNesting = 0; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 12243 | mFlashlightOnTimer = new StopwatchTimer(mClocks, null, -9, null, mOnBatteryTimeBase, in); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 12244 | mCameraOnNesting = 0; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 12245 | mCameraOnTimer = new StopwatchTimer(mClocks, null, -13, null, mOnBatteryTimeBase, in); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 12246 | mBluetoothScanNesting = 0; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 12247 | mBluetoothScanTimer = new StopwatchTimer(mClocks, null, -14, null, mOnBatteryTimeBase, in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 12248 | mDischargeUnplugLevel = in.readInt(); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 12249 | mDischargePlugLevel = in.readInt(); |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 12250 | mDischargeCurrentLevel = in.readInt(); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 12251 | mCurrentBatteryLevel = in.readInt(); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 12252 | mLowDischargeAmountSinceCharge = in.readInt(); |
| 12253 | mHighDischargeAmountSinceCharge = in.readInt(); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 12254 | mDischargeAmountScreenOn = in.readInt(); |
| 12255 | mDischargeAmountScreenOnSinceCharge = in.readInt(); |
| 12256 | mDischargeAmountScreenOff = in.readInt(); |
| 12257 | mDischargeAmountScreenOffSinceCharge = in.readInt(); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 12258 | mDischargeStepTracker.readFromParcel(in); |
| 12259 | mChargeStepTracker.readFromParcel(in); |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 12260 | mDischargeCounter = new LongSamplingCounter(mOnBatteryTimeBase, in); |
| 12261 | mDischargeScreenOffCounter = new LongSamplingCounter(mOnBatteryTimeBase, in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12262 | mLastWriteTime = in.readLong(); |
| 12263 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 12264 | mKernelWakelockStats.clear(); |
| 12265 | int NKW = in.readInt(); |
| 12266 | for (int ikw = 0; ikw < NKW; ikw++) { |
| 12267 | if (in.readInt() != 0) { |
| 12268 | String wakelockName = in.readString(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 12269 | SamplingTimer kwlt = new SamplingTimer(mClocks, mOnBatteryScreenOffTimeBase, in); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 12270 | mKernelWakelockStats.put(wakelockName, kwlt); |
| 12271 | } |
| 12272 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 12273 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 12274 | mWakeupReasonStats.clear(); |
| 12275 | int NWR = in.readInt(); |
| 12276 | for (int iwr = 0; iwr < NWR; iwr++) { |
| 12277 | if (in.readInt() != 0) { |
| 12278 | String reasonName = in.readString(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 12279 | SamplingTimer timer = new SamplingTimer(mClocks, mOnBatteryTimeBase, in); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 12280 | mWakeupReasonStats.put(reasonName, timer); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 12281 | } |
| 12282 | } |
| 12283 | |
James Carr | 3a22605 | 2016-07-01 14:49:52 -0700 | [diff] [blame] | 12284 | mKernelMemoryStats.clear(); |
| 12285 | int nmt = in.readInt(); |
| 12286 | for (int imt = 0; imt < nmt; imt++) { |
| 12287 | if (in.readInt() != 0) { |
| 12288 | Long bucket = in.readLong(); |
| 12289 | SamplingTimer kmt = new SamplingTimer(mClocks, mOnBatteryTimeBase, in); |
| 12290 | mKernelMemoryStats.put(bucket, kmt); |
| 12291 | } |
| 12292 | } |
| 12293 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12294 | mPartialTimers.clear(); |
| 12295 | mFullTimers.clear(); |
| 12296 | mWindowTimers.clear(); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 12297 | mWifiRunningTimers.clear(); |
| 12298 | mFullWifiLockTimers.clear(); |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 12299 | mWifiScanTimers.clear(); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 12300 | mWifiBatchedScanTimers.clear(); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 12301 | mWifiMulticastTimers.clear(); |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 12302 | mAudioTurnedOnTimers.clear(); |
| 12303 | mVideoTurnedOnTimers.clear(); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 12304 | mFlashlightTurnedOnTimers.clear(); |
| 12305 | mCameraTurnedOnTimers.clear(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12306 | |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 12307 | mCpuFreqs = in.createLongArray(); |
| 12308 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12309 | int numUids = in.readInt(); |
| 12310 | mUidStats.clear(); |
| 12311 | for (int i = 0; i < numUids; i++) { |
| 12312 | int uid = in.readInt(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 12313 | Uid u = new Uid(this, uid); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 12314 | u.readFromParcelLocked(mOnBatteryTimeBase, mOnBatteryScreenOffTimeBase, in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12315 | mUidStats.append(uid, u); |
| 12316 | } |
| 12317 | } |
| 12318 | |
| 12319 | public void writeToParcel(Parcel out, int flags) { |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 12320 | writeToParcelLocked(out, true, flags); |
| 12321 | } |
| 12322 | |
| 12323 | public void writeToParcelWithoutUids(Parcel out, int flags) { |
| 12324 | writeToParcelLocked(out, false, flags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12325 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 12326 | |
| 12327 | @SuppressWarnings("unused") |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 12328 | void writeToParcelLocked(Parcel out, boolean inclUids, int flags) { |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 12329 | // Need to update with current kernel wake lock counts. |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 12330 | pullPendingStateUpdatesLocked(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 12331 | |
Dianne Hackborn | 7d9eefd | 2014-08-27 18:30:31 -0700 | [diff] [blame] | 12332 | // Pull the clock time. This may update the time and make a new history entry |
| 12333 | // if we had originally pulled a time before the RTC was set. |
| 12334 | long startClockTime = getStartClockTime(); |
| 12335 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 12336 | final long uSecUptime = mClocks.uptimeMillis() * 1000; |
| 12337 | final long uSecRealtime = mClocks.elapsedRealtime() * 1000; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 12338 | final long batteryRealtime = mOnBatteryTimeBase.getRealtime(uSecRealtime); |
| 12339 | final long batteryScreenOffRealtime = mOnBatteryScreenOffTimeBase.getRealtime(uSecRealtime); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 12340 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12341 | out.writeInt(MAGIC); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 12342 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 12343 | writeHistory(out, true, false); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 12344 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12345 | out.writeInt(mStartCount); |
Dianne Hackborn | 7d9eefd | 2014-08-27 18:30:31 -0700 | [diff] [blame] | 12346 | out.writeLong(startClockTime); |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 12347 | out.writeString(mStartPlatformVersion); |
| 12348 | out.writeString(mEndPlatformVersion); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12349 | out.writeLong(mUptime); |
| 12350 | out.writeLong(mUptimeStart); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12351 | out.writeLong(mRealtime); |
| 12352 | out.writeLong(mRealtimeStart); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12353 | out.writeInt(mOnBattery ? 1 : 0); |
Adam Lesinski | f9b20a9 | 2016-06-17 17:30:01 -0700 | [diff] [blame] | 12354 | out.writeInt(mEstimatedBatteryCapacity); |
Jocelyn Dang | c627d10 | 2017-04-14 13:15:14 -0700 | [diff] [blame] | 12355 | out.writeInt(mMinLearnedBatteryCapacity); |
| 12356 | out.writeInt(mMaxLearnedBatteryCapacity); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 12357 | mOnBatteryTimeBase.writeToParcel(out, uSecUptime, uSecRealtime); |
| 12358 | mOnBatteryScreenOffTimeBase.writeToParcel(out, uSecUptime, uSecRealtime); |
| 12359 | |
| 12360 | mScreenOnTimer.writeToParcel(out, uSecRealtime); |
| 12361 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
| 12362 | mScreenBrightnessTimer[i].writeToParcel(out, uSecRealtime); |
| 12363 | } |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 12364 | mInteractiveTimer.writeToParcel(out, uSecRealtime); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 12365 | mPowerSaveModeEnabledTimer.writeToParcel(out, uSecRealtime); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 12366 | out.writeLong(mLongestLightIdleTime); |
| 12367 | out.writeLong(mLongestFullIdleTime); |
| 12368 | mDeviceIdleModeLightTimer.writeToParcel(out, uSecRealtime); |
| 12369 | mDeviceIdleModeFullTimer.writeToParcel(out, uSecRealtime); |
| 12370 | mDeviceLightIdlingTimer.writeToParcel(out, uSecRealtime); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 12371 | mDeviceIdlingTimer.writeToParcel(out, uSecRealtime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 12372 | mPhoneOnTimer.writeToParcel(out, uSecRealtime); |
| 12373 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
| 12374 | mPhoneSignalStrengthsTimer[i].writeToParcel(out, uSecRealtime); |
| 12375 | } |
| 12376 | mPhoneSignalScanningTimer.writeToParcel(out, uSecRealtime); |
| 12377 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
| 12378 | mPhoneDataConnectionsTimer[i].writeToParcel(out, uSecRealtime); |
| 12379 | } |
| 12380 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
| 12381 | mNetworkByteActivityCounters[i].writeToParcel(out); |
| 12382 | mNetworkPacketActivityCounters[i].writeToParcel(out); |
| 12383 | } |
| 12384 | mMobileRadioActiveTimer.writeToParcel(out, uSecRealtime); |
| 12385 | mMobileRadioActivePerAppTimer.writeToParcel(out, uSecRealtime); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 12386 | mMobileRadioActiveAdjustedTime.writeToParcel(out); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 12387 | mMobileRadioActiveUnknownTime.writeToParcel(out); |
| 12388 | mMobileRadioActiveUnknownCount.writeToParcel(out); |
| 12389 | mWifiOnTimer.writeToParcel(out, uSecRealtime); |
| 12390 | mGlobalWifiRunningTimer.writeToParcel(out, uSecRealtime); |
| 12391 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
| 12392 | mWifiStateTimer[i].writeToParcel(out, uSecRealtime); |
| 12393 | } |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 12394 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
| 12395 | mWifiSupplStateTimer[i].writeToParcel(out, uSecRealtime); |
| 12396 | } |
| 12397 | for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 12398 | mWifiSignalStrengthsTimer[i].writeToParcel(out, uSecRealtime); |
| 12399 | } |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 12400 | mWifiActivity.writeToParcel(out, 0); |
| 12401 | mBluetoothActivity.writeToParcel(out, 0); |
| 12402 | mModemActivity.writeToParcel(out, 0); |
| 12403 | out.writeInt(mHasWifiReporting ? 1 : 0); |
| 12404 | out.writeInt(mHasBluetoothReporting ? 1 : 0); |
| 12405 | out.writeInt(mHasModemReporting ? 1 : 0); |
| 12406 | |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 12407 | out.writeInt(mNumConnectivityChange); |
| 12408 | out.writeInt(mLoadedNumConnectivityChange); |
| 12409 | out.writeInt(mUnpluggedNumConnectivityChange); |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 12410 | mFlashlightOnTimer.writeToParcel(out, uSecRealtime); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 12411 | mCameraOnTimer.writeToParcel(out, uSecRealtime); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 12412 | mBluetoothScanTimer.writeToParcel(out, uSecRealtime); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 12413 | out.writeInt(mDischargeUnplugLevel); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 12414 | out.writeInt(mDischargePlugLevel); |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 12415 | out.writeInt(mDischargeCurrentLevel); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 12416 | out.writeInt(mCurrentBatteryLevel); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 12417 | out.writeInt(mLowDischargeAmountSinceCharge); |
| 12418 | out.writeInt(mHighDischargeAmountSinceCharge); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 12419 | out.writeInt(mDischargeAmountScreenOn); |
| 12420 | out.writeInt(mDischargeAmountScreenOnSinceCharge); |
| 12421 | out.writeInt(mDischargeAmountScreenOff); |
| 12422 | out.writeInt(mDischargeAmountScreenOffSinceCharge); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 12423 | mDischargeStepTracker.writeToParcel(out); |
| 12424 | mChargeStepTracker.writeToParcel(out); |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 12425 | mDischargeCounter.writeToParcel(out); |
| 12426 | mDischargeScreenOffCounter.writeToParcel(out); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12427 | out.writeLong(mLastWriteTime); |
| 12428 | |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 12429 | if (inclUids) { |
| 12430 | out.writeInt(mKernelWakelockStats.size()); |
| 12431 | for (Map.Entry<String, SamplingTimer> ent : mKernelWakelockStats.entrySet()) { |
| 12432 | SamplingTimer kwlt = ent.getValue(); |
| 12433 | if (kwlt != null) { |
| 12434 | out.writeInt(1); |
| 12435 | out.writeString(ent.getKey()); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 12436 | kwlt.writeToParcel(out, uSecRealtime); |
| 12437 | } else { |
| 12438 | out.writeInt(0); |
| 12439 | } |
| 12440 | } |
| 12441 | out.writeInt(mWakeupReasonStats.size()); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 12442 | for (Map.Entry<String, SamplingTimer> ent : mWakeupReasonStats.entrySet()) { |
| 12443 | SamplingTimer timer = ent.getValue(); |
| 12444 | if (timer != null) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 12445 | out.writeInt(1); |
| 12446 | out.writeString(ent.getKey()); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 12447 | timer.writeToParcel(out, uSecRealtime); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 12448 | } else { |
| 12449 | out.writeInt(0); |
| 12450 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 12451 | } |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 12452 | } else { |
| 12453 | out.writeInt(0); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 12454 | } |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 12455 | |
James Carr | 3a22605 | 2016-07-01 14:49:52 -0700 | [diff] [blame] | 12456 | out.writeInt(mKernelMemoryStats.size()); |
| 12457 | for (int i = 0; i < mKernelMemoryStats.size(); i++) { |
| 12458 | SamplingTimer kmt = mKernelMemoryStats.valueAt(i); |
| 12459 | if (kmt != null) { |
| 12460 | out.writeInt(1); |
| 12461 | out.writeLong(mKernelMemoryStats.keyAt(i)); |
| 12462 | kmt.writeToParcel(out, uSecRealtime); |
| 12463 | } else { |
| 12464 | out.writeInt(0); |
| 12465 | } |
| 12466 | } |
| 12467 | |
Sudheer Shanka | 9b735c5 | 2017-05-09 18:26:18 -0700 | [diff] [blame] | 12468 | out.writeLongArray(mCpuFreqs); |
| 12469 | |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 12470 | if (inclUids) { |
| 12471 | int size = mUidStats.size(); |
| 12472 | out.writeInt(size); |
| 12473 | for (int i = 0; i < size; i++) { |
| 12474 | out.writeInt(mUidStats.keyAt(i)); |
| 12475 | Uid uid = mUidStats.valueAt(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12476 | |
Bookatz | 867c0d7 | 2017-03-07 18:23:42 -0800 | [diff] [blame] | 12477 | uid.writeToParcelLocked(out, uSecUptime, uSecRealtime); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 12478 | } |
| 12479 | } else { |
| 12480 | out.writeInt(0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12481 | } |
| 12482 | } |
| 12483 | |
| 12484 | public static final Parcelable.Creator<BatteryStatsImpl> CREATOR = |
| 12485 | new Parcelable.Creator<BatteryStatsImpl>() { |
| 12486 | public BatteryStatsImpl createFromParcel(Parcel in) { |
| 12487 | return new BatteryStatsImpl(in); |
| 12488 | } |
| 12489 | |
| 12490 | public BatteryStatsImpl[] newArray(int size) { |
| 12491 | return new BatteryStatsImpl[size]; |
| 12492 | } |
| 12493 | }; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 12494 | |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 12495 | public void prepareForDumpLocked() { |
| 12496 | // Need to retrieve current kernel wake lock stats before printing. |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 12497 | pullPendingStateUpdatesLocked(); |
Dianne Hackborn | 7d9eefd | 2014-08-27 18:30:31 -0700 | [diff] [blame] | 12498 | |
| 12499 | // Pull the clock time. This may update the time and make a new history entry |
| 12500 | // if we had originally pulled a time before the RTC was set. |
| 12501 | getStartClockTime(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 12502 | } |
| 12503 | |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 12504 | 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] | 12505 | if (DEBUG) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 12506 | pw.println("mOnBatteryTimeBase:"); |
| 12507 | mOnBatteryTimeBase.dump(pw, " "); |
| 12508 | pw.println("mOnBatteryScreenOffTimeBase:"); |
| 12509 | mOnBatteryScreenOffTimeBase.dump(pw, " "); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 12510 | Printer pr = new PrintWriterPrinter(pw); |
| 12511 | pr.println("*** Screen timer:"); |
| 12512 | mScreenOnTimer.logState(pr, " "); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 12513 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 12514 | pr.println("*** Screen brightness #" + i + ":"); |
| 12515 | mScreenBrightnessTimer[i].logState(pr, " "); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 12516 | } |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 12517 | pr.println("*** Interactive timer:"); |
| 12518 | mInteractiveTimer.logState(pr, " "); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 12519 | pr.println("*** Power save mode timer:"); |
| 12520 | mPowerSaveModeEnabledTimer.logState(pr, " "); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 12521 | pr.println("*** Device idle mode light timer:"); |
| 12522 | mDeviceIdleModeLightTimer.logState(pr, " "); |
| 12523 | pr.println("*** Device idle mode full timer:"); |
| 12524 | mDeviceIdleModeFullTimer.logState(pr, " "); |
| 12525 | pr.println("*** Device light idling timer:"); |
| 12526 | mDeviceLightIdlingTimer.logState(pr, " "); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 12527 | pr.println("*** Device idling timer:"); |
| 12528 | mDeviceIdlingTimer.logState(pr, " "); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 12529 | pr.println("*** Phone timer:"); |
| 12530 | mPhoneOnTimer.logState(pr, " "); |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 12531 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 12532 | pr.println("*** Phone signal strength #" + i + ":"); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 12533 | mPhoneSignalStrengthsTimer[i].logState(pr, " "); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 12534 | } |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 12535 | pr.println("*** Signal scanning :"); |
| 12536 | mPhoneSignalScanningTimer.logState(pr, " "); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 12537 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 12538 | pr.println("*** Data connection type #" + i + ":"); |
| 12539 | mPhoneDataConnectionsTimer[i].logState(pr, " "); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 12540 | } |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 12541 | pr.println("*** mMobileRadioPowerState=" + mMobileRadioPowerState); |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 12542 | pr.println("*** Mobile network active timer:"); |
| 12543 | mMobileRadioActiveTimer.logState(pr, " "); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 12544 | pr.println("*** Mobile network active adjusted timer:"); |
| 12545 | mMobileRadioActiveAdjustedTime.logState(pr, " "); |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 12546 | pr.println("*** mWifiRadioPowerState=" + mWifiRadioPowerState); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 12547 | pr.println("*** Wifi timer:"); |
| 12548 | mWifiOnTimer.logState(pr, " "); |
| 12549 | pr.println("*** WifiRunning timer:"); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 12550 | mGlobalWifiRunningTimer.logState(pr, " "); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 12551 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
| 12552 | pr.println("*** Wifi state #" + i + ":"); |
| 12553 | mWifiStateTimer[i].logState(pr, " "); |
| 12554 | } |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 12555 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
| 12556 | pr.println("*** Wifi suppl state #" + i + ":"); |
| 12557 | mWifiSupplStateTimer[i].logState(pr, " "); |
| 12558 | } |
| 12559 | for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 12560 | pr.println("*** Wifi signal strength #" + i + ":"); |
| 12561 | mWifiSignalStrengthsTimer[i].logState(pr, " "); |
| 12562 | } |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 12563 | pr.println("*** Flashlight timer:"); |
| 12564 | mFlashlightOnTimer.logState(pr, " "); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 12565 | pr.println("*** Camera timer:"); |
| 12566 | mCameraOnTimer.logState(pr, " "); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12567 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 12568 | super.dumpLocked(context, pw, flags, reqUid, histStart); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12569 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12570 | } |