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 | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 111 | private static final int VERSION = 144 + (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 | |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 512 | static final int MAX_LEVEL_STEPS = 200; |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 513 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 514 | int mInitStepMode = 0; |
| 515 | int mCurStepMode = 0; |
| 516 | int mModStepMode = 0; |
| 517 | |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 518 | int mLastDischargeStepLevel; |
Dianne Hackborn | 2932513 | 2014-05-21 15:01:03 -0700 | [diff] [blame] | 519 | int mMinDischargeStepLevel; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 520 | final LevelStepTracker mDischargeStepTracker = new LevelStepTracker(MAX_LEVEL_STEPS); |
| 521 | final LevelStepTracker mDailyDischargeStepTracker = new LevelStepTracker(MAX_LEVEL_STEPS*2); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 522 | ArrayList<PackageChange> mDailyPackageChanges; |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 523 | |
| 524 | int mLastChargeStepLevel; |
Dianne Hackborn | 2932513 | 2014-05-21 15:01:03 -0700 | [diff] [blame] | 525 | int mMaxChargeStepLevel; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 526 | final LevelStepTracker mChargeStepTracker = new LevelStepTracker(MAX_LEVEL_STEPS); |
| 527 | final LevelStepTracker mDailyChargeStepTracker = new LevelStepTracker(MAX_LEVEL_STEPS*2); |
| 528 | |
| 529 | static final int MAX_DAILY_ITEMS = 10; |
| 530 | |
| 531 | long mDailyStartTime = 0; |
| 532 | long mNextMinDailyDeadline = 0; |
| 533 | long mNextMaxDailyDeadline = 0; |
| 534 | |
| 535 | final ArrayList<DailyItem> mDailyItems = new ArrayList<>(); |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 536 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 537 | long mLastWriteTime = 0; // Milliseconds |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 538 | |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 539 | private int mPhoneServiceState = -1; |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 540 | private int mPhoneServiceStateRaw = -1; |
| 541 | private int mPhoneSimStateRaw = -1; |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 542 | |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 543 | private int mNumConnectivityChange; |
| 544 | private int mLoadedNumConnectivityChange; |
| 545 | private int mUnpluggedNumConnectivityChange; |
| 546 | |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 547 | private final NetworkStats.Entry mTmpNetworkStatsEntry = new NetworkStats.Entry(); |
| 548 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 549 | private PowerProfile mPowerProfile; |
| 550 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 551 | /* |
| 552 | * Holds a SamplingTimer associated with each kernel wakelock name being tracked. |
| 553 | */ |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 554 | private final HashMap<String, SamplingTimer> mKernelWakelockStats = new HashMap<>(); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 555 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 556 | public Map<String, ? extends Timer> getKernelWakelockStats() { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 557 | return mKernelWakelockStats; |
| 558 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 559 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 560 | String mLastWakeupReason = null; |
| 561 | long mLastWakeupUptimeMs = 0; |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 562 | private final HashMap<String, SamplingTimer> mWakeupReasonStats = new HashMap<>(); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 563 | |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 564 | public Map<String, ? extends Timer> getWakeupReasonStats() { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 565 | return mWakeupReasonStats; |
| 566 | } |
| 567 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 568 | public BatteryStatsImpl() { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 569 | this(new SystemClocks()); |
| 570 | } |
| 571 | |
| 572 | public BatteryStatsImpl(Clocks clocks) { |
| 573 | init(clocks); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 574 | mFile = null; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 575 | mCheckinFile = null; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 576 | mDailyFile = null; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 577 | mHandler = null; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 578 | mExternalSync = null; |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 579 | mPlatformIdleStateCallback = null; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 580 | clearHistoryLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 581 | } |
| 582 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 583 | private void init(Clocks clocks) { |
| 584 | mClocks = clocks; |
| 585 | mMobileNetworkStats = new NetworkStats[] { |
| 586 | new NetworkStats(mClocks.elapsedRealtime(), 50), |
| 587 | new NetworkStats(mClocks.elapsedRealtime(), 50), |
| 588 | new NetworkStats(mClocks.elapsedRealtime(), 50) |
| 589 | }; |
| 590 | mWifiNetworkStats = new NetworkStats[] { |
| 591 | new NetworkStats(mClocks.elapsedRealtime(), 50), |
| 592 | new NetworkStats(mClocks.elapsedRealtime(), 50), |
| 593 | new NetworkStats(mClocks.elapsedRealtime(), 50) |
| 594 | }; |
| 595 | } |
| 596 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 597 | public static interface TimeBaseObs { |
| 598 | void onTimeStarted(long elapsedRealtime, long baseUptime, long baseRealtime); |
| 599 | void onTimeStopped(long elapsedRealtime, long baseUptime, long baseRealtime); |
| 600 | } |
| 601 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 602 | // methods are protected not private to be VisibleForTesting |
| 603 | public static class TimeBase { |
| 604 | protected final ArrayList<TimeBaseObs> mObservers = new ArrayList<>(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 605 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 606 | protected long mUptime; |
| 607 | protected long mRealtime; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 608 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 609 | protected boolean mRunning; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 610 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 611 | protected long mPastUptime; |
| 612 | protected long mUptimeStart; |
| 613 | protected long mPastRealtime; |
| 614 | protected long mRealtimeStart; |
| 615 | protected long mUnpluggedUptime; |
| 616 | protected long mUnpluggedRealtime; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 617 | |
| 618 | public void dump(PrintWriter pw, String prefix) { |
| 619 | StringBuilder sb = new StringBuilder(128); |
| 620 | pw.print(prefix); pw.print("mRunning="); pw.println(mRunning); |
| 621 | sb.setLength(0); |
| 622 | sb.append(prefix); |
| 623 | sb.append("mUptime="); |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 624 | formatTimeMs(sb, mUptime / 1000); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 625 | pw.println(sb.toString()); |
| 626 | sb.setLength(0); |
| 627 | sb.append(prefix); |
| 628 | sb.append("mRealtime="); |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 629 | formatTimeMs(sb, mRealtime / 1000); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 630 | pw.println(sb.toString()); |
| 631 | sb.setLength(0); |
| 632 | sb.append(prefix); |
| 633 | sb.append("mPastUptime="); |
| 634 | formatTimeMs(sb, mPastUptime / 1000); sb.append("mUptimeStart="); |
| 635 | formatTimeMs(sb, mUptimeStart / 1000); |
| 636 | sb.append("mUnpluggedUptime="); formatTimeMs(sb, mUnpluggedUptime / 1000); |
| 637 | pw.println(sb.toString()); |
| 638 | sb.setLength(0); |
| 639 | sb.append(prefix); |
| 640 | sb.append("mPastRealtime="); |
| 641 | formatTimeMs(sb, mPastRealtime / 1000); sb.append("mRealtimeStart="); |
| 642 | formatTimeMs(sb, mRealtimeStart / 1000); |
| 643 | sb.append("mUnpluggedRealtime="); formatTimeMs(sb, mUnpluggedRealtime / 1000); |
| 644 | pw.println(sb.toString()); |
| 645 | } |
| 646 | |
| 647 | public void add(TimeBaseObs observer) { |
| 648 | mObservers.add(observer); |
| 649 | } |
| 650 | |
| 651 | public void remove(TimeBaseObs observer) { |
| 652 | if (!mObservers.remove(observer)) { |
| 653 | Slog.wtf(TAG, "Removed unknown observer: " + observer); |
| 654 | } |
| 655 | } |
| 656 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 657 | public boolean hasObserver(TimeBaseObs observer) { |
| 658 | return mObservers.contains(observer); |
| 659 | } |
| 660 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 661 | public void init(long uptime, long realtime) { |
| 662 | mRealtime = 0; |
| 663 | mUptime = 0; |
| 664 | mPastUptime = 0; |
| 665 | mPastRealtime = 0; |
| 666 | mUptimeStart = uptime; |
| 667 | mRealtimeStart = realtime; |
| 668 | mUnpluggedUptime = getUptime(mUptimeStart); |
| 669 | mUnpluggedRealtime = getRealtime(mRealtimeStart); |
| 670 | } |
| 671 | |
| 672 | public void reset(long uptime, long realtime) { |
| 673 | if (!mRunning) { |
| 674 | mPastUptime = 0; |
| 675 | mPastRealtime = 0; |
| 676 | } else { |
| 677 | mUptimeStart = uptime; |
| 678 | mRealtimeStart = realtime; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 679 | // TODO: Since mUptimeStart was just reset and we are running, getUptime will |
| 680 | // 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] | 681 | mUnpluggedUptime = getUptime(uptime); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 682 | // TODO: likewise. |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 683 | mUnpluggedRealtime = getRealtime(realtime); |
| 684 | } |
| 685 | } |
| 686 | |
| 687 | public long computeUptime(long curTime, int which) { |
| 688 | switch (which) { |
| 689 | case STATS_SINCE_CHARGED: |
| 690 | return mUptime + getUptime(curTime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 691 | case STATS_CURRENT: |
| 692 | return getUptime(curTime); |
| 693 | case STATS_SINCE_UNPLUGGED: |
| 694 | return getUptime(curTime) - mUnpluggedUptime; |
| 695 | } |
| 696 | return 0; |
| 697 | } |
| 698 | |
| 699 | public long computeRealtime(long curTime, int which) { |
| 700 | switch (which) { |
| 701 | case STATS_SINCE_CHARGED: |
| 702 | return mRealtime + getRealtime(curTime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 703 | case STATS_CURRENT: |
| 704 | return getRealtime(curTime); |
| 705 | case STATS_SINCE_UNPLUGGED: |
| 706 | return getRealtime(curTime) - mUnpluggedRealtime; |
| 707 | } |
| 708 | return 0; |
| 709 | } |
| 710 | |
| 711 | public long getUptime(long curTime) { |
| 712 | long time = mPastUptime; |
| 713 | if (mRunning) { |
| 714 | time += curTime - mUptimeStart; |
| 715 | } |
| 716 | return time; |
| 717 | } |
| 718 | |
| 719 | public long getRealtime(long curTime) { |
| 720 | long time = mPastRealtime; |
| 721 | if (mRunning) { |
| 722 | time += curTime - mRealtimeStart; |
| 723 | } |
| 724 | return time; |
| 725 | } |
| 726 | |
| 727 | public long getUptimeStart() { |
| 728 | return mUptimeStart; |
| 729 | } |
| 730 | |
| 731 | public long getRealtimeStart() { |
| 732 | return mRealtimeStart; |
| 733 | } |
| 734 | |
| 735 | public boolean isRunning() { |
| 736 | return mRunning; |
| 737 | } |
| 738 | |
| 739 | public boolean setRunning(boolean running, long uptime, long realtime) { |
| 740 | if (mRunning != running) { |
| 741 | mRunning = running; |
| 742 | if (running) { |
| 743 | mUptimeStart = uptime; |
| 744 | mRealtimeStart = realtime; |
| 745 | long batteryUptime = mUnpluggedUptime = getUptime(uptime); |
| 746 | long batteryRealtime = mUnpluggedRealtime = getRealtime(realtime); |
| 747 | |
| 748 | for (int i = mObservers.size() - 1; i >= 0; i--) { |
| 749 | mObservers.get(i).onTimeStarted(realtime, batteryUptime, batteryRealtime); |
| 750 | } |
| 751 | } else { |
| 752 | mPastUptime += uptime - mUptimeStart; |
| 753 | mPastRealtime += realtime - mRealtimeStart; |
| 754 | |
| 755 | long batteryUptime = getUptime(uptime); |
| 756 | long batteryRealtime = getRealtime(realtime); |
| 757 | |
| 758 | for (int i = mObservers.size() - 1; i >= 0; i--) { |
| 759 | mObservers.get(i).onTimeStopped(realtime, batteryUptime, batteryRealtime); |
| 760 | } |
| 761 | } |
| 762 | return true; |
| 763 | } |
| 764 | return false; |
| 765 | } |
| 766 | |
| 767 | public void readSummaryFromParcel(Parcel in) { |
| 768 | mUptime = in.readLong(); |
| 769 | mRealtime = in.readLong(); |
| 770 | } |
| 771 | |
| 772 | public void writeSummaryToParcel(Parcel out, long uptime, long realtime) { |
| 773 | out.writeLong(computeUptime(uptime, STATS_SINCE_CHARGED)); |
| 774 | out.writeLong(computeRealtime(realtime, STATS_SINCE_CHARGED)); |
| 775 | } |
| 776 | |
| 777 | public void readFromParcel(Parcel in) { |
| 778 | mRunning = false; |
| 779 | mUptime = in.readLong(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 780 | mPastUptime = in.readLong(); |
| 781 | mUptimeStart = in.readLong(); |
Dianne Hackborn | ef640cd | 2014-03-25 14:41:05 -0700 | [diff] [blame] | 782 | mRealtime = in.readLong(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 783 | mPastRealtime = in.readLong(); |
| 784 | mRealtimeStart = in.readLong(); |
| 785 | mUnpluggedUptime = in.readLong(); |
| 786 | mUnpluggedRealtime = in.readLong(); |
| 787 | } |
| 788 | |
| 789 | public void writeToParcel(Parcel out, long uptime, long realtime) { |
| 790 | final long runningUptime = getUptime(uptime); |
| 791 | final long runningRealtime = getRealtime(realtime); |
| 792 | out.writeLong(mUptime); |
| 793 | out.writeLong(runningUptime); |
| 794 | out.writeLong(mUptimeStart); |
Dianne Hackborn | ef640cd | 2014-03-25 14:41:05 -0700 | [diff] [blame] | 795 | out.writeLong(mRealtime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 796 | out.writeLong(runningRealtime); |
| 797 | out.writeLong(mRealtimeStart); |
| 798 | out.writeLong(mUnpluggedUptime); |
| 799 | out.writeLong(mUnpluggedRealtime); |
| 800 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 801 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 802 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 803 | /** |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 804 | * State for keeping track of counting information. |
| 805 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 806 | public static class Counter extends BatteryStats.Counter implements TimeBaseObs { |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 807 | final AtomicInteger mCount = new AtomicInteger(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 808 | final TimeBase mTimeBase; |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 809 | int mLoadedCount; |
| 810 | int mLastCount; |
| 811 | int mUnpluggedCount; |
| 812 | int mPluggedCount; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 813 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 814 | Counter(TimeBase timeBase, Parcel in) { |
| 815 | mTimeBase = timeBase; |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 816 | mPluggedCount = in.readInt(); |
| 817 | mCount.set(mPluggedCount); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 818 | mLoadedCount = in.readInt(); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 819 | mLastCount = 0; |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 820 | mUnpluggedCount = in.readInt(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 821 | timeBase.add(this); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 822 | } |
| 823 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 824 | Counter(TimeBase timeBase) { |
| 825 | mTimeBase = timeBase; |
| 826 | timeBase.add(this); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 827 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 828 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 829 | public void writeToParcel(Parcel out) { |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 830 | out.writeInt(mCount.get()); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 831 | out.writeInt(mLoadedCount); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 832 | out.writeInt(mUnpluggedCount); |
| 833 | } |
| 834 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 835 | public void onTimeStarted(long elapsedRealtime, long baseUptime, long baseRealtime) { |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 836 | mUnpluggedCount = mPluggedCount; |
| 837 | mCount.set(mPluggedCount); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 838 | } |
| 839 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 840 | public void onTimeStopped(long elapsedRealtime, long baseUptime, long baseRealtime) { |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 841 | mPluggedCount = mCount.get(); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 842 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 843 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 844 | /** |
| 845 | * Writes a possibly null Counter to a Parcel. |
| 846 | * |
| 847 | * @param out the Parcel to be written to. |
| 848 | * @param counter a Counter, or null. |
| 849 | */ |
| 850 | public static void writeCounterToParcel(Parcel out, Counter counter) { |
| 851 | if (counter == null) { |
| 852 | out.writeInt(0); // indicates null |
| 853 | return; |
| 854 | } |
| 855 | out.writeInt(1); // indicates non-null |
| 856 | |
| 857 | counter.writeToParcel(out); |
| 858 | } |
| 859 | |
| 860 | @Override |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 861 | public int getCountLocked(int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 862 | int val = mCount.get(); |
| 863 | if (which == STATS_SINCE_UNPLUGGED) { |
| 864 | val -= mUnpluggedCount; |
| 865 | } else if (which != STATS_SINCE_CHARGED) { |
| 866 | val -= mLoadedCount; |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 867 | } |
| 868 | |
| 869 | return val; |
| 870 | } |
| 871 | |
| 872 | public void logState(Printer pw, String prefix) { |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 873 | pw.println(prefix + "mCount=" + mCount.get() |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 874 | + " mLoadedCount=" + mLoadedCount + " mLastCount=" + mLastCount |
| 875 | + " mUnpluggedCount=" + mUnpluggedCount |
| 876 | + " mPluggedCount=" + mPluggedCount); |
| 877 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 878 | |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 879 | void stepAtomic() { |
| 880 | mCount.incrementAndGet(); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 881 | } |
| 882 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 883 | /** |
| 884 | * Clear state of this counter. |
| 885 | */ |
| 886 | void reset(boolean detachIfReset) { |
| 887 | mCount.set(0); |
| 888 | mLoadedCount = mLastCount = mPluggedCount = mUnpluggedCount = 0; |
| 889 | if (detachIfReset) { |
| 890 | detach(); |
| 891 | } |
| 892 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 893 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 894 | void detach() { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 895 | mTimeBase.remove(this); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 896 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 897 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 898 | void writeSummaryFromParcelLocked(Parcel out) { |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 899 | int count = mCount.get(); |
| 900 | out.writeInt(count); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 901 | } |
| 902 | |
| 903 | void readSummaryFromParcelLocked(Parcel in) { |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 904 | mLoadedCount = in.readInt(); |
| 905 | mCount.set(mLoadedCount); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 906 | mLastCount = 0; |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 907 | mUnpluggedCount = mPluggedCount = mLoadedCount; |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 908 | } |
| 909 | } |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 910 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 911 | public static class LongSamplingCounter extends LongCounter implements TimeBaseObs { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 912 | final TimeBase mTimeBase; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 913 | long mCount; |
| 914 | long mLoadedCount; |
| 915 | long mLastCount; |
| 916 | long mUnpluggedCount; |
| 917 | long mPluggedCount; |
| 918 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 919 | LongSamplingCounter(TimeBase timeBase, Parcel in) { |
| 920 | mTimeBase = timeBase; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 921 | mPluggedCount = in.readLong(); |
| 922 | mCount = mPluggedCount; |
| 923 | mLoadedCount = in.readLong(); |
| 924 | mLastCount = 0; |
| 925 | mUnpluggedCount = in.readLong(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 926 | timeBase.add(this); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 927 | } |
| 928 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 929 | LongSamplingCounter(TimeBase timeBase) { |
| 930 | mTimeBase = timeBase; |
| 931 | timeBase.add(this); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 932 | } |
| 933 | |
| 934 | public void writeToParcel(Parcel out) { |
| 935 | out.writeLong(mCount); |
| 936 | out.writeLong(mLoadedCount); |
| 937 | out.writeLong(mUnpluggedCount); |
| 938 | } |
| 939 | |
| 940 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 941 | public void onTimeStarted(long elapsedRealtime, long baseUptime, long baseRealtime) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 942 | mUnpluggedCount = mPluggedCount; |
| 943 | mCount = mPluggedCount; |
| 944 | } |
| 945 | |
| 946 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 947 | public void onTimeStopped(long elapsedRealtime, long baseUptime, long baseRealtime) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 948 | mPluggedCount = mCount; |
| 949 | } |
| 950 | |
| 951 | public long getCountLocked(int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 952 | long val = mCount; |
| 953 | if (which == STATS_SINCE_UNPLUGGED) { |
| 954 | val -= mUnpluggedCount; |
| 955 | } else if (which != STATS_SINCE_CHARGED) { |
| 956 | val -= mLoadedCount; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 957 | } |
| 958 | |
| 959 | return val; |
| 960 | } |
| 961 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 962 | @Override |
| 963 | public void logState(Printer pw, String prefix) { |
| 964 | pw.println(prefix + "mCount=" + mCount |
| 965 | + " mLoadedCount=" + mLoadedCount + " mLastCount=" + mLastCount |
| 966 | + " mUnpluggedCount=" + mUnpluggedCount |
| 967 | + " mPluggedCount=" + mPluggedCount); |
| 968 | } |
| 969 | |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 970 | void addCountLocked(long count) { |
| 971 | mCount += count; |
| 972 | } |
| 973 | |
| 974 | /** |
| 975 | * Clear state of this counter. |
| 976 | */ |
| 977 | void reset(boolean detachIfReset) { |
| 978 | mCount = 0; |
| 979 | mLoadedCount = mLastCount = mPluggedCount = mUnpluggedCount = 0; |
| 980 | if (detachIfReset) { |
| 981 | detach(); |
| 982 | } |
| 983 | } |
| 984 | |
| 985 | void detach() { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 986 | mTimeBase.remove(this); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 987 | } |
| 988 | |
| 989 | void writeSummaryFromParcelLocked(Parcel out) { |
| 990 | out.writeLong(mCount); |
| 991 | } |
| 992 | |
| 993 | void readSummaryFromParcelLocked(Parcel in) { |
| 994 | mLoadedCount = in.readLong(); |
| 995 | mCount = mLoadedCount; |
| 996 | mLastCount = 0; |
| 997 | mUnpluggedCount = mPluggedCount = mLoadedCount; |
| 998 | } |
| 999 | } |
| 1000 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 1001 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1002 | * State for keeping track of timing information. |
| 1003 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1004 | public static abstract class Timer extends BatteryStats.Timer implements TimeBaseObs { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1005 | protected final Clocks mClocks; |
| 1006 | protected final int mType; |
| 1007 | protected final TimeBase mTimeBase; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1008 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1009 | protected int mCount; |
| 1010 | protected int mLoadedCount; |
| 1011 | protected int mLastCount; |
| 1012 | protected int mUnpluggedCount; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1013 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1014 | // Times are in microseconds for better accuracy when dividing by the |
| 1015 | // lock count, and are in "battery realtime" units. |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1016 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1017 | /** |
| 1018 | * The total time we have accumulated since the start of the original |
| 1019 | * boot, to the last time something interesting happened in the |
| 1020 | * current run. |
| 1021 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1022 | protected long mTotalTime; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1023 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1024 | /** |
| 1025 | * The total time we loaded for the previous runs. Subtract this from |
| 1026 | * mTotalTime to find the time for the current run of the system. |
| 1027 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1028 | protected long mLoadedTime; |
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 | /** |
| 1031 | * The run time of the last run of the system, as loaded from the |
| 1032 | * saved data. |
| 1033 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1034 | protected long mLastTime; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1035 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1036 | /** |
| 1037 | * The value of mTotalTime when unplug() was last called. Subtract |
| 1038 | * this from mTotalTime to find the time since the last unplug from |
| 1039 | * power. |
| 1040 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1041 | protected long mUnpluggedTime; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1042 | |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 1043 | /** |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 1044 | * The total time this timer has been running until the latest mark has been set. |
| 1045 | * Subtract this from mTotalTime to get the time spent running since the mark was set. |
| 1046 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1047 | protected long mTimeBeforeMark; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 1048 | |
| 1049 | /** |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 1050 | * Constructs from a parcel. |
| 1051 | * @param type |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1052 | * @param timeBase |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 1053 | * @param in |
| 1054 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1055 | public Timer(Clocks clocks, int type, TimeBase timeBase, Parcel in) { |
| 1056 | mClocks = clocks; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1057 | mType = type; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1058 | mTimeBase = timeBase; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1059 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1060 | mCount = in.readInt(); |
| 1061 | mLoadedCount = in.readInt(); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 1062 | mLastCount = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1063 | mUnpluggedCount = in.readInt(); |
| 1064 | mTotalTime = in.readLong(); |
| 1065 | mLoadedTime = in.readLong(); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 1066 | mLastTime = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1067 | mUnpluggedTime = in.readLong(); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 1068 | mTimeBeforeMark = in.readLong(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1069 | timeBase.add(this); |
Dianne Hackborn | 2932513 | 2014-05-21 15:01:03 -0700 | [diff] [blame] | 1070 | 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] | 1071 | } |
| 1072 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1073 | public Timer(Clocks clocks, int type, TimeBase timeBase) { |
| 1074 | mClocks = clocks; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1075 | mType = type; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1076 | mTimeBase = timeBase; |
| 1077 | timeBase.add(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1078 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1079 | |
| 1080 | protected abstract long computeRunTimeLocked(long curBatteryRealtime); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1081 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1082 | protected abstract int computeCurrentCountLocked(); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1083 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1084 | /** |
| 1085 | * Clear state of this timer. Returns true if the timer is inactive |
| 1086 | * so can be completely dropped. |
| 1087 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1088 | public boolean reset(boolean detachIfReset) { |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 1089 | mTotalTime = mLoadedTime = mLastTime = mTimeBeforeMark = 0; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1090 | mCount = mLoadedCount = mLastCount = 0; |
| 1091 | if (detachIfReset) { |
| 1092 | detach(); |
| 1093 | } |
| 1094 | return true; |
| 1095 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1096 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1097 | public void detach() { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1098 | mTimeBase.remove(this); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1099 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1100 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1101 | public void writeToParcel(Parcel out, long elapsedRealtimeUs) { |
Dianne Hackborn | 2932513 | 2014-05-21 15:01:03 -0700 | [diff] [blame] | 1102 | if (DEBUG) Log.i(TAG, "**** WRITING TIMER #" + mType + ": mTotalTime=" |
| 1103 | + computeRunTimeLocked(mTimeBase.getRealtime(elapsedRealtimeUs))); |
Adam Lesinski | 98f0d46 | 2016-04-19 16:46:20 -0700 | [diff] [blame] | 1104 | out.writeInt(computeCurrentCountLocked()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1105 | out.writeInt(mLoadedCount); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1106 | out.writeInt(mUnpluggedCount); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1107 | out.writeLong(computeRunTimeLocked(mTimeBase.getRealtime(elapsedRealtimeUs))); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1108 | out.writeLong(mLoadedTime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1109 | out.writeLong(mUnpluggedTime); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 1110 | out.writeLong(mTimeBeforeMark); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1111 | } |
| 1112 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 1113 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1114 | public void onTimeStarted(long elapsedRealtime, long timeBaseUptime, long baseRealtime) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1115 | if (DEBUG && mType < 0) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1116 | Log.v(TAG, "unplug #" + mType + ": realtime=" + baseRealtime |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1117 | + " old mUnpluggedTime=" + mUnpluggedTime |
| 1118 | + " old mUnpluggedCount=" + mUnpluggedCount); |
| 1119 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1120 | mUnpluggedTime = computeRunTimeLocked(baseRealtime); |
Adam Lesinski | 98f0d46 | 2016-04-19 16:46:20 -0700 | [diff] [blame] | 1121 | mUnpluggedCount = computeCurrentCountLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1122 | if (DEBUG && mType < 0) { |
| 1123 | Log.v(TAG, "unplug #" + mType |
| 1124 | + ": new mUnpluggedTime=" + mUnpluggedTime |
| 1125 | + " new mUnpluggedCount=" + mUnpluggedCount); |
| 1126 | } |
| 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 onTimeStopped(long elapsedRealtime, long baseUptime, long baseRealtime) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1131 | if (DEBUG && mType < 0) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1132 | Log.v(TAG, "plug #" + mType + ": realtime=" + baseRealtime |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1133 | + " old mTotalTime=" + mTotalTime); |
| 1134 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1135 | mTotalTime = computeRunTimeLocked(baseRealtime); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1136 | mCount = computeCurrentCountLocked(); |
| 1137 | if (DEBUG && mType < 0) { |
| 1138 | Log.v(TAG, "plug #" + mType |
| 1139 | + ": new mTotalTime=" + mTotalTime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1140 | } |
| 1141 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1142 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1143 | /** |
| 1144 | * Writes a possibly null Timer to a Parcel. |
| 1145 | * |
| 1146 | * @param out the Parcel to be written to. |
| 1147 | * @param timer a Timer, or null. |
| 1148 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1149 | 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] | 1150 | if (timer == null) { |
| 1151 | out.writeInt(0); // indicates null |
| 1152 | return; |
| 1153 | } |
| 1154 | out.writeInt(1); // indicates non-null |
| 1155 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1156 | timer.writeToParcel(out, elapsedRealtimeUs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1157 | } |
| 1158 | |
| 1159 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1160 | public long getTotalTimeLocked(long elapsedRealtimeUs, int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 1161 | long val = computeRunTimeLocked(mTimeBase.getRealtime(elapsedRealtimeUs)); |
| 1162 | if (which == STATS_SINCE_UNPLUGGED) { |
| 1163 | val -= mUnpluggedTime; |
| 1164 | } else if (which != STATS_SINCE_CHARGED) { |
| 1165 | val -= mLoadedTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1166 | } |
| 1167 | |
| 1168 | return val; |
| 1169 | } |
| 1170 | |
| 1171 | @Override |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1172 | public int getCountLocked(int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 1173 | int val = computeCurrentCountLocked(); |
| 1174 | if (which == STATS_SINCE_UNPLUGGED) { |
| 1175 | val -= mUnpluggedCount; |
| 1176 | } else if (which != STATS_SINCE_CHARGED) { |
| 1177 | val -= mLoadedCount; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1178 | } |
| 1179 | |
| 1180 | return val; |
| 1181 | } |
| 1182 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 1183 | @Override |
| 1184 | public long getTimeSinceMarkLocked(long elapsedRealtimeUs) { |
| 1185 | long val = computeRunTimeLocked(mTimeBase.getRealtime(elapsedRealtimeUs)); |
| 1186 | return val - mTimeBeforeMark; |
| 1187 | } |
| 1188 | |
| 1189 | @Override |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 1190 | public void logState(Printer pw, String prefix) { |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 1191 | pw.println(prefix + "mCount=" + mCount |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1192 | + " mLoadedCount=" + mLoadedCount + " mLastCount=" + mLastCount |
| 1193 | + " mUnpluggedCount=" + mUnpluggedCount); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 1194 | pw.println(prefix + "mTotalTime=" + mTotalTime |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1195 | + " mLoadedTime=" + mLoadedTime); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 1196 | pw.println(prefix + "mLastTime=" + mLastTime |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1197 | + " mUnpluggedTime=" + mUnpluggedTime); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1198 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1199 | |
| 1200 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1201 | public void writeSummaryFromParcelLocked(Parcel out, long elapsedRealtimeUs) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1202 | long runTime = computeRunTimeLocked(mTimeBase.getRealtime(elapsedRealtimeUs)); |
| 1203 | out.writeLong(runTime); |
Adam Lesinski | 98f0d46 | 2016-04-19 16:46:20 -0700 | [diff] [blame] | 1204 | out.writeInt(computeCurrentCountLocked()); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1205 | } |
| 1206 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1207 | public void readSummaryFromParcelLocked(Parcel in) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1208 | // Multiply by 1000 for backwards compatibility |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1209 | mTotalTime = mLoadedTime = in.readLong(); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 1210 | mLastTime = 0; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1211 | mUnpluggedTime = mTotalTime; |
| 1212 | mCount = mLoadedCount = in.readInt(); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 1213 | mLastCount = 0; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1214 | mUnpluggedCount = mCount; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 1215 | |
| 1216 | // When reading the summary, we set the mark to be the latest information. |
| 1217 | mTimeBeforeMark = mTotalTime; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1218 | } |
| 1219 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1220 | |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 1221 | /** |
| 1222 | * A counter meant to accept monotonically increasing values to its {@link #update(long, int)} |
| 1223 | * method. The state of the timer according to its {@link TimeBase} will determine how much |
| 1224 | * of the value is recorded. |
| 1225 | * |
| 1226 | * If the value being recorded resets, {@link #endSample()} can be called in order to |
| 1227 | * account for the change. If the value passed in to {@link #update(long, int)} decreased |
| 1228 | * between calls, the {@link #endSample()} is automatically called and the new value is |
| 1229 | * expected to increase monotonically from that point on. |
| 1230 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1231 | public static class SamplingTimer extends Timer { |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1232 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1233 | /** |
| 1234 | * The most recent reported count from /proc/wakelocks. |
| 1235 | */ |
| 1236 | int mCurrentReportedCount; |
| 1237 | |
| 1238 | /** |
| 1239 | * The reported count from /proc/wakelocks when unplug() was last |
| 1240 | * called. |
| 1241 | */ |
| 1242 | int mUnpluggedReportedCount; |
| 1243 | |
| 1244 | /** |
| 1245 | * The most recent reported total_time from /proc/wakelocks. |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1246 | */ |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1247 | long mCurrentReportedTotalTime; |
| 1248 | |
| 1249 | |
| 1250 | /** |
| 1251 | * The reported total_time from /proc/wakelocks when unplug() was last |
| 1252 | * called. |
| 1253 | */ |
| 1254 | long mUnpluggedReportedTotalTime; |
| 1255 | |
| 1256 | /** |
| 1257 | * Whether we are currently in a discharge cycle. |
| 1258 | */ |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1259 | boolean mTimeBaseRunning; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1260 | |
| 1261 | /** |
| 1262 | * Whether we are currently recording reported values. |
| 1263 | */ |
| 1264 | boolean mTrackingReportedValues; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1265 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1266 | /* |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1267 | * A sequence counter, incremented once for each update of the stats. |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1268 | */ |
| 1269 | int mUpdateVersion; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1270 | |
Adam Lesinski | 98f0d46 | 2016-04-19 16:46:20 -0700 | [diff] [blame] | 1271 | @VisibleForTesting |
| 1272 | public SamplingTimer(Clocks clocks, TimeBase timeBase, Parcel in) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1273 | super(clocks, 0, timeBase, in); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1274 | mCurrentReportedCount = in.readInt(); |
| 1275 | mUnpluggedReportedCount = in.readInt(); |
| 1276 | mCurrentReportedTotalTime = in.readLong(); |
| 1277 | mUnpluggedReportedTotalTime = in.readLong(); |
| 1278 | mTrackingReportedValues = in.readInt() == 1; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1279 | mTimeBaseRunning = timeBase.isRunning(); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1280 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1281 | |
Adam Lesinski | 98f0d46 | 2016-04-19 16:46:20 -0700 | [diff] [blame] | 1282 | @VisibleForTesting |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 1283 | public SamplingTimer(Clocks clocks, TimeBase timeBase) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1284 | super(clocks, 0, timeBase); |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 1285 | mTrackingReportedValues = false; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1286 | mTimeBaseRunning = timeBase.isRunning(); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1287 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1288 | |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 1289 | /** |
| 1290 | * Ends the current sample, allowing subsequent values to {@link #update(long, int)} to |
| 1291 | * be less than the values used for a previous invocation. |
| 1292 | */ |
| 1293 | public void endSample() { |
| 1294 | mTotalTime = computeRunTimeLocked(0 /* unused by us */); |
| 1295 | mCount = computeCurrentCountLocked(); |
| 1296 | mUnpluggedReportedTotalTime = mCurrentReportedTotalTime = 0; |
| 1297 | mUnpluggedReportedCount = mCurrentReportedCount = 0; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1298 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1299 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1300 | public void setUpdateVersion(int version) { |
| 1301 | mUpdateVersion = version; |
| 1302 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1303 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1304 | public int getUpdateVersion() { |
| 1305 | return mUpdateVersion; |
| 1306 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1307 | |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 1308 | /** |
| 1309 | * Updates the current recorded values. These are meant to be monotonically increasing |
| 1310 | * and cumulative. If you are dealing with deltas, use {@link #add(long, int)}. |
| 1311 | * |
| 1312 | * If the values being recorded have been reset, the monotonically increasing requirement |
| 1313 | * will be broken. In this case, {@link #endSample()} is automatically called and |
| 1314 | * the total value of totalTime and count are recorded, starting a new monotonically |
| 1315 | * increasing sample. |
| 1316 | * |
| 1317 | * @param totalTime total time of sample in microseconds. |
| 1318 | * @param count total number of times the event being sampled occurred. |
| 1319 | */ |
| 1320 | public void update(long totalTime, int count) { |
| 1321 | if (mTimeBaseRunning && !mTrackingReportedValues) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1322 | // Updating the reported value for the first time. |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 1323 | mUnpluggedReportedTotalTime = totalTime; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1324 | mUnpluggedReportedCount = count; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1325 | } |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 1326 | |
| 1327 | mTrackingReportedValues = true; |
| 1328 | |
| 1329 | if (totalTime < mCurrentReportedTotalTime || count < mCurrentReportedCount) { |
| 1330 | endSample(); |
| 1331 | } |
| 1332 | |
| 1333 | mCurrentReportedTotalTime = totalTime; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1334 | mCurrentReportedCount = count; |
| 1335 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1336 | |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 1337 | /** |
| 1338 | * Adds deltaTime and deltaCount to the current sample. |
| 1339 | * |
| 1340 | * @param deltaTime additional time recorded since the last sampled event, in microseconds. |
| 1341 | * @param deltaCount additional number of times the event being sampled occurred. |
| 1342 | */ |
| 1343 | public void add(long deltaTime, int deltaCount) { |
| 1344 | update(mCurrentReportedTotalTime + deltaTime, mCurrentReportedCount + deltaCount); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 1345 | } |
| 1346 | |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 1347 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1348 | public void onTimeStarted(long elapsedRealtime, long baseUptime, long baseRealtime) { |
| 1349 | super.onTimeStarted(elapsedRealtime, baseUptime, baseRealtime); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1350 | if (mTrackingReportedValues) { |
| 1351 | mUnpluggedReportedTotalTime = mCurrentReportedTotalTime; |
| 1352 | mUnpluggedReportedCount = mCurrentReportedCount; |
| 1353 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1354 | mTimeBaseRunning = true; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1355 | } |
| 1356 | |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 1357 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1358 | public void onTimeStopped(long elapsedRealtime, long baseUptime, long baseRealtime) { |
| 1359 | super.onTimeStopped(elapsedRealtime, baseUptime, baseRealtime); |
| 1360 | mTimeBaseRunning = false; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1361 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1362 | |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 1363 | @Override |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1364 | public void logState(Printer pw, String prefix) { |
| 1365 | super.logState(pw, prefix); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1366 | pw.println(prefix + "mCurrentReportedCount=" + mCurrentReportedCount |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1367 | + " mUnpluggedReportedCount=" + mUnpluggedReportedCount |
| 1368 | + " mCurrentReportedTotalTime=" + mCurrentReportedTotalTime |
| 1369 | + " mUnpluggedReportedTotalTime=" + mUnpluggedReportedTotalTime); |
| 1370 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1371 | |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 1372 | @Override |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1373 | protected long computeRunTimeLocked(long curBatteryRealtime) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1374 | return mTotalTime + (mTimeBaseRunning && mTrackingReportedValues |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1375 | ? mCurrentReportedTotalTime - mUnpluggedReportedTotalTime : 0); |
| 1376 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1377 | |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 1378 | @Override |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1379 | protected int computeCurrentCountLocked() { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1380 | return mCount + (mTimeBaseRunning && mTrackingReportedValues |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1381 | ? mCurrentReportedCount - mUnpluggedReportedCount : 0); |
| 1382 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1383 | |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 1384 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1385 | public void writeToParcel(Parcel out, long elapsedRealtimeUs) { |
| 1386 | super.writeToParcel(out, elapsedRealtimeUs); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1387 | out.writeInt(mCurrentReportedCount); |
| 1388 | out.writeInt(mUnpluggedReportedCount); |
| 1389 | out.writeLong(mCurrentReportedTotalTime); |
| 1390 | out.writeLong(mUnpluggedReportedTotalTime); |
| 1391 | out.writeInt(mTrackingReportedValues ? 1 : 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 |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1395 | public boolean reset(boolean detachIfReset) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1396 | super.reset(detachIfReset); |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 1397 | mTrackingReportedValues = false; |
| 1398 | mUnpluggedReportedTotalTime = 0; |
| 1399 | mUnpluggedReportedCount = 0; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1400 | return true; |
| 1401 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1402 | |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 1403 | @Override |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1404 | public void writeSummaryFromParcelLocked(Parcel out, long batteryRealtime) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1405 | super.writeSummaryFromParcelLocked(out, batteryRealtime); |
| 1406 | out.writeLong(mCurrentReportedTotalTime); |
| 1407 | out.writeInt(mCurrentReportedCount); |
| 1408 | out.writeInt(mTrackingReportedValues ? 1 : 0); |
| 1409 | } |
| 1410 | |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 1411 | @Override |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1412 | public void readSummaryFromParcelLocked(Parcel in) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1413 | super.readSummaryFromParcelLocked(in); |
| 1414 | mUnpluggedReportedTotalTime = mCurrentReportedTotalTime = in.readLong(); |
| 1415 | mUnpluggedReportedCount = mCurrentReportedCount = in.readInt(); |
| 1416 | mTrackingReportedValues = in.readInt() == 1; |
| 1417 | } |
| 1418 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1419 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1420 | /** |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1421 | * A timer that increments in batches. It does not run for durations, but just jumps |
| 1422 | * for a pre-determined amount. |
| 1423 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1424 | public static class BatchTimer extends Timer { |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1425 | final Uid mUid; |
| 1426 | |
| 1427 | /** |
| 1428 | * The last time at which we updated the timer. This is in elapsed realtime microseconds. |
| 1429 | */ |
| 1430 | long mLastAddedTime; |
| 1431 | |
| 1432 | /** |
| 1433 | * The last duration that we added to the timer. This is in microseconds. |
| 1434 | */ |
| 1435 | long mLastAddedDuration; |
| 1436 | |
| 1437 | /** |
| 1438 | * Whether we are currently in a discharge cycle. |
| 1439 | */ |
| 1440 | boolean mInDischarge; |
| 1441 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1442 | BatchTimer(Clocks clocks, Uid uid, int type, TimeBase timeBase, Parcel in) { |
| 1443 | super(clocks, type, timeBase, in); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1444 | mUid = uid; |
| 1445 | mLastAddedTime = in.readLong(); |
| 1446 | mLastAddedDuration = in.readLong(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1447 | mInDischarge = timeBase.isRunning(); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1448 | } |
| 1449 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1450 | BatchTimer(Clocks clocks, Uid uid, int type, TimeBase timeBase) { |
| 1451 | super(clocks, type, timeBase); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1452 | mUid = uid; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1453 | mInDischarge = timeBase.isRunning(); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1454 | } |
| 1455 | |
| 1456 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1457 | public void writeToParcel(Parcel out, long elapsedRealtimeUs) { |
| 1458 | super.writeToParcel(out, elapsedRealtimeUs); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1459 | out.writeLong(mLastAddedTime); |
| 1460 | out.writeLong(mLastAddedDuration); |
| 1461 | } |
| 1462 | |
| 1463 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1464 | public void onTimeStopped(long elapsedRealtime, long baseUptime, long baseRealtime) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1465 | recomputeLastDuration(mClocks.elapsedRealtime() * 1000, false); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1466 | mInDischarge = false; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1467 | super.onTimeStopped(elapsedRealtime, baseUptime, baseRealtime); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1468 | } |
| 1469 | |
| 1470 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1471 | public void onTimeStarted(long elapsedRealtime, long baseUptime, long baseRealtime) { |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1472 | recomputeLastDuration(elapsedRealtime, false); |
| 1473 | mInDischarge = true; |
| 1474 | // If we are still within the last added duration, then re-added whatever remains. |
| 1475 | if (mLastAddedTime == elapsedRealtime) { |
| 1476 | mTotalTime += mLastAddedDuration; |
| 1477 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1478 | super.onTimeStarted(elapsedRealtime, baseUptime, baseRealtime); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1479 | } |
| 1480 | |
| 1481 | @Override |
| 1482 | public void logState(Printer pw, String prefix) { |
| 1483 | super.logState(pw, prefix); |
| 1484 | pw.println(prefix + "mLastAddedTime=" + mLastAddedTime |
| 1485 | + " mLastAddedDuration=" + mLastAddedDuration); |
| 1486 | } |
| 1487 | |
| 1488 | private long computeOverage(long curTime) { |
| 1489 | if (mLastAddedTime > 0) { |
| 1490 | return mLastTime + mLastAddedDuration - curTime; |
| 1491 | } |
| 1492 | return 0; |
| 1493 | } |
| 1494 | |
| 1495 | private void recomputeLastDuration(long curTime, boolean abort) { |
| 1496 | final long overage = computeOverage(curTime); |
| 1497 | if (overage > 0) { |
| 1498 | // Aborting before the duration ran out -- roll back the remaining |
| 1499 | // duration. Only do this if currently discharging; otherwise we didn't |
| 1500 | // actually add the time. |
| 1501 | if (mInDischarge) { |
| 1502 | mTotalTime -= overage; |
| 1503 | } |
| 1504 | if (abort) { |
| 1505 | mLastAddedTime = 0; |
| 1506 | } else { |
| 1507 | mLastAddedTime = curTime; |
| 1508 | mLastAddedDuration -= overage; |
| 1509 | } |
| 1510 | } |
| 1511 | } |
| 1512 | |
| 1513 | public void addDuration(BatteryStatsImpl stats, long durationMillis) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1514 | final long now = mClocks.elapsedRealtime() * 1000; |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1515 | recomputeLastDuration(now, true); |
| 1516 | mLastAddedTime = now; |
| 1517 | mLastAddedDuration = durationMillis * 1000; |
| 1518 | if (mInDischarge) { |
| 1519 | mTotalTime += mLastAddedDuration; |
| 1520 | mCount++; |
| 1521 | } |
| 1522 | } |
| 1523 | |
| 1524 | public void abortLastDuration(BatteryStatsImpl stats) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1525 | final long now = mClocks.elapsedRealtime() * 1000; |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1526 | recomputeLastDuration(now, true); |
| 1527 | } |
| 1528 | |
| 1529 | @Override |
| 1530 | protected int computeCurrentCountLocked() { |
| 1531 | return mCount; |
| 1532 | } |
| 1533 | |
| 1534 | @Override |
| 1535 | protected long computeRunTimeLocked(long curBatteryRealtime) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1536 | final long overage = computeOverage(mClocks.elapsedRealtime() * 1000); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1537 | if (overage > 0) { |
| 1538 | return mTotalTime = overage; |
| 1539 | } |
| 1540 | return mTotalTime; |
| 1541 | } |
| 1542 | |
| 1543 | @Override |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1544 | public boolean reset(boolean detachIfReset) { |
| 1545 | final long now = mClocks.elapsedRealtime() * 1000; |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1546 | recomputeLastDuration(now, true); |
| 1547 | boolean stillActive = mLastAddedTime == now; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1548 | super.reset(!stillActive && detachIfReset); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1549 | return !stillActive; |
| 1550 | } |
| 1551 | } |
| 1552 | |
| 1553 | /** |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1554 | * State for keeping track of timing information. |
| 1555 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1556 | public static class StopwatchTimer extends Timer { |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 1557 | final Uid mUid; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1558 | final ArrayList<StopwatchTimer> mTimerPool; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 1559 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1560 | int mNesting; |
| 1561 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1562 | /** |
| 1563 | * The last time at which we updated the timer. If mNesting is > 0, |
| 1564 | * subtract this from the current battery time to find the amount of |
| 1565 | * time we have been running since we last computed an update. |
| 1566 | */ |
| 1567 | long mUpdateTime; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1568 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1569 | /** |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 1570 | * 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] | 1571 | * was actually held for an interesting duration. |
| 1572 | */ |
| 1573 | long mAcquireTime; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1574 | |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 1575 | long mTimeout; |
| 1576 | |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 1577 | /** |
| 1578 | * For partial wake locks, keep track of whether we are in the list |
| 1579 | * to consume CPU cycles. |
| 1580 | */ |
| 1581 | boolean mInList; |
| 1582 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1583 | public StopwatchTimer(Clocks clocks, Uid uid, int type, ArrayList<StopwatchTimer> timerPool, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1584 | TimeBase timeBase, Parcel in) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1585 | super(clocks, type, timeBase, in); |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 1586 | mUid = uid; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1587 | mTimerPool = timerPool; |
| 1588 | mUpdateTime = in.readLong(); |
| 1589 | } |
| 1590 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1591 | public StopwatchTimer(Clocks clocks, Uid uid, int type, ArrayList<StopwatchTimer> timerPool, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1592 | TimeBase timeBase) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1593 | super(clocks, type, timeBase); |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 1594 | mUid = uid; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1595 | mTimerPool = timerPool; |
| 1596 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1597 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1598 | public void setTimeout(long timeout) { |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 1599 | mTimeout = timeout; |
| 1600 | } |
| 1601 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1602 | public void writeToParcel(Parcel out, long elapsedRealtimeUs) { |
| 1603 | super.writeToParcel(out, elapsedRealtimeUs); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1604 | out.writeLong(mUpdateTime); |
| 1605 | } |
| 1606 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1607 | public void onTimeStopped(long elapsedRealtime, long baseUptime, long baseRealtime) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1608 | if (mNesting > 0) { |
| 1609 | if (DEBUG && mType < 0) { |
| 1610 | Log.v(TAG, "old mUpdateTime=" + mUpdateTime); |
| 1611 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1612 | super.onTimeStopped(elapsedRealtime, baseUptime, baseRealtime); |
| 1613 | mUpdateTime = baseRealtime; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1614 | if (DEBUG && mType < 0) { |
| 1615 | Log.v(TAG, "new mUpdateTime=" + mUpdateTime); |
| 1616 | } |
| 1617 | } |
| 1618 | } |
| 1619 | |
| 1620 | public void logState(Printer pw, String prefix) { |
| 1621 | super.logState(pw, prefix); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 1622 | pw.println(prefix + "mNesting=" + mNesting + " mUpdateTime=" + mUpdateTime |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1623 | + " mAcquireTime=" + mAcquireTime); |
| 1624 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1625 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1626 | public void startRunningLocked(long elapsedRealtimeMs) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1627 | if (mNesting++ == 0) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1628 | final long batteryRealtime = mTimeBase.getRealtime(elapsedRealtimeMs * 1000); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 1629 | mUpdateTime = batteryRealtime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1630 | if (mTimerPool != null) { |
| 1631 | // Accumulate time to all currently active timers before adding |
| 1632 | // this new one to the pool. |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1633 | refreshTimersLocked(batteryRealtime, mTimerPool, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1634 | // Add this timer to the active pool |
| 1635 | mTimerPool.add(this); |
| 1636 | } |
| 1637 | // Increment the count |
| 1638 | mCount++; |
| 1639 | mAcquireTime = mTotalTime; |
| 1640 | if (DEBUG && mType < 0) { |
| 1641 | Log.v(TAG, "start #" + mType + ": mUpdateTime=" + mUpdateTime |
| 1642 | + " mTotalTime=" + mTotalTime + " mCount=" + mCount |
| 1643 | + " mAcquireTime=" + mAcquireTime); |
| 1644 | } |
| 1645 | } |
| 1646 | } |
| 1647 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1648 | public boolean isRunningLocked() { |
Amith Yamasani | 32dbefd | 2009-06-19 09:21:17 -0700 | [diff] [blame] | 1649 | return mNesting > 0; |
| 1650 | } |
| 1651 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1652 | public void stopRunningLocked(long elapsedRealtimeMs) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1653 | // Ignore attempt to stop a timer that isn't running |
| 1654 | if (mNesting == 0) { |
| 1655 | return; |
| 1656 | } |
| 1657 | if (--mNesting == 0) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1658 | final long batteryRealtime = mTimeBase.getRealtime(elapsedRealtimeMs * 1000); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1659 | if (mTimerPool != null) { |
| 1660 | // Accumulate time to all active counters, scaled by the total |
| 1661 | // active in the pool, before taking this one out of the pool. |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1662 | refreshTimersLocked(batteryRealtime, mTimerPool, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1663 | // Remove this timer from the active pool |
| 1664 | mTimerPool.remove(this); |
| 1665 | } else { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1666 | mNesting = 1; |
| 1667 | mTotalTime = computeRunTimeLocked(batteryRealtime); |
| 1668 | mNesting = 0; |
| 1669 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1670 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1671 | if (DEBUG && mType < 0) { |
| 1672 | Log.v(TAG, "stop #" + mType + ": mUpdateTime=" + mUpdateTime |
| 1673 | + " mTotalTime=" + mTotalTime + " mCount=" + mCount |
| 1674 | + " mAcquireTime=" + mAcquireTime); |
| 1675 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1676 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1677 | if (mTotalTime == mAcquireTime) { |
| 1678 | // If there was no change in the time, then discard this |
| 1679 | // count. A somewhat cheezy strategy, but hey. |
| 1680 | mCount--; |
| 1681 | } |
| 1682 | } |
| 1683 | } |
| 1684 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1685 | public void stopAllRunningLocked(long elapsedRealtimeMs) { |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 1686 | if (mNesting > 0) { |
| 1687 | mNesting = 1; |
| 1688 | stopRunningLocked(elapsedRealtimeMs); |
| 1689 | } |
| 1690 | } |
| 1691 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1692 | // Update the total time for all other running Timers with the same type as this Timer |
| 1693 | // due to a change in timer count |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1694 | private static long refreshTimersLocked(long batteryRealtime, |
| 1695 | final ArrayList<StopwatchTimer> pool, StopwatchTimer self) { |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 1696 | long selfTime = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1697 | final int N = pool.size(); |
| 1698 | for (int i=N-1; i>= 0; i--) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1699 | final StopwatchTimer t = pool.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1700 | long heldTime = batteryRealtime - t.mUpdateTime; |
| 1701 | if (heldTime > 0) { |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 1702 | final long myTime = heldTime / N; |
| 1703 | if (t == self) { |
| 1704 | selfTime = myTime; |
| 1705 | } |
| 1706 | t.mTotalTime += myTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1707 | } |
| 1708 | t.mUpdateTime = batteryRealtime; |
| 1709 | } |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 1710 | return selfTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1711 | } |
| 1712 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1713 | @Override |
| 1714 | protected long computeRunTimeLocked(long curBatteryRealtime) { |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 1715 | if (mTimeout > 0 && curBatteryRealtime > mUpdateTime + mTimeout) { |
| 1716 | curBatteryRealtime = mUpdateTime + mTimeout; |
| 1717 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1718 | return mTotalTime + (mNesting > 0 |
| 1719 | ? (curBatteryRealtime - mUpdateTime) |
| 1720 | / (mTimerPool != null ? mTimerPool.size() : 1) |
| 1721 | : 0); |
| 1722 | } |
| 1723 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1724 | @Override |
| 1725 | protected int computeCurrentCountLocked() { |
| 1726 | return mCount; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1727 | } |
| 1728 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 1729 | @Override |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1730 | public boolean reset(boolean detachIfReset) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1731 | boolean canDetach = mNesting <= 0; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 1732 | super.reset(canDetach && detachIfReset); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 1733 | if (mNesting > 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1734 | mUpdateTime = mTimeBase.getRealtime(mClocks.elapsedRealtime() * 1000); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 1735 | } |
| 1736 | mAcquireTime = mTotalTime; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1737 | return canDetach; |
| 1738 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1739 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 1740 | @Override |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1741 | public void detach() { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 1742 | super.detach(); |
| 1743 | if (mTimerPool != null) { |
| 1744 | mTimerPool.remove(this); |
| 1745 | } |
| 1746 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1747 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 1748 | @Override |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 1749 | public void readSummaryFromParcelLocked(Parcel in) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 1750 | super.readSummaryFromParcelLocked(in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1751 | mNesting = 0; |
| 1752 | } |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 1753 | |
| 1754 | /** |
| 1755 | * Set the mark so that we can query later for the total time the timer has |
| 1756 | * accumulated since this point. The timer can be running or not. |
| 1757 | * |
| 1758 | * @param elapsedRealtimeMs the current elapsed realtime in milliseconds. |
| 1759 | */ |
| 1760 | public void setMark(long elapsedRealtimeMs) { |
| 1761 | final long batteryRealtime = mTimeBase.getRealtime(elapsedRealtimeMs * 1000); |
| 1762 | if (mNesting > 0) { |
| 1763 | // We are running. |
| 1764 | if (mTimerPool != null) { |
| 1765 | refreshTimersLocked(batteryRealtime, mTimerPool, this); |
| 1766 | } else { |
| 1767 | mTotalTime += batteryRealtime - mUpdateTime; |
| 1768 | mUpdateTime = batteryRealtime; |
| 1769 | } |
| 1770 | } |
| 1771 | mTimeBeforeMark = mTotalTime; |
| 1772 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1773 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 1774 | |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 1775 | public abstract class OverflowArrayMap<T> { |
| 1776 | private static final String OVERFLOW_NAME = "*overflow*"; |
| 1777 | |
| 1778 | final ArrayMap<String, T> mMap = new ArrayMap<>(); |
| 1779 | T mCurOverflow; |
| 1780 | ArrayMap<String, MutableInt> mActiveOverflow; |
| 1781 | |
| 1782 | public OverflowArrayMap() { |
| 1783 | } |
| 1784 | |
| 1785 | public ArrayMap<String, T> getMap() { |
| 1786 | return mMap; |
| 1787 | } |
| 1788 | |
| 1789 | public void clear() { |
| 1790 | mMap.clear(); |
| 1791 | mCurOverflow = null; |
| 1792 | mActiveOverflow = null; |
| 1793 | } |
| 1794 | |
| 1795 | public void add(String name, T obj) { |
Joe Onorato | 388fc33 | 2016-04-12 17:06:47 -0700 | [diff] [blame] | 1796 | if (name == null) { |
| 1797 | name = ""; |
| 1798 | } |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 1799 | mMap.put(name, obj); |
| 1800 | if (OVERFLOW_NAME.equals(name)) { |
| 1801 | mCurOverflow = obj; |
| 1802 | } |
| 1803 | } |
| 1804 | |
| 1805 | public void cleanup() { |
| 1806 | if (mActiveOverflow != null) { |
| 1807 | if (mActiveOverflow.size() == 0) { |
| 1808 | mActiveOverflow = null; |
| 1809 | } |
| 1810 | } |
| 1811 | if (mActiveOverflow == null) { |
| 1812 | // There is no currently active overflow, so we should no longer have |
| 1813 | // an overflow entry. |
| 1814 | if (mMap.containsKey(OVERFLOW_NAME)) { |
| 1815 | Slog.wtf(TAG, "Cleaning up with no active overflow, but have overflow entry " |
| 1816 | + mMap.get(OVERFLOW_NAME)); |
| 1817 | mMap.remove(OVERFLOW_NAME); |
| 1818 | } |
| 1819 | mCurOverflow = null; |
| 1820 | } else { |
| 1821 | // There is currently active overflow, so we should still have an overflow entry. |
| 1822 | if (mCurOverflow == null || !mMap.containsKey(OVERFLOW_NAME)) { |
| 1823 | Slog.wtf(TAG, "Cleaning up with active overflow, but no overflow entry: cur=" |
| 1824 | + mCurOverflow + " map=" + mMap.get(OVERFLOW_NAME)); |
| 1825 | } |
| 1826 | } |
| 1827 | } |
| 1828 | |
| 1829 | public T startObject(String name) { |
Joe Onorato | 388fc33 | 2016-04-12 17:06:47 -0700 | [diff] [blame] | 1830 | if (name == null) { |
| 1831 | name = ""; |
| 1832 | } |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 1833 | T obj = mMap.get(name); |
| 1834 | if (obj != null) { |
| 1835 | return obj; |
| 1836 | } |
| 1837 | |
| 1838 | // No object exists for the given name, but do we currently have it |
| 1839 | // running as part of the overflow? |
| 1840 | if (mActiveOverflow != null) { |
| 1841 | MutableInt over = mActiveOverflow.get(name); |
| 1842 | if (over != null) { |
| 1843 | // We are already actively counting this name in the overflow object. |
| 1844 | obj = mCurOverflow; |
| 1845 | if (obj == null) { |
| 1846 | // Shouldn't be here, but we'll try to recover. |
| 1847 | Slog.wtf(TAG, "Have active overflow " + name + " but null overflow"); |
| 1848 | obj = mCurOverflow = instantiateObject(); |
| 1849 | mMap.put(OVERFLOW_NAME, obj); |
| 1850 | } |
| 1851 | over.value++; |
| 1852 | return obj; |
| 1853 | } |
| 1854 | } |
| 1855 | |
| 1856 | // No object exists for given name nor in the overflow; we need to make |
| 1857 | // a new one. |
| 1858 | final int N = mMap.size(); |
| 1859 | if (N >= MAX_WAKELOCKS_PER_UID) { |
| 1860 | // Went over the limit on number of objects to track; this one goes |
| 1861 | // in to the overflow. |
| 1862 | obj = mCurOverflow; |
| 1863 | if (obj == null) { |
| 1864 | // Need to start overflow now... |
| 1865 | obj = mCurOverflow = instantiateObject(); |
| 1866 | mMap.put(OVERFLOW_NAME, obj); |
| 1867 | } |
| 1868 | if (mActiveOverflow == null) { |
| 1869 | mActiveOverflow = new ArrayMap<>(); |
| 1870 | } |
| 1871 | mActiveOverflow.put(name, new MutableInt(1)); |
| 1872 | return obj; |
| 1873 | } |
| 1874 | |
| 1875 | // Normal case where we just need to make a new object. |
| 1876 | obj = instantiateObject(); |
| 1877 | mMap.put(name, obj); |
| 1878 | return obj; |
| 1879 | } |
| 1880 | |
| 1881 | public T stopObject(String name) { |
Joe Onorato | 388fc33 | 2016-04-12 17:06:47 -0700 | [diff] [blame] | 1882 | if (name == null) { |
| 1883 | name = ""; |
| 1884 | } |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 1885 | T obj = mMap.get(name); |
| 1886 | if (obj != null) { |
| 1887 | return obj; |
| 1888 | } |
| 1889 | |
| 1890 | // No object exists for the given name, but do we currently have it |
| 1891 | // running as part of the overflow? |
| 1892 | if (mActiveOverflow != null) { |
| 1893 | MutableInt over = mActiveOverflow.get(name); |
| 1894 | if (over != null) { |
| 1895 | // We are already actively counting this name in the overflow object. |
| 1896 | obj = mCurOverflow; |
| 1897 | if (obj != null) { |
| 1898 | over.value--; |
| 1899 | if (over.value <= 0) { |
| 1900 | mActiveOverflow.remove(name); |
| 1901 | } |
| 1902 | return obj; |
| 1903 | } |
| 1904 | } |
| 1905 | } |
| 1906 | |
| 1907 | // Huh, they are stopping an active operation but we can't find one! |
| 1908 | // That's not good. |
| 1909 | Slog.wtf(TAG, "Unable to find object for " + name + " mapsize=" |
| 1910 | + mMap.size() + " activeoverflow=" + mActiveOverflow |
| 1911 | + " curoverflow=" + mCurOverflow); |
| 1912 | return null; |
| 1913 | } |
| 1914 | |
| 1915 | public abstract T instantiateObject(); |
| 1916 | } |
| 1917 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 1918 | public static class ControllerActivityCounterImpl extends ControllerActivityCounter |
| 1919 | implements Parcelable { |
| 1920 | private final LongSamplingCounter mIdleTimeMillis; |
| 1921 | private final LongSamplingCounter mRxTimeMillis; |
| 1922 | private final LongSamplingCounter[] mTxTimeMillis; |
| 1923 | private final LongSamplingCounter mPowerDrainMaMs; |
| 1924 | |
| 1925 | public ControllerActivityCounterImpl(TimeBase timeBase, int numTxStates) { |
| 1926 | mIdleTimeMillis = new LongSamplingCounter(timeBase); |
| 1927 | mRxTimeMillis = new LongSamplingCounter(timeBase); |
| 1928 | mTxTimeMillis = new LongSamplingCounter[numTxStates]; |
| 1929 | for (int i = 0; i < numTxStates; i++) { |
| 1930 | mTxTimeMillis[i] = new LongSamplingCounter(timeBase); |
| 1931 | } |
| 1932 | mPowerDrainMaMs = new LongSamplingCounter(timeBase); |
| 1933 | } |
| 1934 | |
| 1935 | public ControllerActivityCounterImpl(TimeBase timeBase, int numTxStates, Parcel in) { |
| 1936 | mIdleTimeMillis = new LongSamplingCounter(timeBase, in); |
| 1937 | mRxTimeMillis = new LongSamplingCounter(timeBase, in); |
| 1938 | final int recordedTxStates = in.readInt(); |
| 1939 | if (recordedTxStates != numTxStates) { |
| 1940 | throw new ParcelFormatException("inconsistent tx state lengths"); |
| 1941 | } |
| 1942 | |
| 1943 | mTxTimeMillis = new LongSamplingCounter[numTxStates]; |
| 1944 | for (int i = 0; i < numTxStates; i++) { |
| 1945 | mTxTimeMillis[i] = new LongSamplingCounter(timeBase, in); |
| 1946 | } |
| 1947 | mPowerDrainMaMs = new LongSamplingCounter(timeBase, in); |
| 1948 | } |
| 1949 | |
| 1950 | public void readSummaryFromParcel(Parcel in) { |
| 1951 | mIdleTimeMillis.readSummaryFromParcelLocked(in); |
| 1952 | mRxTimeMillis.readSummaryFromParcelLocked(in); |
| 1953 | final int recordedTxStates = in.readInt(); |
| 1954 | if (recordedTxStates != mTxTimeMillis.length) { |
| 1955 | throw new ParcelFormatException("inconsistent tx state lengths"); |
| 1956 | } |
| 1957 | for (LongSamplingCounter counter : mTxTimeMillis) { |
| 1958 | counter.readSummaryFromParcelLocked(in); |
| 1959 | } |
| 1960 | mPowerDrainMaMs.readSummaryFromParcelLocked(in); |
| 1961 | } |
| 1962 | |
| 1963 | @Override |
| 1964 | public int describeContents() { |
| 1965 | return 0; |
| 1966 | } |
| 1967 | |
| 1968 | public void writeSummaryToParcel(Parcel dest) { |
| 1969 | mIdleTimeMillis.writeSummaryFromParcelLocked(dest); |
| 1970 | mRxTimeMillis.writeSummaryFromParcelLocked(dest); |
| 1971 | dest.writeInt(mTxTimeMillis.length); |
| 1972 | for (LongSamplingCounter counter : mTxTimeMillis) { |
| 1973 | counter.writeSummaryFromParcelLocked(dest); |
| 1974 | } |
| 1975 | mPowerDrainMaMs.writeSummaryFromParcelLocked(dest); |
| 1976 | } |
| 1977 | |
| 1978 | @Override |
| 1979 | public void writeToParcel(Parcel dest, int flags) { |
| 1980 | mIdleTimeMillis.writeToParcel(dest); |
| 1981 | mRxTimeMillis.writeToParcel(dest); |
| 1982 | dest.writeInt(mTxTimeMillis.length); |
| 1983 | for (LongSamplingCounter counter : mTxTimeMillis) { |
| 1984 | counter.writeToParcel(dest); |
| 1985 | } |
| 1986 | mPowerDrainMaMs.writeToParcel(dest); |
| 1987 | } |
| 1988 | |
| 1989 | public void reset(boolean detachIfReset) { |
| 1990 | mIdleTimeMillis.reset(detachIfReset); |
| 1991 | mRxTimeMillis.reset(detachIfReset); |
| 1992 | for (LongSamplingCounter counter : mTxTimeMillis) { |
| 1993 | counter.reset(detachIfReset); |
| 1994 | } |
| 1995 | mPowerDrainMaMs.reset(detachIfReset); |
| 1996 | } |
| 1997 | |
| 1998 | public void detach() { |
| 1999 | mIdleTimeMillis.detach(); |
| 2000 | mRxTimeMillis.detach(); |
| 2001 | for (LongSamplingCounter counter : mTxTimeMillis) { |
| 2002 | counter.detach(); |
| 2003 | } |
| 2004 | mPowerDrainMaMs.detach(); |
| 2005 | } |
| 2006 | |
| 2007 | /** |
| 2008 | * @return a LongSamplingCounter, measuring time spent in the idle state in |
| 2009 | * milliseconds. |
| 2010 | */ |
| 2011 | @Override |
| 2012 | public LongSamplingCounter getIdleTimeCounter() { |
Roshan Pius | 8164330 | 2016-03-14 16:45:55 -0700 | [diff] [blame] | 2013 | return mIdleTimeMillis; |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 2014 | } |
| 2015 | |
| 2016 | /** |
| 2017 | * @return a LongSamplingCounter, measuring time spent in the receive state in |
| 2018 | * milliseconds. |
| 2019 | */ |
| 2020 | @Override |
| 2021 | public LongSamplingCounter getRxTimeCounter() { |
| 2022 | return mRxTimeMillis; |
| 2023 | } |
| 2024 | |
| 2025 | /** |
| 2026 | * @return a LongSamplingCounter[], measuring time spent in various transmit states in |
| 2027 | * milliseconds. |
| 2028 | */ |
| 2029 | @Override |
| 2030 | public LongSamplingCounter[] getTxTimeCounters() { |
| 2031 | return mTxTimeMillis; |
| 2032 | } |
| 2033 | |
| 2034 | /** |
| 2035 | * @return a LongSamplingCounter, measuring power use in milli-ampere milliseconds (mAmS). |
| 2036 | */ |
| 2037 | @Override |
| 2038 | public LongSamplingCounter getPowerCounter() { |
| 2039 | return mPowerDrainMaMs; |
| 2040 | } |
| 2041 | } |
| 2042 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2043 | /* |
| 2044 | * Get the wakeup reason counter, and create a new one if one |
| 2045 | * doesn't already exist. |
| 2046 | */ |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 2047 | public SamplingTimer getWakeupReasonTimerLocked(String name) { |
| 2048 | SamplingTimer timer = mWakeupReasonStats.get(name); |
| 2049 | if (timer == null) { |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 2050 | timer = new SamplingTimer(mClocks, mOnBatteryTimeBase); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 2051 | mWakeupReasonStats.put(name, timer); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2052 | } |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 2053 | return timer; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2054 | } |
| 2055 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2056 | /* |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2057 | * 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] | 2058 | * doesn't already exist. |
| 2059 | */ |
| 2060 | public SamplingTimer getKernelWakelockTimerLocked(String name) { |
| 2061 | SamplingTimer kwlt = mKernelWakelockStats.get(name); |
| 2062 | if (kwlt == null) { |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 2063 | kwlt = new SamplingTimer(mClocks, mOnBatteryScreenOffTimeBase); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 2064 | mKernelWakelockStats.put(name, kwlt); |
| 2065 | } |
| 2066 | return kwlt; |
| 2067 | } |
Amith Yamasani | 3718aaa | 2009-06-09 06:32:35 -0700 | [diff] [blame] | 2068 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2069 | private int writeHistoryTag(HistoryTag tag) { |
| 2070 | Integer idxObj = mHistoryTagPool.get(tag); |
| 2071 | int idx; |
| 2072 | if (idxObj != null) { |
| 2073 | idx = idxObj; |
| 2074 | } else { |
| 2075 | idx = mNextHistoryTagIdx; |
| 2076 | HistoryTag key = new HistoryTag(); |
| 2077 | key.setTo(tag); |
| 2078 | tag.poolIdx = idx; |
| 2079 | mHistoryTagPool.put(key, idx); |
| 2080 | mNextHistoryTagIdx++; |
| 2081 | mNumHistoryTagChars += key.string.length() + 1; |
| 2082 | } |
| 2083 | return idx; |
| 2084 | } |
| 2085 | |
| 2086 | private void readHistoryTag(int index, HistoryTag tag) { |
| 2087 | tag.string = mReadHistoryStrings[index]; |
| 2088 | tag.uid = mReadHistoryUids[index]; |
| 2089 | tag.poolIdx = index; |
| 2090 | } |
| 2091 | |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 2092 | /* |
| 2093 | The history delta format uses flags to denote further data in subsequent ints in the parcel. |
| 2094 | |
| 2095 | There is always the first token, which may contain the delta time, or an indicator of |
| 2096 | the length of the time (int or long) following this token. |
| 2097 | |
| 2098 | First token: always present, |
| 2099 | 31 23 15 7 0 |
| 2100 | â–ˆ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â–ˆ |
| 2101 | |
| 2102 | T: the delta time if it is <= 0x7fffd. Otherwise 0x7fffe indicates an int immediately |
| 2103 | follows containing the time, and 0x7ffff indicates a long immediately follows with the |
| 2104 | delta time. |
| 2105 | A: battery level changed and an int follows with battery data. |
| 2106 | B: state changed and an int follows with state change data. |
| 2107 | C: state2 has changed and an int follows with state2 change data. |
| 2108 | D: wakelock/wakereason has changed and an wakelock/wakereason struct follows. |
| 2109 | E: event data has changed and an event struct follows. |
| 2110 | F: battery charge in coulombs has changed and an int with the charge follows. |
| 2111 | G: state flag denoting that the mobile radio was active. |
| 2112 | H: state flag denoting that the wifi radio was active. |
| 2113 | I: state flag denoting that a wifi scan occurred. |
| 2114 | J: state flag denoting that a wifi full lock was held. |
| 2115 | K: state flag denoting that the gps was on. |
| 2116 | L: state flag denoting that a wakelock was held. |
| 2117 | M: state flag denoting that the cpu was running. |
| 2118 | |
| 2119 | Time int/long: if T in the first token is 0x7ffff or 0x7fffe, then an int or long follows |
| 2120 | with the time delta. |
| 2121 | |
| 2122 | Battery level int: if A in the first token is set, |
| 2123 | 31 23 15 7 0 |
| 2124 | â–ˆ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â–ˆ |
| 2125 | |
| 2126 | D: indicates that extra history details follow. |
| 2127 | V: the battery voltage. |
| 2128 | T: the battery temperature. |
| 2129 | L: the battery level (out of 100). |
| 2130 | |
| 2131 | State change int: if B in the first token is set, |
| 2132 | 31 23 15 7 0 |
| 2133 | â–ˆS|S|S|H|H|H|P|Pâ–ˆF|E|D|C|B| | |Aâ–ˆ | | | | | | | â–ˆ | | | | | | | â–ˆ |
| 2134 | |
| 2135 | A: wifi multicast was on. |
| 2136 | B: battery was plugged in. |
| 2137 | C: screen was on. |
| 2138 | D: phone was scanning for signal. |
| 2139 | E: audio was on. |
| 2140 | F: a sensor was active. |
| 2141 | |
| 2142 | State2 change int: if C in the first token is set, |
| 2143 | 31 23 15 7 0 |
| 2144 | â–ˆM|L|K|J|I|H|H|Gâ–ˆF|E|D|C| | | | â–ˆ | | | | | | | â–ˆ |B|B|B|A|A|A|Aâ–ˆ |
| 2145 | |
| 2146 | A: 4 bits indicating the wifi supplicant state: {@link BatteryStats#WIFI_SUPPL_STATE_NAMES}. |
| 2147 | B: 3 bits indicating the wifi signal strength: 0, 1, 2, 3, 4. |
| 2148 | C: a bluetooth scan was active. |
| 2149 | D: the camera was active. |
| 2150 | E: bluetooth was on. |
| 2151 | F: a phone call was active. |
| 2152 | G: the device was charging. |
| 2153 | H: 2 bits indicating the device-idle (doze) state: off, light, full |
| 2154 | I: the flashlight was on. |
| 2155 | J: wifi was on. |
| 2156 | K: wifi was running. |
| 2157 | L: video was playing. |
| 2158 | M: power save mode was on. |
| 2159 | |
| 2160 | Wakelock/wakereason struct: if D in the first token is set, |
| 2161 | TODO(adamlesinski): describe wakelock/wakereason struct. |
| 2162 | |
| 2163 | Event struct: if E in the first token is set, |
| 2164 | TODO(adamlesinski): describe the event struct. |
| 2165 | |
| 2166 | History step details struct: if D in the battery level int is set, |
| 2167 | TODO(adamlesinski): describe the history step details struct. |
| 2168 | |
| 2169 | Battery charge int: if F in the first token is set, an int representing the battery charge |
| 2170 | in coulombs follows. |
| 2171 | */ |
| 2172 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2173 | // Part of initial delta int that specifies the time delta. |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 2174 | static final int DELTA_TIME_MASK = 0x7ffff; |
| 2175 | static final int DELTA_TIME_LONG = 0x7ffff; // The delta is a following long |
| 2176 | static final int DELTA_TIME_INT = 0x7fffe; // The delta is a following int |
| 2177 | 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] | 2178 | // Flag in delta int: a new battery level int follows. |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 2179 | static final int DELTA_BATTERY_LEVEL_FLAG = 0x00080000; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2180 | // 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] | 2181 | static final int DELTA_STATE_FLAG = 0x00100000; |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 2182 | // Flag in delta int: a new full state2 int follows. |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 2183 | static final int DELTA_STATE2_FLAG = 0x00200000; |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 2184 | // Flag in delta int: contains a wakelock or wakeReason tag. |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 2185 | static final int DELTA_WAKELOCK_FLAG = 0x00400000; |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2186 | // Flag in delta int: contains an event description. |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 2187 | static final int DELTA_EVENT_FLAG = 0x00800000; |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame^] | 2188 | // Flag in delta int: contains the battery charge count in uAh. |
| 2189 | static final int DELTA_BATTERY_CHARGE_FLAG = 0x01000000; |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2190 | // These upper bits are the frequently changing state bits. |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 2191 | static final int DELTA_STATE_MASK = 0xfe000000; |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 2192 | |
| 2193 | // These are the pieces of battery state that are packed in to the upper bits of |
| 2194 | // 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] | 2195 | // in STATE_BATTERY_MASK. |
| 2196 | static final int STATE_BATTERY_MASK = 0xff000000; |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 2197 | static final int STATE_BATTERY_STATUS_MASK = 0x00000007; |
| 2198 | static final int STATE_BATTERY_STATUS_SHIFT = 29; |
| 2199 | static final int STATE_BATTERY_HEALTH_MASK = 0x00000007; |
| 2200 | static final int STATE_BATTERY_HEALTH_SHIFT = 26; |
| 2201 | static final int STATE_BATTERY_PLUG_MASK = 0x00000003; |
| 2202 | static final int STATE_BATTERY_PLUG_SHIFT = 24; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2203 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 2204 | // We use the low bit of the battery state int to indicate that we have full details |
| 2205 | // from a battery level change. |
| 2206 | static final int BATTERY_DELTA_LEVEL_FLAG = 0x00000001; |
| 2207 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2208 | public void writeHistoryDelta(Parcel dest, HistoryItem cur, HistoryItem last) { |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2209 | if (last == null || cur.cmd != HistoryItem.CMD_UPDATE) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2210 | dest.writeInt(DELTA_TIME_ABS); |
| 2211 | cur.writeToParcel(dest, 0); |
| 2212 | return; |
| 2213 | } |
| 2214 | |
| 2215 | final long deltaTime = cur.time - last.time; |
| 2216 | final int lastBatteryLevelInt = buildBatteryLevelInt(last); |
| 2217 | final int lastStateInt = buildStateInt(last); |
| 2218 | |
| 2219 | int deltaTimeToken; |
| 2220 | if (deltaTime < 0 || deltaTime > Integer.MAX_VALUE) { |
| 2221 | deltaTimeToken = DELTA_TIME_LONG; |
| 2222 | } else if (deltaTime >= DELTA_TIME_ABS) { |
| 2223 | deltaTimeToken = DELTA_TIME_INT; |
| 2224 | } else { |
| 2225 | deltaTimeToken = (int)deltaTime; |
| 2226 | } |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2227 | int firstToken = deltaTimeToken | (cur.states&DELTA_STATE_MASK); |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 2228 | final int includeStepDetails = mLastHistoryStepLevel > cur.batteryLevel |
| 2229 | ? BATTERY_DELTA_LEVEL_FLAG : 0; |
| 2230 | final boolean computeStepDetails = includeStepDetails != 0 |
| 2231 | || mLastHistoryStepDetails == null; |
| 2232 | final int batteryLevelInt = buildBatteryLevelInt(cur) | includeStepDetails; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2233 | final boolean batteryLevelIntChanged = batteryLevelInt != lastBatteryLevelInt; |
| 2234 | if (batteryLevelIntChanged) { |
| 2235 | firstToken |= DELTA_BATTERY_LEVEL_FLAG; |
| 2236 | } |
| 2237 | final int stateInt = buildStateInt(cur); |
| 2238 | final boolean stateIntChanged = stateInt != lastStateInt; |
| 2239 | if (stateIntChanged) { |
| 2240 | firstToken |= DELTA_STATE_FLAG; |
| 2241 | } |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2242 | final boolean state2IntChanged = cur.states2 != last.states2; |
| 2243 | if (state2IntChanged) { |
| 2244 | firstToken |= DELTA_STATE2_FLAG; |
| 2245 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 2246 | if (cur.wakelockTag != null || cur.wakeReasonTag != null) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2247 | firstToken |= DELTA_WAKELOCK_FLAG; |
| 2248 | } |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2249 | if (cur.eventCode != HistoryItem.EVENT_NONE) { |
| 2250 | firstToken |= DELTA_EVENT_FLAG; |
| 2251 | } |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 2252 | |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame^] | 2253 | final boolean batteryChargeChanged = cur.batteryChargeUAh != last.batteryChargeUAh; |
| 2254 | if (batteryChargeChanged) { |
| 2255 | firstToken |= DELTA_BATTERY_CHARGE_FLAG; |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 2256 | } |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2257 | dest.writeInt(firstToken); |
| 2258 | if (DEBUG) Slog.i(TAG, "WRITE DELTA: firstToken=0x" + Integer.toHexString(firstToken) |
| 2259 | + " deltaTime=" + deltaTime); |
| 2260 | |
| 2261 | if (deltaTimeToken >= DELTA_TIME_INT) { |
| 2262 | if (deltaTimeToken == DELTA_TIME_INT) { |
| 2263 | if (DEBUG) Slog.i(TAG, "WRITE DELTA: int deltaTime=" + (int)deltaTime); |
| 2264 | dest.writeInt((int)deltaTime); |
| 2265 | } else { |
| 2266 | if (DEBUG) Slog.i(TAG, "WRITE DELTA: long deltaTime=" + deltaTime); |
| 2267 | dest.writeLong(deltaTime); |
| 2268 | } |
| 2269 | } |
| 2270 | if (batteryLevelIntChanged) { |
| 2271 | dest.writeInt(batteryLevelInt); |
| 2272 | if (DEBUG) Slog.i(TAG, "WRITE DELTA: batteryToken=0x" |
| 2273 | + Integer.toHexString(batteryLevelInt) |
| 2274 | + " batteryLevel=" + cur.batteryLevel |
| 2275 | + " batteryTemp=" + cur.batteryTemperature |
| 2276 | + " batteryVolt=" + (int)cur.batteryVoltage); |
| 2277 | } |
| 2278 | if (stateIntChanged) { |
| 2279 | dest.writeInt(stateInt); |
| 2280 | if (DEBUG) Slog.i(TAG, "WRITE DELTA: stateToken=0x" |
| 2281 | + Integer.toHexString(stateInt) |
| 2282 | + " batteryStatus=" + cur.batteryStatus |
| 2283 | + " batteryHealth=" + cur.batteryHealth |
| 2284 | + " batteryPlugType=" + cur.batteryPlugType |
| 2285 | + " states=0x" + Integer.toHexString(cur.states)); |
| 2286 | } |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2287 | if (state2IntChanged) { |
| 2288 | dest.writeInt(cur.states2); |
| 2289 | if (DEBUG) Slog.i(TAG, "WRITE DELTA: states2=0x" |
| 2290 | + Integer.toHexString(cur.states2)); |
| 2291 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 2292 | if (cur.wakelockTag != null || cur.wakeReasonTag != null) { |
| 2293 | int wakeLockIndex; |
| 2294 | int wakeReasonIndex; |
| 2295 | if (cur.wakelockTag != null) { |
| 2296 | wakeLockIndex = writeHistoryTag(cur.wakelockTag); |
| 2297 | if (DEBUG) Slog.i(TAG, "WRITE DELTA: wakelockTag=#" + cur.wakelockTag.poolIdx |
| 2298 | + " " + cur.wakelockTag.uid + ":" + cur.wakelockTag.string); |
| 2299 | } else { |
| 2300 | wakeLockIndex = 0xffff; |
| 2301 | } |
| 2302 | if (cur.wakeReasonTag != null) { |
| 2303 | wakeReasonIndex = writeHistoryTag(cur.wakeReasonTag); |
| 2304 | if (DEBUG) Slog.i(TAG, "WRITE DELTA: wakeReasonTag=#" + cur.wakeReasonTag.poolIdx |
| 2305 | + " " + cur.wakeReasonTag.uid + ":" + cur.wakeReasonTag.string); |
| 2306 | } else { |
| 2307 | wakeReasonIndex = 0xffff; |
| 2308 | } |
| 2309 | dest.writeInt((wakeReasonIndex<<16) | wakeLockIndex); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2310 | } |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2311 | if (cur.eventCode != HistoryItem.EVENT_NONE) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2312 | int index = writeHistoryTag(cur.eventTag); |
| 2313 | int codeAndIndex = (cur.eventCode&0xffff) | (index<<16); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 2314 | dest.writeInt(codeAndIndex); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2315 | if (DEBUG) Slog.i(TAG, "WRITE DELTA: event=" + cur.eventCode + " tag=#" |
| 2316 | + cur.eventTag.poolIdx + " " + cur.eventTag.uid + ":" |
| 2317 | + cur.eventTag.string); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2318 | } |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 2319 | if (computeStepDetails) { |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 2320 | if (mPlatformIdleStateCallback != null) { |
| 2321 | mCurHistoryStepDetails.statPlatformIdleState = |
| 2322 | mPlatformIdleStateCallback.getPlatformLowPowerStats(); |
| 2323 | if (DEBUG) Slog.i(TAG, "WRITE PlatformIdleState:" + |
| 2324 | mCurHistoryStepDetails.statPlatformIdleState); |
| 2325 | } |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 2326 | computeHistoryStepDetails(mCurHistoryStepDetails, mLastHistoryStepDetails); |
| 2327 | if (includeStepDetails != 0) { |
| 2328 | mCurHistoryStepDetails.writeToParcel(dest); |
| 2329 | } |
| 2330 | cur.stepDetails = mCurHistoryStepDetails; |
| 2331 | mLastHistoryStepDetails = mCurHistoryStepDetails; |
| 2332 | } else { |
| 2333 | cur.stepDetails = null; |
| 2334 | } |
| 2335 | if (mLastHistoryStepLevel < cur.batteryLevel) { |
| 2336 | mLastHistoryStepDetails = null; |
| 2337 | } |
| 2338 | mLastHistoryStepLevel = cur.batteryLevel; |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 2339 | |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame^] | 2340 | if (batteryChargeChanged) { |
| 2341 | if (DEBUG) Slog.i(TAG, "WRITE DELTA: batteryChargeUAh=" + cur.batteryChargeUAh); |
| 2342 | dest.writeInt(cur.batteryChargeUAh); |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 2343 | } |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2344 | } |
| 2345 | |
| 2346 | private int buildBatteryLevelInt(HistoryItem h) { |
| 2347 | return ((((int)h.batteryLevel)<<25)&0xfe000000) |
Adam Lesinski | 3944c81 | 2015-11-13 15:54:59 -0800 | [diff] [blame] | 2348 | | ((((int)h.batteryTemperature)<<15)&0x01ff8000) |
| 2349 | | ((((int)h.batteryVoltage)<<1)&0x00007ffe); |
| 2350 | } |
| 2351 | |
| 2352 | private void readBatteryLevelInt(int batteryLevelInt, HistoryItem out) { |
| 2353 | out.batteryLevel = (byte)((batteryLevelInt & 0xfe000000) >>> 25); |
| 2354 | out.batteryTemperature = (short)((batteryLevelInt & 0x01ff8000) >>> 15); |
| 2355 | out.batteryVoltage = (char)((batteryLevelInt & 0x00007ffe) >>> 1); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2356 | } |
| 2357 | |
| 2358 | private int buildStateInt(HistoryItem h) { |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 2359 | int plugType = 0; |
| 2360 | if ((h.batteryPlugType&BatteryManager.BATTERY_PLUGGED_AC) != 0) { |
| 2361 | plugType = 1; |
| 2362 | } else if ((h.batteryPlugType&BatteryManager.BATTERY_PLUGGED_USB) != 0) { |
| 2363 | plugType = 2; |
| 2364 | } else if ((h.batteryPlugType&BatteryManager.BATTERY_PLUGGED_WIRELESS) != 0) { |
| 2365 | plugType = 3; |
| 2366 | } |
| 2367 | return ((h.batteryStatus&STATE_BATTERY_STATUS_MASK)<<STATE_BATTERY_STATUS_SHIFT) |
| 2368 | | ((h.batteryHealth&STATE_BATTERY_HEALTH_MASK)<<STATE_BATTERY_HEALTH_SHIFT) |
| 2369 | | ((plugType&STATE_BATTERY_PLUG_MASK)<<STATE_BATTERY_PLUG_SHIFT) |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 2370 | | (h.states&(~STATE_BATTERY_MASK)); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2371 | } |
| 2372 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 2373 | private void computeHistoryStepDetails(final HistoryStepDetails out, |
| 2374 | final HistoryStepDetails last) { |
| 2375 | final HistoryStepDetails tmp = last != null ? mTmpHistoryStepDetails : out; |
| 2376 | |
| 2377 | // Perform a CPU update right after we do this collection, so we have started |
| 2378 | // collecting good data for the next step. |
| 2379 | requestImmediateCpuUpdate(); |
| 2380 | |
| 2381 | if (last == null) { |
| 2382 | // We are not generating a delta, so all we need to do is reset the stats |
| 2383 | // we will later be doing a delta from. |
| 2384 | final int NU = mUidStats.size(); |
| 2385 | for (int i=0; i<NU; i++) { |
| 2386 | final BatteryStatsImpl.Uid uid = mUidStats.valueAt(i); |
| 2387 | uid.mLastStepUserTime = uid.mCurStepUserTime; |
| 2388 | uid.mLastStepSystemTime = uid.mCurStepSystemTime; |
| 2389 | } |
| 2390 | mLastStepCpuUserTime = mCurStepCpuUserTime; |
| 2391 | mLastStepCpuSystemTime = mCurStepCpuSystemTime; |
| 2392 | mLastStepStatUserTime = mCurStepStatUserTime; |
| 2393 | mLastStepStatSystemTime = mCurStepStatSystemTime; |
| 2394 | mLastStepStatIOWaitTime = mCurStepStatIOWaitTime; |
| 2395 | mLastStepStatIrqTime = mCurStepStatIrqTime; |
| 2396 | mLastStepStatSoftIrqTime = mCurStepStatSoftIrqTime; |
| 2397 | mLastStepStatIdleTime = mCurStepStatIdleTime; |
| 2398 | tmp.clear(); |
| 2399 | return; |
| 2400 | } |
| 2401 | if (DEBUG) { |
| 2402 | Slog.d(TAG, "Step stats last: user=" + mLastStepCpuUserTime + " sys=" |
| 2403 | + mLastStepStatSystemTime + " io=" + mLastStepStatIOWaitTime |
| 2404 | + " irq=" + mLastStepStatIrqTime + " sirq=" |
| 2405 | + mLastStepStatSoftIrqTime + " idle=" + mLastStepStatIdleTime); |
| 2406 | Slog.d(TAG, "Step stats cur: user=" + mCurStepCpuUserTime + " sys=" |
| 2407 | + mCurStepStatSystemTime + " io=" + mCurStepStatIOWaitTime |
| 2408 | + " irq=" + mCurStepStatIrqTime + " sirq=" |
| 2409 | + mCurStepStatSoftIrqTime + " idle=" + mCurStepStatIdleTime); |
| 2410 | } |
| 2411 | out.userTime = (int)(mCurStepCpuUserTime - mLastStepCpuUserTime); |
| 2412 | out.systemTime = (int)(mCurStepCpuSystemTime - mLastStepCpuSystemTime); |
| 2413 | out.statUserTime = (int)(mCurStepStatUserTime - mLastStepStatUserTime); |
| 2414 | out.statSystemTime = (int)(mCurStepStatSystemTime - mLastStepStatSystemTime); |
| 2415 | out.statIOWaitTime = (int)(mCurStepStatIOWaitTime - mLastStepStatIOWaitTime); |
| 2416 | out.statIrqTime = (int)(mCurStepStatIrqTime - mLastStepStatIrqTime); |
| 2417 | out.statSoftIrqTime = (int)(mCurStepStatSoftIrqTime - mLastStepStatSoftIrqTime); |
| 2418 | out.statIdlTime = (int)(mCurStepStatIdleTime - mLastStepStatIdleTime); |
| 2419 | out.appCpuUid1 = out.appCpuUid2 = out.appCpuUid3 = -1; |
| 2420 | out.appCpuUTime1 = out.appCpuUTime2 = out.appCpuUTime3 = 0; |
| 2421 | out.appCpuSTime1 = out.appCpuSTime2 = out.appCpuSTime3 = 0; |
| 2422 | final int NU = mUidStats.size(); |
| 2423 | for (int i=0; i<NU; i++) { |
| 2424 | final BatteryStatsImpl.Uid uid = mUidStats.valueAt(i); |
| 2425 | final int totalUTime = (int)(uid.mCurStepUserTime - uid.mLastStepUserTime); |
| 2426 | final int totalSTime = (int)(uid.mCurStepSystemTime - uid.mLastStepSystemTime); |
| 2427 | final int totalTime = totalUTime + totalSTime; |
| 2428 | uid.mLastStepUserTime = uid.mCurStepUserTime; |
| 2429 | uid.mLastStepSystemTime = uid.mCurStepSystemTime; |
| 2430 | if (totalTime <= (out.appCpuUTime3+out.appCpuSTime3)) { |
| 2431 | continue; |
| 2432 | } |
| 2433 | if (totalTime <= (out.appCpuUTime2+out.appCpuSTime2)) { |
| 2434 | out.appCpuUid3 = uid.mUid; |
| 2435 | out.appCpuUTime3 = totalUTime; |
| 2436 | out.appCpuSTime3 = totalSTime; |
| 2437 | } else { |
| 2438 | out.appCpuUid3 = out.appCpuUid2; |
| 2439 | out.appCpuUTime3 = out.appCpuUTime2; |
| 2440 | out.appCpuSTime3 = out.appCpuSTime2; |
| 2441 | if (totalTime <= (out.appCpuUTime1+out.appCpuSTime1)) { |
| 2442 | out.appCpuUid2 = uid.mUid; |
| 2443 | out.appCpuUTime2 = totalUTime; |
| 2444 | out.appCpuSTime2 = totalSTime; |
| 2445 | } else { |
| 2446 | out.appCpuUid2 = out.appCpuUid1; |
| 2447 | out.appCpuUTime2 = out.appCpuUTime1; |
| 2448 | out.appCpuSTime2 = out.appCpuSTime1; |
| 2449 | out.appCpuUid1 = uid.mUid; |
| 2450 | out.appCpuUTime1 = totalUTime; |
| 2451 | out.appCpuSTime1 = totalSTime; |
| 2452 | } |
| 2453 | } |
| 2454 | } |
| 2455 | mLastStepCpuUserTime = mCurStepCpuUserTime; |
| 2456 | mLastStepCpuSystemTime = mCurStepCpuSystemTime; |
| 2457 | mLastStepStatUserTime = mCurStepStatUserTime; |
| 2458 | mLastStepStatSystemTime = mCurStepStatSystemTime; |
| 2459 | mLastStepStatIOWaitTime = mCurStepStatIOWaitTime; |
| 2460 | mLastStepStatIrqTime = mCurStepStatIrqTime; |
| 2461 | mLastStepStatSoftIrqTime = mCurStepStatSoftIrqTime; |
| 2462 | mLastStepStatIdleTime = mCurStepStatIdleTime; |
| 2463 | } |
| 2464 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2465 | public void readHistoryDelta(Parcel src, HistoryItem cur) { |
| 2466 | int firstToken = src.readInt(); |
| 2467 | int deltaTimeToken = firstToken&DELTA_TIME_MASK; |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2468 | cur.cmd = HistoryItem.CMD_UPDATE; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2469 | cur.numReadInts = 1; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2470 | if (DEBUG) Slog.i(TAG, "READ DELTA: firstToken=0x" + Integer.toHexString(firstToken) |
| 2471 | + " deltaTimeToken=" + deltaTimeToken); |
| 2472 | |
| 2473 | if (deltaTimeToken < DELTA_TIME_ABS) { |
| 2474 | cur.time += deltaTimeToken; |
| 2475 | } else if (deltaTimeToken == DELTA_TIME_ABS) { |
| 2476 | cur.time = src.readLong(); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2477 | cur.numReadInts += 2; |
| 2478 | if (DEBUG) Slog.i(TAG, "READ DELTA: ABS time=" + cur.time); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2479 | cur.readFromParcel(src); |
| 2480 | return; |
| 2481 | } else if (deltaTimeToken == DELTA_TIME_INT) { |
| 2482 | int delta = src.readInt(); |
| 2483 | cur.time += delta; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2484 | cur.numReadInts += 1; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2485 | if (DEBUG) Slog.i(TAG, "READ DELTA: time delta=" + delta + " new time=" + cur.time); |
| 2486 | } else { |
| 2487 | long delta = src.readLong(); |
| 2488 | if (DEBUG) Slog.i(TAG, "READ DELTA: time delta=" + delta + " new time=" + cur.time); |
| 2489 | cur.time += delta; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2490 | cur.numReadInts += 2; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2491 | } |
| 2492 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 2493 | final int batteryLevelInt; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2494 | if ((firstToken&DELTA_BATTERY_LEVEL_FLAG) != 0) { |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 2495 | batteryLevelInt = src.readInt(); |
Adam Lesinski | 3944c81 | 2015-11-13 15:54:59 -0800 | [diff] [blame] | 2496 | readBatteryLevelInt(batteryLevelInt, cur); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2497 | cur.numReadInts += 1; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2498 | if (DEBUG) Slog.i(TAG, "READ DELTA: batteryToken=0x" |
| 2499 | + Integer.toHexString(batteryLevelInt) |
| 2500 | + " batteryLevel=" + cur.batteryLevel |
| 2501 | + " batteryTemp=" + cur.batteryTemperature |
| 2502 | + " batteryVolt=" + (int)cur.batteryVoltage); |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 2503 | } else { |
| 2504 | batteryLevelInt = 0; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2505 | } |
| 2506 | |
| 2507 | if ((firstToken&DELTA_STATE_FLAG) != 0) { |
| 2508 | int stateInt = src.readInt(); |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 2509 | cur.states = (firstToken&DELTA_STATE_MASK) | (stateInt&(~STATE_BATTERY_MASK)); |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 2510 | cur.batteryStatus = (byte)((stateInt>>STATE_BATTERY_STATUS_SHIFT) |
| 2511 | & STATE_BATTERY_STATUS_MASK); |
| 2512 | cur.batteryHealth = (byte)((stateInt>>STATE_BATTERY_HEALTH_SHIFT) |
| 2513 | & STATE_BATTERY_HEALTH_MASK); |
| 2514 | cur.batteryPlugType = (byte)((stateInt>>STATE_BATTERY_PLUG_SHIFT) |
| 2515 | & STATE_BATTERY_PLUG_MASK); |
| 2516 | switch (cur.batteryPlugType) { |
| 2517 | case 1: |
| 2518 | cur.batteryPlugType = BatteryManager.BATTERY_PLUGGED_AC; |
| 2519 | break; |
| 2520 | case 2: |
| 2521 | cur.batteryPlugType = BatteryManager.BATTERY_PLUGGED_USB; |
| 2522 | break; |
| 2523 | case 3: |
| 2524 | cur.batteryPlugType = BatteryManager.BATTERY_PLUGGED_WIRELESS; |
| 2525 | break; |
| 2526 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2527 | cur.numReadInts += 1; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2528 | if (DEBUG) Slog.i(TAG, "READ DELTA: stateToken=0x" |
| 2529 | + Integer.toHexString(stateInt) |
| 2530 | + " batteryStatus=" + cur.batteryStatus |
| 2531 | + " batteryHealth=" + cur.batteryHealth |
| 2532 | + " batteryPlugType=" + cur.batteryPlugType |
| 2533 | + " states=0x" + Integer.toHexString(cur.states)); |
| 2534 | } else { |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 2535 | cur.states = (firstToken&DELTA_STATE_MASK) | (cur.states&(~STATE_BATTERY_MASK)); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2536 | } |
| 2537 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2538 | if ((firstToken&DELTA_STATE2_FLAG) != 0) { |
| 2539 | cur.states2 = src.readInt(); |
| 2540 | if (DEBUG) Slog.i(TAG, "READ DELTA: states2=0x" |
| 2541 | + Integer.toHexString(cur.states2)); |
| 2542 | } |
| 2543 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2544 | if ((firstToken&DELTA_WAKELOCK_FLAG) != 0) { |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 2545 | int indexes = src.readInt(); |
| 2546 | int wakeLockIndex = indexes&0xffff; |
| 2547 | int wakeReasonIndex = (indexes>>16)&0xffff; |
| 2548 | if (wakeLockIndex != 0xffff) { |
| 2549 | cur.wakelockTag = cur.localWakelockTag; |
| 2550 | readHistoryTag(wakeLockIndex, cur.wakelockTag); |
| 2551 | if (DEBUG) Slog.i(TAG, "READ DELTA: wakelockTag=#" + cur.wakelockTag.poolIdx |
| 2552 | + " " + cur.wakelockTag.uid + ":" + cur.wakelockTag.string); |
| 2553 | } else { |
| 2554 | cur.wakelockTag = null; |
| 2555 | } |
| 2556 | if (wakeReasonIndex != 0xffff) { |
| 2557 | cur.wakeReasonTag = cur.localWakeReasonTag; |
| 2558 | readHistoryTag(wakeReasonIndex, cur.wakeReasonTag); |
| 2559 | if (DEBUG) Slog.i(TAG, "READ DELTA: wakeReasonTag=#" + cur.wakeReasonTag.poolIdx |
| 2560 | + " " + cur.wakeReasonTag.uid + ":" + cur.wakeReasonTag.string); |
| 2561 | } else { |
| 2562 | cur.wakeReasonTag = null; |
| 2563 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2564 | cur.numReadInts += 1; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2565 | } else { |
| 2566 | cur.wakelockTag = null; |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 2567 | cur.wakeReasonTag = null; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2568 | } |
| 2569 | |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2570 | if ((firstToken&DELTA_EVENT_FLAG) != 0) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2571 | cur.eventTag = cur.localEventTag; |
| 2572 | final int codeAndIndex = src.readInt(); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 2573 | cur.eventCode = (codeAndIndex&0xffff); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2574 | final int index = ((codeAndIndex>>16)&0xffff); |
| 2575 | readHistoryTag(index, cur.eventTag); |
| 2576 | cur.numReadInts += 1; |
| 2577 | if (DEBUG) Slog.i(TAG, "READ DELTA: event=" + cur.eventCode + " tag=#" |
| 2578 | + cur.eventTag.poolIdx + " " + cur.eventTag.uid + ":" |
| 2579 | + cur.eventTag.string); |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2580 | } else { |
| 2581 | cur.eventCode = HistoryItem.EVENT_NONE; |
| 2582 | } |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 2583 | |
| 2584 | if ((batteryLevelInt&BATTERY_DELTA_LEVEL_FLAG) != 0) { |
| 2585 | cur.stepDetails = mReadHistoryStepDetails; |
| 2586 | cur.stepDetails.readFromParcel(src); |
| 2587 | } else { |
| 2588 | cur.stepDetails = null; |
| 2589 | } |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 2590 | |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame^] | 2591 | if ((firstToken&DELTA_BATTERY_CHARGE_FLAG) != 0) { |
| 2592 | cur.batteryChargeUAh = src.readInt(); |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 2593 | } |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2594 | } |
| 2595 | |
Dianne Hackborn | fc06413 | 2014-06-02 12:42:12 -0700 | [diff] [blame] | 2596 | @Override |
| 2597 | public void commitCurrentHistoryBatchLocked() { |
| 2598 | mHistoryLastWritten.cmd = HistoryItem.CMD_NULL; |
| 2599 | } |
| 2600 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2601 | void addHistoryBufferLocked(long elapsedRealtimeMs, long uptimeMs, HistoryItem cur) { |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2602 | if (!mHaveBatteryLevel || !mRecordingHistory) { |
| 2603 | return; |
| 2604 | } |
| 2605 | |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2606 | final long timeDiff = (mHistoryBaseTime+elapsedRealtimeMs) - mHistoryLastWritten.time; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 2607 | final int diffStates = mHistoryLastWritten.states^(cur.states&mActiveHistoryStates); |
| 2608 | final int diffStates2 = mHistoryLastWritten.states2^(cur.states2&mActiveHistoryStates2); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2609 | final int lastDiffStates = mHistoryLastWritten.states^mHistoryLastLastWritten.states; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2610 | final int lastDiffStates2 = mHistoryLastWritten.states2^mHistoryLastLastWritten.states2; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2611 | if (DEBUG) Slog.i(TAG, "ADD: tdelta=" + timeDiff + " diff=" |
| 2612 | + Integer.toHexString(diffStates) + " lastDiff=" |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2613 | + Integer.toHexString(lastDiffStates) + " diff2=" |
| 2614 | + Integer.toHexString(diffStates2) + " lastDiff2=" |
| 2615 | + Integer.toHexString(lastDiffStates2)); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2616 | if (mHistoryBufferLastPos >= 0 && mHistoryLastWritten.cmd == HistoryItem.CMD_UPDATE |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2617 | && timeDiff < 1000 && (diffStates&lastDiffStates) == 0 |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2618 | && (diffStates2&lastDiffStates2) == 0 |
| 2619 | && (mHistoryLastWritten.wakelockTag == null || cur.wakelockTag == null) |
| 2620 | && (mHistoryLastWritten.wakeReasonTag == null || cur.wakeReasonTag == null) |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 2621 | && mHistoryLastWritten.stepDetails == null |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2622 | && (mHistoryLastWritten.eventCode == HistoryItem.EVENT_NONE |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2623 | || cur.eventCode == HistoryItem.EVENT_NONE) |
| 2624 | && mHistoryLastWritten.batteryLevel == cur.batteryLevel |
| 2625 | && mHistoryLastWritten.batteryStatus == cur.batteryStatus |
| 2626 | && mHistoryLastWritten.batteryHealth == cur.batteryHealth |
| 2627 | && mHistoryLastWritten.batteryPlugType == cur.batteryPlugType |
| 2628 | && mHistoryLastWritten.batteryTemperature == cur.batteryTemperature |
| 2629 | && mHistoryLastWritten.batteryVoltage == cur.batteryVoltage) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2630 | // 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] | 2631 | // 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] | 2632 | // as long as no bit has changed both between now and the last entry, as |
| 2633 | // well as the last entry and the one before it (so we capture any toggles). |
| 2634 | if (DEBUG) Slog.i(TAG, "ADD: rewinding back to " + mHistoryBufferLastPos); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2635 | mHistoryBuffer.setDataSize(mHistoryBufferLastPos); |
| 2636 | mHistoryBuffer.setDataPosition(mHistoryBufferLastPos); |
| 2637 | mHistoryBufferLastPos = -1; |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2638 | elapsedRealtimeMs = mHistoryLastWritten.time - mHistoryBaseTime; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2639 | // If the last written history had a wakelock tag, we need to retain it. |
| 2640 | // Note that the condition above made sure that we aren't in a case where |
| 2641 | // both it and the current history item have a wakelock tag. |
| 2642 | if (mHistoryLastWritten.wakelockTag != null) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2643 | cur.wakelockTag = cur.localWakelockTag; |
| 2644 | cur.wakelockTag.setTo(mHistoryLastWritten.wakelockTag); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2645 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 2646 | // If the last written history had a wake reason tag, we need to retain it. |
| 2647 | // Note that the condition above made sure that we aren't in a case where |
| 2648 | // both it and the current history item have a wakelock tag. |
| 2649 | if (mHistoryLastWritten.wakeReasonTag != null) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2650 | cur.wakeReasonTag = cur.localWakeReasonTag; |
| 2651 | cur.wakeReasonTag.setTo(mHistoryLastWritten.wakeReasonTag); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 2652 | } |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2653 | // If the last written history had an event, we need to retain it. |
| 2654 | // Note that the condition above made sure that we aren't in a case where |
| 2655 | // both it and the current history item have an event. |
| 2656 | if (mHistoryLastWritten.eventCode != HistoryItem.EVENT_NONE) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2657 | cur.eventCode = mHistoryLastWritten.eventCode; |
| 2658 | cur.eventTag = cur.localEventTag; |
| 2659 | cur.eventTag.setTo(mHistoryLastWritten.eventTag); |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2660 | } |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 2661 | mHistoryLastWritten.setTo(mHistoryLastLastWritten); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2662 | } |
| 2663 | |
| 2664 | final int dataSize = mHistoryBuffer.dataSize(); |
| 2665 | if (dataSize >= MAX_HISTORY_BUFFER) { |
| 2666 | if (!mHistoryOverflow) { |
| 2667 | mHistoryOverflow = true; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2668 | addHistoryBufferLocked(elapsedRealtimeMs, uptimeMs, HistoryItem.CMD_UPDATE, cur); |
| 2669 | addHistoryBufferLocked(elapsedRealtimeMs, uptimeMs, HistoryItem.CMD_OVERFLOW, cur); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2670 | return; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2671 | } |
| 2672 | |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 2673 | // After overflow, we allow various bit-wise states to settle to 0. |
| 2674 | boolean writeAnyway = false; |
| 2675 | final int curStates = cur.states & HistoryItem.SETTLE_TO_ZERO_STATES |
| 2676 | & mActiveHistoryStates; |
| 2677 | if (mHistoryLastWritten.states != curStates) { |
| 2678 | // mActiveHistoryStates keeps track of which bits in .states are now being |
| 2679 | // forced to 0. |
| 2680 | int old = mActiveHistoryStates; |
| 2681 | mActiveHistoryStates &= curStates | ~HistoryItem.SETTLE_TO_ZERO_STATES; |
| 2682 | writeAnyway |= old != mActiveHistoryStates; |
| 2683 | } |
| 2684 | final int curStates2 = cur.states2 & HistoryItem.SETTLE_TO_ZERO_STATES2 |
| 2685 | & mActiveHistoryStates2; |
| 2686 | if (mHistoryLastWritten.states2 != curStates2) { |
| 2687 | // mActiveHistoryStates2 keeps track of which bits in .states2 are now being |
| 2688 | // forced to 0. |
| 2689 | int old = mActiveHistoryStates2; |
| 2690 | mActiveHistoryStates2 &= curStates2 | ~HistoryItem.SETTLE_TO_ZERO_STATES2; |
| 2691 | writeAnyway |= old != mActiveHistoryStates2; |
| 2692 | } |
| 2693 | |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2694 | // Once we've reached the maximum number of items, we only |
| 2695 | // record changes to the battery level and the most interesting states. |
| 2696 | // Once we've reached the maximum maximum number of items, we only |
| 2697 | // record changes to the battery level. |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 2698 | if (!writeAnyway && mHistoryLastWritten.batteryLevel == cur.batteryLevel && |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2699 | (dataSize >= MAX_MAX_HISTORY_BUFFER |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2700 | || ((mHistoryLastWritten.states^cur.states) |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 2701 | & HistoryItem.MOST_INTERESTING_STATES) == 0 |
| 2702 | || ((mHistoryLastWritten.states2^cur.states2) |
| 2703 | & HistoryItem.MOST_INTERESTING_STATES2) == 0)) { |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2704 | return; |
| 2705 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2706 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2707 | addHistoryBufferLocked(elapsedRealtimeMs, uptimeMs, HistoryItem.CMD_UPDATE, cur); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2708 | return; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2709 | } |
| 2710 | |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 2711 | if (dataSize == 0) { |
| 2712 | // The history is currently empty; we need it to start with a time stamp. |
| 2713 | cur.currentTime = System.currentTimeMillis(); |
| 2714 | addHistoryBufferLocked(elapsedRealtimeMs, uptimeMs, HistoryItem.CMD_RESET, cur); |
| 2715 | } |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2716 | addHistoryBufferLocked(elapsedRealtimeMs, uptimeMs, HistoryItem.CMD_UPDATE, cur); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2717 | } |
| 2718 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2719 | private void addHistoryBufferLocked(long elapsedRealtimeMs, long uptimeMs, byte cmd, |
| 2720 | HistoryItem cur) { |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2721 | if (mIteratingHistory) { |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2722 | throw new IllegalStateException("Can't do this while iterating history!"); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2723 | } |
| 2724 | mHistoryBufferLastPos = mHistoryBuffer.dataPosition(); |
| 2725 | mHistoryLastLastWritten.setTo(mHistoryLastWritten); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2726 | mHistoryLastWritten.setTo(mHistoryBaseTime + elapsedRealtimeMs, cmd, cur); |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 2727 | mHistoryLastWritten.states &= mActiveHistoryStates; |
| 2728 | mHistoryLastWritten.states2 &= mActiveHistoryStates2; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 2729 | writeHistoryDelta(mHistoryBuffer, mHistoryLastWritten, mHistoryLastLastWritten); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2730 | mLastHistoryElapsedRealtime = elapsedRealtimeMs; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2731 | cur.wakelockTag = null; |
| 2732 | cur.wakeReasonTag = null; |
| 2733 | cur.eventCode = HistoryItem.EVENT_NONE; |
| 2734 | cur.eventTag = null; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2735 | if (DEBUG_HISTORY) Slog.i(TAG, "Writing history buffer: was " + mHistoryBufferLastPos |
| 2736 | + " now " + mHistoryBuffer.dataPosition() |
| 2737 | + " size is now " + mHistoryBuffer.dataSize()); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2738 | } |
| 2739 | |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 2740 | int mChangedStates = 0; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2741 | int mChangedStates2 = 0; |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 2742 | |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2743 | void addHistoryRecordLocked(long elapsedRealtimeMs, long uptimeMs) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2744 | if (mTrackRunningHistoryElapsedRealtime != 0) { |
| 2745 | final long diffElapsed = elapsedRealtimeMs - mTrackRunningHistoryElapsedRealtime; |
| 2746 | final long diffUptime = uptimeMs - mTrackRunningHistoryUptime; |
| 2747 | if (diffUptime < (diffElapsed-20)) { |
| 2748 | final long wakeElapsedTime = elapsedRealtimeMs - (diffElapsed - diffUptime); |
| 2749 | mHistoryAddTmp.setTo(mHistoryLastWritten); |
| 2750 | mHistoryAddTmp.wakelockTag = null; |
| 2751 | mHistoryAddTmp.wakeReasonTag = null; |
| 2752 | mHistoryAddTmp.eventCode = HistoryItem.EVENT_NONE; |
| 2753 | mHistoryAddTmp.states &= ~HistoryItem.STATE_CPU_RUNNING_FLAG; |
| 2754 | addHistoryRecordInnerLocked(wakeElapsedTime, uptimeMs, mHistoryAddTmp); |
| 2755 | } |
| 2756 | } |
| 2757 | mHistoryCur.states |= HistoryItem.STATE_CPU_RUNNING_FLAG; |
| 2758 | mTrackRunningHistoryElapsedRealtime = elapsedRealtimeMs; |
| 2759 | mTrackRunningHistoryUptime = uptimeMs; |
| 2760 | addHistoryRecordInnerLocked(elapsedRealtimeMs, uptimeMs, mHistoryCur); |
| 2761 | } |
| 2762 | |
| 2763 | void addHistoryRecordInnerLocked(long elapsedRealtimeMs, long uptimeMs, HistoryItem cur) { |
| 2764 | addHistoryBufferLocked(elapsedRealtimeMs, uptimeMs, cur); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2765 | |
Dianne Hackborn | e8c88e6 | 2011-08-17 19:09:09 -0700 | [diff] [blame] | 2766 | if (!USE_OLD_HISTORY) { |
| 2767 | return; |
| 2768 | } |
| 2769 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2770 | if (!mHaveBatteryLevel || !mRecordingHistory) { |
| 2771 | return; |
| 2772 | } |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2773 | |
| 2774 | // If the current time is basically the same as the last time, |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 2775 | // and no states have since the last recorded entry changed and |
| 2776 | // are now resetting back to their original value, then just collapse |
| 2777 | // into one record. |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2778 | if (mHistoryEnd != null && mHistoryEnd.cmd == HistoryItem.CMD_UPDATE |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2779 | && (mHistoryBaseTime+elapsedRealtimeMs) < (mHistoryEnd.time+1000) |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 2780 | && ((mHistoryEnd.states^cur.states)&mChangedStates&mActiveHistoryStates) == 0 |
| 2781 | && ((mHistoryEnd.states2^cur.states2)&mChangedStates2&mActiveHistoryStates2) == 0) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2782 | // If the current is the same as the one before, then we no |
| 2783 | // longer need the entry. |
| 2784 | if (mHistoryLastEnd != null && mHistoryLastEnd.cmd == HistoryItem.CMD_UPDATE |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2785 | && (mHistoryBaseTime+elapsedRealtimeMs) < (mHistoryEnd.time+500) |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2786 | && mHistoryLastEnd.sameNonEvent(cur)) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2787 | mHistoryLastEnd.next = null; |
| 2788 | mHistoryEnd.next = mHistoryCache; |
| 2789 | mHistoryCache = mHistoryEnd; |
| 2790 | mHistoryEnd = mHistoryLastEnd; |
| 2791 | mHistoryLastEnd = null; |
| 2792 | } else { |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 2793 | mChangedStates |= mHistoryEnd.states^(cur.states&mActiveHistoryStates); |
| 2794 | mChangedStates2 |= mHistoryEnd.states^(cur.states2&mActiveHistoryStates2); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2795 | mHistoryEnd.setTo(mHistoryEnd.time, HistoryItem.CMD_UPDATE, cur); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2796 | } |
| 2797 | return; |
| 2798 | } |
| 2799 | |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 2800 | mChangedStates = 0; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2801 | mChangedStates2 = 0; |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 2802 | |
| 2803 | if (mNumHistoryItems == MAX_HISTORY_ITEMS |
| 2804 | || mNumHistoryItems == MAX_MAX_HISTORY_ITEMS) { |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2805 | addHistoryRecordLocked(elapsedRealtimeMs, HistoryItem.CMD_OVERFLOW); |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 2806 | } |
| 2807 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2808 | if (mNumHistoryItems >= MAX_HISTORY_ITEMS) { |
| 2809 | // Once we've reached the maximum number of items, we only |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 2810 | // record changes to the battery level and the most interesting states. |
| 2811 | // Once we've reached the maximum maximum number of items, we only |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2812 | // record changes to the battery level. |
| 2813 | if (mHistoryEnd != null && mHistoryEnd.batteryLevel |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2814 | == cur.batteryLevel && |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 2815 | (mNumHistoryItems >= MAX_MAX_HISTORY_ITEMS |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 2816 | || ((mHistoryEnd.states^(cur.states&mActiveHistoryStates)) |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 2817 | & HistoryItem.MOST_INTERESTING_STATES) == 0)) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2818 | return; |
| 2819 | } |
| 2820 | } |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2821 | |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2822 | addHistoryRecordLocked(elapsedRealtimeMs, HistoryItem.CMD_UPDATE); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2823 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2824 | |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 2825 | public void addHistoryEventLocked(long elapsedRealtimeMs, long uptimeMs, int code, |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2826 | String name, int uid) { |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2827 | mHistoryCur.eventCode = code; |
| 2828 | mHistoryCur.eventTag = mHistoryCur.localEventTag; |
| 2829 | mHistoryCur.eventTag.string = name; |
| 2830 | mHistoryCur.eventTag.uid = uid; |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 2831 | addHistoryRecordLocked(elapsedRealtimeMs, uptimeMs); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 2832 | } |
| 2833 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2834 | void addHistoryRecordLocked(long elapsedRealtimeMs, long uptimeMs, byte cmd, HistoryItem cur) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2835 | HistoryItem rec = mHistoryCache; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 2836 | if (rec != null) { |
| 2837 | mHistoryCache = rec.next; |
| 2838 | } else { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2839 | rec = new HistoryItem(); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 2840 | } |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2841 | rec.setTo(mHistoryBaseTime + elapsedRealtimeMs, cmd, cur); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2842 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2843 | addHistoryRecordLocked(rec); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 2844 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2845 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2846 | void addHistoryRecordLocked(HistoryItem rec) { |
| 2847 | mNumHistoryItems++; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 2848 | rec.next = null; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 2849 | mHistoryLastEnd = mHistoryEnd; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 2850 | if (mHistoryEnd != null) { |
| 2851 | mHistoryEnd.next = rec; |
| 2852 | mHistoryEnd = rec; |
| 2853 | } else { |
| 2854 | mHistory = mHistoryEnd = rec; |
| 2855 | } |
| 2856 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2857 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2858 | void clearHistoryLocked() { |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2859 | if (DEBUG_HISTORY) Slog.i(TAG, "********** CLEARING HISTORY!"); |
Dianne Hackborn | e8c88e6 | 2011-08-17 19:09:09 -0700 | [diff] [blame] | 2860 | if (USE_OLD_HISTORY) { |
| 2861 | if (mHistory != null) { |
| 2862 | mHistoryEnd.next = mHistoryCache; |
| 2863 | mHistoryCache = mHistory; |
| 2864 | mHistory = mHistoryLastEnd = mHistoryEnd = null; |
| 2865 | } |
| 2866 | mNumHistoryItems = 0; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 2867 | } |
Dianne Hackborn | e8c88e6 | 2011-08-17 19:09:09 -0700 | [diff] [blame] | 2868 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 2869 | mHistoryBaseTime = 0; |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2870 | mLastHistoryElapsedRealtime = 0; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 2871 | mTrackRunningHistoryElapsedRealtime = 0; |
| 2872 | mTrackRunningHistoryUptime = 0; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2873 | |
| 2874 | mHistoryBuffer.setDataSize(0); |
| 2875 | mHistoryBuffer.setDataPosition(0); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2876 | mHistoryBuffer.setDataCapacity(MAX_HISTORY_BUFFER / 2); |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 2877 | mHistoryLastLastWritten.clear(); |
| 2878 | mHistoryLastWritten.clear(); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 2879 | mHistoryTagPool.clear(); |
| 2880 | mNextHistoryTagIdx = 0; |
| 2881 | mNumHistoryTagChars = 0; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 2882 | mHistoryBufferLastPos = -1; |
| 2883 | mHistoryOverflow = false; |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 2884 | mActiveHistoryStates = 0xffffffff; |
| 2885 | mActiveHistoryStates2 = 0xffffffff; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 2886 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 2887 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2888 | public void updateTimeBasesLocked(boolean unplugged, boolean screenOff, long uptime, |
| 2889 | long realtime) { |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 2890 | mOnBatteryTimeBase.setRunning(unplugged, uptime, realtime); |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 2891 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2892 | boolean unpluggedScreenOff = unplugged && screenOff; |
| 2893 | if (unpluggedScreenOff != mOnBatteryScreenOffTimeBase.isRunning()) { |
| 2894 | updateKernelWakelocksLocked(); |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 2895 | if (DEBUG_ENERGY_CPU) { |
| 2896 | Slog.d(TAG, "Updating cpu time because screen is now " + |
| 2897 | (unpluggedScreenOff ? "off" : "on")); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2898 | } |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 2899 | updateCpuTimeLocked(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 2900 | mOnBatteryScreenOffTimeBase.setRunning(unpluggedScreenOff, uptime, realtime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2901 | } |
| 2902 | } |
Amith Yamasani | 3718aaa | 2009-06-09 06:32:35 -0700 | [diff] [blame] | 2903 | |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 2904 | public void addIsolatedUidLocked(int isolatedUid, int appUid) { |
| 2905 | mIsolatedUids.put(isolatedUid, appUid); |
| 2906 | } |
| 2907 | |
Adam Lesinski | 61db88f | 2015-07-01 15:05:07 -0700 | [diff] [blame] | 2908 | /** |
| 2909 | * Schedules a read of the latest cpu times before removing the isolated UID. |
| 2910 | * @see #removeIsolatedUidLocked(int) |
| 2911 | */ |
| 2912 | public void scheduleRemoveIsolatedUidLocked(int isolatedUid, int appUid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 2913 | int curUid = mIsolatedUids.get(isolatedUid, -1); |
| 2914 | if (curUid == appUid) { |
Adam Lesinski | 61db88f | 2015-07-01 15:05:07 -0700 | [diff] [blame] | 2915 | if (mExternalSync != null) { |
| 2916 | mExternalSync.scheduleCpuSyncDueToRemovedUid(isolatedUid); |
| 2917 | } |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 2918 | } |
| 2919 | } |
| 2920 | |
Adam Lesinski | 61db88f | 2015-07-01 15:05:07 -0700 | [diff] [blame] | 2921 | /** |
| 2922 | * This should only be called after the cpu times have been read. |
| 2923 | * @see #scheduleRemoveIsolatedUidLocked(int, int) |
| 2924 | */ |
| 2925 | public void removeIsolatedUidLocked(int isolatedUid) { |
| 2926 | mIsolatedUids.delete(isolatedUid); |
| 2927 | mKernelUidCpuTimeReader.removeUid(isolatedUid); |
| 2928 | } |
| 2929 | |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 2930 | public int mapUid(int uid) { |
| 2931 | int isolated = mIsolatedUids.get(uid, -1); |
| 2932 | return isolated > 0 ? isolated : uid; |
| 2933 | } |
| 2934 | |
| 2935 | public void noteEventLocked(int code, String name, int uid) { |
| 2936 | uid = mapUid(uid); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 2937 | if (!mActiveEvents.updateState(code, name, uid, 0)) { |
| 2938 | return; |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 2939 | } |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 2940 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 2941 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 2942 | addHistoryEventLocked(elapsedRealtime, uptime, code, name, uid); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 2943 | } |
| 2944 | |
Dianne Hackborn | d48954f | 2015-07-22 17:20:33 -0700 | [diff] [blame] | 2945 | boolean ensureStartClockTime(final long currentTime) { |
| 2946 | final long ABOUT_ONE_YEAR = 365*24*60*60*1000L; |
| 2947 | if (currentTime > ABOUT_ONE_YEAR && mStartClockTime < (currentTime-ABOUT_ONE_YEAR)) { |
| 2948 | // If the start clock time has changed by more than a year, then presumably |
| 2949 | // the previous time was completely bogus. So we are going to figure out a |
| 2950 | // 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] | 2951 | mStartClockTime = currentTime - (mClocks.elapsedRealtime()-(mRealtimeStart/1000)); |
Dianne Hackborn | d48954f | 2015-07-22 17:20:33 -0700 | [diff] [blame] | 2952 | return true; |
| 2953 | } |
| 2954 | return false; |
| 2955 | } |
| 2956 | |
Dianne Hackborn | 7d9eefd | 2014-08-27 18:30:31 -0700 | [diff] [blame] | 2957 | public void noteCurrentTimeChangedLocked() { |
| 2958 | final long currentTime = System.currentTimeMillis(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 2959 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 2960 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 7d9eefd | 2014-08-27 18:30:31 -0700 | [diff] [blame] | 2961 | recordCurrentTimeChangeLocked(currentTime, elapsedRealtime, uptime); |
Dianne Hackborn | d48954f | 2015-07-22 17:20:33 -0700 | [diff] [blame] | 2962 | ensureStartClockTime(currentTime); |
Dianne Hackborn | 7d9eefd | 2014-08-27 18:30:31 -0700 | [diff] [blame] | 2963 | } |
| 2964 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 2965 | public void noteProcessStartLocked(String name, int uid) { |
| 2966 | uid = mapUid(uid); |
| 2967 | if (isOnBattery()) { |
| 2968 | Uid u = getUidStatsLocked(uid); |
| 2969 | u.getProcessStatsLocked(name).incStartsLocked(); |
| 2970 | } |
| 2971 | if (!mActiveEvents.updateState(HistoryItem.EVENT_PROC_START, name, uid, 0)) { |
| 2972 | return; |
| 2973 | } |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 2974 | if (!mRecordAllHistory) { |
| 2975 | return; |
| 2976 | } |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 2977 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 2978 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 2979 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_PROC_START, name, uid); |
| 2980 | } |
| 2981 | |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 2982 | public void noteProcessCrashLocked(String name, int uid) { |
| 2983 | uid = mapUid(uid); |
| 2984 | if (isOnBattery()) { |
| 2985 | Uid u = getUidStatsLocked(uid); |
| 2986 | u.getProcessStatsLocked(name).incNumCrashesLocked(); |
| 2987 | } |
| 2988 | } |
| 2989 | |
| 2990 | public void noteProcessAnrLocked(String name, int uid) { |
| 2991 | uid = mapUid(uid); |
| 2992 | if (isOnBattery()) { |
| 2993 | Uid u = getUidStatsLocked(uid); |
| 2994 | u.getProcessStatsLocked(name).incNumAnrsLocked(); |
| 2995 | } |
| 2996 | } |
| 2997 | |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 2998 | public void noteUidProcessStateLocked(int uid, int state) { |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 2999 | uid = mapUid(uid); |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 3000 | getUidStatsLocked(uid).updateUidProcessStateLocked(state); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 3001 | } |
| 3002 | |
| 3003 | public void noteProcessFinishLocked(String name, int uid) { |
| 3004 | uid = mapUid(uid); |
| 3005 | if (!mActiveEvents.updateState(HistoryItem.EVENT_PROC_FINISH, name, uid, 0)) { |
| 3006 | return; |
| 3007 | } |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 3008 | if (!mRecordAllHistory) { |
| 3009 | return; |
| 3010 | } |
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 | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 3013 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_PROC_FINISH, name, uid); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 3014 | } |
| 3015 | |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 3016 | public void noteSyncStartLocked(String name, int uid) { |
| 3017 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3018 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3019 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 3020 | getUidStatsLocked(uid).noteStartSyncLocked(name, elapsedRealtime); |
| 3021 | if (!mActiveEvents.updateState(HistoryItem.EVENT_SYNC_START, name, uid, 0)) { |
| 3022 | return; |
| 3023 | } |
| 3024 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_SYNC_START, name, uid); |
| 3025 | } |
| 3026 | |
| 3027 | public void noteSyncFinishLocked(String name, int uid) { |
| 3028 | uid = mapUid(uid); |
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 | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 3031 | getUidStatsLocked(uid).noteStopSyncLocked(name, elapsedRealtime); |
| 3032 | if (!mActiveEvents.updateState(HistoryItem.EVENT_SYNC_FINISH, name, uid, 0)) { |
| 3033 | return; |
| 3034 | } |
| 3035 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_SYNC_FINISH, name, uid); |
| 3036 | } |
| 3037 | |
| 3038 | public void noteJobStartLocked(String name, int uid) { |
| 3039 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3040 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3041 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 3042 | getUidStatsLocked(uid).noteStartJobLocked(name, elapsedRealtime); |
| 3043 | if (!mActiveEvents.updateState(HistoryItem.EVENT_JOB_START, name, uid, 0)) { |
| 3044 | return; |
| 3045 | } |
| 3046 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_JOB_START, name, uid); |
| 3047 | } |
| 3048 | |
| 3049 | public void noteJobFinishLocked(String name, int uid) { |
| 3050 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3051 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3052 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 3053 | getUidStatsLocked(uid).noteStopJobLocked(name, elapsedRealtime); |
| 3054 | if (!mActiveEvents.updateState(HistoryItem.EVENT_JOB_FINISH, name, uid, 0)) { |
| 3055 | return; |
| 3056 | } |
| 3057 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_JOB_FINISH, name, uid); |
| 3058 | } |
| 3059 | |
Dianne Hackborn | 1e38382 | 2015-04-10 14:02:33 -0700 | [diff] [blame] | 3060 | public void noteAlarmStartLocked(String name, int uid) { |
| 3061 | if (!mRecordAllHistory) { |
| 3062 | return; |
| 3063 | } |
| 3064 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3065 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3066 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 1e38382 | 2015-04-10 14:02:33 -0700 | [diff] [blame] | 3067 | if (!mActiveEvents.updateState(HistoryItem.EVENT_ALARM_START, name, uid, 0)) { |
| 3068 | return; |
| 3069 | } |
| 3070 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_ALARM_START, name, uid); |
| 3071 | } |
| 3072 | |
| 3073 | public void noteAlarmFinishLocked(String name, int uid) { |
| 3074 | if (!mRecordAllHistory) { |
| 3075 | return; |
| 3076 | } |
| 3077 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3078 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3079 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 1e38382 | 2015-04-10 14:02:33 -0700 | [diff] [blame] | 3080 | if (!mActiveEvents.updateState(HistoryItem.EVENT_ALARM_FINISH, name, uid, 0)) { |
| 3081 | return; |
| 3082 | } |
| 3083 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_ALARM_FINISH, name, uid); |
| 3084 | } |
| 3085 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3086 | private void requestWakelockCpuUpdate() { |
| 3087 | if (!mHandler.hasMessages(MSG_UPDATE_WAKELOCKS)) { |
| 3088 | Message m = mHandler.obtainMessage(MSG_UPDATE_WAKELOCKS); |
| 3089 | mHandler.sendMessageDelayed(m, DELAY_UPDATE_WAKELOCKS); |
| 3090 | } |
| 3091 | } |
| 3092 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 3093 | private void requestImmediateCpuUpdate() { |
| 3094 | mHandler.removeMessages(MSG_UPDATE_WAKELOCKS); |
| 3095 | mHandler.sendEmptyMessage(MSG_UPDATE_WAKELOCKS); |
| 3096 | } |
| 3097 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 3098 | public void setRecordAllHistoryLocked(boolean enabled) { |
| 3099 | mRecordAllHistory = enabled; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3100 | if (!enabled) { |
| 3101 | // Clear out any existing state. |
| 3102 | mActiveEvents.removeEvents(HistoryItem.EVENT_WAKE_LOCK); |
Dianne Hackborn | 1e38382 | 2015-04-10 14:02:33 -0700 | [diff] [blame] | 3103 | mActiveEvents.removeEvents(HistoryItem.EVENT_ALARM); |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 3104 | // Record the currently running processes as stopping, now that we are no |
| 3105 | // longer tracking them. |
| 3106 | HashMap<String, SparseIntArray> active = mActiveEvents.getStateForEvent( |
| 3107 | HistoryItem.EVENT_PROC); |
| 3108 | if (active != null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3109 | long mSecRealtime = mClocks.elapsedRealtime(); |
| 3110 | final long mSecUptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 3111 | for (HashMap.Entry<String, SparseIntArray> ent : active.entrySet()) { |
| 3112 | SparseIntArray uids = ent.getValue(); |
| 3113 | for (int j=0; j<uids.size(); j++) { |
| 3114 | addHistoryEventLocked(mSecRealtime, mSecUptime, |
| 3115 | HistoryItem.EVENT_PROC_FINISH, ent.getKey(), uids.keyAt(j)); |
| 3116 | } |
| 3117 | } |
| 3118 | } |
| 3119 | } else { |
| 3120 | // Record the currently running processes as starting, now that we are tracking them. |
| 3121 | HashMap<String, SparseIntArray> active = mActiveEvents.getStateForEvent( |
| 3122 | HistoryItem.EVENT_PROC); |
| 3123 | if (active != null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3124 | long mSecRealtime = mClocks.elapsedRealtime(); |
| 3125 | final long mSecUptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 3126 | for (HashMap.Entry<String, SparseIntArray> ent : active.entrySet()) { |
| 3127 | SparseIntArray uids = ent.getValue(); |
| 3128 | for (int j=0; j<uids.size(); j++) { |
| 3129 | addHistoryEventLocked(mSecRealtime, mSecUptime, |
| 3130 | HistoryItem.EVENT_PROC_START, ent.getKey(), uids.keyAt(j)); |
| 3131 | } |
| 3132 | } |
| 3133 | } |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3134 | } |
| 3135 | } |
| 3136 | |
Dianne Hackborn | 9a75543 | 2014-05-15 17:05:22 -0700 | [diff] [blame] | 3137 | public void setNoAutoReset(boolean enabled) { |
| 3138 | mNoAutoReset = enabled; |
| 3139 | } |
| 3140 | |
| 3141 | private String mInitialAcquireWakeName; |
| 3142 | private int mInitialAcquireWakeUid = -1; |
| 3143 | |
Dianne Hackborn | a1f1a3c | 2014-02-24 18:12:28 -0800 | [diff] [blame] | 3144 | 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] | 3145 | boolean unimportantForLogging, long elapsedRealtime, long uptime) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3146 | uid = mapUid(uid); |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 3147 | if (type == WAKE_TYPE_PARTIAL) { |
| 3148 | // Only care about partial wake locks, since full wake locks |
| 3149 | // will be canceled when the user puts the screen to sleep. |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3150 | aggregateLastWakeupUptimeLocked(uptime); |
Dianne Hackborn | fc06413 | 2014-06-02 12:42:12 -0700 | [diff] [blame] | 3151 | if (historyName == null) { |
| 3152 | historyName = name; |
| 3153 | } |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 3154 | if (mRecordAllHistory) { |
Dianne Hackborn | fc06413 | 2014-06-02 12:42:12 -0700 | [diff] [blame] | 3155 | if (mActiveEvents.updateState(HistoryItem.EVENT_WAKE_LOCK_START, historyName, |
| 3156 | uid, 0)) { |
Dianne Hackborn | 536456f | 2014-05-23 16:51:05 -0700 | [diff] [blame] | 3157 | addHistoryEventLocked(elapsedRealtime, uptime, |
Dianne Hackborn | fc06413 | 2014-06-02 12:42:12 -0700 | [diff] [blame] | 3158 | HistoryItem.EVENT_WAKE_LOCK_START, historyName, uid); |
Dianne Hackborn | 536456f | 2014-05-23 16:51:05 -0700 | [diff] [blame] | 3159 | } |
| 3160 | } |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 3161 | if (mWakeLockNesting == 0) { |
| 3162 | mHistoryCur.states |= HistoryItem.STATE_WAKE_LOCK_FLAG; |
| 3163 | if (DEBUG_HISTORY) Slog.v(TAG, "Start wake lock to: " |
| 3164 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 3165 | mHistoryCur.wakelockTag = mHistoryCur.localWakelockTag; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3166 | mHistoryCur.wakelockTag.string = mInitialAcquireWakeName = historyName; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 3167 | mHistoryCur.wakelockTag.uid = mInitialAcquireWakeUid = uid; |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 3168 | mWakeLockImportant = !unimportantForLogging; |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3169 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | fc06413 | 2014-06-02 12:42:12 -0700 | [diff] [blame] | 3170 | } else if (!mWakeLockImportant && !unimportantForLogging |
| 3171 | && mHistoryLastWritten.cmd == HistoryItem.CMD_UPDATE) { |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 3172 | if (mHistoryLastWritten.wakelockTag != null) { |
| 3173 | // We'll try to update the last tag. |
| 3174 | mHistoryLastWritten.wakelockTag = null; |
| 3175 | mHistoryCur.wakelockTag = mHistoryCur.localWakelockTag; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3176 | mHistoryCur.wakelockTag.string = mInitialAcquireWakeName = historyName; |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 3177 | mHistoryCur.wakelockTag.uid = mInitialAcquireWakeUid = uid; |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3178 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 3179 | } |
| 3180 | mWakeLockImportant = true; |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 3181 | } |
| 3182 | mWakeLockNesting++; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3183 | } |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3184 | if (uid >= 0) { |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 3185 | if (mOnBatteryScreenOffTimeBase.isRunning()) { |
| 3186 | // We only update the cpu time when a wake lock is acquired if the screen is off. |
| 3187 | // If the screen is on, we don't distribute the power amongst partial wakelocks. |
| 3188 | if (DEBUG_ENERGY_CPU) { |
| 3189 | Slog.d(TAG, "Updating cpu time because of +wake_lock"); |
| 3190 | } |
| 3191 | requestWakelockCpuUpdate(); |
| 3192 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3193 | getUidStatsLocked(uid).noteStartWakeLocked(pid, name, type, elapsedRealtime); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3194 | } |
| 3195 | } |
| 3196 | |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3197 | public void noteStopWakeLocked(int uid, int pid, String name, String historyName, int type, |
| 3198 | long elapsedRealtime, long uptime) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3199 | uid = mapUid(uid); |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 3200 | if (type == WAKE_TYPE_PARTIAL) { |
| 3201 | mWakeLockNesting--; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 3202 | if (mRecordAllHistory) { |
Dianne Hackborn | fc06413 | 2014-06-02 12:42:12 -0700 | [diff] [blame] | 3203 | if (historyName == null) { |
| 3204 | historyName = name; |
| 3205 | } |
| 3206 | if (mActiveEvents.updateState(HistoryItem.EVENT_WAKE_LOCK_FINISH, historyName, |
| 3207 | uid, 0)) { |
Dianne Hackborn | 536456f | 2014-05-23 16:51:05 -0700 | [diff] [blame] | 3208 | addHistoryEventLocked(elapsedRealtime, uptime, |
Dianne Hackborn | fc06413 | 2014-06-02 12:42:12 -0700 | [diff] [blame] | 3209 | HistoryItem.EVENT_WAKE_LOCK_FINISH, historyName, uid); |
Dianne Hackborn | 536456f | 2014-05-23 16:51:05 -0700 | [diff] [blame] | 3210 | } |
| 3211 | } |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 3212 | if (mWakeLockNesting == 0) { |
| 3213 | mHistoryCur.states &= ~HistoryItem.STATE_WAKE_LOCK_FLAG; |
| 3214 | if (DEBUG_HISTORY) Slog.v(TAG, "Stop wake lock to: " |
| 3215 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 3216 | mInitialAcquireWakeName = null; |
| 3217 | mInitialAcquireWakeUid = -1; |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3218 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 3219 | } |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3220 | } |
| 3221 | if (uid >= 0) { |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 3222 | if (mOnBatteryScreenOffTimeBase.isRunning()) { |
| 3223 | if (DEBUG_ENERGY_CPU) { |
| 3224 | Slog.d(TAG, "Updating cpu time because of -wake_lock"); |
| 3225 | } |
| 3226 | requestWakelockCpuUpdate(); |
| 3227 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3228 | getUidStatsLocked(uid).noteStopWakeLocked(pid, name, type, elapsedRealtime); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3229 | } |
| 3230 | } |
| 3231 | |
Dianne Hackborn | a1f1a3c | 2014-02-24 18:12:28 -0800 | [diff] [blame] | 3232 | public void noteStartWakeFromSourceLocked(WorkSource ws, int pid, String name, |
| 3233 | String historyName, int type, boolean unimportantForLogging) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3234 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3235 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 3236 | final int N = ws.size(); |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 3237 | for (int i=0; i<N; i++) { |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 3238 | noteStartWakeLocked(ws.get(i), pid, name, historyName, type, unimportantForLogging, |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3239 | elapsedRealtime, uptime); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 3240 | } |
| 3241 | } |
| 3242 | |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3243 | public void noteChangeWakelockFromSourceLocked(WorkSource ws, int pid, String name, |
| 3244 | String historyName, int type, WorkSource newWs, int newPid, String newName, |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 3245 | String newHistoryName, int newType, boolean newUnimportantForLogging) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3246 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3247 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 3248 | // For correct semantics, we start the need worksources first, so that we won't |
| 3249 | // make inappropriate history items as if all wake locks went away and new ones |
| 3250 | // appeared. This is okay because tracking of wake locks allows nesting. |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3251 | final int NN = newWs.size(); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 3252 | for (int i=0; i<NN; i++) { |
| 3253 | noteStartWakeLocked(newWs.get(i), newPid, newName, newHistoryName, newType, |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3254 | newUnimportantForLogging, elapsedRealtime, uptime); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 3255 | } |
| 3256 | final int NO = ws.size(); |
| 3257 | for (int i=0; i<NO; i++) { |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3258 | noteStopWakeLocked(ws.get(i), pid, name, historyName, type, elapsedRealtime, uptime); |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 3259 | } |
| 3260 | } |
| 3261 | |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3262 | public void noteStopWakeFromSourceLocked(WorkSource ws, int pid, String name, |
| 3263 | String historyName, int type) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3264 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3265 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 3266 | final int N = ws.size(); |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 3267 | for (int i=0; i<N; i++) { |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3268 | noteStopWakeLocked(ws.get(i), pid, name, historyName, type, elapsedRealtime, uptime); |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 3269 | } |
| 3270 | } |
| 3271 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3272 | void aggregateLastWakeupUptimeLocked(long uptimeMs) { |
| 3273 | if (mLastWakeupReason != null) { |
| 3274 | long deltaUptime = uptimeMs - mLastWakeupUptimeMs; |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 3275 | SamplingTimer timer = getWakeupReasonTimerLocked(mLastWakeupReason); |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 3276 | timer.add(deltaUptime * 1000, 1); // time in in microseconds |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3277 | mLastWakeupReason = null; |
| 3278 | } |
| 3279 | } |
| 3280 | |
| 3281 | public void noteWakeupReasonLocked(String reason) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3282 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3283 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 3284 | if (DEBUG_HISTORY) Slog.v(TAG, "Wakeup reason \"" + reason +"\": " |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 3285 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3286 | aggregateLastWakeupUptimeLocked(uptime); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 3287 | mHistoryCur.wakeReasonTag = mHistoryCur.localWakeReasonTag; |
| 3288 | mHistoryCur.wakeReasonTag.string = reason; |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3289 | mHistoryCur.wakeReasonTag.uid = 0; |
| 3290 | mLastWakeupReason = reason; |
| 3291 | mLastWakeupUptimeMs = uptime; |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3292 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 3293 | } |
| 3294 | |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 3295 | public boolean startAddingCpuLocked() { |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 3296 | mHandler.removeMessages(MSG_UPDATE_WAKELOCKS); |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 3297 | return mOnBatteryInternal; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 3298 | } |
| 3299 | |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 3300 | public void finishAddingCpuLocked(int totalUTime, int totalSTime, int statUserTime, |
| 3301 | int statSystemTime, int statIOWaitTime, int statIrqTime, |
| 3302 | int statSoftIrqTime, int statIdleTime) { |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 3303 | if (DEBUG) Slog.d(TAG, "Adding cpu: tuser=" + totalUTime + " tsys=" + totalSTime |
| 3304 | + " user=" + statUserTime + " sys=" + statSystemTime |
| 3305 | + " io=" + statIOWaitTime + " irq=" + statIrqTime |
| 3306 | + " sirq=" + statSoftIrqTime + " idle=" + statIdleTime); |
| 3307 | mCurStepCpuUserTime += totalUTime; |
| 3308 | mCurStepCpuSystemTime += totalSTime; |
| 3309 | mCurStepStatUserTime += statUserTime; |
| 3310 | mCurStepStatSystemTime += statSystemTime; |
| 3311 | mCurStepStatIOWaitTime += statIOWaitTime; |
| 3312 | mCurStepStatIrqTime += statIrqTime; |
| 3313 | mCurStepStatSoftIrqTime += statSoftIrqTime; |
| 3314 | mCurStepStatIdleTime += statIdleTime; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 3315 | } |
| 3316 | |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3317 | public void noteProcessDiedLocked(int uid, int pid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3318 | uid = mapUid(uid); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3319 | Uid u = mUidStats.get(uid); |
| 3320 | if (u != null) { |
| 3321 | u.mPids.remove(pid); |
| 3322 | } |
| 3323 | } |
| 3324 | |
| 3325 | public long getProcessWakeTime(int uid, int pid, long realtime) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3326 | uid = mapUid(uid); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3327 | Uid u = mUidStats.get(uid); |
| 3328 | if (u != null) { |
| 3329 | Uid.Pid p = u.mPids.get(pid); |
| 3330 | if (p != null) { |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 3331 | return p.mWakeSumMs + (p.mWakeNesting > 0 ? (realtime - p.mWakeStartMs) : 0); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3332 | } |
| 3333 | } |
| 3334 | return 0; |
| 3335 | } |
| 3336 | |
| 3337 | public void reportExcessiveWakeLocked(int uid, String proc, long overTime, long usedTime) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3338 | uid = mapUid(uid); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3339 | Uid u = mUidStats.get(uid); |
| 3340 | if (u != null) { |
| 3341 | u.reportExcessiveWakeLocked(proc, overTime, usedTime); |
| 3342 | } |
| 3343 | } |
| 3344 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 3345 | public void reportExcessiveCpuLocked(int uid, String proc, long overTime, long usedTime) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3346 | uid = mapUid(uid); |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 3347 | Uid u = mUidStats.get(uid); |
| 3348 | if (u != null) { |
| 3349 | u.reportExcessiveCpuLocked(proc, overTime, usedTime); |
| 3350 | } |
| 3351 | } |
| 3352 | |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3353 | int mSensorNesting; |
| 3354 | |
| 3355 | public void noteStartSensorLocked(int uid, int sensor) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3356 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3357 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3358 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3359 | if (mSensorNesting == 0) { |
| 3360 | mHistoryCur.states |= HistoryItem.STATE_SENSOR_ON_FLAG; |
| 3361 | if (DEBUG_HISTORY) Slog.v(TAG, "Start sensor to: " |
| 3362 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3363 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3364 | } |
| 3365 | mSensorNesting++; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3366 | getUidStatsLocked(uid).noteStartSensor(sensor, elapsedRealtime); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3367 | } |
| 3368 | |
| 3369 | public void noteStopSensorLocked(int uid, int sensor) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3370 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3371 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3372 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3373 | mSensorNesting--; |
| 3374 | if (mSensorNesting == 0) { |
| 3375 | mHistoryCur.states &= ~HistoryItem.STATE_SENSOR_ON_FLAG; |
| 3376 | if (DEBUG_HISTORY) Slog.v(TAG, "Stop sensor to: " |
| 3377 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3378 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3379 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3380 | getUidStatsLocked(uid).noteStopSensor(sensor, elapsedRealtime); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3381 | } |
| 3382 | |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3383 | int mGpsNesting; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3384 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3385 | public void noteStartGpsLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3386 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3387 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3388 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3389 | if (mGpsNesting == 0) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3390 | mHistoryCur.states |= HistoryItem.STATE_GPS_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3391 | if (DEBUG_HISTORY) Slog.v(TAG, "Start GPS to: " |
| 3392 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3393 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3394 | } |
| 3395 | mGpsNesting++; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3396 | getUidStatsLocked(uid).noteStartGps(elapsedRealtime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3397 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3398 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3399 | public void noteStopGpsLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3400 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3401 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3402 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3403 | mGpsNesting--; |
| 3404 | if (mGpsNesting == 0) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3405 | mHistoryCur.states &= ~HistoryItem.STATE_GPS_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3406 | if (DEBUG_HISTORY) Slog.v(TAG, "Stop GPS to: " |
| 3407 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3408 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3409 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3410 | getUidStatsLocked(uid).noteStopGps(elapsedRealtime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3411 | } |
Amith Yamasani | 3718aaa | 2009-06-09 06:32:35 -0700 | [diff] [blame] | 3412 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 3413 | public void noteScreenStateLocked(int state) { |
| 3414 | if (mScreenState != state) { |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 3415 | recordDailyStatsIfNeededLocked(true); |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 3416 | final int oldState = mScreenState; |
| 3417 | mScreenState = state; |
| 3418 | if (DEBUG) Slog.v(TAG, "Screen state: oldState=" + Display.stateToString(oldState) |
| 3419 | + ", newState=" + Display.stateToString(state)); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3420 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 3421 | if (state != Display.STATE_UNKNOWN) { |
| 3422 | int stepState = state-1; |
| 3423 | if (stepState < 4) { |
| 3424 | mModStepMode |= (mCurStepMode&STEP_LEVEL_MODE_SCREEN_STATE) ^ stepState; |
| 3425 | mCurStepMode = (mCurStepMode&~STEP_LEVEL_MODE_SCREEN_STATE) | stepState; |
| 3426 | } else { |
| 3427 | Slog.wtf(TAG, "Unexpected screen state: " + state); |
| 3428 | } |
| 3429 | } |
| 3430 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 3431 | if (state == Display.STATE_ON) { |
| 3432 | // Screen turning on. |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3433 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3434 | final long uptime = mClocks.uptimeMillis(); |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 3435 | mHistoryCur.states |= HistoryItem.STATE_SCREEN_ON_FLAG; |
| 3436 | if (DEBUG_HISTORY) Slog.v(TAG, "Screen on to: " |
| 3437 | + Integer.toHexString(mHistoryCur.states)); |
| 3438 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 3439 | mScreenOnTimer.startRunningLocked(elapsedRealtime); |
| 3440 | if (mScreenBrightnessBin >= 0) { |
| 3441 | mScreenBrightnessTimer[mScreenBrightnessBin].startRunningLocked(elapsedRealtime); |
| 3442 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3443 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 3444 | updateTimeBasesLocked(mOnBatteryTimeBase.isRunning(), false, |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3445 | mClocks.uptimeMillis() * 1000, elapsedRealtime * 1000); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 3446 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 3447 | // Fake a wake lock, so we consider the device waked as long |
| 3448 | // as the screen is on. |
| 3449 | noteStartWakeLocked(-1, -1, "screen", null, WAKE_TYPE_PARTIAL, false, |
| 3450 | elapsedRealtime, uptime); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3451 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 3452 | // Update discharge amounts. |
| 3453 | if (mOnBatteryInternal) { |
| 3454 | updateDischargeScreenLevelsLocked(false, true); |
| 3455 | } |
| 3456 | } else if (oldState == Display.STATE_ON) { |
| 3457 | // Screen turning off or dozing. |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3458 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3459 | final long uptime = mClocks.uptimeMillis(); |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 3460 | mHistoryCur.states &= ~HistoryItem.STATE_SCREEN_ON_FLAG; |
| 3461 | if (DEBUG_HISTORY) Slog.v(TAG, "Screen off to: " |
| 3462 | + Integer.toHexString(mHistoryCur.states)); |
| 3463 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 3464 | mScreenOnTimer.stopRunningLocked(elapsedRealtime); |
| 3465 | if (mScreenBrightnessBin >= 0) { |
| 3466 | mScreenBrightnessTimer[mScreenBrightnessBin].stopRunningLocked(elapsedRealtime); |
| 3467 | } |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 3468 | |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3469 | noteStopWakeLocked(-1, -1, "screen", "screen", WAKE_TYPE_PARTIAL, |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 3470 | elapsedRealtime, uptime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3471 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 3472 | updateTimeBasesLocked(mOnBatteryTimeBase.isRunning(), true, |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3473 | mClocks.uptimeMillis() * 1000, elapsedRealtime * 1000); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3474 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 3475 | // Update discharge amounts. |
| 3476 | if (mOnBatteryInternal) { |
| 3477 | updateDischargeScreenLevelsLocked(true, false); |
| 3478 | } |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 3479 | } |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3480 | } |
| 3481 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3482 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3483 | public void noteScreenBrightnessLocked(int brightness) { |
| 3484 | // Bin the brightness. |
| 3485 | int bin = brightness / (256/NUM_SCREEN_BRIGHTNESS_BINS); |
| 3486 | if (bin < 0) bin = 0; |
| 3487 | else if (bin >= NUM_SCREEN_BRIGHTNESS_BINS) bin = NUM_SCREEN_BRIGHTNESS_BINS-1; |
| 3488 | if (mScreenBrightnessBin != bin) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3489 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3490 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3491 | mHistoryCur.states = (mHistoryCur.states&~HistoryItem.STATE_BRIGHTNESS_MASK) |
| 3492 | | (bin << HistoryItem.STATE_BRIGHTNESS_SHIFT); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3493 | if (DEBUG_HISTORY) Slog.v(TAG, "Screen brightness " + bin + " to: " |
| 3494 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3495 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 3496 | if (mScreenState == Display.STATE_ON) { |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3497 | if (mScreenBrightnessBin >= 0) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3498 | mScreenBrightnessTimer[mScreenBrightnessBin].stopRunningLocked(elapsedRealtime); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3499 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3500 | mScreenBrightnessTimer[bin].startRunningLocked(elapsedRealtime); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3501 | } |
| 3502 | mScreenBrightnessBin = bin; |
| 3503 | } |
| 3504 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3505 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 3506 | public void noteUserActivityLocked(int uid, int event) { |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 3507 | if (mOnBatteryInternal) { |
| 3508 | uid = mapUid(uid); |
| 3509 | getUidStatsLocked(uid).noteUserActivityLocked(event); |
| 3510 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3511 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3512 | |
Dianne Hackborn | 280a64e | 2015-07-13 14:48:08 -0700 | [diff] [blame] | 3513 | public void noteWakeUpLocked(String reason, int reasonUid) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3514 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3515 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 280a64e | 2015-07-13 14:48:08 -0700 | [diff] [blame] | 3516 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_SCREEN_WAKE_UP, |
| 3517 | reason, reasonUid); |
| 3518 | } |
| 3519 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 3520 | public void noteInteractiveLocked(boolean interactive) { |
| 3521 | if (mInteractive != interactive) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3522 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 3523 | mInteractive = interactive; |
| 3524 | if (DEBUG) Slog.v(TAG, "Interactive: " + interactive); |
| 3525 | if (interactive) { |
| 3526 | mInteractiveTimer.startRunningLocked(elapsedRealtime); |
| 3527 | } else { |
| 3528 | mInteractiveTimer.stopRunningLocked(elapsedRealtime); |
| 3529 | } |
| 3530 | } |
| 3531 | } |
| 3532 | |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 3533 | public void noteConnectivityChangedLocked(int type, String extra) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3534 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3535 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 3536 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_CONNECTIVITY_CHANGED, |
| 3537 | extra, type); |
| 3538 | mNumConnectivityChange++; |
| 3539 | } |
| 3540 | |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 3541 | public void noteMobileRadioPowerState(int powerState, long timestampNs) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3542 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3543 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 3544 | if (mMobileRadioPowerState != powerState) { |
| 3545 | long realElapsedRealtimeMs; |
| 3546 | final boolean active = |
| 3547 | powerState == DataConnectionRealTimeInfo.DC_POWER_STATE_MEDIUM |
| 3548 | || powerState == DataConnectionRealTimeInfo.DC_POWER_STATE_HIGH; |
| 3549 | if (active) { |
Adam Lesinski | 9acfd81 | 2016-04-19 18:29:50 -0700 | [diff] [blame] | 3550 | mMobileRadioActiveStartTime = realElapsedRealtimeMs = timestampNs / (1000 * 1000); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 3551 | mHistoryCur.states |= HistoryItem.STATE_MOBILE_RADIO_ACTIVE_FLAG; |
| 3552 | } else { |
| 3553 | realElapsedRealtimeMs = timestampNs / (1000*1000); |
Dianne Hackborn | f7097a5 | 2014-05-13 09:56:14 -0700 | [diff] [blame] | 3554 | long lastUpdateTimeMs = mMobileRadioActiveStartTime; |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 3555 | if (realElapsedRealtimeMs < lastUpdateTimeMs) { |
| 3556 | Slog.wtf(TAG, "Data connection inactive timestamp " + realElapsedRealtimeMs |
| 3557 | + " is before start time " + lastUpdateTimeMs); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3558 | realElapsedRealtimeMs = elapsedRealtime; |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 3559 | } else if (realElapsedRealtimeMs < elapsedRealtime) { |
| 3560 | mMobileRadioActiveAdjustedTime.addCountLocked(elapsedRealtime |
| 3561 | - realElapsedRealtimeMs); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3562 | } |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 3563 | mHistoryCur.states &= ~HistoryItem.STATE_MOBILE_RADIO_ACTIVE_FLAG; |
| 3564 | } |
| 3565 | if (DEBUG_HISTORY) Slog.v(TAG, "Mobile network active " + active + " to: " |
| 3566 | + Integer.toHexString(mHistoryCur.states)); |
| 3567 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 3568 | mMobileRadioPowerState = powerState; |
| 3569 | if (active) { |
| 3570 | mMobileRadioActiveTimer.startRunningLocked(elapsedRealtime); |
| 3571 | mMobileRadioActivePerAppTimer.startRunningLocked(elapsedRealtime); |
| 3572 | } else { |
| 3573 | mMobileRadioActiveTimer.stopRunningLocked(realElapsedRealtimeMs); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 3574 | updateMobileRadioStateLocked(realElapsedRealtimeMs, null); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 3575 | mMobileRadioActivePerAppTimer.stopRunningLocked(realElapsedRealtimeMs); |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 3576 | } |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 3577 | } |
| 3578 | } |
| 3579 | |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3580 | public void notePowerSaveMode(boolean enabled) { |
| 3581 | if (mPowerSaveModeEnabled != enabled) { |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 3582 | int stepState = enabled ? STEP_LEVEL_MODE_POWER_SAVE : 0; |
| 3583 | mModStepMode |= (mCurStepMode&STEP_LEVEL_MODE_POWER_SAVE) ^ stepState; |
| 3584 | mCurStepMode = (mCurStepMode&~STEP_LEVEL_MODE_POWER_SAVE) | stepState; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3585 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3586 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3587 | mPowerSaveModeEnabled = enabled; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3588 | if (enabled) { |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3589 | mHistoryCur.states2 |= HistoryItem.STATE2_POWER_SAVE_FLAG; |
| 3590 | if (DEBUG_HISTORY) Slog.v(TAG, "Power save mode enabled to: " |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3591 | + Integer.toHexString(mHistoryCur.states2)); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3592 | mPowerSaveModeEnabledTimer.startRunningLocked(elapsedRealtime); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3593 | } else { |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3594 | mHistoryCur.states2 &= ~HistoryItem.STATE2_POWER_SAVE_FLAG; |
| 3595 | if (DEBUG_HISTORY) Slog.v(TAG, "Power save mode disabled to: " |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3596 | + Integer.toHexString(mHistoryCur.states2)); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3597 | mPowerSaveModeEnabledTimer.stopRunningLocked(elapsedRealtime); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 3598 | } |
| 3599 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 3600 | } |
| 3601 | } |
| 3602 | |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3603 | public void noteDeviceIdleModeLocked(int mode, String activeReason, int activeUid) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3604 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3605 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 3606 | boolean nowIdling = mode == DEVICE_IDLE_MODE_DEEP; |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3607 | if (mDeviceIdling && !nowIdling && activeReason == null) { |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 3608 | // We don't go out of general idling mode until explicitly taken out of |
| 3609 | // device idle through going active or significant motion. |
| 3610 | nowIdling = true; |
| 3611 | } |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3612 | boolean nowLightIdling = mode == DEVICE_IDLE_MODE_LIGHT; |
| 3613 | if (mDeviceLightIdling && !nowLightIdling && !nowIdling && activeReason == null) { |
| 3614 | // We don't go out of general light idling mode until explicitly taken out of |
| 3615 | // device idle through going active or significant motion. |
| 3616 | nowLightIdling = true; |
| 3617 | } |
| 3618 | if (activeReason != null && (mDeviceIdling || mDeviceLightIdling)) { |
| 3619 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_ACTIVE, |
| 3620 | activeReason, activeUid); |
| 3621 | } |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 3622 | if (mDeviceIdling != nowIdling) { |
| 3623 | mDeviceIdling = nowIdling; |
| 3624 | int stepState = nowIdling ? STEP_LEVEL_MODE_DEVICE_IDLE : 0; |
| 3625 | mModStepMode |= (mCurStepMode&STEP_LEVEL_MODE_DEVICE_IDLE) ^ stepState; |
| 3626 | mCurStepMode = (mCurStepMode&~STEP_LEVEL_MODE_DEVICE_IDLE) | stepState; |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3627 | if (nowIdling) { |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 3628 | mDeviceIdlingTimer.startRunningLocked(elapsedRealtime); |
| 3629 | } else { |
| 3630 | mDeviceIdlingTimer.stopRunningLocked(elapsedRealtime); |
| 3631 | } |
| 3632 | } |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3633 | if (mDeviceLightIdling != nowLightIdling) { |
| 3634 | mDeviceLightIdling = nowLightIdling; |
| 3635 | if (nowLightIdling) { |
| 3636 | mDeviceLightIdlingTimer.startRunningLocked(elapsedRealtime); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3637 | } else { |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3638 | mDeviceLightIdlingTimer.stopRunningLocked(elapsedRealtime); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3639 | } |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3640 | } |
| 3641 | if (mDeviceIdleMode != mode) { |
| 3642 | mHistoryCur.states2 = (mHistoryCur.states2 & ~HistoryItem.STATE2_DEVICE_IDLE_MASK) |
| 3643 | | (mode << HistoryItem.STATE2_DEVICE_IDLE_SHIFT); |
| 3644 | if (DEBUG_HISTORY) Slog.v(TAG, "Device idle mode changed to: " |
| 3645 | + Integer.toHexString(mHistoryCur.states2)); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3646 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3647 | long lastDuration = elapsedRealtime - mLastIdleTimeStart; |
| 3648 | mLastIdleTimeStart = elapsedRealtime; |
| 3649 | if (mDeviceIdleMode == DEVICE_IDLE_MODE_LIGHT) { |
| 3650 | if (lastDuration > mLongestLightIdleTime) { |
| 3651 | mLongestLightIdleTime = lastDuration; |
| 3652 | } |
| 3653 | mDeviceIdleModeLightTimer.stopRunningLocked(elapsedRealtime); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 3654 | } else if (mDeviceIdleMode == DEVICE_IDLE_MODE_DEEP) { |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3655 | if (lastDuration > mLongestFullIdleTime) { |
| 3656 | mLongestFullIdleTime = lastDuration; |
| 3657 | } |
| 3658 | mDeviceIdleModeFullTimer.stopRunningLocked(elapsedRealtime); |
| 3659 | } |
| 3660 | if (mode == DEVICE_IDLE_MODE_LIGHT) { |
| 3661 | mDeviceIdleModeLightTimer.startRunningLocked(elapsedRealtime); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 3662 | } else if (mode == DEVICE_IDLE_MODE_DEEP) { |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 3663 | mDeviceIdleModeFullTimer.startRunningLocked(elapsedRealtime); |
| 3664 | } |
| 3665 | mDeviceIdleMode = mode; |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3666 | } |
| 3667 | } |
| 3668 | |
| 3669 | public void notePackageInstalledLocked(String pkgName, int versionCode) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3670 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3671 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3672 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_PACKAGE_INSTALLED, |
| 3673 | pkgName, versionCode); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 3674 | PackageChange pc = new PackageChange(); |
| 3675 | pc.mPackageName = pkgName; |
| 3676 | pc.mUpdate = true; |
| 3677 | pc.mVersionCode = versionCode; |
| 3678 | addPackageChange(pc); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3679 | } |
| 3680 | |
| 3681 | public void notePackageUninstalledLocked(String pkgName) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3682 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3683 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3684 | addHistoryEventLocked(elapsedRealtime, uptime, HistoryItem.EVENT_PACKAGE_UNINSTALLED, |
| 3685 | pkgName, 0); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 3686 | PackageChange pc = new PackageChange(); |
| 3687 | pc.mPackageName = pkgName; |
| 3688 | pc.mUpdate = true; |
| 3689 | addPackageChange(pc); |
| 3690 | } |
| 3691 | |
| 3692 | private void addPackageChange(PackageChange pc) { |
| 3693 | if (mDailyPackageChanges == null) { |
| 3694 | mDailyPackageChanges = new ArrayList<>(); |
| 3695 | } |
| 3696 | mDailyPackageChanges.add(pc); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 3697 | } |
| 3698 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3699 | public void notePhoneOnLocked() { |
| 3700 | if (!mPhoneOn) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3701 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3702 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 3703 | mHistoryCur.states2 |= HistoryItem.STATE2_PHONE_IN_CALL_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3704 | if (DEBUG_HISTORY) Slog.v(TAG, "Phone on to: " |
| 3705 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3706 | addHistoryRecordLocked(elapsedRealtime, uptime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3707 | mPhoneOn = true; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3708 | mPhoneOnTimer.startRunningLocked(elapsedRealtime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3709 | } |
| 3710 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3711 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3712 | public void notePhoneOffLocked() { |
| 3713 | if (mPhoneOn) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3714 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3715 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 3716 | mHistoryCur.states2 &= ~HistoryItem.STATE2_PHONE_IN_CALL_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3717 | if (DEBUG_HISTORY) Slog.v(TAG, "Phone off to: " |
| 3718 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3719 | addHistoryRecordLocked(elapsedRealtime, uptime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3720 | mPhoneOn = false; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3721 | mPhoneOnTimer.stopRunningLocked(elapsedRealtime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3722 | } |
| 3723 | } |
Amith Yamasani | 32dbefd | 2009-06-19 09:21:17 -0700 | [diff] [blame] | 3724 | |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 3725 | void stopAllPhoneSignalStrengthTimersLocked(int except) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3726 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 3727 | for (int i = 0; i < SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 3728 | if (i == except) { |
| 3729 | continue; |
| 3730 | } |
| 3731 | while (mPhoneSignalStrengthsTimer[i].isRunningLocked()) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3732 | mPhoneSignalStrengthsTimer[i].stopRunningLocked(elapsedRealtime); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 3733 | } |
| 3734 | } |
| 3735 | } |
| 3736 | |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3737 | private int fixPhoneServiceState(int state, int signalBin) { |
| 3738 | if (mPhoneSimStateRaw == TelephonyManager.SIM_STATE_ABSENT) { |
| 3739 | // In this case we will always be STATE_OUT_OF_SERVICE, so need |
| 3740 | // to infer that we are scanning from other data. |
| 3741 | if (state == ServiceState.STATE_OUT_OF_SERVICE |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 3742 | && signalBin > SignalStrength.SIGNAL_STRENGTH_NONE_OR_UNKNOWN) { |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3743 | state = ServiceState.STATE_IN_SERVICE; |
| 3744 | } |
| 3745 | } |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 3746 | |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3747 | return state; |
| 3748 | } |
| 3749 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3750 | private void updateAllPhoneStateLocked(int state, int simState, int strengthBin) { |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3751 | boolean scanning = false; |
| 3752 | boolean newHistory = false; |
| 3753 | |
| 3754 | mPhoneServiceStateRaw = state; |
| 3755 | mPhoneSimStateRaw = simState; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3756 | mPhoneSignalStrengthBinRaw = strengthBin; |
| 3757 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3758 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3759 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3760 | |
| 3761 | if (simState == TelephonyManager.SIM_STATE_ABSENT) { |
| 3762 | // In this case we will always be STATE_OUT_OF_SERVICE, so need |
| 3763 | // to infer that we are scanning from other data. |
| 3764 | if (state == ServiceState.STATE_OUT_OF_SERVICE |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3765 | && strengthBin > SignalStrength.SIGNAL_STRENGTH_NONE_OR_UNKNOWN) { |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3766 | state = ServiceState.STATE_IN_SERVICE; |
| 3767 | } |
| 3768 | } |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 3769 | |
| 3770 | // If the phone is powered off, stop all timers. |
| 3771 | if (state == ServiceState.STATE_POWER_OFF) { |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3772 | strengthBin = -1; |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 3773 | |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3774 | // If we are in service, make sure the correct signal string timer is running. |
| 3775 | } else if (state == ServiceState.STATE_IN_SERVICE) { |
| 3776 | // Bin will be changed below. |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 3777 | |
| 3778 | // If we're out of service, we are in the lowest signal strength |
| 3779 | // bin and have the scanning bit set. |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 3780 | } else if (state == ServiceState.STATE_OUT_OF_SERVICE) { |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 3781 | scanning = true; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3782 | strengthBin = SignalStrength.SIGNAL_STRENGTH_NONE_OR_UNKNOWN; |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 3783 | if (!mPhoneSignalScanningTimer.isRunningLocked()) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3784 | mHistoryCur.states |= HistoryItem.STATE_PHONE_SCANNING_FLAG; |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3785 | newHistory = true; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3786 | if (DEBUG_HISTORY) Slog.v(TAG, "Phone started scanning to: " |
| 3787 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3788 | mPhoneSignalScanningTimer.startRunningLocked(elapsedRealtime); |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 3789 | } |
| 3790 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3791 | |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 3792 | if (!scanning) { |
| 3793 | // If we are no longer scanning, then stop the scanning timer. |
| 3794 | if (mPhoneSignalScanningTimer.isRunningLocked()) { |
| 3795 | mHistoryCur.states &= ~HistoryItem.STATE_PHONE_SCANNING_FLAG; |
| 3796 | if (DEBUG_HISTORY) Slog.v(TAG, "Phone stopped scanning to: " |
| 3797 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3798 | newHistory = true; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3799 | mPhoneSignalScanningTimer.stopRunningLocked(elapsedRealtime); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 3800 | } |
| 3801 | } |
| 3802 | |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3803 | if (mPhoneServiceState != state) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3804 | mHistoryCur.states = (mHistoryCur.states&~HistoryItem.STATE_PHONE_STATE_MASK) |
| 3805 | | (state << HistoryItem.STATE_PHONE_STATE_SHIFT); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3806 | if (DEBUG_HISTORY) Slog.v(TAG, "Phone state " + state + " to: " |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3807 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3808 | newHistory = true; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3809 | mPhoneServiceState = state; |
| 3810 | } |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3811 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3812 | if (mPhoneSignalStrengthBin != strengthBin) { |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3813 | if (mPhoneSignalStrengthBin >= 0) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3814 | mPhoneSignalStrengthsTimer[mPhoneSignalStrengthBin].stopRunningLocked( |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3815 | elapsedRealtime); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3816 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3817 | if (strengthBin >= 0) { |
| 3818 | if (!mPhoneSignalStrengthsTimer[strengthBin].isRunningLocked()) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3819 | mPhoneSignalStrengthsTimer[strengthBin].startRunningLocked(elapsedRealtime); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3820 | } |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 3821 | mHistoryCur.states = (mHistoryCur.states&~HistoryItem.STATE_PHONE_SIGNAL_STRENGTH_MASK) |
| 3822 | | (strengthBin << HistoryItem.STATE_PHONE_SIGNAL_STRENGTH_SHIFT); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3823 | if (DEBUG_HISTORY) Slog.v(TAG, "Signal strength " + strengthBin + " to: " |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3824 | + Integer.toHexString(mHistoryCur.states)); |
| 3825 | newHistory = true; |
| 3826 | } else { |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 3827 | stopAllPhoneSignalStrengthTimersLocked(-1); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3828 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3829 | mPhoneSignalStrengthBin = strengthBin; |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3830 | } |
| 3831 | |
| 3832 | if (newHistory) { |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3833 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3834 | } |
| 3835 | } |
| 3836 | |
| 3837 | /** |
| 3838 | * Telephony stack updates the phone state. |
| 3839 | * @param state phone state from ServiceState.getState() |
| 3840 | */ |
| 3841 | public void notePhoneStateLocked(int state, int simState) { |
| 3842 | updateAllPhoneStateLocked(state, simState, mPhoneSignalStrengthBinRaw); |
Amith Yamasani | 32dbefd | 2009-06-19 09:21:17 -0700 | [diff] [blame] | 3843 | } |
| 3844 | |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 3845 | public void notePhoneSignalStrengthLocked(SignalStrength signalStrength) { |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3846 | // Bin the strength. |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 3847 | int bin = signalStrength.getLevel(); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 3848 | updateAllPhoneStateLocked(mPhoneServiceStateRaw, mPhoneSimStateRaw, bin); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3849 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3850 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3851 | public void notePhoneDataConnectionStateLocked(int dataType, boolean hasData) { |
| 3852 | int bin = DATA_CONNECTION_NONE; |
| 3853 | if (hasData) { |
| 3854 | switch (dataType) { |
| 3855 | case TelephonyManager.NETWORK_TYPE_EDGE: |
| 3856 | bin = DATA_CONNECTION_EDGE; |
| 3857 | break; |
| 3858 | case TelephonyManager.NETWORK_TYPE_GPRS: |
| 3859 | bin = DATA_CONNECTION_GPRS; |
| 3860 | break; |
| 3861 | case TelephonyManager.NETWORK_TYPE_UMTS: |
| 3862 | bin = DATA_CONNECTION_UMTS; |
| 3863 | break; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3864 | case TelephonyManager.NETWORK_TYPE_CDMA: |
| 3865 | bin = DATA_CONNECTION_CDMA; |
| 3866 | break; |
| 3867 | case TelephonyManager.NETWORK_TYPE_EVDO_0: |
| 3868 | bin = DATA_CONNECTION_EVDO_0; |
| 3869 | break; |
| 3870 | case TelephonyManager.NETWORK_TYPE_EVDO_A: |
| 3871 | bin = DATA_CONNECTION_EVDO_A; |
| 3872 | break; |
| 3873 | case TelephonyManager.NETWORK_TYPE_1xRTT: |
| 3874 | bin = DATA_CONNECTION_1xRTT; |
| 3875 | break; |
| 3876 | case TelephonyManager.NETWORK_TYPE_HSDPA: |
| 3877 | bin = DATA_CONNECTION_HSDPA; |
| 3878 | break; |
| 3879 | case TelephonyManager.NETWORK_TYPE_HSUPA: |
| 3880 | bin = DATA_CONNECTION_HSUPA; |
| 3881 | break; |
| 3882 | case TelephonyManager.NETWORK_TYPE_HSPA: |
| 3883 | bin = DATA_CONNECTION_HSPA; |
| 3884 | break; |
| 3885 | case TelephonyManager.NETWORK_TYPE_IDEN: |
| 3886 | bin = DATA_CONNECTION_IDEN; |
| 3887 | break; |
| 3888 | case TelephonyManager.NETWORK_TYPE_EVDO_B: |
| 3889 | bin = DATA_CONNECTION_EVDO_B; |
| 3890 | break; |
Robert Greenwalt | 962a990 | 2010-11-02 11:10:25 -0700 | [diff] [blame] | 3891 | case TelephonyManager.NETWORK_TYPE_LTE: |
| 3892 | bin = DATA_CONNECTION_LTE; |
| 3893 | break; |
| 3894 | case TelephonyManager.NETWORK_TYPE_EHRPD: |
| 3895 | bin = DATA_CONNECTION_EHRPD; |
| 3896 | break; |
Patrick Tjin | b71703c | 2013-11-06 09:27:03 -0800 | [diff] [blame] | 3897 | case TelephonyManager.NETWORK_TYPE_HSPAP: |
| 3898 | bin = DATA_CONNECTION_HSPAP; |
| 3899 | break; |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3900 | default: |
| 3901 | bin = DATA_CONNECTION_OTHER; |
| 3902 | break; |
| 3903 | } |
| 3904 | } |
Amith Yamasani | 3718aaa | 2009-06-09 06:32:35 -0700 | [diff] [blame] | 3905 | if (DEBUG) Log.i(TAG, "Phone Data Connection -> " + dataType + " = " + hasData); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3906 | if (mPhoneDataConnectionType != bin) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3907 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3908 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3909 | mHistoryCur.states = (mHistoryCur.states&~HistoryItem.STATE_DATA_CONNECTION_MASK) |
| 3910 | | (bin << HistoryItem.STATE_DATA_CONNECTION_SHIFT); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3911 | if (DEBUG_HISTORY) Slog.v(TAG, "Data connection " + bin + " to: " |
| 3912 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3913 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3914 | if (mPhoneDataConnectionType >= 0) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3915 | mPhoneDataConnectionsTimer[mPhoneDataConnectionType].stopRunningLocked( |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3916 | elapsedRealtime); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3917 | } |
| 3918 | mPhoneDataConnectionType = bin; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3919 | mPhoneDataConnectionsTimer[bin].startRunningLocked(elapsedRealtime); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 3920 | } |
| 3921 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3922 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 3923 | public void noteWifiOnLocked() { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3924 | if (!mWifiOn) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3925 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3926 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 3927 | mHistoryCur.states2 |= HistoryItem.STATE2_WIFI_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3928 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI on to: " |
| 3929 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3930 | addHistoryRecordLocked(elapsedRealtime, uptime); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3931 | mWifiOn = true; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3932 | mWifiOnTimer.startRunningLocked(elapsedRealtime); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 3933 | scheduleSyncExternalStatsLocked("wifi-off", ExternalStatsSync.UPDATE_WIFI); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3934 | } |
| 3935 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3936 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 3937 | public void noteWifiOffLocked() { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3938 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3939 | final long uptime = mClocks.uptimeMillis(); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3940 | if (mWifiOn) { |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 3941 | mHistoryCur.states2 &= ~HistoryItem.STATE2_WIFI_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3942 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI off to: " |
| 3943 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3944 | addHistoryRecordLocked(elapsedRealtime, uptime); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3945 | mWifiOn = false; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3946 | mWifiOnTimer.stopRunningLocked(elapsedRealtime); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 3947 | scheduleSyncExternalStatsLocked("wifi-on", ExternalStatsSync.UPDATE_WIFI); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3948 | } |
| 3949 | } |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 3950 | |
| 3951 | public void noteAudioOnLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3952 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3953 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3954 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 3955 | if (mAudioOnNesting == 0) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3956 | mHistoryCur.states |= HistoryItem.STATE_AUDIO_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3957 | if (DEBUG_HISTORY) Slog.v(TAG, "Audio on to: " |
| 3958 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3959 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3960 | mAudioOnTimer.startRunningLocked(elapsedRealtime); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 3961 | } |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 3962 | mAudioOnNesting++; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3963 | getUidStatsLocked(uid).noteAudioTurnedOnLocked(elapsedRealtime); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 3964 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3965 | |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 3966 | public void noteAudioOffLocked(int uid) { |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 3967 | if (mAudioOnNesting == 0) { |
| 3968 | return; |
| 3969 | } |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3970 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3971 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3972 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 3973 | if (--mAudioOnNesting == 0) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 3974 | mHistoryCur.states &= ~HistoryItem.STATE_AUDIO_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3975 | if (DEBUG_HISTORY) Slog.v(TAG, "Audio off to: " |
| 3976 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3977 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3978 | mAudioOnTimer.stopRunningLocked(elapsedRealtime); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 3979 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3980 | getUidStatsLocked(uid).noteAudioTurnedOffLocked(elapsedRealtime); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 3981 | } |
| 3982 | |
| 3983 | public void noteVideoOnLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 3984 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 3985 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 3986 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 3987 | if (mVideoOnNesting == 0) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 3988 | mHistoryCur.states2 |= HistoryItem.STATE2_VIDEO_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 3989 | if (DEBUG_HISTORY) Slog.v(TAG, "Video on to: " |
| 3990 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 3991 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 3992 | mVideoOnTimer.startRunningLocked(elapsedRealtime); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 3993 | } |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 3994 | mVideoOnNesting++; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 3995 | getUidStatsLocked(uid).noteVideoTurnedOnLocked(elapsedRealtime); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 3996 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 3997 | |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 3998 | public void noteVideoOffLocked(int uid) { |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 3999 | if (mVideoOnNesting == 0) { |
| 4000 | return; |
| 4001 | } |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4002 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4003 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4004 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 4005 | if (--mVideoOnNesting == 0) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 4006 | mHistoryCur.states2 &= ~HistoryItem.STATE2_VIDEO_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4007 | if (DEBUG_HISTORY) Slog.v(TAG, "Video off to: " |
| 4008 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 4009 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4010 | mVideoOnTimer.stopRunningLocked(elapsedRealtime); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 4011 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4012 | getUidStatsLocked(uid).noteVideoTurnedOffLocked(elapsedRealtime); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 4013 | } |
| 4014 | |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 4015 | public void noteResetAudioLocked() { |
| 4016 | if (mAudioOnNesting > 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4017 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4018 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 4019 | mAudioOnNesting = 0; |
| 4020 | mHistoryCur.states &= ~HistoryItem.STATE_AUDIO_ON_FLAG; |
| 4021 | if (DEBUG_HISTORY) Slog.v(TAG, "Audio off to: " |
| 4022 | + Integer.toHexString(mHistoryCur.states)); |
| 4023 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 4024 | mAudioOnTimer.stopAllRunningLocked(elapsedRealtime); |
| 4025 | for (int i=0; i<mUidStats.size(); i++) { |
| 4026 | BatteryStatsImpl.Uid uid = mUidStats.valueAt(i); |
| 4027 | uid.noteResetAudioLocked(elapsedRealtime); |
| 4028 | } |
| 4029 | } |
| 4030 | } |
| 4031 | |
| 4032 | public void noteResetVideoLocked() { |
| 4033 | if (mVideoOnNesting > 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4034 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4035 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 4036 | mAudioOnNesting = 0; |
| 4037 | mHistoryCur.states2 &= ~HistoryItem.STATE2_VIDEO_ON_FLAG; |
| 4038 | if (DEBUG_HISTORY) Slog.v(TAG, "Video off to: " |
| 4039 | + Integer.toHexString(mHistoryCur.states)); |
| 4040 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 4041 | mVideoOnTimer.stopAllRunningLocked(elapsedRealtime); |
| 4042 | for (int i=0; i<mUidStats.size(); i++) { |
| 4043 | BatteryStatsImpl.Uid uid = mUidStats.valueAt(i); |
| 4044 | uid.noteResetVideoLocked(elapsedRealtime); |
| 4045 | } |
| 4046 | } |
| 4047 | } |
| 4048 | |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 4049 | public void noteActivityResumedLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4050 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4051 | getUidStatsLocked(uid).noteActivityResumedLocked(mClocks.elapsedRealtime()); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 4052 | } |
| 4053 | |
| 4054 | public void noteActivityPausedLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4055 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4056 | getUidStatsLocked(uid).noteActivityPausedLocked(mClocks.elapsedRealtime()); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 4057 | } |
| 4058 | |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 4059 | public void noteVibratorOnLocked(int uid, long durationMillis) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4060 | uid = mapUid(uid); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 4061 | getUidStatsLocked(uid).noteVibratorOnLocked(durationMillis); |
| 4062 | } |
| 4063 | |
| 4064 | public void noteVibratorOffLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4065 | uid = mapUid(uid); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 4066 | getUidStatsLocked(uid).noteVibratorOffLocked(); |
| 4067 | } |
| 4068 | |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 4069 | public void noteFlashlightOnLocked(int uid) { |
| 4070 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4071 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4072 | final long uptime = mClocks.uptimeMillis(); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 4073 | if (mFlashlightOnNesting++ == 0) { |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 4074 | mHistoryCur.states2 |= HistoryItem.STATE2_FLASHLIGHT_FLAG; |
| 4075 | if (DEBUG_HISTORY) Slog.v(TAG, "Flashlight on to: " |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 4076 | + Integer.toHexString(mHistoryCur.states2)); |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 4077 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 4078 | mFlashlightOnTimer.startRunningLocked(elapsedRealtime); |
| 4079 | } |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 4080 | getUidStatsLocked(uid).noteFlashlightTurnedOnLocked(elapsedRealtime); |
| 4081 | } |
| 4082 | |
| 4083 | public void noteFlashlightOffLocked(int uid) { |
| 4084 | if (mFlashlightOnNesting == 0) { |
| 4085 | return; |
| 4086 | } |
| 4087 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4088 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4089 | final long uptime = mClocks.uptimeMillis(); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 4090 | if (--mFlashlightOnNesting == 0) { |
| 4091 | mHistoryCur.states2 &= ~HistoryItem.STATE2_FLASHLIGHT_FLAG; |
| 4092 | if (DEBUG_HISTORY) Slog.v(TAG, "Flashlight off to: " |
| 4093 | + Integer.toHexString(mHistoryCur.states2)); |
| 4094 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 4095 | mFlashlightOnTimer.stopRunningLocked(elapsedRealtime); |
| 4096 | } |
| 4097 | getUidStatsLocked(uid).noteFlashlightTurnedOffLocked(elapsedRealtime); |
| 4098 | } |
| 4099 | |
| 4100 | public void noteCameraOnLocked(int uid) { |
| 4101 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4102 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4103 | final long uptime = mClocks.uptimeMillis(); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 4104 | if (mCameraOnNesting++ == 0) { |
| 4105 | mHistoryCur.states2 |= HistoryItem.STATE2_CAMERA_FLAG; |
| 4106 | if (DEBUG_HISTORY) Slog.v(TAG, "Camera on to: " |
| 4107 | + Integer.toHexString(mHistoryCur.states2)); |
| 4108 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 4109 | mCameraOnTimer.startRunningLocked(elapsedRealtime); |
| 4110 | } |
| 4111 | getUidStatsLocked(uid).noteCameraTurnedOnLocked(elapsedRealtime); |
| 4112 | } |
| 4113 | |
| 4114 | public void noteCameraOffLocked(int uid) { |
| 4115 | if (mCameraOnNesting == 0) { |
| 4116 | return; |
| 4117 | } |
| 4118 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4119 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4120 | final long uptime = mClocks.uptimeMillis(); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 4121 | if (--mCameraOnNesting == 0) { |
| 4122 | mHistoryCur.states2 &= ~HistoryItem.STATE2_CAMERA_FLAG; |
| 4123 | if (DEBUG_HISTORY) Slog.v(TAG, "Camera off to: " |
| 4124 | + Integer.toHexString(mHistoryCur.states2)); |
| 4125 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 4126 | mCameraOnTimer.stopRunningLocked(elapsedRealtime); |
| 4127 | } |
| 4128 | getUidStatsLocked(uid).noteCameraTurnedOffLocked(elapsedRealtime); |
| 4129 | } |
| 4130 | |
| 4131 | public void noteResetCameraLocked() { |
| 4132 | if (mCameraOnNesting > 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4133 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4134 | final long uptime = mClocks.uptimeMillis(); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 4135 | mCameraOnNesting = 0; |
| 4136 | mHistoryCur.states2 &= ~HistoryItem.STATE2_CAMERA_FLAG; |
| 4137 | if (DEBUG_HISTORY) Slog.v(TAG, "Camera off to: " |
| 4138 | + Integer.toHexString(mHistoryCur.states2)); |
| 4139 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 4140 | mCameraOnTimer.stopAllRunningLocked(elapsedRealtime); |
| 4141 | for (int i=0; i<mUidStats.size(); i++) { |
| 4142 | BatteryStatsImpl.Uid uid = mUidStats.valueAt(i); |
| 4143 | uid.noteResetCameraLocked(elapsedRealtime); |
| 4144 | } |
| 4145 | } |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 4146 | } |
| 4147 | |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 4148 | public void noteResetFlashlightLocked() { |
| 4149 | if (mFlashlightOnNesting > 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4150 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4151 | final long uptime = mClocks.uptimeMillis(); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 4152 | mFlashlightOnNesting = 0; |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 4153 | mHistoryCur.states2 &= ~HistoryItem.STATE2_FLASHLIGHT_FLAG; |
| 4154 | if (DEBUG_HISTORY) Slog.v(TAG, "Flashlight off to: " |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 4155 | + Integer.toHexString(mHistoryCur.states2)); |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 4156 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 4157 | mFlashlightOnTimer.stopAllRunningLocked(elapsedRealtime); |
| 4158 | for (int i=0; i<mUidStats.size(); i++) { |
| 4159 | BatteryStatsImpl.Uid uid = mUidStats.valueAt(i); |
| 4160 | uid.noteResetFlashlightLocked(elapsedRealtime); |
| 4161 | } |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 4162 | } |
| 4163 | } |
| 4164 | |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 4165 | private void noteBluetoothScanStartedLocked(int uid) { |
| 4166 | uid = mapUid(uid); |
| 4167 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 4168 | final long uptime = SystemClock.uptimeMillis(); |
| 4169 | if (mBluetoothScanNesting == 0) { |
| 4170 | mHistoryCur.states2 |= HistoryItem.STATE2_BLUETOOTH_SCAN_FLAG; |
| 4171 | if (DEBUG_HISTORY) Slog.v(TAG, "BLE scan started for: " |
| 4172 | + Integer.toHexString(mHistoryCur.states2)); |
| 4173 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Adam Lesinski | d9b99be | 2016-03-30 16:58:51 -0700 | [diff] [blame] | 4174 | mBluetoothScanTimer.startRunningLocked(elapsedRealtime); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 4175 | } |
| 4176 | mBluetoothScanNesting++; |
| 4177 | getUidStatsLocked(uid).noteBluetoothScanStartedLocked(elapsedRealtime); |
| 4178 | } |
| 4179 | |
| 4180 | public void noteBluetoothScanStartedFromSourceLocked(WorkSource ws) { |
| 4181 | final int N = ws.size(); |
| 4182 | for (int i = 0; i < N; i++) { |
| 4183 | noteBluetoothScanStartedLocked(ws.get(i)); |
| 4184 | } |
| 4185 | } |
| 4186 | |
| 4187 | private void noteBluetoothScanStoppedLocked(int uid) { |
| 4188 | uid = mapUid(uid); |
| 4189 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 4190 | final long uptime = SystemClock.uptimeMillis(); |
| 4191 | mBluetoothScanNesting--; |
| 4192 | if (mBluetoothScanNesting == 0) { |
| 4193 | mHistoryCur.states2 &= ~HistoryItem.STATE2_BLUETOOTH_SCAN_FLAG; |
| 4194 | if (DEBUG_HISTORY) Slog.v(TAG, "BLE scan stopped for: " |
| 4195 | + Integer.toHexString(mHistoryCur.states2)); |
| 4196 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Adam Lesinski | d9b99be | 2016-03-30 16:58:51 -0700 | [diff] [blame] | 4197 | mBluetoothScanTimer.stopRunningLocked(elapsedRealtime); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 4198 | } |
| 4199 | getUidStatsLocked(uid).noteBluetoothScanStoppedLocked(elapsedRealtime); |
| 4200 | } |
| 4201 | |
| 4202 | public void noteBluetoothScanStoppedFromSourceLocked(WorkSource ws) { |
| 4203 | final int N = ws.size(); |
| 4204 | for (int i = 0; i < N; i++) { |
| 4205 | noteBluetoothScanStoppedLocked(ws.get(i)); |
| 4206 | } |
| 4207 | } |
| 4208 | |
| 4209 | public void noteResetBluetoothScanLocked() { |
| 4210 | if (mBluetoothScanNesting > 0) { |
| 4211 | final long elapsedRealtime = SystemClock.elapsedRealtime(); |
| 4212 | final long uptime = SystemClock.uptimeMillis(); |
| 4213 | mBluetoothScanNesting = 0; |
| 4214 | mHistoryCur.states2 &= ~HistoryItem.STATE2_BLUETOOTH_SCAN_FLAG; |
| 4215 | if (DEBUG_HISTORY) Slog.v(TAG, "BLE can stopped for: " |
| 4216 | + Integer.toHexString(mHistoryCur.states2)); |
| 4217 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 4218 | mBluetoothScanTimer.stopAllRunningLocked(elapsedRealtime); |
| 4219 | for (int i=0; i<mUidStats.size(); i++) { |
| 4220 | BatteryStatsImpl.Uid uid = mUidStats.valueAt(i); |
| 4221 | uid.noteResetBluetoothScanLocked(elapsedRealtime); |
| 4222 | } |
| 4223 | } |
| 4224 | } |
| 4225 | |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 4226 | public void noteWifiRadioPowerState(int powerState, long timestampNs) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4227 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4228 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 4229 | if (mWifiRadioPowerState != powerState) { |
| 4230 | final boolean active = |
| 4231 | powerState == DataConnectionRealTimeInfo.DC_POWER_STATE_MEDIUM |
| 4232 | || powerState == DataConnectionRealTimeInfo.DC_POWER_STATE_HIGH; |
| 4233 | if (active) { |
| 4234 | mHistoryCur.states |= HistoryItem.STATE_WIFI_RADIO_ACTIVE_FLAG; |
| 4235 | } else { |
| 4236 | mHistoryCur.states &= ~HistoryItem.STATE_WIFI_RADIO_ACTIVE_FLAG; |
| 4237 | } |
| 4238 | if (DEBUG_HISTORY) Slog.v(TAG, "Wifi network active " + active + " to: " |
| 4239 | + Integer.toHexString(mHistoryCur.states)); |
| 4240 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 4241 | mWifiRadioPowerState = powerState; |
| 4242 | } |
| 4243 | } |
| 4244 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 4245 | public void noteWifiRunningLocked(WorkSource ws) { |
| 4246 | if (!mGlobalWifiRunning) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4247 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4248 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 4249 | mHistoryCur.states2 |= HistoryItem.STATE2_WIFI_RUNNING_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4250 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI running to: " |
| 4251 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 4252 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 4253 | mGlobalWifiRunning = true; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4254 | mGlobalWifiRunningTimer.startRunningLocked(elapsedRealtime); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 4255 | int N = ws.size(); |
| 4256 | for (int i=0; i<N; i++) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4257 | int uid = mapUid(ws.get(i)); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4258 | getUidStatsLocked(uid).noteWifiRunningLocked(elapsedRealtime); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 4259 | } |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 4260 | scheduleSyncExternalStatsLocked("wifi-running", ExternalStatsSync.UPDATE_WIFI); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 4261 | } else { |
| 4262 | Log.w(TAG, "noteWifiRunningLocked -- called while WIFI running"); |
Eric Shienbrood | d4c5f89 | 2009-03-24 18:13:20 -0700 | [diff] [blame] | 4263 | } |
| 4264 | } |
| 4265 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 4266 | public void noteWifiRunningChangedLocked(WorkSource oldWs, WorkSource newWs) { |
| 4267 | if (mGlobalWifiRunning) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4268 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 4269 | int N = oldWs.size(); |
| 4270 | for (int i=0; i<N; i++) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4271 | int uid = mapUid(oldWs.get(i)); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4272 | getUidStatsLocked(uid).noteWifiStoppedLocked(elapsedRealtime); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 4273 | } |
| 4274 | N = newWs.size(); |
| 4275 | for (int i=0; i<N; i++) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4276 | int uid = mapUid(newWs.get(i)); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4277 | getUidStatsLocked(uid).noteWifiRunningLocked(elapsedRealtime); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 4278 | } |
| 4279 | } else { |
| 4280 | Log.w(TAG, "noteWifiRunningChangedLocked -- called while WIFI not running"); |
| 4281 | } |
| 4282 | } |
| 4283 | |
| 4284 | public void noteWifiStoppedLocked(WorkSource ws) { |
| 4285 | if (mGlobalWifiRunning) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4286 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4287 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 4288 | mHistoryCur.states2 &= ~HistoryItem.STATE2_WIFI_RUNNING_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4289 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI stopped to: " |
| 4290 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 4291 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 4292 | mGlobalWifiRunning = false; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4293 | mGlobalWifiRunningTimer.stopRunningLocked(elapsedRealtime); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 4294 | int N = ws.size(); |
| 4295 | for (int i=0; i<N; i++) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4296 | int uid = mapUid(ws.get(i)); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4297 | getUidStatsLocked(uid).noteWifiStoppedLocked(elapsedRealtime); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 4298 | } |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 4299 | scheduleSyncExternalStatsLocked("wifi-stopped", ExternalStatsSync.UPDATE_WIFI); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 4300 | } else { |
| 4301 | Log.w(TAG, "noteWifiStoppedLocked -- called while WIFI not running"); |
Eric Shienbrood | d4c5f89 | 2009-03-24 18:13:20 -0700 | [diff] [blame] | 4302 | } |
| 4303 | } |
| 4304 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4305 | public void noteWifiStateLocked(int wifiState, String accessPoint) { |
| 4306 | if (DEBUG) Log.i(TAG, "WiFi state -> " + wifiState); |
| 4307 | if (mWifiState != wifiState) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4308 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4309 | if (mWifiState >= 0) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4310 | mWifiStateTimer[mWifiState].stopRunningLocked(elapsedRealtime); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4311 | } |
| 4312 | mWifiState = wifiState; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4313 | mWifiStateTimer[wifiState].startRunningLocked(elapsedRealtime); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 4314 | scheduleSyncExternalStatsLocked("wifi-state", ExternalStatsSync.UPDATE_WIFI); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4315 | } |
| 4316 | } |
| 4317 | |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 4318 | public void noteWifiSupplicantStateChangedLocked(int supplState, boolean failedAuth) { |
| 4319 | if (DEBUG) Log.i(TAG, "WiFi suppl state -> " + supplState); |
| 4320 | if (mWifiSupplState != supplState) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4321 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4322 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 4323 | if (mWifiSupplState >= 0) { |
| 4324 | mWifiSupplStateTimer[mWifiSupplState].stopRunningLocked(elapsedRealtime); |
| 4325 | } |
| 4326 | mWifiSupplState = supplState; |
| 4327 | mWifiSupplStateTimer[supplState].startRunningLocked(elapsedRealtime); |
| 4328 | mHistoryCur.states2 = |
| 4329 | (mHistoryCur.states2&~HistoryItem.STATE2_WIFI_SUPPL_STATE_MASK) |
| 4330 | | (supplState << HistoryItem.STATE2_WIFI_SUPPL_STATE_SHIFT); |
| 4331 | if (DEBUG_HISTORY) Slog.v(TAG, "Wifi suppl state " + supplState + " to: " |
| 4332 | + Integer.toHexString(mHistoryCur.states2)); |
| 4333 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 4334 | } |
| 4335 | } |
| 4336 | |
| 4337 | void stopAllWifiSignalStrengthTimersLocked(int except) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4338 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 4339 | for (int i = 0; i < NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 4340 | if (i == except) { |
| 4341 | continue; |
| 4342 | } |
| 4343 | while (mWifiSignalStrengthsTimer[i].isRunningLocked()) { |
| 4344 | mWifiSignalStrengthsTimer[i].stopRunningLocked(elapsedRealtime); |
| 4345 | } |
| 4346 | } |
| 4347 | } |
| 4348 | |
| 4349 | public void noteWifiRssiChangedLocked(int newRssi) { |
| 4350 | int strengthBin = WifiManager.calculateSignalLevel(newRssi, NUM_WIFI_SIGNAL_STRENGTH_BINS); |
| 4351 | if (DEBUG) Log.i(TAG, "WiFi rssi -> " + newRssi + " bin=" + strengthBin); |
| 4352 | if (mWifiSignalStrengthBin != strengthBin) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4353 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4354 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 4355 | if (mWifiSignalStrengthBin >= 0) { |
| 4356 | mWifiSignalStrengthsTimer[mWifiSignalStrengthBin].stopRunningLocked( |
| 4357 | elapsedRealtime); |
| 4358 | } |
| 4359 | if (strengthBin >= 0) { |
| 4360 | if (!mWifiSignalStrengthsTimer[strengthBin].isRunningLocked()) { |
| 4361 | mWifiSignalStrengthsTimer[strengthBin].startRunningLocked(elapsedRealtime); |
| 4362 | } |
| 4363 | mHistoryCur.states2 = |
| 4364 | (mHistoryCur.states2&~HistoryItem.STATE2_WIFI_SIGNAL_STRENGTH_MASK) |
| 4365 | | (strengthBin << HistoryItem.STATE2_WIFI_SIGNAL_STRENGTH_SHIFT); |
| 4366 | if (DEBUG_HISTORY) Slog.v(TAG, "Wifi signal strength " + strengthBin + " to: " |
| 4367 | + Integer.toHexString(mHistoryCur.states2)); |
| 4368 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 4369 | } else { |
| 4370 | stopAllWifiSignalStrengthTimersLocked(-1); |
| 4371 | } |
| 4372 | mWifiSignalStrengthBin = strengthBin; |
| 4373 | } |
| 4374 | } |
| 4375 | |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4376 | int mWifiFullLockNesting = 0; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4377 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4378 | public void noteFullWifiLockAcquiredLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4379 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4380 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4381 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4382 | if (mWifiFullLockNesting == 0) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4383 | mHistoryCur.states |= HistoryItem.STATE_WIFI_FULL_LOCK_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4384 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI full lock on to: " |
| 4385 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 4386 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4387 | } |
| 4388 | mWifiFullLockNesting++; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4389 | getUidStatsLocked(uid).noteFullWifiLockAcquiredLocked(elapsedRealtime); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4390 | } |
| 4391 | |
| 4392 | public void noteFullWifiLockReleasedLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4393 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4394 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4395 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4396 | mWifiFullLockNesting--; |
| 4397 | if (mWifiFullLockNesting == 0) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4398 | mHistoryCur.states &= ~HistoryItem.STATE_WIFI_FULL_LOCK_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4399 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI full lock off to: " |
| 4400 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 4401 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4402 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4403 | getUidStatsLocked(uid).noteFullWifiLockReleasedLocked(elapsedRealtime); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4404 | } |
| 4405 | |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 4406 | int mWifiScanNesting = 0; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4407 | |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 4408 | public void noteWifiScanStartedLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4409 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4410 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4411 | final long uptime = mClocks.uptimeMillis(); |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 4412 | if (mWifiScanNesting == 0) { |
| 4413 | mHistoryCur.states |= HistoryItem.STATE_WIFI_SCAN_FLAG; |
| 4414 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI scan started for: " |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4415 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 4416 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4417 | } |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 4418 | mWifiScanNesting++; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4419 | getUidStatsLocked(uid).noteWifiScanStartedLocked(elapsedRealtime); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4420 | } |
| 4421 | |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 4422 | public void noteWifiScanStoppedLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4423 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4424 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4425 | final long uptime = mClocks.uptimeMillis(); |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 4426 | mWifiScanNesting--; |
| 4427 | if (mWifiScanNesting == 0) { |
| 4428 | mHistoryCur.states &= ~HistoryItem.STATE_WIFI_SCAN_FLAG; |
| 4429 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI scan stopped for: " |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4430 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 4431 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4432 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4433 | getUidStatsLocked(uid).noteWifiScanStoppedLocked(elapsedRealtime); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4434 | } |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 4435 | |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 4436 | public void noteWifiBatchedScanStartedLocked(int uid, int csph) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4437 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4438 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4439 | getUidStatsLocked(uid).noteWifiBatchedScanStartedLocked(csph, elapsedRealtime); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 4440 | } |
| 4441 | |
| 4442 | public void noteWifiBatchedScanStoppedLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4443 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4444 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4445 | getUidStatsLocked(uid).noteWifiBatchedScanStoppedLocked(elapsedRealtime); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 4446 | } |
| 4447 | |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4448 | int mWifiMulticastNesting = 0; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4449 | |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 4450 | public void noteWifiMulticastEnabledLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4451 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4452 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4453 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4454 | if (mWifiMulticastNesting == 0) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4455 | mHistoryCur.states |= HistoryItem.STATE_WIFI_MULTICAST_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4456 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI multicast on to: " |
| 4457 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 4458 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4459 | } |
| 4460 | mWifiMulticastNesting++; |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4461 | getUidStatsLocked(uid).noteWifiMulticastEnabledLocked(elapsedRealtime); |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 4462 | } |
| 4463 | |
| 4464 | public void noteWifiMulticastDisabledLocked(int uid) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 4465 | uid = mapUid(uid); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4466 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 4467 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4468 | mWifiMulticastNesting--; |
| 4469 | if (mWifiMulticastNesting == 0) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 4470 | mHistoryCur.states &= ~HistoryItem.STATE_WIFI_MULTICAST_ON_FLAG; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4471 | if (DEBUG_HISTORY) Slog.v(TAG, "WIFI multicast off to: " |
| 4472 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 4473 | addHistoryRecordLocked(elapsedRealtime, uptime); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 4474 | } |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4475 | getUidStatsLocked(uid).noteWifiMulticastDisabledLocked(elapsedRealtime); |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 4476 | } |
| 4477 | |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 4478 | public void noteFullWifiLockAcquiredFromSourceLocked(WorkSource ws) { |
| 4479 | int N = ws.size(); |
| 4480 | for (int i=0; i<N; i++) { |
| 4481 | noteFullWifiLockAcquiredLocked(ws.get(i)); |
| 4482 | } |
| 4483 | } |
| 4484 | |
| 4485 | public void noteFullWifiLockReleasedFromSourceLocked(WorkSource ws) { |
| 4486 | int N = ws.size(); |
| 4487 | for (int i=0; i<N; i++) { |
| 4488 | noteFullWifiLockReleasedLocked(ws.get(i)); |
| 4489 | } |
| 4490 | } |
| 4491 | |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 4492 | public void noteWifiScanStartedFromSourceLocked(WorkSource ws) { |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 4493 | int N = ws.size(); |
| 4494 | for (int i=0; i<N; i++) { |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 4495 | noteWifiScanStartedLocked(ws.get(i)); |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 4496 | } |
| 4497 | } |
| 4498 | |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 4499 | public void noteWifiScanStoppedFromSourceLocked(WorkSource ws) { |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 4500 | int N = ws.size(); |
| 4501 | for (int i=0; i<N; i++) { |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 4502 | noteWifiScanStoppedLocked(ws.get(i)); |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 4503 | } |
| 4504 | } |
| 4505 | |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 4506 | public void noteWifiBatchedScanStartedFromSourceLocked(WorkSource ws, int csph) { |
| 4507 | int N = ws.size(); |
| 4508 | for (int i=0; i<N; i++) { |
| 4509 | noteWifiBatchedScanStartedLocked(ws.get(i), csph); |
| 4510 | } |
| 4511 | } |
| 4512 | |
| 4513 | public void noteWifiBatchedScanStoppedFromSourceLocked(WorkSource ws) { |
| 4514 | int N = ws.size(); |
| 4515 | for (int i=0; i<N; i++) { |
| 4516 | noteWifiBatchedScanStoppedLocked(ws.get(i)); |
| 4517 | } |
| 4518 | } |
| 4519 | |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 4520 | public void noteWifiMulticastEnabledFromSourceLocked(WorkSource ws) { |
| 4521 | int N = ws.size(); |
| 4522 | for (int i=0; i<N; i++) { |
| 4523 | noteWifiMulticastEnabledLocked(ws.get(i)); |
| 4524 | } |
| 4525 | } |
| 4526 | |
| 4527 | public void noteWifiMulticastDisabledFromSourceLocked(WorkSource ws) { |
| 4528 | int N = ws.size(); |
| 4529 | for (int i=0; i<N; i++) { |
| 4530 | noteWifiMulticastDisabledLocked(ws.get(i)); |
| 4531 | } |
| 4532 | } |
| 4533 | |
Dianne Hackborn | d0c5b9a | 2014-02-21 16:19:05 -0800 | [diff] [blame] | 4534 | private static String[] includeInStringArray(String[] array, String str) { |
| 4535 | if (ArrayUtils.indexOf(array, str) >= 0) { |
| 4536 | return array; |
| 4537 | } |
| 4538 | String[] newArray = new String[array.length+1]; |
| 4539 | System.arraycopy(array, 0, newArray, 0, array.length); |
| 4540 | newArray[array.length] = str; |
| 4541 | return newArray; |
| 4542 | } |
| 4543 | |
| 4544 | private static String[] excludeFromStringArray(String[] array, String str) { |
| 4545 | int index = ArrayUtils.indexOf(array, str); |
| 4546 | if (index >= 0) { |
| 4547 | String[] newArray = new String[array.length-1]; |
| 4548 | if (index > 0) { |
| 4549 | System.arraycopy(array, 0, newArray, 0, index); |
| 4550 | } |
| 4551 | if (index < array.length-1) { |
| 4552 | System.arraycopy(array, index+1, newArray, index, array.length-index-1); |
| 4553 | } |
| 4554 | return newArray; |
| 4555 | } |
| 4556 | return array; |
| 4557 | } |
| 4558 | |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 4559 | public void noteNetworkInterfaceTypeLocked(String iface, int networkType) { |
Jeff Sharkey | 9da2f1e | 2014-08-14 12:55:00 -0700 | [diff] [blame] | 4560 | if (TextUtils.isEmpty(iface)) return; |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 4561 | if (ConnectivityManager.isNetworkTypeMobile(networkType)) { |
Dianne Hackborn | d0c5b9a | 2014-02-21 16:19:05 -0800 | [diff] [blame] | 4562 | mMobileIfaces = includeInStringArray(mMobileIfaces, iface); |
| 4563 | if (DEBUG) Slog.d(TAG, "Note mobile iface " + iface + ": " + mMobileIfaces); |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 4564 | } else { |
Dianne Hackborn | d0c5b9a | 2014-02-21 16:19:05 -0800 | [diff] [blame] | 4565 | mMobileIfaces = excludeFromStringArray(mMobileIfaces, iface); |
| 4566 | if (DEBUG) Slog.d(TAG, "Note non-mobile iface " + iface + ": " + mMobileIfaces); |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 4567 | } |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 4568 | if (ConnectivityManager.isNetworkTypeWifi(networkType)) { |
Dianne Hackborn | d0c5b9a | 2014-02-21 16:19:05 -0800 | [diff] [blame] | 4569 | mWifiIfaces = includeInStringArray(mWifiIfaces, iface); |
| 4570 | if (DEBUG) Slog.d(TAG, "Note wifi iface " + iface + ": " + mWifiIfaces); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 4571 | } else { |
Dianne Hackborn | d0c5b9a | 2014-02-21 16:19:05 -0800 | [diff] [blame] | 4572 | mWifiIfaces = excludeFromStringArray(mWifiIfaces, iface); |
| 4573 | if (DEBUG) Slog.d(TAG, "Note non-wifi iface " + iface + ": " + mWifiIfaces); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 4574 | } |
| 4575 | } |
| 4576 | |
| 4577 | public void noteNetworkStatsEnabledLocked() { |
| 4578 | // During device boot, qtaguid isn't enabled until after the inital |
| 4579 | // loading of battery stats. Now that they're enabled, take our initial |
| 4580 | // snapshot for future delta calculation. |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4581 | updateMobileRadioStateLocked(mClocks.elapsedRealtime(), null); |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 4582 | updateWifiStateLocked(null); |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 4583 | } |
| 4584 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4585 | @Override public long getScreenOnTime(long elapsedRealtimeUs, int which) { |
| 4586 | return mScreenOnTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4587 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4588 | |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 4589 | @Override public int getScreenOnCount(int which) { |
| 4590 | return mScreenOnTimer.getCountLocked(which); |
| 4591 | } |
| 4592 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4593 | @Override public long getScreenBrightnessTime(int brightnessBin, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4594 | long elapsedRealtimeUs, int which) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 4595 | return mScreenBrightnessTimer[brightnessBin].getTotalTimeLocked( |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4596 | elapsedRealtimeUs, which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4597 | } |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 4598 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 4599 | @Override public long getInteractiveTime(long elapsedRealtimeUs, int which) { |
| 4600 | return mInteractiveTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4601 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4602 | |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4603 | @Override public long getPowerSaveModeEnabledTime(long elapsedRealtimeUs, int which) { |
| 4604 | return mPowerSaveModeEnabledTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 4605 | } |
| 4606 | |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4607 | @Override public int getPowerSaveModeEnabledCount(int which) { |
| 4608 | return mPowerSaveModeEnabledTimer.getCountLocked(which); |
| 4609 | } |
| 4610 | |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4611 | @Override public long getDeviceIdleModeTime(int mode, long elapsedRealtimeUs, |
| 4612 | int which) { |
| 4613 | switch (mode) { |
| 4614 | case DEVICE_IDLE_MODE_LIGHT: |
| 4615 | return mDeviceIdleModeLightTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 4616 | case DEVICE_IDLE_MODE_DEEP: |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4617 | return mDeviceIdleModeFullTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
| 4618 | } |
| 4619 | return 0; |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 4620 | } |
| 4621 | |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4622 | @Override public int getDeviceIdleModeCount(int mode, int which) { |
| 4623 | switch (mode) { |
| 4624 | case DEVICE_IDLE_MODE_LIGHT: |
| 4625 | return mDeviceIdleModeLightTimer.getCountLocked(which); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 4626 | case DEVICE_IDLE_MODE_DEEP: |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4627 | return mDeviceIdleModeFullTimer.getCountLocked(which); |
| 4628 | } |
| 4629 | return 0; |
Dianne Hackborn | cbefd8d | 2014-05-14 11:42:00 -0700 | [diff] [blame] | 4630 | } |
| 4631 | |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4632 | @Override public long getLongestDeviceIdleModeTime(int mode) { |
| 4633 | switch (mode) { |
| 4634 | case DEVICE_IDLE_MODE_LIGHT: |
| 4635 | return mLongestLightIdleTime; |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 4636 | case DEVICE_IDLE_MODE_DEEP: |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4637 | return mLongestFullIdleTime; |
| 4638 | } |
| 4639 | return 0; |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 4640 | } |
| 4641 | |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4642 | @Override public long getDeviceIdlingTime(int mode, long elapsedRealtimeUs, int which) { |
| 4643 | switch (mode) { |
| 4644 | case DEVICE_IDLE_MODE_LIGHT: |
| 4645 | return mDeviceLightIdlingTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 4646 | case DEVICE_IDLE_MODE_DEEP: |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4647 | return mDeviceIdlingTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
| 4648 | } |
| 4649 | return 0; |
| 4650 | } |
| 4651 | |
| 4652 | @Override public int getDeviceIdlingCount(int mode, int which) { |
| 4653 | switch (mode) { |
| 4654 | case DEVICE_IDLE_MODE_LIGHT: |
| 4655 | return mDeviceLightIdlingTimer.getCountLocked(which); |
Dianne Hackborn | 2fefbcf | 2016-03-18 15:34:54 -0700 | [diff] [blame] | 4656 | case DEVICE_IDLE_MODE_DEEP: |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 4657 | return mDeviceIdlingTimer.getCountLocked(which); |
| 4658 | } |
| 4659 | return 0; |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 4660 | } |
| 4661 | |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 4662 | @Override public int getNumConnectivityChange(int which) { |
| 4663 | int val = mNumConnectivityChange; |
| 4664 | if (which == STATS_CURRENT) { |
| 4665 | val -= mLoadedNumConnectivityChange; |
| 4666 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 4667 | val -= mUnpluggedNumConnectivityChange; |
| 4668 | } |
| 4669 | return val; |
| 4670 | } |
| 4671 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4672 | @Override public long getPhoneOnTime(long elapsedRealtimeUs, int which) { |
| 4673 | return mPhoneOnTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4674 | } |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 4675 | |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 4676 | @Override public int getPhoneOnCount(int which) { |
| 4677 | return mPhoneOnTimer.getCountLocked(which); |
| 4678 | } |
| 4679 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4680 | @Override public long getPhoneSignalStrengthTime(int strengthBin, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4681 | long elapsedRealtimeUs, int which) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 4682 | return mPhoneSignalStrengthsTimer[strengthBin].getTotalTimeLocked( |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4683 | elapsedRealtimeUs, which); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4684 | } |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 4685 | |
| 4686 | @Override public long getPhoneSignalScanningTime( |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4687 | long elapsedRealtimeUs, int which) { |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 4688 | return mPhoneSignalScanningTimer.getTotalTimeLocked( |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4689 | elapsedRealtimeUs, which); |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 4690 | } |
| 4691 | |
Catherine Liu | fb90081 | 2012-07-17 14:12:56 -0500 | [diff] [blame] | 4692 | @Override public int getPhoneSignalStrengthCount(int strengthBin, int which) { |
| 4693 | return mPhoneSignalStrengthsTimer[strengthBin].getCountLocked(which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4694 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4695 | |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4696 | @Override public long getPhoneDataConnectionTime(int dataType, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4697 | long elapsedRealtimeUs, int which) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 4698 | return mPhoneDataConnectionsTimer[dataType].getTotalTimeLocked( |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4699 | elapsedRealtimeUs, which); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 4700 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4701 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4702 | @Override public int getPhoneDataConnectionCount(int dataType, int which) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 4703 | return mPhoneDataConnectionsTimer[dataType].getCountLocked(which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4704 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4705 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4706 | @Override public long getMobileRadioActiveTime(long elapsedRealtimeUs, int which) { |
| 4707 | return mMobileRadioActiveTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 4708 | } |
| 4709 | |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4710 | @Override public int getMobileRadioActiveCount(int which) { |
| 4711 | return mMobileRadioActiveTimer.getCountLocked(which); |
| 4712 | } |
| 4713 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 4714 | @Override public long getMobileRadioActiveAdjustedTime(int which) { |
| 4715 | return mMobileRadioActiveAdjustedTime.getCountLocked(which); |
| 4716 | } |
| 4717 | |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4718 | @Override public long getMobileRadioActiveUnknownTime(int which) { |
| 4719 | return mMobileRadioActiveUnknownTime.getCountLocked(which); |
| 4720 | } |
| 4721 | |
| 4722 | @Override public int getMobileRadioActiveUnknownCount(int which) { |
| 4723 | return (int)mMobileRadioActiveUnknownCount.getCountLocked(which); |
| 4724 | } |
| 4725 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4726 | @Override public long getWifiOnTime(long elapsedRealtimeUs, int which) { |
| 4727 | return mWifiOnTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4728 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4729 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4730 | @Override public long getGlobalWifiRunningTime(long elapsedRealtimeUs, int which) { |
| 4731 | return mGlobalWifiRunningTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Eric Shienbrood | d4c5f89 | 2009-03-24 18:13:20 -0700 | [diff] [blame] | 4732 | } |
| 4733 | |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4734 | @Override public long getWifiStateTime(int wifiState, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4735 | long elapsedRealtimeUs, int which) { |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4736 | return mWifiStateTimer[wifiState].getTotalTimeLocked( |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 4737 | elapsedRealtimeUs, which); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 4738 | } |
| 4739 | |
| 4740 | @Override public int getWifiStateCount(int wifiState, int which) { |
| 4741 | return mWifiStateTimer[wifiState].getCountLocked(which); |
| 4742 | } |
| 4743 | |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 4744 | @Override public long getWifiSupplStateTime(int state, |
| 4745 | long elapsedRealtimeUs, int which) { |
| 4746 | return mWifiSupplStateTimer[state].getTotalTimeLocked( |
| 4747 | elapsedRealtimeUs, which); |
| 4748 | } |
| 4749 | |
| 4750 | @Override public int getWifiSupplStateCount(int state, int which) { |
| 4751 | return mWifiSupplStateTimer[state].getCountLocked(which); |
| 4752 | } |
| 4753 | |
| 4754 | @Override public long getWifiSignalStrengthTime(int strengthBin, |
| 4755 | long elapsedRealtimeUs, int which) { |
| 4756 | return mWifiSignalStrengthsTimer[strengthBin].getTotalTimeLocked( |
| 4757 | elapsedRealtimeUs, which); |
| 4758 | } |
| 4759 | |
| 4760 | @Override public int getWifiSignalStrengthCount(int strengthBin, int which) { |
| 4761 | return mWifiSignalStrengthsTimer[strengthBin].getCountLocked(which); |
| 4762 | } |
| 4763 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 4764 | @Override |
| 4765 | public ControllerActivityCounter getBluetoothControllerActivity() { |
| 4766 | return mBluetoothActivity; |
Adam Lesinski | 1739076 | 2015-04-10 13:17:47 -0700 | [diff] [blame] | 4767 | } |
| 4768 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 4769 | @Override |
| 4770 | public ControllerActivityCounter getWifiControllerActivity() { |
| 4771 | return mWifiActivity; |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 4772 | } |
| 4773 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 4774 | @Override |
| 4775 | public ControllerActivityCounter getModemControllerActivity() { |
| 4776 | return mModemActivity; |
Adam Lesinski | 1739076 | 2015-04-10 13:17:47 -0700 | [diff] [blame] | 4777 | } |
| 4778 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 4779 | @Override |
| 4780 | public boolean hasBluetoothActivityReporting() { |
| 4781 | return mHasBluetoothReporting; |
| 4782 | } |
| 4783 | |
| 4784 | @Override |
| 4785 | public boolean hasWifiActivityReporting() { |
| 4786 | return mHasWifiReporting; |
| 4787 | } |
| 4788 | |
| 4789 | @Override |
| 4790 | public boolean hasModemActivityReporting() { |
| 4791 | return mHasModemReporting; |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 4792 | } |
| 4793 | |
Ruben Brunk | 5b1308f | 2015-06-03 18:49:27 -0700 | [diff] [blame] | 4794 | @Override |
| 4795 | public long getFlashlightOnTime(long elapsedRealtimeUs, int which) { |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 4796 | return mFlashlightOnTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
| 4797 | } |
| 4798 | |
Ruben Brunk | 5b1308f | 2015-06-03 18:49:27 -0700 | [diff] [blame] | 4799 | @Override |
| 4800 | public long getFlashlightOnCount(int which) { |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 4801 | return mFlashlightOnTimer.getCountLocked(which); |
| 4802 | } |
| 4803 | |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 4804 | @Override |
Ruben Brunk | 5b1308f | 2015-06-03 18:49:27 -0700 | [diff] [blame] | 4805 | public long getCameraOnTime(long elapsedRealtimeUs, int which) { |
| 4806 | return mCameraOnTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
| 4807 | } |
| 4808 | |
| 4809 | @Override |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 4810 | public long getBluetoothScanTime(long elapsedRealtimeUs, int which) { |
| 4811 | return mBluetoothScanTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
| 4812 | } |
| 4813 | |
| 4814 | @Override |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4815 | public long getNetworkActivityBytes(int type, int which) { |
| 4816 | if (type >= 0 && type < mNetworkByteActivityCounters.length) { |
| 4817 | return mNetworkByteActivityCounters[type].getCountLocked(which); |
| 4818 | } else { |
| 4819 | return 0; |
| 4820 | } |
| 4821 | } |
| 4822 | |
| 4823 | @Override |
| 4824 | public long getNetworkActivityPackets(int type, int which) { |
| 4825 | if (type >= 0 && type < mNetworkPacketActivityCounters.length) { |
| 4826 | return mNetworkPacketActivityCounters[type].getCountLocked(which); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 4827 | } else { |
| 4828 | return 0; |
| 4829 | } |
| 4830 | } |
| 4831 | |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 4832 | @Override public long getStartClockTime() { |
Dianne Hackborn | d48954f | 2015-07-22 17:20:33 -0700 | [diff] [blame] | 4833 | final long currentTime = System.currentTimeMillis(); |
| 4834 | if (ensureStartClockTime(currentTime)) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4835 | recordCurrentTimeChangeLocked(currentTime, mClocks.elapsedRealtime(), |
| 4836 | mClocks.uptimeMillis()); |
Dianne Hackborn | 7d9eefd | 2014-08-27 18:30:31 -0700 | [diff] [blame] | 4837 | } |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 4838 | return mStartClockTime; |
| 4839 | } |
| 4840 | |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 4841 | @Override public String getStartPlatformVersion() { |
| 4842 | return mStartPlatformVersion; |
| 4843 | } |
| 4844 | |
| 4845 | @Override public String getEndPlatformVersion() { |
| 4846 | return mEndPlatformVersion; |
| 4847 | } |
| 4848 | |
| 4849 | @Override public int getParcelVersion() { |
| 4850 | return VERSION; |
| 4851 | } |
| 4852 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4853 | @Override public boolean getIsOnBattery() { |
| 4854 | return mOnBattery; |
| 4855 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4856 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4857 | @Override public SparseArray<? extends BatteryStats.Uid> getUidStats() { |
| 4858 | return mUidStats; |
| 4859 | } |
| 4860 | |
| 4861 | /** |
| 4862 | * The statistics associated with a particular uid. |
| 4863 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4864 | public static class Uid extends BatteryStats.Uid { |
| 4865 | /** |
| 4866 | * BatteryStatsImpl that we are associated with. |
| 4867 | */ |
| 4868 | protected BatteryStatsImpl mBsi; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4869 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4870 | final int mUid; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4871 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 4872 | boolean mWifiRunning; |
| 4873 | StopwatchTimer mWifiRunningTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4874 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4875 | boolean mFullWifiLockOut; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 4876 | StopwatchTimer mFullWifiLockTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4877 | |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 4878 | boolean mWifiScanStarted; |
| 4879 | StopwatchTimer mWifiScanTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4880 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 4881 | static final int NO_BATCHED_SCAN_STARTED = -1; |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 4882 | int mWifiBatchedScanBinStarted = NO_BATCHED_SCAN_STARTED; |
| 4883 | StopwatchTimer[] mWifiBatchedScanTimer; |
| 4884 | |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 4885 | boolean mWifiMulticastEnabled; |
| 4886 | StopwatchTimer mWifiMulticastTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4887 | |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 4888 | StopwatchTimer mAudioTurnedOnTimer; |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 4889 | StopwatchTimer mVideoTurnedOnTimer; |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 4890 | StopwatchTimer mFlashlightTurnedOnTimer; |
| 4891 | StopwatchTimer mCameraTurnedOnTimer; |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 4892 | StopwatchTimer mForegroundActivityTimer; |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 4893 | StopwatchTimer mBluetoothScanTimer; |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 4894 | |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 4895 | int mProcessState = ActivityManager.PROCESS_STATE_NONEXISTENT; |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 4896 | StopwatchTimer[] mProcessStateTimer; |
| 4897 | |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 4898 | BatchTimer mVibratorOnTimer; |
| 4899 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 4900 | Counter[] mUserActivityCounters; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4901 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 4902 | LongSamplingCounter[] mNetworkByteActivityCounters; |
| 4903 | LongSamplingCounter[] mNetworkPacketActivityCounters; |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 4904 | LongSamplingCounter mMobileRadioActiveTime; |
| 4905 | LongSamplingCounter mMobileRadioActiveCount; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 4906 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4907 | /** |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 4908 | * 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] | 4909 | * Can be null if the UID has had no such activity. |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 4910 | */ |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 4911 | private ControllerActivityCounterImpl mWifiControllerActivity; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 4912 | |
| 4913 | /** |
| 4914 | * 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] | 4915 | * Can be null if the UID has had no such activity. |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 4916 | */ |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 4917 | private ControllerActivityCounterImpl mBluetoothControllerActivity; |
| 4918 | |
| 4919 | /** |
| 4920 | * The amount of time this uid has kept the Modem controller in idle, tx, and rx mode. |
| 4921 | * Can be null if the UID has had no such activity. |
| 4922 | */ |
| 4923 | private ControllerActivityCounterImpl mModemControllerActivity; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 4924 | |
| 4925 | /** |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 4926 | * The CPU times we had at the last history details update. |
| 4927 | */ |
| 4928 | long mLastStepUserTime; |
| 4929 | long mLastStepSystemTime; |
| 4930 | long mCurStepUserTime; |
| 4931 | long mCurStepSystemTime; |
| 4932 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4933 | LongSamplingCounter mUserCpuTime; |
| 4934 | LongSamplingCounter mSystemCpuTime; |
| 4935 | LongSamplingCounter mCpuPower; |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 4936 | LongSamplingCounter[][] mCpuClusterSpeed; |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 4937 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 4938 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4939 | * The statistics we have collected for this uid's wake locks. |
| 4940 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4941 | final OverflowArrayMap<Wakelock> mWakelockStats; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4942 | |
| 4943 | /** |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 4944 | * The statistics we have collected for this uid's syncs. |
| 4945 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4946 | final OverflowArrayMap<StopwatchTimer> mSyncStats; |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 4947 | |
| 4948 | /** |
| 4949 | * The statistics we have collected for this uid's jobs. |
| 4950 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4951 | final OverflowArrayMap<StopwatchTimer> mJobStats; |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 4952 | |
| 4953 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4954 | * The statistics we have collected for this uid's sensor activations. |
| 4955 | */ |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 4956 | final SparseArray<Sensor> mSensorStats = new SparseArray<>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4957 | |
| 4958 | /** |
| 4959 | * The statistics we have collected for this uid's processes. |
| 4960 | */ |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 4961 | final ArrayMap<String, Proc> mProcessStats = new ArrayMap<>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4962 | |
| 4963 | /** |
| 4964 | * The statistics we have collected for this uid's processes. |
| 4965 | */ |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 4966 | final ArrayMap<String, Pkg> mPackageStats = new ArrayMap<>(); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 4967 | |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4968 | /** |
| 4969 | * The transient wake stats we have collected for this uid's pids. |
| 4970 | */ |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 4971 | final SparseArray<Pid> mPids = new SparseArray<>(); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 4972 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4973 | public Uid(BatteryStatsImpl bsi, int uid) { |
| 4974 | mBsi = bsi; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4975 | mUid = uid; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 4976 | |
| 4977 | mUserCpuTime = new LongSamplingCounter(mBsi.mOnBatteryTimeBase); |
| 4978 | mSystemCpuTime = new LongSamplingCounter(mBsi.mOnBatteryTimeBase); |
| 4979 | mCpuPower = new LongSamplingCounter(mBsi.mOnBatteryTimeBase); |
| 4980 | |
| 4981 | mWakelockStats = mBsi.new OverflowArrayMap<Wakelock>() { |
| 4982 | @Override public Wakelock instantiateObject() { |
| 4983 | return new Wakelock(mBsi, Uid.this); |
| 4984 | } |
| 4985 | }; |
| 4986 | mSyncStats = mBsi.new OverflowArrayMap<StopwatchTimer>() { |
| 4987 | @Override public StopwatchTimer instantiateObject() { |
| 4988 | return new StopwatchTimer(mBsi.mClocks, Uid.this, SYNC, null, |
| 4989 | mBsi.mOnBatteryTimeBase); |
| 4990 | } |
| 4991 | }; |
| 4992 | mJobStats = mBsi.new OverflowArrayMap<StopwatchTimer>() { |
| 4993 | @Override public StopwatchTimer instantiateObject() { |
| 4994 | return new StopwatchTimer(mBsi.mClocks, Uid.this, JOB, null, |
| 4995 | mBsi.mOnBatteryTimeBase); |
| 4996 | } |
| 4997 | }; |
| 4998 | |
| 4999 | mWifiRunningTimer = new StopwatchTimer(mBsi.mClocks, this, WIFI_RUNNING, |
| 5000 | mBsi.mWifiRunningTimers, mBsi.mOnBatteryTimeBase); |
| 5001 | mFullWifiLockTimer = new StopwatchTimer(mBsi.mClocks, this, FULL_WIFI_LOCK, |
| 5002 | mBsi.mFullWifiLockTimers, mBsi.mOnBatteryTimeBase); |
| 5003 | mWifiScanTimer = new StopwatchTimer(mBsi.mClocks, this, WIFI_SCAN, |
| 5004 | mBsi.mWifiScanTimers, mBsi.mOnBatteryTimeBase); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 5005 | mWifiBatchedScanTimer = new StopwatchTimer[NUM_WIFI_BATCHED_SCAN_BINS]; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5006 | mWifiMulticastTimer = new StopwatchTimer(mBsi.mClocks, this, WIFI_MULTICAST_ENABLED, |
| 5007 | mBsi.mWifiMulticastTimers, mBsi.mOnBatteryTimeBase); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5008 | mProcessStateTimer = new StopwatchTimer[NUM_PROCESS_STATE]; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5009 | } |
| 5010 | |
| 5011 | @Override |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5012 | public ArrayMap<String, ? extends BatteryStats.Uid.Wakelock> getWakelockStats() { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 5013 | return mWakelockStats.getMap(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5014 | } |
| 5015 | |
| 5016 | @Override |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5017 | public ArrayMap<String, ? extends BatteryStats.Timer> getSyncStats() { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 5018 | return mSyncStats.getMap(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 5019 | } |
| 5020 | |
| 5021 | @Override |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5022 | public ArrayMap<String, ? extends BatteryStats.Timer> getJobStats() { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 5023 | return mJobStats.getMap(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 5024 | } |
| 5025 | |
| 5026 | @Override |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5027 | public SparseArray<? extends BatteryStats.Uid.Sensor> getSensorStats() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5028 | return mSensorStats; |
| 5029 | } |
| 5030 | |
| 5031 | @Override |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5032 | public ArrayMap<String, ? extends BatteryStats.Uid.Proc> getProcessStats() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5033 | return mProcessStats; |
| 5034 | } |
| 5035 | |
| 5036 | @Override |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 5037 | public ArrayMap<String, ? extends BatteryStats.Uid.Pkg> getPackageStats() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5038 | return mPackageStats; |
| 5039 | } |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 5040 | |
| 5041 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5042 | public int getUid() { |
| 5043 | return mUid; |
| 5044 | } |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 5045 | |
| 5046 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5047 | public void noteWifiRunningLocked(long elapsedRealtimeMs) { |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 5048 | if (!mWifiRunning) { |
| 5049 | mWifiRunning = true; |
| 5050 | if (mWifiRunningTimer == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5051 | mWifiRunningTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, WIFI_RUNNING, |
| 5052 | mBsi.mWifiRunningTimers, mBsi.mOnBatteryTimeBase); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5053 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5054 | mWifiRunningTimer.startRunningLocked(elapsedRealtimeMs); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 5055 | } |
| 5056 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5057 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 5058 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5059 | public void noteWifiStoppedLocked(long elapsedRealtimeMs) { |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 5060 | if (mWifiRunning) { |
| 5061 | mWifiRunning = false; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5062 | mWifiRunningTimer.stopRunningLocked(elapsedRealtimeMs); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 5063 | } |
| 5064 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5065 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 5066 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5067 | public void noteFullWifiLockAcquiredLocked(long elapsedRealtimeMs) { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 5068 | if (!mFullWifiLockOut) { |
| 5069 | mFullWifiLockOut = true; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5070 | if (mFullWifiLockTimer == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5071 | mFullWifiLockTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, FULL_WIFI_LOCK, |
| 5072 | mBsi.mFullWifiLockTimers, mBsi.mOnBatteryTimeBase); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5073 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5074 | mFullWifiLockTimer.startRunningLocked(elapsedRealtimeMs); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 5075 | } |
| 5076 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5077 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 5078 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5079 | public void noteFullWifiLockReleasedLocked(long elapsedRealtimeMs) { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 5080 | if (mFullWifiLockOut) { |
| 5081 | mFullWifiLockOut = false; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5082 | mFullWifiLockTimer.stopRunningLocked(elapsedRealtimeMs); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 5083 | } |
| 5084 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5085 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 5086 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5087 | public void noteWifiScanStartedLocked(long elapsedRealtimeMs) { |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 5088 | if (!mWifiScanStarted) { |
| 5089 | mWifiScanStarted = true; |
| 5090 | if (mWifiScanTimer == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5091 | mWifiScanTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, WIFI_SCAN, |
| 5092 | mBsi.mWifiScanTimers, mBsi.mOnBatteryTimeBase); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5093 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5094 | mWifiScanTimer.startRunningLocked(elapsedRealtimeMs); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 5095 | } |
| 5096 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5097 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 5098 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5099 | public void noteWifiScanStoppedLocked(long elapsedRealtimeMs) { |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 5100 | if (mWifiScanStarted) { |
| 5101 | mWifiScanStarted = false; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5102 | mWifiScanTimer.stopRunningLocked(elapsedRealtimeMs); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 5103 | } |
| 5104 | } |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 5105 | |
| 5106 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5107 | public void noteWifiBatchedScanStartedLocked(int csph, long elapsedRealtimeMs) { |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 5108 | int bin = 0; |
Navtej Singh Mann | 3c0ce5c | 2015-06-11 16:53:11 -0700 | [diff] [blame] | 5109 | while (csph > 8 && bin < NUM_WIFI_BATCHED_SCAN_BINS-1) { |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 5110 | csph = csph >> 3; |
| 5111 | bin++; |
| 5112 | } |
| 5113 | |
| 5114 | if (mWifiBatchedScanBinStarted == bin) return; |
| 5115 | |
| 5116 | if (mWifiBatchedScanBinStarted != NO_BATCHED_SCAN_STARTED) { |
| 5117 | mWifiBatchedScanTimer[mWifiBatchedScanBinStarted]. |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5118 | stopRunningLocked(elapsedRealtimeMs); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 5119 | } |
| 5120 | mWifiBatchedScanBinStarted = bin; |
| 5121 | if (mWifiBatchedScanTimer[bin] == null) { |
| 5122 | makeWifiBatchedScanBin(bin, null); |
| 5123 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5124 | mWifiBatchedScanTimer[bin].startRunningLocked(elapsedRealtimeMs); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 5125 | } |
| 5126 | |
| 5127 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5128 | public void noteWifiBatchedScanStoppedLocked(long elapsedRealtimeMs) { |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 5129 | if (mWifiBatchedScanBinStarted != NO_BATCHED_SCAN_STARTED) { |
| 5130 | mWifiBatchedScanTimer[mWifiBatchedScanBinStarted]. |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5131 | stopRunningLocked(elapsedRealtimeMs); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 5132 | mWifiBatchedScanBinStarted = NO_BATCHED_SCAN_STARTED; |
| 5133 | } |
| 5134 | } |
| 5135 | |
| 5136 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5137 | public void noteWifiMulticastEnabledLocked(long elapsedRealtimeMs) { |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 5138 | if (!mWifiMulticastEnabled) { |
| 5139 | mWifiMulticastEnabled = true; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5140 | if (mWifiMulticastTimer == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5141 | mWifiMulticastTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, |
| 5142 | WIFI_MULTICAST_ENABLED, mBsi.mWifiMulticastTimers, mBsi.mOnBatteryTimeBase); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5143 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5144 | mWifiMulticastTimer.startRunningLocked(elapsedRealtimeMs); |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 5145 | } |
| 5146 | } |
| 5147 | |
| 5148 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5149 | public void noteWifiMulticastDisabledLocked(long elapsedRealtimeMs) { |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 5150 | if (mWifiMulticastEnabled) { |
| 5151 | mWifiMulticastEnabled = false; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5152 | mWifiMulticastTimer.stopRunningLocked(elapsedRealtimeMs); |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 5153 | } |
| 5154 | } |
| 5155 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 5156 | @Override |
| 5157 | public ControllerActivityCounter getWifiControllerActivity() { |
| 5158 | return mWifiControllerActivity; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 5159 | } |
| 5160 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 5161 | @Override |
| 5162 | public ControllerActivityCounter getBluetoothControllerActivity() { |
| 5163 | return mBluetoothControllerActivity; |
| 5164 | } |
| 5165 | |
| 5166 | @Override |
| 5167 | public ControllerActivityCounter getModemControllerActivity() { |
| 5168 | return mModemControllerActivity; |
| 5169 | } |
| 5170 | |
| 5171 | public ControllerActivityCounterImpl getOrCreateWifiControllerActivityLocked() { |
| 5172 | if (mWifiControllerActivity == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5173 | mWifiControllerActivity = new ControllerActivityCounterImpl(mBsi.mOnBatteryTimeBase, |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 5174 | NUM_BT_TX_LEVELS); |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 5175 | } |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 5176 | return mWifiControllerActivity; |
| 5177 | } |
| 5178 | |
| 5179 | public ControllerActivityCounterImpl getOrCreateBluetoothControllerActivityLocked() { |
| 5180 | if (mBluetoothControllerActivity == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5181 | mBluetoothControllerActivity = new ControllerActivityCounterImpl(mBsi.mOnBatteryTimeBase, |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 5182 | NUM_BT_TX_LEVELS); |
| 5183 | } |
| 5184 | return mBluetoothControllerActivity; |
| 5185 | } |
| 5186 | |
| 5187 | public ControllerActivityCounterImpl getOrCreateModemControllerActivityLocked() { |
| 5188 | if (mModemControllerActivity == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5189 | mModemControllerActivity = new ControllerActivityCounterImpl(mBsi.mOnBatteryTimeBase, |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 5190 | ModemActivityInfo.TX_POWER_LEVELS); |
| 5191 | } |
| 5192 | return mModemControllerActivity; |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 5193 | } |
| 5194 | |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 5195 | public StopwatchTimer createAudioTurnedOnTimerLocked() { |
| 5196 | if (mAudioTurnedOnTimer == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5197 | mAudioTurnedOnTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, AUDIO_TURNED_ON, |
| 5198 | mBsi.mAudioTurnedOnTimers, mBsi.mOnBatteryTimeBase); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 5199 | } |
| 5200 | return mAudioTurnedOnTimer; |
| 5201 | } |
| 5202 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5203 | public void noteAudioTurnedOnLocked(long elapsedRealtimeMs) { |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 5204 | createAudioTurnedOnTimerLocked().startRunningLocked(elapsedRealtimeMs); |
| 5205 | } |
| 5206 | |
| 5207 | public void noteAudioTurnedOffLocked(long elapsedRealtimeMs) { |
| 5208 | if (mAudioTurnedOnTimer != null) { |
| 5209 | mAudioTurnedOnTimer.stopRunningLocked(elapsedRealtimeMs); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5210 | } |
| 5211 | } |
| 5212 | |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 5213 | public void noteResetAudioLocked(long elapsedRealtimeMs) { |
| 5214 | if (mAudioTurnedOnTimer != null) { |
| 5215 | mAudioTurnedOnTimer.stopAllRunningLocked(elapsedRealtimeMs); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5216 | } |
| 5217 | } |
| 5218 | |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 5219 | public StopwatchTimer createVideoTurnedOnTimerLocked() { |
| 5220 | if (mVideoTurnedOnTimer == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5221 | mVideoTurnedOnTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, VIDEO_TURNED_ON, |
| 5222 | mBsi.mVideoTurnedOnTimers, mBsi.mOnBatteryTimeBase); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 5223 | } |
| 5224 | return mVideoTurnedOnTimer; |
| 5225 | } |
| 5226 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5227 | public void noteVideoTurnedOnLocked(long elapsedRealtimeMs) { |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 5228 | createVideoTurnedOnTimerLocked().startRunningLocked(elapsedRealtimeMs); |
| 5229 | } |
| 5230 | |
| 5231 | public void noteVideoTurnedOffLocked(long elapsedRealtimeMs) { |
| 5232 | if (mVideoTurnedOnTimer != null) { |
| 5233 | mVideoTurnedOnTimer.stopRunningLocked(elapsedRealtimeMs); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5234 | } |
| 5235 | } |
| 5236 | |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 5237 | public void noteResetVideoLocked(long elapsedRealtimeMs) { |
| 5238 | if (mVideoTurnedOnTimer != null) { |
| 5239 | mVideoTurnedOnTimer.stopAllRunningLocked(elapsedRealtimeMs); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 5240 | } |
| 5241 | } |
| 5242 | |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 5243 | public StopwatchTimer createFlashlightTurnedOnTimerLocked() { |
| 5244 | if (mFlashlightTurnedOnTimer == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5245 | mFlashlightTurnedOnTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, |
| 5246 | FLASHLIGHT_TURNED_ON, mBsi.mFlashlightTurnedOnTimers, mBsi.mOnBatteryTimeBase); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 5247 | } |
| 5248 | return mFlashlightTurnedOnTimer; |
| 5249 | } |
| 5250 | |
| 5251 | public void noteFlashlightTurnedOnLocked(long elapsedRealtimeMs) { |
| 5252 | createFlashlightTurnedOnTimerLocked().startRunningLocked(elapsedRealtimeMs); |
| 5253 | } |
| 5254 | |
| 5255 | public void noteFlashlightTurnedOffLocked(long elapsedRealtimeMs) { |
| 5256 | if (mFlashlightTurnedOnTimer != null) { |
| 5257 | mFlashlightTurnedOnTimer.stopRunningLocked(elapsedRealtimeMs); |
| 5258 | } |
| 5259 | } |
| 5260 | |
| 5261 | public void noteResetFlashlightLocked(long elapsedRealtimeMs) { |
| 5262 | if (mFlashlightTurnedOnTimer != null) { |
| 5263 | mFlashlightTurnedOnTimer.stopAllRunningLocked(elapsedRealtimeMs); |
| 5264 | } |
| 5265 | } |
| 5266 | |
| 5267 | public StopwatchTimer createCameraTurnedOnTimerLocked() { |
| 5268 | if (mCameraTurnedOnTimer == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5269 | mCameraTurnedOnTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, CAMERA_TURNED_ON, |
| 5270 | mBsi.mCameraTurnedOnTimers, mBsi.mOnBatteryTimeBase); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 5271 | } |
| 5272 | return mCameraTurnedOnTimer; |
| 5273 | } |
| 5274 | |
| 5275 | public void noteCameraTurnedOnLocked(long elapsedRealtimeMs) { |
| 5276 | createCameraTurnedOnTimerLocked().startRunningLocked(elapsedRealtimeMs); |
| 5277 | } |
| 5278 | |
| 5279 | public void noteCameraTurnedOffLocked(long elapsedRealtimeMs) { |
| 5280 | if (mCameraTurnedOnTimer != null) { |
| 5281 | mCameraTurnedOnTimer.stopRunningLocked(elapsedRealtimeMs); |
| 5282 | } |
| 5283 | } |
| 5284 | |
| 5285 | public void noteResetCameraLocked(long elapsedRealtimeMs) { |
| 5286 | if (mCameraTurnedOnTimer != null) { |
| 5287 | mCameraTurnedOnTimer.stopAllRunningLocked(elapsedRealtimeMs); |
| 5288 | } |
| 5289 | } |
| 5290 | |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 5291 | public StopwatchTimer createForegroundActivityTimerLocked() { |
| 5292 | if (mForegroundActivityTimer == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5293 | mForegroundActivityTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, |
| 5294 | FOREGROUND_ACTIVITY, null, mBsi.mOnBatteryTimeBase); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 5295 | } |
| 5296 | return mForegroundActivityTimer; |
| 5297 | } |
| 5298 | |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 5299 | public StopwatchTimer createBluetoothScanTimerLocked() { |
| 5300 | if (mBluetoothScanTimer == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5301 | mBluetoothScanTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, BLUETOOTH_SCAN_ON, |
| 5302 | mBsi.mBluetoothScanOnTimers, mBsi.mOnBatteryTimeBase); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 5303 | } |
| 5304 | return mBluetoothScanTimer; |
| 5305 | } |
| 5306 | |
| 5307 | public void noteBluetoothScanStartedLocked(long elapsedRealtimeMs) { |
| 5308 | createBluetoothScanTimerLocked().startRunningLocked(elapsedRealtimeMs); |
| 5309 | } |
| 5310 | |
| 5311 | public void noteBluetoothScanStoppedLocked(long elapsedRealtimeMs) { |
| 5312 | if (mBluetoothScanTimer != null) { |
| 5313 | mBluetoothScanTimer.stopRunningLocked(elapsedRealtimeMs); |
| 5314 | } |
| 5315 | } |
| 5316 | |
| 5317 | public void noteResetBluetoothScanLocked(long elapsedRealtimeMs) { |
| 5318 | if (mBluetoothScanTimer != null) { |
| 5319 | mBluetoothScanTimer.stopAllRunningLocked(elapsedRealtimeMs); |
| 5320 | } |
| 5321 | } |
| 5322 | |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 5323 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5324 | public void noteActivityResumedLocked(long elapsedRealtimeMs) { |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 5325 | // We always start, since we want multiple foreground PIDs to nest |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5326 | createForegroundActivityTimerLocked().startRunningLocked(elapsedRealtimeMs); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 5327 | } |
| 5328 | |
| 5329 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5330 | public void noteActivityPausedLocked(long elapsedRealtimeMs) { |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 5331 | if (mForegroundActivityTimer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5332 | mForegroundActivityTimer.stopRunningLocked(elapsedRealtimeMs); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 5333 | } |
| 5334 | } |
| 5335 | |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 5336 | public BatchTimer createVibratorOnTimerLocked() { |
| 5337 | if (mVibratorOnTimer == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5338 | mVibratorOnTimer = new BatchTimer(mBsi.mClocks, Uid.this, VIBRATOR_ON, |
| 5339 | mBsi.mOnBatteryTimeBase); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 5340 | } |
| 5341 | return mVibratorOnTimer; |
| 5342 | } |
| 5343 | |
| 5344 | public void noteVibratorOnLocked(long durationMillis) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5345 | createVibratorOnTimerLocked().addDuration(mBsi, durationMillis); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 5346 | } |
| 5347 | |
| 5348 | public void noteVibratorOffLocked() { |
| 5349 | if (mVibratorOnTimer != null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5350 | mVibratorOnTimer.abortLastDuration(mBsi); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5351 | } |
| 5352 | } |
| 5353 | |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5354 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5355 | public long getWifiRunningTime(long elapsedRealtimeUs, int which) { |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 5356 | if (mWifiRunningTimer == null) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5357 | return 0; |
| 5358 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5359 | return mWifiRunningTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 5360 | } |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 5361 | |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5362 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5363 | public long getFullWifiLockTime(long elapsedRealtimeUs, int which) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5364 | if (mFullWifiLockTimer == null) { |
| 5365 | return 0; |
| 5366 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5367 | return mFullWifiLockTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 5368 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5369 | |
| 5370 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5371 | public long getWifiScanTime(long elapsedRealtimeUs, int which) { |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 5372 | if (mWifiScanTimer == null) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5373 | return 0; |
| 5374 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5375 | return mWifiScanTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 5376 | } |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 5377 | |
| 5378 | @Override |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 5379 | public int getWifiScanCount(int which) { |
| 5380 | if (mWifiScanTimer == null) { |
| 5381 | return 0; |
| 5382 | } |
| 5383 | return mWifiScanTimer.getCountLocked(which); |
| 5384 | } |
| 5385 | |
| 5386 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5387 | public long getWifiBatchedScanTime(int csphBin, long elapsedRealtimeUs, int which) { |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 5388 | if (csphBin < 0 || csphBin >= NUM_WIFI_BATCHED_SCAN_BINS) return 0; |
| 5389 | if (mWifiBatchedScanTimer[csphBin] == null) { |
| 5390 | return 0; |
| 5391 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5392 | return mWifiBatchedScanTimer[csphBin].getTotalTimeLocked(elapsedRealtimeUs, which); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 5393 | } |
| 5394 | |
| 5395 | @Override |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 5396 | public int getWifiBatchedScanCount(int csphBin, int which) { |
| 5397 | if (csphBin < 0 || csphBin >= NUM_WIFI_BATCHED_SCAN_BINS) return 0; |
| 5398 | if (mWifiBatchedScanTimer[csphBin] == null) { |
| 5399 | return 0; |
| 5400 | } |
| 5401 | return mWifiBatchedScanTimer[csphBin].getCountLocked(which); |
| 5402 | } |
| 5403 | |
| 5404 | @Override |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5405 | public long getWifiMulticastTime(long elapsedRealtimeUs, int which) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5406 | if (mWifiMulticastTimer == null) { |
| 5407 | return 0; |
| 5408 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5409 | return mWifiMulticastTimer.getTotalTimeLocked(elapsedRealtimeUs, which); |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 5410 | } |
| 5411 | |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5412 | @Override |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 5413 | public Timer getAudioTurnedOnTimer() { |
| 5414 | return mAudioTurnedOnTimer; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5415 | } |
| 5416 | |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5417 | @Override |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 5418 | public Timer getVideoTurnedOnTimer() { |
| 5419 | return mVideoTurnedOnTimer; |
| 5420 | } |
| 5421 | |
| 5422 | @Override |
| 5423 | public Timer getFlashlightTurnedOnTimer() { |
| 5424 | return mFlashlightTurnedOnTimer; |
| 5425 | } |
| 5426 | |
| 5427 | @Override |
| 5428 | public Timer getCameraTurnedOnTimer() { |
| 5429 | return mCameraTurnedOnTimer; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5430 | } |
| 5431 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 5432 | @Override |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 5433 | public Timer getForegroundActivityTimer() { |
| 5434 | return mForegroundActivityTimer; |
| 5435 | } |
| 5436 | |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 5437 | @Override |
| 5438 | public Timer getBluetoothScanTimer() { |
| 5439 | return mBluetoothScanTimer; |
| 5440 | } |
| 5441 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5442 | void makeProcessState(int i, Parcel in) { |
| 5443 | if (i < 0 || i >= NUM_PROCESS_STATE) return; |
| 5444 | |
| 5445 | if (in == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5446 | mProcessStateTimer[i] = new StopwatchTimer(mBsi.mClocks, this, PROCESS_STATE, null, |
| 5447 | mBsi.mOnBatteryTimeBase); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5448 | } else { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5449 | mProcessStateTimer[i] = new StopwatchTimer(mBsi.mClocks, this, PROCESS_STATE, null, |
| 5450 | mBsi.mOnBatteryTimeBase, in); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5451 | } |
| 5452 | } |
| 5453 | |
| 5454 | @Override |
| 5455 | public long getProcessStateTime(int state, long elapsedRealtimeUs, int which) { |
| 5456 | if (state < 0 || state >= NUM_PROCESS_STATE) return 0; |
| 5457 | if (mProcessStateTimer[state] == null) { |
| 5458 | return 0; |
| 5459 | } |
| 5460 | return mProcessStateTimer[state].getTotalTimeLocked(elapsedRealtimeUs, which); |
| 5461 | } |
| 5462 | |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 5463 | @Override |
Joe Onorato | 713fec8 | 2016-03-04 10:34:02 -0800 | [diff] [blame] | 5464 | public Timer getProcessStateTimer(int state) { |
| 5465 | if (state < 0 || state >= NUM_PROCESS_STATE) return null; |
| 5466 | return mProcessStateTimer[state]; |
| 5467 | } |
| 5468 | |
| 5469 | @Override |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 5470 | public Timer getVibratorOnTimer() { |
| 5471 | return mVibratorOnTimer; |
| 5472 | } |
| 5473 | |
| 5474 | @Override |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 5475 | public void noteUserActivityLocked(int type) { |
| 5476 | if (mUserActivityCounters == null) { |
| 5477 | initUserActivityLocked(); |
| 5478 | } |
Jeff Brown | df693de | 2012-07-27 12:03:38 -0700 | [diff] [blame] | 5479 | if (type >= 0 && type < NUM_USER_ACTIVITY_TYPES) { |
| 5480 | mUserActivityCounters[type].stepAtomic(); |
| 5481 | } else { |
| 5482 | Slog.w(TAG, "Unknown user activity type " + type + " was specified.", |
| 5483 | new Throwable()); |
| 5484 | } |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 5485 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5486 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 5487 | @Override |
| 5488 | public boolean hasUserActivity() { |
| 5489 | return mUserActivityCounters != null; |
| 5490 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5491 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 5492 | @Override |
| 5493 | public int getUserActivityCount(int type, int which) { |
| 5494 | if (mUserActivityCounters == null) { |
| 5495 | return 0; |
| 5496 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 5497 | return mUserActivityCounters[type].getCountLocked(which); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 5498 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5499 | |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 5500 | void makeWifiBatchedScanBin(int i, Parcel in) { |
| 5501 | if (i < 0 || i >= NUM_WIFI_BATCHED_SCAN_BINS) return; |
| 5502 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5503 | ArrayList<StopwatchTimer> collected = mBsi.mWifiBatchedScanTimers.get(i); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 5504 | if (collected == null) { |
| 5505 | collected = new ArrayList<StopwatchTimer>(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5506 | mBsi.mWifiBatchedScanTimers.put(i, collected); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 5507 | } |
| 5508 | if (in == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5509 | mWifiBatchedScanTimer[i] = new StopwatchTimer(mBsi.mClocks, this, WIFI_BATCHED_SCAN, |
| 5510 | collected, mBsi.mOnBatteryTimeBase); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 5511 | } else { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5512 | mWifiBatchedScanTimer[i] = new StopwatchTimer(mBsi.mClocks, this, WIFI_BATCHED_SCAN, |
| 5513 | collected, mBsi.mOnBatteryTimeBase, in); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 5514 | } |
| 5515 | } |
| 5516 | |
| 5517 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 5518 | void initUserActivityLocked() { |
| 5519 | mUserActivityCounters = new Counter[NUM_USER_ACTIVITY_TYPES]; |
| 5520 | for (int i=0; i<NUM_USER_ACTIVITY_TYPES; i++) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5521 | mUserActivityCounters[i] = new Counter(mBsi.mOnBatteryTimeBase); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 5522 | } |
| 5523 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5524 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5525 | void noteNetworkActivityLocked(int type, long deltaBytes, long deltaPackets) { |
| 5526 | if (mNetworkByteActivityCounters == null) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5527 | initNetworkActivityLocked(); |
| 5528 | } |
| 5529 | if (type >= 0 && type < NUM_NETWORK_ACTIVITY_TYPES) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5530 | mNetworkByteActivityCounters[type].addCountLocked(deltaBytes); |
| 5531 | mNetworkPacketActivityCounters[type].addCountLocked(deltaPackets); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5532 | } else { |
| 5533 | Slog.w(TAG, "Unknown network activity type " + type + " was specified.", |
| 5534 | new Throwable()); |
| 5535 | } |
| 5536 | } |
| 5537 | |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 5538 | void noteMobileRadioActiveTimeLocked(long batteryUptime) { |
| 5539 | if (mNetworkByteActivityCounters == null) { |
| 5540 | initNetworkActivityLocked(); |
| 5541 | } |
| 5542 | mMobileRadioActiveTime.addCountLocked(batteryUptime); |
| 5543 | mMobileRadioActiveCount.addCountLocked(1); |
| 5544 | } |
| 5545 | |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5546 | @Override |
| 5547 | public boolean hasNetworkActivity() { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5548 | return mNetworkByteActivityCounters != null; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5549 | } |
| 5550 | |
| 5551 | @Override |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5552 | public long getNetworkActivityBytes(int type, int which) { |
| 5553 | if (mNetworkByteActivityCounters != null && type >= 0 |
| 5554 | && type < mNetworkByteActivityCounters.length) { |
| 5555 | return mNetworkByteActivityCounters[type].getCountLocked(which); |
| 5556 | } else { |
| 5557 | return 0; |
| 5558 | } |
| 5559 | } |
| 5560 | |
| 5561 | @Override |
| 5562 | public long getNetworkActivityPackets(int type, int which) { |
| 5563 | if (mNetworkPacketActivityCounters != null && type >= 0 |
| 5564 | && type < mNetworkPacketActivityCounters.length) { |
| 5565 | return mNetworkPacketActivityCounters[type].getCountLocked(which); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5566 | } else { |
| 5567 | return 0; |
| 5568 | } |
| 5569 | } |
| 5570 | |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 5571 | @Override |
| 5572 | public long getMobileRadioActiveTime(int which) { |
| 5573 | return mMobileRadioActiveTime != null |
| 5574 | ? mMobileRadioActiveTime.getCountLocked(which) : 0; |
| 5575 | } |
| 5576 | |
| 5577 | @Override |
| 5578 | public int getMobileRadioActiveCount(int which) { |
| 5579 | return mMobileRadioActiveCount != null |
| 5580 | ? (int)mMobileRadioActiveCount.getCountLocked(which) : 0; |
| 5581 | } |
| 5582 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 5583 | @Override |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 5584 | public long getUserCpuTimeUs(int which) { |
| 5585 | return mUserCpuTime.getCountLocked(which); |
| 5586 | } |
| 5587 | |
| 5588 | @Override |
| 5589 | public long getSystemCpuTimeUs(int which) { |
| 5590 | return mSystemCpuTime.getCountLocked(which); |
| 5591 | } |
| 5592 | |
| 5593 | @Override |
Adam Lesinski | a7a4ccc | 2015-06-26 17:43:04 -0700 | [diff] [blame] | 5594 | public long getCpuPowerMaUs(int which) { |
| 5595 | return mCpuPower.getCountLocked(which); |
| 5596 | } |
| 5597 | |
| 5598 | @Override |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 5599 | public long getTimeAtCpuSpeed(int cluster, int step, int which) { |
| 5600 | if (mCpuClusterSpeed != null) { |
| 5601 | if (cluster >= 0 && cluster < mCpuClusterSpeed.length) { |
| 5602 | final LongSamplingCounter[] cpuSpeeds = mCpuClusterSpeed[cluster]; |
| 5603 | if (cpuSpeeds != null) { |
| 5604 | if (step >= 0 && step < cpuSpeeds.length) { |
| 5605 | final LongSamplingCounter c = cpuSpeeds[step]; |
| 5606 | if (c != null) { |
| 5607 | return c.getCountLocked(which); |
| 5608 | } |
| 5609 | } |
| 5610 | } |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 5611 | } |
| 5612 | } |
| 5613 | return 0; |
| 5614 | } |
| 5615 | |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5616 | void initNetworkActivityLocked() { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5617 | mNetworkByteActivityCounters = new LongSamplingCounter[NUM_NETWORK_ACTIVITY_TYPES]; |
| 5618 | mNetworkPacketActivityCounters = new LongSamplingCounter[NUM_NETWORK_ACTIVITY_TYPES]; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5619 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5620 | mNetworkByteActivityCounters[i] = new LongSamplingCounter(mBsi.mOnBatteryTimeBase); |
| 5621 | mNetworkPacketActivityCounters[i] = new LongSamplingCounter(mBsi.mOnBatteryTimeBase); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5622 | } |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 5623 | mMobileRadioActiveTime = new LongSamplingCounter(mBsi.mOnBatteryTimeBase); |
| 5624 | mMobileRadioActiveCount = new LongSamplingCounter(mBsi.mOnBatteryTimeBase); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5625 | } |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 5626 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5627 | /** |
| 5628 | * Clear all stats for this uid. Returns true if the uid is completely |
| 5629 | * inactive so can be dropped. |
| 5630 | */ |
| 5631 | boolean reset() { |
| 5632 | boolean active = false; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5633 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 5634 | if (mWifiRunningTimer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5635 | active |= !mWifiRunningTimer.reset(false); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 5636 | active |= mWifiRunning; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5637 | } |
| 5638 | if (mFullWifiLockTimer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5639 | active |= !mFullWifiLockTimer.reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5640 | active |= mFullWifiLockOut; |
| 5641 | } |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 5642 | if (mWifiScanTimer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5643 | active |= !mWifiScanTimer.reset(false); |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 5644 | active |= mWifiScanStarted; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5645 | } |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 5646 | if (mWifiBatchedScanTimer != null) { |
| 5647 | for (int i = 0; i < NUM_WIFI_BATCHED_SCAN_BINS; i++) { |
| 5648 | if (mWifiBatchedScanTimer[i] != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5649 | active |= !mWifiBatchedScanTimer[i].reset(false); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 5650 | } |
| 5651 | } |
| 5652 | active |= (mWifiBatchedScanBinStarted != NO_BATCHED_SCAN_STARTED); |
| 5653 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5654 | if (mWifiMulticastTimer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5655 | active |= !mWifiMulticastTimer.reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5656 | active |= mWifiMulticastEnabled; |
| 5657 | } |
| 5658 | if (mAudioTurnedOnTimer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5659 | active |= !mAudioTurnedOnTimer.reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5660 | } |
| 5661 | if (mVideoTurnedOnTimer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5662 | active |= !mVideoTurnedOnTimer.reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5663 | } |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 5664 | if (mFlashlightTurnedOnTimer != null) { |
| 5665 | active |= !mFlashlightTurnedOnTimer.reset(false); |
| 5666 | } |
| 5667 | if (mCameraTurnedOnTimer != null) { |
| 5668 | active |= !mCameraTurnedOnTimer.reset(false); |
| 5669 | } |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 5670 | if (mForegroundActivityTimer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5671 | active |= !mForegroundActivityTimer.reset(false); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 5672 | } |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 5673 | if (mBluetoothScanTimer != null) { |
| 5674 | active |= !mBluetoothScanTimer.reset(false); |
| 5675 | } |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5676 | if (mProcessStateTimer != null) { |
| 5677 | for (int i = 0; i < NUM_PROCESS_STATE; i++) { |
| 5678 | if (mProcessStateTimer[i] != null) { |
| 5679 | active |= !mProcessStateTimer[i].reset(false); |
| 5680 | } |
| 5681 | } |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 5682 | active |= (mProcessState != ActivityManager.PROCESS_STATE_NONEXISTENT); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5683 | } |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 5684 | if (mVibratorOnTimer != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5685 | if (mVibratorOnTimer.reset(false)) { |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 5686 | mVibratorOnTimer.detach(); |
| 5687 | mVibratorOnTimer = null; |
| 5688 | } else { |
| 5689 | active = true; |
| 5690 | } |
| 5691 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5692 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5693 | if (mUserActivityCounters != null) { |
| 5694 | for (int i=0; i<NUM_USER_ACTIVITY_TYPES; i++) { |
| 5695 | mUserActivityCounters[i].reset(false); |
| 5696 | } |
| 5697 | } |
| 5698 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5699 | if (mNetworkByteActivityCounters != null) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5700 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5701 | mNetworkByteActivityCounters[i].reset(false); |
| 5702 | mNetworkPacketActivityCounters[i].reset(false); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5703 | } |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 5704 | mMobileRadioActiveTime.reset(false); |
| 5705 | mMobileRadioActiveCount.reset(false); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5706 | } |
| 5707 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 5708 | if (mWifiControllerActivity != null) { |
| 5709 | mWifiControllerActivity.reset(false); |
| 5710 | } |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 5711 | |
Adam Lesinski | 1a2b39e | 2016-04-29 17:56:58 -0700 | [diff] [blame] | 5712 | if (mBluetoothControllerActivity != null) { |
| 5713 | mBluetoothControllerActivity.reset(false); |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 5714 | } |
| 5715 | |
Adam Lesinski | 1a2b39e | 2016-04-29 17:56:58 -0700 | [diff] [blame] | 5716 | if (mModemControllerActivity != null) { |
| 5717 | mModemControllerActivity.reset(false); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 5718 | } |
| 5719 | |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 5720 | mUserCpuTime.reset(false); |
| 5721 | mSystemCpuTime.reset(false); |
Adam Lesinski | a7a4ccc | 2015-06-26 17:43:04 -0700 | [diff] [blame] | 5722 | mCpuPower.reset(false); |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 5723 | |
| 5724 | if (mCpuClusterSpeed != null) { |
| 5725 | for (LongSamplingCounter[] speeds : mCpuClusterSpeed) { |
| 5726 | if (speeds != null) { |
| 5727 | for (LongSamplingCounter speed : speeds) { |
| 5728 | if (speed != null) { |
| 5729 | speed.reset(false); |
| 5730 | } |
| 5731 | } |
| 5732 | } |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 5733 | } |
| 5734 | } |
| 5735 | |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 5736 | final ArrayMap<String, Wakelock> wakeStats = mWakelockStats.getMap(); |
| 5737 | for (int iw=wakeStats.size()-1; iw>=0; iw--) { |
| 5738 | Wakelock wl = wakeStats.valueAt(iw); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5739 | if (wl.reset()) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 5740 | wakeStats.removeAt(iw); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5741 | } else { |
| 5742 | active = true; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5743 | } |
| 5744 | } |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 5745 | mWakelockStats.cleanup(); |
| 5746 | final ArrayMap<String, StopwatchTimer> syncStats = mSyncStats.getMap(); |
| 5747 | for (int is=syncStats.size()-1; is>=0; is--) { |
| 5748 | StopwatchTimer timer = syncStats.valueAt(is); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 5749 | if (timer.reset(false)) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 5750 | syncStats.removeAt(is); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 5751 | timer.detach(); |
| 5752 | } else { |
| 5753 | active = true; |
| 5754 | } |
| 5755 | } |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 5756 | mSyncStats.cleanup(); |
| 5757 | final ArrayMap<String, StopwatchTimer> jobStats = mJobStats.getMap(); |
| 5758 | for (int ij=jobStats.size()-1; ij>=0; ij--) { |
| 5759 | StopwatchTimer timer = jobStats.valueAt(ij); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 5760 | if (timer.reset(false)) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 5761 | jobStats.removeAt(ij); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 5762 | timer.detach(); |
| 5763 | } else { |
| 5764 | active = true; |
| 5765 | } |
| 5766 | } |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 5767 | mJobStats.cleanup(); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5768 | for (int ise=mSensorStats.size()-1; ise>=0; ise--) { |
| 5769 | Sensor s = mSensorStats.valueAt(ise); |
| 5770 | if (s.reset()) { |
| 5771 | mSensorStats.removeAt(ise); |
| 5772 | } else { |
| 5773 | active = true; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5774 | } |
| 5775 | } |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5776 | for (int ip=mProcessStats.size()-1; ip>=0; ip--) { |
| 5777 | Proc proc = mProcessStats.valueAt(ip); |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 5778 | proc.detach(); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5779 | } |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 5780 | mProcessStats.clear(); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 5781 | if (mPids.size() > 0) { |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 5782 | for (int i=mPids.size()-1; i>=0; i--) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 5783 | Pid pid = mPids.valueAt(i); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 5784 | if (pid.mWakeNesting > 0) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 5785 | active = true; |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 5786 | } else { |
| 5787 | mPids.removeAt(i); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 5788 | } |
| 5789 | } |
| 5790 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5791 | if (mPackageStats.size() > 0) { |
| 5792 | Iterator<Map.Entry<String, Pkg>> it = mPackageStats.entrySet().iterator(); |
| 5793 | while (it.hasNext()) { |
| 5794 | Map.Entry<String, Pkg> pkgEntry = it.next(); |
| 5795 | Pkg p = pkgEntry.getValue(); |
| 5796 | p.detach(); |
| 5797 | if (p.mServiceStats.size() > 0) { |
| 5798 | Iterator<Map.Entry<String, Pkg.Serv>> it2 |
| 5799 | = p.mServiceStats.entrySet().iterator(); |
| 5800 | while (it2.hasNext()) { |
| 5801 | Map.Entry<String, Pkg.Serv> servEntry = it2.next(); |
| 5802 | servEntry.getValue().detach(); |
| 5803 | } |
| 5804 | } |
| 5805 | } |
| 5806 | mPackageStats.clear(); |
| 5807 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5808 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 5809 | mLastStepUserTime = mLastStepSystemTime = 0; |
| 5810 | mCurStepUserTime = mCurStepSystemTime = 0; |
| 5811 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5812 | if (!active) { |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 5813 | if (mWifiRunningTimer != null) { |
| 5814 | mWifiRunningTimer.detach(); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5815 | } |
| 5816 | if (mFullWifiLockTimer != null) { |
| 5817 | mFullWifiLockTimer.detach(); |
| 5818 | } |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 5819 | if (mWifiScanTimer != null) { |
| 5820 | mWifiScanTimer.detach(); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5821 | } |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 5822 | for (int i = 0; i < NUM_WIFI_BATCHED_SCAN_BINS; i++) { |
| 5823 | if (mWifiBatchedScanTimer[i] != null) { |
| 5824 | mWifiBatchedScanTimer[i].detach(); |
| 5825 | } |
| 5826 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5827 | if (mWifiMulticastTimer != null) { |
| 5828 | mWifiMulticastTimer.detach(); |
| 5829 | } |
| 5830 | if (mAudioTurnedOnTimer != null) { |
| 5831 | mAudioTurnedOnTimer.detach(); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 5832 | mAudioTurnedOnTimer = null; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5833 | } |
| 5834 | if (mVideoTurnedOnTimer != null) { |
| 5835 | mVideoTurnedOnTimer.detach(); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 5836 | mVideoTurnedOnTimer = null; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5837 | } |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 5838 | if (mFlashlightTurnedOnTimer != null) { |
| 5839 | mFlashlightTurnedOnTimer.detach(); |
| 5840 | mFlashlightTurnedOnTimer = null; |
| 5841 | } |
| 5842 | if (mCameraTurnedOnTimer != null) { |
| 5843 | mCameraTurnedOnTimer.detach(); |
| 5844 | mCameraTurnedOnTimer = null; |
| 5845 | } |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 5846 | if (mForegroundActivityTimer != null) { |
| 5847 | mForegroundActivityTimer.detach(); |
| 5848 | mForegroundActivityTimer = null; |
| 5849 | } |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 5850 | if (mBluetoothScanTimer != null) { |
| 5851 | mBluetoothScanTimer.detach(); |
| 5852 | mBluetoothScanTimer = null; |
| 5853 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5854 | if (mUserActivityCounters != null) { |
| 5855 | for (int i=0; i<NUM_USER_ACTIVITY_TYPES; i++) { |
| 5856 | mUserActivityCounters[i].detach(); |
| 5857 | } |
| 5858 | } |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5859 | if (mNetworkByteActivityCounters != null) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5860 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 5861 | mNetworkByteActivityCounters[i].detach(); |
| 5862 | mNetworkPacketActivityCounters[i].detach(); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 5863 | } |
| 5864 | } |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 5865 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 5866 | if (mWifiControllerActivity != null) { |
| 5867 | mWifiControllerActivity.detach(); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 5868 | } |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 5869 | |
| 5870 | if (mBluetoothControllerActivity != null) { |
| 5871 | mBluetoothControllerActivity.detach(); |
| 5872 | } |
| 5873 | |
| 5874 | if (mModemControllerActivity != null) { |
| 5875 | mModemControllerActivity.detach(); |
| 5876 | } |
| 5877 | |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 5878 | mPids.clear(); |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 5879 | |
| 5880 | mUserCpuTime.detach(); |
| 5881 | mSystemCpuTime.detach(); |
Adam Lesinski | a7a4ccc | 2015-06-26 17:43:04 -0700 | [diff] [blame] | 5882 | mCpuPower.detach(); |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 5883 | |
| 5884 | if (mCpuClusterSpeed != null) { |
| 5885 | for (LongSamplingCounter[] cpuSpeeds : mCpuClusterSpeed) { |
| 5886 | if (cpuSpeeds != null) { |
| 5887 | for (LongSamplingCounter c : cpuSpeeds) { |
| 5888 | if (c != null) { |
| 5889 | c.detach(); |
| 5890 | } |
| 5891 | } |
| 5892 | } |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 5893 | } |
| 5894 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5895 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5896 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5897 | return !active; |
| 5898 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5899 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5900 | void writeToParcelLocked(Parcel out, long elapsedRealtimeUs) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 5901 | final ArrayMap<String, Wakelock> wakeStats = mWakelockStats.getMap(); |
| 5902 | int NW = wakeStats.size(); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5903 | out.writeInt(NW); |
| 5904 | for (int iw=0; iw<NW; iw++) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 5905 | out.writeString(wakeStats.keyAt(iw)); |
| 5906 | Uid.Wakelock wakelock = wakeStats.valueAt(iw); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5907 | wakelock.writeToParcelLocked(out, elapsedRealtimeUs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5908 | } |
| 5909 | |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 5910 | final ArrayMap<String, StopwatchTimer> syncStats = mSyncStats.getMap(); |
| 5911 | int NS = syncStats.size(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 5912 | out.writeInt(NS); |
| 5913 | for (int is=0; is<NS; is++) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 5914 | out.writeString(syncStats.keyAt(is)); |
| 5915 | StopwatchTimer timer = syncStats.valueAt(is); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 5916 | Timer.writeTimerToParcel(out, timer, elapsedRealtimeUs); |
| 5917 | } |
| 5918 | |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 5919 | final ArrayMap<String, StopwatchTimer> jobStats = mJobStats.getMap(); |
| 5920 | int NJ = jobStats.size(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 5921 | out.writeInt(NJ); |
| 5922 | for (int ij=0; ij<NJ; ij++) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 5923 | out.writeString(jobStats.keyAt(ij)); |
| 5924 | StopwatchTimer timer = jobStats.valueAt(ij); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 5925 | Timer.writeTimerToParcel(out, timer, elapsedRealtimeUs); |
| 5926 | } |
| 5927 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5928 | int NSE = mSensorStats.size(); |
| 5929 | out.writeInt(NSE); |
| 5930 | for (int ise=0; ise<NSE; ise++) { |
| 5931 | out.writeInt(mSensorStats.keyAt(ise)); |
| 5932 | Uid.Sensor sensor = mSensorStats.valueAt(ise); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5933 | sensor.writeToParcelLocked(out, elapsedRealtimeUs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5934 | } |
| 5935 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 5936 | int NP = mProcessStats.size(); |
| 5937 | out.writeInt(NP); |
| 5938 | for (int ip=0; ip<NP; ip++) { |
| 5939 | out.writeString(mProcessStats.keyAt(ip)); |
| 5940 | Uid.Proc proc = mProcessStats.valueAt(ip); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5941 | proc.writeToParcelLocked(out); |
| 5942 | } |
| 5943 | |
| 5944 | out.writeInt(mPackageStats.size()); |
| 5945 | for (Map.Entry<String, Uid.Pkg> pkgEntry : mPackageStats.entrySet()) { |
| 5946 | out.writeString(pkgEntry.getKey()); |
| 5947 | Uid.Pkg pkg = pkgEntry.getValue(); |
| 5948 | pkg.writeToParcelLocked(out); |
| 5949 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 5950 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 5951 | if (mWifiRunningTimer != null) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5952 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5953 | mWifiRunningTimer.writeToParcel(out, elapsedRealtimeUs); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 5954 | } else { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5955 | out.writeInt(0); |
| 5956 | } |
| 5957 | if (mFullWifiLockTimer != null) { |
| 5958 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5959 | mFullWifiLockTimer.writeToParcel(out, elapsedRealtimeUs); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5960 | } else { |
| 5961 | out.writeInt(0); |
| 5962 | } |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 5963 | if (mWifiScanTimer != null) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5964 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5965 | mWifiScanTimer.writeToParcel(out, elapsedRealtimeUs); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5966 | } else { |
| 5967 | out.writeInt(0); |
| 5968 | } |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 5969 | for (int i = 0; i < NUM_WIFI_BATCHED_SCAN_BINS; i++) { |
| 5970 | if (mWifiBatchedScanTimer[i] != null) { |
| 5971 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5972 | mWifiBatchedScanTimer[i].writeToParcel(out, elapsedRealtimeUs); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 5973 | } else { |
| 5974 | out.writeInt(0); |
| 5975 | } |
| 5976 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5977 | if (mWifiMulticastTimer != null) { |
| 5978 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5979 | mWifiMulticastTimer.writeToParcel(out, elapsedRealtimeUs); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5980 | } else { |
| 5981 | out.writeInt(0); |
| 5982 | } |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 5983 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5984 | if (mAudioTurnedOnTimer != null) { |
| 5985 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5986 | mAudioTurnedOnTimer.writeToParcel(out, elapsedRealtimeUs); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5987 | } else { |
| 5988 | out.writeInt(0); |
| 5989 | } |
| 5990 | if (mVideoTurnedOnTimer != null) { |
| 5991 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 5992 | mVideoTurnedOnTimer.writeToParcel(out, elapsedRealtimeUs); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 5993 | } else { |
| 5994 | out.writeInt(0); |
| 5995 | } |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 5996 | if (mFlashlightTurnedOnTimer != null) { |
| 5997 | out.writeInt(1); |
| 5998 | mFlashlightTurnedOnTimer.writeToParcel(out, elapsedRealtimeUs); |
| 5999 | } else { |
| 6000 | out.writeInt(0); |
| 6001 | } |
| 6002 | if (mCameraTurnedOnTimer != null) { |
| 6003 | out.writeInt(1); |
| 6004 | mCameraTurnedOnTimer.writeToParcel(out, elapsedRealtimeUs); |
| 6005 | } else { |
| 6006 | out.writeInt(0); |
| 6007 | } |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 6008 | if (mForegroundActivityTimer != null) { |
| 6009 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6010 | mForegroundActivityTimer.writeToParcel(out, elapsedRealtimeUs); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 6011 | } else { |
| 6012 | out.writeInt(0); |
| 6013 | } |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 6014 | if (mBluetoothScanTimer != null) { |
| 6015 | out.writeInt(1); |
| 6016 | mBluetoothScanTimer.writeToParcel(out, elapsedRealtimeUs); |
| 6017 | } else { |
| 6018 | out.writeInt(0); |
| 6019 | } |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 6020 | for (int i = 0; i < NUM_PROCESS_STATE; i++) { |
| 6021 | if (mProcessStateTimer[i] != null) { |
| 6022 | out.writeInt(1); |
| 6023 | mProcessStateTimer[i].writeToParcel(out, elapsedRealtimeUs); |
| 6024 | } else { |
| 6025 | out.writeInt(0); |
| 6026 | } |
| 6027 | } |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 6028 | if (mVibratorOnTimer != null) { |
| 6029 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6030 | mVibratorOnTimer.writeToParcel(out, elapsedRealtimeUs); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 6031 | } else { |
| 6032 | out.writeInt(0); |
| 6033 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6034 | if (mUserActivityCounters != null) { |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 6035 | out.writeInt(1); |
| 6036 | for (int i=0; i<NUM_USER_ACTIVITY_TYPES; i++) { |
| 6037 | mUserActivityCounters[i].writeToParcel(out); |
| 6038 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6039 | } else { |
| 6040 | out.writeInt(0); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 6041 | } |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6042 | if (mNetworkByteActivityCounters != null) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 6043 | out.writeInt(1); |
| 6044 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6045 | mNetworkByteActivityCounters[i].writeToParcel(out); |
| 6046 | mNetworkPacketActivityCounters[i].writeToParcel(out); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 6047 | } |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 6048 | mMobileRadioActiveTime.writeToParcel(out); |
| 6049 | mMobileRadioActiveCount.writeToParcel(out); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 6050 | } else { |
| 6051 | out.writeInt(0); |
| 6052 | } |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 6053 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 6054 | if (mWifiControllerActivity != null) { |
| 6055 | out.writeInt(1); |
| 6056 | mWifiControllerActivity.writeToParcel(out, 0); |
| 6057 | } else { |
| 6058 | out.writeInt(0); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 6059 | } |
| 6060 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 6061 | if (mBluetoothControllerActivity != null) { |
| 6062 | out.writeInt(1); |
| 6063 | mBluetoothControllerActivity.writeToParcel(out, 0); |
| 6064 | } else { |
| 6065 | out.writeInt(0); |
| 6066 | } |
| 6067 | |
| 6068 | if (mModemControllerActivity != null) { |
| 6069 | out.writeInt(1); |
| 6070 | mModemControllerActivity.writeToParcel(out, 0); |
| 6071 | } else { |
| 6072 | out.writeInt(0); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 6073 | } |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 6074 | |
| 6075 | mUserCpuTime.writeToParcel(out); |
| 6076 | mSystemCpuTime.writeToParcel(out); |
Adam Lesinski | a7a4ccc | 2015-06-26 17:43:04 -0700 | [diff] [blame] | 6077 | mCpuPower.writeToParcel(out); |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 6078 | |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 6079 | if (mCpuClusterSpeed != null) { |
| 6080 | out.writeInt(1); |
| 6081 | out.writeInt(mCpuClusterSpeed.length); |
| 6082 | for (LongSamplingCounter[] cpuSpeeds : mCpuClusterSpeed) { |
| 6083 | if (cpuSpeeds != null) { |
| 6084 | out.writeInt(1); |
| 6085 | out.writeInt(cpuSpeeds.length); |
| 6086 | for (LongSamplingCounter c : cpuSpeeds) { |
| 6087 | if (c != null) { |
| 6088 | out.writeInt(1); |
| 6089 | c.writeToParcel(out); |
| 6090 | } else { |
| 6091 | out.writeInt(0); |
| 6092 | } |
| 6093 | } |
| 6094 | } else { |
| 6095 | out.writeInt(0); |
| 6096 | } |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 6097 | } |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 6098 | } else { |
| 6099 | out.writeInt(0); |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 6100 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6101 | } |
| 6102 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6103 | void readFromParcelLocked(TimeBase timeBase, TimeBase screenOffTimeBase, Parcel in) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6104 | int numWakelocks = in.readInt(); |
| 6105 | mWakelockStats.clear(); |
| 6106 | for (int j = 0; j < numWakelocks; j++) { |
| 6107 | String wakelockName = in.readString(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6108 | Uid.Wakelock wakelock = new Wakelock(mBsi, this); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6109 | wakelock.readFromParcelLocked(timeBase, screenOffTimeBase, in); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 6110 | mWakelockStats.add(wakelockName, wakelock); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6111 | } |
| 6112 | |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 6113 | int numSyncs = in.readInt(); |
| 6114 | mSyncStats.clear(); |
| 6115 | for (int j = 0; j < numSyncs; j++) { |
| 6116 | String syncName = in.readString(); |
| 6117 | if (in.readInt() != 0) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 6118 | mSyncStats.add(syncName, |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6119 | new StopwatchTimer(mBsi.mClocks, Uid.this, SYNC, null, timeBase, in)); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 6120 | } |
| 6121 | } |
| 6122 | |
| 6123 | int numJobs = in.readInt(); |
| 6124 | mJobStats.clear(); |
| 6125 | for (int j = 0; j < numJobs; j++) { |
| 6126 | String jobName = in.readString(); |
| 6127 | if (in.readInt() != 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6128 | mJobStats.add(jobName, new StopwatchTimer(mBsi.mClocks, Uid.this, JOB, null, |
| 6129 | timeBase, in)); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 6130 | } |
| 6131 | } |
| 6132 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6133 | int numSensors = in.readInt(); |
| 6134 | mSensorStats.clear(); |
| 6135 | for (int k = 0; k < numSensors; k++) { |
| 6136 | int sensorNumber = in.readInt(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6137 | Uid.Sensor sensor = new Sensor(mBsi, this, sensorNumber); |
| 6138 | sensor.readFromParcelLocked(mBsi.mOnBatteryTimeBase, in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6139 | mSensorStats.put(sensorNumber, sensor); |
| 6140 | } |
| 6141 | |
| 6142 | int numProcs = in.readInt(); |
| 6143 | mProcessStats.clear(); |
| 6144 | for (int k = 0; k < numProcs; k++) { |
| 6145 | String processName = in.readString(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6146 | Uid.Proc proc = new Proc(mBsi, processName); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6147 | proc.readFromParcelLocked(in); |
| 6148 | mProcessStats.put(processName, proc); |
| 6149 | } |
| 6150 | |
| 6151 | int numPkgs = in.readInt(); |
| 6152 | mPackageStats.clear(); |
| 6153 | for (int l = 0; l < numPkgs; l++) { |
| 6154 | String packageName = in.readString(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6155 | Uid.Pkg pkg = new Pkg(mBsi); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6156 | pkg.readFromParcelLocked(in); |
| 6157 | mPackageStats.put(packageName, pkg); |
| 6158 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6159 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 6160 | mWifiRunning = false; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6161 | if (in.readInt() != 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6162 | mWifiRunningTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, WIFI_RUNNING, |
| 6163 | mBsi.mWifiRunningTimers, mBsi.mOnBatteryTimeBase, in); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 6164 | } else { |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 6165 | mWifiRunningTimer = null; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6166 | } |
| 6167 | mFullWifiLockOut = false; |
| 6168 | if (in.readInt() != 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6169 | mFullWifiLockTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, FULL_WIFI_LOCK, |
| 6170 | mBsi.mFullWifiLockTimers, mBsi.mOnBatteryTimeBase, in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6171 | } else { |
| 6172 | mFullWifiLockTimer = null; |
| 6173 | } |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 6174 | mWifiScanStarted = false; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6175 | if (in.readInt() != 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6176 | mWifiScanTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, WIFI_SCAN, |
| 6177 | mBsi.mWifiScanTimers, mBsi.mOnBatteryTimeBase, in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6178 | } else { |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 6179 | mWifiScanTimer = null; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6180 | } |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 6181 | mWifiBatchedScanBinStarted = NO_BATCHED_SCAN_STARTED; |
| 6182 | for (int i = 0; i < NUM_WIFI_BATCHED_SCAN_BINS; i++) { |
| 6183 | if (in.readInt() != 0) { |
| 6184 | makeWifiBatchedScanBin(i, in); |
| 6185 | } else { |
| 6186 | mWifiBatchedScanTimer[i] = null; |
| 6187 | } |
| 6188 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6189 | mWifiMulticastEnabled = false; |
| 6190 | if (in.readInt() != 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6191 | mWifiMulticastTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, WIFI_MULTICAST_ENABLED, |
| 6192 | mBsi.mWifiMulticastTimers, mBsi.mOnBatteryTimeBase, in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6193 | } else { |
| 6194 | mWifiMulticastTimer = null; |
| 6195 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6196 | if (in.readInt() != 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6197 | mAudioTurnedOnTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, AUDIO_TURNED_ON, |
| 6198 | mBsi.mAudioTurnedOnTimers, mBsi.mOnBatteryTimeBase, in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6199 | } else { |
| 6200 | mAudioTurnedOnTimer = null; |
| 6201 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6202 | if (in.readInt() != 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6203 | mVideoTurnedOnTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, VIDEO_TURNED_ON, |
| 6204 | mBsi.mVideoTurnedOnTimers, mBsi.mOnBatteryTimeBase, in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6205 | } else { |
| 6206 | mVideoTurnedOnTimer = null; |
| 6207 | } |
| 6208 | if (in.readInt() != 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6209 | mFlashlightTurnedOnTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, |
| 6210 | FLASHLIGHT_TURNED_ON, mBsi.mFlashlightTurnedOnTimers, mBsi.mOnBatteryTimeBase, in); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 6211 | } else { |
| 6212 | mFlashlightTurnedOnTimer = null; |
| 6213 | } |
| 6214 | if (in.readInt() != 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6215 | mCameraTurnedOnTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, CAMERA_TURNED_ON, |
| 6216 | mBsi.mCameraTurnedOnTimers, mBsi.mOnBatteryTimeBase, in); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 6217 | } else { |
| 6218 | mCameraTurnedOnTimer = null; |
| 6219 | } |
| 6220 | if (in.readInt() != 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6221 | mForegroundActivityTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, |
| 6222 | FOREGROUND_ACTIVITY, null, mBsi.mOnBatteryTimeBase, in); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 6223 | } else { |
| 6224 | mForegroundActivityTimer = null; |
| 6225 | } |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 6226 | if (in.readInt() != 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6227 | mBluetoothScanTimer = new StopwatchTimer(mBsi.mClocks, Uid.this, BLUETOOTH_SCAN_ON, |
| 6228 | mBsi.mBluetoothScanOnTimers, mBsi.mOnBatteryTimeBase, in); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 6229 | } else { |
| 6230 | mBluetoothScanTimer = null; |
| 6231 | } |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 6232 | mProcessState = ActivityManager.PROCESS_STATE_NONEXISTENT; |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 6233 | for (int i = 0; i < NUM_PROCESS_STATE; i++) { |
| 6234 | if (in.readInt() != 0) { |
| 6235 | makeProcessState(i, in); |
| 6236 | } else { |
| 6237 | mProcessStateTimer[i] = null; |
| 6238 | } |
| 6239 | } |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 6240 | if (in.readInt() != 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6241 | mVibratorOnTimer = new BatchTimer(mBsi.mClocks, Uid.this, VIBRATOR_ON, |
| 6242 | mBsi.mOnBatteryTimeBase, in); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 6243 | } else { |
| 6244 | mVibratorOnTimer = null; |
| 6245 | } |
| 6246 | if (in.readInt() != 0) { |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 6247 | mUserActivityCounters = new Counter[NUM_USER_ACTIVITY_TYPES]; |
| 6248 | for (int i=0; i<NUM_USER_ACTIVITY_TYPES; i++) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6249 | mUserActivityCounters[i] = new Counter(mBsi.mOnBatteryTimeBase, in); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 6250 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6251 | } else { |
| 6252 | mUserActivityCounters = null; |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 6253 | } |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 6254 | if (in.readInt() != 0) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6255 | mNetworkByteActivityCounters = new LongSamplingCounter[NUM_NETWORK_ACTIVITY_TYPES]; |
| 6256 | mNetworkPacketActivityCounters |
| 6257 | = new LongSamplingCounter[NUM_NETWORK_ACTIVITY_TYPES]; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 6258 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6259 | mNetworkByteActivityCounters[i] |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6260 | = new LongSamplingCounter(mBsi.mOnBatteryTimeBase, in); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6261 | mNetworkPacketActivityCounters[i] |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6262 | = new LongSamplingCounter(mBsi.mOnBatteryTimeBase, in); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 6263 | } |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6264 | mMobileRadioActiveTime = new LongSamplingCounter(mBsi.mOnBatteryTimeBase, in); |
| 6265 | mMobileRadioActiveCount = new LongSamplingCounter(mBsi.mOnBatteryTimeBase, in); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 6266 | } else { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 6267 | mNetworkByteActivityCounters = null; |
| 6268 | mNetworkPacketActivityCounters = null; |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 6269 | } |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 6270 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 6271 | if (in.readInt() != 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6272 | mWifiControllerActivity = new ControllerActivityCounterImpl(mBsi.mOnBatteryTimeBase, |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 6273 | NUM_WIFI_TX_LEVELS, in); |
| 6274 | } else { |
| 6275 | mWifiControllerActivity = null; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 6276 | } |
| 6277 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 6278 | if (in.readInt() != 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6279 | mBluetoothControllerActivity = new ControllerActivityCounterImpl(mBsi.mOnBatteryTimeBase, |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 6280 | NUM_BT_TX_LEVELS, in); |
| 6281 | } else { |
| 6282 | mBluetoothControllerActivity = null; |
| 6283 | } |
| 6284 | |
| 6285 | if (in.readInt() != 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6286 | mModemControllerActivity = new ControllerActivityCounterImpl(mBsi.mOnBatteryTimeBase, |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 6287 | ModemActivityInfo.TX_POWER_LEVELS, in); |
| 6288 | } else { |
| 6289 | mModemControllerActivity = null; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 6290 | } |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 6291 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6292 | mUserCpuTime = new LongSamplingCounter(mBsi.mOnBatteryTimeBase, in); |
| 6293 | mSystemCpuTime = new LongSamplingCounter(mBsi.mOnBatteryTimeBase, in); |
| 6294 | mCpuPower = new LongSamplingCounter(mBsi.mOnBatteryTimeBase, in); |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 6295 | |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 6296 | if (in.readInt() != 0) { |
| 6297 | int numCpuClusters = in.readInt(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6298 | if (mBsi.mPowerProfile != null && mBsi.mPowerProfile.getNumCpuClusters() != numCpuClusters) { |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 6299 | throw new ParcelFormatException("Incompatible number of cpu clusters"); |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 6300 | } |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 6301 | |
| 6302 | mCpuClusterSpeed = new LongSamplingCounter[numCpuClusters][]; |
| 6303 | for (int cluster = 0; cluster < numCpuClusters; cluster++) { |
| 6304 | if (in.readInt() != 0) { |
| 6305 | int numSpeeds = in.readInt(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6306 | if (mBsi.mPowerProfile != null && |
| 6307 | mBsi.mPowerProfile.getNumSpeedStepsInCpuCluster(cluster) != numSpeeds) { |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 6308 | throw new ParcelFormatException("Incompatible number of cpu speeds"); |
| 6309 | } |
| 6310 | |
| 6311 | final LongSamplingCounter[] cpuSpeeds = new LongSamplingCounter[numSpeeds]; |
| 6312 | mCpuClusterSpeed[cluster] = cpuSpeeds; |
| 6313 | for (int speed = 0; speed < numSpeeds; speed++) { |
| 6314 | if (in.readInt() != 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6315 | cpuSpeeds[speed] = new LongSamplingCounter(mBsi.mOnBatteryTimeBase, in); |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 6316 | } |
| 6317 | } |
Adam Lesinski | a57a540 | 2015-09-28 10:21:33 -0700 | [diff] [blame] | 6318 | } else { |
| 6319 | mCpuClusterSpeed[cluster] = null; |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 6320 | } |
| 6321 | } |
| 6322 | } else { |
| 6323 | mCpuClusterSpeed = null; |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 6324 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6325 | } |
| 6326 | |
| 6327 | /** |
| 6328 | * The statistics associated with a particular wake lock. |
| 6329 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6330 | public static class Wakelock extends BatteryStats.Uid.Wakelock { |
| 6331 | /** |
| 6332 | * BatteryStatsImpl that we are associated with. |
| 6333 | */ |
| 6334 | protected BatteryStatsImpl mBsi; |
| 6335 | |
| 6336 | /** |
| 6337 | * BatteryStatsImpl that we are associated with. |
| 6338 | */ |
| 6339 | protected Uid mUid; |
| 6340 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6341 | /** |
| 6342 | * How long (in ms) this uid has been keeping the device partially awake. |
| 6343 | */ |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 6344 | StopwatchTimer mTimerPartial; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6345 | |
| 6346 | /** |
| 6347 | * How long (in ms) this uid has been keeping the device fully awake. |
| 6348 | */ |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 6349 | StopwatchTimer mTimerFull; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6350 | |
| 6351 | /** |
| 6352 | * How long (in ms) this uid has had a window keeping the device awake. |
| 6353 | */ |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 6354 | StopwatchTimer mTimerWindow; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6355 | |
| 6356 | /** |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 6357 | * How long (in ms) this uid has had a draw wake lock. |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 6358 | */ |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 6359 | StopwatchTimer mTimerDraw; |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 6360 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6361 | public Wakelock(BatteryStatsImpl bsi, Uid uid) { |
| 6362 | mBsi = bsi; |
| 6363 | mUid = uid; |
| 6364 | } |
| 6365 | |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 6366 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6367 | * Reads a possibly null Timer from a Parcel. The timer is associated with the |
| 6368 | * proper timer pool from the given BatteryStatsImpl object. |
| 6369 | * |
| 6370 | * @param in the Parcel to be read from. |
| 6371 | * return a new Timer, or null. |
| 6372 | */ |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 6373 | private StopwatchTimer readTimerFromParcel(int type, ArrayList<StopwatchTimer> pool, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6374 | TimeBase timeBase, Parcel in) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6375 | if (in.readInt() == 0) { |
| 6376 | return null; |
| 6377 | } |
| 6378 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6379 | 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] | 6380 | } |
| 6381 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6382 | boolean reset() { |
| 6383 | boolean wlactive = false; |
| 6384 | if (mTimerFull != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6385 | wlactive |= !mTimerFull.reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6386 | } |
| 6387 | if (mTimerPartial != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6388 | wlactive |= !mTimerPartial.reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6389 | } |
| 6390 | if (mTimerWindow != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6391 | wlactive |= !mTimerWindow.reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6392 | } |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 6393 | if (mTimerDraw != null) { |
| 6394 | wlactive |= !mTimerDraw.reset(false); |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 6395 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6396 | if (!wlactive) { |
| 6397 | if (mTimerFull != null) { |
| 6398 | mTimerFull.detach(); |
| 6399 | mTimerFull = null; |
| 6400 | } |
| 6401 | if (mTimerPartial != null) { |
| 6402 | mTimerPartial.detach(); |
| 6403 | mTimerPartial = null; |
| 6404 | } |
| 6405 | if (mTimerWindow != null) { |
| 6406 | mTimerWindow.detach(); |
| 6407 | mTimerWindow = null; |
| 6408 | } |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 6409 | if (mTimerDraw != null) { |
| 6410 | mTimerDraw.detach(); |
| 6411 | mTimerDraw = null; |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 6412 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6413 | } |
| 6414 | return !wlactive; |
| 6415 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6416 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6417 | void readFromParcelLocked(TimeBase timeBase, TimeBase screenOffTimeBase, Parcel in) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6418 | mTimerPartial = readTimerFromParcel(WAKE_TYPE_PARTIAL, |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6419 | mBsi.mPartialTimers, screenOffTimeBase, in); |
| 6420 | mTimerFull = readTimerFromParcel(WAKE_TYPE_FULL, mBsi.mFullTimers, timeBase, in); |
| 6421 | mTimerWindow = readTimerFromParcel(WAKE_TYPE_WINDOW, mBsi.mWindowTimers, timeBase, in); |
| 6422 | mTimerDraw = readTimerFromParcel(WAKE_TYPE_DRAW, mBsi.mDrawTimers, timeBase, in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6423 | } |
| 6424 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6425 | void writeToParcelLocked(Parcel out, long elapsedRealtimeUs) { |
| 6426 | Timer.writeTimerToParcel(out, mTimerPartial, elapsedRealtimeUs); |
| 6427 | Timer.writeTimerToParcel(out, mTimerFull, elapsedRealtimeUs); |
| 6428 | Timer.writeTimerToParcel(out, mTimerWindow, elapsedRealtimeUs); |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 6429 | Timer.writeTimerToParcel(out, mTimerDraw, elapsedRealtimeUs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6430 | } |
| 6431 | |
| 6432 | @Override |
| 6433 | public Timer getWakeTime(int type) { |
| 6434 | switch (type) { |
| 6435 | case WAKE_TYPE_FULL: return mTimerFull; |
| 6436 | case WAKE_TYPE_PARTIAL: return mTimerPartial; |
| 6437 | case WAKE_TYPE_WINDOW: return mTimerWindow; |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 6438 | case WAKE_TYPE_DRAW: return mTimerDraw; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6439 | default: throw new IllegalArgumentException("type = " + type); |
| 6440 | } |
| 6441 | } |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 6442 | |
| 6443 | public StopwatchTimer getStopwatchTimer(int type) { |
| 6444 | StopwatchTimer t; |
| 6445 | switch (type) { |
| 6446 | case WAKE_TYPE_PARTIAL: |
| 6447 | t = mTimerPartial; |
| 6448 | if (t == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6449 | t = new StopwatchTimer(mBsi.mClocks, mUid, WAKE_TYPE_PARTIAL, |
| 6450 | mBsi.mPartialTimers, mBsi.mOnBatteryScreenOffTimeBase); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 6451 | mTimerPartial = t; |
| 6452 | } |
| 6453 | return t; |
| 6454 | case WAKE_TYPE_FULL: |
| 6455 | t = mTimerFull; |
| 6456 | if (t == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6457 | t = new StopwatchTimer(mBsi.mClocks, mUid, WAKE_TYPE_FULL, |
| 6458 | mBsi.mFullTimers, mBsi.mOnBatteryTimeBase); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 6459 | mTimerFull = t; |
| 6460 | } |
| 6461 | return t; |
| 6462 | case WAKE_TYPE_WINDOW: |
| 6463 | t = mTimerWindow; |
| 6464 | if (t == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6465 | t = new StopwatchTimer(mBsi.mClocks, mUid, WAKE_TYPE_WINDOW, |
| 6466 | mBsi.mWindowTimers, mBsi.mOnBatteryTimeBase); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 6467 | mTimerWindow = t; |
| 6468 | } |
| 6469 | return t; |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 6470 | case WAKE_TYPE_DRAW: |
| 6471 | t = mTimerDraw; |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 6472 | if (t == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6473 | t = new StopwatchTimer(mBsi.mClocks, mUid, WAKE_TYPE_DRAW, |
| 6474 | mBsi.mDrawTimers, mBsi.mOnBatteryTimeBase); |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 6475 | mTimerDraw = t; |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 6476 | } |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 6477 | return t; |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 6478 | default: |
| 6479 | throw new IllegalArgumentException("type=" + type); |
| 6480 | } |
| 6481 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6482 | } |
| 6483 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6484 | public static class Sensor extends BatteryStats.Uid.Sensor { |
| 6485 | /** |
| 6486 | * BatteryStatsImpl that we are associated with. |
| 6487 | */ |
| 6488 | protected BatteryStatsImpl mBsi; |
| 6489 | |
| 6490 | /** |
| 6491 | * BatteryStatsImpl that we are associated with. |
| 6492 | */ |
| 6493 | protected Uid mUid; |
| 6494 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6495 | final int mHandle; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 6496 | StopwatchTimer mTimer; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6497 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6498 | public Sensor(BatteryStatsImpl bsi, Uid uid, int handle) { |
| 6499 | mBsi = bsi; |
| 6500 | mUid = uid; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6501 | mHandle = handle; |
| 6502 | } |
| 6503 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6504 | private StopwatchTimer readTimerFromParcel(TimeBase timeBase, Parcel in) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6505 | if (in.readInt() == 0) { |
| 6506 | return null; |
| 6507 | } |
| 6508 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6509 | ArrayList<StopwatchTimer> pool = mBsi.mSensorTimers.get(mHandle); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6510 | if (pool == null) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 6511 | pool = new ArrayList<StopwatchTimer>(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6512 | mBsi.mSensorTimers.put(mHandle, pool); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6513 | } |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6514 | 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] | 6515 | } |
| 6516 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6517 | boolean reset() { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6518 | if (mTimer.reset(true)) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6519 | mTimer = null; |
| 6520 | return true; |
| 6521 | } |
| 6522 | return false; |
| 6523 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6524 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6525 | void readFromParcelLocked(TimeBase timeBase, Parcel in) { |
| 6526 | mTimer = readTimerFromParcel(timeBase, in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6527 | } |
| 6528 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6529 | void writeToParcelLocked(Parcel out, long elapsedRealtimeUs) { |
| 6530 | Timer.writeTimerToParcel(out, mTimer, elapsedRealtimeUs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6531 | } |
| 6532 | |
| 6533 | @Override |
| 6534 | public Timer getSensorTime() { |
| 6535 | return mTimer; |
| 6536 | } |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 6537 | |
| 6538 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6539 | public int getHandle() { |
| 6540 | return mHandle; |
| 6541 | } |
| 6542 | } |
| 6543 | |
| 6544 | /** |
| 6545 | * The statistics associated with a particular process. |
| 6546 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6547 | public static class Proc extends BatteryStats.Uid.Proc implements TimeBaseObs { |
| 6548 | /** |
| 6549 | * BatteryStatsImpl that we are associated with. |
| 6550 | */ |
| 6551 | protected BatteryStatsImpl mBsi; |
| 6552 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6553 | /** |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 6554 | * The name of this process. |
| 6555 | */ |
| 6556 | final String mName; |
| 6557 | |
| 6558 | /** |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 6559 | * Remains true until removed from the stats. |
| 6560 | */ |
| 6561 | boolean mActive = true; |
| 6562 | |
| 6563 | /** |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 6564 | * Total time (in ms) spent executing in user code. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6565 | */ |
| 6566 | long mUserTime; |
| 6567 | |
| 6568 | /** |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 6569 | * Total time (in ms) spent executing in kernel code. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6570 | */ |
| 6571 | long mSystemTime; |
| 6572 | |
| 6573 | /** |
Dianne Hackborn | 62793e4 | 2015-03-09 11:15:41 -0700 | [diff] [blame] | 6574 | * Amount of time (in ms) the process was running in the foreground. |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 6575 | */ |
| 6576 | long mForegroundTime; |
| 6577 | |
| 6578 | /** |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 6579 | * Number of times the process has been started. |
| 6580 | */ |
| 6581 | int mStarts; |
| 6582 | |
| 6583 | /** |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 6584 | * Number of times the process has crashed. |
| 6585 | */ |
| 6586 | int mNumCrashes; |
| 6587 | |
| 6588 | /** |
| 6589 | * Number of times the process has had an ANR. |
| 6590 | */ |
| 6591 | int mNumAnrs; |
| 6592 | |
| 6593 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6594 | * The amount of user time loaded from a previous save. |
| 6595 | */ |
| 6596 | long mLoadedUserTime; |
| 6597 | |
| 6598 | /** |
| 6599 | * The amount of system time loaded from a previous save. |
| 6600 | */ |
| 6601 | long mLoadedSystemTime; |
| 6602 | |
| 6603 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 6604 | * The amount of foreground time loaded from a previous save. |
| 6605 | */ |
| 6606 | long mLoadedForegroundTime; |
| 6607 | |
| 6608 | /** |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 6609 | * The number of times the process has started from a previous save. |
| 6610 | */ |
| 6611 | int mLoadedStarts; |
| 6612 | |
| 6613 | /** |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 6614 | * 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] | 6615 | */ |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 6616 | int mLoadedNumCrashes; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6617 | |
| 6618 | /** |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 6619 | * 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] | 6620 | */ |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 6621 | int mLoadedNumAnrs; |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 6622 | |
| 6623 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6624 | * The amount of user time when last unplugged. |
| 6625 | */ |
| 6626 | long mUnpluggedUserTime; |
| 6627 | |
| 6628 | /** |
| 6629 | * The amount of system time when last unplugged. |
| 6630 | */ |
| 6631 | long mUnpluggedSystemTime; |
| 6632 | |
| 6633 | /** |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 6634 | * The amount of foreground time since unplugged. |
| 6635 | */ |
| 6636 | long mUnpluggedForegroundTime; |
| 6637 | |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 6638 | /** |
| 6639 | * The number of times the process has started before unplugged. |
| 6640 | */ |
| 6641 | int mUnpluggedStarts; |
| 6642 | |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 6643 | /** |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 6644 | * Number of times the process has crashed before unplugged. |
| 6645 | */ |
| 6646 | int mUnpluggedNumCrashes; |
| 6647 | |
| 6648 | /** |
| 6649 | * Number of times the process has had an ANR before unplugged. |
| 6650 | */ |
| 6651 | int mUnpluggedNumAnrs; |
| 6652 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 6653 | ArrayList<ExcessivePower> mExcessivePower; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 6654 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6655 | public Proc(BatteryStatsImpl bsi, String name) { |
| 6656 | mBsi = bsi; |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 6657 | mName = name; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6658 | mBsi.mOnBatteryTimeBase.add(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6659 | } |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 6660 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6661 | public void onTimeStarted(long elapsedRealtime, long baseUptime, long baseRealtime) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6662 | mUnpluggedUserTime = mUserTime; |
| 6663 | mUnpluggedSystemTime = mSystemTime; |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 6664 | mUnpluggedForegroundTime = mForegroundTime; |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 6665 | mUnpluggedStarts = mStarts; |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 6666 | mUnpluggedNumCrashes = mNumCrashes; |
| 6667 | mUnpluggedNumAnrs = mNumAnrs; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6668 | } |
| 6669 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6670 | public void onTimeStopped(long elapsedRealtime, long baseUptime, long baseRealtime) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6671 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6672 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6673 | void detach() { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 6674 | mActive = false; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6675 | mBsi.mOnBatteryTimeBase.remove(this); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6676 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6677 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 6678 | public int countExcessivePowers() { |
| 6679 | return mExcessivePower != null ? mExcessivePower.size() : 0; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 6680 | } |
| 6681 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 6682 | public ExcessivePower getExcessivePower(int i) { |
| 6683 | if (mExcessivePower != null) { |
| 6684 | return mExcessivePower.get(i); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 6685 | } |
| 6686 | return null; |
| 6687 | } |
| 6688 | |
| 6689 | public void addExcessiveWake(long overTime, long usedTime) { |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 6690 | if (mExcessivePower == null) { |
| 6691 | mExcessivePower = new ArrayList<ExcessivePower>(); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 6692 | } |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 6693 | ExcessivePower ew = new ExcessivePower(); |
| 6694 | ew.type = ExcessivePower.TYPE_WAKE; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 6695 | ew.overTime = overTime; |
| 6696 | ew.usedTime = usedTime; |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 6697 | mExcessivePower.add(ew); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 6698 | } |
| 6699 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 6700 | public void addExcessiveCpu(long overTime, long usedTime) { |
| 6701 | if (mExcessivePower == null) { |
| 6702 | mExcessivePower = new ArrayList<ExcessivePower>(); |
| 6703 | } |
| 6704 | ExcessivePower ew = new ExcessivePower(); |
| 6705 | ew.type = ExcessivePower.TYPE_CPU; |
| 6706 | ew.overTime = overTime; |
| 6707 | ew.usedTime = usedTime; |
| 6708 | mExcessivePower.add(ew); |
| 6709 | } |
| 6710 | |
| 6711 | void writeExcessivePowerToParcelLocked(Parcel out) { |
| 6712 | if (mExcessivePower == null) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 6713 | out.writeInt(0); |
| 6714 | return; |
| 6715 | } |
| 6716 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 6717 | final int N = mExcessivePower.size(); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 6718 | out.writeInt(N); |
| 6719 | for (int i=0; i<N; i++) { |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 6720 | ExcessivePower ew = mExcessivePower.get(i); |
| 6721 | out.writeInt(ew.type); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 6722 | out.writeLong(ew.overTime); |
| 6723 | out.writeLong(ew.usedTime); |
| 6724 | } |
| 6725 | } |
| 6726 | |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 6727 | void readExcessivePowerFromParcelLocked(Parcel in) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 6728 | final int N = in.readInt(); |
| 6729 | if (N == 0) { |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 6730 | mExcessivePower = null; |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 6731 | return; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 6732 | } |
| 6733 | |
Dianne Hackborn | 7b9c56f | 2010-12-07 11:14:53 -0800 | [diff] [blame] | 6734 | if (N > 10000) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 6735 | throw new ParcelFormatException( |
| 6736 | "File corrupt: too many excessive power entries " + N); |
Dianne Hackborn | 7b9c56f | 2010-12-07 11:14:53 -0800 | [diff] [blame] | 6737 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 6738 | |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 6739 | mExcessivePower = new ArrayList<>(); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 6740 | for (int i=0; i<N; i++) { |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 6741 | ExcessivePower ew = new ExcessivePower(); |
| 6742 | ew.type = in.readInt(); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 6743 | ew.overTime = in.readLong(); |
| 6744 | ew.usedTime = in.readLong(); |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 6745 | mExcessivePower.add(ew); |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 6746 | } |
| 6747 | } |
| 6748 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6749 | void writeToParcelLocked(Parcel out) { |
| 6750 | out.writeLong(mUserTime); |
| 6751 | out.writeLong(mSystemTime); |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 6752 | out.writeLong(mForegroundTime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6753 | out.writeInt(mStarts); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 6754 | out.writeInt(mNumCrashes); |
| 6755 | out.writeInt(mNumAnrs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6756 | out.writeLong(mLoadedUserTime); |
| 6757 | out.writeLong(mLoadedSystemTime); |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 6758 | out.writeLong(mLoadedForegroundTime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6759 | out.writeInt(mLoadedStarts); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 6760 | out.writeInt(mLoadedNumCrashes); |
| 6761 | out.writeInt(mLoadedNumAnrs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6762 | out.writeLong(mUnpluggedUserTime); |
| 6763 | out.writeLong(mUnpluggedSystemTime); |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 6764 | out.writeLong(mUnpluggedForegroundTime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6765 | out.writeInt(mUnpluggedStarts); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 6766 | out.writeInt(mUnpluggedNumCrashes); |
| 6767 | out.writeInt(mUnpluggedNumAnrs); |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 6768 | writeExcessivePowerToParcelLocked(out); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6769 | } |
| 6770 | |
| 6771 | void readFromParcelLocked(Parcel in) { |
| 6772 | mUserTime = in.readLong(); |
| 6773 | mSystemTime = in.readLong(); |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 6774 | mForegroundTime = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6775 | mStarts = in.readInt(); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 6776 | mNumCrashes = in.readInt(); |
| 6777 | mNumAnrs = in.readInt(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6778 | mLoadedUserTime = in.readLong(); |
| 6779 | mLoadedSystemTime = in.readLong(); |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 6780 | mLoadedForegroundTime = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6781 | mLoadedStarts = in.readInt(); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 6782 | mLoadedNumCrashes = in.readInt(); |
| 6783 | mLoadedNumAnrs = in.readInt(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6784 | mUnpluggedUserTime = in.readLong(); |
| 6785 | mUnpluggedSystemTime = in.readLong(); |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 6786 | mUnpluggedForegroundTime = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6787 | mUnpluggedStarts = in.readInt(); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 6788 | mUnpluggedNumCrashes = in.readInt(); |
| 6789 | mUnpluggedNumAnrs = in.readInt(); |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 6790 | readExcessivePowerFromParcelLocked(in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6791 | } |
| 6792 | |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 6793 | public void addCpuTimeLocked(int utime, int stime) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6794 | mUserTime += utime; |
| 6795 | mSystemTime += stime; |
| 6796 | } |
| 6797 | |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 6798 | public void addForegroundTimeLocked(long ttime) { |
| 6799 | mForegroundTime += ttime; |
| 6800 | } |
| 6801 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6802 | public void incStartsLocked() { |
| 6803 | mStarts++; |
| 6804 | } |
| 6805 | |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 6806 | public void incNumCrashesLocked() { |
| 6807 | mNumCrashes++; |
| 6808 | } |
| 6809 | |
| 6810 | public void incNumAnrsLocked() { |
| 6811 | mNumAnrs++; |
| 6812 | } |
| 6813 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6814 | @Override |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 6815 | public boolean isActive() { |
| 6816 | return mActive; |
| 6817 | } |
| 6818 | |
| 6819 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6820 | public long getUserTime(int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 6821 | long val = mUserTime; |
| 6822 | if (which == STATS_CURRENT) { |
| 6823 | val -= mLoadedUserTime; |
| 6824 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 6825 | val -= mUnpluggedUserTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6826 | } |
| 6827 | return val; |
| 6828 | } |
| 6829 | |
| 6830 | @Override |
| 6831 | public long getSystemTime(int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 6832 | long val = mSystemTime; |
| 6833 | if (which == STATS_CURRENT) { |
| 6834 | val -= mLoadedSystemTime; |
| 6835 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 6836 | val -= mUnpluggedSystemTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6837 | } |
| 6838 | return val; |
| 6839 | } |
| 6840 | |
| 6841 | @Override |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 6842 | public long getForegroundTime(int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 6843 | long val = mForegroundTime; |
| 6844 | if (which == STATS_CURRENT) { |
| 6845 | val -= mLoadedForegroundTime; |
| 6846 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 6847 | val -= mUnpluggedForegroundTime; |
Amith Yamasani | eaeb663 | 2009-06-03 15:16:10 -0700 | [diff] [blame] | 6848 | } |
| 6849 | return val; |
| 6850 | } |
| 6851 | |
| 6852 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6853 | public int getStarts(int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 6854 | int val = mStarts; |
| 6855 | if (which == STATS_CURRENT) { |
| 6856 | val -= mLoadedStarts; |
| 6857 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 6858 | val -= mUnpluggedStarts; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6859 | } |
| 6860 | return val; |
| 6861 | } |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 6862 | |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 6863 | @Override |
| 6864 | public int getNumCrashes(int which) { |
| 6865 | int val = mNumCrashes; |
| 6866 | if (which == STATS_CURRENT) { |
| 6867 | val -= mLoadedNumCrashes; |
| 6868 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 6869 | val -= mUnpluggedNumCrashes; |
| 6870 | } |
| 6871 | return val; |
| 6872 | } |
| 6873 | |
| 6874 | @Override |
| 6875 | public int getNumAnrs(int which) { |
| 6876 | int val = mNumAnrs; |
| 6877 | if (which == STATS_CURRENT) { |
| 6878 | val -= mLoadedNumAnrs; |
| 6879 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 6880 | val -= mUnpluggedNumAnrs; |
| 6881 | } |
| 6882 | return val; |
| 6883 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6884 | } |
| 6885 | |
| 6886 | /** |
| 6887 | * The statistics associated with a particular package. |
| 6888 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6889 | public static class Pkg extends BatteryStats.Uid.Pkg implements TimeBaseObs { |
| 6890 | /** |
| 6891 | * BatteryStatsImpl that we are associated with. |
| 6892 | */ |
| 6893 | protected BatteryStatsImpl mBsi; |
| 6894 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6895 | /** |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 6896 | * 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] | 6897 | */ |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 6898 | ArrayMap<String, Counter> mWakeupAlarms = new ArrayMap<>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6899 | |
| 6900 | /** |
| 6901 | * The statics we have collected for this package's services. |
| 6902 | */ |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 6903 | final ArrayMap<String, Serv> mServiceStats = new ArrayMap<>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6904 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6905 | public Pkg(BatteryStatsImpl bsi) { |
| 6906 | mBsi = bsi; |
| 6907 | mBsi.mOnBatteryScreenOffTimeBase.add(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6908 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6909 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6910 | public void onTimeStarted(long elapsedRealtime, long baseUptime, long baseRealtime) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6911 | } |
| 6912 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 6913 | public void onTimeStopped(long elapsedRealtime, long baseUptime, long baseRealtime) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6914 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6915 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6916 | void detach() { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6917 | mBsi.mOnBatteryScreenOffTimeBase.remove(this); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 6918 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 6919 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6920 | void readFromParcelLocked(Parcel in) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 6921 | int numWA = in.readInt(); |
| 6922 | mWakeupAlarms.clear(); |
| 6923 | for (int i=0; i<numWA; i++) { |
| 6924 | String tag = in.readString(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6925 | mWakeupAlarms.put(tag, new Counter(mBsi.mOnBatteryTimeBase, in)); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 6926 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6927 | |
| 6928 | int numServs = in.readInt(); |
| 6929 | mServiceStats.clear(); |
| 6930 | for (int m = 0; m < numServs; m++) { |
| 6931 | String serviceName = in.readString(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6932 | Uid.Pkg.Serv serv = new Serv(mBsi); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6933 | mServiceStats.put(serviceName, serv); |
| 6934 | |
| 6935 | serv.readFromParcelLocked(in); |
| 6936 | } |
| 6937 | } |
| 6938 | |
| 6939 | void writeToParcelLocked(Parcel out) { |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 6940 | int numWA = mWakeupAlarms.size(); |
| 6941 | out.writeInt(numWA); |
| 6942 | for (int i=0; i<numWA; i++) { |
| 6943 | out.writeString(mWakeupAlarms.keyAt(i)); |
| 6944 | mWakeupAlarms.valueAt(i).writeToParcel(out); |
| 6945 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6946 | |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 6947 | final int NS = mServiceStats.size(); |
| 6948 | out.writeInt(NS); |
| 6949 | for (int i=0; i<NS; i++) { |
| 6950 | out.writeString(mServiceStats.keyAt(i)); |
| 6951 | Uid.Pkg.Serv serv = mServiceStats.valueAt(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6952 | serv.writeToParcelLocked(out); |
| 6953 | } |
| 6954 | } |
| 6955 | |
| 6956 | @Override |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 6957 | public ArrayMap<String, ? extends BatteryStats.Counter> getWakeupAlarmStats() { |
| 6958 | return mWakeupAlarms; |
| 6959 | } |
| 6960 | |
| 6961 | public void noteWakeupAlarmLocked(String tag) { |
| 6962 | Counter c = mWakeupAlarms.get(tag); |
| 6963 | if (c == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6964 | c = new Counter(mBsi.mOnBatteryTimeBase); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 6965 | mWakeupAlarms.put(tag, c); |
| 6966 | } |
| 6967 | c.stepAtomic(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6968 | } |
| 6969 | |
| 6970 | @Override |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 6971 | public ArrayMap<String, ? extends BatteryStats.Uid.Pkg.Serv> getServiceStats() { |
| 6972 | return mServiceStats; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6973 | } |
| 6974 | |
| 6975 | /** |
| 6976 | * The statistics associated with a particular service. |
| 6977 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6978 | public static class Serv extends BatteryStats.Uid.Pkg.Serv implements TimeBaseObs { |
| 6979 | /** |
| 6980 | * BatteryStatsImpl that we are associated with. |
| 6981 | */ |
| 6982 | protected BatteryStatsImpl mBsi; |
| 6983 | |
| 6984 | /** |
| 6985 | * The android package in which this service resides. |
| 6986 | */ |
| 6987 | protected Pkg mPkg; |
| 6988 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6989 | /** |
| 6990 | * Total time (ms in battery uptime) the service has been left started. |
| 6991 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6992 | protected long mStartTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6993 | |
| 6994 | /** |
| 6995 | * If service has been started and not yet stopped, this is |
| 6996 | * when it was started. |
| 6997 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 6998 | protected long mRunningSince; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6999 | |
| 7000 | /** |
| 7001 | * True if we are currently running. |
| 7002 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7003 | protected boolean mRunning; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7004 | |
| 7005 | /** |
| 7006 | * Total number of times startService() has been called. |
| 7007 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7008 | protected int mStarts; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7009 | |
| 7010 | /** |
| 7011 | * Total time (ms in battery uptime) the service has been left launched. |
| 7012 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7013 | protected long mLaunchedTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7014 | |
| 7015 | /** |
| 7016 | * If service has been launched and not yet exited, this is |
| 7017 | * when it was launched (ms in battery uptime). |
| 7018 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7019 | protected long mLaunchedSince; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7020 | |
| 7021 | /** |
| 7022 | * True if we are currently launched. |
| 7023 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7024 | protected boolean mLaunched; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7025 | |
| 7026 | /** |
| 7027 | * Total number times the service has been launched. |
| 7028 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7029 | protected int mLaunches; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7030 | |
| 7031 | /** |
| 7032 | * The amount of time spent started loaded from a previous save |
| 7033 | * (ms in battery uptime). |
| 7034 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7035 | protected long mLoadedStartTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7036 | |
| 7037 | /** |
| 7038 | * The number of starts loaded from a previous save. |
| 7039 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7040 | protected int mLoadedStarts; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7041 | |
| 7042 | /** |
| 7043 | * The number of launches loaded from a previous save. |
| 7044 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7045 | protected int mLoadedLaunches; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7046 | |
| 7047 | /** |
| 7048 | * The amount of time spent started as of the last run (ms |
| 7049 | * in battery uptime). |
| 7050 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7051 | protected long mLastStartTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7052 | |
| 7053 | /** |
| 7054 | * The number of starts as of the last run. |
| 7055 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7056 | protected int mLastStarts; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7057 | |
| 7058 | /** |
| 7059 | * The number of launches as of the last run. |
| 7060 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7061 | protected int mLastLaunches; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7062 | |
| 7063 | /** |
| 7064 | * The amount of time spent started when last unplugged (ms |
| 7065 | * in battery uptime). |
| 7066 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7067 | protected long mUnpluggedStartTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7068 | |
| 7069 | /** |
| 7070 | * The number of starts when last unplugged. |
| 7071 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7072 | protected int mUnpluggedStarts; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7073 | |
| 7074 | /** |
| 7075 | * The number of launches when last unplugged. |
| 7076 | */ |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7077 | protected int mUnpluggedLaunches; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7078 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7079 | /** |
| 7080 | * Construct a Serv. Also adds it to the on-battery time base as a listener. |
| 7081 | */ |
| 7082 | public Serv(BatteryStatsImpl bsi) { |
| 7083 | mBsi = bsi; |
| 7084 | mBsi.mOnBatteryTimeBase.add(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7085 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7086 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7087 | public void onTimeStarted(long elapsedRealtime, long baseUptime, |
| 7088 | long baseRealtime) { |
| 7089 | mUnpluggedStartTime = getStartTimeToNowLocked(baseUptime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7090 | mUnpluggedStarts = mStarts; |
| 7091 | mUnpluggedLaunches = mLaunches; |
| 7092 | } |
| 7093 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7094 | public void onTimeStopped(long elapsedRealtime, long baseUptime, |
| 7095 | long baseRealtime) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7096 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7097 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7098 | /** |
| 7099 | * Remove this Serv as a listener from the time base. |
| 7100 | */ |
| 7101 | public void detach() { |
| 7102 | mBsi.mOnBatteryTimeBase.remove(this); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7103 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7104 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7105 | public void readFromParcelLocked(Parcel in) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7106 | mStartTime = in.readLong(); |
| 7107 | mRunningSince = in.readLong(); |
| 7108 | mRunning = in.readInt() != 0; |
| 7109 | mStarts = in.readInt(); |
| 7110 | mLaunchedTime = in.readLong(); |
| 7111 | mLaunchedSince = in.readLong(); |
| 7112 | mLaunched = in.readInt() != 0; |
| 7113 | mLaunches = in.readInt(); |
| 7114 | mLoadedStartTime = in.readLong(); |
| 7115 | mLoadedStarts = in.readInt(); |
| 7116 | mLoadedLaunches = in.readInt(); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 7117 | mLastStartTime = 0; |
| 7118 | mLastStarts = 0; |
| 7119 | mLastLaunches = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7120 | mUnpluggedStartTime = in.readLong(); |
| 7121 | mUnpluggedStarts = in.readInt(); |
| 7122 | mUnpluggedLaunches = in.readInt(); |
| 7123 | } |
| 7124 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7125 | public void writeToParcelLocked(Parcel out) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7126 | out.writeLong(mStartTime); |
| 7127 | out.writeLong(mRunningSince); |
| 7128 | out.writeInt(mRunning ? 1 : 0); |
| 7129 | out.writeInt(mStarts); |
| 7130 | out.writeLong(mLaunchedTime); |
| 7131 | out.writeLong(mLaunchedSince); |
| 7132 | out.writeInt(mLaunched ? 1 : 0); |
| 7133 | out.writeInt(mLaunches); |
| 7134 | out.writeLong(mLoadedStartTime); |
| 7135 | out.writeInt(mLoadedStarts); |
| 7136 | out.writeInt(mLoadedLaunches); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7137 | out.writeLong(mUnpluggedStartTime); |
| 7138 | out.writeInt(mUnpluggedStarts); |
| 7139 | out.writeInt(mUnpluggedLaunches); |
| 7140 | } |
| 7141 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7142 | public long getLaunchTimeToNowLocked(long batteryUptime) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7143 | if (!mLaunched) return mLaunchedTime; |
| 7144 | return mLaunchedTime + batteryUptime - mLaunchedSince; |
| 7145 | } |
| 7146 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7147 | public long getStartTimeToNowLocked(long batteryUptime) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7148 | if (!mRunning) return mStartTime; |
| 7149 | return mStartTime + batteryUptime - mRunningSince; |
| 7150 | } |
| 7151 | |
| 7152 | public void startLaunchedLocked() { |
| 7153 | if (!mLaunched) { |
| 7154 | mLaunches++; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7155 | mLaunchedSince = mBsi.getBatteryUptimeLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7156 | mLaunched = true; |
| 7157 | } |
| 7158 | } |
| 7159 | |
| 7160 | public void stopLaunchedLocked() { |
| 7161 | if (mLaunched) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7162 | long time = mBsi.getBatteryUptimeLocked() - mLaunchedSince; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7163 | if (time > 0) { |
| 7164 | mLaunchedTime += time; |
| 7165 | } else { |
| 7166 | mLaunches--; |
| 7167 | } |
| 7168 | mLaunched = false; |
| 7169 | } |
| 7170 | } |
| 7171 | |
| 7172 | public void startRunningLocked() { |
| 7173 | if (!mRunning) { |
| 7174 | mStarts++; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7175 | mRunningSince = mBsi.getBatteryUptimeLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7176 | mRunning = true; |
| 7177 | } |
| 7178 | } |
| 7179 | |
| 7180 | public void stopRunningLocked() { |
| 7181 | if (mRunning) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7182 | long time = mBsi.getBatteryUptimeLocked() - mRunningSince; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7183 | if (time > 0) { |
| 7184 | mStartTime += time; |
| 7185 | } else { |
| 7186 | mStarts--; |
| 7187 | } |
| 7188 | mRunning = false; |
| 7189 | } |
| 7190 | } |
| 7191 | |
| 7192 | public BatteryStatsImpl getBatteryStats() { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7193 | return mBsi; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7194 | } |
| 7195 | |
| 7196 | @Override |
| 7197 | public int getLaunches(int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 7198 | int val = mLaunches; |
| 7199 | if (which == STATS_CURRENT) { |
| 7200 | val -= mLoadedLaunches; |
| 7201 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 7202 | val -= mUnpluggedLaunches; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7203 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7204 | return val; |
| 7205 | } |
| 7206 | |
| 7207 | @Override |
| 7208 | public long getStartTime(long now, int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 7209 | long val = getStartTimeToNowLocked(now); |
| 7210 | if (which == STATS_CURRENT) { |
| 7211 | val -= mLoadedStartTime; |
| 7212 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 7213 | val -= mUnpluggedStartTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7214 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7215 | return val; |
| 7216 | } |
| 7217 | |
| 7218 | @Override |
| 7219 | public int getStarts(int which) { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 7220 | int val = mStarts; |
| 7221 | if (which == STATS_CURRENT) { |
| 7222 | val -= mLoadedStarts; |
| 7223 | } else if (which == STATS_SINCE_UNPLUGGED) { |
| 7224 | val -= mUnpluggedStarts; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7225 | } |
| 7226 | |
| 7227 | return val; |
| 7228 | } |
| 7229 | } |
| 7230 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7231 | final Serv newServiceStatsLocked() { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7232 | return new Serv(mBsi); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7233 | } |
| 7234 | } |
| 7235 | |
| 7236 | /** |
| 7237 | * Retrieve the statistics object for a particular process, creating |
| 7238 | * if needed. |
| 7239 | */ |
| 7240 | public Proc getProcessStatsLocked(String name) { |
| 7241 | Proc ps = mProcessStats.get(name); |
| 7242 | if (ps == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7243 | ps = new Proc(mBsi, name); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7244 | mProcessStats.put(name, ps); |
| 7245 | } |
| 7246 | |
| 7247 | return ps; |
| 7248 | } |
| 7249 | |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 7250 | public void updateUidProcessStateLocked(int procState) { |
| 7251 | int uidRunningState; |
| 7252 | if (procState == ActivityManager.PROCESS_STATE_NONEXISTENT) { |
| 7253 | uidRunningState = ActivityManager.PROCESS_STATE_NONEXISTENT; |
| 7254 | } else if (procState == ActivityManager.PROCESS_STATE_TOP) { |
| 7255 | uidRunningState = PROCESS_STATE_TOP; |
| 7256 | } else if (procState <= ActivityManager.PROCESS_STATE_FOREGROUND_SERVICE) { |
| 7257 | // Persistent and other foreground states go here. |
| 7258 | uidRunningState = PROCESS_STATE_FOREGROUND_SERVICE; |
| 7259 | } else if (procState <= ActivityManager.PROCESS_STATE_TOP_SLEEPING) { |
| 7260 | uidRunningState = PROCESS_STATE_TOP_SLEEPING; |
| 7261 | } else if (procState <= ActivityManager.PROCESS_STATE_IMPORTANT_FOREGROUND) { |
| 7262 | // Persistent and other foreground states go here. |
| 7263 | uidRunningState = PROCESS_STATE_FOREGROUND; |
| 7264 | } else if (procState <= ActivityManager.PROCESS_STATE_RECEIVER) { |
| 7265 | uidRunningState = PROCESS_STATE_BACKGROUND; |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 7266 | } else { |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 7267 | uidRunningState = PROCESS_STATE_CACHED; |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 7268 | } |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 7269 | |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 7270 | if (mProcessState == uidRunningState) return; |
| 7271 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7272 | final long elapsedRealtime = mBsi.mClocks.elapsedRealtime(); |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 7273 | |
| 7274 | if (mProcessState != ActivityManager.PROCESS_STATE_NONEXISTENT) { |
| 7275 | mProcessStateTimer[mProcessState].stopRunningLocked(elapsedRealtime); |
| 7276 | } |
| 7277 | mProcessState = uidRunningState; |
| 7278 | if (uidRunningState != ActivityManager.PROCESS_STATE_NONEXISTENT) { |
| 7279 | if (mProcessStateTimer[uidRunningState] == null) { |
| 7280 | makeProcessState(uidRunningState, null); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 7281 | } |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 7282 | mProcessStateTimer[uidRunningState].startRunningLocked(elapsedRealtime); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 7283 | } |
| 7284 | } |
| 7285 | |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 7286 | public SparseArray<? extends Pid> getPidStats() { |
| 7287 | return mPids; |
| 7288 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7289 | |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 7290 | public Pid getPidStatsLocked(int pid) { |
| 7291 | Pid p = mPids.get(pid); |
| 7292 | if (p == null) { |
| 7293 | p = new Pid(); |
| 7294 | mPids.put(pid, p); |
| 7295 | } |
| 7296 | return p; |
| 7297 | } |
| 7298 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7299 | /** |
| 7300 | * Retrieve the statistics object for a particular service, creating |
| 7301 | * if needed. |
| 7302 | */ |
| 7303 | public Pkg getPackageStatsLocked(String name) { |
| 7304 | Pkg ps = mPackageStats.get(name); |
| 7305 | if (ps == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7306 | ps = new Pkg(mBsi); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7307 | mPackageStats.put(name, ps); |
| 7308 | } |
| 7309 | |
| 7310 | return ps; |
| 7311 | } |
| 7312 | |
| 7313 | /** |
| 7314 | * Retrieve the statistics object for a particular service, creating |
| 7315 | * if needed. |
| 7316 | */ |
| 7317 | public Pkg.Serv getServiceStatsLocked(String pkg, String serv) { |
| 7318 | Pkg ps = getPackageStatsLocked(pkg); |
| 7319 | Pkg.Serv ss = ps.mServiceStats.get(serv); |
| 7320 | if (ss == null) { |
| 7321 | ss = ps.newServiceStatsLocked(); |
| 7322 | ps.mServiceStats.put(serv, ss); |
| 7323 | } |
| 7324 | |
| 7325 | return ss; |
| 7326 | } |
| 7327 | |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 7328 | public void readSyncSummaryFromParcelLocked(String name, Parcel in) { |
| 7329 | StopwatchTimer timer = mSyncStats.instantiateObject(); |
| 7330 | timer.readSummaryFromParcelLocked(in); |
| 7331 | mSyncStats.add(name, timer); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 7332 | } |
| 7333 | |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 7334 | public void readJobSummaryFromParcelLocked(String name, Parcel in) { |
| 7335 | StopwatchTimer timer = mJobStats.instantiateObject(); |
| 7336 | timer.readSummaryFromParcelLocked(in); |
| 7337 | mJobStats.add(name, timer); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 7338 | } |
| 7339 | |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 7340 | public void readWakeSummaryFromParcelLocked(String wlName, Parcel in) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7341 | Wakelock wl = new Wakelock(mBsi, this); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 7342 | mWakelockStats.add(wlName, wl); |
| 7343 | if (in.readInt() != 0) { |
| 7344 | wl.getStopwatchTimer(WAKE_TYPE_FULL).readSummaryFromParcelLocked(in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7345 | } |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 7346 | if (in.readInt() != 0) { |
| 7347 | wl.getStopwatchTimer(WAKE_TYPE_PARTIAL).readSummaryFromParcelLocked(in); |
| 7348 | } |
| 7349 | if (in.readInt() != 0) { |
| 7350 | wl.getStopwatchTimer(WAKE_TYPE_WINDOW).readSummaryFromParcelLocked(in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7351 | } |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 7352 | if (in.readInt() != 0) { |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 7353 | wl.getStopwatchTimer(WAKE_TYPE_DRAW).readSummaryFromParcelLocked(in); |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 7354 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7355 | } |
| 7356 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 7357 | public StopwatchTimer getSensorTimerLocked(int sensor, boolean create) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7358 | Sensor se = mSensorStats.get(sensor); |
| 7359 | if (se == null) { |
| 7360 | if (!create) { |
| 7361 | return null; |
| 7362 | } |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7363 | se = new Sensor(mBsi, this, sensor); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7364 | mSensorStats.put(sensor, se); |
| 7365 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 7366 | StopwatchTimer t = se.mTimer; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7367 | if (t != null) { |
| 7368 | return t; |
| 7369 | } |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7370 | ArrayList<StopwatchTimer> timers = mBsi.mSensorTimers.get(sensor); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7371 | if (timers == null) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 7372 | timers = new ArrayList<StopwatchTimer>(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7373 | mBsi.mSensorTimers.put(sensor, timers); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7374 | } |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7375 | t = new StopwatchTimer(mBsi.mClocks, this, BatteryStats.SENSOR, timers, |
| 7376 | mBsi.mOnBatteryTimeBase); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7377 | se.mTimer = t; |
| 7378 | return t; |
| 7379 | } |
| 7380 | |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 7381 | public void noteStartSyncLocked(String name, long elapsedRealtimeMs) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 7382 | StopwatchTimer t = mSyncStats.startObject(name); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 7383 | if (t != null) { |
| 7384 | t.startRunningLocked(elapsedRealtimeMs); |
| 7385 | } |
| 7386 | } |
| 7387 | |
| 7388 | public void noteStopSyncLocked(String name, long elapsedRealtimeMs) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 7389 | StopwatchTimer t = mSyncStats.stopObject(name); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 7390 | if (t != null) { |
| 7391 | t.stopRunningLocked(elapsedRealtimeMs); |
| 7392 | } |
| 7393 | } |
| 7394 | |
| 7395 | public void noteStartJobLocked(String name, long elapsedRealtimeMs) { |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 7396 | StopwatchTimer t = mJobStats.startObject(name); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 7397 | if (t != null) { |
| 7398 | t.startRunningLocked(elapsedRealtimeMs); |
| 7399 | } |
| 7400 | } |
| 7401 | |
| 7402 | public void noteStopJobLocked(String name, long elapsedRealtimeMs) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 7403 | StopwatchTimer t = mJobStats.stopObject(name); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 7404 | if (t != null) { |
| 7405 | t.stopRunningLocked(elapsedRealtimeMs); |
| 7406 | } |
| 7407 | } |
| 7408 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7409 | public void noteStartWakeLocked(int pid, String name, int type, long elapsedRealtimeMs) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 7410 | Wakelock wl = mWakelockStats.startObject(name); |
| 7411 | if (wl != null) { |
| 7412 | wl.getStopwatchTimer(type).startRunningLocked(elapsedRealtimeMs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7413 | } |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 7414 | if (pid >= 0 && type == WAKE_TYPE_PARTIAL) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 7415 | Pid p = getPidStatsLocked(pid); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 7416 | if (p.mWakeNesting++ == 0) { |
| 7417 | p.mWakeStartMs = elapsedRealtimeMs; |
Dianne Hackborn | b8071d79 | 2010-09-09 16:45:15 -0700 | [diff] [blame] | 7418 | } |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 7419 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7420 | } |
| 7421 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7422 | public void noteStopWakeLocked(int pid, String name, int type, long elapsedRealtimeMs) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 7423 | Wakelock wl = mWakelockStats.stopObject(name); |
| 7424 | if (wl != null) { |
| 7425 | wl.getStopwatchTimer(type).stopRunningLocked(elapsedRealtimeMs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7426 | } |
Dianne Hackborn | 1ebccf5 | 2010-08-15 13:04:34 -0700 | [diff] [blame] | 7427 | if (pid >= 0 && type == WAKE_TYPE_PARTIAL) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 7428 | Pid p = mPids.get(pid); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 7429 | if (p != null && p.mWakeNesting > 0) { |
| 7430 | if (p.mWakeNesting-- == 1) { |
| 7431 | p.mWakeSumMs += elapsedRealtimeMs - p.mWakeStartMs; |
| 7432 | p.mWakeStartMs = 0; |
| 7433 | } |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 7434 | } |
| 7435 | } |
| 7436 | } |
| 7437 | |
| 7438 | public void reportExcessiveWakeLocked(String proc, long overTime, long usedTime) { |
| 7439 | Proc p = getProcessStatsLocked(proc); |
| 7440 | if (p != null) { |
| 7441 | p.addExcessiveWake(overTime, usedTime); |
| 7442 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7443 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7444 | |
Dianne Hackborn | 287952c | 2010-09-22 22:34:31 -0700 | [diff] [blame] | 7445 | public void reportExcessiveCpuLocked(String proc, long overTime, long usedTime) { |
| 7446 | Proc p = getProcessStatsLocked(proc); |
| 7447 | if (p != null) { |
| 7448 | p.addExcessiveCpu(overTime, usedTime); |
| 7449 | } |
| 7450 | } |
| 7451 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7452 | public void noteStartSensor(int sensor, long elapsedRealtimeMs) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 7453 | StopwatchTimer t = getSensorTimerLocked(sensor, true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7454 | if (t != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7455 | t.startRunningLocked(elapsedRealtimeMs); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7456 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7457 | } |
| 7458 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7459 | public void noteStopSensor(int sensor, long elapsedRealtimeMs) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7460 | // Don't create a timer if one doesn't already exist |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 7461 | StopwatchTimer t = getSensorTimerLocked(sensor, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7462 | if (t != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7463 | t.stopRunningLocked(elapsedRealtimeMs); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7464 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7465 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7466 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7467 | public void noteStartGps(long elapsedRealtimeMs) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 7468 | StopwatchTimer t = getSensorTimerLocked(Sensor.GPS, true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7469 | if (t != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7470 | t.startRunningLocked(elapsedRealtimeMs); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7471 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7472 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 7473 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7474 | public void noteStopGps(long elapsedRealtimeMs) { |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 7475 | StopwatchTimer t = getSensorTimerLocked(Sensor.GPS, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7476 | if (t != null) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7477 | t.stopRunningLocked(elapsedRealtimeMs); |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 7478 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7479 | } |
| 7480 | |
| 7481 | public BatteryStatsImpl getBatteryStats() { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7482 | return mBsi; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7483 | } |
| 7484 | } |
| 7485 | |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 7486 | public BatteryStatsImpl(File systemDir, Handler handler, ExternalStatsSync externalSync) { |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 7487 | this(new SystemClocks(), systemDir, handler, externalSync, null); |
| 7488 | } |
| 7489 | |
| 7490 | public BatteryStatsImpl(File systemDir, Handler handler, ExternalStatsSync externalSync, |
| 7491 | PlatformIdleStateCallback cb) { |
| 7492 | this(new SystemClocks(), systemDir, handler, externalSync, cb); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7493 | } |
| 7494 | |
| 7495 | public BatteryStatsImpl(Clocks clocks, File systemDir, Handler handler, |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 7496 | ExternalStatsSync externalSync, PlatformIdleStateCallback cb) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7497 | init(clocks); |
| 7498 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 7499 | if (systemDir != null) { |
| 7500 | mFile = new JournaledFile(new File(systemDir, "batterystats.bin"), |
| 7501 | new File(systemDir, "batterystats.bin.tmp")); |
| 7502 | } else { |
| 7503 | mFile = null; |
| 7504 | } |
| 7505 | mCheckinFile = new AtomicFile(new File(systemDir, "batterystats-checkin.bin")); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 7506 | mDailyFile = new AtomicFile(new File(systemDir, "batterystats-daily.xml")); |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 7507 | mExternalSync = externalSync; |
Jeff Brown | 6f357d3 | 2014-01-15 20:40:55 -0800 | [diff] [blame] | 7508 | mHandler = new MyHandler(handler.getLooper()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7509 | mStartCount++; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7510 | mScreenOnTimer = new StopwatchTimer(mClocks, null, -1, null, mOnBatteryTimeBase); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 7511 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7512 | mScreenBrightnessTimer[i] = new StopwatchTimer(mClocks, null, -100-i, null, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7513 | mOnBatteryTimeBase); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 7514 | } |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7515 | mInteractiveTimer = new StopwatchTimer(mClocks, null, -10, null, mOnBatteryTimeBase); |
| 7516 | mPowerSaveModeEnabledTimer = new StopwatchTimer(mClocks, null, -2, null, |
| 7517 | mOnBatteryTimeBase); |
| 7518 | mDeviceIdleModeLightTimer = new StopwatchTimer(mClocks, null, -11, null, |
| 7519 | mOnBatteryTimeBase); |
| 7520 | mDeviceIdleModeFullTimer = new StopwatchTimer(mClocks, null, -14, null, mOnBatteryTimeBase); |
| 7521 | mDeviceLightIdlingTimer = new StopwatchTimer(mClocks, null, -15, null, mOnBatteryTimeBase); |
| 7522 | mDeviceIdlingTimer = new StopwatchTimer(mClocks, null, -12, null, mOnBatteryTimeBase); |
| 7523 | mPhoneOnTimer = new StopwatchTimer(mClocks, null, -3, null, mOnBatteryTimeBase); |
| 7524 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
| 7525 | mPhoneSignalStrengthsTimer[i] = new StopwatchTimer(mClocks, null, -200-i, null, |
| 7526 | mOnBatteryTimeBase); |
| 7527 | } |
| 7528 | mPhoneSignalScanningTimer = new StopwatchTimer(mClocks, null, -200+1, null, |
| 7529 | mOnBatteryTimeBase); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 7530 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7531 | mPhoneDataConnectionsTimer[i] = new StopwatchTimer(mClocks, null, -300-i, null, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7532 | mOnBatteryTimeBase); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 7533 | } |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 7534 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7535 | mNetworkByteActivityCounters[i] = new LongSamplingCounter(mOnBatteryTimeBase); |
| 7536 | mNetworkPacketActivityCounters[i] = new LongSamplingCounter(mOnBatteryTimeBase); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 7537 | } |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 7538 | mWifiActivity = new ControllerActivityCounterImpl(mOnBatteryTimeBase, NUM_WIFI_TX_LEVELS); |
| 7539 | mBluetoothActivity = new ControllerActivityCounterImpl(mOnBatteryTimeBase, |
| 7540 | NUM_BT_TX_LEVELS); |
| 7541 | mModemActivity = new ControllerActivityCounterImpl(mOnBatteryTimeBase, |
| 7542 | ModemActivityInfo.TX_POWER_LEVELS); |
| 7543 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7544 | mMobileRadioActiveTimer = new StopwatchTimer(mClocks, null, -400, null, mOnBatteryTimeBase); |
| 7545 | mMobileRadioActivePerAppTimer = new StopwatchTimer(mClocks, null, -401, null, |
| 7546 | mOnBatteryTimeBase); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 7547 | mMobileRadioActiveAdjustedTime = new LongSamplingCounter(mOnBatteryTimeBase); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7548 | mMobileRadioActiveUnknownTime = new LongSamplingCounter(mOnBatteryTimeBase); |
| 7549 | mMobileRadioActiveUnknownCount = new LongSamplingCounter(mOnBatteryTimeBase); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7550 | mWifiOnTimer = new StopwatchTimer(mClocks, null, -4, null, mOnBatteryTimeBase); |
| 7551 | mGlobalWifiRunningTimer = new StopwatchTimer(mClocks, null, -5, null, mOnBatteryTimeBase); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 7552 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7553 | mWifiStateTimer[i] = new StopwatchTimer(mClocks, null, -600-i, null, |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 7554 | mOnBatteryTimeBase); |
| 7555 | } |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7556 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
| 7557 | mWifiSupplStateTimer[i] = new StopwatchTimer(mClocks, null, -700-i, null, |
| 7558 | mOnBatteryTimeBase); |
| 7559 | } |
| 7560 | for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 7561 | mWifiSignalStrengthsTimer[i] = new StopwatchTimer(mClocks, null, -800-i, null, |
| 7562 | mOnBatteryTimeBase); |
| 7563 | } |
| 7564 | mAudioOnTimer = new StopwatchTimer(mClocks, null, -7, null, mOnBatteryTimeBase); |
| 7565 | mVideoOnTimer = new StopwatchTimer(mClocks, null, -8, null, mOnBatteryTimeBase); |
| 7566 | mFlashlightOnTimer = new StopwatchTimer(mClocks, null, -9, null, mOnBatteryTimeBase); |
| 7567 | mCameraOnTimer = new StopwatchTimer(mClocks, null, -13, null, mOnBatteryTimeBase); |
| 7568 | mBluetoothScanTimer = new StopwatchTimer(mClocks, null, -14, null, mOnBatteryTimeBase); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7569 | mOnBattery = mOnBatteryInternal = false; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7570 | long uptime = mClocks.uptimeMillis() * 1000; |
| 7571 | long realtime = mClocks.elapsedRealtime() * 1000; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 7572 | initTimes(uptime, realtime); |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 7573 | mStartPlatformVersion = mEndPlatformVersion = Build.ID; |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 7574 | mDischargeStartLevel = 0; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 7575 | mDischargeUnplugLevel = 0; |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 7576 | mDischargePlugLevel = -1; |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 7577 | mDischargeCurrentLevel = 0; |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 7578 | mCurrentBatteryLevel = 0; |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 7579 | initDischarge(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 7580 | clearHistoryLocked(); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 7581 | updateDailyDeadlineLocked(); |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 7582 | mPlatformIdleStateCallback = cb; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7583 | } |
| 7584 | |
| 7585 | public BatteryStatsImpl(Parcel p) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 7586 | this(new SystemClocks(), p); |
| 7587 | } |
| 7588 | |
| 7589 | public BatteryStatsImpl(Clocks clocks, Parcel p) { |
| 7590 | init(clocks); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 7591 | mFile = null; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 7592 | mCheckinFile = null; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 7593 | mDailyFile = null; |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 7594 | mHandler = null; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 7595 | mExternalSync = null; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 7596 | clearHistoryLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7597 | readFromParcel(p); |
Badhri Jagan Sridharan | 68cdf19 | 2016-04-03 21:57:15 -0700 | [diff] [blame] | 7598 | mPlatformIdleStateCallback = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7599 | } |
| 7600 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 7601 | public void setPowerProfile(PowerProfile profile) { |
| 7602 | synchronized (this) { |
| 7603 | mPowerProfile = profile; |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 7604 | |
| 7605 | // We need to initialize the KernelCpuSpeedReaders to read from |
| 7606 | // the first cpu of each core. Once we have the PowerProfile, we have access to this |
| 7607 | // information. |
| 7608 | final int numClusters = mPowerProfile.getNumCpuClusters(); |
| 7609 | mKernelCpuSpeedReaders = new KernelCpuSpeedReader[numClusters]; |
| 7610 | int firstCpuOfCluster = 0; |
| 7611 | for (int i = 0; i < numClusters; i++) { |
| 7612 | final int numSpeedSteps = mPowerProfile.getNumSpeedStepsInCpuCluster(i); |
| 7613 | mKernelCpuSpeedReaders[i] = new KernelCpuSpeedReader(firstCpuOfCluster, |
| 7614 | numSpeedSteps); |
| 7615 | firstCpuOfCluster += mPowerProfile.getNumCoresInCpuCluster(i); |
| 7616 | } |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 7617 | } |
| 7618 | } |
| 7619 | |
Dianne Hackborn | 0d903a8 | 2010-09-07 23:51:03 -0700 | [diff] [blame] | 7620 | public void setCallback(BatteryCallback cb) { |
| 7621 | mCallback = cb; |
| 7622 | } |
| 7623 | |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 7624 | public void setRadioScanningTimeout(long timeout) { |
| 7625 | if (mPhoneSignalScanningTimer != null) { |
| 7626 | mPhoneSignalScanningTimer.setTimeout(timeout); |
| 7627 | } |
| 7628 | } |
| 7629 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 7630 | public void updateDailyDeadlineLocked() { |
| 7631 | // Get the current time. |
| 7632 | long currentTime = mDailyStartTime = System.currentTimeMillis(); |
| 7633 | Calendar calDeadline = Calendar.getInstance(); |
| 7634 | calDeadline.setTimeInMillis(currentTime); |
| 7635 | |
| 7636 | // Move time up to the next day, ranging from 1am to 3pm. |
| 7637 | calDeadline.set(Calendar.DAY_OF_YEAR, calDeadline.get(Calendar.DAY_OF_YEAR) + 1); |
| 7638 | calDeadline.set(Calendar.MILLISECOND, 0); |
| 7639 | calDeadline.set(Calendar.SECOND, 0); |
| 7640 | calDeadline.set(Calendar.MINUTE, 0); |
| 7641 | calDeadline.set(Calendar.HOUR_OF_DAY, 1); |
| 7642 | mNextMinDailyDeadline = calDeadline.getTimeInMillis(); |
| 7643 | calDeadline.set(Calendar.HOUR_OF_DAY, 3); |
| 7644 | mNextMaxDailyDeadline = calDeadline.getTimeInMillis(); |
| 7645 | } |
| 7646 | |
| 7647 | public void recordDailyStatsIfNeededLocked(boolean settled) { |
| 7648 | long currentTime = System.currentTimeMillis(); |
| 7649 | if (currentTime >= mNextMaxDailyDeadline) { |
| 7650 | recordDailyStatsLocked(); |
| 7651 | } else if (settled && currentTime >= mNextMinDailyDeadline) { |
| 7652 | recordDailyStatsLocked(); |
| 7653 | } else if (currentTime < (mDailyStartTime-(1000*60*60*24))) { |
| 7654 | recordDailyStatsLocked(); |
| 7655 | } |
| 7656 | } |
| 7657 | |
| 7658 | public void recordDailyStatsLocked() { |
| 7659 | DailyItem item = new DailyItem(); |
| 7660 | item.mStartTime = mDailyStartTime; |
| 7661 | item.mEndTime = System.currentTimeMillis(); |
| 7662 | boolean hasData = false; |
| 7663 | if (mDailyDischargeStepTracker.mNumStepDurations > 0) { |
| 7664 | hasData = true; |
| 7665 | item.mDischargeSteps = new LevelStepTracker( |
| 7666 | mDailyDischargeStepTracker.mNumStepDurations, |
| 7667 | mDailyDischargeStepTracker.mStepDurations); |
| 7668 | } |
| 7669 | if (mDailyChargeStepTracker.mNumStepDurations > 0) { |
| 7670 | hasData = true; |
| 7671 | item.mChargeSteps = new LevelStepTracker( |
| 7672 | mDailyChargeStepTracker.mNumStepDurations, |
| 7673 | mDailyChargeStepTracker.mStepDurations); |
| 7674 | } |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 7675 | if (mDailyPackageChanges != null) { |
| 7676 | hasData = true; |
| 7677 | item.mPackageChanges = mDailyPackageChanges; |
| 7678 | mDailyPackageChanges = null; |
| 7679 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 7680 | mDailyDischargeStepTracker.init(); |
| 7681 | mDailyChargeStepTracker.init(); |
| 7682 | updateDailyDeadlineLocked(); |
| 7683 | |
| 7684 | if (hasData) { |
| 7685 | mDailyItems.add(item); |
| 7686 | while (mDailyItems.size() > MAX_DAILY_ITEMS) { |
| 7687 | mDailyItems.remove(0); |
| 7688 | } |
| 7689 | final ByteArrayOutputStream memStream = new ByteArrayOutputStream(); |
| 7690 | try { |
| 7691 | XmlSerializer out = new FastXmlSerializer(); |
Wojciech Staszkiewicz | 9e9e2e7 | 2015-05-08 14:58:46 +0100 | [diff] [blame] | 7692 | out.setOutput(memStream, StandardCharsets.UTF_8.name()); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 7693 | writeDailyItemsLocked(out); |
| 7694 | BackgroundThread.getHandler().post(new Runnable() { |
| 7695 | @Override |
| 7696 | public void run() { |
| 7697 | synchronized (mCheckinFile) { |
| 7698 | FileOutputStream stream = null; |
| 7699 | try { |
| 7700 | stream = mDailyFile.startWrite(); |
| 7701 | memStream.writeTo(stream); |
| 7702 | stream.flush(); |
| 7703 | FileUtils.sync(stream); |
| 7704 | stream.close(); |
| 7705 | mDailyFile.finishWrite(stream); |
| 7706 | } catch (IOException e) { |
| 7707 | Slog.w("BatteryStats", |
| 7708 | "Error writing battery daily items", e); |
| 7709 | mDailyFile.failWrite(stream); |
| 7710 | } |
| 7711 | } |
| 7712 | } |
| 7713 | }); |
| 7714 | } catch (IOException e) { |
| 7715 | } |
| 7716 | } |
| 7717 | } |
| 7718 | |
| 7719 | private void writeDailyItemsLocked(XmlSerializer out) throws IOException { |
| 7720 | StringBuilder sb = new StringBuilder(64); |
| 7721 | out.startDocument(null, true); |
| 7722 | out.startTag(null, "daily-items"); |
| 7723 | for (int i=0; i<mDailyItems.size(); i++) { |
| 7724 | final DailyItem dit = mDailyItems.get(i); |
| 7725 | out.startTag(null, "item"); |
| 7726 | out.attribute(null, "start", Long.toString(dit.mStartTime)); |
| 7727 | out.attribute(null, "end", Long.toString(dit.mEndTime)); |
| 7728 | writeDailyLevelSteps(out, "dis", dit.mDischargeSteps, sb); |
| 7729 | writeDailyLevelSteps(out, "chg", dit.mChargeSteps, sb); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 7730 | if (dit.mPackageChanges != null) { |
| 7731 | for (int j=0; j<dit.mPackageChanges.size(); j++) { |
| 7732 | PackageChange pc = dit.mPackageChanges.get(j); |
| 7733 | if (pc.mUpdate) { |
| 7734 | out.startTag(null, "upd"); |
| 7735 | out.attribute(null, "pkg", pc.mPackageName); |
| 7736 | out.attribute(null, "ver", Integer.toString(pc.mVersionCode)); |
| 7737 | out.endTag(null, "upd"); |
| 7738 | } else { |
| 7739 | out.startTag(null, "rem"); |
| 7740 | out.attribute(null, "pkg", pc.mPackageName); |
| 7741 | out.endTag(null, "rem"); |
| 7742 | } |
| 7743 | } |
| 7744 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 7745 | out.endTag(null, "item"); |
| 7746 | } |
| 7747 | out.endTag(null, "daily-items"); |
| 7748 | out.endDocument(); |
| 7749 | } |
| 7750 | |
| 7751 | private void writeDailyLevelSteps(XmlSerializer out, String tag, LevelStepTracker steps, |
| 7752 | StringBuilder tmpBuilder) throws IOException { |
| 7753 | if (steps != null) { |
| 7754 | out.startTag(null, tag); |
| 7755 | out.attribute(null, "n", Integer.toString(steps.mNumStepDurations)); |
| 7756 | for (int i=0; i<steps.mNumStepDurations; i++) { |
| 7757 | out.startTag(null, "s"); |
| 7758 | tmpBuilder.setLength(0); |
| 7759 | steps.encodeEntryAt(i, tmpBuilder); |
| 7760 | out.attribute(null, "v", tmpBuilder.toString()); |
| 7761 | out.endTag(null, "s"); |
| 7762 | } |
| 7763 | out.endTag(null, tag); |
| 7764 | } |
| 7765 | } |
| 7766 | |
| 7767 | public void readDailyStatsLocked() { |
| 7768 | Slog.d(TAG, "Reading daily items from " + mDailyFile.getBaseFile()); |
| 7769 | mDailyItems.clear(); |
| 7770 | FileInputStream stream; |
| 7771 | try { |
| 7772 | stream = mDailyFile.openRead(); |
| 7773 | } catch (FileNotFoundException e) { |
| 7774 | return; |
| 7775 | } |
| 7776 | try { |
| 7777 | XmlPullParser parser = Xml.newPullParser(); |
Wojciech Staszkiewicz | 9e9e2e7 | 2015-05-08 14:58:46 +0100 | [diff] [blame] | 7778 | parser.setInput(stream, StandardCharsets.UTF_8.name()); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 7779 | readDailyItemsLocked(parser); |
| 7780 | } catch (XmlPullParserException e) { |
| 7781 | } finally { |
| 7782 | try { |
| 7783 | stream.close(); |
| 7784 | } catch (IOException e) { |
| 7785 | } |
| 7786 | } |
| 7787 | } |
| 7788 | |
| 7789 | private void readDailyItemsLocked(XmlPullParser parser) { |
| 7790 | try { |
| 7791 | int type; |
| 7792 | while ((type = parser.next()) != XmlPullParser.START_TAG |
| 7793 | && type != XmlPullParser.END_DOCUMENT) { |
| 7794 | ; |
| 7795 | } |
| 7796 | |
| 7797 | if (type != XmlPullParser.START_TAG) { |
| 7798 | throw new IllegalStateException("no start tag found"); |
| 7799 | } |
| 7800 | |
| 7801 | int outerDepth = parser.getDepth(); |
| 7802 | while ((type = parser.next()) != XmlPullParser.END_DOCUMENT |
| 7803 | && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) { |
| 7804 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 7805 | continue; |
| 7806 | } |
| 7807 | |
| 7808 | String tagName = parser.getName(); |
| 7809 | if (tagName.equals("item")) { |
| 7810 | readDailyItemTagLocked(parser); |
| 7811 | } else { |
| 7812 | Slog.w(TAG, "Unknown element under <daily-items>: " |
| 7813 | + parser.getName()); |
| 7814 | XmlUtils.skipCurrentTag(parser); |
| 7815 | } |
| 7816 | } |
| 7817 | |
| 7818 | } catch (IllegalStateException e) { |
| 7819 | Slog.w(TAG, "Failed parsing daily " + e); |
| 7820 | } catch (NullPointerException e) { |
| 7821 | Slog.w(TAG, "Failed parsing daily " + e); |
| 7822 | } catch (NumberFormatException e) { |
| 7823 | Slog.w(TAG, "Failed parsing daily " + e); |
| 7824 | } catch (XmlPullParserException e) { |
| 7825 | Slog.w(TAG, "Failed parsing daily " + e); |
| 7826 | } catch (IOException e) { |
| 7827 | Slog.w(TAG, "Failed parsing daily " + e); |
| 7828 | } catch (IndexOutOfBoundsException e) { |
| 7829 | Slog.w(TAG, "Failed parsing daily " + e); |
| 7830 | } |
| 7831 | } |
| 7832 | |
| 7833 | void readDailyItemTagLocked(XmlPullParser parser) throws NumberFormatException, |
| 7834 | XmlPullParserException, IOException { |
| 7835 | DailyItem dit = new DailyItem(); |
| 7836 | String attr = parser.getAttributeValue(null, "start"); |
| 7837 | if (attr != null) { |
| 7838 | dit.mStartTime = Long.parseLong(attr); |
| 7839 | } |
| 7840 | attr = parser.getAttributeValue(null, "end"); |
| 7841 | if (attr != null) { |
| 7842 | dit.mEndTime = Long.parseLong(attr); |
| 7843 | } |
| 7844 | int outerDepth = parser.getDepth(); |
| 7845 | int type; |
| 7846 | while ((type = parser.next()) != XmlPullParser.END_DOCUMENT |
| 7847 | && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) { |
| 7848 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 7849 | continue; |
| 7850 | } |
| 7851 | |
| 7852 | String tagName = parser.getName(); |
| 7853 | if (tagName.equals("dis")) { |
| 7854 | readDailyItemTagDetailsLocked(parser, dit, false, "dis"); |
| 7855 | } else if (tagName.equals("chg")) { |
| 7856 | readDailyItemTagDetailsLocked(parser, dit, true, "chg"); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 7857 | } else if (tagName.equals("upd")) { |
| 7858 | if (dit.mPackageChanges == null) { |
| 7859 | dit.mPackageChanges = new ArrayList<>(); |
| 7860 | } |
| 7861 | PackageChange pc = new PackageChange(); |
| 7862 | pc.mUpdate = true; |
| 7863 | pc.mPackageName = parser.getAttributeValue(null, "pkg"); |
| 7864 | String verStr = parser.getAttributeValue(null, "ver"); |
| 7865 | pc.mVersionCode = verStr != null ? Integer.parseInt(verStr) : 0; |
| 7866 | dit.mPackageChanges.add(pc); |
| 7867 | XmlUtils.skipCurrentTag(parser); |
| 7868 | } else if (tagName.equals("rem")) { |
| 7869 | if (dit.mPackageChanges == null) { |
| 7870 | dit.mPackageChanges = new ArrayList<>(); |
| 7871 | } |
| 7872 | PackageChange pc = new PackageChange(); |
| 7873 | pc.mUpdate = false; |
| 7874 | pc.mPackageName = parser.getAttributeValue(null, "pkg"); |
| 7875 | dit.mPackageChanges.add(pc); |
| 7876 | XmlUtils.skipCurrentTag(parser); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 7877 | } else { |
| 7878 | Slog.w(TAG, "Unknown element under <item>: " |
| 7879 | + parser.getName()); |
| 7880 | XmlUtils.skipCurrentTag(parser); |
| 7881 | } |
| 7882 | } |
| 7883 | mDailyItems.add(dit); |
| 7884 | } |
| 7885 | |
| 7886 | void readDailyItemTagDetailsLocked(XmlPullParser parser, DailyItem dit, boolean isCharge, |
| 7887 | String tag) |
| 7888 | throws NumberFormatException, XmlPullParserException, IOException { |
| 7889 | final String numAttr = parser.getAttributeValue(null, "n"); |
| 7890 | if (numAttr == null) { |
| 7891 | Slog.w(TAG, "Missing 'n' attribute at " + parser.getPositionDescription()); |
| 7892 | XmlUtils.skipCurrentTag(parser); |
| 7893 | return; |
| 7894 | } |
| 7895 | final int num = Integer.parseInt(numAttr); |
| 7896 | LevelStepTracker steps = new LevelStepTracker(num); |
| 7897 | if (isCharge) { |
| 7898 | dit.mChargeSteps = steps; |
| 7899 | } else { |
| 7900 | dit.mDischargeSteps = steps; |
| 7901 | } |
| 7902 | int i = 0; |
| 7903 | int outerDepth = parser.getDepth(); |
| 7904 | int type; |
| 7905 | while ((type = parser.next()) != XmlPullParser.END_DOCUMENT |
| 7906 | && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) { |
| 7907 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 7908 | continue; |
| 7909 | } |
| 7910 | |
| 7911 | String tagName = parser.getName(); |
| 7912 | if ("s".equals(tagName)) { |
| 7913 | if (i < num) { |
| 7914 | String valueAttr = parser.getAttributeValue(null, "v"); |
| 7915 | if (valueAttr != null) { |
| 7916 | steps.decodeEntryAt(i, valueAttr); |
| 7917 | i++; |
| 7918 | } |
| 7919 | } |
| 7920 | } else { |
| 7921 | Slog.w(TAG, "Unknown element under <" + tag + ">: " |
| 7922 | + parser.getName()); |
| 7923 | XmlUtils.skipCurrentTag(parser); |
| 7924 | } |
| 7925 | } |
| 7926 | steps.mNumStepDurations = i; |
| 7927 | } |
| 7928 | |
| 7929 | @Override |
| 7930 | public DailyItem getDailyItemLocked(int daysAgo) { |
| 7931 | int index = mDailyItems.size()-1-daysAgo; |
| 7932 | return index >= 0 ? mDailyItems.get(index) : null; |
| 7933 | } |
| 7934 | |
| 7935 | @Override |
| 7936 | public long getCurrentDailyStartTime() { |
| 7937 | return mDailyStartTime; |
| 7938 | } |
| 7939 | |
| 7940 | @Override |
| 7941 | public long getNextMinDailyDeadline() { |
| 7942 | return mNextMinDailyDeadline; |
| 7943 | } |
| 7944 | |
| 7945 | @Override |
| 7946 | public long getNextMaxDailyDeadline() { |
| 7947 | return mNextMaxDailyDeadline; |
| 7948 | } |
| 7949 | |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 7950 | @Override |
| 7951 | public boolean startIteratingOldHistoryLocked() { |
| 7952 | if (DEBUG_HISTORY) Slog.i(TAG, "ITERATING: buff size=" + mHistoryBuffer.dataSize() |
| 7953 | + " pos=" + mHistoryBuffer.dataPosition()); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 7954 | if ((mHistoryIterator = mHistory) == null) { |
| 7955 | return false; |
| 7956 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 7957 | mHistoryBuffer.setDataPosition(0); |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 7958 | mHistoryReadTmp.clear(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 7959 | mReadOverflow = false; |
| 7960 | mIteratingHistory = true; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 7961 | return true; |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 7962 | } |
| 7963 | |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 7964 | @Override |
| 7965 | public boolean getNextOldHistoryLocked(HistoryItem out) { |
| 7966 | boolean end = mHistoryBuffer.dataPosition() >= mHistoryBuffer.dataSize(); |
| 7967 | if (!end) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 7968 | readHistoryDelta(mHistoryBuffer, mHistoryReadTmp); |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 7969 | mReadOverflow |= mHistoryReadTmp.cmd == HistoryItem.CMD_OVERFLOW; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 7970 | } |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 7971 | HistoryItem cur = mHistoryIterator; |
| 7972 | if (cur == null) { |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 7973 | if (!mReadOverflow && !end) { |
| 7974 | Slog.w(TAG, "Old history ends before new history!"); |
| 7975 | } |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 7976 | return false; |
| 7977 | } |
| 7978 | out.setTo(cur); |
| 7979 | mHistoryIterator = cur.next; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 7980 | if (!mReadOverflow) { |
| 7981 | if (end) { |
| 7982 | Slog.w(TAG, "New history ends before old history!"); |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 7983 | } else if (!out.same(mHistoryReadTmp)) { |
Dianne Hackborn | 8c84109 | 2013-06-24 13:46:13 -0700 | [diff] [blame] | 7984 | PrintWriter pw = new FastPrintWriter(new LogWriter(android.util.Log.WARN, TAG)); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 7985 | pw.println("Histories differ!"); |
| 7986 | pw.println("Old history:"); |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 7987 | (new HistoryPrinter()).printNextItem(pw, out, 0, false, true); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 7988 | pw.println("New history:"); |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 7989 | (new HistoryPrinter()).printNextItem(pw, mHistoryReadTmp, 0, false, |
| 7990 | true); |
Dianne Hackborn | 8c84109 | 2013-06-24 13:46:13 -0700 | [diff] [blame] | 7991 | pw.flush(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 7992 | } |
| 7993 | } |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 7994 | return true; |
| 7995 | } |
| 7996 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7997 | @Override |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 7998 | public void finishIteratingOldHistoryLocked() { |
| 7999 | mIteratingHistory = false; |
| 8000 | mHistoryBuffer.setDataPosition(mHistoryBuffer.dataSize()); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 8001 | mHistoryIterator = null; |
| 8002 | } |
| 8003 | |
| 8004 | public int getHistoryTotalSize() { |
| 8005 | return MAX_HISTORY_BUFFER; |
| 8006 | } |
| 8007 | |
| 8008 | public int getHistoryUsedSize() { |
| 8009 | return mHistoryBuffer.dataSize(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 8010 | } |
| 8011 | |
| 8012 | @Override |
| 8013 | public boolean startIteratingHistoryLocked() { |
| 8014 | if (DEBUG_HISTORY) Slog.i(TAG, "ITERATING: buff size=" + mHistoryBuffer.dataSize() |
| 8015 | + " pos=" + mHistoryBuffer.dataPosition()); |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 8016 | if (mHistoryBuffer.dataSize() <= 0) { |
| 8017 | return false; |
| 8018 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 8019 | mHistoryBuffer.setDataPosition(0); |
| 8020 | mReadOverflow = false; |
| 8021 | mIteratingHistory = true; |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 8022 | mReadHistoryStrings = new String[mHistoryTagPool.size()]; |
| 8023 | mReadHistoryUids = new int[mHistoryTagPool.size()]; |
| 8024 | mReadHistoryChars = 0; |
| 8025 | for (HashMap.Entry<HistoryTag, Integer> ent : mHistoryTagPool.entrySet()) { |
| 8026 | final HistoryTag tag = ent.getKey(); |
| 8027 | final int idx = ent.getValue(); |
| 8028 | mReadHistoryStrings[idx] = tag.string; |
| 8029 | mReadHistoryUids[idx] = tag.uid; |
| 8030 | mReadHistoryChars += tag.string.length() + 1; |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 8031 | } |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 8032 | return true; |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 8033 | } |
| 8034 | |
| 8035 | @Override |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 8036 | public int getHistoryStringPoolSize() { |
| 8037 | return mReadHistoryStrings.length; |
| 8038 | } |
| 8039 | |
| 8040 | @Override |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 8041 | public int getHistoryStringPoolBytes() { |
| 8042 | // Each entry is a fixed 12 bytes: 4 for index, 4 for uid, 4 for string size |
| 8043 | // Each string character is 2 bytes. |
| 8044 | return (mReadHistoryStrings.length * 12) + (mReadHistoryChars * 2); |
| 8045 | } |
| 8046 | |
| 8047 | @Override |
| 8048 | public String getHistoryTagPoolString(int index) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 8049 | return mReadHistoryStrings[index]; |
| 8050 | } |
| 8051 | |
| 8052 | @Override |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 8053 | public int getHistoryTagPoolUid(int index) { |
| 8054 | return mReadHistoryUids[index]; |
| 8055 | } |
| 8056 | |
| 8057 | @Override |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 8058 | public boolean getNextHistoryLocked(HistoryItem out) { |
Dianne Hackborn | 1fadab5 | 2011-04-14 17:57:33 -0700 | [diff] [blame] | 8059 | final int pos = mHistoryBuffer.dataPosition(); |
| 8060 | if (pos == 0) { |
| 8061 | out.clear(); |
| 8062 | } |
| 8063 | boolean end = pos >= mHistoryBuffer.dataSize(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 8064 | if (end) { |
| 8065 | return false; |
| 8066 | } |
| 8067 | |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 8068 | final long lastRealtime = out.time; |
| 8069 | final long lastWalltime = out.currentTime; |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 8070 | readHistoryDelta(mHistoryBuffer, out); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 8071 | if (out.cmd != HistoryItem.CMD_CURRENT_TIME |
| 8072 | && out.cmd != HistoryItem.CMD_RESET && lastWalltime != 0) { |
Dianne Hackborn | 99009ea | 2014-04-18 16:23:42 -0700 | [diff] [blame] | 8073 | out.currentTime = lastWalltime + (out.time - lastRealtime); |
| 8074 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 8075 | return true; |
| 8076 | } |
| 8077 | |
| 8078 | @Override |
| 8079 | public void finishIteratingHistoryLocked() { |
| 8080 | mIteratingHistory = false; |
| 8081 | mHistoryBuffer.setDataPosition(mHistoryBuffer.dataSize()); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 8082 | mReadHistoryStrings = null; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 8083 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 8084 | |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 8085 | @Override |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 8086 | public long getHistoryBaseTime() { |
| 8087 | return mHistoryBaseTime; |
| 8088 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 8089 | |
Dianne Hackborn | b5e3165 | 2010-09-07 12:13:55 -0700 | [diff] [blame] | 8090 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8091 | public int getStartCount() { |
| 8092 | return mStartCount; |
| 8093 | } |
| 8094 | |
| 8095 | public boolean isOnBattery() { |
| 8096 | return mOnBattery; |
| 8097 | } |
| 8098 | |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 8099 | public boolean isCharging() { |
| 8100 | return mCharging; |
| 8101 | } |
| 8102 | |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 8103 | public boolean isScreenOn() { |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 8104 | return mScreenState == Display.STATE_ON; |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 8105 | } |
| 8106 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8107 | void initTimes(long uptime, long realtime) { |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 8108 | mStartClockTime = System.currentTimeMillis(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8109 | mOnBatteryTimeBase.init(uptime, realtime); |
| 8110 | mOnBatteryScreenOffTimeBase.init(uptime, realtime); |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 8111 | mRealtime = 0; |
| 8112 | mUptime = 0; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8113 | mRealtimeStart = realtime; |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 8114 | mUptimeStart = uptime; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8115 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 8116 | |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 8117 | void initDischarge() { |
| 8118 | mLowDischargeAmountSinceCharge = 0; |
| 8119 | mHighDischargeAmountSinceCharge = 0; |
| 8120 | mDischargeAmountScreenOn = 0; |
| 8121 | mDischargeAmountScreenOnSinceCharge = 0; |
| 8122 | mDischargeAmountScreenOff = 0; |
| 8123 | mDischargeAmountScreenOffSinceCharge = 0; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 8124 | mDischargeStepTracker.init(); |
| 8125 | mChargeStepTracker.init(); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 8126 | } |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 8127 | |
| 8128 | public void resetAllStatsCmdLocked() { |
| 8129 | resetAllStatsLocked(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8130 | final long mSecUptime = mClocks.uptimeMillis(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 8131 | long uptime = mSecUptime * 1000; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8132 | long mSecRealtime = mClocks.elapsedRealtime(); |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 8133 | long realtime = mSecRealtime * 1000; |
| 8134 | mDischargeStartLevel = mHistoryCur.batteryLevel; |
| 8135 | pullPendingStateUpdatesLocked(); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 8136 | addHistoryRecordLocked(mSecRealtime, mSecUptime); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 8137 | mDischargeCurrentLevel = mDischargeUnplugLevel = mDischargePlugLevel |
| 8138 | = mCurrentBatteryLevel = mHistoryCur.batteryLevel; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8139 | mOnBatteryTimeBase.reset(uptime, realtime); |
| 8140 | mOnBatteryScreenOffTimeBase.reset(uptime, realtime); |
| 8141 | if ((mHistoryCur.states&HistoryItem.STATE_BATTERY_PLUGGED_FLAG) == 0) { |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 8142 | if (mScreenState == Display.STATE_ON) { |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 8143 | mDischargeScreenOnUnplugLevel = mHistoryCur.batteryLevel; |
| 8144 | mDischargeScreenOffUnplugLevel = 0; |
| 8145 | } else { |
| 8146 | mDischargeScreenOnUnplugLevel = 0; |
| 8147 | mDischargeScreenOffUnplugLevel = mHistoryCur.batteryLevel; |
| 8148 | } |
| 8149 | mDischargeAmountScreenOn = 0; |
| 8150 | mDischargeAmountScreenOff = 0; |
| 8151 | } |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 8152 | initActiveHistoryEventsLocked(mSecRealtime, mSecUptime); |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 8153 | } |
| 8154 | |
| 8155 | private void resetAllStatsLocked() { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8156 | mStartCount = 0; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8157 | initTimes(mClocks.uptimeMillis() * 1000, mClocks.elapsedRealtime() * 1000); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8158 | mScreenOnTimer.reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8159 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8160 | mScreenBrightnessTimer[i].reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8161 | } |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 8162 | mInteractiveTimer.reset(false); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 8163 | mPowerSaveModeEnabledTimer.reset(false); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 8164 | mLongestLightIdleTime = 0; |
| 8165 | mLongestFullIdleTime = 0; |
| 8166 | mDeviceIdleModeLightTimer.reset(false); |
| 8167 | mDeviceIdleModeFullTimer.reset(false); |
| 8168 | mDeviceLightIdlingTimer.reset(false); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 8169 | mDeviceIdlingTimer.reset(false); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8170 | mPhoneOnTimer.reset(false); |
| 8171 | mAudioOnTimer.reset(false); |
| 8172 | mVideoOnTimer.reset(false); |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 8173 | mFlashlightOnTimer.reset(false); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 8174 | mCameraOnTimer.reset(false); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 8175 | mBluetoothScanTimer.reset(false); |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 8176 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8177 | mPhoneSignalStrengthsTimer[i].reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8178 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8179 | mPhoneSignalScanningTimer.reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8180 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8181 | mPhoneDataConnectionsTimer[i].reset(false); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8182 | } |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 8183 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 8184 | mNetworkByteActivityCounters[i].reset(false); |
| 8185 | mNetworkPacketActivityCounters[i].reset(false); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 8186 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8187 | mMobileRadioActiveTimer.reset(false); |
| 8188 | mMobileRadioActivePerAppTimer.reset(false); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 8189 | mMobileRadioActiveAdjustedTime.reset(false); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 8190 | mMobileRadioActiveUnknownTime.reset(false); |
| 8191 | mMobileRadioActiveUnknownCount.reset(false); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8192 | mWifiOnTimer.reset(false); |
| 8193 | mGlobalWifiRunningTimer.reset(false); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 8194 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8195 | mWifiStateTimer[i].reset(false); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 8196 | } |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 8197 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
| 8198 | mWifiSupplStateTimer[i].reset(false); |
| 8199 | } |
| 8200 | for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 8201 | mWifiSignalStrengthsTimer[i].reset(false); |
| 8202 | } |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 8203 | mWifiActivity.reset(false); |
| 8204 | mBluetoothActivity.reset(false); |
| 8205 | mModemActivity.reset(false); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 8206 | mNumConnectivityChange = mLoadedNumConnectivityChange = mUnpluggedNumConnectivityChange = 0; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 8207 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8208 | for (int i=0; i<mUidStats.size(); i++) { |
| 8209 | if (mUidStats.valueAt(i).reset()) { |
| 8210 | mUidStats.remove(mUidStats.keyAt(i)); |
| 8211 | i--; |
| 8212 | } |
| 8213 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 8214 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8215 | if (mKernelWakelockStats.size() > 0) { |
| 8216 | for (SamplingTimer timer : mKernelWakelockStats.values()) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 8217 | mOnBatteryScreenOffTimeBase.remove(timer); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8218 | } |
| 8219 | mKernelWakelockStats.clear(); |
| 8220 | } |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 8221 | |
| 8222 | if (mWakeupReasonStats.size() > 0) { |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 8223 | for (SamplingTimer timer : mWakeupReasonStats.values()) { |
| 8224 | mOnBatteryTimeBase.remove(timer); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 8225 | } |
| 8226 | mWakeupReasonStats.clear(); |
| 8227 | } |
| 8228 | |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 8229 | mLastHistoryStepDetails = null; |
| 8230 | mLastStepCpuUserTime = mLastStepCpuSystemTime = 0; |
| 8231 | mCurStepCpuUserTime = mCurStepCpuSystemTime = 0; |
| 8232 | mLastStepCpuUserTime = mCurStepCpuUserTime = 0; |
| 8233 | mLastStepCpuSystemTime = mCurStepCpuSystemTime = 0; |
| 8234 | mLastStepStatUserTime = mCurStepStatUserTime = 0; |
| 8235 | mLastStepStatSystemTime = mCurStepStatSystemTime = 0; |
| 8236 | mLastStepStatIOWaitTime = mCurStepStatIOWaitTime = 0; |
| 8237 | mLastStepStatIrqTime = mCurStepStatIrqTime = 0; |
| 8238 | mLastStepStatSoftIrqTime = mCurStepStatSoftIrqTime = 0; |
| 8239 | mLastStepStatIdleTime = mCurStepStatIdleTime = 0; |
| 8240 | |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 8241 | initDischarge(); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 8242 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 8243 | clearHistoryLocked(); |
| 8244 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 8245 | |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 8246 | private void initActiveHistoryEventsLocked(long elapsedRealtimeMs, long uptimeMs) { |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 8247 | for (int i=0; i<HistoryItem.EVENT_COUNT; i++) { |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 8248 | if (!mRecordAllHistory && i == HistoryItem.EVENT_PROC) { |
| 8249 | // Not recording process starts/stops. |
| 8250 | continue; |
| 8251 | } |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 8252 | HashMap<String, SparseIntArray> active = mActiveEvents.getStateForEvent(i); |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 8253 | if (active == null) { |
| 8254 | continue; |
| 8255 | } |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 8256 | for (HashMap.Entry<String, SparseIntArray> ent : active.entrySet()) { |
| 8257 | SparseIntArray uids = ent.getValue(); |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 8258 | for (int j=0; j<uids.size(); j++) { |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 8259 | addHistoryEventLocked(elapsedRealtimeMs, uptimeMs, i, ent.getKey(), |
| 8260 | uids.keyAt(j)); |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 8261 | } |
| 8262 | } |
| 8263 | } |
| 8264 | } |
| 8265 | |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 8266 | void updateDischargeScreenLevelsLocked(boolean oldScreenOn, boolean newScreenOn) { |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 8267 | if (oldScreenOn) { |
| 8268 | int diff = mDischargeScreenOnUnplugLevel - mDischargeCurrentLevel; |
| 8269 | if (diff > 0) { |
| 8270 | mDischargeAmountScreenOn += diff; |
| 8271 | mDischargeAmountScreenOnSinceCharge += diff; |
| 8272 | } |
| 8273 | } else { |
| 8274 | int diff = mDischargeScreenOffUnplugLevel - mDischargeCurrentLevel; |
| 8275 | if (diff > 0) { |
| 8276 | mDischargeAmountScreenOff += diff; |
| 8277 | mDischargeAmountScreenOffSinceCharge += diff; |
| 8278 | } |
| 8279 | } |
| 8280 | if (newScreenOn) { |
| 8281 | mDischargeScreenOnUnplugLevel = mDischargeCurrentLevel; |
| 8282 | mDischargeScreenOffUnplugLevel = 0; |
| 8283 | } else { |
| 8284 | mDischargeScreenOnUnplugLevel = 0; |
| 8285 | mDischargeScreenOffUnplugLevel = mDischargeCurrentLevel; |
| 8286 | } |
| 8287 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8288 | |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 8289 | public void pullPendingStateUpdatesLocked() { |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 8290 | if (mOnBatteryInternal) { |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 8291 | final boolean screenOn = mScreenState == Display.STATE_ON; |
| 8292 | updateDischargeScreenLevelsLocked(screenOn, screenOn); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 8293 | } |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 8294 | } |
| 8295 | |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8296 | private String[] mMobileIfaces = EmptyArray.STRING; |
| 8297 | private String[] mWifiIfaces = EmptyArray.STRING; |
| 8298 | |
| 8299 | private final NetworkStatsFactory mNetworkStatsFactory = new NetworkStatsFactory(); |
| 8300 | |
| 8301 | private static final int NETWORK_STATS_LAST = 0; |
| 8302 | private static final int NETWORK_STATS_NEXT = 1; |
| 8303 | private static final int NETWORK_STATS_DELTA = 2; |
| 8304 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8305 | private NetworkStats[] mMobileNetworkStats; |
| 8306 | private NetworkStats[] mWifiNetworkStats; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8307 | |
| 8308 | /** |
| 8309 | * Retrieves the delta of network stats for the given network ifaces. Uses networkStatsBuffer |
| 8310 | * as a buffer of NetworkStats objects to cycle through when computing deltas. |
| 8311 | */ |
| 8312 | private NetworkStats getNetworkStatsDeltaLocked(String[] ifaces, |
| 8313 | NetworkStats[] networkStatsBuffer) |
| 8314 | throws IOException { |
| 8315 | if (!SystemProperties.getBoolean(NetworkManagementSocketTagger.PROP_QTAGUID_ENABLED, |
| 8316 | false)) { |
| 8317 | return null; |
| 8318 | } |
| 8319 | |
| 8320 | final NetworkStats stats = mNetworkStatsFactory.readNetworkStatsDetail(NetworkStats.UID_ALL, |
| 8321 | ifaces, NetworkStats.TAG_NONE, networkStatsBuffer[NETWORK_STATS_NEXT]); |
| 8322 | networkStatsBuffer[NETWORK_STATS_DELTA] = NetworkStats.subtract(stats, |
| 8323 | networkStatsBuffer[NETWORK_STATS_LAST], null, null, |
| 8324 | networkStatsBuffer[NETWORK_STATS_DELTA]); |
| 8325 | networkStatsBuffer[NETWORK_STATS_NEXT] = networkStatsBuffer[NETWORK_STATS_LAST]; |
| 8326 | networkStatsBuffer[NETWORK_STATS_LAST] = stats; |
| 8327 | return networkStatsBuffer[NETWORK_STATS_DELTA]; |
| 8328 | } |
| 8329 | |
| 8330 | /** |
| 8331 | * Distribute WiFi energy info and network traffic to apps. |
| 8332 | * @param info The energy information from the WiFi controller. |
| 8333 | */ |
| 8334 | public void updateWifiStateLocked(@Nullable final WifiActivityEnergyInfo info) { |
Adam Lesinski | a7c90c8 | 2015-06-18 14:52:24 -0700 | [diff] [blame] | 8335 | if (DEBUG_ENERGY) { |
| 8336 | Slog.d(TAG, "Updating wifi stats"); |
| 8337 | } |
| 8338 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8339 | final long elapsedRealtimeMs = mClocks.elapsedRealtime(); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 8340 | NetworkStats delta = null; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8341 | try { |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 8342 | if (!ArrayUtils.isEmpty(mWifiIfaces)) { |
| 8343 | delta = getNetworkStatsDeltaLocked(mWifiIfaces, mWifiNetworkStats); |
| 8344 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8345 | } catch (IOException e) { |
| 8346 | Slog.wtf(TAG, "Failed to get wifi network stats", e); |
| 8347 | return; |
| 8348 | } |
| 8349 | |
| 8350 | if (!mOnBatteryInternal) { |
| 8351 | return; |
| 8352 | } |
| 8353 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 8354 | SparseLongArray rxPackets = new SparseLongArray(); |
| 8355 | SparseLongArray txPackets = new SparseLongArray(); |
| 8356 | long totalTxPackets = 0; |
| 8357 | long totalRxPackets = 0; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8358 | if (delta != null) { |
| 8359 | final int size = delta.size(); |
| 8360 | for (int i = 0; i < size; i++) { |
| 8361 | final NetworkStats.Entry entry = delta.getValues(i, mTmpNetworkStatsEntry); |
| 8362 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 8363 | if (DEBUG_ENERGY) { |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8364 | Slog.d(TAG, "Wifi uid " + entry.uid + ": delta rx=" + entry.rxBytes |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 8365 | + " tx=" + entry.txBytes + " rxPackets=" + entry.rxPackets |
| 8366 | + " txPackets=" + entry.txPackets); |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8367 | } |
| 8368 | |
Adam Lesinski | 6cca414 | 2016-02-25 18:23:02 -0800 | [diff] [blame] | 8369 | if (entry.rxBytes == 0 && entry.txBytes == 0) { |
| 8370 | // Skip the lookup below since there is no work to do. |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8371 | continue; |
| 8372 | } |
| 8373 | |
| 8374 | final Uid u = getUidStatsLocked(mapUid(entry.uid)); |
Adam Lesinski | ba88e68 | 2015-12-08 12:06:55 -0800 | [diff] [blame] | 8375 | if (entry.rxBytes != 0) { |
| 8376 | u.noteNetworkActivityLocked(NETWORK_WIFI_RX_DATA, entry.rxBytes, |
| 8377 | entry.rxPackets); |
| 8378 | mNetworkByteActivityCounters[NETWORK_WIFI_RX_DATA].addCountLocked( |
| 8379 | entry.rxBytes); |
| 8380 | mNetworkPacketActivityCounters[NETWORK_WIFI_RX_DATA].addCountLocked( |
| 8381 | entry.rxPackets); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 8382 | |
Adam Lesinski | ba88e68 | 2015-12-08 12:06:55 -0800 | [diff] [blame] | 8383 | rxPackets.put(u.getUid(), entry.rxPackets); |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8384 | |
Adam Lesinski | ba88e68 | 2015-12-08 12:06:55 -0800 | [diff] [blame] | 8385 | // Sum the total number of packets so that the Rx Power can |
| 8386 | // be evenly distributed amongst the apps. |
| 8387 | totalRxPackets += entry.rxPackets; |
| 8388 | } |
| 8389 | |
| 8390 | if (entry.txBytes != 0) { |
| 8391 | u.noteNetworkActivityLocked(NETWORK_WIFI_TX_DATA, entry.txBytes, |
| 8392 | entry.txPackets); |
| 8393 | mNetworkByteActivityCounters[NETWORK_WIFI_TX_DATA].addCountLocked( |
| 8394 | entry.txBytes); |
| 8395 | mNetworkPacketActivityCounters[NETWORK_WIFI_TX_DATA].addCountLocked( |
| 8396 | entry.txPackets); |
| 8397 | |
| 8398 | txPackets.put(u.getUid(), entry.txPackets); |
| 8399 | |
| 8400 | // Sum the total number of packets so that the Tx Power can |
| 8401 | // be evenly distributed amongst the apps. |
| 8402 | totalTxPackets += entry.txPackets; |
| 8403 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8404 | } |
| 8405 | } |
| 8406 | |
| 8407 | if (info != null) { |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 8408 | mHasWifiReporting = true; |
Adam Lesinski | 1739076 | 2015-04-10 13:17:47 -0700 | [diff] [blame] | 8409 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 8410 | // Measured in mAms |
| 8411 | final long txTimeMs = info.getControllerTxTimeMillis(); |
| 8412 | final long rxTimeMs = info.getControllerRxTimeMillis(); |
| 8413 | final long idleTimeMs = info.getControllerIdleTimeMillis(); |
| 8414 | final long totalTimeMs = txTimeMs + rxTimeMs + idleTimeMs; |
| 8415 | |
| 8416 | long leftOverRxTimeMs = rxTimeMs; |
Mitchell Wills | f901649 | 2015-07-29 17:47:44 -0700 | [diff] [blame] | 8417 | long leftOverTxTimeMs = txTimeMs; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 8418 | |
| 8419 | if (DEBUG_ENERGY) { |
| 8420 | Slog.d(TAG, "------ BEGIN WiFi power blaming ------"); |
| 8421 | Slog.d(TAG, " Tx Time: " + txTimeMs + " ms"); |
| 8422 | Slog.d(TAG, " Rx Time: " + rxTimeMs + " ms"); |
| 8423 | Slog.d(TAG, " Idle Time: " + idleTimeMs + " ms"); |
| 8424 | Slog.d(TAG, " Total Time: " + totalTimeMs + " ms"); |
| 8425 | } |
| 8426 | |
| 8427 | long totalWifiLockTimeMs = 0; |
| 8428 | long totalScanTimeMs = 0; |
| 8429 | |
| 8430 | // On the first pass, collect some totals so that we can normalize power |
| 8431 | // calculations if we need to. |
| 8432 | final int uidStatsSize = mUidStats.size(); |
| 8433 | for (int i = 0; i < uidStatsSize; i++) { |
| 8434 | final Uid uid = mUidStats.valueAt(i); |
| 8435 | |
| 8436 | // Sum the total scan power for all apps. |
| 8437 | totalScanTimeMs += uid.mWifiScanTimer.getTimeSinceMarkLocked( |
| 8438 | elapsedRealtimeMs * 1000) / 1000; |
| 8439 | |
| 8440 | // Sum the total time holding wifi lock for all apps. |
| 8441 | totalWifiLockTimeMs += uid.mFullWifiLockTimer.getTimeSinceMarkLocked( |
| 8442 | elapsedRealtimeMs * 1000) / 1000; |
| 8443 | } |
| 8444 | |
| 8445 | if (DEBUG_ENERGY && totalScanTimeMs > rxTimeMs) { |
| 8446 | Slog.d(TAG, " !Estimated scan time > Actual rx time (" + totalScanTimeMs + " ms > " |
| 8447 | + rxTimeMs + " ms). Normalizing scan time."); |
| 8448 | } |
Mitchell Wills | f901649 | 2015-07-29 17:47:44 -0700 | [diff] [blame] | 8449 | if (DEBUG_ENERGY && totalScanTimeMs > txTimeMs) { |
| 8450 | Slog.d(TAG, " !Estimated scan time > Actual tx time (" + totalScanTimeMs + " ms > " |
| 8451 | + txTimeMs + " ms). Normalizing scan time."); |
| 8452 | } |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 8453 | |
| 8454 | // Actually assign and distribute power usage to apps. |
| 8455 | for (int i = 0; i < uidStatsSize; i++) { |
| 8456 | final Uid uid = mUidStats.valueAt(i); |
| 8457 | |
| 8458 | long scanTimeSinceMarkMs = uid.mWifiScanTimer.getTimeSinceMarkLocked( |
| 8459 | elapsedRealtimeMs * 1000) / 1000; |
| 8460 | if (scanTimeSinceMarkMs > 0) { |
| 8461 | // Set the new mark so that next time we get new data since this point. |
| 8462 | uid.mWifiScanTimer.setMark(elapsedRealtimeMs); |
| 8463 | |
Mitchell Wills | f901649 | 2015-07-29 17:47:44 -0700 | [diff] [blame] | 8464 | long scanRxTimeSinceMarkMs = scanTimeSinceMarkMs; |
| 8465 | long scanTxTimeSinceMarkMs = scanTimeSinceMarkMs; |
| 8466 | |
| 8467 | // Our total scan time is more than the reported Tx/Rx time. |
| 8468 | // This is possible because the cost of a scan is approximate. |
| 8469 | // Let's normalize the result so that we evenly blame each app |
| 8470 | // scanning. |
| 8471 | // |
| 8472 | // This means that we may have apps that transmitted/received packets not be |
| 8473 | // 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] | 8474 | if (totalScanTimeMs > rxTimeMs) { |
Mitchell Wills | f901649 | 2015-07-29 17:47:44 -0700 | [diff] [blame] | 8475 | scanRxTimeSinceMarkMs = (rxTimeMs * scanRxTimeSinceMarkMs) / |
| 8476 | totalScanTimeMs; |
| 8477 | } |
| 8478 | if (totalScanTimeMs > txTimeMs) { |
| 8479 | scanTxTimeSinceMarkMs = (txTimeMs * scanTxTimeSinceMarkMs) / |
| 8480 | totalScanTimeMs; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 8481 | } |
| 8482 | |
| 8483 | if (DEBUG_ENERGY) { |
Mitchell Wills | f901649 | 2015-07-29 17:47:44 -0700 | [diff] [blame] | 8484 | Slog.d(TAG, " ScanTime for UID " + uid.getUid() + ": Rx:" |
| 8485 | + scanRxTimeSinceMarkMs + " ms Tx:" |
| 8486 | + scanTxTimeSinceMarkMs + " ms)"); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 8487 | } |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 8488 | |
| 8489 | ControllerActivityCounterImpl activityCounter = |
| 8490 | uid.getOrCreateWifiControllerActivityLocked(); |
| 8491 | activityCounter.getRxTimeCounter().addCountLocked(scanRxTimeSinceMarkMs); |
| 8492 | activityCounter.getTxTimeCounters()[0].addCountLocked(scanTxTimeSinceMarkMs); |
Mitchell Wills | f901649 | 2015-07-29 17:47:44 -0700 | [diff] [blame] | 8493 | leftOverRxTimeMs -= scanRxTimeSinceMarkMs; |
| 8494 | leftOverTxTimeMs -= scanTxTimeSinceMarkMs; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 8495 | } |
| 8496 | |
| 8497 | // Distribute evenly the power consumed while Idle to each app holding a WiFi |
| 8498 | // lock. |
| 8499 | final long wifiLockTimeSinceMarkMs = uid.mFullWifiLockTimer.getTimeSinceMarkLocked( |
| 8500 | elapsedRealtimeMs * 1000) / 1000; |
| 8501 | if (wifiLockTimeSinceMarkMs > 0) { |
| 8502 | // Set the new mark so that next time we get new data since this point. |
| 8503 | uid.mFullWifiLockTimer.setMark(elapsedRealtimeMs); |
| 8504 | |
| 8505 | final long myIdleTimeMs = (wifiLockTimeSinceMarkMs * idleTimeMs) |
| 8506 | / totalWifiLockTimeMs; |
| 8507 | if (DEBUG_ENERGY) { |
| 8508 | Slog.d(TAG, " IdleTime for UID " + uid.getUid() + ": " |
| 8509 | + myIdleTimeMs + " ms"); |
| 8510 | } |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 8511 | uid.getOrCreateWifiControllerActivityLocked().getIdleTimeCounter() |
| 8512 | .addCountLocked(myIdleTimeMs); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 8513 | } |
| 8514 | } |
| 8515 | |
| 8516 | if (DEBUG_ENERGY) { |
| 8517 | Slog.d(TAG, " New RxPower: " + leftOverRxTimeMs + " ms"); |
Mitchell Wills | f901649 | 2015-07-29 17:47:44 -0700 | [diff] [blame] | 8518 | Slog.d(TAG, " New TxPower: " + leftOverTxTimeMs + " ms"); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 8519 | } |
| 8520 | |
Mitchell Wills | f901649 | 2015-07-29 17:47:44 -0700 | [diff] [blame] | 8521 | // Distribute the remaining Tx power appropriately between all apps that transmitted |
| 8522 | // packets. |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 8523 | for (int i = 0; i < txPackets.size(); i++) { |
| 8524 | final Uid uid = getUidStatsLocked(txPackets.keyAt(i)); |
Mitchell Wills | f901649 | 2015-07-29 17:47:44 -0700 | [diff] [blame] | 8525 | final long myTxTimeMs = (txPackets.valueAt(i) * leftOverTxTimeMs) / totalTxPackets; |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 8526 | if (DEBUG_ENERGY) { |
| 8527 | Slog.d(TAG, " TxTime for UID " + uid.getUid() + ": " + myTxTimeMs + " ms"); |
| 8528 | } |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 8529 | uid.getOrCreateWifiControllerActivityLocked().getTxTimeCounters()[0] |
| 8530 | .addCountLocked(myTxTimeMs); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 8531 | } |
| 8532 | |
| 8533 | // Distribute the remaining Rx power appropriately between all apps that received |
| 8534 | // packets. |
| 8535 | for (int i = 0; i < rxPackets.size(); i++) { |
| 8536 | final Uid uid = getUidStatsLocked(rxPackets.keyAt(i)); |
| 8537 | final long myRxTimeMs = (rxPackets.valueAt(i) * leftOverRxTimeMs) / totalRxPackets; |
| 8538 | if (DEBUG_ENERGY) { |
| 8539 | Slog.d(TAG, " RxTime for UID " + uid.getUid() + ": " + myRxTimeMs + " ms"); |
| 8540 | } |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 8541 | uid.getOrCreateWifiControllerActivityLocked().getRxTimeCounter() |
| 8542 | .addCountLocked(myRxTimeMs); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 8543 | } |
| 8544 | |
| 8545 | // Any left over power use will be picked up by the WiFi category in BatteryStatsHelper. |
| 8546 | |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8547 | // Update WiFi controller stats. |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 8548 | mWifiActivity.getRxTimeCounter().addCountLocked(info.getControllerRxTimeMillis()); |
| 8549 | mWifiActivity.getTxTimeCounters()[0].addCountLocked(info.getControllerTxTimeMillis()); |
| 8550 | mWifiActivity.getIdleTimeCounter().addCountLocked(info.getControllerIdleTimeMillis()); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 8551 | |
Adam Lesinski | 8576cf9 | 2015-06-09 12:48:25 -0700 | [diff] [blame] | 8552 | // POWER_WIFI_CONTROLLER_OPERATING_VOLTAGE is measured in mV, so convert to V. |
| 8553 | final double opVolt = mPowerProfile.getAveragePower( |
| 8554 | PowerProfile.POWER_WIFI_CONTROLLER_OPERATING_VOLTAGE) / 1000.0; |
| 8555 | if (opVolt != 0) { |
| 8556 | // We store the power drain as mAms. |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 8557 | mWifiActivity.getPowerCounter().addCountLocked( |
Adam Lesinski | 8576cf9 | 2015-06-09 12:48:25 -0700 | [diff] [blame] | 8558 | (long)(info.getControllerEnergyUsed() / opVolt)); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 8559 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8560 | } |
| 8561 | } |
| 8562 | |
| 8563 | /** |
| 8564 | * Distribute Cell radio energy info and network traffic to apps. |
| 8565 | */ |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 8566 | public void updateMobileRadioStateLocked(final long elapsedRealtimeMs, |
| 8567 | final ModemActivityInfo activityInfo) { |
Adam Lesinski | a7c90c8 | 2015-06-18 14:52:24 -0700 | [diff] [blame] | 8568 | if (DEBUG_ENERGY) { |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 8569 | Slog.d(TAG, "Updating mobile radio stats with " + activityInfo); |
Adam Lesinski | a7c90c8 | 2015-06-18 14:52:24 -0700 | [diff] [blame] | 8570 | } |
| 8571 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 8572 | NetworkStats delta = null; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8573 | try { |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 8574 | if (!ArrayUtils.isEmpty(mMobileIfaces)) { |
| 8575 | delta = getNetworkStatsDeltaLocked(mMobileIfaces, mMobileNetworkStats); |
| 8576 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8577 | } catch (IOException e) { |
| 8578 | Slog.wtf(TAG, "Failed to get mobile network stats", e); |
| 8579 | return; |
| 8580 | } |
| 8581 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 8582 | if (!mOnBatteryInternal) { |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8583 | return; |
| 8584 | } |
| 8585 | |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 8586 | long radioTime = mMobileRadioActivePerAppTimer.getTimeSinceMarkLocked( |
| 8587 | elapsedRealtimeMs * 1000); |
| 8588 | mMobileRadioActivePerAppTimer.setMark(elapsedRealtimeMs); |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8589 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 8590 | long totalRxPackets = 0; |
| 8591 | long totalTxPackets = 0; |
| 8592 | if (delta != null) { |
| 8593 | final int size = delta.size(); |
| 8594 | for (int i = 0; i < size; i++) { |
| 8595 | final NetworkStats.Entry entry = delta.getValues(i, mTmpNetworkStatsEntry); |
Adam Lesinski | a426817 | 2016-01-29 12:13:54 -0800 | [diff] [blame] | 8596 | if (entry.rxPackets == 0 && entry.txPackets == 0) { |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 8597 | continue; |
| 8598 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8599 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 8600 | if (DEBUG_ENERGY) { |
| 8601 | Slog.d(TAG, "Mobile uid " + entry.uid + ": delta rx=" + entry.rxBytes |
| 8602 | + " tx=" + entry.txBytes + " rxPackets=" + entry.rxPackets |
| 8603 | + " txPackets=" + entry.txPackets); |
| 8604 | } |
| 8605 | |
| 8606 | totalRxPackets += entry.rxPackets; |
| 8607 | totalTxPackets += entry.txPackets; |
| 8608 | |
| 8609 | final Uid u = getUidStatsLocked(mapUid(entry.uid)); |
| 8610 | u.noteNetworkActivityLocked(NETWORK_MOBILE_RX_DATA, entry.rxBytes, entry.rxPackets); |
| 8611 | u.noteNetworkActivityLocked(NETWORK_MOBILE_TX_DATA, entry.txBytes, entry.txPackets); |
| 8612 | |
| 8613 | mNetworkByteActivityCounters[NETWORK_MOBILE_RX_DATA].addCountLocked( |
| 8614 | entry.rxBytes); |
| 8615 | mNetworkByteActivityCounters[NETWORK_MOBILE_TX_DATA].addCountLocked( |
| 8616 | entry.txBytes); |
| 8617 | mNetworkPacketActivityCounters[NETWORK_MOBILE_RX_DATA].addCountLocked( |
| 8618 | entry.rxPackets); |
| 8619 | mNetworkPacketActivityCounters[NETWORK_MOBILE_TX_DATA].addCountLocked( |
| 8620 | entry.txPackets); |
Adam Lesinski | e08af19 | 2015-03-25 16:42:59 -0700 | [diff] [blame] | 8621 | } |
| 8622 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 8623 | // Now distribute proportional blame to the apps that did networking. |
| 8624 | long totalPackets = totalRxPackets + totalTxPackets; |
| 8625 | if (totalPackets > 0) { |
| 8626 | for (int i = 0; i < size; i++) { |
| 8627 | final NetworkStats.Entry entry = delta.getValues(i, mTmpNetworkStatsEntry); |
| 8628 | if (entry.rxPackets == 0 && entry.txPackets == 0) { |
| 8629 | continue; |
| 8630 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8631 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 8632 | final Uid u = getUidStatsLocked(mapUid(entry.uid)); |
| 8633 | |
| 8634 | // Distribute total radio active time in to this app. |
| 8635 | final long appPackets = entry.rxPackets + entry.txPackets; |
| 8636 | final long appRadioTime = (radioTime * appPackets) / totalPackets; |
| 8637 | u.noteMobileRadioActiveTimeLocked(appRadioTime); |
| 8638 | |
| 8639 | // Remove this app from the totals, so that we don't lose any time |
| 8640 | // due to rounding. |
| 8641 | radioTime -= appRadioTime; |
| 8642 | totalPackets -= appPackets; |
| 8643 | |
| 8644 | if (activityInfo != null) { |
| 8645 | ControllerActivityCounterImpl activityCounter = |
| 8646 | u.getOrCreateModemControllerActivityLocked(); |
Adam Lesinski | a426817 | 2016-01-29 12:13:54 -0800 | [diff] [blame] | 8647 | if (totalRxPackets > 0 && entry.rxPackets > 0) { |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 8648 | final long rxMs = (entry.rxPackets * activityInfo.getRxTimeMillis()) |
| 8649 | / totalRxPackets; |
| 8650 | activityCounter.getRxTimeCounter().addCountLocked(rxMs); |
| 8651 | } |
| 8652 | |
Adam Lesinski | a426817 | 2016-01-29 12:13:54 -0800 | [diff] [blame] | 8653 | if (totalTxPackets > 0 && entry.txPackets > 0) { |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 8654 | for (int lvl = 0; lvl < ModemActivityInfo.TX_POWER_LEVELS; lvl++) { |
| 8655 | long txMs = entry.txPackets * activityInfo.getTxTimeMillis()[lvl]; |
| 8656 | txMs /= totalTxPackets; |
| 8657 | activityCounter.getTxTimeCounters()[lvl].addCountLocked(txMs); |
| 8658 | } |
| 8659 | } |
| 8660 | } |
| 8661 | } |
| 8662 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8663 | |
| 8664 | if (radioTime > 0) { |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 8665 | // Whoops, there is some radio time we can't blame on an app! |
| 8666 | mMobileRadioActiveUnknownTime.addCountLocked(radioTime); |
| 8667 | mMobileRadioActiveUnknownCount.addCountLocked(1); |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8668 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8669 | } |
| 8670 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 8671 | if (activityInfo != null) { |
| 8672 | mHasModemReporting = true; |
| 8673 | mModemActivity.getIdleTimeCounter().addCountLocked(activityInfo.getIdleTimeMillis()); |
| 8674 | mModemActivity.getRxTimeCounter().addCountLocked(activityInfo.getRxTimeMillis()); |
| 8675 | for (int lvl = 0; lvl < ModemActivityInfo.TX_POWER_LEVELS; lvl++) { |
| 8676 | mModemActivity.getTxTimeCounters()[lvl] |
| 8677 | .addCountLocked(activityInfo.getTxTimeMillis()[lvl]); |
| 8678 | } |
| 8679 | |
| 8680 | // POWER_MODEM_CONTROLLER_OPERATING_VOLTAGE is measured in mV, so convert to V. |
| 8681 | final double opVolt = mPowerProfile.getAveragePower( |
| 8682 | PowerProfile.POWER_MODEM_CONTROLLER_OPERATING_VOLTAGE) / 1000.0; |
| 8683 | if (opVolt != 0) { |
| 8684 | // We store the power drain as mAms. |
| 8685 | mModemActivity.getPowerCounter().addCountLocked( |
| 8686 | (long) (activityInfo.getEnergyUsed() / opVolt)); |
| 8687 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8688 | } |
| 8689 | } |
| 8690 | |
| 8691 | /** |
| 8692 | * Distribute Bluetooth energy info and network traffic to apps. |
| 8693 | * @param info The energy information from the bluetooth controller. |
| 8694 | */ |
| 8695 | public void updateBluetoothStateLocked(@Nullable final BluetoothActivityEnergyInfo info) { |
Adam Lesinski | a7c90c8 | 2015-06-18 14:52:24 -0700 | [diff] [blame] | 8696 | if (DEBUG_ENERGY) { |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 8697 | Slog.d(TAG, "Updating bluetooth stats: " + info); |
Adam Lesinski | a7c90c8 | 2015-06-18 14:52:24 -0700 | [diff] [blame] | 8698 | } |
| 8699 | |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 8700 | if (info == null || !mOnBatteryInternal) { |
| 8701 | return; |
| 8702 | } |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 8703 | |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 8704 | mHasBluetoothReporting = true; |
| 8705 | |
| 8706 | final long elapsedRealtimeMs = SystemClock.elapsedRealtime(); |
| 8707 | final long rxTimeMs = info.getControllerRxTimeMillis(); |
| 8708 | final long txTimeMs = info.getControllerTxTimeMillis(); |
| 8709 | |
| 8710 | if (DEBUG_ENERGY) { |
| 8711 | Slog.d(TAG, "------ BEGIN BLE power blaming ------"); |
| 8712 | Slog.d(TAG, " Tx Time: " + txTimeMs + " ms"); |
| 8713 | Slog.d(TAG, " Rx Time: " + rxTimeMs + " ms"); |
| 8714 | Slog.d(TAG, " Idle Time: " + info.getControllerIdleTimeMillis() + " ms"); |
| 8715 | } |
| 8716 | |
| 8717 | long totalScanTimeMs = 0; |
| 8718 | |
| 8719 | final int uidCount = mUidStats.size(); |
| 8720 | for (int i = 0; i < uidCount; i++) { |
| 8721 | final Uid u = mUidStats.valueAt(i); |
| 8722 | if (u.mBluetoothScanTimer == null) { |
| 8723 | continue; |
Adam Lesinski | e283d33 | 2015-04-16 12:29:25 -0700 | [diff] [blame] | 8724 | } |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 8725 | |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 8726 | totalScanTimeMs += u.mBluetoothScanTimer.getTimeSinceMarkLocked( |
| 8727 | elapsedRealtimeMs * 1000) / 1000; |
| 8728 | } |
| 8729 | |
| 8730 | final boolean normalizeScanRxTime = (totalScanTimeMs > rxTimeMs); |
| 8731 | final boolean normalizeScanTxTime = (totalScanTimeMs > txTimeMs); |
| 8732 | |
| 8733 | if (DEBUG_ENERGY) { |
| 8734 | Slog.d(TAG, "Normalizing scan power for RX=" + normalizeScanRxTime |
| 8735 | + " TX=" + normalizeScanTxTime); |
| 8736 | } |
| 8737 | |
| 8738 | long leftOverRxTimeMs = rxTimeMs; |
| 8739 | long leftOverTxTimeMs = txTimeMs; |
| 8740 | |
| 8741 | for (int i = 0; i < uidCount; i++) { |
| 8742 | final Uid u = mUidStats.valueAt(i); |
| 8743 | if (u.mBluetoothScanTimer == null) { |
| 8744 | continue; |
| 8745 | } |
| 8746 | |
| 8747 | long scanTimeSinceMarkMs = u.mBluetoothScanTimer.getTimeSinceMarkLocked( |
| 8748 | elapsedRealtimeMs * 1000) / 1000; |
| 8749 | if (scanTimeSinceMarkMs > 0) { |
| 8750 | // Set the new mark so that next time we get new data since this point. |
| 8751 | u.mBluetoothScanTimer.setMark(elapsedRealtimeMs); |
| 8752 | |
| 8753 | long scanTimeRxSinceMarkMs = scanTimeSinceMarkMs; |
| 8754 | long scanTimeTxSinceMarkMs = scanTimeSinceMarkMs; |
| 8755 | |
| 8756 | if (normalizeScanRxTime) { |
| 8757 | // Scan time is longer than the total rx time in the controller, |
| 8758 | // so distribute the scan time proportionately. This means regular traffic |
| 8759 | // will not blamed, but scans are more expensive anyways. |
| 8760 | scanTimeRxSinceMarkMs = (rxTimeMs * scanTimeRxSinceMarkMs) / totalScanTimeMs; |
| 8761 | } |
| 8762 | |
| 8763 | if (normalizeScanTxTime) { |
| 8764 | // Scan time is longer than the total tx time in the controller, |
| 8765 | // so distribute the scan time proportionately. This means regular traffic |
| 8766 | // will not blamed, but scans are more expensive anyways. |
| 8767 | scanTimeTxSinceMarkMs = (txTimeMs * scanTimeTxSinceMarkMs) / totalScanTimeMs; |
| 8768 | } |
| 8769 | |
| 8770 | final ControllerActivityCounterImpl counter = |
| 8771 | u.getOrCreateBluetoothControllerActivityLocked(); |
| 8772 | counter.getRxTimeCounter().addCountLocked(scanTimeRxSinceMarkMs); |
| 8773 | counter.getTxTimeCounters()[0].addCountLocked(scanTimeTxSinceMarkMs); |
| 8774 | |
| 8775 | leftOverRxTimeMs -= scanTimeRxSinceMarkMs; |
| 8776 | leftOverTxTimeMs -= scanTimeTxSinceMarkMs; |
| 8777 | } |
| 8778 | } |
| 8779 | |
| 8780 | if (DEBUG_ENERGY) { |
| 8781 | Slog.d(TAG, "Left over time for traffic RX=" + leftOverRxTimeMs |
| 8782 | + " TX=" + leftOverTxTimeMs); |
| 8783 | } |
| 8784 | |
| 8785 | // |
| 8786 | // Now distribute blame to apps that did bluetooth traffic. |
| 8787 | // |
| 8788 | |
| 8789 | long totalTxBytes = 0; |
| 8790 | long totalRxBytes = 0; |
| 8791 | |
| 8792 | final UidTraffic[] uidTraffic = info.getUidTraffic(); |
| 8793 | final int numUids = uidTraffic != null ? uidTraffic.length : 0; |
| 8794 | for (int i = 0; i < numUids; i++) { |
| 8795 | final UidTraffic traffic = uidTraffic[i]; |
| 8796 | |
| 8797 | // Add to the global counters. |
| 8798 | mNetworkByteActivityCounters[NETWORK_BT_RX_DATA].addCountLocked( |
| 8799 | traffic.getRxBytes()); |
| 8800 | mNetworkByteActivityCounters[NETWORK_BT_TX_DATA].addCountLocked( |
| 8801 | traffic.getTxBytes()); |
| 8802 | |
| 8803 | // Add to the UID counters. |
| 8804 | final Uid u = getUidStatsLocked(mapUid(traffic.getUid())); |
| 8805 | u.noteNetworkActivityLocked(NETWORK_BT_RX_DATA, traffic.getRxBytes(), 0); |
| 8806 | u.noteNetworkActivityLocked(NETWORK_BT_TX_DATA, traffic.getTxBytes(), 0); |
| 8807 | |
| 8808 | // Calculate the total traffic. |
| 8809 | totalTxBytes += traffic.getTxBytes(); |
| 8810 | totalRxBytes += traffic.getRxBytes(); |
| 8811 | } |
| 8812 | |
| 8813 | if ((totalTxBytes != 0 || totalRxBytes != 0) && |
| 8814 | (leftOverRxTimeMs != 0 || leftOverTxTimeMs != 0)) { |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 8815 | for (int i = 0; i < numUids; i++) { |
| 8816 | final UidTraffic traffic = uidTraffic[i]; |
| 8817 | |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 8818 | final Uid u = getUidStatsLocked(mapUid(traffic.getUid())); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 8819 | final ControllerActivityCounterImpl counter = |
| 8820 | u.getOrCreateBluetoothControllerActivityLocked(); |
| 8821 | |
| 8822 | if (totalRxBytes > 0 && traffic.getRxBytes() > 0) { |
| 8823 | final long timeRxMs = (leftOverRxTimeMs * traffic.getRxBytes()) / totalRxBytes; |
| 8824 | |
| 8825 | if (DEBUG_ENERGY) { |
| 8826 | Slog.d(TAG, "UID=" + traffic.getUid() + " rx_bytes=" + traffic.getRxBytes() |
| 8827 | + " rx_time=" + timeRxMs); |
| 8828 | } |
| 8829 | counter.getRxTimeCounter().addCountLocked(timeRxMs); |
| 8830 | leftOverRxTimeMs -= timeRxMs; |
| 8831 | } |
| 8832 | |
| 8833 | if (totalTxBytes > 0 && traffic.getTxBytes() > 0) { |
| 8834 | final long timeTxMs = (leftOverTxTimeMs * traffic.getTxBytes()) / totalTxBytes; |
| 8835 | |
| 8836 | if (DEBUG_ENERGY) { |
| 8837 | Slog.d(TAG, "UID=" + traffic.getUid() + " tx_bytes=" + traffic.getTxBytes() |
| 8838 | + " tx_time=" + timeTxMs); |
| 8839 | } |
| 8840 | |
| 8841 | counter.getTxTimeCounters()[0].addCountLocked(timeTxMs); |
| 8842 | leftOverTxTimeMs -= timeTxMs; |
| 8843 | } |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 8844 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8845 | } |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 8846 | |
| 8847 | mBluetoothActivity.getRxTimeCounter().addCountLocked( |
| 8848 | info.getControllerRxTimeMillis()); |
| 8849 | mBluetoothActivity.getTxTimeCounters()[0].addCountLocked( |
| 8850 | info.getControllerTxTimeMillis()); |
| 8851 | mBluetoothActivity.getIdleTimeCounter().addCountLocked( |
| 8852 | info.getControllerIdleTimeMillis()); |
| 8853 | |
| 8854 | // POWER_BLUETOOTH_CONTROLLER_OPERATING_VOLTAGE is measured in mV, so convert to V. |
| 8855 | final double opVolt = mPowerProfile.getAveragePower( |
| 8856 | PowerProfile.POWER_BLUETOOTH_CONTROLLER_OPERATING_VOLTAGE) / 1000.0; |
| 8857 | if (opVolt != 0) { |
| 8858 | // We store the power drain as mAms. |
| 8859 | mBluetoothActivity.getPowerCounter().addCountLocked( |
| 8860 | (long) (info.getControllerEnergyUsed() / opVolt)); |
| 8861 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8862 | } |
| 8863 | |
| 8864 | /** |
| 8865 | * Read and distribute kernel wake lock use across apps. |
| 8866 | */ |
| 8867 | public void updateKernelWakelocksLocked() { |
| 8868 | final KernelWakelockStats wakelockStats = mKernelWakelockReader.readKernelWakelockStats( |
| 8869 | mTmpWakelockStats); |
| 8870 | if (wakelockStats == null) { |
| 8871 | // Not crashing might make board bringup easier. |
| 8872 | Slog.w(TAG, "Couldn't get kernel wake lock stats"); |
| 8873 | return; |
| 8874 | } |
| 8875 | |
Adam Lesinski | fbabe7d | 2015-08-03 14:37:38 -0700 | [diff] [blame] | 8876 | // Record whether we've seen a non-zero time (for debugging b/22716723). |
| 8877 | boolean seenNonZeroTime = false; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8878 | for (Map.Entry<String, KernelWakelockStats.Entry> ent : wakelockStats.entrySet()) { |
| 8879 | String name = ent.getKey(); |
| 8880 | KernelWakelockStats.Entry kws = ent.getValue(); |
| 8881 | |
| 8882 | SamplingTimer kwlt = mKernelWakelockStats.get(name); |
| 8883 | if (kwlt == null) { |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 8884 | kwlt = new SamplingTimer(mClocks, mOnBatteryScreenOffTimeBase); |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8885 | mKernelWakelockStats.put(name, kwlt); |
| 8886 | } |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 8887 | kwlt.update(kws.mTotalTime, kws.mCount); |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8888 | kwlt.setUpdateVersion(kws.mVersion); |
Adam Lesinski | fbabe7d | 2015-08-03 14:37:38 -0700 | [diff] [blame] | 8889 | |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 8890 | if (kws.mVersion != wakelockStats.kernelWakelockVersion) { |
| 8891 | seenNonZeroTime |= kws.mTotalTime > 0; |
| 8892 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8893 | } |
| 8894 | |
Adam Lesinski | fbabe7d | 2015-08-03 14:37:38 -0700 | [diff] [blame] | 8895 | int numWakelocksSetStale = 0; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8896 | if (wakelockStats.size() != mKernelWakelockStats.size()) { |
| 8897 | // Set timers to stale if they didn't appear in /proc/wakelocks this time. |
| 8898 | for (Map.Entry<String, SamplingTimer> ent : mKernelWakelockStats.entrySet()) { |
| 8899 | SamplingTimer st = ent.getValue(); |
| 8900 | if (st.getUpdateVersion() != wakelockStats.kernelWakelockVersion) { |
Adam Lesinski | 757c6ea | 2016-04-21 09:55:41 -0700 | [diff] [blame] | 8901 | st.endSample(); |
Adam Lesinski | fbabe7d | 2015-08-03 14:37:38 -0700 | [diff] [blame] | 8902 | numWakelocksSetStale++; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8903 | } |
| 8904 | } |
| 8905 | } |
Adam Lesinski | fbabe7d | 2015-08-03 14:37:38 -0700 | [diff] [blame] | 8906 | |
| 8907 | if (!seenNonZeroTime) { |
| 8908 | Slog.wtf(TAG, "All kernel wakelocks had time of zero"); |
| 8909 | } |
| 8910 | |
| 8911 | if (numWakelocksSetStale == mKernelWakelockStats.size()) { |
| 8912 | Slog.wtf(TAG, "All kernel wakelocks were set stale. new version=" + |
| 8913 | wakelockStats.kernelWakelockVersion); |
| 8914 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 8915 | } |
| 8916 | |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 8917 | // We use an anonymous class to access these variables, |
| 8918 | // so they can't live on the stack or they'd have to be |
| 8919 | // final MutableLong objects (more allocations). |
| 8920 | // Used in updateCpuTimeLocked(). |
| 8921 | long mTempTotalCpuUserTimeUs; |
| 8922 | long mTempTotalCpuSystemTimeUs; |
| 8923 | |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 8924 | /** |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 8925 | * Read and distribute CPU usage across apps. If their are partial wakelocks being held |
| 8926 | * and we are on battery with screen off, we give more of the cpu time to those apps holding |
| 8927 | * 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] | 8928 | */ |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 8929 | public void updateCpuTimeLocked() { |
Adam Lesinski | 52290c9c | 2015-09-21 16:54:52 -0700 | [diff] [blame] | 8930 | if (mPowerProfile == null) { |
| 8931 | return; |
| 8932 | } |
| 8933 | |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 8934 | if (DEBUG_ENERGY_CPU) { |
| 8935 | Slog.d(TAG, "!Cpu updating!"); |
| 8936 | } |
| 8937 | |
| 8938 | // Holding a wakelock costs more than just using the cpu. |
| 8939 | // Currently, we assign only half the cpu time to an app that is running but |
| 8940 | // not holding a wakelock. The apps holding wakelocks get the rest of the blame. |
| 8941 | // If no app is holding a wakelock, then the distribution is normal. |
| 8942 | final int wakelockWeight = 50; |
| 8943 | |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 8944 | // Read the time spent for each cluster at various cpu frequencies. |
| 8945 | final long[][] clusterSpeeds = new long[mKernelCpuSpeedReaders.length][]; |
| 8946 | for (int cluster = 0; cluster < mKernelCpuSpeedReaders.length; cluster++) { |
| 8947 | clusterSpeeds[cluster] = mKernelCpuSpeedReaders[cluster].readDelta(); |
| 8948 | } |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 8949 | |
| 8950 | int numWakelocks = 0; |
| 8951 | |
| 8952 | // Calculate how many wakelocks we have to distribute amongst. The system is excluded. |
| 8953 | // Only distribute cpu power to wakelocks if the screen is off and we're on battery. |
| 8954 | final int numPartialTimers = mPartialTimers.size(); |
| 8955 | if (mOnBatteryScreenOffTimeBase.isRunning()) { |
| 8956 | for (int i = 0; i < numPartialTimers; i++) { |
| 8957 | final StopwatchTimer timer = mPartialTimers.get(i); |
| 8958 | if (timer.mInList && timer.mUid != null && timer.mUid.mUid != Process.SYSTEM_UID) { |
| 8959 | // Since the collection and blaming of wakelocks can be scheduled to run after |
| 8960 | // some delay, the mPartialTimers list may have new entries. We can't blame |
| 8961 | // the newly added timer for past cpu time, so we only consider timers that |
| 8962 | // were present for one round of collection. Once a timer has gone through |
| 8963 | // a round of collection, its mInList field is set to true. |
| 8964 | numWakelocks++; |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 8965 | } |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 8966 | } |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 8967 | } |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 8968 | |
| 8969 | final int numWakelocksF = numWakelocks; |
| 8970 | mTempTotalCpuUserTimeUs = 0; |
| 8971 | mTempTotalCpuSystemTimeUs = 0; |
| 8972 | |
| 8973 | // Read the CPU data for each UID. This will internally generate a snapshot so next time |
| 8974 | // we read, we get a delta. If we are to distribute the cpu time, then do so. Otherwise |
| 8975 | // we just ignore the data. |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 8976 | final long startTimeMs = mClocks.elapsedRealtime(); |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 8977 | mKernelUidCpuTimeReader.readDelta(!mOnBatteryInternal ? null : |
| 8978 | new KernelUidCpuTimeReader.Callback() { |
| 8979 | @Override |
Adam Lesinski | a7a4ccc | 2015-06-26 17:43:04 -0700 | [diff] [blame] | 8980 | public void onUidCpuTime(int uid, long userTimeUs, long systemTimeUs, |
| 8981 | long powerMaUs) { |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 8982 | final Uid u = getUidStatsLocked(mapUid(uid)); |
| 8983 | |
| 8984 | // Accumulate the total system and user time. |
| 8985 | mTempTotalCpuUserTimeUs += userTimeUs; |
| 8986 | mTempTotalCpuSystemTimeUs += systemTimeUs; |
| 8987 | |
| 8988 | StringBuilder sb = null; |
| 8989 | if (DEBUG_ENERGY_CPU) { |
| 8990 | sb = new StringBuilder(); |
| 8991 | sb.append(" got time for uid=").append(u.mUid).append(": u="); |
| 8992 | TimeUtils.formatDuration(userTimeUs / 1000, sb); |
| 8993 | sb.append(" s="); |
| 8994 | TimeUtils.formatDuration(systemTimeUs / 1000, sb); |
Adam Lesinski | a7a4ccc | 2015-06-26 17:43:04 -0700 | [diff] [blame] | 8995 | sb.append(" p=").append(powerMaUs / 1000).append("mAms\n"); |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 8996 | } |
| 8997 | |
| 8998 | if (numWakelocksF > 0) { |
| 8999 | // We have wakelocks being held, so only give a portion of the |
| 9000 | // time to the process. The rest will be distributed among wakelock |
| 9001 | // holders. |
| 9002 | userTimeUs = (userTimeUs * wakelockWeight) / 100; |
| 9003 | systemTimeUs = (systemTimeUs * wakelockWeight) / 100; |
| 9004 | } |
| 9005 | |
| 9006 | if (sb != null) { |
| 9007 | sb.append(" adding to uid=").append(u.mUid).append(": u="); |
| 9008 | TimeUtils.formatDuration(userTimeUs / 1000, sb); |
| 9009 | sb.append(" s="); |
| 9010 | TimeUtils.formatDuration(systemTimeUs / 1000, sb); |
Adam Lesinski | a7a4ccc | 2015-06-26 17:43:04 -0700 | [diff] [blame] | 9011 | sb.append(" p=").append(powerMaUs / 1000).append("mAms"); |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 9012 | Slog.d(TAG, sb.toString()); |
| 9013 | } |
| 9014 | |
| 9015 | u.mUserCpuTime.addCountLocked(userTimeUs); |
| 9016 | u.mSystemCpuTime.addCountLocked(systemTimeUs); |
Adam Lesinski | a7a4ccc | 2015-06-26 17:43:04 -0700 | [diff] [blame] | 9017 | u.mCpuPower.addCountLocked(powerMaUs); |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 9018 | |
| 9019 | // Add the cpu speeds to this UID. These are used as a ratio |
| 9020 | // for computing the power this UID used. |
Adam Lesinski | 52290c9c | 2015-09-21 16:54:52 -0700 | [diff] [blame] | 9021 | final int numClusters = mPowerProfile.getNumCpuClusters(); |
| 9022 | if (u.mCpuClusterSpeed == null || u.mCpuClusterSpeed.length != |
| 9023 | numClusters) { |
| 9024 | u.mCpuClusterSpeed = new LongSamplingCounter[numClusters][]; |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 9025 | } |
| 9026 | |
| 9027 | for (int cluster = 0; cluster < clusterSpeeds.length; cluster++) { |
Adam Lesinski | 52290c9c | 2015-09-21 16:54:52 -0700 | [diff] [blame] | 9028 | final int speedsInCluster = mPowerProfile.getNumSpeedStepsInCpuCluster( |
| 9029 | cluster); |
| 9030 | if (u.mCpuClusterSpeed[cluster] == null || speedsInCluster != |
| 9031 | u.mCpuClusterSpeed[cluster].length) { |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 9032 | u.mCpuClusterSpeed[cluster] = |
Adam Lesinski | 52290c9c | 2015-09-21 16:54:52 -0700 | [diff] [blame] | 9033 | new LongSamplingCounter[speedsInCluster]; |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 9034 | } |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 9035 | |
| 9036 | final LongSamplingCounter[] cpuSpeeds = u.mCpuClusterSpeed[cluster]; |
| 9037 | for (int speed = 0; speed < clusterSpeeds[cluster].length; speed++) { |
| 9038 | if (cpuSpeeds[speed] == null) { |
| 9039 | cpuSpeeds[speed] = new LongSamplingCounter(mOnBatteryTimeBase); |
| 9040 | } |
| 9041 | cpuSpeeds[speed].addCountLocked(clusterSpeeds[cluster][speed]); |
| 9042 | } |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 9043 | } |
| 9044 | } |
| 9045 | }); |
| 9046 | |
| 9047 | if (DEBUG_ENERGY_CPU) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9048 | Slog.d(TAG, "Reading cpu stats took " + (mClocks.elapsedRealtime() - startTimeMs) + |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 9049 | " ms"); |
| 9050 | } |
| 9051 | |
| 9052 | if (mOnBatteryInternal && numWakelocks > 0) { |
| 9053 | // Distribute a portion of the total cpu time to wakelock holders. |
| 9054 | mTempTotalCpuUserTimeUs = (mTempTotalCpuUserTimeUs * (100 - wakelockWeight)) / 100; |
| 9055 | mTempTotalCpuSystemTimeUs = |
| 9056 | (mTempTotalCpuSystemTimeUs * (100 - wakelockWeight)) / 100; |
| 9057 | |
| 9058 | for (int i = 0; i < numPartialTimers; i++) { |
| 9059 | final StopwatchTimer timer = mPartialTimers.get(i); |
| 9060 | |
| 9061 | // The system does not share any blame, as it is usually holding the wakelock |
| 9062 | // on behalf of an app. |
| 9063 | if (timer.mInList && timer.mUid != null && timer.mUid.mUid != Process.SYSTEM_UID) { |
| 9064 | int userTimeUs = (int) (mTempTotalCpuUserTimeUs / numWakelocks); |
| 9065 | int systemTimeUs = (int) (mTempTotalCpuSystemTimeUs / numWakelocks); |
| 9066 | |
| 9067 | if (DEBUG_ENERGY_CPU) { |
| 9068 | StringBuilder sb = new StringBuilder(); |
| 9069 | sb.append(" Distributing wakelock uid=").append(timer.mUid.mUid) |
| 9070 | .append(": u="); |
| 9071 | TimeUtils.formatDuration(userTimeUs / 1000, sb); |
| 9072 | sb.append(" s="); |
| 9073 | TimeUtils.formatDuration(systemTimeUs / 1000, sb); |
| 9074 | Slog.d(TAG, sb.toString()); |
| 9075 | } |
| 9076 | |
| 9077 | timer.mUid.mUserCpuTime.addCountLocked(userTimeUs); |
| 9078 | timer.mUid.mSystemCpuTime.addCountLocked(systemTimeUs); |
| 9079 | |
| 9080 | final Uid.Proc proc = timer.mUid.getProcessStatsLocked("*wakelock*"); |
Adam Lesinski | 062e66c | 2015-07-14 12:02:44 -0700 | [diff] [blame] | 9081 | proc.addCpuTimeLocked(userTimeUs / 1000, systemTimeUs / 1000); |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 9082 | |
| 9083 | mTempTotalCpuUserTimeUs -= userTimeUs; |
| 9084 | mTempTotalCpuSystemTimeUs -= systemTimeUs; |
| 9085 | numWakelocks--; |
| 9086 | } |
| 9087 | } |
| 9088 | |
| 9089 | if (mTempTotalCpuUserTimeUs > 0 || mTempTotalCpuSystemTimeUs > 0) { |
| 9090 | // Anything left over is given to the system. |
| 9091 | if (DEBUG_ENERGY_CPU) { |
| 9092 | StringBuilder sb = new StringBuilder(); |
| 9093 | sb.append(" Distributing lost time to system: u="); |
| 9094 | TimeUtils.formatDuration(mTempTotalCpuUserTimeUs / 1000, sb); |
| 9095 | sb.append(" s="); |
| 9096 | TimeUtils.formatDuration(mTempTotalCpuSystemTimeUs / 1000, sb); |
| 9097 | Slog.d(TAG, sb.toString()); |
| 9098 | } |
| 9099 | |
| 9100 | final Uid u = getUidStatsLocked(Process.SYSTEM_UID); |
| 9101 | u.mUserCpuTime.addCountLocked(mTempTotalCpuUserTimeUs); |
| 9102 | u.mSystemCpuTime.addCountLocked(mTempTotalCpuSystemTimeUs); |
| 9103 | |
| 9104 | final Uid.Proc proc = u.getProcessStatsLocked("*lost*"); |
Adam Lesinski | 062e66c | 2015-07-14 12:02:44 -0700 | [diff] [blame] | 9105 | proc.addCpuTimeLocked((int) mTempTotalCpuUserTimeUs / 1000, |
| 9106 | (int) mTempTotalCpuSystemTimeUs / 1000); |
Adam Lesinski | 72478f0 | 2015-06-17 15:39:43 -0700 | [diff] [blame] | 9107 | } |
| 9108 | } |
| 9109 | |
| 9110 | // See if there is a difference in wakelocks between this collection and the last |
| 9111 | // collection. |
| 9112 | if (ArrayUtils.referenceEquals(mPartialTimers, mLastPartialTimers)) { |
| 9113 | // No difference, so each timer is now considered for the next collection. |
| 9114 | for (int i = 0; i < numPartialTimers; i++) { |
| 9115 | mPartialTimers.get(i).mInList = true; |
| 9116 | } |
| 9117 | } else { |
| 9118 | // The lists are different, meaning we added (or removed a timer) since the last |
| 9119 | // collection. |
| 9120 | final int numLastPartialTimers = mLastPartialTimers.size(); |
| 9121 | for (int i = 0; i < numLastPartialTimers; i++) { |
| 9122 | mLastPartialTimers.get(i).mInList = false; |
| 9123 | } |
| 9124 | mLastPartialTimers.clear(); |
| 9125 | |
| 9126 | // Mark the current timers as gone through a collection. |
| 9127 | for (int i = 0; i < numPartialTimers; i++) { |
| 9128 | final StopwatchTimer timer = mPartialTimers.get(i); |
| 9129 | timer.mInList = true; |
| 9130 | mLastPartialTimers.add(timer); |
| 9131 | } |
| 9132 | } |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 9133 | } |
| 9134 | |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 9135 | boolean setChargingLocked(boolean charging) { |
| 9136 | if (mCharging != charging) { |
| 9137 | mCharging = charging; |
| 9138 | if (charging) { |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 9139 | mHistoryCur.states2 |= HistoryItem.STATE2_CHARGING_FLAG; |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 9140 | } else { |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 9141 | mHistoryCur.states2 &= ~HistoryItem.STATE2_CHARGING_FLAG; |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 9142 | } |
| 9143 | mHandler.sendEmptyMessage(MSG_REPORT_CHARGING); |
| 9144 | return true; |
| 9145 | } |
| 9146 | return false; |
| 9147 | } |
| 9148 | |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 9149 | void setOnBatteryLocked(final long mSecRealtime, final long mSecUptime, final boolean onBattery, |
| 9150 | final int oldStatus, final int level) { |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 9151 | boolean doWrite = false; |
| 9152 | Message m = mHandler.obtainMessage(MSG_REPORT_POWER_CHANGE); |
| 9153 | m.arg1 = onBattery ? 1 : 0; |
| 9154 | mHandler.sendMessage(m); |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 9155 | |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 9156 | final long uptime = mSecUptime * 1000; |
| 9157 | final long realtime = mSecRealtime * 1000; |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 9158 | final boolean screenOn = mScreenState == Display.STATE_ON; |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 9159 | if (onBattery) { |
| 9160 | // We will reset our status if we are unplugging after the |
| 9161 | // battery was last full, or the level is at 100, or |
| 9162 | // we have gone through a significant charge (from a very low |
| 9163 | // level to a now very high level). |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 9164 | boolean reset = false; |
Dianne Hackborn | 9a75543 | 2014-05-15 17:05:22 -0700 | [diff] [blame] | 9165 | if (!mNoAutoReset && (oldStatus == BatteryManager.BATTERY_STATUS_FULL |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 9166 | || level >= 90 |
Dianne Hackborn | fb3809c | 2014-09-29 18:31:22 -0700 | [diff] [blame] | 9167 | || (mDischargeCurrentLevel < 20 && level >= 80) |
| 9168 | || (getHighDischargeAmountSinceCharge() >= 200 |
| 9169 | && mHistoryBuffer.dataSize() >= MAX_HISTORY_BUFFER))) { |
Dianne Hackborn | 73d6a82 | 2014-09-29 10:52:47 -0700 | [diff] [blame] | 9170 | Slog.i(TAG, "Resetting battery stats: level=" + level + " status=" + oldStatus |
Dianne Hackborn | fb3809c | 2014-09-29 18:31:22 -0700 | [diff] [blame] | 9171 | + " dischargeLevel=" + mDischargeCurrentLevel |
Dianne Hackborn | 73d6a82 | 2014-09-29 10:52:47 -0700 | [diff] [blame] | 9172 | + " lowAmount=" + getLowDischargeAmountSinceCharge() |
| 9173 | + " highAmount=" + getHighDischargeAmountSinceCharge()); |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 9174 | // Before we write, collect a snapshot of the final aggregated |
| 9175 | // stats to be reported in the next checkin. Only do this if we have |
| 9176 | // a sufficient amount of data to make it interesting. |
| 9177 | if (getLowDischargeAmountSinceCharge() >= 20) { |
| 9178 | final Parcel parcel = Parcel.obtain(); |
| 9179 | writeSummaryToParcel(parcel, true); |
| 9180 | BackgroundThread.getHandler().post(new Runnable() { |
| 9181 | @Override public void run() { |
| 9182 | synchronized (mCheckinFile) { |
| 9183 | FileOutputStream stream = null; |
| 9184 | try { |
| 9185 | stream = mCheckinFile.startWrite(); |
| 9186 | stream.write(parcel.marshall()); |
| 9187 | stream.flush(); |
| 9188 | FileUtils.sync(stream); |
| 9189 | stream.close(); |
| 9190 | mCheckinFile.finishWrite(stream); |
| 9191 | } catch (IOException e) { |
| 9192 | Slog.w("BatteryStats", |
| 9193 | "Error writing checkin battery statistics", e); |
| 9194 | mCheckinFile.failWrite(stream); |
| 9195 | } finally { |
| 9196 | parcel.recycle(); |
| 9197 | } |
| 9198 | } |
| 9199 | } |
| 9200 | }); |
| 9201 | } |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 9202 | doWrite = true; |
| 9203 | resetAllStatsLocked(); |
| 9204 | mDischargeStartLevel = level; |
Dianne Hackborn | eaf2ac4 | 2014-02-07 13:01:07 -0800 | [diff] [blame] | 9205 | reset = true; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 9206 | mDischargeStepTracker.init(); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9207 | } |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 9208 | if (mCharging) { |
| 9209 | setChargingLocked(false); |
| 9210 | } |
| 9211 | mLastChargingStateLevel = level; |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 9212 | mOnBattery = mOnBatteryInternal = true; |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 9213 | mLastDischargeStepLevel = level; |
Dianne Hackborn | 2932513 | 2014-05-21 15:01:03 -0700 | [diff] [blame] | 9214 | mMinDischargeStepLevel = level; |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 9215 | mDischargeStepTracker.clearTime(); |
| 9216 | mDailyDischargeStepTracker.clearTime(); |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 9217 | mInitStepMode = mCurStepMode; |
| 9218 | mModStepMode = 0; |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 9219 | pullPendingStateUpdatesLocked(); |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 9220 | mHistoryCur.batteryLevel = (byte)level; |
| 9221 | mHistoryCur.states &= ~HistoryItem.STATE_BATTERY_PLUGGED_FLAG; |
| 9222 | if (DEBUG_HISTORY) Slog.v(TAG, "Battery unplugged to: " |
| 9223 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 9224 | if (reset) { |
| 9225 | mRecordingHistory = true; |
| 9226 | startRecordingHistory(mSecRealtime, mSecUptime, reset); |
| 9227 | } |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 9228 | addHistoryRecordLocked(mSecRealtime, mSecUptime); |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 9229 | mDischargeCurrentLevel = mDischargeUnplugLevel = level; |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 9230 | if (screenOn) { |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 9231 | mDischargeScreenOnUnplugLevel = level; |
| 9232 | mDischargeScreenOffUnplugLevel = 0; |
| 9233 | } else { |
| 9234 | mDischargeScreenOnUnplugLevel = 0; |
| 9235 | mDischargeScreenOffUnplugLevel = level; |
| 9236 | } |
| 9237 | mDischargeAmountScreenOn = 0; |
| 9238 | mDischargeAmountScreenOff = 0; |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 9239 | updateTimeBasesLocked(true, !screenOn, uptime, realtime); |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 9240 | } else { |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 9241 | mLastChargingStateLevel = level; |
Dianne Hackborn | d1eccbe | 2015-02-18 14:02:14 -0800 | [diff] [blame] | 9242 | mOnBattery = mOnBatteryInternal = false; |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 9243 | pullPendingStateUpdatesLocked(); |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 9244 | mHistoryCur.batteryLevel = (byte)level; |
| 9245 | mHistoryCur.states |= HistoryItem.STATE_BATTERY_PLUGGED_FLAG; |
| 9246 | if (DEBUG_HISTORY) Slog.v(TAG, "Battery plugged to: " |
| 9247 | + Integer.toHexString(mHistoryCur.states)); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 9248 | addHistoryRecordLocked(mSecRealtime, mSecUptime); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 9249 | mDischargeCurrentLevel = mDischargePlugLevel = level; |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 9250 | if (level < mDischargeUnplugLevel) { |
| 9251 | mLowDischargeAmountSinceCharge += mDischargeUnplugLevel-level-1; |
| 9252 | mHighDischargeAmountSinceCharge += mDischargeUnplugLevel-level; |
| 9253 | } |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 9254 | updateDischargeScreenLevelsLocked(screenOn, screenOn); |
| 9255 | updateTimeBasesLocked(false, !screenOn, uptime, realtime); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 9256 | mChargeStepTracker.init(); |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 9257 | mLastChargeStepLevel = level; |
Dianne Hackborn | 2932513 | 2014-05-21 15:01:03 -0700 | [diff] [blame] | 9258 | mMaxChargeStepLevel = level; |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 9259 | mInitStepMode = mCurStepMode; |
| 9260 | mModStepMode = 0; |
Dianne Hackborn | 32de2f6 | 2011-03-09 14:03:35 -0800 | [diff] [blame] | 9261 | } |
| 9262 | if (doWrite || (mLastWriteTime + (60 * 1000)) < mSecRealtime) { |
| 9263 | if (mFile != null) { |
| 9264 | writeAsyncLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9265 | } |
| 9266 | } |
| 9267 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 9268 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 9269 | private void startRecordingHistory(final long elapsedRealtimeMs, final long uptimeMs, |
| 9270 | boolean reset) { |
| 9271 | mRecordingHistory = true; |
| 9272 | mHistoryCur.currentTime = System.currentTimeMillis(); |
Dianne Hackborn | 37de098 | 2014-05-09 09:32:18 -0700 | [diff] [blame] | 9273 | addHistoryBufferLocked(elapsedRealtimeMs, uptimeMs, |
| 9274 | reset ? HistoryItem.CMD_RESET : HistoryItem.CMD_CURRENT_TIME, |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 9275 | mHistoryCur); |
| 9276 | mHistoryCur.currentTime = 0; |
| 9277 | if (reset) { |
| 9278 | initActiveHistoryEventsLocked(elapsedRealtimeMs, uptimeMs); |
| 9279 | } |
| 9280 | } |
| 9281 | |
Dianne Hackborn | 7d9eefd | 2014-08-27 18:30:31 -0700 | [diff] [blame] | 9282 | private void recordCurrentTimeChangeLocked(final long currentTime, final long elapsedRealtimeMs, |
| 9283 | final long uptimeMs) { |
| 9284 | if (mRecordingHistory) { |
| 9285 | mHistoryCur.currentTime = currentTime; |
| 9286 | addHistoryBufferLocked(elapsedRealtimeMs, uptimeMs, HistoryItem.CMD_CURRENT_TIME, |
| 9287 | mHistoryCur); |
| 9288 | mHistoryCur.currentTime = 0; |
| 9289 | } |
| 9290 | } |
| 9291 | |
Dianne Hackborn | 29cd7f1 | 2015-01-08 10:37:05 -0800 | [diff] [blame] | 9292 | private void recordShutdownLocked(final long elapsedRealtimeMs, final long uptimeMs) { |
| 9293 | if (mRecordingHistory) { |
| 9294 | mHistoryCur.currentTime = System.currentTimeMillis(); |
Dianne Hackborn | 29cd7f1 | 2015-01-08 10:37:05 -0800 | [diff] [blame] | 9295 | addHistoryBufferLocked(elapsedRealtimeMs, uptimeMs, HistoryItem.CMD_SHUTDOWN, |
| 9296 | mHistoryCur); |
| 9297 | mHistoryCur.currentTime = 0; |
| 9298 | } |
| 9299 | } |
| 9300 | |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 9301 | private void scheduleSyncExternalStatsLocked(String reason, int updateFlags) { |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 9302 | if (mExternalSync != null) { |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 9303 | mExternalSync.scheduleSync(reason, updateFlags); |
Adam Lesinski | a7c90c8 | 2015-06-18 14:52:24 -0700 | [diff] [blame] | 9304 | } |
| 9305 | } |
| 9306 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9307 | // 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] | 9308 | public static final int BATTERY_PLUGGED_NONE = 0; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 9309 | |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 9310 | public void setBatteryStateLocked(int status, int health, int plugType, int level, |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame^] | 9311 | int temp, int volt, int chargeUAh) { |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 9312 | final boolean onBattery = plugType == BATTERY_PLUGGED_NONE; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9313 | final long uptime = mClocks.uptimeMillis(); |
| 9314 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 9315 | if (!mHaveBatteryLevel) { |
| 9316 | mHaveBatteryLevel = true; |
| 9317 | // We start out assuming that the device is plugged in (not |
| 9318 | // on battery). If our first report is now that we are indeed |
| 9319 | // plugged in, then twiddle our state to correctly reflect that |
| 9320 | // since we won't be going through the full setOnBattery(). |
| 9321 | if (onBattery == mOnBattery) { |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 9322 | if (onBattery) { |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 9323 | mHistoryCur.states &= ~HistoryItem.STATE_BATTERY_PLUGGED_FLAG; |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 9324 | } else { |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 9325 | mHistoryCur.states |= HistoryItem.STATE_BATTERY_PLUGGED_FLAG; |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 9326 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9327 | } |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 9328 | // Always start out assuming charging, that will be updated later. |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 9329 | mHistoryCur.states2 |= HistoryItem.STATE2_CHARGING_FLAG; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 9330 | mHistoryCur.batteryStatus = (byte)status; |
| 9331 | mHistoryCur.batteryLevel = (byte)level; |
| 9332 | mMaxChargeStepLevel = mMinDischargeStepLevel = |
| 9333 | mLastChargeStepLevel = mLastDischargeStepLevel = level; |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 9334 | mLastChargingStateLevel = level; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 9335 | } else if (mCurrentBatteryLevel != level || mOnBattery != onBattery) { |
| 9336 | recordDailyStatsIfNeededLocked(level >= 100 && onBattery); |
| 9337 | } |
| 9338 | int oldStatus = mHistoryCur.batteryStatus; |
| 9339 | if (onBattery) { |
| 9340 | mDischargeCurrentLevel = level; |
| 9341 | if (!mRecordingHistory) { |
| 9342 | mRecordingHistory = true; |
| 9343 | startRecordingHistory(elapsedRealtime, uptime, true); |
| 9344 | } |
| 9345 | } else if (level < 96) { |
| 9346 | if (!mRecordingHistory) { |
| 9347 | mRecordingHistory = true; |
| 9348 | startRecordingHistory(elapsedRealtime, uptime, true); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9349 | } |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 9350 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 9351 | mCurrentBatteryLevel = level; |
| 9352 | if (mDischargePlugLevel < 0) { |
| 9353 | mDischargePlugLevel = level; |
Marco Nelissen | d859331 | 2009-04-30 14:45:06 -0700 | [diff] [blame] | 9354 | } |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 9355 | |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 9356 | if (onBattery != mOnBattery) { |
| 9357 | mHistoryCur.batteryLevel = (byte)level; |
| 9358 | mHistoryCur.batteryStatus = (byte)status; |
| 9359 | mHistoryCur.batteryHealth = (byte)health; |
| 9360 | mHistoryCur.batteryPlugType = (byte)plugType; |
| 9361 | mHistoryCur.batteryTemperature = (short)temp; |
| 9362 | mHistoryCur.batteryVoltage = (char)volt; |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame^] | 9363 | mHistoryCur.batteryChargeUAh = chargeUAh; |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 9364 | setOnBatteryLocked(elapsedRealtime, uptime, onBattery, oldStatus, level); |
| 9365 | } else { |
| 9366 | boolean changed = false; |
| 9367 | if (mHistoryCur.batteryLevel != level) { |
| 9368 | mHistoryCur.batteryLevel = (byte)level; |
| 9369 | changed = true; |
Marco Nelissen | d859331 | 2009-04-30 14:45:06 -0700 | [diff] [blame] | 9370 | |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 9371 | // TODO(adamlesinski): Schedule the creation of a HistoryStepDetails record |
| 9372 | // which will pull external stats. |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 9373 | scheduleSyncExternalStatsLocked("battery-level", ExternalStatsSync.UPDATE_ALL); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 9374 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 9375 | if (mHistoryCur.batteryStatus != status) { |
| 9376 | mHistoryCur.batteryStatus = (byte)status; |
| 9377 | changed = true; |
| 9378 | } |
| 9379 | if (mHistoryCur.batteryHealth != health) { |
| 9380 | mHistoryCur.batteryHealth = (byte)health; |
| 9381 | changed = true; |
| 9382 | } |
| 9383 | if (mHistoryCur.batteryPlugType != plugType) { |
| 9384 | mHistoryCur.batteryPlugType = (byte)plugType; |
| 9385 | changed = true; |
| 9386 | } |
| 9387 | if (temp >= (mHistoryCur.batteryTemperature+10) |
| 9388 | || temp <= (mHistoryCur.batteryTemperature-10)) { |
| 9389 | mHistoryCur.batteryTemperature = (short)temp; |
| 9390 | changed = true; |
| 9391 | } |
| 9392 | if (volt > (mHistoryCur.batteryVoltage+20) |
| 9393 | || volt < (mHistoryCur.batteryVoltage-20)) { |
| 9394 | mHistoryCur.batteryVoltage = (char)volt; |
| 9395 | changed = true; |
| 9396 | } |
Adam Lesinski | a8018ac | 2016-05-03 10:18:10 -0700 | [diff] [blame^] | 9397 | if (chargeUAh >= (mHistoryCur.batteryChargeUAh+10) |
| 9398 | || chargeUAh <= (mHistoryCur.batteryChargeUAh-10)) { |
| 9399 | mHistoryCur.batteryChargeUAh = chargeUAh; |
Adam Lesinski | 926969b | 2016-04-28 17:31:12 -0700 | [diff] [blame] | 9400 | changed = true; |
| 9401 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 9402 | long modeBits = (((long)mInitStepMode) << STEP_LEVEL_INITIAL_MODE_SHIFT) |
| 9403 | | (((long)mModStepMode) << STEP_LEVEL_MODIFIED_MODE_SHIFT) |
| 9404 | | (((long)(level&0xff)) << STEP_LEVEL_LEVEL_SHIFT); |
| 9405 | if (onBattery) { |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 9406 | changed |= setChargingLocked(false); |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 9407 | if (mLastDischargeStepLevel != level && mMinDischargeStepLevel > level) { |
| 9408 | mDischargeStepTracker.addLevelSteps(mLastDischargeStepLevel - level, |
| 9409 | modeBits, elapsedRealtime); |
| 9410 | mDailyDischargeStepTracker.addLevelSteps(mLastDischargeStepLevel - level, |
| 9411 | modeBits, elapsedRealtime); |
| 9412 | mLastDischargeStepLevel = level; |
| 9413 | mMinDischargeStepLevel = level; |
| 9414 | mInitStepMode = mCurStepMode; |
| 9415 | mModStepMode = 0; |
| 9416 | } |
| 9417 | } else { |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 9418 | if (level >= 90) { |
| 9419 | // If the battery level is at least 90%, always consider the device to be |
| 9420 | // charging even if it happens to go down a level. |
| 9421 | changed |= setChargingLocked(true); |
| 9422 | mLastChargeStepLevel = level; |
| 9423 | } if (!mCharging) { |
| 9424 | if (mLastChargeStepLevel < level) { |
| 9425 | // We have not reporting that we are charging, but the level has now |
| 9426 | // gone up, so consider the state to be charging. |
| 9427 | changed |= setChargingLocked(true); |
| 9428 | mLastChargeStepLevel = level; |
| 9429 | } |
| 9430 | } else { |
| 9431 | if (mLastChargeStepLevel > level) { |
| 9432 | // We had reported that the device was charging, but here we are with |
| 9433 | // power connected and the level going down. Looks like the current |
| 9434 | // power supplied isn't enough, so consider the device to now be |
| 9435 | // discharging. |
| 9436 | changed |= setChargingLocked(false); |
| 9437 | mLastChargeStepLevel = level; |
| 9438 | } |
| 9439 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 9440 | if (mLastChargeStepLevel != level && mMaxChargeStepLevel < level) { |
| 9441 | mChargeStepTracker.addLevelSteps(level - mLastChargeStepLevel, |
| 9442 | modeBits, elapsedRealtime); |
| 9443 | mDailyChargeStepTracker.addLevelSteps(level - mLastChargeStepLevel, |
| 9444 | modeBits, elapsedRealtime); |
| 9445 | mLastChargeStepLevel = level; |
| 9446 | mMaxChargeStepLevel = level; |
| 9447 | mInitStepMode = mCurStepMode; |
| 9448 | mModStepMode = 0; |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 9449 | } |
| 9450 | } |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 9451 | if (changed) { |
| 9452 | addHistoryRecordLocked(elapsedRealtime, uptime); |
| 9453 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 9454 | } |
Adam Lesinski | 4b6bd8d | 2015-03-19 14:35:45 -0700 | [diff] [blame] | 9455 | if (!onBattery && status == BatteryManager.BATTERY_STATUS_FULL) { |
| 9456 | // We don't record history while we are plugged in and fully charged. |
| 9457 | // The next time we are unplugged, history will be cleared. |
| 9458 | mRecordingHistory = DEBUG; |
Dianne Hackborn | d0c5b9a | 2014-02-21 16:19:05 -0800 | [diff] [blame] | 9459 | } |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 9460 | } |
| 9461 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9462 | public long getAwakeTimeBattery() { |
| 9463 | return computeBatteryUptime(getBatteryUptimeLocked(), STATS_CURRENT); |
| 9464 | } |
| 9465 | |
| 9466 | public long getAwakeTimePlugged() { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9467 | return (mClocks.uptimeMillis() * 1000) - getAwakeTimeBattery(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9468 | } |
| 9469 | |
| 9470 | @Override |
| 9471 | public long computeUptime(long curTime, int which) { |
| 9472 | switch (which) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9473 | case STATS_SINCE_CHARGED: return mUptime + (curTime-mUptimeStart); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9474 | case STATS_CURRENT: return (curTime-mUptimeStart); |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 9475 | case STATS_SINCE_UNPLUGGED: return (curTime-mOnBatteryTimeBase.getUptimeStart()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9476 | } |
| 9477 | return 0; |
| 9478 | } |
| 9479 | |
| 9480 | @Override |
| 9481 | public long computeRealtime(long curTime, int which) { |
| 9482 | switch (which) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9483 | case STATS_SINCE_CHARGED: return mRealtime + (curTime-mRealtimeStart); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9484 | case STATS_CURRENT: return (curTime-mRealtimeStart); |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 9485 | case STATS_SINCE_UNPLUGGED: return (curTime-mOnBatteryTimeBase.getRealtimeStart()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9486 | } |
| 9487 | return 0; |
| 9488 | } |
| 9489 | |
| 9490 | @Override |
| 9491 | public long computeBatteryUptime(long curTime, int which) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9492 | return mOnBatteryTimeBase.computeUptime(curTime, which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9493 | } |
| 9494 | |
| 9495 | @Override |
| 9496 | public long computeBatteryRealtime(long curTime, int which) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9497 | return mOnBatteryTimeBase.computeRealtime(curTime, which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9498 | } |
| 9499 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9500 | @Override |
| 9501 | public long computeBatteryScreenOffUptime(long curTime, int which) { |
| 9502 | return mOnBatteryScreenOffTimeBase.computeUptime(curTime, which); |
| 9503 | } |
| 9504 | |
| 9505 | @Override |
| 9506 | public long computeBatteryScreenOffRealtime(long curTime, int which) { |
| 9507 | return mOnBatteryScreenOffTimeBase.computeRealtime(curTime, which); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9508 | } |
| 9509 | |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 9510 | private long computeTimePerLevel(long[] steps, int numSteps) { |
| 9511 | // For now we'll do a simple average across all steps. |
| 9512 | if (numSteps <= 0) { |
| 9513 | return -1; |
| 9514 | } |
| 9515 | long total = 0; |
| 9516 | for (int i=0; i<numSteps; i++) { |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 9517 | total += steps[i] & STEP_LEVEL_TIME_MASK; |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 9518 | } |
| 9519 | return total / numSteps; |
| 9520 | /* |
| 9521 | long[] buckets = new long[numSteps]; |
| 9522 | int numBuckets = 0; |
| 9523 | int numToAverage = 4; |
| 9524 | int i = 0; |
| 9525 | while (i < numSteps) { |
| 9526 | long totalTime = 0; |
| 9527 | int num = 0; |
| 9528 | for (int j=0; j<numToAverage && (i+j)<numSteps; j++) { |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 9529 | totalTime += steps[i+j] & STEP_LEVEL_TIME_MASK; |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 9530 | num++; |
| 9531 | } |
| 9532 | buckets[numBuckets] = totalTime / num; |
| 9533 | numBuckets++; |
| 9534 | numToAverage *= 2; |
| 9535 | i += num; |
| 9536 | } |
| 9537 | if (numBuckets < 1) { |
| 9538 | return -1; |
| 9539 | } |
| 9540 | long averageTime = buckets[numBuckets-1]; |
| 9541 | for (i=numBuckets-2; i>=0; i--) { |
| 9542 | averageTime = (averageTime + buckets[i]) / 2; |
| 9543 | } |
| 9544 | return averageTime; |
| 9545 | */ |
| 9546 | } |
| 9547 | |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 9548 | @Override |
| 9549 | public long computeBatteryTimeRemaining(long curTime) { |
| 9550 | if (!mOnBattery) { |
| 9551 | return -1; |
| 9552 | } |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 9553 | /* Simple implementation just looks at the average discharge per level across the |
| 9554 | entire sample period. |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 9555 | int discharge = (getLowDischargeAmountSinceCharge()+getHighDischargeAmountSinceCharge())/2; |
| 9556 | if (discharge < 2) { |
| 9557 | return -1; |
| 9558 | } |
| 9559 | long duration = computeBatteryRealtime(curTime, STATS_SINCE_CHARGED); |
| 9560 | if (duration < 1000*1000) { |
| 9561 | return -1; |
| 9562 | } |
| 9563 | long usPerLevel = duration/discharge; |
| 9564 | return usPerLevel * mCurrentBatteryLevel; |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 9565 | */ |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 9566 | if (mDischargeStepTracker.mNumStepDurations < 1) { |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 9567 | return -1; |
| 9568 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 9569 | long msPerLevel = mDischargeStepTracker.computeTimePerLevel(); |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 9570 | if (msPerLevel <= 0) { |
| 9571 | return -1; |
| 9572 | } |
| 9573 | return (msPerLevel * mCurrentBatteryLevel) * 1000; |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 9574 | } |
| 9575 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 9576 | @Override |
| 9577 | public LevelStepTracker getDischargeLevelStepTracker() { |
| 9578 | return mDischargeStepTracker; |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 9579 | } |
| 9580 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 9581 | @Override |
| 9582 | public LevelStepTracker getDailyDischargeLevelStepTracker() { |
| 9583 | return mDailyDischargeStepTracker; |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 9584 | } |
| 9585 | |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 9586 | @Override |
| 9587 | public long computeChargeTimeRemaining(long curTime) { |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 9588 | if (mOnBattery) { |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 9589 | // Not yet working. |
| 9590 | return -1; |
| 9591 | } |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 9592 | /* Broken |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 9593 | int curLevel = mCurrentBatteryLevel; |
| 9594 | int plugLevel = mDischargePlugLevel; |
| 9595 | if (plugLevel < 0 || curLevel < (plugLevel+1)) { |
| 9596 | return -1; |
| 9597 | } |
| 9598 | long duration = computeBatteryRealtime(curTime, STATS_SINCE_UNPLUGGED); |
| 9599 | if (duration < 1000*1000) { |
| 9600 | return -1; |
| 9601 | } |
| 9602 | long usPerLevel = duration/(curLevel-plugLevel); |
| 9603 | return usPerLevel * (100-curLevel); |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 9604 | */ |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 9605 | if (mChargeStepTracker.mNumStepDurations < 1) { |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 9606 | return -1; |
| 9607 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 9608 | long msPerLevel = mChargeStepTracker.computeTimePerLevel(); |
Dianne Hackborn | 260c502 | 2014-04-29 11:23:16 -0700 | [diff] [blame] | 9609 | if (msPerLevel <= 0) { |
| 9610 | return -1; |
| 9611 | } |
| 9612 | return (msPerLevel * (100-mCurrentBatteryLevel)) * 1000; |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 9613 | } |
| 9614 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 9615 | @Override |
| 9616 | public LevelStepTracker getChargeLevelStepTracker() { |
| 9617 | return mChargeStepTracker; |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 9618 | } |
| 9619 | |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 9620 | @Override |
| 9621 | public LevelStepTracker getDailyChargeLevelStepTracker() { |
| 9622 | return mDailyChargeStepTracker; |
Dianne Hackborn | ab5c0ea | 2014-04-29 14:53:32 -0700 | [diff] [blame] | 9623 | } |
| 9624 | |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 9625 | @Override |
| 9626 | public ArrayList<PackageChange> getDailyPackageChanges() { |
| 9627 | return mDailyPackageChanges; |
| 9628 | } |
| 9629 | |
Joe Onorato | e1acd63 | 2016-02-23 13:25:10 -0800 | [diff] [blame] | 9630 | protected long getBatteryUptimeLocked() { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9631 | return mOnBatteryTimeBase.getUptime(mClocks.uptimeMillis() * 1000); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9632 | } |
| 9633 | |
| 9634 | @Override |
| 9635 | public long getBatteryUptime(long curTime) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9636 | return mOnBatteryTimeBase.getUptime(curTime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9637 | } |
| 9638 | |
| 9639 | @Override |
| 9640 | public long getBatteryRealtime(long curTime) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 9641 | return mOnBatteryTimeBase.getRealtime(curTime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9642 | } |
Amith Yamasani | 3718aaa | 2009-06-09 06:32:35 -0700 | [diff] [blame] | 9643 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 9644 | @Override |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 9645 | public int getDischargeStartLevel() { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 9646 | synchronized(this) { |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 9647 | return getDischargeStartLevelLocked(); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 9648 | } |
| 9649 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 9650 | |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 9651 | public int getDischargeStartLevelLocked() { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9652 | return mDischargeUnplugLevel; |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 9653 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 9654 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 9655 | @Override |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 9656 | public int getDischargeCurrentLevel() { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 9657 | synchronized(this) { |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 9658 | return getDischargeCurrentLevelLocked(); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 9659 | } |
| 9660 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 9661 | |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 9662 | public int getDischargeCurrentLevelLocked() { |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 9663 | return mDischargeCurrentLevel; |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 9664 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9665 | |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 9666 | @Override |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 9667 | public int getLowDischargeAmountSinceCharge() { |
| 9668 | synchronized(this) { |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 9669 | int val = mLowDischargeAmountSinceCharge; |
| 9670 | if (mOnBattery && mDischargeCurrentLevel < mDischargeUnplugLevel) { |
| 9671 | val += mDischargeUnplugLevel-mDischargeCurrentLevel-1; |
| 9672 | } |
| 9673 | return val; |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 9674 | } |
| 9675 | } |
| 9676 | |
| 9677 | @Override |
| 9678 | public int getHighDischargeAmountSinceCharge() { |
| 9679 | synchronized(this) { |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 9680 | int val = mHighDischargeAmountSinceCharge; |
| 9681 | if (mOnBattery && mDischargeCurrentLevel < mDischargeUnplugLevel) { |
| 9682 | val += mDischargeUnplugLevel-mDischargeCurrentLevel; |
| 9683 | } |
| 9684 | return val; |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 9685 | } |
| 9686 | } |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 9687 | |
| 9688 | @Override |
| 9689 | public int getDischargeAmount(int which) { |
| 9690 | int dischargeAmount = which == STATS_SINCE_CHARGED |
| 9691 | ? getHighDischargeAmountSinceCharge() |
| 9692 | : (getDischargeStartLevel() - getDischargeCurrentLevel()); |
| 9693 | if (dischargeAmount < 0) { |
| 9694 | dischargeAmount = 0; |
| 9695 | } |
| 9696 | return dischargeAmount; |
| 9697 | } |
| 9698 | |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 9699 | public int getDischargeAmountScreenOn() { |
| 9700 | synchronized(this) { |
| 9701 | int val = mDischargeAmountScreenOn; |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 9702 | if (mOnBattery && mScreenState == Display.STATE_ON |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 9703 | && mDischargeCurrentLevel < mDischargeScreenOnUnplugLevel) { |
| 9704 | val += mDischargeScreenOnUnplugLevel-mDischargeCurrentLevel; |
| 9705 | } |
| 9706 | return val; |
| 9707 | } |
| 9708 | } |
| 9709 | |
| 9710 | public int getDischargeAmountScreenOnSinceCharge() { |
| 9711 | synchronized(this) { |
| 9712 | int val = mDischargeAmountScreenOnSinceCharge; |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 9713 | if (mOnBattery && mScreenState == Display.STATE_ON |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 9714 | && mDischargeCurrentLevel < mDischargeScreenOnUnplugLevel) { |
| 9715 | val += mDischargeScreenOnUnplugLevel-mDischargeCurrentLevel; |
| 9716 | } |
| 9717 | return val; |
| 9718 | } |
| 9719 | } |
| 9720 | |
| 9721 | public int getDischargeAmountScreenOff() { |
| 9722 | synchronized(this) { |
| 9723 | int val = mDischargeAmountScreenOff; |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 9724 | if (mOnBattery && mScreenState != Display.STATE_ON |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 9725 | && mDischargeCurrentLevel < mDischargeScreenOffUnplugLevel) { |
| 9726 | val += mDischargeScreenOffUnplugLevel-mDischargeCurrentLevel; |
| 9727 | } |
| 9728 | return val; |
| 9729 | } |
| 9730 | } |
| 9731 | |
| 9732 | public int getDischargeAmountScreenOffSinceCharge() { |
| 9733 | synchronized(this) { |
| 9734 | int val = mDischargeAmountScreenOffSinceCharge; |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 9735 | if (mOnBattery && mScreenState != Display.STATE_ON |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 9736 | && mDischargeCurrentLevel < mDischargeScreenOffUnplugLevel) { |
| 9737 | val += mDischargeScreenOffUnplugLevel-mDischargeCurrentLevel; |
| 9738 | } |
| 9739 | return val; |
| 9740 | } |
| 9741 | } |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 9742 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9743 | /** |
| 9744 | * Retrieve the statistics object for a particular uid, creating if needed. |
| 9745 | */ |
| 9746 | public Uid getUidStatsLocked(int uid) { |
| 9747 | Uid u = mUidStats.get(uid); |
| 9748 | if (u == null) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9749 | u = new Uid(this, uid); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9750 | mUidStats.put(uid, u); |
| 9751 | } |
| 9752 | return u; |
| 9753 | } |
| 9754 | |
| 9755 | /** |
| 9756 | * Remove the statistics object for a particular uid. |
| 9757 | */ |
| 9758 | public void removeUidStatsLocked(int uid) { |
Adam Lesinski | b83ffee | 2015-05-12 14:43:47 -0700 | [diff] [blame] | 9759 | mKernelUidCpuTimeReader.removeUid(uid); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9760 | mUidStats.remove(uid); |
| 9761 | } |
Amith Yamasani | 32dbefd | 2009-06-19 09:21:17 -0700 | [diff] [blame] | 9762 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9763 | /** |
| 9764 | * Retrieve the statistics object for a particular process, creating |
| 9765 | * if needed. |
| 9766 | */ |
| 9767 | public Uid.Proc getProcessStatsLocked(int uid, String name) { |
Dianne Hackborn | bbb7472 | 2014-03-13 09:50:24 -0700 | [diff] [blame] | 9768 | uid = mapUid(uid); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9769 | Uid u = getUidStatsLocked(uid); |
| 9770 | return u.getProcessStatsLocked(name); |
| 9771 | } |
| 9772 | |
| 9773 | /** |
| 9774 | * Retrieve the statistics object for a particular process, creating |
| 9775 | * if needed. |
| 9776 | */ |
| 9777 | public Uid.Pkg getPackageStatsLocked(int uid, String pkg) { |
Dianne Hackborn | bbb7472 | 2014-03-13 09:50:24 -0700 | [diff] [blame] | 9778 | uid = mapUid(uid); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9779 | Uid u = getUidStatsLocked(uid); |
| 9780 | return u.getPackageStatsLocked(pkg); |
| 9781 | } |
| 9782 | |
| 9783 | /** |
| 9784 | * Retrieve the statistics object for a particular service, creating |
| 9785 | * if needed. |
| 9786 | */ |
| 9787 | public Uid.Pkg.Serv getServiceStatsLocked(int uid, String pkg, String name) { |
Dianne Hackborn | bbb7472 | 2014-03-13 09:50:24 -0700 | [diff] [blame] | 9788 | uid = mapUid(uid); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9789 | Uid u = getUidStatsLocked(uid); |
| 9790 | return u.getServiceStatsLocked(pkg, name); |
| 9791 | } |
| 9792 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9793 | public void shutdownLocked() { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9794 | recordShutdownLocked(mClocks.elapsedRealtime(), mClocks.uptimeMillis()); |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 9795 | writeSyncLocked(); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9796 | mShuttingDown = true; |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 9797 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 9798 | |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 9799 | Parcel mPendingWrite = null; |
| 9800 | final ReentrantLock mWriteLock = new ReentrantLock(); |
| 9801 | |
| 9802 | public void writeAsyncLocked() { |
| 9803 | writeLocked(false); |
| 9804 | } |
| 9805 | |
| 9806 | public void writeSyncLocked() { |
| 9807 | writeLocked(true); |
| 9808 | } |
| 9809 | |
| 9810 | void writeLocked(boolean sync) { |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 9811 | if (mFile == null) { |
| 9812 | 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] | 9813 | return; |
| 9814 | } |
| 9815 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 9816 | if (mShuttingDown) { |
| 9817 | return; |
| 9818 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 9819 | |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 9820 | Parcel out = Parcel.obtain(); |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 9821 | writeSummaryToParcel(out, true); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9822 | mLastWriteTime = mClocks.elapsedRealtime(); |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 9823 | |
| 9824 | if (mPendingWrite != null) { |
| 9825 | mPendingWrite.recycle(); |
| 9826 | } |
| 9827 | mPendingWrite = out; |
| 9828 | |
| 9829 | if (sync) { |
| 9830 | commitPendingDataToDisk(); |
| 9831 | } else { |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 9832 | BackgroundThread.getHandler().post(new Runnable() { |
| 9833 | @Override public void run() { |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 9834 | commitPendingDataToDisk(); |
| 9835 | } |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 9836 | }); |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 9837 | } |
| 9838 | } |
| 9839 | |
| 9840 | public void commitPendingDataToDisk() { |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 9841 | final Parcel next; |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 9842 | synchronized (this) { |
| 9843 | next = mPendingWrite; |
| 9844 | mPendingWrite = null; |
Dianne Hackborn | f47d8f2 | 2010-10-08 10:46:55 -0700 | [diff] [blame] | 9845 | if (next == null) { |
| 9846 | return; |
| 9847 | } |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 9848 | |
| 9849 | mWriteLock.lock(); |
| 9850 | } |
| 9851 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9852 | try { |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 9853 | FileOutputStream stream = new FileOutputStream(mFile.chooseForWrite()); |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 9854 | stream.write(next.marshall()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9855 | stream.flush(); |
Dianne Hackborn | 8bdf593 | 2010-10-15 12:54:40 -0700 | [diff] [blame] | 9856 | FileUtils.sync(stream); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9857 | stream.close(); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 9858 | mFile.commit(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9859 | } catch (IOException e) { |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 9860 | Slog.w("BatteryStats", "Error writing battery statistics", e); |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 9861 | mFile.rollback(); |
| 9862 | } finally { |
| 9863 | next.recycle(); |
| 9864 | mWriteLock.unlock(); |
Suchi Amalapurapu | 8550f25 | 2009-09-29 15:20:32 -0700 | [diff] [blame] | 9865 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9866 | } |
| 9867 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9868 | public void readLocked() { |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 9869 | if (mDailyFile != null) { |
| 9870 | readDailyStatsLocked(); |
| 9871 | } |
| 9872 | |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 9873 | if (mFile == null) { |
| 9874 | 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] | 9875 | return; |
| 9876 | } |
| 9877 | |
| 9878 | mUidStats.clear(); |
| 9879 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9880 | try { |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 9881 | File file = mFile.chooseForRead(); |
| 9882 | if (!file.exists()) { |
| 9883 | return; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9884 | } |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 9885 | FileInputStream stream = new FileInputStream(file); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9886 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 9887 | byte[] raw = BatteryStatsHelper.readFully(stream); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9888 | Parcel in = Parcel.obtain(); |
| 9889 | in.unmarshall(raw, 0, raw.length); |
| 9890 | in.setDataPosition(0); |
| 9891 | stream.close(); |
| 9892 | |
| 9893 | readSummaryFromParcel(in); |
Dianne Hackborn | 00e2521 | 2014-02-19 10:49:24 -0800 | [diff] [blame] | 9894 | } catch(Exception e) { |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 9895 | Slog.e("BatteryStats", "Error reading battery statistics", e); |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 9896 | resetAllStatsLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9897 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 9898 | |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 9899 | mEndPlatformVersion = Build.ID; |
| 9900 | |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 9901 | if (mHistoryBuffer.dataPosition() > 0) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 9902 | mRecordingHistory = true; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9903 | final long elapsedRealtime = mClocks.elapsedRealtime(); |
| 9904 | final long uptime = mClocks.uptimeMillis(); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 9905 | if (USE_OLD_HISTORY) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 9906 | addHistoryRecordLocked(elapsedRealtime, uptime, HistoryItem.CMD_START, mHistoryCur); |
Dianne Hackborn | e5167ca | 2014-03-08 14:39:10 -0800 | [diff] [blame] | 9907 | } |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 9908 | addHistoryBufferLocked(elapsedRealtime, uptime, HistoryItem.CMD_START, mHistoryCur); |
| 9909 | startRecordingHistory(elapsedRealtime, uptime, false); |
Dianne Hackborn | e8c88e6 | 2011-08-17 19:09:09 -0700 | [diff] [blame] | 9910 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 9911 | |
| 9912 | recordDailyStatsIfNeededLocked(false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9913 | } |
| 9914 | |
| 9915 | public int describeContents() { |
| 9916 | return 0; |
| 9917 | } |
| 9918 | |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 9919 | void readHistory(Parcel in, boolean andOldHistory) throws ParcelFormatException { |
Dianne Hackborn | ae38445 | 2011-06-28 12:33:48 -0700 | [diff] [blame] | 9920 | final long historyBaseTime = in.readLong(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 9921 | |
| 9922 | mHistoryBuffer.setDataSize(0); |
| 9923 | mHistoryBuffer.setDataPosition(0); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 9924 | mHistoryTagPool.clear(); |
| 9925 | mNextHistoryTagIdx = 0; |
| 9926 | mNumHistoryTagChars = 0; |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 9927 | |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 9928 | int numTags = in.readInt(); |
| 9929 | for (int i=0; i<numTags; i++) { |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 9930 | int idx = in.readInt(); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 9931 | String str = in.readString(); |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 9932 | if (str == null) { |
| 9933 | throw new ParcelFormatException("null history tag string"); |
| 9934 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 9935 | int uid = in.readInt(); |
| 9936 | HistoryTag tag = new HistoryTag(); |
| 9937 | tag.string = str; |
| 9938 | tag.uid = uid; |
| 9939 | tag.poolIdx = idx; |
| 9940 | mHistoryTagPool.put(tag, idx); |
| 9941 | if (idx >= mNextHistoryTagIdx) { |
| 9942 | mNextHistoryTagIdx = idx+1; |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 9943 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 9944 | mNumHistoryTagChars += tag.string.length() + 1; |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 9945 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 9946 | |
| 9947 | int bufSize = in.readInt(); |
| 9948 | int curPos = in.dataPosition(); |
| 9949 | if (bufSize >= (MAX_MAX_HISTORY_BUFFER*3)) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 9950 | throw new ParcelFormatException("File corrupt: history data buffer too large " + |
| 9951 | bufSize); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 9952 | } else if ((bufSize&~3) != bufSize) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 9953 | throw new ParcelFormatException("File corrupt: history data buffer not aligned " + |
| 9954 | bufSize); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 9955 | } else { |
| 9956 | if (DEBUG_HISTORY) Slog.i(TAG, "***************** READING NEW HISTORY: " + bufSize |
| 9957 | + " bytes at " + curPos); |
| 9958 | mHistoryBuffer.appendFrom(in, curPos, bufSize); |
| 9959 | in.setDataPosition(curPos + bufSize); |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 9960 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 9961 | |
Dianne Hackborn | ae38445 | 2011-06-28 12:33:48 -0700 | [diff] [blame] | 9962 | if (andOldHistory) { |
| 9963 | readOldHistory(in); |
| 9964 | } |
| 9965 | |
| 9966 | if (DEBUG_HISTORY) { |
| 9967 | StringBuilder sb = new StringBuilder(128); |
| 9968 | sb.append("****************** OLD mHistoryBaseTime: "); |
| 9969 | TimeUtils.formatDuration(mHistoryBaseTime, sb); |
| 9970 | Slog.i(TAG, sb.toString()); |
| 9971 | } |
| 9972 | mHistoryBaseTime = historyBaseTime; |
| 9973 | if (DEBUG_HISTORY) { |
| 9974 | StringBuilder sb = new StringBuilder(128); |
| 9975 | sb.append("****************** NEW mHistoryBaseTime: "); |
| 9976 | TimeUtils.formatDuration(mHistoryBaseTime, sb); |
| 9977 | Slog.i(TAG, sb.toString()); |
| 9978 | } |
| 9979 | |
| 9980 | // We are just arbitrarily going to insert 1 minute from the sample of |
| 9981 | // the last run until samples in this run. |
| 9982 | if (mHistoryBaseTime > 0) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 9983 | long oldnow = mClocks.elapsedRealtime(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 9984 | mHistoryBaseTime = mHistoryBaseTime - oldnow + 1; |
Dianne Hackborn | ae38445 | 2011-06-28 12:33:48 -0700 | [diff] [blame] | 9985 | if (DEBUG_HISTORY) { |
| 9986 | StringBuilder sb = new StringBuilder(128); |
| 9987 | sb.append("****************** ADJUSTED mHistoryBaseTime: "); |
| 9988 | TimeUtils.formatDuration(mHistoryBaseTime, sb); |
| 9989 | Slog.i(TAG, sb.toString()); |
| 9990 | } |
Dianne Hackborn | 1e4b9f3 | 2010-06-23 14:10:57 -0700 | [diff] [blame] | 9991 | } |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 9992 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 9993 | |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 9994 | void readOldHistory(Parcel in) { |
Dianne Hackborn | e8c88e6 | 2011-08-17 19:09:09 -0700 | [diff] [blame] | 9995 | if (!USE_OLD_HISTORY) { |
| 9996 | return; |
| 9997 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 9998 | mHistory = mHistoryEnd = mHistoryCache = null; |
| 9999 | long time; |
Conley Owens | 5e3357f | 2011-05-02 09:59:30 -0700 | [diff] [blame] | 10000 | while (in.dataAvail() > 0 && (time=in.readLong()) >= 0) { |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 10001 | HistoryItem rec = new HistoryItem(time, in); |
| 10002 | addHistoryRecordLocked(rec); |
| 10003 | } |
| 10004 | } |
| 10005 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 10006 | void writeHistory(Parcel out, boolean inclData, boolean andOldHistory) { |
Dianne Hackborn | ae38445 | 2011-06-28 12:33:48 -0700 | [diff] [blame] | 10007 | if (DEBUG_HISTORY) { |
| 10008 | StringBuilder sb = new StringBuilder(128); |
| 10009 | sb.append("****************** WRITING mHistoryBaseTime: "); |
| 10010 | TimeUtils.formatDuration(mHistoryBaseTime, sb); |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 10011 | sb.append(" mLastHistoryElapsedRealtime: "); |
| 10012 | TimeUtils.formatDuration(mLastHistoryElapsedRealtime, sb); |
Dianne Hackborn | ae38445 | 2011-06-28 12:33:48 -0700 | [diff] [blame] | 10013 | Slog.i(TAG, sb.toString()); |
| 10014 | } |
Dianne Hackborn | 40c8725 | 2014-03-19 16:55:40 -0700 | [diff] [blame] | 10015 | out.writeLong(mHistoryBaseTime + mLastHistoryElapsedRealtime); |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 10016 | if (!inclData) { |
| 10017 | out.writeInt(0); |
| 10018 | out.writeInt(0); |
| 10019 | return; |
| 10020 | } |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 10021 | out.writeInt(mHistoryTagPool.size()); |
| 10022 | for (HashMap.Entry<HistoryTag, Integer> ent : mHistoryTagPool.entrySet()) { |
| 10023 | HistoryTag tag = ent.getKey(); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 10024 | out.writeInt(ent.getValue()); |
Dianne Hackborn | 71fc13e | 2014-02-03 10:50:53 -0800 | [diff] [blame] | 10025 | out.writeString(tag.string); |
| 10026 | out.writeInt(tag.uid); |
Dianne Hackborn | 099bc62 | 2014-01-22 13:39:16 -0800 | [diff] [blame] | 10027 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 10028 | out.writeInt(mHistoryBuffer.dataSize()); |
| 10029 | if (DEBUG_HISTORY) Slog.i(TAG, "***************** WRITING HISTORY: " |
| 10030 | + mHistoryBuffer.dataSize() + " bytes at " + out.dataPosition()); |
| 10031 | out.appendFrom(mHistoryBuffer, 0, mHistoryBuffer.dataSize()); |
Dianne Hackborn | ae38445 | 2011-06-28 12:33:48 -0700 | [diff] [blame] | 10032 | |
| 10033 | if (andOldHistory) { |
| 10034 | writeOldHistory(out); |
| 10035 | } |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 10036 | } |
| 10037 | |
| 10038 | void writeOldHistory(Parcel out) { |
Dianne Hackborn | e8c88e6 | 2011-08-17 19:09:09 -0700 | [diff] [blame] | 10039 | if (!USE_OLD_HISTORY) { |
| 10040 | return; |
| 10041 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10042 | HistoryItem rec = mHistory; |
Dianne Hackborn | 32907cf | 2010-06-10 17:50:20 -0700 | [diff] [blame] | 10043 | while (rec != null) { |
| 10044 | if (rec.time >= 0) rec.writeToParcel(out, 0); |
| 10045 | rec = rec.next; |
| 10046 | } |
| 10047 | out.writeLong(-1); |
| 10048 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 10049 | |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 10050 | public void readSummaryFromParcel(Parcel in) throws ParcelFormatException { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10051 | final int version = in.readInt(); |
| 10052 | if (version != VERSION) { |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 10053 | Slog.w("BatteryStats", "readFromParcel: version got " + version |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10054 | + ", expected " + VERSION + "; erasing old stats"); |
| 10055 | return; |
| 10056 | } |
| 10057 | |
Dianne Hackborn | ae38445 | 2011-06-28 12:33:48 -0700 | [diff] [blame] | 10058 | readHistory(in, true); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 10059 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10060 | mStartCount = in.readInt(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10061 | mUptime = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10062 | mRealtime = in.readLong(); |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 10063 | mStartClockTime = in.readLong(); |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 10064 | mStartPlatformVersion = in.readString(); |
| 10065 | mEndPlatformVersion = in.readString(); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10066 | mOnBatteryTimeBase.readSummaryFromParcel(in); |
| 10067 | mOnBatteryScreenOffTimeBase.readSummaryFromParcel(in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10068 | mDischargeUnplugLevel = in.readInt(); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 10069 | mDischargePlugLevel = in.readInt(); |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 10070 | mDischargeCurrentLevel = in.readInt(); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 10071 | mCurrentBatteryLevel = in.readInt(); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 10072 | mLowDischargeAmountSinceCharge = in.readInt(); |
| 10073 | mHighDischargeAmountSinceCharge = in.readInt(); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 10074 | mDischargeAmountScreenOnSinceCharge = in.readInt(); |
| 10075 | mDischargeAmountScreenOffSinceCharge = in.readInt(); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 10076 | mDischargeStepTracker.readFromParcel(in); |
| 10077 | mChargeStepTracker.readFromParcel(in); |
| 10078 | mDailyDischargeStepTracker.readFromParcel(in); |
| 10079 | mDailyChargeStepTracker.readFromParcel(in); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 10080 | int NPKG = in.readInt(); |
| 10081 | if (NPKG > 0) { |
| 10082 | mDailyPackageChanges = new ArrayList<>(NPKG); |
| 10083 | while (NPKG > 0) { |
| 10084 | NPKG--; |
| 10085 | PackageChange pc = new PackageChange(); |
| 10086 | pc.mPackageName = in.readString(); |
| 10087 | pc.mUpdate = in.readInt() != 0; |
| 10088 | pc.mVersionCode = in.readInt(); |
| 10089 | mDailyPackageChanges.add(pc); |
| 10090 | } |
| 10091 | } else { |
| 10092 | mDailyPackageChanges = null; |
| 10093 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 10094 | mDailyStartTime = in.readLong(); |
| 10095 | mNextMinDailyDeadline = in.readLong(); |
| 10096 | mNextMaxDailyDeadline = in.readLong(); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 10097 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10098 | mStartCount++; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 10099 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 10100 | mScreenState = Display.STATE_UNKNOWN; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10101 | mScreenOnTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 10102 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
| 10103 | mScreenBrightnessTimer[i].readSummaryFromParcelLocked(in); |
| 10104 | } |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 10105 | mInteractive = false; |
| 10106 | mInteractiveTimer.readSummaryFromParcelLocked(in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10107 | mPhoneOn = false; |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 10108 | mPowerSaveModeEnabledTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 10109 | mLongestLightIdleTime = in.readLong(); |
| 10110 | mLongestFullIdleTime = in.readLong(); |
| 10111 | mDeviceIdleModeLightTimer.readSummaryFromParcelLocked(in); |
| 10112 | mDeviceIdleModeFullTimer.readSummaryFromParcelLocked(in); |
| 10113 | mDeviceLightIdlingTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 10114 | mDeviceIdlingTimer.readSummaryFromParcelLocked(in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10115 | mPhoneOnTimer.readSummaryFromParcelLocked(in); |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 10116 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 10117 | mPhoneSignalStrengthsTimer[i].readSummaryFromParcelLocked(in); |
| 10118 | } |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 10119 | mPhoneSignalScanningTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 10120 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
| 10121 | mPhoneDataConnectionsTimer[i].readSummaryFromParcelLocked(in); |
| 10122 | } |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 10123 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 10124 | mNetworkByteActivityCounters[i].readSummaryFromParcelLocked(in); |
| 10125 | mNetworkPacketActivityCounters[i].readSummaryFromParcelLocked(in); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 10126 | } |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 10127 | mMobileRadioPowerState = DataConnectionRealTimeInfo.DC_POWER_STATE_LOW; |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 10128 | mMobileRadioActiveTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 10129 | mMobileRadioActivePerAppTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 10130 | mMobileRadioActiveAdjustedTime.readSummaryFromParcelLocked(in); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 10131 | mMobileRadioActiveUnknownTime.readSummaryFromParcelLocked(in); |
| 10132 | mMobileRadioActiveUnknownCount.readSummaryFromParcelLocked(in); |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 10133 | mWifiRadioPowerState = DataConnectionRealTimeInfo.DC_POWER_STATE_LOW; |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 10134 | mWifiOn = false; |
| 10135 | mWifiOnTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 10136 | mGlobalWifiRunning = false; |
| 10137 | mGlobalWifiRunningTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 10138 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
| 10139 | mWifiStateTimer[i].readSummaryFromParcelLocked(in); |
| 10140 | } |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 10141 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
| 10142 | mWifiSupplStateTimer[i].readSummaryFromParcelLocked(in); |
| 10143 | } |
| 10144 | for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 10145 | mWifiSignalStrengthsTimer[i].readSummaryFromParcelLocked(in); |
| 10146 | } |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 10147 | mWifiActivity.readSummaryFromParcel(in); |
| 10148 | mBluetoothActivity.readSummaryFromParcel(in); |
| 10149 | mModemActivity.readSummaryFromParcel(in); |
| 10150 | mHasWifiReporting = in.readInt() != 0; |
| 10151 | mHasBluetoothReporting = in.readInt() != 0; |
| 10152 | mHasModemReporting = in.readInt() != 0; |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 10153 | |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 10154 | mNumConnectivityChange = mLoadedNumConnectivityChange = in.readInt(); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 10155 | mFlashlightOnNesting = 0; |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 10156 | mFlashlightOnTimer.readSummaryFromParcelLocked(in); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 10157 | mCameraOnNesting = 0; |
| 10158 | mCameraOnTimer.readSummaryFromParcelLocked(in); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 10159 | mBluetoothScanNesting = 0; |
| 10160 | mBluetoothScanTimer.readSummaryFromParcelLocked(in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10161 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 10162 | int NKW = in.readInt(); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 10163 | if (NKW > 10000) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 10164 | throw new ParcelFormatException("File corrupt: too many kernel wake locks " + NKW); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 10165 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 10166 | for (int ikw = 0; ikw < NKW; ikw++) { |
| 10167 | if (in.readInt() != 0) { |
| 10168 | String kwltName = in.readString(); |
| 10169 | getKernelWakelockTimerLocked(kwltName).readSummaryFromParcelLocked(in); |
| 10170 | } |
| 10171 | } |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 10172 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 10173 | int NWR = in.readInt(); |
| 10174 | if (NWR > 10000) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 10175 | throw new ParcelFormatException("File corrupt: too many wakeup reasons " + NWR); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 10176 | } |
| 10177 | for (int iwr = 0; iwr < NWR; iwr++) { |
| 10178 | if (in.readInt() != 0) { |
| 10179 | String reasonName = in.readString(); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 10180 | getWakeupReasonTimerLocked(reasonName).readSummaryFromParcelLocked(in); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 10181 | } |
| 10182 | } |
| 10183 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10184 | final int NU = in.readInt(); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 10185 | if (NU > 10000) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 10186 | throw new ParcelFormatException("File corrupt: too many uids " + NU); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 10187 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10188 | for (int iu = 0; iu < NU; iu++) { |
| 10189 | int uid = in.readInt(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 10190 | Uid u = new Uid(this, uid); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10191 | mUidStats.put(uid, u); |
| 10192 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 10193 | u.mWifiRunning = false; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10194 | if (in.readInt() != 0) { |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 10195 | u.mWifiRunningTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10196 | } |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 10197 | u.mFullWifiLockOut = false; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10198 | if (in.readInt() != 0) { |
| 10199 | u.mFullWifiLockTimer.readSummaryFromParcelLocked(in); |
| 10200 | } |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 10201 | u.mWifiScanStarted = false; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10202 | if (in.readInt() != 0) { |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 10203 | u.mWifiScanTimer.readSummaryFromParcelLocked(in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10204 | } |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 10205 | u.mWifiBatchedScanBinStarted = Uid.NO_BATCHED_SCAN_STARTED; |
| 10206 | for (int i = 0; i < Uid.NUM_WIFI_BATCHED_SCAN_BINS; i++) { |
| 10207 | if (in.readInt() != 0) { |
| 10208 | u.makeWifiBatchedScanBin(i, null); |
| 10209 | u.mWifiBatchedScanTimer[i].readSummaryFromParcelLocked(in); |
| 10210 | } |
| 10211 | } |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 10212 | u.mWifiMulticastEnabled = false; |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10213 | if (in.readInt() != 0) { |
| 10214 | u.mWifiMulticastTimer.readSummaryFromParcelLocked(in); |
| 10215 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10216 | if (in.readInt() != 0) { |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 10217 | u.createAudioTurnedOnTimerLocked().readSummaryFromParcelLocked(in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10218 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10219 | if (in.readInt() != 0) { |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 10220 | u.createVideoTurnedOnTimerLocked().readSummaryFromParcelLocked(in); |
| 10221 | } |
| 10222 | if (in.readInt() != 0) { |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 10223 | u.createFlashlightTurnedOnTimerLocked().readSummaryFromParcelLocked(in); |
| 10224 | } |
| 10225 | if (in.readInt() != 0) { |
| 10226 | u.createCameraTurnedOnTimerLocked().readSummaryFromParcelLocked(in); |
| 10227 | } |
| 10228 | if (in.readInt() != 0) { |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 10229 | u.createForegroundActivityTimerLocked().readSummaryFromParcelLocked(in); |
| 10230 | } |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 10231 | if (in.readInt() != 0) { |
| 10232 | u.createBluetoothScanTimerLocked().readSummaryFromParcelLocked(in); |
| 10233 | } |
Dianne Hackborn | a8d1094 | 2015-11-19 17:55:19 -0800 | [diff] [blame] | 10234 | u.mProcessState = ActivityManager.PROCESS_STATE_NONEXISTENT; |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 10235 | for (int i = 0; i < Uid.NUM_PROCESS_STATE; i++) { |
| 10236 | if (in.readInt() != 0) { |
| 10237 | u.makeProcessState(i, null); |
| 10238 | u.mProcessStateTimer[i].readSummaryFromParcelLocked(in); |
| 10239 | } |
| 10240 | } |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 10241 | if (in.readInt() != 0) { |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 10242 | u.createVibratorOnTimerLocked().readSummaryFromParcelLocked(in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10243 | } |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 10244 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 10245 | if (in.readInt() != 0) { |
| 10246 | if (u.mUserActivityCounters == null) { |
| 10247 | u.initUserActivityLocked(); |
| 10248 | } |
| 10249 | for (int i=0; i<Uid.NUM_USER_ACTIVITY_TYPES; i++) { |
| 10250 | u.mUserActivityCounters[i].readSummaryFromParcelLocked(in); |
| 10251 | } |
| 10252 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 10253 | |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 10254 | if (in.readInt() != 0) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 10255 | if (u.mNetworkByteActivityCounters == null) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 10256 | u.initNetworkActivityLocked(); |
| 10257 | } |
| 10258 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 10259 | u.mNetworkByteActivityCounters[i].readSummaryFromParcelLocked(in); |
| 10260 | u.mNetworkPacketActivityCounters[i].readSummaryFromParcelLocked(in); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 10261 | } |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 10262 | u.mMobileRadioActiveTime.readSummaryFromParcelLocked(in); |
| 10263 | u.mMobileRadioActiveCount.readSummaryFromParcelLocked(in); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 10264 | } |
| 10265 | |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 10266 | u.mUserCpuTime.readSummaryFromParcelLocked(in); |
| 10267 | u.mSystemCpuTime.readSummaryFromParcelLocked(in); |
Adam Lesinski | a7a4ccc | 2015-06-26 17:43:04 -0700 | [diff] [blame] | 10268 | u.mCpuPower.readSummaryFromParcelLocked(in); |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 10269 | |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 10270 | if (in.readInt() != 0) { |
| 10271 | final int numClusters = in.readInt(); |
| 10272 | if (mPowerProfile != null && mPowerProfile.getNumCpuClusters() != numClusters) { |
| 10273 | throw new ParcelFormatException("Incompatible cpu cluster arrangement"); |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 10274 | } |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 10275 | |
| 10276 | u.mCpuClusterSpeed = new LongSamplingCounter[numClusters][]; |
| 10277 | for (int cluster = 0; cluster < numClusters; cluster++) { |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 10278 | if (in.readInt() != 0) { |
Adam Lesinski | a57a540 | 2015-09-28 10:21:33 -0700 | [diff] [blame] | 10279 | final int NSB = in.readInt(); |
| 10280 | if (mPowerProfile != null && |
| 10281 | mPowerProfile.getNumSpeedStepsInCpuCluster(cluster) != NSB) { |
| 10282 | throw new ParcelFormatException("File corrupt: too many speed bins " + |
| 10283 | NSB); |
| 10284 | } |
| 10285 | |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 10286 | u.mCpuClusterSpeed[cluster] = new LongSamplingCounter[NSB]; |
| 10287 | for (int speed = 0; speed < NSB; speed++) { |
| 10288 | if (in.readInt() != 0) { |
| 10289 | u.mCpuClusterSpeed[cluster][speed] = new LongSamplingCounter( |
| 10290 | mOnBatteryTimeBase); |
| 10291 | u.mCpuClusterSpeed[cluster][speed].readSummaryFromParcelLocked(in); |
| 10292 | } |
| 10293 | } |
Adam Lesinski | a57a540 | 2015-09-28 10:21:33 -0700 | [diff] [blame] | 10294 | } else { |
| 10295 | u.mCpuClusterSpeed[cluster] = null; |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 10296 | } |
| 10297 | } |
| 10298 | } else { |
| 10299 | u.mCpuClusterSpeed = null; |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 10300 | } |
| 10301 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10302 | int NW = in.readInt(); |
Dianne Hackborn | 7b9c56f | 2010-12-07 11:14:53 -0800 | [diff] [blame] | 10303 | if (NW > 100) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 10304 | throw new ParcelFormatException("File corrupt: too many wake locks " + NW); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 10305 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10306 | for (int iw = 0; iw < NW; iw++) { |
| 10307 | String wlName = in.readString(); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 10308 | u.readWakeSummaryFromParcelLocked(wlName, in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10309 | } |
| 10310 | |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 10311 | int NS = in.readInt(); |
| 10312 | if (NS > 100) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 10313 | throw new ParcelFormatException("File corrupt: too many syncs " + NS); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 10314 | } |
| 10315 | for (int is = 0; is < NS; is++) { |
| 10316 | String name = in.readString(); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 10317 | u.readSyncSummaryFromParcelLocked(name, in); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 10318 | } |
| 10319 | |
| 10320 | int NJ = in.readInt(); |
| 10321 | if (NJ > 100) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 10322 | throw new ParcelFormatException("File corrupt: too many job timers " + NJ); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 10323 | } |
| 10324 | for (int ij = 0; ij < NJ; ij++) { |
| 10325 | String name = in.readString(); |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 10326 | u.readJobSummaryFromParcelLocked(name, in); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 10327 | } |
| 10328 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10329 | int NP = in.readInt(); |
Dianne Hackborn | 7b9c56f | 2010-12-07 11:14:53 -0800 | [diff] [blame] | 10330 | if (NP > 1000) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 10331 | throw new ParcelFormatException("File corrupt: too many sensors " + NP); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 10332 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10333 | for (int is = 0; is < NP; is++) { |
| 10334 | int seNumber = in.readInt(); |
| 10335 | if (in.readInt() != 0) { |
| 10336 | u.getSensorTimerLocked(seNumber, true) |
| 10337 | .readSummaryFromParcelLocked(in); |
| 10338 | } |
| 10339 | } |
| 10340 | |
| 10341 | NP = in.readInt(); |
Dianne Hackborn | 7b9c56f | 2010-12-07 11:14:53 -0800 | [diff] [blame] | 10342 | if (NP > 1000) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 10343 | throw new ParcelFormatException("File corrupt: too many processes " + NP); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 10344 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10345 | for (int ip = 0; ip < NP; ip++) { |
| 10346 | String procName = in.readString(); |
| 10347 | Uid.Proc p = u.getProcessStatsLocked(procName); |
| 10348 | p.mUserTime = p.mLoadedUserTime = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10349 | p.mSystemTime = p.mLoadedSystemTime = in.readLong(); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 10350 | p.mForegroundTime = p.mLoadedForegroundTime = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10351 | p.mStarts = p.mLoadedStarts = in.readInt(); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 10352 | p.mNumCrashes = p.mLoadedNumCrashes = in.readInt(); |
| 10353 | p.mNumAnrs = p.mLoadedNumAnrs = in.readInt(); |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 10354 | p.readExcessivePowerFromParcelLocked(in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10355 | } |
| 10356 | |
| 10357 | NP = in.readInt(); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 10358 | if (NP > 10000) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 10359 | throw new ParcelFormatException("File corrupt: too many packages " + NP); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 10360 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10361 | for (int ip = 0; ip < NP; ip++) { |
| 10362 | String pkgName = in.readString(); |
| 10363 | Uid.Pkg p = u.getPackageStatsLocked(pkgName); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 10364 | final int NWA = in.readInt(); |
| 10365 | if (NWA > 1000) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 10366 | throw new ParcelFormatException("File corrupt: too many wakeup alarms " + NWA); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 10367 | } |
| 10368 | p.mWakeupAlarms.clear(); |
| 10369 | for (int iwa=0; iwa<NWA; iwa++) { |
| 10370 | String tag = in.readString(); |
| 10371 | Counter c = new Counter(mOnBatteryTimeBase); |
| 10372 | c.readSummaryFromParcelLocked(in); |
| 10373 | p.mWakeupAlarms.put(tag, c); |
| 10374 | } |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 10375 | NS = in.readInt(); |
Dianne Hackborn | 7b9c56f | 2010-12-07 11:14:53 -0800 | [diff] [blame] | 10376 | if (NS > 1000) { |
Adam Lesinski | 9ae9cba | 2015-07-08 17:09:34 -0700 | [diff] [blame] | 10377 | throw new ParcelFormatException("File corrupt: too many services " + NS); |
Dianne Hackborn | 7b9c56f | 2010-12-07 11:14:53 -0800 | [diff] [blame] | 10378 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10379 | for (int is = 0; is < NS; is++) { |
| 10380 | String servName = in.readString(); |
| 10381 | Uid.Pkg.Serv s = u.getServiceStatsLocked(pkgName, servName); |
| 10382 | s.mStartTime = s.mLoadedStartTime = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10383 | s.mStarts = s.mLoadedStarts = in.readInt(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10384 | s.mLaunches = s.mLoadedLaunches = in.readInt(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10385 | } |
| 10386 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10387 | } |
| 10388 | } |
| 10389 | |
| 10390 | /** |
| 10391 | * Writes a summary of the statistics to a Parcel, in a format suitable to be written to |
| 10392 | * disk. This format does not allow a lossless round-trip. |
| 10393 | * |
| 10394 | * @param out the Parcel to be written to. |
| 10395 | */ |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 10396 | public void writeSummaryToParcel(Parcel out, boolean inclHistory) { |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 10397 | pullPendingStateUpdatesLocked(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 10398 | |
Dianne Hackborn | 7d9eefd | 2014-08-27 18:30:31 -0700 | [diff] [blame] | 10399 | // Pull the clock time. This may update the time and make a new history entry |
| 10400 | // if we had originally pulled a time before the RTC was set. |
| 10401 | long startClockTime = getStartClockTime(); |
| 10402 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 10403 | final long NOW_SYS = mClocks.uptimeMillis() * 1000; |
| 10404 | final long NOWREAL_SYS = mClocks.elapsedRealtime() * 1000; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10405 | |
| 10406 | out.writeInt(VERSION); |
| 10407 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 10408 | writeHistory(out, inclHistory, true); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 10409 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10410 | out.writeInt(mStartCount); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10411 | out.writeLong(computeUptime(NOW_SYS, STATS_SINCE_CHARGED)); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10412 | out.writeLong(computeRealtime(NOWREAL_SYS, STATS_SINCE_CHARGED)); |
Dianne Hackborn | 7d9eefd | 2014-08-27 18:30:31 -0700 | [diff] [blame] | 10413 | out.writeLong(startClockTime); |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 10414 | out.writeString(mStartPlatformVersion); |
| 10415 | out.writeString(mEndPlatformVersion); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10416 | mOnBatteryTimeBase.writeSummaryToParcel(out, NOW_SYS, NOWREAL_SYS); |
| 10417 | mOnBatteryScreenOffTimeBase.writeSummaryToParcel(out, NOW_SYS, NOWREAL_SYS); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10418 | out.writeInt(mDischargeUnplugLevel); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 10419 | out.writeInt(mDischargePlugLevel); |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 10420 | out.writeInt(mDischargeCurrentLevel); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 10421 | out.writeInt(mCurrentBatteryLevel); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 10422 | out.writeInt(getLowDischargeAmountSinceCharge()); |
| 10423 | out.writeInt(getHighDischargeAmountSinceCharge()); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 10424 | out.writeInt(getDischargeAmountScreenOnSinceCharge()); |
| 10425 | out.writeInt(getDischargeAmountScreenOffSinceCharge()); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 10426 | mDischargeStepTracker.writeToParcel(out); |
| 10427 | mChargeStepTracker.writeToParcel(out); |
| 10428 | mDailyDischargeStepTracker.writeToParcel(out); |
| 10429 | mDailyChargeStepTracker.writeToParcel(out); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 10430 | if (mDailyPackageChanges != null) { |
| 10431 | final int NPKG = mDailyPackageChanges.size(); |
| 10432 | out.writeInt(NPKG); |
| 10433 | for (int i=0; i<NPKG; i++) { |
| 10434 | PackageChange pc = mDailyPackageChanges.get(i); |
| 10435 | out.writeString(pc.mPackageName); |
| 10436 | out.writeInt(pc.mUpdate ? 1 : 0); |
| 10437 | out.writeInt(pc.mVersionCode); |
| 10438 | } |
| 10439 | } else { |
| 10440 | out.writeInt(0); |
| 10441 | } |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 10442 | out.writeLong(mDailyStartTime); |
| 10443 | out.writeLong(mNextMinDailyDeadline); |
| 10444 | out.writeLong(mNextMaxDailyDeadline); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10445 | |
| 10446 | mScreenOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 10447 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10448 | mScreenBrightnessTimer[i].writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 10449 | } |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 10450 | mInteractiveTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 10451 | mPowerSaveModeEnabledTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 10452 | out.writeLong(mLongestLightIdleTime); |
| 10453 | out.writeLong(mLongestFullIdleTime); |
| 10454 | mDeviceIdleModeLightTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 10455 | mDeviceIdleModeFullTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 10456 | mDeviceLightIdlingTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 10457 | mDeviceIdlingTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10458 | mPhoneOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 10459 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10460 | mPhoneSignalStrengthsTimer[i].writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 10461 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10462 | mPhoneSignalScanningTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 10463 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10464 | mPhoneDataConnectionsTimer[i].writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 10465 | } |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 10466 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 10467 | mNetworkByteActivityCounters[i].writeSummaryFromParcelLocked(out); |
| 10468 | mNetworkPacketActivityCounters[i].writeSummaryFromParcelLocked(out); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 10469 | } |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10470 | mMobileRadioActiveTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 10471 | mMobileRadioActivePerAppTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 10472 | mMobileRadioActiveAdjustedTime.writeSummaryFromParcelLocked(out); |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 10473 | mMobileRadioActiveUnknownTime.writeSummaryFromParcelLocked(out); |
| 10474 | mMobileRadioActiveUnknownCount.writeSummaryFromParcelLocked(out); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10475 | mWifiOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 10476 | mGlobalWifiRunningTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 10477 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10478 | mWifiStateTimer[i].writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 10479 | } |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 10480 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
| 10481 | mWifiSupplStateTimer[i].writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 10482 | } |
| 10483 | for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 10484 | mWifiSignalStrengthsTimer[i].writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 10485 | } |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 10486 | mWifiActivity.writeSummaryToParcel(out); |
| 10487 | mBluetoothActivity.writeSummaryToParcel(out); |
| 10488 | mModemActivity.writeSummaryToParcel(out); |
| 10489 | out.writeInt(mHasWifiReporting ? 1 : 0); |
| 10490 | out.writeInt(mHasBluetoothReporting ? 1 : 0); |
| 10491 | out.writeInt(mHasModemReporting ? 1 : 0); |
| 10492 | |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 10493 | out.writeInt(mNumConnectivityChange); |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 10494 | mFlashlightOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 10495 | mCameraOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 10496 | mBluetoothScanTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10497 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 10498 | out.writeInt(mKernelWakelockStats.size()); |
| 10499 | for (Map.Entry<String, SamplingTimer> ent : mKernelWakelockStats.entrySet()) { |
| 10500 | Timer kwlt = ent.getValue(); |
| 10501 | if (kwlt != null) { |
| 10502 | out.writeInt(1); |
| 10503 | out.writeString(ent.getKey()); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 10504 | kwlt.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 10505 | } else { |
| 10506 | out.writeInt(0); |
| 10507 | } |
| 10508 | } |
| 10509 | |
| 10510 | out.writeInt(mWakeupReasonStats.size()); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 10511 | for (Map.Entry<String, SamplingTimer> ent : mWakeupReasonStats.entrySet()) { |
| 10512 | SamplingTimer timer = ent.getValue(); |
| 10513 | if (timer != null) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 10514 | out.writeInt(1); |
| 10515 | out.writeString(ent.getKey()); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 10516 | timer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 10517 | } else { |
| 10518 | out.writeInt(0); |
| 10519 | } |
| 10520 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 10521 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10522 | final int NU = mUidStats.size(); |
| 10523 | out.writeInt(NU); |
| 10524 | for (int iu = 0; iu < NU; iu++) { |
| 10525 | out.writeInt(mUidStats.keyAt(iu)); |
| 10526 | Uid u = mUidStats.valueAt(iu); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 10527 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 10528 | if (u.mWifiRunningTimer != null) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10529 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10530 | u.mWifiRunningTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10531 | } else { |
| 10532 | out.writeInt(0); |
| 10533 | } |
| 10534 | if (u.mFullWifiLockTimer != null) { |
| 10535 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10536 | u.mFullWifiLockTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10537 | } else { |
| 10538 | out.writeInt(0); |
| 10539 | } |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 10540 | if (u.mWifiScanTimer != null) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10541 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10542 | u.mWifiScanTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10543 | } else { |
| 10544 | out.writeInt(0); |
| 10545 | } |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 10546 | for (int i = 0; i < Uid.NUM_WIFI_BATCHED_SCAN_BINS; i++) { |
| 10547 | if (u.mWifiBatchedScanTimer[i] != null) { |
| 10548 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10549 | u.mWifiBatchedScanTimer[i].writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 10550 | } else { |
| 10551 | out.writeInt(0); |
| 10552 | } |
| 10553 | } |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10554 | if (u.mWifiMulticastTimer != null) { |
| 10555 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10556 | u.mWifiMulticastTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10557 | } else { |
| 10558 | out.writeInt(0); |
| 10559 | } |
| 10560 | if (u.mAudioTurnedOnTimer != null) { |
| 10561 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10562 | u.mAudioTurnedOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10563 | } else { |
| 10564 | out.writeInt(0); |
| 10565 | } |
| 10566 | if (u.mVideoTurnedOnTimer != null) { |
| 10567 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10568 | u.mVideoTurnedOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10569 | } else { |
| 10570 | out.writeInt(0); |
| 10571 | } |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 10572 | if (u.mFlashlightTurnedOnTimer != null) { |
| 10573 | out.writeInt(1); |
| 10574 | u.mFlashlightTurnedOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 10575 | } else { |
| 10576 | out.writeInt(0); |
| 10577 | } |
| 10578 | if (u.mCameraTurnedOnTimer != null) { |
| 10579 | out.writeInt(1); |
| 10580 | u.mCameraTurnedOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 10581 | } else { |
| 10582 | out.writeInt(0); |
| 10583 | } |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 10584 | if (u.mForegroundActivityTimer != null) { |
| 10585 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10586 | u.mForegroundActivityTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Jeff Sharkey | 3e013e8 | 2013-04-25 14:48:19 -0700 | [diff] [blame] | 10587 | } else { |
| 10588 | out.writeInt(0); |
| 10589 | } |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 10590 | if (u.mBluetoothScanTimer != null) { |
| 10591 | out.writeInt(1); |
| 10592 | u.mBluetoothScanTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 10593 | } else { |
| 10594 | out.writeInt(0); |
| 10595 | } |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 10596 | for (int i = 0; i < Uid.NUM_PROCESS_STATE; i++) { |
| 10597 | if (u.mProcessStateTimer[i] != null) { |
| 10598 | out.writeInt(1); |
| 10599 | u.mProcessStateTimer[i].writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 10600 | } else { |
| 10601 | out.writeInt(0); |
| 10602 | } |
| 10603 | } |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 10604 | if (u.mVibratorOnTimer != null) { |
| 10605 | out.writeInt(1); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10606 | u.mVibratorOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 10607 | } else { |
| 10608 | out.writeInt(0); |
| 10609 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10610 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 10611 | if (u.mUserActivityCounters == null) { |
| 10612 | out.writeInt(0); |
| 10613 | } else { |
| 10614 | out.writeInt(1); |
| 10615 | for (int i=0; i<Uid.NUM_USER_ACTIVITY_TYPES; i++) { |
| 10616 | u.mUserActivityCounters[i].writeSummaryFromParcelLocked(out); |
| 10617 | } |
| 10618 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 10619 | |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 10620 | if (u.mNetworkByteActivityCounters == null) { |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 10621 | out.writeInt(0); |
| 10622 | } else { |
| 10623 | out.writeInt(1); |
| 10624 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
Dianne Hackborn | 57ed6a6 | 2013-12-09 18:15:56 -0800 | [diff] [blame] | 10625 | u.mNetworkByteActivityCounters[i].writeSummaryFromParcelLocked(out); |
| 10626 | u.mNetworkPacketActivityCounters[i].writeSummaryFromParcelLocked(out); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 10627 | } |
Dianne Hackborn | d45665b | 2014-02-26 12:35:32 -0800 | [diff] [blame] | 10628 | u.mMobileRadioActiveTime.writeSummaryFromParcelLocked(out); |
| 10629 | u.mMobileRadioActiveCount.writeSummaryFromParcelLocked(out); |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 10630 | } |
| 10631 | |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 10632 | u.mUserCpuTime.writeSummaryFromParcelLocked(out); |
| 10633 | u.mSystemCpuTime.writeSummaryFromParcelLocked(out); |
Adam Lesinski | a7a4ccc | 2015-06-26 17:43:04 -0700 | [diff] [blame] | 10634 | u.mCpuPower.writeSummaryFromParcelLocked(out); |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 10635 | |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 10636 | if (u.mCpuClusterSpeed != null) { |
| 10637 | out.writeInt(1); |
| 10638 | out.writeInt(u.mCpuClusterSpeed.length); |
| 10639 | for (LongSamplingCounter[] cpuSpeeds : u.mCpuClusterSpeed) { |
| 10640 | if (cpuSpeeds != null) { |
| 10641 | out.writeInt(1); |
| 10642 | out.writeInt(cpuSpeeds.length); |
| 10643 | for (LongSamplingCounter c : cpuSpeeds) { |
| 10644 | if (c != null) { |
| 10645 | out.writeInt(1); |
| 10646 | c.writeSummaryFromParcelLocked(out); |
| 10647 | } else { |
| 10648 | out.writeInt(0); |
| 10649 | } |
| 10650 | } |
| 10651 | } else { |
| 10652 | out.writeInt(0); |
| 10653 | } |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 10654 | } |
Adam Lesinski | 6832f39 | 2015-09-05 18:05:40 -0700 | [diff] [blame] | 10655 | } else { |
| 10656 | out.writeInt(0); |
Adam Lesinski | 06af1fa | 2015-05-05 17:35:35 -0700 | [diff] [blame] | 10657 | } |
| 10658 | |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 10659 | final ArrayMap<String, Uid.Wakelock> wakeStats = u.mWakelockStats.getMap(); |
| 10660 | int NW = wakeStats.size(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10661 | out.writeInt(NW); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 10662 | for (int iw=0; iw<NW; iw++) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 10663 | out.writeString(wakeStats.keyAt(iw)); |
| 10664 | Uid.Wakelock wl = wakeStats.valueAt(iw); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 10665 | if (wl.mTimerFull != null) { |
| 10666 | out.writeInt(1); |
| 10667 | wl.mTimerFull.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 10668 | } else { |
| 10669 | out.writeInt(0); |
| 10670 | } |
| 10671 | if (wl.mTimerPartial != null) { |
| 10672 | out.writeInt(1); |
| 10673 | wl.mTimerPartial.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 10674 | } else { |
| 10675 | out.writeInt(0); |
| 10676 | } |
| 10677 | if (wl.mTimerWindow != null) { |
| 10678 | out.writeInt(1); |
| 10679 | wl.mTimerWindow.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 10680 | } else { |
| 10681 | out.writeInt(0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10682 | } |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 10683 | if (wl.mTimerDraw != null) { |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 10684 | out.writeInt(1); |
Jeff Brown | 6a8bd7b | 2015-06-19 15:07:51 -0700 | [diff] [blame] | 10685 | wl.mTimerDraw.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Adam Lesinski | 9425fe2 | 2015-06-19 12:02:13 -0700 | [diff] [blame] | 10686 | } else { |
| 10687 | out.writeInt(0); |
| 10688 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10689 | } |
| 10690 | |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 10691 | final ArrayMap<String, StopwatchTimer> syncStats = u.mSyncStats.getMap(); |
| 10692 | int NS = syncStats.size(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 10693 | out.writeInt(NS); |
| 10694 | for (int is=0; is<NS; is++) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 10695 | out.writeString(syncStats.keyAt(is)); |
| 10696 | syncStats.valueAt(is).writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 10697 | } |
| 10698 | |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 10699 | final ArrayMap<String, StopwatchTimer> jobStats = u.mJobStats.getMap(); |
| 10700 | int NJ = jobStats.size(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 10701 | out.writeInt(NJ); |
| 10702 | for (int ij=0; ij<NJ; ij++) { |
Dianne Hackborn | d953c53 | 2014-08-16 18:17:38 -0700 | [diff] [blame] | 10703 | out.writeString(jobStats.keyAt(ij)); |
| 10704 | jobStats.valueAt(ij).writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 10705 | } |
| 10706 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10707 | int NSE = u.mSensorStats.size(); |
| 10708 | out.writeInt(NSE); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 10709 | for (int ise=0; ise<NSE; ise++) { |
| 10710 | out.writeInt(u.mSensorStats.keyAt(ise)); |
| 10711 | Uid.Sensor se = u.mSensorStats.valueAt(ise); |
| 10712 | if (se.mTimer != null) { |
| 10713 | out.writeInt(1); |
| 10714 | se.mTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS); |
| 10715 | } else { |
| 10716 | out.writeInt(0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10717 | } |
| 10718 | } |
| 10719 | |
| 10720 | int NP = u.mProcessStats.size(); |
| 10721 | out.writeInt(NP); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 10722 | for (int ip=0; ip<NP; ip++) { |
| 10723 | out.writeString(u.mProcessStats.keyAt(ip)); |
| 10724 | Uid.Proc ps = u.mProcessStats.valueAt(ip); |
| 10725 | out.writeLong(ps.mUserTime); |
| 10726 | out.writeLong(ps.mSystemTime); |
| 10727 | out.writeLong(ps.mForegroundTime); |
| 10728 | out.writeInt(ps.mStarts); |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 10729 | out.writeInt(ps.mNumCrashes); |
| 10730 | out.writeInt(ps.mNumAnrs); |
Dianne Hackborn | 61659e5 | 2014-07-09 16:13:01 -0700 | [diff] [blame] | 10731 | ps.writeExcessivePowerToParcelLocked(out); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10732 | } |
| 10733 | |
| 10734 | NP = u.mPackageStats.size(); |
| 10735 | out.writeInt(NP); |
| 10736 | if (NP > 0) { |
| 10737 | for (Map.Entry<String, BatteryStatsImpl.Uid.Pkg> ent |
| 10738 | : u.mPackageStats.entrySet()) { |
| 10739 | out.writeString(ent.getKey()); |
| 10740 | Uid.Pkg ps = ent.getValue(); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 10741 | final int NWA = ps.mWakeupAlarms.size(); |
| 10742 | out.writeInt(NWA); |
| 10743 | for (int iwa=0; iwa<NWA; iwa++) { |
| 10744 | out.writeString(ps.mWakeupAlarms.keyAt(iwa)); |
| 10745 | ps.mWakeupAlarms.valueAt(iwa).writeSummaryFromParcelLocked(out); |
| 10746 | } |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 10747 | NS = ps.mServiceStats.size(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10748 | out.writeInt(NS); |
Dianne Hackborn | 1e725a7 | 2015-03-24 18:23:19 -0700 | [diff] [blame] | 10749 | for (int is=0; is<NS; is++) { |
| 10750 | out.writeString(ps.mServiceStats.keyAt(is)); |
| 10751 | BatteryStatsImpl.Uid.Pkg.Serv ss = ps.mServiceStats.valueAt(is); |
| 10752 | long time = ss.getStartTimeToNowLocked( |
| 10753 | mOnBatteryTimeBase.getUptime(NOW_SYS)); |
| 10754 | out.writeLong(time); |
| 10755 | out.writeInt(ss.mStarts); |
| 10756 | out.writeInt(ss.mLaunches); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10757 | } |
| 10758 | } |
| 10759 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10760 | } |
| 10761 | } |
| 10762 | |
| 10763 | public void readFromParcel(Parcel in) { |
| 10764 | readFromParcelLocked(in); |
| 10765 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 10766 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10767 | void readFromParcelLocked(Parcel in) { |
| 10768 | int magic = in.readInt(); |
| 10769 | if (magic != MAGIC) { |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 10770 | throw new ParcelFormatException("Bad magic number: #" + Integer.toHexString(magic)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10771 | } |
| 10772 | |
Dianne Hackborn | ae38445 | 2011-06-28 12:33:48 -0700 | [diff] [blame] | 10773 | readHistory(in, false); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 10774 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10775 | mStartCount = in.readInt(); |
Dianne Hackborn | 5f4a5f9 | 2014-01-24 16:59:34 -0800 | [diff] [blame] | 10776 | mStartClockTime = in.readLong(); |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 10777 | mStartPlatformVersion = in.readString(); |
| 10778 | mEndPlatformVersion = in.readString(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10779 | mUptime = in.readLong(); |
| 10780 | mUptimeStart = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10781 | mRealtime = in.readLong(); |
| 10782 | mRealtimeStart = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10783 | mOnBattery = in.readInt() != 0; |
| 10784 | mOnBatteryInternal = false; // we are no longer really running. |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10785 | mOnBatteryTimeBase.readFromParcel(in); |
| 10786 | mOnBatteryScreenOffTimeBase.readFromParcel(in); |
| 10787 | |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 10788 | mScreenState = Display.STATE_UNKNOWN; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 10789 | mScreenOnTimer = new StopwatchTimer(mClocks, null, -1, null, mOnBatteryTimeBase, in); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10790 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 10791 | mScreenBrightnessTimer[i] = new StopwatchTimer(mClocks, null, -100-i, null, |
| 10792 | mOnBatteryTimeBase, in); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10793 | } |
Dianne Hackborn | 2932513 | 2014-05-21 15:01:03 -0700 | [diff] [blame] | 10794 | mInteractive = false; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 10795 | mInteractiveTimer = new StopwatchTimer(mClocks, null, -10, null, mOnBatteryTimeBase, in); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10796 | mPhoneOn = false; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 10797 | mPowerSaveModeEnabledTimer = new StopwatchTimer(mClocks, null, -2, null, |
| 10798 | mOnBatteryTimeBase, in); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 10799 | mLongestLightIdleTime = in.readLong(); |
| 10800 | mLongestFullIdleTime = in.readLong(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 10801 | mDeviceIdleModeLightTimer = new StopwatchTimer(mClocks, null, -14, null, |
| 10802 | mOnBatteryTimeBase, in); |
| 10803 | mDeviceIdleModeFullTimer = new StopwatchTimer(mClocks, null, -11, null, |
| 10804 | mOnBatteryTimeBase, in); |
| 10805 | mDeviceLightIdlingTimer = new StopwatchTimer(mClocks, null, -15, null, |
| 10806 | mOnBatteryTimeBase, in); |
| 10807 | mDeviceIdlingTimer = new StopwatchTimer(mClocks, null, -12, null, mOnBatteryTimeBase, in); |
| 10808 | mPhoneOnTimer = new StopwatchTimer(mClocks, null, -3, null, mOnBatteryTimeBase, in); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10809 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 10810 | mPhoneSignalStrengthsTimer[i] = new StopwatchTimer(mClocks, null, -200-i, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10811 | null, mOnBatteryTimeBase, in); |
| 10812 | } |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 10813 | mPhoneSignalScanningTimer = new StopwatchTimer(mClocks, null, -200+1, null, |
| 10814 | mOnBatteryTimeBase, in); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10815 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 10816 | mPhoneDataConnectionsTimer[i] = new StopwatchTimer(mClocks, null, -300-i, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10817 | null, mOnBatteryTimeBase, in); |
| 10818 | } |
| 10819 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
| 10820 | mNetworkByteActivityCounters[i] = new LongSamplingCounter(mOnBatteryTimeBase, in); |
| 10821 | mNetworkPacketActivityCounters[i] = new LongSamplingCounter(mOnBatteryTimeBase, in); |
| 10822 | } |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 10823 | mMobileRadioPowerState = DataConnectionRealTimeInfo.DC_POWER_STATE_LOW; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 10824 | mMobileRadioActiveTimer = new StopwatchTimer(mClocks, null, -400, null, |
| 10825 | mOnBatteryTimeBase, in); |
| 10826 | mMobileRadioActivePerAppTimer = new StopwatchTimer(mClocks, null, -401, null, |
| 10827 | mOnBatteryTimeBase, in); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 10828 | mMobileRadioActiveAdjustedTime = new LongSamplingCounter(mOnBatteryTimeBase, in); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10829 | mMobileRadioActiveUnknownTime = new LongSamplingCounter(mOnBatteryTimeBase, in); |
| 10830 | mMobileRadioActiveUnknownCount = new LongSamplingCounter(mOnBatteryTimeBase, in); |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 10831 | mWifiRadioPowerState = DataConnectionRealTimeInfo.DC_POWER_STATE_LOW; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10832 | mWifiOn = false; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 10833 | mWifiOnTimer = new StopwatchTimer(mClocks, null, -4, null, mOnBatteryTimeBase, in); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10834 | mGlobalWifiRunning = false; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 10835 | mGlobalWifiRunningTimer = new StopwatchTimer(mClocks, null, -5, null, |
| 10836 | mOnBatteryTimeBase, in); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10837 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 10838 | mWifiStateTimer[i] = new StopwatchTimer(mClocks, null, -600-i, |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10839 | null, mOnBatteryTimeBase, in); |
| 10840 | } |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 10841 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 10842 | mWifiSupplStateTimer[i] = new StopwatchTimer(mClocks, null, -700-i, |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 10843 | null, mOnBatteryTimeBase, in); |
| 10844 | } |
| 10845 | for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 10846 | mWifiSignalStrengthsTimer[i] = new StopwatchTimer(mClocks, null, -800-i, |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 10847 | null, mOnBatteryTimeBase, in); |
| 10848 | } |
Adam Lesinski | 33dac55 | 2015-03-09 15:24:48 -0700 | [diff] [blame] | 10849 | |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 10850 | mWifiActivity = new ControllerActivityCounterImpl(mOnBatteryTimeBase, |
| 10851 | NUM_WIFI_TX_LEVELS, in); |
| 10852 | mBluetoothActivity = new ControllerActivityCounterImpl(mOnBatteryTimeBase, |
| 10853 | NUM_BT_TX_LEVELS, in); |
| 10854 | mModemActivity = new ControllerActivityCounterImpl(mOnBatteryTimeBase, |
| 10855 | ModemActivityInfo.TX_POWER_LEVELS, in); |
| 10856 | mHasWifiReporting = in.readInt() != 0; |
| 10857 | mHasBluetoothReporting = in.readInt() != 0; |
| 10858 | mHasModemReporting = in.readInt() != 0; |
| 10859 | |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 10860 | mNumConnectivityChange = in.readInt(); |
| 10861 | mLoadedNumConnectivityChange = in.readInt(); |
| 10862 | mUnpluggedNumConnectivityChange = in.readInt(); |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 10863 | mAudioOnNesting = 0; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 10864 | mAudioOnTimer = new StopwatchTimer(mClocks, null, -7, null, mOnBatteryTimeBase); |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 10865 | mVideoOnNesting = 0; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 10866 | mVideoOnTimer = new StopwatchTimer(mClocks, null, -8, null, mOnBatteryTimeBase); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 10867 | mFlashlightOnNesting = 0; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 10868 | mFlashlightOnTimer = new StopwatchTimer(mClocks, null, -9, null, mOnBatteryTimeBase, in); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 10869 | mCameraOnNesting = 0; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 10870 | mCameraOnTimer = new StopwatchTimer(mClocks, null, -13, null, mOnBatteryTimeBase, in); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 10871 | mBluetoothScanNesting = 0; |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 10872 | mBluetoothScanTimer = new StopwatchTimer(mClocks, null, -14, null, mOnBatteryTimeBase, in); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 10873 | mDischargeUnplugLevel = in.readInt(); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 10874 | mDischargePlugLevel = in.readInt(); |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 10875 | mDischargeCurrentLevel = in.readInt(); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 10876 | mCurrentBatteryLevel = in.readInt(); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 10877 | mLowDischargeAmountSinceCharge = in.readInt(); |
| 10878 | mHighDischargeAmountSinceCharge = in.readInt(); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 10879 | mDischargeAmountScreenOn = in.readInt(); |
| 10880 | mDischargeAmountScreenOnSinceCharge = in.readInt(); |
| 10881 | mDischargeAmountScreenOff = in.readInt(); |
| 10882 | mDischargeAmountScreenOffSinceCharge = in.readInt(); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 10883 | mDischargeStepTracker.readFromParcel(in); |
| 10884 | mChargeStepTracker.readFromParcel(in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10885 | mLastWriteTime = in.readLong(); |
| 10886 | |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 10887 | mKernelWakelockStats.clear(); |
| 10888 | int NKW = in.readInt(); |
| 10889 | for (int ikw = 0; ikw < NKW; ikw++) { |
| 10890 | if (in.readInt() != 0) { |
| 10891 | String wakelockName = in.readString(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 10892 | SamplingTimer kwlt = new SamplingTimer(mClocks, mOnBatteryScreenOffTimeBase, in); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 10893 | mKernelWakelockStats.put(wakelockName, kwlt); |
| 10894 | } |
| 10895 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 10896 | |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 10897 | mWakeupReasonStats.clear(); |
| 10898 | int NWR = in.readInt(); |
| 10899 | for (int iwr = 0; iwr < NWR; iwr++) { |
| 10900 | if (in.readInt() != 0) { |
| 10901 | String reasonName = in.readString(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 10902 | SamplingTimer timer = new SamplingTimer(mClocks, mOnBatteryTimeBase, in); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 10903 | mWakeupReasonStats.put(reasonName, timer); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 10904 | } |
| 10905 | } |
| 10906 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10907 | mPartialTimers.clear(); |
| 10908 | mFullTimers.clear(); |
| 10909 | mWindowTimers.clear(); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 10910 | mWifiRunningTimers.clear(); |
| 10911 | mFullWifiLockTimers.clear(); |
Nick Pelly | 6ccaa54 | 2012-06-15 15:22:47 -0700 | [diff] [blame] | 10912 | mWifiScanTimers.clear(); |
Robert Greenwalt | a029ea1 | 2013-09-25 16:38:12 -0700 | [diff] [blame] | 10913 | mWifiBatchedScanTimers.clear(); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 10914 | mWifiMulticastTimers.clear(); |
Dianne Hackborn | 10eaa85 | 2014-07-22 22:54:55 -0700 | [diff] [blame] | 10915 | mAudioTurnedOnTimers.clear(); |
| 10916 | mVideoTurnedOnTimers.clear(); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 10917 | mFlashlightTurnedOnTimers.clear(); |
| 10918 | mCameraTurnedOnTimers.clear(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10919 | |
| 10920 | int numUids = in.readInt(); |
| 10921 | mUidStats.clear(); |
| 10922 | for (int i = 0; i < numUids; i++) { |
| 10923 | int uid = in.readInt(); |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 10924 | Uid u = new Uid(this, uid); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10925 | u.readFromParcelLocked(mOnBatteryTimeBase, mOnBatteryScreenOffTimeBase, in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10926 | mUidStats.append(uid, u); |
| 10927 | } |
| 10928 | } |
| 10929 | |
| 10930 | public void writeToParcel(Parcel out, int flags) { |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 10931 | writeToParcelLocked(out, true, flags); |
| 10932 | } |
| 10933 | |
| 10934 | public void writeToParcelWithoutUids(Parcel out, int flags) { |
| 10935 | writeToParcelLocked(out, false, flags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10936 | } |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 10937 | |
| 10938 | @SuppressWarnings("unused") |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 10939 | void writeToParcelLocked(Parcel out, boolean inclUids, int flags) { |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 10940 | // Need to update with current kernel wake lock counts. |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 10941 | pullPendingStateUpdatesLocked(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 10942 | |
Dianne Hackborn | 7d9eefd | 2014-08-27 18:30:31 -0700 | [diff] [blame] | 10943 | // Pull the clock time. This may update the time and make a new history entry |
| 10944 | // if we had originally pulled a time before the RTC was set. |
| 10945 | long startClockTime = getStartClockTime(); |
| 10946 | |
Joe Onorato | abded11 | 2016-02-08 16:49:39 -0800 | [diff] [blame] | 10947 | final long uSecUptime = mClocks.uptimeMillis() * 1000; |
| 10948 | final long uSecRealtime = mClocks.elapsedRealtime() * 1000; |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10949 | final long batteryRealtime = mOnBatteryTimeBase.getRealtime(uSecRealtime); |
| 10950 | final long batteryScreenOffRealtime = mOnBatteryScreenOffTimeBase.getRealtime(uSecRealtime); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 10951 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10952 | out.writeInt(MAGIC); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 10953 | |
Dianne Hackborn | 0068d3dc | 2014-08-06 19:20:25 -0700 | [diff] [blame] | 10954 | writeHistory(out, true, false); |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 10955 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10956 | out.writeInt(mStartCount); |
Dianne Hackborn | 7d9eefd | 2014-08-27 18:30:31 -0700 | [diff] [blame] | 10957 | out.writeLong(startClockTime); |
Dianne Hackborn | cd0e335 | 2014-08-07 17:08:09 -0700 | [diff] [blame] | 10958 | out.writeString(mStartPlatformVersion); |
| 10959 | out.writeString(mEndPlatformVersion); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10960 | out.writeLong(mUptime); |
| 10961 | out.writeLong(mUptimeStart); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10962 | out.writeLong(mRealtime); |
| 10963 | out.writeLong(mRealtimeStart); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10964 | out.writeInt(mOnBattery ? 1 : 0); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10965 | mOnBatteryTimeBase.writeToParcel(out, uSecUptime, uSecRealtime); |
| 10966 | mOnBatteryScreenOffTimeBase.writeToParcel(out, uSecUptime, uSecRealtime); |
| 10967 | |
| 10968 | mScreenOnTimer.writeToParcel(out, uSecRealtime); |
| 10969 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
| 10970 | mScreenBrightnessTimer[i].writeToParcel(out, uSecRealtime); |
| 10971 | } |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 10972 | mInteractiveTimer.writeToParcel(out, uSecRealtime); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 10973 | mPowerSaveModeEnabledTimer.writeToParcel(out, uSecRealtime); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 10974 | out.writeLong(mLongestLightIdleTime); |
| 10975 | out.writeLong(mLongestFullIdleTime); |
| 10976 | mDeviceIdleModeLightTimer.writeToParcel(out, uSecRealtime); |
| 10977 | mDeviceIdleModeFullTimer.writeToParcel(out, uSecRealtime); |
| 10978 | mDeviceLightIdlingTimer.writeToParcel(out, uSecRealtime); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 10979 | mDeviceIdlingTimer.writeToParcel(out, uSecRealtime); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10980 | mPhoneOnTimer.writeToParcel(out, uSecRealtime); |
| 10981 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
| 10982 | mPhoneSignalStrengthsTimer[i].writeToParcel(out, uSecRealtime); |
| 10983 | } |
| 10984 | mPhoneSignalScanningTimer.writeToParcel(out, uSecRealtime); |
| 10985 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
| 10986 | mPhoneDataConnectionsTimer[i].writeToParcel(out, uSecRealtime); |
| 10987 | } |
| 10988 | for (int i = 0; i < NUM_NETWORK_ACTIVITY_TYPES; i++) { |
| 10989 | mNetworkByteActivityCounters[i].writeToParcel(out); |
| 10990 | mNetworkPacketActivityCounters[i].writeToParcel(out); |
| 10991 | } |
| 10992 | mMobileRadioActiveTimer.writeToParcel(out, uSecRealtime); |
| 10993 | mMobileRadioActivePerAppTimer.writeToParcel(out, uSecRealtime); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 10994 | mMobileRadioActiveAdjustedTime.writeToParcel(out); |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 10995 | mMobileRadioActiveUnknownTime.writeToParcel(out); |
| 10996 | mMobileRadioActiveUnknownCount.writeToParcel(out); |
| 10997 | mWifiOnTimer.writeToParcel(out, uSecRealtime); |
| 10998 | mGlobalWifiRunningTimer.writeToParcel(out, uSecRealtime); |
| 10999 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
| 11000 | mWifiStateTimer[i].writeToParcel(out, uSecRealtime); |
| 11001 | } |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 11002 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
| 11003 | mWifiSupplStateTimer[i].writeToParcel(out, uSecRealtime); |
| 11004 | } |
| 11005 | for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 11006 | mWifiSignalStrengthsTimer[i].writeToParcel(out, uSecRealtime); |
| 11007 | } |
Adam Lesinski | 21f76aa | 2016-01-25 12:27:06 -0800 | [diff] [blame] | 11008 | mWifiActivity.writeToParcel(out, 0); |
| 11009 | mBluetoothActivity.writeToParcel(out, 0); |
| 11010 | mModemActivity.writeToParcel(out, 0); |
| 11011 | out.writeInt(mHasWifiReporting ? 1 : 0); |
| 11012 | out.writeInt(mHasBluetoothReporting ? 1 : 0); |
| 11013 | out.writeInt(mHasModemReporting ? 1 : 0); |
| 11014 | |
Dianne Hackborn | 1e01d16 | 2014-12-04 17:46:42 -0800 | [diff] [blame] | 11015 | out.writeInt(mNumConnectivityChange); |
| 11016 | out.writeInt(mLoadedNumConnectivityChange); |
| 11017 | out.writeInt(mUnpluggedNumConnectivityChange); |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 11018 | mFlashlightOnTimer.writeToParcel(out, uSecRealtime); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 11019 | mCameraOnTimer.writeToParcel(out, uSecRealtime); |
Adam Lesinski | 9f55cc7 | 2016-01-27 20:42:14 -0800 | [diff] [blame] | 11020 | mBluetoothScanTimer.writeToParcel(out, uSecRealtime); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 11021 | out.writeInt(mDischargeUnplugLevel); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 11022 | out.writeInt(mDischargePlugLevel); |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 11023 | out.writeInt(mDischargeCurrentLevel); |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 11024 | out.writeInt(mCurrentBatteryLevel); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 11025 | out.writeInt(mLowDischargeAmountSinceCharge); |
| 11026 | out.writeInt(mHighDischargeAmountSinceCharge); |
Dianne Hackborn | c1b40e3 | 2011-01-05 18:27:40 -0800 | [diff] [blame] | 11027 | out.writeInt(mDischargeAmountScreenOn); |
| 11028 | out.writeInt(mDischargeAmountScreenOnSinceCharge); |
| 11029 | out.writeInt(mDischargeAmountScreenOff); |
| 11030 | out.writeInt(mDischargeAmountScreenOffSinceCharge); |
Dianne Hackborn | d4a8af7 | 2015-03-03 10:06:15 -0800 | [diff] [blame] | 11031 | mDischargeStepTracker.writeToParcel(out); |
| 11032 | mChargeStepTracker.writeToParcel(out); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11033 | out.writeLong(mLastWriteTime); |
| 11034 | |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 11035 | if (inclUids) { |
| 11036 | out.writeInt(mKernelWakelockStats.size()); |
| 11037 | for (Map.Entry<String, SamplingTimer> ent : mKernelWakelockStats.entrySet()) { |
| 11038 | SamplingTimer kwlt = ent.getValue(); |
| 11039 | if (kwlt != null) { |
| 11040 | out.writeInt(1); |
| 11041 | out.writeString(ent.getKey()); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 11042 | kwlt.writeToParcel(out, uSecRealtime); |
| 11043 | } else { |
| 11044 | out.writeInt(0); |
| 11045 | } |
| 11046 | } |
| 11047 | out.writeInt(mWakeupReasonStats.size()); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 11048 | for (Map.Entry<String, SamplingTimer> ent : mWakeupReasonStats.entrySet()) { |
| 11049 | SamplingTimer timer = ent.getValue(); |
| 11050 | if (timer != null) { |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 11051 | out.writeInt(1); |
| 11052 | out.writeString(ent.getKey()); |
Dianne Hackborn | c3940bc | 2014-09-05 15:50:25 -0700 | [diff] [blame] | 11053 | timer.writeToParcel(out, uSecRealtime); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 11054 | } else { |
| 11055 | out.writeInt(0); |
| 11056 | } |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 11057 | } |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 11058 | } else { |
| 11059 | out.writeInt(0); |
Evan Millar | c64edde | 2009-04-18 12:26:32 -0700 | [diff] [blame] | 11060 | } |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 11061 | |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 11062 | if (inclUids) { |
| 11063 | int size = mUidStats.size(); |
| 11064 | out.writeInt(size); |
| 11065 | for (int i = 0; i < size; i++) { |
| 11066 | out.writeInt(mUidStats.keyAt(i)); |
| 11067 | Uid uid = mUidStats.valueAt(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11068 | |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 11069 | uid.writeToParcelLocked(out, uSecRealtime); |
Dianne Hackborn | 3bee5af8 | 2010-07-23 00:22:04 -0700 | [diff] [blame] | 11070 | } |
| 11071 | } else { |
| 11072 | out.writeInt(0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11073 | } |
| 11074 | } |
| 11075 | |
| 11076 | public static final Parcelable.Creator<BatteryStatsImpl> CREATOR = |
| 11077 | new Parcelable.Creator<BatteryStatsImpl>() { |
| 11078 | public BatteryStatsImpl createFromParcel(Parcel in) { |
| 11079 | return new BatteryStatsImpl(in); |
| 11080 | } |
| 11081 | |
| 11082 | public BatteryStatsImpl[] newArray(int size) { |
| 11083 | return new BatteryStatsImpl[size]; |
| 11084 | } |
| 11085 | }; |
Jaikumar Ganesh | 5a1e4cf | 2010-10-18 17:05:09 -0700 | [diff] [blame] | 11086 | |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 11087 | public void prepareForDumpLocked() { |
| 11088 | // Need to retrieve current kernel wake lock stats before printing. |
Dianne Hackborn | a7c837f | 2014-01-15 16:20:44 -0800 | [diff] [blame] | 11089 | pullPendingStateUpdatesLocked(); |
Dianne Hackborn | 7d9eefd | 2014-08-27 18:30:31 -0700 | [diff] [blame] | 11090 | |
| 11091 | // Pull the clock time. This may update the time and make a new history entry |
| 11092 | // if we had originally pulled a time before the RTC was set. |
| 11093 | getStartClockTime(); |
Dianne Hackborn | 0ffc988 | 2011-04-13 18:15:56 -0700 | [diff] [blame] | 11094 | } |
| 11095 | |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 11096 | 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] | 11097 | if (DEBUG) { |
Dianne Hackborn | 97ae538 | 2014-03-05 16:43:25 -0800 | [diff] [blame] | 11098 | pw.println("mOnBatteryTimeBase:"); |
| 11099 | mOnBatteryTimeBase.dump(pw, " "); |
| 11100 | pw.println("mOnBatteryScreenOffTimeBase:"); |
| 11101 | mOnBatteryScreenOffTimeBase.dump(pw, " "); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11102 | Printer pr = new PrintWriterPrinter(pw); |
| 11103 | pr.println("*** Screen timer:"); |
| 11104 | mScreenOnTimer.logState(pr, " "); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 11105 | for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11106 | pr.println("*** Screen brightness #" + i + ":"); |
| 11107 | mScreenBrightnessTimer[i].logState(pr, " "); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 11108 | } |
Jeff Brown | e95c3cd | 2014-05-02 16:59:26 -0700 | [diff] [blame] | 11109 | pr.println("*** Interactive timer:"); |
| 11110 | mInteractiveTimer.logState(pr, " "); |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 11111 | pr.println("*** Power save mode timer:"); |
| 11112 | mPowerSaveModeEnabledTimer.logState(pr, " "); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 11113 | pr.println("*** Device idle mode light timer:"); |
| 11114 | mDeviceIdleModeLightTimer.logState(pr, " "); |
| 11115 | pr.println("*** Device idle mode full timer:"); |
| 11116 | mDeviceIdleModeFullTimer.logState(pr, " "); |
| 11117 | pr.println("*** Device light idling timer:"); |
| 11118 | mDeviceLightIdlingTimer.logState(pr, " "); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 11119 | pr.println("*** Device idling timer:"); |
| 11120 | mDeviceIdlingTimer.logState(pr, " "); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11121 | pr.println("*** Phone timer:"); |
| 11122 | mPhoneOnTimer.logState(pr, " "); |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 11123 | for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 11124 | pr.println("*** Phone signal strength #" + i + ":"); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11125 | mPhoneSignalStrengthsTimer[i].logState(pr, " "); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 11126 | } |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 11127 | pr.println("*** Signal scanning :"); |
| 11128 | mPhoneSignalScanningTimer.logState(pr, " "); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 11129 | for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11130 | pr.println("*** Data connection type #" + i + ":"); |
| 11131 | mPhoneDataConnectionsTimer[i].logState(pr, " "); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 11132 | } |
Dianne Hackborn | 2ffa11e | 2014-04-21 15:56:18 -0700 | [diff] [blame] | 11133 | pr.println("*** mMobileRadioPowerState=" + mMobileRadioPowerState); |
Dianne Hackborn | e13c4c0 | 2014-02-11 17:18:35 -0800 | [diff] [blame] | 11134 | pr.println("*** Mobile network active timer:"); |
| 11135 | mMobileRadioActiveTimer.logState(pr, " "); |
Dianne Hackborn | a1bd792 | 2014-03-21 11:07:11 -0700 | [diff] [blame] | 11136 | pr.println("*** Mobile network active adjusted timer:"); |
| 11137 | mMobileRadioActiveAdjustedTime.logState(pr, " "); |
Dianne Hackborn | 0c820db | 2015-04-14 17:47:34 -0700 | [diff] [blame] | 11138 | pr.println("*** mWifiRadioPowerState=" + mWifiRadioPowerState); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11139 | pr.println("*** Wifi timer:"); |
| 11140 | mWifiOnTimer.logState(pr, " "); |
| 11141 | pr.println("*** WifiRunning timer:"); |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 11142 | mGlobalWifiRunningTimer.logState(pr, " "); |
Dianne Hackborn | ca1bf21 | 2014-02-14 14:18:36 -0800 | [diff] [blame] | 11143 | for (int i=0; i<NUM_WIFI_STATES; i++) { |
| 11144 | pr.println("*** Wifi state #" + i + ":"); |
| 11145 | mWifiStateTimer[i].logState(pr, " "); |
| 11146 | } |
Dianne Hackborn | 3251b90 | 2014-06-20 14:40:53 -0700 | [diff] [blame] | 11147 | for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) { |
| 11148 | pr.println("*** Wifi suppl state #" + i + ":"); |
| 11149 | mWifiSupplStateTimer[i].logState(pr, " "); |
| 11150 | } |
| 11151 | for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) { |
| 11152 | pr.println("*** Wifi signal strength #" + i + ":"); |
| 11153 | mWifiSignalStrengthsTimer[i].logState(pr, " "); |
| 11154 | } |
Dianne Hackborn | abc7c49 | 2014-06-30 16:57:46 -0700 | [diff] [blame] | 11155 | pr.println("*** Flashlight timer:"); |
| 11156 | mFlashlightOnTimer.logState(pr, " "); |
Ruben Brunk | 6d2c363 | 2015-05-26 17:32:16 -0700 | [diff] [blame] | 11157 | pr.println("*** Camera timer:"); |
| 11158 | mCameraOnTimer.logState(pr, " "); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11159 | } |
Dianne Hackborn | c51cf03 | 2014-03-02 19:08:15 -0800 | [diff] [blame] | 11160 | super.dumpLocked(context, pw, flags, reqUid, histStart); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11161 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11162 | } |