The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2006-2007 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.internal.os; |
| 18 | |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 19 | import android.annotation.Nullable; |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 20 | import android.app.ActivityManager; |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 21 | import android.bluetooth.BluetoothActivityEnergyInfo; |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 22 | import android.bluetooth.UidTraffic; |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 23 | import android.content.Context; |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 24 | import android.content.Intent; |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 25 | import android.net.ConnectivityManager; |
| 26 | import android.net.NetworkStats; |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 27 | import android.net.wifi.WifiActivityEnergyInfo; |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 28 | import android.net.wifi.WifiManager; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 29 | import android.os.BatteryManager; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 30 | import android.os.BatteryStats; |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 31 | import android.os.Build; |
Dianne Hackborn | 8bdf593 | 2010-10-15 12:54:40 -0700 | [diff] [blame] | 32 | import android.os.FileUtils; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 33 | import android.os.Handler; |
Jeff Brown | 6f357d3 | 2014-01-15 20:40:55 -0800 | [diff] [blame] | 34 | import android.os.Looper; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 35 | import android.os.Message; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 36 | import android.os.Parcel; |
| 37 | import android.os.ParcelFormatException; |
| 38 | import android.os.Parcelable; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 39 | import android.os.Process; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 40 | import android.os.SystemClock; |
Jeff Sharkey | 418d12d | 2011-12-13 15:38:03 -0800 | [diff] [blame] | 41 | import android.os.SystemProperties; |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 42 | import android.os.WorkSource; |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 43 | import android.telephony.DataConnectionRealTimeInfo; |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 44 | import android.telephony.ModemActivityInfo; |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 45 | import android.telephony.ServiceState; |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 46 | import android.telephony.SignalStrength; |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 47 | import android.telephony.TelephonyManager; |
Jeff Sharkey | 9da2f1e | 2014-08-14 12:55:00 -0700 | [diff] [blame] | 48 | import android.text.TextUtils; |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 49 | import android.util.ArrayMap; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 50 | import android.util.Log; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 51 | import android.util.LogWriter; |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 52 | import android.util.MutableInt; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 53 | import android.util.PrintWriterPrinter; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 54 | import android.util.Printer; |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 55 | import android.util.Slog; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 56 | import android.util.SparseArray; |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 57 | import android.util.SparseIntArray; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 58 | import android.util.SparseLongArray; |
Dianne Hackborn | ae38445 | 2011-06-28 12:33:48 -0700 | [diff] [blame] | 59 | import android.util.TimeUtils; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 60 | import android.util.Xml; |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 61 | import android.view.Display; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 62 | |
Adam Lesinski | 98f0d46 | 2016-04-19 16:46:20 -0700 | [diff] [blame] | 63 | import com.android.internal.annotations.VisibleForTesting; |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 64 | import com.android.internal.net.NetworkStatsFactory; |
Dianne Hackborn | d0c5b9a | 2014-02-21 16:19:05 -0800 | [diff] [blame] | 65 | import com.android.internal.util.ArrayUtils; |
Dianne Hackborn | 8c84109 | 2013-06-24 13:46:13 -0700 | [diff] [blame] | 66 | import com.android.internal.util.FastPrintWriter; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 67 | import com.android.internal.util.FastXmlSerializer; |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 68 | import com.android.internal.util.JournaledFile; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 69 | import com.android.internal.util.XmlUtils; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 70 | import com.android.server.NetworkManagementSocketTagger; |
| 71 | import libcore.util.EmptyArray; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 72 | import org.xmlpull.v1.XmlPullParser; |
| 73 | import org.xmlpull.v1.XmlPullParserException; |
| 74 | import org.xmlpull.v1.XmlSerializer; |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 75 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 76 | import java.io.ByteArrayOutputStream; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 77 | import java.io.File; |
| 78 | import java.io.FileInputStream; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 79 | import java.io.FileNotFoundException; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 80 | import java.io.FileOutputStream; |
| 81 | import java.io.IOException; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 82 | import java.io.PrintWriter; |
Wojciech Staszkiewicz | 9e9e2e7 | 2015-05-08 14:58:46 +0100 | [diff] [blame] | 83 | import java.nio.charset.StandardCharsets; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 84 | import java.util.ArrayList; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 85 | import java.util.Calendar; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 86 | import java.util.HashMap; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 87 | import java.util.Iterator; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 88 | import java.util.Map; |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 89 | import java.util.concurrent.atomic.AtomicInteger; |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 90 | import java.util.concurrent.locks.ReentrantLock; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 91 | |
| 92 | /** |
| 93 | * All information we are collecting about things that can happen that impact |
| 94 | * battery life. All times are represented in microseconds except where indicated |
| 95 | * otherwise. |
| 96 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 97 | public class BatteryStatsImpl extends BatteryStats { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 98 | private static final String TAG = "BatteryStatsImpl"; |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 99 | private static final boolean DEBUG = false; |
Adam Lesinski | a7c90c8 | 2015-06-18 14:52:24 -0700 | [diff] [blame] | 100 | public static final boolean DEBUG_ENERGY = false; |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 101 | private static final boolean DEBUG_ENERGY_CPU = DEBUG_ENERGY; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 102 | private static final boolean DEBUG_HISTORY = false; |
Dianne Hackborn | e8c88e6 | 2011-08-17 19:09:09 -0700 | [diff] [blame] | 103 | private static final boolean USE_OLD_HISTORY = false; // for debugging. |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 104 | |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 105 | // TODO: remove "tcp" from network methods, since we measure total stats. |
| 106 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 107 | // 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] | 108 | private static final int MAGIC = 0xBA757475; // 'BATSTATS' |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 109 | |
| 110 | // Current on-disk Parcel version |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 111 | private static final int VERSION = 148 + (USE_OLD_HISTORY ? 1000 : 0); |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 112 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 113 | // Maximum number of items we will record in the history. |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 114 | private static final int MAX_HISTORY_ITEMS = 2000; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 115 | |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 116 | // No, really, THIS is the maximum number of items we will record in the history. |
| 117 | private static final int MAX_MAX_HISTORY_ITEMS = 3000; |
| 118 | |
Dianne Hackborn | 9e0f5d9 | 2010-02-22 15:05:42 -0800 | [diff] [blame] | 119 | // The maximum number of names wakelocks we will keep track of |
| 120 | // per uid; once the limit is reached, we batch the remaining wakelocks |
| 121 | // in to one common name. |
Dianne Hackborn | acc4a12 | 2014-08-18 16:33:44 -0700 | [diff] [blame] | 122 | private static final int MAX_WAKELOCKS_PER_UID = 100; |
Dianne Hackborn | c24ab86 | 2011-10-18 15:55:03 -0700 | [diff] [blame] | 123 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 124 | // Number of transmit power states the Wifi controller can be in. |
| 125 | private static final int NUM_WIFI_TX_LEVELS = 1; |
| 126 | |
| 127 | // Number of transmit power states the Bluetooth controller can be in. |
| 128 | private static final int NUM_BT_TX_LEVELS = 1; |
| 129 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 130 | protected Clocks mClocks; |
| 131 | |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 132 | private final JournaledFile mFile; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 133 | public final AtomicFile mCheckinFile; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 134 | public final AtomicFile mDailyFile; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 135 | |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 136 | static final int MSG_UPDATE_WAKELOCKS = 1; |
| 137 | static final int MSG_REPORT_POWER_CHANGE = 2; |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 138 | static final int MSG_REPORT_CHARGING = 3; |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 139 | static final long DELAY_UPDATE_WAKELOCKS = 5*1000; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 140 | |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 141 | private final KernelWakelockReader mKernelWakelockReader = new KernelWakelockReader(); |
| 142 | private final KernelWakelockStats mTmpWakelockStats = new KernelWakelockStats(); |
| 143 | |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 144 | private final KernelUidCpuTimeReader mKernelUidCpuTimeReader = new KernelUidCpuTimeReader(); |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 145 | private KernelCpuSpeedReader[] mKernelCpuSpeedReaders; |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 146 | |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 147 | public interface BatteryCallback { |
| 148 | public void batteryNeedsCpuUpdate(); |
| 149 | public void batteryPowerChanged(boolean onBattery); |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 150 | public void batterySendBroadcast(Intent intent); |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 151 | } |
| 152 | |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 153 | public interface PlatformIdleStateCallback { |
| 154 | public String getPlatformLowPowerStats(); |
| 155 | } |
| 156 | |
| 157 | private final PlatformIdleStateCallback mPlatformIdleStateCallback; |
| 158 | |
| 159 | |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 160 | final class MyHandler extends Handler { |
Jeff Brown | 6f357d3 | 2014-01-15 20:40:55 -0800 | [diff] [blame] | 161 | public MyHandler(Looper looper) { |
| 162 | super(looper, null, true); |
| 163 | } |
| 164 | |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 165 | @Override |
| 166 | public void handleMessage(Message msg) { |
| 167 | BatteryCallback cb = mCallback; |
| 168 | switch (msg.what) { |
| 169 | case MSG_UPDATE_WAKELOCKS: |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 170 | synchronized (BatteryStatsImpl.this) { |
| 171 | updateCpuTimeLocked(); |
| 172 | } |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 173 | if (cb != null) { |
| 174 | cb.batteryNeedsCpuUpdate(); |
| 175 | } |
| 176 | break; |
| 177 | case MSG_REPORT_POWER_CHANGE: |
| 178 | if (cb != null) { |
| 179 | cb.batteryPowerChanged(msg.arg1 != 0); |
| 180 | } |
| 181 | break; |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 182 | case MSG_REPORT_CHARGING: |
| 183 | if (cb != null) { |
| 184 | final String action; |
| 185 | synchronized (BatteryStatsImpl.this) { |
| 186 | action = mCharging ? BatteryManager.ACTION_CHARGING |
| 187 | : BatteryManager.ACTION_DISCHARGING; |
| 188 | } |
| 189 | Intent intent = new Intent(action); |
| 190 | intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT); |
| 191 | cb.batterySendBroadcast(intent); |
| 192 | } |
| 193 | break; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 194 | } |
| 195 | } |
| 196 | } |
| 197 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 198 | public interface Clocks { |
| 199 | public long elapsedRealtime(); |
| 200 | public long uptimeMillis(); |
| 201 | } |
| 202 | |
| 203 | public static class SystemClocks implements Clocks { |
| 204 | public long elapsedRealtime() { |
| 205 | return SystemClock.elapsedRealtime(); |
| 206 | } |
| 207 | |
| 208 | public long uptimeMillis() { |
| 209 | return SystemClock.uptimeMillis(); |
| 210 | } |
| 211 | } |
| 212 | |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 213 | public interface ExternalStatsSync { |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 214 | public static final int UPDATE_CPU = 0x01; |
| 215 | public static final int UPDATE_WIFI = 0x02; |
| 216 | public static final int UPDATE_RADIO = 0x04; |
| 217 | public static final int UPDATE_BT = 0x08; |
| 218 | public static final int UPDATE_ALL = UPDATE_CPU | UPDATE_WIFI | UPDATE_RADIO | UPDATE_BT; |
| 219 | |
| 220 | void scheduleSync(String reason, int flags); |
Adam Lesinski | 61db88f | 2015-07-01 15:05:07 -0700 | [diff] [blame] | 221 | void scheduleCpuSyncDueToRemovedUid(int uid); |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 222 | } |
| 223 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 224 | public final MyHandler mHandler; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 225 | private final ExternalStatsSync mExternalSync; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 226 | |
| 227 | private BatteryCallback mCallback; |
| 228 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 229 | /** |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 230 | * Mapping isolated uids to the actual owning app uid. |
| 231 | */ |
| 232 | final SparseIntArray mIsolatedUids = new SparseIntArray(); |
| 233 | |
| 234 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 235 | * The statistics we have collected organized by uids. |
| 236 | */ |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 237 | final SparseArray<BatteryStatsImpl.Uid> mUidStats = new SparseArray<>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 238 | |
| 239 | // A set of pools of currently active timers. When a timer is queried, we will divide the |
| 240 | // elapsed time by the number of active timers to arrive at that timer's share of the time. |
| 241 | // In order to do this, we must refresh each timer whenever the number of active timers |
| 242 | // changes. |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 243 | final ArrayList<StopwatchTimer> mPartialTimers = new ArrayList<>(); |
| 244 | final ArrayList<StopwatchTimer> mFullTimers = new ArrayList<>(); |
| 245 | final ArrayList<StopwatchTimer> mWindowTimers = new ArrayList<>(); |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 246 | final ArrayList<StopwatchTimer> mDrawTimers = new ArrayList<>(); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 247 | final SparseArray<ArrayList<StopwatchTimer>> mSensorTimers = new SparseArray<>(); |
| 248 | final ArrayList<StopwatchTimer> mWifiRunningTimers = new ArrayList<>(); |
| 249 | final ArrayList<StopwatchTimer> mFullWifiLockTimers = new ArrayList<>(); |
| 250 | final ArrayList<StopwatchTimer> mWifiMulticastTimers = new ArrayList<>(); |
| 251 | final ArrayList<StopwatchTimer> mWifiScanTimers = new ArrayList<>(); |
| 252 | final SparseArray<ArrayList<StopwatchTimer>> mWifiBatchedScanTimers = new SparseArray<>(); |
| 253 | final ArrayList<StopwatchTimer> mAudioTurnedOnTimers = new ArrayList<>(); |
| 254 | final ArrayList<StopwatchTimer> mVideoTurnedOnTimers = new ArrayList<>(); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 255 | final ArrayList<StopwatchTimer> mFlashlightTurnedOnTimers = new ArrayList<>(); |
| 256 | final ArrayList<StopwatchTimer> mCameraTurnedOnTimers = new ArrayList<>(); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 257 | final ArrayList<StopwatchTimer> mBluetoothScanOnTimers = new ArrayList<>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 258 | |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 259 | // Last partial timers we use for distributing CPU usage. |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 260 | final ArrayList<StopwatchTimer> mLastPartialTimers = new ArrayList<>(); |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 261 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 262 | // These are the objects that will want to do something when the device |
| 263 | // is unplugged from power. |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 264 | protected final TimeBase mOnBatteryTimeBase = new TimeBase(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 265 | |
| 266 | // These are the objects that will want to do something when the device |
| 267 | // is unplugged from power *and* the screen is off. |
| 268 | final TimeBase mOnBatteryScreenOffTimeBase = new TimeBase(); |
| 269 | |
| 270 | // Set to true when we want to distribute CPU across wakelocks for the next |
| 271 | // CPU update, even if we aren't currently running wake locks. |
| 272 | boolean mDistributeWakelockCpu; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 273 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 274 | boolean mShuttingDown; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 275 | |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 276 | final HistoryEventTracker mActiveEvents = new HistoryEventTracker(); |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 277 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 278 | long mHistoryBaseTime; |
| 279 | boolean mHaveBatteryLevel = false; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 280 | boolean mRecordingHistory = false; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 281 | int mNumHistoryItems; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 282 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 283 | static final int MAX_HISTORY_BUFFER = 256*1024; // 256KB |
| 284 | static final int MAX_MAX_HISTORY_BUFFER = 320*1024; // 320KB |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 285 | final Parcel mHistoryBuffer = Parcel.obtain(); |
| 286 | final HistoryItem mHistoryLastWritten = new HistoryItem(); |
| 287 | final HistoryItem mHistoryLastLastWritten = new HistoryItem(); |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 288 | final HistoryItem mHistoryReadTmp = new HistoryItem(); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 289 | final HistoryItem mHistoryAddTmp = new HistoryItem(); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 290 | final HashMap<HistoryTag, Integer> mHistoryTagPool = new HashMap<>(); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 291 | String[] mReadHistoryStrings; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 292 | int[] mReadHistoryUids; |
| 293 | int mReadHistoryChars; |
| 294 | int mNextHistoryTagIdx = 0; |
| 295 | int mNumHistoryTagChars = 0; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 296 | int mHistoryBufferLastPos = -1; |
| 297 | boolean mHistoryOverflow = false; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 298 | int mActiveHistoryStates = 0xffffffff; |
| 299 | int mActiveHistoryStates2 = 0xffffffff; |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 300 | long mLastHistoryElapsedRealtime = 0; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 301 | long mTrackRunningHistoryElapsedRealtime = 0; |
| 302 | long mTrackRunningHistoryUptime = 0; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 303 | |
| 304 | final HistoryItem mHistoryCur = new HistoryItem(); |
| 305 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 306 | HistoryItem mHistory; |
| 307 | HistoryItem mHistoryEnd; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 308 | HistoryItem mHistoryLastEnd; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 309 | HistoryItem mHistoryCache; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 310 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 311 | // Used by computeHistoryStepDetails |
| 312 | HistoryStepDetails mLastHistoryStepDetails = null; |
| 313 | byte mLastHistoryStepLevel = 0; |
| 314 | final HistoryStepDetails mCurHistoryStepDetails = new HistoryStepDetails(); |
| 315 | final HistoryStepDetails mReadHistoryStepDetails = new HistoryStepDetails(); |
| 316 | final HistoryStepDetails mTmpHistoryStepDetails = new HistoryStepDetails(); |
Adam Lesinski | 7b83b0c | 2015-06-05 12:59:36 -0700 | [diff] [blame] | 317 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 318 | /** |
Adam Lesinski | 7b83b0c | 2015-06-05 12:59:36 -0700 | [diff] [blame] | 319 | * Total time (in milliseconds) spent executing in user code. |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 320 | */ |
| 321 | long mLastStepCpuUserTime; |
| 322 | long mCurStepCpuUserTime; |
| 323 | /** |
Adam Lesinski | 7b83b0c | 2015-06-05 12:59:36 -0700 | [diff] [blame] | 324 | * Total time (in milliseconds) spent executing in kernel code. |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 325 | */ |
| 326 | long mLastStepCpuSystemTime; |
| 327 | long mCurStepCpuSystemTime; |
| 328 | /** |
Adam Lesinski | 7b83b0c | 2015-06-05 12:59:36 -0700 | [diff] [blame] | 329 | * Times from /proc/stat (but measured in milliseconds). |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 330 | */ |
| 331 | long mLastStepStatUserTime; |
| 332 | long mLastStepStatSystemTime; |
| 333 | long mLastStepStatIOWaitTime; |
| 334 | long mLastStepStatIrqTime; |
| 335 | long mLastStepStatSoftIrqTime; |
| 336 | long mLastStepStatIdleTime; |
| 337 | long mCurStepStatUserTime; |
| 338 | long mCurStepStatSystemTime; |
| 339 | long mCurStepStatIOWaitTime; |
| 340 | long mCurStepStatIrqTime; |
| 341 | long mCurStepStatSoftIrqTime; |
| 342 | long mCurStepStatIdleTime; |
| 343 | |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 344 | private HistoryItem mHistoryIterator; |
| 345 | private boolean mReadOverflow; |
| 346 | private boolean mIteratingHistory; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 347 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 348 | int mStartCount; |
| 349 | |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 350 | long mStartClockTime; |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 351 | String mStartPlatformVersion; |
| 352 | String mEndPlatformVersion; |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 353 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 354 | long mUptime; |
| 355 | long mUptimeStart; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 356 | long mRealtime; |
| 357 | long mRealtimeStart; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 358 | |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 359 | int mWakeLockNesting; |
| 360 | boolean mWakeLockImportant; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 361 | public boolean mRecordAllHistory; |
Dianne Hackborn | 9a75543 | 2014-05-15 17:05:22 -0700 | [diff] [blame] | 362 | boolean mNoAutoReset; |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 363 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 364 | int mScreenState = Display.STATE_UNKNOWN; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 365 | StopwatchTimer mScreenOnTimer; |
Amith Yamasani | 3718aaa | 2009-06-09 06:32:35 -0700 | [diff] [blame] | 366 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 367 | int mScreenBrightnessBin = -1; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 368 | final StopwatchTimer[] mScreenBrightnessTimer = new StopwatchTimer[NUM_SCREEN_BRIGHTNESS_BINS]; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 369 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 370 | boolean mInteractive; |
| 371 | StopwatchTimer mInteractiveTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 372 | |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 373 | boolean mPowerSaveModeEnabled; |
| 374 | StopwatchTimer mPowerSaveModeEnabledTimer; |
| 375 | |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 376 | boolean mDeviceIdling; |
| 377 | StopwatchTimer mDeviceIdlingTimer; |
| 378 | |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 379 | boolean mDeviceLightIdling; |
| 380 | StopwatchTimer mDeviceLightIdlingTimer; |
| 381 | |
| 382 | int mDeviceIdleMode; |
| 383 | long mLastIdleTimeStart; |
| 384 | long mLongestLightIdleTime; |
| 385 | long mLongestFullIdleTime; |
| 386 | StopwatchTimer mDeviceIdleModeLightTimer; |
| 387 | StopwatchTimer mDeviceIdleModeFullTimer; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 388 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 389 | boolean mPhoneOn; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 390 | StopwatchTimer mPhoneOnTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 391 | |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 392 | int mAudioOnNesting; |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 393 | StopwatchTimer mAudioOnTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 394 | |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 395 | int mVideoOnNesting; |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 396 | StopwatchTimer mVideoOnTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 397 | |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 398 | int mFlashlightOnNesting; |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 399 | StopwatchTimer mFlashlightOnTimer; |
| 400 | |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 401 | int mCameraOnNesting; |
| 402 | StopwatchTimer mCameraOnTimer; |
| 403 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 404 | int mPhoneSignalStrengthBin = -1; |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 405 | int mPhoneSignalStrengthBinRaw = -1; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 406 | final StopwatchTimer[] mPhoneSignalStrengthsTimer = |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 407 | new StopwatchTimer[SignalStrength.NUM_SIGNAL_STRENGTH_BINS]; |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 408 | |
| 409 | StopwatchTimer mPhoneSignalScanningTimer; |
| 410 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 411 | int mPhoneDataConnectionType = -1; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 412 | final StopwatchTimer[] mPhoneDataConnectionsTimer = |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 413 | new StopwatchTimer[NUM_DATA_CONNECTION_TYPES]; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 414 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 415 | final LongSamplingCounter[] mNetworkByteActivityCounters = |
| 416 | new LongSamplingCounter[NUM_NETWORK_ACTIVITY_TYPES]; |
| 417 | final LongSamplingCounter[] mNetworkPacketActivityCounters = |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 418 | new LongSamplingCounter[NUM_NETWORK_ACTIVITY_TYPES]; |
| 419 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 420 | /** |
| 421 | * The WiFi controller activity (time in tx, rx, idle, and power consumed) for the device. |
| 422 | */ |
| 423 | ControllerActivityCounterImpl mWifiActivity; |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 424 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 425 | /** |
| 426 | * The Bluetooth controller activity (time in tx, rx, idle, and power consumed) for the device. |
| 427 | */ |
| 428 | ControllerActivityCounterImpl mBluetoothActivity; |
| 429 | |
| 430 | /** |
| 431 | * The Modem controller activity (time in tx, rx, idle, and power consumed) for the device. |
| 432 | */ |
| 433 | ControllerActivityCounterImpl mModemActivity; |
| 434 | |
| 435 | /** |
| 436 | * Whether the device supports WiFi controller energy reporting. This is set to true on |
| 437 | * the first WiFi energy report. See {@link #mWifiActivity}. |
| 438 | */ |
| 439 | boolean mHasWifiReporting = false; |
| 440 | |
| 441 | /** |
| 442 | * Whether the device supports Bluetooth controller energy reporting. This is set to true on |
| 443 | * the first Bluetooth energy report. See {@link #mBluetoothActivity}. |
| 444 | */ |
| 445 | boolean mHasBluetoothReporting = false; |
| 446 | |
| 447 | /** |
| 448 | * Whether the device supports Modem controller energy reporting. This is set to true on |
| 449 | * the first Modem energy report. See {@link #mModemActivity}. |
| 450 | */ |
| 451 | boolean mHasModemReporting = false; |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 452 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 453 | boolean mWifiOn; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 454 | StopwatchTimer mWifiOnTimer; |
Eric Shienbrood | d4c5f89 | 2009-03-24 18:13:20 -0700 | [diff] [blame] | 455 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 456 | boolean mGlobalWifiRunning; |
| 457 | StopwatchTimer mGlobalWifiRunningTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 458 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 459 | int mWifiState = -1; |
| 460 | final StopwatchTimer[] mWifiStateTimer = new StopwatchTimer[NUM_WIFI_STATES]; |
| 461 | |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 462 | int mWifiSupplState = -1; |
| 463 | final StopwatchTimer[] mWifiSupplStateTimer = new StopwatchTimer[NUM_WIFI_SUPPL_STATES]; |
| 464 | |
| 465 | int mWifiSignalStrengthBin = -1; |
| 466 | final StopwatchTimer[] mWifiSignalStrengthsTimer = |
| 467 | new StopwatchTimer[NUM_WIFI_SIGNAL_STRENGTH_BINS]; |
| 468 | |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 469 | int mBluetoothScanNesting; |
| 470 | StopwatchTimer mBluetoothScanTimer; |
| 471 | |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 472 | int mMobileRadioPowerState = DataConnectionRealTimeInfo.DC_POWER_STATE_LOW; |
Dianne Hackborn | f7097a5 | 2014-05-13 09:56:14 -0700 | [diff] [blame] | 473 | long mMobileRadioActiveStartTime; |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 474 | StopwatchTimer mMobileRadioActiveTimer; |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 475 | StopwatchTimer mMobileRadioActivePerAppTimer; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 476 | LongSamplingCounter mMobileRadioActiveAdjustedTime; |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 477 | LongSamplingCounter mMobileRadioActiveUnknownTime; |
| 478 | LongSamplingCounter mMobileRadioActiveUnknownCount; |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 479 | |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 480 | int mWifiRadioPowerState = DataConnectionRealTimeInfo.DC_POWER_STATE_LOW; |
| 481 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 482 | /** |
| 483 | * These provide time bases that discount the time the device is plugged |
| 484 | * in to power. |
| 485 | */ |
| 486 | boolean mOnBattery; |
| 487 | boolean mOnBatteryInternal; |
Amith Yamasani | 3718aaa | 2009-06-09 06:32:35 -0700 | [diff] [blame] | 488 | |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 489 | /** |
| 490 | * External reporting of whether the device is actually charging. |
| 491 | */ |
| 492 | boolean mCharging = true; |
| 493 | int mLastChargingStateLevel; |
| 494 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 495 | /* |
| 496 | * These keep track of battery levels (1-100) at the last plug event and the last unplug event. |
| 497 | */ |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 498 | int mDischargeStartLevel; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 499 | int mDischargeUnplugLevel; |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 500 | int mDischargePlugLevel; |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 501 | int mDischargeCurrentLevel; |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 502 | int mCurrentBatteryLevel; |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 503 | int mLowDischargeAmountSinceCharge; |
| 504 | int mHighDischargeAmountSinceCharge; |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 505 | int mDischargeScreenOnUnplugLevel; |
| 506 | int mDischargeScreenOffUnplugLevel; |
| 507 | int mDischargeAmountScreenOn; |
| 508 | int mDischargeAmountScreenOnSinceCharge; |
| 509 | int mDischargeAmountScreenOff; |
| 510 | int mDischargeAmountScreenOffSinceCharge; |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 511 | |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 512 | private LongSamplingCounter mDischargeScreenOffCounter; |
| 513 | private LongSamplingCounter mDischargeCounter; |
| 514 | |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 515 | static final int MAX_LEVEL_STEPS = 200; |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 516 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 517 | int mInitStepMode = 0; |
| 518 | int mCurStepMode = 0; |
| 519 | int mModStepMode = 0; |
| 520 | |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 521 | int mLastDischargeStepLevel; |
Dianne Hackborn | 2932513 | 2014-05-21 15:01:03 -0700 | [diff] [blame] | 522 | int mMinDischargeStepLevel; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 523 | final LevelStepTracker mDischargeStepTracker = new LevelStepTracker(MAX_LEVEL_STEPS); |
| 524 | final LevelStepTracker mDailyDischargeStepTracker = new LevelStepTracker(MAX_LEVEL_STEPS*2); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 525 | ArrayList<PackageChange> mDailyPackageChanges; |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 526 | |
| 527 | int mLastChargeStepLevel; |
Dianne Hackborn | 2932513 | 2014-05-21 15:01:03 -0700 | [diff] [blame] | 528 | int mMaxChargeStepLevel; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 529 | final LevelStepTracker mChargeStepTracker = new LevelStepTracker(MAX_LEVEL_STEPS); |
| 530 | final LevelStepTracker mDailyChargeStepTracker = new LevelStepTracker(MAX_LEVEL_STEPS*2); |
| 531 | |
| 532 | static final int MAX_DAILY_ITEMS = 10; |
| 533 | |
| 534 | long mDailyStartTime = 0; |
| 535 | long mNextMinDailyDeadline = 0; |
| 536 | long mNextMaxDailyDeadline = 0; |
| 537 | |
| 538 | final ArrayList<DailyItem> mDailyItems = new ArrayList<>(); |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 539 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 540 | long mLastWriteTime = 0; // Milliseconds |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 541 | |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 542 | private int mPhoneServiceState = -1; |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 543 | private int mPhoneServiceStateRaw = -1; |
| 544 | private int mPhoneSimStateRaw = -1; |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 545 | |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 546 | private int mNumConnectivityChange; |
| 547 | private int mLoadedNumConnectivityChange; |
| 548 | private int mUnpluggedNumConnectivityChange; |
| 549 | |
Adam Lesinski | f9b20a9 | 2016-06-17 17:30:01 -0700 | [diff] [blame] | 550 | private int mEstimatedBatteryCapacity = -1; |
| 551 | |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 552 | private final NetworkStats.Entry mTmpNetworkStatsEntry = new NetworkStats.Entry(); |
| 553 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 554 | private PowerProfile mPowerProfile; |
| 555 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 556 | /* |
| 557 | * Holds a SamplingTimer associated with each kernel wakelock name being tracked. |
| 558 | */ |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 559 | private final HashMap<String, SamplingTimer> mKernelWakelockStats = new HashMap<>(); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 560 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 561 | public Map<String, ? extends Timer> getKernelWakelockStats() { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 562 | return mKernelWakelockStats; |
| 563 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 564 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 565 | String mLastWakeupReason = null; |
| 566 | long mLastWakeupUptimeMs = 0; |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 567 | private final HashMap<String, SamplingTimer> mWakeupReasonStats = new HashMap<>(); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 568 | |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 569 | public Map<String, ? extends Timer> getWakeupReasonStats() { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 570 | return mWakeupReasonStats; |
| 571 | } |
| 572 | |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 573 | @Override |
| 574 | public LongCounter getDischargeScreenOffCoulombCounter() { |
| 575 | return mDischargeScreenOffCounter; |
| 576 | } |
| 577 | |
| 578 | @Override |
| 579 | public LongCounter getDischargeCoulombCounter() { |
| 580 | return mDischargeCounter; |
| 581 | } |
| 582 | |
Adam Lesinski | f9b20a9 | 2016-06-17 17:30:01 -0700 | [diff] [blame] | 583 | @Override |
| 584 | public int getEstimatedBatteryCapacity() { |
| 585 | return mEstimatedBatteryCapacity; |
| 586 | } |
| 587 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 588 | public BatteryStatsImpl() { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 589 | this(new SystemClocks()); |
| 590 | } |
| 591 | |
| 592 | public BatteryStatsImpl(Clocks clocks) { |
| 593 | init(clocks); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 594 | mFile = null; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 595 | mCheckinFile = null; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 596 | mDailyFile = null; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 597 | mHandler = null; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 598 | mExternalSync = null; |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 599 | mPlatformIdleStateCallback = null; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 600 | clearHistoryLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 601 | } |
| 602 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 603 | private void init(Clocks clocks) { |
| 604 | mClocks = clocks; |
| 605 | mMobileNetworkStats = new NetworkStats[] { |
| 606 | new NetworkStats(mClocks.elapsedRealtime(), 50), |
| 607 | new NetworkStats(mClocks.elapsedRealtime(), 50), |
| 608 | new NetworkStats(mClocks.elapsedRealtime(), 50) |
| 609 | }; |
| 610 | mWifiNetworkStats = new NetworkStats[] { |
| 611 | new NetworkStats(mClocks.elapsedRealtime(), 50), |
| 612 | new NetworkStats(mClocks.elapsedRealtime(), 50), |
| 613 | new NetworkStats(mClocks.elapsedRealtime(), 50) |
| 614 | }; |
| 615 | } |
| 616 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 617 | public static interface TimeBaseObs { |
| 618 | void onTimeStarted(long elapsedRealtime, long baseUptime, long baseRealtime); |
| 619 | void onTimeStopped(long elapsedRealtime, long baseUptime, long baseRealtime); |
| 620 | } |
| 621 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 622 | // methods are protected not private to be VisibleForTesting |
| 623 | public static class TimeBase { |
| 624 | protected final ArrayList<TimeBaseObs> mObservers = new ArrayList<>(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 625 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 626 | protected long mUptime; |
| 627 | protected long mRealtime; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 628 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 629 | protected boolean mRunning; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 630 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 631 | protected long mPastUptime; |
| 632 | protected long mUptimeStart; |
| 633 | protected long mPastRealtime; |
| 634 | protected long mRealtimeStart; |
| 635 | protected long mUnpluggedUptime; |
| 636 | protected long mUnpluggedRealtime; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 637 | |
| 638 | public void dump(PrintWriter pw, String prefix) { |
| 639 | StringBuilder sb = new StringBuilder(128); |
| 640 | pw.print(prefix); pw.print("mRunning="); pw.println(mRunning); |
| 641 | sb.setLength(0); |
| 642 | sb.append(prefix); |
| 643 | sb.append("mUptime="); |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 644 | formatTimeMs(sb, mUptime / 1000); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 645 | pw.println(sb.toString()); |
| 646 | sb.setLength(0); |
| 647 | sb.append(prefix); |
| 648 | sb.append("mRealtime="); |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 649 | formatTimeMs(sb, mRealtime / 1000); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 650 | pw.println(sb.toString()); |
| 651 | sb.setLength(0); |
| 652 | sb.append(prefix); |
| 653 | sb.append("mPastUptime="); |
| 654 | formatTimeMs(sb, mPastUptime / 1000); sb.append("mUptimeStart="); |
| 655 | formatTimeMs(sb, mUptimeStart / 1000); |
| 656 | sb.append("mUnpluggedUptime="); formatTimeMs(sb, mUnpluggedUptime / 1000); |
| 657 | pw.println(sb.toString()); |
| 658 | sb.setLength(0); |
| 659 | sb.append(prefix); |
| 660 | sb.append("mPastRealtime="); |
| 661 | formatTimeMs(sb, mPastRealtime / 1000); sb.append("mRealtimeStart="); |
| 662 | formatTimeMs(sb, mRealtimeStart / 1000); |
| 663 | sb.append("mUnpluggedRealtime="); formatTimeMs(sb, mUnpluggedRealtime / 1000); |
| 664 | pw.println(sb.toString()); |
| 665 | } |
| 666 | |
| 667 | public void add(TimeBaseObs observer) { |
| 668 | mObservers.add(observer); |
| 669 | } |
| 670 | |
| 671 | public void remove(TimeBaseObs observer) { |
| 672 | if (!mObservers.remove(observer)) { |
| 673 | Slog.wtf(TAG, "Removed unknown observer: " + observer); |
| 674 | } |
| 675 | } |
| 676 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 677 | public boolean hasObserver(TimeBaseObs observer) { |
| 678 | return mObservers.contains(observer); |
| 679 | } |
| 680 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 681 | public void init(long uptime, long realtime) { |
| 682 | mRealtime = 0; |
| 683 | mUptime = 0; |
| 684 | mPastUptime = 0; |
| 685 | mPastRealtime = 0; |
| 686 | mUptimeStart = uptime; |
| 687 | mRealtimeStart = realtime; |
| 688 | mUnpluggedUptime = getUptime(mUptimeStart); |
| 689 | mUnpluggedRealtime = getRealtime(mRealtimeStart); |
| 690 | } |
| 691 | |
| 692 | public void reset(long uptime, long realtime) { |
| 693 | if (!mRunning) { |
| 694 | mPastUptime = 0; |
| 695 | mPastRealtime = 0; |
| 696 | } else { |
| 697 | mUptimeStart = uptime; |
| 698 | mRealtimeStart = realtime; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 699 | // TODO: Since mUptimeStart was just reset and we are running, getUptime will |
| 700 | // 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] | 701 | mUnpluggedUptime = getUptime(uptime); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 702 | // TODO: likewise. |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 703 | mUnpluggedRealtime = getRealtime(realtime); |
| 704 | } |
| 705 | } |
| 706 | |
| 707 | public long computeUptime(long curTime, int which) { |
| 708 | switch (which) { |
| 709 | case STATS_SINCE_CHARGED: |
| 710 | return mUptime + getUptime(curTime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 711 | case STATS_CURRENT: |
| 712 | return getUptime(curTime); |
| 713 | case STATS_SINCE_UNPLUGGED: |
| 714 | return getUptime(curTime) - mUnpluggedUptime; |
| 715 | } |
| 716 | return 0; |
| 717 | } |
| 718 | |
| 719 | public long computeRealtime(long curTime, int which) { |
| 720 | switch (which) { |
| 721 | case STATS_SINCE_CHARGED: |
| 722 | return mRealtime + getRealtime(curTime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 723 | case STATS_CURRENT: |
| 724 | return getRealtime(curTime); |
| 725 | case STATS_SINCE_UNPLUGGED: |
| 726 | return getRealtime(curTime) - mUnpluggedRealtime; |
| 727 | } |
| 728 | return 0; |
| 729 | } |
| 730 | |
| 731 | public long getUptime(long curTime) { |
| 732 | long time = mPastUptime; |
| 733 | if (mRunning) { |
| 734 | time += curTime - mUptimeStart; |
| 735 | } |
| 736 | return time; |
| 737 | } |
| 738 | |
| 739 | public long getRealtime(long curTime) { |
| 740 | long time = mPastRealtime; |
| 741 | if (mRunning) { |
| 742 | time += curTime - mRealtimeStart; |
| 743 | } |
| 744 | return time; |
| 745 | } |
| 746 | |
| 747 | public long getUptimeStart() { |
| 748 | return mUptimeStart; |
| 749 | } |
| 750 | |
| 751 | public long getRealtimeStart() { |
| 752 | return mRealtimeStart; |
| 753 | } |
| 754 | |
| 755 | public boolean isRunning() { |
| 756 | return mRunning; |
| 757 | } |
| 758 | |
| 759 | public boolean setRunning(boolean running, long uptime, long realtime) { |
| 760 | if (mRunning != running) { |
| 761 | mRunning = running; |
| 762 | if (running) { |
| 763 | mUptimeStart = uptime; |
| 764 | mRealtimeStart = realtime; |
| 765 | long batteryUptime = mUnpluggedUptime = getUptime(uptime); |
| 766 | long batteryRealtime = mUnpluggedRealtime = getRealtime(realtime); |
| 767 | |
| 768 | for (int i = mObservers.size() - 1; i >= 0; i--) { |
| 769 | mObservers.get(i).onTimeStarted(realtime, batteryUptime, batteryRealtime); |
| 770 | } |
| 771 | } else { |
| 772 | mPastUptime += uptime - mUptimeStart; |
| 773 | mPastRealtime += realtime - mRealtimeStart; |
| 774 | |
| 775 | long batteryUptime = getUptime(uptime); |
| 776 | long batteryRealtime = getRealtime(realtime); |
| 777 | |
| 778 | for (int i = mObservers.size() - 1; i >= 0; i--) { |
| 779 | mObservers.get(i).onTimeStopped(realtime, batteryUptime, batteryRealtime); |
| 780 | } |
| 781 | } |
| 782 | return true; |
| 783 | } |
| 784 | return false; |
| 785 | } |
| 786 | |
| 787 | public void readSummaryFromParcel(Parcel in) { |
| 788 | mUptime = in.readLong(); |
| 789 | mRealtime = in.readLong(); |
| 790 | } |
| 791 | |
| 792 | public void writeSummaryToParcel(Parcel out, long uptime, long realtime) { |
| 793 | out.writeLong(computeUptime(uptime, STATS_SINCE_CHARGED)); |
| 794 | out.writeLong(computeRealtime(realtime, STATS_SINCE_CHARGED)); |
| 795 | } |
| 796 | |
| 797 | public void readFromParcel(Parcel in) { |
| 798 | mRunning = false; |
| 799 | mUptime = in.readLong(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 800 | mPastUptime = in.readLong(); |
| 801 | mUptimeStart = in.readLong(); |
Dianne Hackborn | ef640cd | 2014-03-25 14:41:05 -0700 | [diff] [blame] | 802 | mRealtime = in.readLong(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 803 | mPastRealtime = in.readLong(); |
| 804 | mRealtimeStart = in.readLong(); |
| 805 | mUnpluggedUptime = in.readLong(); |
| 806 | mUnpluggedRealtime = in.readLong(); |
| 807 | } |
| 808 | |
| 809 | public void writeToParcel(Parcel out, long uptime, long realtime) { |
| 810 | final long runningUptime = getUptime(uptime); |
| 811 | final long runningRealtime = getRealtime(realtime); |
| 812 | out.writeLong(mUptime); |
| 813 | out.writeLong(runningUptime); |
| 814 | out.writeLong(mUptimeStart); |
Dianne Hackborn | ef640cd | 2014-03-25 14:41:05 -0700 | [diff] [blame] | 815 | out.writeLong(mRealtime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 816 | out.writeLong(runningRealtime); |
| 817 | out.writeLong(mRealtimeStart); |
| 818 | out.writeLong(mUnpluggedUptime); |
| 819 | out.writeLong(mUnpluggedRealtime); |
| 820 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 821 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 822 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 823 | /** |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 824 | * State for keeping track of counting information. |
| 825 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 826 | public static class Counter extends BatteryStats.Counter implements TimeBaseObs { |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 827 | final AtomicInteger mCount = new AtomicInteger(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 828 | final TimeBase mTimeBase; |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 829 | int mLoadedCount; |
| 830 | int mLastCount; |
| 831 | int mUnpluggedCount; |
| 832 | int mPluggedCount; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 833 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 834 | Counter(TimeBase timeBase, Parcel in) { |
| 835 | mTimeBase = timeBase; |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 836 | mPluggedCount = in.readInt(); |
| 837 | mCount.set(mPluggedCount); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 838 | mLoadedCount = in.readInt(); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 839 | mLastCount = 0; |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 840 | mUnpluggedCount = in.readInt(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 841 | timeBase.add(this); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 842 | } |
| 843 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 844 | Counter(TimeBase timeBase) { |
| 845 | mTimeBase = timeBase; |
| 846 | timeBase.add(this); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 847 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 848 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 849 | public void writeToParcel(Parcel out) { |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 850 | out.writeInt(mCount.get()); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 851 | out.writeInt(mLoadedCount); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 852 | out.writeInt(mUnpluggedCount); |
| 853 | } |
| 854 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 855 | public void onTimeStarted(long elapsedRealtime, long baseUptime, long baseRealtime) { |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 856 | mUnpluggedCount = mPluggedCount; |
| 857 | mCount.set(mPluggedCount); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 858 | } |
| 859 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 860 | public void onTimeStopped(long elapsedRealtime, long baseUptime, long baseRealtime) { |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 861 | mPluggedCount = mCount.get(); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 862 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 863 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 864 | /** |
| 865 | * Writes a possibly null Counter to a Parcel. |
| 866 | * |
| 867 | * @param out the Parcel to be written to. |
| 868 | * @param counter a Counter, or null. |
| 869 | */ |
| 870 | public static void writeCounterToParcel(Parcel out, Counter counter) { |
| 871 | if (counter == null) { |
| 872 | out.writeInt(0); // indicates null |
| 873 | return; |
| 874 | } |
| 875 | out.writeInt(1); // indicates non-null |
| 876 | |
| 877 | counter.writeToParcel(out); |
| 878 | } |
| 879 | |
| 880 | @Override |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 881 | public int getCountLocked(int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 882 | int val = mCount.get(); |
| 883 | if (which == STATS_SINCE_UNPLUGGED) { |
| 884 | val -= mUnpluggedCount; |
| 885 | } else if (which != STATS_SINCE_CHARGED) { |
| 886 | val -= mLoadedCount; |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 887 | } |
| 888 | |
| 889 | return val; |
| 890 | } |
| 891 | |
| 892 | public void logState(Printer pw, String prefix) { |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 893 | pw.println(prefix + "mCount=" + mCount.get() |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 894 | + " mLoadedCount=" + mLoadedCount + " mLastCount=" + mLastCount |
| 895 | + " mUnpluggedCount=" + mUnpluggedCount |
| 896 | + " mPluggedCount=" + mPluggedCount); |
| 897 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 898 | |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 899 | void stepAtomic() { |
| 900 | mCount.incrementAndGet(); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 901 | } |
| 902 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 903 | /** |
| 904 | * Clear state of this counter. |
| 905 | */ |
| 906 | void reset(boolean detachIfReset) { |
| 907 | mCount.set(0); |
| 908 | mLoadedCount = mLastCount = mPluggedCount = mUnpluggedCount = 0; |
| 909 | if (detachIfReset) { |
| 910 | detach(); |
| 911 | } |
| 912 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 913 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 914 | void detach() { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 915 | mTimeBase.remove(this); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 916 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 917 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 918 | void writeSummaryFromParcelLocked(Parcel out) { |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 919 | int count = mCount.get(); |
| 920 | out.writeInt(count); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 921 | } |
| 922 | |
| 923 | void readSummaryFromParcelLocked(Parcel in) { |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 924 | mLoadedCount = in.readInt(); |
| 925 | mCount.set(mLoadedCount); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 926 | mLastCount = 0; |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 927 | mUnpluggedCount = mPluggedCount = mLoadedCount; |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 928 | } |
| 929 | } |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 930 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 931 | public static class LongSamplingCounter extends LongCounter implements TimeBaseObs { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 932 | final TimeBase mTimeBase; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 933 | long mCount; |
| 934 | long mLoadedCount; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 935 | long mUnpluggedCount; |
| 936 | long mPluggedCount; |
| 937 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 938 | LongSamplingCounter(TimeBase timeBase, Parcel in) { |
| 939 | mTimeBase = timeBase; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 940 | mPluggedCount = in.readLong(); |
| 941 | mCount = mPluggedCount; |
| 942 | mLoadedCount = in.readLong(); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 943 | mUnpluggedCount = in.readLong(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 944 | timeBase.add(this); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 945 | } |
| 946 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 947 | LongSamplingCounter(TimeBase timeBase) { |
| 948 | mTimeBase = timeBase; |
| 949 | timeBase.add(this); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 950 | } |
| 951 | |
| 952 | public void writeToParcel(Parcel out) { |
| 953 | out.writeLong(mCount); |
| 954 | out.writeLong(mLoadedCount); |
| 955 | out.writeLong(mUnpluggedCount); |
| 956 | } |
| 957 | |
| 958 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 959 | public void onTimeStarted(long elapsedRealtime, long baseUptime, long baseRealtime) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 960 | mUnpluggedCount = mPluggedCount; |
| 961 | mCount = mPluggedCount; |
| 962 | } |
| 963 | |
| 964 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 965 | public void onTimeStopped(long elapsedRealtime, long baseUptime, long baseRealtime) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 966 | mPluggedCount = mCount; |
| 967 | } |
| 968 | |
| 969 | public long getCountLocked(int which) { |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 970 | long val = mTimeBase.isRunning() ? mCount : mPluggedCount; |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 971 | if (which == STATS_SINCE_UNPLUGGED) { |
| 972 | val -= mUnpluggedCount; |
| 973 | } else if (which != STATS_SINCE_CHARGED) { |
| 974 | val -= mLoadedCount; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 975 | } |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 976 | return val; |
| 977 | } |
| 978 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 979 | @Override |
| 980 | public void logState(Printer pw, String prefix) { |
| 981 | pw.println(prefix + "mCount=" + mCount |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 982 | + " mLoadedCount=" + mLoadedCount |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 983 | + " mUnpluggedCount=" + mUnpluggedCount |
| 984 | + " mPluggedCount=" + mPluggedCount); |
| 985 | } |
| 986 | |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 987 | void addCountLocked(long count) { |
| 988 | mCount += count; |
| 989 | } |
| 990 | |
| 991 | /** |
| 992 | * Clear state of this counter. |
| 993 | */ |
| 994 | void reset(boolean detachIfReset) { |
| 995 | mCount = 0; |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 996 | mLoadedCount = mPluggedCount = mUnpluggedCount = 0; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 997 | if (detachIfReset) { |
| 998 | detach(); |
| 999 | } |
| 1000 | } |
| 1001 | |
| 1002 | void detach() { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1003 | mTimeBase.remove(this); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 1004 | } |
| 1005 | |
| 1006 | void writeSummaryFromParcelLocked(Parcel out) { |
| 1007 | out.writeLong(mCount); |
| 1008 | } |
| 1009 | |
| 1010 | void readSummaryFromParcelLocked(Parcel in) { |
| 1011 | mLoadedCount = in.readLong(); |
| 1012 | mCount = mLoadedCount; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 1013 | mUnpluggedCount = mPluggedCount = mLoadedCount; |
| 1014 | } |
| 1015 | } |
| 1016 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1017 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1018 | * State for keeping track of timing information. |
| 1019 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1020 | public static abstract class Timer extends BatteryStats.Timer implements TimeBaseObs { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1021 | protected final Clocks mClocks; |
| 1022 | protected final int mType; |
| 1023 | protected final TimeBase mTimeBase; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1024 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1025 | protected int mCount; |
| 1026 | protected int mLoadedCount; |
| 1027 | protected int mLastCount; |
| 1028 | protected int mUnpluggedCount; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1029 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1030 | // Times are in microseconds for better accuracy when dividing by the |
| 1031 | // lock count, and are in "battery realtime" units. |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1032 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1033 | /** |
| 1034 | * The total time we have accumulated since the start of the original |
| 1035 | * boot, to the last time something interesting happened in the |
| 1036 | * current run. |
| 1037 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1038 | protected long mTotalTime; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1039 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1040 | /** |
| 1041 | * The total time we loaded for the previous runs. Subtract this from |
| 1042 | * mTotalTime to find the time for the current run of the system. |
| 1043 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1044 | protected long mLoadedTime; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1045 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1046 | /** |
| 1047 | * The run time of the last run of the system, as loaded from the |
| 1048 | * saved data. |
| 1049 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1050 | protected long mLastTime; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1051 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1052 | /** |
| 1053 | * The value of mTotalTime when unplug() was last called. Subtract |
| 1054 | * this from mTotalTime to find the time since the last unplug from |
| 1055 | * power. |
| 1056 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1057 | protected long mUnpluggedTime; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1058 | |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 1059 | /** |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 1060 | * The total time this timer has been running until the latest mark has been set. |
| 1061 | * Subtract this from mTotalTime to get the time spent running since the mark was set. |
| 1062 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1063 | protected long mTimeBeforeMark; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 1064 | |
| 1065 | /** |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 1066 | * Constructs from a parcel. |
| 1067 | * @param type |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1068 | * @param timeBase |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 1069 | * @param in |
| 1070 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1071 | public Timer(Clocks clocks, int type, TimeBase timeBase, Parcel in) { |
| 1072 | mClocks = clocks; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1073 | mType = type; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1074 | mTimeBase = timeBase; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1075 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1076 | mCount = in.readInt(); |
| 1077 | mLoadedCount = in.readInt(); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 1078 | mLastCount = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1079 | mUnpluggedCount = in.readInt(); |
| 1080 | mTotalTime = in.readLong(); |
| 1081 | mLoadedTime = in.readLong(); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 1082 | mLastTime = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1083 | mUnpluggedTime = in.readLong(); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 1084 | mTimeBeforeMark = in.readLong(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1085 | timeBase.add(this); |
Dianne Hackborn | 2932513 | 2014-05-21 15:01:03 -0700 | [diff] [blame] | 1086 | 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] | 1087 | } |
| 1088 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1089 | public Timer(Clocks clocks, int type, TimeBase timeBase) { |
| 1090 | mClocks = clocks; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1091 | mType = type; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1092 | mTimeBase = timeBase; |
| 1093 | timeBase.add(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1094 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1095 | |
| 1096 | protected abstract long computeRunTimeLocked(long curBatteryRealtime); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1097 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1098 | protected abstract int computeCurrentCountLocked(); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1099 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1100 | /** |
| 1101 | * Clear state of this timer. Returns true if the timer is inactive |
| 1102 | * so can be completely dropped. |
| 1103 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1104 | public boolean reset(boolean detachIfReset) { |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 1105 | mTotalTime = mLoadedTime = mLastTime = mTimeBeforeMark = 0; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1106 | mCount = mLoadedCount = mLastCount = 0; |
| 1107 | if (detachIfReset) { |
| 1108 | detach(); |
| 1109 | } |
| 1110 | return true; |
| 1111 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1112 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1113 | public void detach() { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1114 | mTimeBase.remove(this); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1115 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1116 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1117 | public void writeToParcel(Parcel out, long elapsedRealtimeUs) { |
Dianne Hackborn | 2932513 | 2014-05-21 15:01:03 -0700 | [diff] [blame] | 1118 | if (DEBUG) Log.i(TAG, "**** WRITING TIMER #" + mType + ": mTotalTime=" |
| 1119 | + computeRunTimeLocked(mTimeBase.getRealtime(elapsedRealtimeUs))); |
Adam Lesinski | 98f0d46 | 2016-04-19 16:46:20 -0700 | [diff] [blame] | 1120 | out.writeInt(computeCurrentCountLocked()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1121 | out.writeInt(mLoadedCount); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1122 | out.writeInt(mUnpluggedCount); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1123 | out.writeLong(computeRunTimeLocked(mTimeBase.getRealtime(elapsedRealtimeUs))); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1124 | out.writeLong(mLoadedTime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1125 | out.writeLong(mUnpluggedTime); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 1126 | out.writeLong(mTimeBeforeMark); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1127 | } |
| 1128 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 1129 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1130 | public void onTimeStarted(long elapsedRealtime, long timeBaseUptime, long baseRealtime) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1131 | if (DEBUG && mType < 0) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1132 | Log.v(TAG, "unplug #" + mType + ": realtime=" + baseRealtime |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1133 | + " old mUnpluggedTime=" + mUnpluggedTime |
| 1134 | + " old mUnpluggedCount=" + mUnpluggedCount); |
| 1135 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1136 | mUnpluggedTime = computeRunTimeLocked(baseRealtime); |
Adam Lesinski | 98f0d46 | 2016-04-19 16:46:20 -0700 | [diff] [blame] | 1137 | mUnpluggedCount = computeCurrentCountLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1138 | if (DEBUG && mType < 0) { |
| 1139 | Log.v(TAG, "unplug #" + mType |
| 1140 | + ": new mUnpluggedTime=" + mUnpluggedTime |
| 1141 | + " new mUnpluggedCount=" + mUnpluggedCount); |
| 1142 | } |
| 1143 | } |
| 1144 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 1145 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1146 | public void onTimeStopped(long elapsedRealtime, long baseUptime, long baseRealtime) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1147 | if (DEBUG && mType < 0) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1148 | Log.v(TAG, "plug #" + mType + ": realtime=" + baseRealtime |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1149 | + " old mTotalTime=" + mTotalTime); |
| 1150 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1151 | mTotalTime = computeRunTimeLocked(baseRealtime); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1152 | mCount = computeCurrentCountLocked(); |
| 1153 | if (DEBUG && mType < 0) { |
| 1154 | Log.v(TAG, "plug #" + mType |
| 1155 | + ": new mTotalTime=" + mTotalTime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1156 | } |
| 1157 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1158 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1159 | /** |
| 1160 | * Writes a possibly null Timer to a Parcel. |
| 1161 | * |
| 1162 | * @param out the Parcel to be written to. |
| 1163 | * @param timer a Timer, or null. |
| 1164 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1165 | 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] | 1166 | if (timer == null) { |
| 1167 | out.writeInt(0); // indicates null |
| 1168 | return; |
| 1169 | } |
| 1170 | out.writeInt(1); // indicates non-null |
| 1171 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1172 | timer.writeToParcel(out, elapsedRealtimeUs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1173 | } |
| 1174 | |
| 1175 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1176 | public long getTotalTimeLocked(long elapsedRealtimeUs, int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 1177 | long val = computeRunTimeLocked(mTimeBase.getRealtime(elapsedRealtimeUs)); |
| 1178 | if (which == STATS_SINCE_UNPLUGGED) { |
| 1179 | val -= mUnpluggedTime; |
| 1180 | } else if (which != STATS_SINCE_CHARGED) { |
| 1181 | val -= mLoadedTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1182 | } |
| 1183 | |
| 1184 | return val; |
| 1185 | } |
| 1186 | |
| 1187 | @Override |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1188 | public int getCountLocked(int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 1189 | int val = computeCurrentCountLocked(); |
| 1190 | if (which == STATS_SINCE_UNPLUGGED) { |
| 1191 | val -= mUnpluggedCount; |
| 1192 | } else if (which != STATS_SINCE_CHARGED) { |
| 1193 | val -= mLoadedCount; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1194 | } |
| 1195 | |
| 1196 | return val; |
| 1197 | } |
| 1198 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 1199 | @Override |
| 1200 | public long getTimeSinceMarkLocked(long elapsedRealtimeUs) { |
| 1201 | long val = computeRunTimeLocked(mTimeBase.getRealtime(elapsedRealtimeUs)); |
| 1202 | return val - mTimeBeforeMark; |
| 1203 | } |
| 1204 | |
| 1205 | @Override |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 1206 | public void logState(Printer pw, String prefix) { |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 1207 | pw.println(prefix + "mCount=" + mCount |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1208 | + " mLoadedCount=" + mLoadedCount + " mLastCount=" + mLastCount |
| 1209 | + " mUnpluggedCount=" + mUnpluggedCount); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 1210 | pw.println(prefix + "mTotalTime=" + mTotalTime |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1211 | + " mLoadedTime=" + mLoadedTime); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 1212 | pw.println(prefix + "mLastTime=" + mLastTime |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1213 | + " mUnpluggedTime=" + mUnpluggedTime); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1214 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1215 | |
| 1216 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1217 | public void writeSummaryFromParcelLocked(Parcel out, long elapsedRealtimeUs) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1218 | long runTime = computeRunTimeLocked(mTimeBase.getRealtime(elapsedRealtimeUs)); |
| 1219 | out.writeLong(runTime); |
Adam Lesinski | 98f0d46 | 2016-04-19 16:46:20 -0700 | [diff] [blame] | 1220 | out.writeInt(computeCurrentCountLocked()); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1221 | } |
| 1222 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1223 | public void readSummaryFromParcelLocked(Parcel in) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1224 | // Multiply by 1000 for backwards compatibility |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1225 | mTotalTime = mLoadedTime = in.readLong(); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 1226 | mLastTime = 0; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1227 | mUnpluggedTime = mTotalTime; |
| 1228 | mCount = mLoadedCount = in.readInt(); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 1229 | mLastCount = 0; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1230 | mUnpluggedCount = mCount; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 1231 | |
| 1232 | // When reading the summary, we set the mark to be the latest information. |
| 1233 | mTimeBeforeMark = mTotalTime; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1234 | } |
| 1235 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1236 | |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 1237 | /** |
| 1238 | * A counter meant to accept monotonically increasing values to its {@link #update(long, int)} |
| 1239 | * method. The state of the timer according to its {@link TimeBase} will determine how much |
| 1240 | * of the value is recorded. |
| 1241 | * |
| 1242 | * If the value being recorded resets, {@link #endSample()} can be called in order to |
| 1243 | * account for the change. If the value passed in to {@link #update(long, int)} decreased |
| 1244 | * between calls, the {@link #endSample()} is automatically called and the new value is |
| 1245 | * expected to increase monotonically from that point on. |
| 1246 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1247 | public static class SamplingTimer extends Timer { |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1248 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1249 | /** |
| 1250 | * The most recent reported count from /proc/wakelocks. |
| 1251 | */ |
| 1252 | int mCurrentReportedCount; |
| 1253 | |
| 1254 | /** |
| 1255 | * The reported count from /proc/wakelocks when unplug() was last |
| 1256 | * called. |
| 1257 | */ |
| 1258 | int mUnpluggedReportedCount; |
| 1259 | |
| 1260 | /** |
| 1261 | * The most recent reported total_time from /proc/wakelocks. |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1262 | */ |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1263 | long mCurrentReportedTotalTime; |
| 1264 | |
| 1265 | |
| 1266 | /** |
| 1267 | * The reported total_time from /proc/wakelocks when unplug() was last |
| 1268 | * called. |
| 1269 | */ |
| 1270 | long mUnpluggedReportedTotalTime; |
| 1271 | |
| 1272 | /** |
| 1273 | * Whether we are currently in a discharge cycle. |
| 1274 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1275 | boolean mTimeBaseRunning; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1276 | |
| 1277 | /** |
| 1278 | * Whether we are currently recording reported values. |
| 1279 | */ |
| 1280 | boolean mTrackingReportedValues; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1281 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1282 | /* |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1283 | * A sequence counter, incremented once for each update of the stats. |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1284 | */ |
| 1285 | int mUpdateVersion; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1286 | |
Adam Lesinski | 98f0d46 | 2016-04-19 16:46:20 -0700 | [diff] [blame] | 1287 | @VisibleForTesting |
| 1288 | public SamplingTimer(Clocks clocks, TimeBase timeBase, Parcel in) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1289 | super(clocks, 0, timeBase, in); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1290 | mCurrentReportedCount = in.readInt(); |
| 1291 | mUnpluggedReportedCount = in.readInt(); |
| 1292 | mCurrentReportedTotalTime = in.readLong(); |
| 1293 | mUnpluggedReportedTotalTime = in.readLong(); |
| 1294 | mTrackingReportedValues = in.readInt() == 1; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1295 | mTimeBaseRunning = timeBase.isRunning(); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1296 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1297 | |
Adam Lesinski | 98f0d46 | 2016-04-19 16:46:20 -0700 | [diff] [blame] | 1298 | @VisibleForTesting |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 1299 | public SamplingTimer(Clocks clocks, TimeBase timeBase) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1300 | super(clocks, 0, timeBase); |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 1301 | mTrackingReportedValues = false; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1302 | mTimeBaseRunning = timeBase.isRunning(); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1303 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1304 | |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 1305 | /** |
| 1306 | * Ends the current sample, allowing subsequent values to {@link #update(long, int)} to |
| 1307 | * be less than the values used for a previous invocation. |
| 1308 | */ |
| 1309 | public void endSample() { |
| 1310 | mTotalTime = computeRunTimeLocked(0 /* unused by us */); |
| 1311 | mCount = computeCurrentCountLocked(); |
| 1312 | mUnpluggedReportedTotalTime = mCurrentReportedTotalTime = 0; |
| 1313 | mUnpluggedReportedCount = mCurrentReportedCount = 0; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1314 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1315 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1316 | public void setUpdateVersion(int version) { |
| 1317 | mUpdateVersion = version; |
| 1318 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1319 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1320 | public int getUpdateVersion() { |
| 1321 | return mUpdateVersion; |
| 1322 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1323 | |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 1324 | /** |
| 1325 | * Updates the current recorded values. These are meant to be monotonically increasing |
| 1326 | * and cumulative. If you are dealing with deltas, use {@link #add(long, int)}. |
| 1327 | * |
| 1328 | * If the values being recorded have been reset, the monotonically increasing requirement |
| 1329 | * will be broken. In this case, {@link #endSample()} is automatically called and |
| 1330 | * the total value of totalTime and count are recorded, starting a new monotonically |
| 1331 | * increasing sample. |
| 1332 | * |
| 1333 | * @param totalTime total time of sample in microseconds. |
| 1334 | * @param count total number of times the event being sampled occurred. |
| 1335 | */ |
| 1336 | public void update(long totalTime, int count) { |
| 1337 | if (mTimeBaseRunning && !mTrackingReportedValues) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1338 | // Updating the reported value for the first time. |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 1339 | mUnpluggedReportedTotalTime = totalTime; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1340 | mUnpluggedReportedCount = count; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1341 | } |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 1342 | |
| 1343 | mTrackingReportedValues = true; |
| 1344 | |
| 1345 | if (totalTime < mCurrentReportedTotalTime || count < mCurrentReportedCount) { |
| 1346 | endSample(); |
| 1347 | } |
| 1348 | |
| 1349 | mCurrentReportedTotalTime = totalTime; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1350 | mCurrentReportedCount = count; |
| 1351 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1352 | |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 1353 | /** |
| 1354 | * Adds deltaTime and deltaCount to the current sample. |
| 1355 | * |
| 1356 | * @param deltaTime additional time recorded since the last sampled event, in microseconds. |
| 1357 | * @param deltaCount additional number of times the event being sampled occurred. |
| 1358 | */ |
| 1359 | public void add(long deltaTime, int deltaCount) { |
| 1360 | update(mCurrentReportedTotalTime + deltaTime, mCurrentReportedCount + deltaCount); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 1361 | } |
| 1362 | |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 1363 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1364 | public void onTimeStarted(long elapsedRealtime, long baseUptime, long baseRealtime) { |
| 1365 | super.onTimeStarted(elapsedRealtime, baseUptime, baseRealtime); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1366 | if (mTrackingReportedValues) { |
| 1367 | mUnpluggedReportedTotalTime = mCurrentReportedTotalTime; |
| 1368 | mUnpluggedReportedCount = mCurrentReportedCount; |
| 1369 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1370 | mTimeBaseRunning = true; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1371 | } |
| 1372 | |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 1373 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1374 | public void onTimeStopped(long elapsedRealtime, long baseUptime, long baseRealtime) { |
| 1375 | super.onTimeStopped(elapsedRealtime, baseUptime, baseRealtime); |
| 1376 | mTimeBaseRunning = false; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1377 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1378 | |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 1379 | @Override |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1380 | public void logState(Printer pw, String prefix) { |
| 1381 | super.logState(pw, prefix); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1382 | pw.println(prefix + "mCurrentReportedCount=" + mCurrentReportedCount |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1383 | + " mUnpluggedReportedCount=" + mUnpluggedReportedCount |
| 1384 | + " mCurrentReportedTotalTime=" + mCurrentReportedTotalTime |
| 1385 | + " mUnpluggedReportedTotalTime=" + mUnpluggedReportedTotalTime); |
| 1386 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1387 | |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 1388 | @Override |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1389 | protected long computeRunTimeLocked(long curBatteryRealtime) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1390 | return mTotalTime + (mTimeBaseRunning && mTrackingReportedValues |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1391 | ? mCurrentReportedTotalTime - mUnpluggedReportedTotalTime : 0); |
| 1392 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1393 | |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 1394 | @Override |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1395 | protected int computeCurrentCountLocked() { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1396 | return mCount + (mTimeBaseRunning && mTrackingReportedValues |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1397 | ? mCurrentReportedCount - mUnpluggedReportedCount : 0); |
| 1398 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1399 | |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 1400 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1401 | public void writeToParcel(Parcel out, long elapsedRealtimeUs) { |
| 1402 | super.writeToParcel(out, elapsedRealtimeUs); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1403 | out.writeInt(mCurrentReportedCount); |
| 1404 | out.writeInt(mUnpluggedReportedCount); |
| 1405 | out.writeLong(mCurrentReportedTotalTime); |
| 1406 | out.writeLong(mUnpluggedReportedTotalTime); |
| 1407 | out.writeInt(mTrackingReportedValues ? 1 : 0); |
| 1408 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1409 | |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 1410 | @Override |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1411 | public boolean reset(boolean detachIfReset) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1412 | super.reset(detachIfReset); |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 1413 | mTrackingReportedValues = false; |
| 1414 | mUnpluggedReportedTotalTime = 0; |
| 1415 | mUnpluggedReportedCount = 0; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1416 | return true; |
| 1417 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1418 | |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 1419 | @Override |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1420 | public void writeSummaryFromParcelLocked(Parcel out, long batteryRealtime) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1421 | super.writeSummaryFromParcelLocked(out, batteryRealtime); |
| 1422 | out.writeLong(mCurrentReportedTotalTime); |
| 1423 | out.writeInt(mCurrentReportedCount); |
| 1424 | out.writeInt(mTrackingReportedValues ? 1 : 0); |
| 1425 | } |
| 1426 | |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 1427 | @Override |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1428 | public void readSummaryFromParcelLocked(Parcel in) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1429 | super.readSummaryFromParcelLocked(in); |
| 1430 | mUnpluggedReportedTotalTime = mCurrentReportedTotalTime = in.readLong(); |
| 1431 | mUnpluggedReportedCount = mCurrentReportedCount = in.readInt(); |
| 1432 | mTrackingReportedValues = in.readInt() == 1; |
| 1433 | } |
| 1434 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1435 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1436 | /** |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1437 | * A timer that increments in batches. It does not run for durations, but just jumps |
| 1438 | * for a pre-determined amount. |
| 1439 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1440 | public static class BatchTimer extends Timer { |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1441 | final Uid mUid; |
| 1442 | |
| 1443 | /** |
| 1444 | * The last time at which we updated the timer. This is in elapsed realtime microseconds. |
| 1445 | */ |
| 1446 | long mLastAddedTime; |
| 1447 | |
| 1448 | /** |
| 1449 | * The last duration that we added to the timer. This is in microseconds. |
| 1450 | */ |
| 1451 | long mLastAddedDuration; |
| 1452 | |
| 1453 | /** |
| 1454 | * Whether we are currently in a discharge cycle. |
| 1455 | */ |
| 1456 | boolean mInDischarge; |
| 1457 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1458 | BatchTimer(Clocks clocks, Uid uid, int type, TimeBase timeBase, Parcel in) { |
| 1459 | super(clocks, type, timeBase, in); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1460 | mUid = uid; |
| 1461 | mLastAddedTime = in.readLong(); |
| 1462 | mLastAddedDuration = in.readLong(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1463 | mInDischarge = timeBase.isRunning(); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1464 | } |
| 1465 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1466 | BatchTimer(Clocks clocks, Uid uid, int type, TimeBase timeBase) { |
| 1467 | super(clocks, type, timeBase); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1468 | mUid = uid; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1469 | mInDischarge = timeBase.isRunning(); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1470 | } |
| 1471 | |
| 1472 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1473 | public void writeToParcel(Parcel out, long elapsedRealtimeUs) { |
| 1474 | super.writeToParcel(out, elapsedRealtimeUs); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1475 | out.writeLong(mLastAddedTime); |
| 1476 | out.writeLong(mLastAddedDuration); |
| 1477 | } |
| 1478 | |
| 1479 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1480 | public void onTimeStopped(long elapsedRealtime, long baseUptime, long baseRealtime) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1481 | recomputeLastDuration(mClocks.elapsedRealtime() * 1000, false); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1482 | mInDischarge = false; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1483 | super.onTimeStopped(elapsedRealtime, baseUptime, baseRealtime); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1484 | } |
| 1485 | |
| 1486 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1487 | public void onTimeStarted(long elapsedRealtime, long baseUptime, long baseRealtime) { |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1488 | recomputeLastDuration(elapsedRealtime, false); |
| 1489 | mInDischarge = true; |
| 1490 | // If we are still within the last added duration, then re-added whatever remains. |
| 1491 | if (mLastAddedTime == elapsedRealtime) { |
| 1492 | mTotalTime += mLastAddedDuration; |
| 1493 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1494 | super.onTimeStarted(elapsedRealtime, baseUptime, baseRealtime); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1495 | } |
| 1496 | |
| 1497 | @Override |
| 1498 | public void logState(Printer pw, String prefix) { |
| 1499 | super.logState(pw, prefix); |
| 1500 | pw.println(prefix + "mLastAddedTime=" + mLastAddedTime |
| 1501 | + " mLastAddedDuration=" + mLastAddedDuration); |
| 1502 | } |
| 1503 | |
| 1504 | private long computeOverage(long curTime) { |
| 1505 | if (mLastAddedTime > 0) { |
| 1506 | return mLastTime + mLastAddedDuration - curTime; |
| 1507 | } |
| 1508 | return 0; |
| 1509 | } |
| 1510 | |
| 1511 | private void recomputeLastDuration(long curTime, boolean abort) { |
| 1512 | final long overage = computeOverage(curTime); |
| 1513 | if (overage > 0) { |
| 1514 | // Aborting before the duration ran out -- roll back the remaining |
| 1515 | // duration. Only do this if currently discharging; otherwise we didn't |
| 1516 | // actually add the time. |
| 1517 | if (mInDischarge) { |
| 1518 | mTotalTime -= overage; |
| 1519 | } |
| 1520 | if (abort) { |
| 1521 | mLastAddedTime = 0; |
| 1522 | } else { |
| 1523 | mLastAddedTime = curTime; |
| 1524 | mLastAddedDuration -= overage; |
| 1525 | } |
| 1526 | } |
| 1527 | } |
| 1528 | |
| 1529 | public void addDuration(BatteryStatsImpl stats, long durationMillis) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1530 | final long now = mClocks.elapsedRealtime() * 1000; |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1531 | recomputeLastDuration(now, true); |
| 1532 | mLastAddedTime = now; |
| 1533 | mLastAddedDuration = durationMillis * 1000; |
| 1534 | if (mInDischarge) { |
| 1535 | mTotalTime += mLastAddedDuration; |
| 1536 | mCount++; |
| 1537 | } |
| 1538 | } |
| 1539 | |
| 1540 | public void abortLastDuration(BatteryStatsImpl stats) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1541 | final long now = mClocks.elapsedRealtime() * 1000; |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1542 | recomputeLastDuration(now, true); |
| 1543 | } |
| 1544 | |
| 1545 | @Override |
| 1546 | protected int computeCurrentCountLocked() { |
| 1547 | return mCount; |
| 1548 | } |
| 1549 | |
| 1550 | @Override |
| 1551 | protected long computeRunTimeLocked(long curBatteryRealtime) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1552 | final long overage = computeOverage(mClocks.elapsedRealtime() * 1000); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1553 | if (overage > 0) { |
| 1554 | return mTotalTime = overage; |
| 1555 | } |
| 1556 | return mTotalTime; |
| 1557 | } |
| 1558 | |
| 1559 | @Override |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1560 | public boolean reset(boolean detachIfReset) { |
| 1561 | final long now = mClocks.elapsedRealtime() * 1000; |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1562 | recomputeLastDuration(now, true); |
| 1563 | boolean stillActive = mLastAddedTime == now; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1564 | super.reset(!stillActive && detachIfReset); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1565 | return !stillActive; |
| 1566 | } |
| 1567 | } |
| 1568 | |
| 1569 | /** |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1570 | * State for keeping track of timing information. |
| 1571 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1572 | public static class StopwatchTimer extends Timer { |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 1573 | final Uid mUid; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1574 | final ArrayList<StopwatchTimer> mTimerPool; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 1575 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1576 | int mNesting; |
| 1577 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1578 | /** |
| 1579 | * The last time at which we updated the timer. If mNesting is > 0, |
| 1580 | * subtract this from the current battery time to find the amount of |
| 1581 | * time we have been running since we last computed an update. |
| 1582 | */ |
| 1583 | long mUpdateTime; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1584 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1585 | /** |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 1586 | * The total time at which the timer was acquired, to determine if it |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1587 | * was actually held for an interesting duration. |
| 1588 | */ |
| 1589 | long mAcquireTime; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1590 | |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 1591 | long mTimeout; |
| 1592 | |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 1593 | /** |
| 1594 | * For partial wake locks, keep track of whether we are in the list |
| 1595 | * to consume CPU cycles. |
| 1596 | */ |
| 1597 | boolean mInList; |
| 1598 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1599 | public StopwatchTimer(Clocks clocks, Uid uid, int type, ArrayList<StopwatchTimer> timerPool, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1600 | TimeBase timeBase, Parcel in) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1601 | super(clocks, type, timeBase, in); |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 1602 | mUid = uid; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1603 | mTimerPool = timerPool; |
| 1604 | mUpdateTime = in.readLong(); |
| 1605 | } |
| 1606 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1607 | public StopwatchTimer(Clocks clocks, Uid uid, int type, ArrayList<StopwatchTimer> timerPool, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1608 | TimeBase timeBase) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1609 | super(clocks, type, timeBase); |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 1610 | mUid = uid; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1611 | mTimerPool = timerPool; |
| 1612 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1613 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1614 | public void setTimeout(long timeout) { |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 1615 | mTimeout = timeout; |
| 1616 | } |
| 1617 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1618 | public void writeToParcel(Parcel out, long elapsedRealtimeUs) { |
| 1619 | super.writeToParcel(out, elapsedRealtimeUs); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1620 | out.writeLong(mUpdateTime); |
| 1621 | } |
| 1622 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1623 | public void onTimeStopped(long elapsedRealtime, long baseUptime, long baseRealtime) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1624 | if (mNesting > 0) { |
| 1625 | if (DEBUG && mType < 0) { |
| 1626 | Log.v(TAG, "old mUpdateTime=" + mUpdateTime); |
| 1627 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1628 | super.onTimeStopped(elapsedRealtime, baseUptime, baseRealtime); |
| 1629 | mUpdateTime = baseRealtime; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1630 | if (DEBUG && mType < 0) { |
| 1631 | Log.v(TAG, "new mUpdateTime=" + mUpdateTime); |
| 1632 | } |
| 1633 | } |
| 1634 | } |
| 1635 | |
| 1636 | public void logState(Printer pw, String prefix) { |
| 1637 | super.logState(pw, prefix); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 1638 | pw.println(prefix + "mNesting=" + mNesting + " mUpdateTime=" + mUpdateTime |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1639 | + " mAcquireTime=" + mAcquireTime); |
| 1640 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1641 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1642 | public void startRunningLocked(long elapsedRealtimeMs) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1643 | if (mNesting++ == 0) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1644 | final long batteryRealtime = mTimeBase.getRealtime(elapsedRealtimeMs * 1000); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 1645 | mUpdateTime = batteryRealtime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1646 | if (mTimerPool != null) { |
| 1647 | // Accumulate time to all currently active timers before adding |
| 1648 | // this new one to the pool. |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1649 | refreshTimersLocked(batteryRealtime, mTimerPool, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1650 | // Add this timer to the active pool |
| 1651 | mTimerPool.add(this); |
| 1652 | } |
| 1653 | // Increment the count |
| 1654 | mCount++; |
| 1655 | mAcquireTime = mTotalTime; |
| 1656 | if (DEBUG && mType < 0) { |
| 1657 | Log.v(TAG, "start #" + mType + ": mUpdateTime=" + mUpdateTime |
| 1658 | + " mTotalTime=" + mTotalTime + " mCount=" + mCount |
| 1659 | + " mAcquireTime=" + mAcquireTime); |
| 1660 | } |
| 1661 | } |
| 1662 | } |
| 1663 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1664 | public boolean isRunningLocked() { |
Amith Yamasani | 32dbefd | 2009-06-19 09:21:17 -0700 | [diff] [blame] | 1665 | return mNesting > 0; |
| 1666 | } |
| 1667 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1668 | public void stopRunningLocked(long elapsedRealtimeMs) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1669 | // Ignore attempt to stop a timer that isn't running |
| 1670 | if (mNesting == 0) { |
| 1671 | return; |
| 1672 | } |
| 1673 | if (--mNesting == 0) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1674 | final long batteryRealtime = mTimeBase.getRealtime(elapsedRealtimeMs * 1000); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1675 | if (mTimerPool != null) { |
| 1676 | // Accumulate time to all active counters, scaled by the total |
| 1677 | // active in the pool, before taking this one out of the pool. |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1678 | refreshTimersLocked(batteryRealtime, mTimerPool, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1679 | // Remove this timer from the active pool |
| 1680 | mTimerPool.remove(this); |
| 1681 | } else { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1682 | mNesting = 1; |
| 1683 | mTotalTime = computeRunTimeLocked(batteryRealtime); |
| 1684 | mNesting = 0; |
| 1685 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1686 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1687 | if (DEBUG && mType < 0) { |
| 1688 | Log.v(TAG, "stop #" + mType + ": mUpdateTime=" + mUpdateTime |
| 1689 | + " mTotalTime=" + mTotalTime + " mCount=" + mCount |
| 1690 | + " mAcquireTime=" + mAcquireTime); |
| 1691 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1692 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1693 | if (mTotalTime == mAcquireTime) { |
| 1694 | // If there was no change in the time, then discard this |
| 1695 | // count. A somewhat cheezy strategy, but hey. |
| 1696 | mCount--; |
| 1697 | } |
| 1698 | } |
| 1699 | } |
| 1700 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1701 | public void stopAllRunningLocked(long elapsedRealtimeMs) { |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 1702 | if (mNesting > 0) { |
| 1703 | mNesting = 1; |
| 1704 | stopRunningLocked(elapsedRealtimeMs); |
| 1705 | } |
| 1706 | } |
| 1707 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1708 | // Update the total time for all other running Timers with the same type as this Timer |
| 1709 | // due to a change in timer count |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1710 | private static long refreshTimersLocked(long batteryRealtime, |
| 1711 | final ArrayList<StopwatchTimer> pool, StopwatchTimer self) { |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 1712 | long selfTime = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1713 | final int N = pool.size(); |
| 1714 | for (int i=N-1; i>= 0; i--) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1715 | final StopwatchTimer t = pool.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1716 | long heldTime = batteryRealtime - t.mUpdateTime; |
| 1717 | if (heldTime > 0) { |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 1718 | final long myTime = heldTime / N; |
| 1719 | if (t == self) { |
| 1720 | selfTime = myTime; |
| 1721 | } |
| 1722 | t.mTotalTime += myTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1723 | } |
| 1724 | t.mUpdateTime = batteryRealtime; |
| 1725 | } |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 1726 | return selfTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1727 | } |
| 1728 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1729 | @Override |
| 1730 | protected long computeRunTimeLocked(long curBatteryRealtime) { |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 1731 | if (mTimeout > 0 && curBatteryRealtime > mUpdateTime + mTimeout) { |
| 1732 | curBatteryRealtime = mUpdateTime + mTimeout; |
| 1733 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1734 | return mTotalTime + (mNesting > 0 |
| 1735 | ? (curBatteryRealtime - mUpdateTime) |
| 1736 | / (mTimerPool != null ? mTimerPool.size() : 1) |
| 1737 | : 0); |
| 1738 | } |
| 1739 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1740 | @Override |
| 1741 | protected int computeCurrentCountLocked() { |
| 1742 | return mCount; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1743 | } |
| 1744 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 1745 | @Override |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1746 | public boolean reset(boolean detachIfReset) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1747 | boolean canDetach = mNesting <= 0; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1748 | super.reset(canDetach && detachIfReset); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 1749 | if (mNesting > 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1750 | mUpdateTime = mTimeBase.getRealtime(mClocks.elapsedRealtime() * 1000); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 1751 | } |
| 1752 | mAcquireTime = mTotalTime; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1753 | return canDetach; |
| 1754 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1755 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 1756 | @Override |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1757 | public void detach() { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1758 | super.detach(); |
| 1759 | if (mTimerPool != null) { |
| 1760 | mTimerPool.remove(this); |
| 1761 | } |
| 1762 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1763 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 1764 | @Override |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1765 | public void readSummaryFromParcelLocked(Parcel in) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1766 | super.readSummaryFromParcelLocked(in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1767 | mNesting = 0; |
| 1768 | } |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 1769 | |
| 1770 | /** |
| 1771 | * Set the mark so that we can query later for the total time the timer has |
| 1772 | * accumulated since this point. The timer can be running or not. |
| 1773 | * |
| 1774 | * @param elapsedRealtimeMs the current elapsed realtime in milliseconds. |
| 1775 | */ |
| 1776 | public void setMark(long elapsedRealtimeMs) { |
| 1777 | final long batteryRealtime = mTimeBase.getRealtime(elapsedRealtimeMs * 1000); |
| 1778 | if (mNesting > 0) { |
| 1779 | // We are running. |
| 1780 | if (mTimerPool != null) { |
| 1781 | refreshTimersLocked(batteryRealtime, mTimerPool, this); |
| 1782 | } else { |
| 1783 | mTotalTime += batteryRealtime - mUpdateTime; |
| 1784 | mUpdateTime = batteryRealtime; |
| 1785 | } |
| 1786 | } |
| 1787 | mTimeBeforeMark = mTotalTime; |
| 1788 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1789 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1790 | |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 1791 | public abstract class OverflowArrayMap<T> { |
| 1792 | private static final String OVERFLOW_NAME = "*overflow*"; |
| 1793 | |
Dianne Hackborn | 657153b | 2016-07-29 14:54:14 -0700 | [diff] [blame^] | 1794 | final int mUid; |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 1795 | final ArrayMap<String, T> mMap = new ArrayMap<>(); |
| 1796 | T mCurOverflow; |
| 1797 | ArrayMap<String, MutableInt> mActiveOverflow; |
Dianne Hackborn | 657153b | 2016-07-29 14:54:14 -0700 | [diff] [blame^] | 1798 | long mLastOverflowTime; |
| 1799 | long mLastOverflowFinishTime; |
| 1800 | long mLastClearTime; |
| 1801 | long mLastCleanupTime; |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 1802 | |
Dianne Hackborn | 657153b | 2016-07-29 14:54:14 -0700 | [diff] [blame^] | 1803 | public OverflowArrayMap(int uid) { |
| 1804 | mUid = uid; |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 1805 | } |
| 1806 | |
| 1807 | public ArrayMap<String, T> getMap() { |
| 1808 | return mMap; |
| 1809 | } |
| 1810 | |
| 1811 | public void clear() { |
Dianne Hackborn | 657153b | 2016-07-29 14:54:14 -0700 | [diff] [blame^] | 1812 | mLastClearTime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 1813 | mMap.clear(); |
| 1814 | mCurOverflow = null; |
| 1815 | mActiveOverflow = null; |
| 1816 | } |
| 1817 | |
| 1818 | public void add(String name, T obj) { |
Joe Onorato | 388fc33 | 2016-04-12 17:06:47 -0700 | [diff] [blame] | 1819 | if (name == null) { |
| 1820 | name = ""; |
| 1821 | } |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 1822 | mMap.put(name, obj); |
| 1823 | if (OVERFLOW_NAME.equals(name)) { |
| 1824 | mCurOverflow = obj; |
| 1825 | } |
| 1826 | } |
| 1827 | |
| 1828 | public void cleanup() { |
Dianne Hackborn | 657153b | 2016-07-29 14:54:14 -0700 | [diff] [blame^] | 1829 | mLastCleanupTime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 1830 | if (mActiveOverflow != null) { |
| 1831 | if (mActiveOverflow.size() == 0) { |
| 1832 | mActiveOverflow = null; |
| 1833 | } |
| 1834 | } |
| 1835 | if (mActiveOverflow == null) { |
| 1836 | // There is no currently active overflow, so we should no longer have |
| 1837 | // an overflow entry. |
| 1838 | if (mMap.containsKey(OVERFLOW_NAME)) { |
| 1839 | Slog.wtf(TAG, "Cleaning up with no active overflow, but have overflow entry " |
| 1840 | + mMap.get(OVERFLOW_NAME)); |
| 1841 | mMap.remove(OVERFLOW_NAME); |
| 1842 | } |
| 1843 | mCurOverflow = null; |
| 1844 | } else { |
| 1845 | // There is currently active overflow, so we should still have an overflow entry. |
| 1846 | if (mCurOverflow == null || !mMap.containsKey(OVERFLOW_NAME)) { |
| 1847 | Slog.wtf(TAG, "Cleaning up with active overflow, but no overflow entry: cur=" |
| 1848 | + mCurOverflow + " map=" + mMap.get(OVERFLOW_NAME)); |
| 1849 | } |
| 1850 | } |
| 1851 | } |
| 1852 | |
| 1853 | public T startObject(String name) { |
Joe Onorato | 388fc33 | 2016-04-12 17:06:47 -0700 | [diff] [blame] | 1854 | if (name == null) { |
| 1855 | name = ""; |
| 1856 | } |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 1857 | T obj = mMap.get(name); |
| 1858 | if (obj != null) { |
| 1859 | return obj; |
| 1860 | } |
| 1861 | |
| 1862 | // No object exists for the given name, but do we currently have it |
| 1863 | // running as part of the overflow? |
| 1864 | if (mActiveOverflow != null) { |
| 1865 | MutableInt over = mActiveOverflow.get(name); |
| 1866 | if (over != null) { |
| 1867 | // We are already actively counting this name in the overflow object. |
| 1868 | obj = mCurOverflow; |
| 1869 | if (obj == null) { |
| 1870 | // Shouldn't be here, but we'll try to recover. |
| 1871 | Slog.wtf(TAG, "Have active overflow " + name + " but null overflow"); |
| 1872 | obj = mCurOverflow = instantiateObject(); |
| 1873 | mMap.put(OVERFLOW_NAME, obj); |
| 1874 | } |
| 1875 | over.value++; |
| 1876 | return obj; |
| 1877 | } |
| 1878 | } |
| 1879 | |
| 1880 | // No object exists for given name nor in the overflow; we need to make |
| 1881 | // a new one. |
| 1882 | final int N = mMap.size(); |
| 1883 | if (N >= MAX_WAKELOCKS_PER_UID) { |
| 1884 | // Went over the limit on number of objects to track; this one goes |
| 1885 | // in to the overflow. |
| 1886 | obj = mCurOverflow; |
| 1887 | if (obj == null) { |
| 1888 | // Need to start overflow now... |
| 1889 | obj = mCurOverflow = instantiateObject(); |
| 1890 | mMap.put(OVERFLOW_NAME, obj); |
| 1891 | } |
| 1892 | if (mActiveOverflow == null) { |
| 1893 | mActiveOverflow = new ArrayMap<>(); |
| 1894 | } |
| 1895 | mActiveOverflow.put(name, new MutableInt(1)); |
Dianne Hackborn | 657153b | 2016-07-29 14:54:14 -0700 | [diff] [blame^] | 1896 | mLastOverflowTime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 1897 | return obj; |
| 1898 | } |
| 1899 | |
| 1900 | // Normal case where we just need to make a new object. |
| 1901 | obj = instantiateObject(); |
| 1902 | mMap.put(name, obj); |
| 1903 | return obj; |
| 1904 | } |
| 1905 | |
| 1906 | public T stopObject(String name) { |
Joe Onorato | 388fc33 | 2016-04-12 17:06:47 -0700 | [diff] [blame] | 1907 | if (name == null) { |
| 1908 | name = ""; |
| 1909 | } |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 1910 | T obj = mMap.get(name); |
| 1911 | if (obj != null) { |
| 1912 | return obj; |
| 1913 | } |
| 1914 | |
| 1915 | // No object exists for the given name, but do we currently have it |
| 1916 | // running as part of the overflow? |
| 1917 | if (mActiveOverflow != null) { |
| 1918 | MutableInt over = mActiveOverflow.get(name); |
| 1919 | if (over != null) { |
| 1920 | // We are already actively counting this name in the overflow object. |
| 1921 | obj = mCurOverflow; |
| 1922 | if (obj != null) { |
| 1923 | over.value--; |
| 1924 | if (over.value <= 0) { |
| 1925 | mActiveOverflow.remove(name); |
Dianne Hackborn | 657153b | 2016-07-29 14:54:14 -0700 | [diff] [blame^] | 1926 | mLastOverflowFinishTime = SystemClock.elapsedRealtime(); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 1927 | } |
| 1928 | return obj; |
| 1929 | } |
| 1930 | } |
| 1931 | } |
| 1932 | |
| 1933 | // Huh, they are stopping an active operation but we can't find one! |
| 1934 | // That's not good. |
Dianne Hackborn | 657153b | 2016-07-29 14:54:14 -0700 | [diff] [blame^] | 1935 | StringBuilder sb = new StringBuilder(); |
| 1936 | sb.append("Unable to find object for "); |
| 1937 | sb.append(name); |
| 1938 | sb.append(" in uid "); |
| 1939 | sb.append(mUid); |
| 1940 | sb.append(" mapsize="); |
| 1941 | sb.append(mMap.size()); |
| 1942 | sb.append(" activeoverflow="); |
| 1943 | sb.append(mActiveOverflow); |
| 1944 | sb.append(" curoverflow="); |
| 1945 | sb.append(mCurOverflow); |
| 1946 | long now = SystemClock.elapsedRealtime(); |
| 1947 | if (mLastOverflowTime != 0) { |
| 1948 | sb.append(" lastOverflowTime="); |
| 1949 | TimeUtils.formatDuration(mLastOverflowTime-now, sb); |
| 1950 | } |
| 1951 | if (mLastOverflowFinishTime != 0) { |
| 1952 | sb.append(" lastOverflowFinishTime="); |
| 1953 | TimeUtils.formatDuration(mLastOverflowFinishTime-now, sb); |
| 1954 | } |
| 1955 | if (mLastClearTime != 0) { |
| 1956 | sb.append(" lastClearTime="); |
| 1957 | TimeUtils.formatDuration(mLastClearTime-now, sb); |
| 1958 | } |
| 1959 | if (mLastCleanupTime != 0) { |
| 1960 | sb.append(" lastCleanupTime="); |
| 1961 | TimeUtils.formatDuration(mLastCleanupTime-now, sb); |
| 1962 | } |
| 1963 | Slog.wtf(TAG, sb.toString()); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 1964 | return null; |
| 1965 | } |
| 1966 | |
| 1967 | public abstract T instantiateObject(); |
| 1968 | } |
| 1969 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 1970 | public static class ControllerActivityCounterImpl extends ControllerActivityCounter |
| 1971 | implements Parcelable { |
| 1972 | private final LongSamplingCounter mIdleTimeMillis; |
| 1973 | private final LongSamplingCounter mRxTimeMillis; |
| 1974 | private final LongSamplingCounter[] mTxTimeMillis; |
| 1975 | private final LongSamplingCounter mPowerDrainMaMs; |
| 1976 | |
| 1977 | public ControllerActivityCounterImpl(TimeBase timeBase, int numTxStates) { |
| 1978 | mIdleTimeMillis = new LongSamplingCounter(timeBase); |
| 1979 | mRxTimeMillis = new LongSamplingCounter(timeBase); |
| 1980 | mTxTimeMillis = new LongSamplingCounter[numTxStates]; |
| 1981 | for (int i = 0; i < numTxStates; i++) { |
| 1982 | mTxTimeMillis[i] = new LongSamplingCounter(timeBase); |
| 1983 | } |
| 1984 | mPowerDrainMaMs = new LongSamplingCounter(timeBase); |
| 1985 | } |
| 1986 | |
| 1987 | public ControllerActivityCounterImpl(TimeBase timeBase, int numTxStates, Parcel in) { |
| 1988 | mIdleTimeMillis = new LongSamplingCounter(timeBase, in); |
| 1989 | mRxTimeMillis = new LongSamplingCounter(timeBase, in); |
| 1990 | final int recordedTxStates = in.readInt(); |
| 1991 | if (recordedTxStates != numTxStates) { |
| 1992 | throw new ParcelFormatException("inconsistent tx state lengths"); |
| 1993 | } |
| 1994 | |
| 1995 | mTxTimeMillis = new LongSamplingCounter[numTxStates]; |
| 1996 | for (int i = 0; i < numTxStates; i++) { |
| 1997 | mTxTimeMillis[i] = new LongSamplingCounter(timeBase, in); |
| 1998 | } |
| 1999 | mPowerDrainMaMs = new LongSamplingCounter(timeBase, in); |
| 2000 | } |
| 2001 | |
| 2002 | public void readSummaryFromParcel(Parcel in) { |
| 2003 | mIdleTimeMillis.readSummaryFromParcelLocked(in); |
| 2004 | mRxTimeMillis.readSummaryFromParcelLocked(in); |
| 2005 | final int recordedTxStates = in.readInt(); |
| 2006 | if (recordedTxStates != mTxTimeMillis.length) { |
| 2007 | throw new ParcelFormatException("inconsistent tx state lengths"); |
| 2008 | } |
| 2009 | for (LongSamplingCounter counter : mTxTimeMillis) { |
| 2010 | counter.readSummaryFromParcelLocked(in); |
| 2011 | } |
| 2012 | mPowerDrainMaMs.readSummaryFromParcelLocked(in); |
| 2013 | } |
| 2014 | |
| 2015 | @Override |
| 2016 | public int describeContents() { |
| 2017 | return 0; |
| 2018 | } |
| 2019 | |
| 2020 | public void writeSummaryToParcel(Parcel dest) { |
| 2021 | mIdleTimeMillis.writeSummaryFromParcelLocked(dest); |
| 2022 | mRxTimeMillis.writeSummaryFromParcelLocked(dest); |
| 2023 | dest.writeInt(mTxTimeMillis.length); |
| 2024 | for (LongSamplingCounter counter : mTxTimeMillis) { |
| 2025 | counter.writeSummaryFromParcelLocked(dest); |
| 2026 | } |
| 2027 | mPowerDrainMaMs.writeSummaryFromParcelLocked(dest); |
| 2028 | } |
| 2029 | |
| 2030 | @Override |
| 2031 | public void writeToParcel(Parcel dest, int flags) { |
| 2032 | mIdleTimeMillis.writeToParcel(dest); |
| 2033 | mRxTimeMillis.writeToParcel(dest); |
| 2034 | dest.writeInt(mTxTimeMillis.length); |
| 2035 | for (LongSamplingCounter counter : mTxTimeMillis) { |
| 2036 | counter.writeToParcel(dest); |
| 2037 | } |
| 2038 | mPowerDrainMaMs.writeToParcel(dest); |
| 2039 | } |
| 2040 | |
| 2041 | public void reset(boolean detachIfReset) { |
| 2042 | mIdleTimeMillis.reset(detachIfReset); |
| 2043 | mRxTimeMillis.reset(detachIfReset); |
| 2044 | for (LongSamplingCounter counter : mTxTimeMillis) { |
| 2045 | counter.reset(detachIfReset); |
| 2046 | } |
| 2047 | mPowerDrainMaMs.reset(detachIfReset); |
| 2048 | } |
| 2049 | |
| 2050 | public void detach() { |
| 2051 | mIdleTimeMillis.detach(); |
| 2052 | mRxTimeMillis.detach(); |
| 2053 | for (LongSamplingCounter counter : mTxTimeMillis) { |
| 2054 | counter.detach(); |
| 2055 | } |
| 2056 | mPowerDrainMaMs.detach(); |
| 2057 | } |
| 2058 | |
| 2059 | /** |
| 2060 | * @return a LongSamplingCounter, measuring time spent in the idle state in |
| 2061 | * milliseconds. |
| 2062 | */ |
| 2063 | @Override |
| 2064 | public LongSamplingCounter getIdleTimeCounter() { |
Roshan Pius | 8164330 | 2016-03-14 16:45:55 -0700 | [diff] [blame] | 2065 | return mIdleTimeMillis; |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 2066 | } |
| 2067 | |
| 2068 | /** |
| 2069 | * @return a LongSamplingCounter, measuring time spent in the receive state in |
| 2070 | * milliseconds. |
| 2071 | */ |
| 2072 | @Override |
| 2073 | public LongSamplingCounter getRxTimeCounter() { |
| 2074 | return mRxTimeMillis; |
| 2075 | } |
| 2076 | |
| 2077 | /** |
| 2078 | * @return a LongSamplingCounter[], measuring time spent in various transmit states in |
| 2079 | * milliseconds. |
| 2080 | */ |
| 2081 | @Override |
| 2082 | public LongSamplingCounter[] getTxTimeCounters() { |
| 2083 | return mTxTimeMillis; |
| 2084 | } |
| 2085 | |
| 2086 | /** |
| 2087 | * @return a LongSamplingCounter, measuring power use in milli-ampere milliseconds (mAmS). |
| 2088 | */ |
| 2089 | @Override |
| 2090 | public LongSamplingCounter getPowerCounter() { |
| 2091 | return mPowerDrainMaMs; |
| 2092 | } |
| 2093 | } |
| 2094 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2095 | /* |
| 2096 | * Get the wakeup reason counter, and create a new one if one |
| 2097 | * doesn't already exist. |
| 2098 | */ |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 2099 | public SamplingTimer getWakeupReasonTimerLocked(String name) { |
| 2100 | SamplingTimer timer = mWakeupReasonStats.get(name); |
| 2101 | if (timer == null) { |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 2102 | timer = new SamplingTimer(mClocks, mOnBatteryTimeBase); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 2103 | mWakeupReasonStats.put(name, timer); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2104 | } |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 2105 | return timer; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2106 | } |
| 2107 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2108 | /* |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2109 | * 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] | 2110 | * doesn't already exist. |
| 2111 | */ |
| 2112 | public SamplingTimer getKernelWakelockTimerLocked(String name) { |
| 2113 | SamplingTimer kwlt = mKernelWakelockStats.get(name); |
| 2114 | if (kwlt == null) { |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 2115 | kwlt = new SamplingTimer(mClocks, mOnBatteryScreenOffTimeBase); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2116 | mKernelWakelockStats.put(name, kwlt); |
| 2117 | } |
| 2118 | return kwlt; |
| 2119 | } |
Amith Yamasani | 3718aaa | 2009-06-09 06:32:35 -0700 | [diff] [blame] | 2120 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2121 | private int writeHistoryTag(HistoryTag tag) { |
| 2122 | Integer idxObj = mHistoryTagPool.get(tag); |
| 2123 | int idx; |
| 2124 | if (idxObj != null) { |
| 2125 | idx = idxObj; |
| 2126 | } else { |
| 2127 | idx = mNextHistoryTagIdx; |
| 2128 | HistoryTag key = new HistoryTag(); |
| 2129 | key.setTo(tag); |
| 2130 | tag.poolIdx = idx; |
| 2131 | mHistoryTagPool.put(key, idx); |
| 2132 | mNextHistoryTagIdx++; |
| 2133 | mNumHistoryTagChars += key.string.length() + 1; |
| 2134 | } |
| 2135 | return idx; |
| 2136 | } |
| 2137 | |
| 2138 | private void readHistoryTag(int index, HistoryTag tag) { |
| 2139 | tag.string = mReadHistoryStrings[index]; |
| 2140 | tag.uid = mReadHistoryUids[index]; |
| 2141 | tag.poolIdx = index; |
| 2142 | } |
| 2143 | |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 2144 | /* |
| 2145 | The history delta format uses flags to denote further data in subsequent ints in the parcel. |
| 2146 | |
| 2147 | There is always the first token, which may contain the delta time, or an indicator of |
| 2148 | the length of the time (int or long) following this token. |
| 2149 | |
| 2150 | First token: always present, |
| 2151 | 31 23 15 7 0 |
| 2152 | â–ˆ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â–ˆ |
| 2153 | |
| 2154 | T: the delta time if it is <= 0x7fffd. Otherwise 0x7fffe indicates an int immediately |
| 2155 | follows containing the time, and 0x7ffff indicates a long immediately follows with the |
| 2156 | delta time. |
| 2157 | A: battery level changed and an int follows with battery data. |
| 2158 | B: state changed and an int follows with state change data. |
| 2159 | C: state2 has changed and an int follows with state2 change data. |
| 2160 | D: wakelock/wakereason has changed and an wakelock/wakereason struct follows. |
| 2161 | E: event data has changed and an event struct follows. |
| 2162 | F: battery charge in coulombs has changed and an int with the charge follows. |
| 2163 | G: state flag denoting that the mobile radio was active. |
| 2164 | H: state flag denoting that the wifi radio was active. |
| 2165 | I: state flag denoting that a wifi scan occurred. |
| 2166 | J: state flag denoting that a wifi full lock was held. |
| 2167 | K: state flag denoting that the gps was on. |
| 2168 | L: state flag denoting that a wakelock was held. |
| 2169 | M: state flag denoting that the cpu was running. |
| 2170 | |
| 2171 | Time int/long: if T in the first token is 0x7ffff or 0x7fffe, then an int or long follows |
| 2172 | with the time delta. |
| 2173 | |
| 2174 | Battery level int: if A in the first token is set, |
| 2175 | 31 23 15 7 0 |
| 2176 | â–ˆ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â–ˆ |
| 2177 | |
| 2178 | D: indicates that extra history details follow. |
| 2179 | V: the battery voltage. |
| 2180 | T: the battery temperature. |
| 2181 | L: the battery level (out of 100). |
| 2182 | |
| 2183 | State change int: if B in the first token is set, |
| 2184 | 31 23 15 7 0 |
| 2185 | â–ˆS|S|S|H|H|H|P|Pâ–ˆF|E|D|C|B| | |Aâ–ˆ | | | | | | | â–ˆ | | | | | | | â–ˆ |
| 2186 | |
| 2187 | A: wifi multicast was on. |
| 2188 | B: battery was plugged in. |
| 2189 | C: screen was on. |
| 2190 | D: phone was scanning for signal. |
| 2191 | E: audio was on. |
| 2192 | F: a sensor was active. |
| 2193 | |
| 2194 | State2 change int: if C in the first token is set, |
| 2195 | 31 23 15 7 0 |
| 2196 | â–ˆM|L|K|J|I|H|H|Gâ–ˆF|E|D|C| | | | â–ˆ | | | | | | | â–ˆ |B|B|B|A|A|A|Aâ–ˆ |
| 2197 | |
| 2198 | A: 4 bits indicating the wifi supplicant state: {@link BatteryStats#WIFI_SUPPL_STATE_NAMES}. |
| 2199 | B: 3 bits indicating the wifi signal strength: 0, 1, 2, 3, 4. |
| 2200 | C: a bluetooth scan was active. |
| 2201 | D: the camera was active. |
| 2202 | E: bluetooth was on. |
| 2203 | F: a phone call was active. |
| 2204 | G: the device was charging. |
| 2205 | H: 2 bits indicating the device-idle (doze) state: off, light, full |
| 2206 | I: the flashlight was on. |
| 2207 | J: wifi was on. |
| 2208 | K: wifi was running. |
| 2209 | L: video was playing. |
| 2210 | M: power save mode was on. |
| 2211 | |
| 2212 | Wakelock/wakereason struct: if D in the first token is set, |
| 2213 | TODO(adamlesinski): describe wakelock/wakereason struct. |
| 2214 | |
| 2215 | Event struct: if E in the first token is set, |
| 2216 | TODO(adamlesinski): describe the event struct. |
| 2217 | |
| 2218 | History step details struct: if D in the battery level int is set, |
| 2219 | TODO(adamlesinski): describe the history step details struct. |
| 2220 | |
| 2221 | Battery charge int: if F in the first token is set, an int representing the battery charge |
| 2222 | in coulombs follows. |
| 2223 | */ |
| 2224 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2225 | // Part of initial delta int that specifies the time delta. |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 2226 | static final int DELTA_TIME_MASK = 0x7ffff; |
| 2227 | static final int DELTA_TIME_LONG = 0x7ffff; // The delta is a following long |
| 2228 | static final int DELTA_TIME_INT = 0x7fffe; // The delta is a following int |
| 2229 | 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] | 2230 | // Flag in delta int: a new battery level int follows. |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 2231 | static final int DELTA_BATTERY_LEVEL_FLAG = 0x00080000; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2232 | // 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] | 2233 | static final int DELTA_STATE_FLAG = 0x00100000; |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 2234 | // Flag in delta int: a new full state2 int follows. |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 2235 | static final int DELTA_STATE2_FLAG = 0x00200000; |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 2236 | // Flag in delta int: contains a wakelock or wakeReason tag. |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 2237 | static final int DELTA_WAKELOCK_FLAG = 0x00400000; |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2238 | // Flag in delta int: contains an event description. |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 2239 | static final int DELTA_EVENT_FLAG = 0x00800000; |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 2240 | // Flag in delta int: contains the battery charge count in uAh. |
| 2241 | static final int DELTA_BATTERY_CHARGE_FLAG = 0x01000000; |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2242 | // These upper bits are the frequently changing state bits. |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 2243 | static final int DELTA_STATE_MASK = 0xfe000000; |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 2244 | |
| 2245 | // These are the pieces of battery state that are packed in to the upper bits of |
| 2246 | // 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] | 2247 | // in STATE_BATTERY_MASK. |
| 2248 | static final int STATE_BATTERY_MASK = 0xff000000; |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 2249 | static final int STATE_BATTERY_STATUS_MASK = 0x00000007; |
| 2250 | static final int STATE_BATTERY_STATUS_SHIFT = 29; |
| 2251 | static final int STATE_BATTERY_HEALTH_MASK = 0x00000007; |
| 2252 | static final int STATE_BATTERY_HEALTH_SHIFT = 26; |
| 2253 | static final int STATE_BATTERY_PLUG_MASK = 0x00000003; |
| 2254 | static final int STATE_BATTERY_PLUG_SHIFT = 24; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2255 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 2256 | // We use the low bit of the battery state int to indicate that we have full details |
| 2257 | // from a battery level change. |
| 2258 | static final int BATTERY_DELTA_LEVEL_FLAG = 0x00000001; |
| 2259 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2260 | public void writeHistoryDelta(Parcel dest, HistoryItem cur, HistoryItem last) { |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2261 | if (last == null || cur.cmd != HistoryItem.CMD_UPDATE) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2262 | dest.writeInt(DELTA_TIME_ABS); |
| 2263 | cur.writeToParcel(dest, 0); |
| 2264 | return; |
| 2265 | } |
| 2266 | |
| 2267 | final long deltaTime = cur.time - last.time; |
| 2268 | final int lastBatteryLevelInt = buildBatteryLevelInt(last); |
| 2269 | final int lastStateInt = buildStateInt(last); |
| 2270 | |
| 2271 | int deltaTimeToken; |
| 2272 | if (deltaTime < 0 || deltaTime > Integer.MAX_VALUE) { |
| 2273 | deltaTimeToken = DELTA_TIME_LONG; |
| 2274 | } else if (deltaTime >= DELTA_TIME_ABS) { |
| 2275 | deltaTimeToken = DELTA_TIME_INT; |
| 2276 | } else { |
| 2277 | deltaTimeToken = (int)deltaTime; |
| 2278 | } |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2279 | int firstToken = deltaTimeToken | (cur.states&DELTA_STATE_MASK); |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 2280 | final int includeStepDetails = mLastHistoryStepLevel > cur.batteryLevel |
| 2281 | ? BATTERY_DELTA_LEVEL_FLAG : 0; |
| 2282 | final boolean computeStepDetails = includeStepDetails != 0 |
| 2283 | || mLastHistoryStepDetails == null; |
| 2284 | final int batteryLevelInt = buildBatteryLevelInt(cur) | includeStepDetails; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2285 | final boolean batteryLevelIntChanged = batteryLevelInt != lastBatteryLevelInt; |
| 2286 | if (batteryLevelIntChanged) { |
| 2287 | firstToken |= DELTA_BATTERY_LEVEL_FLAG; |
| 2288 | } |
| 2289 | final int stateInt = buildStateInt(cur); |
| 2290 | final boolean stateIntChanged = stateInt != lastStateInt; |
| 2291 | if (stateIntChanged) { |
| 2292 | firstToken |= DELTA_STATE_FLAG; |
| 2293 | } |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2294 | final boolean state2IntChanged = cur.states2 != last.states2; |
| 2295 | if (state2IntChanged) { |
| 2296 | firstToken |= DELTA_STATE2_FLAG; |
| 2297 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 2298 | if (cur.wakelockTag != null || cur.wakeReasonTag != null) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2299 | firstToken |= DELTA_WAKELOCK_FLAG; |
| 2300 | } |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2301 | if (cur.eventCode != HistoryItem.EVENT_NONE) { |
| 2302 | firstToken |= DELTA_EVENT_FLAG; |
| 2303 | } |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 2304 | |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 2305 | final boolean batteryChargeChanged = cur.batteryChargeUAh != last.batteryChargeUAh; |
| 2306 | if (batteryChargeChanged) { |
| 2307 | firstToken |= DELTA_BATTERY_CHARGE_FLAG; |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 2308 | } |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2309 | dest.writeInt(firstToken); |
| 2310 | if (DEBUG) Slog.i(TAG, "WRITE DELTA: firstToken=0x" + Integer.toHexString(firstToken) |
| 2311 | + " deltaTime=" + deltaTime); |
| 2312 | |
| 2313 | if (deltaTimeToken >= DELTA_TIME_INT) { |
| 2314 | if (deltaTimeToken == DELTA_TIME_INT) { |
| 2315 | if (DEBUG) Slog.i(TAG, "WRITE DELTA: int deltaTime=" + (int)deltaTime); |
| 2316 | dest.writeInt((int)deltaTime); |
| 2317 | } else { |
| 2318 | if (DEBUG) Slog.i(TAG, "WRITE DELTA: long deltaTime=" + deltaTime); |
| 2319 | dest.writeLong(deltaTime); |
| 2320 | } |
| 2321 | } |
| 2322 | if (batteryLevelIntChanged) { |
| 2323 | dest.writeInt(batteryLevelInt); |
| 2324 | if (DEBUG) Slog.i(TAG, "WRITE DELTA: batteryToken=0x" |
| 2325 | + Integer.toHexString(batteryLevelInt) |
| 2326 | + " batteryLevel=" + cur.batteryLevel |
| 2327 | + " batteryTemp=" + cur.batteryTemperature |
| 2328 | + " batteryVolt=" + (int)cur.batteryVoltage); |
| 2329 | } |
| 2330 | if (stateIntChanged) { |
| 2331 | dest.writeInt(stateInt); |
| 2332 | if (DEBUG) Slog.i(TAG, "WRITE DELTA: stateToken=0x" |
| 2333 | + Integer.toHexString(stateInt) |
| 2334 | + " batteryStatus=" + cur.batteryStatus |
| 2335 | + " batteryHealth=" + cur.batteryHealth |
| 2336 | + " batteryPlugType=" + cur.batteryPlugType |
| 2337 | + " states=0x" + Integer.toHexString(cur.states)); |
| 2338 | } |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2339 | if (state2IntChanged) { |
| 2340 | dest.writeInt(cur.states2); |
| 2341 | if (DEBUG) Slog.i(TAG, "WRITE DELTA: states2=0x" |
| 2342 | + Integer.toHexString(cur.states2)); |
| 2343 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 2344 | if (cur.wakelockTag != null || cur.wakeReasonTag != null) { |
| 2345 | int wakeLockIndex; |
| 2346 | int wakeReasonIndex; |
| 2347 | if (cur.wakelockTag != null) { |
| 2348 | wakeLockIndex = writeHistoryTag(cur.wakelockTag); |
| 2349 | if (DEBUG) Slog.i(TAG, "WRITE DELTA: wakelockTag=#" + cur.wakelockTag.poolIdx |
| 2350 | + " " + cur.wakelockTag.uid + ":" + cur.wakelockTag.string); |
| 2351 | } else { |
| 2352 | wakeLockIndex = 0xffff; |
| 2353 | } |
| 2354 | if (cur.wakeReasonTag != null) { |
| 2355 | wakeReasonIndex = writeHistoryTag(cur.wakeReasonTag); |
| 2356 | if (DEBUG) Slog.i(TAG, "WRITE DELTA: wakeReasonTag=#" + cur.wakeReasonTag.poolIdx |
| 2357 | + " " + cur.wakeReasonTag.uid + ":" + cur.wakeReasonTag.string); |
| 2358 | } else { |
| 2359 | wakeReasonIndex = 0xffff; |
| 2360 | } |
| 2361 | dest.writeInt((wakeReasonIndex<<16) | wakeLockIndex); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2362 | } |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2363 | if (cur.eventCode != HistoryItem.EVENT_NONE) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2364 | int index = writeHistoryTag(cur.eventTag); |
| 2365 | int codeAndIndex = (cur.eventCode&0xffff) | (index<<16); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 2366 | dest.writeInt(codeAndIndex); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2367 | if (DEBUG) Slog.i(TAG, "WRITE DELTA: event=" + cur.eventCode + " tag=#" |
| 2368 | + cur.eventTag.poolIdx + " " + cur.eventTag.uid + ":" |
| 2369 | + cur.eventTag.string); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2370 | } |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 2371 | if (computeStepDetails) { |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 2372 | if (mPlatformIdleStateCallback != null) { |
| 2373 | mCurHistoryStepDetails.statPlatformIdleState = |
| 2374 | mPlatformIdleStateCallback.getPlatformLowPowerStats(); |
| 2375 | if (DEBUG) Slog.i(TAG, "WRITE PlatformIdleState:" + |
| 2376 | mCurHistoryStepDetails.statPlatformIdleState); |
| 2377 | } |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 2378 | computeHistoryStepDetails(mCurHistoryStepDetails, mLastHistoryStepDetails); |
| 2379 | if (includeStepDetails != 0) { |
| 2380 | mCurHistoryStepDetails.writeToParcel(dest); |
| 2381 | } |
| 2382 | cur.stepDetails = mCurHistoryStepDetails; |
| 2383 | mLastHistoryStepDetails = mCurHistoryStepDetails; |
| 2384 | } else { |
| 2385 | cur.stepDetails = null; |
| 2386 | } |
| 2387 | if (mLastHistoryStepLevel < cur.batteryLevel) { |
| 2388 | mLastHistoryStepDetails = null; |
| 2389 | } |
| 2390 | mLastHistoryStepLevel = cur.batteryLevel; |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 2391 | |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 2392 | if (batteryChargeChanged) { |
| 2393 | if (DEBUG) Slog.i(TAG, "WRITE DELTA: batteryChargeUAh=" + cur.batteryChargeUAh); |
| 2394 | dest.writeInt(cur.batteryChargeUAh); |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 2395 | } |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2396 | } |
| 2397 | |
| 2398 | private int buildBatteryLevelInt(HistoryItem h) { |
| 2399 | return ((((int)h.batteryLevel)<<25)&0xfe000000) |
Adam Lesinski | 3944c81 | 2015-11-13 15:54:59 -0800 | [diff] [blame] | 2400 | | ((((int)h.batteryTemperature)<<15)&0x01ff8000) |
| 2401 | | ((((int)h.batteryVoltage)<<1)&0x00007ffe); |
| 2402 | } |
| 2403 | |
| 2404 | private void readBatteryLevelInt(int batteryLevelInt, HistoryItem out) { |
| 2405 | out.batteryLevel = (byte)((batteryLevelInt & 0xfe000000) >>> 25); |
| 2406 | out.batteryTemperature = (short)((batteryLevelInt & 0x01ff8000) >>> 15); |
| 2407 | out.batteryVoltage = (char)((batteryLevelInt & 0x00007ffe) >>> 1); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2408 | } |
| 2409 | |
| 2410 | private int buildStateInt(HistoryItem h) { |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 2411 | int plugType = 0; |
| 2412 | if ((h.batteryPlugType&BatteryManager.BATTERY_PLUGGED_AC) != 0) { |
| 2413 | plugType = 1; |
| 2414 | } else if ((h.batteryPlugType&BatteryManager.BATTERY_PLUGGED_USB) != 0) { |
| 2415 | plugType = 2; |
| 2416 | } else if ((h.batteryPlugType&BatteryManager.BATTERY_PLUGGED_WIRELESS) != 0) { |
| 2417 | plugType = 3; |
| 2418 | } |
| 2419 | return ((h.batteryStatus&STATE_BATTERY_STATUS_MASK)<<STATE_BATTERY_STATUS_SHIFT) |
| 2420 | | ((h.batteryHealth&STATE_BATTERY_HEALTH_MASK)<<STATE_BATTERY_HEALTH_SHIFT) |
| 2421 | | ((plugType&STATE_BATTERY_PLUG_MASK)<<STATE_BATTERY_PLUG_SHIFT) |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 2422 | | (h.states&(~STATE_BATTERY_MASK)); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2423 | } |
| 2424 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 2425 | private void computeHistoryStepDetails(final HistoryStepDetails out, |
| 2426 | final HistoryStepDetails last) { |
| 2427 | final HistoryStepDetails tmp = last != null ? mTmpHistoryStepDetails : out; |
| 2428 | |
| 2429 | // Perform a CPU update right after we do this collection, so we have started |
| 2430 | // collecting good data for the next step. |
| 2431 | requestImmediateCpuUpdate(); |
| 2432 | |
| 2433 | if (last == null) { |
| 2434 | // We are not generating a delta, so all we need to do is reset the stats |
| 2435 | // we will later be doing a delta from. |
| 2436 | final int NU = mUidStats.size(); |
| 2437 | for (int i=0; i<NU; i++) { |
| 2438 | final BatteryStatsImpl.Uid uid = mUidStats.valueAt(i); |
| 2439 | uid.mLastStepUserTime = uid.mCurStepUserTime; |
| 2440 | uid.mLastStepSystemTime = uid.mCurStepSystemTime; |
| 2441 | } |
| 2442 | mLastStepCpuUserTime = mCurStepCpuUserTime; |
| 2443 | mLastStepCpuSystemTime = mCurStepCpuSystemTime; |
| 2444 | mLastStepStatUserTime = mCurStepStatUserTime; |
| 2445 | mLastStepStatSystemTime = mCurStepStatSystemTime; |
| 2446 | mLastStepStatIOWaitTime = mCurStepStatIOWaitTime; |
| 2447 | mLastStepStatIrqTime = mCurStepStatIrqTime; |
| 2448 | mLastStepStatSoftIrqTime = mCurStepStatSoftIrqTime; |
| 2449 | mLastStepStatIdleTime = mCurStepStatIdleTime; |
| 2450 | tmp.clear(); |
| 2451 | return; |
| 2452 | } |
| 2453 | if (DEBUG) { |
| 2454 | Slog.d(TAG, "Step stats last: user=" + mLastStepCpuUserTime + " sys=" |
| 2455 | + mLastStepStatSystemTime + " io=" + mLastStepStatIOWaitTime |
| 2456 | + " irq=" + mLastStepStatIrqTime + " sirq=" |
| 2457 | + mLastStepStatSoftIrqTime + " idle=" + mLastStepStatIdleTime); |
| 2458 | Slog.d(TAG, "Step stats cur: user=" + mCurStepCpuUserTime + " sys=" |
| 2459 | + mCurStepStatSystemTime + " io=" + mCurStepStatIOWaitTime |
| 2460 | + " irq=" + mCurStepStatIrqTime + " sirq=" |
| 2461 | + mCurStepStatSoftIrqTime + " idle=" + mCurStepStatIdleTime); |
| 2462 | } |
| 2463 | out.userTime = (int)(mCurStepCpuUserTime - mLastStepCpuUserTime); |
| 2464 | out.systemTime = (int)(mCurStepCpuSystemTime - mLastStepCpuSystemTime); |
| 2465 | out.statUserTime = (int)(mCurStepStatUserTime - mLastStepStatUserTime); |
| 2466 | out.statSystemTime = (int)(mCurStepStatSystemTime - mLastStepStatSystemTime); |
| 2467 | out.statIOWaitTime = (int)(mCurStepStatIOWaitTime - mLastStepStatIOWaitTime); |
| 2468 | out.statIrqTime = (int)(mCurStepStatIrqTime - mLastStepStatIrqTime); |
| 2469 | out.statSoftIrqTime = (int)(mCurStepStatSoftIrqTime - mLastStepStatSoftIrqTime); |
| 2470 | out.statIdlTime = (int)(mCurStepStatIdleTime - mLastStepStatIdleTime); |
| 2471 | out.appCpuUid1 = out.appCpuUid2 = out.appCpuUid3 = -1; |
| 2472 | out.appCpuUTime1 = out.appCpuUTime2 = out.appCpuUTime3 = 0; |
| 2473 | out.appCpuSTime1 = out.appCpuSTime2 = out.appCpuSTime3 = 0; |
| 2474 | final int NU = mUidStats.size(); |
| 2475 | for (int i=0; i<NU; i++) { |
| 2476 | final BatteryStatsImpl.Uid uid = mUidStats.valueAt(i); |
| 2477 | final int totalUTime = (int)(uid.mCurStepUserTime - uid.mLastStepUserTime); |
| 2478 | final int totalSTime = (int)(uid.mCurStepSystemTime - uid.mLastStepSystemTime); |
| 2479 | final int totalTime = totalUTime + totalSTime; |
| 2480 | uid.mLastStepUserTime = uid.mCurStepUserTime; |
| 2481 | uid.mLastStepSystemTime = uid.mCurStepSystemTime; |
| 2482 | if (totalTime <= (out.appCpuUTime3+out.appCpuSTime3)) { |
| 2483 | continue; |
| 2484 | } |
| 2485 | if (totalTime <= (out.appCpuUTime2+out.appCpuSTime2)) { |
| 2486 | out.appCpuUid3 = uid.mUid; |
| 2487 | out.appCpuUTime3 = totalUTime; |
| 2488 | out.appCpuSTime3 = totalSTime; |
| 2489 | } else { |
| 2490 | out.appCpuUid3 = out.appCpuUid2; |
| 2491 | out.appCpuUTime3 = out.appCpuUTime2; |
| 2492 | out.appCpuSTime3 = out.appCpuSTime2; |
| 2493 | if (totalTime <= (out.appCpuUTime1+out.appCpuSTime1)) { |
| 2494 | out.appCpuUid2 = uid.mUid; |
| 2495 | out.appCpuUTime2 = totalUTime; |
| 2496 | out.appCpuSTime2 = totalSTime; |
| 2497 | } else { |
| 2498 | out.appCpuUid2 = out.appCpuUid1; |
| 2499 | out.appCpuUTime2 = out.appCpuUTime1; |
| 2500 | out.appCpuSTime2 = out.appCpuSTime1; |
| 2501 | out.appCpuUid1 = uid.mUid; |
| 2502 | out.appCpuUTime1 = totalUTime; |
| 2503 | out.appCpuSTime1 = totalSTime; |
| 2504 | } |
| 2505 | } |
| 2506 | } |
| 2507 | mLastStepCpuUserTime = mCurStepCpuUserTime; |
| 2508 | mLastStepCpuSystemTime = mCurStepCpuSystemTime; |
| 2509 | mLastStepStatUserTime = mCurStepStatUserTime; |
| 2510 | mLastStepStatSystemTime = mCurStepStatSystemTime; |
| 2511 | mLastStepStatIOWaitTime = mCurStepStatIOWaitTime; |
| 2512 | mLastStepStatIrqTime = mCurStepStatIrqTime; |
| 2513 | mLastStepStatSoftIrqTime = mCurStepStatSoftIrqTime; |
| 2514 | mLastStepStatIdleTime = mCurStepStatIdleTime; |
| 2515 | } |
| 2516 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2517 | public void readHistoryDelta(Parcel src, HistoryItem cur) { |
| 2518 | int firstToken = src.readInt(); |
| 2519 | int deltaTimeToken = firstToken&DELTA_TIME_MASK; |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2520 | cur.cmd = HistoryItem.CMD_UPDATE; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2521 | cur.numReadInts = 1; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2522 | if (DEBUG) Slog.i(TAG, "READ DELTA: firstToken=0x" + Integer.toHexString(firstToken) |
| 2523 | + " deltaTimeToken=" + deltaTimeToken); |
| 2524 | |
| 2525 | if (deltaTimeToken < DELTA_TIME_ABS) { |
| 2526 | cur.time += deltaTimeToken; |
| 2527 | } else if (deltaTimeToken == DELTA_TIME_ABS) { |
| 2528 | cur.time = src.readLong(); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2529 | cur.numReadInts += 2; |
| 2530 | if (DEBUG) Slog.i(TAG, "READ DELTA: ABS time=" + cur.time); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2531 | cur.readFromParcel(src); |
| 2532 | return; |
| 2533 | } else if (deltaTimeToken == DELTA_TIME_INT) { |
| 2534 | int delta = src.readInt(); |
| 2535 | cur.time += delta; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2536 | cur.numReadInts += 1; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2537 | if (DEBUG) Slog.i(TAG, "READ DELTA: time delta=" + delta + " new time=" + cur.time); |
| 2538 | } else { |
| 2539 | long delta = src.readLong(); |
| 2540 | if (DEBUG) Slog.i(TAG, "READ DELTA: time delta=" + delta + " new time=" + cur.time); |
| 2541 | cur.time += delta; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2542 | cur.numReadInts += 2; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2543 | } |
| 2544 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 2545 | final int batteryLevelInt; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2546 | if ((firstToken&DELTA_BATTERY_LEVEL_FLAG) != 0) { |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 2547 | batteryLevelInt = src.readInt(); |
Adam Lesinski | 3944c81 | 2015-11-13 15:54:59 -0800 | [diff] [blame] | 2548 | readBatteryLevelInt(batteryLevelInt, cur); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2549 | cur.numReadInts += 1; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2550 | if (DEBUG) Slog.i(TAG, "READ DELTA: batteryToken=0x" |
| 2551 | + Integer.toHexString(batteryLevelInt) |
| 2552 | + " batteryLevel=" + cur.batteryLevel |
| 2553 | + " batteryTemp=" + cur.batteryTemperature |
| 2554 | + " batteryVolt=" + (int)cur.batteryVoltage); |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 2555 | } else { |
| 2556 | batteryLevelInt = 0; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2557 | } |
| 2558 | |
| 2559 | if ((firstToken&DELTA_STATE_FLAG) != 0) { |
| 2560 | int stateInt = src.readInt(); |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 2561 | cur.states = (firstToken&DELTA_STATE_MASK) | (stateInt&(~STATE_BATTERY_MASK)); |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 2562 | cur.batteryStatus = (byte)((stateInt>>STATE_BATTERY_STATUS_SHIFT) |
| 2563 | & STATE_BATTERY_STATUS_MASK); |
| 2564 | cur.batteryHealth = (byte)((stateInt>>STATE_BATTERY_HEALTH_SHIFT) |
| 2565 | & STATE_BATTERY_HEALTH_MASK); |
| 2566 | cur.batteryPlugType = (byte)((stateInt>>STATE_BATTERY_PLUG_SHIFT) |
| 2567 | & STATE_BATTERY_PLUG_MASK); |
| 2568 | switch (cur.batteryPlugType) { |
| 2569 | case 1: |
| 2570 | cur.batteryPlugType = BatteryManager.BATTERY_PLUGGED_AC; |
| 2571 | break; |
| 2572 | case 2: |
| 2573 | cur.batteryPlugType = BatteryManager.BATTERY_PLUGGED_USB; |
| 2574 | break; |
| 2575 | case 3: |
| 2576 | cur.batteryPlugType = BatteryManager.BATTERY_PLUGGED_WIRELESS; |
| 2577 | break; |
| 2578 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2579 | cur.numReadInts += 1; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2580 | if (DEBUG) Slog.i(TAG, "READ DELTA: stateToken=0x" |
| 2581 | + Integer.toHexString(stateInt) |
| 2582 | + " batteryStatus=" + cur.batteryStatus |
| 2583 | + " batteryHealth=" + cur.batteryHealth |
| 2584 | + " batteryPlugType=" + cur.batteryPlugType |
| 2585 | + " states=0x" + Integer.toHexString(cur.states)); |
| 2586 | } else { |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 2587 | cur.states = (firstToken&DELTA_STATE_MASK) | (cur.states&(~STATE_BATTERY_MASK)); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2588 | } |
| 2589 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2590 | if ((firstToken&DELTA_STATE2_FLAG) != 0) { |
| 2591 | cur.states2 = src.readInt(); |
| 2592 | if (DEBUG) Slog.i(TAG, "READ DELTA: states2=0x" |
| 2593 | + Integer.toHexString(cur.states2)); |
| 2594 | } |
| 2595 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2596 | if ((firstToken&DELTA_WAKELOCK_FLAG) != 0) { |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 2597 | int indexes = src.readInt(); |
| 2598 | int wakeLockIndex = indexes&0xffff; |
| 2599 | int wakeReasonIndex = (indexes>>16)&0xffff; |
| 2600 | if (wakeLockIndex != 0xffff) { |
| 2601 | cur.wakelockTag = cur.localWakelockTag; |
| 2602 | readHistoryTag(wakeLockIndex, cur.wakelockTag); |
| 2603 | if (DEBUG) Slog.i(TAG, "READ DELTA: wakelockTag=#" + cur.wakelockTag.poolIdx |
| 2604 | + " " + cur.wakelockTag.uid + ":" + cur.wakelockTag.string); |
| 2605 | } else { |
| 2606 | cur.wakelockTag = null; |
| 2607 | } |
| 2608 | if (wakeReasonIndex != 0xffff) { |
| 2609 | cur.wakeReasonTag = cur.localWakeReasonTag; |
| 2610 | readHistoryTag(wakeReasonIndex, cur.wakeReasonTag); |
| 2611 | if (DEBUG) Slog.i(TAG, "READ DELTA: wakeReasonTag=#" + cur.wakeReasonTag.poolIdx |
| 2612 | + " " + cur.wakeReasonTag.uid + ":" + cur.wakeReasonTag.string); |
| 2613 | } else { |
| 2614 | cur.wakeReasonTag = null; |
| 2615 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2616 | cur.numReadInts += 1; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2617 | } else { |
| 2618 | cur.wakelockTag = null; |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 2619 | cur.wakeReasonTag = null; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2620 | } |
| 2621 | |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2622 | if ((firstToken&DELTA_EVENT_FLAG) != 0) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2623 | cur.eventTag = cur.localEventTag; |
| 2624 | final int codeAndIndex = src.readInt(); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 2625 | cur.eventCode = (codeAndIndex&0xffff); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2626 | final int index = ((codeAndIndex>>16)&0xffff); |
| 2627 | readHistoryTag(index, cur.eventTag); |
| 2628 | cur.numReadInts += 1; |
| 2629 | if (DEBUG) Slog.i(TAG, "READ DELTA: event=" + cur.eventCode + " tag=#" |
| 2630 | + cur.eventTag.poolIdx + " " + cur.eventTag.uid + ":" |
| 2631 | + cur.eventTag.string); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2632 | } else { |
| 2633 | cur.eventCode = HistoryItem.EVENT_NONE; |
| 2634 | } |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 2635 | |
| 2636 | if ((batteryLevelInt&BATTERY_DELTA_LEVEL_FLAG) != 0) { |
| 2637 | cur.stepDetails = mReadHistoryStepDetails; |
| 2638 | cur.stepDetails.readFromParcel(src); |
| 2639 | } else { |
| 2640 | cur.stepDetails = null; |
| 2641 | } |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 2642 | |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 2643 | if ((firstToken&DELTA_BATTERY_CHARGE_FLAG) != 0) { |
| 2644 | cur.batteryChargeUAh = src.readInt(); |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 2645 | } |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2646 | } |
| 2647 | |
Dianne Hackborn | fc06413 | 2014-06-02 12:42:12 -0700 | [diff] [blame] | 2648 | @Override |
| 2649 | public void commitCurrentHistoryBatchLocked() { |
| 2650 | mHistoryLastWritten.cmd = HistoryItem.CMD_NULL; |
| 2651 | } |
| 2652 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2653 | void addHistoryBufferLocked(long elapsedRealtimeMs, long uptimeMs, HistoryItem cur) { |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2654 | if (!mHaveBatteryLevel || !mRecordingHistory) { |
| 2655 | return; |
| 2656 | } |
| 2657 | |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2658 | final long timeDiff = (mHistoryBaseTime+elapsedRealtimeMs) - mHistoryLastWritten.time; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 2659 | final int diffStates = mHistoryLastWritten.states^(cur.states&mActiveHistoryStates); |
| 2660 | final int diffStates2 = mHistoryLastWritten.states2^(cur.states2&mActiveHistoryStates2); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2661 | final int lastDiffStates = mHistoryLastWritten.states^mHistoryLastLastWritten.states; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2662 | final int lastDiffStates2 = mHistoryLastWritten.states2^mHistoryLastLastWritten.states2; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2663 | if (DEBUG) Slog.i(TAG, "ADD: tdelta=" + timeDiff + " diff=" |
| 2664 | + Integer.toHexString(diffStates) + " lastDiff=" |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2665 | + Integer.toHexString(lastDiffStates) + " diff2=" |
| 2666 | + Integer.toHexString(diffStates2) + " lastDiff2=" |
| 2667 | + Integer.toHexString(lastDiffStates2)); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2668 | if (mHistoryBufferLastPos >= 0 && mHistoryLastWritten.cmd == HistoryItem.CMD_UPDATE |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2669 | && timeDiff < 1000 && (diffStates&lastDiffStates) == 0 |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2670 | && (diffStates2&lastDiffStates2) == 0 |
| 2671 | && (mHistoryLastWritten.wakelockTag == null || cur.wakelockTag == null) |
| 2672 | && (mHistoryLastWritten.wakeReasonTag == null || cur.wakeReasonTag == null) |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 2673 | && mHistoryLastWritten.stepDetails == null |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2674 | && (mHistoryLastWritten.eventCode == HistoryItem.EVENT_NONE |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2675 | || cur.eventCode == HistoryItem.EVENT_NONE) |
| 2676 | && mHistoryLastWritten.batteryLevel == cur.batteryLevel |
| 2677 | && mHistoryLastWritten.batteryStatus == cur.batteryStatus |
| 2678 | && mHistoryLastWritten.batteryHealth == cur.batteryHealth |
| 2679 | && mHistoryLastWritten.batteryPlugType == cur.batteryPlugType |
| 2680 | && mHistoryLastWritten.batteryTemperature == cur.batteryTemperature |
| 2681 | && mHistoryLastWritten.batteryVoltage == cur.batteryVoltage) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2682 | // 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] | 2683 | // 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] | 2684 | // as long as no bit has changed both between now and the last entry, as |
| 2685 | // well as the last entry and the one before it (so we capture any toggles). |
| 2686 | if (DEBUG) Slog.i(TAG, "ADD: rewinding back to " + mHistoryBufferLastPos); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2687 | mHistoryBuffer.setDataSize(mHistoryBufferLastPos); |
| 2688 | mHistoryBuffer.setDataPosition(mHistoryBufferLastPos); |
| 2689 | mHistoryBufferLastPos = -1; |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2690 | elapsedRealtimeMs = mHistoryLastWritten.time - mHistoryBaseTime; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2691 | // If the last written history had a wakelock tag, we need to retain it. |
| 2692 | // Note that the condition above made sure that we aren't in a case where |
| 2693 | // both it and the current history item have a wakelock tag. |
| 2694 | if (mHistoryLastWritten.wakelockTag != null) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2695 | cur.wakelockTag = cur.localWakelockTag; |
| 2696 | cur.wakelockTag.setTo(mHistoryLastWritten.wakelockTag); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2697 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 2698 | // If the last written history had a wake reason tag, we need to retain it. |
| 2699 | // Note that the condition above made sure that we aren't in a case where |
| 2700 | // both it and the current history item have a wakelock tag. |
| 2701 | if (mHistoryLastWritten.wakeReasonTag != null) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2702 | cur.wakeReasonTag = cur.localWakeReasonTag; |
| 2703 | cur.wakeReasonTag.setTo(mHistoryLastWritten.wakeReasonTag); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 2704 | } |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2705 | // If the last written history had an event, we need to retain it. |
| 2706 | // Note that the condition above made sure that we aren't in a case where |
| 2707 | // both it and the current history item have an event. |
| 2708 | if (mHistoryLastWritten.eventCode != HistoryItem.EVENT_NONE) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2709 | cur.eventCode = mHistoryLastWritten.eventCode; |
| 2710 | cur.eventTag = cur.localEventTag; |
| 2711 | cur.eventTag.setTo(mHistoryLastWritten.eventTag); |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2712 | } |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 2713 | mHistoryLastWritten.setTo(mHistoryLastLastWritten); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2714 | } |
| 2715 | |
| 2716 | final int dataSize = mHistoryBuffer.dataSize(); |
| 2717 | if (dataSize >= MAX_HISTORY_BUFFER) { |
| 2718 | if (!mHistoryOverflow) { |
| 2719 | mHistoryOverflow = true; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2720 | addHistoryBufferLocked(elapsedRealtimeMs, uptimeMs, HistoryItem.CMD_UPDATE, cur); |
| 2721 | addHistoryBufferLocked(elapsedRealtimeMs, uptimeMs, HistoryItem.CMD_OVERFLOW, cur); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2722 | return; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2723 | } |
| 2724 | |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 2725 | // After overflow, we allow various bit-wise states to settle to 0. |
| 2726 | boolean writeAnyway = false; |
| 2727 | final int curStates = cur.states & HistoryItem.SETTLE_TO_ZERO_STATES |
| 2728 | & mActiveHistoryStates; |
| 2729 | if (mHistoryLastWritten.states != curStates) { |
| 2730 | // mActiveHistoryStates keeps track of which bits in .states are now being |
| 2731 | // forced to 0. |
| 2732 | int old = mActiveHistoryStates; |
| 2733 | mActiveHistoryStates &= curStates | ~HistoryItem.SETTLE_TO_ZERO_STATES; |
| 2734 | writeAnyway |= old != mActiveHistoryStates; |
| 2735 | } |
| 2736 | final int curStates2 = cur.states2 & HistoryItem.SETTLE_TO_ZERO_STATES2 |
| 2737 | & mActiveHistoryStates2; |
| 2738 | if (mHistoryLastWritten.states2 != curStates2) { |
| 2739 | // mActiveHistoryStates2 keeps track of which bits in .states2 are now being |
| 2740 | // forced to 0. |
| 2741 | int old = mActiveHistoryStates2; |
| 2742 | mActiveHistoryStates2 &= curStates2 | ~HistoryItem.SETTLE_TO_ZERO_STATES2; |
| 2743 | writeAnyway |= old != mActiveHistoryStates2; |
| 2744 | } |
| 2745 | |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2746 | // Once we've reached the maximum number of items, we only |
| 2747 | // record changes to the battery level and the most interesting states. |
| 2748 | // Once we've reached the maximum maximum number of items, we only |
| 2749 | // record changes to the battery level. |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 2750 | if (!writeAnyway && mHistoryLastWritten.batteryLevel == cur.batteryLevel && |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2751 | (dataSize >= MAX_MAX_HISTORY_BUFFER |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2752 | || ((mHistoryLastWritten.states^cur.states) |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 2753 | & HistoryItem.MOST_INTERESTING_STATES) == 0 |
| 2754 | || ((mHistoryLastWritten.states2^cur.states2) |
| 2755 | & HistoryItem.MOST_INTERESTING_STATES2) == 0)) { |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2756 | return; |
| 2757 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2758 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2759 | addHistoryBufferLocked(elapsedRealtimeMs, uptimeMs, HistoryItem.CMD_UPDATE, cur); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2760 | return; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2761 | } |
| 2762 | |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 2763 | if (dataSize == 0) { |
| 2764 | // The history is currently empty; we need it to start with a time stamp. |
| 2765 | cur.currentTime = System.currentTimeMillis(); |
| 2766 | addHistoryBufferLocked(elapsedRealtimeMs, uptimeMs, HistoryItem.CMD_RESET, cur); |
| 2767 | } |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2768 | addHistoryBufferLocked(elapsedRealtimeMs, uptimeMs, HistoryItem.CMD_UPDATE, cur); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2769 | } |
| 2770 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2771 | private void addHistoryBufferLocked(long elapsedRealtimeMs, long uptimeMs, byte cmd, |
| 2772 | HistoryItem cur) { |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2773 | if (mIteratingHistory) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2774 | throw new IllegalStateException("Can't do this while iterating history!"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2775 | } |
| 2776 | mHistoryBufferLastPos = mHistoryBuffer.dataPosition(); |
| 2777 | mHistoryLastLastWritten.setTo(mHistoryLastWritten); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2778 | mHistoryLastWritten.setTo(mHistoryBaseTime + elapsedRealtimeMs, cmd, cur); |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 2779 | mHistoryLastWritten.states &= mActiveHistoryStates; |
| 2780 | mHistoryLastWritten.states2 &= mActiveHistoryStates2; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2781 | writeHistoryDelta(mHistoryBuffer, mHistoryLastWritten, mHistoryLastLastWritten); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2782 | mLastHistoryElapsedRealtime = elapsedRealtimeMs; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2783 | cur.wakelockTag = null; |
| 2784 | cur.wakeReasonTag = null; |
| 2785 | cur.eventCode = HistoryItem.EVENT_NONE; |
| 2786 | cur.eventTag = null; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2787 | if (DEBUG_HISTORY) Slog.i(TAG, "Writing history buffer: was " + mHistoryBufferLastPos |
| 2788 | + " now " + mHistoryBuffer.dataPosition() |
| 2789 | + " size is now " + mHistoryBuffer.dataSize()); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2790 | } |
| 2791 | |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 2792 | int mChangedStates = 0; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2793 | int mChangedStates2 = 0; |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 2794 | |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2795 | void addHistoryRecordLocked(long elapsedRealtimeMs, long uptimeMs) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2796 | if (mTrackRunningHistoryElapsedRealtime != 0) { |
| 2797 | final long diffElapsed = elapsedRealtimeMs - mTrackRunningHistoryElapsedRealtime; |
| 2798 | final long diffUptime = uptimeMs - mTrackRunningHistoryUptime; |
| 2799 | if (diffUptime < (diffElapsed-20)) { |
| 2800 | final long wakeElapsedTime = elapsedRealtimeMs - (diffElapsed - diffUptime); |
| 2801 | mHistoryAddTmp.setTo(mHistoryLastWritten); |
| 2802 | mHistoryAddTmp.wakelockTag = null; |
| 2803 | mHistoryAddTmp.wakeReasonTag = null; |
| 2804 | mHistoryAddTmp.eventCode = HistoryItem.EVENT_NONE; |
| 2805 | mHistoryAddTmp.states &= ~HistoryItem.STATE_CPU_RUNNING_FLAG; |
| 2806 | addHistoryRecordInnerLocked(wakeElapsedTime, uptimeMs, mHistoryAddTmp); |
| 2807 | } |
| 2808 | } |
| 2809 | mHistoryCur.states |= HistoryItem.STATE_CPU_RUNNING_FLAG; |
| 2810 | mTrackRunningHistoryElapsedRealtime = elapsedRealtimeMs; |
| 2811 | mTrackRunningHistoryUptime = uptimeMs; |
| 2812 | addHistoryRecordInnerLocked(elapsedRealtimeMs, uptimeMs, mHistoryCur); |
| 2813 | } |
| 2814 | |
| 2815 | void addHistoryRecordInnerLocked(long elapsedRealtimeMs, long uptimeMs, HistoryItem cur) { |
| 2816 | addHistoryBufferLocked(elapsedRealtimeMs, uptimeMs, cur); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2817 | |
Dianne Hackborn | e8c88e6 | 2011-08-17 19:09:09 -0700 | [diff] [blame] | 2818 | if (!USE_OLD_HISTORY) { |
| 2819 | return; |
| 2820 | } |
| 2821 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2822 | if (!mHaveBatteryLevel || !mRecordingHistory) { |
| 2823 | return; |
| 2824 | } |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2825 | |
| 2826 | // If the current time is basically the same as the last time, |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 2827 | // and no states have since the last recorded entry changed and |
| 2828 | // are now resetting back to their original value, then just collapse |
| 2829 | // into one record. |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2830 | if (mHistoryEnd != null && mHistoryEnd.cmd == HistoryItem.CMD_UPDATE |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2831 | && (mHistoryBaseTime+elapsedRealtimeMs) < (mHistoryEnd.time+1000) |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 2832 | && ((mHistoryEnd.states^cur.states)&mChangedStates&mActiveHistoryStates) == 0 |
| 2833 | && ((mHistoryEnd.states2^cur.states2)&mChangedStates2&mActiveHistoryStates2) == 0) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2834 | // If the current is the same as the one before, then we no |
| 2835 | // longer need the entry. |
| 2836 | if (mHistoryLastEnd != null && mHistoryLastEnd.cmd == HistoryItem.CMD_UPDATE |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2837 | && (mHistoryBaseTime+elapsedRealtimeMs) < (mHistoryEnd.time+500) |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2838 | && mHistoryLastEnd.sameNonEvent(cur)) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2839 | mHistoryLastEnd.next = null; |
| 2840 | mHistoryEnd.next = mHistoryCache; |
| 2841 | mHistoryCache = mHistoryEnd; |
| 2842 | mHistoryEnd = mHistoryLastEnd; |
| 2843 | mHistoryLastEnd = null; |
| 2844 | } else { |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 2845 | mChangedStates |= mHistoryEnd.states^(cur.states&mActiveHistoryStates); |
| 2846 | mChangedStates2 |= mHistoryEnd.states^(cur.states2&mActiveHistoryStates2); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2847 | mHistoryEnd.setTo(mHistoryEnd.time, HistoryItem.CMD_UPDATE, cur); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2848 | } |
| 2849 | return; |
| 2850 | } |
| 2851 | |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 2852 | mChangedStates = 0; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2853 | mChangedStates2 = 0; |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 2854 | |
| 2855 | if (mNumHistoryItems == MAX_HISTORY_ITEMS |
| 2856 | || mNumHistoryItems == MAX_MAX_HISTORY_ITEMS) { |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2857 | addHistoryRecordLocked(elapsedRealtimeMs, HistoryItem.CMD_OVERFLOW); |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 2858 | } |
| 2859 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2860 | if (mNumHistoryItems >= MAX_HISTORY_ITEMS) { |
| 2861 | // Once we've reached the maximum number of items, we only |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 2862 | // record changes to the battery level and the most interesting states. |
| 2863 | // Once we've reached the maximum maximum number of items, we only |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2864 | // record changes to the battery level. |
| 2865 | if (mHistoryEnd != null && mHistoryEnd.batteryLevel |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2866 | == cur.batteryLevel && |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 2867 | (mNumHistoryItems >= MAX_MAX_HISTORY_ITEMS |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 2868 | || ((mHistoryEnd.states^(cur.states&mActiveHistoryStates)) |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 2869 | & HistoryItem.MOST_INTERESTING_STATES) == 0)) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2870 | return; |
| 2871 | } |
| 2872 | } |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2873 | |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2874 | addHistoryRecordLocked(elapsedRealtimeMs, HistoryItem.CMD_UPDATE); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2875 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2876 | |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 2877 | public void addHistoryEventLocked(long elapsedRealtimeMs, long uptimeMs, int code, |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2878 | String name, int uid) { |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2879 | mHistoryCur.eventCode = code; |
| 2880 | mHistoryCur.eventTag = mHistoryCur.localEventTag; |
| 2881 | mHistoryCur.eventTag.string = name; |
| 2882 | mHistoryCur.eventTag.uid = uid; |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 2883 | addHistoryRecordLocked(elapsedRealtimeMs, uptimeMs); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 2884 | } |
| 2885 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2886 | void addHistoryRecordLocked(long elapsedRealtimeMs, long uptimeMs, byte cmd, HistoryItem cur) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2887 | HistoryItem rec = mHistoryCache; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 2888 | if (rec != null) { |
| 2889 | mHistoryCache = rec.next; |
| 2890 | } else { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2891 | rec = new HistoryItem(); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 2892 | } |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2893 | rec.setTo(mHistoryBaseTime + elapsedRealtimeMs, cmd, cur); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2894 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2895 | addHistoryRecordLocked(rec); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 2896 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2897 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2898 | void addHistoryRecordLocked(HistoryItem rec) { |
| 2899 | mNumHistoryItems++; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 2900 | rec.next = null; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2901 | mHistoryLastEnd = mHistoryEnd; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 2902 | if (mHistoryEnd != null) { |
| 2903 | mHistoryEnd.next = rec; |
| 2904 | mHistoryEnd = rec; |
| 2905 | } else { |
| 2906 | mHistory = mHistoryEnd = rec; |
| 2907 | } |
| 2908 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2909 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2910 | void clearHistoryLocked() { |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2911 | if (DEBUG_HISTORY) Slog.i(TAG, "********** CLEARING HISTORY!"); |
Dianne Hackborn | e8c88e6 | 2011-08-17 19:09:09 -0700 | [diff] [blame] | 2912 | if (USE_OLD_HISTORY) { |
| 2913 | if (mHistory != null) { |
| 2914 | mHistoryEnd.next = mHistoryCache; |
| 2915 | mHistoryCache = mHistory; |
| 2916 | mHistory = mHistoryLastEnd = mHistoryEnd = null; |
| 2917 | } |
| 2918 | mNumHistoryItems = 0; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 2919 | } |
Dianne Hackborn | e8c88e6 | 2011-08-17 19:09:09 -0700 | [diff] [blame] | 2920 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2921 | mHistoryBaseTime = 0; |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2922 | mLastHistoryElapsedRealtime = 0; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2923 | mTrackRunningHistoryElapsedRealtime = 0; |
| 2924 | mTrackRunningHistoryUptime = 0; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2925 | |
| 2926 | mHistoryBuffer.setDataSize(0); |
| 2927 | mHistoryBuffer.setDataPosition(0); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2928 | mHistoryBuffer.setDataCapacity(MAX_HISTORY_BUFFER / 2); |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2929 | mHistoryLastLastWritten.clear(); |
| 2930 | mHistoryLastWritten.clear(); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2931 | mHistoryTagPool.clear(); |
| 2932 | mNextHistoryTagIdx = 0; |
| 2933 | mNumHistoryTagChars = 0; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2934 | mHistoryBufferLastPos = -1; |
| 2935 | mHistoryOverflow = false; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 2936 | mActiveHistoryStates = 0xffffffff; |
| 2937 | mActiveHistoryStates2 = 0xffffffff; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 2938 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2939 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2940 | public void updateTimeBasesLocked(boolean unplugged, boolean screenOff, long uptime, |
| 2941 | long realtime) { |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 2942 | mOnBatteryTimeBase.setRunning(unplugged, uptime, realtime); |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 2943 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2944 | boolean unpluggedScreenOff = unplugged && screenOff; |
| 2945 | if (unpluggedScreenOff != mOnBatteryScreenOffTimeBase.isRunning()) { |
| 2946 | updateKernelWakelocksLocked(); |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 2947 | if (DEBUG_ENERGY_CPU) { |
| 2948 | Slog.d(TAG, "Updating cpu time because screen is now " + |
| 2949 | (unpluggedScreenOff ? "off" : "on")); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2950 | } |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 2951 | updateCpuTimeLocked(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2952 | mOnBatteryScreenOffTimeBase.setRunning(unpluggedScreenOff, uptime, realtime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2953 | } |
| 2954 | } |
Amith Yamasani | 3718aaa | 2009-06-09 06:32:35 -0700 | [diff] [blame] | 2955 | |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 2956 | public void addIsolatedUidLocked(int isolatedUid, int appUid) { |
| 2957 | mIsolatedUids.put(isolatedUid, appUid); |
| 2958 | } |
| 2959 | |
Adam Lesinski | 61db88f | 2015-07-01 15:05:07 -0700 | [diff] [blame] | 2960 | /** |
| 2961 | * Schedules a read of the latest cpu times before removing the isolated UID. |
| 2962 | * @see #removeIsolatedUidLocked(int) |
| 2963 | */ |
| 2964 | public void scheduleRemoveIsolatedUidLocked(int isolatedUid, int appUid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 2965 | int curUid = mIsolatedUids.get(isolatedUid, -1); |
| 2966 | if (curUid == appUid) { |
Adam Lesinski | 61db88f | 2015-07-01 15:05:07 -0700 | [diff] [blame] | 2967 | if (mExternalSync != null) { |
| 2968 | mExternalSync.scheduleCpuSyncDueToRemovedUid(isolatedUid); |
| 2969 | } |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 2970 | } |
| 2971 | } |
| 2972 | |
Adam Lesinski | 61db88f | 2015-07-01 15:05:07 -0700 | [diff] [blame] | 2973 | /** |
| 2974 | * This should only be called after the cpu times have been read. |
| 2975 | * @see #scheduleRemoveIsolatedUidLocked(int, int) |
| 2976 | */ |
| 2977 | public void removeIsolatedUidLocked(int isolatedUid) { |
| 2978 | mIsolatedUids.delete(isolatedUid); |
| 2979 | mKernelUidCpuTimeReader.removeUid(isolatedUid); |
| 2980 | } |
| 2981 | |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 2982 | public int mapUid(int uid) { |
| 2983 | int isolated = mIsolatedUids.get(uid, -1); |
| 2984 | return isolated > 0 ? isolated : uid; |
| 2985 | } |
| 2986 | |
| 2987 | public void noteEventLocked(int code, String name, int uid) { |
| 2988 | uid = mapUid(uid); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 2989 | if (!mActiveEvents.updateState(code, name, uid, 0)) { |
| 2990 | return; |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 2991 | } |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 2992 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 2993 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2994 | addHistoryEventLocked(elapsedRealtime, uptime, code, name, uid); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 2995 | } |
| 2996 | |
Dianne Hackborn | d48954f | 2015-07-22 17:20:33 -0700 | [diff] [blame] | 2997 | boolean ensureStartClockTime(final long currentTime) { |
| 2998 | final long ABOUT_ONE_YEAR = 365*24*60*60*1000L; |
| 2999 | if (currentTime > ABOUT_ONE_YEAR && mStartClockTime < (currentTime-ABOUT_ONE_YEAR)) { |
| 3000 | // If the start clock time has changed by more than a year, then presumably |
| 3001 | // the previous time was completely bogus. So we are going to figure out a |
| 3002 | // 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] | 3003 | mStartClockTime = currentTime - (mClocks.elapsedRealtime()-(mRealtimeStart/1000)); |
Dianne Hackborn | d48954f | 2015-07-22 17:20:33 -0700 | [diff] [blame] | 3004 | return true; |
| 3005 | } |
| 3006 | return false; |
| 3007 | } |
| 3008 | |
Dianne Hackborn | 7d9eefd | 2014-08-27 18:30:31 -0700 | [diff] [blame] | 3009 | public void noteCurrentTimeChangedLocked() { |
| 3010 | final long currentTime = System.currentTimeMillis(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3011 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3012 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 7d9eefd | 2014-08-27 18:30:31 -0700 | [diff] [blame] | 3013 | recordCurrentTimeChangeLocked(currentTime, elapsedRealtime, uptime); |
Dianne Hackborn | d48954f | 2015-07-22 17:20:33 -0700 | [diff] [blame] | 3014 | ensureStartClockTime(currentTime); |
Dianne Hackborn | 7d9eefd | 2014-08-27 18:30:31 -0700 | [diff] [blame] | 3015 | } |
| 3016 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 3017 | public void noteProcessStartLocked(String name, int uid) { |
| 3018 | uid = mapUid(uid); |
| 3019 | if (isOnBattery()) { |
| 3020 | Uid u = getUidStatsLocked(uid); |
| 3021 | u.getProcessStatsLocked(name).incStartsLocked(); |
| 3022 | } |
| 3023 | if (!mActiveEvents.updateState(HistoryItem.EVENT_PROC_START, name, uid, 0)) { |
| 3024 | return; |
| 3025 | } |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 3026 | if (!mRecordAllHistory) { |
| 3027 | return; |
| 3028 | } |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3029 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3030 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 3031 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_PROC_START, name, uid); |
| 3032 | } |
| 3033 | |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 3034 | public void noteProcessCrashLocked(String name, int uid) { |
| 3035 | uid = mapUid(uid); |
| 3036 | if (isOnBattery()) { |
| 3037 | Uid u = getUidStatsLocked(uid); |
| 3038 | u.getProcessStatsLocked(name).incNumCrashesLocked(); |
| 3039 | } |
| 3040 | } |
| 3041 | |
| 3042 | public void noteProcessAnrLocked(String name, int uid) { |
| 3043 | uid = mapUid(uid); |
| 3044 | if (isOnBattery()) { |
| 3045 | Uid u = getUidStatsLocked(uid); |
| 3046 | u.getProcessStatsLocked(name).incNumAnrsLocked(); |
| 3047 | } |
| 3048 | } |
| 3049 | |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 3050 | public void noteUidProcessStateLocked(int uid, int state) { |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 3051 | uid = mapUid(uid); |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 3052 | getUidStatsLocked(uid).updateUidProcessStateLocked(state); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 3053 | } |
| 3054 | |
| 3055 | public void noteProcessFinishLocked(String name, int uid) { |
| 3056 | uid = mapUid(uid); |
| 3057 | if (!mActiveEvents.updateState(HistoryItem.EVENT_PROC_FINISH, name, uid, 0)) { |
| 3058 | return; |
| 3059 | } |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 3060 | if (!mRecordAllHistory) { |
| 3061 | return; |
| 3062 | } |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3063 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3064 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 3065 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_PROC_FINISH, name, uid); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 3066 | } |
| 3067 | |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 3068 | public void noteSyncStartLocked(String name, int uid) { |
| 3069 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3070 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3071 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 3072 | getUidStatsLocked(uid).noteStartSyncLocked(name, elapsedRealtime); |
| 3073 | if (!mActiveEvents.updateState(HistoryItem.EVENT_SYNC_START, name, uid, 0)) { |
| 3074 | return; |
| 3075 | } |
| 3076 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_SYNC_START, name, uid); |
| 3077 | } |
| 3078 | |
| 3079 | public void noteSyncFinishLocked(String name, int uid) { |
| 3080 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3081 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3082 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 3083 | getUidStatsLocked(uid).noteStopSyncLocked(name, elapsedRealtime); |
| 3084 | if (!mActiveEvents.updateState(HistoryItem.EVENT_SYNC_FINISH, name, uid, 0)) { |
| 3085 | return; |
| 3086 | } |
| 3087 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_SYNC_FINISH, name, uid); |
| 3088 | } |
| 3089 | |
| 3090 | public void noteJobStartLocked(String name, int uid) { |
| 3091 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3092 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3093 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 3094 | getUidStatsLocked(uid).noteStartJobLocked(name, elapsedRealtime); |
| 3095 | if (!mActiveEvents.updateState(HistoryItem.EVENT_JOB_START, name, uid, 0)) { |
| 3096 | return; |
| 3097 | } |
| 3098 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_JOB_START, name, uid); |
| 3099 | } |
| 3100 | |
| 3101 | public void noteJobFinishLocked(String name, int uid) { |
| 3102 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3103 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3104 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 3105 | getUidStatsLocked(uid).noteStopJobLocked(name, elapsedRealtime); |
| 3106 | if (!mActiveEvents.updateState(HistoryItem.EVENT_JOB_FINISH, name, uid, 0)) { |
| 3107 | return; |
| 3108 | } |
| 3109 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_JOB_FINISH, name, uid); |
| 3110 | } |
| 3111 | |
Dianne Hackborn | 1e38382 | 2015-04-10 14:02:33 -0700 | [diff] [blame] | 3112 | public void noteAlarmStartLocked(String name, int uid) { |
| 3113 | if (!mRecordAllHistory) { |
| 3114 | return; |
| 3115 | } |
| 3116 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3117 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3118 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 1e38382 | 2015-04-10 14:02:33 -0700 | [diff] [blame] | 3119 | if (!mActiveEvents.updateState(HistoryItem.EVENT_ALARM_START, name, uid, 0)) { |
| 3120 | return; |
| 3121 | } |
| 3122 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_ALARM_START, name, uid); |
| 3123 | } |
| 3124 | |
| 3125 | public void noteAlarmFinishLocked(String name, int uid) { |
| 3126 | if (!mRecordAllHistory) { |
| 3127 | return; |
| 3128 | } |
| 3129 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3130 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3131 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 1e38382 | 2015-04-10 14:02:33 -0700 | [diff] [blame] | 3132 | if (!mActiveEvents.updateState(HistoryItem.EVENT_ALARM_FINISH, name, uid, 0)) { |
| 3133 | return; |
| 3134 | } |
| 3135 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_ALARM_FINISH, name, uid); |
| 3136 | } |
| 3137 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3138 | private void requestWakelockCpuUpdate() { |
| 3139 | if (!mHandler.hasMessages(MSG_UPDATE_WAKELOCKS)) { |
| 3140 | Message m = mHandler.obtainMessage(MSG_UPDATE_WAKELOCKS); |
| 3141 | mHandler.sendMessageDelayed(m, DELAY_UPDATE_WAKELOCKS); |
| 3142 | } |
| 3143 | } |
| 3144 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 3145 | private void requestImmediateCpuUpdate() { |
| 3146 | mHandler.removeMessages(MSG_UPDATE_WAKELOCKS); |
| 3147 | mHandler.sendEmptyMessage(MSG_UPDATE_WAKELOCKS); |
| 3148 | } |
| 3149 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 3150 | public void setRecordAllHistoryLocked(boolean enabled) { |
| 3151 | mRecordAllHistory = enabled; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3152 | if (!enabled) { |
| 3153 | // Clear out any existing state. |
| 3154 | mActiveEvents.removeEvents(HistoryItem.EVENT_WAKE_LOCK); |
Dianne Hackborn | 1e38382 | 2015-04-10 14:02:33 -0700 | [diff] [blame] | 3155 | mActiveEvents.removeEvents(HistoryItem.EVENT_ALARM); |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 3156 | // Record the currently running processes as stopping, now that we are no |
| 3157 | // longer tracking them. |
| 3158 | HashMap<String, SparseIntArray> active = mActiveEvents.getStateForEvent( |
| 3159 | HistoryItem.EVENT_PROC); |
| 3160 | if (active != null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3161 | long mSecRealtime = mClocks.elapsedRealtime(); |
| 3162 | final long mSecUptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 3163 | for (HashMap.Entry<String, SparseIntArray> ent : active.entrySet()) { |
| 3164 | SparseIntArray uids = ent.getValue(); |
| 3165 | for (int j=0; j<uids.size(); j++) { |
| 3166 | addHistoryEventLocked(mSecRealtime, mSecUptime, |
| 3167 | HistoryItem.EVENT_PROC_FINISH, ent.getKey(), uids.keyAt(j)); |
| 3168 | } |
| 3169 | } |
| 3170 | } |
| 3171 | } else { |
| 3172 | // Record the currently running processes as starting, now that we are tracking them. |
| 3173 | HashMap<String, SparseIntArray> active = mActiveEvents.getStateForEvent( |
| 3174 | HistoryItem.EVENT_PROC); |
| 3175 | if (active != null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3176 | long mSecRealtime = mClocks.elapsedRealtime(); |
| 3177 | final long mSecUptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 3178 | for (HashMap.Entry<String, SparseIntArray> ent : active.entrySet()) { |
| 3179 | SparseIntArray uids = ent.getValue(); |
| 3180 | for (int j=0; j<uids.size(); j++) { |
| 3181 | addHistoryEventLocked(mSecRealtime, mSecUptime, |
| 3182 | HistoryItem.EVENT_PROC_START, ent.getKey(), uids.keyAt(j)); |
| 3183 | } |
| 3184 | } |
| 3185 | } |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3186 | } |
| 3187 | } |
| 3188 | |
Dianne Hackborn | 9a75543 | 2014-05-15 17:05:22 -0700 | [diff] [blame] | 3189 | public void setNoAutoReset(boolean enabled) { |
| 3190 | mNoAutoReset = enabled; |
| 3191 | } |
| 3192 | |
| 3193 | private String mInitialAcquireWakeName; |
| 3194 | private int mInitialAcquireWakeUid = -1; |
| 3195 | |
Dianne Hackborn | a1f1a3c | 2014-02-24 18:12:28 -0800 | [diff] [blame] | 3196 | 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] | 3197 | boolean unimportantForLogging, long elapsedRealtime, long uptime) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3198 | uid = mapUid(uid); |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 3199 | if (type == WAKE_TYPE_PARTIAL) { |
| 3200 | // Only care about partial wake locks, since full wake locks |
| 3201 | // will be canceled when the user puts the screen to sleep. |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3202 | aggregateLastWakeupUptimeLocked(uptime); |
Dianne Hackborn | fc06413 | 2014-06-02 12:42:12 -0700 | [diff] [blame] | 3203 | if (historyName == null) { |
| 3204 | historyName = name; |
| 3205 | } |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 3206 | if (mRecordAllHistory) { |
Dianne Hackborn | fc06413 | 2014-06-02 12:42:12 -0700 | [diff] [blame] | 3207 | if (mActiveEvents.updateState(HistoryItem.EVENT_WAKE_LOCK_START, historyName, |
| 3208 | uid, 0)) { |
Dianne Hackborn | 536456f | 2014-05-23 16:51:05 -0700 | [diff] [blame] | 3209 | addHistoryEventLocked(elapsedRealtime, uptime, |
Dianne Hackborn | fc06413 | 2014-06-02 12:42:12 -0700 | [diff] [blame] | 3210 | HistoryItem.EVENT_WAKE_LOCK_START, historyName, uid); |
Dianne Hackborn | 536456f | 2014-05-23 16:51:05 -0700 | [diff] [blame] | 3211 | } |
| 3212 | } |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 3213 | if (mWakeLockNesting == 0) { |
| 3214 | mHistoryCur.states |= HistoryItem.STATE_WAKE_LOCK_FLAG; |
| 3215 | if (DEBUG_HISTORY) Slog.v(TAG, "Start wake lock to: " |
| 3216 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3217 | mHistoryCur.wakelockTag = mHistoryCur.localWakelockTag; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3218 | mHistoryCur.wakelockTag.string = mInitialAcquireWakeName = historyName; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 3219 | mHistoryCur.wakelockTag.uid = mInitialAcquireWakeUid = uid; |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 3220 | mWakeLockImportant = !unimportantForLogging; |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3221 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | fc06413 | 2014-06-02 12:42:12 -0700 | [diff] [blame] | 3222 | } else if (!mWakeLockImportant && !unimportantForLogging |
| 3223 | && mHistoryLastWritten.cmd == HistoryItem.CMD_UPDATE) { |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 3224 | if (mHistoryLastWritten.wakelockTag != null) { |
| 3225 | // We'll try to update the last tag. |
| 3226 | mHistoryLastWritten.wakelockTag = null; |
| 3227 | mHistoryCur.wakelockTag = mHistoryCur.localWakelockTag; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3228 | mHistoryCur.wakelockTag.string = mInitialAcquireWakeName = historyName; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 3229 | mHistoryCur.wakelockTag.uid = mInitialAcquireWakeUid = uid; |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3230 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 3231 | } |
| 3232 | mWakeLockImportant = true; |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 3233 | } |
| 3234 | mWakeLockNesting++; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3235 | } |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3236 | if (uid >= 0) { |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 3237 | if (mOnBatteryScreenOffTimeBase.isRunning()) { |
| 3238 | // We only update the cpu time when a wake lock is acquired if the screen is off. |
| 3239 | // If the screen is on, we don't distribute the power amongst partial wakelocks. |
| 3240 | if (DEBUG_ENERGY_CPU) { |
| 3241 | Slog.d(TAG, "Updating cpu time because of +wake_lock"); |
| 3242 | } |
| 3243 | requestWakelockCpuUpdate(); |
| 3244 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3245 | getUidStatsLocked(uid).noteStartWakeLocked(pid, name, type, elapsedRealtime); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3246 | } |
| 3247 | } |
| 3248 | |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3249 | public void noteStopWakeLocked(int uid, int pid, String name, String historyName, int type, |
| 3250 | long elapsedRealtime, long uptime) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3251 | uid = mapUid(uid); |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 3252 | if (type == WAKE_TYPE_PARTIAL) { |
| 3253 | mWakeLockNesting--; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 3254 | if (mRecordAllHistory) { |
Dianne Hackborn | fc06413 | 2014-06-02 12:42:12 -0700 | [diff] [blame] | 3255 | if (historyName == null) { |
| 3256 | historyName = name; |
| 3257 | } |
| 3258 | if (mActiveEvents.updateState(HistoryItem.EVENT_WAKE_LOCK_FINISH, historyName, |
| 3259 | uid, 0)) { |
Dianne Hackborn | 536456f | 2014-05-23 16:51:05 -0700 | [diff] [blame] | 3260 | addHistoryEventLocked(elapsedRealtime, uptime, |
Dianne Hackborn | fc06413 | 2014-06-02 12:42:12 -0700 | [diff] [blame] | 3261 | HistoryItem.EVENT_WAKE_LOCK_FINISH, historyName, uid); |
Dianne Hackborn | 536456f | 2014-05-23 16:51:05 -0700 | [diff] [blame] | 3262 | } |
| 3263 | } |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 3264 | if (mWakeLockNesting == 0) { |
| 3265 | mHistoryCur.states &= ~HistoryItem.STATE_WAKE_LOCK_FLAG; |
| 3266 | if (DEBUG_HISTORY) Slog.v(TAG, "Stop wake lock to: " |
| 3267 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 3268 | mInitialAcquireWakeName = null; |
| 3269 | mInitialAcquireWakeUid = -1; |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3270 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 3271 | } |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3272 | } |
| 3273 | if (uid >= 0) { |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 3274 | if (mOnBatteryScreenOffTimeBase.isRunning()) { |
| 3275 | if (DEBUG_ENERGY_CPU) { |
| 3276 | Slog.d(TAG, "Updating cpu time because of -wake_lock"); |
| 3277 | } |
| 3278 | requestWakelockCpuUpdate(); |
| 3279 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3280 | getUidStatsLocked(uid).noteStopWakeLocked(pid, name, type, elapsedRealtime); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3281 | } |
| 3282 | } |
| 3283 | |
Dianne Hackborn | a1f1a3c | 2014-02-24 18:12:28 -0800 | [diff] [blame] | 3284 | public void noteStartWakeFromSourceLocked(WorkSource ws, int pid, String name, |
| 3285 | String historyName, int type, boolean unimportantForLogging) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3286 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3287 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 3288 | final int N = ws.size(); |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 3289 | for (int i=0; i<N; i++) { |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 3290 | noteStartWakeLocked(ws.get(i), pid, name, historyName, type, unimportantForLogging, |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3291 | elapsedRealtime, uptime); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 3292 | } |
| 3293 | } |
| 3294 | |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3295 | public void noteChangeWakelockFromSourceLocked(WorkSource ws, int pid, String name, |
| 3296 | String historyName, int type, WorkSource newWs, int newPid, String newName, |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 3297 | String newHistoryName, int newType, boolean newUnimportantForLogging) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3298 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3299 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 3300 | // For correct semantics, we start the need worksources first, so that we won't |
| 3301 | // make inappropriate history items as if all wake locks went away and new ones |
| 3302 | // appeared. This is okay because tracking of wake locks allows nesting. |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3303 | final int NN = newWs.size(); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 3304 | for (int i=0; i<NN; i++) { |
| 3305 | noteStartWakeLocked(newWs.get(i), newPid, newName, newHistoryName, newType, |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3306 | newUnimportantForLogging, elapsedRealtime, uptime); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 3307 | } |
| 3308 | final int NO = ws.size(); |
| 3309 | for (int i=0; i<NO; i++) { |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3310 | noteStopWakeLocked(ws.get(i), pid, name, historyName, type, elapsedRealtime, uptime); |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 3311 | } |
| 3312 | } |
| 3313 | |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3314 | public void noteStopWakeFromSourceLocked(WorkSource ws, int pid, String name, |
| 3315 | String historyName, int type) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3316 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3317 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 3318 | final int N = ws.size(); |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 3319 | for (int i=0; i<N; i++) { |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3320 | noteStopWakeLocked(ws.get(i), pid, name, historyName, type, elapsedRealtime, uptime); |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 3321 | } |
| 3322 | } |
| 3323 | |
Dianne Hackborn | d0db6f0 | 2016-07-18 14:14:20 -0700 | [diff] [blame] | 3324 | public void noteLongPartialWakelockStart(String name, String historyName, int uid) { |
| 3325 | uid = mapUid(uid); |
| 3326 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3327 | final long uptime = mClocks.uptimeMillis(); |
| 3328 | if (historyName == null) { |
| 3329 | historyName = name; |
| 3330 | } |
| 3331 | if (!mActiveEvents.updateState(HistoryItem.EVENT_LONG_WAKE_LOCK_START, historyName, uid, |
| 3332 | 0)) { |
| 3333 | return; |
| 3334 | } |
| 3335 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_LONG_WAKE_LOCK_START, |
| 3336 | historyName, uid); |
| 3337 | } |
| 3338 | |
| 3339 | public void noteLongPartialWakelockFinish(String name, String historyName, int uid) { |
| 3340 | uid = mapUid(uid); |
| 3341 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3342 | final long uptime = mClocks.uptimeMillis(); |
| 3343 | if (historyName == null) { |
| 3344 | historyName = name; |
| 3345 | } |
| 3346 | if (!mActiveEvents.updateState(HistoryItem.EVENT_LONG_WAKE_LOCK_FINISH, historyName, uid, |
| 3347 | 0)) { |
| 3348 | return; |
| 3349 | } |
| 3350 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_LONG_WAKE_LOCK_FINISH, |
| 3351 | historyName, uid); |
| 3352 | } |
| 3353 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3354 | void aggregateLastWakeupUptimeLocked(long uptimeMs) { |
| 3355 | if (mLastWakeupReason != null) { |
| 3356 | long deltaUptime = uptimeMs - mLastWakeupUptimeMs; |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 3357 | SamplingTimer timer = getWakeupReasonTimerLocked(mLastWakeupReason); |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 3358 | timer.add(deltaUptime * 1000, 1); // time in in microseconds |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3359 | mLastWakeupReason = null; |
| 3360 | } |
| 3361 | } |
| 3362 | |
| 3363 | public void noteWakeupReasonLocked(String reason) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3364 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3365 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 3366 | if (DEBUG_HISTORY) Slog.v(TAG, "Wakeup reason \"" + reason +"\": " |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 3367 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3368 | aggregateLastWakeupUptimeLocked(uptime); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 3369 | mHistoryCur.wakeReasonTag = mHistoryCur.localWakeReasonTag; |
| 3370 | mHistoryCur.wakeReasonTag.string = reason; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3371 | mHistoryCur.wakeReasonTag.uid = 0; |
| 3372 | mLastWakeupReason = reason; |
| 3373 | mLastWakeupUptimeMs = uptime; |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3374 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 3375 | } |
| 3376 | |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 3377 | public boolean startAddingCpuLocked() { |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 3378 | mHandler.removeMessages(MSG_UPDATE_WAKELOCKS); |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 3379 | return mOnBatteryInternal; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 3380 | } |
| 3381 | |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 3382 | public void finishAddingCpuLocked(int totalUTime, int totalSTime, int statUserTime, |
| 3383 | int statSystemTime, int statIOWaitTime, int statIrqTime, |
| 3384 | int statSoftIrqTime, int statIdleTime) { |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 3385 | if (DEBUG) Slog.d(TAG, "Adding cpu: tuser=" + totalUTime + " tsys=" + totalSTime |
| 3386 | + " user=" + statUserTime + " sys=" + statSystemTime |
| 3387 | + " io=" + statIOWaitTime + " irq=" + statIrqTime |
| 3388 | + " sirq=" + statSoftIrqTime + " idle=" + statIdleTime); |
| 3389 | mCurStepCpuUserTime += totalUTime; |
| 3390 | mCurStepCpuSystemTime += totalSTime; |
| 3391 | mCurStepStatUserTime += statUserTime; |
| 3392 | mCurStepStatSystemTime += statSystemTime; |
| 3393 | mCurStepStatIOWaitTime += statIOWaitTime; |
| 3394 | mCurStepStatIrqTime += statIrqTime; |
| 3395 | mCurStepStatSoftIrqTime += statSoftIrqTime; |
| 3396 | mCurStepStatIdleTime += statIdleTime; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 3397 | } |
| 3398 | |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3399 | public void noteProcessDiedLocked(int uid, int pid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3400 | uid = mapUid(uid); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3401 | Uid u = mUidStats.get(uid); |
| 3402 | if (u != null) { |
| 3403 | u.mPids.remove(pid); |
| 3404 | } |
| 3405 | } |
| 3406 | |
| 3407 | public long getProcessWakeTime(int uid, int pid, long realtime) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3408 | uid = mapUid(uid); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3409 | Uid u = mUidStats.get(uid); |
| 3410 | if (u != null) { |
| 3411 | Uid.Pid p = u.mPids.get(pid); |
| 3412 | if (p != null) { |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 3413 | return p.mWakeSumMs + (p.mWakeNesting > 0 ? (realtime - p.mWakeStartMs) : 0); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3414 | } |
| 3415 | } |
| 3416 | return 0; |
| 3417 | } |
| 3418 | |
| 3419 | public void reportExcessiveWakeLocked(int uid, String proc, long overTime, long usedTime) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3420 | uid = mapUid(uid); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3421 | Uid u = mUidStats.get(uid); |
| 3422 | if (u != null) { |
| 3423 | u.reportExcessiveWakeLocked(proc, overTime, usedTime); |
| 3424 | } |
| 3425 | } |
| 3426 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 3427 | public void reportExcessiveCpuLocked(int uid, String proc, long overTime, long usedTime) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3428 | uid = mapUid(uid); |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 3429 | Uid u = mUidStats.get(uid); |
| 3430 | if (u != null) { |
| 3431 | u.reportExcessiveCpuLocked(proc, overTime, usedTime); |
| 3432 | } |
| 3433 | } |
| 3434 | |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3435 | int mSensorNesting; |
| 3436 | |
| 3437 | public void noteStartSensorLocked(int uid, int sensor) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3438 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3439 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3440 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3441 | if (mSensorNesting == 0) { |
| 3442 | mHistoryCur.states |= HistoryItem.STATE_SENSOR_ON_FLAG; |
| 3443 | if (DEBUG_HISTORY) Slog.v(TAG, "Start sensor to: " |
| 3444 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3445 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3446 | } |
| 3447 | mSensorNesting++; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3448 | getUidStatsLocked(uid).noteStartSensor(sensor, elapsedRealtime); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3449 | } |
| 3450 | |
| 3451 | public void noteStopSensorLocked(int uid, int sensor) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3452 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3453 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3454 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3455 | mSensorNesting--; |
| 3456 | if (mSensorNesting == 0) { |
| 3457 | mHistoryCur.states &= ~HistoryItem.STATE_SENSOR_ON_FLAG; |
| 3458 | if (DEBUG_HISTORY) Slog.v(TAG, "Stop sensor to: " |
| 3459 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3460 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3461 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3462 | getUidStatsLocked(uid).noteStopSensor(sensor, elapsedRealtime); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3463 | } |
| 3464 | |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3465 | int mGpsNesting; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3466 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3467 | public void noteStartGpsLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3468 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3469 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3470 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3471 | if (mGpsNesting == 0) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3472 | mHistoryCur.states |= HistoryItem.STATE_GPS_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3473 | if (DEBUG_HISTORY) Slog.v(TAG, "Start GPS to: " |
| 3474 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3475 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3476 | } |
| 3477 | mGpsNesting++; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3478 | getUidStatsLocked(uid).noteStartGps(elapsedRealtime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3479 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3480 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3481 | public void noteStopGpsLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3482 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3483 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3484 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3485 | mGpsNesting--; |
| 3486 | if (mGpsNesting == 0) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3487 | mHistoryCur.states &= ~HistoryItem.STATE_GPS_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3488 | if (DEBUG_HISTORY) Slog.v(TAG, "Stop GPS to: " |
| 3489 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3490 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3491 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3492 | getUidStatsLocked(uid).noteStopGps(elapsedRealtime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3493 | } |
Amith Yamasani | 3718aaa | 2009-06-09 06:32:35 -0700 | [diff] [blame] | 3494 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 3495 | public void noteScreenStateLocked(int state) { |
| 3496 | if (mScreenState != state) { |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 3497 | recordDailyStatsIfNeededLocked(true); |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 3498 | final int oldState = mScreenState; |
| 3499 | mScreenState = state; |
| 3500 | if (DEBUG) Slog.v(TAG, "Screen state: oldState=" + Display.stateToString(oldState) |
| 3501 | + ", newState=" + Display.stateToString(state)); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3502 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 3503 | if (state != Display.STATE_UNKNOWN) { |
| 3504 | int stepState = state-1; |
| 3505 | if (stepState < 4) { |
| 3506 | mModStepMode |= (mCurStepMode&STEP_LEVEL_MODE_SCREEN_STATE) ^ stepState; |
| 3507 | mCurStepMode = (mCurStepMode&~STEP_LEVEL_MODE_SCREEN_STATE) | stepState; |
| 3508 | } else { |
| 3509 | Slog.wtf(TAG, "Unexpected screen state: " + state); |
| 3510 | } |
| 3511 | } |
| 3512 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 3513 | if (state == Display.STATE_ON) { |
| 3514 | // Screen turning on. |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3515 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3516 | final long uptime = mClocks.uptimeMillis(); |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 3517 | mHistoryCur.states |= HistoryItem.STATE_SCREEN_ON_FLAG; |
| 3518 | if (DEBUG_HISTORY) Slog.v(TAG, "Screen on to: " |
| 3519 | + Integer.toHexString(mHistoryCur.states)); |
| 3520 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 3521 | mScreenOnTimer.startRunningLocked(elapsedRealtime); |
| 3522 | if (mScreenBrightnessBin >= 0) { |
| 3523 | mScreenBrightnessTimer[mScreenBrightnessBin].startRunningLocked(elapsedRealtime); |
| 3524 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3525 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 3526 | updateTimeBasesLocked(mOnBatteryTimeBase.isRunning(), false, |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3527 | mClocks.uptimeMillis() * 1000, elapsedRealtime * 1000); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 3528 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 3529 | // Fake a wake lock, so we consider the device waked as long |
| 3530 | // as the screen is on. |
| 3531 | noteStartWakeLocked(-1, -1, "screen", null, WAKE_TYPE_PARTIAL, false, |
| 3532 | elapsedRealtime, uptime); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3533 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 3534 | // Update discharge amounts. |
| 3535 | if (mOnBatteryInternal) { |
| 3536 | updateDischargeScreenLevelsLocked(false, true); |
| 3537 | } |
| 3538 | } else if (oldState == Display.STATE_ON) { |
| 3539 | // Screen turning off or dozing. |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3540 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3541 | final long uptime = mClocks.uptimeMillis(); |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 3542 | mHistoryCur.states &= ~HistoryItem.STATE_SCREEN_ON_FLAG; |
| 3543 | if (DEBUG_HISTORY) Slog.v(TAG, "Screen off to: " |
| 3544 | + Integer.toHexString(mHistoryCur.states)); |
| 3545 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 3546 | mScreenOnTimer.stopRunningLocked(elapsedRealtime); |
| 3547 | if (mScreenBrightnessBin >= 0) { |
| 3548 | mScreenBrightnessTimer[mScreenBrightnessBin].stopRunningLocked(elapsedRealtime); |
| 3549 | } |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3550 | |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3551 | noteStopWakeLocked(-1, -1, "screen", "screen", WAKE_TYPE_PARTIAL, |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 3552 | elapsedRealtime, uptime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3553 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 3554 | updateTimeBasesLocked(mOnBatteryTimeBase.isRunning(), true, |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3555 | mClocks.uptimeMillis() * 1000, elapsedRealtime * 1000); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3556 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 3557 | // Update discharge amounts. |
| 3558 | if (mOnBatteryInternal) { |
| 3559 | updateDischargeScreenLevelsLocked(true, false); |
| 3560 | } |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 3561 | } |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3562 | } |
| 3563 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3564 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3565 | public void noteScreenBrightnessLocked(int brightness) { |
| 3566 | // Bin the brightness. |
| 3567 | int bin = brightness / (256/NUM_SCREEN_BRIGHTNESS_BINS); |
| 3568 | if (bin < 0) bin = 0; |
| 3569 | else if (bin >= NUM_SCREEN_BRIGHTNESS_BINS) bin = NUM_SCREEN_BRIGHTNESS_BINS-1; |
| 3570 | if (mScreenBrightnessBin != bin) { |
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 | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3573 | mHistoryCur.states = (mHistoryCur.states&~HistoryItem.STATE_BRIGHTNESS_MASK) |
| 3574 | | (bin << HistoryItem.STATE_BRIGHTNESS_SHIFT); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3575 | if (DEBUG_HISTORY) Slog.v(TAG, "Screen brightness " + bin + " to: " |
| 3576 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3577 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 3578 | if (mScreenState == Display.STATE_ON) { |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3579 | if (mScreenBrightnessBin >= 0) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3580 | mScreenBrightnessTimer[mScreenBrightnessBin].stopRunningLocked(elapsedRealtime); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3581 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3582 | mScreenBrightnessTimer[bin].startRunningLocked(elapsedRealtime); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3583 | } |
| 3584 | mScreenBrightnessBin = bin; |
| 3585 | } |
| 3586 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3587 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3588 | public void noteUserActivityLocked(int uid, int event) { |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 3589 | if (mOnBatteryInternal) { |
| 3590 | uid = mapUid(uid); |
| 3591 | getUidStatsLocked(uid).noteUserActivityLocked(event); |
| 3592 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3593 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3594 | |
Dianne Hackborn | 280a64e | 2015-07-13 14:48:08 -0700 | [diff] [blame] | 3595 | public void noteWakeUpLocked(String reason, int reasonUid) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3596 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3597 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 280a64e | 2015-07-13 14:48:08 -0700 | [diff] [blame] | 3598 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_SCREEN_WAKE_UP, |
| 3599 | reason, reasonUid); |
| 3600 | } |
| 3601 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 3602 | public void noteInteractiveLocked(boolean interactive) { |
| 3603 | if (mInteractive != interactive) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3604 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 3605 | mInteractive = interactive; |
| 3606 | if (DEBUG) Slog.v(TAG, "Interactive: " + interactive); |
| 3607 | if (interactive) { |
| 3608 | mInteractiveTimer.startRunningLocked(elapsedRealtime); |
| 3609 | } else { |
| 3610 | mInteractiveTimer.stopRunningLocked(elapsedRealtime); |
| 3611 | } |
| 3612 | } |
| 3613 | } |
| 3614 | |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 3615 | public void noteConnectivityChangedLocked(int type, String extra) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3616 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3617 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 3618 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_CONNECTIVITY_CHANGED, |
| 3619 | extra, type); |
| 3620 | mNumConnectivityChange++; |
| 3621 | } |
| 3622 | |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 3623 | private void noteMobileRadioApWakeupLocked(final long elapsedRealtimeMillis, |
| 3624 | final long uptimeMillis, int uid) { |
| 3625 | uid = mapUid(uid); |
| 3626 | addHistoryEventLocked(elapsedRealtimeMillis, uptimeMillis, HistoryItem.EVENT_WAKEUP_AP, "", |
| 3627 | uid); |
| 3628 | getUidStatsLocked(uid).noteMobileRadioApWakeupLocked(); |
| 3629 | } |
| 3630 | |
Ruchi Kandoi | fa97fcf | 2016-05-13 15:10:39 -0700 | [diff] [blame] | 3631 | public void noteMobileRadioPowerState(int powerState, long timestampNs, int uid) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3632 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3633 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 3634 | if (mMobileRadioPowerState != powerState) { |
| 3635 | long realElapsedRealtimeMs; |
| 3636 | final boolean active = |
| 3637 | powerState == DataConnectionRealTimeInfo.DC_POWER_STATE_MEDIUM |
| 3638 | || powerState == DataConnectionRealTimeInfo.DC_POWER_STATE_HIGH; |
| 3639 | if (active) { |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 3640 | if (uid > 0) { |
| 3641 | noteMobileRadioApWakeupLocked(elapsedRealtime, uptime, uid); |
| 3642 | } |
| 3643 | |
Adam Lesinski | 9acfd81 | 2016-04-19 18:29:50 -0700 | [diff] [blame] | 3644 | mMobileRadioActiveStartTime = realElapsedRealtimeMs = timestampNs / (1000 * 1000); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 3645 | mHistoryCur.states |= HistoryItem.STATE_MOBILE_RADIO_ACTIVE_FLAG; |
| 3646 | } else { |
| 3647 | realElapsedRealtimeMs = timestampNs / (1000*1000); |
Dianne Hackborn | f7097a5 | 2014-05-13 09:56:14 -0700 | [diff] [blame] | 3648 | long lastUpdateTimeMs = mMobileRadioActiveStartTime; |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 3649 | if (realElapsedRealtimeMs < lastUpdateTimeMs) { |
| 3650 | Slog.wtf(TAG, "Data connection inactive timestamp " + realElapsedRealtimeMs |
| 3651 | + " is before start time " + lastUpdateTimeMs); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3652 | realElapsedRealtimeMs = elapsedRealtime; |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 3653 | } else if (realElapsedRealtimeMs < elapsedRealtime) { |
| 3654 | mMobileRadioActiveAdjustedTime.addCountLocked(elapsedRealtime |
| 3655 | - realElapsedRealtimeMs); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3656 | } |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 3657 | mHistoryCur.states &= ~HistoryItem.STATE_MOBILE_RADIO_ACTIVE_FLAG; |
| 3658 | } |
| 3659 | if (DEBUG_HISTORY) Slog.v(TAG, "Mobile network active " + active + " to: " |
| 3660 | + Integer.toHexString(mHistoryCur.states)); |
| 3661 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 3662 | mMobileRadioPowerState = powerState; |
| 3663 | if (active) { |
| 3664 | mMobileRadioActiveTimer.startRunningLocked(elapsedRealtime); |
| 3665 | mMobileRadioActivePerAppTimer.startRunningLocked(elapsedRealtime); |
| 3666 | } else { |
| 3667 | mMobileRadioActiveTimer.stopRunningLocked(realElapsedRealtimeMs); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3668 | updateMobileRadioStateLocked(realElapsedRealtimeMs, null); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 3669 | mMobileRadioActivePerAppTimer.stopRunningLocked(realElapsedRealtimeMs); |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 3670 | } |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 3671 | } |
| 3672 | } |
| 3673 | |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3674 | public void notePowerSaveMode(boolean enabled) { |
| 3675 | if (mPowerSaveModeEnabled != enabled) { |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 3676 | int stepState = enabled ? STEP_LEVEL_MODE_POWER_SAVE : 0; |
| 3677 | mModStepMode |= (mCurStepMode&STEP_LEVEL_MODE_POWER_SAVE) ^ stepState; |
| 3678 | mCurStepMode = (mCurStepMode&~STEP_LEVEL_MODE_POWER_SAVE) | stepState; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3679 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3680 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3681 | mPowerSaveModeEnabled = enabled; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3682 | if (enabled) { |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3683 | mHistoryCur.states2 |= HistoryItem.STATE2_POWER_SAVE_FLAG; |
| 3684 | if (DEBUG_HISTORY) Slog.v(TAG, "Power save mode enabled to: " |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3685 | + Integer.toHexString(mHistoryCur.states2)); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3686 | mPowerSaveModeEnabledTimer.startRunningLocked(elapsedRealtime); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3687 | } else { |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3688 | mHistoryCur.states2 &= ~HistoryItem.STATE2_POWER_SAVE_FLAG; |
| 3689 | if (DEBUG_HISTORY) Slog.v(TAG, "Power save mode disabled to: " |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3690 | + Integer.toHexString(mHistoryCur.states2)); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3691 | mPowerSaveModeEnabledTimer.stopRunningLocked(elapsedRealtime); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3692 | } |
| 3693 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 3694 | } |
| 3695 | } |
| 3696 | |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3697 | public void noteDeviceIdleModeLocked(int mode, String activeReason, int activeUid) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3698 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3699 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 3700 | boolean nowIdling = mode == DEVICE_IDLE_MODE_DEEP; |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3701 | if (mDeviceIdling && !nowIdling && activeReason == null) { |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 3702 | // We don't go out of general idling mode until explicitly taken out of |
| 3703 | // device idle through going active or significant motion. |
| 3704 | nowIdling = true; |
| 3705 | } |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3706 | boolean nowLightIdling = mode == DEVICE_IDLE_MODE_LIGHT; |
| 3707 | if (mDeviceLightIdling && !nowLightIdling && !nowIdling && activeReason == null) { |
| 3708 | // We don't go out of general light idling mode until explicitly taken out of |
| 3709 | // device idle through going active or significant motion. |
| 3710 | nowLightIdling = true; |
| 3711 | } |
| 3712 | if (activeReason != null && (mDeviceIdling || mDeviceLightIdling)) { |
| 3713 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_ACTIVE, |
| 3714 | activeReason, activeUid); |
| 3715 | } |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 3716 | if (mDeviceIdling != nowIdling) { |
| 3717 | mDeviceIdling = nowIdling; |
| 3718 | int stepState = nowIdling ? STEP_LEVEL_MODE_DEVICE_IDLE : 0; |
| 3719 | mModStepMode |= (mCurStepMode&STEP_LEVEL_MODE_DEVICE_IDLE) ^ stepState; |
| 3720 | mCurStepMode = (mCurStepMode&~STEP_LEVEL_MODE_DEVICE_IDLE) | stepState; |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3721 | if (nowIdling) { |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 3722 | mDeviceIdlingTimer.startRunningLocked(elapsedRealtime); |
| 3723 | } else { |
| 3724 | mDeviceIdlingTimer.stopRunningLocked(elapsedRealtime); |
| 3725 | } |
| 3726 | } |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3727 | if (mDeviceLightIdling != nowLightIdling) { |
| 3728 | mDeviceLightIdling = nowLightIdling; |
| 3729 | if (nowLightIdling) { |
| 3730 | mDeviceLightIdlingTimer.startRunningLocked(elapsedRealtime); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3731 | } else { |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3732 | mDeviceLightIdlingTimer.stopRunningLocked(elapsedRealtime); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3733 | } |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3734 | } |
| 3735 | if (mDeviceIdleMode != mode) { |
| 3736 | mHistoryCur.states2 = (mHistoryCur.states2 & ~HistoryItem.STATE2_DEVICE_IDLE_MASK) |
| 3737 | | (mode << HistoryItem.STATE2_DEVICE_IDLE_SHIFT); |
| 3738 | if (DEBUG_HISTORY) Slog.v(TAG, "Device idle mode changed to: " |
| 3739 | + Integer.toHexString(mHistoryCur.states2)); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3740 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3741 | long lastDuration = elapsedRealtime - mLastIdleTimeStart; |
| 3742 | mLastIdleTimeStart = elapsedRealtime; |
| 3743 | if (mDeviceIdleMode == DEVICE_IDLE_MODE_LIGHT) { |
| 3744 | if (lastDuration > mLongestLightIdleTime) { |
| 3745 | mLongestLightIdleTime = lastDuration; |
| 3746 | } |
| 3747 | mDeviceIdleModeLightTimer.stopRunningLocked(elapsedRealtime); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 3748 | } else if (mDeviceIdleMode == DEVICE_IDLE_MODE_DEEP) { |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3749 | if (lastDuration > mLongestFullIdleTime) { |
| 3750 | mLongestFullIdleTime = lastDuration; |
| 3751 | } |
| 3752 | mDeviceIdleModeFullTimer.stopRunningLocked(elapsedRealtime); |
| 3753 | } |
| 3754 | if (mode == DEVICE_IDLE_MODE_LIGHT) { |
| 3755 | mDeviceIdleModeLightTimer.startRunningLocked(elapsedRealtime); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 3756 | } else if (mode == DEVICE_IDLE_MODE_DEEP) { |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3757 | mDeviceIdleModeFullTimer.startRunningLocked(elapsedRealtime); |
| 3758 | } |
| 3759 | mDeviceIdleMode = mode; |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3760 | } |
| 3761 | } |
| 3762 | |
| 3763 | public void notePackageInstalledLocked(String pkgName, int versionCode) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3764 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3765 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3766 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_PACKAGE_INSTALLED, |
| 3767 | pkgName, versionCode); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 3768 | PackageChange pc = new PackageChange(); |
| 3769 | pc.mPackageName = pkgName; |
| 3770 | pc.mUpdate = true; |
| 3771 | pc.mVersionCode = versionCode; |
| 3772 | addPackageChange(pc); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3773 | } |
| 3774 | |
| 3775 | public void notePackageUninstalledLocked(String pkgName) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3776 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3777 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3778 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_PACKAGE_UNINSTALLED, |
| 3779 | pkgName, 0); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 3780 | PackageChange pc = new PackageChange(); |
| 3781 | pc.mPackageName = pkgName; |
| 3782 | pc.mUpdate = true; |
| 3783 | addPackageChange(pc); |
| 3784 | } |
| 3785 | |
| 3786 | private void addPackageChange(PackageChange pc) { |
| 3787 | if (mDailyPackageChanges == null) { |
| 3788 | mDailyPackageChanges = new ArrayList<>(); |
| 3789 | } |
| 3790 | mDailyPackageChanges.add(pc); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3791 | } |
| 3792 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3793 | public void notePhoneOnLocked() { |
| 3794 | if (!mPhoneOn) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3795 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3796 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 3797 | mHistoryCur.states2 |= HistoryItem.STATE2_PHONE_IN_CALL_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3798 | if (DEBUG_HISTORY) Slog.v(TAG, "Phone on to: " |
| 3799 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3800 | addHistoryRecordLocked(elapsedRealtime, uptime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3801 | mPhoneOn = true; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3802 | mPhoneOnTimer.startRunningLocked(elapsedRealtime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3803 | } |
| 3804 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3805 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3806 | public void notePhoneOffLocked() { |
| 3807 | if (mPhoneOn) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3808 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3809 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 3810 | mHistoryCur.states2 &= ~HistoryItem.STATE2_PHONE_IN_CALL_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3811 | if (DEBUG_HISTORY) Slog.v(TAG, "Phone off to: " |
| 3812 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3813 | addHistoryRecordLocked(elapsedRealtime, uptime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3814 | mPhoneOn = false; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3815 | mPhoneOnTimer.stopRunningLocked(elapsedRealtime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3816 | } |
| 3817 | } |
Amith Yamasani | 32dbefd | 2009-06-19 09:21:17 -0700 | [diff] [blame] | 3818 | |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 3819 | void stopAllPhoneSignalStrengthTimersLocked(int except) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3820 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 3821 | for (int i = 0; i < SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 3822 | if (i == except) { |
| 3823 | continue; |
| 3824 | } |
| 3825 | while (mPhoneSignalStrengthsTimer[i].isRunningLocked()) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3826 | mPhoneSignalStrengthsTimer[i].stopRunningLocked(elapsedRealtime); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 3827 | } |
| 3828 | } |
| 3829 | } |
| 3830 | |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3831 | private int fixPhoneServiceState(int state, int signalBin) { |
| 3832 | if (mPhoneSimStateRaw == TelephonyManager.SIM_STATE_ABSENT) { |
| 3833 | // In this case we will always be STATE_OUT_OF_SERVICE, so need |
| 3834 | // to infer that we are scanning from other data. |
| 3835 | if (state == ServiceState.STATE_OUT_OF_SERVICE |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 3836 | && signalBin > SignalStrength.SIGNAL_STRENGTH_NONE_OR_UNKNOWN) { |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3837 | state = ServiceState.STATE_IN_SERVICE; |
| 3838 | } |
| 3839 | } |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 3840 | |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3841 | return state; |
| 3842 | } |
| 3843 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3844 | private void updateAllPhoneStateLocked(int state, int simState, int strengthBin) { |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3845 | boolean scanning = false; |
| 3846 | boolean newHistory = false; |
| 3847 | |
| 3848 | mPhoneServiceStateRaw = state; |
| 3849 | mPhoneSimStateRaw = simState; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3850 | mPhoneSignalStrengthBinRaw = strengthBin; |
| 3851 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3852 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3853 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3854 | |
| 3855 | if (simState == TelephonyManager.SIM_STATE_ABSENT) { |
| 3856 | // In this case we will always be STATE_OUT_OF_SERVICE, so need |
| 3857 | // to infer that we are scanning from other data. |
| 3858 | if (state == ServiceState.STATE_OUT_OF_SERVICE |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3859 | && strengthBin > SignalStrength.SIGNAL_STRENGTH_NONE_OR_UNKNOWN) { |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3860 | state = ServiceState.STATE_IN_SERVICE; |
| 3861 | } |
| 3862 | } |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 3863 | |
| 3864 | // If the phone is powered off, stop all timers. |
| 3865 | if (state == ServiceState.STATE_POWER_OFF) { |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3866 | strengthBin = -1; |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 3867 | |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3868 | // If we are in service, make sure the correct signal string timer is running. |
| 3869 | } else if (state == ServiceState.STATE_IN_SERVICE) { |
| 3870 | // Bin will be changed below. |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 3871 | |
| 3872 | // If we're out of service, we are in the lowest signal strength |
| 3873 | // bin and have the scanning bit set. |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 3874 | } else if (state == ServiceState.STATE_OUT_OF_SERVICE) { |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 3875 | scanning = true; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3876 | strengthBin = SignalStrength.SIGNAL_STRENGTH_NONE_OR_UNKNOWN; |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 3877 | if (!mPhoneSignalScanningTimer.isRunningLocked()) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3878 | mHistoryCur.states |= HistoryItem.STATE_PHONE_SCANNING_FLAG; |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3879 | newHistory = true; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3880 | if (DEBUG_HISTORY) Slog.v(TAG, "Phone started scanning to: " |
| 3881 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3882 | mPhoneSignalScanningTimer.startRunningLocked(elapsedRealtime); |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 3883 | } |
| 3884 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3885 | |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 3886 | if (!scanning) { |
| 3887 | // If we are no longer scanning, then stop the scanning timer. |
| 3888 | if (mPhoneSignalScanningTimer.isRunningLocked()) { |
| 3889 | mHistoryCur.states &= ~HistoryItem.STATE_PHONE_SCANNING_FLAG; |
| 3890 | if (DEBUG_HISTORY) Slog.v(TAG, "Phone stopped scanning to: " |
| 3891 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3892 | newHistory = true; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3893 | mPhoneSignalScanningTimer.stopRunningLocked(elapsedRealtime); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 3894 | } |
| 3895 | } |
| 3896 | |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3897 | if (mPhoneServiceState != state) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3898 | mHistoryCur.states = (mHistoryCur.states&~HistoryItem.STATE_PHONE_STATE_MASK) |
| 3899 | | (state << HistoryItem.STATE_PHONE_STATE_SHIFT); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3900 | if (DEBUG_HISTORY) Slog.v(TAG, "Phone state " + state + " to: " |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3901 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3902 | newHistory = true; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3903 | mPhoneServiceState = state; |
| 3904 | } |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3905 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3906 | if (mPhoneSignalStrengthBin != strengthBin) { |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3907 | if (mPhoneSignalStrengthBin >= 0) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3908 | mPhoneSignalStrengthsTimer[mPhoneSignalStrengthBin].stopRunningLocked( |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3909 | elapsedRealtime); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3910 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3911 | if (strengthBin >= 0) { |
| 3912 | if (!mPhoneSignalStrengthsTimer[strengthBin].isRunningLocked()) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3913 | mPhoneSignalStrengthsTimer[strengthBin].startRunningLocked(elapsedRealtime); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3914 | } |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 3915 | mHistoryCur.states = (mHistoryCur.states&~HistoryItem.STATE_PHONE_SIGNAL_STRENGTH_MASK) |
| 3916 | | (strengthBin << HistoryItem.STATE_PHONE_SIGNAL_STRENGTH_SHIFT); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3917 | if (DEBUG_HISTORY) Slog.v(TAG, "Signal strength " + strengthBin + " to: " |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3918 | + Integer.toHexString(mHistoryCur.states)); |
| 3919 | newHistory = true; |
| 3920 | } else { |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 3921 | stopAllPhoneSignalStrengthTimersLocked(-1); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3922 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3923 | mPhoneSignalStrengthBin = strengthBin; |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3924 | } |
| 3925 | |
| 3926 | if (newHistory) { |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3927 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3928 | } |
| 3929 | } |
| 3930 | |
| 3931 | /** |
| 3932 | * Telephony stack updates the phone state. |
| 3933 | * @param state phone state from ServiceState.getState() |
| 3934 | */ |
| 3935 | public void notePhoneStateLocked(int state, int simState) { |
| 3936 | updateAllPhoneStateLocked(state, simState, mPhoneSignalStrengthBinRaw); |
Amith Yamasani | 32dbefd | 2009-06-19 09:21:17 -0700 | [diff] [blame] | 3937 | } |
| 3938 | |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 3939 | public void notePhoneSignalStrengthLocked(SignalStrength signalStrength) { |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3940 | // Bin the strength. |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 3941 | int bin = signalStrength.getLevel(); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3942 | updateAllPhoneStateLocked(mPhoneServiceStateRaw, mPhoneSimStateRaw, bin); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3943 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3944 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3945 | public void notePhoneDataConnectionStateLocked(int dataType, boolean hasData) { |
| 3946 | int bin = DATA_CONNECTION_NONE; |
| 3947 | if (hasData) { |
| 3948 | switch (dataType) { |
| 3949 | case TelephonyManager.NETWORK_TYPE_EDGE: |
| 3950 | bin = DATA_CONNECTION_EDGE; |
| 3951 | break; |
| 3952 | case TelephonyManager.NETWORK_TYPE_GPRS: |
| 3953 | bin = DATA_CONNECTION_GPRS; |
| 3954 | break; |
| 3955 | case TelephonyManager.NETWORK_TYPE_UMTS: |
| 3956 | bin = DATA_CONNECTION_UMTS; |
| 3957 | break; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3958 | case TelephonyManager.NETWORK_TYPE_CDMA: |
| 3959 | bin = DATA_CONNECTION_CDMA; |
| 3960 | break; |
| 3961 | case TelephonyManager.NETWORK_TYPE_EVDO_0: |
| 3962 | bin = DATA_CONNECTION_EVDO_0; |
| 3963 | break; |
| 3964 | case TelephonyManager.NETWORK_TYPE_EVDO_A: |
| 3965 | bin = DATA_CONNECTION_EVDO_A; |
| 3966 | break; |
| 3967 | case TelephonyManager.NETWORK_TYPE_1xRTT: |
| 3968 | bin = DATA_CONNECTION_1xRTT; |
| 3969 | break; |
| 3970 | case TelephonyManager.NETWORK_TYPE_HSDPA: |
| 3971 | bin = DATA_CONNECTION_HSDPA; |
| 3972 | break; |
| 3973 | case TelephonyManager.NETWORK_TYPE_HSUPA: |
| 3974 | bin = DATA_CONNECTION_HSUPA; |
| 3975 | break; |
| 3976 | case TelephonyManager.NETWORK_TYPE_HSPA: |
| 3977 | bin = DATA_CONNECTION_HSPA; |
| 3978 | break; |
| 3979 | case TelephonyManager.NETWORK_TYPE_IDEN: |
| 3980 | bin = DATA_CONNECTION_IDEN; |
| 3981 | break; |
| 3982 | case TelephonyManager.NETWORK_TYPE_EVDO_B: |
| 3983 | bin = DATA_CONNECTION_EVDO_B; |
| 3984 | break; |
Robert Greenwalt | 962a990 | 2010-11-02 11:10:25 -0700 | [diff] [blame] | 3985 | case TelephonyManager.NETWORK_TYPE_LTE: |
| 3986 | bin = DATA_CONNECTION_LTE; |
| 3987 | break; |
| 3988 | case TelephonyManager.NETWORK_TYPE_EHRPD: |
| 3989 | bin = DATA_CONNECTION_EHRPD; |
| 3990 | break; |
Patrick Tjin | b71703c | 2013-11-06 09:27:03 -0800 | [diff] [blame] | 3991 | case TelephonyManager.NETWORK_TYPE_HSPAP: |
| 3992 | bin = DATA_CONNECTION_HSPAP; |
| 3993 | break; |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3994 | default: |
| 3995 | bin = DATA_CONNECTION_OTHER; |
| 3996 | break; |
| 3997 | } |
| 3998 | } |
Amith Yamasani | 3718aaa | 2009-06-09 06:32:35 -0700 | [diff] [blame] | 3999 | if (DEBUG) Log.i(TAG, "Phone Data Connection -> " + dataType + " = " + hasData); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4000 | if (mPhoneDataConnectionType != bin) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4001 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4002 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4003 | mHistoryCur.states = (mHistoryCur.states&~HistoryItem.STATE_DATA_CONNECTION_MASK) |
| 4004 | | (bin << HistoryItem.STATE_DATA_CONNECTION_SHIFT); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4005 | if (DEBUG_HISTORY) Slog.v(TAG, "Data connection " + bin + " to: " |
| 4006 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 4007 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4008 | if (mPhoneDataConnectionType >= 0) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4009 | mPhoneDataConnectionsTimer[mPhoneDataConnectionType].stopRunningLocked( |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4010 | elapsedRealtime); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4011 | } |
| 4012 | mPhoneDataConnectionType = bin; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4013 | mPhoneDataConnectionsTimer[bin].startRunningLocked(elapsedRealtime); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4014 | } |
| 4015 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4016 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 4017 | public void noteWifiOnLocked() { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4018 | if (!mWifiOn) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4019 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4020 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 4021 | mHistoryCur.states2 |= HistoryItem.STATE2_WIFI_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4022 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI on to: " |
| 4023 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 4024 | addHistoryRecordLocked(elapsedRealtime, uptime); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4025 | mWifiOn = true; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4026 | mWifiOnTimer.startRunningLocked(elapsedRealtime); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 4027 | scheduleSyncExternalStatsLocked("wifi-off", ExternalStatsSync.UPDATE_WIFI); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4028 | } |
| 4029 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4030 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 4031 | public void noteWifiOffLocked() { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4032 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4033 | final long uptime = mClocks.uptimeMillis(); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4034 | if (mWifiOn) { |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 4035 | mHistoryCur.states2 &= ~HistoryItem.STATE2_WIFI_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4036 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI off to: " |
| 4037 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 4038 | addHistoryRecordLocked(elapsedRealtime, uptime); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4039 | mWifiOn = false; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4040 | mWifiOnTimer.stopRunningLocked(elapsedRealtime); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 4041 | scheduleSyncExternalStatsLocked("wifi-on", ExternalStatsSync.UPDATE_WIFI); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4042 | } |
| 4043 | } |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 4044 | |
| 4045 | public void noteAudioOnLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4046 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4047 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4048 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 4049 | if (mAudioOnNesting == 0) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4050 | mHistoryCur.states |= HistoryItem.STATE_AUDIO_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4051 | if (DEBUG_HISTORY) Slog.v(TAG, "Audio on to: " |
| 4052 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 4053 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4054 | mAudioOnTimer.startRunningLocked(elapsedRealtime); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 4055 | } |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 4056 | mAudioOnNesting++; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4057 | getUidStatsLocked(uid).noteAudioTurnedOnLocked(elapsedRealtime); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 4058 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4059 | |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 4060 | public void noteAudioOffLocked(int uid) { |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 4061 | if (mAudioOnNesting == 0) { |
| 4062 | return; |
| 4063 | } |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4064 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4065 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4066 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 4067 | if (--mAudioOnNesting == 0) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4068 | mHistoryCur.states &= ~HistoryItem.STATE_AUDIO_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4069 | if (DEBUG_HISTORY) Slog.v(TAG, "Audio off to: " |
| 4070 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 4071 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4072 | mAudioOnTimer.stopRunningLocked(elapsedRealtime); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 4073 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4074 | getUidStatsLocked(uid).noteAudioTurnedOffLocked(elapsedRealtime); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 4075 | } |
| 4076 | |
| 4077 | public void noteVideoOnLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4078 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4079 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4080 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 4081 | if (mVideoOnNesting == 0) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 4082 | mHistoryCur.states2 |= HistoryItem.STATE2_VIDEO_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4083 | if (DEBUG_HISTORY) Slog.v(TAG, "Video on to: " |
| 4084 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 4085 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4086 | mVideoOnTimer.startRunningLocked(elapsedRealtime); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 4087 | } |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 4088 | mVideoOnNesting++; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4089 | getUidStatsLocked(uid).noteVideoTurnedOnLocked(elapsedRealtime); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 4090 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4091 | |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 4092 | public void noteVideoOffLocked(int uid) { |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 4093 | if (mVideoOnNesting == 0) { |
| 4094 | return; |
| 4095 | } |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4096 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4097 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4098 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 4099 | if (--mVideoOnNesting == 0) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 4100 | mHistoryCur.states2 &= ~HistoryItem.STATE2_VIDEO_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4101 | if (DEBUG_HISTORY) Slog.v(TAG, "Video off to: " |
| 4102 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 4103 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4104 | mVideoOnTimer.stopRunningLocked(elapsedRealtime); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 4105 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4106 | getUidStatsLocked(uid).noteVideoTurnedOffLocked(elapsedRealtime); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 4107 | } |
| 4108 | |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 4109 | public void noteResetAudioLocked() { |
| 4110 | if (mAudioOnNesting > 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4111 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4112 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 4113 | mAudioOnNesting = 0; |
| 4114 | mHistoryCur.states &= ~HistoryItem.STATE_AUDIO_ON_FLAG; |
| 4115 | if (DEBUG_HISTORY) Slog.v(TAG, "Audio off to: " |
| 4116 | + Integer.toHexString(mHistoryCur.states)); |
| 4117 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 4118 | mAudioOnTimer.stopAllRunningLocked(elapsedRealtime); |
| 4119 | for (int i=0; i<mUidStats.size(); i++) { |
| 4120 | BatteryStatsImpl.Uid uid = mUidStats.valueAt(i); |
| 4121 | uid.noteResetAudioLocked(elapsedRealtime); |
| 4122 | } |
| 4123 | } |
| 4124 | } |
| 4125 | |
| 4126 | public void noteResetVideoLocked() { |
| 4127 | if (mVideoOnNesting > 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4128 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4129 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 4130 | mAudioOnNesting = 0; |
| 4131 | mHistoryCur.states2 &= ~HistoryItem.STATE2_VIDEO_ON_FLAG; |
| 4132 | if (DEBUG_HISTORY) Slog.v(TAG, "Video off to: " |
| 4133 | + Integer.toHexString(mHistoryCur.states)); |
| 4134 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 4135 | mVideoOnTimer.stopAllRunningLocked(elapsedRealtime); |
| 4136 | for (int i=0; i<mUidStats.size(); i++) { |
| 4137 | BatteryStatsImpl.Uid uid = mUidStats.valueAt(i); |
| 4138 | uid.noteResetVideoLocked(elapsedRealtime); |
| 4139 | } |
| 4140 | } |
| 4141 | } |
| 4142 | |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 4143 | public void noteActivityResumedLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4144 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4145 | getUidStatsLocked(uid).noteActivityResumedLocked(mClocks.elapsedRealtime()); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 4146 | } |
| 4147 | |
| 4148 | public void noteActivityPausedLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4149 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4150 | getUidStatsLocked(uid).noteActivityPausedLocked(mClocks.elapsedRealtime()); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 4151 | } |
| 4152 | |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 4153 | public void noteVibratorOnLocked(int uid, long durationMillis) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4154 | uid = mapUid(uid); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 4155 | getUidStatsLocked(uid).noteVibratorOnLocked(durationMillis); |
| 4156 | } |
| 4157 | |
| 4158 | public void noteVibratorOffLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4159 | uid = mapUid(uid); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 4160 | getUidStatsLocked(uid).noteVibratorOffLocked(); |
| 4161 | } |
| 4162 | |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 4163 | public void noteFlashlightOnLocked(int uid) { |
| 4164 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4165 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4166 | final long uptime = mClocks.uptimeMillis(); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 4167 | if (mFlashlightOnNesting++ == 0) { |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 4168 | mHistoryCur.states2 |= HistoryItem.STATE2_FLASHLIGHT_FLAG; |
| 4169 | if (DEBUG_HISTORY) Slog.v(TAG, "Flashlight on to: " |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 4170 | + Integer.toHexString(mHistoryCur.states2)); |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 4171 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 4172 | mFlashlightOnTimer.startRunningLocked(elapsedRealtime); |
| 4173 | } |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 4174 | getUidStatsLocked(uid).noteFlashlightTurnedOnLocked(elapsedRealtime); |
| 4175 | } |
| 4176 | |
| 4177 | public void noteFlashlightOffLocked(int uid) { |
| 4178 | if (mFlashlightOnNesting == 0) { |
| 4179 | return; |
| 4180 | } |
| 4181 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4182 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4183 | final long uptime = mClocks.uptimeMillis(); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 4184 | if (--mFlashlightOnNesting == 0) { |
| 4185 | mHistoryCur.states2 &= ~HistoryItem.STATE2_FLASHLIGHT_FLAG; |
| 4186 | if (DEBUG_HISTORY) Slog.v(TAG, "Flashlight off to: " |
| 4187 | + Integer.toHexString(mHistoryCur.states2)); |
| 4188 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 4189 | mFlashlightOnTimer.stopRunningLocked(elapsedRealtime); |
| 4190 | } |
| 4191 | getUidStatsLocked(uid).noteFlashlightTurnedOffLocked(elapsedRealtime); |
| 4192 | } |
| 4193 | |
| 4194 | public void noteCameraOnLocked(int uid) { |
| 4195 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4196 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4197 | final long uptime = mClocks.uptimeMillis(); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 4198 | if (mCameraOnNesting++ == 0) { |
| 4199 | mHistoryCur.states2 |= HistoryItem.STATE2_CAMERA_FLAG; |
| 4200 | if (DEBUG_HISTORY) Slog.v(TAG, "Camera on to: " |
| 4201 | + Integer.toHexString(mHistoryCur.states2)); |
| 4202 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 4203 | mCameraOnTimer.startRunningLocked(elapsedRealtime); |
| 4204 | } |
| 4205 | getUidStatsLocked(uid).noteCameraTurnedOnLocked(elapsedRealtime); |
| 4206 | } |
| 4207 | |
| 4208 | public void noteCameraOffLocked(int uid) { |
| 4209 | if (mCameraOnNesting == 0) { |
| 4210 | return; |
| 4211 | } |
| 4212 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4213 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4214 | final long uptime = mClocks.uptimeMillis(); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 4215 | if (--mCameraOnNesting == 0) { |
| 4216 | mHistoryCur.states2 &= ~HistoryItem.STATE2_CAMERA_FLAG; |
| 4217 | if (DEBUG_HISTORY) Slog.v(TAG, "Camera off to: " |
| 4218 | + Integer.toHexString(mHistoryCur.states2)); |
| 4219 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 4220 | mCameraOnTimer.stopRunningLocked(elapsedRealtime); |
| 4221 | } |
| 4222 | getUidStatsLocked(uid).noteCameraTurnedOffLocked(elapsedRealtime); |
| 4223 | } |
| 4224 | |
| 4225 | public void noteResetCameraLocked() { |
| 4226 | if (mCameraOnNesting > 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4227 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4228 | final long uptime = mClocks.uptimeMillis(); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 4229 | mCameraOnNesting = 0; |
| 4230 | mHistoryCur.states2 &= ~HistoryItem.STATE2_CAMERA_FLAG; |
| 4231 | if (DEBUG_HISTORY) Slog.v(TAG, "Camera off to: " |
| 4232 | + Integer.toHexString(mHistoryCur.states2)); |
| 4233 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 4234 | mCameraOnTimer.stopAllRunningLocked(elapsedRealtime); |
| 4235 | for (int i=0; i<mUidStats.size(); i++) { |
| 4236 | BatteryStatsImpl.Uid uid = mUidStats.valueAt(i); |
| 4237 | uid.noteResetCameraLocked(elapsedRealtime); |
| 4238 | } |
| 4239 | } |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 4240 | } |
| 4241 | |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 4242 | public void noteResetFlashlightLocked() { |
| 4243 | if (mFlashlightOnNesting > 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4244 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4245 | final long uptime = mClocks.uptimeMillis(); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 4246 | mFlashlightOnNesting = 0; |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 4247 | mHistoryCur.states2 &= ~HistoryItem.STATE2_FLASHLIGHT_FLAG; |
| 4248 | if (DEBUG_HISTORY) Slog.v(TAG, "Flashlight off to: " |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 4249 | + Integer.toHexString(mHistoryCur.states2)); |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 4250 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 4251 | mFlashlightOnTimer.stopAllRunningLocked(elapsedRealtime); |
| 4252 | for (int i=0; i<mUidStats.size(); i++) { |
| 4253 | BatteryStatsImpl.Uid uid = mUidStats.valueAt(i); |
| 4254 | uid.noteResetFlashlightLocked(elapsedRealtime); |
| 4255 | } |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 4256 | } |
| 4257 | } |
| 4258 | |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 4259 | private void noteBluetoothScanStartedLocked(int uid) { |
| 4260 | uid = mapUid(uid); |
| 4261 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 4262 | final long uptime = SystemClock.uptimeMillis(); |
| 4263 | if (mBluetoothScanNesting == 0) { |
| 4264 | mHistoryCur.states2 |= HistoryItem.STATE2_BLUETOOTH_SCAN_FLAG; |
| 4265 | if (DEBUG_HISTORY) Slog.v(TAG, "BLE scan started for: " |
| 4266 | + Integer.toHexString(mHistoryCur.states2)); |
| 4267 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Adam Lesinski | d9b99be | 2016-03-30 16:58:51 -0700 | [diff] [blame] | 4268 | mBluetoothScanTimer.startRunningLocked(elapsedRealtime); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 4269 | } |
| 4270 | mBluetoothScanNesting++; |
| 4271 | getUidStatsLocked(uid).noteBluetoothScanStartedLocked(elapsedRealtime); |
| 4272 | } |
| 4273 | |
| 4274 | public void noteBluetoothScanStartedFromSourceLocked(WorkSource ws) { |
| 4275 | final int N = ws.size(); |
| 4276 | for (int i = 0; i < N; i++) { |
| 4277 | noteBluetoothScanStartedLocked(ws.get(i)); |
| 4278 | } |
| 4279 | } |
| 4280 | |
| 4281 | private void noteBluetoothScanStoppedLocked(int uid) { |
| 4282 | uid = mapUid(uid); |
| 4283 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 4284 | final long uptime = SystemClock.uptimeMillis(); |
| 4285 | mBluetoothScanNesting--; |
| 4286 | if (mBluetoothScanNesting == 0) { |
| 4287 | mHistoryCur.states2 &= ~HistoryItem.STATE2_BLUETOOTH_SCAN_FLAG; |
| 4288 | if (DEBUG_HISTORY) Slog.v(TAG, "BLE scan stopped for: " |
| 4289 | + Integer.toHexString(mHistoryCur.states2)); |
| 4290 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Adam Lesinski | d9b99be | 2016-03-30 16:58:51 -0700 | [diff] [blame] | 4291 | mBluetoothScanTimer.stopRunningLocked(elapsedRealtime); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 4292 | } |
| 4293 | getUidStatsLocked(uid).noteBluetoothScanStoppedLocked(elapsedRealtime); |
| 4294 | } |
| 4295 | |
| 4296 | public void noteBluetoothScanStoppedFromSourceLocked(WorkSource ws) { |
| 4297 | final int N = ws.size(); |
| 4298 | for (int i = 0; i < N; i++) { |
| 4299 | noteBluetoothScanStoppedLocked(ws.get(i)); |
| 4300 | } |
| 4301 | } |
| 4302 | |
| 4303 | public void noteResetBluetoothScanLocked() { |
| 4304 | if (mBluetoothScanNesting > 0) { |
| 4305 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 4306 | final long uptime = SystemClock.uptimeMillis(); |
| 4307 | mBluetoothScanNesting = 0; |
| 4308 | mHistoryCur.states2 &= ~HistoryItem.STATE2_BLUETOOTH_SCAN_FLAG; |
| 4309 | if (DEBUG_HISTORY) Slog.v(TAG, "BLE can stopped for: " |
| 4310 | + Integer.toHexString(mHistoryCur.states2)); |
| 4311 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 4312 | mBluetoothScanTimer.stopAllRunningLocked(elapsedRealtime); |
| 4313 | for (int i=0; i<mUidStats.size(); i++) { |
| 4314 | BatteryStatsImpl.Uid uid = mUidStats.valueAt(i); |
| 4315 | uid.noteResetBluetoothScanLocked(elapsedRealtime); |
| 4316 | } |
| 4317 | } |
| 4318 | } |
| 4319 | |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 4320 | private void noteWifiRadioApWakeupLocked(final long elapsedRealtimeMillis, |
| 4321 | final long uptimeMillis, int uid) { |
| 4322 | uid = mapUid(uid); |
| 4323 | addHistoryEventLocked(elapsedRealtimeMillis, uptimeMillis, HistoryItem.EVENT_WAKEUP_AP, "", |
| 4324 | uid); |
| 4325 | getUidStatsLocked(uid).noteWifiRadioApWakeupLocked(); |
| 4326 | } |
| 4327 | |
| 4328 | public void noteWifiRadioPowerState(int powerState, long timestampNs, int uid) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4329 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4330 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 4331 | if (mWifiRadioPowerState != powerState) { |
| 4332 | final boolean active = |
| 4333 | powerState == DataConnectionRealTimeInfo.DC_POWER_STATE_MEDIUM |
| 4334 | || powerState == DataConnectionRealTimeInfo.DC_POWER_STATE_HIGH; |
| 4335 | if (active) { |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 4336 | if (uid > 0) { |
| 4337 | noteWifiRadioApWakeupLocked(elapsedRealtime, uptime, uid); |
| 4338 | } |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 4339 | mHistoryCur.states |= HistoryItem.STATE_WIFI_RADIO_ACTIVE_FLAG; |
| 4340 | } else { |
| 4341 | mHistoryCur.states &= ~HistoryItem.STATE_WIFI_RADIO_ACTIVE_FLAG; |
| 4342 | } |
| 4343 | if (DEBUG_HISTORY) Slog.v(TAG, "Wifi network active " + active + " to: " |
| 4344 | + Integer.toHexString(mHistoryCur.states)); |
| 4345 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 4346 | mWifiRadioPowerState = powerState; |
| 4347 | } |
| 4348 | } |
| 4349 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 4350 | public void noteWifiRunningLocked(WorkSource ws) { |
| 4351 | if (!mGlobalWifiRunning) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4352 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4353 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 4354 | mHistoryCur.states2 |= HistoryItem.STATE2_WIFI_RUNNING_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4355 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI running to: " |
| 4356 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 4357 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 4358 | mGlobalWifiRunning = true; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4359 | mGlobalWifiRunningTimer.startRunningLocked(elapsedRealtime); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 4360 | int N = ws.size(); |
| 4361 | for (int i=0; i<N; i++) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4362 | int uid = mapUid(ws.get(i)); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4363 | getUidStatsLocked(uid).noteWifiRunningLocked(elapsedRealtime); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 4364 | } |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 4365 | scheduleSyncExternalStatsLocked("wifi-running", ExternalStatsSync.UPDATE_WIFI); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 4366 | } else { |
| 4367 | Log.w(TAG, "noteWifiRunningLocked -- called while WIFI running"); |
Eric Shienbrood | d4c5f89 | 2009-03-24 18:13:20 -0700 | [diff] [blame] | 4368 | } |
| 4369 | } |
| 4370 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 4371 | public void noteWifiRunningChangedLocked(WorkSource oldWs, WorkSource newWs) { |
| 4372 | if (mGlobalWifiRunning) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4373 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 4374 | int N = oldWs.size(); |
| 4375 | for (int i=0; i<N; i++) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4376 | int uid = mapUid(oldWs.get(i)); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4377 | getUidStatsLocked(uid).noteWifiStoppedLocked(elapsedRealtime); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 4378 | } |
| 4379 | N = newWs.size(); |
| 4380 | for (int i=0; i<N; i++) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4381 | int uid = mapUid(newWs.get(i)); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4382 | getUidStatsLocked(uid).noteWifiRunningLocked(elapsedRealtime); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 4383 | } |
| 4384 | } else { |
| 4385 | Log.w(TAG, "noteWifiRunningChangedLocked -- called while WIFI not running"); |
| 4386 | } |
| 4387 | } |
| 4388 | |
| 4389 | public void noteWifiStoppedLocked(WorkSource ws) { |
| 4390 | if (mGlobalWifiRunning) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4391 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4392 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 4393 | mHistoryCur.states2 &= ~HistoryItem.STATE2_WIFI_RUNNING_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4394 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI stopped to: " |
| 4395 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 4396 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 4397 | mGlobalWifiRunning = false; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4398 | mGlobalWifiRunningTimer.stopRunningLocked(elapsedRealtime); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 4399 | int N = ws.size(); |
| 4400 | for (int i=0; i<N; i++) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4401 | int uid = mapUid(ws.get(i)); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4402 | getUidStatsLocked(uid).noteWifiStoppedLocked(elapsedRealtime); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 4403 | } |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 4404 | scheduleSyncExternalStatsLocked("wifi-stopped", ExternalStatsSync.UPDATE_WIFI); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 4405 | } else { |
| 4406 | Log.w(TAG, "noteWifiStoppedLocked -- called while WIFI not running"); |
Eric Shienbrood | d4c5f89 | 2009-03-24 18:13:20 -0700 | [diff] [blame] | 4407 | } |
| 4408 | } |
| 4409 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4410 | public void noteWifiStateLocked(int wifiState, String accessPoint) { |
| 4411 | if (DEBUG) Log.i(TAG, "WiFi state -> " + wifiState); |
| 4412 | if (mWifiState != wifiState) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4413 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4414 | if (mWifiState >= 0) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4415 | mWifiStateTimer[mWifiState].stopRunningLocked(elapsedRealtime); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4416 | } |
| 4417 | mWifiState = wifiState; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4418 | mWifiStateTimer[wifiState].startRunningLocked(elapsedRealtime); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 4419 | scheduleSyncExternalStatsLocked("wifi-state", ExternalStatsSync.UPDATE_WIFI); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4420 | } |
| 4421 | } |
| 4422 | |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 4423 | public void noteWifiSupplicantStateChangedLocked(int supplState, boolean failedAuth) { |
| 4424 | if (DEBUG) Log.i(TAG, "WiFi suppl state -> " + supplState); |
| 4425 | if (mWifiSupplState != supplState) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4426 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4427 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 4428 | if (mWifiSupplState >= 0) { |
| 4429 | mWifiSupplStateTimer[mWifiSupplState].stopRunningLocked(elapsedRealtime); |
| 4430 | } |
| 4431 | mWifiSupplState = supplState; |
| 4432 | mWifiSupplStateTimer[supplState].startRunningLocked(elapsedRealtime); |
| 4433 | mHistoryCur.states2 = |
| 4434 | (mHistoryCur.states2&~HistoryItem.STATE2_WIFI_SUPPL_STATE_MASK) |
| 4435 | | (supplState << HistoryItem.STATE2_WIFI_SUPPL_STATE_SHIFT); |
| 4436 | if (DEBUG_HISTORY) Slog.v(TAG, "Wifi suppl state " + supplState + " to: " |
| 4437 | + Integer.toHexString(mHistoryCur.states2)); |
| 4438 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 4439 | } |
| 4440 | } |
| 4441 | |
| 4442 | void stopAllWifiSignalStrengthTimersLocked(int except) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4443 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 4444 | for (int i = 0; i < NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 4445 | if (i == except) { |
| 4446 | continue; |
| 4447 | } |
| 4448 | while (mWifiSignalStrengthsTimer[i].isRunningLocked()) { |
| 4449 | mWifiSignalStrengthsTimer[i].stopRunningLocked(elapsedRealtime); |
| 4450 | } |
| 4451 | } |
| 4452 | } |
| 4453 | |
| 4454 | public void noteWifiRssiChangedLocked(int newRssi) { |
| 4455 | int strengthBin = WifiManager.calculateSignalLevel(newRssi, NUM_WIFI_SIGNAL_STRENGTH_BINS); |
| 4456 | if (DEBUG) Log.i(TAG, "WiFi rssi -> " + newRssi + " bin=" + strengthBin); |
| 4457 | if (mWifiSignalStrengthBin != strengthBin) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4458 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4459 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 4460 | if (mWifiSignalStrengthBin >= 0) { |
| 4461 | mWifiSignalStrengthsTimer[mWifiSignalStrengthBin].stopRunningLocked( |
| 4462 | elapsedRealtime); |
| 4463 | } |
| 4464 | if (strengthBin >= 0) { |
| 4465 | if (!mWifiSignalStrengthsTimer[strengthBin].isRunningLocked()) { |
| 4466 | mWifiSignalStrengthsTimer[strengthBin].startRunningLocked(elapsedRealtime); |
| 4467 | } |
| 4468 | mHistoryCur.states2 = |
| 4469 | (mHistoryCur.states2&~HistoryItem.STATE2_WIFI_SIGNAL_STRENGTH_MASK) |
| 4470 | | (strengthBin << HistoryItem.STATE2_WIFI_SIGNAL_STRENGTH_SHIFT); |
| 4471 | if (DEBUG_HISTORY) Slog.v(TAG, "Wifi signal strength " + strengthBin + " to: " |
| 4472 | + Integer.toHexString(mHistoryCur.states2)); |
| 4473 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 4474 | } else { |
| 4475 | stopAllWifiSignalStrengthTimersLocked(-1); |
| 4476 | } |
| 4477 | mWifiSignalStrengthBin = strengthBin; |
| 4478 | } |
| 4479 | } |
| 4480 | |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4481 | int mWifiFullLockNesting = 0; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4482 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4483 | public void noteFullWifiLockAcquiredLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4484 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4485 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4486 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4487 | if (mWifiFullLockNesting == 0) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4488 | mHistoryCur.states |= HistoryItem.STATE_WIFI_FULL_LOCK_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4489 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI full lock on to: " |
| 4490 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 4491 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4492 | } |
| 4493 | mWifiFullLockNesting++; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4494 | getUidStatsLocked(uid).noteFullWifiLockAcquiredLocked(elapsedRealtime); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4495 | } |
| 4496 | |
| 4497 | public void noteFullWifiLockReleasedLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4498 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4499 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4500 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4501 | mWifiFullLockNesting--; |
| 4502 | if (mWifiFullLockNesting == 0) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4503 | mHistoryCur.states &= ~HistoryItem.STATE_WIFI_FULL_LOCK_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4504 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI full lock off to: " |
| 4505 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 4506 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4507 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4508 | getUidStatsLocked(uid).noteFullWifiLockReleasedLocked(elapsedRealtime); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4509 | } |
| 4510 | |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 4511 | int mWifiScanNesting = 0; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4512 | |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 4513 | public void noteWifiScanStartedLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4514 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4515 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4516 | final long uptime = mClocks.uptimeMillis(); |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 4517 | if (mWifiScanNesting == 0) { |
| 4518 | mHistoryCur.states |= HistoryItem.STATE_WIFI_SCAN_FLAG; |
| 4519 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI scan started for: " |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4520 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 4521 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4522 | } |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 4523 | mWifiScanNesting++; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4524 | getUidStatsLocked(uid).noteWifiScanStartedLocked(elapsedRealtime); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4525 | } |
| 4526 | |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 4527 | public void noteWifiScanStoppedLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4528 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4529 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4530 | final long uptime = mClocks.uptimeMillis(); |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 4531 | mWifiScanNesting--; |
| 4532 | if (mWifiScanNesting == 0) { |
| 4533 | mHistoryCur.states &= ~HistoryItem.STATE_WIFI_SCAN_FLAG; |
| 4534 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI scan stopped for: " |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4535 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 4536 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4537 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4538 | getUidStatsLocked(uid).noteWifiScanStoppedLocked(elapsedRealtime); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4539 | } |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 4540 | |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 4541 | public void noteWifiBatchedScanStartedLocked(int uid, int csph) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4542 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4543 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4544 | getUidStatsLocked(uid).noteWifiBatchedScanStartedLocked(csph, elapsedRealtime); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 4545 | } |
| 4546 | |
| 4547 | public void noteWifiBatchedScanStoppedLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4548 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4549 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4550 | getUidStatsLocked(uid).noteWifiBatchedScanStoppedLocked(elapsedRealtime); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 4551 | } |
| 4552 | |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4553 | int mWifiMulticastNesting = 0; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4554 | |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 4555 | public void noteWifiMulticastEnabledLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4556 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4557 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4558 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4559 | if (mWifiMulticastNesting == 0) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4560 | mHistoryCur.states |= HistoryItem.STATE_WIFI_MULTICAST_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4561 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI multicast on to: " |
| 4562 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 4563 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4564 | } |
| 4565 | mWifiMulticastNesting++; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4566 | getUidStatsLocked(uid).noteWifiMulticastEnabledLocked(elapsedRealtime); |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 4567 | } |
| 4568 | |
| 4569 | public void noteWifiMulticastDisabledLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4570 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4571 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4572 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4573 | mWifiMulticastNesting--; |
| 4574 | if (mWifiMulticastNesting == 0) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4575 | mHistoryCur.states &= ~HistoryItem.STATE_WIFI_MULTICAST_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4576 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI multicast off to: " |
| 4577 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 4578 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4579 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4580 | getUidStatsLocked(uid).noteWifiMulticastDisabledLocked(elapsedRealtime); |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 4581 | } |
| 4582 | |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 4583 | public void noteFullWifiLockAcquiredFromSourceLocked(WorkSource ws) { |
| 4584 | int N = ws.size(); |
| 4585 | for (int i=0; i<N; i++) { |
| 4586 | noteFullWifiLockAcquiredLocked(ws.get(i)); |
| 4587 | } |
| 4588 | } |
| 4589 | |
| 4590 | public void noteFullWifiLockReleasedFromSourceLocked(WorkSource ws) { |
| 4591 | int N = ws.size(); |
| 4592 | for (int i=0; i<N; i++) { |
| 4593 | noteFullWifiLockReleasedLocked(ws.get(i)); |
| 4594 | } |
| 4595 | } |
| 4596 | |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 4597 | public void noteWifiScanStartedFromSourceLocked(WorkSource ws) { |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 4598 | int N = ws.size(); |
| 4599 | for (int i=0; i<N; i++) { |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 4600 | noteWifiScanStartedLocked(ws.get(i)); |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 4601 | } |
| 4602 | } |
| 4603 | |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 4604 | public void noteWifiScanStoppedFromSourceLocked(WorkSource ws) { |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 4605 | int N = ws.size(); |
| 4606 | for (int i=0; i<N; i++) { |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 4607 | noteWifiScanStoppedLocked(ws.get(i)); |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 4608 | } |
| 4609 | } |
| 4610 | |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 4611 | public void noteWifiBatchedScanStartedFromSourceLocked(WorkSource ws, int csph) { |
| 4612 | int N = ws.size(); |
| 4613 | for (int i=0; i<N; i++) { |
| 4614 | noteWifiBatchedScanStartedLocked(ws.get(i), csph); |
| 4615 | } |
| 4616 | } |
| 4617 | |
| 4618 | public void noteWifiBatchedScanStoppedFromSourceLocked(WorkSource ws) { |
| 4619 | int N = ws.size(); |
| 4620 | for (int i=0; i<N; i++) { |
| 4621 | noteWifiBatchedScanStoppedLocked(ws.get(i)); |
| 4622 | } |
| 4623 | } |
| 4624 | |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 4625 | public void noteWifiMulticastEnabledFromSourceLocked(WorkSource ws) { |
| 4626 | int N = ws.size(); |
| 4627 | for (int i=0; i<N; i++) { |
| 4628 | noteWifiMulticastEnabledLocked(ws.get(i)); |
| 4629 | } |
| 4630 | } |
| 4631 | |
| 4632 | public void noteWifiMulticastDisabledFromSourceLocked(WorkSource ws) { |
| 4633 | int N = ws.size(); |
| 4634 | for (int i=0; i<N; i++) { |
| 4635 | noteWifiMulticastDisabledLocked(ws.get(i)); |
| 4636 | } |
| 4637 | } |
| 4638 | |
Dianne Hackborn | d0c5b9a | 2014-02-21 16:19:05 -0800 | [diff] [blame] | 4639 | private static String[] includeInStringArray(String[] array, String str) { |
| 4640 | if (ArrayUtils.indexOf(array, str) >= 0) { |
| 4641 | return array; |
| 4642 | } |
| 4643 | String[] newArray = new String[array.length+1]; |
| 4644 | System.arraycopy(array, 0, newArray, 0, array.length); |
| 4645 | newArray[array.length] = str; |
| 4646 | return newArray; |
| 4647 | } |
| 4648 | |
| 4649 | private static String[] excludeFromStringArray(String[] array, String str) { |
| 4650 | int index = ArrayUtils.indexOf(array, str); |
| 4651 | if (index >= 0) { |
| 4652 | String[] newArray = new String[array.length-1]; |
| 4653 | if (index > 0) { |
| 4654 | System.arraycopy(array, 0, newArray, 0, index); |
| 4655 | } |
| 4656 | if (index < array.length-1) { |
| 4657 | System.arraycopy(array, index+1, newArray, index, array.length-index-1); |
| 4658 | } |
| 4659 | return newArray; |
| 4660 | } |
| 4661 | return array; |
| 4662 | } |
| 4663 | |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 4664 | public void noteNetworkInterfaceTypeLocked(String iface, int networkType) { |
Jeff Sharkey | 9da2f1e | 2014-08-14 12:55:00 -0700 | [diff] [blame] | 4665 | if (TextUtils.isEmpty(iface)) return; |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 4666 | if (ConnectivityManager.isNetworkTypeMobile(networkType)) { |
Dianne Hackborn | d0c5b9a | 2014-02-21 16:19:05 -0800 | [diff] [blame] | 4667 | mMobileIfaces = includeInStringArray(mMobileIfaces, iface); |
| 4668 | if (DEBUG) Slog.d(TAG, "Note mobile iface " + iface + ": " + mMobileIfaces); |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 4669 | } else { |
Dianne Hackborn | d0c5b9a | 2014-02-21 16:19:05 -0800 | [diff] [blame] | 4670 | mMobileIfaces = excludeFromStringArray(mMobileIfaces, iface); |
| 4671 | if (DEBUG) Slog.d(TAG, "Note non-mobile iface " + iface + ": " + mMobileIfaces); |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 4672 | } |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 4673 | if (ConnectivityManager.isNetworkTypeWifi(networkType)) { |
Dianne Hackborn | d0c5b9a | 2014-02-21 16:19:05 -0800 | [diff] [blame] | 4674 | mWifiIfaces = includeInStringArray(mWifiIfaces, iface); |
| 4675 | if (DEBUG) Slog.d(TAG, "Note wifi iface " + iface + ": " + mWifiIfaces); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 4676 | } else { |
Dianne Hackborn | d0c5b9a | 2014-02-21 16:19:05 -0800 | [diff] [blame] | 4677 | mWifiIfaces = excludeFromStringArray(mWifiIfaces, iface); |
| 4678 | if (DEBUG) Slog.d(TAG, "Note non-wifi iface " + iface + ": " + mWifiIfaces); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 4679 | } |
| 4680 | } |
| 4681 | |
| 4682 | public void noteNetworkStatsEnabledLocked() { |
| 4683 | // During device boot, qtaguid isn't enabled until after the inital |
| 4684 | // loading of battery stats. Now that they're enabled, take our initial |
| 4685 | // snapshot for future delta calculation. |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4686 | updateMobileRadioStateLocked(mClocks.elapsedRealtime(), null); |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 4687 | updateWifiStateLocked(null); |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 4688 | } |
| 4689 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4690 | @Override public long getScreenOnTime(long elapsedRealtimeUs, int which) { |
| 4691 | return mScreenOnTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4692 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4693 | |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 4694 | @Override public int getScreenOnCount(int which) { |
| 4695 | return mScreenOnTimer.getCountLocked(which); |
| 4696 | } |
| 4697 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4698 | @Override public long getScreenBrightnessTime(int brightnessBin, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4699 | long elapsedRealtimeUs, int which) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 4700 | return mScreenBrightnessTimer[brightnessBin].getTotalTimeLocked( |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4701 | elapsedRealtimeUs, which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4702 | } |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 4703 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 4704 | @Override public long getInteractiveTime(long elapsedRealtimeUs, int which) { |
| 4705 | return mInteractiveTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4706 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4707 | |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4708 | @Override public long getPowerSaveModeEnabledTime(long elapsedRealtimeUs, int which) { |
| 4709 | return mPowerSaveModeEnabledTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 4710 | } |
| 4711 | |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4712 | @Override public int getPowerSaveModeEnabledCount(int which) { |
| 4713 | return mPowerSaveModeEnabledTimer.getCountLocked(which); |
| 4714 | } |
| 4715 | |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4716 | @Override public long getDeviceIdleModeTime(int mode, long elapsedRealtimeUs, |
| 4717 | int which) { |
| 4718 | switch (mode) { |
| 4719 | case DEVICE_IDLE_MODE_LIGHT: |
| 4720 | return mDeviceIdleModeLightTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 4721 | case DEVICE_IDLE_MODE_DEEP: |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4722 | return mDeviceIdleModeFullTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
| 4723 | } |
| 4724 | return 0; |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4725 | } |
| 4726 | |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4727 | @Override public int getDeviceIdleModeCount(int mode, int which) { |
| 4728 | switch (mode) { |
| 4729 | case DEVICE_IDLE_MODE_LIGHT: |
| 4730 | return mDeviceIdleModeLightTimer.getCountLocked(which); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 4731 | case DEVICE_IDLE_MODE_DEEP: |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4732 | return mDeviceIdleModeFullTimer.getCountLocked(which); |
| 4733 | } |
| 4734 | return 0; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 4735 | } |
| 4736 | |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4737 | @Override public long getLongestDeviceIdleModeTime(int mode) { |
| 4738 | switch (mode) { |
| 4739 | case DEVICE_IDLE_MODE_LIGHT: |
| 4740 | return mLongestLightIdleTime; |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 4741 | case DEVICE_IDLE_MODE_DEEP: |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4742 | return mLongestFullIdleTime; |
| 4743 | } |
| 4744 | return 0; |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 4745 | } |
| 4746 | |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4747 | @Override public long getDeviceIdlingTime(int mode, long elapsedRealtimeUs, int which) { |
| 4748 | switch (mode) { |
| 4749 | case DEVICE_IDLE_MODE_LIGHT: |
| 4750 | return mDeviceLightIdlingTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 4751 | case DEVICE_IDLE_MODE_DEEP: |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4752 | return mDeviceIdlingTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
| 4753 | } |
| 4754 | return 0; |
| 4755 | } |
| 4756 | |
| 4757 | @Override public int getDeviceIdlingCount(int mode, int which) { |
| 4758 | switch (mode) { |
| 4759 | case DEVICE_IDLE_MODE_LIGHT: |
| 4760 | return mDeviceLightIdlingTimer.getCountLocked(which); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 4761 | case DEVICE_IDLE_MODE_DEEP: |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4762 | return mDeviceIdlingTimer.getCountLocked(which); |
| 4763 | } |
| 4764 | return 0; |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 4765 | } |
| 4766 | |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 4767 | @Override public int getNumConnectivityChange(int which) { |
| 4768 | int val = mNumConnectivityChange; |
| 4769 | if (which == STATS_CURRENT) { |
| 4770 | val -= mLoadedNumConnectivityChange; |
| 4771 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 4772 | val -= mUnpluggedNumConnectivityChange; |
| 4773 | } |
| 4774 | return val; |
| 4775 | } |
| 4776 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4777 | @Override public long getPhoneOnTime(long elapsedRealtimeUs, int which) { |
| 4778 | return mPhoneOnTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4779 | } |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 4780 | |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 4781 | @Override public int getPhoneOnCount(int which) { |
| 4782 | return mPhoneOnTimer.getCountLocked(which); |
| 4783 | } |
| 4784 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4785 | @Override public long getPhoneSignalStrengthTime(int strengthBin, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4786 | long elapsedRealtimeUs, int which) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 4787 | return mPhoneSignalStrengthsTimer[strengthBin].getTotalTimeLocked( |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4788 | elapsedRealtimeUs, which); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4789 | } |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 4790 | |
| 4791 | @Override public long getPhoneSignalScanningTime( |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4792 | long elapsedRealtimeUs, int which) { |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 4793 | return mPhoneSignalScanningTimer.getTotalTimeLocked( |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4794 | elapsedRealtimeUs, which); |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 4795 | } |
| 4796 | |
Catherine Liu | fb90081 | 2012-07-17 14:12:56 -0500 | [diff] [blame] | 4797 | @Override public int getPhoneSignalStrengthCount(int strengthBin, int which) { |
| 4798 | return mPhoneSignalStrengthsTimer[strengthBin].getCountLocked(which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4799 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4800 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4801 | @Override public long getPhoneDataConnectionTime(int dataType, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4802 | long elapsedRealtimeUs, int which) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 4803 | return mPhoneDataConnectionsTimer[dataType].getTotalTimeLocked( |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4804 | elapsedRealtimeUs, which); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4805 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4806 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4807 | @Override public int getPhoneDataConnectionCount(int dataType, int which) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 4808 | return mPhoneDataConnectionsTimer[dataType].getCountLocked(which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4809 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4810 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4811 | @Override public long getMobileRadioActiveTime(long elapsedRealtimeUs, int which) { |
| 4812 | return mMobileRadioActiveTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 4813 | } |
| 4814 | |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4815 | @Override public int getMobileRadioActiveCount(int which) { |
| 4816 | return mMobileRadioActiveTimer.getCountLocked(which); |
| 4817 | } |
| 4818 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 4819 | @Override public long getMobileRadioActiveAdjustedTime(int which) { |
| 4820 | return mMobileRadioActiveAdjustedTime.getCountLocked(which); |
| 4821 | } |
| 4822 | |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4823 | @Override public long getMobileRadioActiveUnknownTime(int which) { |
| 4824 | return mMobileRadioActiveUnknownTime.getCountLocked(which); |
| 4825 | } |
| 4826 | |
| 4827 | @Override public int getMobileRadioActiveUnknownCount(int which) { |
| 4828 | return (int)mMobileRadioActiveUnknownCount.getCountLocked(which); |
| 4829 | } |
| 4830 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4831 | @Override public long getWifiOnTime(long elapsedRealtimeUs, int which) { |
| 4832 | return mWifiOnTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4833 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4834 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4835 | @Override public long getGlobalWifiRunningTime(long elapsedRealtimeUs, int which) { |
| 4836 | return mGlobalWifiRunningTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Eric Shienbrood | d4c5f89 | 2009-03-24 18:13:20 -0700 | [diff] [blame] | 4837 | } |
| 4838 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4839 | @Override public long getWifiStateTime(int wifiState, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4840 | long elapsedRealtimeUs, int which) { |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4841 | return mWifiStateTimer[wifiState].getTotalTimeLocked( |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4842 | elapsedRealtimeUs, which); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4843 | } |
| 4844 | |
| 4845 | @Override public int getWifiStateCount(int wifiState, int which) { |
| 4846 | return mWifiStateTimer[wifiState].getCountLocked(which); |
| 4847 | } |
| 4848 | |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 4849 | @Override public long getWifiSupplStateTime(int state, |
| 4850 | long elapsedRealtimeUs, int which) { |
| 4851 | return mWifiSupplStateTimer[state].getTotalTimeLocked( |
| 4852 | elapsedRealtimeUs, which); |
| 4853 | } |
| 4854 | |
| 4855 | @Override public int getWifiSupplStateCount(int state, int which) { |
| 4856 | return mWifiSupplStateTimer[state].getCountLocked(which); |
| 4857 | } |
| 4858 | |
| 4859 | @Override public long getWifiSignalStrengthTime(int strengthBin, |
| 4860 | long elapsedRealtimeUs, int which) { |
| 4861 | return mWifiSignalStrengthsTimer[strengthBin].getTotalTimeLocked( |
| 4862 | elapsedRealtimeUs, which); |
| 4863 | } |
| 4864 | |
| 4865 | @Override public int getWifiSignalStrengthCount(int strengthBin, int which) { |
| 4866 | return mWifiSignalStrengthsTimer[strengthBin].getCountLocked(which); |
| 4867 | } |
| 4868 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 4869 | @Override |
| 4870 | public ControllerActivityCounter getBluetoothControllerActivity() { |
| 4871 | return mBluetoothActivity; |
Adam Lesinski | 1739076 | 2015-04-10 13:17:47 -0700 | [diff] [blame] | 4872 | } |
| 4873 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 4874 | @Override |
| 4875 | public ControllerActivityCounter getWifiControllerActivity() { |
| 4876 | return mWifiActivity; |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 4877 | } |
| 4878 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 4879 | @Override |
| 4880 | public ControllerActivityCounter getModemControllerActivity() { |
| 4881 | return mModemActivity; |
Adam Lesinski | 1739076 | 2015-04-10 13:17:47 -0700 | [diff] [blame] | 4882 | } |
| 4883 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 4884 | @Override |
| 4885 | public boolean hasBluetoothActivityReporting() { |
| 4886 | return mHasBluetoothReporting; |
| 4887 | } |
| 4888 | |
| 4889 | @Override |
| 4890 | public boolean hasWifiActivityReporting() { |
| 4891 | return mHasWifiReporting; |
| 4892 | } |
| 4893 | |
| 4894 | @Override |
| 4895 | public boolean hasModemActivityReporting() { |
| 4896 | return mHasModemReporting; |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 4897 | } |
| 4898 | |
Ruben Brunk | 5b1308f | 2015-06-03 18:49:27 -0700 | [diff] [blame] | 4899 | @Override |
| 4900 | public long getFlashlightOnTime(long elapsedRealtimeUs, int which) { |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 4901 | return mFlashlightOnTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
| 4902 | } |
| 4903 | |
Ruben Brunk | 5b1308f | 2015-06-03 18:49:27 -0700 | [diff] [blame] | 4904 | @Override |
| 4905 | public long getFlashlightOnCount(int which) { |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 4906 | return mFlashlightOnTimer.getCountLocked(which); |
| 4907 | } |
| 4908 | |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 4909 | @Override |
Ruben Brunk | 5b1308f | 2015-06-03 18:49:27 -0700 | [diff] [blame] | 4910 | public long getCameraOnTime(long elapsedRealtimeUs, int which) { |
| 4911 | return mCameraOnTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
| 4912 | } |
| 4913 | |
| 4914 | @Override |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 4915 | public long getBluetoothScanTime(long elapsedRealtimeUs, int which) { |
| 4916 | return mBluetoothScanTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
| 4917 | } |
| 4918 | |
| 4919 | @Override |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4920 | public long getNetworkActivityBytes(int type, int which) { |
| 4921 | if (type >= 0 && type < mNetworkByteActivityCounters.length) { |
| 4922 | return mNetworkByteActivityCounters[type].getCountLocked(which); |
| 4923 | } else { |
| 4924 | return 0; |
| 4925 | } |
| 4926 | } |
| 4927 | |
| 4928 | @Override |
| 4929 | public long getNetworkActivityPackets(int type, int which) { |
| 4930 | if (type >= 0 && type < mNetworkPacketActivityCounters.length) { |
| 4931 | return mNetworkPacketActivityCounters[type].getCountLocked(which); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 4932 | } else { |
| 4933 | return 0; |
| 4934 | } |
| 4935 | } |
| 4936 | |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 4937 | @Override public long getStartClockTime() { |
Dianne Hackborn | d48954f | 2015-07-22 17:20:33 -0700 | [diff] [blame] | 4938 | final long currentTime = System.currentTimeMillis(); |
| 4939 | if (ensureStartClockTime(currentTime)) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4940 | recordCurrentTimeChangeLocked(currentTime, mClocks.elapsedRealtime(), |
| 4941 | mClocks.uptimeMillis()); |
Dianne Hackborn | 7d9eefd | 2014-08-27 18:30:31 -0700 | [diff] [blame] | 4942 | } |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 4943 | return mStartClockTime; |
| 4944 | } |
| 4945 | |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 4946 | @Override public String getStartPlatformVersion() { |
| 4947 | return mStartPlatformVersion; |
| 4948 | } |
| 4949 | |
| 4950 | @Override public String getEndPlatformVersion() { |
| 4951 | return mEndPlatformVersion; |
| 4952 | } |
| 4953 | |
| 4954 | @Override public int getParcelVersion() { |
| 4955 | return VERSION; |
| 4956 | } |
| 4957 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4958 | @Override public boolean getIsOnBattery() { |
| 4959 | return mOnBattery; |
| 4960 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4961 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4962 | @Override public SparseArray<? extends BatteryStats.Uid> getUidStats() { |
| 4963 | return mUidStats; |
| 4964 | } |
| 4965 | |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 4966 | private static void detachTimerIfNotNull(BatteryStatsImpl.Timer timer) { |
| 4967 | if (timer != null) { |
| 4968 | timer.detach(); |
| 4969 | } |
| 4970 | } |
| 4971 | |
| 4972 | private static boolean resetTimerIfNotNull(BatteryStatsImpl.Timer timer, |
| 4973 | boolean detachIfReset) { |
| 4974 | if (timer != null) { |
| 4975 | return timer.reset(detachIfReset); |
| 4976 | } |
| 4977 | return true; |
| 4978 | } |
| 4979 | |
| 4980 | private static void detachLongCounterIfNotNull(LongSamplingCounter counter) { |
| 4981 | if (counter != null) { |
| 4982 | counter.detach(); |
| 4983 | } |
| 4984 | } |
| 4985 | |
| 4986 | private static void resetLongCounterIfNotNull(LongSamplingCounter counter, |
| 4987 | boolean detachIfReset) { |
| 4988 | if (counter != null) { |
| 4989 | counter.reset(detachIfReset); |
| 4990 | } |
| 4991 | } |
| 4992 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4993 | /** |
| 4994 | * The statistics associated with a particular uid. |
| 4995 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4996 | public static class Uid extends BatteryStats.Uid { |
| 4997 | /** |
| 4998 | * BatteryStatsImpl that we are associated with. |
| 4999 | */ |
| 5000 | protected BatteryStatsImpl mBsi; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5001 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5002 | final int mUid; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5003 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 5004 | boolean mWifiRunning; |
| 5005 | StopwatchTimer mWifiRunningTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5006 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 5007 | boolean mFullWifiLockOut; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 5008 | StopwatchTimer mFullWifiLockTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5009 | |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 5010 | boolean mWifiScanStarted; |
| 5011 | StopwatchTimer mWifiScanTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5012 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5013 | static final int NO_BATCHED_SCAN_STARTED = -1; |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 5014 | int mWifiBatchedScanBinStarted = NO_BATCHED_SCAN_STARTED; |
| 5015 | StopwatchTimer[] mWifiBatchedScanTimer; |
| 5016 | |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 5017 | boolean mWifiMulticastEnabled; |
| 5018 | StopwatchTimer mWifiMulticastTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5019 | |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 5020 | StopwatchTimer mAudioTurnedOnTimer; |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 5021 | StopwatchTimer mVideoTurnedOnTimer; |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 5022 | StopwatchTimer mFlashlightTurnedOnTimer; |
| 5023 | StopwatchTimer mCameraTurnedOnTimer; |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 5024 | StopwatchTimer mForegroundActivityTimer; |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 5025 | StopwatchTimer mBluetoothScanTimer; |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 5026 | |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 5027 | int mProcessState = ActivityManager.PROCESS_STATE_NONEXISTENT; |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5028 | StopwatchTimer[] mProcessStateTimer; |
| 5029 | |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 5030 | BatchTimer mVibratorOnTimer; |
| 5031 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 5032 | Counter[] mUserActivityCounters; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5033 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5034 | LongSamplingCounter[] mNetworkByteActivityCounters; |
| 5035 | LongSamplingCounter[] mNetworkPacketActivityCounters; |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 5036 | LongSamplingCounter mMobileRadioActiveTime; |
| 5037 | LongSamplingCounter mMobileRadioActiveCount; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5038 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5039 | /** |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 5040 | * How many times this UID woke up the Application Processor due to a Mobile radio packet. |
| 5041 | */ |
| 5042 | private LongSamplingCounter mMobileRadioApWakeupCount; |
| 5043 | |
| 5044 | /** |
| 5045 | * How many times this UID woke up the Application Processor due to a Wifi packet. |
| 5046 | */ |
| 5047 | private LongSamplingCounter mWifiRadioApWakeupCount; |
| 5048 | |
| 5049 | /** |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 5050 | * 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] | 5051 | * Can be null if the UID has had no such activity. |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 5052 | */ |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 5053 | private ControllerActivityCounterImpl mWifiControllerActivity; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 5054 | |
| 5055 | /** |
| 5056 | * 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] | 5057 | * Can be null if the UID has had no such activity. |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 5058 | */ |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 5059 | private ControllerActivityCounterImpl mBluetoothControllerActivity; |
| 5060 | |
| 5061 | /** |
| 5062 | * The amount of time this uid has kept the Modem controller in idle, tx, and rx mode. |
| 5063 | * Can be null if the UID has had no such activity. |
| 5064 | */ |
| 5065 | private ControllerActivityCounterImpl mModemControllerActivity; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 5066 | |
| 5067 | /** |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 5068 | * The CPU times we had at the last history details update. |
| 5069 | */ |
| 5070 | long mLastStepUserTime; |
| 5071 | long mLastStepSystemTime; |
| 5072 | long mCurStepUserTime; |
| 5073 | long mCurStepSystemTime; |
| 5074 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5075 | LongSamplingCounter mUserCpuTime; |
| 5076 | LongSamplingCounter mSystemCpuTime; |
| 5077 | LongSamplingCounter mCpuPower; |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 5078 | LongSamplingCounter[][] mCpuClusterSpeed; |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 5079 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 5080 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5081 | * The statistics we have collected for this uid's wake locks. |
| 5082 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5083 | final OverflowArrayMap<Wakelock> mWakelockStats; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5084 | |
| 5085 | /** |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 5086 | * The statistics we have collected for this uid's syncs. |
| 5087 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5088 | final OverflowArrayMap<StopwatchTimer> mSyncStats; |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 5089 | |
| 5090 | /** |
| 5091 | * The statistics we have collected for this uid's jobs. |
| 5092 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5093 | final OverflowArrayMap<StopwatchTimer> mJobStats; |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 5094 | |
| 5095 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5096 | * The statistics we have collected for this uid's sensor activations. |
| 5097 | */ |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 5098 | final SparseArray<Sensor> mSensorStats = new SparseArray<>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5099 | |
| 5100 | /** |
| 5101 | * The statistics we have collected for this uid's processes. |
| 5102 | */ |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 5103 | final ArrayMap<String, Proc> mProcessStats = new ArrayMap<>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5104 | |
| 5105 | /** |
| 5106 | * The statistics we have collected for this uid's processes. |
| 5107 | */ |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 5108 | final ArrayMap<String, Pkg> mPackageStats = new ArrayMap<>(); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5109 | |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 5110 | /** |
| 5111 | * The transient wake stats we have collected for this uid's pids. |
| 5112 | */ |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 5113 | final SparseArray<Pid> mPids = new SparseArray<>(); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 5114 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5115 | public Uid(BatteryStatsImpl bsi, int uid) { |
| 5116 | mBsi = bsi; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5117 | mUid = uid; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5118 | |
| 5119 | mUserCpuTime = new LongSamplingCounter(mBsi.mOnBatteryTimeBase); |
| 5120 | mSystemCpuTime = new LongSamplingCounter(mBsi.mOnBatteryTimeBase); |
| 5121 | mCpuPower = new LongSamplingCounter(mBsi.mOnBatteryTimeBase); |
| 5122 | |
Dianne Hackborn | 657153b | 2016-07-29 14:54:14 -0700 | [diff] [blame^] | 5123 | mWakelockStats = mBsi.new OverflowArrayMap<Wakelock>(uid) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5124 | @Override public Wakelock instantiateObject() { |
| 5125 | return new Wakelock(mBsi, Uid.this); |
| 5126 | } |
| 5127 | }; |
Dianne Hackborn | 657153b | 2016-07-29 14:54:14 -0700 | [diff] [blame^] | 5128 | mSyncStats = mBsi.new OverflowArrayMap<StopwatchTimer>(uid) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5129 | @Override public StopwatchTimer instantiateObject() { |
| 5130 | return new StopwatchTimer(mBsi.mClocks, Uid.this, SYNC, null, |
| 5131 | mBsi.mOnBatteryTimeBase); |
| 5132 | } |
| 5133 | }; |
Dianne Hackborn | 657153b | 2016-07-29 14:54:14 -0700 | [diff] [blame^] | 5134 | mJobStats = mBsi.new OverflowArrayMap<StopwatchTimer>(uid) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5135 | @Override public StopwatchTimer instantiateObject() { |
| 5136 | return new StopwatchTimer(mBsi.mClocks, Uid.this, JOB, null, |
| 5137 | mBsi.mOnBatteryTimeBase); |
| 5138 | } |
| 5139 | }; |
| 5140 | |
| 5141 | mWifiRunningTimer = new StopwatchTimer(mBsi.mClocks, this, WIFI_RUNNING, |
| 5142 | mBsi.mWifiRunningTimers, mBsi.mOnBatteryTimeBase); |
| 5143 | mFullWifiLockTimer = new StopwatchTimer(mBsi.mClocks, this, FULL_WIFI_LOCK, |
| 5144 | mBsi.mFullWifiLockTimers, mBsi.mOnBatteryTimeBase); |
| 5145 | mWifiScanTimer = new StopwatchTimer(mBsi.mClocks, this, WIFI_SCAN, |
| 5146 | mBsi.mWifiScanTimers, mBsi.mOnBatteryTimeBase); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 5147 | mWifiBatchedScanTimer = new StopwatchTimer[NUM_WIFI_BATCHED_SCAN_BINS]; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5148 | mWifiMulticastTimer = new StopwatchTimer(mBsi.mClocks, this, WIFI_MULTICAST_ENABLED, |
| 5149 | mBsi.mWifiMulticastTimers, mBsi.mOnBatteryTimeBase); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5150 | mProcessStateTimer = new StopwatchTimer[NUM_PROCESS_STATE]; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5151 | } |
| 5152 | |
| 5153 | @Override |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5154 | public ArrayMap<String, ? extends BatteryStats.Uid.Wakelock> getWakelockStats() { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 5155 | return mWakelockStats.getMap(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5156 | } |
| 5157 | |
| 5158 | @Override |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5159 | public ArrayMap<String, ? extends BatteryStats.Timer> getSyncStats() { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 5160 | return mSyncStats.getMap(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 5161 | } |
| 5162 | |
| 5163 | @Override |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5164 | public ArrayMap<String, ? extends BatteryStats.Timer> getJobStats() { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 5165 | return mJobStats.getMap(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 5166 | } |
| 5167 | |
| 5168 | @Override |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5169 | public SparseArray<? extends BatteryStats.Uid.Sensor> getSensorStats() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5170 | return mSensorStats; |
| 5171 | } |
| 5172 | |
| 5173 | @Override |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5174 | public ArrayMap<String, ? extends BatteryStats.Uid.Proc> getProcessStats() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5175 | return mProcessStats; |
| 5176 | } |
| 5177 | |
| 5178 | @Override |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5179 | public ArrayMap<String, ? extends BatteryStats.Uid.Pkg> getPackageStats() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5180 | return mPackageStats; |
| 5181 | } |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 5182 | |
| 5183 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5184 | public int getUid() { |
| 5185 | return mUid; |
| 5186 | } |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 5187 | |
| 5188 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5189 | public void noteWifiRunningLocked(long elapsedRealtimeMs) { |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 5190 | if (!mWifiRunning) { |
| 5191 | mWifiRunning = true; |
| 5192 | if (mWifiRunningTimer == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5193 | mWifiRunningTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, WIFI_RUNNING, |
| 5194 | mBsi.mWifiRunningTimers, mBsi.mOnBatteryTimeBase); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5195 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5196 | mWifiRunningTimer.startRunningLocked(elapsedRealtimeMs); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 5197 | } |
| 5198 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5199 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 5200 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5201 | public void noteWifiStoppedLocked(long elapsedRealtimeMs) { |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 5202 | if (mWifiRunning) { |
| 5203 | mWifiRunning = false; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5204 | mWifiRunningTimer.stopRunningLocked(elapsedRealtimeMs); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 5205 | } |
| 5206 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5207 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 5208 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5209 | public void noteFullWifiLockAcquiredLocked(long elapsedRealtimeMs) { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 5210 | if (!mFullWifiLockOut) { |
| 5211 | mFullWifiLockOut = true; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5212 | if (mFullWifiLockTimer == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5213 | mFullWifiLockTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, FULL_WIFI_LOCK, |
| 5214 | mBsi.mFullWifiLockTimers, mBsi.mOnBatteryTimeBase); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5215 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5216 | mFullWifiLockTimer.startRunningLocked(elapsedRealtimeMs); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 5217 | } |
| 5218 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5219 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 5220 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5221 | public void noteFullWifiLockReleasedLocked(long elapsedRealtimeMs) { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 5222 | if (mFullWifiLockOut) { |
| 5223 | mFullWifiLockOut = false; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5224 | mFullWifiLockTimer.stopRunningLocked(elapsedRealtimeMs); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 5225 | } |
| 5226 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5227 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 5228 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5229 | public void noteWifiScanStartedLocked(long elapsedRealtimeMs) { |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 5230 | if (!mWifiScanStarted) { |
| 5231 | mWifiScanStarted = true; |
| 5232 | if (mWifiScanTimer == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5233 | mWifiScanTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, WIFI_SCAN, |
| 5234 | mBsi.mWifiScanTimers, mBsi.mOnBatteryTimeBase); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5235 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5236 | mWifiScanTimer.startRunningLocked(elapsedRealtimeMs); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 5237 | } |
| 5238 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5239 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 5240 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5241 | public void noteWifiScanStoppedLocked(long elapsedRealtimeMs) { |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 5242 | if (mWifiScanStarted) { |
| 5243 | mWifiScanStarted = false; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5244 | mWifiScanTimer.stopRunningLocked(elapsedRealtimeMs); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 5245 | } |
| 5246 | } |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 5247 | |
| 5248 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5249 | public void noteWifiBatchedScanStartedLocked(int csph, long elapsedRealtimeMs) { |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 5250 | int bin = 0; |
Navtej Singh Mann | 3c0ce5c | 2015-06-11 16:53:11 -0700 | [diff] [blame] | 5251 | while (csph > 8 && bin < NUM_WIFI_BATCHED_SCAN_BINS-1) { |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 5252 | csph = csph >> 3; |
| 5253 | bin++; |
| 5254 | } |
| 5255 | |
| 5256 | if (mWifiBatchedScanBinStarted == bin) return; |
| 5257 | |
| 5258 | if (mWifiBatchedScanBinStarted != NO_BATCHED_SCAN_STARTED) { |
| 5259 | mWifiBatchedScanTimer[mWifiBatchedScanBinStarted]. |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5260 | stopRunningLocked(elapsedRealtimeMs); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 5261 | } |
| 5262 | mWifiBatchedScanBinStarted = bin; |
| 5263 | if (mWifiBatchedScanTimer[bin] == null) { |
| 5264 | makeWifiBatchedScanBin(bin, null); |
| 5265 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5266 | mWifiBatchedScanTimer[bin].startRunningLocked(elapsedRealtimeMs); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 5267 | } |
| 5268 | |
| 5269 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5270 | public void noteWifiBatchedScanStoppedLocked(long elapsedRealtimeMs) { |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 5271 | if (mWifiBatchedScanBinStarted != NO_BATCHED_SCAN_STARTED) { |
| 5272 | mWifiBatchedScanTimer[mWifiBatchedScanBinStarted]. |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5273 | stopRunningLocked(elapsedRealtimeMs); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 5274 | mWifiBatchedScanBinStarted = NO_BATCHED_SCAN_STARTED; |
| 5275 | } |
| 5276 | } |
| 5277 | |
| 5278 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5279 | public void noteWifiMulticastEnabledLocked(long elapsedRealtimeMs) { |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 5280 | if (!mWifiMulticastEnabled) { |
| 5281 | mWifiMulticastEnabled = true; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5282 | if (mWifiMulticastTimer == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5283 | mWifiMulticastTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, |
| 5284 | WIFI_MULTICAST_ENABLED, mBsi.mWifiMulticastTimers, mBsi.mOnBatteryTimeBase); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5285 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5286 | mWifiMulticastTimer.startRunningLocked(elapsedRealtimeMs); |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 5287 | } |
| 5288 | } |
| 5289 | |
| 5290 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5291 | public void noteWifiMulticastDisabledLocked(long elapsedRealtimeMs) { |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 5292 | if (mWifiMulticastEnabled) { |
| 5293 | mWifiMulticastEnabled = false; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5294 | mWifiMulticastTimer.stopRunningLocked(elapsedRealtimeMs); |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 5295 | } |
| 5296 | } |
| 5297 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 5298 | @Override |
| 5299 | public ControllerActivityCounter getWifiControllerActivity() { |
| 5300 | return mWifiControllerActivity; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 5301 | } |
| 5302 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 5303 | @Override |
| 5304 | public ControllerActivityCounter getBluetoothControllerActivity() { |
| 5305 | return mBluetoothControllerActivity; |
| 5306 | } |
| 5307 | |
| 5308 | @Override |
| 5309 | public ControllerActivityCounter getModemControllerActivity() { |
| 5310 | return mModemControllerActivity; |
| 5311 | } |
| 5312 | |
| 5313 | public ControllerActivityCounterImpl getOrCreateWifiControllerActivityLocked() { |
| 5314 | if (mWifiControllerActivity == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5315 | mWifiControllerActivity = new ControllerActivityCounterImpl(mBsi.mOnBatteryTimeBase, |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 5316 | NUM_BT_TX_LEVELS); |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 5317 | } |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 5318 | return mWifiControllerActivity; |
| 5319 | } |
| 5320 | |
| 5321 | public ControllerActivityCounterImpl getOrCreateBluetoothControllerActivityLocked() { |
| 5322 | if (mBluetoothControllerActivity == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5323 | mBluetoothControllerActivity = new ControllerActivityCounterImpl(mBsi.mOnBatteryTimeBase, |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 5324 | NUM_BT_TX_LEVELS); |
| 5325 | } |
| 5326 | return mBluetoothControllerActivity; |
| 5327 | } |
| 5328 | |
| 5329 | public ControllerActivityCounterImpl getOrCreateModemControllerActivityLocked() { |
| 5330 | if (mModemControllerActivity == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5331 | mModemControllerActivity = new ControllerActivityCounterImpl(mBsi.mOnBatteryTimeBase, |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 5332 | ModemActivityInfo.TX_POWER_LEVELS); |
| 5333 | } |
| 5334 | return mModemControllerActivity; |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 5335 | } |
| 5336 | |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 5337 | public StopwatchTimer createAudioTurnedOnTimerLocked() { |
| 5338 | if (mAudioTurnedOnTimer == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5339 | mAudioTurnedOnTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, AUDIO_TURNED_ON, |
| 5340 | mBsi.mAudioTurnedOnTimers, mBsi.mOnBatteryTimeBase); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 5341 | } |
| 5342 | return mAudioTurnedOnTimer; |
| 5343 | } |
| 5344 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5345 | public void noteAudioTurnedOnLocked(long elapsedRealtimeMs) { |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 5346 | createAudioTurnedOnTimerLocked().startRunningLocked(elapsedRealtimeMs); |
| 5347 | } |
| 5348 | |
| 5349 | public void noteAudioTurnedOffLocked(long elapsedRealtimeMs) { |
| 5350 | if (mAudioTurnedOnTimer != null) { |
| 5351 | mAudioTurnedOnTimer.stopRunningLocked(elapsedRealtimeMs); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5352 | } |
| 5353 | } |
| 5354 | |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 5355 | public void noteResetAudioLocked(long elapsedRealtimeMs) { |
| 5356 | if (mAudioTurnedOnTimer != null) { |
| 5357 | mAudioTurnedOnTimer.stopAllRunningLocked(elapsedRealtimeMs); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5358 | } |
| 5359 | } |
| 5360 | |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 5361 | public StopwatchTimer createVideoTurnedOnTimerLocked() { |
| 5362 | if (mVideoTurnedOnTimer == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5363 | mVideoTurnedOnTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, VIDEO_TURNED_ON, |
| 5364 | mBsi.mVideoTurnedOnTimers, mBsi.mOnBatteryTimeBase); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 5365 | } |
| 5366 | return mVideoTurnedOnTimer; |
| 5367 | } |
| 5368 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5369 | public void noteVideoTurnedOnLocked(long elapsedRealtimeMs) { |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 5370 | createVideoTurnedOnTimerLocked().startRunningLocked(elapsedRealtimeMs); |
| 5371 | } |
| 5372 | |
| 5373 | public void noteVideoTurnedOffLocked(long elapsedRealtimeMs) { |
| 5374 | if (mVideoTurnedOnTimer != null) { |
| 5375 | mVideoTurnedOnTimer.stopRunningLocked(elapsedRealtimeMs); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5376 | } |
| 5377 | } |
| 5378 | |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 5379 | public void noteResetVideoLocked(long elapsedRealtimeMs) { |
| 5380 | if (mVideoTurnedOnTimer != null) { |
| 5381 | mVideoTurnedOnTimer.stopAllRunningLocked(elapsedRealtimeMs); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 5382 | } |
| 5383 | } |
| 5384 | |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 5385 | public StopwatchTimer createFlashlightTurnedOnTimerLocked() { |
| 5386 | if (mFlashlightTurnedOnTimer == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5387 | mFlashlightTurnedOnTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, |
| 5388 | FLASHLIGHT_TURNED_ON, mBsi.mFlashlightTurnedOnTimers, mBsi.mOnBatteryTimeBase); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 5389 | } |
| 5390 | return mFlashlightTurnedOnTimer; |
| 5391 | } |
| 5392 | |
| 5393 | public void noteFlashlightTurnedOnLocked(long elapsedRealtimeMs) { |
| 5394 | createFlashlightTurnedOnTimerLocked().startRunningLocked(elapsedRealtimeMs); |
| 5395 | } |
| 5396 | |
| 5397 | public void noteFlashlightTurnedOffLocked(long elapsedRealtimeMs) { |
| 5398 | if (mFlashlightTurnedOnTimer != null) { |
| 5399 | mFlashlightTurnedOnTimer.stopRunningLocked(elapsedRealtimeMs); |
| 5400 | } |
| 5401 | } |
| 5402 | |
| 5403 | public void noteResetFlashlightLocked(long elapsedRealtimeMs) { |
| 5404 | if (mFlashlightTurnedOnTimer != null) { |
| 5405 | mFlashlightTurnedOnTimer.stopAllRunningLocked(elapsedRealtimeMs); |
| 5406 | } |
| 5407 | } |
| 5408 | |
| 5409 | public StopwatchTimer createCameraTurnedOnTimerLocked() { |
| 5410 | if (mCameraTurnedOnTimer == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5411 | mCameraTurnedOnTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, CAMERA_TURNED_ON, |
| 5412 | mBsi.mCameraTurnedOnTimers, mBsi.mOnBatteryTimeBase); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 5413 | } |
| 5414 | return mCameraTurnedOnTimer; |
| 5415 | } |
| 5416 | |
| 5417 | public void noteCameraTurnedOnLocked(long elapsedRealtimeMs) { |
| 5418 | createCameraTurnedOnTimerLocked().startRunningLocked(elapsedRealtimeMs); |
| 5419 | } |
| 5420 | |
| 5421 | public void noteCameraTurnedOffLocked(long elapsedRealtimeMs) { |
| 5422 | if (mCameraTurnedOnTimer != null) { |
| 5423 | mCameraTurnedOnTimer.stopRunningLocked(elapsedRealtimeMs); |
| 5424 | } |
| 5425 | } |
| 5426 | |
| 5427 | public void noteResetCameraLocked(long elapsedRealtimeMs) { |
| 5428 | if (mCameraTurnedOnTimer != null) { |
| 5429 | mCameraTurnedOnTimer.stopAllRunningLocked(elapsedRealtimeMs); |
| 5430 | } |
| 5431 | } |
| 5432 | |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 5433 | public StopwatchTimer createForegroundActivityTimerLocked() { |
| 5434 | if (mForegroundActivityTimer == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5435 | mForegroundActivityTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, |
| 5436 | FOREGROUND_ACTIVITY, null, mBsi.mOnBatteryTimeBase); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 5437 | } |
| 5438 | return mForegroundActivityTimer; |
| 5439 | } |
| 5440 | |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 5441 | public StopwatchTimer createBluetoothScanTimerLocked() { |
| 5442 | if (mBluetoothScanTimer == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5443 | mBluetoothScanTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, BLUETOOTH_SCAN_ON, |
| 5444 | mBsi.mBluetoothScanOnTimers, mBsi.mOnBatteryTimeBase); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 5445 | } |
| 5446 | return mBluetoothScanTimer; |
| 5447 | } |
| 5448 | |
| 5449 | public void noteBluetoothScanStartedLocked(long elapsedRealtimeMs) { |
| 5450 | createBluetoothScanTimerLocked().startRunningLocked(elapsedRealtimeMs); |
| 5451 | } |
| 5452 | |
| 5453 | public void noteBluetoothScanStoppedLocked(long elapsedRealtimeMs) { |
| 5454 | if (mBluetoothScanTimer != null) { |
| 5455 | mBluetoothScanTimer.stopRunningLocked(elapsedRealtimeMs); |
| 5456 | } |
| 5457 | } |
| 5458 | |
| 5459 | public void noteResetBluetoothScanLocked(long elapsedRealtimeMs) { |
| 5460 | if (mBluetoothScanTimer != null) { |
| 5461 | mBluetoothScanTimer.stopAllRunningLocked(elapsedRealtimeMs); |
| 5462 | } |
| 5463 | } |
| 5464 | |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 5465 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5466 | public void noteActivityResumedLocked(long elapsedRealtimeMs) { |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 5467 | // We always start, since we want multiple foreground PIDs to nest |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5468 | createForegroundActivityTimerLocked().startRunningLocked(elapsedRealtimeMs); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 5469 | } |
| 5470 | |
| 5471 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5472 | public void noteActivityPausedLocked(long elapsedRealtimeMs) { |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 5473 | if (mForegroundActivityTimer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5474 | mForegroundActivityTimer.stopRunningLocked(elapsedRealtimeMs); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 5475 | } |
| 5476 | } |
| 5477 | |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 5478 | public BatchTimer createVibratorOnTimerLocked() { |
| 5479 | if (mVibratorOnTimer == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5480 | mVibratorOnTimer = new BatchTimer(mBsi.mClocks, Uid.this, VIBRATOR_ON, |
| 5481 | mBsi.mOnBatteryTimeBase); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 5482 | } |
| 5483 | return mVibratorOnTimer; |
| 5484 | } |
| 5485 | |
| 5486 | public void noteVibratorOnLocked(long durationMillis) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5487 | createVibratorOnTimerLocked().addDuration(mBsi, durationMillis); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 5488 | } |
| 5489 | |
| 5490 | public void noteVibratorOffLocked() { |
| 5491 | if (mVibratorOnTimer != null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5492 | mVibratorOnTimer.abortLastDuration(mBsi); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5493 | } |
| 5494 | } |
| 5495 | |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5496 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5497 | public long getWifiRunningTime(long elapsedRealtimeUs, int which) { |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 5498 | if (mWifiRunningTimer == null) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5499 | return 0; |
| 5500 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5501 | return mWifiRunningTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 5502 | } |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 5503 | |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5504 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5505 | public long getFullWifiLockTime(long elapsedRealtimeUs, int which) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5506 | if (mFullWifiLockTimer == null) { |
| 5507 | return 0; |
| 5508 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5509 | return mFullWifiLockTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 5510 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5511 | |
| 5512 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5513 | public long getWifiScanTime(long elapsedRealtimeUs, int which) { |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 5514 | if (mWifiScanTimer == null) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5515 | return 0; |
| 5516 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5517 | return mWifiScanTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 5518 | } |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 5519 | |
| 5520 | @Override |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 5521 | public int getWifiScanCount(int which) { |
| 5522 | if (mWifiScanTimer == null) { |
| 5523 | return 0; |
| 5524 | } |
| 5525 | return mWifiScanTimer.getCountLocked(which); |
| 5526 | } |
| 5527 | |
| 5528 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5529 | public long getWifiBatchedScanTime(int csphBin, long elapsedRealtimeUs, int which) { |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 5530 | if (csphBin < 0 || csphBin >= NUM_WIFI_BATCHED_SCAN_BINS) return 0; |
| 5531 | if (mWifiBatchedScanTimer[csphBin] == null) { |
| 5532 | return 0; |
| 5533 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5534 | return mWifiBatchedScanTimer[csphBin].getTotalTimeLocked(elapsedRealtimeUs, which); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 5535 | } |
| 5536 | |
| 5537 | @Override |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 5538 | public int getWifiBatchedScanCount(int csphBin, int which) { |
| 5539 | if (csphBin < 0 || csphBin >= NUM_WIFI_BATCHED_SCAN_BINS) return 0; |
| 5540 | if (mWifiBatchedScanTimer[csphBin] == null) { |
| 5541 | return 0; |
| 5542 | } |
| 5543 | return mWifiBatchedScanTimer[csphBin].getCountLocked(which); |
| 5544 | } |
| 5545 | |
| 5546 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5547 | public long getWifiMulticastTime(long elapsedRealtimeUs, int which) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5548 | if (mWifiMulticastTimer == null) { |
| 5549 | return 0; |
| 5550 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5551 | return mWifiMulticastTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 5552 | } |
| 5553 | |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5554 | @Override |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 5555 | public Timer getAudioTurnedOnTimer() { |
| 5556 | return mAudioTurnedOnTimer; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5557 | } |
| 5558 | |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5559 | @Override |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 5560 | public Timer getVideoTurnedOnTimer() { |
| 5561 | return mVideoTurnedOnTimer; |
| 5562 | } |
| 5563 | |
| 5564 | @Override |
| 5565 | public Timer getFlashlightTurnedOnTimer() { |
| 5566 | return mFlashlightTurnedOnTimer; |
| 5567 | } |
| 5568 | |
| 5569 | @Override |
| 5570 | public Timer getCameraTurnedOnTimer() { |
| 5571 | return mCameraTurnedOnTimer; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5572 | } |
| 5573 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 5574 | @Override |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 5575 | public Timer getForegroundActivityTimer() { |
| 5576 | return mForegroundActivityTimer; |
| 5577 | } |
| 5578 | |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 5579 | @Override |
| 5580 | public Timer getBluetoothScanTimer() { |
| 5581 | return mBluetoothScanTimer; |
| 5582 | } |
| 5583 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5584 | void makeProcessState(int i, Parcel in) { |
| 5585 | if (i < 0 || i >= NUM_PROCESS_STATE) return; |
| 5586 | |
| 5587 | if (in == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5588 | mProcessStateTimer[i] = new StopwatchTimer(mBsi.mClocks, this, PROCESS_STATE, null, |
| 5589 | mBsi.mOnBatteryTimeBase); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5590 | } else { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5591 | mProcessStateTimer[i] = new StopwatchTimer(mBsi.mClocks, this, PROCESS_STATE, null, |
| 5592 | mBsi.mOnBatteryTimeBase, in); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5593 | } |
| 5594 | } |
| 5595 | |
| 5596 | @Override |
| 5597 | public long getProcessStateTime(int state, long elapsedRealtimeUs, int which) { |
| 5598 | if (state < 0 || state >= NUM_PROCESS_STATE) return 0; |
| 5599 | if (mProcessStateTimer[state] == null) { |
| 5600 | return 0; |
| 5601 | } |
| 5602 | return mProcessStateTimer[state].getTotalTimeLocked(elapsedRealtimeUs, which); |
| 5603 | } |
| 5604 | |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 5605 | @Override |
Joe Onorato | 713fec8 | 2016-03-04 10:34:02 -0800 | [diff] [blame] | 5606 | public Timer getProcessStateTimer(int state) { |
| 5607 | if (state < 0 || state >= NUM_PROCESS_STATE) return null; |
| 5608 | return mProcessStateTimer[state]; |
| 5609 | } |
| 5610 | |
| 5611 | @Override |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 5612 | public Timer getVibratorOnTimer() { |
| 5613 | return mVibratorOnTimer; |
| 5614 | } |
| 5615 | |
| 5616 | @Override |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 5617 | public void noteUserActivityLocked(int type) { |
| 5618 | if (mUserActivityCounters == null) { |
| 5619 | initUserActivityLocked(); |
| 5620 | } |
Jeff Brown | df693de | 2012-07-27 12:03:38 -0700 | [diff] [blame] | 5621 | if (type >= 0 && type < NUM_USER_ACTIVITY_TYPES) { |
| 5622 | mUserActivityCounters[type].stepAtomic(); |
| 5623 | } else { |
| 5624 | Slog.w(TAG, "Unknown user activity type " + type + " was specified.", |
| 5625 | new Throwable()); |
| 5626 | } |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 5627 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5628 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 5629 | @Override |
| 5630 | public boolean hasUserActivity() { |
| 5631 | return mUserActivityCounters != null; |
| 5632 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5633 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 5634 | @Override |
| 5635 | public int getUserActivityCount(int type, int which) { |
| 5636 | if (mUserActivityCounters == null) { |
| 5637 | return 0; |
| 5638 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 5639 | return mUserActivityCounters[type].getCountLocked(which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 5640 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5641 | |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 5642 | void makeWifiBatchedScanBin(int i, Parcel in) { |
| 5643 | if (i < 0 || i >= NUM_WIFI_BATCHED_SCAN_BINS) return; |
| 5644 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5645 | ArrayList<StopwatchTimer> collected = mBsi.mWifiBatchedScanTimers.get(i); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 5646 | if (collected == null) { |
| 5647 | collected = new ArrayList<StopwatchTimer>(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5648 | mBsi.mWifiBatchedScanTimers.put(i, collected); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 5649 | } |
| 5650 | if (in == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5651 | mWifiBatchedScanTimer[i] = new StopwatchTimer(mBsi.mClocks, this, WIFI_BATCHED_SCAN, |
| 5652 | collected, mBsi.mOnBatteryTimeBase); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 5653 | } else { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5654 | mWifiBatchedScanTimer[i] = new StopwatchTimer(mBsi.mClocks, this, WIFI_BATCHED_SCAN, |
| 5655 | collected, mBsi.mOnBatteryTimeBase, in); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 5656 | } |
| 5657 | } |
| 5658 | |
| 5659 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 5660 | void initUserActivityLocked() { |
| 5661 | mUserActivityCounters = new Counter[NUM_USER_ACTIVITY_TYPES]; |
| 5662 | for (int i=0; i<NUM_USER_ACTIVITY_TYPES; i++) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5663 | mUserActivityCounters[i] = new Counter(mBsi.mOnBatteryTimeBase); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 5664 | } |
| 5665 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5666 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5667 | void noteNetworkActivityLocked(int type, long deltaBytes, long deltaPackets) { |
| 5668 | if (mNetworkByteActivityCounters == null) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5669 | initNetworkActivityLocked(); |
| 5670 | } |
| 5671 | if (type >= 0 && type < NUM_NETWORK_ACTIVITY_TYPES) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5672 | mNetworkByteActivityCounters[type].addCountLocked(deltaBytes); |
| 5673 | mNetworkPacketActivityCounters[type].addCountLocked(deltaPackets); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5674 | } else { |
| 5675 | Slog.w(TAG, "Unknown network activity type " + type + " was specified.", |
| 5676 | new Throwable()); |
| 5677 | } |
| 5678 | } |
| 5679 | |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 5680 | void noteMobileRadioActiveTimeLocked(long batteryUptime) { |
| 5681 | if (mNetworkByteActivityCounters == null) { |
| 5682 | initNetworkActivityLocked(); |
| 5683 | } |
| 5684 | mMobileRadioActiveTime.addCountLocked(batteryUptime); |
| 5685 | mMobileRadioActiveCount.addCountLocked(1); |
| 5686 | } |
| 5687 | |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5688 | @Override |
| 5689 | public boolean hasNetworkActivity() { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5690 | return mNetworkByteActivityCounters != null; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5691 | } |
| 5692 | |
| 5693 | @Override |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5694 | public long getNetworkActivityBytes(int type, int which) { |
| 5695 | if (mNetworkByteActivityCounters != null && type >= 0 |
| 5696 | && type < mNetworkByteActivityCounters.length) { |
| 5697 | return mNetworkByteActivityCounters[type].getCountLocked(which); |
| 5698 | } else { |
| 5699 | return 0; |
| 5700 | } |
| 5701 | } |
| 5702 | |
| 5703 | @Override |
| 5704 | public long getNetworkActivityPackets(int type, int which) { |
| 5705 | if (mNetworkPacketActivityCounters != null && type >= 0 |
| 5706 | && type < mNetworkPacketActivityCounters.length) { |
| 5707 | return mNetworkPacketActivityCounters[type].getCountLocked(which); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5708 | } else { |
| 5709 | return 0; |
| 5710 | } |
| 5711 | } |
| 5712 | |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 5713 | @Override |
| 5714 | public long getMobileRadioActiveTime(int which) { |
| 5715 | return mMobileRadioActiveTime != null |
| 5716 | ? mMobileRadioActiveTime.getCountLocked(which) : 0; |
| 5717 | } |
| 5718 | |
| 5719 | @Override |
| 5720 | public int getMobileRadioActiveCount(int which) { |
| 5721 | return mMobileRadioActiveCount != null |
| 5722 | ? (int)mMobileRadioActiveCount.getCountLocked(which) : 0; |
| 5723 | } |
| 5724 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 5725 | @Override |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 5726 | public long getUserCpuTimeUs(int which) { |
| 5727 | return mUserCpuTime.getCountLocked(which); |
| 5728 | } |
| 5729 | |
| 5730 | @Override |
| 5731 | public long getSystemCpuTimeUs(int which) { |
| 5732 | return mSystemCpuTime.getCountLocked(which); |
| 5733 | } |
| 5734 | |
| 5735 | @Override |
Adam Lesinski | a7a4ccc | 2015-06-26 17:43:04 -0700 | [diff] [blame] | 5736 | public long getCpuPowerMaUs(int which) { |
| 5737 | return mCpuPower.getCountLocked(which); |
| 5738 | } |
| 5739 | |
| 5740 | @Override |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 5741 | public long getTimeAtCpuSpeed(int cluster, int step, int which) { |
| 5742 | if (mCpuClusterSpeed != null) { |
| 5743 | if (cluster >= 0 && cluster < mCpuClusterSpeed.length) { |
| 5744 | final LongSamplingCounter[] cpuSpeeds = mCpuClusterSpeed[cluster]; |
| 5745 | if (cpuSpeeds != null) { |
| 5746 | if (step >= 0 && step < cpuSpeeds.length) { |
| 5747 | final LongSamplingCounter c = cpuSpeeds[step]; |
| 5748 | if (c != null) { |
| 5749 | return c.getCountLocked(which); |
| 5750 | } |
| 5751 | } |
| 5752 | } |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 5753 | } |
| 5754 | } |
| 5755 | return 0; |
| 5756 | } |
| 5757 | |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 5758 | public void noteMobileRadioApWakeupLocked() { |
| 5759 | if (mMobileRadioApWakeupCount == null) { |
| 5760 | mMobileRadioApWakeupCount = new LongSamplingCounter(mBsi.mOnBatteryTimeBase); |
| 5761 | } |
| 5762 | mMobileRadioApWakeupCount.addCountLocked(1); |
| 5763 | } |
| 5764 | |
| 5765 | @Override |
| 5766 | public long getMobileRadioApWakeupCount(int which) { |
| 5767 | if (mMobileRadioApWakeupCount != null) { |
| 5768 | return mMobileRadioApWakeupCount.getCountLocked(which); |
| 5769 | } |
| 5770 | return 0; |
| 5771 | } |
| 5772 | |
| 5773 | public void noteWifiRadioApWakeupLocked() { |
| 5774 | if (mWifiRadioApWakeupCount == null) { |
| 5775 | mWifiRadioApWakeupCount = new LongSamplingCounter(mBsi.mOnBatteryTimeBase); |
| 5776 | } |
| 5777 | mWifiRadioApWakeupCount.addCountLocked(1); |
| 5778 | } |
| 5779 | |
| 5780 | @Override |
| 5781 | public long getWifiRadioApWakeupCount(int which) { |
| 5782 | if (mWifiRadioApWakeupCount != null) { |
| 5783 | return mWifiRadioApWakeupCount.getCountLocked(which); |
| 5784 | } |
| 5785 | return 0; |
| 5786 | } |
| 5787 | |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5788 | void initNetworkActivityLocked() { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5789 | mNetworkByteActivityCounters = new LongSamplingCounter[NUM_NETWORK_ACTIVITY_TYPES]; |
| 5790 | mNetworkPacketActivityCounters = new LongSamplingCounter[NUM_NETWORK_ACTIVITY_TYPES]; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5791 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5792 | mNetworkByteActivityCounters[i] = new LongSamplingCounter(mBsi.mOnBatteryTimeBase); |
| 5793 | mNetworkPacketActivityCounters[i] = new LongSamplingCounter(mBsi.mOnBatteryTimeBase); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5794 | } |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5795 | mMobileRadioActiveTime = new LongSamplingCounter(mBsi.mOnBatteryTimeBase); |
| 5796 | mMobileRadioActiveCount = new LongSamplingCounter(mBsi.mOnBatteryTimeBase); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5797 | } |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 5798 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5799 | /** |
| 5800 | * Clear all stats for this uid. Returns true if the uid is completely |
| 5801 | * inactive so can be dropped. |
| 5802 | */ |
| 5803 | boolean reset() { |
| 5804 | boolean active = false; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5805 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 5806 | if (mWifiRunningTimer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5807 | active |= !mWifiRunningTimer.reset(false); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 5808 | active |= mWifiRunning; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5809 | } |
| 5810 | if (mFullWifiLockTimer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5811 | active |= !mFullWifiLockTimer.reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5812 | active |= mFullWifiLockOut; |
| 5813 | } |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 5814 | if (mWifiScanTimer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5815 | active |= !mWifiScanTimer.reset(false); |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 5816 | active |= mWifiScanStarted; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5817 | } |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 5818 | if (mWifiBatchedScanTimer != null) { |
| 5819 | for (int i = 0; i < NUM_WIFI_BATCHED_SCAN_BINS; i++) { |
| 5820 | if (mWifiBatchedScanTimer[i] != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5821 | active |= !mWifiBatchedScanTimer[i].reset(false); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 5822 | } |
| 5823 | } |
| 5824 | active |= (mWifiBatchedScanBinStarted != NO_BATCHED_SCAN_STARTED); |
| 5825 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5826 | if (mWifiMulticastTimer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5827 | active |= !mWifiMulticastTimer.reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5828 | active |= mWifiMulticastEnabled; |
| 5829 | } |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 5830 | |
| 5831 | active |= !resetTimerIfNotNull(mAudioTurnedOnTimer, false); |
| 5832 | active |= !resetTimerIfNotNull(mVideoTurnedOnTimer, false); |
| 5833 | active |= !resetTimerIfNotNull(mFlashlightTurnedOnTimer, false); |
| 5834 | active |= !resetTimerIfNotNull(mCameraTurnedOnTimer, false); |
| 5835 | active |= !resetTimerIfNotNull(mForegroundActivityTimer, false); |
| 5836 | active |= !resetTimerIfNotNull(mBluetoothScanTimer, false); |
| 5837 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5838 | if (mProcessStateTimer != null) { |
| 5839 | for (int i = 0; i < NUM_PROCESS_STATE; i++) { |
| 5840 | if (mProcessStateTimer[i] != null) { |
| 5841 | active |= !mProcessStateTimer[i].reset(false); |
| 5842 | } |
| 5843 | } |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 5844 | active |= (mProcessState != ActivityManager.PROCESS_STATE_NONEXISTENT); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5845 | } |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 5846 | if (mVibratorOnTimer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5847 | if (mVibratorOnTimer.reset(false)) { |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 5848 | mVibratorOnTimer.detach(); |
| 5849 | mVibratorOnTimer = null; |
| 5850 | } else { |
| 5851 | active = true; |
| 5852 | } |
| 5853 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5854 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5855 | if (mUserActivityCounters != null) { |
| 5856 | for (int i=0; i<NUM_USER_ACTIVITY_TYPES; i++) { |
| 5857 | mUserActivityCounters[i].reset(false); |
| 5858 | } |
| 5859 | } |
| 5860 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5861 | if (mNetworkByteActivityCounters != null) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5862 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5863 | mNetworkByteActivityCounters[i].reset(false); |
| 5864 | mNetworkPacketActivityCounters[i].reset(false); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5865 | } |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 5866 | mMobileRadioActiveTime.reset(false); |
| 5867 | mMobileRadioActiveCount.reset(false); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5868 | } |
| 5869 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 5870 | if (mWifiControllerActivity != null) { |
| 5871 | mWifiControllerActivity.reset(false); |
| 5872 | } |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 5873 | |
Adam Lesinski | 1a2b39e | 2016-04-29 17:56:58 -0700 | [diff] [blame] | 5874 | if (mBluetoothControllerActivity != null) { |
| 5875 | mBluetoothControllerActivity.reset(false); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 5876 | } |
| 5877 | |
Adam Lesinski | 1a2b39e | 2016-04-29 17:56:58 -0700 | [diff] [blame] | 5878 | if (mModemControllerActivity != null) { |
| 5879 | mModemControllerActivity.reset(false); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 5880 | } |
| 5881 | |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 5882 | mUserCpuTime.reset(false); |
| 5883 | mSystemCpuTime.reset(false); |
Adam Lesinski | a7a4ccc | 2015-06-26 17:43:04 -0700 | [diff] [blame] | 5884 | mCpuPower.reset(false); |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 5885 | |
| 5886 | if (mCpuClusterSpeed != null) { |
| 5887 | for (LongSamplingCounter[] speeds : mCpuClusterSpeed) { |
| 5888 | if (speeds != null) { |
| 5889 | for (LongSamplingCounter speed : speeds) { |
| 5890 | if (speed != null) { |
| 5891 | speed.reset(false); |
| 5892 | } |
| 5893 | } |
| 5894 | } |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 5895 | } |
| 5896 | } |
| 5897 | |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 5898 | resetLongCounterIfNotNull(mMobileRadioApWakeupCount, false); |
| 5899 | resetLongCounterIfNotNull(mWifiRadioApWakeupCount, false); |
| 5900 | |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 5901 | final ArrayMap<String, Wakelock> wakeStats = mWakelockStats.getMap(); |
| 5902 | for (int iw=wakeStats.size()-1; iw>=0; iw--) { |
| 5903 | Wakelock wl = wakeStats.valueAt(iw); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5904 | if (wl.reset()) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 5905 | wakeStats.removeAt(iw); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5906 | } else { |
| 5907 | active = true; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5908 | } |
| 5909 | } |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 5910 | mWakelockStats.cleanup(); |
| 5911 | final ArrayMap<String, StopwatchTimer> syncStats = mSyncStats.getMap(); |
| 5912 | for (int is=syncStats.size()-1; is>=0; is--) { |
| 5913 | StopwatchTimer timer = syncStats.valueAt(is); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 5914 | if (timer.reset(false)) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 5915 | syncStats.removeAt(is); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 5916 | timer.detach(); |
| 5917 | } else { |
| 5918 | active = true; |
| 5919 | } |
| 5920 | } |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 5921 | mSyncStats.cleanup(); |
| 5922 | final ArrayMap<String, StopwatchTimer> jobStats = mJobStats.getMap(); |
| 5923 | for (int ij=jobStats.size()-1; ij>=0; ij--) { |
| 5924 | StopwatchTimer timer = jobStats.valueAt(ij); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 5925 | if (timer.reset(false)) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 5926 | jobStats.removeAt(ij); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 5927 | timer.detach(); |
| 5928 | } else { |
| 5929 | active = true; |
| 5930 | } |
| 5931 | } |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 5932 | mJobStats.cleanup(); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5933 | for (int ise=mSensorStats.size()-1; ise>=0; ise--) { |
| 5934 | Sensor s = mSensorStats.valueAt(ise); |
| 5935 | if (s.reset()) { |
| 5936 | mSensorStats.removeAt(ise); |
| 5937 | } else { |
| 5938 | active = true; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5939 | } |
| 5940 | } |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5941 | for (int ip=mProcessStats.size()-1; ip>=0; ip--) { |
| 5942 | Proc proc = mProcessStats.valueAt(ip); |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 5943 | proc.detach(); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5944 | } |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 5945 | mProcessStats.clear(); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 5946 | if (mPids.size() > 0) { |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 5947 | for (int i=mPids.size()-1; i>=0; i--) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 5948 | Pid pid = mPids.valueAt(i); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 5949 | if (pid.mWakeNesting > 0) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 5950 | active = true; |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 5951 | } else { |
| 5952 | mPids.removeAt(i); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 5953 | } |
| 5954 | } |
| 5955 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5956 | if (mPackageStats.size() > 0) { |
| 5957 | Iterator<Map.Entry<String, Pkg>> it = mPackageStats.entrySet().iterator(); |
| 5958 | while (it.hasNext()) { |
| 5959 | Map.Entry<String, Pkg> pkgEntry = it.next(); |
| 5960 | Pkg p = pkgEntry.getValue(); |
| 5961 | p.detach(); |
| 5962 | if (p.mServiceStats.size() > 0) { |
| 5963 | Iterator<Map.Entry<String, Pkg.Serv>> it2 |
| 5964 | = p.mServiceStats.entrySet().iterator(); |
| 5965 | while (it2.hasNext()) { |
| 5966 | Map.Entry<String, Pkg.Serv> servEntry = it2.next(); |
| 5967 | servEntry.getValue().detach(); |
| 5968 | } |
| 5969 | } |
| 5970 | } |
| 5971 | mPackageStats.clear(); |
| 5972 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5973 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 5974 | mLastStepUserTime = mLastStepSystemTime = 0; |
| 5975 | mCurStepUserTime = mCurStepSystemTime = 0; |
| 5976 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5977 | if (!active) { |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 5978 | if (mWifiRunningTimer != null) { |
| 5979 | mWifiRunningTimer.detach(); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5980 | } |
| 5981 | if (mFullWifiLockTimer != null) { |
| 5982 | mFullWifiLockTimer.detach(); |
| 5983 | } |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 5984 | if (mWifiScanTimer != null) { |
| 5985 | mWifiScanTimer.detach(); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5986 | } |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 5987 | for (int i = 0; i < NUM_WIFI_BATCHED_SCAN_BINS; i++) { |
| 5988 | if (mWifiBatchedScanTimer[i] != null) { |
| 5989 | mWifiBatchedScanTimer[i].detach(); |
| 5990 | } |
| 5991 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5992 | if (mWifiMulticastTimer != null) { |
| 5993 | mWifiMulticastTimer.detach(); |
| 5994 | } |
| 5995 | if (mAudioTurnedOnTimer != null) { |
| 5996 | mAudioTurnedOnTimer.detach(); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 5997 | mAudioTurnedOnTimer = null; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5998 | } |
| 5999 | if (mVideoTurnedOnTimer != null) { |
| 6000 | mVideoTurnedOnTimer.detach(); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 6001 | mVideoTurnedOnTimer = null; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6002 | } |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 6003 | if (mFlashlightTurnedOnTimer != null) { |
| 6004 | mFlashlightTurnedOnTimer.detach(); |
| 6005 | mFlashlightTurnedOnTimer = null; |
| 6006 | } |
| 6007 | if (mCameraTurnedOnTimer != null) { |
| 6008 | mCameraTurnedOnTimer.detach(); |
| 6009 | mCameraTurnedOnTimer = null; |
| 6010 | } |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 6011 | if (mForegroundActivityTimer != null) { |
| 6012 | mForegroundActivityTimer.detach(); |
| 6013 | mForegroundActivityTimer = null; |
| 6014 | } |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 6015 | if (mBluetoothScanTimer != null) { |
| 6016 | mBluetoothScanTimer.detach(); |
| 6017 | mBluetoothScanTimer = null; |
| 6018 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6019 | if (mUserActivityCounters != null) { |
| 6020 | for (int i=0; i<NUM_USER_ACTIVITY_TYPES; i++) { |
| 6021 | mUserActivityCounters[i].detach(); |
| 6022 | } |
| 6023 | } |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6024 | if (mNetworkByteActivityCounters != null) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 6025 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6026 | mNetworkByteActivityCounters[i].detach(); |
| 6027 | mNetworkPacketActivityCounters[i].detach(); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 6028 | } |
| 6029 | } |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 6030 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 6031 | if (mWifiControllerActivity != null) { |
| 6032 | mWifiControllerActivity.detach(); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 6033 | } |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 6034 | |
| 6035 | if (mBluetoothControllerActivity != null) { |
| 6036 | mBluetoothControllerActivity.detach(); |
| 6037 | } |
| 6038 | |
| 6039 | if (mModemControllerActivity != null) { |
| 6040 | mModemControllerActivity.detach(); |
| 6041 | } |
| 6042 | |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 6043 | mPids.clear(); |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 6044 | |
| 6045 | mUserCpuTime.detach(); |
| 6046 | mSystemCpuTime.detach(); |
Adam Lesinski | a7a4ccc | 2015-06-26 17:43:04 -0700 | [diff] [blame] | 6047 | mCpuPower.detach(); |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 6048 | |
| 6049 | if (mCpuClusterSpeed != null) { |
| 6050 | for (LongSamplingCounter[] cpuSpeeds : mCpuClusterSpeed) { |
| 6051 | if (cpuSpeeds != null) { |
| 6052 | for (LongSamplingCounter c : cpuSpeeds) { |
| 6053 | if (c != null) { |
| 6054 | c.detach(); |
| 6055 | } |
| 6056 | } |
| 6057 | } |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 6058 | } |
| 6059 | } |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 6060 | |
| 6061 | detachLongCounterIfNotNull(mMobileRadioApWakeupCount); |
| 6062 | detachLongCounterIfNotNull(mWifiRadioApWakeupCount); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6063 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6064 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6065 | return !active; |
| 6066 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6067 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6068 | void writeToParcelLocked(Parcel out, long elapsedRealtimeUs) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 6069 | final ArrayMap<String, Wakelock> wakeStats = mWakelockStats.getMap(); |
| 6070 | int NW = wakeStats.size(); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 6071 | out.writeInt(NW); |
| 6072 | for (int iw=0; iw<NW; iw++) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 6073 | out.writeString(wakeStats.keyAt(iw)); |
| 6074 | Uid.Wakelock wakelock = wakeStats.valueAt(iw); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6075 | wakelock.writeToParcelLocked(out, elapsedRealtimeUs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6076 | } |
| 6077 | |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 6078 | final ArrayMap<String, StopwatchTimer> syncStats = mSyncStats.getMap(); |
| 6079 | int NS = syncStats.size(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 6080 | out.writeInt(NS); |
| 6081 | for (int is=0; is<NS; is++) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 6082 | out.writeString(syncStats.keyAt(is)); |
| 6083 | StopwatchTimer timer = syncStats.valueAt(is); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 6084 | Timer.writeTimerToParcel(out, timer, elapsedRealtimeUs); |
| 6085 | } |
| 6086 | |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 6087 | final ArrayMap<String, StopwatchTimer> jobStats = mJobStats.getMap(); |
| 6088 | int NJ = jobStats.size(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 6089 | out.writeInt(NJ); |
| 6090 | for (int ij=0; ij<NJ; ij++) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 6091 | out.writeString(jobStats.keyAt(ij)); |
| 6092 | StopwatchTimer timer = jobStats.valueAt(ij); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 6093 | Timer.writeTimerToParcel(out, timer, elapsedRealtimeUs); |
| 6094 | } |
| 6095 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 6096 | int NSE = mSensorStats.size(); |
| 6097 | out.writeInt(NSE); |
| 6098 | for (int ise=0; ise<NSE; ise++) { |
| 6099 | out.writeInt(mSensorStats.keyAt(ise)); |
| 6100 | Uid.Sensor sensor = mSensorStats.valueAt(ise); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6101 | sensor.writeToParcelLocked(out, elapsedRealtimeUs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6102 | } |
| 6103 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 6104 | int NP = mProcessStats.size(); |
| 6105 | out.writeInt(NP); |
| 6106 | for (int ip=0; ip<NP; ip++) { |
| 6107 | out.writeString(mProcessStats.keyAt(ip)); |
| 6108 | Uid.Proc proc = mProcessStats.valueAt(ip); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6109 | proc.writeToParcelLocked(out); |
| 6110 | } |
| 6111 | |
| 6112 | out.writeInt(mPackageStats.size()); |
| 6113 | for (Map.Entry<String, Uid.Pkg> pkgEntry : mPackageStats.entrySet()) { |
| 6114 | out.writeString(pkgEntry.getKey()); |
| 6115 | Uid.Pkg pkg = pkgEntry.getValue(); |
| 6116 | pkg.writeToParcelLocked(out); |
| 6117 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6118 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 6119 | if (mWifiRunningTimer != null) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6120 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6121 | mWifiRunningTimer.writeToParcel(out, elapsedRealtimeUs); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 6122 | } else { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6123 | out.writeInt(0); |
| 6124 | } |
| 6125 | if (mFullWifiLockTimer != null) { |
| 6126 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6127 | mFullWifiLockTimer.writeToParcel(out, elapsedRealtimeUs); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6128 | } else { |
| 6129 | out.writeInt(0); |
| 6130 | } |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 6131 | if (mWifiScanTimer != null) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6132 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6133 | mWifiScanTimer.writeToParcel(out, elapsedRealtimeUs); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6134 | } else { |
| 6135 | out.writeInt(0); |
| 6136 | } |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 6137 | for (int i = 0; i < NUM_WIFI_BATCHED_SCAN_BINS; i++) { |
| 6138 | if (mWifiBatchedScanTimer[i] != null) { |
| 6139 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6140 | mWifiBatchedScanTimer[i].writeToParcel(out, elapsedRealtimeUs); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 6141 | } else { |
| 6142 | out.writeInt(0); |
| 6143 | } |
| 6144 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6145 | if (mWifiMulticastTimer != null) { |
| 6146 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6147 | mWifiMulticastTimer.writeToParcel(out, elapsedRealtimeUs); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6148 | } else { |
| 6149 | out.writeInt(0); |
| 6150 | } |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 6151 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6152 | if (mAudioTurnedOnTimer != null) { |
| 6153 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6154 | mAudioTurnedOnTimer.writeToParcel(out, elapsedRealtimeUs); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6155 | } else { |
| 6156 | out.writeInt(0); |
| 6157 | } |
| 6158 | if (mVideoTurnedOnTimer != null) { |
| 6159 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6160 | mVideoTurnedOnTimer.writeToParcel(out, elapsedRealtimeUs); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6161 | } else { |
| 6162 | out.writeInt(0); |
| 6163 | } |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 6164 | if (mFlashlightTurnedOnTimer != null) { |
| 6165 | out.writeInt(1); |
| 6166 | mFlashlightTurnedOnTimer.writeToParcel(out, elapsedRealtimeUs); |
| 6167 | } else { |
| 6168 | out.writeInt(0); |
| 6169 | } |
| 6170 | if (mCameraTurnedOnTimer != null) { |
| 6171 | out.writeInt(1); |
| 6172 | mCameraTurnedOnTimer.writeToParcel(out, elapsedRealtimeUs); |
| 6173 | } else { |
| 6174 | out.writeInt(0); |
| 6175 | } |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 6176 | if (mForegroundActivityTimer != null) { |
| 6177 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6178 | mForegroundActivityTimer.writeToParcel(out, elapsedRealtimeUs); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 6179 | } else { |
| 6180 | out.writeInt(0); |
| 6181 | } |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 6182 | if (mBluetoothScanTimer != null) { |
| 6183 | out.writeInt(1); |
| 6184 | mBluetoothScanTimer.writeToParcel(out, elapsedRealtimeUs); |
| 6185 | } else { |
| 6186 | out.writeInt(0); |
| 6187 | } |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 6188 | for (int i = 0; i < NUM_PROCESS_STATE; i++) { |
| 6189 | if (mProcessStateTimer[i] != null) { |
| 6190 | out.writeInt(1); |
| 6191 | mProcessStateTimer[i].writeToParcel(out, elapsedRealtimeUs); |
| 6192 | } else { |
| 6193 | out.writeInt(0); |
| 6194 | } |
| 6195 | } |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 6196 | if (mVibratorOnTimer != null) { |
| 6197 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6198 | mVibratorOnTimer.writeToParcel(out, elapsedRealtimeUs); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 6199 | } else { |
| 6200 | out.writeInt(0); |
| 6201 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6202 | if (mUserActivityCounters != null) { |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 6203 | out.writeInt(1); |
| 6204 | for (int i=0; i<NUM_USER_ACTIVITY_TYPES; i++) { |
| 6205 | mUserActivityCounters[i].writeToParcel(out); |
| 6206 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6207 | } else { |
| 6208 | out.writeInt(0); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 6209 | } |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6210 | if (mNetworkByteActivityCounters != null) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 6211 | out.writeInt(1); |
| 6212 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6213 | mNetworkByteActivityCounters[i].writeToParcel(out); |
| 6214 | mNetworkPacketActivityCounters[i].writeToParcel(out); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 6215 | } |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 6216 | mMobileRadioActiveTime.writeToParcel(out); |
| 6217 | mMobileRadioActiveCount.writeToParcel(out); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 6218 | } else { |
| 6219 | out.writeInt(0); |
| 6220 | } |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 6221 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 6222 | if (mWifiControllerActivity != null) { |
| 6223 | out.writeInt(1); |
| 6224 | mWifiControllerActivity.writeToParcel(out, 0); |
| 6225 | } else { |
| 6226 | out.writeInt(0); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 6227 | } |
| 6228 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 6229 | if (mBluetoothControllerActivity != null) { |
| 6230 | out.writeInt(1); |
| 6231 | mBluetoothControllerActivity.writeToParcel(out, 0); |
| 6232 | } else { |
| 6233 | out.writeInt(0); |
| 6234 | } |
| 6235 | |
| 6236 | if (mModemControllerActivity != null) { |
| 6237 | out.writeInt(1); |
| 6238 | mModemControllerActivity.writeToParcel(out, 0); |
| 6239 | } else { |
| 6240 | out.writeInt(0); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 6241 | } |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 6242 | |
| 6243 | mUserCpuTime.writeToParcel(out); |
| 6244 | mSystemCpuTime.writeToParcel(out); |
Adam Lesinski | a7a4ccc | 2015-06-26 17:43:04 -0700 | [diff] [blame] | 6245 | mCpuPower.writeToParcel(out); |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 6246 | |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 6247 | if (mCpuClusterSpeed != null) { |
| 6248 | out.writeInt(1); |
| 6249 | out.writeInt(mCpuClusterSpeed.length); |
| 6250 | for (LongSamplingCounter[] cpuSpeeds : mCpuClusterSpeed) { |
| 6251 | if (cpuSpeeds != null) { |
| 6252 | out.writeInt(1); |
| 6253 | out.writeInt(cpuSpeeds.length); |
| 6254 | for (LongSamplingCounter c : cpuSpeeds) { |
| 6255 | if (c != null) { |
| 6256 | out.writeInt(1); |
| 6257 | c.writeToParcel(out); |
| 6258 | } else { |
| 6259 | out.writeInt(0); |
| 6260 | } |
| 6261 | } |
| 6262 | } else { |
| 6263 | out.writeInt(0); |
| 6264 | } |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 6265 | } |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 6266 | } else { |
| 6267 | out.writeInt(0); |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 6268 | } |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 6269 | |
| 6270 | if (mMobileRadioApWakeupCount != null) { |
| 6271 | out.writeInt(1); |
| 6272 | mMobileRadioApWakeupCount.writeToParcel(out); |
| 6273 | } else { |
| 6274 | out.writeInt(0); |
| 6275 | } |
| 6276 | |
| 6277 | if (mWifiRadioApWakeupCount != null) { |
| 6278 | out.writeInt(1); |
| 6279 | mWifiRadioApWakeupCount.writeToParcel(out); |
| 6280 | } else { |
| 6281 | out.writeInt(0); |
| 6282 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6283 | } |
| 6284 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6285 | void readFromParcelLocked(TimeBase timeBase, TimeBase screenOffTimeBase, Parcel in) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6286 | int numWakelocks = in.readInt(); |
| 6287 | mWakelockStats.clear(); |
| 6288 | for (int j = 0; j < numWakelocks; j++) { |
| 6289 | String wakelockName = in.readString(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6290 | Uid.Wakelock wakelock = new Wakelock(mBsi, this); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6291 | wakelock.readFromParcelLocked(timeBase, screenOffTimeBase, in); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 6292 | mWakelockStats.add(wakelockName, wakelock); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6293 | } |
| 6294 | |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 6295 | int numSyncs = in.readInt(); |
| 6296 | mSyncStats.clear(); |
| 6297 | for (int j = 0; j < numSyncs; j++) { |
| 6298 | String syncName = in.readString(); |
| 6299 | if (in.readInt() != 0) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 6300 | mSyncStats.add(syncName, |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6301 | new StopwatchTimer(mBsi.mClocks, Uid.this, SYNC, null, timeBase, in)); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 6302 | } |
| 6303 | } |
| 6304 | |
| 6305 | int numJobs = in.readInt(); |
| 6306 | mJobStats.clear(); |
| 6307 | for (int j = 0; j < numJobs; j++) { |
| 6308 | String jobName = in.readString(); |
| 6309 | if (in.readInt() != 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6310 | mJobStats.add(jobName, new StopwatchTimer(mBsi.mClocks, Uid.this, JOB, null, |
| 6311 | timeBase, in)); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 6312 | } |
| 6313 | } |
| 6314 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6315 | int numSensors = in.readInt(); |
| 6316 | mSensorStats.clear(); |
| 6317 | for (int k = 0; k < numSensors; k++) { |
| 6318 | int sensorNumber = in.readInt(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6319 | Uid.Sensor sensor = new Sensor(mBsi, this, sensorNumber); |
| 6320 | sensor.readFromParcelLocked(mBsi.mOnBatteryTimeBase, in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6321 | mSensorStats.put(sensorNumber, sensor); |
| 6322 | } |
| 6323 | |
| 6324 | int numProcs = in.readInt(); |
| 6325 | mProcessStats.clear(); |
| 6326 | for (int k = 0; k < numProcs; k++) { |
| 6327 | String processName = in.readString(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6328 | Uid.Proc proc = new Proc(mBsi, processName); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6329 | proc.readFromParcelLocked(in); |
| 6330 | mProcessStats.put(processName, proc); |
| 6331 | } |
| 6332 | |
| 6333 | int numPkgs = in.readInt(); |
| 6334 | mPackageStats.clear(); |
| 6335 | for (int l = 0; l < numPkgs; l++) { |
| 6336 | String packageName = in.readString(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6337 | Uid.Pkg pkg = new Pkg(mBsi); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6338 | pkg.readFromParcelLocked(in); |
| 6339 | mPackageStats.put(packageName, pkg); |
| 6340 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6341 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 6342 | mWifiRunning = false; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6343 | if (in.readInt() != 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6344 | mWifiRunningTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, WIFI_RUNNING, |
| 6345 | mBsi.mWifiRunningTimers, mBsi.mOnBatteryTimeBase, in); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 6346 | } else { |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 6347 | mWifiRunningTimer = null; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6348 | } |
| 6349 | mFullWifiLockOut = false; |
| 6350 | if (in.readInt() != 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6351 | mFullWifiLockTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, FULL_WIFI_LOCK, |
| 6352 | mBsi.mFullWifiLockTimers, mBsi.mOnBatteryTimeBase, in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6353 | } else { |
| 6354 | mFullWifiLockTimer = null; |
| 6355 | } |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 6356 | mWifiScanStarted = false; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6357 | if (in.readInt() != 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6358 | mWifiScanTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, WIFI_SCAN, |
| 6359 | mBsi.mWifiScanTimers, mBsi.mOnBatteryTimeBase, in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6360 | } else { |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 6361 | mWifiScanTimer = null; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6362 | } |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 6363 | mWifiBatchedScanBinStarted = NO_BATCHED_SCAN_STARTED; |
| 6364 | for (int i = 0; i < NUM_WIFI_BATCHED_SCAN_BINS; i++) { |
| 6365 | if (in.readInt() != 0) { |
| 6366 | makeWifiBatchedScanBin(i, in); |
| 6367 | } else { |
| 6368 | mWifiBatchedScanTimer[i] = null; |
| 6369 | } |
| 6370 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6371 | mWifiMulticastEnabled = false; |
| 6372 | if (in.readInt() != 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6373 | mWifiMulticastTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, WIFI_MULTICAST_ENABLED, |
| 6374 | mBsi.mWifiMulticastTimers, mBsi.mOnBatteryTimeBase, in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6375 | } else { |
| 6376 | mWifiMulticastTimer = null; |
| 6377 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6378 | if (in.readInt() != 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6379 | mAudioTurnedOnTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, AUDIO_TURNED_ON, |
| 6380 | mBsi.mAudioTurnedOnTimers, mBsi.mOnBatteryTimeBase, in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6381 | } else { |
| 6382 | mAudioTurnedOnTimer = null; |
| 6383 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6384 | if (in.readInt() != 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6385 | mVideoTurnedOnTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, VIDEO_TURNED_ON, |
| 6386 | mBsi.mVideoTurnedOnTimers, mBsi.mOnBatteryTimeBase, in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6387 | } else { |
| 6388 | mVideoTurnedOnTimer = null; |
| 6389 | } |
| 6390 | if (in.readInt() != 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6391 | mFlashlightTurnedOnTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, |
| 6392 | FLASHLIGHT_TURNED_ON, mBsi.mFlashlightTurnedOnTimers, mBsi.mOnBatteryTimeBase, in); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 6393 | } else { |
| 6394 | mFlashlightTurnedOnTimer = null; |
| 6395 | } |
| 6396 | if (in.readInt() != 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6397 | mCameraTurnedOnTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, CAMERA_TURNED_ON, |
| 6398 | mBsi.mCameraTurnedOnTimers, mBsi.mOnBatteryTimeBase, in); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 6399 | } else { |
| 6400 | mCameraTurnedOnTimer = null; |
| 6401 | } |
| 6402 | if (in.readInt() != 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6403 | mForegroundActivityTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, |
| 6404 | FOREGROUND_ACTIVITY, null, mBsi.mOnBatteryTimeBase, in); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 6405 | } else { |
| 6406 | mForegroundActivityTimer = null; |
| 6407 | } |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 6408 | if (in.readInt() != 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6409 | mBluetoothScanTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, BLUETOOTH_SCAN_ON, |
| 6410 | mBsi.mBluetoothScanOnTimers, mBsi.mOnBatteryTimeBase, in); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 6411 | } else { |
| 6412 | mBluetoothScanTimer = null; |
| 6413 | } |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 6414 | mProcessState = ActivityManager.PROCESS_STATE_NONEXISTENT; |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 6415 | for (int i = 0; i < NUM_PROCESS_STATE; i++) { |
| 6416 | if (in.readInt() != 0) { |
| 6417 | makeProcessState(i, in); |
| 6418 | } else { |
| 6419 | mProcessStateTimer[i] = null; |
| 6420 | } |
| 6421 | } |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 6422 | if (in.readInt() != 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6423 | mVibratorOnTimer = new BatchTimer(mBsi.mClocks, Uid.this, VIBRATOR_ON, |
| 6424 | mBsi.mOnBatteryTimeBase, in); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 6425 | } else { |
| 6426 | mVibratorOnTimer = null; |
| 6427 | } |
| 6428 | if (in.readInt() != 0) { |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 6429 | mUserActivityCounters = new Counter[NUM_USER_ACTIVITY_TYPES]; |
| 6430 | for (int i=0; i<NUM_USER_ACTIVITY_TYPES; i++) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6431 | mUserActivityCounters[i] = new Counter(mBsi.mOnBatteryTimeBase, in); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 6432 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6433 | } else { |
| 6434 | mUserActivityCounters = null; |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 6435 | } |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 6436 | if (in.readInt() != 0) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6437 | mNetworkByteActivityCounters = new LongSamplingCounter[NUM_NETWORK_ACTIVITY_TYPES]; |
| 6438 | mNetworkPacketActivityCounters |
| 6439 | = new LongSamplingCounter[NUM_NETWORK_ACTIVITY_TYPES]; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 6440 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6441 | mNetworkByteActivityCounters[i] |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6442 | = new LongSamplingCounter(mBsi.mOnBatteryTimeBase, in); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6443 | mNetworkPacketActivityCounters[i] |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6444 | = new LongSamplingCounter(mBsi.mOnBatteryTimeBase, in); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 6445 | } |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6446 | mMobileRadioActiveTime = new LongSamplingCounter(mBsi.mOnBatteryTimeBase, in); |
| 6447 | mMobileRadioActiveCount = new LongSamplingCounter(mBsi.mOnBatteryTimeBase, in); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 6448 | } else { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6449 | mNetworkByteActivityCounters = null; |
| 6450 | mNetworkPacketActivityCounters = null; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 6451 | } |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 6452 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 6453 | if (in.readInt() != 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6454 | mWifiControllerActivity = new ControllerActivityCounterImpl(mBsi.mOnBatteryTimeBase, |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 6455 | NUM_WIFI_TX_LEVELS, in); |
| 6456 | } else { |
| 6457 | mWifiControllerActivity = null; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 6458 | } |
| 6459 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 6460 | if (in.readInt() != 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6461 | mBluetoothControllerActivity = new ControllerActivityCounterImpl(mBsi.mOnBatteryTimeBase, |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 6462 | NUM_BT_TX_LEVELS, in); |
| 6463 | } else { |
| 6464 | mBluetoothControllerActivity = null; |
| 6465 | } |
| 6466 | |
| 6467 | if (in.readInt() != 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6468 | mModemControllerActivity = new ControllerActivityCounterImpl(mBsi.mOnBatteryTimeBase, |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 6469 | ModemActivityInfo.TX_POWER_LEVELS, in); |
| 6470 | } else { |
| 6471 | mModemControllerActivity = null; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 6472 | } |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 6473 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6474 | mUserCpuTime = new LongSamplingCounter(mBsi.mOnBatteryTimeBase, in); |
| 6475 | mSystemCpuTime = new LongSamplingCounter(mBsi.mOnBatteryTimeBase, in); |
| 6476 | mCpuPower = new LongSamplingCounter(mBsi.mOnBatteryTimeBase, in); |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 6477 | |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 6478 | if (in.readInt() != 0) { |
| 6479 | int numCpuClusters = in.readInt(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6480 | if (mBsi.mPowerProfile != null && mBsi.mPowerProfile.getNumCpuClusters() != numCpuClusters) { |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 6481 | throw new ParcelFormatException("Incompatible number of cpu clusters"); |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 6482 | } |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 6483 | |
| 6484 | mCpuClusterSpeed = new LongSamplingCounter[numCpuClusters][]; |
| 6485 | for (int cluster = 0; cluster < numCpuClusters; cluster++) { |
| 6486 | if (in.readInt() != 0) { |
| 6487 | int numSpeeds = in.readInt(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6488 | if (mBsi.mPowerProfile != null && |
| 6489 | mBsi.mPowerProfile.getNumSpeedStepsInCpuCluster(cluster) != numSpeeds) { |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 6490 | throw new ParcelFormatException("Incompatible number of cpu speeds"); |
| 6491 | } |
| 6492 | |
| 6493 | final LongSamplingCounter[] cpuSpeeds = new LongSamplingCounter[numSpeeds]; |
| 6494 | mCpuClusterSpeed[cluster] = cpuSpeeds; |
| 6495 | for (int speed = 0; speed < numSpeeds; speed++) { |
| 6496 | if (in.readInt() != 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6497 | cpuSpeeds[speed] = new LongSamplingCounter(mBsi.mOnBatteryTimeBase, in); |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 6498 | } |
| 6499 | } |
Adam Lesinski | a57a540 | 2015-09-28 10:21:33 -0700 | [diff] [blame] | 6500 | } else { |
| 6501 | mCpuClusterSpeed[cluster] = null; |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 6502 | } |
| 6503 | } |
| 6504 | } else { |
| 6505 | mCpuClusterSpeed = null; |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 6506 | } |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 6507 | |
| 6508 | if (in.readInt() != 0) { |
| 6509 | mMobileRadioApWakeupCount = new LongSamplingCounter(mBsi.mOnBatteryTimeBase, in); |
| 6510 | } else { |
| 6511 | mMobileRadioApWakeupCount = null; |
| 6512 | } |
| 6513 | |
| 6514 | if (in.readInt() != 0) { |
| 6515 | mWifiRadioApWakeupCount = new LongSamplingCounter(mBsi.mOnBatteryTimeBase, in); |
| 6516 | } else { |
| 6517 | mWifiRadioApWakeupCount = null; |
| 6518 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6519 | } |
| 6520 | |
| 6521 | /** |
| 6522 | * The statistics associated with a particular wake lock. |
| 6523 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6524 | public static class Wakelock extends BatteryStats.Uid.Wakelock { |
| 6525 | /** |
| 6526 | * BatteryStatsImpl that we are associated with. |
| 6527 | */ |
| 6528 | protected BatteryStatsImpl mBsi; |
| 6529 | |
| 6530 | /** |
| 6531 | * BatteryStatsImpl that we are associated with. |
| 6532 | */ |
| 6533 | protected Uid mUid; |
| 6534 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6535 | /** |
| 6536 | * How long (in ms) this uid has been keeping the device partially awake. |
| 6537 | */ |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 6538 | StopwatchTimer mTimerPartial; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6539 | |
| 6540 | /** |
| 6541 | * How long (in ms) this uid has been keeping the device fully awake. |
| 6542 | */ |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 6543 | StopwatchTimer mTimerFull; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6544 | |
| 6545 | /** |
| 6546 | * How long (in ms) this uid has had a window keeping the device awake. |
| 6547 | */ |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 6548 | StopwatchTimer mTimerWindow; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6549 | |
| 6550 | /** |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 6551 | * How long (in ms) this uid has had a draw wake lock. |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 6552 | */ |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 6553 | StopwatchTimer mTimerDraw; |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 6554 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6555 | public Wakelock(BatteryStatsImpl bsi, Uid uid) { |
| 6556 | mBsi = bsi; |
| 6557 | mUid = uid; |
| 6558 | } |
| 6559 | |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 6560 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6561 | * Reads a possibly null Timer from a Parcel. The timer is associated with the |
| 6562 | * proper timer pool from the given BatteryStatsImpl object. |
| 6563 | * |
| 6564 | * @param in the Parcel to be read from. |
| 6565 | * return a new Timer, or null. |
| 6566 | */ |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 6567 | private StopwatchTimer readTimerFromParcel(int type, ArrayList<StopwatchTimer> pool, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6568 | TimeBase timeBase, Parcel in) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6569 | if (in.readInt() == 0) { |
| 6570 | return null; |
| 6571 | } |
| 6572 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6573 | 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] | 6574 | } |
| 6575 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6576 | boolean reset() { |
| 6577 | boolean wlactive = false; |
| 6578 | if (mTimerFull != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6579 | wlactive |= !mTimerFull.reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6580 | } |
| 6581 | if (mTimerPartial != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6582 | wlactive |= !mTimerPartial.reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6583 | } |
| 6584 | if (mTimerWindow != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6585 | wlactive |= !mTimerWindow.reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6586 | } |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 6587 | if (mTimerDraw != null) { |
| 6588 | wlactive |= !mTimerDraw.reset(false); |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 6589 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6590 | if (!wlactive) { |
| 6591 | if (mTimerFull != null) { |
| 6592 | mTimerFull.detach(); |
| 6593 | mTimerFull = null; |
| 6594 | } |
| 6595 | if (mTimerPartial != null) { |
| 6596 | mTimerPartial.detach(); |
| 6597 | mTimerPartial = null; |
| 6598 | } |
| 6599 | if (mTimerWindow != null) { |
| 6600 | mTimerWindow.detach(); |
| 6601 | mTimerWindow = null; |
| 6602 | } |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 6603 | if (mTimerDraw != null) { |
| 6604 | mTimerDraw.detach(); |
| 6605 | mTimerDraw = null; |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 6606 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6607 | } |
| 6608 | return !wlactive; |
| 6609 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6610 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6611 | void readFromParcelLocked(TimeBase timeBase, TimeBase screenOffTimeBase, Parcel in) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6612 | mTimerPartial = readTimerFromParcel(WAKE_TYPE_PARTIAL, |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6613 | mBsi.mPartialTimers, screenOffTimeBase, in); |
| 6614 | mTimerFull = readTimerFromParcel(WAKE_TYPE_FULL, mBsi.mFullTimers, timeBase, in); |
| 6615 | mTimerWindow = readTimerFromParcel(WAKE_TYPE_WINDOW, mBsi.mWindowTimers, timeBase, in); |
| 6616 | mTimerDraw = readTimerFromParcel(WAKE_TYPE_DRAW, mBsi.mDrawTimers, timeBase, in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6617 | } |
| 6618 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6619 | void writeToParcelLocked(Parcel out, long elapsedRealtimeUs) { |
| 6620 | Timer.writeTimerToParcel(out, mTimerPartial, elapsedRealtimeUs); |
| 6621 | Timer.writeTimerToParcel(out, mTimerFull, elapsedRealtimeUs); |
| 6622 | Timer.writeTimerToParcel(out, mTimerWindow, elapsedRealtimeUs); |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 6623 | Timer.writeTimerToParcel(out, mTimerDraw, elapsedRealtimeUs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6624 | } |
| 6625 | |
| 6626 | @Override |
| 6627 | public Timer getWakeTime(int type) { |
| 6628 | switch (type) { |
| 6629 | case WAKE_TYPE_FULL: return mTimerFull; |
| 6630 | case WAKE_TYPE_PARTIAL: return mTimerPartial; |
| 6631 | case WAKE_TYPE_WINDOW: return mTimerWindow; |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 6632 | case WAKE_TYPE_DRAW: return mTimerDraw; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6633 | default: throw new IllegalArgumentException("type = " + type); |
| 6634 | } |
| 6635 | } |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 6636 | |
| 6637 | public StopwatchTimer getStopwatchTimer(int type) { |
| 6638 | StopwatchTimer t; |
| 6639 | switch (type) { |
| 6640 | case WAKE_TYPE_PARTIAL: |
| 6641 | t = mTimerPartial; |
| 6642 | if (t == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6643 | t = new StopwatchTimer(mBsi.mClocks, mUid, WAKE_TYPE_PARTIAL, |
| 6644 | mBsi.mPartialTimers, mBsi.mOnBatteryScreenOffTimeBase); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 6645 | mTimerPartial = t; |
| 6646 | } |
| 6647 | return t; |
| 6648 | case WAKE_TYPE_FULL: |
| 6649 | t = mTimerFull; |
| 6650 | if (t == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6651 | t = new StopwatchTimer(mBsi.mClocks, mUid, WAKE_TYPE_FULL, |
| 6652 | mBsi.mFullTimers, mBsi.mOnBatteryTimeBase); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 6653 | mTimerFull = t; |
| 6654 | } |
| 6655 | return t; |
| 6656 | case WAKE_TYPE_WINDOW: |
| 6657 | t = mTimerWindow; |
| 6658 | if (t == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6659 | t = new StopwatchTimer(mBsi.mClocks, mUid, WAKE_TYPE_WINDOW, |
| 6660 | mBsi.mWindowTimers, mBsi.mOnBatteryTimeBase); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 6661 | mTimerWindow = t; |
| 6662 | } |
| 6663 | return t; |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 6664 | case WAKE_TYPE_DRAW: |
| 6665 | t = mTimerDraw; |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 6666 | if (t == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6667 | t = new StopwatchTimer(mBsi.mClocks, mUid, WAKE_TYPE_DRAW, |
| 6668 | mBsi.mDrawTimers, mBsi.mOnBatteryTimeBase); |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 6669 | mTimerDraw = t; |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 6670 | } |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 6671 | return t; |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 6672 | default: |
| 6673 | throw new IllegalArgumentException("type=" + type); |
| 6674 | } |
| 6675 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6676 | } |
| 6677 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6678 | public static class Sensor extends BatteryStats.Uid.Sensor { |
| 6679 | /** |
| 6680 | * BatteryStatsImpl that we are associated with. |
| 6681 | */ |
| 6682 | protected BatteryStatsImpl mBsi; |
| 6683 | |
| 6684 | /** |
| 6685 | * BatteryStatsImpl that we are associated with. |
| 6686 | */ |
| 6687 | protected Uid mUid; |
| 6688 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6689 | final int mHandle; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 6690 | StopwatchTimer mTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6691 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6692 | public Sensor(BatteryStatsImpl bsi, Uid uid, int handle) { |
| 6693 | mBsi = bsi; |
| 6694 | mUid = uid; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6695 | mHandle = handle; |
| 6696 | } |
| 6697 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6698 | private StopwatchTimer readTimerFromParcel(TimeBase timeBase, Parcel in) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6699 | if (in.readInt() == 0) { |
| 6700 | return null; |
| 6701 | } |
| 6702 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6703 | ArrayList<StopwatchTimer> pool = mBsi.mSensorTimers.get(mHandle); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6704 | if (pool == null) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 6705 | pool = new ArrayList<StopwatchTimer>(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6706 | mBsi.mSensorTimers.put(mHandle, pool); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6707 | } |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6708 | return new StopwatchTimer(mBsi.mClocks, mUid, 0, pool, timeBase, in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6709 | } |
| 6710 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6711 | boolean reset() { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6712 | if (mTimer.reset(true)) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6713 | mTimer = null; |
| 6714 | return true; |
| 6715 | } |
| 6716 | return false; |
| 6717 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6718 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6719 | void readFromParcelLocked(TimeBase timeBase, Parcel in) { |
| 6720 | mTimer = readTimerFromParcel(timeBase, in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6721 | } |
| 6722 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6723 | void writeToParcelLocked(Parcel out, long elapsedRealtimeUs) { |
| 6724 | Timer.writeTimerToParcel(out, mTimer, elapsedRealtimeUs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6725 | } |
| 6726 | |
| 6727 | @Override |
| 6728 | public Timer getSensorTime() { |
| 6729 | return mTimer; |
| 6730 | } |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 6731 | |
| 6732 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6733 | public int getHandle() { |
| 6734 | return mHandle; |
| 6735 | } |
| 6736 | } |
| 6737 | |
| 6738 | /** |
| 6739 | * The statistics associated with a particular process. |
| 6740 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6741 | public static class Proc extends BatteryStats.Uid.Proc implements TimeBaseObs { |
| 6742 | /** |
| 6743 | * BatteryStatsImpl that we are associated with. |
| 6744 | */ |
| 6745 | protected BatteryStatsImpl mBsi; |
| 6746 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6747 | /** |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 6748 | * The name of this process. |
| 6749 | */ |
| 6750 | final String mName; |
| 6751 | |
| 6752 | /** |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 6753 | * Remains true until removed from the stats. |
| 6754 | */ |
| 6755 | boolean mActive = true; |
| 6756 | |
| 6757 | /** |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 6758 | * Total time (in ms) spent executing in user code. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6759 | */ |
| 6760 | long mUserTime; |
| 6761 | |
| 6762 | /** |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 6763 | * Total time (in ms) spent executing in kernel code. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6764 | */ |
| 6765 | long mSystemTime; |
| 6766 | |
| 6767 | /** |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 6768 | * Amount of time (in ms) the process was running in the foreground. |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 6769 | */ |
| 6770 | long mForegroundTime; |
| 6771 | |
| 6772 | /** |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 6773 | * Number of times the process has been started. |
| 6774 | */ |
| 6775 | int mStarts; |
| 6776 | |
| 6777 | /** |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 6778 | * Number of times the process has crashed. |
| 6779 | */ |
| 6780 | int mNumCrashes; |
| 6781 | |
| 6782 | /** |
| 6783 | * Number of times the process has had an ANR. |
| 6784 | */ |
| 6785 | int mNumAnrs; |
| 6786 | |
| 6787 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6788 | * The amount of user time loaded from a previous save. |
| 6789 | */ |
| 6790 | long mLoadedUserTime; |
| 6791 | |
| 6792 | /** |
| 6793 | * The amount of system time loaded from a previous save. |
| 6794 | */ |
| 6795 | long mLoadedSystemTime; |
| 6796 | |
| 6797 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 6798 | * The amount of foreground time loaded from a previous save. |
| 6799 | */ |
| 6800 | long mLoadedForegroundTime; |
| 6801 | |
| 6802 | /** |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 6803 | * The number of times the process has started from a previous save. |
| 6804 | */ |
| 6805 | int mLoadedStarts; |
| 6806 | |
| 6807 | /** |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 6808 | * 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] | 6809 | */ |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 6810 | int mLoadedNumCrashes; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6811 | |
| 6812 | /** |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 6813 | * 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] | 6814 | */ |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 6815 | int mLoadedNumAnrs; |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 6816 | |
| 6817 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6818 | * The amount of user time when last unplugged. |
| 6819 | */ |
| 6820 | long mUnpluggedUserTime; |
| 6821 | |
| 6822 | /** |
| 6823 | * The amount of system time when last unplugged. |
| 6824 | */ |
| 6825 | long mUnpluggedSystemTime; |
| 6826 | |
| 6827 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 6828 | * The amount of foreground time since unplugged. |
| 6829 | */ |
| 6830 | long mUnpluggedForegroundTime; |
| 6831 | |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 6832 | /** |
| 6833 | * The number of times the process has started before unplugged. |
| 6834 | */ |
| 6835 | int mUnpluggedStarts; |
| 6836 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 6837 | /** |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 6838 | * Number of times the process has crashed before unplugged. |
| 6839 | */ |
| 6840 | int mUnpluggedNumCrashes; |
| 6841 | |
| 6842 | /** |
| 6843 | * Number of times the process has had an ANR before unplugged. |
| 6844 | */ |
| 6845 | int mUnpluggedNumAnrs; |
| 6846 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 6847 | ArrayList<ExcessivePower> mExcessivePower; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 6848 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6849 | public Proc(BatteryStatsImpl bsi, String name) { |
| 6850 | mBsi = bsi; |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 6851 | mName = name; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6852 | mBsi.mOnBatteryTimeBase.add(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6853 | } |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 6854 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6855 | public void onTimeStarted(long elapsedRealtime, long baseUptime, long baseRealtime) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6856 | mUnpluggedUserTime = mUserTime; |
| 6857 | mUnpluggedSystemTime = mSystemTime; |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 6858 | mUnpluggedForegroundTime = mForegroundTime; |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 6859 | mUnpluggedStarts = mStarts; |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 6860 | mUnpluggedNumCrashes = mNumCrashes; |
| 6861 | mUnpluggedNumAnrs = mNumAnrs; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6862 | } |
| 6863 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6864 | public void onTimeStopped(long elapsedRealtime, long baseUptime, long baseRealtime) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6865 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6866 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6867 | void detach() { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 6868 | mActive = false; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6869 | mBsi.mOnBatteryTimeBase.remove(this); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6870 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6871 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 6872 | public int countExcessivePowers() { |
| 6873 | return mExcessivePower != null ? mExcessivePower.size() : 0; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 6874 | } |
| 6875 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 6876 | public ExcessivePower getExcessivePower(int i) { |
| 6877 | if (mExcessivePower != null) { |
| 6878 | return mExcessivePower.get(i); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 6879 | } |
| 6880 | return null; |
| 6881 | } |
| 6882 | |
| 6883 | public void addExcessiveWake(long overTime, long usedTime) { |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 6884 | if (mExcessivePower == null) { |
| 6885 | mExcessivePower = new ArrayList<ExcessivePower>(); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 6886 | } |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 6887 | ExcessivePower ew = new ExcessivePower(); |
| 6888 | ew.type = ExcessivePower.TYPE_WAKE; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 6889 | ew.overTime = overTime; |
| 6890 | ew.usedTime = usedTime; |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 6891 | mExcessivePower.add(ew); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 6892 | } |
| 6893 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 6894 | public void addExcessiveCpu(long overTime, long usedTime) { |
| 6895 | if (mExcessivePower == null) { |
| 6896 | mExcessivePower = new ArrayList<ExcessivePower>(); |
| 6897 | } |
| 6898 | ExcessivePower ew = new ExcessivePower(); |
| 6899 | ew.type = ExcessivePower.TYPE_CPU; |
| 6900 | ew.overTime = overTime; |
| 6901 | ew.usedTime = usedTime; |
| 6902 | mExcessivePower.add(ew); |
| 6903 | } |
| 6904 | |
| 6905 | void writeExcessivePowerToParcelLocked(Parcel out) { |
| 6906 | if (mExcessivePower == null) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 6907 | out.writeInt(0); |
| 6908 | return; |
| 6909 | } |
| 6910 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 6911 | final int N = mExcessivePower.size(); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 6912 | out.writeInt(N); |
| 6913 | for (int i=0; i<N; i++) { |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 6914 | ExcessivePower ew = mExcessivePower.get(i); |
| 6915 | out.writeInt(ew.type); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 6916 | out.writeLong(ew.overTime); |
| 6917 | out.writeLong(ew.usedTime); |
| 6918 | } |
| 6919 | } |
| 6920 | |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 6921 | void readExcessivePowerFromParcelLocked(Parcel in) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 6922 | final int N = in.readInt(); |
| 6923 | if (N == 0) { |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 6924 | mExcessivePower = null; |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 6925 | return; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 6926 | } |
| 6927 | |
Dianne Hackborn | 7b9c56f | 2010-12-07 11:14:53 -0800 | [diff] [blame] | 6928 | if (N > 10000) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 6929 | throw new ParcelFormatException( |
| 6930 | "File corrupt: too many excessive power entries " + N); |
Dianne Hackborn | 7b9c56f | 2010-12-07 11:14:53 -0800 | [diff] [blame] | 6931 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 6932 | |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 6933 | mExcessivePower = new ArrayList<>(); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 6934 | for (int i=0; i<N; i++) { |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 6935 | ExcessivePower ew = new ExcessivePower(); |
| 6936 | ew.type = in.readInt(); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 6937 | ew.overTime = in.readLong(); |
| 6938 | ew.usedTime = in.readLong(); |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 6939 | mExcessivePower.add(ew); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 6940 | } |
| 6941 | } |
| 6942 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6943 | void writeToParcelLocked(Parcel out) { |
| 6944 | out.writeLong(mUserTime); |
| 6945 | out.writeLong(mSystemTime); |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 6946 | out.writeLong(mForegroundTime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6947 | out.writeInt(mStarts); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 6948 | out.writeInt(mNumCrashes); |
| 6949 | out.writeInt(mNumAnrs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6950 | out.writeLong(mLoadedUserTime); |
| 6951 | out.writeLong(mLoadedSystemTime); |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 6952 | out.writeLong(mLoadedForegroundTime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6953 | out.writeInt(mLoadedStarts); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 6954 | out.writeInt(mLoadedNumCrashes); |
| 6955 | out.writeInt(mLoadedNumAnrs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6956 | out.writeLong(mUnpluggedUserTime); |
| 6957 | out.writeLong(mUnpluggedSystemTime); |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 6958 | out.writeLong(mUnpluggedForegroundTime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6959 | out.writeInt(mUnpluggedStarts); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 6960 | out.writeInt(mUnpluggedNumCrashes); |
| 6961 | out.writeInt(mUnpluggedNumAnrs); |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 6962 | writeExcessivePowerToParcelLocked(out); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6963 | } |
| 6964 | |
| 6965 | void readFromParcelLocked(Parcel in) { |
| 6966 | mUserTime = in.readLong(); |
| 6967 | mSystemTime = in.readLong(); |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 6968 | mForegroundTime = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6969 | mStarts = in.readInt(); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 6970 | mNumCrashes = in.readInt(); |
| 6971 | mNumAnrs = in.readInt(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6972 | mLoadedUserTime = in.readLong(); |
| 6973 | mLoadedSystemTime = in.readLong(); |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 6974 | mLoadedForegroundTime = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6975 | mLoadedStarts = in.readInt(); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 6976 | mLoadedNumCrashes = in.readInt(); |
| 6977 | mLoadedNumAnrs = in.readInt(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6978 | mUnpluggedUserTime = in.readLong(); |
| 6979 | mUnpluggedSystemTime = in.readLong(); |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 6980 | mUnpluggedForegroundTime = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6981 | mUnpluggedStarts = in.readInt(); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 6982 | mUnpluggedNumCrashes = in.readInt(); |
| 6983 | mUnpluggedNumAnrs = in.readInt(); |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 6984 | readExcessivePowerFromParcelLocked(in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6985 | } |
| 6986 | |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 6987 | public void addCpuTimeLocked(int utime, int stime) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6988 | mUserTime += utime; |
| 6989 | mSystemTime += stime; |
| 6990 | } |
| 6991 | |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 6992 | public void addForegroundTimeLocked(long ttime) { |
| 6993 | mForegroundTime += ttime; |
| 6994 | } |
| 6995 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6996 | public void incStartsLocked() { |
| 6997 | mStarts++; |
| 6998 | } |
| 6999 | |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 7000 | public void incNumCrashesLocked() { |
| 7001 | mNumCrashes++; |
| 7002 | } |
| 7003 | |
| 7004 | public void incNumAnrsLocked() { |
| 7005 | mNumAnrs++; |
| 7006 | } |
| 7007 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7008 | @Override |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 7009 | public boolean isActive() { |
| 7010 | return mActive; |
| 7011 | } |
| 7012 | |
| 7013 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7014 | public long getUserTime(int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 7015 | long val = mUserTime; |
| 7016 | if (which == STATS_CURRENT) { |
| 7017 | val -= mLoadedUserTime; |
| 7018 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 7019 | val -= mUnpluggedUserTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7020 | } |
| 7021 | return val; |
| 7022 | } |
| 7023 | |
| 7024 | @Override |
| 7025 | public long getSystemTime(int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 7026 | long val = mSystemTime; |
| 7027 | if (which == STATS_CURRENT) { |
| 7028 | val -= mLoadedSystemTime; |
| 7029 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 7030 | val -= mUnpluggedSystemTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7031 | } |
| 7032 | return val; |
| 7033 | } |
| 7034 | |
| 7035 | @Override |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 7036 | public long getForegroundTime(int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 7037 | long val = mForegroundTime; |
| 7038 | if (which == STATS_CURRENT) { |
| 7039 | val -= mLoadedForegroundTime; |
| 7040 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 7041 | val -= mUnpluggedForegroundTime; |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 7042 | } |
| 7043 | return val; |
| 7044 | } |
| 7045 | |
| 7046 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7047 | public int getStarts(int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 7048 | int val = mStarts; |
| 7049 | if (which == STATS_CURRENT) { |
| 7050 | val -= mLoadedStarts; |
| 7051 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 7052 | val -= mUnpluggedStarts; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7053 | } |
| 7054 | return val; |
| 7055 | } |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 7056 | |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 7057 | @Override |
| 7058 | public int getNumCrashes(int which) { |
| 7059 | int val = mNumCrashes; |
| 7060 | if (which == STATS_CURRENT) { |
| 7061 | val -= mLoadedNumCrashes; |
| 7062 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 7063 | val -= mUnpluggedNumCrashes; |
| 7064 | } |
| 7065 | return val; |
| 7066 | } |
| 7067 | |
| 7068 | @Override |
| 7069 | public int getNumAnrs(int which) { |
| 7070 | int val = mNumAnrs; |
| 7071 | if (which == STATS_CURRENT) { |
| 7072 | val -= mLoadedNumAnrs; |
| 7073 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 7074 | val -= mUnpluggedNumAnrs; |
| 7075 | } |
| 7076 | return val; |
| 7077 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7078 | } |
| 7079 | |
| 7080 | /** |
| 7081 | * The statistics associated with a particular package. |
| 7082 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7083 | public static class Pkg extends BatteryStats.Uid.Pkg implements TimeBaseObs { |
| 7084 | /** |
| 7085 | * BatteryStatsImpl that we are associated with. |
| 7086 | */ |
| 7087 | protected BatteryStatsImpl mBsi; |
| 7088 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7089 | /** |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 7090 | * 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] | 7091 | */ |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 7092 | ArrayMap<String, Counter> mWakeupAlarms = new ArrayMap<>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7093 | |
| 7094 | /** |
| 7095 | * The statics we have collected for this package's services. |
| 7096 | */ |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 7097 | final ArrayMap<String, Serv> mServiceStats = new ArrayMap<>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7098 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7099 | public Pkg(BatteryStatsImpl bsi) { |
| 7100 | mBsi = bsi; |
| 7101 | mBsi.mOnBatteryScreenOffTimeBase.add(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7102 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7103 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7104 | public void onTimeStarted(long elapsedRealtime, long baseUptime, long baseRealtime) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7105 | } |
| 7106 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7107 | public void onTimeStopped(long elapsedRealtime, long baseUptime, long baseRealtime) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7108 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7109 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7110 | void detach() { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7111 | mBsi.mOnBatteryScreenOffTimeBase.remove(this); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7112 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7113 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7114 | void readFromParcelLocked(Parcel in) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 7115 | int numWA = in.readInt(); |
| 7116 | mWakeupAlarms.clear(); |
| 7117 | for (int i=0; i<numWA; i++) { |
| 7118 | String tag = in.readString(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7119 | mWakeupAlarms.put(tag, new Counter(mBsi.mOnBatteryTimeBase, in)); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 7120 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7121 | |
| 7122 | int numServs = in.readInt(); |
| 7123 | mServiceStats.clear(); |
| 7124 | for (int m = 0; m < numServs; m++) { |
| 7125 | String serviceName = in.readString(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7126 | Uid.Pkg.Serv serv = new Serv(mBsi); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7127 | mServiceStats.put(serviceName, serv); |
| 7128 | |
| 7129 | serv.readFromParcelLocked(in); |
| 7130 | } |
| 7131 | } |
| 7132 | |
| 7133 | void writeToParcelLocked(Parcel out) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 7134 | int numWA = mWakeupAlarms.size(); |
| 7135 | out.writeInt(numWA); |
| 7136 | for (int i=0; i<numWA; i++) { |
| 7137 | out.writeString(mWakeupAlarms.keyAt(i)); |
| 7138 | mWakeupAlarms.valueAt(i).writeToParcel(out); |
| 7139 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7140 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 7141 | final int NS = mServiceStats.size(); |
| 7142 | out.writeInt(NS); |
| 7143 | for (int i=0; i<NS; i++) { |
| 7144 | out.writeString(mServiceStats.keyAt(i)); |
| 7145 | Uid.Pkg.Serv serv = mServiceStats.valueAt(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7146 | serv.writeToParcelLocked(out); |
| 7147 | } |
| 7148 | } |
| 7149 | |
| 7150 | @Override |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 7151 | public ArrayMap<String, ? extends BatteryStats.Counter> getWakeupAlarmStats() { |
| 7152 | return mWakeupAlarms; |
| 7153 | } |
| 7154 | |
| 7155 | public void noteWakeupAlarmLocked(String tag) { |
| 7156 | Counter c = mWakeupAlarms.get(tag); |
| 7157 | if (c == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7158 | c = new Counter(mBsi.mOnBatteryTimeBase); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 7159 | mWakeupAlarms.put(tag, c); |
| 7160 | } |
| 7161 | c.stepAtomic(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7162 | } |
| 7163 | |
| 7164 | @Override |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 7165 | public ArrayMap<String, ? extends BatteryStats.Uid.Pkg.Serv> getServiceStats() { |
| 7166 | return mServiceStats; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7167 | } |
| 7168 | |
| 7169 | /** |
| 7170 | * The statistics associated with a particular service. |
| 7171 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7172 | public static class Serv extends BatteryStats.Uid.Pkg.Serv implements TimeBaseObs { |
| 7173 | /** |
| 7174 | * BatteryStatsImpl that we are associated with. |
| 7175 | */ |
| 7176 | protected BatteryStatsImpl mBsi; |
| 7177 | |
| 7178 | /** |
| 7179 | * The android package in which this service resides. |
| 7180 | */ |
| 7181 | protected Pkg mPkg; |
| 7182 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7183 | /** |
| 7184 | * Total time (ms in battery uptime) the service has been left started. |
| 7185 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7186 | protected long mStartTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7187 | |
| 7188 | /** |
| 7189 | * If service has been started and not yet stopped, this is |
| 7190 | * when it was started. |
| 7191 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7192 | protected long mRunningSince; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7193 | |
| 7194 | /** |
| 7195 | * True if we are currently running. |
| 7196 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7197 | protected boolean mRunning; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7198 | |
| 7199 | /** |
| 7200 | * Total number of times startService() has been called. |
| 7201 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7202 | protected int mStarts; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7203 | |
| 7204 | /** |
| 7205 | * Total time (ms in battery uptime) the service has been left launched. |
| 7206 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7207 | protected long mLaunchedTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7208 | |
| 7209 | /** |
| 7210 | * If service has been launched and not yet exited, this is |
| 7211 | * when it was launched (ms in battery uptime). |
| 7212 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7213 | protected long mLaunchedSince; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7214 | |
| 7215 | /** |
| 7216 | * True if we are currently launched. |
| 7217 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7218 | protected boolean mLaunched; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7219 | |
| 7220 | /** |
| 7221 | * Total number times the service has been launched. |
| 7222 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7223 | protected int mLaunches; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7224 | |
| 7225 | /** |
| 7226 | * The amount of time spent started loaded from a previous save |
| 7227 | * (ms in battery uptime). |
| 7228 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7229 | protected long mLoadedStartTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7230 | |
| 7231 | /** |
| 7232 | * The number of starts loaded from a previous save. |
| 7233 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7234 | protected int mLoadedStarts; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7235 | |
| 7236 | /** |
| 7237 | * The number of launches loaded from a previous save. |
| 7238 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7239 | protected int mLoadedLaunches; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7240 | |
| 7241 | /** |
| 7242 | * The amount of time spent started as of the last run (ms |
| 7243 | * in battery uptime). |
| 7244 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7245 | protected long mLastStartTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7246 | |
| 7247 | /** |
| 7248 | * The number of starts as of the last run. |
| 7249 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7250 | protected int mLastStarts; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7251 | |
| 7252 | /** |
| 7253 | * The number of launches as of the last run. |
| 7254 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7255 | protected int mLastLaunches; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7256 | |
| 7257 | /** |
| 7258 | * The amount of time spent started when last unplugged (ms |
| 7259 | * in battery uptime). |
| 7260 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7261 | protected long mUnpluggedStartTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7262 | |
| 7263 | /** |
| 7264 | * The number of starts when last unplugged. |
| 7265 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7266 | protected int mUnpluggedStarts; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7267 | |
| 7268 | /** |
| 7269 | * The number of launches when last unplugged. |
| 7270 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7271 | protected int mUnpluggedLaunches; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7272 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7273 | /** |
| 7274 | * Construct a Serv. Also adds it to the on-battery time base as a listener. |
| 7275 | */ |
| 7276 | public Serv(BatteryStatsImpl bsi) { |
| 7277 | mBsi = bsi; |
| 7278 | mBsi.mOnBatteryTimeBase.add(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7279 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7280 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7281 | public void onTimeStarted(long elapsedRealtime, long baseUptime, |
| 7282 | long baseRealtime) { |
| 7283 | mUnpluggedStartTime = getStartTimeToNowLocked(baseUptime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7284 | mUnpluggedStarts = mStarts; |
| 7285 | mUnpluggedLaunches = mLaunches; |
| 7286 | } |
| 7287 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7288 | public void onTimeStopped(long elapsedRealtime, long baseUptime, |
| 7289 | long baseRealtime) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7290 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7291 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7292 | /** |
| 7293 | * Remove this Serv as a listener from the time base. |
| 7294 | */ |
| 7295 | public void detach() { |
| 7296 | mBsi.mOnBatteryTimeBase.remove(this); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7297 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7298 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7299 | public void readFromParcelLocked(Parcel in) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7300 | mStartTime = in.readLong(); |
| 7301 | mRunningSince = in.readLong(); |
| 7302 | mRunning = in.readInt() != 0; |
| 7303 | mStarts = in.readInt(); |
| 7304 | mLaunchedTime = in.readLong(); |
| 7305 | mLaunchedSince = in.readLong(); |
| 7306 | mLaunched = in.readInt() != 0; |
| 7307 | mLaunches = in.readInt(); |
| 7308 | mLoadedStartTime = in.readLong(); |
| 7309 | mLoadedStarts = in.readInt(); |
| 7310 | mLoadedLaunches = in.readInt(); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 7311 | mLastStartTime = 0; |
| 7312 | mLastStarts = 0; |
| 7313 | mLastLaunches = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7314 | mUnpluggedStartTime = in.readLong(); |
| 7315 | mUnpluggedStarts = in.readInt(); |
| 7316 | mUnpluggedLaunches = in.readInt(); |
| 7317 | } |
| 7318 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7319 | public void writeToParcelLocked(Parcel out) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7320 | out.writeLong(mStartTime); |
| 7321 | out.writeLong(mRunningSince); |
| 7322 | out.writeInt(mRunning ? 1 : 0); |
| 7323 | out.writeInt(mStarts); |
| 7324 | out.writeLong(mLaunchedTime); |
| 7325 | out.writeLong(mLaunchedSince); |
| 7326 | out.writeInt(mLaunched ? 1 : 0); |
| 7327 | out.writeInt(mLaunches); |
| 7328 | out.writeLong(mLoadedStartTime); |
| 7329 | out.writeInt(mLoadedStarts); |
| 7330 | out.writeInt(mLoadedLaunches); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7331 | out.writeLong(mUnpluggedStartTime); |
| 7332 | out.writeInt(mUnpluggedStarts); |
| 7333 | out.writeInt(mUnpluggedLaunches); |
| 7334 | } |
| 7335 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7336 | public long getLaunchTimeToNowLocked(long batteryUptime) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7337 | if (!mLaunched) return mLaunchedTime; |
| 7338 | return mLaunchedTime + batteryUptime - mLaunchedSince; |
| 7339 | } |
| 7340 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7341 | public long getStartTimeToNowLocked(long batteryUptime) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7342 | if (!mRunning) return mStartTime; |
| 7343 | return mStartTime + batteryUptime - mRunningSince; |
| 7344 | } |
| 7345 | |
| 7346 | public void startLaunchedLocked() { |
| 7347 | if (!mLaunched) { |
| 7348 | mLaunches++; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7349 | mLaunchedSince = mBsi.getBatteryUptimeLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7350 | mLaunched = true; |
| 7351 | } |
| 7352 | } |
| 7353 | |
| 7354 | public void stopLaunchedLocked() { |
| 7355 | if (mLaunched) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7356 | long time = mBsi.getBatteryUptimeLocked() - mLaunchedSince; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7357 | if (time > 0) { |
| 7358 | mLaunchedTime += time; |
| 7359 | } else { |
| 7360 | mLaunches--; |
| 7361 | } |
| 7362 | mLaunched = false; |
| 7363 | } |
| 7364 | } |
| 7365 | |
| 7366 | public void startRunningLocked() { |
| 7367 | if (!mRunning) { |
| 7368 | mStarts++; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7369 | mRunningSince = mBsi.getBatteryUptimeLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7370 | mRunning = true; |
| 7371 | } |
| 7372 | } |
| 7373 | |
| 7374 | public void stopRunningLocked() { |
| 7375 | if (mRunning) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7376 | long time = mBsi.getBatteryUptimeLocked() - mRunningSince; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7377 | if (time > 0) { |
| 7378 | mStartTime += time; |
| 7379 | } else { |
| 7380 | mStarts--; |
| 7381 | } |
| 7382 | mRunning = false; |
| 7383 | } |
| 7384 | } |
| 7385 | |
| 7386 | public BatteryStatsImpl getBatteryStats() { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7387 | return mBsi; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7388 | } |
| 7389 | |
| 7390 | @Override |
| 7391 | public int getLaunches(int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 7392 | int val = mLaunches; |
| 7393 | if (which == STATS_CURRENT) { |
| 7394 | val -= mLoadedLaunches; |
| 7395 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 7396 | val -= mUnpluggedLaunches; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7397 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7398 | return val; |
| 7399 | } |
| 7400 | |
| 7401 | @Override |
| 7402 | public long getStartTime(long now, int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 7403 | long val = getStartTimeToNowLocked(now); |
| 7404 | if (which == STATS_CURRENT) { |
| 7405 | val -= mLoadedStartTime; |
| 7406 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 7407 | val -= mUnpluggedStartTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7408 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7409 | return val; |
| 7410 | } |
| 7411 | |
| 7412 | @Override |
| 7413 | public int getStarts(int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 7414 | int val = mStarts; |
| 7415 | if (which == STATS_CURRENT) { |
| 7416 | val -= mLoadedStarts; |
| 7417 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 7418 | val -= mUnpluggedStarts; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7419 | } |
| 7420 | |
| 7421 | return val; |
| 7422 | } |
| 7423 | } |
| 7424 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7425 | final Serv newServiceStatsLocked() { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7426 | return new Serv(mBsi); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7427 | } |
| 7428 | } |
| 7429 | |
| 7430 | /** |
| 7431 | * Retrieve the statistics object for a particular process, creating |
| 7432 | * if needed. |
| 7433 | */ |
| 7434 | public Proc getProcessStatsLocked(String name) { |
| 7435 | Proc ps = mProcessStats.get(name); |
| 7436 | if (ps == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7437 | ps = new Proc(mBsi, name); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7438 | mProcessStats.put(name, ps); |
| 7439 | } |
| 7440 | |
| 7441 | return ps; |
| 7442 | } |
| 7443 | |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 7444 | public void updateUidProcessStateLocked(int procState) { |
| 7445 | int uidRunningState; |
| 7446 | if (procState == ActivityManager.PROCESS_STATE_NONEXISTENT) { |
| 7447 | uidRunningState = ActivityManager.PROCESS_STATE_NONEXISTENT; |
| 7448 | } else if (procState == ActivityManager.PROCESS_STATE_TOP) { |
| 7449 | uidRunningState = PROCESS_STATE_TOP; |
| 7450 | } else if (procState <= ActivityManager.PROCESS_STATE_FOREGROUND_SERVICE) { |
| 7451 | // Persistent and other foreground states go here. |
| 7452 | uidRunningState = PROCESS_STATE_FOREGROUND_SERVICE; |
| 7453 | } else if (procState <= ActivityManager.PROCESS_STATE_TOP_SLEEPING) { |
| 7454 | uidRunningState = PROCESS_STATE_TOP_SLEEPING; |
| 7455 | } else if (procState <= ActivityManager.PROCESS_STATE_IMPORTANT_FOREGROUND) { |
| 7456 | // Persistent and other foreground states go here. |
| 7457 | uidRunningState = PROCESS_STATE_FOREGROUND; |
| 7458 | } else if (procState <= ActivityManager.PROCESS_STATE_RECEIVER) { |
| 7459 | uidRunningState = PROCESS_STATE_BACKGROUND; |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 7460 | } else { |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 7461 | uidRunningState = PROCESS_STATE_CACHED; |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 7462 | } |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 7463 | |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 7464 | if (mProcessState == uidRunningState) return; |
| 7465 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7466 | final long elapsedRealtime = mBsi.mClocks.elapsedRealtime(); |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 7467 | |
| 7468 | if (mProcessState != ActivityManager.PROCESS_STATE_NONEXISTENT) { |
| 7469 | mProcessStateTimer[mProcessState].stopRunningLocked(elapsedRealtime); |
| 7470 | } |
| 7471 | mProcessState = uidRunningState; |
| 7472 | if (uidRunningState != ActivityManager.PROCESS_STATE_NONEXISTENT) { |
| 7473 | if (mProcessStateTimer[uidRunningState] == null) { |
| 7474 | makeProcessState(uidRunningState, null); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 7475 | } |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 7476 | mProcessStateTimer[uidRunningState].startRunningLocked(elapsedRealtime); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 7477 | } |
| 7478 | } |
| 7479 | |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 7480 | public SparseArray<? extends Pid> getPidStats() { |
| 7481 | return mPids; |
| 7482 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7483 | |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 7484 | public Pid getPidStatsLocked(int pid) { |
| 7485 | Pid p = mPids.get(pid); |
| 7486 | if (p == null) { |
| 7487 | p = new Pid(); |
| 7488 | mPids.put(pid, p); |
| 7489 | } |
| 7490 | return p; |
| 7491 | } |
| 7492 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7493 | /** |
| 7494 | * Retrieve the statistics object for a particular service, creating |
| 7495 | * if needed. |
| 7496 | */ |
| 7497 | public Pkg getPackageStatsLocked(String name) { |
| 7498 | Pkg ps = mPackageStats.get(name); |
| 7499 | if (ps == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7500 | ps = new Pkg(mBsi); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7501 | mPackageStats.put(name, ps); |
| 7502 | } |
| 7503 | |
| 7504 | return ps; |
| 7505 | } |
| 7506 | |
| 7507 | /** |
| 7508 | * Retrieve the statistics object for a particular service, creating |
| 7509 | * if needed. |
| 7510 | */ |
| 7511 | public Pkg.Serv getServiceStatsLocked(String pkg, String serv) { |
| 7512 | Pkg ps = getPackageStatsLocked(pkg); |
| 7513 | Pkg.Serv ss = ps.mServiceStats.get(serv); |
| 7514 | if (ss == null) { |
| 7515 | ss = ps.newServiceStatsLocked(); |
| 7516 | ps.mServiceStats.put(serv, ss); |
| 7517 | } |
| 7518 | |
| 7519 | return ss; |
| 7520 | } |
| 7521 | |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 7522 | public void readSyncSummaryFromParcelLocked(String name, Parcel in) { |
| 7523 | StopwatchTimer timer = mSyncStats.instantiateObject(); |
| 7524 | timer.readSummaryFromParcelLocked(in); |
| 7525 | mSyncStats.add(name, timer); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 7526 | } |
| 7527 | |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 7528 | public void readJobSummaryFromParcelLocked(String name, Parcel in) { |
| 7529 | StopwatchTimer timer = mJobStats.instantiateObject(); |
| 7530 | timer.readSummaryFromParcelLocked(in); |
| 7531 | mJobStats.add(name, timer); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 7532 | } |
| 7533 | |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 7534 | public void readWakeSummaryFromParcelLocked(String wlName, Parcel in) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7535 | Wakelock wl = new Wakelock(mBsi, this); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 7536 | mWakelockStats.add(wlName, wl); |
| 7537 | if (in.readInt() != 0) { |
| 7538 | wl.getStopwatchTimer(WAKE_TYPE_FULL).readSummaryFromParcelLocked(in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7539 | } |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 7540 | if (in.readInt() != 0) { |
| 7541 | wl.getStopwatchTimer(WAKE_TYPE_PARTIAL).readSummaryFromParcelLocked(in); |
| 7542 | } |
| 7543 | if (in.readInt() != 0) { |
| 7544 | wl.getStopwatchTimer(WAKE_TYPE_WINDOW).readSummaryFromParcelLocked(in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7545 | } |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 7546 | if (in.readInt() != 0) { |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 7547 | wl.getStopwatchTimer(WAKE_TYPE_DRAW).readSummaryFromParcelLocked(in); |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 7548 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7549 | } |
| 7550 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 7551 | public StopwatchTimer getSensorTimerLocked(int sensor, boolean create) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7552 | Sensor se = mSensorStats.get(sensor); |
| 7553 | if (se == null) { |
| 7554 | if (!create) { |
| 7555 | return null; |
| 7556 | } |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7557 | se = new Sensor(mBsi, this, sensor); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7558 | mSensorStats.put(sensor, se); |
| 7559 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 7560 | StopwatchTimer t = se.mTimer; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7561 | if (t != null) { |
| 7562 | return t; |
| 7563 | } |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7564 | ArrayList<StopwatchTimer> timers = mBsi.mSensorTimers.get(sensor); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7565 | if (timers == null) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 7566 | timers = new ArrayList<StopwatchTimer>(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7567 | mBsi.mSensorTimers.put(sensor, timers); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7568 | } |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7569 | t = new StopwatchTimer(mBsi.mClocks, this, BatteryStats.SENSOR, timers, |
| 7570 | mBsi.mOnBatteryTimeBase); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7571 | se.mTimer = t; |
| 7572 | return t; |
| 7573 | } |
| 7574 | |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 7575 | public void noteStartSyncLocked(String name, long elapsedRealtimeMs) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 7576 | StopwatchTimer t = mSyncStats.startObject(name); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 7577 | if (t != null) { |
| 7578 | t.startRunningLocked(elapsedRealtimeMs); |
| 7579 | } |
| 7580 | } |
| 7581 | |
| 7582 | public void noteStopSyncLocked(String name, long elapsedRealtimeMs) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 7583 | StopwatchTimer t = mSyncStats.stopObject(name); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 7584 | if (t != null) { |
| 7585 | t.stopRunningLocked(elapsedRealtimeMs); |
| 7586 | } |
| 7587 | } |
| 7588 | |
| 7589 | public void noteStartJobLocked(String name, long elapsedRealtimeMs) { |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 7590 | StopwatchTimer t = mJobStats.startObject(name); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 7591 | if (t != null) { |
| 7592 | t.startRunningLocked(elapsedRealtimeMs); |
| 7593 | } |
| 7594 | } |
| 7595 | |
| 7596 | public void noteStopJobLocked(String name, long elapsedRealtimeMs) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 7597 | StopwatchTimer t = mJobStats.stopObject(name); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 7598 | if (t != null) { |
| 7599 | t.stopRunningLocked(elapsedRealtimeMs); |
| 7600 | } |
| 7601 | } |
| 7602 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7603 | public void noteStartWakeLocked(int pid, String name, int type, long elapsedRealtimeMs) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 7604 | Wakelock wl = mWakelockStats.startObject(name); |
| 7605 | if (wl != null) { |
| 7606 | wl.getStopwatchTimer(type).startRunningLocked(elapsedRealtimeMs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7607 | } |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 7608 | if (pid >= 0 && type == WAKE_TYPE_PARTIAL) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 7609 | Pid p = getPidStatsLocked(pid); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 7610 | if (p.mWakeNesting++ == 0) { |
| 7611 | p.mWakeStartMs = elapsedRealtimeMs; |
Dianne Hackborn | b8071d79 | 2010-09-09 16:45:15 -0700 | [diff] [blame] | 7612 | } |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 7613 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7614 | } |
| 7615 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7616 | public void noteStopWakeLocked(int pid, String name, int type, long elapsedRealtimeMs) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 7617 | Wakelock wl = mWakelockStats.stopObject(name); |
| 7618 | if (wl != null) { |
| 7619 | wl.getStopwatchTimer(type).stopRunningLocked(elapsedRealtimeMs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7620 | } |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 7621 | if (pid >= 0 && type == WAKE_TYPE_PARTIAL) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 7622 | Pid p = mPids.get(pid); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 7623 | if (p != null && p.mWakeNesting > 0) { |
| 7624 | if (p.mWakeNesting-- == 1) { |
| 7625 | p.mWakeSumMs += elapsedRealtimeMs - p.mWakeStartMs; |
| 7626 | p.mWakeStartMs = 0; |
| 7627 | } |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 7628 | } |
| 7629 | } |
| 7630 | } |
| 7631 | |
| 7632 | public void reportExcessiveWakeLocked(String proc, long overTime, long usedTime) { |
| 7633 | Proc p = getProcessStatsLocked(proc); |
| 7634 | if (p != null) { |
| 7635 | p.addExcessiveWake(overTime, usedTime); |
| 7636 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7637 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7638 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 7639 | public void reportExcessiveCpuLocked(String proc, long overTime, long usedTime) { |
| 7640 | Proc p = getProcessStatsLocked(proc); |
| 7641 | if (p != null) { |
| 7642 | p.addExcessiveCpu(overTime, usedTime); |
| 7643 | } |
| 7644 | } |
| 7645 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7646 | public void noteStartSensor(int sensor, long elapsedRealtimeMs) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 7647 | StopwatchTimer t = getSensorTimerLocked(sensor, true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7648 | if (t != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7649 | t.startRunningLocked(elapsedRealtimeMs); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7650 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7651 | } |
| 7652 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7653 | public void noteStopSensor(int sensor, long elapsedRealtimeMs) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7654 | // Don't create a timer if one doesn't already exist |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 7655 | StopwatchTimer t = getSensorTimerLocked(sensor, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7656 | if (t != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7657 | t.stopRunningLocked(elapsedRealtimeMs); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7658 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7659 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7660 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7661 | public void noteStartGps(long elapsedRealtimeMs) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 7662 | StopwatchTimer t = getSensorTimerLocked(Sensor.GPS, true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7663 | if (t != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7664 | t.startRunningLocked(elapsedRealtimeMs); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7665 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7666 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7667 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7668 | public void noteStopGps(long elapsedRealtimeMs) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 7669 | StopwatchTimer t = getSensorTimerLocked(Sensor.GPS, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7670 | if (t != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7671 | t.stopRunningLocked(elapsedRealtimeMs); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 7672 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7673 | } |
| 7674 | |
| 7675 | public BatteryStatsImpl getBatteryStats() { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7676 | return mBsi; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7677 | } |
| 7678 | } |
| 7679 | |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 7680 | public BatteryStatsImpl(File systemDir, Handler handler, ExternalStatsSync externalSync) { |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 7681 | this(new SystemClocks(), systemDir, handler, externalSync, null); |
| 7682 | } |
| 7683 | |
| 7684 | public BatteryStatsImpl(File systemDir, Handler handler, ExternalStatsSync externalSync, |
| 7685 | PlatformIdleStateCallback cb) { |
| 7686 | this(new SystemClocks(), systemDir, handler, externalSync, cb); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7687 | } |
| 7688 | |
| 7689 | public BatteryStatsImpl(Clocks clocks, File systemDir, Handler handler, |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 7690 | ExternalStatsSync externalSync, PlatformIdleStateCallback cb) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7691 | init(clocks); |
| 7692 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 7693 | if (systemDir != null) { |
| 7694 | mFile = new JournaledFile(new File(systemDir, "batterystats.bin"), |
| 7695 | new File(systemDir, "batterystats.bin.tmp")); |
| 7696 | } else { |
| 7697 | mFile = null; |
| 7698 | } |
| 7699 | mCheckinFile = new AtomicFile(new File(systemDir, "batterystats-checkin.bin")); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 7700 | mDailyFile = new AtomicFile(new File(systemDir, "batterystats-daily.xml")); |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 7701 | mExternalSync = externalSync; |
Jeff Brown | 6f357d3 | 2014-01-15 20:40:55 -0800 | [diff] [blame] | 7702 | mHandler = new MyHandler(handler.getLooper()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7703 | mStartCount++; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7704 | mScreenOnTimer = new StopwatchTimer(mClocks, null, -1, null, mOnBatteryTimeBase); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 7705 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7706 | mScreenBrightnessTimer[i] = new StopwatchTimer(mClocks, null, -100-i, null, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7707 | mOnBatteryTimeBase); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 7708 | } |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7709 | mInteractiveTimer = new StopwatchTimer(mClocks, null, -10, null, mOnBatteryTimeBase); |
| 7710 | mPowerSaveModeEnabledTimer = new StopwatchTimer(mClocks, null, -2, null, |
| 7711 | mOnBatteryTimeBase); |
| 7712 | mDeviceIdleModeLightTimer = new StopwatchTimer(mClocks, null, -11, null, |
| 7713 | mOnBatteryTimeBase); |
| 7714 | mDeviceIdleModeFullTimer = new StopwatchTimer(mClocks, null, -14, null, mOnBatteryTimeBase); |
| 7715 | mDeviceLightIdlingTimer = new StopwatchTimer(mClocks, null, -15, null, mOnBatteryTimeBase); |
| 7716 | mDeviceIdlingTimer = new StopwatchTimer(mClocks, null, -12, null, mOnBatteryTimeBase); |
| 7717 | mPhoneOnTimer = new StopwatchTimer(mClocks, null, -3, null, mOnBatteryTimeBase); |
| 7718 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
| 7719 | mPhoneSignalStrengthsTimer[i] = new StopwatchTimer(mClocks, null, -200-i, null, |
| 7720 | mOnBatteryTimeBase); |
| 7721 | } |
| 7722 | mPhoneSignalScanningTimer = new StopwatchTimer(mClocks, null, -200+1, null, |
| 7723 | mOnBatteryTimeBase); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 7724 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7725 | mPhoneDataConnectionsTimer[i] = new StopwatchTimer(mClocks, null, -300-i, null, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7726 | mOnBatteryTimeBase); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 7727 | } |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 7728 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7729 | mNetworkByteActivityCounters[i] = new LongSamplingCounter(mOnBatteryTimeBase); |
| 7730 | mNetworkPacketActivityCounters[i] = new LongSamplingCounter(mOnBatteryTimeBase); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 7731 | } |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 7732 | mWifiActivity = new ControllerActivityCounterImpl(mOnBatteryTimeBase, NUM_WIFI_TX_LEVELS); |
| 7733 | mBluetoothActivity = new ControllerActivityCounterImpl(mOnBatteryTimeBase, |
| 7734 | NUM_BT_TX_LEVELS); |
| 7735 | mModemActivity = new ControllerActivityCounterImpl(mOnBatteryTimeBase, |
| 7736 | ModemActivityInfo.TX_POWER_LEVELS); |
| 7737 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7738 | mMobileRadioActiveTimer = new StopwatchTimer(mClocks, null, -400, null, mOnBatteryTimeBase); |
| 7739 | mMobileRadioActivePerAppTimer = new StopwatchTimer(mClocks, null, -401, null, |
| 7740 | mOnBatteryTimeBase); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 7741 | mMobileRadioActiveAdjustedTime = new LongSamplingCounter(mOnBatteryTimeBase); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7742 | mMobileRadioActiveUnknownTime = new LongSamplingCounter(mOnBatteryTimeBase); |
| 7743 | mMobileRadioActiveUnknownCount = new LongSamplingCounter(mOnBatteryTimeBase); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7744 | mWifiOnTimer = new StopwatchTimer(mClocks, null, -4, null, mOnBatteryTimeBase); |
| 7745 | mGlobalWifiRunningTimer = new StopwatchTimer(mClocks, null, -5, null, mOnBatteryTimeBase); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 7746 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7747 | mWifiStateTimer[i] = new StopwatchTimer(mClocks, null, -600-i, null, |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 7748 | mOnBatteryTimeBase); |
| 7749 | } |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7750 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
| 7751 | mWifiSupplStateTimer[i] = new StopwatchTimer(mClocks, null, -700-i, null, |
| 7752 | mOnBatteryTimeBase); |
| 7753 | } |
| 7754 | for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 7755 | mWifiSignalStrengthsTimer[i] = new StopwatchTimer(mClocks, null, -800-i, null, |
| 7756 | mOnBatteryTimeBase); |
| 7757 | } |
| 7758 | mAudioOnTimer = new StopwatchTimer(mClocks, null, -7, null, mOnBatteryTimeBase); |
| 7759 | mVideoOnTimer = new StopwatchTimer(mClocks, null, -8, null, mOnBatteryTimeBase); |
| 7760 | mFlashlightOnTimer = new StopwatchTimer(mClocks, null, -9, null, mOnBatteryTimeBase); |
| 7761 | mCameraOnTimer = new StopwatchTimer(mClocks, null, -13, null, mOnBatteryTimeBase); |
| 7762 | mBluetoothScanTimer = new StopwatchTimer(mClocks, null, -14, null, mOnBatteryTimeBase); |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 7763 | mDischargeScreenOffCounter = new LongSamplingCounter(mOnBatteryScreenOffTimeBase); |
| 7764 | mDischargeCounter = new LongSamplingCounter(mOnBatteryTimeBase); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7765 | mOnBattery = mOnBatteryInternal = false; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7766 | long uptime = mClocks.uptimeMillis() * 1000; |
| 7767 | long realtime = mClocks.elapsedRealtime() * 1000; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7768 | initTimes(uptime, realtime); |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 7769 | mStartPlatformVersion = mEndPlatformVersion = Build.ID; |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 7770 | mDischargeStartLevel = 0; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7771 | mDischargeUnplugLevel = 0; |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 7772 | mDischargePlugLevel = -1; |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 7773 | mDischargeCurrentLevel = 0; |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 7774 | mCurrentBatteryLevel = 0; |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 7775 | initDischarge(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 7776 | clearHistoryLocked(); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 7777 | updateDailyDeadlineLocked(); |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 7778 | mPlatformIdleStateCallback = cb; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7779 | } |
| 7780 | |
| 7781 | public BatteryStatsImpl(Parcel p) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7782 | this(new SystemClocks(), p); |
| 7783 | } |
| 7784 | |
| 7785 | public BatteryStatsImpl(Clocks clocks, Parcel p) { |
| 7786 | init(clocks); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 7787 | mFile = null; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 7788 | mCheckinFile = null; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 7789 | mDailyFile = null; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 7790 | mHandler = null; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 7791 | mExternalSync = null; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 7792 | clearHistoryLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7793 | readFromParcel(p); |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 7794 | mPlatformIdleStateCallback = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7795 | } |
| 7796 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 7797 | public void setPowerProfile(PowerProfile profile) { |
| 7798 | synchronized (this) { |
| 7799 | mPowerProfile = profile; |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 7800 | |
| 7801 | // We need to initialize the KernelCpuSpeedReaders to read from |
| 7802 | // the first cpu of each core. Once we have the PowerProfile, we have access to this |
| 7803 | // information. |
| 7804 | final int numClusters = mPowerProfile.getNumCpuClusters(); |
| 7805 | mKernelCpuSpeedReaders = new KernelCpuSpeedReader[numClusters]; |
| 7806 | int firstCpuOfCluster = 0; |
| 7807 | for (int i = 0; i < numClusters; i++) { |
| 7808 | final int numSpeedSteps = mPowerProfile.getNumSpeedStepsInCpuCluster(i); |
| 7809 | mKernelCpuSpeedReaders[i] = new KernelCpuSpeedReader(firstCpuOfCluster, |
| 7810 | numSpeedSteps); |
| 7811 | firstCpuOfCluster += mPowerProfile.getNumCoresInCpuCluster(i); |
| 7812 | } |
Adam Lesinski | f9b20a9 | 2016-06-17 17:30:01 -0700 | [diff] [blame] | 7813 | |
| 7814 | if (mEstimatedBatteryCapacity == -1) { |
| 7815 | // Initialize the estimated battery capacity to a known preset one. |
| 7816 | mEstimatedBatteryCapacity = (int) mPowerProfile.getBatteryCapacity(); |
| 7817 | } |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 7818 | } |
| 7819 | } |
| 7820 | |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 7821 | public void setCallback(BatteryCallback cb) { |
| 7822 | mCallback = cb; |
| 7823 | } |
| 7824 | |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 7825 | public void setRadioScanningTimeout(long timeout) { |
| 7826 | if (mPhoneSignalScanningTimer != null) { |
| 7827 | mPhoneSignalScanningTimer.setTimeout(timeout); |
| 7828 | } |
| 7829 | } |
| 7830 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 7831 | public void updateDailyDeadlineLocked() { |
| 7832 | // Get the current time. |
| 7833 | long currentTime = mDailyStartTime = System.currentTimeMillis(); |
| 7834 | Calendar calDeadline = Calendar.getInstance(); |
| 7835 | calDeadline.setTimeInMillis(currentTime); |
| 7836 | |
| 7837 | // Move time up to the next day, ranging from 1am to 3pm. |
| 7838 | calDeadline.set(Calendar.DAY_OF_YEAR, calDeadline.get(Calendar.DAY_OF_YEAR) + 1); |
| 7839 | calDeadline.set(Calendar.MILLISECOND, 0); |
| 7840 | calDeadline.set(Calendar.SECOND, 0); |
| 7841 | calDeadline.set(Calendar.MINUTE, 0); |
| 7842 | calDeadline.set(Calendar.HOUR_OF_DAY, 1); |
| 7843 | mNextMinDailyDeadline = calDeadline.getTimeInMillis(); |
| 7844 | calDeadline.set(Calendar.HOUR_OF_DAY, 3); |
| 7845 | mNextMaxDailyDeadline = calDeadline.getTimeInMillis(); |
| 7846 | } |
| 7847 | |
| 7848 | public void recordDailyStatsIfNeededLocked(boolean settled) { |
| 7849 | long currentTime = System.currentTimeMillis(); |
| 7850 | if (currentTime >= mNextMaxDailyDeadline) { |
| 7851 | recordDailyStatsLocked(); |
| 7852 | } else if (settled && currentTime >= mNextMinDailyDeadline) { |
| 7853 | recordDailyStatsLocked(); |
| 7854 | } else if (currentTime < (mDailyStartTime-(1000*60*60*24))) { |
| 7855 | recordDailyStatsLocked(); |
| 7856 | } |
| 7857 | } |
| 7858 | |
| 7859 | public void recordDailyStatsLocked() { |
| 7860 | DailyItem item = new DailyItem(); |
| 7861 | item.mStartTime = mDailyStartTime; |
| 7862 | item.mEndTime = System.currentTimeMillis(); |
| 7863 | boolean hasData = false; |
| 7864 | if (mDailyDischargeStepTracker.mNumStepDurations > 0) { |
| 7865 | hasData = true; |
| 7866 | item.mDischargeSteps = new LevelStepTracker( |
| 7867 | mDailyDischargeStepTracker.mNumStepDurations, |
| 7868 | mDailyDischargeStepTracker.mStepDurations); |
| 7869 | } |
| 7870 | if (mDailyChargeStepTracker.mNumStepDurations > 0) { |
| 7871 | hasData = true; |
| 7872 | item.mChargeSteps = new LevelStepTracker( |
| 7873 | mDailyChargeStepTracker.mNumStepDurations, |
| 7874 | mDailyChargeStepTracker.mStepDurations); |
| 7875 | } |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 7876 | if (mDailyPackageChanges != null) { |
| 7877 | hasData = true; |
| 7878 | item.mPackageChanges = mDailyPackageChanges; |
| 7879 | mDailyPackageChanges = null; |
| 7880 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 7881 | mDailyDischargeStepTracker.init(); |
| 7882 | mDailyChargeStepTracker.init(); |
| 7883 | updateDailyDeadlineLocked(); |
| 7884 | |
| 7885 | if (hasData) { |
| 7886 | mDailyItems.add(item); |
| 7887 | while (mDailyItems.size() > MAX_DAILY_ITEMS) { |
| 7888 | mDailyItems.remove(0); |
| 7889 | } |
| 7890 | final ByteArrayOutputStream memStream = new ByteArrayOutputStream(); |
| 7891 | try { |
| 7892 | XmlSerializer out = new FastXmlSerializer(); |
Wojciech Staszkiewicz | 9e9e2e7 | 2015-05-08 14:58:46 +0100 | [diff] [blame] | 7893 | out.setOutput(memStream, StandardCharsets.UTF_8.name()); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 7894 | writeDailyItemsLocked(out); |
| 7895 | BackgroundThread.getHandler().post(new Runnable() { |
| 7896 | @Override |
| 7897 | public void run() { |
| 7898 | synchronized (mCheckinFile) { |
| 7899 | FileOutputStream stream = null; |
| 7900 | try { |
| 7901 | stream = mDailyFile.startWrite(); |
| 7902 | memStream.writeTo(stream); |
| 7903 | stream.flush(); |
| 7904 | FileUtils.sync(stream); |
| 7905 | stream.close(); |
| 7906 | mDailyFile.finishWrite(stream); |
| 7907 | } catch (IOException e) { |
| 7908 | Slog.w("BatteryStats", |
| 7909 | "Error writing battery daily items", e); |
| 7910 | mDailyFile.failWrite(stream); |
| 7911 | } |
| 7912 | } |
| 7913 | } |
| 7914 | }); |
| 7915 | } catch (IOException e) { |
| 7916 | } |
| 7917 | } |
| 7918 | } |
| 7919 | |
| 7920 | private void writeDailyItemsLocked(XmlSerializer out) throws IOException { |
| 7921 | StringBuilder sb = new StringBuilder(64); |
| 7922 | out.startDocument(null, true); |
| 7923 | out.startTag(null, "daily-items"); |
| 7924 | for (int i=0; i<mDailyItems.size(); i++) { |
| 7925 | final DailyItem dit = mDailyItems.get(i); |
| 7926 | out.startTag(null, "item"); |
| 7927 | out.attribute(null, "start", Long.toString(dit.mStartTime)); |
| 7928 | out.attribute(null, "end", Long.toString(dit.mEndTime)); |
| 7929 | writeDailyLevelSteps(out, "dis", dit.mDischargeSteps, sb); |
| 7930 | writeDailyLevelSteps(out, "chg", dit.mChargeSteps, sb); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 7931 | if (dit.mPackageChanges != null) { |
| 7932 | for (int j=0; j<dit.mPackageChanges.size(); j++) { |
| 7933 | PackageChange pc = dit.mPackageChanges.get(j); |
| 7934 | if (pc.mUpdate) { |
| 7935 | out.startTag(null, "upd"); |
| 7936 | out.attribute(null, "pkg", pc.mPackageName); |
| 7937 | out.attribute(null, "ver", Integer.toString(pc.mVersionCode)); |
| 7938 | out.endTag(null, "upd"); |
| 7939 | } else { |
| 7940 | out.startTag(null, "rem"); |
| 7941 | out.attribute(null, "pkg", pc.mPackageName); |
| 7942 | out.endTag(null, "rem"); |
| 7943 | } |
| 7944 | } |
| 7945 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 7946 | out.endTag(null, "item"); |
| 7947 | } |
| 7948 | out.endTag(null, "daily-items"); |
| 7949 | out.endDocument(); |
| 7950 | } |
| 7951 | |
| 7952 | private void writeDailyLevelSteps(XmlSerializer out, String tag, LevelStepTracker steps, |
| 7953 | StringBuilder tmpBuilder) throws IOException { |
| 7954 | if (steps != null) { |
| 7955 | out.startTag(null, tag); |
| 7956 | out.attribute(null, "n", Integer.toString(steps.mNumStepDurations)); |
| 7957 | for (int i=0; i<steps.mNumStepDurations; i++) { |
| 7958 | out.startTag(null, "s"); |
| 7959 | tmpBuilder.setLength(0); |
| 7960 | steps.encodeEntryAt(i, tmpBuilder); |
| 7961 | out.attribute(null, "v", tmpBuilder.toString()); |
| 7962 | out.endTag(null, "s"); |
| 7963 | } |
| 7964 | out.endTag(null, tag); |
| 7965 | } |
| 7966 | } |
| 7967 | |
| 7968 | public void readDailyStatsLocked() { |
| 7969 | Slog.d(TAG, "Reading daily items from " + mDailyFile.getBaseFile()); |
| 7970 | mDailyItems.clear(); |
| 7971 | FileInputStream stream; |
| 7972 | try { |
| 7973 | stream = mDailyFile.openRead(); |
| 7974 | } catch (FileNotFoundException e) { |
| 7975 | return; |
| 7976 | } |
| 7977 | try { |
| 7978 | XmlPullParser parser = Xml.newPullParser(); |
Wojciech Staszkiewicz | 9e9e2e7 | 2015-05-08 14:58:46 +0100 | [diff] [blame] | 7979 | parser.setInput(stream, StandardCharsets.UTF_8.name()); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 7980 | readDailyItemsLocked(parser); |
| 7981 | } catch (XmlPullParserException e) { |
| 7982 | } finally { |
| 7983 | try { |
| 7984 | stream.close(); |
| 7985 | } catch (IOException e) { |
| 7986 | } |
| 7987 | } |
| 7988 | } |
| 7989 | |
| 7990 | private void readDailyItemsLocked(XmlPullParser parser) { |
| 7991 | try { |
| 7992 | int type; |
| 7993 | while ((type = parser.next()) != XmlPullParser.START_TAG |
| 7994 | && type != XmlPullParser.END_DOCUMENT) { |
| 7995 | ; |
| 7996 | } |
| 7997 | |
| 7998 | if (type != XmlPullParser.START_TAG) { |
| 7999 | throw new IllegalStateException("no start tag found"); |
| 8000 | } |
| 8001 | |
| 8002 | int outerDepth = parser.getDepth(); |
| 8003 | while ((type = parser.next()) != XmlPullParser.END_DOCUMENT |
| 8004 | && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) { |
| 8005 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 8006 | continue; |
| 8007 | } |
| 8008 | |
| 8009 | String tagName = parser.getName(); |
| 8010 | if (tagName.equals("item")) { |
| 8011 | readDailyItemTagLocked(parser); |
| 8012 | } else { |
| 8013 | Slog.w(TAG, "Unknown element under <daily-items>: " |
| 8014 | + parser.getName()); |
| 8015 | XmlUtils.skipCurrentTag(parser); |
| 8016 | } |
| 8017 | } |
| 8018 | |
| 8019 | } catch (IllegalStateException e) { |
| 8020 | Slog.w(TAG, "Failed parsing daily " + e); |
| 8021 | } catch (NullPointerException e) { |
| 8022 | Slog.w(TAG, "Failed parsing daily " + e); |
| 8023 | } catch (NumberFormatException e) { |
| 8024 | Slog.w(TAG, "Failed parsing daily " + e); |
| 8025 | } catch (XmlPullParserException e) { |
| 8026 | Slog.w(TAG, "Failed parsing daily " + e); |
| 8027 | } catch (IOException e) { |
| 8028 | Slog.w(TAG, "Failed parsing daily " + e); |
| 8029 | } catch (IndexOutOfBoundsException e) { |
| 8030 | Slog.w(TAG, "Failed parsing daily " + e); |
| 8031 | } |
| 8032 | } |
| 8033 | |
| 8034 | void readDailyItemTagLocked(XmlPullParser parser) throws NumberFormatException, |
| 8035 | XmlPullParserException, IOException { |
| 8036 | DailyItem dit = new DailyItem(); |
| 8037 | String attr = parser.getAttributeValue(null, "start"); |
| 8038 | if (attr != null) { |
| 8039 | dit.mStartTime = Long.parseLong(attr); |
| 8040 | } |
| 8041 | attr = parser.getAttributeValue(null, "end"); |
| 8042 | if (attr != null) { |
| 8043 | dit.mEndTime = Long.parseLong(attr); |
| 8044 | } |
| 8045 | int outerDepth = parser.getDepth(); |
| 8046 | int type; |
| 8047 | while ((type = parser.next()) != XmlPullParser.END_DOCUMENT |
| 8048 | && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) { |
| 8049 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 8050 | continue; |
| 8051 | } |
| 8052 | |
| 8053 | String tagName = parser.getName(); |
| 8054 | if (tagName.equals("dis")) { |
| 8055 | readDailyItemTagDetailsLocked(parser, dit, false, "dis"); |
| 8056 | } else if (tagName.equals("chg")) { |
| 8057 | readDailyItemTagDetailsLocked(parser, dit, true, "chg"); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 8058 | } else if (tagName.equals("upd")) { |
| 8059 | if (dit.mPackageChanges == null) { |
| 8060 | dit.mPackageChanges = new ArrayList<>(); |
| 8061 | } |
| 8062 | PackageChange pc = new PackageChange(); |
| 8063 | pc.mUpdate = true; |
| 8064 | pc.mPackageName = parser.getAttributeValue(null, "pkg"); |
| 8065 | String verStr = parser.getAttributeValue(null, "ver"); |
| 8066 | pc.mVersionCode = verStr != null ? Integer.parseInt(verStr) : 0; |
| 8067 | dit.mPackageChanges.add(pc); |
| 8068 | XmlUtils.skipCurrentTag(parser); |
| 8069 | } else if (tagName.equals("rem")) { |
| 8070 | if (dit.mPackageChanges == null) { |
| 8071 | dit.mPackageChanges = new ArrayList<>(); |
| 8072 | } |
| 8073 | PackageChange pc = new PackageChange(); |
| 8074 | pc.mUpdate = false; |
| 8075 | pc.mPackageName = parser.getAttributeValue(null, "pkg"); |
| 8076 | dit.mPackageChanges.add(pc); |
| 8077 | XmlUtils.skipCurrentTag(parser); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 8078 | } else { |
| 8079 | Slog.w(TAG, "Unknown element under <item>: " |
| 8080 | + parser.getName()); |
| 8081 | XmlUtils.skipCurrentTag(parser); |
| 8082 | } |
| 8083 | } |
| 8084 | mDailyItems.add(dit); |
| 8085 | } |
| 8086 | |
| 8087 | void readDailyItemTagDetailsLocked(XmlPullParser parser, DailyItem dit, boolean isCharge, |
| 8088 | String tag) |
| 8089 | throws NumberFormatException, XmlPullParserException, IOException { |
| 8090 | final String numAttr = parser.getAttributeValue(null, "n"); |
| 8091 | if (numAttr == null) { |
| 8092 | Slog.w(TAG, "Missing 'n' attribute at " + parser.getPositionDescription()); |
| 8093 | XmlUtils.skipCurrentTag(parser); |
| 8094 | return; |
| 8095 | } |
| 8096 | final int num = Integer.parseInt(numAttr); |
| 8097 | LevelStepTracker steps = new LevelStepTracker(num); |
| 8098 | if (isCharge) { |
| 8099 | dit.mChargeSteps = steps; |
| 8100 | } else { |
| 8101 | dit.mDischargeSteps = steps; |
| 8102 | } |
| 8103 | int i = 0; |
| 8104 | int outerDepth = parser.getDepth(); |
| 8105 | int type; |
| 8106 | while ((type = parser.next()) != XmlPullParser.END_DOCUMENT |
| 8107 | && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) { |
| 8108 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 8109 | continue; |
| 8110 | } |
| 8111 | |
| 8112 | String tagName = parser.getName(); |
| 8113 | if ("s".equals(tagName)) { |
| 8114 | if (i < num) { |
| 8115 | String valueAttr = parser.getAttributeValue(null, "v"); |
| 8116 | if (valueAttr != null) { |
| 8117 | steps.decodeEntryAt(i, valueAttr); |
| 8118 | i++; |
| 8119 | } |
| 8120 | } |
| 8121 | } else { |
| 8122 | Slog.w(TAG, "Unknown element under <" + tag + ">: " |
| 8123 | + parser.getName()); |
| 8124 | XmlUtils.skipCurrentTag(parser); |
| 8125 | } |
| 8126 | } |
| 8127 | steps.mNumStepDurations = i; |
| 8128 | } |
| 8129 | |
| 8130 | @Override |
| 8131 | public DailyItem getDailyItemLocked(int daysAgo) { |
| 8132 | int index = mDailyItems.size()-1-daysAgo; |
| 8133 | return index >= 0 ? mDailyItems.get(index) : null; |
| 8134 | } |
| 8135 | |
| 8136 | @Override |
| 8137 | public long getCurrentDailyStartTime() { |
| 8138 | return mDailyStartTime; |
| 8139 | } |
| 8140 | |
| 8141 | @Override |
| 8142 | public long getNextMinDailyDeadline() { |
| 8143 | return mNextMinDailyDeadline; |
| 8144 | } |
| 8145 | |
| 8146 | @Override |
| 8147 | public long getNextMaxDailyDeadline() { |
| 8148 | return mNextMaxDailyDeadline; |
| 8149 | } |
| 8150 | |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 8151 | @Override |
| 8152 | public boolean startIteratingOldHistoryLocked() { |
| 8153 | if (DEBUG_HISTORY) Slog.i(TAG, "ITERATING: buff size=" + mHistoryBuffer.dataSize() |
| 8154 | + " pos=" + mHistoryBuffer.dataPosition()); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 8155 | if ((mHistoryIterator = mHistory) == null) { |
| 8156 | return false; |
| 8157 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 8158 | mHistoryBuffer.setDataPosition(0); |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 8159 | mHistoryReadTmp.clear(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 8160 | mReadOverflow = false; |
| 8161 | mIteratingHistory = true; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 8162 | return true; |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 8163 | } |
| 8164 | |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 8165 | @Override |
| 8166 | public boolean getNextOldHistoryLocked(HistoryItem out) { |
| 8167 | boolean end = mHistoryBuffer.dataPosition() >= mHistoryBuffer.dataSize(); |
| 8168 | if (!end) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 8169 | readHistoryDelta(mHistoryBuffer, mHistoryReadTmp); |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 8170 | mReadOverflow |= mHistoryReadTmp.cmd == HistoryItem.CMD_OVERFLOW; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 8171 | } |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 8172 | HistoryItem cur = mHistoryIterator; |
| 8173 | if (cur == null) { |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 8174 | if (!mReadOverflow && !end) { |
| 8175 | Slog.w(TAG, "Old history ends before new history!"); |
| 8176 | } |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 8177 | return false; |
| 8178 | } |
| 8179 | out.setTo(cur); |
| 8180 | mHistoryIterator = cur.next; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 8181 | if (!mReadOverflow) { |
| 8182 | if (end) { |
| 8183 | Slog.w(TAG, "New history ends before old history!"); |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 8184 | } else if (!out.same(mHistoryReadTmp)) { |
Dianne Hackborn | 8c84109 | 2013-06-24 13:46:13 -0700 | [diff] [blame] | 8185 | PrintWriter pw = new FastPrintWriter(new LogWriter(android.util.Log.WARN, TAG)); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 8186 | pw.println("Histories differ!"); |
| 8187 | pw.println("Old history:"); |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 8188 | (new HistoryPrinter()).printNextItem(pw, out, 0, false, true); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 8189 | pw.println("New history:"); |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 8190 | (new HistoryPrinter()).printNextItem(pw, mHistoryReadTmp, 0, false, |
| 8191 | true); |
Dianne Hackborn | 8c84109 | 2013-06-24 13:46:13 -0700 | [diff] [blame] | 8192 | pw.flush(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 8193 | } |
| 8194 | } |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 8195 | return true; |
| 8196 | } |
| 8197 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8198 | @Override |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 8199 | public void finishIteratingOldHistoryLocked() { |
| 8200 | mIteratingHistory = false; |
| 8201 | mHistoryBuffer.setDataPosition(mHistoryBuffer.dataSize()); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 8202 | mHistoryIterator = null; |
| 8203 | } |
| 8204 | |
| 8205 | public int getHistoryTotalSize() { |
| 8206 | return MAX_HISTORY_BUFFER; |
| 8207 | } |
| 8208 | |
| 8209 | public int getHistoryUsedSize() { |
| 8210 | return mHistoryBuffer.dataSize(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 8211 | } |
| 8212 | |
| 8213 | @Override |
| 8214 | public boolean startIteratingHistoryLocked() { |
| 8215 | if (DEBUG_HISTORY) Slog.i(TAG, "ITERATING: buff size=" + mHistoryBuffer.dataSize() |
| 8216 | + " pos=" + mHistoryBuffer.dataPosition()); |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 8217 | if (mHistoryBuffer.dataSize() <= 0) { |
| 8218 | return false; |
| 8219 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 8220 | mHistoryBuffer.setDataPosition(0); |
| 8221 | mReadOverflow = false; |
| 8222 | mIteratingHistory = true; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 8223 | mReadHistoryStrings = new String[mHistoryTagPool.size()]; |
| 8224 | mReadHistoryUids = new int[mHistoryTagPool.size()]; |
| 8225 | mReadHistoryChars = 0; |
| 8226 | for (HashMap.Entry<HistoryTag, Integer> ent : mHistoryTagPool.entrySet()) { |
| 8227 | final HistoryTag tag = ent.getKey(); |
| 8228 | final int idx = ent.getValue(); |
| 8229 | mReadHistoryStrings[idx] = tag.string; |
| 8230 | mReadHistoryUids[idx] = tag.uid; |
| 8231 | mReadHistoryChars += tag.string.length() + 1; |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 8232 | } |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 8233 | return true; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 8234 | } |
| 8235 | |
| 8236 | @Override |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 8237 | public int getHistoryStringPoolSize() { |
| 8238 | return mReadHistoryStrings.length; |
| 8239 | } |
| 8240 | |
| 8241 | @Override |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 8242 | public int getHistoryStringPoolBytes() { |
| 8243 | // Each entry is a fixed 12 bytes: 4 for index, 4 for uid, 4 for string size |
| 8244 | // Each string character is 2 bytes. |
| 8245 | return (mReadHistoryStrings.length * 12) + (mReadHistoryChars * 2); |
| 8246 | } |
| 8247 | |
| 8248 | @Override |
| 8249 | public String getHistoryTagPoolString(int index) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 8250 | return mReadHistoryStrings[index]; |
| 8251 | } |
| 8252 | |
| 8253 | @Override |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 8254 | public int getHistoryTagPoolUid(int index) { |
| 8255 | return mReadHistoryUids[index]; |
| 8256 | } |
| 8257 | |
| 8258 | @Override |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 8259 | public boolean getNextHistoryLocked(HistoryItem out) { |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 8260 | final int pos = mHistoryBuffer.dataPosition(); |
| 8261 | if (pos == 0) { |
| 8262 | out.clear(); |
| 8263 | } |
| 8264 | boolean end = pos >= mHistoryBuffer.dataSize(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 8265 | if (end) { |
| 8266 | return false; |
| 8267 | } |
| 8268 | |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 8269 | final long lastRealtime = out.time; |
| 8270 | final long lastWalltime = out.currentTime; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 8271 | readHistoryDelta(mHistoryBuffer, out); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 8272 | if (out.cmd != HistoryItem.CMD_CURRENT_TIME |
| 8273 | && out.cmd != HistoryItem.CMD_RESET && lastWalltime != 0) { |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 8274 | out.currentTime = lastWalltime + (out.time - lastRealtime); |
| 8275 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 8276 | return true; |
| 8277 | } |
| 8278 | |
| 8279 | @Override |
| 8280 | public void finishIteratingHistoryLocked() { |
| 8281 | mIteratingHistory = false; |
| 8282 | mHistoryBuffer.setDataPosition(mHistoryBuffer.dataSize()); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 8283 | mReadHistoryStrings = null; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 8284 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 8285 | |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 8286 | @Override |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 8287 | public long getHistoryBaseTime() { |
| 8288 | return mHistoryBaseTime; |
| 8289 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 8290 | |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 8291 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8292 | public int getStartCount() { |
| 8293 | return mStartCount; |
| 8294 | } |
| 8295 | |
| 8296 | public boolean isOnBattery() { |
| 8297 | return mOnBattery; |
| 8298 | } |
| 8299 | |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 8300 | public boolean isCharging() { |
| 8301 | return mCharging; |
| 8302 | } |
| 8303 | |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 8304 | public boolean isScreenOn() { |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 8305 | return mScreenState == Display.STATE_ON; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 8306 | } |
| 8307 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8308 | void initTimes(long uptime, long realtime) { |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 8309 | mStartClockTime = System.currentTimeMillis(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8310 | mOnBatteryTimeBase.init(uptime, realtime); |
| 8311 | mOnBatteryScreenOffTimeBase.init(uptime, realtime); |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 8312 | mRealtime = 0; |
| 8313 | mUptime = 0; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8314 | mRealtimeStart = realtime; |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 8315 | mUptimeStart = uptime; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8316 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 8317 | |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 8318 | void initDischarge() { |
| 8319 | mLowDischargeAmountSinceCharge = 0; |
| 8320 | mHighDischargeAmountSinceCharge = 0; |
| 8321 | mDischargeAmountScreenOn = 0; |
| 8322 | mDischargeAmountScreenOnSinceCharge = 0; |
| 8323 | mDischargeAmountScreenOff = 0; |
| 8324 | mDischargeAmountScreenOffSinceCharge = 0; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 8325 | mDischargeStepTracker.init(); |
| 8326 | mChargeStepTracker.init(); |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 8327 | mDischargeScreenOffCounter.reset(false); |
| 8328 | mDischargeCounter.reset(false); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 8329 | } |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 8330 | |
| 8331 | public void resetAllStatsCmdLocked() { |
| 8332 | resetAllStatsLocked(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8333 | final long mSecUptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 8334 | long uptime = mSecUptime * 1000; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8335 | long mSecRealtime = mClocks.elapsedRealtime(); |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 8336 | long realtime = mSecRealtime * 1000; |
| 8337 | mDischargeStartLevel = mHistoryCur.batteryLevel; |
| 8338 | pullPendingStateUpdatesLocked(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 8339 | addHistoryRecordLocked(mSecRealtime, mSecUptime); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 8340 | mDischargeCurrentLevel = mDischargeUnplugLevel = mDischargePlugLevel |
| 8341 | = mCurrentBatteryLevel = mHistoryCur.batteryLevel; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8342 | mOnBatteryTimeBase.reset(uptime, realtime); |
| 8343 | mOnBatteryScreenOffTimeBase.reset(uptime, realtime); |
| 8344 | if ((mHistoryCur.states&HistoryItem.STATE_BATTERY_PLUGGED_FLAG) == 0) { |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 8345 | if (mScreenState == Display.STATE_ON) { |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 8346 | mDischargeScreenOnUnplugLevel = mHistoryCur.batteryLevel; |
| 8347 | mDischargeScreenOffUnplugLevel = 0; |
| 8348 | } else { |
| 8349 | mDischargeScreenOnUnplugLevel = 0; |
| 8350 | mDischargeScreenOffUnplugLevel = mHistoryCur.batteryLevel; |
| 8351 | } |
| 8352 | mDischargeAmountScreenOn = 0; |
| 8353 | mDischargeAmountScreenOff = 0; |
| 8354 | } |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 8355 | initActiveHistoryEventsLocked(mSecRealtime, mSecUptime); |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 8356 | } |
| 8357 | |
| 8358 | private void resetAllStatsLocked() { |
Adam Lesinski | 8ce3694 | 2016-05-26 16:05:35 -0700 | [diff] [blame] | 8359 | final long uptimeMillis = mClocks.uptimeMillis(); |
| 8360 | final long elapsedRealtimeMillis = mClocks.elapsedRealtime(); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8361 | mStartCount = 0; |
Adam Lesinski | 8ce3694 | 2016-05-26 16:05:35 -0700 | [diff] [blame] | 8362 | initTimes(uptimeMillis * 1000, elapsedRealtimeMillis * 1000); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8363 | mScreenOnTimer.reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8364 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8365 | mScreenBrightnessTimer[i].reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8366 | } |
Adam Lesinski | 1a76a62 | 2016-06-22 10:28:47 -0700 | [diff] [blame] | 8367 | |
| 8368 | if (mPowerProfile != null) { |
| 8369 | mEstimatedBatteryCapacity = (int) mPowerProfile.getBatteryCapacity(); |
| 8370 | } else { |
| 8371 | mEstimatedBatteryCapacity = -1; |
| 8372 | } |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 8373 | mInteractiveTimer.reset(false); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 8374 | mPowerSaveModeEnabledTimer.reset(false); |
Adam Lesinski | 8ce3694 | 2016-05-26 16:05:35 -0700 | [diff] [blame] | 8375 | mLastIdleTimeStart = elapsedRealtimeMillis; |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 8376 | mLongestLightIdleTime = 0; |
| 8377 | mLongestFullIdleTime = 0; |
| 8378 | mDeviceIdleModeLightTimer.reset(false); |
| 8379 | mDeviceIdleModeFullTimer.reset(false); |
| 8380 | mDeviceLightIdlingTimer.reset(false); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 8381 | mDeviceIdlingTimer.reset(false); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8382 | mPhoneOnTimer.reset(false); |
| 8383 | mAudioOnTimer.reset(false); |
| 8384 | mVideoOnTimer.reset(false); |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 8385 | mFlashlightOnTimer.reset(false); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 8386 | mCameraOnTimer.reset(false); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 8387 | mBluetoothScanTimer.reset(false); |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 8388 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8389 | mPhoneSignalStrengthsTimer[i].reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8390 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8391 | mPhoneSignalScanningTimer.reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8392 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8393 | mPhoneDataConnectionsTimer[i].reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8394 | } |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 8395 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 8396 | mNetworkByteActivityCounters[i].reset(false); |
| 8397 | mNetworkPacketActivityCounters[i].reset(false); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 8398 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8399 | mMobileRadioActiveTimer.reset(false); |
| 8400 | mMobileRadioActivePerAppTimer.reset(false); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 8401 | mMobileRadioActiveAdjustedTime.reset(false); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 8402 | mMobileRadioActiveUnknownTime.reset(false); |
| 8403 | mMobileRadioActiveUnknownCount.reset(false); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8404 | mWifiOnTimer.reset(false); |
| 8405 | mGlobalWifiRunningTimer.reset(false); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 8406 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8407 | mWifiStateTimer[i].reset(false); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 8408 | } |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 8409 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
| 8410 | mWifiSupplStateTimer[i].reset(false); |
| 8411 | } |
| 8412 | for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 8413 | mWifiSignalStrengthsTimer[i].reset(false); |
| 8414 | } |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 8415 | mWifiActivity.reset(false); |
| 8416 | mBluetoothActivity.reset(false); |
| 8417 | mModemActivity.reset(false); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 8418 | mNumConnectivityChange = mLoadedNumConnectivityChange = mUnpluggedNumConnectivityChange = 0; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 8419 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8420 | for (int i=0; i<mUidStats.size(); i++) { |
| 8421 | if (mUidStats.valueAt(i).reset()) { |
| 8422 | mUidStats.remove(mUidStats.keyAt(i)); |
| 8423 | i--; |
| 8424 | } |
| 8425 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 8426 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8427 | if (mKernelWakelockStats.size() > 0) { |
| 8428 | for (SamplingTimer timer : mKernelWakelockStats.values()) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8429 | mOnBatteryScreenOffTimeBase.remove(timer); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8430 | } |
| 8431 | mKernelWakelockStats.clear(); |
| 8432 | } |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 8433 | |
| 8434 | if (mWakeupReasonStats.size() > 0) { |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 8435 | for (SamplingTimer timer : mWakeupReasonStats.values()) { |
| 8436 | mOnBatteryTimeBase.remove(timer); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 8437 | } |
| 8438 | mWakeupReasonStats.clear(); |
| 8439 | } |
| 8440 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 8441 | mLastHistoryStepDetails = null; |
| 8442 | mLastStepCpuUserTime = mLastStepCpuSystemTime = 0; |
| 8443 | mCurStepCpuUserTime = mCurStepCpuSystemTime = 0; |
| 8444 | mLastStepCpuUserTime = mCurStepCpuUserTime = 0; |
| 8445 | mLastStepCpuSystemTime = mCurStepCpuSystemTime = 0; |
| 8446 | mLastStepStatUserTime = mCurStepStatUserTime = 0; |
| 8447 | mLastStepStatSystemTime = mCurStepStatSystemTime = 0; |
| 8448 | mLastStepStatIOWaitTime = mCurStepStatIOWaitTime = 0; |
| 8449 | mLastStepStatIrqTime = mCurStepStatIrqTime = 0; |
| 8450 | mLastStepStatSoftIrqTime = mCurStepStatSoftIrqTime = 0; |
| 8451 | mLastStepStatIdleTime = mCurStepStatIdleTime = 0; |
| 8452 | |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 8453 | initDischarge(); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 8454 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8455 | clearHistoryLocked(); |
| 8456 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 8457 | |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 8458 | private void initActiveHistoryEventsLocked(long elapsedRealtimeMs, long uptimeMs) { |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 8459 | for (int i=0; i<HistoryItem.EVENT_COUNT; i++) { |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 8460 | if (!mRecordAllHistory && i == HistoryItem.EVENT_PROC) { |
| 8461 | // Not recording process starts/stops. |
| 8462 | continue; |
| 8463 | } |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 8464 | HashMap<String, SparseIntArray> active = mActiveEvents.getStateForEvent(i); |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 8465 | if (active == null) { |
| 8466 | continue; |
| 8467 | } |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 8468 | for (HashMap.Entry<String, SparseIntArray> ent : active.entrySet()) { |
| 8469 | SparseIntArray uids = ent.getValue(); |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 8470 | for (int j=0; j<uids.size(); j++) { |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 8471 | addHistoryEventLocked(elapsedRealtimeMs, uptimeMs, i, ent.getKey(), |
| 8472 | uids.keyAt(j)); |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 8473 | } |
| 8474 | } |
| 8475 | } |
| 8476 | } |
| 8477 | |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 8478 | void updateDischargeScreenLevelsLocked(boolean oldScreenOn, boolean newScreenOn) { |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 8479 | if (oldScreenOn) { |
| 8480 | int diff = mDischargeScreenOnUnplugLevel - mDischargeCurrentLevel; |
| 8481 | if (diff > 0) { |
| 8482 | mDischargeAmountScreenOn += diff; |
| 8483 | mDischargeAmountScreenOnSinceCharge += diff; |
| 8484 | } |
| 8485 | } else { |
| 8486 | int diff = mDischargeScreenOffUnplugLevel - mDischargeCurrentLevel; |
| 8487 | if (diff > 0) { |
| 8488 | mDischargeAmountScreenOff += diff; |
| 8489 | mDischargeAmountScreenOffSinceCharge += diff; |
| 8490 | } |
| 8491 | } |
| 8492 | if (newScreenOn) { |
| 8493 | mDischargeScreenOnUnplugLevel = mDischargeCurrentLevel; |
| 8494 | mDischargeScreenOffUnplugLevel = 0; |
| 8495 | } else { |
| 8496 | mDischargeScreenOnUnplugLevel = 0; |
| 8497 | mDischargeScreenOffUnplugLevel = mDischargeCurrentLevel; |
| 8498 | } |
| 8499 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8500 | |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 8501 | public void pullPendingStateUpdatesLocked() { |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 8502 | if (mOnBatteryInternal) { |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 8503 | final boolean screenOn = mScreenState == Display.STATE_ON; |
| 8504 | updateDischargeScreenLevelsLocked(screenOn, screenOn); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 8505 | } |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 8506 | } |
| 8507 | |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8508 | private String[] mMobileIfaces = EmptyArray.STRING; |
| 8509 | private String[] mWifiIfaces = EmptyArray.STRING; |
| 8510 | |
| 8511 | private final NetworkStatsFactory mNetworkStatsFactory = new NetworkStatsFactory(); |
| 8512 | |
| 8513 | private static final int NETWORK_STATS_LAST = 0; |
| 8514 | private static final int NETWORK_STATS_NEXT = 1; |
| 8515 | private static final int NETWORK_STATS_DELTA = 2; |
| 8516 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8517 | private NetworkStats[] mMobileNetworkStats; |
| 8518 | private NetworkStats[] mWifiNetworkStats; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8519 | |
| 8520 | /** |
| 8521 | * Retrieves the delta of network stats for the given network ifaces. Uses networkStatsBuffer |
| 8522 | * as a buffer of NetworkStats objects to cycle through when computing deltas. |
| 8523 | */ |
| 8524 | private NetworkStats getNetworkStatsDeltaLocked(String[] ifaces, |
| 8525 | NetworkStats[] networkStatsBuffer) |
| 8526 | throws IOException { |
| 8527 | if (!SystemProperties.getBoolean(NetworkManagementSocketTagger.PROP_QTAGUID_ENABLED, |
| 8528 | false)) { |
| 8529 | return null; |
| 8530 | } |
| 8531 | |
| 8532 | final NetworkStats stats = mNetworkStatsFactory.readNetworkStatsDetail(NetworkStats.UID_ALL, |
| 8533 | ifaces, NetworkStats.TAG_NONE, networkStatsBuffer[NETWORK_STATS_NEXT]); |
| 8534 | networkStatsBuffer[NETWORK_STATS_DELTA] = NetworkStats.subtract(stats, |
| 8535 | networkStatsBuffer[NETWORK_STATS_LAST], null, null, |
| 8536 | networkStatsBuffer[NETWORK_STATS_DELTA]); |
| 8537 | networkStatsBuffer[NETWORK_STATS_NEXT] = networkStatsBuffer[NETWORK_STATS_LAST]; |
| 8538 | networkStatsBuffer[NETWORK_STATS_LAST] = stats; |
| 8539 | return networkStatsBuffer[NETWORK_STATS_DELTA]; |
| 8540 | } |
| 8541 | |
| 8542 | /** |
| 8543 | * Distribute WiFi energy info and network traffic to apps. |
| 8544 | * @param info The energy information from the WiFi controller. |
| 8545 | */ |
| 8546 | public void updateWifiStateLocked(@Nullable final WifiActivityEnergyInfo info) { |
Adam Lesinski | a7c90c8 | 2015-06-18 14:52:24 -0700 | [diff] [blame] | 8547 | if (DEBUG_ENERGY) { |
| 8548 | Slog.d(TAG, "Updating wifi stats"); |
| 8549 | } |
| 8550 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8551 | final long elapsedRealtimeMs = mClocks.elapsedRealtime(); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 8552 | NetworkStats delta = null; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8553 | try { |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 8554 | if (!ArrayUtils.isEmpty(mWifiIfaces)) { |
| 8555 | delta = getNetworkStatsDeltaLocked(mWifiIfaces, mWifiNetworkStats); |
| 8556 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8557 | } catch (IOException e) { |
| 8558 | Slog.wtf(TAG, "Failed to get wifi network stats", e); |
| 8559 | return; |
| 8560 | } |
| 8561 | |
| 8562 | if (!mOnBatteryInternal) { |
| 8563 | return; |
| 8564 | } |
| 8565 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 8566 | SparseLongArray rxPackets = new SparseLongArray(); |
| 8567 | SparseLongArray txPackets = new SparseLongArray(); |
| 8568 | long totalTxPackets = 0; |
| 8569 | long totalRxPackets = 0; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8570 | if (delta != null) { |
| 8571 | final int size = delta.size(); |
| 8572 | for (int i = 0; i < size; i++) { |
| 8573 | final NetworkStats.Entry entry = delta.getValues(i, mTmpNetworkStatsEntry); |
| 8574 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 8575 | if (DEBUG_ENERGY) { |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8576 | Slog.d(TAG, "Wifi uid " + entry.uid + ": delta rx=" + entry.rxBytes |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 8577 | + " tx=" + entry.txBytes + " rxPackets=" + entry.rxPackets |
| 8578 | + " txPackets=" + entry.txPackets); |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8579 | } |
| 8580 | |
Adam Lesinski | 6cca414 | 2016-02-25 18:23:02 -0800 | [diff] [blame] | 8581 | if (entry.rxBytes == 0 && entry.txBytes == 0) { |
| 8582 | // Skip the lookup below since there is no work to do. |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8583 | continue; |
| 8584 | } |
| 8585 | |
| 8586 | final Uid u = getUidStatsLocked(mapUid(entry.uid)); |
Adam Lesinski | ba88e68 | 2015-12-08 12:06:55 -0800 | [diff] [blame] | 8587 | if (entry.rxBytes != 0) { |
| 8588 | u.noteNetworkActivityLocked(NETWORK_WIFI_RX_DATA, entry.rxBytes, |
| 8589 | entry.rxPackets); |
| 8590 | mNetworkByteActivityCounters[NETWORK_WIFI_RX_DATA].addCountLocked( |
| 8591 | entry.rxBytes); |
| 8592 | mNetworkPacketActivityCounters[NETWORK_WIFI_RX_DATA].addCountLocked( |
| 8593 | entry.rxPackets); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 8594 | |
Adam Lesinski | ba88e68 | 2015-12-08 12:06:55 -0800 | [diff] [blame] | 8595 | rxPackets.put(u.getUid(), entry.rxPackets); |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8596 | |
Adam Lesinski | ba88e68 | 2015-12-08 12:06:55 -0800 | [diff] [blame] | 8597 | // Sum the total number of packets so that the Rx Power can |
| 8598 | // be evenly distributed amongst the apps. |
| 8599 | totalRxPackets += entry.rxPackets; |
| 8600 | } |
| 8601 | |
| 8602 | if (entry.txBytes != 0) { |
| 8603 | u.noteNetworkActivityLocked(NETWORK_WIFI_TX_DATA, entry.txBytes, |
| 8604 | entry.txPackets); |
| 8605 | mNetworkByteActivityCounters[NETWORK_WIFI_TX_DATA].addCountLocked( |
| 8606 | entry.txBytes); |
| 8607 | mNetworkPacketActivityCounters[NETWORK_WIFI_TX_DATA].addCountLocked( |
| 8608 | entry.txPackets); |
| 8609 | |
| 8610 | txPackets.put(u.getUid(), entry.txPackets); |
| 8611 | |
| 8612 | // Sum the total number of packets so that the Tx Power can |
| 8613 | // be evenly distributed amongst the apps. |
| 8614 | totalTxPackets += entry.txPackets; |
| 8615 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8616 | } |
| 8617 | } |
| 8618 | |
| 8619 | if (info != null) { |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 8620 | mHasWifiReporting = true; |
Adam Lesinski | 1739076 | 2015-04-10 13:17:47 -0700 | [diff] [blame] | 8621 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 8622 | // Measured in mAms |
| 8623 | final long txTimeMs = info.getControllerTxTimeMillis(); |
| 8624 | final long rxTimeMs = info.getControllerRxTimeMillis(); |
| 8625 | final long idleTimeMs = info.getControllerIdleTimeMillis(); |
| 8626 | final long totalTimeMs = txTimeMs + rxTimeMs + idleTimeMs; |
| 8627 | |
| 8628 | long leftOverRxTimeMs = rxTimeMs; |
Mitchell Wills | f901649 | 2015-07-29 17:47:44 -0700 | [diff] [blame] | 8629 | long leftOverTxTimeMs = txTimeMs; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 8630 | |
| 8631 | if (DEBUG_ENERGY) { |
| 8632 | Slog.d(TAG, "------ BEGIN WiFi power blaming ------"); |
| 8633 | Slog.d(TAG, " Tx Time: " + txTimeMs + " ms"); |
| 8634 | Slog.d(TAG, " Rx Time: " + rxTimeMs + " ms"); |
| 8635 | Slog.d(TAG, " Idle Time: " + idleTimeMs + " ms"); |
| 8636 | Slog.d(TAG, " Total Time: " + totalTimeMs + " ms"); |
| 8637 | } |
| 8638 | |
| 8639 | long totalWifiLockTimeMs = 0; |
| 8640 | long totalScanTimeMs = 0; |
| 8641 | |
| 8642 | // On the first pass, collect some totals so that we can normalize power |
| 8643 | // calculations if we need to. |
| 8644 | final int uidStatsSize = mUidStats.size(); |
| 8645 | for (int i = 0; i < uidStatsSize; i++) { |
| 8646 | final Uid uid = mUidStats.valueAt(i); |
| 8647 | |
| 8648 | // Sum the total scan power for all apps. |
| 8649 | totalScanTimeMs += uid.mWifiScanTimer.getTimeSinceMarkLocked( |
| 8650 | elapsedRealtimeMs * 1000) / 1000; |
| 8651 | |
| 8652 | // Sum the total time holding wifi lock for all apps. |
| 8653 | totalWifiLockTimeMs += uid.mFullWifiLockTimer.getTimeSinceMarkLocked( |
| 8654 | elapsedRealtimeMs * 1000) / 1000; |
| 8655 | } |
| 8656 | |
| 8657 | if (DEBUG_ENERGY && totalScanTimeMs > rxTimeMs) { |
| 8658 | Slog.d(TAG, " !Estimated scan time > Actual rx time (" + totalScanTimeMs + " ms > " |
| 8659 | + rxTimeMs + " ms). Normalizing scan time."); |
| 8660 | } |
Mitchell Wills | f901649 | 2015-07-29 17:47:44 -0700 | [diff] [blame] | 8661 | if (DEBUG_ENERGY && totalScanTimeMs > txTimeMs) { |
| 8662 | Slog.d(TAG, " !Estimated scan time > Actual tx time (" + totalScanTimeMs + " ms > " |
| 8663 | + txTimeMs + " ms). Normalizing scan time."); |
| 8664 | } |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 8665 | |
| 8666 | // Actually assign and distribute power usage to apps. |
| 8667 | for (int i = 0; i < uidStatsSize; i++) { |
| 8668 | final Uid uid = mUidStats.valueAt(i); |
| 8669 | |
| 8670 | long scanTimeSinceMarkMs = uid.mWifiScanTimer.getTimeSinceMarkLocked( |
| 8671 | elapsedRealtimeMs * 1000) / 1000; |
| 8672 | if (scanTimeSinceMarkMs > 0) { |
| 8673 | // Set the new mark so that next time we get new data since this point. |
| 8674 | uid.mWifiScanTimer.setMark(elapsedRealtimeMs); |
| 8675 | |
Mitchell Wills | f901649 | 2015-07-29 17:47:44 -0700 | [diff] [blame] | 8676 | long scanRxTimeSinceMarkMs = scanTimeSinceMarkMs; |
| 8677 | long scanTxTimeSinceMarkMs = scanTimeSinceMarkMs; |
| 8678 | |
| 8679 | // Our total scan time is more than the reported Tx/Rx time. |
| 8680 | // This is possible because the cost of a scan is approximate. |
| 8681 | // Let's normalize the result so that we evenly blame each app |
| 8682 | // scanning. |
| 8683 | // |
| 8684 | // This means that we may have apps that transmitted/received packets not be |
| 8685 | // blamed for this, but this is fine as scans are relatively more expensive. |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 8686 | if (totalScanTimeMs > rxTimeMs) { |
Mitchell Wills | f901649 | 2015-07-29 17:47:44 -0700 | [diff] [blame] | 8687 | scanRxTimeSinceMarkMs = (rxTimeMs * scanRxTimeSinceMarkMs) / |
| 8688 | totalScanTimeMs; |
| 8689 | } |
| 8690 | if (totalScanTimeMs > txTimeMs) { |
| 8691 | scanTxTimeSinceMarkMs = (txTimeMs * scanTxTimeSinceMarkMs) / |
| 8692 | totalScanTimeMs; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 8693 | } |
| 8694 | |
| 8695 | if (DEBUG_ENERGY) { |
Mitchell Wills | f901649 | 2015-07-29 17:47:44 -0700 | [diff] [blame] | 8696 | Slog.d(TAG, " ScanTime for UID " + uid.getUid() + ": Rx:" |
| 8697 | + scanRxTimeSinceMarkMs + " ms Tx:" |
| 8698 | + scanTxTimeSinceMarkMs + " ms)"); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 8699 | } |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 8700 | |
| 8701 | ControllerActivityCounterImpl activityCounter = |
| 8702 | uid.getOrCreateWifiControllerActivityLocked(); |
| 8703 | activityCounter.getRxTimeCounter().addCountLocked(scanRxTimeSinceMarkMs); |
| 8704 | activityCounter.getTxTimeCounters()[0].addCountLocked(scanTxTimeSinceMarkMs); |
Mitchell Wills | f901649 | 2015-07-29 17:47:44 -0700 | [diff] [blame] | 8705 | leftOverRxTimeMs -= scanRxTimeSinceMarkMs; |
| 8706 | leftOverTxTimeMs -= scanTxTimeSinceMarkMs; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 8707 | } |
| 8708 | |
| 8709 | // Distribute evenly the power consumed while Idle to each app holding a WiFi |
| 8710 | // lock. |
| 8711 | final long wifiLockTimeSinceMarkMs = uid.mFullWifiLockTimer.getTimeSinceMarkLocked( |
| 8712 | elapsedRealtimeMs * 1000) / 1000; |
| 8713 | if (wifiLockTimeSinceMarkMs > 0) { |
| 8714 | // Set the new mark so that next time we get new data since this point. |
| 8715 | uid.mFullWifiLockTimer.setMark(elapsedRealtimeMs); |
| 8716 | |
| 8717 | final long myIdleTimeMs = (wifiLockTimeSinceMarkMs * idleTimeMs) |
| 8718 | / totalWifiLockTimeMs; |
| 8719 | if (DEBUG_ENERGY) { |
| 8720 | Slog.d(TAG, " IdleTime for UID " + uid.getUid() + ": " |
| 8721 | + myIdleTimeMs + " ms"); |
| 8722 | } |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 8723 | uid.getOrCreateWifiControllerActivityLocked().getIdleTimeCounter() |
| 8724 | .addCountLocked(myIdleTimeMs); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 8725 | } |
| 8726 | } |
| 8727 | |
| 8728 | if (DEBUG_ENERGY) { |
| 8729 | Slog.d(TAG, " New RxPower: " + leftOverRxTimeMs + " ms"); |
Mitchell Wills | f901649 | 2015-07-29 17:47:44 -0700 | [diff] [blame] | 8730 | Slog.d(TAG, " New TxPower: " + leftOverTxTimeMs + " ms"); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 8731 | } |
| 8732 | |
Mitchell Wills | f901649 | 2015-07-29 17:47:44 -0700 | [diff] [blame] | 8733 | // Distribute the remaining Tx power appropriately between all apps that transmitted |
| 8734 | // packets. |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 8735 | for (int i = 0; i < txPackets.size(); i++) { |
| 8736 | final Uid uid = getUidStatsLocked(txPackets.keyAt(i)); |
Mitchell Wills | f901649 | 2015-07-29 17:47:44 -0700 | [diff] [blame] | 8737 | final long myTxTimeMs = (txPackets.valueAt(i) * leftOverTxTimeMs) / totalTxPackets; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 8738 | if (DEBUG_ENERGY) { |
| 8739 | Slog.d(TAG, " TxTime for UID " + uid.getUid() + ": " + myTxTimeMs + " ms"); |
| 8740 | } |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 8741 | uid.getOrCreateWifiControllerActivityLocked().getTxTimeCounters()[0] |
| 8742 | .addCountLocked(myTxTimeMs); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 8743 | } |
| 8744 | |
| 8745 | // Distribute the remaining Rx power appropriately between all apps that received |
| 8746 | // packets. |
| 8747 | for (int i = 0; i < rxPackets.size(); i++) { |
| 8748 | final Uid uid = getUidStatsLocked(rxPackets.keyAt(i)); |
| 8749 | final long myRxTimeMs = (rxPackets.valueAt(i) * leftOverRxTimeMs) / totalRxPackets; |
| 8750 | if (DEBUG_ENERGY) { |
| 8751 | Slog.d(TAG, " RxTime for UID " + uid.getUid() + ": " + myRxTimeMs + " ms"); |
| 8752 | } |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 8753 | uid.getOrCreateWifiControllerActivityLocked().getRxTimeCounter() |
| 8754 | .addCountLocked(myRxTimeMs); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 8755 | } |
| 8756 | |
| 8757 | // Any left over power use will be picked up by the WiFi category in BatteryStatsHelper. |
| 8758 | |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8759 | // Update WiFi controller stats. |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 8760 | mWifiActivity.getRxTimeCounter().addCountLocked(info.getControllerRxTimeMillis()); |
| 8761 | mWifiActivity.getTxTimeCounters()[0].addCountLocked(info.getControllerTxTimeMillis()); |
| 8762 | mWifiActivity.getIdleTimeCounter().addCountLocked(info.getControllerIdleTimeMillis()); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 8763 | |
Adam Lesinski | 8576cf9 | 2015-06-09 12:48:25 -0700 | [diff] [blame] | 8764 | // POWER_WIFI_CONTROLLER_OPERATING_VOLTAGE is measured in mV, so convert to V. |
| 8765 | final double opVolt = mPowerProfile.getAveragePower( |
| 8766 | PowerProfile.POWER_WIFI_CONTROLLER_OPERATING_VOLTAGE) / 1000.0; |
| 8767 | if (opVolt != 0) { |
| 8768 | // We store the power drain as mAms. |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 8769 | mWifiActivity.getPowerCounter().addCountLocked( |
Adam Lesinski | 8576cf9 | 2015-06-09 12:48:25 -0700 | [diff] [blame] | 8770 | (long)(info.getControllerEnergyUsed() / opVolt)); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 8771 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8772 | } |
| 8773 | } |
| 8774 | |
| 8775 | /** |
| 8776 | * Distribute Cell radio energy info and network traffic to apps. |
| 8777 | */ |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 8778 | public void updateMobileRadioStateLocked(final long elapsedRealtimeMs, |
| 8779 | final ModemActivityInfo activityInfo) { |
Adam Lesinski | a7c90c8 | 2015-06-18 14:52:24 -0700 | [diff] [blame] | 8780 | if (DEBUG_ENERGY) { |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 8781 | Slog.d(TAG, "Updating mobile radio stats with " + activityInfo); |
Adam Lesinski | a7c90c8 | 2015-06-18 14:52:24 -0700 | [diff] [blame] | 8782 | } |
| 8783 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 8784 | NetworkStats delta = null; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8785 | try { |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 8786 | if (!ArrayUtils.isEmpty(mMobileIfaces)) { |
| 8787 | delta = getNetworkStatsDeltaLocked(mMobileIfaces, mMobileNetworkStats); |
| 8788 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8789 | } catch (IOException e) { |
| 8790 | Slog.wtf(TAG, "Failed to get mobile network stats", e); |
| 8791 | return; |
| 8792 | } |
| 8793 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 8794 | if (!mOnBatteryInternal) { |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8795 | return; |
| 8796 | } |
| 8797 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 8798 | long radioTime = mMobileRadioActivePerAppTimer.getTimeSinceMarkLocked( |
| 8799 | elapsedRealtimeMs * 1000); |
| 8800 | mMobileRadioActivePerAppTimer.setMark(elapsedRealtimeMs); |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8801 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 8802 | long totalRxPackets = 0; |
| 8803 | long totalTxPackets = 0; |
| 8804 | if (delta != null) { |
| 8805 | final int size = delta.size(); |
| 8806 | for (int i = 0; i < size; i++) { |
| 8807 | final NetworkStats.Entry entry = delta.getValues(i, mTmpNetworkStatsEntry); |
Adam Lesinski | a426817 | 2016-01-29 12:13:54 -0800 | [diff] [blame] | 8808 | if (entry.rxPackets == 0 && entry.txPackets == 0) { |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 8809 | continue; |
| 8810 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8811 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 8812 | if (DEBUG_ENERGY) { |
| 8813 | Slog.d(TAG, "Mobile uid " + entry.uid + ": delta rx=" + entry.rxBytes |
| 8814 | + " tx=" + entry.txBytes + " rxPackets=" + entry.rxPackets |
| 8815 | + " txPackets=" + entry.txPackets); |
| 8816 | } |
| 8817 | |
| 8818 | totalRxPackets += entry.rxPackets; |
| 8819 | totalTxPackets += entry.txPackets; |
| 8820 | |
| 8821 | final Uid u = getUidStatsLocked(mapUid(entry.uid)); |
| 8822 | u.noteNetworkActivityLocked(NETWORK_MOBILE_RX_DATA, entry.rxBytes, entry.rxPackets); |
| 8823 | u.noteNetworkActivityLocked(NETWORK_MOBILE_TX_DATA, entry.txBytes, entry.txPackets); |
| 8824 | |
| 8825 | mNetworkByteActivityCounters[NETWORK_MOBILE_RX_DATA].addCountLocked( |
| 8826 | entry.rxBytes); |
| 8827 | mNetworkByteActivityCounters[NETWORK_MOBILE_TX_DATA].addCountLocked( |
| 8828 | entry.txBytes); |
| 8829 | mNetworkPacketActivityCounters[NETWORK_MOBILE_RX_DATA].addCountLocked( |
| 8830 | entry.rxPackets); |
| 8831 | mNetworkPacketActivityCounters[NETWORK_MOBILE_TX_DATA].addCountLocked( |
| 8832 | entry.txPackets); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 8833 | } |
| 8834 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 8835 | // Now distribute proportional blame to the apps that did networking. |
| 8836 | long totalPackets = totalRxPackets + totalTxPackets; |
| 8837 | if (totalPackets > 0) { |
| 8838 | for (int i = 0; i < size; i++) { |
| 8839 | final NetworkStats.Entry entry = delta.getValues(i, mTmpNetworkStatsEntry); |
| 8840 | if (entry.rxPackets == 0 && entry.txPackets == 0) { |
| 8841 | continue; |
| 8842 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8843 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 8844 | final Uid u = getUidStatsLocked(mapUid(entry.uid)); |
| 8845 | |
| 8846 | // Distribute total radio active time in to this app. |
| 8847 | final long appPackets = entry.rxPackets + entry.txPackets; |
| 8848 | final long appRadioTime = (radioTime * appPackets) / totalPackets; |
| 8849 | u.noteMobileRadioActiveTimeLocked(appRadioTime); |
| 8850 | |
| 8851 | // Remove this app from the totals, so that we don't lose any time |
| 8852 | // due to rounding. |
| 8853 | radioTime -= appRadioTime; |
| 8854 | totalPackets -= appPackets; |
| 8855 | |
| 8856 | if (activityInfo != null) { |
| 8857 | ControllerActivityCounterImpl activityCounter = |
| 8858 | u.getOrCreateModemControllerActivityLocked(); |
Adam Lesinski | a426817 | 2016-01-29 12:13:54 -0800 | [diff] [blame] | 8859 | if (totalRxPackets > 0 && entry.rxPackets > 0) { |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 8860 | final long rxMs = (entry.rxPackets * activityInfo.getRxTimeMillis()) |
| 8861 | / totalRxPackets; |
| 8862 | activityCounter.getRxTimeCounter().addCountLocked(rxMs); |
| 8863 | } |
| 8864 | |
Adam Lesinski | a426817 | 2016-01-29 12:13:54 -0800 | [diff] [blame] | 8865 | if (totalTxPackets > 0 && entry.txPackets > 0) { |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 8866 | for (int lvl = 0; lvl < ModemActivityInfo.TX_POWER_LEVELS; lvl++) { |
| 8867 | long txMs = entry.txPackets * activityInfo.getTxTimeMillis()[lvl]; |
| 8868 | txMs /= totalTxPackets; |
| 8869 | activityCounter.getTxTimeCounters()[lvl].addCountLocked(txMs); |
| 8870 | } |
| 8871 | } |
| 8872 | } |
| 8873 | } |
| 8874 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8875 | |
| 8876 | if (radioTime > 0) { |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 8877 | // Whoops, there is some radio time we can't blame on an app! |
| 8878 | mMobileRadioActiveUnknownTime.addCountLocked(radioTime); |
| 8879 | mMobileRadioActiveUnknownCount.addCountLocked(1); |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8880 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8881 | } |
| 8882 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 8883 | if (activityInfo != null) { |
| 8884 | mHasModemReporting = true; |
| 8885 | mModemActivity.getIdleTimeCounter().addCountLocked(activityInfo.getIdleTimeMillis()); |
| 8886 | mModemActivity.getRxTimeCounter().addCountLocked(activityInfo.getRxTimeMillis()); |
| 8887 | for (int lvl = 0; lvl < ModemActivityInfo.TX_POWER_LEVELS; lvl++) { |
| 8888 | mModemActivity.getTxTimeCounters()[lvl] |
| 8889 | .addCountLocked(activityInfo.getTxTimeMillis()[lvl]); |
| 8890 | } |
| 8891 | |
| 8892 | // POWER_MODEM_CONTROLLER_OPERATING_VOLTAGE is measured in mV, so convert to V. |
| 8893 | final double opVolt = mPowerProfile.getAveragePower( |
| 8894 | PowerProfile.POWER_MODEM_CONTROLLER_OPERATING_VOLTAGE) / 1000.0; |
| 8895 | if (opVolt != 0) { |
| 8896 | // We store the power drain as mAms. |
| 8897 | mModemActivity.getPowerCounter().addCountLocked( |
| 8898 | (long) (activityInfo.getEnergyUsed() / opVolt)); |
| 8899 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8900 | } |
| 8901 | } |
| 8902 | |
| 8903 | /** |
| 8904 | * Distribute Bluetooth energy info and network traffic to apps. |
| 8905 | * @param info The energy information from the bluetooth controller. |
| 8906 | */ |
| 8907 | public void updateBluetoothStateLocked(@Nullable final BluetoothActivityEnergyInfo info) { |
Adam Lesinski | a7c90c8 | 2015-06-18 14:52:24 -0700 | [diff] [blame] | 8908 | if (DEBUG_ENERGY) { |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 8909 | Slog.d(TAG, "Updating bluetooth stats: " + info); |
Adam Lesinski | a7c90c8 | 2015-06-18 14:52:24 -0700 | [diff] [blame] | 8910 | } |
| 8911 | |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 8912 | if (info == null || !mOnBatteryInternal) { |
| 8913 | return; |
| 8914 | } |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 8915 | |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 8916 | mHasBluetoothReporting = true; |
| 8917 | |
| 8918 | final long elapsedRealtimeMs = SystemClock.elapsedRealtime(); |
| 8919 | final long rxTimeMs = info.getControllerRxTimeMillis(); |
| 8920 | final long txTimeMs = info.getControllerTxTimeMillis(); |
| 8921 | |
| 8922 | if (DEBUG_ENERGY) { |
| 8923 | Slog.d(TAG, "------ BEGIN BLE power blaming ------"); |
| 8924 | Slog.d(TAG, " Tx Time: " + txTimeMs + " ms"); |
| 8925 | Slog.d(TAG, " Rx Time: " + rxTimeMs + " ms"); |
| 8926 | Slog.d(TAG, " Idle Time: " + info.getControllerIdleTimeMillis() + " ms"); |
| 8927 | } |
| 8928 | |
| 8929 | long totalScanTimeMs = 0; |
| 8930 | |
| 8931 | final int uidCount = mUidStats.size(); |
| 8932 | for (int i = 0; i < uidCount; i++) { |
| 8933 | final Uid u = mUidStats.valueAt(i); |
| 8934 | if (u.mBluetoothScanTimer == null) { |
| 8935 | continue; |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 8936 | } |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 8937 | |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 8938 | totalScanTimeMs += u.mBluetoothScanTimer.getTimeSinceMarkLocked( |
| 8939 | elapsedRealtimeMs * 1000) / 1000; |
| 8940 | } |
| 8941 | |
| 8942 | final boolean normalizeScanRxTime = (totalScanTimeMs > rxTimeMs); |
| 8943 | final boolean normalizeScanTxTime = (totalScanTimeMs > txTimeMs); |
| 8944 | |
| 8945 | if (DEBUG_ENERGY) { |
| 8946 | Slog.d(TAG, "Normalizing scan power for RX=" + normalizeScanRxTime |
| 8947 | + " TX=" + normalizeScanTxTime); |
| 8948 | } |
| 8949 | |
| 8950 | long leftOverRxTimeMs = rxTimeMs; |
| 8951 | long leftOverTxTimeMs = txTimeMs; |
| 8952 | |
| 8953 | for (int i = 0; i < uidCount; i++) { |
| 8954 | final Uid u = mUidStats.valueAt(i); |
| 8955 | if (u.mBluetoothScanTimer == null) { |
| 8956 | continue; |
| 8957 | } |
| 8958 | |
| 8959 | long scanTimeSinceMarkMs = u.mBluetoothScanTimer.getTimeSinceMarkLocked( |
| 8960 | elapsedRealtimeMs * 1000) / 1000; |
| 8961 | if (scanTimeSinceMarkMs > 0) { |
| 8962 | // Set the new mark so that next time we get new data since this point. |
| 8963 | u.mBluetoothScanTimer.setMark(elapsedRealtimeMs); |
| 8964 | |
| 8965 | long scanTimeRxSinceMarkMs = scanTimeSinceMarkMs; |
| 8966 | long scanTimeTxSinceMarkMs = scanTimeSinceMarkMs; |
| 8967 | |
| 8968 | if (normalizeScanRxTime) { |
| 8969 | // Scan time is longer than the total rx time in the controller, |
| 8970 | // so distribute the scan time proportionately. This means regular traffic |
| 8971 | // will not blamed, but scans are more expensive anyways. |
| 8972 | scanTimeRxSinceMarkMs = (rxTimeMs * scanTimeRxSinceMarkMs) / totalScanTimeMs; |
| 8973 | } |
| 8974 | |
| 8975 | if (normalizeScanTxTime) { |
| 8976 | // Scan time is longer than the total tx time in the controller, |
| 8977 | // so distribute the scan time proportionately. This means regular traffic |
| 8978 | // will not blamed, but scans are more expensive anyways. |
| 8979 | scanTimeTxSinceMarkMs = (txTimeMs * scanTimeTxSinceMarkMs) / totalScanTimeMs; |
| 8980 | } |
| 8981 | |
| 8982 | final ControllerActivityCounterImpl counter = |
| 8983 | u.getOrCreateBluetoothControllerActivityLocked(); |
| 8984 | counter.getRxTimeCounter().addCountLocked(scanTimeRxSinceMarkMs); |
| 8985 | counter.getTxTimeCounters()[0].addCountLocked(scanTimeTxSinceMarkMs); |
| 8986 | |
| 8987 | leftOverRxTimeMs -= scanTimeRxSinceMarkMs; |
| 8988 | leftOverTxTimeMs -= scanTimeTxSinceMarkMs; |
| 8989 | } |
| 8990 | } |
| 8991 | |
| 8992 | if (DEBUG_ENERGY) { |
| 8993 | Slog.d(TAG, "Left over time for traffic RX=" + leftOverRxTimeMs |
| 8994 | + " TX=" + leftOverTxTimeMs); |
| 8995 | } |
| 8996 | |
| 8997 | // |
| 8998 | // Now distribute blame to apps that did bluetooth traffic. |
| 8999 | // |
| 9000 | |
| 9001 | long totalTxBytes = 0; |
| 9002 | long totalRxBytes = 0; |
| 9003 | |
| 9004 | final UidTraffic[] uidTraffic = info.getUidTraffic(); |
| 9005 | final int numUids = uidTraffic != null ? uidTraffic.length : 0; |
| 9006 | for (int i = 0; i < numUids; i++) { |
| 9007 | final UidTraffic traffic = uidTraffic[i]; |
| 9008 | |
| 9009 | // Add to the global counters. |
| 9010 | mNetworkByteActivityCounters[NETWORK_BT_RX_DATA].addCountLocked( |
| 9011 | traffic.getRxBytes()); |
| 9012 | mNetworkByteActivityCounters[NETWORK_BT_TX_DATA].addCountLocked( |
| 9013 | traffic.getTxBytes()); |
| 9014 | |
| 9015 | // Add to the UID counters. |
| 9016 | final Uid u = getUidStatsLocked(mapUid(traffic.getUid())); |
| 9017 | u.noteNetworkActivityLocked(NETWORK_BT_RX_DATA, traffic.getRxBytes(), 0); |
| 9018 | u.noteNetworkActivityLocked(NETWORK_BT_TX_DATA, traffic.getTxBytes(), 0); |
| 9019 | |
| 9020 | // Calculate the total traffic. |
| 9021 | totalTxBytes += traffic.getTxBytes(); |
| 9022 | totalRxBytes += traffic.getRxBytes(); |
| 9023 | } |
| 9024 | |
| 9025 | if ((totalTxBytes != 0 || totalRxBytes != 0) && |
| 9026 | (leftOverRxTimeMs != 0 || leftOverTxTimeMs != 0)) { |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 9027 | for (int i = 0; i < numUids; i++) { |
| 9028 | final UidTraffic traffic = uidTraffic[i]; |
| 9029 | |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 9030 | final Uid u = getUidStatsLocked(mapUid(traffic.getUid())); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 9031 | final ControllerActivityCounterImpl counter = |
| 9032 | u.getOrCreateBluetoothControllerActivityLocked(); |
| 9033 | |
| 9034 | if (totalRxBytes > 0 && traffic.getRxBytes() > 0) { |
| 9035 | final long timeRxMs = (leftOverRxTimeMs * traffic.getRxBytes()) / totalRxBytes; |
| 9036 | |
| 9037 | if (DEBUG_ENERGY) { |
| 9038 | Slog.d(TAG, "UID=" + traffic.getUid() + " rx_bytes=" + traffic.getRxBytes() |
| 9039 | + " rx_time=" + timeRxMs); |
| 9040 | } |
| 9041 | counter.getRxTimeCounter().addCountLocked(timeRxMs); |
| 9042 | leftOverRxTimeMs -= timeRxMs; |
| 9043 | } |
| 9044 | |
| 9045 | if (totalTxBytes > 0 && traffic.getTxBytes() > 0) { |
| 9046 | final long timeTxMs = (leftOverTxTimeMs * traffic.getTxBytes()) / totalTxBytes; |
| 9047 | |
| 9048 | if (DEBUG_ENERGY) { |
| 9049 | Slog.d(TAG, "UID=" + traffic.getUid() + " tx_bytes=" + traffic.getTxBytes() |
| 9050 | + " tx_time=" + timeTxMs); |
| 9051 | } |
| 9052 | |
| 9053 | counter.getTxTimeCounters()[0].addCountLocked(timeTxMs); |
| 9054 | leftOverTxTimeMs -= timeTxMs; |
| 9055 | } |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 9056 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 9057 | } |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 9058 | |
| 9059 | mBluetoothActivity.getRxTimeCounter().addCountLocked( |
| 9060 | info.getControllerRxTimeMillis()); |
| 9061 | mBluetoothActivity.getTxTimeCounters()[0].addCountLocked( |
| 9062 | info.getControllerTxTimeMillis()); |
| 9063 | mBluetoothActivity.getIdleTimeCounter().addCountLocked( |
| 9064 | info.getControllerIdleTimeMillis()); |
| 9065 | |
| 9066 | // POWER_BLUETOOTH_CONTROLLER_OPERATING_VOLTAGE is measured in mV, so convert to V. |
| 9067 | final double opVolt = mPowerProfile.getAveragePower( |
| 9068 | PowerProfile.POWER_BLUETOOTH_CONTROLLER_OPERATING_VOLTAGE) / 1000.0; |
| 9069 | if (opVolt != 0) { |
| 9070 | // We store the power drain as mAms. |
| 9071 | mBluetoothActivity.getPowerCounter().addCountLocked( |
| 9072 | (long) (info.getControllerEnergyUsed() / opVolt)); |
| 9073 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 9074 | } |
| 9075 | |
| 9076 | /** |
| 9077 | * Read and distribute kernel wake lock use across apps. |
| 9078 | */ |
| 9079 | public void updateKernelWakelocksLocked() { |
| 9080 | final KernelWakelockStats wakelockStats = mKernelWakelockReader.readKernelWakelockStats( |
| 9081 | mTmpWakelockStats); |
| 9082 | if (wakelockStats == null) { |
| 9083 | // Not crashing might make board bringup easier. |
| 9084 | Slog.w(TAG, "Couldn't get kernel wake lock stats"); |
| 9085 | return; |
| 9086 | } |
| 9087 | |
| 9088 | for (Map.Entry<String, KernelWakelockStats.Entry> ent : wakelockStats.entrySet()) { |
| 9089 | String name = ent.getKey(); |
| 9090 | KernelWakelockStats.Entry kws = ent.getValue(); |
| 9091 | |
| 9092 | SamplingTimer kwlt = mKernelWakelockStats.get(name); |
| 9093 | if (kwlt == null) { |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 9094 | kwlt = new SamplingTimer(mClocks, mOnBatteryScreenOffTimeBase); |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 9095 | mKernelWakelockStats.put(name, kwlt); |
| 9096 | } |
Adam Lesinski | d84ad30 | 2016-05-17 18:31:02 -0700 | [diff] [blame] | 9097 | |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 9098 | kwlt.update(kws.mTotalTime, kws.mCount); |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 9099 | kwlt.setUpdateVersion(kws.mVersion); |
| 9100 | } |
| 9101 | |
Adam Lesinski | fbabe7d | 2015-08-03 14:37:38 -0700 | [diff] [blame] | 9102 | int numWakelocksSetStale = 0; |
Adam Lesinski | d84ad30 | 2016-05-17 18:31:02 -0700 | [diff] [blame] | 9103 | // Set timers to stale if they didn't appear in /d/wakeup_sources (or /proc/wakelocks) |
| 9104 | // this time. |
| 9105 | for (Map.Entry<String, SamplingTimer> ent : mKernelWakelockStats.entrySet()) { |
| 9106 | SamplingTimer st = ent.getValue(); |
| 9107 | if (st.getUpdateVersion() != wakelockStats.kernelWakelockVersion) { |
| 9108 | st.endSample(); |
| 9109 | numWakelocksSetStale++; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 9110 | } |
| 9111 | } |
Adam Lesinski | fbabe7d | 2015-08-03 14:37:38 -0700 | [diff] [blame] | 9112 | |
Adam Lesinski | d84ad30 | 2016-05-17 18:31:02 -0700 | [diff] [blame] | 9113 | // Record whether we've seen a non-zero time (for debugging b/22716723). |
| 9114 | if (wakelockStats.isEmpty()) { |
Adam Lesinski | fbabe7d | 2015-08-03 14:37:38 -0700 | [diff] [blame] | 9115 | Slog.wtf(TAG, "All kernel wakelocks had time of zero"); |
| 9116 | } |
| 9117 | |
| 9118 | if (numWakelocksSetStale == mKernelWakelockStats.size()) { |
| 9119 | Slog.wtf(TAG, "All kernel wakelocks were set stale. new version=" + |
| 9120 | wakelockStats.kernelWakelockVersion); |
| 9121 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 9122 | } |
| 9123 | |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 9124 | // We use an anonymous class to access these variables, |
| 9125 | // so they can't live on the stack or they'd have to be |
| 9126 | // final MutableLong objects (more allocations). |
| 9127 | // Used in updateCpuTimeLocked(). |
| 9128 | long mTempTotalCpuUserTimeUs; |
| 9129 | long mTempTotalCpuSystemTimeUs; |
| 9130 | |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 9131 | /** |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 9132 | * Read and distribute CPU usage across apps. If their are partial wakelocks being held |
| 9133 | * and we are on battery with screen off, we give more of the cpu time to those apps holding |
| 9134 | * 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] | 9135 | */ |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 9136 | public void updateCpuTimeLocked() { |
Adam Lesinski | 52290c9c | 2015-09-21 16:54:52 -0700 | [diff] [blame] | 9137 | if (mPowerProfile == null) { |
| 9138 | return; |
| 9139 | } |
| 9140 | |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 9141 | if (DEBUG_ENERGY_CPU) { |
| 9142 | Slog.d(TAG, "!Cpu updating!"); |
| 9143 | } |
| 9144 | |
| 9145 | // Holding a wakelock costs more than just using the cpu. |
| 9146 | // Currently, we assign only half the cpu time to an app that is running but |
| 9147 | // not holding a wakelock. The apps holding wakelocks get the rest of the blame. |
| 9148 | // If no app is holding a wakelock, then the distribution is normal. |
| 9149 | final int wakelockWeight = 50; |
| 9150 | |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 9151 | // Read the time spent for each cluster at various cpu frequencies. |
| 9152 | final long[][] clusterSpeeds = new long[mKernelCpuSpeedReaders.length][]; |
| 9153 | for (int cluster = 0; cluster < mKernelCpuSpeedReaders.length; cluster++) { |
| 9154 | clusterSpeeds[cluster] = mKernelCpuSpeedReaders[cluster].readDelta(); |
| 9155 | } |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 9156 | |
| 9157 | int numWakelocks = 0; |
| 9158 | |
| 9159 | // Calculate how many wakelocks we have to distribute amongst. The system is excluded. |
| 9160 | // Only distribute cpu power to wakelocks if the screen is off and we're on battery. |
| 9161 | final int numPartialTimers = mPartialTimers.size(); |
| 9162 | if (mOnBatteryScreenOffTimeBase.isRunning()) { |
| 9163 | for (int i = 0; i < numPartialTimers; i++) { |
| 9164 | final StopwatchTimer timer = mPartialTimers.get(i); |
| 9165 | if (timer.mInList && timer.mUid != null && timer.mUid.mUid != Process.SYSTEM_UID) { |
| 9166 | // Since the collection and blaming of wakelocks can be scheduled to run after |
| 9167 | // some delay, the mPartialTimers list may have new entries. We can't blame |
| 9168 | // the newly added timer for past cpu time, so we only consider timers that |
| 9169 | // were present for one round of collection. Once a timer has gone through |
| 9170 | // a round of collection, its mInList field is set to true. |
| 9171 | numWakelocks++; |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 9172 | } |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 9173 | } |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 9174 | } |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 9175 | |
| 9176 | final int numWakelocksF = numWakelocks; |
| 9177 | mTempTotalCpuUserTimeUs = 0; |
| 9178 | mTempTotalCpuSystemTimeUs = 0; |
| 9179 | |
| 9180 | // Read the CPU data for each UID. This will internally generate a snapshot so next time |
| 9181 | // we read, we get a delta. If we are to distribute the cpu time, then do so. Otherwise |
| 9182 | // we just ignore the data. |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9183 | final long startTimeMs = mClocks.elapsedRealtime(); |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 9184 | mKernelUidCpuTimeReader.readDelta(!mOnBatteryInternal ? null : |
| 9185 | new KernelUidCpuTimeReader.Callback() { |
| 9186 | @Override |
Adam Lesinski | a7a4ccc | 2015-06-26 17:43:04 -0700 | [diff] [blame] | 9187 | public void onUidCpuTime(int uid, long userTimeUs, long systemTimeUs, |
| 9188 | long powerMaUs) { |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 9189 | final Uid u = getUidStatsLocked(mapUid(uid)); |
| 9190 | |
| 9191 | // Accumulate the total system and user time. |
| 9192 | mTempTotalCpuUserTimeUs += userTimeUs; |
| 9193 | mTempTotalCpuSystemTimeUs += systemTimeUs; |
| 9194 | |
| 9195 | StringBuilder sb = null; |
| 9196 | if (DEBUG_ENERGY_CPU) { |
| 9197 | sb = new StringBuilder(); |
| 9198 | sb.append(" got time for uid=").append(u.mUid).append(": u="); |
| 9199 | TimeUtils.formatDuration(userTimeUs / 1000, sb); |
| 9200 | sb.append(" s="); |
| 9201 | TimeUtils.formatDuration(systemTimeUs / 1000, sb); |
Adam Lesinski | a7a4ccc | 2015-06-26 17:43:04 -0700 | [diff] [blame] | 9202 | sb.append(" p=").append(powerMaUs / 1000).append("mAms\n"); |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 9203 | } |
| 9204 | |
| 9205 | if (numWakelocksF > 0) { |
| 9206 | // We have wakelocks being held, so only give a portion of the |
| 9207 | // time to the process. The rest will be distributed among wakelock |
| 9208 | // holders. |
| 9209 | userTimeUs = (userTimeUs * wakelockWeight) / 100; |
| 9210 | systemTimeUs = (systemTimeUs * wakelockWeight) / 100; |
| 9211 | } |
| 9212 | |
| 9213 | if (sb != null) { |
| 9214 | sb.append(" adding to uid=").append(u.mUid).append(": u="); |
| 9215 | TimeUtils.formatDuration(userTimeUs / 1000, sb); |
| 9216 | sb.append(" s="); |
| 9217 | TimeUtils.formatDuration(systemTimeUs / 1000, sb); |
Adam Lesinski | a7a4ccc | 2015-06-26 17:43:04 -0700 | [diff] [blame] | 9218 | sb.append(" p=").append(powerMaUs / 1000).append("mAms"); |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 9219 | Slog.d(TAG, sb.toString()); |
| 9220 | } |
| 9221 | |
| 9222 | u.mUserCpuTime.addCountLocked(userTimeUs); |
| 9223 | u.mSystemCpuTime.addCountLocked(systemTimeUs); |
Adam Lesinski | a7a4ccc | 2015-06-26 17:43:04 -0700 | [diff] [blame] | 9224 | u.mCpuPower.addCountLocked(powerMaUs); |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 9225 | |
| 9226 | // Add the cpu speeds to this UID. These are used as a ratio |
| 9227 | // for computing the power this UID used. |
Adam Lesinski | 52290c9c | 2015-09-21 16:54:52 -0700 | [diff] [blame] | 9228 | final int numClusters = mPowerProfile.getNumCpuClusters(); |
| 9229 | if (u.mCpuClusterSpeed == null || u.mCpuClusterSpeed.length != |
| 9230 | numClusters) { |
| 9231 | u.mCpuClusterSpeed = new LongSamplingCounter[numClusters][]; |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 9232 | } |
| 9233 | |
| 9234 | for (int cluster = 0; cluster < clusterSpeeds.length; cluster++) { |
Adam Lesinski | 52290c9c | 2015-09-21 16:54:52 -0700 | [diff] [blame] | 9235 | final int speedsInCluster = mPowerProfile.getNumSpeedStepsInCpuCluster( |
| 9236 | cluster); |
| 9237 | if (u.mCpuClusterSpeed[cluster] == null || speedsInCluster != |
| 9238 | u.mCpuClusterSpeed[cluster].length) { |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 9239 | u.mCpuClusterSpeed[cluster] = |
Adam Lesinski | 52290c9c | 2015-09-21 16:54:52 -0700 | [diff] [blame] | 9240 | new LongSamplingCounter[speedsInCluster]; |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 9241 | } |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 9242 | |
| 9243 | final LongSamplingCounter[] cpuSpeeds = u.mCpuClusterSpeed[cluster]; |
| 9244 | for (int speed = 0; speed < clusterSpeeds[cluster].length; speed++) { |
| 9245 | if (cpuSpeeds[speed] == null) { |
| 9246 | cpuSpeeds[speed] = new LongSamplingCounter(mOnBatteryTimeBase); |
| 9247 | } |
| 9248 | cpuSpeeds[speed].addCountLocked(clusterSpeeds[cluster][speed]); |
| 9249 | } |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 9250 | } |
| 9251 | } |
| 9252 | }); |
| 9253 | |
| 9254 | if (DEBUG_ENERGY_CPU) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9255 | Slog.d(TAG, "Reading cpu stats took " + (mClocks.elapsedRealtime() - startTimeMs) + |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 9256 | " ms"); |
| 9257 | } |
| 9258 | |
| 9259 | if (mOnBatteryInternal && numWakelocks > 0) { |
| 9260 | // Distribute a portion of the total cpu time to wakelock holders. |
| 9261 | mTempTotalCpuUserTimeUs = (mTempTotalCpuUserTimeUs * (100 - wakelockWeight)) / 100; |
| 9262 | mTempTotalCpuSystemTimeUs = |
| 9263 | (mTempTotalCpuSystemTimeUs * (100 - wakelockWeight)) / 100; |
| 9264 | |
| 9265 | for (int i = 0; i < numPartialTimers; i++) { |
| 9266 | final StopwatchTimer timer = mPartialTimers.get(i); |
| 9267 | |
| 9268 | // The system does not share any blame, as it is usually holding the wakelock |
| 9269 | // on behalf of an app. |
| 9270 | if (timer.mInList && timer.mUid != null && timer.mUid.mUid != Process.SYSTEM_UID) { |
| 9271 | int userTimeUs = (int) (mTempTotalCpuUserTimeUs / numWakelocks); |
| 9272 | int systemTimeUs = (int) (mTempTotalCpuSystemTimeUs / numWakelocks); |
| 9273 | |
| 9274 | if (DEBUG_ENERGY_CPU) { |
| 9275 | StringBuilder sb = new StringBuilder(); |
| 9276 | sb.append(" Distributing wakelock uid=").append(timer.mUid.mUid) |
| 9277 | .append(": u="); |
| 9278 | TimeUtils.formatDuration(userTimeUs / 1000, sb); |
| 9279 | sb.append(" s="); |
| 9280 | TimeUtils.formatDuration(systemTimeUs / 1000, sb); |
| 9281 | Slog.d(TAG, sb.toString()); |
| 9282 | } |
| 9283 | |
| 9284 | timer.mUid.mUserCpuTime.addCountLocked(userTimeUs); |
| 9285 | timer.mUid.mSystemCpuTime.addCountLocked(systemTimeUs); |
| 9286 | |
| 9287 | final Uid.Proc proc = timer.mUid.getProcessStatsLocked("*wakelock*"); |
Adam Lesinski | 062e66c | 2015-07-14 12:02:44 -0700 | [diff] [blame] | 9288 | proc.addCpuTimeLocked(userTimeUs / 1000, systemTimeUs / 1000); |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 9289 | |
| 9290 | mTempTotalCpuUserTimeUs -= userTimeUs; |
| 9291 | mTempTotalCpuSystemTimeUs -= systemTimeUs; |
| 9292 | numWakelocks--; |
| 9293 | } |
| 9294 | } |
| 9295 | |
| 9296 | if (mTempTotalCpuUserTimeUs > 0 || mTempTotalCpuSystemTimeUs > 0) { |
| 9297 | // Anything left over is given to the system. |
| 9298 | if (DEBUG_ENERGY_CPU) { |
| 9299 | StringBuilder sb = new StringBuilder(); |
| 9300 | sb.append(" Distributing lost time to system: u="); |
| 9301 | TimeUtils.formatDuration(mTempTotalCpuUserTimeUs / 1000, sb); |
| 9302 | sb.append(" s="); |
| 9303 | TimeUtils.formatDuration(mTempTotalCpuSystemTimeUs / 1000, sb); |
| 9304 | Slog.d(TAG, sb.toString()); |
| 9305 | } |
| 9306 | |
| 9307 | final Uid u = getUidStatsLocked(Process.SYSTEM_UID); |
| 9308 | u.mUserCpuTime.addCountLocked(mTempTotalCpuUserTimeUs); |
| 9309 | u.mSystemCpuTime.addCountLocked(mTempTotalCpuSystemTimeUs); |
| 9310 | |
| 9311 | final Uid.Proc proc = u.getProcessStatsLocked("*lost*"); |
Adam Lesinski | 062e66c | 2015-07-14 12:02:44 -0700 | [diff] [blame] | 9312 | proc.addCpuTimeLocked((int) mTempTotalCpuUserTimeUs / 1000, |
| 9313 | (int) mTempTotalCpuSystemTimeUs / 1000); |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 9314 | } |
| 9315 | } |
| 9316 | |
| 9317 | // See if there is a difference in wakelocks between this collection and the last |
| 9318 | // collection. |
| 9319 | if (ArrayUtils.referenceEquals(mPartialTimers, mLastPartialTimers)) { |
| 9320 | // No difference, so each timer is now considered for the next collection. |
| 9321 | for (int i = 0; i < numPartialTimers; i++) { |
| 9322 | mPartialTimers.get(i).mInList = true; |
| 9323 | } |
| 9324 | } else { |
| 9325 | // The lists are different, meaning we added (or removed a timer) since the last |
| 9326 | // collection. |
| 9327 | final int numLastPartialTimers = mLastPartialTimers.size(); |
| 9328 | for (int i = 0; i < numLastPartialTimers; i++) { |
| 9329 | mLastPartialTimers.get(i).mInList = false; |
| 9330 | } |
| 9331 | mLastPartialTimers.clear(); |
| 9332 | |
| 9333 | // Mark the current timers as gone through a collection. |
| 9334 | for (int i = 0; i < numPartialTimers; i++) { |
| 9335 | final StopwatchTimer timer = mPartialTimers.get(i); |
| 9336 | timer.mInList = true; |
| 9337 | mLastPartialTimers.add(timer); |
| 9338 | } |
| 9339 | } |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 9340 | } |
| 9341 | |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 9342 | boolean setChargingLocked(boolean charging) { |
| 9343 | if (mCharging != charging) { |
| 9344 | mCharging = charging; |
| 9345 | if (charging) { |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 9346 | mHistoryCur.states2 |= HistoryItem.STATE2_CHARGING_FLAG; |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 9347 | } else { |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 9348 | mHistoryCur.states2 &= ~HistoryItem.STATE2_CHARGING_FLAG; |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 9349 | } |
| 9350 | mHandler.sendEmptyMessage(MSG_REPORT_CHARGING); |
| 9351 | return true; |
| 9352 | } |
| 9353 | return false; |
| 9354 | } |
| 9355 | |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 9356 | void setOnBatteryLocked(final long mSecRealtime, final long mSecUptime, final boolean onBattery, |
Adam Lesinski | f9b20a9 | 2016-06-17 17:30:01 -0700 | [diff] [blame] | 9357 | final int oldStatus, final int level, final int chargeUAh) { |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 9358 | boolean doWrite = false; |
| 9359 | Message m = mHandler.obtainMessage(MSG_REPORT_POWER_CHANGE); |
| 9360 | m.arg1 = onBattery ? 1 : 0; |
| 9361 | mHandler.sendMessage(m); |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 9362 | |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 9363 | final long uptime = mSecUptime * 1000; |
| 9364 | final long realtime = mSecRealtime * 1000; |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 9365 | final boolean screenOn = mScreenState == Display.STATE_ON; |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 9366 | if (onBattery) { |
| 9367 | // We will reset our status if we are unplugging after the |
| 9368 | // battery was last full, or the level is at 100, or |
| 9369 | // we have gone through a significant charge (from a very low |
| 9370 | // level to a now very high level). |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 9371 | boolean reset = false; |
Dianne Hackborn | 9a75543 | 2014-05-15 17:05:22 -0700 | [diff] [blame] | 9372 | if (!mNoAutoReset && (oldStatus == BatteryManager.BATTERY_STATUS_FULL |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 9373 | || level >= 90 |
Dianne Hackborn | fb3809c | 2014-09-29 18:31:22 -0700 | [diff] [blame] | 9374 | || (mDischargeCurrentLevel < 20 && level >= 80) |
| 9375 | || (getHighDischargeAmountSinceCharge() >= 200 |
| 9376 | && mHistoryBuffer.dataSize() >= MAX_HISTORY_BUFFER))) { |
Dianne Hackborn | 73d6a82 | 2014-09-29 10:52:47 -0700 | [diff] [blame] | 9377 | Slog.i(TAG, "Resetting battery stats: level=" + level + " status=" + oldStatus |
Dianne Hackborn | fb3809c | 2014-09-29 18:31:22 -0700 | [diff] [blame] | 9378 | + " dischargeLevel=" + mDischargeCurrentLevel |
Dianne Hackborn | 73d6a82 | 2014-09-29 10:52:47 -0700 | [diff] [blame] | 9379 | + " lowAmount=" + getLowDischargeAmountSinceCharge() |
| 9380 | + " highAmount=" + getHighDischargeAmountSinceCharge()); |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 9381 | // Before we write, collect a snapshot of the final aggregated |
| 9382 | // stats to be reported in the next checkin. Only do this if we have |
| 9383 | // a sufficient amount of data to make it interesting. |
| 9384 | if (getLowDischargeAmountSinceCharge() >= 20) { |
| 9385 | final Parcel parcel = Parcel.obtain(); |
| 9386 | writeSummaryToParcel(parcel, true); |
| 9387 | BackgroundThread.getHandler().post(new Runnable() { |
| 9388 | @Override public void run() { |
| 9389 | synchronized (mCheckinFile) { |
| 9390 | FileOutputStream stream = null; |
| 9391 | try { |
| 9392 | stream = mCheckinFile.startWrite(); |
| 9393 | stream.write(parcel.marshall()); |
| 9394 | stream.flush(); |
| 9395 | FileUtils.sync(stream); |
| 9396 | stream.close(); |
| 9397 | mCheckinFile.finishWrite(stream); |
| 9398 | } catch (IOException e) { |
| 9399 | Slog.w("BatteryStats", |
| 9400 | "Error writing checkin battery statistics", e); |
| 9401 | mCheckinFile.failWrite(stream); |
| 9402 | } finally { |
| 9403 | parcel.recycle(); |
| 9404 | } |
| 9405 | } |
| 9406 | } |
| 9407 | }); |
| 9408 | } |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 9409 | doWrite = true; |
| 9410 | resetAllStatsLocked(); |
Adam Lesinski | f9b20a9 | 2016-06-17 17:30:01 -0700 | [diff] [blame] | 9411 | if (chargeUAh > 0) { |
| 9412 | // Only use the reported coulomb charge value if it is supported and reported. |
| 9413 | mEstimatedBatteryCapacity = (int) ((level / 100.0) * (chargeUAh / 1000)); |
| 9414 | } |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 9415 | mDischargeStartLevel = level; |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 9416 | reset = true; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 9417 | mDischargeStepTracker.init(); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9418 | } |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 9419 | if (mCharging) { |
| 9420 | setChargingLocked(false); |
| 9421 | } |
| 9422 | mLastChargingStateLevel = level; |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 9423 | mOnBattery = mOnBatteryInternal = true; |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 9424 | mLastDischargeStepLevel = level; |
Dianne Hackborn | 2932513 | 2014-05-21 15:01:03 -0700 | [diff] [blame] | 9425 | mMinDischargeStepLevel = level; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 9426 | mDischargeStepTracker.clearTime(); |
| 9427 | mDailyDischargeStepTracker.clearTime(); |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 9428 | mInitStepMode = mCurStepMode; |
| 9429 | mModStepMode = 0; |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 9430 | pullPendingStateUpdatesLocked(); |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 9431 | mHistoryCur.batteryLevel = (byte)level; |
| 9432 | mHistoryCur.states &= ~HistoryItem.STATE_BATTERY_PLUGGED_FLAG; |
| 9433 | if (DEBUG_HISTORY) Slog.v(TAG, "Battery unplugged to: " |
| 9434 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 9435 | if (reset) { |
| 9436 | mRecordingHistory = true; |
| 9437 | startRecordingHistory(mSecRealtime, mSecUptime, reset); |
| 9438 | } |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 9439 | addHistoryRecordLocked(mSecRealtime, mSecUptime); |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 9440 | mDischargeCurrentLevel = mDischargeUnplugLevel = level; |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 9441 | if (screenOn) { |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 9442 | mDischargeScreenOnUnplugLevel = level; |
| 9443 | mDischargeScreenOffUnplugLevel = 0; |
| 9444 | } else { |
| 9445 | mDischargeScreenOnUnplugLevel = 0; |
| 9446 | mDischargeScreenOffUnplugLevel = level; |
| 9447 | } |
| 9448 | mDischargeAmountScreenOn = 0; |
| 9449 | mDischargeAmountScreenOff = 0; |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 9450 | updateTimeBasesLocked(true, !screenOn, uptime, realtime); |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 9451 | } else { |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 9452 | mLastChargingStateLevel = level; |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 9453 | mOnBattery = mOnBatteryInternal = false; |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 9454 | pullPendingStateUpdatesLocked(); |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 9455 | mHistoryCur.batteryLevel = (byte)level; |
| 9456 | mHistoryCur.states |= HistoryItem.STATE_BATTERY_PLUGGED_FLAG; |
| 9457 | if (DEBUG_HISTORY) Slog.v(TAG, "Battery plugged to: " |
| 9458 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 9459 | addHistoryRecordLocked(mSecRealtime, mSecUptime); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 9460 | mDischargeCurrentLevel = mDischargePlugLevel = level; |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 9461 | if (level < mDischargeUnplugLevel) { |
| 9462 | mLowDischargeAmountSinceCharge += mDischargeUnplugLevel-level-1; |
| 9463 | mHighDischargeAmountSinceCharge += mDischargeUnplugLevel-level; |
| 9464 | } |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 9465 | updateDischargeScreenLevelsLocked(screenOn, screenOn); |
| 9466 | updateTimeBasesLocked(false, !screenOn, uptime, realtime); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 9467 | mChargeStepTracker.init(); |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 9468 | mLastChargeStepLevel = level; |
Dianne Hackborn | 2932513 | 2014-05-21 15:01:03 -0700 | [diff] [blame] | 9469 | mMaxChargeStepLevel = level; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 9470 | mInitStepMode = mCurStepMode; |
| 9471 | mModStepMode = 0; |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 9472 | } |
| 9473 | if (doWrite || (mLastWriteTime + (60 * 1000)) < mSecRealtime) { |
| 9474 | if (mFile != null) { |
| 9475 | writeAsyncLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9476 | } |
| 9477 | } |
| 9478 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 9479 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 9480 | private void startRecordingHistory(final long elapsedRealtimeMs, final long uptimeMs, |
| 9481 | boolean reset) { |
| 9482 | mRecordingHistory = true; |
| 9483 | mHistoryCur.currentTime = System.currentTimeMillis(); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 9484 | addHistoryBufferLocked(elapsedRealtimeMs, uptimeMs, |
| 9485 | reset ? HistoryItem.CMD_RESET : HistoryItem.CMD_CURRENT_TIME, |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 9486 | mHistoryCur); |
| 9487 | mHistoryCur.currentTime = 0; |
| 9488 | if (reset) { |
| 9489 | initActiveHistoryEventsLocked(elapsedRealtimeMs, uptimeMs); |
| 9490 | } |
| 9491 | } |
| 9492 | |
Dianne Hackborn | 7d9eefd | 2014-08-27 18:30:31 -0700 | [diff] [blame] | 9493 | private void recordCurrentTimeChangeLocked(final long currentTime, final long elapsedRealtimeMs, |
| 9494 | final long uptimeMs) { |
| 9495 | if (mRecordingHistory) { |
| 9496 | mHistoryCur.currentTime = currentTime; |
| 9497 | addHistoryBufferLocked(elapsedRealtimeMs, uptimeMs, HistoryItem.CMD_CURRENT_TIME, |
| 9498 | mHistoryCur); |
| 9499 | mHistoryCur.currentTime = 0; |
| 9500 | } |
| 9501 | } |
| 9502 | |
Dianne Hackborn | 29cd7f1 | 2015-01-08 10:37:05 -0800 | [diff] [blame] | 9503 | private void recordShutdownLocked(final long elapsedRealtimeMs, final long uptimeMs) { |
| 9504 | if (mRecordingHistory) { |
| 9505 | mHistoryCur.currentTime = System.currentTimeMillis(); |
Dianne Hackborn | 29cd7f1 | 2015-01-08 10:37:05 -0800 | [diff] [blame] | 9506 | addHistoryBufferLocked(elapsedRealtimeMs, uptimeMs, HistoryItem.CMD_SHUTDOWN, |
| 9507 | mHistoryCur); |
| 9508 | mHistoryCur.currentTime = 0; |
| 9509 | } |
| 9510 | } |
| 9511 | |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 9512 | private void scheduleSyncExternalStatsLocked(String reason, int updateFlags) { |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 9513 | if (mExternalSync != null) { |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 9514 | mExternalSync.scheduleSync(reason, updateFlags); |
Adam Lesinski | a7c90c8 | 2015-06-18 14:52:24 -0700 | [diff] [blame] | 9515 | } |
| 9516 | } |
| 9517 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9518 | // 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] | 9519 | public static final int BATTERY_PLUGGED_NONE = 0; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 9520 | |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 9521 | public void setBatteryStateLocked(int status, int health, int plugType, int level, |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 9522 | int temp, int volt, int chargeUAh) { |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 9523 | final boolean onBattery = plugType == BATTERY_PLUGGED_NONE; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9524 | final long uptime = mClocks.uptimeMillis(); |
| 9525 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 9526 | if (!mHaveBatteryLevel) { |
| 9527 | mHaveBatteryLevel = true; |
| 9528 | // We start out assuming that the device is plugged in (not |
| 9529 | // on battery). If our first report is now that we are indeed |
| 9530 | // plugged in, then twiddle our state to correctly reflect that |
| 9531 | // since we won't be going through the full setOnBattery(). |
| 9532 | if (onBattery == mOnBattery) { |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 9533 | if (onBattery) { |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 9534 | mHistoryCur.states &= ~HistoryItem.STATE_BATTERY_PLUGGED_FLAG; |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 9535 | } else { |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 9536 | mHistoryCur.states |= HistoryItem.STATE_BATTERY_PLUGGED_FLAG; |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 9537 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9538 | } |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 9539 | // Always start out assuming charging, that will be updated later. |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 9540 | mHistoryCur.states2 |= HistoryItem.STATE2_CHARGING_FLAG; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 9541 | mHistoryCur.batteryStatus = (byte)status; |
| 9542 | mHistoryCur.batteryLevel = (byte)level; |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 9543 | mHistoryCur.batteryChargeUAh = chargeUAh; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 9544 | mMaxChargeStepLevel = mMinDischargeStepLevel = |
| 9545 | mLastChargeStepLevel = mLastDischargeStepLevel = level; |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 9546 | mLastChargingStateLevel = level; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 9547 | } else if (mCurrentBatteryLevel != level || mOnBattery != onBattery) { |
| 9548 | recordDailyStatsIfNeededLocked(level >= 100 && onBattery); |
| 9549 | } |
| 9550 | int oldStatus = mHistoryCur.batteryStatus; |
| 9551 | if (onBattery) { |
| 9552 | mDischargeCurrentLevel = level; |
| 9553 | if (!mRecordingHistory) { |
| 9554 | mRecordingHistory = true; |
| 9555 | startRecordingHistory(elapsedRealtime, uptime, true); |
| 9556 | } |
| 9557 | } else if (level < 96) { |
| 9558 | if (!mRecordingHistory) { |
| 9559 | mRecordingHistory = true; |
| 9560 | startRecordingHistory(elapsedRealtime, uptime, true); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9561 | } |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 9562 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 9563 | mCurrentBatteryLevel = level; |
| 9564 | if (mDischargePlugLevel < 0) { |
| 9565 | mDischargePlugLevel = level; |
Marco Nelissen | d859331 | 2009-04-30 14:45:06 -0700 | [diff] [blame] | 9566 | } |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 9567 | |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 9568 | if (onBattery != mOnBattery) { |
| 9569 | mHistoryCur.batteryLevel = (byte)level; |
| 9570 | mHistoryCur.batteryStatus = (byte)status; |
| 9571 | mHistoryCur.batteryHealth = (byte)health; |
| 9572 | mHistoryCur.batteryPlugType = (byte)plugType; |
| 9573 | mHistoryCur.batteryTemperature = (short)temp; |
| 9574 | mHistoryCur.batteryVoltage = (char)volt; |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 9575 | if (chargeUAh < mHistoryCur.batteryChargeUAh) { |
| 9576 | // Only record discharges |
| 9577 | final long chargeDiff = mHistoryCur.batteryChargeUAh - chargeUAh; |
| 9578 | mDischargeCounter.addCountLocked(chargeDiff); |
| 9579 | mDischargeScreenOffCounter.addCountLocked(chargeDiff); |
| 9580 | } |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 9581 | mHistoryCur.batteryChargeUAh = chargeUAh; |
Adam Lesinski | f9b20a9 | 2016-06-17 17:30:01 -0700 | [diff] [blame] | 9582 | setOnBatteryLocked(elapsedRealtime, uptime, onBattery, oldStatus, level, chargeUAh); |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 9583 | } else { |
| 9584 | boolean changed = false; |
| 9585 | if (mHistoryCur.batteryLevel != level) { |
| 9586 | mHistoryCur.batteryLevel = (byte)level; |
| 9587 | changed = true; |
Marco Nelissen | d859331 | 2009-04-30 14:45:06 -0700 | [diff] [blame] | 9588 | |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 9589 | // TODO(adamlesinski): Schedule the creation of a HistoryStepDetails record |
| 9590 | // which will pull external stats. |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 9591 | scheduleSyncExternalStatsLocked("battery-level", ExternalStatsSync.UPDATE_ALL); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 9592 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 9593 | if (mHistoryCur.batteryStatus != status) { |
| 9594 | mHistoryCur.batteryStatus = (byte)status; |
| 9595 | changed = true; |
| 9596 | } |
| 9597 | if (mHistoryCur.batteryHealth != health) { |
| 9598 | mHistoryCur.batteryHealth = (byte)health; |
| 9599 | changed = true; |
| 9600 | } |
| 9601 | if (mHistoryCur.batteryPlugType != plugType) { |
| 9602 | mHistoryCur.batteryPlugType = (byte)plugType; |
| 9603 | changed = true; |
| 9604 | } |
| 9605 | if (temp >= (mHistoryCur.batteryTemperature+10) |
| 9606 | || temp <= (mHistoryCur.batteryTemperature-10)) { |
| 9607 | mHistoryCur.batteryTemperature = (short)temp; |
| 9608 | changed = true; |
| 9609 | } |
| 9610 | if (volt > (mHistoryCur.batteryVoltage+20) |
| 9611 | || volt < (mHistoryCur.batteryVoltage-20)) { |
| 9612 | mHistoryCur.batteryVoltage = (char)volt; |
| 9613 | changed = true; |
| 9614 | } |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 9615 | if (chargeUAh >= (mHistoryCur.batteryChargeUAh+10) |
| 9616 | || chargeUAh <= (mHistoryCur.batteryChargeUAh-10)) { |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 9617 | if (chargeUAh < mHistoryCur.batteryChargeUAh) { |
| 9618 | // Only record discharges |
| 9619 | final long chargeDiff = mHistoryCur.batteryChargeUAh - chargeUAh; |
| 9620 | mDischargeCounter.addCountLocked(chargeDiff); |
| 9621 | mDischargeScreenOffCounter.addCountLocked(chargeDiff); |
| 9622 | } |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame] | 9623 | mHistoryCur.batteryChargeUAh = chargeUAh; |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 9624 | changed = true; |
| 9625 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 9626 | long modeBits = (((long)mInitStepMode) << STEP_LEVEL_INITIAL_MODE_SHIFT) |
| 9627 | | (((long)mModStepMode) << STEP_LEVEL_MODIFIED_MODE_SHIFT) |
| 9628 | | (((long)(level&0xff)) << STEP_LEVEL_LEVEL_SHIFT); |
| 9629 | if (onBattery) { |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 9630 | changed |= setChargingLocked(false); |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 9631 | if (mLastDischargeStepLevel != level && mMinDischargeStepLevel > level) { |
| 9632 | mDischargeStepTracker.addLevelSteps(mLastDischargeStepLevel - level, |
| 9633 | modeBits, elapsedRealtime); |
| 9634 | mDailyDischargeStepTracker.addLevelSteps(mLastDischargeStepLevel - level, |
| 9635 | modeBits, elapsedRealtime); |
| 9636 | mLastDischargeStepLevel = level; |
| 9637 | mMinDischargeStepLevel = level; |
| 9638 | mInitStepMode = mCurStepMode; |
| 9639 | mModStepMode = 0; |
| 9640 | } |
| 9641 | } else { |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 9642 | if (level >= 90) { |
| 9643 | // If the battery level is at least 90%, always consider the device to be |
| 9644 | // charging even if it happens to go down a level. |
| 9645 | changed |= setChargingLocked(true); |
| 9646 | mLastChargeStepLevel = level; |
| 9647 | } if (!mCharging) { |
| 9648 | if (mLastChargeStepLevel < level) { |
| 9649 | // We have not reporting that we are charging, but the level has now |
| 9650 | // gone up, so consider the state to be charging. |
| 9651 | changed |= setChargingLocked(true); |
| 9652 | mLastChargeStepLevel = level; |
| 9653 | } |
| 9654 | } else { |
| 9655 | if (mLastChargeStepLevel > level) { |
| 9656 | // We had reported that the device was charging, but here we are with |
| 9657 | // power connected and the level going down. Looks like the current |
| 9658 | // power supplied isn't enough, so consider the device to now be |
| 9659 | // discharging. |
| 9660 | changed |= setChargingLocked(false); |
| 9661 | mLastChargeStepLevel = level; |
| 9662 | } |
| 9663 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 9664 | if (mLastChargeStepLevel != level && mMaxChargeStepLevel < level) { |
| 9665 | mChargeStepTracker.addLevelSteps(level - mLastChargeStepLevel, |
| 9666 | modeBits, elapsedRealtime); |
| 9667 | mDailyChargeStepTracker.addLevelSteps(level - mLastChargeStepLevel, |
| 9668 | modeBits, elapsedRealtime); |
| 9669 | mLastChargeStepLevel = level; |
| 9670 | mMaxChargeStepLevel = level; |
| 9671 | mInitStepMode = mCurStepMode; |
| 9672 | mModStepMode = 0; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 9673 | } |
| 9674 | } |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 9675 | if (changed) { |
| 9676 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 9677 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 9678 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 9679 | if (!onBattery && status == BatteryManager.BATTERY_STATUS_FULL) { |
| 9680 | // We don't record history while we are plugged in and fully charged. |
| 9681 | // The next time we are unplugged, history will be cleared. |
| 9682 | mRecordingHistory = DEBUG; |
Dianne Hackborn | d0c5b9a | 2014-02-21 16:19:05 -0800 | [diff] [blame] | 9683 | } |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 9684 | } |
| 9685 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9686 | public long getAwakeTimeBattery() { |
| 9687 | return computeBatteryUptime(getBatteryUptimeLocked(), STATS_CURRENT); |
| 9688 | } |
| 9689 | |
| 9690 | public long getAwakeTimePlugged() { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9691 | return (mClocks.uptimeMillis() * 1000) - getAwakeTimeBattery(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9692 | } |
| 9693 | |
| 9694 | @Override |
| 9695 | public long computeUptime(long curTime, int which) { |
| 9696 | switch (which) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9697 | case STATS_SINCE_CHARGED: return mUptime + (curTime-mUptimeStart); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9698 | case STATS_CURRENT: return (curTime-mUptimeStart); |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 9699 | case STATS_SINCE_UNPLUGGED: return (curTime-mOnBatteryTimeBase.getUptimeStart()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9700 | } |
| 9701 | return 0; |
| 9702 | } |
| 9703 | |
| 9704 | @Override |
| 9705 | public long computeRealtime(long curTime, int which) { |
| 9706 | switch (which) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9707 | case STATS_SINCE_CHARGED: return mRealtime + (curTime-mRealtimeStart); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9708 | case STATS_CURRENT: return (curTime-mRealtimeStart); |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 9709 | case STATS_SINCE_UNPLUGGED: return (curTime-mOnBatteryTimeBase.getRealtimeStart()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9710 | } |
| 9711 | return 0; |
| 9712 | } |
| 9713 | |
| 9714 | @Override |
| 9715 | public long computeBatteryUptime(long curTime, int which) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9716 | return mOnBatteryTimeBase.computeUptime(curTime, which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9717 | } |
| 9718 | |
| 9719 | @Override |
| 9720 | public long computeBatteryRealtime(long curTime, int which) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9721 | return mOnBatteryTimeBase.computeRealtime(curTime, which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9722 | } |
| 9723 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9724 | @Override |
| 9725 | public long computeBatteryScreenOffUptime(long curTime, int which) { |
| 9726 | return mOnBatteryScreenOffTimeBase.computeUptime(curTime, which); |
| 9727 | } |
| 9728 | |
| 9729 | @Override |
| 9730 | public long computeBatteryScreenOffRealtime(long curTime, int which) { |
| 9731 | return mOnBatteryScreenOffTimeBase.computeRealtime(curTime, which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9732 | } |
| 9733 | |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 9734 | private long computeTimePerLevel(long[] steps, int numSteps) { |
| 9735 | // For now we'll do a simple average across all steps. |
| 9736 | if (numSteps <= 0) { |
| 9737 | return -1; |
| 9738 | } |
| 9739 | long total = 0; |
| 9740 | for (int i=0; i<numSteps; i++) { |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 9741 | total += steps[i] & STEP_LEVEL_TIME_MASK; |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 9742 | } |
| 9743 | return total / numSteps; |
| 9744 | /* |
| 9745 | long[] buckets = new long[numSteps]; |
| 9746 | int numBuckets = 0; |
| 9747 | int numToAverage = 4; |
| 9748 | int i = 0; |
| 9749 | while (i < numSteps) { |
| 9750 | long totalTime = 0; |
| 9751 | int num = 0; |
| 9752 | for (int j=0; j<numToAverage && (i+j)<numSteps; j++) { |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 9753 | totalTime += steps[i+j] & STEP_LEVEL_TIME_MASK; |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 9754 | num++; |
| 9755 | } |
| 9756 | buckets[numBuckets] = totalTime / num; |
| 9757 | numBuckets++; |
| 9758 | numToAverage *= 2; |
| 9759 | i += num; |
| 9760 | } |
| 9761 | if (numBuckets < 1) { |
| 9762 | return -1; |
| 9763 | } |
| 9764 | long averageTime = buckets[numBuckets-1]; |
| 9765 | for (i=numBuckets-2; i>=0; i--) { |
| 9766 | averageTime = (averageTime + buckets[i]) / 2; |
| 9767 | } |
| 9768 | return averageTime; |
| 9769 | */ |
| 9770 | } |
| 9771 | |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 9772 | @Override |
| 9773 | public long computeBatteryTimeRemaining(long curTime) { |
| 9774 | if (!mOnBattery) { |
| 9775 | return -1; |
| 9776 | } |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 9777 | /* Simple implementation just looks at the average discharge per level across the |
| 9778 | entire sample period. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 9779 | int discharge = (getLowDischargeAmountSinceCharge()+getHighDischargeAmountSinceCharge())/2; |
| 9780 | if (discharge < 2) { |
| 9781 | return -1; |
| 9782 | } |
| 9783 | long duration = computeBatteryRealtime(curTime, STATS_SINCE_CHARGED); |
| 9784 | if (duration < 1000*1000) { |
| 9785 | return -1; |
| 9786 | } |
| 9787 | long usPerLevel = duration/discharge; |
| 9788 | return usPerLevel * mCurrentBatteryLevel; |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 9789 | */ |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 9790 | if (mDischargeStepTracker.mNumStepDurations < 1) { |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 9791 | return -1; |
| 9792 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 9793 | long msPerLevel = mDischargeStepTracker.computeTimePerLevel(); |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 9794 | if (msPerLevel <= 0) { |
| 9795 | return -1; |
| 9796 | } |
| 9797 | return (msPerLevel * mCurrentBatteryLevel) * 1000; |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 9798 | } |
| 9799 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 9800 | @Override |
| 9801 | public LevelStepTracker getDischargeLevelStepTracker() { |
| 9802 | return mDischargeStepTracker; |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 9803 | } |
| 9804 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 9805 | @Override |
| 9806 | public LevelStepTracker getDailyDischargeLevelStepTracker() { |
| 9807 | return mDailyDischargeStepTracker; |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 9808 | } |
| 9809 | |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 9810 | @Override |
| 9811 | public long computeChargeTimeRemaining(long curTime) { |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 9812 | if (mOnBattery) { |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 9813 | // Not yet working. |
| 9814 | return -1; |
| 9815 | } |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 9816 | /* Broken |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 9817 | int curLevel = mCurrentBatteryLevel; |
| 9818 | int plugLevel = mDischargePlugLevel; |
| 9819 | if (plugLevel < 0 || curLevel < (plugLevel+1)) { |
| 9820 | return -1; |
| 9821 | } |
| 9822 | long duration = computeBatteryRealtime(curTime, STATS_SINCE_UNPLUGGED); |
| 9823 | if (duration < 1000*1000) { |
| 9824 | return -1; |
| 9825 | } |
| 9826 | long usPerLevel = duration/(curLevel-plugLevel); |
| 9827 | return usPerLevel * (100-curLevel); |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 9828 | */ |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 9829 | if (mChargeStepTracker.mNumStepDurations < 1) { |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 9830 | return -1; |
| 9831 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 9832 | long msPerLevel = mChargeStepTracker.computeTimePerLevel(); |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 9833 | if (msPerLevel <= 0) { |
| 9834 | return -1; |
| 9835 | } |
| 9836 | return (msPerLevel * (100-mCurrentBatteryLevel)) * 1000; |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 9837 | } |
| 9838 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 9839 | @Override |
| 9840 | public LevelStepTracker getChargeLevelStepTracker() { |
| 9841 | return mChargeStepTracker; |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 9842 | } |
| 9843 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 9844 | @Override |
| 9845 | public LevelStepTracker getDailyChargeLevelStepTracker() { |
| 9846 | return mDailyChargeStepTracker; |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 9847 | } |
| 9848 | |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 9849 | @Override |
| 9850 | public ArrayList<PackageChange> getDailyPackageChanges() { |
| 9851 | return mDailyPackageChanges; |
| 9852 | } |
| 9853 | |
Joe Onorato | e1acd63 | 2016-02-23 13:25:10 -0800 | [diff] [blame] | 9854 | protected long getBatteryUptimeLocked() { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9855 | return mOnBatteryTimeBase.getUptime(mClocks.uptimeMillis() * 1000); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9856 | } |
| 9857 | |
| 9858 | @Override |
| 9859 | public long getBatteryUptime(long curTime) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9860 | return mOnBatteryTimeBase.getUptime(curTime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9861 | } |
| 9862 | |
| 9863 | @Override |
| 9864 | public long getBatteryRealtime(long curTime) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9865 | return mOnBatteryTimeBase.getRealtime(curTime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9866 | } |
Amith Yamasani | 3718aaa | 2009-06-09 06:32:35 -0700 | [diff] [blame] | 9867 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 9868 | @Override |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 9869 | public int getDischargeStartLevel() { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 9870 | synchronized(this) { |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 9871 | return getDischargeStartLevelLocked(); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 9872 | } |
| 9873 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 9874 | |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 9875 | public int getDischargeStartLevelLocked() { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9876 | return mDischargeUnplugLevel; |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 9877 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 9878 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 9879 | @Override |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 9880 | public int getDischargeCurrentLevel() { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 9881 | synchronized(this) { |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 9882 | return getDischargeCurrentLevelLocked(); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 9883 | } |
| 9884 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 9885 | |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 9886 | public int getDischargeCurrentLevelLocked() { |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 9887 | return mDischargeCurrentLevel; |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 9888 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9889 | |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 9890 | @Override |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 9891 | public int getLowDischargeAmountSinceCharge() { |
| 9892 | synchronized(this) { |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 9893 | int val = mLowDischargeAmountSinceCharge; |
| 9894 | if (mOnBattery && mDischargeCurrentLevel < mDischargeUnplugLevel) { |
| 9895 | val += mDischargeUnplugLevel-mDischargeCurrentLevel-1; |
| 9896 | } |
| 9897 | return val; |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 9898 | } |
| 9899 | } |
| 9900 | |
| 9901 | @Override |
| 9902 | public int getHighDischargeAmountSinceCharge() { |
| 9903 | synchronized(this) { |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 9904 | int val = mHighDischargeAmountSinceCharge; |
| 9905 | if (mOnBattery && mDischargeCurrentLevel < mDischargeUnplugLevel) { |
| 9906 | val += mDischargeUnplugLevel-mDischargeCurrentLevel; |
| 9907 | } |
| 9908 | return val; |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 9909 | } |
| 9910 | } |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 9911 | |
| 9912 | @Override |
| 9913 | public int getDischargeAmount(int which) { |
| 9914 | int dischargeAmount = which == STATS_SINCE_CHARGED |
| 9915 | ? getHighDischargeAmountSinceCharge() |
| 9916 | : (getDischargeStartLevel() - getDischargeCurrentLevel()); |
| 9917 | if (dischargeAmount < 0) { |
| 9918 | dischargeAmount = 0; |
| 9919 | } |
| 9920 | return dischargeAmount; |
| 9921 | } |
| 9922 | |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 9923 | public int getDischargeAmountScreenOn() { |
| 9924 | synchronized(this) { |
| 9925 | int val = mDischargeAmountScreenOn; |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 9926 | if (mOnBattery && mScreenState == Display.STATE_ON |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 9927 | && mDischargeCurrentLevel < mDischargeScreenOnUnplugLevel) { |
| 9928 | val += mDischargeScreenOnUnplugLevel-mDischargeCurrentLevel; |
| 9929 | } |
| 9930 | return val; |
| 9931 | } |
| 9932 | } |
| 9933 | |
| 9934 | public int getDischargeAmountScreenOnSinceCharge() { |
| 9935 | synchronized(this) { |
| 9936 | int val = mDischargeAmountScreenOnSinceCharge; |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 9937 | if (mOnBattery && mScreenState == Display.STATE_ON |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 9938 | && mDischargeCurrentLevel < mDischargeScreenOnUnplugLevel) { |
| 9939 | val += mDischargeScreenOnUnplugLevel-mDischargeCurrentLevel; |
| 9940 | } |
| 9941 | return val; |
| 9942 | } |
| 9943 | } |
| 9944 | |
| 9945 | public int getDischargeAmountScreenOff() { |
| 9946 | synchronized(this) { |
| 9947 | int val = mDischargeAmountScreenOff; |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 9948 | if (mOnBattery && mScreenState != Display.STATE_ON |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 9949 | && mDischargeCurrentLevel < mDischargeScreenOffUnplugLevel) { |
| 9950 | val += mDischargeScreenOffUnplugLevel-mDischargeCurrentLevel; |
| 9951 | } |
| 9952 | return val; |
| 9953 | } |
| 9954 | } |
| 9955 | |
| 9956 | public int getDischargeAmountScreenOffSinceCharge() { |
| 9957 | synchronized(this) { |
| 9958 | int val = mDischargeAmountScreenOffSinceCharge; |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 9959 | if (mOnBattery && mScreenState != Display.STATE_ON |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 9960 | && mDischargeCurrentLevel < mDischargeScreenOffUnplugLevel) { |
| 9961 | val += mDischargeScreenOffUnplugLevel-mDischargeCurrentLevel; |
| 9962 | } |
| 9963 | return val; |
| 9964 | } |
| 9965 | } |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 9966 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9967 | /** |
| 9968 | * Retrieve the statistics object for a particular uid, creating if needed. |
| 9969 | */ |
| 9970 | public Uid getUidStatsLocked(int uid) { |
| 9971 | Uid u = mUidStats.get(uid); |
| 9972 | if (u == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9973 | u = new Uid(this, uid); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9974 | mUidStats.put(uid, u); |
| 9975 | } |
| 9976 | return u; |
| 9977 | } |
| 9978 | |
| 9979 | /** |
| 9980 | * Remove the statistics object for a particular uid. |
| 9981 | */ |
| 9982 | public void removeUidStatsLocked(int uid) { |
Adam Lesinski | b83ffee | 2015-05-12 14:43:47 -0700 | [diff] [blame] | 9983 | mKernelUidCpuTimeReader.removeUid(uid); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9984 | mUidStats.remove(uid); |
| 9985 | } |
Amith Yamasani | 32dbefd | 2009-06-19 09:21:17 -0700 | [diff] [blame] | 9986 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9987 | /** |
| 9988 | * Retrieve the statistics object for a particular process, creating |
| 9989 | * if needed. |
| 9990 | */ |
| 9991 | public Uid.Proc getProcessStatsLocked(int uid, String name) { |
Dianne Hackborn | bbb7472 | 2014-03-13 09:50:24 -0700 | [diff] [blame] | 9992 | uid = mapUid(uid); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9993 | Uid u = getUidStatsLocked(uid); |
| 9994 | return u.getProcessStatsLocked(name); |
| 9995 | } |
| 9996 | |
| 9997 | /** |
| 9998 | * Retrieve the statistics object for a particular process, creating |
| 9999 | * if needed. |
| 10000 | */ |
| 10001 | public Uid.Pkg getPackageStatsLocked(int uid, String pkg) { |
Dianne Hackborn | bbb7472 | 2014-03-13 09:50:24 -0700 | [diff] [blame] | 10002 | uid = mapUid(uid); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10003 | Uid u = getUidStatsLocked(uid); |
| 10004 | return u.getPackageStatsLocked(pkg); |
| 10005 | } |
| 10006 | |
| 10007 | /** |
| 10008 | * Retrieve the statistics object for a particular service, creating |
| 10009 | * if needed. |
| 10010 | */ |
| 10011 | public Uid.Pkg.Serv getServiceStatsLocked(int uid, String pkg, String name) { |
Dianne Hackborn | bbb7472 | 2014-03-13 09:50:24 -0700 | [diff] [blame] | 10012 | uid = mapUid(uid); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10013 | Uid u = getUidStatsLocked(uid); |
| 10014 | return u.getServiceStatsLocked(pkg, name); |
| 10015 | } |
| 10016 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10017 | public void shutdownLocked() { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 10018 | recordShutdownLocked(mClocks.elapsedRealtime(), mClocks.uptimeMillis()); |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 10019 | writeSyncLocked(); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10020 | mShuttingDown = true; |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 10021 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 10022 | |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 10023 | Parcel mPendingWrite = null; |
| 10024 | final ReentrantLock mWriteLock = new ReentrantLock(); |
| 10025 | |
| 10026 | public void writeAsyncLocked() { |
| 10027 | writeLocked(false); |
| 10028 | } |
| 10029 | |
| 10030 | public void writeSyncLocked() { |
| 10031 | writeLocked(true); |
| 10032 | } |
| 10033 | |
| 10034 | void writeLocked(boolean sync) { |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 10035 | if (mFile == null) { |
| 10036 | 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] | 10037 | return; |
| 10038 | } |
| 10039 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10040 | if (mShuttingDown) { |
| 10041 | return; |
| 10042 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 10043 | |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 10044 | Parcel out = Parcel.obtain(); |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 10045 | writeSummaryToParcel(out, true); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 10046 | mLastWriteTime = mClocks.elapsedRealtime(); |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 10047 | |
| 10048 | if (mPendingWrite != null) { |
| 10049 | mPendingWrite.recycle(); |
| 10050 | } |
| 10051 | mPendingWrite = out; |
| 10052 | |
| 10053 | if (sync) { |
| 10054 | commitPendingDataToDisk(); |
| 10055 | } else { |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 10056 | BackgroundThread.getHandler().post(new Runnable() { |
| 10057 | @Override public void run() { |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 10058 | commitPendingDataToDisk(); |
| 10059 | } |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 10060 | }); |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 10061 | } |
| 10062 | } |
| 10063 | |
| 10064 | public void commitPendingDataToDisk() { |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 10065 | final Parcel next; |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 10066 | synchronized (this) { |
| 10067 | next = mPendingWrite; |
| 10068 | mPendingWrite = null; |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 10069 | if (next == null) { |
| 10070 | return; |
| 10071 | } |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 10072 | |
| 10073 | mWriteLock.lock(); |
| 10074 | } |
| 10075 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10076 | try { |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 10077 | FileOutputStream stream = new FileOutputStream(mFile.chooseForWrite()); |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 10078 | stream.write(next.marshall()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10079 | stream.flush(); |
Dianne Hackborn | 8bdf593 | 2010-10-15 12:54:40 -0700 | [diff] [blame] | 10080 | FileUtils.sync(stream); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10081 | stream.close(); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 10082 | mFile.commit(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10083 | } catch (IOException e) { |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 10084 | Slog.w("BatteryStats", "Error writing battery statistics", e); |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 10085 | mFile.rollback(); |
| 10086 | } finally { |
| 10087 | next.recycle(); |
| 10088 | mWriteLock.unlock(); |
Suchi Amalapurapu | 8550f25 | 2009-09-29 15:20:32 -0700 | [diff] [blame] | 10089 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10090 | } |
| 10091 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10092 | public void readLocked() { |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 10093 | if (mDailyFile != null) { |
| 10094 | readDailyStatsLocked(); |
| 10095 | } |
| 10096 | |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 10097 | if (mFile == null) { |
| 10098 | 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] | 10099 | return; |
| 10100 | } |
| 10101 | |
| 10102 | mUidStats.clear(); |
| 10103 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10104 | try { |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 10105 | File file = mFile.chooseForRead(); |
| 10106 | if (!file.exists()) { |
| 10107 | return; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10108 | } |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 10109 | FileInputStream stream = new FileInputStream(file); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10110 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 10111 | byte[] raw = BatteryStatsHelper.readFully(stream); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10112 | Parcel in = Parcel.obtain(); |
| 10113 | in.unmarshall(raw, 0, raw.length); |
| 10114 | in.setDataPosition(0); |
| 10115 | stream.close(); |
| 10116 | |
| 10117 | readSummaryFromParcel(in); |
Dianne Hackborn | 00e2521 | 2014-02-19 10:49:24 -0800 | [diff] [blame] | 10118 | } catch(Exception e) { |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 10119 | Slog.e("BatteryStats", "Error reading battery statistics", e); |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 10120 | resetAllStatsLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10121 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 10122 | |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 10123 | mEndPlatformVersion = Build.ID; |
| 10124 | |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 10125 | if (mHistoryBuffer.dataPosition() > 0) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 10126 | mRecordingHistory = true; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 10127 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 10128 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 10129 | if (USE_OLD_HISTORY) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 10130 | addHistoryRecordLocked(elapsedRealtime, uptime, HistoryItem.CMD_START, mHistoryCur); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 10131 | } |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 10132 | addHistoryBufferLocked(elapsedRealtime, uptime, HistoryItem.CMD_START, mHistoryCur); |
| 10133 | startRecordingHistory(elapsedRealtime, uptime, false); |
Dianne Hackborn | e8c88e6 | 2011-08-17 19:09:09 -0700 | [diff] [blame] | 10134 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 10135 | |
| 10136 | recordDailyStatsIfNeededLocked(false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10137 | } |
| 10138 | |
| 10139 | public int describeContents() { |
| 10140 | return 0; |
| 10141 | } |
| 10142 | |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 10143 | void readHistory(Parcel in, boolean andOldHistory) throws ParcelFormatException { |
Dianne Hackborn | ae38445 | 2011-06-28 12:33:48 -0700 | [diff] [blame] | 10144 | final long historyBaseTime = in.readLong(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 10145 | |
| 10146 | mHistoryBuffer.setDataSize(0); |
| 10147 | mHistoryBuffer.setDataPosition(0); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 10148 | mHistoryTagPool.clear(); |
| 10149 | mNextHistoryTagIdx = 0; |
| 10150 | mNumHistoryTagChars = 0; |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 10151 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 10152 | int numTags = in.readInt(); |
| 10153 | for (int i=0; i<numTags; i++) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 10154 | int idx = in.readInt(); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 10155 | String str = in.readString(); |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 10156 | if (str == null) { |
| 10157 | throw new ParcelFormatException("null history tag string"); |
| 10158 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 10159 | int uid = in.readInt(); |
| 10160 | HistoryTag tag = new HistoryTag(); |
| 10161 | tag.string = str; |
| 10162 | tag.uid = uid; |
| 10163 | tag.poolIdx = idx; |
| 10164 | mHistoryTagPool.put(tag, idx); |
| 10165 | if (idx >= mNextHistoryTagIdx) { |
| 10166 | mNextHistoryTagIdx = idx+1; |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 10167 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 10168 | mNumHistoryTagChars += tag.string.length() + 1; |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 10169 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 10170 | |
| 10171 | int bufSize = in.readInt(); |
| 10172 | int curPos = in.dataPosition(); |
| 10173 | if (bufSize >= (MAX_MAX_HISTORY_BUFFER*3)) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 10174 | throw new ParcelFormatException("File corrupt: history data buffer too large " + |
| 10175 | bufSize); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 10176 | } else if ((bufSize&~3) != bufSize) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 10177 | throw new ParcelFormatException("File corrupt: history data buffer not aligned " + |
| 10178 | bufSize); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 10179 | } else { |
| 10180 | if (DEBUG_HISTORY) Slog.i(TAG, "***************** READING NEW HISTORY: " + bufSize |
| 10181 | + " bytes at " + curPos); |
| 10182 | mHistoryBuffer.appendFrom(in, curPos, bufSize); |
| 10183 | in.setDataPosition(curPos + bufSize); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 10184 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 10185 | |
Dianne Hackborn | ae38445 | 2011-06-28 12:33:48 -0700 | [diff] [blame] | 10186 | if (andOldHistory) { |
| 10187 | readOldHistory(in); |
| 10188 | } |
| 10189 | |
| 10190 | if (DEBUG_HISTORY) { |
| 10191 | StringBuilder sb = new StringBuilder(128); |
| 10192 | sb.append("****************** OLD mHistoryBaseTime: "); |
| 10193 | TimeUtils.formatDuration(mHistoryBaseTime, sb); |
| 10194 | Slog.i(TAG, sb.toString()); |
| 10195 | } |
| 10196 | mHistoryBaseTime = historyBaseTime; |
| 10197 | if (DEBUG_HISTORY) { |
| 10198 | StringBuilder sb = new StringBuilder(128); |
| 10199 | sb.append("****************** NEW mHistoryBaseTime: "); |
| 10200 | TimeUtils.formatDuration(mHistoryBaseTime, sb); |
| 10201 | Slog.i(TAG, sb.toString()); |
| 10202 | } |
| 10203 | |
| 10204 | // We are just arbitrarily going to insert 1 minute from the sample of |
| 10205 | // the last run until samples in this run. |
| 10206 | if (mHistoryBaseTime > 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 10207 | long oldnow = mClocks.elapsedRealtime(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 10208 | mHistoryBaseTime = mHistoryBaseTime - oldnow + 1; |
Dianne Hackborn | ae38445 | 2011-06-28 12:33:48 -0700 | [diff] [blame] | 10209 | if (DEBUG_HISTORY) { |
| 10210 | StringBuilder sb = new StringBuilder(128); |
| 10211 | sb.append("****************** ADJUSTED mHistoryBaseTime: "); |
| 10212 | TimeUtils.formatDuration(mHistoryBaseTime, sb); |
| 10213 | Slog.i(TAG, sb.toString()); |
| 10214 | } |
Dianne Hackborn | 1e4b9f3 | 2010-06-23 14:10:57 -0700 | [diff] [blame] | 10215 | } |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 10216 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 10217 | |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 10218 | void readOldHistory(Parcel in) { |
Dianne Hackborn | e8c88e6 | 2011-08-17 19:09:09 -0700 | [diff] [blame] | 10219 | if (!USE_OLD_HISTORY) { |
| 10220 | return; |
| 10221 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 10222 | mHistory = mHistoryEnd = mHistoryCache = null; |
| 10223 | long time; |
Conley Owens | 5e3357f | 2011-05-02 09:59:30 -0700 | [diff] [blame] | 10224 | while (in.dataAvail() > 0 && (time=in.readLong()) >= 0) { |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 10225 | HistoryItem rec = new HistoryItem(time, in); |
| 10226 | addHistoryRecordLocked(rec); |
| 10227 | } |
| 10228 | } |
| 10229 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 10230 | void writeHistory(Parcel out, boolean inclData, boolean andOldHistory) { |
Dianne Hackborn | ae38445 | 2011-06-28 12:33:48 -0700 | [diff] [blame] | 10231 | if (DEBUG_HISTORY) { |
| 10232 | StringBuilder sb = new StringBuilder(128); |
| 10233 | sb.append("****************** WRITING mHistoryBaseTime: "); |
| 10234 | TimeUtils.formatDuration(mHistoryBaseTime, sb); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 10235 | sb.append(" mLastHistoryElapsedRealtime: "); |
| 10236 | TimeUtils.formatDuration(mLastHistoryElapsedRealtime, sb); |
Dianne Hackborn | ae38445 | 2011-06-28 12:33:48 -0700 | [diff] [blame] | 10237 | Slog.i(TAG, sb.toString()); |
| 10238 | } |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 10239 | out.writeLong(mHistoryBaseTime + mLastHistoryElapsedRealtime); |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 10240 | if (!inclData) { |
| 10241 | out.writeInt(0); |
| 10242 | out.writeInt(0); |
| 10243 | return; |
| 10244 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 10245 | out.writeInt(mHistoryTagPool.size()); |
| 10246 | for (HashMap.Entry<HistoryTag, Integer> ent : mHistoryTagPool.entrySet()) { |
| 10247 | HistoryTag tag = ent.getKey(); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 10248 | out.writeInt(ent.getValue()); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 10249 | out.writeString(tag.string); |
| 10250 | out.writeInt(tag.uid); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 10251 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 10252 | out.writeInt(mHistoryBuffer.dataSize()); |
| 10253 | if (DEBUG_HISTORY) Slog.i(TAG, "***************** WRITING HISTORY: " |
| 10254 | + mHistoryBuffer.dataSize() + " bytes at " + out.dataPosition()); |
| 10255 | out.appendFrom(mHistoryBuffer, 0, mHistoryBuffer.dataSize()); |
Dianne Hackborn | ae38445 | 2011-06-28 12:33:48 -0700 | [diff] [blame] | 10256 | |
| 10257 | if (andOldHistory) { |
| 10258 | writeOldHistory(out); |
| 10259 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 10260 | } |
| 10261 | |
| 10262 | void writeOldHistory(Parcel out) { |
Dianne Hackborn | e8c88e6 | 2011-08-17 19:09:09 -0700 | [diff] [blame] | 10263 | if (!USE_OLD_HISTORY) { |
| 10264 | return; |
| 10265 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10266 | HistoryItem rec = mHistory; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 10267 | while (rec != null) { |
| 10268 | if (rec.time >= 0) rec.writeToParcel(out, 0); |
| 10269 | rec = rec.next; |
| 10270 | } |
| 10271 | out.writeLong(-1); |
| 10272 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 10273 | |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 10274 | public void readSummaryFromParcel(Parcel in) throws ParcelFormatException { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10275 | final int version = in.readInt(); |
| 10276 | if (version != VERSION) { |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 10277 | Slog.w("BatteryStats", "readFromParcel: version got " + version |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10278 | + ", expected " + VERSION + "; erasing old stats"); |
| 10279 | return; |
| 10280 | } |
| 10281 | |
Dianne Hackborn | ae38445 | 2011-06-28 12:33:48 -0700 | [diff] [blame] | 10282 | readHistory(in, true); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 10283 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10284 | mStartCount = in.readInt(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10285 | mUptime = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10286 | mRealtime = in.readLong(); |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 10287 | mStartClockTime = in.readLong(); |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 10288 | mStartPlatformVersion = in.readString(); |
| 10289 | mEndPlatformVersion = in.readString(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10290 | mOnBatteryTimeBase.readSummaryFromParcel(in); |
| 10291 | mOnBatteryScreenOffTimeBase.readSummaryFromParcel(in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10292 | mDischargeUnplugLevel = in.readInt(); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 10293 | mDischargePlugLevel = in.readInt(); |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 10294 | mDischargeCurrentLevel = in.readInt(); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 10295 | mCurrentBatteryLevel = in.readInt(); |
Adam Lesinski | f9b20a9 | 2016-06-17 17:30:01 -0700 | [diff] [blame] | 10296 | mEstimatedBatteryCapacity = in.readInt(); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 10297 | mLowDischargeAmountSinceCharge = in.readInt(); |
| 10298 | mHighDischargeAmountSinceCharge = in.readInt(); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 10299 | mDischargeAmountScreenOnSinceCharge = in.readInt(); |
| 10300 | mDischargeAmountScreenOffSinceCharge = in.readInt(); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 10301 | mDischargeStepTracker.readFromParcel(in); |
| 10302 | mChargeStepTracker.readFromParcel(in); |
| 10303 | mDailyDischargeStepTracker.readFromParcel(in); |
| 10304 | mDailyChargeStepTracker.readFromParcel(in); |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 10305 | mDischargeCounter.readSummaryFromParcelLocked(in); |
| 10306 | mDischargeScreenOffCounter.readSummaryFromParcelLocked(in); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 10307 | int NPKG = in.readInt(); |
| 10308 | if (NPKG > 0) { |
| 10309 | mDailyPackageChanges = new ArrayList<>(NPKG); |
| 10310 | while (NPKG > 0) { |
| 10311 | NPKG--; |
| 10312 | PackageChange pc = new PackageChange(); |
| 10313 | pc.mPackageName = in.readString(); |
| 10314 | pc.mUpdate = in.readInt() != 0; |
| 10315 | pc.mVersionCode = in.readInt(); |
| 10316 | mDailyPackageChanges.add(pc); |
| 10317 | } |
| 10318 | } else { |
| 10319 | mDailyPackageChanges = null; |
| 10320 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 10321 | mDailyStartTime = in.readLong(); |
| 10322 | mNextMinDailyDeadline = in.readLong(); |
| 10323 | mNextMaxDailyDeadline = in.readLong(); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 10324 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10325 | mStartCount++; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 10326 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 10327 | mScreenState = Display.STATE_UNKNOWN; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10328 | mScreenOnTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 10329 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
| 10330 | mScreenBrightnessTimer[i].readSummaryFromParcelLocked(in); |
| 10331 | } |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 10332 | mInteractive = false; |
| 10333 | mInteractiveTimer.readSummaryFromParcelLocked(in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10334 | mPhoneOn = false; |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 10335 | mPowerSaveModeEnabledTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 10336 | mLongestLightIdleTime = in.readLong(); |
| 10337 | mLongestFullIdleTime = in.readLong(); |
| 10338 | mDeviceIdleModeLightTimer.readSummaryFromParcelLocked(in); |
| 10339 | mDeviceIdleModeFullTimer.readSummaryFromParcelLocked(in); |
| 10340 | mDeviceLightIdlingTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 10341 | mDeviceIdlingTimer.readSummaryFromParcelLocked(in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10342 | mPhoneOnTimer.readSummaryFromParcelLocked(in); |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 10343 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 10344 | mPhoneSignalStrengthsTimer[i].readSummaryFromParcelLocked(in); |
| 10345 | } |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 10346 | mPhoneSignalScanningTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 10347 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
| 10348 | mPhoneDataConnectionsTimer[i].readSummaryFromParcelLocked(in); |
| 10349 | } |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 10350 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 10351 | mNetworkByteActivityCounters[i].readSummaryFromParcelLocked(in); |
| 10352 | mNetworkPacketActivityCounters[i].readSummaryFromParcelLocked(in); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 10353 | } |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 10354 | mMobileRadioPowerState = DataConnectionRealTimeInfo.DC_POWER_STATE_LOW; |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 10355 | mMobileRadioActiveTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 10356 | mMobileRadioActivePerAppTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 10357 | mMobileRadioActiveAdjustedTime.readSummaryFromParcelLocked(in); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 10358 | mMobileRadioActiveUnknownTime.readSummaryFromParcelLocked(in); |
| 10359 | mMobileRadioActiveUnknownCount.readSummaryFromParcelLocked(in); |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 10360 | mWifiRadioPowerState = DataConnectionRealTimeInfo.DC_POWER_STATE_LOW; |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 10361 | mWifiOn = false; |
| 10362 | mWifiOnTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 10363 | mGlobalWifiRunning = false; |
| 10364 | mGlobalWifiRunningTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 10365 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
| 10366 | mWifiStateTimer[i].readSummaryFromParcelLocked(in); |
| 10367 | } |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 10368 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
| 10369 | mWifiSupplStateTimer[i].readSummaryFromParcelLocked(in); |
| 10370 | } |
| 10371 | for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 10372 | mWifiSignalStrengthsTimer[i].readSummaryFromParcelLocked(in); |
| 10373 | } |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 10374 | mWifiActivity.readSummaryFromParcel(in); |
| 10375 | mBluetoothActivity.readSummaryFromParcel(in); |
| 10376 | mModemActivity.readSummaryFromParcel(in); |
| 10377 | mHasWifiReporting = in.readInt() != 0; |
| 10378 | mHasBluetoothReporting = in.readInt() != 0; |
| 10379 | mHasModemReporting = in.readInt() != 0; |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 10380 | |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 10381 | mNumConnectivityChange = mLoadedNumConnectivityChange = in.readInt(); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 10382 | mFlashlightOnNesting = 0; |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 10383 | mFlashlightOnTimer.readSummaryFromParcelLocked(in); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 10384 | mCameraOnNesting = 0; |
| 10385 | mCameraOnTimer.readSummaryFromParcelLocked(in); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 10386 | mBluetoothScanNesting = 0; |
| 10387 | mBluetoothScanTimer.readSummaryFromParcelLocked(in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10388 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 10389 | int NKW = in.readInt(); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 10390 | if (NKW > 10000) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 10391 | throw new ParcelFormatException("File corrupt: too many kernel wake locks " + NKW); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 10392 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 10393 | for (int ikw = 0; ikw < NKW; ikw++) { |
| 10394 | if (in.readInt() != 0) { |
| 10395 | String kwltName = in.readString(); |
| 10396 | getKernelWakelockTimerLocked(kwltName).readSummaryFromParcelLocked(in); |
| 10397 | } |
| 10398 | } |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 10399 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 10400 | int NWR = in.readInt(); |
| 10401 | if (NWR > 10000) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 10402 | throw new ParcelFormatException("File corrupt: too many wakeup reasons " + NWR); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 10403 | } |
| 10404 | for (int iwr = 0; iwr < NWR; iwr++) { |
| 10405 | if (in.readInt() != 0) { |
| 10406 | String reasonName = in.readString(); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 10407 | getWakeupReasonTimerLocked(reasonName).readSummaryFromParcelLocked(in); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 10408 | } |
| 10409 | } |
| 10410 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10411 | final int NU = in.readInt(); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 10412 | if (NU > 10000) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 10413 | throw new ParcelFormatException("File corrupt: too many uids " + NU); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 10414 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10415 | for (int iu = 0; iu < NU; iu++) { |
| 10416 | int uid = in.readInt(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 10417 | Uid u = new Uid(this, uid); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10418 | mUidStats.put(uid, u); |
| 10419 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 10420 | u.mWifiRunning = false; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10421 | if (in.readInt() != 0) { |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 10422 | u.mWifiRunningTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10423 | } |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 10424 | u.mFullWifiLockOut = false; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10425 | if (in.readInt() != 0) { |
| 10426 | u.mFullWifiLockTimer.readSummaryFromParcelLocked(in); |
| 10427 | } |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 10428 | u.mWifiScanStarted = false; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10429 | if (in.readInt() != 0) { |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 10430 | u.mWifiScanTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10431 | } |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 10432 | u.mWifiBatchedScanBinStarted = Uid.NO_BATCHED_SCAN_STARTED; |
| 10433 | for (int i = 0; i < Uid.NUM_WIFI_BATCHED_SCAN_BINS; i++) { |
| 10434 | if (in.readInt() != 0) { |
| 10435 | u.makeWifiBatchedScanBin(i, null); |
| 10436 | u.mWifiBatchedScanTimer[i].readSummaryFromParcelLocked(in); |
| 10437 | } |
| 10438 | } |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 10439 | u.mWifiMulticastEnabled = false; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10440 | if (in.readInt() != 0) { |
| 10441 | u.mWifiMulticastTimer.readSummaryFromParcelLocked(in); |
| 10442 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10443 | if (in.readInt() != 0) { |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 10444 | u.createAudioTurnedOnTimerLocked().readSummaryFromParcelLocked(in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10445 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10446 | if (in.readInt() != 0) { |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 10447 | u.createVideoTurnedOnTimerLocked().readSummaryFromParcelLocked(in); |
| 10448 | } |
| 10449 | if (in.readInt() != 0) { |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 10450 | u.createFlashlightTurnedOnTimerLocked().readSummaryFromParcelLocked(in); |
| 10451 | } |
| 10452 | if (in.readInt() != 0) { |
| 10453 | u.createCameraTurnedOnTimerLocked().readSummaryFromParcelLocked(in); |
| 10454 | } |
| 10455 | if (in.readInt() != 0) { |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 10456 | u.createForegroundActivityTimerLocked().readSummaryFromParcelLocked(in); |
| 10457 | } |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 10458 | if (in.readInt() != 0) { |
| 10459 | u.createBluetoothScanTimerLocked().readSummaryFromParcelLocked(in); |
| 10460 | } |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 10461 | u.mProcessState = ActivityManager.PROCESS_STATE_NONEXISTENT; |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 10462 | for (int i = 0; i < Uid.NUM_PROCESS_STATE; i++) { |
| 10463 | if (in.readInt() != 0) { |
| 10464 | u.makeProcessState(i, null); |
| 10465 | u.mProcessStateTimer[i].readSummaryFromParcelLocked(in); |
| 10466 | } |
| 10467 | } |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 10468 | if (in.readInt() != 0) { |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 10469 | u.createVibratorOnTimerLocked().readSummaryFromParcelLocked(in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10470 | } |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 10471 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 10472 | if (in.readInt() != 0) { |
| 10473 | if (u.mUserActivityCounters == null) { |
| 10474 | u.initUserActivityLocked(); |
| 10475 | } |
| 10476 | for (int i=0; i<Uid.NUM_USER_ACTIVITY_TYPES; i++) { |
| 10477 | u.mUserActivityCounters[i].readSummaryFromParcelLocked(in); |
| 10478 | } |
| 10479 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 10480 | |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 10481 | if (in.readInt() != 0) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 10482 | if (u.mNetworkByteActivityCounters == null) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 10483 | u.initNetworkActivityLocked(); |
| 10484 | } |
| 10485 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 10486 | u.mNetworkByteActivityCounters[i].readSummaryFromParcelLocked(in); |
| 10487 | u.mNetworkPacketActivityCounters[i].readSummaryFromParcelLocked(in); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 10488 | } |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 10489 | u.mMobileRadioActiveTime.readSummaryFromParcelLocked(in); |
| 10490 | u.mMobileRadioActiveCount.readSummaryFromParcelLocked(in); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 10491 | } |
| 10492 | |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 10493 | u.mUserCpuTime.readSummaryFromParcelLocked(in); |
| 10494 | u.mSystemCpuTime.readSummaryFromParcelLocked(in); |
Adam Lesinski | a7a4ccc | 2015-06-26 17:43:04 -0700 | [diff] [blame] | 10495 | u.mCpuPower.readSummaryFromParcelLocked(in); |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 10496 | |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 10497 | if (in.readInt() != 0) { |
| 10498 | final int numClusters = in.readInt(); |
| 10499 | if (mPowerProfile != null && mPowerProfile.getNumCpuClusters() != numClusters) { |
| 10500 | throw new ParcelFormatException("Incompatible cpu cluster arrangement"); |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 10501 | } |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 10502 | |
| 10503 | u.mCpuClusterSpeed = new LongSamplingCounter[numClusters][]; |
| 10504 | for (int cluster = 0; cluster < numClusters; cluster++) { |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 10505 | if (in.readInt() != 0) { |
Adam Lesinski | a57a540 | 2015-09-28 10:21:33 -0700 | [diff] [blame] | 10506 | final int NSB = in.readInt(); |
| 10507 | if (mPowerProfile != null && |
| 10508 | mPowerProfile.getNumSpeedStepsInCpuCluster(cluster) != NSB) { |
| 10509 | throw new ParcelFormatException("File corrupt: too many speed bins " + |
| 10510 | NSB); |
| 10511 | } |
| 10512 | |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 10513 | u.mCpuClusterSpeed[cluster] = new LongSamplingCounter[NSB]; |
| 10514 | for (int speed = 0; speed < NSB; speed++) { |
| 10515 | if (in.readInt() != 0) { |
| 10516 | u.mCpuClusterSpeed[cluster][speed] = new LongSamplingCounter( |
| 10517 | mOnBatteryTimeBase); |
| 10518 | u.mCpuClusterSpeed[cluster][speed].readSummaryFromParcelLocked(in); |
| 10519 | } |
| 10520 | } |
Adam Lesinski | a57a540 | 2015-09-28 10:21:33 -0700 | [diff] [blame] | 10521 | } else { |
| 10522 | u.mCpuClusterSpeed[cluster] = null; |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 10523 | } |
| 10524 | } |
| 10525 | } else { |
| 10526 | u.mCpuClusterSpeed = null; |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 10527 | } |
| 10528 | |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 10529 | if (in.readInt() != 0) { |
| 10530 | u.mMobileRadioApWakeupCount = new LongSamplingCounter(mOnBatteryTimeBase); |
| 10531 | u.mMobileRadioApWakeupCount.readSummaryFromParcelLocked(in); |
| 10532 | } else { |
| 10533 | u.mMobileRadioApWakeupCount = null; |
| 10534 | } |
| 10535 | |
| 10536 | if (in.readInt() != 0) { |
| 10537 | u.mWifiRadioApWakeupCount = new LongSamplingCounter(mOnBatteryTimeBase); |
| 10538 | u.mWifiRadioApWakeupCount.readSummaryFromParcelLocked(in); |
| 10539 | } else { |
| 10540 | u.mWifiRadioApWakeupCount = null; |
| 10541 | } |
| 10542 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10543 | int NW = in.readInt(); |
Dianne Hackborn | 7b9c56f | 2010-12-07 11:14:53 -0800 | [diff] [blame] | 10544 | if (NW > 100) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 10545 | throw new ParcelFormatException("File corrupt: too many wake locks " + NW); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 10546 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10547 | for (int iw = 0; iw < NW; iw++) { |
| 10548 | String wlName = in.readString(); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 10549 | u.readWakeSummaryFromParcelLocked(wlName, in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10550 | } |
| 10551 | |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 10552 | int NS = in.readInt(); |
| 10553 | if (NS > 100) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 10554 | throw new ParcelFormatException("File corrupt: too many syncs " + NS); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 10555 | } |
| 10556 | for (int is = 0; is < NS; is++) { |
| 10557 | String name = in.readString(); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 10558 | u.readSyncSummaryFromParcelLocked(name, in); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 10559 | } |
| 10560 | |
| 10561 | int NJ = in.readInt(); |
| 10562 | if (NJ > 100) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 10563 | throw new ParcelFormatException("File corrupt: too many job timers " + NJ); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 10564 | } |
| 10565 | for (int ij = 0; ij < NJ; ij++) { |
| 10566 | String name = in.readString(); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 10567 | u.readJobSummaryFromParcelLocked(name, in); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 10568 | } |
| 10569 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10570 | int NP = in.readInt(); |
Dianne Hackborn | 7b9c56f | 2010-12-07 11:14:53 -0800 | [diff] [blame] | 10571 | if (NP > 1000) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 10572 | throw new ParcelFormatException("File corrupt: too many sensors " + NP); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 10573 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10574 | for (int is = 0; is < NP; is++) { |
| 10575 | int seNumber = in.readInt(); |
| 10576 | if (in.readInt() != 0) { |
| 10577 | u.getSensorTimerLocked(seNumber, true) |
| 10578 | .readSummaryFromParcelLocked(in); |
| 10579 | } |
| 10580 | } |
| 10581 | |
| 10582 | NP = in.readInt(); |
Dianne Hackborn | 7b9c56f | 2010-12-07 11:14:53 -0800 | [diff] [blame] | 10583 | if (NP > 1000) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 10584 | throw new ParcelFormatException("File corrupt: too many processes " + NP); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 10585 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10586 | for (int ip = 0; ip < NP; ip++) { |
| 10587 | String procName = in.readString(); |
| 10588 | Uid.Proc p = u.getProcessStatsLocked(procName); |
| 10589 | p.mUserTime = p.mLoadedUserTime = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10590 | p.mSystemTime = p.mLoadedSystemTime = in.readLong(); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 10591 | p.mForegroundTime = p.mLoadedForegroundTime = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10592 | p.mStarts = p.mLoadedStarts = in.readInt(); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 10593 | p.mNumCrashes = p.mLoadedNumCrashes = in.readInt(); |
| 10594 | p.mNumAnrs = p.mLoadedNumAnrs = in.readInt(); |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 10595 | p.readExcessivePowerFromParcelLocked(in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10596 | } |
| 10597 | |
| 10598 | NP = in.readInt(); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 10599 | if (NP > 10000) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 10600 | throw new ParcelFormatException("File corrupt: too many packages " + NP); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 10601 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10602 | for (int ip = 0; ip < NP; ip++) { |
| 10603 | String pkgName = in.readString(); |
| 10604 | Uid.Pkg p = u.getPackageStatsLocked(pkgName); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 10605 | final int NWA = in.readInt(); |
| 10606 | if (NWA > 1000) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 10607 | throw new ParcelFormatException("File corrupt: too many wakeup alarms " + NWA); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 10608 | } |
| 10609 | p.mWakeupAlarms.clear(); |
| 10610 | for (int iwa=0; iwa<NWA; iwa++) { |
| 10611 | String tag = in.readString(); |
| 10612 | Counter c = new Counter(mOnBatteryTimeBase); |
| 10613 | c.readSummaryFromParcelLocked(in); |
| 10614 | p.mWakeupAlarms.put(tag, c); |
| 10615 | } |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 10616 | NS = in.readInt(); |
Dianne Hackborn | 7b9c56f | 2010-12-07 11:14:53 -0800 | [diff] [blame] | 10617 | if (NS > 1000) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 10618 | throw new ParcelFormatException("File corrupt: too many services " + NS); |
Dianne Hackborn | 7b9c56f | 2010-12-07 11:14:53 -0800 | [diff] [blame] | 10619 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10620 | for (int is = 0; is < NS; is++) { |
| 10621 | String servName = in.readString(); |
| 10622 | Uid.Pkg.Serv s = u.getServiceStatsLocked(pkgName, servName); |
| 10623 | s.mStartTime = s.mLoadedStartTime = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10624 | s.mStarts = s.mLoadedStarts = in.readInt(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10625 | s.mLaunches = s.mLoadedLaunches = in.readInt(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10626 | } |
| 10627 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10628 | } |
| 10629 | } |
| 10630 | |
| 10631 | /** |
| 10632 | * Writes a summary of the statistics to a Parcel, in a format suitable to be written to |
| 10633 | * disk. This format does not allow a lossless round-trip. |
| 10634 | * |
| 10635 | * @param out the Parcel to be written to. |
| 10636 | */ |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 10637 | public void writeSummaryToParcel(Parcel out, boolean inclHistory) { |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 10638 | pullPendingStateUpdatesLocked(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 10639 | |
Dianne Hackborn | 7d9eefd | 2014-08-27 18:30:31 -0700 | [diff] [blame] | 10640 | // Pull the clock time. This may update the time and make a new history entry |
| 10641 | // if we had originally pulled a time before the RTC was set. |
| 10642 | long startClockTime = getStartClockTime(); |
| 10643 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 10644 | final long NOW_SYS = mClocks.uptimeMillis() * 1000; |
| 10645 | final long NOWREAL_SYS = mClocks.elapsedRealtime() * 1000; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10646 | |
| 10647 | out.writeInt(VERSION); |
| 10648 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 10649 | writeHistory(out, inclHistory, true); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 10650 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10651 | out.writeInt(mStartCount); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10652 | out.writeLong(computeUptime(NOW_SYS, STATS_SINCE_CHARGED)); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10653 | out.writeLong(computeRealtime(NOWREAL_SYS, STATS_SINCE_CHARGED)); |
Dianne Hackborn | 7d9eefd | 2014-08-27 18:30:31 -0700 | [diff] [blame] | 10654 | out.writeLong(startClockTime); |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 10655 | out.writeString(mStartPlatformVersion); |
| 10656 | out.writeString(mEndPlatformVersion); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10657 | mOnBatteryTimeBase.writeSummaryToParcel(out, NOW_SYS, NOWREAL_SYS); |
| 10658 | mOnBatteryScreenOffTimeBase.writeSummaryToParcel(out, NOW_SYS, NOWREAL_SYS); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10659 | out.writeInt(mDischargeUnplugLevel); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 10660 | out.writeInt(mDischargePlugLevel); |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 10661 | out.writeInt(mDischargeCurrentLevel); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 10662 | out.writeInt(mCurrentBatteryLevel); |
Adam Lesinski | f9b20a9 | 2016-06-17 17:30:01 -0700 | [diff] [blame] | 10663 | out.writeInt(mEstimatedBatteryCapacity); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 10664 | out.writeInt(getLowDischargeAmountSinceCharge()); |
| 10665 | out.writeInt(getHighDischargeAmountSinceCharge()); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 10666 | out.writeInt(getDischargeAmountScreenOnSinceCharge()); |
| 10667 | out.writeInt(getDischargeAmountScreenOffSinceCharge()); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 10668 | mDischargeStepTracker.writeToParcel(out); |
| 10669 | mChargeStepTracker.writeToParcel(out); |
| 10670 | mDailyDischargeStepTracker.writeToParcel(out); |
| 10671 | mDailyChargeStepTracker.writeToParcel(out); |
Adam Lesinski | 67c134f | 2016-06-10 15:15:08 -0700 | [diff] [blame] | 10672 | mDischargeCounter.writeSummaryFromParcelLocked(out); |
| 10673 | mDischargeScreenOffCounter.writeSummaryFromParcelLocked(out); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 10674 | if (mDailyPackageChanges != null) { |
| 10675 | final int NPKG = mDailyPackageChanges.size(); |
| 10676 | out.writeInt(NPKG); |
| 10677 | for (int i=0; i<NPKG; i++) { |
| 10678 | PackageChange pc = mDailyPackageChanges.get(i); |
| 10679 | out.writeString(pc.mPackageName); |
| 10680 | out.writeInt(pc.mUpdate ? 1 : 0); |
| 10681 | out.writeInt(pc.mVersionCode); |
| 10682 | } |
| 10683 | } else { |
| 10684 | out.writeInt(0); |
| 10685 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 10686 | out.writeLong(mDailyStartTime); |
| 10687 | out.writeLong(mNextMinDailyDeadline); |
| 10688 | out.writeLong(mNextMaxDailyDeadline); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10689 | |
| 10690 | mScreenOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 10691 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10692 | mScreenBrightnessTimer[i].writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 10693 | } |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 10694 | mInteractiveTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 10695 | mPowerSaveModeEnabledTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 10696 | out.writeLong(mLongestLightIdleTime); |
| 10697 | out.writeLong(mLongestFullIdleTime); |
| 10698 | mDeviceIdleModeLightTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 10699 | mDeviceIdleModeFullTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 10700 | mDeviceLightIdlingTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 10701 | mDeviceIdlingTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10702 | mPhoneOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 10703 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10704 | mPhoneSignalStrengthsTimer[i].writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 10705 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10706 | mPhoneSignalScanningTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 10707 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10708 | mPhoneDataConnectionsTimer[i].writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 10709 | } |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 10710 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 10711 | mNetworkByteActivityCounters[i].writeSummaryFromParcelLocked(out); |
| 10712 | mNetworkPacketActivityCounters[i].writeSummaryFromParcelLocked(out); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 10713 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10714 | mMobileRadioActiveTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 10715 | mMobileRadioActivePerAppTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 10716 | mMobileRadioActiveAdjustedTime.writeSummaryFromParcelLocked(out); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 10717 | mMobileRadioActiveUnknownTime.writeSummaryFromParcelLocked(out); |
| 10718 | mMobileRadioActiveUnknownCount.writeSummaryFromParcelLocked(out); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10719 | mWifiOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 10720 | mGlobalWifiRunningTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 10721 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10722 | mWifiStateTimer[i].writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 10723 | } |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 10724 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
| 10725 | mWifiSupplStateTimer[i].writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 10726 | } |
| 10727 | for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 10728 | mWifiSignalStrengthsTimer[i].writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 10729 | } |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 10730 | mWifiActivity.writeSummaryToParcel(out); |
| 10731 | mBluetoothActivity.writeSummaryToParcel(out); |
| 10732 | mModemActivity.writeSummaryToParcel(out); |
| 10733 | out.writeInt(mHasWifiReporting ? 1 : 0); |
| 10734 | out.writeInt(mHasBluetoothReporting ? 1 : 0); |
| 10735 | out.writeInt(mHasModemReporting ? 1 : 0); |
| 10736 | |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 10737 | out.writeInt(mNumConnectivityChange); |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 10738 | mFlashlightOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 10739 | mCameraOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 10740 | mBluetoothScanTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10741 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 10742 | out.writeInt(mKernelWakelockStats.size()); |
| 10743 | for (Map.Entry<String, SamplingTimer> ent : mKernelWakelockStats.entrySet()) { |
| 10744 | Timer kwlt = ent.getValue(); |
| 10745 | if (kwlt != null) { |
| 10746 | out.writeInt(1); |
| 10747 | out.writeString(ent.getKey()); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 10748 | kwlt.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 10749 | } else { |
| 10750 | out.writeInt(0); |
| 10751 | } |
| 10752 | } |
| 10753 | |
| 10754 | out.writeInt(mWakeupReasonStats.size()); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 10755 | for (Map.Entry<String, SamplingTimer> ent : mWakeupReasonStats.entrySet()) { |
| 10756 | SamplingTimer timer = ent.getValue(); |
| 10757 | if (timer != null) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 10758 | out.writeInt(1); |
| 10759 | out.writeString(ent.getKey()); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 10760 | timer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 10761 | } else { |
| 10762 | out.writeInt(0); |
| 10763 | } |
| 10764 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 10765 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10766 | final int NU = mUidStats.size(); |
| 10767 | out.writeInt(NU); |
| 10768 | for (int iu = 0; iu < NU; iu++) { |
| 10769 | out.writeInt(mUidStats.keyAt(iu)); |
| 10770 | Uid u = mUidStats.valueAt(iu); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 10771 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 10772 | if (u.mWifiRunningTimer != null) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10773 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10774 | u.mWifiRunningTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10775 | } else { |
| 10776 | out.writeInt(0); |
| 10777 | } |
| 10778 | if (u.mFullWifiLockTimer != null) { |
| 10779 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10780 | u.mFullWifiLockTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10781 | } else { |
| 10782 | out.writeInt(0); |
| 10783 | } |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 10784 | if (u.mWifiScanTimer != null) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10785 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10786 | u.mWifiScanTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10787 | } else { |
| 10788 | out.writeInt(0); |
| 10789 | } |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 10790 | for (int i = 0; i < Uid.NUM_WIFI_BATCHED_SCAN_BINS; i++) { |
| 10791 | if (u.mWifiBatchedScanTimer[i] != null) { |
| 10792 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10793 | u.mWifiBatchedScanTimer[i].writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 10794 | } else { |
| 10795 | out.writeInt(0); |
| 10796 | } |
| 10797 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10798 | if (u.mWifiMulticastTimer != null) { |
| 10799 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10800 | u.mWifiMulticastTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10801 | } else { |
| 10802 | out.writeInt(0); |
| 10803 | } |
| 10804 | if (u.mAudioTurnedOnTimer != null) { |
| 10805 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10806 | u.mAudioTurnedOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10807 | } else { |
| 10808 | out.writeInt(0); |
| 10809 | } |
| 10810 | if (u.mVideoTurnedOnTimer != null) { |
| 10811 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10812 | u.mVideoTurnedOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10813 | } else { |
| 10814 | out.writeInt(0); |
| 10815 | } |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 10816 | if (u.mFlashlightTurnedOnTimer != null) { |
| 10817 | out.writeInt(1); |
| 10818 | u.mFlashlightTurnedOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 10819 | } else { |
| 10820 | out.writeInt(0); |
| 10821 | } |
| 10822 | if (u.mCameraTurnedOnTimer != null) { |
| 10823 | out.writeInt(1); |
| 10824 | u.mCameraTurnedOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 10825 | } else { |
| 10826 | out.writeInt(0); |
| 10827 | } |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 10828 | if (u.mForegroundActivityTimer != null) { |
| 10829 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10830 | u.mForegroundActivityTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 10831 | } else { |
| 10832 | out.writeInt(0); |
| 10833 | } |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 10834 | if (u.mBluetoothScanTimer != null) { |
| 10835 | out.writeInt(1); |
| 10836 | u.mBluetoothScanTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 10837 | } else { |
| 10838 | out.writeInt(0); |
| 10839 | } |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 10840 | for (int i = 0; i < Uid.NUM_PROCESS_STATE; i++) { |
| 10841 | if (u.mProcessStateTimer[i] != null) { |
| 10842 | out.writeInt(1); |
| 10843 | u.mProcessStateTimer[i].writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 10844 | } else { |
| 10845 | out.writeInt(0); |
| 10846 | } |
| 10847 | } |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 10848 | if (u.mVibratorOnTimer != null) { |
| 10849 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10850 | u.mVibratorOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 10851 | } else { |
| 10852 | out.writeInt(0); |
| 10853 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10854 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 10855 | if (u.mUserActivityCounters == null) { |
| 10856 | out.writeInt(0); |
| 10857 | } else { |
| 10858 | out.writeInt(1); |
| 10859 | for (int i=0; i<Uid.NUM_USER_ACTIVITY_TYPES; i++) { |
| 10860 | u.mUserActivityCounters[i].writeSummaryFromParcelLocked(out); |
| 10861 | } |
| 10862 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 10863 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 10864 | if (u.mNetworkByteActivityCounters == null) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 10865 | out.writeInt(0); |
| 10866 | } else { |
| 10867 | out.writeInt(1); |
| 10868 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 10869 | u.mNetworkByteActivityCounters[i].writeSummaryFromParcelLocked(out); |
| 10870 | u.mNetworkPacketActivityCounters[i].writeSummaryFromParcelLocked(out); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 10871 | } |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 10872 | u.mMobileRadioActiveTime.writeSummaryFromParcelLocked(out); |
| 10873 | u.mMobileRadioActiveCount.writeSummaryFromParcelLocked(out); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 10874 | } |
| 10875 | |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 10876 | u.mUserCpuTime.writeSummaryFromParcelLocked(out); |
| 10877 | u.mSystemCpuTime.writeSummaryFromParcelLocked(out); |
Adam Lesinski | a7a4ccc | 2015-06-26 17:43:04 -0700 | [diff] [blame] | 10878 | u.mCpuPower.writeSummaryFromParcelLocked(out); |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 10879 | |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 10880 | if (u.mCpuClusterSpeed != null) { |
| 10881 | out.writeInt(1); |
| 10882 | out.writeInt(u.mCpuClusterSpeed.length); |
| 10883 | for (LongSamplingCounter[] cpuSpeeds : u.mCpuClusterSpeed) { |
| 10884 | if (cpuSpeeds != null) { |
| 10885 | out.writeInt(1); |
| 10886 | out.writeInt(cpuSpeeds.length); |
| 10887 | for (LongSamplingCounter c : cpuSpeeds) { |
| 10888 | if (c != null) { |
| 10889 | out.writeInt(1); |
| 10890 | c.writeSummaryFromParcelLocked(out); |
| 10891 | } else { |
| 10892 | out.writeInt(0); |
| 10893 | } |
| 10894 | } |
| 10895 | } else { |
| 10896 | out.writeInt(0); |
| 10897 | } |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 10898 | } |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 10899 | } else { |
| 10900 | out.writeInt(0); |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 10901 | } |
| 10902 | |
Adam Lesinski | 5f056f6 | 2016-07-14 16:56:08 -0700 | [diff] [blame] | 10903 | if (u.mMobileRadioApWakeupCount != null) { |
| 10904 | out.writeInt(1); |
| 10905 | u.mMobileRadioApWakeupCount.writeSummaryFromParcelLocked(out); |
| 10906 | } else { |
| 10907 | out.writeInt(0); |
| 10908 | } |
| 10909 | |
| 10910 | if (u.mWifiRadioApWakeupCount != null) { |
| 10911 | out.writeInt(1); |
| 10912 | u.mWifiRadioApWakeupCount.writeSummaryFromParcelLocked(out); |
| 10913 | } else { |
| 10914 | out.writeInt(0); |
| 10915 | } |
| 10916 | |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 10917 | final ArrayMap<String, Uid.Wakelock> wakeStats = u.mWakelockStats.getMap(); |
| 10918 | int NW = wakeStats.size(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10919 | out.writeInt(NW); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 10920 | for (int iw=0; iw<NW; iw++) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 10921 | out.writeString(wakeStats.keyAt(iw)); |
| 10922 | Uid.Wakelock wl = wakeStats.valueAt(iw); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 10923 | if (wl.mTimerFull != null) { |
| 10924 | out.writeInt(1); |
| 10925 | wl.mTimerFull.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 10926 | } else { |
| 10927 | out.writeInt(0); |
| 10928 | } |
| 10929 | if (wl.mTimerPartial != null) { |
| 10930 | out.writeInt(1); |
| 10931 | wl.mTimerPartial.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 10932 | } else { |
| 10933 | out.writeInt(0); |
| 10934 | } |
| 10935 | if (wl.mTimerWindow != null) { |
| 10936 | out.writeInt(1); |
| 10937 | wl.mTimerWindow.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 10938 | } else { |
| 10939 | out.writeInt(0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10940 | } |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 10941 | if (wl.mTimerDraw != null) { |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 10942 | out.writeInt(1); |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 10943 | wl.mTimerDraw.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 10944 | } else { |
| 10945 | out.writeInt(0); |
| 10946 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10947 | } |
| 10948 | |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 10949 | final ArrayMap<String, StopwatchTimer> syncStats = u.mSyncStats.getMap(); |
| 10950 | int NS = syncStats.size(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 10951 | out.writeInt(NS); |
| 10952 | for (int is=0; is<NS; is++) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 10953 | out.writeString(syncStats.keyAt(is)); |
| 10954 | syncStats.valueAt(is).writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 10955 | } |
| 10956 | |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 10957 | final ArrayMap<String, StopwatchTimer> jobStats = u.mJobStats.getMap(); |
| 10958 | int NJ = jobStats.size(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 10959 | out.writeInt(NJ); |
| 10960 | for (int ij=0; ij<NJ; ij++) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 10961 | out.writeString(jobStats.keyAt(ij)); |
| 10962 | jobStats.valueAt(ij).writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 10963 | } |
| 10964 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10965 | int NSE = u.mSensorStats.size(); |
| 10966 | out.writeInt(NSE); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 10967 | for (int ise=0; ise<NSE; ise++) { |
| 10968 | out.writeInt(u.mSensorStats.keyAt(ise)); |
| 10969 | Uid.Sensor se = u.mSensorStats.valueAt(ise); |
| 10970 | if (se.mTimer != null) { |
| 10971 | out.writeInt(1); |
| 10972 | se.mTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 10973 | } else { |
| 10974 | out.writeInt(0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10975 | } |
| 10976 | } |
| 10977 | |
| 10978 | int NP = u.mProcessStats.size(); |
| 10979 | out.writeInt(NP); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 10980 | for (int ip=0; ip<NP; ip++) { |
| 10981 | out.writeString(u.mProcessStats.keyAt(ip)); |
| 10982 | Uid.Proc ps = u.mProcessStats.valueAt(ip); |
| 10983 | out.writeLong(ps.mUserTime); |
| 10984 | out.writeLong(ps.mSystemTime); |
| 10985 | out.writeLong(ps.mForegroundTime); |
| 10986 | out.writeInt(ps.mStarts); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 10987 | out.writeInt(ps.mNumCrashes); |
| 10988 | out.writeInt(ps.mNumAnrs); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 10989 | ps.writeExcessivePowerToParcelLocked(out); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10990 | } |
| 10991 | |
| 10992 | NP = u.mPackageStats.size(); |
| 10993 | out.writeInt(NP); |
| 10994 | if (NP > 0) { |
| 10995 | for (Map.Entry<String, BatteryStatsImpl.Uid.Pkg> ent |
| 10996 | : u.mPackageStats.entrySet()) { |
| 10997 | out.writeString(ent.getKey()); |
| 10998 | Uid.Pkg ps = ent.getValue(); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 10999 | final int NWA = ps.mWakeupAlarms.size(); |
| 11000 | out.writeInt(NWA); |
| 11001 | for (int iwa=0; iwa<NWA; iwa++) { |
| 11002 | out.writeString(ps.mWakeupAlarms.keyAt(iwa)); |
| 11003 | ps.mWakeupAlarms.valueAt(iwa).writeSummaryFromParcelLocked(out); |
| 11004 | } |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 11005 | NS = ps.mServiceStats.size(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11006 | out.writeInt(NS); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 11007 | for (int is=0; is<NS; is++) { |
| 11008 | out.writeString(ps.mServiceStats.keyAt(is)); |
| 11009 | BatteryStatsImpl.Uid.Pkg.Serv ss = ps.mServiceStats.valueAt(is); |
| 11010 | long time = ss.getStartTimeToNowLocked( |
| 11011 | mOnBatteryTimeBase.getUptime(NOW_SYS)); |
| 11012 | out.writeLong(time); |
| 11013 | out.writeInt(ss.mStarts); |
| 11014 | out.writeInt(ss.mLaunches); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11015 | } |
| 11016 | } |
| 11017 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11018 | } |
| 11019 | } |
| 11020 | |
| 11021 | public void readFromParcel(Parcel in) { |
| 11022 | readFromParcelLocked(in); |
| 11023 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 11024 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11025 | void readFromParcelLocked(Parcel in) { |
| 11026 | int magic = in.readInt(); |
| 11027 | if (magic != MAGIC) { |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 11028 | throw new ParcelFormatException("Bad magic number: #" + Integer.toHexString(magic)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11029 | } |
| 11030 | |
Dianne Hackborn | ae38445 | 2011-06-28 12:33:48 -0700 | [diff] [blame] | 11031 | readHistory(in, false); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 11032 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11033 | mStartCount = in.readInt(); |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 11034 | mStartClockTime = in.readLong(); |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 11035 | mStartPlatformVersion = in.readString(); |
| 11036 | mEndPlatformVersion = in.readString(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11037 | mUptime = in.readLong(); |
| 11038 | mUptimeStart = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11039 | mRealtime = in.readLong(); |
| 11040 | mRealtimeStart = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11041 | mOnBattery = in.readInt() != 0; |
Adam Lesinski | f9b20a9 | 2016-06-17 17:30:01 -0700 | [diff] [blame] | 11042 | mEstimatedBatteryCapacity = in.readInt(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11043 | mOnBatteryInternal = false; // we are no longer really running. |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 11044 | mOnBatteryTimeBase.readFromParcel(in); |
| 11045 | mOnBatteryScreenOffTimeBase.readFromParcel(in); |
| 11046 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 11047 | mScreenState = Display.STATE_UNKNOWN; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 11048 | mScreenOnTimer = new StopwatchTimer(mClocks, null, -1, null, mOnBatteryTimeBase, in); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 11049 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 11050 | mScreenBrightnessTimer[i] = new StopwatchTimer(mClocks, null, -100-i, null, |
| 11051 | mOnBatteryTimeBase, in); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 11052 | } |
Dianne Hackborn | 2932513 | 2014-05-21 15:01:03 -0700 | [diff] [blame] | 11053 | mInteractive = false; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 11054 | mInteractiveTimer = new StopwatchTimer(mClocks, null, -10, null, mOnBatteryTimeBase, in); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 11055 | mPhoneOn = false; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 11056 | mPowerSaveModeEnabledTimer = new StopwatchTimer(mClocks, null, -2, null, |
| 11057 | mOnBatteryTimeBase, in); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 11058 | mLongestLightIdleTime = in.readLong(); |
| 11059 | mLongestFullIdleTime = in.readLong(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 11060 | mDeviceIdleModeLightTimer = new StopwatchTimer(mClocks, null, -14, null, |
| 11061 | mOnBatteryTimeBase, in); |
| 11062 | mDeviceIdleModeFullTimer = new StopwatchTimer(mClocks, null, -11, null, |
| 11063 | mOnBatteryTimeBase, in); |
| 11064 | mDeviceLightIdlingTimer = new StopwatchTimer(mClocks, null, -15, null, |
| 11065 | mOnBatteryTimeBase, in); |
| 11066 | mDeviceIdlingTimer = new StopwatchTimer(mClocks, null, -12, null, mOnBatteryTimeBase, in); |
| 11067 | mPhoneOnTimer = new StopwatchTimer(mClocks, null, -3, null, mOnBatteryTimeBase, in); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 11068 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 11069 | mPhoneSignalStrengthsTimer[i] = new StopwatchTimer(mClocks, null, -200-i, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 11070 | null, mOnBatteryTimeBase, in); |
| 11071 | } |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 11072 | mPhoneSignalScanningTimer = new StopwatchTimer(mClocks, null, -200+1, null, |
| 11073 | mOnBatteryTimeBase, in); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 11074 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 11075 | mPhoneDataConnectionsTimer[i] = new StopwatchTimer(mClocks, null, -300-i, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 11076 | null, mOnBatteryTimeBase, in); |
| 11077 | } |
| 11078 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
| 11079 | mNetworkByteActivityCounters[i] = new LongSamplingCounter(mOnBatteryTimeBase, in); |
| 11080 | mNetworkPacketActivityCounters[i] = new LongSamplingCounter(mOnBatteryTimeBase, in); |
| 11081 | } |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 11082 | mMobileRadioPowerState = DataConnectionRealTimeInfo.DC_POWER_STATE_LOW; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 11083 | mMobileRadioActiveTimer = new StopwatchTimer(mClocks, null, -400, null, |
| 11084 | mOnBatteryTimeBase, in); |
| 11085 | mMobileRadioActivePerAppTimer = new StopwatchTimer(mClocks, null, -401, null, |
| 11086 | mOnBatteryTimeBase, in); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 11087 | mMobileRadioActiveAdjustedTime = new LongSamplingCounter(mOnBatteryTimeBase, in); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 11088 | mMobileRadioActiveUnknownTime = new LongSamplingCounter(mOnBatteryTimeBase, in); |
| 11089 | mMobileRadioActiveUnknownCount = new LongSamplingCounter(mOnBatteryTimeBase, in); |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 11090 | mWifiRadioPowerState = DataConnectionRealTimeInfo.DC_POWER_STATE_LOW; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 11091 | mWifiOn = false; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 11092 | mWifiOnTimer = new StopwatchTimer(mClocks, null, -4, null, mOnBatteryTimeBase, in); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 11093 | mGlobalWifiRunning = false; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 11094 | mGlobalWifiRunningTimer = new StopwatchTimer(mClocks, null, -5, null, |
| 11095 | mOnBatteryTimeBase, in); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 11096 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 11097 | mWifiStateTimer[i] = new StopwatchTimer(mClocks, null, -600-i, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 11098 | null, mOnBatteryTimeBase, in); |
| 11099 | } |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 11100 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 11101 | mWifiSupplStateTimer[i] = new StopwatchTimer(mClocks, null, -700-i, |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 11102 | null, mOnBatteryTimeBase, in); |
| 11103 | } |
| 11104 | for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 11105 | mWifiSignalStrengthsTimer[i] = new StopwatchTimer(mClocks, null, -800-i, |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 11106 | null, mOnBatteryTimeBase, in); |
| 11107 | } |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 11108 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 11109 | mWifiActivity = new ControllerActivityCounterImpl(mOnBatteryTimeBase, |
| 11110 | NUM_WIFI_TX_LEVELS, in); |
| 11111 | mBluetoothActivity = new ControllerActivityCounterImpl(mOnBatteryTimeBase, |
| 11112 | NUM_BT_TX_LEVELS, in); |
| 11113 | mModemActivity = new ControllerActivityCounterImpl(mOnBatteryTimeBase, |
| 11114 | ModemActivityInfo.TX_POWER_LEVELS, in); |
| 11115 | mHasWifiReporting = in.readInt() != 0; |
| 11116 | mHasBluetoothReporting = in.readInt() != 0; |
| 11117 | mHasModemReporting = in.readInt() != 0; |
| 11118 | |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 11119 | mNumConnectivityChange = in.readInt(); |
| 11120 | mLoadedNumConnectivityChange = in.readInt(); |
| 11121 | mUnpluggedNumConnectivityChange = in.readInt(); |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 11122 | mAudioOnNesting = 0; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 11123 | mAudioOnTimer = new StopwatchTimer(mClocks, null, -7, null, mOnBatteryTimeBase); |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 11124 | mVideoOnNesting = 0; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 11125 | mVideoOnTimer = new StopwatchTimer(mClocks, null, -8, null, mOnBatteryTimeBase); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 11126 | mFlashlightOnNesting = 0; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 11127 | mFlashlightOnTimer = new StopwatchTimer(mClocks, null, -9, null, mOnBatteryTimeBase, in); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 11128 | mCameraOnNesting = 0; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 11129 | mCameraOnTimer = new StopwatchTimer(mClocks, null, -13, null, mOnBatteryTimeBase, in); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 11130 | mBluetoothScanNesting = 0; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 11131 | mBluetoothScanTimer = new StopwatchTimer(mClocks, null, -14, null, mOnBatteryTimeBase, in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 11132 | mDischargeUnplugLevel = in.readInt(); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 11133 | mDischargePlugLevel = in.readInt(); |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 11134 | mDischargeCurrentLevel = in.readInt(); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 11135 | mCurrentBatteryLevel = in.readInt(); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 11136 | mLowDischargeAmountSinceCharge = in.readInt(); |
| 11137 | mHighDischargeAmountSinceCharge = in.readInt(); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 11138 | mDischargeAmountScreenOn = in.readInt(); |
| 11139 | mDischargeAmountScreenOnSinceCharge = in.readInt(); |
| 11140 | mDischargeAmountScreenOff = in.readInt(); |
| 11141 | mDischargeAmountScreenOffSinceCharge = in.readInt(); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 11142 | mDischargeStepTracker.readFromParcel(in); |
| 11143 | mChargeStepTracker.readFromParcel(in); |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 11144 | mDischargeCounter = new LongSamplingCounter(mOnBatteryTimeBase, in); |
| 11145 | mDischargeScreenOffCounter = new LongSamplingCounter(mOnBatteryTimeBase, in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11146 | mLastWriteTime = in.readLong(); |
| 11147 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 11148 | mKernelWakelockStats.clear(); |
| 11149 | int NKW = in.readInt(); |
| 11150 | for (int ikw = 0; ikw < NKW; ikw++) { |
| 11151 | if (in.readInt() != 0) { |
| 11152 | String wakelockName = in.readString(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 11153 | SamplingTimer kwlt = new SamplingTimer(mClocks, mOnBatteryScreenOffTimeBase, in); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 11154 | mKernelWakelockStats.put(wakelockName, kwlt); |
| 11155 | } |
| 11156 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 11157 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 11158 | mWakeupReasonStats.clear(); |
| 11159 | int NWR = in.readInt(); |
| 11160 | for (int iwr = 0; iwr < NWR; iwr++) { |
| 11161 | if (in.readInt() != 0) { |
| 11162 | String reasonName = in.readString(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 11163 | SamplingTimer timer = new SamplingTimer(mClocks, mOnBatteryTimeBase, in); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 11164 | mWakeupReasonStats.put(reasonName, timer); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 11165 | } |
| 11166 | } |
| 11167 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11168 | mPartialTimers.clear(); |
| 11169 | mFullTimers.clear(); |
| 11170 | mWindowTimers.clear(); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 11171 | mWifiRunningTimers.clear(); |
| 11172 | mFullWifiLockTimers.clear(); |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 11173 | mWifiScanTimers.clear(); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 11174 | mWifiBatchedScanTimers.clear(); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 11175 | mWifiMulticastTimers.clear(); |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 11176 | mAudioTurnedOnTimers.clear(); |
| 11177 | mVideoTurnedOnTimers.clear(); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 11178 | mFlashlightTurnedOnTimers.clear(); |
| 11179 | mCameraTurnedOnTimers.clear(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11180 | |
| 11181 | int numUids = in.readInt(); |
| 11182 | mUidStats.clear(); |
| 11183 | for (int i = 0; i < numUids; i++) { |
| 11184 | int uid = in.readInt(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 11185 | Uid u = new Uid(this, uid); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 11186 | u.readFromParcelLocked(mOnBatteryTimeBase, mOnBatteryScreenOffTimeBase, in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11187 | mUidStats.append(uid, u); |
| 11188 | } |
| 11189 | } |
| 11190 | |
| 11191 | public void writeToParcel(Parcel out, int flags) { |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 11192 | writeToParcelLocked(out, true, flags); |
| 11193 | } |
| 11194 | |
| 11195 | public void writeToParcelWithoutUids(Parcel out, int flags) { |
| 11196 | writeToParcelLocked(out, false, flags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11197 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 11198 | |
| 11199 | @SuppressWarnings("unused") |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 11200 | void writeToParcelLocked(Parcel out, boolean inclUids, int flags) { |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 11201 | // Need to update with current kernel wake lock counts. |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 11202 | pullPendingStateUpdatesLocked(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 11203 | |
Dianne Hackborn | 7d9eefd | 2014-08-27 18:30:31 -0700 | [diff] [blame] | 11204 | // Pull the clock time. This may update the time and make a new history entry |
| 11205 | // if we had originally pulled a time before the RTC was set. |
| 11206 | long startClockTime = getStartClockTime(); |
| 11207 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 11208 | final long uSecUptime = mClocks.uptimeMillis() * 1000; |
| 11209 | final long uSecRealtime = mClocks.elapsedRealtime() * 1000; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 11210 | final long batteryRealtime = mOnBatteryTimeBase.getRealtime(uSecRealtime); |
| 11211 | final long batteryScreenOffRealtime = mOnBatteryScreenOffTimeBase.getRealtime(uSecRealtime); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 11212 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11213 | out.writeInt(MAGIC); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 11214 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 11215 | writeHistory(out, true, false); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 11216 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11217 | out.writeInt(mStartCount); |
Dianne Hackborn | 7d9eefd | 2014-08-27 18:30:31 -0700 | [diff] [blame] | 11218 | out.writeLong(startClockTime); |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 11219 | out.writeString(mStartPlatformVersion); |
| 11220 | out.writeString(mEndPlatformVersion); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11221 | out.writeLong(mUptime); |
| 11222 | out.writeLong(mUptimeStart); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11223 | out.writeLong(mRealtime); |
| 11224 | out.writeLong(mRealtimeStart); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11225 | out.writeInt(mOnBattery ? 1 : 0); |
Adam Lesinski | f9b20a9 | 2016-06-17 17:30:01 -0700 | [diff] [blame] | 11226 | out.writeInt(mEstimatedBatteryCapacity); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 11227 | mOnBatteryTimeBase.writeToParcel(out, uSecUptime, uSecRealtime); |
| 11228 | mOnBatteryScreenOffTimeBase.writeToParcel(out, uSecUptime, uSecRealtime); |
| 11229 | |
| 11230 | mScreenOnTimer.writeToParcel(out, uSecRealtime); |
| 11231 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
| 11232 | mScreenBrightnessTimer[i].writeToParcel(out, uSecRealtime); |
| 11233 | } |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 11234 | mInteractiveTimer.writeToParcel(out, uSecRealtime); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 11235 | mPowerSaveModeEnabledTimer.writeToParcel(out, uSecRealtime); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 11236 | out.writeLong(mLongestLightIdleTime); |
| 11237 | out.writeLong(mLongestFullIdleTime); |
| 11238 | mDeviceIdleModeLightTimer.writeToParcel(out, uSecRealtime); |
| 11239 | mDeviceIdleModeFullTimer.writeToParcel(out, uSecRealtime); |
| 11240 | mDeviceLightIdlingTimer.writeToParcel(out, uSecRealtime); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 11241 | mDeviceIdlingTimer.writeToParcel(out, uSecRealtime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 11242 | mPhoneOnTimer.writeToParcel(out, uSecRealtime); |
| 11243 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
| 11244 | mPhoneSignalStrengthsTimer[i].writeToParcel(out, uSecRealtime); |
| 11245 | } |
| 11246 | mPhoneSignalScanningTimer.writeToParcel(out, uSecRealtime); |
| 11247 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
| 11248 | mPhoneDataConnectionsTimer[i].writeToParcel(out, uSecRealtime); |
| 11249 | } |
| 11250 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
| 11251 | mNetworkByteActivityCounters[i].writeToParcel(out); |
| 11252 | mNetworkPacketActivityCounters[i].writeToParcel(out); |
| 11253 | } |
| 11254 | mMobileRadioActiveTimer.writeToParcel(out, uSecRealtime); |
| 11255 | mMobileRadioActivePerAppTimer.writeToParcel(out, uSecRealtime); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 11256 | mMobileRadioActiveAdjustedTime.writeToParcel(out); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 11257 | mMobileRadioActiveUnknownTime.writeToParcel(out); |
| 11258 | mMobileRadioActiveUnknownCount.writeToParcel(out); |
| 11259 | mWifiOnTimer.writeToParcel(out, uSecRealtime); |
| 11260 | mGlobalWifiRunningTimer.writeToParcel(out, uSecRealtime); |
| 11261 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
| 11262 | mWifiStateTimer[i].writeToParcel(out, uSecRealtime); |
| 11263 | } |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 11264 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
| 11265 | mWifiSupplStateTimer[i].writeToParcel(out, uSecRealtime); |
| 11266 | } |
| 11267 | for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 11268 | mWifiSignalStrengthsTimer[i].writeToParcel(out, uSecRealtime); |
| 11269 | } |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 11270 | mWifiActivity.writeToParcel(out, 0); |
| 11271 | mBluetoothActivity.writeToParcel(out, 0); |
| 11272 | mModemActivity.writeToParcel(out, 0); |
| 11273 | out.writeInt(mHasWifiReporting ? 1 : 0); |
| 11274 | out.writeInt(mHasBluetoothReporting ? 1 : 0); |
| 11275 | out.writeInt(mHasModemReporting ? 1 : 0); |
| 11276 | |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 11277 | out.writeInt(mNumConnectivityChange); |
| 11278 | out.writeInt(mLoadedNumConnectivityChange); |
| 11279 | out.writeInt(mUnpluggedNumConnectivityChange); |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 11280 | mFlashlightOnTimer.writeToParcel(out, uSecRealtime); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 11281 | mCameraOnTimer.writeToParcel(out, uSecRealtime); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 11282 | mBluetoothScanTimer.writeToParcel(out, uSecRealtime); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 11283 | out.writeInt(mDischargeUnplugLevel); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 11284 | out.writeInt(mDischargePlugLevel); |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 11285 | out.writeInt(mDischargeCurrentLevel); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 11286 | out.writeInt(mCurrentBatteryLevel); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 11287 | out.writeInt(mLowDischargeAmountSinceCharge); |
| 11288 | out.writeInt(mHighDischargeAmountSinceCharge); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 11289 | out.writeInt(mDischargeAmountScreenOn); |
| 11290 | out.writeInt(mDischargeAmountScreenOnSinceCharge); |
| 11291 | out.writeInt(mDischargeAmountScreenOff); |
| 11292 | out.writeInt(mDischargeAmountScreenOffSinceCharge); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 11293 | mDischargeStepTracker.writeToParcel(out); |
| 11294 | mChargeStepTracker.writeToParcel(out); |
Adam Lesinski | 3ee3f63 | 2016-06-08 13:55:55 -0700 | [diff] [blame] | 11295 | mDischargeCounter.writeToParcel(out); |
| 11296 | mDischargeScreenOffCounter.writeToParcel(out); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11297 | out.writeLong(mLastWriteTime); |
| 11298 | |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 11299 | if (inclUids) { |
| 11300 | out.writeInt(mKernelWakelockStats.size()); |
| 11301 | for (Map.Entry<String, SamplingTimer> ent : mKernelWakelockStats.entrySet()) { |
| 11302 | SamplingTimer kwlt = ent.getValue(); |
| 11303 | if (kwlt != null) { |
| 11304 | out.writeInt(1); |
| 11305 | out.writeString(ent.getKey()); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 11306 | kwlt.writeToParcel(out, uSecRealtime); |
| 11307 | } else { |
| 11308 | out.writeInt(0); |
| 11309 | } |
| 11310 | } |
| 11311 | out.writeInt(mWakeupReasonStats.size()); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 11312 | for (Map.Entry<String, SamplingTimer> ent : mWakeupReasonStats.entrySet()) { |
| 11313 | SamplingTimer timer = ent.getValue(); |
| 11314 | if (timer != null) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 11315 | out.writeInt(1); |
| 11316 | out.writeString(ent.getKey()); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 11317 | timer.writeToParcel(out, uSecRealtime); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 11318 | } else { |
| 11319 | out.writeInt(0); |
| 11320 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 11321 | } |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 11322 | } else { |
| 11323 | out.writeInt(0); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 11324 | } |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 11325 | |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 11326 | if (inclUids) { |
| 11327 | int size = mUidStats.size(); |
| 11328 | out.writeInt(size); |
| 11329 | for (int i = 0; i < size; i++) { |
| 11330 | out.writeInt(mUidStats.keyAt(i)); |
| 11331 | Uid uid = mUidStats.valueAt(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11332 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 11333 | uid.writeToParcelLocked(out, uSecRealtime); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 11334 | } |
| 11335 | } else { |
| 11336 | out.writeInt(0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11337 | } |
| 11338 | } |
| 11339 | |
| 11340 | public static final Parcelable.Creator<BatteryStatsImpl> CREATOR = |
| 11341 | new Parcelable.Creator<BatteryStatsImpl>() { |
| 11342 | public BatteryStatsImpl createFromParcel(Parcel in) { |
| 11343 | return new BatteryStatsImpl(in); |
| 11344 | } |
| 11345 | |
| 11346 | public BatteryStatsImpl[] newArray(int size) { |
| 11347 | return new BatteryStatsImpl[size]; |
| 11348 | } |
| 11349 | }; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 11350 | |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 11351 | public void prepareForDumpLocked() { |
| 11352 | // Need to retrieve current kernel wake lock stats before printing. |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 11353 | pullPendingStateUpdatesLocked(); |
Dianne Hackborn | 7d9eefd | 2014-08-27 18:30:31 -0700 | [diff] [blame] | 11354 | |
| 11355 | // Pull the clock time. This may update the time and make a new history entry |
| 11356 | // if we had originally pulled a time before the RTC was set. |
| 11357 | getStartClockTime(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 11358 | } |
| 11359 | |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 11360 | 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] | 11361 | if (DEBUG) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 11362 | pw.println("mOnBatteryTimeBase:"); |
| 11363 | mOnBatteryTimeBase.dump(pw, " "); |
| 11364 | pw.println("mOnBatteryScreenOffTimeBase:"); |
| 11365 | mOnBatteryScreenOffTimeBase.dump(pw, " "); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11366 | Printer pr = new PrintWriterPrinter(pw); |
| 11367 | pr.println("*** Screen timer:"); |
| 11368 | mScreenOnTimer.logState(pr, " "); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 11369 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11370 | pr.println("*** Screen brightness #" + i + ":"); |
| 11371 | mScreenBrightnessTimer[i].logState(pr, " "); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 11372 | } |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 11373 | pr.println("*** Interactive timer:"); |
| 11374 | mInteractiveTimer.logState(pr, " "); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 11375 | pr.println("*** Power save mode timer:"); |
| 11376 | mPowerSaveModeEnabledTimer.logState(pr, " "); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 11377 | pr.println("*** Device idle mode light timer:"); |
| 11378 | mDeviceIdleModeLightTimer.logState(pr, " "); |
| 11379 | pr.println("*** Device idle mode full timer:"); |
| 11380 | mDeviceIdleModeFullTimer.logState(pr, " "); |
| 11381 | pr.println("*** Device light idling timer:"); |
| 11382 | mDeviceLightIdlingTimer.logState(pr, " "); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 11383 | pr.println("*** Device idling timer:"); |
| 11384 | mDeviceIdlingTimer.logState(pr, " "); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11385 | pr.println("*** Phone timer:"); |
| 11386 | mPhoneOnTimer.logState(pr, " "); |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 11387 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 11388 | pr.println("*** Phone signal strength #" + i + ":"); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11389 | mPhoneSignalStrengthsTimer[i].logState(pr, " "); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 11390 | } |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 11391 | pr.println("*** Signal scanning :"); |
| 11392 | mPhoneSignalScanningTimer.logState(pr, " "); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 11393 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11394 | pr.println("*** Data connection type #" + i + ":"); |
| 11395 | mPhoneDataConnectionsTimer[i].logState(pr, " "); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 11396 | } |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 11397 | pr.println("*** mMobileRadioPowerState=" + mMobileRadioPowerState); |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 11398 | pr.println("*** Mobile network active timer:"); |
| 11399 | mMobileRadioActiveTimer.logState(pr, " "); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 11400 | pr.println("*** Mobile network active adjusted timer:"); |
| 11401 | mMobileRadioActiveAdjustedTime.logState(pr, " "); |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 11402 | pr.println("*** mWifiRadioPowerState=" + mWifiRadioPowerState); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11403 | pr.println("*** Wifi timer:"); |
| 11404 | mWifiOnTimer.logState(pr, " "); |
| 11405 | pr.println("*** WifiRunning timer:"); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 11406 | mGlobalWifiRunningTimer.logState(pr, " "); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 11407 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
| 11408 | pr.println("*** Wifi state #" + i + ":"); |
| 11409 | mWifiStateTimer[i].logState(pr, " "); |
| 11410 | } |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 11411 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
| 11412 | pr.println("*** Wifi suppl state #" + i + ":"); |
| 11413 | mWifiSupplStateTimer[i].logState(pr, " "); |
| 11414 | } |
| 11415 | for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 11416 | pr.println("*** Wifi signal strength #" + i + ":"); |
| 11417 | mWifiSignalStrengthsTimer[i].logState(pr, " "); |
| 11418 | } |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 11419 | pr.println("*** Flashlight timer:"); |
| 11420 | mFlashlightOnTimer.logState(pr, " "); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 11421 | pr.println("*** Camera timer:"); |
| 11422 | mCameraOnTimer.logState(pr, " "); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11423 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 11424 | super.dumpLocked(context, pw, flags, reqUid, histStart); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11425 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11426 | } |